Package org.eclipse.jdt.core.dom

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


            }
            monitor.worked(3);
            // If we have found the processed project,
            if (javaProject != null) {
              // Then we parse the processed code section
              ASTParser parser = ASTParser.newParser(AST.JLS3);
              parser.setProject(javaProject);
              parser.setResolveBindings(true);
              char[] charArray = new char[buffer.length()];
              buffer.getChars(0, buffer.length(), charArray, 0);
              parser.setUnitName(javaProject.getElementName());
              parser.setSource(charArray);
              monitor.worked(4);
              CompilationUnit result =
                (CompilationUnit)parser.createAST(null);
              monitor.worked(5);
              List<?> types = result.types();
              for(int i=0 ; i<types.size() ; i++) {
                ASTNode node = (ASTNode)types.get(i);
                if(node instanceof TypeDeclaration) {
View Full Code Here


   * @param lwUnit
   *            the Java Model handle for the compilation unit
   * @return the root AST node of the parsed source
   */
  protected CompilationUnit parse(ICompilationUnit lwUnit) {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setSource(lwUnit); // set source
    parser.setResolveBindings(true); // we need bindings later on
    return (CompilationUnit) parser.createAST(null /* IProgressMonitor */); // parse
  }
View Full Code Here

        MessageDialog.openError(FindbugsPlugin.getShell(), "BugResolution failed.", e.getLocalizedMessage());
    }

    private CompilationUnit createWorkingCopy(ICompilationUnit unit) throws JavaModelException {
        unit.becomeWorkingCopy(monitor);
        ASTParser parser = ASTParser.newParser(AST.JLS3);
        parser.setSource(unit);
        parser.setResolveBindings(resolveBindings());
        return (CompilationUnit) parser.createAST(monitor);
    }
View Full Code Here

   * @param lwUnit
   *            the Java Model handle for the compilation unit
   * @return the root AST node of the parsed source
   */
  protected CompilationUnit parse(ICompilationUnit lwUnit) {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setSource(lwUnit); // set source
    parser.setResolveBindings(true); // we need bindings later on
    return (CompilationUnit) parser.createAST(null /* IProgressMonitor */); // parse
  }
View Full Code Here

     * @return Abstract syntax tree representation.
     */
    public static ASTNode runJLS3Conversion( char[] source,
                                             boolean resolveBindings ) {
        // Create parser
        ASTParser parser;
        parser = ASTParser.newParser(AST.JLS3);
        parser.setSource(source);
        parser.setKind(ASTParser.K_COMPILATION_UNIT);
        parser.setResolveBindings(resolveBindings);
        // Parse compilation unit
        return parser.createAST(null);
    }
View Full Code Here

     * @return Abstract syntax tree representation.
     */
    public static ASTNode runJLS3Conversion( char[] source,
                                             boolean resolveBindings ) {
        // Create parser
        ASTParser parser;
        parser = ASTParser.newParser(AST.JLS3);
        parser.setSource(source);
        parser.setKind(ASTParser.K_COMPILATION_UNIT);
        parser.setResolveBindings(resolveBindings);
        // Parse compilation unit
        return parser.createAST(null);
    }
View Full Code Here

   @Override
   @SuppressWarnings({ "rawtypes", "unchecked" })
   public JavaSource<?> parse(final String data)
   {
      Document document = new Document(data);
      ASTParser parser = ASTParser.newParser(AST.JLS3);

      parser.setSource(document.get().toCharArray());
      Map options = JavaCore.getOptions();
      options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
      parser.setCompilerOptions(options);

      parser.setResolveBindings(true);
      parser.setKind(ASTParser.K_COMPILATION_UNIT);
      CompilationUnit unit = (CompilationUnit) parser.createAST(null);
      unit.recordModifications();

      TypeDeclarationFinderVisitor visitor = new TypeDeclarationFinderVisitor();
      unit.accept(visitor);
View Full Code Here

  private ASTNode parse(ICompilationUnit cu) throws JavaModelException {
    if (!cu.isConsistent()) {
      return cu.reconcile(AST.JLS4, true, null, monitor);
    } else {
      ASTParser parser = ASTParser.newParser(AST.JLS4);

      // TODO: it may be possible to convert SimpleNames and QualifiedNames to
      // fully qualified names, thereby avoiding full binding resolution.

      parser.setResolveBindings(true);
      parser.setSource(cu);

      monitor.subTask("Metagen: parsing AST of " + cu.getElementName());

      return parser.createAST(monitor);
    }

  }
View Full Code Here

* with JLS4 level.
*/
public org.eclipse.jdt.core.dom.CompilationUnit getAST3() throws JavaModelException {
  if (this.operation.astLevel != AST.JLS3 || !this.operation.resolveBindings) {
    // create AST (optionally resolving bindings)
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setCompilerOptions(this.workingCopy.getJavaProject().getOptions(true));
    if (JavaProject.hasJavaNature(this.workingCopy.getJavaProject().getProject()))
      parser.setResolveBindings(true);
    parser.setStatementsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
    parser.setBindingsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0);
    parser.setSource(this.workingCopy);
    parser.setIgnoreMethodBodies((this.operation.reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0);
    return (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.operation.progressMonitor);
  }
  return this.operation.makeConsistent(this.workingCopy);
}
View Full Code Here

* @since 3.7.1
*/
public org.eclipse.jdt.core.dom.CompilationUnit getAST4() throws JavaModelException {
  if (this.operation.astLevel != AST.JLS4 || !this.operation.resolveBindings) {
    // create AST (optionally resolving bindings)
    ASTParser parser = ASTParser.newParser(AST.JLS4);
    parser.setCompilerOptions(this.workingCopy.getJavaProject().getOptions(true));
    if (JavaProject.hasJavaNature(this.workingCopy.getJavaProject().getProject()))
      parser.setResolveBindings(true);
    parser.setStatementsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
    parser.setBindingsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0);
    parser.setSource(this.workingCopy);
    parser.setIgnoreMethodBodies((this.operation.reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0);
    return (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.operation.progressMonitor);
  }
  return this.operation.makeConsistent(this.workingCopy);
}
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.ASTParser

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.