1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Fix warnings

This commit is contained in:
Anton Leherbauer 2008-04-24 07:57:46 +00:00
parent 0c5bdcfb6c
commit a3e0775ca4
6 changed files with 68 additions and 61 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others.
* Copyright (c) 2000, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -64,7 +64,7 @@ public abstract class CodeFormatter {
*/
public static final int K_MULTI_LINE_COMMENT = 0x20;
/**
/**
* Format <code>source</code>,
* and returns a text edit that correspond to the difference between the given string and the formatted string.
* It returns null if the given string cannot be formatted.
@ -74,11 +74,10 @@ public abstract class CodeFormatter {
*
* @param kind Use to specify the kind of the code snippet to format. It can be any of these:
* K_EXPRESSION, K_STATEMENTS, K_CLASS_BODY_DECLARATIONS, K_TRANSLATION_UNIT, K_UNKNOWN
* @param file - file associated with this source (null if no file is associated)
* @param source the document to format
* @param offset the given offset to start recording the edits (inclusive).
* @param length the given length to stop recording the edits (exclusive).
* @param indentationLevel the initial indentation level, used
* @param indentationLevel the initial indentation level, used
* to shift left/right the entire source fragment. An initial indentation
* level of zero or below has no effect.
* @param lineSeparator the line separator to use in formatted source,
@ -92,7 +91,7 @@ public abstract class CodeFormatter {
/**
* @param options - general formatter options
*/
public abstract void setOptions(Map options);
public abstract void setOptions(Map<String, ?> options);
/**
* Answers the string that corresponds to the indentation to the given indentation level or an empty string

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 QNX Software Systems and others.
* Copyright (c) 2000, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.formatter;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
@ -38,7 +39,7 @@ import org.eclipse.text.edits.TextEdit;
public class CCodeFormatter extends CodeFormatter {
private DefaultCodeFormatterOptions preferences;
private Map options;
private Map<String, ?> options;
public CCodeFormatter() {
this(DefaultCodeFormatterOptions.getDefaultSettings());
@ -48,14 +49,14 @@ public class CCodeFormatter extends CodeFormatter {
this(preferences, null);
}
public CCodeFormatter(DefaultCodeFormatterOptions defaultCodeFormatterOptions, Map options) {
public CCodeFormatter(DefaultCodeFormatterOptions defaultCodeFormatterOptions, Map<String, ?> options) {
setOptions(options);
if (defaultCodeFormatterOptions != null) {
preferences.set(defaultCodeFormatterOptions.getMap());
}
}
public CCodeFormatter(Map options) {
public CCodeFormatter(Map<String, ?> options) {
this(null, options);
}
@ -102,10 +103,17 @@ public class CCodeFormatter extends CodeFormatter {
}
@Override
public void setOptions(Map options) {
public void setOptions(Map<String, ?> options) {
if (options != null) {
this.options= options;
preferences= new DefaultCodeFormatterOptions(options);
Map<String, String> formatterPrefs= new HashMap<String, String>(options.size());
for (String key : options.keySet()) {
Object value= options.get(key);
if (value instanceof String) {
formatterPrefs.put(key, (String) value);
}
}
preferences= new DefaultCodeFormatterOptions(formatterPrefs);
} else {
this.options= CCorePlugin.getOptions();
preferences= DefaultCodeFormatterOptions.getDefaultSettings();
@ -149,7 +157,7 @@ public class CCodeFormatter extends CodeFormatter {
} catch (CoreException exc) {
throw new AbortFormatting(exc);
}
CodeFormatterVisitor codeFormatter = new CodeFormatterVisitor(this.preferences, this.options, offset, length);
CodeFormatterVisitor codeFormatter = new CodeFormatterVisitor(this.preferences, offset, length);
edit= codeFormatter.format(source, ast);
IStatus status= codeFormatter.getStatus();
if (!status.isOK()) {
@ -174,7 +182,7 @@ public class CCodeFormatter extends CodeFormatter {
IASTTranslationUnit ast;
try {
ast= language.getASTTranslationUnit(reader, scanInfo, codeReaderFactory, null, ParserUtil.getParserLogService());
CodeFormatterVisitor codeFormatter = new CodeFormatterVisitor(this.preferences, this.options, offset, length);
CodeFormatterVisitor codeFormatter = new CodeFormatterVisitor(this.preferences, offset, length);
edit= codeFormatter.format(source, ast);
} catch (CoreException exc) {
throw new AbortFormatting(exc);

View file

@ -16,7 +16,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.EmptyStackException;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import org.eclipse.cdt.core.CCorePlugin;
@ -202,7 +201,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
private MultiStatus fStatus;
public CodeFormatterVisitor(DefaultCodeFormatterOptions preferences, Map<String, String> settings, int offset, int length) {
public CodeFormatterVisitor(DefaultCodeFormatterOptions preferences, int offset, int length) {
localScanner = new Scanner() {
@Override
public Token nextToken() {
@ -241,7 +240,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
if (DEBUG) return failedToFormat(e);
}
if (DEBUG){
System.out.println("Formatting time: " + (System.currentTimeMillis() - startTime)); //$NON-NLS-1$
System.out.println("Formatting time: " + (System.currentTimeMillis() - startTime)); //$NON-NLS-1$
}
return scribe.getRootEdit();
}
@ -434,11 +433,11 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
}
// declarator
final IASTDeclarator declarator= node.getDeclarator();
boolean needSpace= declarator.getPointerOperators().length > 0 && scribe.printComment();
if (needSpace) {
scribe.space();
}
if (declarator != null) {
boolean needSpace= declarator.getPointerOperators().length > 0 && scribe.printComment();
if (needSpace) {
scribe.space();
}
declarator.accept(this);
}
} finally {
@ -662,11 +661,11 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
}
// declarator
final IASTDeclarator declarator= node.getAbstractDeclarator();
boolean needSpace= declarator.getPointerOperators().length > 0 && scribe.printComment();
if (needSpace) {
scribe.space();
}
if (declarator != null) {
boolean needSpace= declarator.getPointerOperators().length > 0 && scribe.printComment();
if (needSpace) {
scribe.space();
}
declarator.accept(this);
}
} finally {
@ -1592,9 +1591,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
if (align.fSpaceAfterOpeningParen) {
scribe.space();
}
final int continuationIndentation=
align.fContinuationIndentation >= 0
? align.fContinuationIndentation
final int continuationIndentation=
align.fContinuationIndentation >= 0
? align.fContinuationIndentation
: preferences.continuation_indentation;
Alignment listAlignment = scribe.createAlignment(
"listElements_"+align,//$NON-NLS-1$
@ -2355,7 +2354,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
IASTExpression condExpr= node.getConditionExpression();
if (condExpr instanceof IASTProblemExpression) {
scribe.skipToToken(Token.tRPAREN);
} else {
} else {
condExpr.accept(this);
}
scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_if);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others.
* Copyright (c) 2000, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -40,7 +40,7 @@ public class Alignment {
public int chunkStartIndex;
public int chunkKind;
// break management
// break management
public int originalIndentationLevel;
public int breakIndentationLevel;
public int shiftBreakIndentationLevel;
@ -49,7 +49,7 @@ public class Alignment {
public Scribe scribe;
/*
/*
* Alignment modes
*/
public static final int M_FORCE = 1; // if bit set, then alignment will be non-optional (default is optional)
@ -80,14 +80,14 @@ public class Alignment {
*/
public static final int M_ONE_PER_LINE_SPLIT = 32+16; // one fragment per line
/**
/**
* foobar(<ul>
* <li> #fragment1, </li>
* <li> #fragment2, </li>
* <li> #fragment3, </li>
* <li> #fragment4, </li>
* </ul>
*/
*/
public static final int M_NEXT_SHIFTED_SPLIT = 64; // one fragment per line, subsequent are indented further
/** foobar(#fragment1, <ul>
@ -102,7 +102,7 @@ public class Alignment {
//64+32+16
// mode controlling column alignments
/**
/**
* <table BORDER COLS=4 WIDTH="100%" >
* <tr><td>#fragment1A</td> <td>#fragment2A</td> <td>#fragment3A</td> <td>#very-long-fragment4A</td></tr>
* <tr><td>#fragment1B</td> <td>#long-fragment2B</td> <td>#fragment3B</td> <td>#fragment4B</td></tr>
@ -171,7 +171,7 @@ public class Alignment {
// check for forced alignments
if ((this.mode & M_FORCE) != 0) {
couldBreak();
}
}
}
public boolean checkChunkStart(int kind, int startIndex, int sourceRestart) {
@ -232,7 +232,7 @@ public class Alignment {
* #AAAAA, #BBBBB,
* #CCCC);
*/
case M_COMPACT_FIRST_BREAK_SPLIT :
case M_COMPACT_FIRST_BREAK_SPLIT :
if (this.fragmentBreaks[0] == NONE) {
this.fragmentBreaks[0] = BREAK;
this.fragmentIndentations[0] = this.breakIndentationLevel;
@ -251,12 +251,12 @@ public class Alignment {
* foo(#AAAAA, #BBBBB,
* #CCCC);
*/
case M_COMPACT_SPLIT :
case M_COMPACT_SPLIT :
i = this.fragmentIndex;
do {
if (this.fragmentBreaks[i] == NONE) {
this.fragmentBreaks[i] = BREAK;
this.fragmentIndentations[i] = this.breakIndentationLevel;
this.fragmentIndentations[i] = this.breakIndentationLevel;
return wasSplit = true;
}
} while (--i >= 0);
@ -270,7 +270,7 @@ public class Alignment {
*/
case M_NEXT_SHIFTED_SPLIT :
if (this.fragmentBreaks[0] == NONE) {
this.fragmentBreaks[0] = BREAK;
this.fragmentBreaks[0] = BREAK;
this.fragmentIndentations[0] = this.breakIndentationLevel;
for (i = 1; i < this.fragmentCount; i++){
this.fragmentBreaks[i] = BREAK;
@ -294,12 +294,13 @@ public class Alignment {
}
return wasSplit = true;
}
break;
/* # aligned fragment
* foo(#AAAAA,
* #BBBBB,
* #CCCC);
*/
case M_NEXT_PER_LINE_SPLIT :
case M_NEXT_PER_LINE_SPLIT :
if (this.fragmentBreaks[0] == NONE) {
if (this.fragmentCount > 1
&& this.fragmentBreaks[1] == NONE) {
@ -314,7 +315,7 @@ public class Alignment {
}
}
break;
}
}
return false; // cannot split better
}
@ -347,14 +348,14 @@ public class Alignment {
if (this.fragmentIndentations[this.fragmentIndex] > 0) {
this.scribe.indentationLevel = this.fragmentIndentations[this.fragmentIndex];
}
}
}
// test whether this is an 'indent-on-column' type alignment and aligns on the given column
public boolean isIndentOnColumn(int column) {
return (mode & M_INDENT_ON_COLUMN) != 0 && breakIndentationLevel == column - 1;
}
// reset fragment indentation/break status
// reset fragment indentation/break status
public void reset() {
if (fragmentCount > 0){
@ -365,8 +366,8 @@ public class Alignment {
// check for forced alignments
if ((mode & M_FORCE) != 0) {
couldBreak();
}
}
}
}
public void toFragmentsString(StringBuffer buffer){
// default implementation
@ -387,7 +388,7 @@ public class Alignment {
.append(this.enclosing.name)
.append('>');
}
buffer.append('\n');
buffer.append('\n');
for (int i = 0; i < this.fragmentCount; i++){
buffer
@ -401,7 +402,7 @@ public class Alignment {
.append(this.fragmentIndentations[i])
.append(">\n"); //$NON-NLS-1$
}
buffer.append('\n');
buffer.append('\n');
return buffer.toString();
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2006 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -19,7 +19,7 @@ import java.util.Stack;
public class ScannerContext {
private Reader fReader;
private int fOffset;
private Stack fUndo = new Stack();
private Stack<Integer> fUndo = new Stack<Integer>();
public ScannerContext() {
}
@ -69,7 +69,7 @@ public class ScannerContext {
* @return int
*/
public final int popUndo() {
return ((Integer)fUndo.pop()).intValue();
return fUndo.pop().intValue();
}
/**

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2006 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -17,7 +17,7 @@ import java.io.Reader;
import java.util.HashMap;
/**
* A C/C++ lexical scanner, which does no preprocessing,
* A C/C++ lexical scanner, which does no preprocessing,
* but tokenizes preprocessor directives, whitespace and comments.
*
* @since 4.0
@ -25,7 +25,7 @@ import java.util.HashMap;
public class SimpleScanner {
private static final int EOFCHAR= -1;
protected static HashMap fgKeywords= new HashMap();
protected static HashMap<String, Integer> fgKeywords= new HashMap<String, Integer>();
protected Token fCurrentToken;
protected ScannerContext fContext;
@ -263,20 +263,20 @@ public class SimpleScanner {
if (c == 'e' || c == 'E') {
if (!floatingPoint)
floatingPoint = true;
// exponent type for floating point
// exponent type for floating point
c = getChar();
// optional + or -
// optional + or -
if (c == '+' || c == '-') {
c = getChar();
}
// digit sequence of exponent part
// digit sequence of exponent part
while ((c >= '0' && c <= '9')) {
c = getChar();
}
// optional suffix
// optional suffix
if (c == 'l' || c == 'L' || c == 'f' || c == 'F') {
c = getChar();
}
@ -621,7 +621,7 @@ public class SimpleScanner {
matchCharLiteral();
return newToken(Token.tCHAR);
case '"':
case '"':
if (fTokenBuffer.length() > 1) {
if (fPreprocessorToken==0) {
fPreprocessorToken= categorizePreprocessor(fTokenBuffer);
@ -653,7 +653,7 @@ public class SimpleScanner {
}
fPreprocessorToken= 0;
return result;
}
}
if (next == '*') {
if (fTokenBuffer.length() > 2) {
ungetChar(next);
@ -682,7 +682,7 @@ public class SimpleScanner {
ungetChar(c);
Token result= null;
if (fTokenBuffer.length() > 0) {
result= newPreprocessorToken();
result= newPreprocessorToken();
}
fPreprocessorToken= 0;
return result;
@ -698,7 +698,7 @@ public class SimpleScanner {
c = getChar();
}
if (c == '/') {
// we need to peek ahead at the next character to see if
// we need to peek ahead at the next character to see if
// this is a comment or not
int next = getChar();
if (next == '/') {