Package org.eclipse.jdt.internal.compiler

Examples of org.eclipse.jdt.internal.compiler.SourceElementParser


public SourceElementParser getSourceElementParser(IJavaProject project, ISourceElementRequestor requestor) {
  // disable task tags to speed up parsing
  Map options = project.getOptions(true);
  options.put(JavaCore.COMPILER_TASK_TAGS, ""); //$NON-NLS-1$

  SourceElementParser parser = new IndexingParser(
    requestor,
    new DefaultProblemFactory(Locale.getDefault()),
    new CompilerOptions(options),
    true, // index local declarations
    true, // optimize string literals
View Full Code Here


    if (elementToFind != null) {
      oldSourceRanges = (HashMap) this.sourceRanges.clone();
    }
    try {
      IProblemFactory factory = new DefaultProblemFactory();
      SourceElementParser parser = null;
      this.anonymousClassName = 0;
      if (info == null) {
        try {
          info = (IBinaryType) this.binaryType.getElementInfo();
        } catch(JavaModelException e) {
          return null;
        }
      }
      boolean isAnonymousClass = info.isAnonymous();
      char[] fullName = info.getName();
      if (isAnonymousClass) {
        String eltName = this.binaryType.getParent().getElementName();
        eltName = eltName.substring(eltName.lastIndexOf('$') + 1, eltName.length());
        try {
          this.anonymousClassName = Integer.parseInt(eltName);
        } catch(NumberFormatException e) {
          // ignore
        }
      }
      boolean doFullParse = hasToRetrieveSourceRangesForLocalClass(fullName);
      parser = new SourceElementParser(this, factory, new CompilerOptions(this.options), doFullParse, true/*optimize string literals*/);
      parser.javadocParser.checkDocComment = false; // disable javadoc parsing
      IJavaElement javaElement = this.binaryType.getCompilationUnit();
      if (javaElement == null) javaElement = this.binaryType.getParent();
      parser.parseCompilationUnit(
        new BasicCompilationUnit(contents, null, this.binaryType.sourceFileName(info), javaElement),
        doFullParse,
        null/*no progress*/);
      if (elementToFind != null) {
        ISourceRange range = getNameRange(elementToFind);
View Full Code Here

  }
  public void indexDocument() {
    // Create a new Parser
    SourceIndexerRequestor requestor = new SourceIndexerRequestor(this);
    String documentPath = this.document.getPath();
    SourceElementParser parser = this.document.getParser();
    if (parser == null) {
      IPath path = new Path(documentPath);
      IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0));
      parser = JavaModelManager.getJavaModelManager().indexManager.getSourceElementParser(JavaCore.create(project), requestor);
    } else {
      parser.setRequestor(requestor);
    }

    // Launch the parser
    char[] source = null;
    char[] name = null;
    try {
      source = this.document.getCharContents();
      name = documentPath.toCharArray();
    } catch(Exception e){
      // ignore
    }
    if (source == null || name == null) return; // could not retrieve document info (e.g. resource was discarded)
    CompilationUnit compilationUnit = new CompilationUnit(source, name);
    try {
      parser.parseCompilationUnit(compilationUnit, true/*full parse*/, null/*no progress*/);
    } catch (Exception e) {
      if (JobManager.VERBOSE) {
        e.printStackTrace();
      }
    }
View Full Code Here

            );
          }
        }
      }

      SourceElementParser parser = this.manager.getSourceElementParser(javaProject, null/*requestor will be set by indexer*/);
      Object[] names = indexedFileNames.keyTable;
      Object[] values = indexedFileNames.valueTable;
      for (int i = 0, namesLength = names.length; i < namesLength; i++) {
        String name = (String) names[i];
        if (name != null) {
View Full Code Here

    // disable task tags checking to speed up parsing
    options.put(JavaCore.COMPILER_TASK_TAGS, ""); //$NON-NLS-1$
  }
  CompilerOptions compilerOptions = new CompilerOptions(options);
  compilerOptions.ignoreMethodBodies = (reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
  SourceElementParser parser = new SourceElementParser(
    requestor,
    problemFactory,
    compilerOptions,
    true/*report local declarations*/,
    !createAST /*optimize string literals only if not creating a DOM AST*/);
  parser.reportOnlyOneSyntaxError = !computeProblems;
  parser.setMethodsFullRecovery(true);
  parser.setStatementsRecovery((reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);

  if (!computeProblems && !resolveBindings && !createAST) // disable javadoc parsing if not computing problems, not resolving and not creating ast
    parser.javadocParser.checkDocComment = false;
  requestor.parser = parser;

  // update timestamp (might be IResource.NULL_STAMP if original does not exist)
  if (underlyingResource == null) {
    underlyingResource = getResource();
  }
  // underlying resource is null in the case of a working copy on a class file in a jar
  if (underlyingResource != null)
    unitInfo.timestamp = ((IFile)underlyingResource).getModificationStamp();

  // compute other problems if needed
  CompilationUnitDeclaration compilationUnitDeclaration = null;
  CompilationUnit source = cloneCachingContents();
  try {
    if (computeProblems) {
      if (problems == null) {
        // report problems to the problem requestor
        problems = new HashMap();
        compilationUnitDeclaration = CompilationUnitProblemFinder.process(source, parser, this.owner, problems, createAST, reconcileFlags, pm);
        try {
          perWorkingCopyInfo.beginReporting();
          for (Iterator iteraror = problems.values().iterator(); iteraror.hasNext();) {
            CategorizedProblem[] categorizedProblems = (CategorizedProblem[]) iteraror.next();
            if (categorizedProblems == null) continue;
            for (int i = 0, length = categorizedProblems.length; i < length; i++) {
              perWorkingCopyInfo.acceptProblem(categorizedProblems[i]);
            }
          }
        } finally {
          perWorkingCopyInfo.endReporting();
        }
      } else {
        // collect problems
        compilationUnitDeclaration = CompilationUnitProblemFinder.process(source, parser, this.owner, problems, createAST, reconcileFlags, pm);
      }
    } else {
      compilationUnitDeclaration = parser.parseCompilationUnit(source, true /*full parse to find local elements*/, pm);
    }

    if (createAST) {
      int astLevel = ((ASTHolderCUInfo) info).astLevel;
      org.eclipse.jdt.core.dom.CompilationUnit cu = AST.convertCompilationUnit(astLevel, compilationUnitDeclaration, options, computeProblems, source, reconcileFlags, pm);
View Full Code Here

      };

      boolean reportLocalDeclarations = true;
      boolean optimizeStringLiterals = true;

      SourceElementParser parser = new SourceElementParser(requestor,
          problemFactory, options, reportLocalDeclarations,
          optimizeStringLiterals);

      File sourceFile = findSourceFile(klass);
      sourceContents = read(sourceFile);
      CompilationUnit unit = new CompilationUnit(sourceContents,
          sourceFile.getName(), null);

      parser.parseCompilationUnit(unit, true);
    }
View Full Code Here

}
/**
* Creates a new parser.
*/
protected SourceElementParser getParser(Map settings) {
  return new SourceElementParser(this, new DefaultProblemFactory(), new CompilerOptions(settings), false/*don't report local declarations*/, true/*optimize string literals*/);
}
 
View Full Code Here

    // disable task tags checking to speed up parsing
    options.put(JavaCore.COMPILER_TASK_TAGS, ""); //$NON-NLS-1$
  }
  CompilerOptions compilerOptions = new CompilerOptions(options);
  compilerOptions.ignoreMethodBodies = (reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
  SourceElementParser parser = new SourceElementParser(
    requestor,
    problemFactory,
    compilerOptions,
    true/*report local declarations*/,
    !createAST /*optimize string literals only if not creating a DOM AST*/);
  parser.reportOnlyOneSyntaxError = !computeProblems;
  parser.setMethodsFullRecovery(true);
  parser.setStatementsRecovery((reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);

  if (!computeProblems && !resolveBindings && !createAST) // disable javadoc parsing if not computing problems, not resolving and not creating ast
    parser.javadocParser.checkDocComment = false;
  requestor.parser = parser;

  // update timestamp (might be IResource.NULL_STAMP if original does not exist)
  if (underlyingResource == null) {
    underlyingResource = getResource();
  }
  // underlying resource is null in the case of a working copy on a class file in a jar
  if (underlyingResource != null)
    unitInfo.timestamp = ((IFile)underlyingResource).getModificationStamp();

  // compute other problems if needed
  CompilationUnitDeclaration compilationUnitDeclaration = null;
  CompilationUnit source = cloneCachingContents();
  try {
    if (computeProblems) {
      if (problems == null) {
        // report problems to the problem requestor
        problems = new HashMap();
        compilationUnitDeclaration = CompilationUnitProblemFinder.process(source, parser, this.owner, problems, createAST, reconcileFlags, pm);
        try {
          perWorkingCopyInfo.beginReporting();
          for (Iterator iteraror = problems.values().iterator(); iteraror.hasNext();) {
            CategorizedProblem[] categorizedProblems = (CategorizedProblem[]) iteraror.next();
            if (categorizedProblems == null) continue;
            for (int i = 0, length = categorizedProblems.length; i < length; i++) {
              perWorkingCopyInfo.acceptProblem(categorizedProblems[i]);
            }
          }
        } finally {
          perWorkingCopyInfo.endReporting();
        }
      } else {
        // collect problems
        compilationUnitDeclaration = CompilationUnitProblemFinder.process(source, parser, this.owner, problems, createAST, reconcileFlags, pm);
      }
    } else {
      compilationUnitDeclaration = parser.parseCompilationUnit(source, true /*full parse to find local elements*/, pm);
    }

    if (createAST) {
      int astLevel = ((ASTHolderCUInfo) info).astLevel;
      org.eclipse.jdt.core.dom.CompilationUnit cu = AST.convertCompilationUnit(astLevel, compilationUnitDeclaration, options, computeProblems, source, reconcileFlags, pm);
View Full Code Here

    // disable task tags checking to speed up parsing
    options.put(JavaCore.COMPILER_TASK_TAGS, ""); //$NON-NLS-1$
  }
  CompilerOptions compilerOptions = new CompilerOptions(options);
  compilerOptions.ignoreMethodBodies = (reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
  SourceElementParser parser = new SourceElementParser(
    requestor,
    problemFactory,
    compilerOptions,
    true/*report local declarations*/,
    !createAST /*optimize string literals only if not creating a DOM AST*/);
  parser.reportOnlyOneSyntaxError = !computeProblems;
  parser.setMethodsFullRecovery(true);
  parser.setStatementsRecovery((reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);

  if (!computeProblems && !resolveBindings && !createAST) // disable javadoc parsing if not computing problems, not resolving and not creating ast
    parser.javadocParser.checkDocComment = false;
  requestor.parser = parser;

  // update timestamp (might be IResource.NULL_STAMP if original does not exist)
  if (underlyingResource == null) {
    underlyingResource = getResource();
  }
  // underlying resource is null in the case of a working copy on a class file in a jar
  if (underlyingResource != null)
    unitInfo.timestamp = ((IFile)underlyingResource).getModificationStamp();

  // compute other problems if needed
  CompilationUnitDeclaration compilationUnitDeclaration = null;
  CompilationUnit source = cloneCachingContents();
  try {
    if (computeProblems) {
      if (problems == null) {
        // report problems to the problem requestor
        problems = new HashMap();
        compilationUnitDeclaration = CompilationUnitProblemFinder.process(source, parser, this.owner, problems, createAST, reconcileFlags, pm);
        try {
          perWorkingCopyInfo.beginReporting();
          for (Iterator iteraror = problems.values().iterator(); iteraror.hasNext();) {
            CategorizedProblem[] categorizedProblems = (CategorizedProblem[]) iteraror.next();
            if (categorizedProblems == null) continue;
            for (int i = 0, length = categorizedProblems.length; i < length; i++) {
              perWorkingCopyInfo.acceptProblem(categorizedProblems[i]);
            }
          }
        } finally {
          perWorkingCopyInfo.endReporting();
        }
      } else {
        // collect problems
        compilationUnitDeclaration = CompilationUnitProblemFinder.process(source, parser, this.owner, problems, createAST, reconcileFlags, pm);
      }
    } else {
      compilationUnitDeclaration = parser.parseCompilationUnit(source, true /*full parse to find local elements*/, pm);
    }

    if (createAST) {
      int astLevel = ((ASTHolderCUInfo) info).astLevel;
      org.eclipse.jdt.core.dom.CompilationUnit cu = AST.convertCompilationUnit(astLevel, compilationUnitDeclaration, options, computeProblems, source, reconcileFlags, pm);
View Full Code Here

}
/**
* Creates a new parser.
*/
protected SourceElementParser getParser(Map settings) {
  return new SourceElementParser(this, new DefaultProblemFactory(), new CompilerOptions(settings), false/*don't report local declarations*/, true/*optimize string literals*/);
}
 
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.SourceElementParser

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.