use of org.codehaus.groovy.ast.ModuleNode in project groovy by apache.
the class GenericsUtils method resolveClassNode.
private static ClassNode resolveClassNode(final SourceUnit sourceUnit, final CompilationUnit compilationUnit, final MethodNode mn, final ASTNode usage, final ClassNode parsedNode) {
ClassNode dummyClass = new ClassNode("dummy", 0, ClassHelper.OBJECT_TYPE);
dummyClass.setModule(new ModuleNode(sourceUnit));
dummyClass.setGenericsTypes(mn.getDeclaringClass().getGenericsTypes());
MethodNode dummyMN = new MethodNode("dummy", 0, parsedNode, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, EmptyStatement.INSTANCE);
dummyMN.setGenericsTypes(mn.getGenericsTypes());
dummyClass.addMethod(dummyMN);
ResolveVisitor visitor = new ResolveVisitor(compilationUnit) {
@Override
public void addError(final String msg, final ASTNode expr) {
sourceUnit.addError(new IncorrectTypeHintException(mn, msg, usage.getLineNumber(), usage.getColumnNumber()));
}
};
visitor.startResolving(dummyClass, sourceUnit);
return dummyMN.getReturnType();
}
use of org.codehaus.groovy.ast.ModuleNode in project intellij-community by JetBrains.
the class GroovyCompilerWrapper method addErrorMessage.
private void addErrorMessage(GroovyRuntimeException exception) {
ASTNode astNode = exception.getNode();
ModuleNode module = exception.getModule();
if (module == null) {
module = findModule(astNode);
}
String moduleName = module == null ? "<no module>" : module.getDescription();
int lineNumber = astNode == null ? -1 : astNode.getLineNumber();
int columnNumber = astNode == null ? -1 : astNode.getColumnNumber();
collector.add(new CompilerMessage(GroovyCompilerMessageCategories.ERROR, getExceptionMessage(exception), moduleName, lineNumber, columnNumber));
}
use of org.codehaus.groovy.ast.ModuleNode in project gradle by gradle.
the class GradleResolveVisitor method visitClass.
public void visitClass(ClassNode node) {
ClassNode oldNode = currentClass;
if (node instanceof InnerClassNode) {
if (Modifier.isStatic(node.getModifiers())) {
genericParameterNames = new HashMap<String, GenericsType>();
}
} else {
genericParameterNames = new HashMap<String, GenericsType>();
}
currentClass = node;
resolveGenericsHeader(node.getGenericsTypes());
ModuleNode module = node.getModule();
if (!module.hasImportsResolved()) {
for (ImportNode importNode : module.getImports()) {
currImportNode = importNode;
ClassNode type = importNode.getType();
if (resolve(type, false, false, true)) {
currImportNode = null;
continue;
}
currImportNode = null;
addError("unable to resolve class " + type.getName(), type);
}
for (ImportNode importNode : module.getStaticStarImports().values()) {
ClassNode type = importNode.getType();
if (resolve(type, false, false, true)) {
continue;
}
// Try with the node's package too. If still not found, revert to original type name.
if (type.getPackageName() == null && node.getPackageName() != null) {
String oldTypeName = type.getName();
type.setName(node.getPackageName() + "." + oldTypeName);
if (resolve(type, false, false, true)) {
continue;
}
type.setName(oldTypeName);
}
addError("unable to resolve class " + type.getName(), type);
}
for (ImportNode importNode : module.getStaticImports().values()) {
ClassNode type = importNode.getType();
if (resolve(type, true, true, true)) {
continue;
}
addError("unable to resolve class " + type.getName(), type);
}
for (ImportNode importNode : module.getStaticStarImports().values()) {
ClassNode type = importNode.getType();
if (resolve(type, true, true, true)) {
continue;
}
addError("unable to resolve class " + type.getName(), type);
}
module.setImportsResolved(true);
}
ClassNode sn = node.getUnresolvedSuperClass();
if (sn != null) {
resolveOrFail(sn, node, true);
}
for (ClassNode anInterface : node.getInterfaces()) {
resolveOrFail(anInterface, node, true);
}
checkCyclicInheritence(node, node.getUnresolvedSuperClass(), node.getInterfaces());
super.visitClass(node);
currentClass = oldNode;
}
use of org.codehaus.groovy.ast.ModuleNode in project groovy-core by groovy.
the class GenericsUtils method resolveClassNode.
private static ClassNode resolveClassNode(final SourceUnit sourceUnit, final CompilationUnit compilationUnit, final MethodNode mn, final ASTNode usage, final ClassNode parsedNode) {
ClassNode dummyClass = new ClassNode("dummy", 0, ClassHelper.OBJECT_TYPE);
dummyClass.setModule(new ModuleNode(sourceUnit));
dummyClass.setGenericsTypes(mn.getDeclaringClass().getGenericsTypes());
MethodNode dummyMN = new MethodNode("dummy", 0, parsedNode, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, EmptyStatement.INSTANCE);
dummyMN.setGenericsTypes(mn.getGenericsTypes());
dummyClass.addMethod(dummyMN);
ResolveVisitor visitor = new ResolveVisitor(compilationUnit) {
@Override
protected void addError(final String msg, final ASTNode expr) {
sourceUnit.addError(new IncorrectTypeHintException(mn, msg, usage.getLineNumber(), usage.getColumnNumber()));
}
};
visitor.startResolving(dummyClass, sourceUnit);
return dummyMN.getReturnType();
}
use of org.codehaus.groovy.ast.ModuleNode in project groovy-core by groovy.
the class AsmClassGenerator method addInnerClass.
public boolean addInnerClass(ClassNode innerClass) {
ModuleNode mn = controller.getClassNode().getModule();
innerClass.setModule(mn);
mn.getUnit().addGeneratedInnerClass((InnerClassNode) innerClass);
return innerClasses.add(innerClass);
}
Aggregations