use of org.codehaus.groovy.control.ErrorCollector in project groovy-core by groovy.
the class TypeCheckingContext method pushErrorCollector.
public ErrorCollector pushErrorCollector() {
ErrorCollector current = getErrorCollector();
ErrorCollector collector = new ErrorCollector(current.getConfiguration());
errorCollectors.add(0, collector);
return collector;
}
use of org.codehaus.groovy.control.ErrorCollector in project groovy by apache.
the class StaticTypeCheckingVisitor method silentlyVisitMethodNode.
/**
* Visits 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 by apache.
the class StaticTypeCheckingVisitor method visitMethod.
@Override
public void visitMethod(final MethodNode node) {
if (shouldSkipMethodNode(node)) {
return;
}
if (!extension.beforeVisitMethod(node)) {
ErrorCollector collector = 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 by apache.
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;
}
use of org.codehaus.groovy.control.ErrorCollector in project hale by halestudio.
the class GroovyScriptPage method addGroovyErrorAnnotation.
/**
* Add an error annotation to the given annotation model based on an
* exception that occurred while compiling or executing the Groovy Script.
*
* @param annotationModel the annotation model
* @param document the current document
* @param script the executed script, or <code>null</code>
* @param exception the occurred exception
*/
public static void addGroovyErrorAnnotation(IAnnotationModel annotationModel, IDocument document, Script script, Exception exception) {
// handle multiple groovy compilation errors
if (exception instanceof MultipleCompilationErrorsException) {
ErrorCollector errors = ((MultipleCompilationErrorsException) exception).getErrorCollector();
for (int i = 0; i < errors.getErrorCount(); i++) {
SyntaxException ex = errors.getSyntaxError(i);
if (ex != null) {
addGroovyErrorAnnotation(annotationModel, document, script, ex);
}
}
return;
}
Annotation annotation = new Annotation(SimpleAnnotations.TYPE_ERROR, false, exception.getLocalizedMessage());
Position position = null;
// single syntax exception
if (exception instanceof SyntaxException) {
int line = ((SyntaxException) exception).getStartLine() - 1;
if (line >= 0) {
try {
position = new Position(document.getLineOffset(line));
} catch (BadLocationException e1) {
log.warn("Wrong error position in document", e1);
}
}
}
// try to determine position from stack trace of script execution
if (position == null && script != null) {
for (StackTraceElement ste : exception.getStackTrace()) {
if (ste.getClassName().startsWith(script.getClass().getName())) {
int line = ste.getLineNumber() - 1;
if (line >= 0) {
try {
position = new Position(document.getLineOffset(line));
break;
} catch (BadLocationException e1) {
log.warn("Wrong error position in document", e1);
}
}
}
}
}
// fallback
if (position == null) {
position = new Position(0);
}
annotationModel.addAnnotation(annotation, position);
}
Aggregations