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

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


      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

      this.compilationUnit = handle;
    }
  }

  private void computeVisibleElementBindings() {
    CompilationUnitDeclaration previousUnitBeingCompleted = this.lookupEnvironment.unitBeingCompleted;
    this.lookupEnvironment.unitBeingCompleted = this.compilationUnitDeclaration;
    try {
      this.hasComputedVisibleElementBindings = true;
 
      Scope scope = this.assistScope;
View Full Code Here

          System.arraycopy(typeVariables, 0, typeVariables = new TypeVariableBinding[count], 0, count);
        }
      }
    }

    CompilationUnitDeclaration previousUnitBeingCompleted = this.lookupEnvironment.unitBeingCompleted;
    this.lookupEnvironment.unitBeingCompleted = this.compilationUnitDeclaration;
    try {

      SignatureWrapper wrapper = new SignatureWrapper(replacePackagesDot(typeSignature.toCharArray()));
      assignableTypeBinding = this.lookupEnvironment.getTypeFromTypeSignature(wrapper, typeVariables, this.assistScope.enclosingClassScope().referenceContext.binding, null);
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

  DefaultBindingResolver(LookupEnvironment lookupEnvironment, WorkingCopyOwner workingCopyOwner, BindingTables bindingTables, boolean isRecoveringBindings, boolean fromJavaProject) {
    this.newAstToOldAst = new HashMap();
    this.astNodesToBlockScope = new HashMap();
    this.bindingsToAstNodes = new HashMap();
    this.bindingTables = bindingTables;
    this.scope = new CompilationUnitScope(new CompilationUnitDeclaration(null, null, -1), lookupEnvironment);
    this.workingCopyOwner = workingCopyOwner;
    this.isRecoveringBindings = isRecoveringBindings;
    this.fromJavaProject = fromJavaProject;
  }
View Full Code Here

            return null;
          }
        }
      }
    } else if (node instanceof CompilationUnitDeclaration) {
      CompilationUnitDeclaration compilationUnitDeclaration = (CompilationUnitDeclaration) node;
      org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = compilationUnitDeclaration.types;
      if (types == null || types.length == 0) {
        return null;
      }
      org.eclipse.jdt.internal.compiler.ast.TypeDeclaration type = types[0];
View Full Code Here

    }
    return null;
  }

  private TextEdit formatCompilationUnit(String source, int indentationLevel, String lineSeparator, IRegion[] regions, boolean includeComments) {
    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

      boolean mandatory = ((severity & ProblemSeverities.Optional) == 0);
      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.