Package org.eclipse.jdt.core.dom

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


   * Gets the root ASTNode for a compilation unit, with bindings on.
   * @param compUnit
   * @return the root ASTNode for a compilation unit, with bindings on.
   */
  public static ASTNode getASTNodeFromCompilationUnit(ICompilationUnit compUnit) {
     ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setResolveBindings(true);
    parser.setSource(compUnit);
    return parser.createAST(/* passing in monitor messes up previous monitor state */ null);
  }
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

  static public CompilationUnit parseCode(String qualifiedCompUnitName)
      throws CoreException {
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
        PROJECT);
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    CompilationUnit node;

    project.open(null);

    IJavaProject javaProject = JavaCore.create(project);
    ICompilationUnit source = javaProject.findType(qualifiedCompUnitName)
        .getCompilationUnit();

    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setSource(source);
    parser.setResolveBindings(true);
    node = (CompilationUnit) parser.createAST(null);

    return node;
  }
View Full Code Here

@Deprecated
public class TestUtilities {

  static public void runTest(String code, String subFolder, String file,
      boolean doCompare, boolean store) throws Exception {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    CompilationUnit node;
    Graph testGraph;
    OutputStream out;

    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setResolveBindings(true);
    // parser.setBindingsRecovery(true);
    parser.setSource(code.toCharArray());
    parser.setUnitName("Foo.java");
    // parser.setProject(JavaCore.create(null));
    node = (CompilationUnit) parser.createAST(null);

    for (IProblem problem : node.getProblems()) {
      System.out.println("Compile problem for " + subFolder + "_" + file);
      System.out.println(problem.getMessage());
    }
View Full Code Here

   * Store the source code of this item
   *
   * @param source
   */
  public void setSource(String source) {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(source.toCharArray());
    resultCompilationUnit = (CompilationUnit) parser.createAST(null);
  }
View Full Code Here

   *
   * @param source
   */
  public void setSource(String source) {
    properties.put(ResultProperty.RAW_SOURCE, source);
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setSource(source.toCharArray());
    Map<?, ?> options = JavaCore.getOptions();
    JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options);
    parser.setCompilerOptions(options);
    try {
      resultCompilationUnit = (CompilationUnit) parser.createAST(null);
    } catch (Throwable e) {
      CrashReporter.reportException(e);
      logger.debug("Could not parse source");
    }
    String sourceInCpu = "";
View Full Code Here

                    "merobase_auto_generated_package_for_adaptation",
                    pkg.getElementName());

            monitor.subTask("Insert adapter class");
            // Find out the name of the adapter
            ASTParser parser = ASTParser.newParser(AST.JLS3);
            parser.setSource(adapterCode.toCharArray());
            CompilationUnit astRoot = (CompilationUnit) parser
                .createAST(null);
            List<TypeDeclaration> typeList = astRoot.types();
            if (typeList != null && typeList.size() > 0) {
              TypeDeclaration adapterType = (TypeDeclaration) typeList
                  .get(0);
View Full Code Here

    boolean overwrite = Activator.getDefault().getPreferenceStore()
        .getBoolean(PreferenceConstants.P_OVERWRITE_ON_INSERT);

    ICompilationUnit cpu = target.getWorkingCopy(null);
    // creation of DOM/AST from an ICompilationUnit
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(cpu);
    CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);

    StringBuffer signature = new StringBuffer();
    signature.append(methodDeclaration.getName().getFullyQualifiedName()
        + " ( ");
    for (Object param : methodDeclaration.parameters()) {
View Full Code Here

      MalformedTreeException, BadLocationException {
    try {
      ICompilationUnit icu = target.getWorkingCopy(null);

      // creation of DOM/AST from an ICompilationUnit
      ASTParser parser = ASTParser.newParser(AST.JLS3);
      parser.setSource(icu);
      CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);

      StringBuffer signature = new StringBuffer();
      signature.append(typeDeclaration.getName().getFullyQualifiedName());

      typeDeclaration.setProperty("Signature", signature.toString());
View Full Code Here

      if (selectedElement.getNodeType() == BodyDeclaration.METHOD_DECLARATION) {
        boolean overwrite = Activator.getDefault().getPreferenceStore()
            .getBoolean(PreferenceConstants.P_OVERWRITE_ON_INSERT);
        ICompilationUnit cpu = target.getWorkingCopy(null);
        // creation of DOM/AST from an ICompilationUnit
        ASTParser parser = ASTParser.newParser(AST.JLS3);
        parser.setSource(cpu);
        CompilationUnit astRoot = (CompilationUnit) parser
            .createAST(null);

        // creation of ASTRewrite
        astRoot.recordModifications();
        IMethod method = null;
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.