use of org.codehaus.groovy.control.ErrorCollector in project groovy-core by groovy.
the class StaticTypeCheckingVisitor method silentlyVisitMethodNode.
/**
* visit a method call target, to infer the type. Don't report errors right
* away, that will be done by a later visitMethod call
*/
protected void silentlyVisitMethodNode(final MethodNode directMethodCallCandidate) {
// visit is authorized because the classnode belongs to the same source unit
ErrorCollector collector = new ErrorCollector(typeCheckingContext.getErrorCollector().getConfiguration());
startMethodInference(directMethodCallCandidate, collector);
}
use of org.codehaus.groovy.control.ErrorCollector in project groovy-core by groovy.
the class StaticTypeCheckingVisitor method visitMethod.
@Override
public void visitMethod(final MethodNode node) {
if (shouldSkipMethodNode(node)) {
// method has already been visited by a static type checking visitor
return;
}
if (!extension.beforeVisitMethod(node)) {
ErrorCollector collector = (ErrorCollector) node.getNodeMetaData(ERROR_COLLECTOR);
if (collector != null) {
typeCheckingContext.getErrorCollector().addCollectorContents(collector);
} else {
startMethodInference(node, typeCheckingContext.getErrorCollector());
}
node.removeNodeMetaData(ERROR_COLLECTOR);
}
extension.afterVisitMethod(node);
}
use of org.codehaus.groovy.control.ErrorCollector in project groovy-core by groovy.
the class ExtendedVerifier method visitConstructorOrMethod.
private void visitConstructorOrMethod(MethodNode node, int methodTarget) {
visitAnnotations(node, methodTarget);
for (int i = 0; i < node.getParameters().length; i++) {
Parameter parameter = node.getParameters()[i];
visitAnnotations(parameter, AnnotationNode.PARAMETER_TARGET);
}
if (this.currentClass.isAnnotationDefinition() && !node.isStaticConstructor()) {
ErrorCollector errorCollector = new ErrorCollector(this.source.getConfiguration());
AnnotationVisitor visitor = new AnnotationVisitor(this.source, errorCollector);
visitor.setReportClass(currentClass);
visitor.checkReturnType(node.getReturnType(), node);
if (node.getParameters().length > 0) {
addError("Annotation members may not have parameters.", node.getParameters()[0]);
}
if (node.getExceptions().length > 0) {
addError("Annotation members may not have a throws clause.", node.getExceptions()[0]);
}
ReturnStatement code = (ReturnStatement) node.getCode();
if (code != null) {
visitor.visitExpression(node.getName(), code.getExpression(), node.getReturnType());
visitor.checkCircularReference(currentClass, node.getReturnType(), code.getExpression());
}
this.source.getErrorCollector().addCollectorContents(errorCollector);
}
Statement code = node.getCode();
if (code != null) {
code.visit(this);
}
}
use of org.codehaus.groovy.control.ErrorCollector in project groovy-core by groovy.
the class ProxyGeneratorAdapter method adjustSuperClass.
private Class adjustSuperClass(Class superClass, final Class[] interfaces) {
boolean isSuperClassAnInterface = superClass.isInterface();
if (!isSuperClassAnInterface) {
return superClass;
}
Class result = Object.class;
Set<ClassNode> traits = new LinkedHashSet<ClassNode>();
// check if it's a trait
collectTraits(superClass, traits);
if (interfaces != null) {
for (Class anInterface : interfaces) {
collectTraits(anInterface, traits);
}
}
if (!traits.isEmpty()) {
String name = superClass.getName() + "$TraitAdapter";
ClassNode cn = new ClassNode(name, ACC_PUBLIC | ACC_ABSTRACT, ClassHelper.OBJECT_TYPE, traits.toArray(new ClassNode[traits.size()]), null);
CompilationUnit cu = new CompilationUnit(loader);
CompilerConfiguration config = new CompilerConfiguration();
SourceUnit su = new SourceUnit(name + "wrapper", "", config, loader, new ErrorCollector(config));
cu.addSource(su);
cu.compile(Phases.CONVERSION);
su.getAST().addClass(cn);
cu.compile(Phases.CLASS_GENERATION);
@SuppressWarnings("unchecked") List<GroovyClass> classes = (List<GroovyClass>) cu.getClasses();
for (GroovyClass groovyClass : classes) {
if (groovyClass.getName().equals(name)) {
return loader.defineClass(name, groovyClass.getBytes());
}
}
}
return result;
}
Aggregations