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
@ -74,7 +74,6 @@ 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).
@ -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() {
@ -434,11 +433,11 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
} }
// declarator // declarator
final IASTDeclarator declarator= node.getDeclarator(); final IASTDeclarator declarator= node.getDeclarator();
if (declarator != null) {
boolean needSpace= declarator.getPointerOperators().length > 0 && scribe.printComment(); boolean needSpace= declarator.getPointerOperators().length > 0 && scribe.printComment();
if (needSpace) { if (needSpace) {
scribe.space(); scribe.space();
} }
if (declarator != null) {
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();
if (declarator != null) {
boolean needSpace= declarator.getPointerOperators().length > 0 && scribe.printComment(); boolean needSpace= declarator.getPointerOperators().length > 0 && scribe.printComment();
if (needSpace) { if (needSpace) {
scribe.space(); scribe.space();
} }
if (declarator != null) {
declarator.accept(this); declarator.accept(this);
} }
} finally { } finally {

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
@ -294,6 +294,7 @@ public class Alignment {
} }
return wasSplit = true; return wasSplit = true;
} }
break;
/* # aligned fragment /* # aligned fragment
* foo(#AAAAA, * foo(#AAAAA,
* #BBBBB, * #BBBBB,

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
@ -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;