org.codehaus.groovy.control.CompilationUnit Java Examples

The following examples show how to use org.codehaus.groovy.control.CompilationUnit. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TraitComposer.java    From groovy with Apache License 2.0 6 votes vote down vote up
/**
 * Given a class node, if this class node implements a trait, then generate all the appropriate
 * code which delegates calls to the trait. It is safe to call this method on a class node which
 * does not implement a trait.
 * @param cNode a class node
 * @param unit the source unit
 */
public static void doExtendTraits(final ClassNode cNode, final SourceUnit unit, final CompilationUnit cu) {
    if (cNode.isInterface()) return;
    boolean isItselfTrait = Traits.isTrait(cNode);
    SuperCallTraitTransformer superCallTransformer = new SuperCallTraitTransformer(unit);
    if (isItselfTrait) {
        checkTraitAllowed(cNode, unit);
        return;
    }
    if (!cNode.getNameWithoutPackage().endsWith(Traits.TRAIT_HELPER)) {
        List<ClassNode> traits = Traits.findTraits(cNode);
        for (ClassNode trait : traits) {
            TraitHelpersTuple helpers = Traits.findHelpers(trait);
            applyTrait(trait, cNode, helpers, unit);
            superCallTransformer.visitClass(cNode);
            if (unit!=null) {
                ASTTransformationCollectorCodeVisitor collector = new ASTTransformationCollectorCodeVisitor(unit, cu.getTransformLoader());
                collector.visitClass(cNode);
            }
        }
    }
}
 
Example #2
Source File: TestMethodUtilTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private ModuleNode createGroovyModuleNode() {
    final CompilerConfiguration conf = new CompilerConfiguration();
    conf.setTargetDirectory(compileDir);
    final CompilationUnit cu
            = new CompilationUnit(
                    new GroovyClassLoader(
                            getClass().getClassLoader()
                    )
            );
    cu.configure(conf);
    final SourceUnit sn = cu.addSource("AGroovyClass.groovy", groovyScript.toString());
    try {
        cu.compile();
    } catch (Exception e) {
        //this groovy compile bit didn't work when running tests
        //but did work when debugging them, so odd, but the AST is in
        //place either way, and is all we need for this
        this.log(e.getMessage());
    }
    final ModuleNode mn = sn.getAST();
    return mn;
}
 
Example #3
Source File: GenericsUtils.java    From groovy with Apache License 2.0 6 votes vote down vote up
public static ClassNode[] parseClassNodesFromString(final String option, final SourceUnit sourceUnit, final CompilationUnit compilationUnit, final MethodNode mn, final ASTNode usage) {
    try {
        ModuleNode moduleNode = ParserPlugin.buildAST("Dummy<" + option + "> dummy;", compilationUnit.getConfiguration(), compilationUnit.getClassLoader(), null);
        DeclarationExpression dummyDeclaration = (DeclarationExpression) ((ExpressionStatement) moduleNode.getStatementBlock().getStatements().get(0)).getExpression();

        // the returned node is DummyNode<Param1, Param2, Param3, ...)
        ClassNode dummyNode = dummyDeclaration.getLeftExpression().getType();
        GenericsType[] dummyNodeGenericsTypes = dummyNode.getGenericsTypes();
        if (dummyNodeGenericsTypes == null) {
            return null;
        }
        ClassNode[] signature = new ClassNode[dummyNodeGenericsTypes.length];
        for (int i = 0, n = dummyNodeGenericsTypes.length; i < n; i += 1) {
            final GenericsType genericsType = dummyNodeGenericsTypes[i];
            signature[i] = resolveClassNode(sourceUnit, compilationUnit, mn, usage, genericsType.getType());
        }
        return signature;
    } catch (Exception | LinkageError e) {
        sourceUnit.addError(new IncorrectTypeHintException(mn, e, usage.getLineNumber(), usage.getColumnNumber()));
    }
    return null;
}
 
Example #4
Source File: GenericsUtils.java    From groovy with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #5
Source File: Groovyc.java    From groovy with Apache License 2.0 6 votes vote down vote up
protected CompilationUnit makeCompileUnit(GroovyClassLoader loader) {
    Map<String, Object> options = configuration.getJointCompilationOptions();
    if (options != null) {
        if (keepStubs) {
            options.put("keepStubs", Boolean.TRUE);
        }
        if (stubDir != null) {
            options.put("stubDir", stubDir);
        } else {
            try {
                File tempStubDir = DefaultGroovyStaticMethods.createTempDir(null, "groovy-generated-", "-java-source");
                temporaryFiles.add(tempStubDir);
                options.put("stubDir", tempStubDir);
            } catch (IOException ioe) {
                throw new BuildException(ioe);
            }
        }
        return new JavaAwareCompilationUnit(configuration, loader);
    } else {
        return new CompilationUnit(configuration, null, loader);
    }
}
 
Example #6
Source File: AstStringCompiler.java    From groovy with Apache License 2.0 6 votes vote down vote up
/**
 * Performs the String source to {@link java.util.List} of {@link ASTNode}.
 *
 * @param script
 *      a Groovy script in String form
 * @param compilePhase
 *      the int based CompilePhase to compile it to.
 * @param statementsOnly
 * @return {@link java.util.List} of {@link ASTNode}
 */
public List<ASTNode> compile(String script, CompilePhase compilePhase, boolean statementsOnly) {
    final String scriptClassName = makeScriptClassName();
    GroovyCodeSource codeSource = new GroovyCodeSource(script, scriptClassName + ".groovy", "/groovy/script");
    CompilationUnit cu = new CompilationUnit(CompilerConfiguration.DEFAULT, codeSource.getCodeSource(),
            AccessController.doPrivileged((PrivilegedAction<GroovyClassLoader>) GroovyClassLoader::new));
    cu.addSource(codeSource.getName(), script);
    cu.compile(compilePhase.getPhaseNumber());

    // collect all the ASTNodes into the result, possibly ignoring the script body if desired
    List<ASTNode> result = cu.getAST().getModules().stream().reduce(new LinkedList<>(), (acc, node) -> {
        BlockStatement statementBlock = node.getStatementBlock();
        if (null != statementBlock) {
            acc.add(statementBlock);
        }
        acc.addAll(
                node.getClasses().stream()
                    .filter(c -> !(statementsOnly && scriptClassName.equals(c.getName())))
                    .collect(Collectors.toList())
        );

        return acc;
    }, (o1, o2) -> o1);

    return result;
}
 
Example #7
Source File: BuildScriptTransformer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void register(CompilationUnit compilationUnit) {
    extractionTransformer.register(compilationUnit);
    new TaskDefinitionScriptTransformer().register(compilationUnit);
    new FixMainScriptTransformer().register(compilationUnit); // TODO - remove this
    new StatementLabelsScriptTransformer().register(compilationUnit);
    new ScriptSourceDescriptionTransformer(scriptSource.getDisplayName()).register(compilationUnit);
    new ModelBlockTransformer().register(compilationUnit);
}
 
Example #8
Source File: FromString.java    From groovy with Apache License 2.0 5 votes vote down vote up
@Override
public List<ClassNode[]> getClosureSignatures(final MethodNode node, final SourceUnit sourceUnit, final CompilationUnit compilationUnit, final String[] options, final ASTNode usage) {
    List<ClassNode[]> list = new ArrayList<ClassNode[]>(options.length);
    for (String option : options) {
        list.add(parseOption(option, sourceUnit, compilationUnit, node, usage));
    }
    return list;
}
 
Example #9
Source File: SimpleType.java    From groovy with Apache License 2.0 5 votes vote down vote up
@Override
public ClassNode[] getParameterTypes(final MethodNode node, final String[] options, final SourceUnit sourceUnit, final CompilationUnit unit, final ASTNode usage) {
    ClassNode[] result = new ClassNode[options.length];
    for (int i = 0; i < result.length; i++) {
        result[i] = findClassNode(sourceUnit, unit, options[i]);
    }
    return result;
}
 
Example #10
Source File: GroovyTypeCheckingExtensionSupport.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a type checking extension relying on a Groovy script (type checking DSL).
 *
 * @param typeCheckingVisitor the type checking visitor
 * @param scriptPath the path to the type checking script (in classpath)
 * @param compilationUnit
 */
public GroovyTypeCheckingExtensionSupport(
        final StaticTypeCheckingVisitor typeCheckingVisitor,
        final String scriptPath, final CompilationUnit compilationUnit) {
    super(typeCheckingVisitor);
    this.scriptPath = scriptPath;
    this.compilationUnit = compilationUnit;
}
 
Example #11
Source File: JavacJavaCompiler.java    From groovy with Apache License 2.0 5 votes vote down vote up
private static void addJavacError(String header, CompilationUnit cu, StringBuilderWriter msg) {
    if (msg != null) {
        header = header + "\n" + msg.getBuilder().toString();
    } else {
        header = header +
                "\nThis javac version does not support compile(String[],PrintWriter), " +
                "so no further details of the error are available. The message error text " +
                "should be found on System.err.\n";
    }
    cu.getErrorCollector().addFatalError(new SimpleMessage(header, cu));
}
 
Example #12
Source File: MapEntryOrKeyValue.java    From groovy with Apache License 2.0 5 votes vote down vote up
public List<ClassNode[]> getClosureSignatures(final MethodNode node, final SourceUnit sourceUnit, final CompilationUnit compilationUnit, final String[] options, final ASTNode usage) {
    Options opt;
    try {
        opt = Options.parse(node, usage, options);
    } catch (IncorrectTypeHintException e) {
        sourceUnit.addError(e);
        return Collections.emptyList();
    }
    GenericsType[] genericsTypes = node.getParameters()[opt.parameterIndex].getOriginType().getGenericsTypes();
    if (genericsTypes==null) {
        // would happen if you have a raw Map type for example
        genericsTypes = new GenericsType[] {
            new GenericsType(ClassHelper.OBJECT_TYPE),
            new GenericsType(ClassHelper.OBJECT_TYPE)
        };
    }
    ClassNode[] firstSig;
    ClassNode[] secondSig;
    ClassNode mapEntry = MAPENTRY_TYPE.getPlainNodeReference();
    mapEntry.setGenericsTypes(genericsTypes);
    if (opt.generateIndex) {
        firstSig = new ClassNode[] {genericsTypes[0].getType(), genericsTypes[1].getType(), ClassHelper.int_TYPE};
        secondSig = new ClassNode[] {mapEntry, ClassHelper.int_TYPE};

    } else {
        firstSig = new ClassNode[] {genericsTypes[0].getType(), genericsTypes[1].getType()};
        secondSig = new ClassNode[] {mapEntry};
    }
    return Arrays.asList(firstSig, secondSig);
}
 
Example #13
Source File: JavacJavaCompiler.java    From groovy with Apache License 2.0 5 votes vote down vote up
private boolean doCompileWithSystemJavaCompiler(CompilationUnit cu, List<String> files, List<String> javacParameters, StringBuilderWriter javacOutput) throws IOException {
    javax.tools.JavaCompiler compiler = javax.tools.ToolProvider.getSystemJavaCompiler();
    try (javax.tools.StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, DEFAULT_LOCALE, charset)) {
        Set<javax.tools.JavaFileObject> compilationUnitSet = cu.getJavaCompilationUnitSet(); // java stubs already added

        Map<String, Object> options = this.config.getJointCompilationOptions();
        if (!Boolean.parseBoolean(options.get(CompilerConfiguration.MEM_STUB).toString())) {
            // clear the java stubs in the source set of Java compilation
            compilationUnitSet = new HashSet<>();

            // use sourcepath to specify the root directory of java stubs
            javacParameters.add("-sourcepath");
            final File stubDir = (File) options.get("stubDir");
            if (null == stubDir) {
                throw new GroovyBugError("stubDir is not specified");
            }
            javacParameters.add(stubDir.getAbsolutePath());
        }

        // add java source files to compile
        fileManager.getJavaFileObjectsFromFiles(
                files.stream().map(File::new).collect(Collectors.toList())
        ).forEach(compilationUnitSet::add);

        javax.tools.JavaCompiler.CompilationTask compilationTask = compiler.getTask(
                javacOutput,
                fileManager,
                null,
                javacParameters,
                Collections.emptyList(),
                compilationUnitSet
        );
        compilationTask.setLocale(DEFAULT_LOCALE);

        return compilationTask.call();
    }
}
 
Example #14
Source File: ScriptCompilationExecuter.java    From groovy with Apache License 2.0 5 votes vote down vote up
public long execute() throws Exception {
    ClassLoader cl = new URLClassLoader(classpath, ClassLoader.getSystemClassLoader().getParent());
    GroovyClassLoader gcl = new GroovyClassLoader(cl);
    CompilationUnit cu = new CompilationUnit(new CompilerConfiguration(), null, gcl, new GroovyClassLoader(this.getClass().getClassLoader()));
    for (File source : sources) {
        cu.addSource(source);
    }
    long sd = System.nanoTime();
    cu.compile(CompilePhase.CLASS_GENERATION.getPhaseNumber());
    long dur = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - sd);
    return dur;
}
 
Example #15
Source File: GroovyClassLoader.java    From groovy with Apache License 2.0 5 votes vote down vote up
private Class doParseClass(GroovyCodeSource codeSource) {
    validate(codeSource);
    Class answer;  // Was neither already loaded nor compiling, so compile and add to cache.
    CompilationUnit unit = createCompilationUnit(config, codeSource.getCodeSource());
    if (recompile!=null && recompile || recompile==null && config.getRecompileGroovySource()) {
        unit.addFirstPhaseOperation(TimestampAdder.INSTANCE, CompilePhase.CLASS_GENERATION.getPhaseNumber());
    }
    SourceUnit su = null;
    File file = codeSource.getFile();
    if (file != null) {
        su = unit.addSource(file);
    } else {
        URL url = codeSource.getURL();
        if (url != null) {
            su = unit.addSource(url);
        } else {
            su = unit.addSource(codeSource.getName(), codeSource.getScriptText());
        }
    }

    ClassCollector collector = createCollector(unit, su);
    unit.setClassgenCallback(collector);
    int goalPhase = Phases.CLASS_GENERATION;
    if (config != null && config.getTargetDirectory() != null) goalPhase = Phases.OUTPUT;
    unit.compile(goalPhase);

    answer = collector.generatedClass;
    String mainClass = su.getAST().getMainClassName();
    for (Object o : collector.getLoadedClasses()) {
        Class clazz = (Class) o;
        String clazzName = clazz.getName();
        definePackageInternal(clazzName);
        setClassCacheEntry(clazz);
        if (clazzName.equals(mainClass)) answer = clazz;
    }
    return answer;
}
 
Example #16
Source File: ClosureSignatureHint.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Finds a class node given a string representing the type. Performs a lookup in the compilation unit to check if it is done in the same source unit.
 * @param sourceUnit source unit
 * @param compilationUnit compilation unit
 * @param className the name of the class we want to get a {@link org.codehaus.groovy.ast.ClassNode} for
 * @return a ClassNode representing the type
 */
protected ClassNode findClassNode(final SourceUnit sourceUnit, final CompilationUnit compilationUnit, final String className) {
    if (className.endsWith("[]")) {
        return findClassNode(sourceUnit, compilationUnit, className.substring(0, className.length() - 2)).makeArray();
    }
    ClassNode cn = compilationUnit.getClassNode(className);
    if (cn == null) {
        try {
            cn = ClassHelper.make(Class.forName(className, false, sourceUnit.getClassLoader()));
        } catch (ClassNotFoundException e) {
            cn = ClassHelper.make(className);
        }
    }
    return cn;
}
 
Example #17
Source File: DependencyTest.java    From groovy with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    cache = new StringSetMap();
    cu = new CompilationUnit();
    cu.addPhaseOperation((final SourceUnit source, final GeneratorContext context, final ClassNode classNode) -> {
        DependencyTracker dt = new DependencyTracker(source, cache);
        dt.visitClass(classNode);
    }, Phases.CLASS_GENERATION);
}
 
Example #18
Source File: PickAnyArgumentHint.java    From groovy with Apache License 2.0 5 votes vote down vote up
@Override
public ClassNode[] getParameterTypes(final MethodNode node, final String[] options, final SourceUnit sourceUnit, final CompilationUnit unit, final ASTNode usage) {
    ClassNode type = node.getParameters()[parameterIndex].getOriginType();
    if (genericTypeIndex>=0) {
        type = pickGenericType(type, genericTypeIndex);
    }
    return new ClassNode[]{type};
}
 
Example #19
Source File: GroovyDocParser.java    From groovy with Apache License 2.0 5 votes vote down vote up
private Map<String, GroovyClassDoc> parseGroovy(String packagePath, String file, String src) throws RuntimeException {
    CompilerConfiguration config = new CompilerConfiguration();
    config.getOptimizationOptions().put(CompilerConfiguration.GROOVYDOC, true);
    CompilationUnit compUnit = new CompilationUnit(config);
    SourceUnit unit = new SourceUnit(file, src, config, null, new ErrorCollector(config));
    compUnit.addSource(unit);
    compUnit.compile(Phases.CONVERSION);
    ModuleNode root = unit.getAST();
    GroovydocVisitor visitor = new GroovydocVisitor(unit, packagePath, links);
    visitor.visitClass(root.getClasses().get(0));
    return visitor.getGroovyClassDocs();
}
 
Example #20
Source File: ProxyGeneratorAdapter.java    From groovy with Apache License 2.0 5 votes vote down vote up
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(ClassNode.EMPTY_ARRAY), 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;
}
 
Example #21
Source File: ASTNodeVisitor.java    From groovy-language-server with Apache License 2.0 5 votes vote down vote up
public void visitCompilationUnit(CompilationUnit unit) {
	nodesByURI.clear();
	classNodesByURI.clear();
	lookup.clear();
	unit.iterator().forEachRemaining(sourceUnit -> {
		visitSourceUnit(sourceUnit);
	});
}
 
Example #22
Source File: FileSystemCompiler.java    From groovy with Apache License 2.0 5 votes vote down vote up
public static void doCompilation(CompilerConfiguration configuration, CompilationUnit unit, String[] filenames, boolean lookupUnnamedFiles) throws Exception {
    File tmpDir = null;
    // if there are any joint compilation options set stubDir if not set
    try {
        if (configuration.getJointCompilationOptions() != null
                && !configuration.getJointCompilationOptions().containsKey("stubDir")) {
            tmpDir = DefaultGroovyStaticMethods.createTempDir(null, "groovy-generated-", "-java-source");
            configuration.getJointCompilationOptions().put("stubDir", tmpDir);
        }

        FileSystemCompiler compiler = new FileSystemCompiler(configuration, unit);

        if (lookupUnnamedFiles) {
            for (String filename : filenames) {
                File file = new File(filename);
                if (file.isFile()) {
                    URL url = file.getAbsoluteFile().getParentFile().toURI().toURL();
                    compiler.unit.getClassLoader().addURL(url);
                }
            }
        } else {
            compiler.unit.getClassLoader()
                    .setResourceLoader(filename -> null);
        }
        compiler.compile(filenames);
    } finally {
        try {
            if (tmpDir != null) deleteRecursive(tmpDir);
        } catch (Throwable t) {
            System.err.println("error: could not delete temp files - " + tmpDir.getPath());
        }
    }
}
 
Example #23
Source File: BuildScriptTransformer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void register(CompilationUnit compilationUnit) {
    extractionTransformer.register(compilationUnit);
    new TaskDefinitionScriptTransformer().register(compilationUnit);
    new FixMainScriptTransformer().register(compilationUnit); // TODO - remove this
    new StatementLabelsScriptTransformer().register(compilationUnit);
    new ScriptSourceDescriptionTransformer(scriptSource.getDisplayName()).register(compilationUnit);
    new ModelBlockTransformer().register(compilationUnit);
}
 
Example #24
Source File: ASTTest.java    From groovy with Apache License 2.0 5 votes vote down vote up
public ModuleNode getAST(String source, int untilPhase) {
    SourceUnit unit = SourceUnit.create("Test", source);
    CompilationUnit compUnit = new CompilationUnit();
    compUnit.addSource(unit);
    compUnit.compile(untilPhase);
    return unit.getAST();
}
 
Example #25
Source File: GrabAnnotationTransformation.java    From groovy with Apache License 2.0 4 votes vote down vote up
public void setCompilationUnit(final CompilationUnit compilationUnit) {
    this.compilationUnit = compilationUnit;
}
 
Example #26
Source File: SecondParam.java    From groovy with Apache License 2.0 4 votes vote down vote up
@Override
public ClassNode[] getParameterTypes(final MethodNode node, final String[] options, final SourceUnit sourceUnit, final CompilationUnit unit, final ASTNode usage) {
    final ClassNode[] parameterTypes = super.getParameterTypes(node, options, sourceUnit, unit, usage);
    parameterTypes[0] = parameterTypes[0].getComponentType();
    return parameterTypes;
}
 
Example #27
Source File: ThirdParam.java    From groovy with Apache License 2.0 4 votes vote down vote up
@Override
public ClassNode[] getParameterTypes(final MethodNode node, final String[] options, final SourceUnit sourceUnit, final CompilationUnit unit, final ASTNode usage) {
    final ClassNode[] parameterTypes = super.getParameterTypes(node, options, sourceUnit, unit, usage);
    parameterTypes[0] = parameterTypes[0].getComponentType();
    return parameterTypes;
}
 
Example #28
Source File: Compiler.java    From groovy with Apache License 2.0 4 votes vote down vote up
/**
 * Compiles a string of code.
 */
public void compile(String name, String code) throws CompilationFailedException {
    CompilationUnit unit = new CompilationUnit(configuration);
    unit.addSource(new SourceUnit(name, code, configuration, unit.getClassLoader(), unit.getErrorCollector()));
    unit.compile();
}
 
Example #29
Source File: Compiler.java    From groovy with Apache License 2.0 4 votes vote down vote up
/**
 * Compiles a series of Files from file names.
 */
public void compile(String[] files) throws CompilationFailedException {
    CompilationUnit unit = new CompilationUnit(configuration);
    unit.addSources(files);
    unit.compile();
}
 
Example #30
Source File: Compiler.java    From groovy with Apache License 2.0 4 votes vote down vote up
/**
 * Compiles a series of Files.
 */
public void compile(File[] files) throws CompilationFailedException {
    CompilationUnit unit = new CompilationUnit(configuration);
    unit.addSources(files);
    unit.compile();
}