Package org.eclipse.jdt.core.dom

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


   * creates a AST tree based on the ICompilationUnit passed in
   * @param iUnit
   * @return a CompilationUnit
   */
  public static CompilationUnit parse (ICompilationUnit iUnit){
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setSource(iUnit);
    parser.setResolveBindings(true);
    return (CompilationUnit) parser.createAST(null);
  }
View Full Code Here


            public Object doTask() throws Throwable {
              return createBeanFromClass(beanClass);
            }
          });
          WidgetAdapter beanAdapter = ExtensionRegistry.createWidgetAdapter(bean);
          ASTParser parser = ASTParser.newParser(AST.JLS3);
          parser.setSource(unit);
          CompilationUnit cunit = (CompilationUnit) parser.createAST(null);
          parseEventListener(cunit, beanAdapter);
          initDesignedWidget(cunit, bean);
          parsePropertyValue(lnf, cunit, beanAdapter);
          beanAdapter.clearDirty();
          return beanAdapter;
View Full Code Here

    IType type = unit.getType(unit_name);
    return type;
  }

  public static ImportRewrite createImportRewrite(ICompilationUnit unit) {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(unit);
    parser.setResolveBindings(false);
    parser.setFocalPosition(0);
    CompilationUnit cu = (CompilationUnit) parser.createAST(null);
    return CodeStyleConfiguration.createImportRewrite(cu, true);
  }
View Full Code Here

          nonExistingFields.add(name);
      }
      for (String nonfield : nonExistingFields) {
        removedNames.remove(nonfield);
      }
      ASTParser astparser = ASTParser.newParser(AST.JLS3);
      astparser.setSource(unit);
      CompilationUnit cunit = (CompilationUnit) astparser.createAST(null);
      List<String> getmethods = new ArrayList<String>();
      for (int i = 0; i < removedNames.size(); i++) {
        String removed_name = removedNames.get(i);
        String getmethod = NamespaceUtil.getGetMethodName(cunit, removed_name);
        getmethods.add(getmethod);
View Full Code Here

      }
    } catch (CoreException e) {
      e.printStackTrace();
    }
    unit = JavaCore.createCompilationUnitFrom(file);
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(unit);
    cunit = (CompilationUnit) parser.createAST(null);
  }
View Full Code Here

  private void addImplInterface(IType type, String cName) {
    try {
      ICompilationUnit icunit = type.getCompilationUnit();
      String source = icunit.getBuffer().getContents();
      Document document = new Document(source);
      ASTParser parser = ASTParser.newParser(AST.JLS3);
      parser.setSource(icunit);
      CompilationUnit cunit = (CompilationUnit) parser.createAST(null);
      cunit.recordModifications();
      AST ast = cunit.getAST();
      TypeDeclaration typeDec = (TypeDeclaration) cunit.types().get(0);
      List list = typeDec.superInterfaceTypes();
      Name name = ast.newName(cName);
View Full Code Here

    Assert.assertFalse(stmts.isEmpty());
    return (Statement) stmts.get(stmts.size()-1);
  }
 
  public static CompilationUnit parseCode(String qualifiedCompUnitName, String code) throws CoreException {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    CompilationUnit node;
   
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("CrystalTest");
    project.open(null /* IProgressMonitor */);
   
    IJavaProject javaProject = JavaCore.create(project);

    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setProject(javaProject);
    parser.setSource(code.toCharArray());
    parser.setUnitName("/CrystalTest/" + qualifiedCompUnitName);
    parser.setResolveBindings(true);
    node = (CompilationUnit) parser.createAST(null);
   
    Message[] msgs = node.getMessages();
    if(msgs.length > 0) {
      StringBuffer errs = new StringBuffer();
      errs.append("Compiler problems for ");
View Full Code Here

      throw new CrystalRuntimeException("null list of compilation units");
   
    Map<ICompilationUnit, ASTNode> parsedCompilationUnits = new HashMap<ICompilationUnit, ASTNode>();
     Iterator<ICompilationUnit> iter = compilationUnits.iterator();
     ICompilationUnit compUnit = null;
     ASTParser parser = null;
     ASTNode node = null;
     for(; iter.hasNext() ;) {
       compUnit = iter.next();
        parser = ASTParser.newParser(AST.JLS3);
       parser.setResolveBindings(true);
       parser.setSource(compUnit);
       node = parser.createAST(null);
       parsedCompilationUnits.put(compUnit, node);
     }
     return parsedCompilationUnits;
  }
View Full Code Here

   * @throws IllegalStateException if {@code compUnit} doesn't have a
   * {@link ITypeRoot#getSource() source attachment}
   * @see ASTParser#createAST(org.eclipse.core.runtime.IProgressMonitor)
   */
  public static ASTNode getASTNodeFromCompilationUnit(ITypeRoot compUnit) {
     ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setResolveBindings(true);
    parser.setSource(compUnit);
    try {
      return parser.createAST(/* passing in monitor messes up previous monitor state */ null);
    } catch (IllegalStateException e) {
      log.log(Level.SEVERE, "could not parse " + compUnit, e);
      throw e;
    }
  }
View Full Code Here

      throw new CrystalRuntimeException("null list of compilation units");
   
    Map<ICompilationUnit, ASTNode> parsedCompilationUnits = new HashMap<ICompilationUnit, ASTNode>();
     Iterator<ICompilationUnit> iter = compilationUnits.iterator();
     ICompilationUnit compUnit = null;
     ASTParser parser = null;
     ASTNode node = null;
     for(; iter.hasNext() ;) {
       compUnit = iter.next();
        parser = ASTParser.newParser(AST.JLS3);
       parser.setResolveBindings(true);
       parser.setSource(compUnit);
       node = parser.createAST(null);
       parsedCompilationUnits.put(compUnit, node);
     }
     return parsedCompilationUnits;
  }
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.