1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * 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; public static final int K_MULTI_LINE_COMMENT = 0x20;
/** /**
* Format <code>source</code>, * Format <code>source</code>,
* and returns a text edit that correspond to the difference between the given string and the formatted string. * 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. * 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: * @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 * 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 source the document to format
* @param offset the given offset to start recording the edits (inclusive). * @param offset the given offset to start recording the edits (inclusive).
* @param length the given length to stop recording the edits (exclusive). * @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 * to shift left/right the entire source fragment. An initial indentation
* level of zero or below has no effect. * level of zero or below has no effect.
* @param lineSeparator the line separator to use in formatted source, * @param lineSeparator the line separator to use in formatted source,
@ -92,7 +91,7 @@ public abstract class CodeFormatter {
/** /**
* @param options - general formatter options * @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 * 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -13,6 +13,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.formatter; package org.eclipse.cdt.internal.formatter;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
@ -38,7 +39,7 @@ import org.eclipse.text.edits.TextEdit;
public class CCodeFormatter extends CodeFormatter { public class CCodeFormatter extends CodeFormatter {
private DefaultCodeFormatterOptions preferences; private DefaultCodeFormatterOptions preferences;
private Map options; private Map<String, ?> options;
public CCodeFormatter() { public CCodeFormatter() {
this(DefaultCodeFormatterOptions.getDefaultSettings()); this(DefaultCodeFormatterOptions.getDefaultSettings());
@ -48,14 +49,14 @@ public class CCodeFormatter extends CodeFormatter {
this(preferences, null); this(preferences, null);
} }
public CCodeFormatter(DefaultCodeFormatterOptions defaultCodeFormatterOptions, Map options) { public CCodeFormatter(DefaultCodeFormatterOptions defaultCodeFormatterOptions, Map<String, ?> options) {
setOptions(options); setOptions(options);
if (defaultCodeFormatterOptions != null) { if (defaultCodeFormatterOptions != null) {
preferences.set(defaultCodeFormatterOptions.getMap()); preferences.set(defaultCodeFormatterOptions.getMap());
} }
} }
public CCodeFormatter(Map options) { public CCodeFormatter(Map<String, ?> options) {
this(null, options); this(null, options);
} }
@ -102,10 +103,17 @@ public class CCodeFormatter extends CodeFormatter {
} }
@Override @Override
public void setOptions(Map options) { public void setOptions(Map<String, ?> options) {
if (options != null) { if (options != null) {
this.options= options; 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 { } else {
this.options= CCorePlugin.getOptions(); this.options= CCorePlugin.getOptions();
preferences= DefaultCodeFormatterOptions.getDefaultSettings(); preferences= DefaultCodeFormatterOptions.getDefaultSettings();
@ -149,7 +157,7 @@ public class CCodeFormatter extends CodeFormatter {
} catch (CoreException exc) { } catch (CoreException exc) {
throw new AbortFormatting(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); edit= codeFormatter.format(source, ast);
IStatus status= codeFormatter.getStatus(); IStatus status= codeFormatter.getStatus();
if (!status.isOK()) { if (!status.isOK()) {
@ -174,7 +182,7 @@ public class CCodeFormatter extends CodeFormatter {
IASTTranslationUnit ast; IASTTranslationUnit ast;
try { try {
ast= language.getASTTranslationUnit(reader, scanInfo, codeReaderFactory, null, ParserUtil.getParserLogService()); 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); edit= codeFormatter.format(source, ast);
} catch (CoreException exc) { } catch (CoreException exc) {
throw new AbortFormatting(exc); throw new AbortFormatting(exc);

View file

@ -16,7 +16,6 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.EmptyStackException; import java.util.EmptyStackException;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Stack; import java.util.Stack;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
@ -202,7 +201,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
private MultiStatus fStatus; 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() { localScanner = new Scanner() {
@Override @Override
public Token nextToken() { public Token nextToken() {
@ -241,7 +240,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
if (DEBUG) return failedToFormat(e); if (DEBUG) return failedToFormat(e);
} }
if (DEBUG){ 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(); return scribe.getRootEdit();
} }
@ -434,11 +433,11 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
} }
// declarator // declarator
final IASTDeclarator declarator= node.getDeclarator(); final IASTDeclarator declarator= node.getDeclarator();
boolean needSpace= declarator.getPointerOperators().length > 0 && scribe.printComment();
if (needSpace) {
scribe.space();
}
if (declarator != null) { if (declarator != null) {
boolean needSpace= declarator.getPointerOperators().length > 0 && scribe.printComment();
if (needSpace) {
scribe.space();
}
declarator.accept(this); declarator.accept(this);
} }
} finally { } finally {
@ -662,11 +661,11 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
} }
// declarator // declarator
final IASTDeclarator declarator= node.getAbstractDeclarator(); final IASTDeclarator declarator= node.getAbstractDeclarator();
boolean needSpace= declarator.getPointerOperators().length > 0 && scribe.printComment();
if (needSpace) {
scribe.space();
}
if (declarator != null) { if (declarator != null) {
boolean needSpace= declarator.getPointerOperators().length > 0 && scribe.printComment();
if (needSpace) {
scribe.space();
}
declarator.accept(this); declarator.accept(this);
} }
} finally { } finally {
@ -1592,9 +1591,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
if (align.fSpaceAfterOpeningParen) { if (align.fSpaceAfterOpeningParen) {
scribe.space(); scribe.space();
} }
final int continuationIndentation= final int continuationIndentation=
align.fContinuationIndentation >= 0 align.fContinuationIndentation >= 0
? align.fContinuationIndentation ? align.fContinuationIndentation
: preferences.continuation_indentation; : preferences.continuation_indentation;
Alignment listAlignment = scribe.createAlignment( Alignment listAlignment = scribe.createAlignment(
"listElements_"+align,//$NON-NLS-1$ "listElements_"+align,//$NON-NLS-1$
@ -2355,7 +2354,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
IASTExpression condExpr= node.getConditionExpression(); IASTExpression condExpr= node.getConditionExpression();
if (condExpr instanceof IASTProblemExpression) { if (condExpr instanceof IASTProblemExpression) {
scribe.skipToToken(Token.tRPAREN); scribe.skipToToken(Token.tRPAREN);
} else { } else {
condExpr.accept(this); condExpr.accept(this);
} }
scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_if); 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -40,7 +40,7 @@ public class Alignment {
public int chunkStartIndex; public int chunkStartIndex;
public int chunkKind; public int chunkKind;
// break management // break management
public int originalIndentationLevel; public int originalIndentationLevel;
public int breakIndentationLevel; public int breakIndentationLevel;
public int shiftBreakIndentationLevel; public int shiftBreakIndentationLevel;
@ -49,7 +49,7 @@ public class Alignment {
public Scribe scribe; public Scribe scribe;
/* /*
* Alignment modes * Alignment modes
*/ */
public static final int M_FORCE = 1; // if bit set, then alignment will be non-optional (default is optional) 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 public static final int M_ONE_PER_LINE_SPLIT = 32+16; // one fragment per line
/** /**
* foobar(<ul> * foobar(<ul>
* <li> #fragment1, </li> * <li> #fragment1, </li>
* <li> #fragment2, </li> * <li> #fragment2, </li>
* <li> #fragment3, </li> * <li> #fragment3, </li>
* <li> #fragment4, </li> * <li> #fragment4, </li>
* </ul> * </ul>
*/ */
public static final int M_NEXT_SHIFTED_SPLIT = 64; // one fragment per line, subsequent are indented further public static final int M_NEXT_SHIFTED_SPLIT = 64; // one fragment per line, subsequent are indented further
/** foobar(#fragment1, <ul> /** foobar(#fragment1, <ul>
@ -102,7 +102,7 @@ public class Alignment {
//64+32+16 //64+32+16
// mode controlling column alignments // mode controlling column alignments
/** /**
* <table BORDER COLS=4 WIDTH="100%" > * <table BORDER COLS=4 WIDTH="100%" >
* <tr><td>#fragment1A</td> <td>#fragment2A</td> <td>#fragment3A</td> <td>#very-long-fragment4A</td></tr> * <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> * <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 // check for forced alignments
if ((this.mode & M_FORCE) != 0) { if ((this.mode & M_FORCE) != 0) {
couldBreak(); couldBreak();
} }
} }
public boolean checkChunkStart(int kind, int startIndex, int sourceRestart) { public boolean checkChunkStart(int kind, int startIndex, int sourceRestart) {
@ -232,7 +232,7 @@ public class Alignment {
* #AAAAA, #BBBBB, * #AAAAA, #BBBBB,
* #CCCC); * #CCCC);
*/ */
case M_COMPACT_FIRST_BREAK_SPLIT : case M_COMPACT_FIRST_BREAK_SPLIT :
if (this.fragmentBreaks[0] == NONE) { if (this.fragmentBreaks[0] == NONE) {
this.fragmentBreaks[0] = BREAK; this.fragmentBreaks[0] = BREAK;
this.fragmentIndentations[0] = this.breakIndentationLevel; this.fragmentIndentations[0] = this.breakIndentationLevel;
@ -251,12 +251,12 @@ public class Alignment {
* foo(#AAAAA, #BBBBB, * foo(#AAAAA, #BBBBB,
* #CCCC); * #CCCC);
*/ */
case M_COMPACT_SPLIT : case M_COMPACT_SPLIT :
i = this.fragmentIndex; i = this.fragmentIndex;
do { do {
if (this.fragmentBreaks[i] == NONE) { if (this.fragmentBreaks[i] == NONE) {
this.fragmentBreaks[i] = BREAK; this.fragmentBreaks[i] = BREAK;
this.fragmentIndentations[i] = this.breakIndentationLevel; this.fragmentIndentations[i] = this.breakIndentationLevel;
return wasSplit = true; return wasSplit = true;
} }
} while (--i >= 0); } while (--i >= 0);
@ -270,7 +270,7 @@ public class Alignment {
*/ */
case M_NEXT_SHIFTED_SPLIT : case M_NEXT_SHIFTED_SPLIT :
if (this.fragmentBreaks[0] == NONE) { if (this.fragmentBreaks[0] == NONE) {
this.fragmentBreaks[0] = BREAK; this.fragmentBreaks[0] = BREAK;
this.fragmentIndentations[0] = this.breakIndentationLevel; this.fragmentIndentations[0] = this.breakIndentationLevel;
for (i = 1; i < this.fragmentCount; i++){ for (i = 1; i < this.fragmentCount; i++){
this.fragmentBreaks[i] = BREAK; this.fragmentBreaks[i] = BREAK;
@ -294,12 +294,13 @@ public class Alignment {
} }
return wasSplit = true; return wasSplit = true;
} }
break;
/* # aligned fragment /* # aligned fragment
* foo(#AAAAA, * foo(#AAAAA,
* #BBBBB, * #BBBBB,
* #CCCC); * #CCCC);
*/ */
case M_NEXT_PER_LINE_SPLIT : case M_NEXT_PER_LINE_SPLIT :
if (this.fragmentBreaks[0] == NONE) { if (this.fragmentBreaks[0] == NONE) {
if (this.fragmentCount > 1 if (this.fragmentCount > 1
&& this.fragmentBreaks[1] == NONE) { && this.fragmentBreaks[1] == NONE) {
@ -314,7 +315,7 @@ public class Alignment {
} }
} }
break; break;
} }
return false; // cannot split better return false; // cannot split better
} }
@ -347,14 +348,14 @@ public class Alignment {
if (this.fragmentIndentations[this.fragmentIndex] > 0) { if (this.fragmentIndentations[this.fragmentIndex] > 0) {
this.scribe.indentationLevel = this.fragmentIndentations[this.fragmentIndex]; this.scribe.indentationLevel = this.fragmentIndentations[this.fragmentIndex];
} }
} }
// test whether this is an 'indent-on-column' type alignment and aligns on the given column // test whether this is an 'indent-on-column' type alignment and aligns on the given column
public boolean isIndentOnColumn(int column) { public boolean isIndentOnColumn(int column) {
return (mode & M_INDENT_ON_COLUMN) != 0 && breakIndentationLevel == column - 1; return (mode & M_INDENT_ON_COLUMN) != 0 && breakIndentationLevel == column - 1;
} }
// reset fragment indentation/break status // reset fragment indentation/break status
public void reset() { public void reset() {
if (fragmentCount > 0){ if (fragmentCount > 0){
@ -365,8 +366,8 @@ public class Alignment {
// check for forced alignments // check for forced alignments
if ((mode & M_FORCE) != 0) { if ((mode & M_FORCE) != 0) {
couldBreak(); couldBreak();
} }
} }
public void toFragmentsString(StringBuffer buffer){ public void toFragmentsString(StringBuffer buffer){
// default implementation // default implementation
@ -387,7 +388,7 @@ public class Alignment {
.append(this.enclosing.name) .append(this.enclosing.name)
.append('>'); .append('>');
} }
buffer.append('\n'); buffer.append('\n');
for (int i = 0; i < this.fragmentCount; i++){ for (int i = 0; i < this.fragmentCount; i++){
buffer buffer
@ -401,7 +402,7 @@ public class Alignment {
.append(this.fragmentIndentations[i]) .append(this.fragmentIndentations[i])
.append(">\n"); //$NON-NLS-1$ .append(">\n"); //$NON-NLS-1$
} }
buffer.append('\n'); buffer.append('\n');
return buffer.toString(); 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -19,7 +19,7 @@ import java.util.Stack;
public class ScannerContext { public class ScannerContext {
private Reader fReader; private Reader fReader;
private int fOffset; private int fOffset;
private Stack fUndo = new Stack(); private Stack<Integer> fUndo = new Stack<Integer>();
public ScannerContext() { public ScannerContext() {
} }
@ -69,7 +69,7 @@ public class ScannerContext {
* @return int * @return int
*/ */
public final int popUndo() { 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -17,7 +17,7 @@ import java.io.Reader;
import java.util.HashMap; 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. * but tokenizes preprocessor directives, whitespace and comments.
* *
* @since 4.0 * @since 4.0
@ -25,7 +25,7 @@ import java.util.HashMap;
public class SimpleScanner { public class SimpleScanner {
private static final int EOFCHAR= -1; 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 Token fCurrentToken;
protected ScannerContext fContext; protected ScannerContext fContext;
@ -263,20 +263,20 @@ public class SimpleScanner {
if (c == 'e' || c == 'E') { if (c == 'e' || c == 'E') {
if (!floatingPoint) if (!floatingPoint)
floatingPoint = true; floatingPoint = true;
// exponent type for floating point // exponent type for floating point
c = getChar(); c = getChar();
// optional + or - // optional + or -
if (c == '+' || c == '-') { if (c == '+' || c == '-') {
c = getChar(); c = getChar();
} }
// digit sequence of exponent part // digit sequence of exponent part
while ((c >= '0' && c <= '9')) { while ((c >= '0' && c <= '9')) {
c = getChar(); c = getChar();
} }
// optional suffix // optional suffix
if (c == 'l' || c == 'L' || c == 'f' || c == 'F') { if (c == 'l' || c == 'L' || c == 'f' || c == 'F') {
c = getChar(); c = getChar();
} }
@ -621,7 +621,7 @@ public class SimpleScanner {
matchCharLiteral(); matchCharLiteral();
return newToken(Token.tCHAR); return newToken(Token.tCHAR);
case '"': case '"':
if (fTokenBuffer.length() > 1) { if (fTokenBuffer.length() > 1) {
if (fPreprocessorToken==0) { if (fPreprocessorToken==0) {
fPreprocessorToken= categorizePreprocessor(fTokenBuffer); fPreprocessorToken= categorizePreprocessor(fTokenBuffer);
@ -653,7 +653,7 @@ public class SimpleScanner {
} }
fPreprocessorToken= 0; fPreprocessorToken= 0;
return result; return result;
} }
if (next == '*') { if (next == '*') {
if (fTokenBuffer.length() > 2) { if (fTokenBuffer.length() > 2) {
ungetChar(next); ungetChar(next);
@ -682,7 +682,7 @@ public class SimpleScanner {
ungetChar(c); ungetChar(c);
Token result= null; Token result= null;
if (fTokenBuffer.length() > 0) { if (fTokenBuffer.length() > 0) {
result= newPreprocessorToken(); result= newPreprocessorToken();
} }
fPreprocessorToken= 0; fPreprocessorToken= 0;
return result; return result;
@ -698,7 +698,7 @@ public class SimpleScanner {
c = getChar(); c = getChar();
} }
if (c == '/') { 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 // this is a comment or not
int next = getChar(); int next = getChar();
if (next == '/') { if (next == '/') {