use of org.codehaus.groovy.syntax.SyntaxException in project groovy by apache.
the class TraitComposer method createException.
private static SyntaxException createException(ClassNode trait, ClassNode targetNode, MethodNode forwarder, MethodNode existingMethod) {
String middle;
ASTNode errorTarget;
if (existingMethod.getLineNumber() == -1) {
// came from a trait
errorTarget = targetNode;
List<AnnotationNode> allAnnos = existingMethod.getAnnotations(Traits.TRAITBRIDGE_CLASSNODE);
AnnotationNode bridgeAnno = allAnnos == null ? null : allAnnos.get(0);
String fromTrait = null;
if (bridgeAnno != null) {
Expression traitClass = bridgeAnno.getMember("traitClass");
if (traitClass instanceof ClassExpression) {
ClassExpression ce = (ClassExpression) traitClass;
fromTrait = ce.getType().getNameWithoutPackage();
}
}
middle = "in '" + targetNode.getNameWithoutPackage();
if (fromTrait != null) {
middle += "' from trait '" + fromTrait;
}
} else {
errorTarget = existingMethod;
middle = "declared in '" + targetNode.getNameWithoutPackage();
}
String message = "The static '" + forwarder.getName() + "' method " + middle + "' conflicts with the instance method having the same signature from trait '" + trait.getNameWithoutPackage() + "'";
return new SyntaxException(message, errorTarget);
}
use of org.codehaus.groovy.syntax.SyntaxException in project groovy by apache.
the class NAryOperationRewriter method transformPrefixExpression.
private Expression transformPrefixExpression(final PrefixExpression exp) {
if (isInternalFieldAccess(exp.getExpression())) {
Token operation = exp.getOperation();
sourceUnit.addError(new SyntaxException("Prefix expressions on trait fields/properties are not supported in traits.", operation.getStartLine(), operation.getStartColumn()));
return exp;
} else {
return super.transform(exp);
}
}
use of org.codehaus.groovy.syntax.SyntaxException in project groovy by apache.
the class ProcessingContextInformation method addError.
public void addError(String msg, ASTNode expr) {
int line = expr.getLineNumber();
int col = expr.getColumnNumber();
SourceUnit source = sourceUnit();
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(new SyntaxException(msg + '\n', line, col), source));
}
use of org.codehaus.groovy.syntax.SyntaxException in project groovy by apache.
the class SyntaxErrorMessageTest method testSetsTheSourceLocatorOfItsSyntaxExceptionAsTheNameOfTheCorrespondingSourceUnitWhenInstantiated.
public void testSetsTheSourceLocatorOfItsSyntaxExceptionAsTheNameOfTheCorrespondingSourceUnitWhenInstantiated() {
SyntaxException syntaxException = new SyntaxException(someString(), -1, -1);
assertEquals("source locator", null, syntaxException.getSourceLocator());
String sourceUnitName = someString();
SourceUnit sourceUnit = SourceUnit.create(sourceUnitName, someString());
new SyntaxErrorMessage(syntaxException, sourceUnit);
assertEquals("source locator", sourceUnitName, syntaxException.getSourceLocator());
}
use of org.codehaus.groovy.syntax.SyntaxException in project groovy-cps by cloudbees.
the class CpsTransformer method visitBinaryExpression.
/**
* @see
* org.codehaus.groovy.classgen.asm.BinaryExpressionHelper#eval(BinaryExpression)
*/
@Override
public void visitBinaryExpression(final BinaryExpression exp) {
String name = BINARY_OP_TO_BUILDER_METHOD.get(exp.getOperation().getType());
if (name != null) {
if (name.equals("assign") && exp.getLeftExpression() instanceof TupleExpression) {
multipleAssignment(exp, (TupleExpression) exp.getLeftExpression(), exp.getRightExpression());
} else {
makeNode(name, new Runnable() {
@Override
public void run() {
loc(exp);
visit(exp.getLeftExpression());
visit(exp.getRightExpression());
}
});
}
return;
}
sourceUnit.addError(new SyntaxException("Unsupported operation in this context", exp.getLineNumber(), exp.getColumnNumber()));
}
Aggregations