Example usage for org.eclipse.jdt.internal.compiler.impl CompilerOptions VERSION_1_8

List of usage examples for org.eclipse.jdt.internal.compiler.impl CompilerOptions VERSION_1_8

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.impl CompilerOptions VERSION_1_8.

Prototype

String VERSION_1_8

To view the source code for org.eclipse.jdt.internal.compiler.impl CompilerOptions VERSION_1_8.

Click Source Link

Usage

From source file:com.bsiag.eclipse.jdt.java.formatter.DefaultCodeFormatter.java

License:Open Source License

private void initOptions(DefaultCodeFormatterOptions defaultCodeFormatterOptions, Map<String, String> options) {
    if (options != null) {
        this.originalOptions = new DefaultCodeFormatterOptions(options);
        this.workingOptions = new DefaultCodeFormatterOptions(options);
        this.oldCommentFormatOption = getOldCommentFormatOption(options);
        String compilerSource = options.get(CompilerOptions.OPTION_Source);
        this.sourceLevel = compilerSource != null ? compilerSource : CompilerOptions.VERSION_1_8;
    } else {/*from  w w  w  . j av  a 2 s.c  o  m*/
        Map<String, String> settings = DefaultCodeFormatterConstants.getJavaConventionsSettings();
        this.originalOptions = new DefaultCodeFormatterOptions(settings);
        this.workingOptions = new DefaultCodeFormatterOptions(settings);
        this.oldCommentFormatOption = DefaultCodeFormatterConstants.TRUE;
        this.sourceLevel = CompilerOptions.VERSION_1_8;
    }
    if (defaultCodeFormatterOptions != null) {
        this.originalOptions.set(defaultCodeFormatterOptions.getMap());
        this.workingOptions.set(defaultCodeFormatterOptions.getMap());
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.JarPackageFragmentRoot.java

License:Open Source License

/**
 * Compute the package fragment children of this package fragment root.
 * These are all of the directory zip entries, and any directories implied
 * by the path of class files contained in the jar of this package fragment root.
 *//*w w w . j  av a 2s.  c  o m*/
protected boolean computeChildren(OpenableElementInfo info, File underlyingResource) throws JavaModelException {
    HashtableOfArrayToObject rawPackageInfo = new HashtableOfArrayToObject();
    IJavaElement[] children;
    ZipFile jar = null;
    try {
        //            Object file = JavaModel.getTarget(getPath(), true);
        //            long level = Util.getJdkLevel(file);
        String compliance = CompilerOptions.VERSION_1_8;
        jar = getJar();

        // always create the default package
        rawPackageInfo.put(CharOperation.NO_STRINGS, new ArrayList[] { EMPTY_LIST, EMPTY_LIST });

        for (Enumeration e = jar.entries(); e.hasMoreElements();) {
            ZipEntry member = (ZipEntry) e.nextElement();
            initRawPackageInfo(rawPackageInfo, member.getName(), member.isDirectory(), compliance);
        }

        // loop through all of referenced packages, creating package fragments if necessary
        // and cache the entry names in the rawPackageInfo table
        children = new IJavaElement[rawPackageInfo.size()];
        int index = 0;
        for (int i = 0, length = rawPackageInfo.keyTable.length; i < length; i++) {
            String[] pkgName = (String[]) rawPackageInfo.keyTable[i];
            if (pkgName == null)
                continue;
            children[index++] = getPackageFragment(pkgName);
        }
    } catch (CoreException e) {
        if (e.getCause() instanceof ZipException) {
            // not a ZIP archive, leave the children empty
            Util.log(IStatus.ERROR, "Invalid ZIP archive: " + toStringWithAncestors()); //$NON-NLS-1$
            children = NO_ELEMENTS;
        } else if (e instanceof JavaModelException) {
            throw (JavaModelException) e;
        } else {
            throw new JavaModelException(e);
        }
    } finally {
        manager.closeZipFile(jar);
    }

    info.setChildren(children);
    ((JarPackageFragmentRootInfo) info).rawPackageInfo = rawPackageInfo;
    return true;
}

From source file:com.tsc9526.monalisa.plugin.eclipse.jdt.JDTCompiler.java

License:Open Source License

public CompilerOptions getCompilerOptions() {
    Map<String, String> settings = new HashMap<String, String>();
    settings.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE);
    settings.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
    settings.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
    settings.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE);
    settings.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE);
    settings.put(CompilerOptions.OPTION_Encoding, "UTF-8");
    settings.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
    String javaVersion = CompilerOptions.VERSION_1_6;

    if (System.getProperty("java.version").startsWith("1.5")) {
        javaVersion = CompilerOptions.VERSION_1_5;
    } else if (System.getProperty("java.version").startsWith("1.7")) {
        javaVersion = CompilerOptions.VERSION_1_7;
    } else if (System.getProperty("java.version").startsWith("1.8")) {
        javaVersion = CompilerOptions.VERSION_1_8;
    }//from   w  w  w. j  av  a2 s  . c  o m

    settings.put(CompilerOptions.OPTION_Source, javaVersion);
    settings.put(CompilerOptions.OPTION_TargetPlatform, javaVersion);
    settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE);
    settings.put(CompilerOptions.OPTION_Compliance, javaVersion);
    return new CompilerOptions(settings);
}

From source file:com.xqbase.compiler.eclipse.EclipseJavaCompiler.java

License:Open Source License

private String decodeVersion(String versionSpec) {
    if (StringUtils.isEmpty(versionSpec)) {
        return null;
    } else if ("1.1".equals(versionSpec)) {
        return CompilerOptions.VERSION_1_1;
    } else if ("1.2".equals(versionSpec)) {
        return CompilerOptions.VERSION_1_2;
    } else if ("1.3".equals(versionSpec)) {
        return CompilerOptions.VERSION_1_3;
    } else if ("1.4".equals(versionSpec)) {
        return CompilerOptions.VERSION_1_4;
    } else if ("1.5".equals(versionSpec)) {
        return CompilerOptions.VERSION_1_5;
    } else if ("1.6".equals(versionSpec)) {
        return CompilerOptions.VERSION_1_6;
    } else if ("1.7".equals(versionSpec)) {
        return CompilerOptions.VERSION_1_7;
    }/*from www .  j  a v  a2s .c  o m*/
    // added by xqbase-compiler-eclipse
    else if ("1.8".equals(versionSpec)) {
        return CompilerOptions.VERSION_1_8;
    } else {
        getLogger().warn(
                "Unknown version '" + versionSpec + "', no version setting will be given to the compiler.");

        return null;
    }
}

From source file:io.gige.compiler.internal.CompilationTaskImpl.java

License:Apache License

protected Main parseOptions(PrintWriter out, Iterable<String> argv,
        Iterable<? extends JavaFileObject> compilationUnits) {
    Map<String, String> defaults = new HashMap<>();
    defaults.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8);
    defaults.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8);
    defaults.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_8);

    Stream<String> files = Stream.concat(stream(argv.spliterator(), false),
            stream(compilationUnits.spliterator(), false).map(JavaFileObject::toUri)
                    .map(uri -> new File(uri).getAbsolutePath()));

    Main main = new Main(out, out, false, defaults, null);
    main.configure(files.toArray(String[]::new));
    return main;/*from  ww w  .  j a v a2  s  .  c o  m*/
}

From source file:org.ant4eclipse.ant.jdt.ecj.CompilerOptionsProvider.java

License:Open Source License

/**
 * <p>//from www.  j ava  2s  . co  m
 * Returns the compiler options specified in the javac task.
 * </p>
 * 
 * @param javac
 *          the javac task
 * @return the compiler options specified in the javac task.
 */
@SuppressWarnings("unchecked")
private static final StringMap getJavacCompilerOptions(Javac javac) {

    StringMap result = new StringMap();

    /*
     * set the source option
     */
    if (Utilities.hasText(javac.getSource())) {

        // get the source
        String source = javac.getSource();
        // set the source
        if (source.equals("1.3")) {
            result.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
        } else if (source.equals("1.4")) {
            result.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4);
        } else if (source.equals("1.5") || source.equals("5") || source.equals("5.0")) {
            result.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
        } else if (source.equals("1.6") || source.equals("6") || source.equals("6.0")) {
            result.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6);
        } else if (source.equals("1.7") || source.equals("7") || source.equals("7.0")) {
            result.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_7);
        } else if (source.equals("1.8") || source.equals("8") || source.equals("8.0")) {
            result.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8);
        } else {
            throw new Ant4EclipseException(EcjExceptionCodes.UNKNOWN_JAVA_SOURCE_OPTION_EXCEPTION, source);
        }
    }

    /*
     * set the target option
     */
    if (Utilities.hasText(javac.getTarget())) {

        // get the target
        String target = javac.getTarget();

        // set the target
        if (target.equals("1.3")) {
            result.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_3);
            result.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_3);
        } else if (target.equals("1.4")) {
            result.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
            result.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4);
        } else if (target.equals("1.5") || target.equals("5") || target.equals("5.0")) {
            result.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
            result.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
        } else if (target.equals("1.6") || target.equals("6") || target.equals("6.0")) {
            result.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6);
            result.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6);
        } else if (target.equals("1.7") || target.equals("7") || target.equals("7.0")) {
            result.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_7);
            result.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7);
        } else if (target.equals("1.8") || target.equals("8") || target.equals("8.0")) {
            result.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_8);
            result.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8);
        } else {
            throw new Ant4EclipseException(EcjExceptionCodes.UNKNOWN_JAVA_TARGET_OPTION_EXCEPTION, target);
        }
    }

    /*
     * set the debug options
     */
    if (javac.getDebug()) {

        String debugLevel = javac.getDebugLevel();

        if (debugLevel != null) {
            result.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE);
            result.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE);
            result.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.DO_NOT_GENERATE);
            if (debugLevel.length() != 0) {
                if (debugLevel.indexOf("vars") != -1) {
                    result.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
                }
                if (debugLevel.indexOf("lines") != -1) {
                    result.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
                }
                if (debugLevel.indexOf("source") != -1) {
                    result.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
                }
            }
        } else {
            result.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
            result.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
            result.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
        }
    } else {
        result.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE);
        result.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE);
        result.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.DO_NOT_GENERATE);
    }

    /*
     * Handle the nowarn option. If none, then we generate all warnings.
     */
    if (javac.getNowarn()) {
        // disable all warnings
        Map.Entry<String, String>[] entries = result.entrySet().toArray(new Map.Entry[result.size()]);
        for (Entry<String, String> entrie : entries) {
            Map.Entry<String, String> entry = entrie;
            if (entry.getValue().equals(CompilerOptions.WARNING)) {
                result.put(entry.getKey(), CompilerOptions.IGNORE);
            }
        }
        result.put(CompilerOptions.OPTION_TaskTags, Util.EMPTY_STRING);
        if (javac.getDeprecation()) {
            result.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING);
            result.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.ENABLED);
            result.put(CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod,
                    CompilerOptions.ENABLED);
        }
    } else if (javac.getDeprecation()) {
        result.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING);
        result.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.ENABLED);
        result.put(CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod,
                CompilerOptions.ENABLED);
    } else {
        result.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE);
        result.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.DISABLED);
        result.put(CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod,
                CompilerOptions.DISABLED);
    }

    /*
     * set the encoding option
     */
    if (javac.getEncoding() != null) {
        result.put(CompilerOptions.OPTION_Encoding, javac.getEncoding());
    }

    // return result
    return result;
}

From source file:org.z2env.impl.components.java.jdt.SimpleJDTCompiler.java

License:Apache License

public boolean compile() {
    long start = System.currentTimeMillis();
    _delete(this.outRoot);
    this.outRoot.mkdirs();
    Map<String, String> settings = new HashMap<String, String>();

    LangLevel ll = JavaComponentUtil.determineLanguageLevel();

    switch (ll) {
    case JAVA6:// ww w. j a v  a 2  s  . c om
        settings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6);
        settings.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6);
        settings.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6);
        break;
    case JAVA7:
        settings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_7);
        settings.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_7);
        settings.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7);
        break;
    case JAVA8:
        settings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8);
        settings.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_8);
        settings.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8);
        break;
    default:
        throw new IllegalStateException("Unsupported language level: " + ll);
    }

    // general compiler options - derived from the VM
    settings.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
    settings.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
    settings.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
    settings.put(CompilerOptions.OPTION_Encoding, UTF8);

    CompilerOptions options = new CompilerOptions(settings);

    INameEnvironment ne = new NameEnvironmentImpl(this.classPath, UTF8, this.srcs);
    CompilerRequestorImpl cr = new CompilerRequestorImpl(this.outRoot);
    ICompilationUnit[] sources = _findSource();
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("Compiling " + sources.length + " source files from " + Arrays.asList(this.srcs) + " to "
                + this.outRoot + " using lang level " + ll);
    }
    org.eclipse.jdt.internal.compiler.Compiler c = new Compiler(ne,
            DefaultErrorHandlingPolicies.exitOnFirstError(), options, cr,
            new DefaultProblemFactory(Locale.getDefault()));
    c.compile(sources);
    long duration = System.currentTimeMillis() - start;
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("Compilation of " + Arrays.asList(this.srcs) + " completed after " + duration + "ms");
    }
    this.successful = !cr.hasError();
    return this.successful;
}

From source file:processing.mode.java.pdex.ErrorCheckerService.java

License:Open Source License

/** Set compiler options for JDT Compiler */
protected void prepareCompilerSetting() {
    compilerSettings = new HashMap<String, String>();

    compilerSettings.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
    compilerSettings.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
    compilerSettings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8);
    compilerSettings.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE);
    compilerSettings.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE);
    compilerSettings.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE);
    compilerSettings.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE);
}