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

Removed class Problem, a duplicate of ASTProblem, related to bug 212864.

This commit is contained in:
Markus Schorn 2008-02-21 10:20:04 +00:00
parent f7b257a9a2
commit f211b6d512
22 changed files with 169 additions and 950 deletions

View file

@ -1,12 +1,12 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2007 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
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.make.internal.core.scannerconfig.gnu; package org.eclipse.cdt.make.internal.core.scannerconfig.gnu;
@ -15,6 +15,7 @@ import java.util.Iterator;
import java.util.Vector; import java.util.Vector;
import org.eclipse.cdt.core.IMarkerGenerator; import org.eclipse.cdt.core.IMarkerGenerator;
import org.eclipse.cdt.core.ProblemMarkerInfo;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
@ -28,17 +29,17 @@ import org.eclipse.core.runtime.Path;
public abstract class AbstractGCCBOPConsoleParserUtility { public abstract class AbstractGCCBOPConsoleParserUtility {
private IProject project; private IProject project;
private IPath fBaseDirectory; private IPath fBaseDirectory;
private Vector fDirectoryStack; private Vector<IPath> fDirectoryStack;
private IMarkerGenerator fMarkerGenerator; private IMarkerGenerator fMarkerGenerator;
private ArrayList fErrors; private ArrayList<Problem> fErrors;
/** /**
* *
*/ */
public AbstractGCCBOPConsoleParserUtility(IProject project, IPath workingDirectory, public AbstractGCCBOPConsoleParserUtility(IProject project, IPath workingDirectory,
IMarkerGenerator markerGenerator) { IMarkerGenerator markerGenerator) {
fDirectoryStack = new Vector(); fDirectoryStack = new Vector<IPath>();
fErrors = new ArrayList(); fErrors = new ArrayList<Problem>();
this.project = project; this.project = project;
fBaseDirectory = project.getLocation(); fBaseDirectory = project.getLocation();
if (workingDirectory != null) { if (workingDirectory != null) {
@ -55,13 +56,13 @@ public abstract class AbstractGCCBOPConsoleParserUtility {
/** /**
* @return Returns the fDirectoryStack. * @return Returns the fDirectoryStack.
*/ */
protected Vector getDirectoryStack() { protected Vector<IPath> getDirectoryStack() {
return fDirectoryStack; return fDirectoryStack;
} }
/** /**
* @return Returns the fErrors. * @return Returns the fErrors.
*/ */
protected ArrayList getErrors() { protected ArrayList<Problem> getErrors() {
return fErrors; return fErrors;
} }
/** /**
@ -79,7 +80,7 @@ public abstract class AbstractGCCBOPConsoleParserUtility {
public IPath getWorkingDirectory() { public IPath getWorkingDirectory() {
if (fDirectoryStack.size() != 0) { if (fDirectoryStack.size() != 0) {
return (IPath) fDirectoryStack.lastElement(); return fDirectoryStack.lastElement();
} }
// Fallback to the Project Location // Fallback to the Project Location
// FIXME: if the build did not start in the Project ? // FIXME: if the build did not start in the Project ?
@ -114,7 +115,7 @@ public abstract class AbstractGCCBOPConsoleParserUtility {
protected IPath popDirectory() { protected IPath popDirectory() {
int i = getDirectoryLevel(); int i = getDirectoryLevel();
if (i != 0) { if (i != 0) {
IPath dir = (IPath) fDirectoryStack.lastElement(); IPath dir = fDirectoryStack.lastElement();
fDirectoryStack.removeElementAt(i - 1); fDirectoryStack.removeElementAt(i - 1);
return dir; return dir;
} }
@ -143,25 +144,25 @@ public abstract class AbstractGCCBOPConsoleParserUtility {
public boolean reportProblems() { public boolean reportProblems() {
boolean reset = false; boolean reset = false;
for (Iterator iter = fErrors.iterator(); iter.hasNext(); ) { for (Iterator<Problem> iter = fErrors.iterator(); iter.hasNext(); ) {
Problem problem = (Problem) iter.next(); Problem problem = iter.next();
if (problem.severity == IMarkerGenerator.SEVERITY_ERROR_BUILD) { if (problem.severity == IMarkerGenerator.SEVERITY_ERROR_BUILD) {
reset = true; reset = true;
} }
if (problem.file == null) { if (problem.file == null) {
fMarkerGenerator.addMarker( fMarkerGenerator.addMarker(new ProblemMarkerInfo(
project, project,
problem.lineNumber, problem.lineNumber,
problem.description, problem.description,
problem.severity, problem.severity,
problem.variableName); problem.variableName));
} else { } else {
fMarkerGenerator.addMarker( fMarkerGenerator.addMarker(new ProblemMarkerInfo(
problem.file, problem.file,
problem.lineNumber, problem.lineNumber,
problem.description, problem.description,
problem.severity, problem.severity,
problem.variableName); problem.variableName));
} }
} }
fErrors.clear(); fErrors.clear();
@ -194,5 +195,4 @@ public abstract class AbstractGCCBOPConsoleParserUtility {
fErrors.add(problem); fErrors.add(problem);
} }
} }
} }

View file

@ -98,11 +98,13 @@ public class LocationMapTests extends BaseTestCase {
return suite(LocationMapTests.class); return suite(LocationMapTests.class);
} }
@Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
fLocationMap= new LocationMap(); fLocationMap= new LocationMap();
} }
@Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
fLocationMap= null; fLocationMap= null;
super.tearDown(); super.tearDown();
@ -177,7 +179,9 @@ public class LocationMapTests extends BaseTestCase {
private void checkProblem(IASTProblem problem, int id, String arg, String marked, private void checkProblem(IASTProblem problem, int id, String arg, String marked,
String filename, int offset, int length, int line, int endline) { String filename, int offset, int length, int line, int endline) {
assertEquals(id, problem.getID()); assertEquals(id, problem.getID());
assertEquals(arg, problem.getArguments()); if (arg != null) {
assertEquals(arg, problem.getArguments()[0]);
}
assertFalse(problem.isError()); assertFalse(problem.isError());
assertTrue(problem.isWarning()); assertTrue(problem.isWarning());
checkASTNode(problem, fTu, IASTTranslationUnit.SCANNER_PROBLEM, filename, offset, length, line, endline, marked); checkASTNode(problem, fTu, IASTTranslationUnit.SCANNER_PROBLEM, filename, offset, length, line, endline, marked);
@ -302,7 +306,7 @@ public class LocationMapTests extends BaseTestCase {
fLocationMap.encounterProblem(2, "b".toCharArray(), 5,16); fLocationMap.encounterProblem(2, "b".toCharArray(), 5,16);
IASTProblem[] problems= fLocationMap.getScannerProblems(); IASTProblem[] problems= fLocationMap.getScannerProblems();
assertEquals(3, problems.length); assertEquals(3, problems.length);
checkProblem(problems[0], 0, "", "", FN, 0,0,1,1); checkProblem(problems[0], 0, null, "", FN, 0,0,1,1);
checkProblem(problems[1], 1, "a", "12", FN,1,2,1,1); checkProblem(problems[1], 1, "a", "12", FN,1,2,1,1);
checkProblem(problems[2], 2, "b", "56789abcdef", FN,5,11,1,1); checkProblem(problems[2], 2, "b", "56789abcdef", FN,5,11,1,1);
} }

View file

@ -168,7 +168,7 @@ public abstract class PreprocessorTestsBase extends BaseTestCase {
IASTProblem problem= fLocationResolver.getScannerProblems()[idx]; IASTProblem problem= fLocationResolver.getScannerProblems()[idx];
assertEquals(problemID, problem.getID()); assertEquals(problemID, problem.getID());
if (detail != null) { if (detail != null) {
assertEquals(detail, problem.getArguments()); assertEquals(detail, problem.getArguments()[0]);
} }
} }

View file

@ -75,7 +75,6 @@ import org.eclipse.cdt.core.model.IContributedModelBuilder;
import org.eclipse.cdt.core.model.IProblemRequestor; import org.eclipse.cdt.core.model.IProblemRequestor;
import org.eclipse.cdt.core.model.IStructure; import org.eclipse.cdt.core.model.IStructure;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration;
@ -91,104 +90,6 @@ import org.eclipse.core.runtime.OperationCanceledException;
*/ */
public class CModelBuilder2 implements IContributedModelBuilder { public class CModelBuilder2 implements IContributedModelBuilder {
/**
* Adapts {@link IASTProblem} to {@link IProblem).
*/
private static class ProblemAdapter implements IProblem {
private IASTProblem fASTProblem;
/**
* @param problem
*/
public ProblemAdapter(IASTProblem problem) {
fASTProblem= problem;
}
/*
* @see org.eclipse.cdt.core.parser.IProblem#checkCategory(int)
*/
public boolean checkCategory(int bitmask) {
return fASTProblem.checkCategory(bitmask);
}
/*
* @see org.eclipse.cdt.core.parser.IProblem#getArguments()
*/
public String[] getArguments() {
return new String[] { fASTProblem.getArguments() };
}
/*
* @see org.eclipse.cdt.core.parser.IProblem#getID()
*/
public int getID() {
return fASTProblem.getID();
}
/*
* @see org.eclipse.cdt.core.parser.IProblem#getMessage()
*/
public String getMessage() {
return fASTProblem.getMessageWithoutLocation();
}
/*
* @see org.eclipse.cdt.core.parser.IProblem#getOriginatingFileName()
*/
public char[] getOriginatingFileName() {
return fASTProblem.getContainingFilename().toCharArray();
}
/*
* @see org.eclipse.cdt.core.parser.IProblem#getSourceEnd()
*/
public int getSourceEnd() {
IASTFileLocation location= fASTProblem.getFileLocation();
if (location != null) {
return location.getNodeOffset() + location.getNodeLength() - 1;
}
return -1;
}
/*
* @see org.eclipse.cdt.core.parser.IProblem#getSourceLineNumber()
*/
public int getSourceLineNumber() {
IASTFileLocation location= fASTProblem.getFileLocation();
if (location != null) {
return location.getStartingLineNumber();
}
return -1;
}
/*
* @see org.eclipse.cdt.core.parser.IProblem#getSourceStart()
*/
public int getSourceStart() {
IASTFileLocation location= fASTProblem.getFileLocation();
if (location != null) {
return location.getNodeOffset();
}
return -1;
}
/*
* @see org.eclipse.cdt.core.parser.IProblem#isError()
*/
public boolean isError() {
return fASTProblem.isError();
}
/*
* @see org.eclipse.cdt.core.parser.IProblem#isWarning()
*/
public boolean isWarning() {
return fASTProblem.isWarning();
}
}
private final TranslationUnit fTranslationUnit; private final TranslationUnit fTranslationUnit;
private String fTranslationUnitFileName; private String fTranslationUnitFileName;
private ASTAccessVisibility fCurrentVisibility; private ASTAccessVisibility fCurrentVisibility;
@ -340,14 +241,14 @@ public class CModelBuilder2 implements IContributedModelBuilder {
for (int i= 0; i < problems.length; i++) { for (int i= 0; i < problems.length; i++) {
IASTProblem problem= problems[i]; IASTProblem problem= problems[i];
if (isLocalToFile(problem)) { if (isLocalToFile(problem)) {
problemRequestor.acceptProblem(new ProblemAdapter(problem)); problemRequestor.acceptProblem(problem);
} }
} }
problems= CPPVisitor.getProblems(ast); problems= CPPVisitor.getProblems(ast);
for (int i= 0; i < problems.length; i++) { for (int i= 0; i < problems.length; i++) {
IASTProblem problem= problems[i]; IASTProblem problem= problems[i];
if (isLocalToFile(problem)) { if (isLocalToFile(problem)) {
problemRequestor.acceptProblem(new ProblemAdapter(problem)); problemRequestor.acceptProblem(problem);
} }
} }
problemRequestor.endReporting(); problemRequestor.endReporting();

View file

@ -1083,6 +1083,6 @@ public class ASTSignatureUtil {
* Returns the same message as {@link IASTProblem#getMessageWithoutLocation()}. * Returns the same message as {@link IASTProblem#getMessageWithoutLocation()}.
*/ */
public static String getProblemMessage(int problemID, String detail) { public static String getProblemMessage(int problemID, String detail) {
return ASTProblem.getMessageWithoutLocation(problemID, detail); return ASTProblem.getMessage(problemID, detail);
} }
} }

View file

@ -11,419 +11,10 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
import org.eclipse.cdt.internal.core.parser.ParserMessages; import org.eclipse.cdt.core.parser.IProblem;
/** /**
* @author jcamelon * Interface for problems in the ast tree.
*
* Description of a C/C++ parse/compilation problem, as detected by the parser
* or some of the underlying clients of the parser.
*
* A problem provides access to:
* <ul>
* <li> its location (originating source file name, source position, line
* number), </li>
* <li> its message description and a predicate to check its severity (warning
* or error). </li>
* <li> its ID : an number identifying the very nature of this problem. All
* possible IDs are listed as constants on this interface. </li>
* </ul>
*/ */
public interface IASTProblem extends IASTNode { public interface IASTProblem extends IProblem, IASTNode {
/**
* Returns the problem id
*
* @return the problem id
*/
int getID();
/**
* Answer a localized, human-readable message string which describes the
* problem including its location
*
* @return a localized, human-readable message string which describes the
* problem
*/
String getMessage();
/**
* Returns a human-readable message string describing the problem, without
* location information.
*/
String getMessageWithoutLocation();
/**
* Return to the client a map between parameter names and values.
*
* The keys and values are all Strings.
*
*
* @return a map between parameter names and values.
*/
String getArguments();
/**
* Checks the severity to see if the Error bit is set.
*
* @return true if the Error bit is set for the severity, false otherwise
*/
boolean isError();
/**
* Checks the severity to see if the Warning bit is not set.
*
* @return true if the Warning bit is not set for the severity, false
* otherwise
*/
boolean isWarning();
/**
* Unknown Numeric Value for line numbers and offsets; use this constant
*/
public final static int INT_VALUE_NOT_PROVIDED = -1;
/**
* Unknown filename sentinel value
*/
public final static String FILENAME_NOT_PROVIDED = ParserMessages
.getString("IProblem.unknownFileName"); //$NON-NLS-1$
/**
* Problem Categories The high bits of a problem ID contains information
* about the category of a problem. For example, (problemID & TypeRelated) !=
* 0, indicates that this problem is type related.
*
* A problem category can help to implement custom problem filters. Indeed,
* when numerous problems are listed, focusing on import related problems
* first might be relevant.
*
* When a problem is tagged as Internal, it means that no change other than
* a local source code change can fix the corresponding problem.
*/
/**
* IProblem relates to a valid error on the Scanner
*/
public final static int SCANNER_RELATED = 0x01000000;
/**
* IProblem relates to a valid error on the preprocessor
*/
public final static int PREPROCESSOR_RELATED = 0x02000000;
/**
* IProblem relates to a valid syntax error in the parser
*/
public final static int SYNTAX_RELATED = 0x04000000;
/**
* IProblem relates to a valid semantical error in the parser
*/
public final static int SEMANTICS_RELATED = 0x08000000;
/**
* IProblem relates to an implementation of design limitation
*/
public final static int INTERNAL_RELATED = 0x10000000;
/**
* Check the parameter bitmask against an IProblem's ID to broadly segregate
* the types of problems.
*
* @param bitmask
* @return true if ( (id & bitmask ) != 0 )
*/
public boolean checkCategory(int bitmask);
/**
* Mask to use in order to filter out the category portion of the problem
* ID.
*/
public final static int IGNORE_CATEGORIES_MASK = 0xFFFFFF;
/**
* Below are listed all available problem attributes. The JavaDoc for each
* problem ID indicates when they should be contributed to creating a
* problem of that type.
*/
// Preprocessor IProblem attributes
/**
* The text that follows a #error preprocessor directive
*/
public final static String A_PREPROC_POUND_ERROR = ParserMessages
.getString("IProblem.preproc.poundError"); //$NON-NLS-1$
/**
* The text that follows a #warning preprocessor directive
*/
public final static String A_PREPROC_POUND_WARNING = ParserMessages
.getString("IProblem.preproc.poundWarning"); //$NON-NLS-1$
/**
* The filename that failed somehow in an preprocessor include directive
*/
public final static String A_PREPROC_INCLUDE_FILENAME = ParserMessages
.getString("IProblem.preproc.include"); //$NON-NLS-1$
/**
* A preprocessor macro name
*/
public final static String A_PREPROC_MACRO_NAME = ParserMessages
.getString("IProblem.preproc.macro"); //$NON-NLS-1$
/**
* A preprocessor conditional that could not be evaluated
*
* #if X + Y == Z <== that one, if X, Y or Z are not defined #endif
*/
public final static String A_PREPROC_CONDITION = ParserMessages
.getString("IProblem.preproc.condition"); //$NON-NLS-1$
/**
* A preprocessor directive that could not be interpretted
*
* e.g. #blah
*/
public final static String A_PREPROC_UNKNOWN_DIRECTIVE = ParserMessages
.getString("IProblem.preproc.unknownDirective"); //$NON-NLS-1$
/**
* The preprocessor conditional statement that caused an unbalanced
* mismatch.
*
* #if X #else #else <=== that one #endif
*/
public final static String A_PREPROC_CONDITIONAL_MISMATCH = ParserMessages
.getString("IProblem.preproc.conditionalMismatch"); //$NON-NLS-1$
/**
* The Bad character encountered in scanner
*/
public static final String A_SCANNER_BADCHAR = null;
/**
* A_SYMBOL_NAME - symbol name
*/
public static final String A_SYMBOL_NAME = ParserMessages
.getString("IProblem.symbolName"); //$NON-NLS-1$
/**
* A_NAMESPACE_NAME = namespace name
*/
public static final String A_NAMESPACE_NAME = ParserMessages
.getString("IProblem.namespaceName"); //$NON-NLS-1$
/**
* A_TYPE_NAME - type name
*/
public static final String A_TYPE_NAME = ParserMessages
.getString("IProblem.typeName"); //$NON-NLS-1$
/**
* Below are listed all available problem IDs. Note that this list could be
* augmented in the future, as new features are added to the C/C++ core
* implementation.
*/
/*
* Scanner Problems
*/
/**
* Bad character encountered by Scanner. Required attributes:
* A_SCANNER_BADCHAR
*
* @see #A_SCANNER_BADCHAR
*/
public final static int SCANNER_BAD_CHARACTER = SCANNER_RELATED | 0x001;
/**
* Unbounded literal string encountered by Scanner. Required attributes:
* none.
*/
public final static int SCANNER_UNBOUNDED_STRING = SCANNER_RELATED | 0x002;
/**
* Invalid escape sequence encountered by Scanner. Required attributes:
* none.
*/
public final static int SCANNER_INVALID_ESCAPECHAR = SCANNER_RELATED | 0x003;
/**
* Bad floating point encountered by Scanner. Required attributes: none.
*/
public final static int SCANNER_BAD_FLOATING_POINT = SCANNER_RELATED | 0x004;
/**
* Bad hexidecimal encountered by Scanner. Required attributes: none.
*/
public final static int SCANNER_BAD_HEX_FORMAT = SCANNER_RELATED | 0x005;
/**
* Unexpected EOF encountered by Scanner. Required attributes: none.
*/
public final static int SCANNER_UNEXPECTED_EOF = SCANNER_RELATED | 0x006;
/**
* Bad octal encountered by Scanner. Required attributes: none.
*/
public final static int SCANNER_BAD_OCTAL_FORMAT = SCANNER_RELATED | 0x007;
/**
* Bad decimal encountered by Scanner. Required attributes: none.
*/
public final static int SCANNER_BAD_DECIMAL_FORMAT = SCANNER_RELATED | 0x008;
/**
* Assignment '=' encountered in macro by Scanner. Required attributes:
* none.
*/
public final static int SCANNER_ASSIGNMENT_NOT_ALLOWED = SCANNER_RELATED | 0x009;
/**
* Division by 0 encountered in macro by Scanner. Required attributes: none.
*/
public final static int SCANNER_DIVIDE_BY_ZERO = SCANNER_RELATED | 0x00A;
/**
* Missing ')' encountered in macro by Scanner. Required attributes: none.
*/
public final static int SCANNER_MISSING_R_PAREN = SCANNER_RELATED | 0x00B;
/**
* Expression syntax error encountered in macro by Scanner. Required
* attributes: none.
*/
public final static int SCANNER_EXPRESSION_SYNTAX_ERROR = SCANNER_RELATED | 0x00C;
/**
* Expression syntax error encountered in macro by Scanner. Required
* attributes: none.
*/
public final static int SCANNER_ILLEGAL_IDENTIFIER = SCANNER_RELATED | 0x00D;
/**
* Division by 0 encountered in macro by Scanner. Required attributes: none.
*/
public final static int SCANNER_BAD_CONDITIONAL_EXPRESSION = SCANNER_RELATED | 0x00E;
/*
* Preprocessor Problems
*/
/**
* #error encountered by Preprocessor. Required attributes:
* A_PREPROC_POUND_ERROR
*
* @see #A_PREPROC_POUND_ERROR
*/
public final static int PREPROCESSOR_POUND_ERROR = PREPROCESSOR_RELATED | 0x001;
/**
* Inclusion not found by Preprocessor. Required attributes:
* A_PREPROC_INCLUDE_FILENAME
*
* @see #A_PREPROC_INCLUDE_FILENAME
*/
public final static int PREPROCESSOR_INCLUSION_NOT_FOUND = PREPROCESSOR_RELATED | 0x002;
/**
* Macro definition not found by Preprocessor. Required attributes:
* A_PREPROC_MACRO_NAME
*
* @see #A_PREPROC_MACRO_NAME
*/
public final static int PREPROCESSOR_DEFINITION_NOT_FOUND = PREPROCESSOR_RELATED | 0x003;
/**
* Preprocessor conditionals seem unbalanced. Required attributes:
* A_PREPROC_CONDITIONAL_MISMATCH
*
* @see #A_PREPROC_CONDITIONAL_MISMATCH
*/
public final static int PREPROCESSOR_UNBALANCE_CONDITION = PREPROCESSOR_RELATED | 0x004;
/**
* Invalid format to Macro definition. Required attributes:
* A_PREPROC_MACRO_NAME
*
* @see #A_PREPROC_MACRO_NAME
*/
public final static int PREPROCESSOR_INVALID_MACRO_DEFN = PREPROCESSOR_RELATED | 0x005;
/**
* Invalid or unknown preprocessor directive encountered by Preprocessor.
* Required attributes: A_PREPROC_UNKNOWN_DIRECTIVE
*
* @see #A_PREPROC_UNKNOWN_DIRECTIVE
*/
public final static int PREPROCESSOR_INVALID_DIRECTIVE = PREPROCESSOR_RELATED | 0x006;
/**
* Invalid macro redefinition encountered by Preprocessor. Required
* attributes: A_PREPROC_MACRO_NAME
*
* @see #A_PREPROC_MACRO_NAME
*/
public final static int PREPROCESSOR_INVALID_MACRO_REDEFN = PREPROCESSOR_RELATED | 0x007;
/**
* Preprocessor Conditional cannot not be evaluated due. Required
* attributes: A_PREPROC_CONDITION
*
* @see #A_PREPROC_CONDITION
*/
public final static int PREPROCESSOR_CONDITIONAL_EVAL_ERROR = PREPROCESSOR_RELATED | 0x008;
/**
* Invalid macro usage encountered by Preprocessor. Required attributes:
* A_PREPROC_MACRO_NAME
*
* @see #A_PREPROC_MACRO_NAME
*/
public final static int PREPROCESSOR_MACRO_USAGE_ERROR = PREPROCESSOR_RELATED | 0x009;
/**
* Invalid Macro Pasting encountered by Preprocessor. Required attributes:
* A_PREPROC_MACRO_NAME
*
* @see #A_PREPROC_MACRO_NAME
*/
public final static int PREPROCESSOR_MACRO_PASTING_ERROR = PREPROCESSOR_RELATED | 0x00A;
/**
* Circular inclusion encountered by Preprocessor. Required attributes:
* A_PREPROC_INCLUDE_FILENAME
*
* @see #A_PREPROC_INCLUDE_FILENAME
*/
public final static int PREPROCESSOR_CIRCULAR_INCLUSION = PREPROCESSOR_RELATED | 0x00B;
/**
* macro argument "..." encountered without the required ')' i.e. must be
* last argument if used Required attributes: none
*/
public final static int PREPROCESSOR_MISSING_RPAREN_PARMLIST = PREPROCESSOR_RELATED | 0x00C;
/**
* __VA_ARGS__ encountered in macro definition without the required '...'
* parameter Required attributes: none
*/
public final static int PREPROCESSOR_INVALID_VA_ARGS = PREPROCESSOR_RELATED | 0x00D;
/**
* #warning encountered by Preprocessor. Required attributes:
* A_PREPROC_POUND_WARNING
*
* @see #A_PREPROC_POUND_WARNING
*/
public final static int PREPROCESSOR_POUND_WARNING = PREPROCESSOR_RELATED | 0x00E;
/*
* Parser Syntactic Problems
*/
public final static int SYNTAX_ERROR = SYNTAX_RELATED | 0x001;
} }

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
@ -42,6 +42,12 @@ public interface IProblem
*/ */
String getMessage(); String getMessage();
/**
* Returns a human-readable message string describing the problem, adding
* location information.
*/
String getMessageWithLocation();
/** /**
* Return to the client a map between parameter names and values. * Return to the client a map between parameter names and values.
* *

View file

@ -61,24 +61,16 @@ public class ASTProblem extends ASTNode implements IASTProblem {
return !isError; return !isError;
} }
public String getMessage() { public String getMessageWithLocation() {
String msg= getMessageWithoutLocation(); String msg= getMessage();
IASTFileLocation f = getFileLocation(); char[] file= getOriginatingFileName();
String file = null; int line= getSourceLineNumber();
int line = 0;
if( f == null )
{
file = ""; //$NON-NLS-1$
} else {
file = f.getFileName();
line = f.getStartingLineNumber();
}
Object[] args = new Object[] { msg, file, new Integer(line) }; Object[] args = new Object[] { msg, file, new Integer(line) };
return ParserMessages.getFormattedString(PROBLEM_PATTERN, args); return ParserMessages.getFormattedString(PROBLEM_PATTERN, args);
} }
public static String getMessageWithoutLocation(int id, String arg) { public static String getMessage(int id, String arg) {
String msg = errorMessages.get(new Integer(id)); String msg = errorMessages.get(new Integer(id));
if (msg == null) if (msg == null)
msg = ""; //$NON-NLS-1$ msg = ""; //$NON-NLS-1$
@ -89,81 +81,121 @@ public class ASTProblem extends ASTNode implements IASTProblem {
return msg; return msg;
} }
public String getMessageWithoutLocation() { public String getMessage() {
return getMessageWithoutLocation(id, arg == null ? null : new String(arg)); return getMessage(id, arg == null ? null : new String(arg));
} }
public boolean checkCategory(int bitmask) { public boolean checkCategory(int bitmask) {
return ((id & bitmask) != 0); return ((id & bitmask) != 0);
} }
public String getArguments() { public String[] getArguments() {
return arg != null ? String.valueOf(arg) : ""; //$NON-NLS-1$ return arg == null ? new String[0] : new String[] {new String(arg)};
} }
protected static final Map<Integer, String> errorMessages; protected static final Map<Integer, String> errorMessages;
static { static {
errorMessages = new HashMap<Integer, String>(); errorMessages = new HashMap<Integer, String>();
errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_POUND_ERROR), errorMessages.put(new Integer(PREPROCESSOR_POUND_ERROR),
ParserMessages.getString("ScannerProblemFactory.error.preproc.error")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.preproc.error")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_POUND_WARNING), errorMessages.put(new Integer(PREPROCESSOR_POUND_WARNING),
ParserMessages.getString("ScannerProblemFactory.error.preproc.warning")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.preproc.warning")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_INCLUSION_NOT_FOUND), errorMessages.put(new Integer(PREPROCESSOR_INCLUSION_NOT_FOUND),
ParserMessages.getString("ScannerProblemFactory.error.preproc.inclusionNotFound")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.preproc.inclusionNotFound")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_DEFINITION_NOT_FOUND), errorMessages.put(new Integer(PREPROCESSOR_DEFINITION_NOT_FOUND),
ParserMessages.getString("ScannerProblemFactory.error.preproc.definitionNotFound")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.preproc.definitionNotFound")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_INVALID_MACRO_DEFN), errorMessages.put(new Integer(PREPROCESSOR_INVALID_MACRO_DEFN),
ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroDefn")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroDefn")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_INVALID_MACRO_REDEFN), errorMessages.put(new Integer(PREPROCESSOR_INVALID_MACRO_REDEFN),
ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroRedefn")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroRedefn")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_UNBALANCE_CONDITION), errorMessages.put(new Integer(PREPROCESSOR_UNBALANCE_CONDITION),
ParserMessages.getString("ScannerProblemFactory.error.preproc.unbalancedConditional")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.preproc.unbalancedConditional")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR), errorMessages.put(new Integer(PREPROCESSOR_CONDITIONAL_EVAL_ERROR),
ParserMessages.getString("ScannerProblemFactory.error.preproc.conditionalEval")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.preproc.conditionalEval")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_MACRO_USAGE_ERROR), errorMessages.put(new Integer(PREPROCESSOR_MACRO_USAGE_ERROR),
ParserMessages.getString("ScannerProblemFactory.error.preproc.macroUsage")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.preproc.macroUsage")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_CIRCULAR_INCLUSION), errorMessages.put(new Integer(PREPROCESSOR_CIRCULAR_INCLUSION),
ParserMessages.getString("ScannerProblemFactory.error.preproc.circularInclusion")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.preproc.circularInclusion")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_INVALID_DIRECTIVE), errorMessages.put(new Integer(PREPROCESSOR_INVALID_DIRECTIVE),
ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidDirective")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidDirective")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_MACRO_PASTING_ERROR), errorMessages.put(new Integer(PREPROCESSOR_MACRO_PASTING_ERROR),
ParserMessages.getString("ScannerProblemFactory.error.preproc.macroPasting")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.preproc.macroPasting")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_MISSING_RPAREN_PARMLIST), errorMessages.put(new Integer(PREPROCESSOR_MISSING_RPAREN_PARMLIST),
ParserMessages.getString("ScannerProblemFactory.error.preproc.missingRParen")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.preproc.missingRParen")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_INVALID_VA_ARGS), errorMessages.put(new Integer(PREPROCESSOR_INVALID_VA_ARGS),
ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidVaArgs")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidVaArgs")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.SCANNER_INVALID_ESCAPECHAR), errorMessages.put(new Integer(SCANNER_INVALID_ESCAPECHAR),
ParserMessages.getString("ScannerProblemFactory.error.scanner.invalidEscapeChar")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.scanner.invalidEscapeChar")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.SCANNER_UNBOUNDED_STRING), errorMessages.put(new Integer(SCANNER_UNBOUNDED_STRING),
ParserMessages.getString("ScannerProblemFactory.error.scanner.unboundedString")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.scanner.unboundedString")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.SCANNER_BAD_FLOATING_POINT), errorMessages.put(new Integer(SCANNER_BAD_FLOATING_POINT),
ParserMessages.getString("ScannerProblemFactory.error.scanner.badFloatingPoint")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.scanner.badFloatingPoint")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.SCANNER_BAD_HEX_FORMAT), errorMessages.put(new Integer(SCANNER_BAD_HEX_FORMAT),
ParserMessages.getString("ScannerProblemFactory.error.scanner.badHexFormat")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.scanner.badHexFormat")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.SCANNER_BAD_OCTAL_FORMAT), errorMessages.put(new Integer(SCANNER_BAD_OCTAL_FORMAT),
ParserMessages.getString("ScannerProblemFactory.error.scanner.badOctalFormat")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.scanner.badOctalFormat")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.SCANNER_BAD_DECIMAL_FORMAT), errorMessages.put(new Integer(SCANNER_BAD_DECIMAL_FORMAT),
ParserMessages.getString("ScannerProblemFactory.error.scanner.badDecimalFormat")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.scanner.badDecimalFormat")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.SCANNER_ASSIGNMENT_NOT_ALLOWED), errorMessages.put(new Integer(SCANNER_ASSIGNMENT_NOT_ALLOWED),
ParserMessages.getString("ScannerProblemFactory.error.scanner.assignmentNotAllowed")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.scanner.assignmentNotAllowed")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.SCANNER_DIVIDE_BY_ZERO), errorMessages.put(new Integer(SCANNER_DIVIDE_BY_ZERO),
ParserMessages.getString("ScannerProblemFactory.error.scanner.divideByZero")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.scanner.divideByZero")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.SCANNER_MISSING_R_PAREN), errorMessages.put(new Integer(SCANNER_MISSING_R_PAREN),
ParserMessages.getString("ScannerProblemFactory.error.scanner.missingRParen")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.scanner.missingRParen")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.SCANNER_EXPRESSION_SYNTAX_ERROR), errorMessages.put(new Integer(SCANNER_EXPRESSION_SYNTAX_ERROR),
ParserMessages.getString("ScannerProblemFactory.error.scanner.expressionSyntaxError")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.scanner.expressionSyntaxError")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.SCANNER_ILLEGAL_IDENTIFIER), errorMessages.put(new Integer(SCANNER_ILLEGAL_IDENTIFIER),
ParserMessages.getString("ScannerProblemFactory.error.scanner.illegalIdentifier")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.scanner.illegalIdentifier")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.SCANNER_BAD_CONDITIONAL_EXPRESSION), errorMessages.put(new Integer(SCANNER_BAD_CONDITIONAL_EXPRESSION),
ParserMessages.getString("ScannerProblemFactory.error.scanner.badConditionalExpression")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.scanner.badConditionalExpression")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.SCANNER_UNEXPECTED_EOF), errorMessages.put(new Integer(SCANNER_UNEXPECTED_EOF),
ParserMessages.getString("ScannerProblemFactory.error.scanner.unexpectedEOF")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.scanner.unexpectedEOF")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.SCANNER_BAD_CHARACTER), errorMessages.put(new Integer(SCANNER_BAD_CHARACTER),
ParserMessages.getString("ScannerProblemFactory.error.scanner.badCharacter")); //$NON-NLS-1$ ParserMessages.getString("ScannerProblemFactory.error.scanner.badCharacter")); //$NON-NLS-1$
errorMessages.put(new Integer(IASTProblem.SYNTAX_ERROR), errorMessages.put(new Integer(SYNTAX_ERROR),
ParserMessages.getString("ParserProblemFactory.error.syntax.syntaxError")); //$NON-NLS-1$ ParserMessages.getString("ParserProblemFactory.error.syntax.syntaxError")); //$NON-NLS-1$
} }
protected final static String PROBLEM_PATTERN = "BaseProblemFactory.problemPattern"; //$NON-NLS-1$ protected final static String PROBLEM_PATTERN = "BaseProblemFactory.problemPattern"; //$NON-NLS-1$
/*
* @see org.eclipse.cdt.core.parser.IProblem#getOriginatingFileName()
*/
public char[] getOriginatingFileName() {
return getContainingFilename().toCharArray();
}
/*
* @see org.eclipse.cdt.core.parser.IProblem#getSourceEnd()
*/
public int getSourceEnd() {
final IASTFileLocation location= getFileLocation();
if (location != null) {
return location.getNodeOffset() + location.getNodeLength() - 1;
}
return -1;
}
/*
* @see org.eclipse.cdt.core.parser.IProblem#getSourceLineNumber()
*/
public int getSourceLineNumber() {
final IASTFileLocation location= getFileLocation();
if (location != null) {
return location.getStartingLineNumber();
}
return -1;
}
/*
* @see org.eclipse.cdt.core.parser.IProblem#getSourceStart()
*/
public int getSourceStart() {
final IASTFileLocation location= getFileLocation();
if (location != null) {
return location.getNodeOffset();
}
return -1;
}
} }

View file

@ -67,6 +67,7 @@ import org.eclipse.cdt.core.parser.AbstractParserLogService;
import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.IGCCToken; import org.eclipse.cdt.core.parser.IGCCToken;
import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.OffsetLimitReachedException; import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
@ -343,7 +344,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
IASTProblem result = null; IASTProblem result = null;
if (bt.getProblem() == null) if (bt.getProblem() == null)
result = createProblem(IASTProblem.SYNTAX_ERROR, bt.getOffset(), bt result = createProblem(IProblem.SYNTAX_ERROR, bt.getOffset(), bt
.getLength()); .getLength());
else else
result = bt.getProblem(); result = bt.getProblem();
@ -383,7 +384,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
} }
} }
public String toString() { @Override
public String toString() {
return scanner.toString(); return scanner.toString();
} }

View file

@ -101,6 +101,7 @@ import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.IGCCToken; import org.eclipse.cdt.core.parser.IGCCToken;
import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ParserMode;
@ -2451,7 +2452,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
} }
private IASTProblemDeclaration createKnRCProblemDeclaration(int length, int offset) throws EndOfFileException { private IASTProblemDeclaration createKnRCProblemDeclaration(int length, int offset) throws EndOfFileException {
IASTProblem p = createProblem(IASTProblem.SYNTAX_ERROR, offset, length); IASTProblem p = createProblem(IProblem.SYNTAX_ERROR, offset, length);
IASTProblemDeclaration pd = createProblemDeclaration(); IASTProblemDeclaration pd = createProblemDeclaration();
pd.setProblem(p); pd.setProblem(p);
((ASTNode) pd).setOffsetAndLength(((ASTNode) p).getOffset(), ((ASTNode) p).getLength()); ((ASTNode) pd).setOffsetAndLength(((ASTNode) p).getOffset(), ((ASTNode) p).getLength());

View file

@ -134,6 +134,7 @@ import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.IGCCToken; import org.eclipse.cdt.core.parser.IGCCToken;
import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ITokenDuple;
@ -3721,7 +3722,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (typeId != null) { if (typeId != null) {
exceptionSpecIds.add(typeId); exceptionSpecIds.add(typeId);
} else { } else {
IASTProblem p = createProblem(IASTProblem.SYNTAX_ERROR, IASTProblem p = createProblem(IProblem.SYNTAX_ERROR,
before.getOffset(), before.getLength()); before.getOffset(), before.getLength());
IASTProblemTypeId typeIdProblem = createTypeIDProblem(); IASTProblemTypeId typeIdProblem = createTypeIDProblem();
typeIdProblem.setProblem(p); typeIdProblem.setProblem(p);

View file

@ -1,34 +0,0 @@
/*******************************************************************************
* Copyright (c) 2002, 2006 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.parser.problem;
import org.eclipse.cdt.core.parser.IProblem;
/**
* @author jcamelon
*/
public abstract class BaseProblemFactory {
protected final static String PROBLEM_PATTERN = "BaseProblemFactory.problemPattern"; //$NON-NLS-1$
public IProblem createProblem(int id, int start, int end, int line, char[] file, String[] arg,
boolean warn, boolean error) {
return new Problem( id, start, end, line, file, arg, warn, error);
}
public boolean checkBitmask(int id, int bitmask) {
return (id & bitmask) != 0;
}
protected IProblem createInternalProblem( int id, int start, int end, int line, char[] file, String[] arg,
boolean warn, boolean error) {
return createProblem(id, start, end, line, file, arg, warn, error);
}
}

View file

@ -1,232 +0,0 @@
/*******************************************************************************
* Copyright (c) 2002, 2007 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.parser.problem;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.internal.core.parser.ParserMessages;
/**
* @author jcamelon
*/
public class Problem implements IProblem {
private final String[] arg;
private final int id;
private final int sourceStart;
private final int sourceEnd;
private final int lineNumber;
private final boolean isError;
private final boolean isWarning;
private final char[] originatingFileName;
private String message = null;
public Problem(int id, int start, int end, int line, char[] file, String[] arg,
boolean warn, boolean error) {
this.id = id;
this.sourceStart = start;
this.sourceEnd = end;
this.lineNumber = line;
this.originatingFileName = file;
this.arg = arg;
this.isWarning = warn;
this.isError = error;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IProblem#getID()
*/
public int getID() {
return id;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IProblem#getOriginatingFileName()
*/
public char[] getOriginatingFileName() {
return originatingFileName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IProblem#getSourceEnd()
*/
public int getSourceEnd() {
return sourceEnd;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IProblem#getSourceLineNumber()
*/
public int getSourceLineNumber() {
return lineNumber;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IProblem#getSourceStart()
*/
public int getSourceStart() {
return sourceStart;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IProblem#isError()
*/
public boolean isError() {
return isError;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IProblem#isWarning()
*/
public boolean isWarning() {
return isWarning;
}
protected static final Map<Integer, String> errorMessages;
static {
errorMessages = new HashMap<Integer, String>();
errorMessages.put(IProblem.SEMANTIC_UNIQUE_NAME_PREDEFINED,
ParserMessages.getString("ASTProblemFactory.error.semantic.uniqueNamePredefined")); //$NON-NLS-1$
errorMessages.put(IProblem.SEMANTIC_NAME_NOT_FOUND,
ParserMessages.getString("ASTProblemFactory.error.semantic.nameNotFound")); //$NON-NLS-1$
errorMessages.put(IProblem.SEMANTIC_NAME_NOT_PROVIDED,
ParserMessages.getString("ASTProblemFactory.error.semantic.nameNotProvided")); //$NON-NLS-1$
errorMessages.put(IProblem.SEMANTIC_INVALID_CONVERSION_TYPE ,
ParserMessages.getString("ASTProblemFactory.error.semantic.invalidConversionType")); //$NON-NLS-1$
errorMessages.put(IProblem.SEMANTIC_MALFORMED_EXPRESSION ,
ParserMessages.getString("ASTProblemFactory.error.semantic.malformedExpression")); //$NON-NLS-1$
errorMessages.put(IProblem.SEMANTIC_AMBIGUOUS_LOOKUP ,
ParserMessages.getString("ASTProblemFactory.error.semantic.pst.ambiguousLookup")); //$NON-NLS-1$
errorMessages.put(IProblem.SEMANTIC_INVALID_TYPE ,
ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidType")); //$NON-NLS-1$
errorMessages.put(IProblem.SEMANTIC_CIRCULAR_INHERITANCE ,
ParserMessages.getString("ASTProblemFactory.error.semantic.pst.circularInheritance")); //$NON-NLS-1$
errorMessages.put(IProblem.SEMANTIC_INVALID_OVERLOAD ,
ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidOverload")); //$NON-NLS-1$
errorMessages.put(IProblem.SEMANTIC_INVALID_TEMPLATE ,
ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidTemplate")); //$NON-NLS-1$
errorMessages.put(IProblem.SEMANTIC_INVALID_USING ,
ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidUsing")); //$NON-NLS-1$
errorMessages.put(IProblem.SEMANTIC_BAD_VISIBILITY ,
ParserMessages.getString("ASTProblemFactory.error.semantic.pst.badVisibility")); //$NON-NLS-1$
errorMessages.put(IProblem.SEMANTIC_UNABLE_TO_RESOLVE_FUNCTION ,
ParserMessages.getString("ASTProblemFactory.error.semantic.pst.unableToResolveFunction")); //$NON-NLS-1$
errorMessages.put(IProblem.SEMANTIC_INVALID_TEMPLATE_ARGUMENT ,
ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidTemplateArgument")); //$NON-NLS-1$
errorMessages.put(IProblem.SEMANTIC_INVALID_TEMPLATE_PARAMETER ,
ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidTemplateParameter")); //$NON-NLS-1$
errorMessages.put(IProblem.SEMANTIC_REDECLARED_TEMPLATE_PARAMETER ,
ParserMessages.getString("ASTProblemFactory.error.semantic.pst.redeclaredTemplateParameter")); //$NON-NLS-1$
errorMessages.put(IProblem.SEMANTIC_RECURSIVE_TEMPLATE_INSTANTIATION ,
ParserMessages.getString("ASTProblemFactory.error.semantic.pst.recursiveTemplateInstantiation")); //$NON-NLS-1$
errorMessages.put(IProblem.PREPROCESSOR_POUND_ERROR,
ParserMessages.getString("ScannerProblemFactory.error.preproc.error")); //$NON-NLS-1$
errorMessages.put(IProblem.PREPROCESSOR_POUND_WARNING,
ParserMessages.getString("ScannerProblemFactory.error.preproc.warning")); //$NON-NLS-1$
errorMessages.put(IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND,
ParserMessages.getString("ScannerProblemFactory.error.preproc.inclusionNotFound")); //$NON-NLS-1$
errorMessages.put(IProblem.PREPROCESSOR_DEFINITION_NOT_FOUND,
ParserMessages.getString("ScannerProblemFactory.error.preproc.definitionNotFound")); //$NON-NLS-1$
errorMessages.put(IProblem.PREPROCESSOR_INVALID_MACRO_DEFN,
ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroDefn")); //$NON-NLS-1$
errorMessages.put(IProblem.PREPROCESSOR_INVALID_MACRO_REDEFN,
ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroRedefn")); //$NON-NLS-1$
errorMessages.put(IProblem.PREPROCESSOR_UNBALANCE_CONDITION,
ParserMessages.getString("ScannerProblemFactory.error.preproc.unbalancedConditional")); //$NON-NLS-1$
errorMessages.put(IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR,
ParserMessages.getString("ScannerProblemFactory.error.preproc.conditionalEval")); //$NON-NLS-1$
errorMessages.put(IProblem.PREPROCESSOR_MACRO_USAGE_ERROR,
ParserMessages.getString("ScannerProblemFactory.error.preproc.macroUsage")); //$NON-NLS-1$
errorMessages.put(IProblem.PREPROCESSOR_CIRCULAR_INCLUSION,
ParserMessages.getString("ScannerProblemFactory.error.preproc.circularInclusion")); //$NON-NLS-1$
errorMessages.put(IProblem.PREPROCESSOR_INVALID_DIRECTIVE,
ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidDirective")); //$NON-NLS-1$
errorMessages.put(IProblem.PREPROCESSOR_MACRO_PASTING_ERROR,
ParserMessages.getString("ScannerProblemFactory.error.preproc.macroPasting")); //$NON-NLS-1$
errorMessages.put(IProblem.PREPROCESSOR_MISSING_RPAREN_PARMLIST,
ParserMessages.getString("ScannerProblemFactory.error.preproc.missingRParen")); //$NON-NLS-1$
errorMessages.put(IProblem.PREPROCESSOR_INVALID_VA_ARGS,
ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidVaArgs")); //$NON-NLS-1$
errorMessages.put(IProblem.SCANNER_INVALID_ESCAPECHAR,
ParserMessages.getString("ScannerProblemFactory.error.scanner.invalidEscapeChar")); //$NON-NLS-1$
errorMessages.put(IProblem.SCANNER_UNBOUNDED_STRING,
ParserMessages.getString("ScannerProblemFactory.error.scanner.unboundedString")); //$NON-NLS-1$
errorMessages.put(IProblem.SCANNER_BAD_FLOATING_POINT,
ParserMessages.getString("ScannerProblemFactory.error.scanner.badFloatingPoint")); //$NON-NLS-1$
errorMessages.put(IProblem.SCANNER_BAD_HEX_FORMAT,
ParserMessages.getString("ScannerProblemFactory.error.scanner.badHexFormat")); //$NON-NLS-1$
errorMessages.put(IProblem.SCANNER_BAD_OCTAL_FORMAT,
ParserMessages.getString("ScannerProblemFactory.error.scanner.badOctalFormat")); //$NON-NLS-1$
errorMessages.put(IProblem.SCANNER_BAD_DECIMAL_FORMAT,
ParserMessages.getString("ScannerProblemFactory.error.scanner.badDecimalFormat")); //$NON-NLS-1$
errorMessages.put(IProblem.SCANNER_ASSIGNMENT_NOT_ALLOWED,
ParserMessages.getString("ScannerProblemFactory.error.scanner.assignmentNotAllowed")); //$NON-NLS-1$
errorMessages.put(IProblem.SCANNER_DIVIDE_BY_ZERO,
ParserMessages.getString("ScannerProblemFactory.error.scanner.divideByZero")); //$NON-NLS-1$
errorMessages.put(IProblem.SCANNER_MISSING_R_PAREN,
ParserMessages.getString("ScannerProblemFactory.error.scanner.missingRParen")); //$NON-NLS-1$
errorMessages.put(IProblem.SCANNER_EXPRESSION_SYNTAX_ERROR,
ParserMessages.getString("ScannerProblemFactory.error.scanner.expressionSyntaxError")); //$NON-NLS-1$
errorMessages.put(IProblem.SCANNER_ILLEGAL_IDENTIFIER,
ParserMessages.getString("ScannerProblemFactory.error.scanner.illegalIdentifier")); //$NON-NLS-1$
errorMessages.put(IProblem.SCANNER_BAD_CONDITIONAL_EXPRESSION,
ParserMessages.getString("ScannerProblemFactory.error.scanner.badConditionalExpression")); //$NON-NLS-1$
errorMessages.put(IProblem.SCANNER_UNEXPECTED_EOF,
ParserMessages.getString("ScannerProblemFactory.error.scanner.unexpectedEOF")); //$NON-NLS-1$
errorMessages.put(IProblem.SCANNER_BAD_CHARACTER,
ParserMessages.getString("ScannerProblemFactory.error.scanner.badCharacter")); //$NON-NLS-1$
errorMessages.put(IProblem.SYNTAX_ERROR,
ParserMessages.getString("ParserProblemFactory.error.syntax.syntaxError")); //$NON-NLS-1$
}
protected final static String PROBLEM_PATTERN = "BaseProblemFactory.problemPattern"; //$NON-NLS-1$
public String getMessage() {
if (message != null)
return message;
String msg = errorMessages.get(id);
if (msg == null)
msg = ""; //$NON-NLS-1$
if (arg != null) {
msg = MessageFormat.format(msg, (Object[]) arg);
}
String[] args = null;
if (originatingFileName != null) {
args = new String[] { msg, new String(originatingFileName), String.valueOf(lineNumber) };
} else {
args = new String[] { msg, "", String.valueOf(lineNumber) }; //$NON-NLS-1$
}
message = ParserMessages.getFormattedString(PROBLEM_PATTERN, args);
return message;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IProblem#checkCategory(int)
*/
public boolean checkCategory(int bitmask) {
return (id & bitmask) != 0;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IProblem#getArguments()
*/
public String[] getArguments() {
return arg;
}
}

View file

@ -1,81 +0,0 @@
/*******************************************************************************
* Copyright (c) 2002, 2007 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.internal.core.parser.problem.BaseProblemFactory;
import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory;
/**
* @author jcamelon
*
*/
public class ScannerProblemFactory extends BaseProblemFactory implements IProblemFactory
{
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IProblemFactory#createProblem(int, int, int, int, char[], java.lang.String, boolean, boolean)
*/
public IProblem createProblem(int id, int start, int end, int line, char[] file, String[] arg,
boolean warn, boolean error) {
if (checkBitmask(id, IProblem.INTERNAL_RELATED))
return createInternalProblem(id, start, end, line, file, arg, warn, error);
if (checkBitmask(id, IProblem.SCANNER_RELATED) ||
checkBitmask(id, IProblem.PREPROCESSOR_RELATED)) {
return super.createProblem(id, start, end, line, file, arg, warn, error);
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IProblemFactory#getRequiredAttributesForId(int)
*/
public String getRequiredAttributesForId(int id)
{
switch (id)
{
case IProblem.PREPROCESSOR_POUND_ERROR :
return IProblem.A_PREPROC_POUND_ERROR;
case IProblem.PREPROCESSOR_POUND_WARNING :
return IProblem.A_PREPROC_POUND_WARNING;
case IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND :
return IProblem.A_PREPROC_INCLUDE_FILENAME;
case IProblem.PREPROCESSOR_DEFINITION_NOT_FOUND :
return IProblem.A_PREPROC_MACRO_NAME;
case IProblem.PREPROCESSOR_UNBALANCE_CONDITION :
return IProblem.A_PREPROC_CONDITIONAL_MISMATCH;
case IProblem.PREPROCESSOR_INVALID_MACRO_DEFN :
return IProblem.A_PREPROC_MACRO_NAME;
case IProblem.PREPROCESSOR_INVALID_DIRECTIVE :
return IProblem.A_PREPROC_UNKNOWN_DIRECTIVE;
case IProblem.PREPROCESSOR_INVALID_MACRO_REDEFN :
return IProblem.A_PREPROC_MACRO_NAME;
case IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR :
return IProblem.A_PREPROC_CONDITION;
case IProblem.PREPROCESSOR_MACRO_USAGE_ERROR :
return IProblem.A_PREPROC_MACRO_NAME;
case IProblem.PREPROCESSOR_MACRO_PASTING_ERROR :
return IProblem.A_PREPROC_MACRO_NAME;
case IProblem.PREPROCESSOR_CIRCULAR_INCLUSION :
return IProblem.A_PREPROC_INCLUDE_FILENAME;
case IProblem.SCANNER_BAD_CHARACTER :
return IProblem.A_SCANNER_BADCHAR;
case IProblem.SCANNER_UNBOUNDED_STRING :
case IProblem.SCANNER_INVALID_ESCAPECHAR :
case IProblem.SCANNER_BAD_FLOATING_POINT :
case IProblem.SCANNER_BAD_HEX_FORMAT :
case IProblem.SCANNER_UNEXPECTED_EOF :
break;
}
return null;
}
}

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
@ -22,7 +22,7 @@ public class TraceUtil {
if( log.isTracing() ) { if( log.isTracing() ) {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
if( preface != null ) buffer.append( preface ); if( preface != null ) buffer.append( preface );
if( problem != null ) buffer.append( problem.getMessage()); if( problem != null ) buffer.append( problem.getMessageWithLocation());
if( first != null ) buffer.append( first ); if( first != null ) buffer.append( first );
if( second != null ) buffer.append( second ); if( second != null ) buffer.append( second );
if( third != null ) buffer.append( third ); if( third != null ) buffer.append( third );
@ -33,7 +33,7 @@ public class TraceUtil {
if( log.isTracing() ) { if( log.isTracing() ) {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
if( preface != null ) buffer.append( preface ); if( preface != null ) buffer.append( preface );
if( problem != null ) buffer.append( problem.getMessage()); if( problem != null ) buffer.append( problem.getMessageWithLocation());
log.traceLog( buffer.toString() ); log.traceLog( buffer.toString() );
} }
} }
@ -41,7 +41,7 @@ public class TraceUtil {
if( log.isTracing() ) { if( log.isTracing() ) {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
if( preface != null ) buffer.append( preface ); if( preface != null ) buffer.append( preface );
if( problem != null ) buffer.append( problem.getMessage()); if( problem != null ) buffer.append( problem.getMessageWithLocation());
if( first != null ) buffer.append( first ); if( first != null ) buffer.append( first );
if( second != null ) buffer.append( second ); if( second != null ) buffer.append( second );
if( third != null ) buffer.append( third ); if( third != null ) buffer.append( third );

View file

@ -42,6 +42,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile; import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IWritableIndex; import org.eclipse.cdt.internal.core.index.IWritableIndex;
@ -343,7 +344,7 @@ abstract public class PDOMWriter {
final boolean reportAll= fShowScannerProblems && fShowInclusionProblems; final boolean reportAll= fShowScannerProblems && fShowInclusionProblems;
IASTProblem[] scannerProblems= ast.getPreprocessorProblems(); IASTProblem[] scannerProblems= ast.getPreprocessorProblems();
for (IASTProblem problem : scannerProblems) { for (IASTProblem problem : scannerProblems) {
if (reportAll || (problem.getID() == IASTProblem.PREPROCESSOR_INCLUSION_NOT_FOUND) == fShowInclusionProblems) { if (reportAll || (problem.getID() == IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND) == fShowInclusionProblems) {
reportProblem(problem); reportProblem(problem);
} }
} }
@ -492,7 +493,7 @@ abstract public class PDOMWriter {
} }
private void reportProblem(IASTProblem problem) { private void reportProblem(IASTProblem problem) {
String msg= "Indexer: " + problem.getMessage(); //$NON-NLS-1$ String msg= "Indexer: " + problem.getMessageWithLocation(); //$NON-NLS-1$
System.out.println(msg); System.out.println(msg);
} }

View file

@ -147,7 +147,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
private static class ASTProblemException extends RuntimeException { private static class ASTProblemException extends RuntimeException {
ASTProblemException(IASTProblem problem) { ASTProblemException(IASTProblem problem) {
super(problem.getMessage()); super(problem.getMessageWithLocation());
} }
} }
@ -197,6 +197,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
public CodeFormatterVisitor(DefaultCodeFormatterOptions preferences, Map<String, String> settings, int offset, int length) { public CodeFormatterVisitor(DefaultCodeFormatterOptions preferences, Map<String, String> settings, int offset, int length) {
localScanner = new Scanner() { localScanner = new Scanner() {
@Override
public Token nextToken() { public Token nextToken() {
Token t= super.nextToken(); Token t= super.nextToken();
while (t != null && (t.isWhiteSpace() || t.isPreprocessor())) { while (t != null && (t.isWhiteSpace() || t.isPreprocessor())) {
@ -274,6 +275,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
/* /*
* @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit) * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)
*/ */
@Override
public int visit(IASTTranslationUnit tu) { public int visit(IASTTranslationUnit tu) {
// fake new line // fake new line
scribe.lastNumberOfNewLines = 1; scribe.lastNumberOfNewLines = 1;
@ -310,6 +312,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
/* /*
* @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTDeclaration) * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
*/ */
@Override
public int visit(IASTDeclaration node) { public int visit(IASTDeclaration node) {
startNode(node); startNode(node);
int indentLevel= scribe.indentationLevel; int indentLevel= scribe.indentationLevel;
@ -364,6 +367,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
/* /*
* @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTName) * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTName)
*/ */
@Override
public int visit(IASTName node) { public int visit(IASTName node) {
startNode(node); startNode(node);
try { try {
@ -383,6 +387,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
/* /*
* @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTInitializer) * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTInitializer)
*/ */
@Override
public int visit(IASTInitializer node) { public int visit(IASTInitializer node) {
if (node instanceof ICPPASTConstructorInitializer) { if (node instanceof ICPPASTConstructorInitializer) {
visit((ICPPASTConstructorInitializer)node); visit((ICPPASTConstructorInitializer)node);
@ -416,6 +421,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
/* /*
* @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration) * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration)
*/ */
@Override
public int visit(IASTParameterDeclaration parameterDeclaration) { public int visit(IASTParameterDeclaration parameterDeclaration) {
formatNode(parameterDeclaration); formatNode(parameterDeclaration);
endOfNode(parameterDeclaration); endOfNode(parameterDeclaration);
@ -425,6 +431,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
/* /*
* @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTDeclarator) * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
*/ */
@Override
public int visit(IASTDeclarator node) { public int visit(IASTDeclarator node) {
startNode(node); startNode(node);
@ -472,6 +479,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
/* /*
* @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)
*/ */
@Override
public int visit(IASTDeclSpecifier node) { public int visit(IASTDeclSpecifier node) {
startNode(node); startNode(node);
try { try {
@ -501,6 +509,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
/* /*
* @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTExpression) * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTExpression)
*/ */
@Override
public int visit(IASTExpression node) { public int visit(IASTExpression node) {
// scribe.printComment(); // scribe.printComment();
startNode(node); startNode(node);
@ -539,6 +548,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
/* /*
* @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTStatement) * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTStatement)
*/ */
@Override
public int visit(IASTStatement node) { public int visit(IASTStatement node) {
// scribe.printComment(); // scribe.printComment();
startNode(node); startNode(node);
@ -607,6 +617,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
/* /*
* @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTTypeId) * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTTypeId)
*/ */
@Override
public int visit(IASTTypeId node) { public int visit(IASTTypeId node) {
startNode(node); startNode(node);
try { try {
@ -630,6 +641,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
/* /*
* @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator)
*/ */
@Override
public int visit(IASTEnumerator enumerator) { public int visit(IASTEnumerator enumerator) {
formatNode(enumerator); formatNode(enumerator);
endOfNode(enumerator); endOfNode(enumerator);
@ -639,6 +651,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
/* /*
* @see org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor#visit(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier) * @see org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor#visit(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier)
*/ */
@Override
public int visit(ICPPASTBaseSpecifier specifier) { public int visit(ICPPASTBaseSpecifier specifier) {
formatNode(specifier); formatNode(specifier);
endOfNode(specifier); endOfNode(specifier);
@ -648,6 +661,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
/* /*
* @see org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor#visit(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition) * @see org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor#visit(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition)
*/ */
@Override
public int visit(ICPPASTNamespaceDefinition node) { public int visit(ICPPASTNamespaceDefinition node) {
scribe.printComment(); scribe.printComment();
startNode(node); startNode(node);
@ -721,6 +735,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
/* /*
* @see org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor#visit(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter) * @see org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor#visit(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter)
*/ */
@Override
public int visit(ICPPASTTemplateParameter node) { public int visit(ICPPASTTemplateParameter node) {
startNode(node); startNode(node);
try { try {

View file

@ -1,12 +1,12 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2006 IBM Corporation and others. * Copyright (c) 2005, 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
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.tests.DOMAST; package org.eclipse.cdt.ui.tests.DOMAST;
@ -112,7 +112,7 @@ public class DOMASTNodeLeaf implements IAdaptable {
} }
public String toString() { public String toString() {
if( node == null ) return BLANK_STRING; //$NON-NLS-1$ if( node == null ) return BLANK_STRING;
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
Class[] classes = node.getClass().getInterfaces(); Class[] classes = node.getClass().getInterfaces();
@ -132,7 +132,7 @@ public class DOMASTNodeLeaf implements IAdaptable {
if ( node instanceof IASTProblemHolder ) { if ( node instanceof IASTProblemHolder ) {
buffer.append(START_OF_LIST); buffer.append(START_OF_LIST);
buffer.append(((IASTProblemHolder)node).getProblem().getMessage()); buffer.append(((IASTProblemHolder)node).getProblem().getMessageWithLocation());
} else if ( node instanceof IASTSimpleDeclaration ) { } else if ( node instanceof IASTSimpleDeclaration ) {
String name = null; String name = null;
IASTDeclarator[] decltors = ((IASTSimpleDeclaration)node).getDeclarators(); IASTDeclarator[] decltors = ((IASTSimpleDeclaration)node).getDeclarators();
@ -287,21 +287,21 @@ public class DOMASTNodeLeaf implements IAdaptable {
if ( node == null ) return BLANK_STRING; if ( node == null ) return BLANK_STRING;
IASTFileLocation f = node.getFileLocation(); IASTFileLocation f = node.getFileLocation();
if( f == null ) if( f == null )
return BLANK_STRING; //$NON-NLS-1$ return BLANK_STRING;
return f.getFileName(); return f.getFileName();
} }
public int getOffset() { public int getOffset() {
IASTFileLocation f = node.getFileLocation(); IASTFileLocation f = node.getFileLocation();
if( f == null ) if( f == null )
return 0; //$NON-NLS-1$ return 0;
return f.getNodeOffset(); return f.getNodeOffset();
} }
public int getLength() { public int getLength() {
IASTFileLocation f = node.getFileLocation(); IASTFileLocation f = node.getFileLocation();
if( f == null ) if( f == null )
return 0; //$NON-NLS-1$ return 0;
return f.getNodeLength(); return f.getNodeLength();
} }

View file

@ -307,7 +307,7 @@ public class CreateParserLogAction implements IObjectActionDelegate {
private void output(PrintStream out, String indent, IASTProblem[] preprocessorProblems) { private void output(PrintStream out, String indent, IASTProblem[] preprocessorProblems) {
for (IASTProblem problem : preprocessorProblems) { for (IASTProblem problem : preprocessorProblems) {
out.println(indent + problem.getMessage()); out.println(indent + problem.getMessageWithLocation());
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2006 IBM Corporation and others. * Copyright (c) 2005, 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
@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.ui.text.spelling;
import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.IRegion;
import org.eclipse.osgi.util.NLS;
import org.eclipse.cdt.core.parser.IPersistableProblem; import org.eclipse.cdt.core.parser.IPersistableProblem;
@ -109,6 +110,14 @@ public class CoreSpellingProblem implements IPersistableProblem {
return fMessage; return fMessage;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IProblem#getMessageWithLocation()
*/
public String getMessageWithLocation() {
return NLS.bind(Messages.Spelling_msgWithLocation, new Object[] {fMessage, fOrigin, fLineNumber});
}
/* /*
* @see org.eclipse.cdt.core.parser.IProblem#getOriginatingFileName() * @see org.eclipse.cdt.core.parser.IProblem#getOriginatingFileName()
*/ */

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007 IBM Corporation and others. * Copyright (c) 2007, 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
@ -32,6 +32,8 @@ public class Messages extends NLS {
public static String Spelling_ignore_info; public static String Spelling_ignore_info;
public static String Spelling_ignore_label; public static String Spelling_ignore_label;
public static String Spelling_msgWithLocation;
static { static {
// Initialize resource bundle // Initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class); NLS.initializeMessages(BUNDLE_NAME, Messages.class);

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
@ -24,3 +24,4 @@ Spelling_error_case_label= The word ''{0}'' should have an initial upper case le
Spelling_error_label=The word ''{0}'' is not correctly spelled Spelling_error_label=The word ''{0}'' is not correctly spelled
Spelling_ignore_info=Ignores ''{0}'' during the current session Spelling_ignore_info=Ignores ''{0}'' during the current session
Spelling_ignore_label=Ignore ''{0}'' during the current session Spelling_ignore_label=Ignore ''{0}'' during the current session
Spelling_msgWithLocation={0} in file: {1}:{2}