mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 10:46:02 +02:00
basic file & offsets for CASTProblems
This commit is contained in:
parent
6fa14f6b94
commit
da848cc63b
4 changed files with 27 additions and 4 deletions
|
@ -117,7 +117,7 @@ public class AST2BaseTest extends TestCase {
|
|||
|
||||
IASTTranslationUnit tu = parser2.parse();
|
||||
|
||||
if( parser2.encounteredError() )
|
||||
if( parser2.encounteredError() && expectNoProblems )
|
||||
throw new ParserException( "FAILURE"); //$NON-NLS-1$
|
||||
|
||||
if( lang == ParserLanguage.C && expectNoProblems )
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
|
@ -2591,4 +2592,12 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals( refs.length, 1 );
|
||||
assertSame( refs[0].resolveBinding(), a );
|
||||
}
|
||||
|
||||
public void testProblems() throws Exception {
|
||||
|
||||
IASTTranslationUnit tu = parse( " a += ;", ParserLanguage.C, true, false ); //$NON-NLS-1$
|
||||
IASTProblem [] ps = CVisitor.getProblems( tu );
|
||||
assertEquals( ps.length, 1 );
|
||||
ps[0].getMessage();
|
||||
}
|
||||
}
|
|
@ -15,7 +15,9 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserMessages;
|
||||
|
@ -253,7 +255,7 @@ public class CASTProblem extends CASTNode implements IASTProblem {
|
|||
.getString("ParserProblemFactory.error.syntax.syntaxError")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
protected final static String PROBLEM_PATTERN = "BaseProblemFactory.problemPattern"; //$NON-NLS-1$
|
||||
protected final static String AST_PROBLEM_PATTERN = "BaseProblemFactory.astProblemPattern"; //$NON-NLS-1$
|
||||
|
||||
public String getMessage() {
|
||||
if (message != null)
|
||||
|
@ -267,8 +269,19 @@ public class CASTProblem extends CASTNode implements IASTProblem {
|
|||
msg = MessageFormat.format(msg, new Object[] { new String(arg) });
|
||||
}
|
||||
|
||||
Object[] args = new Object[] { msg, new String(""), new Integer(0) }; //$NON-NLS-1$
|
||||
message = ParserMessages.getFormattedString(PROBLEM_PATTERN, args);
|
||||
IASTNodeLocation [] locs = getNodeLocations();
|
||||
String file = null;
|
||||
int offset = 0;
|
||||
if( locs != null && locs.length > 0 ){
|
||||
file = ((IASTFileLocation) locs[0]).getFileName();
|
||||
offset = locs[0].getNodeOffset();
|
||||
} else {
|
||||
file = ""; //$NON-NLS-1$
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
Object[] args = new Object[] { msg, file, new Integer( offset ) }; //$NON-NLS-1$
|
||||
message = ParserMessages.getFormattedString(AST_PROBLEM_PATTERN, args);
|
||||
return message;
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ ASTProblemFactory.error.semantic.malformedExpression=Malformed expression
|
|||
LineOffsetReconciler.error.couldNotResetReader=Could not reset Reader
|
||||
|
||||
BaseProblemFactory.problemPattern={0} in file: {1} on line: {2, number, integer}.
|
||||
BaseProblemFactory.astProblemPattern={0} in file: {1} at offset: {2, number, integer}.
|
||||
|
||||
ASTProblemFactory.error.semantic.pst.ambiguousLookup=Ambiguity encountered during lookup: {0}
|
||||
ASTProblemFactory.error.semantic.pst.invalidType=Invalid type encountered in: {0}
|
||||
|
|
Loading…
Add table
Reference in a new issue