use of org.codehaus.groovy.ast.ASTNode 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.ast.ASTNode in project micronaut-core by micronaut-projects.
the class GroovyVisitorContext method info.
@Override
public void info(String message, @Nullable Element element) {
StringBuilder msg = new StringBuilder("Note: ").append(message);
if (element != null) {
ASTNode expr = (ASTNode) element.getNativeType();
final String sample = sourceUnit.getSample(expr.getLineNumber(), expr.getColumnNumber(), new Janitor());
msg.append("\n\n").append(sample);
}
System.out.println(msg);
}
use of org.codehaus.groovy.ast.ASTNode in project micronaut-core by micronaut-projects.
the class GroovyVisitorContext method warn.
@Override
public void warn(String message, @Nullable Element element) {
StringBuilder msg = new StringBuilder("WARNING: ").append(message);
if (element != null) {
ASTNode expr = (ASTNode) element.getNativeType();
final String sample = sourceUnit.getSample(expr.getLineNumber(), expr.getColumnNumber(), new Janitor());
msg.append("\n\n").append(sample);
}
System.out.println(msg);
}
Aggregations