@Override protected SourceUnit getSourceUnit() { return cNode.getModule().getContext(); }
private String getPath(Class clazz, Map<String, String> precompiledEntries) { CompilationUnit cu = getLocalData().get().cu; String name = clazz.getName(); ClassNode classNode = cu.getClassNode(name); if (classNode == null) { // this is a precompiled class! String path = precompiledEntries.get(name); if (path == null) throw new GroovyBugError("Precompiled class " + name + " should be available in precompiled entries map, but was not."); return path; } else { return classNode.getModule().getContext().getName(); } }
public static void markAsGenerated(ClassNode containingClass, AnnotatedNode nodeToMark) { boolean shouldAnnotate = containingClass.getModule() != null && containingClass.getModule().getContext() != null; if (shouldAnnotate && !hasAnnotation(nodeToMark, GENERATED_TYPE)) { nodeToMark.addAnnotation(new AnnotationNode(GENERATED_TYPE)); } }
/** * Loads the given class node returning the implementation Class. * <p> * WARNING: this compilation is not synchronized * * @param classNode * @return a class */ public Class defineClass(ClassNode classNode, String file, String newCodeBase) { CodeSource codeSource = null; try { codeSource = new CodeSource(new URL("file", "", newCodeBase), (java.security.cert.Certificate[]) null); } catch (MalformedURLException e) { //swallow } CompilationUnit unit = createCompilationUnit(config, codeSource); ClassCollector collector = createCollector(unit, classNode.getModule().getContext()); try { unit.addClassNode(classNode); unit.setClassgenCallback(collector); unit.compile(Phases.CLASS_GENERATION); definePackageInternal(collector.generatedClass.getName()); return collector.generatedClass; } catch (CompilationFailedException e) { throw new RuntimeException(e); } }
private void addSpecMetadata(Spec spec) { AnnotationNode ann = new AnnotationNode(nodeCache.SpecMetadata); String pathname = spec.getAst().getModule().getContext().getName(); String filename = new File(pathname).getName(); ann.setMember(SpecMetadata.FILENAME, new ConstantExpression(filename)); ann.setMember(SpecMetadata.LINE, new ConstantExpression(spec.getAst().getLineNumber())); spec.getAst().addAnnotation(ann); }
protected Class createClass(byte[] code, ClassNode classNode) { BytecodeProcessor bytecodePostprocessor = unit.getConfiguration().getBytecodePostprocessor(); byte[] fcode = code; if (bytecodePostprocessor!=null) { fcode = bytecodePostprocessor.processBytecode(classNode.getName(), fcode); } GroovyClassLoader cl = getDefiningClassLoader(); Class theClass = cl.defineClass(classNode.getName(), fcode, 0, fcode.length, unit.getAST().getCodeSource()); this.loadedClasses.add(theClass); if (generatedClass == null) { ModuleNode mn = classNode.getModule(); SourceUnit msu = null; if (mn != null) msu = mn.getContext(); ClassNode main = null; if (mn != null) main = (ClassNode) mn.getClasses().get(0); if (msu == su && main == classNode) generatedClass = theClass; } return theClass; }
SourceUnit nodeSource = node.getModule().getContext(); SourceUnit storedSource = stored.getModule().getContext(); String txt = "Invalid duplicate class definition of class " + node.getName() + " : "; if (nodeSource == storedSource) {
SourceUnit context = null; try { context = classNode.getModule().getContext(); if (context == null || context.phase < phase || (context.phase == phase && !context.phaseComplete)) { int offset = 1;
FieldNode metaClassField = getMetaClassField(node); boolean shouldAnnotate = classNode.getModule().getContext() != null; AnnotationNode generatedAnnotation = shouldAnnotate ? new AnnotationNode(ClassHelper.make(GENERATED_ANNOTATION)) : null; AnnotationNode internalAnnotation = shouldAnnotate ? new AnnotationNode(ClassHelper.make(INTERNAL_ANNOTATION)) : null;
@Override protected SourceUnit getSourceUnit() { return moduleNode.getContext(); }
@Override protected SourceUnit getSourceUnit() { return root.getContext(); }
private String getPath(Class clazz, Map<String,String> precompiledEntries) { CompilationUnit cu = getLocalData().get().cu; String name = clazz.getName(); ClassNode classNode = cu.getClassNode(name); if (classNode == null) { // this is a precompiled class! String path = precompiledEntries.get(name); if (path == null) throw new GroovyBugError("Precompiled class "+name+" should be available in precompiled entries map, but was not."); return path; } else { return classNode.getModule().getContext().getName(); } }
private static Set<OffsetRange> markOccurences(AstPath path, BaseDocument document, int cursorOffset) { final Set<OffsetRange> regions = new HashSet<OffsetRange>(); final ASTNode root = path.root(); assert root instanceof ModuleNode; final ModuleNode moduleNode = (ModuleNode) root; VariableScopeVisitor scopeVisitor = new VariableScopeVisitor(moduleNode.getContext(), path, document, cursorOffset); scopeVisitor.collect(); for (ASTNode astNode : scopeVisitor.getOccurrences()) { regions.add(ASTUtils.getRange(astNode, document)); } return regions; } }
protected Class createClass(byte[] code, ClassNode classNode) { GroovyClassLoader cl = getDefiningClassLoader(); Class theClass = cl.defineClass(classNode.getName(), code, 0, code.length, unit.getAST().getCodeSource()); this.loadedClasses.add(theClass); if (generatedClass == null) { ModuleNode mn = classNode.getModule(); SourceUnit msu = null; if (mn != null) msu = mn.getContext(); ClassNode main = null; if (mn != null) main = (ClassNode) mn.getClasses().get(0); if (msu == su && main == classNode) generatedClass = theClass; } return theClass; }
protected Class createClass(byte[] code, ClassNode classNode) { GroovyClassLoader cl = getDefiningClassLoader(); Class theClass = cl.defineClass(classNode.getName(), code, 0, code.length, unit.getAST().getCodeSource()); this.loadedClasses.add(theClass); if (generatedClass == null) { ModuleNode mn = classNode.getModule(); SourceUnit msu = null; if (mn != null) msu = mn.getContext(); ClassNode main = null; if (mn != null) main = (ClassNode) mn.getClasses().get(0); if (msu == su && main == classNode) generatedClass = theClass; } return theClass; }
protected void handleAnnotations(ClassNode classNode, List<AnnotationNode> annotations, ModuleNode moduleNode) { CheckResult checkResult = checkCurrentClass(classNode); if (checkResult.isError()) { addError(checkResult.getMessage(), classNode, moduleNode.getContext()); return; } for (ClassNode type : findTypes(annotations)) { CheckResult implementationResult = isImplementation(classNode, PROPERTY_EDITOR_TYPE); if (implementationResult.isError()) { addError(implementationResult.getMessage(), classNode, moduleNode.getContext()); } else { register(type.getName(), classNode); } } }
@Override protected void initialize(ModuleNode moduleNode) { super.initialize(moduleNode); File outputDir = moduleNode.getContext().getConfiguration().getTargetDirectory(); persistence = new PropertyEditorPersistence(NAME, options.dir(), outputDir, logger); data = new PropertyEditorCollector(persistence.getInitializer(), logger); data.load(); }
@Override protected void initialize(ModuleNode moduleNode) { super.initialize(moduleNode); File outputDir = moduleNode.getContext().getConfiguration().getTargetDirectory(); persistence = new TypePersistence(NAME, options.dir(), outputDir, logger); data = new TypeCollector(persistence.getInitializer(), logger); // Initialize if possible for (String typeName : persistence.tryFind()) { data.getType(typeName); } //data.cache(); }
@Override protected void initialize(ModuleNode moduleNode) { super.initialize(moduleNode); File outputDir = moduleNode.getContext().getConfiguration().getTargetDirectory(); persistence = new ServicePersistence(NAME, options.dir(), outputDir, logger); data = new ServiceCollector(persistence.getInitializer(), logger); // Initialize if possible for (String serviceName : persistence.tryFind()) { data.getService(serviceName); } // data.cache(); }
@Override protected void initialize(ModuleNode moduleNode) { super.initialize(moduleNode); File outputDir = moduleNode.getContext().getConfiguration().getTargetDirectory(); persistence = new ArtifactPersistence(NAME, options.dir(), outputDir, logger); data = new ArtifactCollector(persistence.getInitializer(), logger); // Initialize if possible for (String artifactName : persistence.tryFind()) { data.getArtifact(artifactName); } //data.cache(); }