Examples of CompilationUnit


Examples of org.apache.sling.commons.compiler.CompilationUnit

        implements ClassLoaderWriter {

    public void testJava5Support() throws Exception {
        String sourceFile = "Java5Test";

        CompilationUnit unit = createCompileUnit(sourceFile);
        final Options options = new Options();
        options.put(Options.KEY_SOURCE_VERSION, Options.VERSION_1_5);
        options.put(Options.KEY_CLASS_LOADER_WRITER, this);
        options.put(Options.KEY_CLASS_LOADER, this.getClass().getClassLoader());
View Full Code Here

Examples of org.apache.sling.commons.compiler.CompilationUnit

    }

    //--------------------------------------------------------< misc. helpers >

    private CompilationUnit createCompileUnit(final String sourceFile) throws Exception {
        return new CompilationUnit() {

            /**
             * @see org.apache.sling.commons.compiler.CompilationUnit#getMainClassName()
             */
            public String getMainClassName() {
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit

  buff.append(lineSeparator + " public class A {" + lineSeparator); //$NON-NLS-1$
  buff.append(this.source);
  buff.append(lineSeparator).append('}');
  ASTParser parser = ASTParser.newParser(AST.JLS3);
  parser.setSource(buff.toString().toCharArray());
  CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null);
  TypeDeclaration typeDeclaration = (TypeDeclaration) compilationUnit.types().iterator().next();
  List bodyDeclarations = typeDeclaration.bodyDeclarations();
  if (bodyDeclarations.size() != 0)
    this.createdNode = (ASTNode) bodyDeclarations.iterator().next();
  return buff.toString();
}
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit

   
    ASTNode root= rootNode.getRoot();
    if (!(root instanceof CompilationUnit)) {
      throw new IllegalArgumentException("This API can only be used if the AST is created from a compilation unit or class file"); //$NON-NLS-1$
    }
    CompilationUnit astRoot= (CompilationUnit) root;
    ITypeRoot typeRoot = astRoot.getTypeRoot();
    if (typeRoot == null || typeRoot.getBuffer() == null) {
      throw new IllegalArgumentException("This API can only be used if the AST is created from a compilation unit or class file"); //$NON-NLS-1$
    }
   
    char[] content= typeRoot.getBuffer().getCharacters();
    LineInformation lineInfo= LineInformation.create(astRoot);
    String lineDelim= typeRoot.findRecommendedLineSeparator();
    Map options= typeRoot.getJavaProject().getOptions(true);
   
    return internalRewriteAST(content, lineInfo, lineDelim, astRoot.getCommentList(), options, rootNode);
  }
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit

   * that should be replaced (or deleted)
   */
  public SourceRange computeSourceRange(ASTNode node) {
    ASTNode root= node.getRoot();
    if (root instanceof CompilationUnit) {
      CompilationUnit cu= (CompilationUnit) root;
      return new SourceRange(cu.getExtendedStartPosition(node), cu.getExtendedLength(node));
    }
    return new SourceRange(node.getStartPosition(), node.getLength());
  }
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit

 
  private void deleteElement(IJavaElement elementToRemove, ICompilationUnit cu) throws JavaModelException {
    // ensure cu is consistent (noop if already consistent)
    cu.makeConsistent(this.progressMonitor);
    this.parser.setSource(cu);
    CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor);
    ASTNode node = ((JavaElement) elementToRemove).findNode(astCU);
    if (node == null)
      Assert.isTrue(false, "Failed to locate " + elementToRemove.getElementName() + " in " + cu.getElementName()); //$NON-NLS-1$//$NON-NLS-2$
    IDocument document = getDocument(cu);
    AST ast = astCU.getAST();
    ASTRewrite rewriter = ASTRewrite.create(ast);
    rewriter.remove(node, null);
     TextEdit edits = rewriter.rewriteAST(document, null);
     try {
       edits.apply(document);
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit

          if (Util.isJavaLikeFileName(resourceName)) {
            // we only consider potential compilation units
            ICompilationUnit cu = newFrag.getCompilationUnit(resourceName);
            if (Util.isExcluded(cu.getPath(), inclusionPatterns, exclusionPatterns, false/*not a folder*/)) continue;
            this.parser.setSource(cu);
            CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor);
            AST ast = astCU.getAST();
            ASTRewrite rewrite = ASTRewrite.create(ast);
            updatePackageStatement(astCU, newFragName, rewrite);
            IDocument document = getDocument(cu);
            TextEdit edits = rewrite.rewriteAST(document, null);
            try {
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit

      return null; //nothing to change
    } else {
      // ensure cu is consistent (noop if already consistent)
      cu.makeConsistent(this.progressMonitor);
      this.parser.setSource(cu);
      CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor);
      AST ast = astCU.getAST();
      ASTRewrite rewrite = ASTRewrite.create(ast);
      updateTypeName(cu, astCU, cu.getElementName(), newName, rewrite);
      updatePackageStatement(astCU, destPackageName, rewrite);
      return rewrite;
    }
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.internal.compiler.batch.CompilationUnit

    if ("".equals(defaultEncoding)) {//$NON-NLS-1$
      defaultEncoding = null;
    }

    for (int i = 0; i < fileCount; i++) {
      units[i] = new CompilationUnit(null, filenames[i], defaultEncoding);
    }
    return units;
  }
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.internal.compiler.batch.CompilationUnit

    CommentRecorderParser parser = new CommentRecorderParser(problemReporter, false);
    parser.setMethodsFullRecovery(false);
    parser.setStatementsRecovery(false);
   
    ICompilationUnit sourceUnit =
      new CompilationUnit(
        source,
        "", //$NON-NLS-1$
        compilerOptions.defaultEncoding);

    CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, compilerOptions.maxProblemsPerUnit);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.