Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Thomann2015-03-16 11:31:59 +0000
committerJayaprakash Arthanareeswaran2015-03-16 16:18:58 +0000
commit30e98d6cc084dfe1b207ffb7493b2de7b6cec8c4 (patch)
tree2f5c9d05e5817dbc368bd65393dccb076d13d1ad /org.eclipse.jdt.compiler.tool
parentf6d7e4c8ebdaaf8a904962804a027a09edc0c0d3 (diff)
downloadeclipse.jdt.core-30e98d6cc084dfe1b207ffb7493b2de7b6cec8c4.tar.gz
eclipse.jdt.core-30e98d6cc084dfe1b207ffb7493b2de7b6cec8c4.tar.xz
eclipse.jdt.core-30e98d6cc084dfe1b207ffb7493b2de7b6cec8c4.zip
Bug 188796 [jsr199] Using JSR199 to extend ECJ
Change-Id: Ic851300c2069ec68675bd77cb24d8af51f328399 Signed-off-by: Olivier Thomann <Olivier_Thomann@ca.ibm.com>
Diffstat (limited to 'org.eclipse.jdt.compiler.tool')
-rw-r--r--org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJsr199.java203
-rw-r--r--org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Archive.java32
-rw-r--r--org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/ArchiveFileObject.java119
-rw-r--r--org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java14
-rw-r--r--org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java284
-rw-r--r--org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java146
-rw-r--r--org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileObject.java15
-rw-r--r--org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java11
-rw-r--r--org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Util.java4
9 files changed, 593 insertions, 235 deletions
diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJsr199.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJsr199.java
new file mode 100644
index 0000000000..24adb24277
--- /dev/null
+++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJsr199.java
@@ -0,0 +1,203 @@
+/*******************************************************************************
+ * Copyright (c) 2015 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.compiler.batch;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.tools.JavaFileManager;
+import javax.tools.JavaFileObject;
+
+import org.eclipse.jdt.core.compiler.CharOperation;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
+import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
+
+@SuppressWarnings({ "rawtypes", "unchecked" })
+public class ClasspathJsr199 extends ClasspathLocation {
+ private static final Set<JavaFileObject.Kind> fileTypes = new HashSet<>();
+
+ static {
+ fileTypes.add(JavaFileObject.Kind.CLASS);
+ }
+
+ private JavaFileManager fileManager;
+ private JavaFileManager.Location location;
+
+ public ClasspathJsr199(JavaFileManager file, JavaFileManager.Location location) {
+ super(null, null);
+ this.fileManager = file;
+ this.location = location;
+ }
+
+ @Override
+ public List fetchLinkedJars(FileSystem.ClasspathSectionProblemReporter problemReporter) {
+ // Assume no linked jars
+ return null;
+ }
+
+ @Override
+ public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String qualifiedBinaryFileName) {
+ return findClass(typeName, qualifiedPackageName, qualifiedBinaryFileName, false);
+ }
+
+ @Override
+ public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String aQualifiedBinaryFileName,
+ boolean asBinaryOnly) {
+
+ String qualifiedBinaryFileName = File.separatorChar == '/'
+ ? aQualifiedBinaryFileName
+ : aQualifiedBinaryFileName.replace(File.separatorChar, '/');
+
+ try {
+ int lastDot = qualifiedBinaryFileName.lastIndexOf('.');
+ String className = lastDot < 0 ? qualifiedBinaryFileName : qualifiedBinaryFileName.substring(0, lastDot);
+ JavaFileObject jfo = null;
+ try {
+ jfo = this.fileManager.getJavaFileForInput(this.location, className, JavaFileObject.Kind.CLASS);
+ } catch (IOException e) {
+ // treat as if class file is missing
+ }
+
+ if (jfo == null)
+ return null; // most common case
+
+ try (InputStream inputStream = jfo.openInputStream()) {
+ ClassFileReader reader = ClassFileReader.read(inputStream, qualifiedBinaryFileName);
+ if (reader != null) {
+ return new NameEnvironmentAnswer(reader, fetchAccessRestriction(qualifiedBinaryFileName));
+ }
+ }
+ } catch (ClassFormatException e) {
+ // treat as if class file is missing
+ } catch (IOException e) {
+ // treat as if class file is missing
+ }
+ return null;
+ }
+
+ @Override
+ public char[][][] findTypeNames(String aQualifiedPackageName) {
+ String qualifiedPackageName = File.separatorChar == '/' ? aQualifiedPackageName : aQualifiedPackageName.replace(
+ File.separatorChar, '/');
+
+ Iterable<JavaFileObject> files = null;
+ try {
+ files = this.fileManager.list(this.location, qualifiedPackageName, fileTypes, false);
+ } catch (IOException e) {
+ // treat as if empty
+ }
+ if (files == null) {
+ return null;
+ }
+ ArrayList answers = new ArrayList();
+ char[][] packageName = CharOperation.splitOn(File.separatorChar, qualifiedPackageName.toCharArray());
+
+ for (JavaFileObject file : files) {
+ String fileName = file.toUri().getPath();
+
+ int last = fileName.lastIndexOf('/');
+ if (last > 0) {
+ int indexOfDot = fileName.lastIndexOf('.');
+ if (indexOfDot != -1) {
+ String typeName = fileName.substring(last + 1, indexOfDot);
+ answers.add(CharOperation.arrayConcat(packageName, typeName.toCharArray()));
+ }
+ }
+ }
+ int size = answers.size();
+ if (size != 0) {
+ char[][][] result = new char[size][][];
+ answers.toArray(result);
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ public void initialize() throws IOException {
+ // nothing to do
+ }
+
+ @Override
+ public boolean isPackage(String aQualifiedPackageName) {
+ String qualifiedPackageName = File.separatorChar == '/' ? aQualifiedPackageName : aQualifiedPackageName.replace(
+ File.separatorChar, '/');
+
+ boolean result = false;
+ try {
+ Iterable<JavaFileObject> files = this.fileManager.list(this.location, qualifiedPackageName, fileTypes, false);
+ Iterator f = files.iterator();
+ // if there is any content, assume a package
+ if (f.hasNext()) {
+ result = true;
+ } else {
+ // I hate to do this since it is expensive and will throw off garbage
+ // but can't think of an alternative now
+ files = this.fileManager.list(this.location, qualifiedPackageName, fileTypes, true);
+ f = files.iterator();
+ // if there is any content, assume a package
+ if (f.hasNext()) {
+ result = true;
+ }
+ }
+ } catch (IOException e) {
+ // treat as if missing
+ }
+ return result;
+ }
+
+ @Override
+ public void reset() {
+ try {
+ this.fileManager.flush();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "Classpath for Jsr 199 JavaFileManager: " + this.location; //$NON-NLS-1$
+ }
+
+ @Override
+ public char[] normalizedPath() {
+ if (this.normalizedPath == null) {
+ this.normalizedPath = this.path.toCharArray();
+ }
+ return this.normalizedPath;
+ }
+
+ @Override
+ public String getPath() {
+ if (this.path == null) {
+ this.path = this.location.getName();
+ }
+ return this.path;
+ }
+
+ @Override
+ public int getMode() {
+ return BINARY;
+ }
+
+ @Override
+ public boolean hasAnnotationFileFor(String qualifiedTypeName) {
+ return false;
+ }
+}
diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Archive.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Archive.java
index f5c39dd8bb..f6094e9315 100644
--- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Archive.java
+++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Archive.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 IBM Corporation and others.
+ * Copyright (c) 2006, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,8 +14,10 @@ import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.List;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
@@ -30,6 +32,7 @@ public class Archive {
ZipFile zipFile;
File file;
+
protected Hashtable<String, ArrayList<String>> packagesCache;
private Archive() {
@@ -39,12 +42,12 @@ public class Archive {
public Archive(File file) throws ZipException, IOException {
this.file = file;
this.zipFile = new ZipFile(file);
- initialize();
+ initialize();
}
private void initialize() {
// initialize packages
- this.packagesCache = new Hashtable<String, ArrayList<String>>();
+ this.packagesCache = new Hashtable<>();
nextEntry : for (Enumeration<? extends ZipEntry> e = this.zipFile.entries(); e.hasMoreElements(); ) {
String fileName = ((ZipEntry) e.nextElement()).getName();
@@ -59,7 +62,7 @@ public class Archive {
if (typeName.length() == 0) {
continue nextEntry;
}
- types = new ArrayList<String>();
+ types = new ArrayList<>();
types.add(typeName);
this.packagesCache.put(packageName, types);
} else {
@@ -69,7 +72,7 @@ public class Archive {
}
public ArchiveFileObject getArchiveFileObject(String entryName, Charset charset) {
- return new ArchiveFileObject(this.file, this.zipFile, entryName, charset);
+ return new ArchiveFileObject(this.file, entryName, charset);
}
public boolean contains(String entryName) {
@@ -83,8 +86,16 @@ public class Archive {
return this.packagesCache.keySet();
}
- public ArrayList<String> getTypes(String packageName) {
+ public List<String> getTypes(String packageName) {
// package name is expected to ends with '/'
+ if (this.packagesCache == null) {
+ try {
+ this.zipFile = new ZipFile(this.file);
+ } catch(IOException e) {
+ return Collections.<String>emptyList();
+ }
+ this.initialize();
+ }
return this.packagesCache.get(packageName);
}
@@ -94,10 +105,17 @@ public class Archive {
public void close() {
try {
- if (this.zipFile != null) this.zipFile.close();
+ if (this.zipFile != null) {
+ this.zipFile.close();
+ }
this.packagesCache = null;
} catch (IOException e) {
// ignore
}
}
+
+ @Override
+ public String toString() {
+ return "Archive: " + (this.file == null ? "UNKNOWN_ARCHIVE" : this.file.getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/ArchiveFileObject.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/ArchiveFileObject.java
index e07ff84e6e..73ef27efa6 100644
--- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/ArchiveFileObject.java
+++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/ArchiveFileObject.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2013 IBM Corporation and others.
+ * Copyright (c) 2006, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -34,20 +34,29 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
* Implementation of a Java file object that corresponds to an entry in a zip/jar file
*/
public class ArchiveFileObject implements JavaFileObject {
- private ZipEntry zipEntry;
- private ZipFile zipFile;
private String entryName;
private File file;
+ private ZipFile zipFile;
private Charset charset;
-
- public ArchiveFileObject(File file, ZipFile zipFile, String entryName, Charset charset) {
- this.zipFile = zipFile;
- this.zipEntry = zipFile.getEntry(entryName);
+
+ public ArchiveFileObject(File file, String entryName, Charset charset) {
this.entryName = entryName;
this.file = file;
this.charset = charset;
}
+ @Override
+ protected void finalize() throws Throwable {
+ if (this.zipFile != null) {
+ try {
+ this.zipFile.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ super.finalize();
+ }
+
/* (non-Javadoc)
* @see javax.tools.JavaFileObject#getAccessLevel()
*/
@@ -59,12 +68,15 @@ public class ArchiveFileObject implements JavaFileObject {
}
ClassFileReader reader = null;
try {
- reader = ClassFileReader.read(this.zipFile, this.entryName);
+ try (ZipFile zip = new ZipFile(this.file)) {
+ reader = ClassFileReader.read(zip, this.entryName);
+ }
} catch (ClassFormatException e) {
// ignore
} catch (IOException e) {
// ignore
}
+
if (reader == null) {
return null;
}
@@ -103,32 +115,34 @@ public class ArchiveFileObject implements JavaFileObject {
@Override
public NestingKind getNestingKind() {
switch(getKind()) {
- case SOURCE :
- return NestingKind.TOP_LEVEL;
- case CLASS :
- ClassFileReader reader = null;
- try {
- reader = ClassFileReader.read(this.zipFile, this.entryName);
- } catch (ClassFormatException e) {
- // ignore
- } catch (IOException e) {
- // ignore
- }
- if (reader == null) {
- return null;
- }
- if (reader.isAnonymous()) {
- return NestingKind.ANONYMOUS;
- }
- if (reader.isLocal()) {
- return NestingKind.LOCAL;
- }
- if (reader.isMember()) {
- return NestingKind.MEMBER;
- }
- return NestingKind.TOP_LEVEL;
- default:
- return null;
+ case SOURCE :
+ return NestingKind.TOP_LEVEL;
+ case CLASS :
+ ClassFileReader reader = null;
+ try {
+ try (ZipFile zip = new ZipFile(this.file)) {
+ reader = ClassFileReader.read(zip, this.entryName);
+ }
+ } catch (ClassFormatException e) {
+ // ignore
+ } catch (IOException e) {
+ // ignore
+ }
+ if (reader == null) {
+ return null;
+ }
+ if (reader.isAnonymous()) {
+ return NestingKind.ANONYMOUS;
+ }
+ if (reader.isLocal()) {
+ return NestingKind.LOCAL;
+ }
+ if (reader.isMember()) {
+ return NestingKind.MEMBER;
+ }
+ return NestingKind.TOP_LEVEL;
+ default:
+ return null;
}
}
@@ -137,7 +151,7 @@ public class ArchiveFileObject implements JavaFileObject {
*/
@Override
public boolean isNameCompatible(String simpleName, Kind kind) {
- return this.zipEntry.getName().endsWith(simpleName + kind.extension);
+ return this.entryName.endsWith(simpleName + kind.extension);
}
/* (non-Javadoc)
@@ -156,7 +170,7 @@ public class ArchiveFileObject implements JavaFileObject {
ArchiveFileObject archiveFileObject = (ArchiveFileObject) o;
return archiveFileObject.toUri().equals(this.toUri());
}
-
+
@Override
public int hashCode() {
return this.toUri().hashCode();
@@ -168,7 +182,10 @@ public class ArchiveFileObject implements JavaFileObject {
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
if (getKind() == Kind.SOURCE) {
- return Util.getCharContents(this, ignoreEncodingErrors, org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(this.zipEntry, this.zipFile), this.charset.name());
+ try (ZipFile zipFile2 = new ZipFile(this.file)) {
+ ZipEntry zipEntry = zipFile2.getEntry(this.entryName);
+ return Util.getCharContents(this, ignoreEncodingErrors, org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(zipEntry, zipFile2), this.charset.name());
+ }
}
return null;
}
@@ -178,7 +195,13 @@ public class ArchiveFileObject implements JavaFileObject {
*/
@Override
public long getLastModified() {
- return this.zipEntry.getTime(); // looks the closest from the last modification
+ try (ZipFile zip = new ZipFile(this.file)) {
+ ZipEntry zipEntry = zip.getEntry(this.entryName);
+ return zipEntry.getTime(); // looks the closest from the last modification
+ } catch(IOException e) {
+ // ignore
+ }
+ return 0;
}
/* (non-Javadoc)
@@ -186,7 +209,7 @@ public class ArchiveFileObject implements JavaFileObject {
*/
@Override
public String getName() {
- return this.zipEntry.getName();
+ return this.entryName;
}
/* (non-Javadoc)
@@ -194,7 +217,11 @@ public class ArchiveFileObject implements JavaFileObject {
*/
@Override
public InputStream openInputStream() throws IOException {
- return this.zipFile.getInputStream(this.zipEntry);
+ if (this.zipFile == null) {
+ this.zipFile = new ZipFile(this.file);
+ }
+ ZipEntry zipEntry = this.zipFile.getEntry(this.entryName);
+ return this.zipFile.getInputStream(zipEntry);
}
/* (non-Javadoc)
@@ -227,15 +254,15 @@ public class ArchiveFileObject implements JavaFileObject {
@Override
public URI toUri() {
try {
- return new URI("jar:" + this.file.toURI().getPath() + "!" + this.zipEntry.getName()); //$NON-NLS-1$//$NON-NLS-2$
+ return new URI("jar:" + this.file.toURI().getPath() + "!" + this.entryName); //$NON-NLS-1$//$NON-NLS-2$
} catch (URISyntaxException e) {
return null;
}
}
-
- @Override
- public String toString() {
- return this.file.getAbsolutePath() + "[" + this.zipEntry.getName() + "]";//$NON-NLS-1$//$NON-NLS-2$
- }
+
+ @Override
+ public String toString() {
+ return this.file.getAbsolutePath() + "[" + this.entryName + "]";//$NON-NLS-1$//$NON-NLS-2$
+ }
}
diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java
index a61c4dcd43..3081318b63 100644
--- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java
+++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2014 IBM Corporation and others.
+ * Copyright (c) 2006, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -57,7 +57,7 @@ public class EclipseCompiler implements JavaCompiler {
public DiagnosticListener<? super JavaFileObject> diagnosticListener;
public EclipseCompiler() {
- this.threadCache = new WeakHashMap<Thread, EclipseCompilerImpl>();
+ this.threadCache = new WeakHashMap<>();
}
/*
* (non-Javadoc)
@@ -119,7 +119,7 @@ public class EclipseCompiler implements JavaCompiler {
eclipseCompiler2.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6);
eclipseCompiler2.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6);
- ArrayList<String> allOptions = new ArrayList<String>();
+ ArrayList<String> allOptions = new ArrayList<>();
if (options != null) {
for (Iterator<String> iterator = options.iterator(); iterator.hasNext(); ) {
eclipseCompiler2.fileManager.handleOption(iterator.next(), iterator);
@@ -139,7 +139,11 @@ public class EclipseCompiler implements JavaCompiler {
if (!uri.isAbsolute()) {
uri = URI.create("file://" + uri.toString()); //$NON-NLS-1$
}
- allOptions.add(new File(uri).getAbsolutePath());
+ if (uri.getScheme().equals("file")) { //$NON-NLS-1$
+ allOptions.add(new File(uri).getAbsolutePath());
+ } else {
+ allOptions.add(uri.toString());
+ }
}
}
@@ -192,7 +196,7 @@ public class EclipseCompiler implements JavaCompiler {
}
@Override
public void setProcessors(Iterable<? extends Processor> processors) {
- ArrayList<Processor> temp = new ArrayList<Processor>();
+ ArrayList<Processor> temp = new ArrayList<>();
for (Processor processor : processors) {
temp.add(processor);
}
diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java
index 2897d8d309..d21fffc06c 100644
--- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java
+++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 IBM Corporation and others.
+ * Copyright (c) 2007, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -35,8 +35,9 @@ import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.compiler.CompilationProgress;
import org.eclipse.jdt.internal.compiler.ClassFile;
import org.eclipse.jdt.internal.compiler.CompilationResult;
-import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
+import org.eclipse.jdt.internal.compiler.IProblemFactory;
+import org.eclipse.jdt.internal.compiler.batch.ClasspathJsr199;
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit;
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
@@ -44,6 +45,7 @@ import org.eclipse.jdt.internal.compiler.batch.Main;
import org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
+import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
import org.eclipse.jdt.internal.compiler.util.Messages;
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
@@ -104,7 +106,7 @@ public class EclipseCompilerImpl extends Main {
@Override
public CompilationUnit[] getCompilationUnits() {
if (this.compilationUnits == null) return EclipseCompilerImpl.NO_UNITS;
- ArrayList<CompilationUnit> units = new ArrayList<CompilationUnit>();
+ ArrayList<CompilationUnit> units = new ArrayList<>();
for (final JavaFileObject javaFileObject : this.compilationUnits) {
if (javaFileObject.getKind() != JavaFileObject.Kind.SOURCE) {
throw new IllegalArgumentException();
@@ -155,14 +157,158 @@ public class EclipseCompilerImpl extends Main {
}
@Override
- public ICompilerRequestor getBatchRequestor() {
- return new EclipseCompilerRequestor(this, this.diagnosticListener, (DefaultProblemFactory) getProblemFactory());
- }
+ public IProblemFactory getProblemFactory() {
+ return new DefaultProblemFactory() {
+ @Override
+ public CategorizedProblem createProblem(
+ final char[] originatingFileName,
+ final int problemId,
+ final String[] problemArguments,
+ final String[] messageArguments,
+ final int severity,
+ final int startPosition,
+ final int endPosition,
+ final int lineNumber,
+ final int columnNumber) {
+
+ DiagnosticListener<? super JavaFileObject> diagListener = EclipseCompilerImpl.this.diagnosticListener;
+ if (diagListener != null) {
+ diagListener.report(new Diagnostic<JavaFileObject>() {
+ @Override
+ public String getCode() {
+ return Integer.toString(problemId);
+ }
+ @Override
+ public long getColumnNumber() {
+ return columnNumber;
+ }
+ @Override
+ public long getEndPosition() {
+ return endPosition;
+ }
+ @Override
+ public Kind getKind() {
+ if ((severity & ProblemSeverities.Error) != 0) {
+ return Diagnostic.Kind.ERROR;
+ }
+ if ((severity & ProblemSeverities.Optional) != 0) {
+ return Diagnostic.Kind.WARNING;
+ }
+ if ((severity & ProblemSeverities.Warning) != 0) {
+ return Diagnostic.Kind.MANDATORY_WARNING;
+ }
+ return Diagnostic.Kind.OTHER;
+ }
+ @Override
+ public long getLineNumber() {
+ return lineNumber;
+ }
+ @Override
+ public String getMessage(Locale locale) {
+ if (locale != null) {
+ setLocale(locale);
+ }
+ return getLocalizedMessage(problemId, problemArguments);
+ }
+ @Override
+ public long getPosition() {
+ return startPosition;
+ }
+ @Override
+ public JavaFileObject getSource() {
+ File f = new File(new String(originatingFileName));
+ if (f.exists()) {
+ return new EclipseFileObject(null, f.toURI(), JavaFileObject.Kind.SOURCE, null);
+ }
+ return null;
+ }
+ @Override
+ public long getStartPosition() {
+ return startPosition;
+ }
+ });
+ }
+ return super.createProblem(originatingFileName, problemId, problemArguments, messageArguments, severity, startPosition, endPosition, lineNumber, columnNumber);
+ }
+ @Override
+ public CategorizedProblem createProblem(
+ final char[] originatingFileName,
+ final int problemId,
+ final String[] problemArguments,
+ final int elaborationID,
+ final String[] messageArguments,
+ final int severity,
+ final int startPosition,
+ final int endPosition,
+ final int lineNumber,
+ final int columnNumber) {
+ DiagnosticListener<? super JavaFileObject> diagListener = EclipseCompilerImpl.this.diagnosticListener;
+ if (diagListener != null) {
+ diagListener.report(new Diagnostic<JavaFileObject>() {
+ @Override
+ public String getCode() {
+ return Integer.toString(problemId);
+ }
+ @Override
+ public long getColumnNumber() {
+ return columnNumber;
+ }
+ @Override
+ public long getEndPosition() {
+ return endPosition;
+ }
+ @Override
+ public Kind getKind() {
+ if ((severity & ProblemSeverities.Error) != 0) {
+ return Diagnostic.Kind.ERROR;
+ }
+ if ((severity & ProblemSeverities.Optional) != 0) {
+ return Diagnostic.Kind.WARNING;
+ }
+ if ((severity & ProblemSeverities.Warning) != 0) {
+ return Diagnostic.Kind.MANDATORY_WARNING;
+ }
+ return Diagnostic.Kind.OTHER;
+ }
+ @Override
+ public long getLineNumber() {
+ return lineNumber;
+ }
+ @Override
+ public String getMessage(Locale locale) {
+ if (locale != null) {
+ setLocale(locale);
+ }
+ return getLocalizedMessage(problemId, problemArguments);
+ }
+ @Override
+ public long getPosition() {
+ return startPosition;
+ }
@Override
+ public JavaFileObject getSource() {
+ File f = new File(new String(originatingFileName));
+ if (f.exists()) {
+ return new EclipseFileObject(null, f.toURI(), JavaFileObject.Kind.SOURCE, null);
+ }
+ return null;
+ }
+ @Override
+ public long getStartPosition() {
+ return startPosition;
+ }
+ });
+ }
+ return super.createProblem(originatingFileName, problemId, problemArguments, elaborationID, messageArguments, severity, startPosition, endPosition, lineNumber, columnNumber);
+ }
+ };
+ }
+
+ @Override
protected void initialize(PrintWriter outWriter, PrintWriter errWriter, boolean systemExit, Map customDefaultOptions, CompilationProgress compilationProgress) {
super.initialize(outWriter, errWriter, systemExit, customDefaultOptions, compilationProgress);
- this.javaFileObjectMap = new HashMap<CompilationUnit, JavaFileObject>();
+ this.javaFileObjectMap = new HashMap<>();
}
@Override
@@ -209,11 +355,11 @@ public class EclipseCompilerImpl extends Main {
}
try {
JavaFileObject javaFileForOutput =
- this.fileManager.getJavaFileForOutput(
- StandardLocation.CLASS_OUTPUT,
- new String(filename),
- JavaFileObject.Kind.CLASS,
- this.javaFileObjectMap.get(unitResult.compilationUnit));
+ this.fileManager.getJavaFileForOutput(
+ StandardLocation.CLASS_OUTPUT,
+ new String(filename),
+ JavaFileObject.Kind.CLASS,
+ this.javaFileObjectMap.get(unitResult.compilationUnit));
if (generateClasspathStructure) {
if (currentDestinationPath != null) {
@@ -234,12 +380,11 @@ public class EclipseCompilerImpl extends Main {
}
}
- OutputStream openOutputStream = javaFileForOutput.openOutputStream();
- BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(openOutputStream);
- bufferedOutputStream.write(classFile.header, 0, classFile.headerOffset);
- bufferedOutputStream.write(classFile.contents, 0, classFile.contentsOffset);
- bufferedOutputStream.flush();
- bufferedOutputStream.close();
+ try (OutputStream openOutputStream = javaFileForOutput.openOutputStream(); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(openOutputStream)) {
+ bufferedOutputStream.write(classFile.header, 0, classFile.headerOffset);
+ bufferedOutputStream.write(classFile.contents, 0, classFile.contentsOffset);
+ bufferedOutputStream.flush();
+ }
} catch (IOException e) {
this.logger.logNoClassFileCreated(currentDestinationPath, relativeStringName, e);
}
@@ -262,78 +407,95 @@ public class EclipseCompilerImpl extends Main {
ArrayList endorsedDirClasspaths,
String customEncoding) {
- ArrayList<FileSystem.Classpath> fileSystemClasspaths = new ArrayList<FileSystem.Classpath>();
- EclipseFileManager javaFileManager = null;
+ 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) {
- javaFileManager = (EclipseFileManager) this.fileManager;
+ eclipseJavaFileManager = (EclipseFileManager) this.fileManager;
}
if (this.fileManager instanceof StandardJavaFileManager) {
standardJavaFileManager = (StandardJavaFileManager) this.fileManager;
}
+ javaFileManager = this.fileManager;
- if (javaFileManager != null) {
- if ((javaFileManager.flags & EclipseFileManager.HAS_ENDORSED_DIRS) == 0
- && (javaFileManager.flags & EclipseFileManager.HAS_BOOTCLASSPATH) != 0) {
+ 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> location = null;
if (standardJavaFileManager != null) {
location = standardJavaFileManager.getLocation(StandardLocation.PLATFORM_CLASS_PATH);
- }
- if (location != null) {
- for (File file : location) {
- Classpath classpath = FileSystem.getClasspath(
- file.getAbsolutePath(),
- null,
- null);
- if (classpath != null) {
- fileSystemClasspaths.add(classpath);
+ if (location != null) {
+ for (File file : location) {
+ Classpath classpath = FileSystem.getClasspath(
+ file.getAbsolutePath(),
+ null,
+ null);
+ if (classpath != null) {
+ fileSystemClasspaths.add(classpath);
+ havePlatformPaths = true;
+ }
}
}
+ } else if (javaFileManager != null) {
+ Classpath classpath = new ClasspathJsr199(this.fileManager, StandardLocation.PLATFORM_CLASS_PATH);
+ fileSystemClasspaths.add(classpath);
+ havePlatformPaths = true;
}
- if (javaFileManager != null) {
- if ((javaFileManager.flags & EclipseFileManager.HAS_EXT_DIRS) == 0
- && (javaFileManager.flags & EclipseFileManager.HAS_BOOTCLASSPATH) != 0) {
+ 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) {
location = standardJavaFileManager.getLocation(StandardLocation.SOURCE_PATH);
- } else {
- location = null;
- }
- if (location != null) {
- for (File file : location) {
- Classpath classpath = FileSystem.getClasspath(
+ if (location != null) {
+ for (File file : location) {
+ Classpath classpath = FileSystem.getClasspath(
+ file.getAbsolutePath(),
+ null,
+ null);
+ if (classpath != null) {
+ fileSystemClasspaths.add(classpath);
+ }
+ }
+ }
+ location = standardJavaFileManager.getLocation(StandardLocation.CLASS_PATH);
+ if (location != null) {
+ for (File file : location) {
+ Classpath classpath = FileSystem.getClasspath(
file.getAbsolutePath(),
null,
null);
- if (classpath != null) {
- fileSystemClasspaths.add(classpath);
+ if (classpath != null) {
+ fileSystemClasspaths.add(classpath);
+ haveClassPaths = true;
+ }
}
}
- }
- if (standardJavaFileManager != null) {
- location = standardJavaFileManager.getLocation(StandardLocation.CLASS_PATH);
- } else {
- location = null;
- }
- if (location != null) {
- for (File file : location) {
- Classpath classpath = FileSystem.getClasspath(
- file.getAbsolutePath(),
- null,
- null);
- if (classpath != null) {
- fileSystemClasspaths.add(classpath);
- }
+ } 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);
}
+ classpath = new ClasspathJsr199(this.fileManager, StandardLocation.CLASS_PATH);
+ fileSystemClasspaths.add(classpath);
+ haveClassPaths = true;
}
if (this.checkedClasspaths == null) {
- fileSystemClasspaths.addAll(this.handleBootclasspath(null, null));
- fileSystemClasspaths.addAll(this.handleClasspath(null, null));
+ // It appears to be necessary to handleBootclasspath() for IBM JVMs
+ // in order to have visibility to java.lang.String (not present in rt.jar).
+ // The jars returned by StandardFileManager.getLocation(PLATFORM_CLASS_PATH) are
+ // 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();
diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java
index 59f6a040de..a5bd770d27 100644
--- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java
+++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2014 IBM Corporation and others.
+ * Copyright (c) 2006, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
@@ -33,9 +34,9 @@ import java.util.zip.ZipException;
import javax.tools.FileObject;
import javax.tools.JavaFileObject;
+import javax.tools.JavaFileObject.Kind;
import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation;
-import javax.tools.JavaFileObject.Kind;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
@@ -67,8 +68,8 @@ public class EclipseFileManager implements StandardJavaFileManager {
public EclipseFileManager(Locale locale, Charset charset) {
this.locale = locale == null ? Locale.getDefault() : locale;
this.charset = charset == null ? Charset.defaultCharset() : charset;
- this.locations = new HashMap<String, Iterable<? extends File>>();
- this.archivesCache = new HashMap<File, Archive>();
+ this.locations = new HashMap<>();
+ this.archivesCache = new HashMap<>();
try {
this.setLocation(StandardLocation.PLATFORM_CLASS_PATH, getDefaultBootclasspath());
Iterable<? extends File> defaultClasspath = getDefaultClasspath();
@@ -84,56 +85,16 @@ public class EclipseFileManager implements StandardJavaFileManager {
}
}
- private void addFiles(File[][] jars, ArrayList<File> files) {
- if (jars != null) {
- for (File[] currentJars : jars) {
- if (currentJars != null) {
- for (File currentJar : currentJars) {
- if (currentJar.exists()) {
- files.add(currentJar);
- }
- }
- }
- }
- }
- }
-
-
- private void addFilesFrom(File javaHome, String propertyName, String defaultPath, ArrayList<File> files) {
- String extdirsStr = System.getProperty(propertyName);
- File[] directoriesToCheck = null;
- if (extdirsStr == null) {
- if (javaHome != null) {
- directoriesToCheck = new File[] { new File(javaHome, defaultPath) };
- }
- } else {
- StringTokenizer tokenizer = new StringTokenizer(extdirsStr, File.pathSeparator);
- ArrayList<String> paths = new ArrayList<String>();
- while (tokenizer.hasMoreTokens()) {
- paths.add(tokenizer.nextToken());
- }
- if (paths.size() != 0) {
- directoriesToCheck = new File[paths.size()];
- for (int i = 0; i < directoriesToCheck.length; i++) {
- directoriesToCheck[i] = new File(paths.get(i));
- }
- }
- }
- if (directoriesToCheck != null) {
- addFiles(Main.getLibrariesFiles(directoriesToCheck), files);
- }
-
- }
-
/* (non-Javadoc)
* @see javax.tools.JavaFileManager#close()
*/
@Override
public void close() throws IOException {
- this.locations = null;
+ if (this.locations != null) this.locations.clear();
for (Archive archive : this.archivesCache.values()) {
archive.close();
}
+ this.archivesCache.clear();
}
private void collectAllMatchingFiles(File file, String normalizedPackageName, Set<Kind> kinds, boolean recurse, ArrayList<JavaFileObject> collector) {
@@ -166,6 +127,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
}
} else {
Archive archive = this.getArchive(file);
+ if (archive == Archive.UNKNOWN_ARCHIVE) return;
String key = normalizedPackageName;
if (!normalizedPackageName.endsWith("/")) {//$NON-NLS-1$
key += '/';
@@ -174,7 +136,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
if (recurse) {
for (String packageName : archive.allPackages()) {
if (packageName.startsWith(key)) {
- ArrayList<String> types = archive.getTypes(packageName);
+ List<String> types = archive.getTypes(packageName);
if (types != null) {
for (String typeName : types) {
final Kind kind = getKind(getExtension(typeName));
@@ -186,12 +148,12 @@ public class EclipseFileManager implements StandardJavaFileManager {
}
}
} else {
- ArrayList<String> types = archive.getTypes(key);
+ List<String> types = archive.getTypes(key);
if (types != null) {
for (String typeName : types) {
- final Kind kind = getKind(typeName);
+ final Kind kind = getKind(getExtension(typeName));
if (kinds.contains(kind)) {
- collector.add(archive.getArchiveFileObject(normalizedPackageName + typeName, this.charset));
+ collector.add(archive.getArchiveFileObject(key + typeName, this.charset));
}
}
}
@@ -200,7 +162,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
}
private Iterable<? extends File> concatFiles(Iterable<? extends File> iterable, Iterable<? extends File> iterable2) {
- ArrayList<File> list = new ArrayList<File>();
+ ArrayList<File> list = new ArrayList<>();
if (iterable2 == null) return iterable;
for (Iterator<? extends File> iterator = iterable.iterator(); iterator.hasNext(); ) {
list.add(iterator.next());
@@ -225,23 +187,21 @@ public class EclipseFileManager implements StandardJavaFileManager {
// check the archive (jar/zip) cache
Archive archive = this.archivesCache.get(f);
if (archive == null) {
+ archive = Archive.UNKNOWN_ARCHIVE;
// create a new archive
if (f.exists()) {
- try {
- archive = new Archive(f);
- } catch (ZipException e) {
- // ignore
- } catch (IOException e) {
- // ignore
- }
- if (archive != null) {
- this.archivesCache.put(f, archive);
- } else {
- this.archivesCache.put(f, Archive.UNKNOWN_ARCHIVE);
- }
- } else {
- this.archivesCache.put(f, Archive.UNKNOWN_ARCHIVE);
+ try {
+ archive = new Archive(f);
+ } catch (ZipException e) {
+ // ignore
+ } catch (IOException e) {
+ // ignore
+ }
+ if (archive != null) {
+ this.archivesCache.put(f, archive);
+ }
}
+ this.archivesCache.put(f, archive);
}
return archive;
}
@@ -256,7 +216,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
// location is unknown
return null;
}
- ArrayList<URL> allURLs = new ArrayList<URL>();
+ ArrayList<URL> allURLs = new ArrayList<>();
for (File f : files) {
try {
allURLs.add(f.toURI().toURL());
@@ -270,8 +230,8 @@ public class EclipseFileManager implements StandardJavaFileManager {
}
private Iterable<? extends File> getPathsFrom(String path) {
- ArrayList<FileSystem.Classpath> paths = new ArrayList<FileSystem.Classpath>();
- ArrayList<File> files = new ArrayList<File>();
+ ArrayList<FileSystem.Classpath> paths = new ArrayList<>();
+ ArrayList<File> files = new ArrayList<>();
try {
this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.name(), false, false);
} catch (IllegalArgumentException e) {
@@ -284,7 +244,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
}
Iterable<? extends File> getDefaultBootclasspath() {
- ArrayList<File> files = new ArrayList<File>();
+ List<File> files = new ArrayList<>();
String javaversion = System.getProperty("java.version");//$NON-NLS-1$
if(javaversion.length() > 3)
javaversion = javaversion.substring(0, 3);
@@ -294,37 +254,15 @@ public class EclipseFileManager implements StandardJavaFileManager {
return null;
}
- /*
- * Handle >= JDK 1.6
- */
- String javaHome = System.getProperty("java.home"); //$NON-NLS-1$
- File javaHomeFile = null;
- if (javaHome != null) {
- javaHomeFile = new File(javaHome);
- if (!javaHomeFile.exists())
- javaHomeFile = null;
- }
-
- addFilesFrom(javaHomeFile, "java.endorsed.dirs", "/lib/endorsed", files);//$NON-NLS-1$//$NON-NLS-2$
- if (javaHomeFile != null) {
- File[] directoriesToCheck = null;
- if (System.getProperty("os.name").startsWith("Mac")) {//$NON-NLS-1$//$NON-NLS-2$
- directoriesToCheck = new File[] { new File(javaHomeFile, "../Classes"), //$NON-NLS-1$
- };
- } else {
- directoriesToCheck = new File[] { new File(javaHomeFile, "lib") //$NON-NLS-1$
- };
- }
- File[][] jars = Main.getLibrariesFiles(directoriesToCheck);
- addFiles(jars, files);
+ for (String fileName : org.eclipse.jdt.internal.compiler.util.Util.collectFilesNames()) {
+ files.add(new File(fileName));
}
- addFilesFrom(javaHomeFile, "java.ext.dirs", "/lib/ext", files);//$NON-NLS-1$//$NON-NLS-2$
return files;
}
Iterable<? extends File> getDefaultClasspath() {
// default classpath
- ArrayList<File> files = new ArrayList<File>();
+ ArrayList<File> files = new ArrayList<>();
String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$
if ((classProp == null) || (classProp.length() == 0)) {
return null;
@@ -343,8 +281,8 @@ public class EclipseFileManager implements StandardJavaFileManager {
}
private Iterable<? extends File> getEndorsedDirsFrom(String path) {
- ArrayList<FileSystem.Classpath> paths = new ArrayList<FileSystem.Classpath>();
- ArrayList<File> files = new ArrayList<File>();
+ ArrayList<FileSystem.Classpath> paths = new ArrayList<>();
+ ArrayList<File> files = new ArrayList<>();
try {
this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.name(), false, false);
} catch (IllegalArgumentException e) {
@@ -357,8 +295,8 @@ public class EclipseFileManager implements StandardJavaFileManager {
}
private Iterable<? extends File> getExtdirsFrom(String path) {
- ArrayList<FileSystem.Classpath> paths = new ArrayList<FileSystem.Classpath>();
- ArrayList<File> files = new ArrayList<File>();
+ ArrayList<FileSystem.Classpath> paths = new ArrayList<>();
+ ArrayList<File> files = new ArrayList<>();
try {
this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.name(), false, false);
} catch (IllegalArgumentException e) {
@@ -547,7 +485,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
*/
@Override
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(Iterable<? extends File> files) {
- ArrayList<JavaFileObject> javaFileArrayList = new ArrayList<JavaFileObject>();
+ ArrayList<JavaFileObject> javaFileArrayList = new ArrayList<>();
for (File f : files) {
if (f.isDirectory()) {
throw new IllegalArgumentException("file : " + f.getAbsolutePath() + " is a directory"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -562,7 +500,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
*/
@Override
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) {
- ArrayList<File> files = new ArrayList<File>();
+ ArrayList<File> files = new ArrayList<>();
for (String name : names) {
files.add(new File(name));
}
@@ -601,7 +539,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
if (file.exists() && !file.isDirectory()) {
throw new IllegalArgumentException("file : " + file.getAbsolutePath() + " is not a directory");//$NON-NLS-1$//$NON-NLS-2$
}
- ArrayList<File> list = new ArrayList<File>(1);
+ ArrayList<File> list = new ArrayList<>(1);
list.add(file);
return list;
}
@@ -765,7 +703,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
if (javaFileObject == null) {
return null;
}
- return normalized(name);
+ return name.replace('/', '.');
}
private boolean isArchive(File f) {
@@ -803,7 +741,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
throw new IllegalArgumentException("Unknown location : " + location);//$NON-NLS-1$
}
- ArrayList<JavaFileObject> collector = new ArrayList<JavaFileObject>();
+ ArrayList<JavaFileObject> collector = new ArrayList<>();
String normalizedPackageName = normalized(packageName);
for (File file : allFilesInLocations) {
collectAllMatchingFiles(file, normalizedPackageName, kinds, recurse, collector);
@@ -828,7 +766,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
private Iterable<? extends File> prependFiles(Iterable<? extends File> iterable,
Iterable<? extends File> iterable2) {
if (iterable2 == null) return iterable;
- ArrayList<File> list = new ArrayList<File>();
+ ArrayList<File> list = new ArrayList<>();
for (Iterator<? extends File> iterator = iterable2.iterator(); iterator.hasNext(); ) {
list.add(iterator.next());
}
diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileObject.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileObject.java
index d3f326ee9e..615268e6ed 100644
--- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileObject.java
+++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileObject.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2011 IBM Corporation and others.
+ * Copyright (c) 2006, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,6 +12,10 @@
package org.eclipse.jdt.internal.compiler.tool;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -164,8 +168,7 @@ public class EclipseFileObject extends SimpleJavaFileObject {
*/
@Override
public InputStream openInputStream() throws IOException {
- // TODO (olivier) should use buffered input stream
- return new FileInputStream(this.f);
+ return new BufferedInputStream(new FileInputStream(this.f));
}
/**
@@ -174,7 +177,7 @@ public class EclipseFileObject extends SimpleJavaFileObject {
@Override
public OutputStream openOutputStream() throws IOException {
ensureParentDirectoriesExist();
- return new FileOutputStream(this.f);
+ return new BufferedOutputStream(new FileOutputStream(this.f));
}
/**
@@ -182,7 +185,7 @@ public class EclipseFileObject extends SimpleJavaFileObject {
*/
@Override
public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
- return new FileReader(this.f);
+ return new BufferedReader(new FileReader(this.f));
}
/**
@@ -191,7 +194,7 @@ public class EclipseFileObject extends SimpleJavaFileObject {
@Override
public Writer openWriter() throws IOException {
ensureParentDirectoriesExist();
- return new FileWriter(this.f);
+ return new BufferedWriter(new FileWriter(this.f));
}
@Override
diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java
index 4b2f1fffee..173bebe432 100644
--- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java
+++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2014 IBM Corporation and others.
+ * Copyright (c) 2006, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -24,7 +24,7 @@ public final class Options {
private static final Set<String> ONE_ARGUMENT_OPTIONS;
private static final Set<String> FILE_MANAGER_OPTIONS;
static {
- ZERO_ARGUMENT_OPTIONS = new HashSet<String>();
+ ZERO_ARGUMENT_OPTIONS = new HashSet<>();
Options.ZERO_ARGUMENT_OPTIONS.add("-progress");//$NON-NLS-1$
Options.ZERO_ARGUMENT_OPTIONS.add("-proceedOnError");//$NON-NLS-1$
Options.ZERO_ARGUMENT_OPTIONS.add("-proceedOnError:Fatal");//$NON-NLS-1$
@@ -60,6 +60,9 @@ public final class Options {
Options.ZERO_ARGUMENT_OPTIONS.add("-1.7");//$NON-NLS-1$
Options.ZERO_ARGUMENT_OPTIONS.add("-7");//$NON-NLS-1$
Options.ZERO_ARGUMENT_OPTIONS.add("-7.0");//$NON-NLS-1$
+ Options.ZERO_ARGUMENT_OPTIONS.add("-1.8");//$NON-NLS-1$
+ Options.ZERO_ARGUMENT_OPTIONS.add("-8");//$NON-NLS-1$
+ Options.ZERO_ARGUMENT_OPTIONS.add("-8.0");//$NON-NLS-1$
Options.ZERO_ARGUMENT_OPTIONS.add("-proc:only");//$NON-NLS-1$
Options.ZERO_ARGUMENT_OPTIONS.add("-proc:none");//$NON-NLS-1$
Options.ZERO_ARGUMENT_OPTIONS.add("-XprintProcessorInfo");//$NON-NLS-1$
@@ -67,7 +70,7 @@ public final class Options {
Options.ZERO_ARGUMENT_OPTIONS.add("-parameters");//$NON-NLS-1$
Options.ZERO_ARGUMENT_OPTIONS.add("-genericsignature");//$NON-NLS-1$
- FILE_MANAGER_OPTIONS = new HashSet<String>();
+ FILE_MANAGER_OPTIONS = new HashSet<>();
Options.FILE_MANAGER_OPTIONS.add("-bootclasspath");//$NON-NLS-1$
Options.FILE_MANAGER_OPTIONS.add("-encoding");//$NON-NLS-1$
Options.FILE_MANAGER_OPTIONS.add("-d");//$NON-NLS-1$
@@ -79,7 +82,7 @@ public final class Options {
Options.FILE_MANAGER_OPTIONS.add("-s");//$NON-NLS-1$
Options.FILE_MANAGER_OPTIONS.add("-processorpath");//$NON-NLS-1$
- ONE_ARGUMENT_OPTIONS = new HashSet<String>();
+ ONE_ARGUMENT_OPTIONS = new HashSet<>();
Options.ONE_ARGUMENT_OPTIONS.addAll(Options.FILE_MANAGER_OPTIONS);
Options.ONE_ARGUMENT_OPTIONS.add("-log");//$NON-NLS-1$
Options.ONE_ARGUMENT_OPTIONS.add("-repeat");//$NON-NLS-1$
diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Util.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Util.java
index 88e2343218..0f1c715d4f 100644
--- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Util.java
+++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Util.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 IBM Corporation and others.
+ * Copyright (c) 2006, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -95,7 +95,7 @@ public final class Util {
}
}
public static class EncodingErrorCollector {
- ArrayList<EncodingError> encodingErrors = new ArrayList<EncodingError>();
+ ArrayList<EncodingError> encodingErrors = new ArrayList<>();
FileObject fileObject;
String encoding;

Back to the top