use of org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit in project bazel-jdt-java-toolchain by salesforce.
the class CompilationUnitDeclaration method resolve.
public void resolve() {
int startingTypeIndex = 0;
boolean isPackageInfo = isPackageInfo();
boolean isModuleInfo = isModuleInfo();
if (this.types != null && isPackageInfo) {
// resolve synthetic type declaration
final TypeDeclaration syntheticTypeDeclaration = this.types[0];
// set empty javadoc to avoid missing warning (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=95286)
if (syntheticTypeDeclaration.javadoc == null) {
syntheticTypeDeclaration.javadoc = new Javadoc(syntheticTypeDeclaration.declarationSourceStart, syntheticTypeDeclaration.declarationSourceStart);
}
syntheticTypeDeclaration.resolve(this.scope);
/*
* resolve javadoc package if any, skip this step if we don't have a valid scope due to an earlier error (bug 252555)
* we do it now as the javadoc in the fake type won't be resolved. The peculiar usage of MethodScope to resolve the
* package level javadoc is because the CU level resolve method is a NOP to mimic Javadoc's behavior and can't be used
* as such.
*/
if (this.javadoc != null && syntheticTypeDeclaration.staticInitializerScope != null) {
this.javadoc.resolve(syntheticTypeDeclaration.staticInitializerScope);
}
startingTypeIndex = 1;
} else if (this.moduleDeclaration != null && isModuleInfo) {
if (this.javadoc != null) {
this.javadoc.resolve(this.moduleDeclaration.scope);
} else if (this.moduleDeclaration.binding != null) {
ProblemReporter reporter = this.scope.problemReporter();
int severity = reporter.computeSeverity(IProblem.JavadocMissing);
if (severity != ProblemSeverities.Ignore) {
reporter.javadocModuleMissing(this.moduleDeclaration.declarationSourceStart, this.moduleDeclaration.bodyStart, severity);
}
}
} else {
// resolve compilation unit javadoc package if any
if (this.javadoc != null) {
this.javadoc.resolve(this.scope);
}
}
if (this.currentPackage != null && this.currentPackage.annotations != null && !isPackageInfo) {
this.scope.problemReporter().invalidFileNameForPackageAnnotations(this.currentPackage.annotations[0]);
}
try {
if (this.types != null) {
for (int i = startingTypeIndex, count = this.types.length; i < count; i++) {
this.types[i].resolve(this.scope);
}
}
if (!this.compilationResult.hasMandatoryErrors())
checkUnusedImports();
reportNLSProblems();
} catch (AbortCompilationUnit e) {
this.ignoreFurtherInvestigation = true;
return;
}
}
use of org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit in project bazel-jdt-java-toolchain by salesforce.
the class CompilationUnitDeclaration method traverse.
public void traverse(ASTVisitor visitor, CompilationUnitScope unitScope, boolean skipOnError) {
if (skipOnError && this.ignoreFurtherInvestigation)
return;
try {
if (visitor.visit(this, this.scope)) {
if (this.types != null && isPackageInfo()) {
// resolve synthetic type declaration
final TypeDeclaration syntheticTypeDeclaration = this.types[0];
// resolve javadoc package if any
final MethodScope methodScope = syntheticTypeDeclaration.staticInitializerScope;
// Don't traverse in null scope and invite trouble a la bug 252555.
if (this.javadoc != null && methodScope != null) {
this.javadoc.traverse(visitor, methodScope);
}
// Don't traverse in null scope and invite trouble a la bug 252555.
if (this.currentPackage != null && methodScope != null) {
final Annotation[] annotations = this.currentPackage.annotations;
if (annotations != null) {
int annotationsLength = annotations.length;
for (int i = 0; i < annotationsLength; i++) {
annotations[i].traverse(visitor, methodScope);
}
}
}
}
if (this.currentPackage != null) {
this.currentPackage.traverse(visitor, this.scope);
}
if (this.imports != null) {
int importLength = this.imports.length;
for (int i = 0; i < importLength; i++) {
this.imports[i].traverse(visitor, this.scope);
}
}
if (this.types != null) {
int typesLength = this.types.length;
for (int i = 0; i < typesLength; i++) {
this.types[i].traverse(visitor, this.scope);
}
}
if (this.isModuleInfo() && this.moduleDeclaration != null) {
this.moduleDeclaration.traverse(visitor, this.scope);
}
}
visitor.endVisit(this, this.scope);
} catch (AbortCompilationUnit e) {
// ignore
}
}
use of org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit in project bazel-jdt-java-toolchain by salesforce.
the class EclipseCompilerImpl method getCompilationUnits.
@Override
public CompilationUnit[] getCompilationUnits() {
// This method is largely a copy of Main#getCompilationUnits()
if (this.compilationUnits == null)
return EclipseCompilerImpl.NO_UNITS;
HashtableOfObject knownFileNames = new HashtableOfObject();
ArrayList<CompilationUnit> units = new ArrayList<>();
for (int round = 0; round < 2; round++) {
int i = 0;
for (final JavaFileObject javaFileObject : this.compilationUnits) {
String name = javaFileObject.getName();
char[] charName = name.toCharArray();
boolean isModuleInfo = CharOperation.endsWith(charName, TypeConstants.MODULE_INFO_FILE_NAME);
if (isModuleInfo == (round == 0)) {
// 1st round: modules, 2nd round others (to ensure populating pathToModCU well in time)
if (knownFileNames.get(charName) != null)
// $NON-NLS-1$
throw new IllegalArgumentException(this.bind("unit.more", name));
knownFileNames.put(charName, charName);
boolean found = false;
try {
if (this.fileManager.hasLocation(StandardLocation.SOURCE_PATH)) {
found = this.fileManager.contains(StandardLocation.SOURCE_PATH, javaFileObject);
}
if (!found) {
if (this.fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH)) {
found = this.fileManager.contains(StandardLocation.MODULE_SOURCE_PATH, javaFileObject);
}
}
} catch (IOException e) {
// Not found.
}
if (!found) {
File file = new File(name);
if (!file.exists())
// $NON-NLS-1$
throw new IllegalArgumentException(this.bind("unit.missing", name));
}
CompilationUnit cu = new CompilationUnit(null, name, null, this.destinationPaths[i], shouldIgnoreOptionalProblems(this.ignoreOptionalProblemsFromFolders, name.toCharArray()), this.modNames[i]) {
@Override
public char[] getContents() {
try {
return javaFileObject.getCharContent(true).toString().toCharArray();
} catch (IOException e) {
e.printStackTrace();
throw new AbortCompilationUnit(null, e, null);
}
}
};
units.add(cu);
this.javaFileObjectMap.put(cu, javaFileObject);
}
i++;
}
}
CompilationUnit[] result = new CompilationUnit[units.size()];
units.toArray(result);
return result;
}
use of org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit in project bazel-jdt-java-toolchain by salesforce.
the class EclipseCompilerImpl method handleLocations.
protected void handleLocations() {
ArrayList<FileSystem.Classpath> fileSystemClasspaths = new ArrayList<>();
EclipseFileManager eclipseJavaFileManager = null;
StandardJavaFileManager standardJavaFileManager = null;
JavaFileManager javaFileManager = null;
boolean havePlatformPaths = false;
boolean haveClassPaths = false;
if (this.fileManager instanceof EclipseFileManager) {
eclipseJavaFileManager = (EclipseFileManager) this.fileManager;
}
if (this.fileManager instanceof StandardJavaFileManager) {
standardJavaFileManager = (StandardJavaFileManager) this.fileManager;
}
javaFileManager = this.fileManager;
if (eclipseJavaFileManager != null) {
if ((eclipseJavaFileManager.flags & EclipseFileManager.HAS_ENDORSED_DIRS) == 0 && (eclipseJavaFileManager.flags & EclipseFileManager.HAS_BOOTCLASSPATH) != 0) {
fileSystemClasspaths.addAll(this.handleEndorseddirs(null));
}
}
Iterable<? extends File> locationFiles = null;
if (standardJavaFileManager != null) {
locationFiles = standardJavaFileManager.getLocation(StandardLocation.PLATFORM_CLASS_PATH);
if (locationFiles != null) {
for (File file : locationFiles) {
if (file.isDirectory()) {
List<Classpath> platformLocations = getPlatformLocations(file);
if (standardJavaFileManager instanceof EclipseFileManager) {
if (platformLocations.size() == 1) {
Classpath jrt = platformLocations.get(0);
if (jrt instanceof ClasspathJrt) {
ClasspathJrt classpathJrt = (ClasspathJrt) jrt;
// TODO: double check, should it be platform or system module?
try {
EclipseFileManager efm = (EclipseFileManager) standardJavaFileManager;
// XXX EclipseFileManager should close jrtfs but it looks like standardJavaFileManager is never closed
@SuppressWarnings("resource") JrtFileSystem // Was leaking new JrtFileSystem(classpathJrt.file):
jrtfs = efm.getJrtFileSystem(classpathJrt.file);
efm.locationHandler.newSystemLocation(StandardLocation.SYSTEM_MODULES, jrtfs);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
fileSystemClasspaths.addAll(platformLocations);
// Only possible scenario is, we have one and only entry representing the Java home.
break;
} else {
Classpath classpath = FileSystem.getClasspath(file.getAbsolutePath(), null, null, this.options, this.releaseVersion);
if (classpath != null) {
fileSystemClasspaths.add(classpath);
havePlatformPaths = true;
}
}
}
}
} else if (javaFileManager != null) {
File javaHome = Util.getJavaHome();
long jdkLevel = Util.getJDKLevel(javaHome);
if (jdkLevel >= ClassFileConstants.JDK9) {
Classpath systemClasspath = getSystemClasspath(javaHome, jdkLevel);
Classpath classpath = new ClasspathJsr199(systemClasspath, this.fileManager, StandardLocation.SYSTEM_MODULES);
fileSystemClasspaths.add(classpath);
classpath = new ClasspathJsr199(systemClasspath, this.fileManager, StandardLocation.PLATFORM_CLASS_PATH);
fileSystemClasspaths.add(classpath);
} else {
Classpath classpath = new ClasspathJsr199(this.fileManager, StandardLocation.PLATFORM_CLASS_PATH);
fileSystemClasspaths.add(classpath);
}
havePlatformPaths = true;
}
if (eclipseJavaFileManager != null) {
if ((eclipseJavaFileManager.flags & EclipseFileManager.HAS_EXT_DIRS) == 0 && (eclipseJavaFileManager.flags & EclipseFileManager.HAS_BOOTCLASSPATH) != 0) {
fileSystemClasspaths.addAll(this.handleExtdirs(null));
}
}
if (standardJavaFileManager != null) {
locationFiles = standardJavaFileManager.getLocation(StandardLocation.SOURCE_PATH);
if (locationFiles != null) {
for (File file : locationFiles) {
Classpath classpath = FileSystem.getClasspath(file.getAbsolutePath(), null, null, this.options, this.releaseVersion);
if (classpath != null) {
fileSystemClasspaths.add(classpath);
}
}
}
locationFiles = standardJavaFileManager.getLocation(StandardLocation.CLASS_PATH);
if (locationFiles != null) {
for (File file : locationFiles) {
Classpath classpath = FileSystem.getClasspath(file.getAbsolutePath(), null, null, this.options, this.releaseVersion);
if (classpath != null) {
fileSystemClasspaths.add(classpath);
haveClassPaths = true;
}
}
}
locationFiles = standardJavaFileManager.getLocation(StandardLocation.PLATFORM_CLASS_PATH);
if (locationFiles != null) {
for (File file : locationFiles) {
if (file.isDirectory()) {
String javaVersion = getJavaVersion(file);
// $NON-NLS-1$
long jdkLevel = javaVersion.equals("") ? this.complianceLevel : CompilerOptions.versionToJdkLevel(javaVersion);
Classpath systemClasspath = getSystemClasspath(file, jdkLevel);
Classpath classpath = new ClasspathJsr199(systemClasspath, this.fileManager, StandardLocation.PLATFORM_CLASS_PATH);
fileSystemClasspaths.add(classpath);
// Copy over to modules location as well
if (standardJavaFileManager.getLocation(StandardLocation.SYSTEM_MODULES) == null) {
classpath = new ClasspathJsr199(systemClasspath, this.fileManager, StandardLocation.SYSTEM_MODULES);
fileSystemClasspaths.add(classpath);
}
haveClassPaths = true;
// unlikely to have more than one path
break;
}
}
}
locationFiles = standardJavaFileManager.getLocation(StandardLocation.SYSTEM_MODULES);
if (locationFiles != null) {
for (File file : locationFiles) {
if (file.isDirectory()) {
String javaVersion = getJavaVersion(file);
// $NON-NLS-1$
long jdkLevel = javaVersion.equals("") ? this.complianceLevel : CompilerOptions.versionToJdkLevel(javaVersion);
Classpath systemClasspath = getSystemClasspath(file, jdkLevel);
Classpath classpath = new ClasspathJsr199(systemClasspath, this.fileManager, StandardLocation.SYSTEM_MODULES);
fileSystemClasspaths.add(classpath);
// Copy over to platform location as well
if (standardJavaFileManager.getLocation(StandardLocation.PLATFORM_CLASS_PATH) == null) {
classpath = new ClasspathJsr199(systemClasspath, this.fileManager, StandardLocation.PLATFORM_CLASS_PATH);
fileSystemClasspaths.add(classpath);
}
haveClassPaths = true;
// unlikely to have more than one path
break;
}
}
}
try {
Iterable<? extends Path> locationAsPaths = standardJavaFileManager.getLocationAsPaths(StandardLocation.MODULE_SOURCE_PATH);
if (locationAsPaths != null) {
StringBuilder builder = new StringBuilder();
for (Path path : locationAsPaths) {
// Append all of them
builder.append(path.toFile().getCanonicalPath());
builder.append(File.pathSeparator);
}
ArrayList<Classpath> modulepaths = handleModuleSourcepath(builder.toString());
for (Classpath classpath : modulepaths) {
Collection<String> moduleNames = classpath.getModuleNames(null);
for (String modName : moduleNames) {
Path p = Paths.get(classpath.getPath());
standardJavaFileManager.setLocationForModule(StandardLocation.MODULE_SOURCE_PATH, modName, Collections.singletonList(p));
p = Paths.get(classpath.getDestinationPath());
}
}
fileSystemClasspaths.addAll(modulepaths);
}
} catch (IllegalStateException e) {
// Ignore this as JRE 9 throws IllegalStateException for getLocation returning null
} catch (IllegalArgumentException e) {
throw e;
} catch (Exception e) {
this.logger.logException(e);
}
try {
locationFiles = standardJavaFileManager.getLocation(StandardLocation.MODULE_PATH);
if (locationFiles != null) {
for (File file : locationFiles) {
try {
ArrayList<Classpath> modulepaths = handleModulepath(file.getCanonicalPath());
for (Classpath classpath : modulepaths) {
Collection<String> moduleNames = classpath.getModuleNames(null);
for (String string : moduleNames) {
Path path = Paths.get(classpath.getPath());
standardJavaFileManager.setLocationForModule(StandardLocation.MODULE_PATH, string, Collections.singletonList(path));
}
}
fileSystemClasspaths.addAll(modulepaths);
} catch (IOException e) {
throw new AbortCompilationUnit(null, e, null);
}
}
}
} catch (IllegalStateException e) {
// Ignore this as JRE 9 throws IllegalStateException for getLocation returning null
} catch (IllegalArgumentException e) {
throw e;
} catch (Exception e) {
this.logger.logException(e);
}
} else if (javaFileManager != null) {
Classpath classpath = null;
if (this.fileManager.hasLocation(StandardLocation.SOURCE_PATH)) {
classpath = new ClasspathJsr199(this.fileManager, StandardLocation.SOURCE_PATH);
fileSystemClasspaths.add(classpath);
}
// Add the locations to search for in specific order
if (this.fileManager.hasLocation(StandardLocation.UPGRADE_MODULE_PATH)) {
classpath = new ClasspathJsr199(this.fileManager, StandardLocation.UPGRADE_MODULE_PATH);
}
if (this.fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH)) {
classpath = new ClasspathJsr199(this.fileManager, StandardLocation.PATCH_MODULE_PATH);
fileSystemClasspaths.add(classpath);
}
if (this.fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH)) {
classpath = new ClasspathJsr199(this.fileManager, StandardLocation.MODULE_SOURCE_PATH);
fileSystemClasspaths.add(classpath);
}
if (this.fileManager.hasLocation(StandardLocation.MODULE_PATH)) {
classpath = new ClasspathJsr199(this.fileManager, StandardLocation.MODULE_PATH);
fileSystemClasspaths.add(classpath);
}
classpath = new ClasspathJsr199(this.fileManager, StandardLocation.CLASS_PATH);
fileSystemClasspaths.add(classpath);
haveClassPaths = true;
}
if (this.checkedClasspaths == null) {
// not sufficient to resolve all standard classes.
if (!havePlatformPaths)
fileSystemClasspaths.addAll(this.handleBootclasspath(null, null));
if (!haveClassPaths)
fileSystemClasspaths.addAll(this.handleClasspath(null, null));
}
fileSystemClasspaths = FileSystem.ClasspathNormalizer.normalize(fileSystemClasspaths);
final int size = fileSystemClasspaths.size();
if (size != 0) {
this.checkedClasspaths = new FileSystem.Classpath[size];
int i = 0;
for (FileSystem.Classpath classpath : fileSystemClasspaths) {
this.checkedClasspaths[i++] = classpath;
}
}
}
Aggregations