Package org.codehaus.groovy.control

Examples of org.codehaus.groovy.control.CompilationUnit$SourceUnitOperation


    /**
     * @see groovy.lang.GroovyClassLoader#createCompilationUnit(org.codehaus.groovy.control.CompilerConfiguration, java.security.CodeSource)
     */
    @Override
    protected CompilationUnit createCompilationUnit(CompilerConfiguration config, CodeSource source) {
        CompilationUnit cu = super.createCompilationUnit(config, source);

        GroovyPageInjectionOperation operation;

        operation = new GroovyPageInjectionOperation();

        cu.addPhaseOperation(operation, Phases.CANONICALIZATION);
        return cu;
    }
View Full Code Here


   @Override
   protected CompilationUnit createCompilationUnit(final CompilerConfiguration compilerConfiguration,
      final CodeSource codeSource)
   {
      //
      final CompilationUnit unit = SecurityHelper.doPrivilegedAction(new PrivilegedAction<CompilationUnit>()
      {
         public CompilationUnit run()
         {
            return JarJarClassLoader.super.createCompilationUnit(compilerConfiguration, codeSource);
         }
      });

      //
      unit.addPhaseOperation(new CompilationUnit.PrimaryClassNodeOperation()
      {
         @Override
         public void call(SourceUnit sourceUnit, GeneratorContext generatorContext, ClassNode classNode)
            throws CompilationFailedException
         {
View Full Code Here

                // Let's compile the groovy source
                final List<GroovyClass> groovyClassesForThisTemplate = new ArrayList<GroovyClass>();
                // ~~~ Please !
                CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
                compilerConfiguration.setSourceEncoding("utf-8"); // ouf
                CompilationUnit compilationUnit = new CompilationUnit(compilerConfiguration);
                compilationUnit.addSource(new SourceUnit(name, compiledSource, compilerConfiguration, tClassLoader, compilationUnit.getErrorCollector()));
                Field phasesF = compilationUnit.getClass().getDeclaredField("phaseOperations");
                phasesF.setAccessible(true);
                LinkedList[] phases = (LinkedList[]) phasesF.get(compilationUnit);
                LinkedList<GroovyClassOperation> output = new LinkedList<GroovyClassOperation>();
                phases[Phases.OUTPUT] = output;
                output.add(new GroovyClassOperation() {
                    public void call(GroovyClass gclass) {
                        groovyClassesForThisTemplate.add(gclass);
                    }
                });
                compilationUnit.compile();
                // ouf

                // Define script classes
                StringBuilder sb = new StringBuilder();
                sb.append("LINESMATRIX" + "\n");
View Full Code Here

  @Override
  public String checkSyntaxErrors(String path, String script) {
    URL url;
    try {
      url = new URL("file", "", path);
      final CompilationUnit unit = new CompilationUnit(CompilerConfiguration.DEFAULT, new CodeSource(url,
          (java.security.cert.Certificate[]) null), null);
      unit.addSource(path, script);
      unit.compile(Phases.CONVERSION);
    } catch (MalformedURLException e) {
      noOp();
    } catch (CompilationFailedException ce) {
      return ce.getMessage();
    }
View Full Code Here

            ) {

        final CompilerConfiguration configuration = ((GroovyJavaCompilerSettings) pSettings).getCompilerConfiguration();
        final ErrorCollector collector = new ErrorCollector(configuration);
        final GroovyClassLoader groovyClassLoader = new GroovyClassLoader(pClassLoader);
        final CompilationUnit unit = new CompilationUnit(configuration, null, groovyClassLoader);
        final SourceUnit[] source = new SourceUnit[pResourceNames.length];
        for (int i = 0; i < source.length; i++) {
            final String resourceName = pResourceNames[i];
            source[i] = new SourceUnit(
                    ConversionUtils.convertResourceToClassName(resourceName),
                    new String(pReader.getBytes(resourceName)), // FIXME delay the read
                    configuration,
                    groovyClassLoader,
                    collector
                    );
            unit.addSource(source[i]);
        }
       
        final Collection problems = new ArrayList();

        try {
            log.debug("compiling");
            unit.compile(Phases.CLASS_GENERATION);
           
            final List classes = unit.getClasses();
            for (final Iterator it = classes.iterator(); it.hasNext();) {
                final GroovyClass clazz = (GroovyClass) it.next();
                final byte[] bytes = clazz.getBytes();
                pStore.write(ConversionUtils.convertClassToResourcePath(clazz.getName()), bytes);
            }
View Full Code Here

                // Let's compile the groovy source
                final List<GroovyClass> groovyClassesForThisTemplate = new ArrayList<GroovyClass>();
                // ~~~ Please !
                CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
                compilerConfiguration.setSourceEncoding("utf-8"); // ouf
                CompilationUnit compilationUnit = new CompilationUnit(compilerConfiguration);
                compilationUnit.addSource(new SourceUnit(name, compiledSource, compilerConfiguration, tClassLoader, compilationUnit.getErrorCollector()));
                Field phasesF = compilationUnit.getClass().getDeclaredField("phaseOperations");
                phasesF.setAccessible(true);
                LinkedList[] phases = (LinkedList[]) phasesF.get(compilationUnit);
                LinkedList<GroovyClassOperation> output = new LinkedList<GroovyClassOperation>();
                phases[Phases.OUTPUT] = output;
                output.add(new GroovyClassOperation() {
                    public void call(GroovyClass gclass) {
                        groovyClassesForThisTemplate.add(gclass);
                    }
                });
                compilationUnit.compile();
                // ouf

                // Define script classes
                StringBuilder sb = new StringBuilder();
                sb.append("LINESMATRIX" + "\n");
View Full Code Here

         }

         final HierarchicalResourceLoader loader =
            new HierarchicalResourceLoader(actualLoader, JcrGroovyClassLoader.this.getResourceLoader());
        
         CompilationUnit cunit =
            new JcrCompilationUnit(config, cs, new JcrGroovyClassLoader(
               JcrGroovyClassLoaderProvider.class.getClassLoader()) {
               public GroovyResourceLoader getResourceLoader()
               {
                  return loader;
               }
            });
        
         for (int i = 0; i < files.length; i++)
            cunit.addSource(files[i].getPath());
         cunit.compile(phase);
        
         List classNodes = cunit.getAST().getClasses();
         List<URL> dependencies = new ArrayList<URL>(classNodes.size());
         for (Iterator iter = classNodes.iterator(); iter.hasNext();)
         {
            ClassNode classNode = (ClassNode)iter.next();
            ModuleNode module = classNode.getModule();
View Full Code Here

      {
         Class target = (Class)sourceCache.get(fileName);
         if (target == null)
         {
            CodeSource cs = new CodeSource(getCodeSource(), (java.security.cert.Certificate[])null);
            CompilationUnit cunit = createCompilationUnit(config, cs);
            SourceUnit targetSunit = cunit.addSource(fileName, in);
            if (files != null)
            {
               for (int i = 0; i < files.length; i++)
                  cunit.addSource(files[i].getPath());
            }
            SingleClassCollector collector = createSingleCollector(cunit, targetSunit);
            cunit.setClassgenCallback(collector);
            cunit.compile(phase);

            for (Iterator iter = collector.getLoadedClasses().iterator(); iter.hasNext();)
            {
               Class clazz = (Class)iter.next();
               String classname = clazz.getName();
View Full Code Here

   protected Class[] doParseClasses(SourceFile[] sources, int phase, CompilerConfiguration config)
   {
      synchronized (classCache)
      {
         CodeSource cs = new CodeSource(getCodeSource(), (java.security.cert.Certificate[])null);
         CompilationUnit cunit = createCompilationUnit(config, cs);
         Set<SourceUnit> setSunit = new HashSet<SourceUnit>();
         for (int i = 0; i < sources.length; i++)
            setSunit.add(cunit.addSource(sources[i].getPath()));
         MultipleClassCollector collector = createMultipleCollector(cunit, setSunit);
         cunit.setClassgenCallback(collector);
         cunit.compile(phase);

         for (Iterator iter = collector.getLoadedClasses().iterator(); iter.hasNext();)
         {
            Class clazz = (Class)iter.next();
            String classname = clazz.getName();
View Full Code Here

    *      java.security.CodeSource)
    */
   @Override
   protected CompilationUnit createCompilationUnit(CompilerConfiguration config, CodeSource cs)
   {
      return new CompilationUnit(config, cs, this);
   }
View Full Code Here

TOP

Related Classes of org.codehaus.groovy.control.CompilationUnit$SourceUnitOperation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.