Package org.codehaus.groovy.control

Examples of org.codehaus.groovy.control.SourceUnit


   
   
    public void write( PrintWriter writer, Janitor janitor )
    {
        if (owner instanceof SourceUnit) {
            SourceUnit source = (SourceUnit) owner;

            String name   = source.getName();
            int    line   = context.getStartLine();
            int    column = context.getStartColumn();
            String sample = source.getSample( line, column, janitor );

            if( sample != null )
            {
                writer.println( source.getSample(line, column, janitor) );
            }

            writer.println( name + ": " + line + ": " + this.message );
            writer.println("");
        } else {
View Full Code Here


    */
   
    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();
    }
View Full Code Here

        ClassNode stored = classes.get(name);
        if (stored != null && stored != node) {
            // we have a duplicate class!
            // One possibility for this is, that we declared a script and a
            // class in the same file and named the class like the file
            SourceUnit nodeSource = node.getModule().getContext();
            SourceUnit storedSource = stored.getModule().getContext();
            String txt = "Invalid duplicate class definition of class " + node.getName() + " : ";
            if (nodeSource == storedSource) {
                // same class in same source
                txt += "The source " + nodeSource.getName() + " contains at least two definitions of the class " + node.getName() + ".\n";
                if (node.isScriptBody() || stored.isScriptBody()) {
                    txt += "One of the classes is a explicit generated class using the class statement, the other is a class generated from" +
                            " the script body based on the file name. Solutions are to change the file name or to change the class name.\n";
                }
            } else {
                txt += "The sources " + nodeSource.getName() + " and " + storedSource.getName() + " are containing both a class of the name " + node.getName() + ".\n";
            }
            nodeSource.getErrorCollector().addErrorAndContinue(
                    new SyntaxErrorMessage(new SyntaxException(txt, node.getLineNumber(), node.getColumnNumber()), nodeSource)
            );
        }
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());
            }
View Full Code Here

         Class clazz = cl.defineClass(classNode.getName(), code, cunit.getAST().getCodeSource());
         getLoadedClasses().add(clazz);
         if (target == null)
         {
            ClassNode targetClassNode = null;
            SourceUnit targetSunit = null;
            ModuleNode module = classNode.getModule();
            if (module != null)
            {
               targetClassNode = (ClassNode)module.getClasses().get(0);
               targetSunit = module.getContext();
View Full Code Here

         Class clazz = cl.defineClass(classNode.getName(), code, cunit.getAST().getCodeSource());
         getLoadedClasses().add(clazz);
         ModuleNode module = classNode.getModule();
         if (module != null)
         {
            SourceUnit currentSunit = module.getContext();
            if (sunitSet.contains(currentSunit))
               compiledClasses.add(clazz);
         }
         return clazz;
      }
View Full Code Here

    adjustedText = TextUtil.repeatChar(' ', startPos.getColumnIndex()) + text;
    lines = adjustedText.split("\n");
  }

  public ExpressionInfo build() {
    SourceUnit unit = SourceUnit.create("Spec expression", adjustedText);
    unit.parse();
    unit.completePhase();
    unit.convert();

    BlockStatement blockStat = unit.getAST().getStatementBlock();
    Assert.that(blockStat != null && blockStat.getStatements().size() == 1);
    Statement stat = blockStat.getStatements().get(0);
    Assert.that(stat instanceof ExpressionStatement);
    Expression expr = ((ExpressionStatement)stat).getExpression();
View Full Code Here

TOP

Related Classes of org.codehaus.groovy.control.SourceUnit

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.