Search in sources :

Example 1 with FileSystem

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);
}
Also used : IErrorHandlingPolicy(org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy) Compiler(org.eclipse.jdt.internal.compiler.Compiler) FileSystem(org.eclipse.jdt.internal.compiler.batch.FileSystem) CompilerOptions(org.eclipse.jdt.internal.compiler.impl.CompilerOptions) INameEnvironment(org.eclipse.jdt.internal.compiler.env.INameEnvironment) DefaultProblemFactory(org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory) ICompilerRequestor(org.eclipse.jdt.internal.compiler.ICompilerRequestor) IProblemFactory(org.eclipse.jdt.internal.compiler.IProblemFactory)

Example 2 with FileSystem

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");
}
Also used : FileSystem(org.eclipse.jdt.internal.compiler.batch.FileSystem) ArrayList(java.util.ArrayList) File(java.io.File)

Example 3 with FileSystem

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");
}
Also used : FileSystem(org.eclipse.jdt.internal.compiler.batch.FileSystem) ArrayList(java.util.ArrayList) File(java.io.File)

Example 4 with FileSystem

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);
}
Also used : PackageElement(javax.lang.model.element.PackageElement) Element(javax.lang.model.element.Element) ArrayList(java.util.ArrayList) PackageBinding(org.eclipse.jdt.internal.compiler.lookup.PackageBinding) ReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) LookupEnvironment(org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment) FileSystem(org.eclipse.jdt.internal.compiler.batch.FileSystem) INameEnvironment(org.eclipse.jdt.internal.compiler.env.INameEnvironment) HashSet(java.util.HashSet)

Example 5 with FileSystem

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");
}
Also used : FileSystem(org.eclipse.jdt.internal.compiler.batch.FileSystem) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

FileSystem (org.eclipse.jdt.internal.compiler.batch.FileSystem)5 ArrayList (java.util.ArrayList)4 File (java.io.File)3 INameEnvironment (org.eclipse.jdt.internal.compiler.env.INameEnvironment)2 HashSet (java.util.HashSet)1 Element (javax.lang.model.element.Element)1 PackageElement (javax.lang.model.element.PackageElement)1 Compiler (org.eclipse.jdt.internal.compiler.Compiler)1 ICompilerRequestor (org.eclipse.jdt.internal.compiler.ICompilerRequestor)1 IErrorHandlingPolicy (org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy)1 IProblemFactory (org.eclipse.jdt.internal.compiler.IProblemFactory)1 CompilerOptions (org.eclipse.jdt.internal.compiler.impl.CompilerOptions)1 LookupEnvironment (org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment)1 PackageBinding (org.eclipse.jdt.internal.compiler.lookup.PackageBinding)1 ReferenceBinding (org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding)1 DefaultProblemFactory (org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory)1