Examples of ASTParser


Examples of org.eclipse.jdt.core.dom.ASTParser

            monitorInternal.done();
        }
    }

    private CompilationUnit createASTForImports(ICompilationUnit cu) {
        ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
        parser.setSource(cu);
        parser.setResolveBindings(false);
        parser.setFocalPosition(0);
        return (CompilationUnit) parser.createAST(null);
    }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.ASTParser

        }
        return res;
    }

    private void removeUnusedImports(ICompilationUnit cu, Set<String> existingImports, boolean needsSave) throws CoreException {
        ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
        parser.setSource(cu);
        parser.setResolveBindings(true);

        CompilationUnit root = (CompilationUnit) parser.createAST(null);
        if (root.getProblems().length == 0) {
            return;
        }

        @SuppressWarnings("unchecked")
View Full Code Here

Examples of org.eclipse.jdt.core.dom.ASTParser

        String fileComment = getFileComment(cu, lineDelimiter);
        String typeComment = getTypeComment(cu, lineDelimiter);
        IPackageFragment pack = (IPackageFragment) cu.getParent();
        String content = CodeGeneration.getCompilationUnitContent(cu, fileComment, typeComment, typeContent, lineDelimiter);
        if (content != null) {
            ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
            parser.setProject(cu.getJavaProject());
            parser.setSource(content.toCharArray());
            CompilationUnit unit = (CompilationUnit) parser.createAST(null);
            if ((pack.isDefaultPackage() || unit.getPackage() != null) && !unit.types().isEmpty()) {
                return content;
            }
        }
        StringBuffer buf = new StringBuffer();
View Full Code Here

Examples of org.eclipse.jdt.core.dom.ASTParser

        for (int index = 0; index < typeMethods.length; index++)
            handleIds.add(typeMethods[index].getHandleIdentifier());
        ArrayList<IMethod> newMethods = new ArrayList<IMethod>();
        CodeGenerationSettings settings = JavaPreferencesSettings.getCodeGenerationSettings(type.getJavaProject());
        settings.createComments = isAddComments();
        ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
        parser.setResolveBindings(true);
        parser.setSource(cu);
        CompilationUnit unit = (CompilationUnit) parser.createAST(new SubProgressMonitor(monitor, 1));
        final ITypeBinding binding = ASTNodes.getTypeBinding(unit, type);
        if (binding != null) {
            if (doUnimplementedMethods) {
                AddUnimplementedMethodsOperation operation = new AddUnimplementedMethodsOperation(unit, binding, null, -1, false, true, false);
                operation.setCreateComments(isAddComments());
View Full Code Here

Examples of org.eclipse.jdt.core.dom.ASTParser

    this.resolveElements();
    System.out.println(model);
  }

  private void resolveElements() {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setResolveBindings(true);
    parser.setProject(project);
    IJavaElement[] elements = toBeResolved.toArray(new IJavaElement[toBeResolved.size()]);
    IBinding[] bindings = parser.createBindings(elements, null);
    for (IBinding each: bindings) this.resolveBinding(each);
  }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.ASTParser

      }
  }

  protected CompilationUnit getCompilationUnit(String unitName, char[] contents, boolean resolveBindings, IString javaVersion)
      throws IOException {
    ASTParser parser = ASTParser.newParser(AST.JLS4);
    parser.setUnitName(unitName);
    parser.setResolveBindings(resolveBindings);
    parser.setSource(contents);
    parser.setBindingsRecovery(true);
    parser.setStatementsRecovery(true);

    Hashtable<String, String> options = new Hashtable<String, String>();

    options.put(JavaCore.COMPILER_SOURCE, javaVersion.getValue());
    options.put(JavaCore.COMPILER_COMPLIANCE, javaVersion.getValue());
    options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, "enabled");

    parser.setCompilerOptions(options);

    parser.setEnvironment(classPathEntries.toArray(new String[classPathEntries.size()]),
        sourcePathEntries.toArray(new String[sourcePathEntries.size()]), null, true);

    CompilationUnit cu = (CompilationUnit) parser.createAST(null);

    return cu;
  }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.ASTParser

        this.javaFile = javaFile;
    }

    // use ASTParse to parse string
    public void parse() throws IOException {
        final ASTParser parser = ASTParser.newParser(AST.JLS3);
        parser.setSource(readFileToString().toCharArray());
        parser.setKind(ASTParser.K_COMPILATION_UNIT);

        // For now we only care about the package, parse more data as need
        // arises
        final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
        javaPackage = cu.getPackage();
    }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.ASTParser

    public char[] getContents() {
      StringBuilder bs = new StringBuilder();
     
      bs
          .append("package snippet;import java.io.PrintWriter;");
      ASTParser newParser = ASTParser.newParser(AST.JLS3);
      newParser.setSource(str.toCharArray());
      StringBuilder bls=new StringBuilder(str);
      CompilationUnit createAST = (CompilationUnit) newParser.createAST(null);
      //ArrayList<String> results = new ArrayList<String>();
      for (Object n : createAST.imports()) {
        ImportDeclaration decl = (ImportDeclaration) n;
        String name = decl.getName().getFullyQualifiedName();
        if (decl.isOnDemand()) {
View Full Code Here

Examples of org.eclipse.jdt.core.dom.ASTParser

   
  }

  protected String[] getImports() {
    String snippet = getSourceViewer().getDocument().get();
    ASTParser newParser = ASTParser.newParser(AST.JLS3);
    newParser.setSource(snippet.toCharArray());
    CompilationUnit createAST = (CompilationUnit) newParser.createAST(null);
    ArrayList<String> results = new ArrayList<String>();
    for (Object n : createAST.imports()) {
      ImportDeclaration decl = (ImportDeclaration) n;
      String name = decl.getName().getFullyQualifiedName();
      if (decl.isOnDemand()) {
View Full Code Here

Examples of org.eclipse.jdt.core.dom.ASTParser

   
    return null;
  }
 
  private void goThroughClass(ICompilationUnit ClassContent, final String contextTypeId) {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(ClassContent);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
    cu.accept(new ASTVisitor() {
      private boolean parameter = false;
      private String paramName = "";
      public void endVisit(FieldDeclaration node) {
        paramName = "";
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.