Package org.eclipse.jdt.internal.compiler.ast

Examples of org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration


        source,
        "", //$NON-NLS-1$
        compilerOptions.defaultEncoding);

    final CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, compilerOptions.maxProblemsPerUnit);
    CompilationUnitDeclaration compilationUnitDeclaration = new CompilationUnitDeclaration(problemReporter, compilationResult, length);

    ConstructorDeclaration constructorDeclaration = new ConstructorDeclaration(compilationResult);
    constructorDeclaration.sourceEnd  = -1;
    constructorDeclaration.declarationSourceEnd = offset + length - 1;
    constructorDeclaration.bodyStart = offset;
View Full Code Here


  /* (non-Javadoc)
   * @see org.eclipse.jdt.internal.compiler.parser.Parser#endParse(int)
   */
  protected CompilationUnitDeclaration endParse(int act) {
    CompilationUnitDeclaration unit = super.endParse(act);
    if (unit.comments == null) {
      pushOnCommentsStack(0, this.scanner.commentPtr);
      unit.comments = getCommentsPositions();
    }
    return unit;
View Full Code Here

      IJavaProject project = ((SourceTypeElementInfo) sourceTypes[0]).getHandle().getJavaProject();
      this.options.complianceLevel = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_COMPLIANCE, true));
      this.options.sourceLevel = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_SOURCE, true));

      // need to hold onto this
      CompilationUnitDeclaration unit =
        SourceTypeConverter.buildCompilationUnit(
            sourceTypes,//sourceTypes[0] is always toplevel here
            SourceTypeConverter.FIELD_AND_METHOD // need field and methods
            | SourceTypeConverter.MEMBER_TYPE // need member types
            | SourceTypeConverter.FIELD_INITIALIZATION, // need field initialization
View Full Code Here

    JavaProject project = (JavaProject) unitElement.getJavaProject();
    CancelableNameEnvironment environment = null;
    CancelableProblemFactory problemFactory = null;
    CompilationUnitProblemFinder problemFinder = null;
    CompilationUnitDeclaration unit = null;
    try {
      environment = new CancelableNameEnvironment(project, workingCopyOwner, monitor);
      problemFactory = new CancelableProblemFactory(monitor);
      CompilerOptions compilerOptions = getCompilerOptions(project.getOptions(true), creatingAST, ((reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0));
      boolean ignoreMethodBodies = (reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
View Full Code Here

      return this.ast;
    }
    if (this.ast != null)
      return this.ast; // no need to recompute AST if known already

    CompilationUnitDeclaration unit = null;
    try {
      JavaModelManager.getJavaModelManager().abortOnMissingSource.set(Boolean.TRUE);
      CompilationUnit source = workingCopy.cloneCachingContents();
      // find problems if needed
      if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject())
          && (this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0) {
        this.resolveBindings = this.requestorIsActive;
        if (this.problems == null)
          this.problems = new HashMap();
        unit =
          CompilationUnitProblemFinder.process(
            source,
            this.workingCopyOwner,
            this.problems,
            this.astLevel != ICompilationUnit.NO_AST/*creating AST if level is not NO_AST */,
            this.reconcileFlags,
            this.progressMonitor);
        if (this.progressMonitor != null) this.progressMonitor.worked(1);
      }

      // create AST if needed
      if (this.astLevel != ICompilationUnit.NO_AST
          && unit !=null/*unit is null if working copy is consistent && (problem detection not forced || non-Java project) -> don't create AST as per API*/) {
        Map options = workingCopy.getJavaProject().getOptions(true);
        // convert AST
        this.ast =
          AST.convertCompilationUnit(
            this.astLevel,
            unit,
            options,
            this.resolveBindings,
            source,
            this.reconcileFlags,
            this.progressMonitor);
        if (this.ast != null) {
          if (this.deltaBuilder.delta == null) {
            this.deltaBuilder.delta = new JavaElementDelta(workingCopy);
          }
          this.deltaBuilder.delta.changedAST(this.ast);
        }
        if (this.progressMonitor != null) this.progressMonitor.worked(1);
      }
      } catch (JavaModelException e) {
        if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject()))
          throw e;
        // else JavaProject has lost its nature (or most likely was closed/deleted) while reconciling -> ignore
        // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=100919)
      } finally {
      JavaModelManager.getJavaModelManager().abortOnMissingSource.set(null);
          if (unit != null) {
              unit.cleanUp();
          }
      }
    return this.ast;
  }
View Full Code Here

    // walks the source units
    this.requestedSources = new HashtableOfObject();
    for (int i = 0; i < sourceLength; i++) {
      org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = sourceUnits[i];
      CompilationUnitDeclaration parsedUnit;
      CompilationResult unitResult =
        new CompilationResult(sourceUnit, index++, maxUnits, this.options.maxProblemsPerUnit);
      try {
        if (this.options.verbose) {
          this.out.println(
            Messages.bind(Messages.compilation_request,
            new String[] {
              String.valueOf(index++ + 1),
              String.valueOf(maxUnits),
              new String(sourceUnit.getFileName())
            }));
        }
        // diet parsing for large collection of units
        if (this.totalUnits < this.parseThreshold) {
          parsedUnit = this.parser.parse(sourceUnit, unitResult);
        } else {
          parsedUnit = this.parser.dietParse(sourceUnit, unitResult);
        }
        // initial type binding creation
        this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/);
        addCompilationUnit(sourceUnit, parsedUnit);
        this.requestedSources.put(unitResult.getFileName(), sourceUnit);
        worked(1);
      } finally {
        sourceUnits[i] = null; // no longer hold onto the unit
      }
    }

    // walk the binding keys
    this.requestedKeys = new HashtableOfObject();
    for (int i = 0; i < keyLength; i++) {
      BindingKeyResolver resolver = new BindingKeyResolver(bindingKeys[i], this, this.lookupEnvironment);
      resolver.parse(true/*pause after fully qualified name*/);
      // If it doesn't have a type name, then it is either an array type, package or base type, which will definitely not have a compilation unit.
      // Skipping it will speed up performance because the call will open jars. (theodora)
      CompilationUnitDeclaration parsedUnit = resolver.hasTypeName() ? resolver.getCompilationUnitDeclaration() : null;
      if (parsedUnit != null) {
        char[] fileName = parsedUnit.compilationResult.getFileName();
        Object existing = this.requestedKeys.get(fileName);
        if (existing == null)
          this.requestedKeys.put(fileName, resolver);
View Full Code Here

      int unitLength = compilationUnits.length;
      if (monitor != null) monitor.beginTask("", unitLength); //$NON-NLS-1$
      for (int i = 0; i < unitLength; i++) {
        org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) compilationUnits[i];
        CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, compilerOptions.maxProblemsPerUnit);
        CompilationUnitDeclaration compilationUnitDeclaration = parser.dietParse(sourceUnit, compilationResult);

        if (compilationUnitDeclaration.ignoreMethodBodies) {
          compilationUnitDeclaration.ignoreFurtherInvestigation = true;
          // if initial diet parse did not work, no need to dig into method bodies.
          continue;
View Full Code Here

          continue;
        }
        org.eclipse.jdt.internal.compiler.batch.CompilationUnit compilationUnit = new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(contents, sourceUnits[i], encoding);
        org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = compilationUnit;
        CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, compilerOptions.maxProblemsPerUnit);
        CompilationUnitDeclaration compilationUnitDeclaration = parser.dietParse(sourceUnit, compilationResult);

        if (compilationUnitDeclaration.ignoreMethodBodies) {
          compilationUnitDeclaration.ignoreFurtherInvestigation = true;
          // if initial diet parse did not work, no need to dig into method bodies.
          continue;
View Full Code Here

          DefaultErrorHandlingPolicies.proceedWithAllProblems(),
          compilerOptions,
          new DefaultProblemFactory()),
      false);
    CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, compilerOptions.maxProblemsPerUnit);
    CompilationUnitDeclaration compilationUnitDeclaration = parser.dietParse(sourceUnit, compilationResult);

    if (compilationUnitDeclaration.ignoreMethodBodies) {
      compilationUnitDeclaration.ignoreFurtherInvestigation = true;
      // if initial diet parse did not work, no need to dig into method bodies.
      return compilationUnitDeclaration;
    }

    if (nodeSearcher != null) {
      char[] source = parser.scanner.getSource();
      int searchPosition = nodeSearcher.position;
      if (searchPosition < 0 || searchPosition > source.length) {
        // the position is out of range. There is no need to search for a node.
        return compilationUnitDeclaration;
      }

      compilationUnitDeclaration.traverse(nodeSearcher, compilationUnitDeclaration.scope);

      org.eclipse.jdt.internal.compiler.ast.ASTNode node = nodeSearcher.found;
      if (node == null) {
        return compilationUnitDeclaration;
      }
View Full Code Here

      Map options,
      WorkingCopyOwner owner,
      int flags,
      IProgressMonitor monitor) throws JavaModelException {

    CompilationUnitDeclaration unit = null;
    INameEnvironmentWithProgress environment = null;
    CancelableProblemFactory problemFactory = null;
    CompilationUnitResolver resolver = null;
    try {
      if (javaProject == null) {
        Classpath[] allEntries = new Classpath[classpaths.size()];
        classpaths.toArray(allEntries);
        environment = new NameEnvironmentWithProgress(allEntries, null, monitor);
      } else {
        environment = new CancelableNameEnvironment((JavaProject) javaProject, owner, monitor);
      }
      problemFactory = new CancelableProblemFactory(monitor);
      CompilerOptions compilerOptions = getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
      boolean ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
      compilerOptions.ignoreMethodBodies = ignoreMethodBodies;
      resolver =
        new CompilationUnitResolver(
          environment,
          getHandlingPolicy(),
          compilerOptions,
          getRequestor(),
          problemFactory,
          monitor,
          javaProject != null);
      boolean analyzeAndGenerateCode = !ignoreMethodBodies;
      unit =
        resolver.resolve(
          null, // no existing compilation unit declaration
          sourceUnit,
          nodeSearcher,
          true, // method verification
          analyzeAndGenerateCode, // analyze code
          analyzeAndGenerateCode); // generate code
      if (resolver.hasCompilationAborted) {
        // the bindings could not be resolved due to missing types in name environment
        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=86541
        CompilationUnitDeclaration unitDeclaration = parse(sourceUnit, nodeSearcher, options, flags);
        if (unit != null) {
          final int problemCount = unit.compilationResult.problemCount;
          if (problemCount != 0) {
            unitDeclaration.compilationResult.problems = new CategorizedProblem[problemCount];
            System.arraycopy(unit.compilationResult.problems, 0, unitDeclaration.compilationResult.problems, 0, problemCount);
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration

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.