/** * Returns true if the two classes share the same compilation unit. * @param a class a * @param b class b * @return true if both classes share the same compilation unit */ public static boolean isSameCompilationUnit(ClassNode a, ClassNode b) { CompileUnit cu1 = a.getCompileUnit(); CompileUnit cu2 = b.getCompileUnit(); return cu1 !=null && cu2 !=null && cu1==cu2; }
public static boolean isBeingCompiled(ClassNode node) { return node.getCompileUnit() != null; }
/** * Creates a ClassNode from a real class. The resulting * ClassNode will not be a primary ClassNode. */ public ClassNode(Class c) { this(c.getName(), c.getModifiers(), null, null ,MixinNode.EMPTY_ARRAY); clazz=c; lazyInitDone=false; CompileUnit cu = getCompileUnit(); if (cu!=null) cu.addClass(this); isPrimaryNode=false; }
protected CompileUnit getCompileUnit() { CompileUnit answer = classNode.getCompileUnit(); if (answer == null) { answer = context.getCompileUnit(); } return answer; }
protected CompileUnit getCompileUnit() { CompileUnit answer = controller.getClassNode().getCompileUnit(); if (answer == null) { answer = context.getCompileUnit(); } return answer; }
public CompileUnit getCompileUnit() { if (redirect!=null) return redirect().getCompileUnit(); if (compileUnit == null && module != null) { compileUnit = module.getUnit(); } return compileUnit; }
private boolean resolveFromCompileUnit(ClassNode type) { // look into the compile unit if there is a class with that name CompileUnit compileUnit = currentClass.getCompileUnit(); if (compileUnit == null) return false; ClassNode cuClass = compileUnit.getClass(type.getName()); if (cuClass != null) { if (type != cuClass) type.setRedirect(cuClass); return true; } return false; }
public void call(SourceUnit source) throws CompilationFailedException { List<ClassNode> classes = source.ast.getClasses(); for (ClassNode node : classes) { CompileUnit cu = node.getCompileUnit(); for (Iterator iter = cu.iterateClassNodeToCompile(); iter.hasNext();) { String name = (String) iter.next();
private boolean resolveToOuter(ClassNode type) { String name = type.getName(); // We do not need to check instances of LowerCaseClass // to be a Class, because unless there was an import for // for this we do not lookup these cases. This was a decision // made on the mailing list. To ensure we will not visit this // method again we set a NO_CLASS for this name if (type instanceof LowerCaseClass) { classNodeResolver.cacheClass(name, ClassNodeResolver.NO_CLASS); return false; } if (currentClass.getModule().hasPackageName() && name.indexOf('.') == -1) return false; LookupResult lr = classNodeResolver.resolveName(name, compilationUnit); if (lr != null) { if (lr.isSourceUnit()) { SourceUnit su = lr.getSourceUnit(); currentClass.getCompileUnit().addClassNodeToCompile(type, su); } else { type.setRedirect(lr.getClassNode()); } return true; } return false; }
public void init(AsmClassGenerator asmClassGenerator, GeneratorContext gcon, ClassVisitor cv, ClassNode cn) { CompilerConfiguration config = cn.getCompileUnit().getConfig(); Map<String,Boolean> optOptions = config.getOptimizationOptions(); boolean invokedynamic=false;
@Override public void init(final AsmClassGenerator asmClassGenerator, final GeneratorContext gcon, final ClassVisitor cv, final ClassNode cn) { super.init(asmClassGenerator, gcon, cv, cn); this.callSiteWriter = new StaticTypesCallSiteWriter(this); this.statementWriter = new StaticTypesStatementWriter(this); this.typeChooser = new StaticTypesTypeChooser(); this.invocationWriter = new StaticInvocationWriter(this); this.closureWriter = new StaticTypesClosureWriter(this); this.unaryExpressionHelper = new StaticTypesUnaryExpressionHelper(this); CompilerConfiguration config = cn.getCompileUnit().getConfig(); this.binaryExprHelper = config.isIndyEnabled() ? new IndyStaticTypesMultiTypeDispatcher(this) : new StaticTypesBinaryExpressionMultiTypeDispatcher(this); }
public boolean implementsInterfaceOrIsSubclassOf(ClassNode type, ClassNode superOrInterface) { boolean result = type.equals(superOrInterface) || type.isDerivedFrom(superOrInterface) || type.implementsInterface(superOrInterface); if (result) { return true; } if (GROOVY_OBJECT_TYPE.equals(superOrInterface) && type.getCompileUnit()!=null) { // type is being compiled so it will implement GroovyObject later return true; } if (superOrInterface instanceof WideningCategories.LowestUpperBoundClassNode) { WideningCategories.LowestUpperBoundClassNode cn = (WideningCategories.LowestUpperBoundClassNode) superOrInterface; result = implementsInterfaceOrIsSubclassOf(type, cn.getSuperClass()); if (result) { for (ClassNode interfaceNode : cn.getInterfaces()) { result = implementsInterfaceOrIsSubclassOf(type,interfaceNode); if (!result) break; } } if (result) return true; } if (type.isArray() && superOrInterface.isArray()) { return implementsInterfaceOrIsSubclassOf(type.getComponentType(), superOrInterface.getComponentType()); } return false; }
/** * Creates a ClassNode from a real class. The resulting * ClassNode will be no primary ClassNode. */ public ClassNode(Class c) { this(c.getName(), c.getModifiers(), null, null ,MixinNode.EMPTY_ARRAY); clazz=c; lazyInitDone=false; CompileUnit cu = getCompileUnit(); if (cu!=null) cu.addClass(this); isPrimaryNode=false; }
protected CompileUnit getCompileUnit() { CompileUnit answer = classNode.getCompileUnit(); if (answer == null) { answer = context.getCompileUnit(); } return answer; }
/** * Creates a ClassNode from a real class. The resulting * ClassNode will not be a primary ClassNode. */ public ClassNode(Class c) { this(c.getName(), c.getModifiers(), null, null ,MixinNode.EMPTY_ARRAY); clazz=c; lazyInitDone=false; CompileUnit cu = getCompileUnit(); if (cu!=null) cu.addClass(this); isPrimaryNode=false; }
protected CompileUnit getCompileUnit() { CompileUnit answer = classNode.getCompileUnit(); if (answer == null) { answer = context.getCompileUnit(); } return answer; }
public CompileUnit getCompileUnit() { if (redirect!=null) return redirect().getCompileUnit(); if (compileUnit == null && module != null) { compileUnit = module.getUnit(); } return compileUnit; }
public CompileUnit getCompileUnit() { if (redirect!=null) return redirect().getCompileUnit(); if (compileUnit == null && module != null) { compileUnit = module.getUnit(); } return compileUnit; }
public CompileUnit getCompileUnit() { if (redirect!=null) return redirect().getCompileUnit(); if (compileUnit == null && module != null) { compileUnit = module.getUnit(); } return compileUnit; }
protected CompileUnit getCompileUnit() { CompileUnit answer = controller.getClassNode().getCompileUnit(); if (answer == null) { answer = context.getCompileUnit(); } return answer; }