// 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 | (isJava8 ? SourceTypeConverter.METHOD : 0)
: 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;