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

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


      order.append("[");
      for (int i = 0; i < units.length; i++) {
        if (i != 0) {
          order.append(",");
        }
        CompilationUnitDeclaration declaration = units[i];
        String filename = new String(declaration.getFileName());
        int idx = filename.lastIndexOf('/');
        if (idx > 0) {
          filename = filename.substring(idx + 1);
        }
        idx = filename.lastIndexOf('\\');
View Full Code Here


    }
    return new MultiTextEdit();
  }

  private TextEdit formatCompilationUnit(String source, int indentationLevel, String lineSeparator, int offset, int length) {
    CompilationUnitDeclaration compilationUnitDeclaration = this.codeSnippetParsingUtil.parseCompilationUnit(source.toCharArray(), getDefaultCompilerOptions(), true);
   
    if (lineSeparator != null) {
      this.preferences.line_separator = lineSeparator;
    } else {
      this.preferences.line_separator = Util.LINE_SEPARATOR;
View Full Code Here

        // exit?
        if (Main.this.systemExitWhenFinished && !Main.this.proceedOnError && (localErrorCount > 0)) {
          // ensure dumping problems for enqueued units as well, since may contain primary errors (123476)
          CompilationUnitDeclaration[] queuedUnits = Main.this.batchCompiler.unitsToProcess;
          for (int i = 0, length = Main.this.batchCompiler.totalUnits; i < length; i++) {
            CompilationUnitDeclaration queuedUnit = queuedUnits[i];
            if (queuedUnit == null) continue;
            CompilationResult result = queuedUnit.compilationResult;
            if (result.hasProblems() && !result.hasBeenAccepted) {
              Main.this.logger.logProblems(result.getAllProblems(), result.compilationUnit.getContents(), Main.this);
            }
View Full Code Here

  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;
  CompilationUnitDeclaration unit = parser.parseCompilationUnit(
    new org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit() {
      public char[] getContents() {
        return contents;
      }
      public char[] getMainTypeName() {
        return CompilationUnit.this.getMainTypeName();
      }
      public char[][] getPackageName() {
        return CompilationUnit.this.getPackageName();
      }
      public char[] getFileName() {
        return CompilationUnit.this.getFileName();
      }
    },
    true /*full parse to find local elements*/);
 
  // 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;
  try {
    if (computeProblems) {
      if (problems == null) {
        // report problems to the problem requestor
        problems = new HashMap();
        compilationUnitDeclaration = CompilationUnitProblemFinder.process(unit, this, contents, 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(unit, this, contents, parser, this.owner, problems, createAST, reconcileFlags, pm);
      }
    }
   
    if (createAST) {
      int astLevel = ((ASTHolderCUInfo) info).astLevel;
      org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit cu = AST.convertCompilationUnit(astLevel, unit, contents, options, computeProblems, this, reconcileFlags, pm);
      ((ASTHolderCUInfo) info).ast = cu;
    }
  } finally {
      if (compilationUnitDeclaration != null) {
          compilationUnitDeclaration.cleanUp();
      }
  }
 
  return unitInfo.isStructureKnown();
}
View Full Code Here

          }
          return internalCreateASTForKind();
        }
        break;
      case K_COMPILATION_UNIT :
        CompilationUnitDeclaration compilationUnitDeclaration = null;
        try {
          NodeSearcher searcher = null;
          org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = null;
          WorkingCopyOwner wcOwner = this.workingCopyOwner;
          if (this.typeRoot instanceof ICompilationUnit) {
              /*
               * this.compilationUnitSource is an instance of org.aspectj.org.eclipse.jdt.internal.core.CompilationUnit that implements
               * both org.aspectj.org.eclipse.jdt.core.ICompilationUnit and org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit
               */
              sourceUnit = (org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit) this.typeRoot;
              /*
               * use a BasicCompilation that caches the source instead of using the compilationUnitSource directly
               * (if it is a working copy, the source can change between the parse and the AST convertion)
               * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=75632)
               */
              sourceUnit = new BasicCompilationUnit(sourceUnit.getContents(), sourceUnit.getPackageName(), new String(sourceUnit.getFileName()), this.project);
              wcOwner = ((ICompilationUnit) this.typeRoot).getOwner();
          } else if (this.typeRoot instanceof IClassFile) {
            try {
              String sourceString = this.typeRoot.getSource();
              if (sourceString == null) {
                throw new IllegalStateException();
              }
              PackageFragment packageFragment = (PackageFragment) this.typeRoot.getParent();
              BinaryType type = (BinaryType) this.typeRoot.findPrimaryType();
              IBinaryType binaryType = (IBinaryType) type.getElementInfo();
              // file name is used to recreate the Java element, so it has to be the toplevel .class file name
              char[] fileName = binaryType.getFileName();
              int firstDollar = CharOperation.indexOf('$', fileName);
              if (firstDollar != -1) {
                char[] suffix = SuffixConstants.SUFFIX_class;
                int suffixLength = suffix.length;
                char[] newFileName = new char[firstDollar + suffixLength];
                System.arraycopy(fileName, 0, newFileName, 0, firstDollar);
                System.arraycopy(suffix, 0, newFileName, firstDollar, suffixLength);
                fileName = newFileName;
              }
              sourceUnit = new BasicCompilationUnit(sourceString.toCharArray(), Util.toCharArrays(packageFragment.names), new String(fileName), this.project);
            } catch(JavaModelException e) {
              // an error occured accessing the java element
              throw new IllegalStateException();
            }
          } else if (this.rawSource != null) {
            needToResolveBindings = this.resolveBindings && this.unitName != null && this.project != null && this.compilerOptions != null;
            sourceUnit = new BasicCompilationUnit(this.rawSource, null, this.unitName == null ? "" : this.unitName, this.project); //$NON-NLS-1$
          } else {
            throw new IllegalStateException();
          }
          if (this.partial) {
            searcher = new NodeSearcher(this.focalPointPosition);
          }
          int flags = 0;
          if (this.statementsRecovery) flags |= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY;
          if (needToResolveBindings) {
            if (this.bindingsRecovery) flags |= ICompilationUnit.ENABLE_BINDINGS_RECOVERY;
            try {
              // parse and resolve
              compilationUnitDeclaration =
                CompilationUnitResolver.resolve(
                  sourceUnit,
                  this.project,
                  searcher,
                  this.compilerOptions,
                  this.workingCopyOwner,
                  flags,
                  monitor);
            } catch (JavaModelException e) {
              flags &= ~ICompilationUnit.ENABLE_BINDINGS_RECOVERY;
              compilationUnitDeclaration = CompilationUnitResolver.parse(
                  sourceUnit,
                  searcher,
                  this.compilerOptions,
                  flags);
              needToResolveBindings = false;
            }
          } else {
            compilationUnitDeclaration = CompilationUnitResolver.parse(
                sourceUnit,
                searcher,
                this.compilerOptions,
                flags);
            needToResolveBindings = false;
          }
          CompilationUnit result = CompilationUnitResolver.convert(
            compilationUnitDeclaration,
            sourceUnit.getContents(),
            this.apiLevel,
            this.compilerOptions,
            needToResolveBindings,
            wcOwner,
            needToResolveBindings ? new DefaultBindingResolver.BindingTables() : null,
            flags,
            monitor);
          result.setTypeRoot(this.typeRoot);
          return result;
        } finally {
          if (compilationUnitDeclaration != null && this.resolveBindings) {
            compilationUnitDeclaration.cleanUp();
          }
        }
    }
    throw new IllegalStateException();
  }
View Full Code Here

    // walks the source units
    this.requestedSources = new HashtableOfObject();
    for (int i = 0; i < sourceLength; i++) {
      org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = sourceUnits[i];
      CompilationUnitDeclaration parsedUnit;
      CompilationResult unitResult =
        new CompilationResult(sourceUnit, index++, maxUnits, this.options.maxProblemsPerUnit);
      try {
        if (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 length = compilationUnits.length;
      if (monitor != null) monitor.beginTask("", length); //$NON-NLS-1$
      for (int i = 0; i < length; i++) {
        org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = (org.aspectj.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

          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 null;
    }

    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.aspectj.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;
    CancelableNameEnvironment environment = null;
    CancelableProblemFactory problemFactory = null;
    CompilationUnitResolver resolver = null;
    try {
      environment = new CancelableNameEnvironment(((JavaProject)javaProject), owner, monitor);
      problemFactory = new CancelableProblemFactory(monitor);
      resolver =
        new CompilationUnitResolver(
          environment,
          getHandlingPolicy(),
          getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0),
          getRequestor(),
          problemFactory,
          monitor);

      unit =
        resolver.resolve(
          null, // no existing compilation unit declaration
          sourceUnit,
          nodeSearcher,
          true, // method verification
          true, // analyze code
          true); // 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);
        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);
          unitDeclaration.compilationResult.problemCount = problemCount;
View Full Code Here

  private void resolve(ICompilationUnit[] compilationUnits, String[] bindingKeys, ASTRequestor astRequestor, int apiLevel, Map compilerOptions, WorkingCopyOwner owner, int flags) {

    // temporararily connect ourselves to the ASTResolver - must disconnect when done
    astRequestor.compilationUnitResolver = this;
    this.bindingTables = new DefaultBindingResolver.BindingTables();
    CompilationUnitDeclaration unit = null;
    int i = 0;
    try {
      int length = compilationUnits.length;
      org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit[] sourceUnits = new org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit[length];
      System.arraycopy(compilationUnits, 0, sourceUnits, 0, length);
      beginToCompile(sourceUnits, bindingKeys);
      // process all units (some more could be injected in the loop by the lookup environment)
      for (; i < this.totalUnits; i++) {
        if (this.requestedSources.size() == 0 && this.requestedKeys.size() == 0) {
          // no need to keep resolving if no more ASTs and no more binding keys are needed
          // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=114935
          // cleanup remaining units
          for (; i < this.totalUnits; i++) {
            this.unitsToProcess[i].cleanUp();
            this.unitsToProcess[i] = null;
          }
          break;
        }
        unit = this.unitsToProcess[i];
        try {
          super.process(unit, i); // this.process(...) is optimized to not process already known units

          // requested AST
          char[] fileName = unit.compilationResult.getFileName();
          ICompilationUnit source = (ICompilationUnit) this.requestedSources.get(fileName);
          if (source != null) {
            // convert AST
            CompilationResult compilationResult = unit.compilationResult;
            org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = compilationResult.compilationUnit;
            char[] contents = sourceUnit.getContents();
            // AspectJ Extension start - use the factory
            // old code:
            // AST ast = AST.newAST(apiLevel);
            // new code:
            AST ast = ASTParser.getAST(apiLevel);
            // End AspectJ Extension
            ast.setFlag(flags | AST.RESOLVED_BINDINGS);
            ast.setDefaultNodeFlag(ASTNode.ORIGINAL);
            // AspectJ Extension - use the factory
            // old code:
            // ASTConverter converter = new ASTConverter(compilerOptions, true/*need to resolve bindings*/, this.monitor);
            // new code:
            ASTConverter converter = ASTConverter.getASTConverter(compilerOptions,true,this.monitor);
            // End AspectJ Extension
            BindingResolver resolver = new DefaultBindingResolver(unit.scope, owner, this.bindingTables, (flags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0);
            ast.setBindingResolver(resolver);
            converter.setAST(ast);
            CompilationUnit compilationUnit = converter.convert(unit, contents);
            compilationUnit.setTypeRoot(source);
            compilationUnit.setLineEndTable(compilationResult.getLineSeparatorPositions());
            ast.setDefaultNodeFlag(0);
            ast.setOriginalModificationCount(ast.modificationCount());

            // pass it to requestor
            astRequestor.acceptAST(source, compilationUnit);

            worked(1);
          }

          // requested binding
          Object key = this.requestedKeys.get(fileName);
          if (key instanceof BindingKeyResolver) {
            reportBinding(key, astRequestor, owner, unit);
            worked(1);
          } else if (key instanceof ArrayList) {
            Iterator iterator = ((ArrayList) key).iterator();
            while (iterator.hasNext()) {
              reportBinding(iterator.next(), astRequestor, owner, unit);
              worked(1);
            }
          }

          // remove at the end so that we don't resolve twice if a source and a key for the same file name have been requested
          this.requestedSources.removeKey(fileName);
          this.requestedKeys.removeKey(fileName);
        } finally {
          // cleanup compilation unit result
          unit.cleanUp();
        }
        this.unitsToProcess[i] = null; // release reference to processed unit declaration
        this.requestor.acceptResult(unit.compilationResult.tagAsAccepted());
      }

View Full Code Here

TOP

Related Classes of org.aspectj.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.