use of org.eclipse.jdt.internal.compiler.batch.FileSystem in project eclipse.jdt.ui by eclipse-jdt.
the class JarUtil method compile.
public static void compile(String[] pathsAndContents, Map<String, String> options, String[] classpath, String outputPath, ClassFileFilter classFileFilter) {
IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());
Requestor requestor = new Requestor(classFileFilter);
requestor.outputPath = outputPath.endsWith(File.separator) ? outputPath : outputPath + File.separator;
String[] classLibs = getJavaClassLibs();
if (classpath != null) {
int length = classpath.length;
int classLibsLength = classLibs.length;
System.arraycopy(classpath, 0, classpath = new String[length + classLibsLength], 0, length);
System.arraycopy(classLibs, 0, classpath, length, classLibsLength);
} else {
classpath = classLibs;
}
INameEnvironment nameEnvironment = new FileSystem(classpath, new String[] {}, null);
IErrorHandlingPolicy errorHandlingPolicy = new IErrorHandlingPolicy() {
@Override
public boolean proceedOnErrors() {
return true;
}
@Override
public boolean stopOnFirstError() {
return false;
}
@Override
public boolean ignoreAllErrors() {
return false;
}
};
CompilerOptions compilerOptions = new CompilerOptions(options);
compilerOptions.performMethodsFullRecovery = false;
compilerOptions.performStatementsRecovery = false;
Compiler batchCompiler = new Compiler(nameEnvironment, errorHandlingPolicy, compilerOptions, requestor, problemFactory);
batchCompiler.options.produceReferenceInfo = true;
// compile all files together
batchCompiler.compile(compilationUnits(pathsAndContents));
// cleanup
nameEnvironment.cleanup();
if (requestor.hasErrors)
// problem log empty if no problems
System.err.print(requestor.problemLog);
}
use of org.eclipse.jdt.internal.compiler.batch.FileSystem in project lombok by rzwitserloot.
the class RunTestsViaEcj method createFileSystem.
private FileSystem createFileSystem(File file) {
List<String> classpath = new ArrayList<String>();
for (Iterator<String> i = classpath.iterator(); i.hasNext(); ) {
if (FileSystem.getClasspath(i.next(), "UTF-8", null) == null) {
i.remove();
}
}
if (new File("bin").exists())
classpath.add("bin");
classpath.add("dist/lombok.jar");
classpath.add("lib/oracleJDK8Environment/rt.jar");
classpath.add("lib/test/commons-logging-commons-logging.jar");
classpath.add("lib/test/org.slf4j-slf4j-api.jar");
classpath.add("lib/test/org.slf4j-slf4j-ext.jar");
classpath.add("lib/test/log4j-log4j.jar");
classpath.add("lib/test/org.apache.logging.log4j-log4j-api.jar");
classpath.add("lib/test/org.jboss.logging-jboss-logging.jar");
classpath.add("lib/test/com.google.guava-guava.jar");
classpath.add("lib/test/com.google.code.findbugs-findbugs.jar");
return new FileSystem(classpath.toArray(new String[0]), new String[] { file.getAbsolutePath() }, "UTF-8");
}
use of org.eclipse.jdt.internal.compiler.batch.FileSystem in project lombok by rzwitserloot.
the class RunTestsViaEcj method createFileSystem.
private FileSystem createFileSystem(File file, int minVersion) {
List<String> classpath = new ArrayList<String>();
if (new File("bin/main").exists())
classpath.add("bin/main");
classpath.add("dist/lombok.jar");
classpath.add("build/teststubs");
if (bootRuntimePath == null || bootRuntimePath.isEmpty())
throw new IllegalStateException("System property delombok.bootclasspath is not set; set it to the rt of java6 or java8");
classpath.add(bootRuntimePath);
for (File f : new File("lib/test").listFiles()) {
String fn = f.getName();
if (fn.length() < 4)
continue;
if (!fn.substring(fn.length() - 4).toLowerCase().equals(".jar"))
continue;
classpath.add("lib/test/" + fn);
}
for (Iterator<String> i = classpath.iterator(); i.hasNext(); ) {
if (FileSystem.getClasspath(i.next(), "UTF-8", null) == null) {
i.remove();
}
}
return new FileSystem(classpath.toArray(new String[0]), new String[] { file.getAbsolutePath() }, "UTF-8");
}
use of org.eclipse.jdt.internal.compiler.batch.FileSystem in project bazel-jdt-java-toolchain by salesforce.
the class PackageElementImpl method getEnclosedElements.
@Override
public List<? extends Element> getEnclosedElements() {
PackageBinding binding = (PackageBinding) _binding;
LookupEnvironment environment = binding.environment;
char[][][] typeNames = null;
INameEnvironment nameEnvironment = binding.environment.nameEnvironment;
if (nameEnvironment instanceof FileSystem) {
typeNames = ((FileSystem) nameEnvironment).findTypeNames(binding.compoundName);
}
HashSet<Element> set = new HashSet<>();
Set<ReferenceBinding> types = new HashSet<>();
if (typeNames != null) {
for (char[][] typeName : typeNames) {
if (typeName == null)
continue;
ReferenceBinding type = environment.getType(typeName);
if (type == null || type.isMemberType())
continue;
if (type.isValidBinding()) {
Element newElement = _env.getFactory().newElement(type);
if (newElement.getKind() != ElementKind.PACKAGE) {
set.add(newElement);
types.add(type);
}
}
}
}
if (binding.knownTypes != null) {
ReferenceBinding[] knownTypes = binding.knownTypes.valueTable;
for (ReferenceBinding referenceBinding : knownTypes) {
if (referenceBinding != null && referenceBinding.isValidBinding() && referenceBinding.enclosingType() == null) {
if (!types.contains(referenceBinding)) {
Element newElement = _env.getFactory().newElement(referenceBinding);
if (newElement.getKind() != ElementKind.PACKAGE)
set.add(newElement);
}
}
}
}
ArrayList<Element> list = new ArrayList<>(set.size());
list.addAll(set);
return Collections.unmodifiableList(list);
}
use of org.eclipse.jdt.internal.compiler.batch.FileSystem in project lombok by projectlombok.
the class RunTestsViaEcj method createFileSystem.
private FileSystem createFileSystem(File file, int minVersion) {
List<String> classpath = new ArrayList<String>();
if (new File("bin/main").exists())
classpath.add("bin/main");
classpath.add("dist/lombok.jar");
classpath.add("build/teststubs");
if (bootRuntimePath == null || bootRuntimePath.isEmpty())
throw new IllegalStateException("System property delombok.bootclasspath is not set; set it to the rt of java6 or java8");
classpath.add(bootRuntimePath);
for (File f : new File("lib/test").listFiles()) {
String fn = f.getName();
if (fn.length() < 4)
continue;
if (!fn.substring(fn.length() - 4).toLowerCase().equals(".jar"))
continue;
classpath.add("lib/test/" + fn);
}
for (Iterator<String> i = classpath.iterator(); i.hasNext(); ) {
if (FileSystem.getClasspath(i.next(), "UTF-8", null) == null) {
i.remove();
}
}
return new FileSystem(classpath.toArray(new String[0]), new String[] { file.getAbsolutePath() }, "UTF-8");
}
Aggregations