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

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


  // 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);
      ((ASTHolderCUInfo) info).ast = cu;
    }
  } finally {
      if (compilationUnitDeclaration != null) {
        unitInfo.hasFunctionalTypes = compilationUnitDeclaration.hasFunctionalTypes();
          compilationUnitDeclaration.cleanUp();
      }
  }

  return unitInfo.isStructureKnown();
}
View Full Code Here


          }
          return internalCreateASTForKind();
        }
        break;
      case K_COMPILATION_UNIT :
        CompilationUnitDeclaration compilationUnitDeclaration = null;
        try {
          NodeSearcher searcher = null;
          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.eclipse.jdt.internal.core.CompilationUnit that implements
               * both org.eclipse.jdt.core.ICompilationUnit and org.eclipse.jdt.internal.compiler.env.ICompilationUnit
               */
              sourceUnit = (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
              StringWriter stringWriter = new StringWriter();
              PrintWriter writer = null;
              try {
                writer = new PrintWriter(stringWriter);
                e.printStackTrace(writer);
              } finally {
                if (writer != null) writer.close();
              }
              throw new IllegalStateException(String.valueOf(stringWriter.getBuffer()));
            }
          } else if (this.rawSource != null) {
            needToResolveBindings =
              ((this.bits & CompilationUnitResolver.RESOLVE_BINDING) != 0)
              && this.unitName != null
              && (this.project != null
                  || this.classpaths != null
                  || this.sourcepaths != null
                  || ((this.bits & CompilationUnitResolver.INCLUDE_RUNNING_VM_BOOTCLASSPATH) != 0))
              && 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.bits & CompilationUnitResolver.PARTIAL) != 0) {
            searcher = new NodeSearcher(this.focalPointPosition);
          }
          int flags = 0;
          if ((this.bits & CompilationUnitResolver.STATEMENT_RECOVERY) != 0) {
            flags |= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY;
          }
          if (searcher == null && ((this.bits & CompilationUnitResolver.IGNORE_METHOD_BODIES) != 0)) {
            flags |= ICompilationUnit.IGNORE_METHOD_BODIES;
          }
          if (needToResolveBindings) {
            if ((this.bits & CompilationUnitResolver.BINDING_RECOVERY) != 0) {
              flags |= ICompilationUnit.ENABLE_BINDINGS_RECOVERY;
            }
            try {
              // parse and resolve
              compilationUnitDeclaration =
                CompilationUnitResolver.resolve(
                  sourceUnit,
                  this.project,
                  getClasspath(),
                  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,
            this.project != null);
          result.setTypeRoot(this.typeRoot);
          return result;
        } finally {
          if (compilationUnitDeclaration != null
              && ((this.bits & CompilationUnitResolver.RESOLVE_BINDING) != 0)) {
            compilationUnitDeclaration.cleanUp();
          }
        }
    }
    throw new IllegalStateException();
  }
View Full Code Here

  if (this.sleepCount <= -1)
    notify(); // wake up writing thread to accept next unit - could be the last one - must avoid deadlock
}

public CompilationUnitDeclaration removeNextUnit() throws Error {
  CompilationUnitDeclaration next = null;
  boolean yield = false;
  synchronized (this) {
    next = this.units[this.currentIndex];
    if (next == null || this.caughtException != null) {
      do {
View Full Code Here

  return null;
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=372012
public void missingNonNullByDefaultAnnotation(TypeDeclaration type) {
  int severity;
  CompilationUnitDeclaration compUnitDecl = type.getCompilationUnitDeclaration();
  String[] arguments;
  if (compUnitDecl.currentPackage == null) {
    severity = computeSeverity(IProblem.MissingNonNullByDefaultAnnotationOnType);
    if (severity == ProblemSeverities.Ignore) return;
    // Default package
View Full Code Here

    // Find the newest of all these.
    //
    lastModified = 0;
    CompilationUnitProvider newestCup = null;
    for (int i = 0; i < goldenCuds.length; i++) {
      CompilationUnitDeclaration cud = goldenCuds[i];
      ICompilationUnitAdapter icua = (ICompilationUnitAdapter) cud.compilationResult.compilationUnit;
      CompilationUnitProvider cup = icua.getCompilationUnitProvider();
      long cupLastModified = cup.getLastModified();
      if (cupLastModified > lastModified) {
        newestCup = cup;
View Full Code Here

    boolean compilationFailed = false;
    if (goldenCuds.length == 0) {
      compilationFailed = true;
    }
    for (int iCud = 0; iCud < goldenCuds.length; iCud++) {
      CompilationUnitDeclaration cud = goldenCuds[iCud];
      CompilationResult result = cud.compilationResult();
      if (result.hasErrors()) {
        compilationFailed = true;
        // Early out if we don't need to itemize.
        if (!itemizeErrors) {
          break;
View Full Code Here

        // If the referenced type belongs to a compilation unit that is
        // not in the list of valid units, then the unit in which it
        // is referenced must also be removed.
        //
        String referencedFn = String.valueOf(referencedType.getFileName());
        CompilationUnitDeclaration referencedCud = (CompilationUnitDeclaration) cudsByFileName.get(referencedFn);
        if (referencedCud == null) {
          // This is a referenced to a bad or non-existent unit.
          // So, remove the referrer's unit if it hasn't been already.
          //
          String referrerFn = String.valueOf(unitOfReferrer.getFileName());
          if (cudsByFileName.containsKey(referrerFn)
              && !pendingRemovals.contains(referrerFn)) {
            TreeLogger branch = logger.branch(TreeLogger.TRACE,
                "Cascaded removal of compilation unit '" + referrerFn + "'",
                null);
            final String badTypeName = CharOperation.toString(referencedType.compoundName);
            branch.branch(TreeLogger.TRACE,
                "Due to reference to unavailable type: " + badTypeName, null);
            pendingRemovals.add(referrerFn);
          }
        }
      }
    };

    do {
      // Perform any pending removals.
      //
      for (Iterator iter = pendingRemovals.iterator(); iter.hasNext();) {
        String fnToRemove = (String) iter.next();
        Object removed = cudsByFileName.remove(fnToRemove);
        assert (removed != null);
      }

      // Start fresh for this iteration.
      //
      pendingRemovals.clear();

      // Find references to type in units that aren't valid.
      //
      for (Iterator iter = cudsByFileName.values().iterator(); iter.hasNext();) {
        CompilationUnitDeclaration cud = (CompilationUnitDeclaration) iter.next();
        cud.traverse(trv, cud.scope);
      }
    } while (!pendingRemovals.isEmpty());
  }
View Full Code Here

      Map cudsByFileName) {
    // Start by removing units with a known problem.
    //
    boolean anyRemoved = false;
    for (Iterator iter = cudsByFileName.values().iterator(); iter.hasNext();) {
      CompilationUnitDeclaration cud = (CompilationUnitDeclaration) iter.next();
      CompilationResult result = cud.compilationResult;
      IProblem[] errors = result.getErrors();
      if (errors != null && errors.length > 0) {
        anyRemoved = true;
        iter.remove();

        String fileName = CharOperation.charToString(cud.getFileName());
        char[] source = cud.compilationResult.compilationUnit.getContents();
        Util.maybeDumpSource(logger, fileName, source, null);
        logger.log(TreeLogger.TRACE, "Removing problematic compilation unit '"
            + fileName + "'", null);
      }
View Full Code Here

    // Build a list that makes it easy to remove problems.
    //
    final Map cudsByFileName = new HashMap();
    for (int i = 0; i < cuds.length; i++) {
      CompilationUnitDeclaration cud = cuds[i];
      char[] location = cud.getFileName();
      cudsByFileName.put(String.valueOf(location), cud);
    }
    cacheManager.getCudsByFileName().putAll(cudsByFileName);

    // Remove bad cuds and all the other cuds that are affected.
    //
    removeUnitsWithErrors(logger, cudsByFileName);

    // Also remove any compilation units that we've seen before.
    //
    for (Iterator iter = cudsByFileName.values().iterator(); iter.hasNext();) {
      CompilationUnitDeclaration cud = (CompilationUnitDeclaration) iter.next();
      // If we've seen this compilation unit before, the type oracle will
      // tell us about it and so we don't assimilate it again.
      //
      ICompilationUnit unit = cud.compilationResult.compilationUnit;
      ICompilationUnitAdapter adapter = ((ICompilationUnitAdapter) unit);
      CompilationUnitProvider cup = adapter.getCompilationUnitProvider();
      JClassType[] seen = oracle.getTypesInCompilationUnit(cup);
      if (seen.length > 0) {
        // This compilation unit has already been assimilated.
        //
        iter.remove();
      }
    }

    // Perform a shallow pass to establish identity for new types.
    //
    final CacheManager.Mapper identityMapper = cacheManager.getIdentityMapper();
    for (Iterator iter = cudsByFileName.values().iterator(); iter.hasNext();) {
      CompilationUnitDeclaration cud = (CompilationUnitDeclaration) iter.next();

      cud.traverse(new ASTVisitor() {
        public boolean visit(TypeDeclaration typeDecl, BlockScope scope) {
          JClassType enclosingType = identityMapper.get((SourceTypeBinding) typeDecl.binding.enclosingType());
          processType(typeDecl, enclosingType, true);
          return true;
        }

        public boolean visit(TypeDeclaration typeDecl, ClassScope scope) {
          JClassType enclosingType = identityMapper.get((SourceTypeBinding) typeDecl.binding.enclosingType());
          processType(typeDecl, enclosingType, false);
          return true;
        }

        public boolean visit(TypeDeclaration typeDecl,
            CompilationUnitScope scope) {
          processType(typeDecl, null, false);
          return true;
        }
      }, cud.scope);
    }

    // Perform a deep pass to resolve all types in terms of our types.
    //
    for (Iterator iter = cudsByFileName.values().iterator(); iter.hasNext();) {
      CompilationUnitDeclaration cud = (CompilationUnitDeclaration) iter.next();
      String loc = String.valueOf(cud.getFileName());
      String processing = "Processing types in compilation unit: " + loc;
      final TreeLogger cudLogger = logger.branch(TreeLogger.SPAM, processing,
          null);
      final char[] source = cud.compilationResult.compilationUnit.getContents();

      cud.traverse(new ASTVisitor() {
        public boolean visit(TypeDeclaration typeDecl, BlockScope scope) {
          if (!resolveTypeDeclaration(cudLogger, source, typeDecl)) {
            String name = String.valueOf(typeDecl.binding.readableName());
            String msg = "Unexpectedly unable to fully resolve type " + name;
            logger.log(TreeLogger.WARN, msg, null);
View Full Code Here

        outSet.addAll(element);
      }
      CompilationUnitDeclaration[] out = new CompilationUnitDeclaration[outSet.size()];
      int i = 0;
      for (Iterator iter = outSet.iterator(); iter.hasNext();) {
        CompilationUnitDeclaration element = (CompilationUnitDeclaration) iter.next();
        out[i] = element;
        i++;
      }
      return out;
    }
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.