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

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


    char[][] specifiedTags = null;
    switch (kind) {
      case Scope.COMPILATION_UNIT_SCOPE:
        // bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=255752
        // Check for FAKE_TYPE_NAME to allow proposals (@see CompletionParser#consumeCompilationUnit)
        CompilationUnitDeclaration compilationUnit = scope.referenceCompilationUnit();
        if (compilationUnit != null &&
            (compilationUnit.types.length > 0 && compilationUnit.types[0].name == CompletionParser.FAKE_TYPE_NAME)) {
          specifiedTags = CLASS_TAGS;
        } else {
          specifiedTags = COMPILATION_UNIT_TAGS;
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

      int flags) {

    // temporarily connect ourselves to the ASTResolver - must disconnect when done
    astRequestor.compilationUnitResolver = this;
    this.bindingTables = new DefaultBindingResolver.BindingTables();
    CompilationUnitDeclaration unit = null;
    try {
      int length = compilationUnits.length;
      org.eclipse.jdt.internal.compiler.env.ICompilationUnit[] sourceUnits = new 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 (int i = 0; i < this.totalUnits; i++) {
        if (resolvedRequestedSourcesAndKeys(i)) {
          // 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.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = compilationResult.compilationUnit;
            char[] contents = sourceUnit.getContents();
            AST ast = AST.newAST(apiLevel);
            ast.setFlag(flags | AST.RESOLVED_BINDINGS);
            ast.setDefaultNodeFlag(ASTNode.ORIGINAL);
            ASTConverter converter = new ASTConverter(compilerOptions, true/*need to resolve bindings*/, this.monitor);
            BindingResolver resolver = new DefaultBindingResolver(unit.scope, owner, this.bindingTables, (flags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0, this.fromJavaProject);
            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);

            // 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.put(fileName, null); // mark it as removed
          }

          // requested binding
          Object key = this.requestedKeys.get(fileName);
          if (key != null) {
            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.requestedKeys.put(fileName, null); // mark it as removed
          }
        } 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

      int flags) {

    // temporarily connect ourselves to the ASTResolver - must disconnect when done
    astRequestor.compilationUnitResolver = this;
    this.bindingTables = new DefaultBindingResolver.BindingTables();
    CompilationUnitDeclaration unit = null;
    try {
      int length = sourceCompilationUnits.length;
      org.eclipse.jdt.internal.compiler.env.ICompilationUnit[] sourceUnits = new org.eclipse.jdt.internal.compiler.env.ICompilationUnit[length];
      int count = 0;
      for (int i = 0; i < length; i++) {
        char[] contents = null;
        String encoding = encodings != null ? encodings[i] : null;
        String sourceUnitPath = sourceCompilationUnits[i];
        try {
          contents = Util.getFileCharContent(new File(sourceUnitPath), encoding);
        } catch(IOException e) {
          // go to the next unit
          continue;
        }
        if (contents == null) {
          // go to the next unit
          continue;
        }
        sourceUnits[count++] = new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(contents, sourceUnitPath, encoding);
      }
      beginToCompile(sourceUnits, bindingKeys);
      // process all units (some more could be injected in the loop by the lookup environment)
      for (int i = 0; i < this.totalUnits; i++) {
        if (resolvedRequestedSourcesAndKeys(i)) {
          // 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();
          org.eclipse.jdt.internal.compiler.env.ICompilationUnit source = (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) this.requestedSources.get(fileName);
          if (source != null) {
            // convert AST
            CompilationResult compilationResult = unit.compilationResult;
            org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = compilationResult.compilationUnit;
            char[] contents = sourceUnit.getContents();
            AST ast = AST.newAST(apiLevel);
            ast.setFlag(flags | AST.RESOLVED_BINDINGS);
            ast.setDefaultNodeFlag(ASTNode.ORIGINAL);
            ASTConverter converter = new ASTConverter(compilerOptions, true/*need to resolve bindings*/, this.monitor);
            BindingResolver resolver = new DefaultBindingResolver(unit.scope, null, this.bindingTables, (flags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0, this.fromJavaProject);
            ast.setBindingResolver(resolver);
            converter.setAST(ast);
            CompilationUnit compilationUnit = converter.convert(unit, contents);
            compilationUnit.setTypeRoot(null);
            compilationUnit.setLineEndTable(compilationResult.getLineSeparatorPositions());
            ast.setDefaultNodeFlag(0);
            ast.setOriginalModificationCount(ast.modificationCount());

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

            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.put(fileName, null); // mark it as removed
          }

          // requested binding
          Object key = this.requestedKeys.get(fileName);
          if (key != null) {
            if (key instanceof BindingKeyResolver) {
              reportBinding(key, astRequestor, unit);
              worked(1);
            } else if (key instanceof ArrayList) {
              Iterator iterator = ((ArrayList) key).iterator();
              while (iterator.hasNext()) {
                reportBinding(iterator.next(), astRequestor, 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.requestedKeys.put(fileName, null); // mark it as removed
          }
        } 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

        // build and record parsed units
        this.parseThreshold = 0; // will request a full parse
        beginToCompile(new org.eclipse.jdt.internal.compiler.env.ICompilationUnit[] { sourceUnit });
        // find the right unit from what was injected via accept(ICompilationUnit,..):
        for (int i=0, max = this.totalUnits; i < max; i++) {
          CompilationUnitDeclaration currentCompilationUnitDeclaration = this.unitsToProcess[i];
          if (currentCompilationUnitDeclaration != null
              && currentCompilationUnitDeclaration.compilationResult.compilationUnit == sourceUnit) {
            unit = currentCompilationUnitDeclaration;
            break;
          }
View Full Code Here

    case ProblemSeverities.Error :
      record(problem, unitResult, referenceContext, mandatory);
      if ((severity & ProblemSeverities.Fatal) != 0) {
        // don't abort or tag as error if the error is suppressed
        if (!referenceContext.hasErrors() && !mandatory && this.options.suppressOptionalErrors) {
          CompilationUnitDeclaration unitDecl = referenceContext.getCompilationUnitDeclaration();
          if (unitDecl != null && unitDecl.isSuppressed(problem)) {
            return;
          }
        }
        referenceContext.tagAsHavingErrors();
        // should abort ?
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.