Package org.eclipse.jdt.internal.compiler.parser

Examples of org.eclipse.jdt.internal.compiler.parser.Parser


        focusOpenable = (Openable)focus.getCompilationUnit();
      }
    }

    // build type bindings
    Parser parser = new Parser(this.lookupEnvironment.problemReporter, true);
    for (int i = 0; i < openablesLength; i++) {
      Openable openable = openables[i];
      if (openable instanceof org.eclipse.jdt.core.ICompilationUnit) {
        org.eclipse.jdt.core.ICompilationUnit cu = (org.eclipse.jdt.core.ICompilationUnit)openable;

        // contains a potential subtype as a local or anonymous type?
        boolean containsLocalType = false;
        if (localTypes == null) { // case of hierarchy on region
          containsLocalType = true;
        } else {
          IPath path = cu.getPath();
          containsLocalType = localTypes.contains(path.toString());
        }

        // build parsed unit
        CompilationUnitDeclaration parsedUnit = null;
        if (cu.isOpen()) {
          // create parsed unit from source element infos
          CompilationResult result = new CompilationResult((ICompilationUnit)cu, i, openablesLength, this.options.maxProblemsPerUnit);
          SourceTypeElementInfo[] typeInfos = null;
          try {
            IType[] topLevelTypes = cu.getTypes();
            int topLevelLength = topLevelTypes.length;
            if (topLevelLength == 0) continue; // empty cu: no need to parse (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=65677)
            typeInfos = new SourceTypeElementInfo[topLevelLength];
            for (int j = 0; j < topLevelLength; j++) {
              IType topLevelType = topLevelTypes[j];
              typeInfos[j] = (SourceTypeElementInfo)((JavaElement)topLevelType).getElementInfo();
            }
          } catch (JavaModelException e) {
            // types/cu exist since cu is opened
          }
          int flags = !containsLocalType
            ? SourceTypeConverter.MEMBER_TYPE
            : SourceTypeConverter.FIELD_AND_METHOD | SourceTypeConverter.MEMBER_TYPE | SourceTypeConverter.LOCAL_TYPE;
          parsedUnit =
            SourceTypeConverter.buildCompilationUnit(
              typeInfos,
              flags,
              this.lookupEnvironment.problemReporter,
              result);
         
          // We would have got all the necessary local types by now and hence there is no further need
          // to parse the method bodies. Parser.getMethodBodies, which is called latter in this function,
          // will not parse the method statements if ASTNode.HasAllMethodBodies is set.
          if (containsLocalType)   parsedUnit.bits |= ASTNode.HasAllMethodBodies;
        } else {
          // create parsed unit from file
          IFile file = (IFile) cu.getResource();
          ICompilationUnit sourceUnit = this.builder.createCompilationUnitFromPath(openable, file);

          CompilationResult unitResult = new CompilationResult(sourceUnit, i, openablesLength, this.options.maxProblemsPerUnit);
          parsedUnit = parser.dietParse(sourceUnit, unitResult);
        }

        if (parsedUnit != null) {
          hasLocalType[unitsIndex] = containsLocalType;
          cus[unitsIndex] = cu;
          parsedUnits[unitsIndex++] = parsedUnit;
          try {
            this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/);
            if (openable.equals(focusOpenable)) {
              focusUnit = parsedUnit;
            }
          } catch (AbortCompilation e) {
            // classpath problem for this type: ignore
          }
        }
      } else {
        // cache binary type binding
        ClassFile classFile = (ClassFile)openable;
        IBinaryType binaryType = (IBinaryType) JavaModelManager.getJavaModelManager().getInfo(classFile.getType());
        if (binaryType == null) {
          // create binary type from file
          if (classFile.getPackageFragmentRoot().isArchive()) {
            binaryType = this.builder.createInfoFromClassFileInJar(classFile);
          } else {
            IResource file = classFile.resource();
            binaryType = this.builder.createInfoFromClassFile(classFile, file);
          }
        }
        if (binaryType != null) {
          try {
            BinaryTypeBinding binaryTypeBinding = this.lookupEnvironment.cacheBinaryType(binaryType, false/*don't need field and method (bug 125067)*/, null /*no access restriction*/);
            remember(binaryType, binaryTypeBinding);
            if (openable.equals(focusOpenable)) {
              focusBinaryBinding = binaryTypeBinding;
            }
          } catch (AbortCompilation e) {
            // classpath problem for this type: ignore
          }
        }
      }
    }

    // remember type declaration of focus if local/anonymous early (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=210498)
    TypeDeclaration focusLocalType = null;
    if (focus != null && focusBinaryBinding == null && focusUnit != null && ((Member)focus).getOuterMostLocalContext() != null) {
      focusLocalType = new ASTNodeFinder(focusUnit).findType(focus);
    }


    for (int i = 0; i <= this.typeIndex; i++) {
      IGenericType suppliedType = this.typeModels[i];
      if (suppliedType != null && suppliedType.isBinaryType()) {
        CompilationUnitDeclaration previousUnitBeingCompleted = this.lookupEnvironment.unitBeingCompleted;
        // fault in its hierarchy...
        try {
          // ensure that unitBeingCompleted is set so that we don't get an AbortCompilation for a missing type
          // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=213249 )
          if (previousUnitBeingCompleted == null) {
            this.lookupEnvironment.unitBeingCompleted = FakeUnit;
          }
          ReferenceBinding typeBinding = this.typeBindings[i];
          typeBinding.superclass();
          typeBinding.superInterfaces();
        } catch (AbortCompilation e) {
          // classpath problem for this type: ignore
        } finally {
          this.lookupEnvironment.unitBeingCompleted = previousUnitBeingCompleted;
        }
      }
    }

    // complete type bindings (i.e. connect super types)
    for (int i = 0; i < unitsIndex; i++) {
      CompilationUnitDeclaration parsedUnit = parsedUnits[i];
      if (parsedUnit != null) {
        try {
          if (hasLocalType[i]) { // NB: no-op if method bodies have been already parsed
            if (monitor != null && monitor.isCanceled())
              throw new OperationCanceledException();
            parser.getMethodBodies(parsedUnit);
          }
        } catch (AbortCompilation e) {
          // classpath problem for this type: don't try to resolve (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49809)
          hasLocalType[i] = false;
        }
View Full Code Here


  public static void parse(ICompilationUnit[] compilationUnits, ASTRequestor astRequestor, int apiLevel, Map options, int flags, IProgressMonitor monitor) {
    try {
      CompilerOptions compilerOptions = new CompilerOptions(options);
      compilerOptions.ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
      Parser parser = new CommentRecorderParser(
        new ProblemReporter(
            DefaultErrorHandlingPolicies.proceedWithAllProblems(),
            compilerOptions,
            new DefaultProblemFactory()),
        false);
      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

      int flags,
      IProgressMonitor monitor) {
    try {
      CompilerOptions compilerOptions = new CompilerOptions(options);
      compilerOptions.ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
      Parser parser = new CommentRecorderParser(
        new ProblemReporter(
            DefaultErrorHandlingPolicies.proceedWithAllProblems(),
            compilerOptions,
            new DefaultProblemFactory()),
        false);
      int unitLength = sourceUnits.length;
      if (monitor != null) monitor.beginTask("", unitLength); //$NON-NLS-1$
      for (int i = 0; i < unitLength; i++) {
        char[] contents = null;
        String encoding = encodings != null ? encodings[i] : null;
        try {
          contents = Util.getFileCharContent(new File(sourceUnits[i]), encoding);
        } catch(IOException e) {
          // go to the next unit
          continue;
        }
        if (contents == null) {
          // go to the next unit
          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

    CompilerOptions compilerOptions = new CompilerOptions(settings);
    boolean statementsRecovery = (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0;
    compilerOptions.performMethodsFullRecovery = statementsRecovery;
    compilerOptions.performStatementsRecovery = statementsRecovery;
    compilerOptions.ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
    Parser parser = new CommentRecorderParser(
      new ProblemReporter(
          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;
View Full Code Here

    JustJavadocParser(ProblemReporter reporter, String mainTypeName) {
      super(makeDummyParser(reporter, mainTypeName));
    }
   
    private static Parser makeDummyParser(ProblemReporter reporter, String mainTypeName) {
      Parser parser = new Parser(reporter, false);
      CompilationResult cr = new CompilationResult((mainTypeName + ".java").toCharArray(), 0, 1, 0);
      parser.compilationUnit = new CompilationUnitDeclaration(reporter, cr, 0);
      return parser;
    }
View Full Code Here

            CompilerOptions options = createCompilerOptions();
            ProblemReporter problemReporter = new ProblemReporter(
                    DefaultErrorHandlingPolicies.exitOnFirstError(),
                    options,
                    new DefaultProblemFactory());
            mParser = new Parser(problemReporter,
                    options.parseLiteralExpressionsAsConstants);
            mParser.javadocParser.checkDocComment = false;
        }
        return mParser;
    }
View Full Code Here

    private CompilationUtils() {}

    public static JavaCompilation compileSource(String source) {
        CompilerOptions options = getDefaultCompilerOptions();
        Parser parser = createCommentRecorderParser(options);
        ICompilationUnit cu = createCompilationunit(source, "");
        CompilationResult compilationResult = createDefaultCompilationResult(cu, options);
        return new JavaCompilation(parser.parse(cu, compilationResult), parser.scanner);
    }
View Full Code Here

        ICompilationUnit cu = new CompilationUnit(source.toCharArray(), filename, null);
        return cu;
    }

    private static Parser createCommentRecorderParser(CompilerOptions options) {
        Parser parser =
                new CommentRecorderParser(new ProblemReporter(
                        DefaultErrorHandlingPolicies.proceedWithAllProblems(),
                        options,
                        new DefaultProblemFactory()), false);
        return parser;
View Full Code Here

     *            of the file to compile (relative to {@value #TEST_DATA_BASE_DIR}).
     * @return the compilation of the file
     */
    public static JavaCompilation compileFile(String filename) {
        CompilerOptions options = getDefaultCompilerOptions();
        Parser parser = createCommentRecorderParser(options);
        ICompilationUnit cu = createCompilationunit(getContentOfFile(TEST_DATA_BASE_DIR + filename), filename);
        CompilationResult compilationResult = createDefaultCompilationResult(cu, options);
        return new JavaCompilation(parser.parse(cu, compilationResult), parser.scanner);
    }
View Full Code Here

     * @return the compilation of the Java source
     * @throws InvalidSyntaxException if the file has syntax errors.
     */
    public static JavaCompilation compile(String source, String fileName) {
        CompilerOptions options = getDefaultCompilerOptions();
        Parser parser = createCommentRecorderParser(options);
        ICompilationUnit cu = createCompilationUnit(source, fileName);
        CompilationResult compilationResult = createDefaultCompilationResult(cu, options);
        JavaCompilation javaCompilation = new JavaCompilation(parser.parse(cu, compilationResult), parser.scanner);
       
        if (compilationResult.hasSyntaxError) {
          throw new InvalidSyntaxException(new String(compilationResult.getFileName()), compilationResult.toString());
        }
   
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.parser.Parser

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.