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

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

Introduction

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

Prototype

String OPTION_LineNumberAttribute

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

Click Source Link

Usage

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 a  va 2s. co  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

public CompilerResult performCompile(CompilerConfiguration config) throws CompilerException {

    // added by xqbase-compiler-eclipse
    if (config.getGeneratedSourcesDirectory() != null) {
        config.getGeneratedSourcesDirectory().mkdirs();
    }/*from  ww w.  j a  v a 2  s  .com*/

    List<CompilerMessage> errors = new LinkedList<CompilerMessage>();

    List<String> classpathEntries = config.getClasspathEntries();

    URL[] urls = new URL[1 + classpathEntries.size()];

    int i = 0;

    try {
        urls[i++] = new File(config.getOutputLocation()).toURL();

        for (String entry : classpathEntries) {
            urls[i++] = new File(entry).toURL();
        }
    } catch (MalformedURLException e) {
        throw new CompilerException("Error while converting the classpath entries to URLs.", e);
    }

    ClassLoader classLoader = new URLClassLoader(urls);

    SourceCodeLocator sourceCodeLocator = new SourceCodeLocator(config.getSourceLocations());

    INameEnvironment env = new EclipseCompilerINameEnvironment(sourceCodeLocator, classLoader, errors);

    IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems();

    // ----------------------------------------------------------------------
    // Build settings from configuration
    // ----------------------------------------------------------------------

    Map<String, String> settings = new HashMap<String, String>();

    if (config.isDebug()) {
        settings.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
        settings.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
        settings.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
    }

    if (!config.isShowWarnings()) {
        Map opts = new CompilerOptions().getMap();
        for (Object optKey : opts.keySet()) {
            if (opts.get(optKey).equals(CompilerOptions.WARNING)) {
                settings.put((String) optKey, CompilerOptions.IGNORE);
            }
        }
    }

    String sourceVersion = decodeVersion(config.getSourceVersion());

    if (sourceVersion != null) {
        settings.put(CompilerOptions.OPTION_Source, sourceVersion);
    }

    String targetVersion = decodeVersion(config.getTargetVersion());

    if (targetVersion != null) {
        settings.put(CompilerOptions.OPTION_TargetPlatform, targetVersion);

        if (config.isOptimize()) {
            settings.put(CompilerOptions.OPTION_Compliance, targetVersion);
        }
    }

    if (StringUtils.isNotEmpty(config.getSourceEncoding())) {
        settings.put(CompilerOptions.OPTION_Encoding, config.getSourceEncoding());
    }

    if (config.isShowDeprecation()) {
        settings.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING);
    } else {
        settings.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE);
    }

    // ----------------------------------------------------------------------
    // Set Eclipse-specific options
    // ----------------------------------------------------------------------

    settings.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
    settings.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);

    // compiler-specific extra options override anything else in the config object...
    Map<String, String> extras = config.getCustomCompilerArguments();
    if (extras != null && !extras.isEmpty()) {
        settings.putAll(extras);
    }

    if (settings.containsKey("-properties")) {
        initializeWarnings(settings.get("-properties"), settings);
        settings.remove("-properties");
    }

    IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());

    ICompilerRequestor requestor = new EclipseCompilerICompilerRequestor(config.getOutputLocation(), errors);

    List<CompilationUnit> compilationUnits = new ArrayList<CompilationUnit>();

    for (String sourceRoot : config.getSourceLocations()) {
        Set<String> sources = getSourceFilesForSourceRoot(config, sourceRoot);

        for (String source : sources) {
            CompilationUnit unit = new CompilationUnit(source, makeClassName(source, sourceRoot), errors,
                    config.getSourceEncoding());

            compilationUnits.add(unit);
        }
    }

    // ----------------------------------------------------------------------
    // Compile!
    // ----------------------------------------------------------------------

    CompilerOptions options = new CompilerOptions(settings);
    Compiler compiler = new Compiler(env, policy, options, requestor, problemFactory);

    ICompilationUnit[] units = compilationUnits.toArray(new ICompilationUnit[compilationUnits.size()]);

    compiler.compile(units);

    CompilerResult compilerResult = new CompilerResult().compilerMessages(errors);

    for (CompilerMessage compilerMessage : errors) {
        if (compilerMessage.isError()) {
            compilerResult.setSuccess(false);
            continue;
        }
    }

    return compilerResult;
}

From source file:dacapo.eclipse.EclipseBuildTests.java

License:Open Source License

protected static Hashtable warningOptions(int kind) {
    // Values/*from w ww.j  a  v a 2  s .c  o  m*/
    Hashtable optionsMap = null;
    switch (kind) {
    case 0:
        optionsMap = JavaCore.getDefaultOptions();
        break;
    default:
        optionsMap = new Hashtable(350);
        break;
    }
    if (kind == 0) {
        // Default set since 3.1
        optionsMap.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE);
    } else {
        boolean all = kind == 1;
        String generate = all ? CompilerOptions.GENERATE : CompilerOptions.DO_NOT_GENERATE;
        String warning = all ? CompilerOptions.WARNING : CompilerOptions.IGNORE;
        String enabled = all ? CompilerOptions.ENABLED : CompilerOptions.DISABLED;
        String preserve = all ? CompilerOptions.OPTIMIZE_OUT : CompilerOptions.PRESERVE;

        // Set options values
        optionsMap.put(CompilerOptions.OPTION_LocalVariableAttribute, generate);
        optionsMap.put(CompilerOptions.OPTION_LineNumberAttribute, generate);
        optionsMap.put(CompilerOptions.OPTION_SourceFileAttribute, generate);
        optionsMap.put(CompilerOptions.OPTION_PreserveUnusedLocal, preserve);
        optionsMap.put(CompilerOptions.OPTION_DocCommentSupport, enabled);
        optionsMap.put(CompilerOptions.OPTION_ReportMethodWithConstructorName, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportOverridingPackageDefaultMethod, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportDeprecation, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, enabled);
        optionsMap.put(CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, enabled);
        optionsMap.put(CompilerOptions.OPTION_ReportHiddenCatchBlock, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportUnusedLocal, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportUnusedParameter, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportUnusedImport, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportNoEffectAssignment, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportNoImplicitStringConversion, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportIndirectStaticAccess, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportIncompatibleNonInheritedInterfaceMethod, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportLocalVariableHiding, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportFieldHiding, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportPossibleAccidentalBooleanAssignment, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportEmptyStatement, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportAssertIdentifier, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportUndocumentedEmptyBlock, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportUnnecessaryElse, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportInvalidJavadoc, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportInvalidJavadocTags, enabled);
        optionsMap.put(CompilerOptions.OPTION_ReportMissingJavadocTags, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportMissingJavadocComments, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportFinallyBlockNotCompletingNormally, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownException, warning);
        optionsMap.put(CompilerOptions.OPTION_ReportUnqualifiedFieldAccess, warning);
        optionsMap.put(CompilerOptions.OPTION_TaskTags, all ? JavaCore.DEFAULT_TASK_TAGS : "");
        optionsMap.put(CompilerOptions.OPTION_TaskPriorities, all ? JavaCore.DEFAULT_TASK_PRIORITIES : "");
        optionsMap.put(CompilerOptions.OPTION_TaskCaseSensitive, enabled);
        optionsMap.put(CompilerOptions.OPTION_ReportUnusedParameterWhenImplementingAbstract, enabled);
        optionsMap.put(CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete, enabled);
        optionsMap.put(CompilerOptions.OPTION_ReportSpecialParameterHidingField, enabled);
        optionsMap.put(CompilerOptions.OPTION_InlineJsr, enabled);
    }

    // Ignore 3.1 options
    optionsMap.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE);
    optionsMap.put(CompilerOptions.OPTION_ReportEnumIdentifier, CompilerOptions.IGNORE);

    // Return created options map
    return optionsMap;
}

From source file:io.takari.maven.plugins.compile.jdt.CompilerJdt.java

License:Open Source License

@Override
public int compile() throws MojoExecutionException, IOException {
    Map<String, String> args = new HashMap<String, String>();
    // XXX figure out how to reuse source/target check from jdt
    // org.eclipse.jdt.internal.compiler.batch.Main.validateOptions(boolean)
    args.put(CompilerOptions.OPTION_TargetPlatform, getTarget()); // support 5/6/7 aliases
    args.put(CompilerOptions.OPTION_Compliance, getTarget()); // support 5/6/7 aliases
    args.put(CompilerOptions.OPTION_Source, getSource()); // support 5/6/7 aliases
    args.put(CompilerOptions.OPTION_ReportForbiddenReference, CompilerOptions.ERROR);
    Set<Debug> debug = getDebug();
    if (debug == null || debug.contains(Debug.all)) {
        args.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
        args.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
        args.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
    } else if (debug.contains(Debug.none)) {
        args.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE);
        args.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE);
        args.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.DO_NOT_GENERATE);
    } else {/*w ww.j  a v  a 2 s.c  o m*/
        args.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE);
        args.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE);
        args.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.DO_NOT_GENERATE);
        for (Debug keyword : debug) {
            switch (keyword) {
            case lines:
                args.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
                break;
            case source:
                args.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
                break;
            case vars:
                args.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
                break;
            default:
                throw new IllegalArgumentException();
            }
        }
    }

    class _CompilerOptions extends CompilerOptions {
        public void setShowWarnings(boolean showWarnings) {
            if (showWarnings) {
                warningThreshold = IrritantSet.COMPILER_DEFAULT_WARNINGS;
            } else {
                warningThreshold = new IrritantSet(0);
            }
        }
    }
    _CompilerOptions compilerOptions = new _CompilerOptions();

    compilerOptions.set(args);
    compilerOptions.performMethodsFullRecovery = false;
    compilerOptions.performStatementsRecovery = false;
    compilerOptions.verbose = isVerbose();
    compilerOptions.suppressWarnings = true;
    compilerOptions.setShowWarnings(isShowWarnings());
    compilerOptions.docCommentSupport = true;

    if (isProcEscalate() && strategy instanceof IncrementalCompilationStrategy) {
        strategy.enqueueAllSources();
        strategy = new FullCompilationStrategy();
    }

    Classpath namingEnvironment = strategy.createClasspath();
    IErrorHandlingPolicy errorHandlingPolicy = DefaultErrorHandlingPolicies.exitAfterAllProblems();
    IProblemFactory problemFactory = ProblemFactory.getProblemFactory(Locale.getDefault());
    Compiler compiler = new Compiler(namingEnvironment, errorHandlingPolicy, compilerOptions, this,
            problemFactory);
    compiler.options.produceReferenceInfo = true;

    EclipseFileManager fileManager = null;
    try {
        if (!isProcNone()) {
            fileManager = new EclipseFileManager(null, getSourceEncoding());
            fileManager.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, dependencies);
            fileManager.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(getOutputDirectory()));
            fileManager.setLocation(StandardLocation.SOURCE_OUTPUT,
                    Collections.singleton(getGeneratedSourcesDirectory()));

            ProcessingEnvImpl processingEnv = new ProcessingEnvImpl(context, fileManager,
                    getAnnotationProcessorOptions(), compiler, this);

            compiler.annotationProcessorManager = new AnnotationProcessorManager(processingEnv, fileManager,
                    getAnnotationProcessors());
            compiler.options.storeAnnotations = true;
        }

        return strategy.compile(namingEnvironment, compiler);
    } finally {
        if (fileManager != null) {
            fileManager.flush();
            fileManager.close();
        }
    }
}

From source file:jetbrick.template.compiler.JdtCompiler.java

License:Open Source License

private CompilerOptions getCompilerOptions() {
    Map<String, String> settings = new HashMap<String, String>();
    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_Encoding, JavaSource.JAVA_FILE_ENCODING);
    settings.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
    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);

    CompilerOptions options = new CompilerOptions(settings);
    options.parseLiteralExpressionsAsConstants = true;
    return options;
}

From source file:ma.glasnost.orika.impl.generator.EclipseJdtCompiler.java

License:Apache License

private CompilerOptions getCompilerOptions() {

    Map<Object, Object> options = new HashMap<Object, Object>();

    options.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
    options.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
    options.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);

    options.put(CompilerOptions.OPTION_SuppressWarnings, CompilerOptions.ENABLED);

    options.put(CompilerOptions.OPTION_Source, JAVA_COMPILER_SOURCE_VERSION);
    options.put(CompilerOptions.OPTION_TargetPlatform, JAVA_COMPILER_CODEGEN_TARGET_PLATFORM_VERSION);
    options.put(CompilerOptions.OPTION_Encoding, JAVA_SOURCE_ENCODING);
    options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE);

    // Ignore unchecked types and raw types
    options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, CompilerOptions.IGNORE);
    options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, CompilerOptions.IGNORE);
    options.put(JavaCore.COMPILER_PB_VARARGS_ARGUMENT_NEED_CAST, CompilerOptions.IGNORE);

    return new CompilerOptions(options);
}

From source file:net.sf.jasperreports.eclipse.builder.jdt.JRJdtCompiler.java

License:Open Source License

protected Map<String, String> getJdtSettings() {
    if (settings == null) {
        settings = new HashMap<String, String>();
        settings.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
        settings.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
        settings.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE);
        // if (ctxt.getOptions().getJavaEncoding() != null)
        // {/*from w w  w . jav a  2s .c  o m*/
        // settings.put(CompilerOptions.OPTION_Encoding,
        // ctxt.getOptions().getJavaEncoding());
        // }
        // if (ctxt.getOptions().getClassDebugInfo())
        // {
        // settings.put(CompilerOptions.OPTION_LocalVariableAttribute,
        // CompilerOptions.GENERATE);
        // }

        List<JRPropertiesUtil.PropertySuffix> properties = JRPropertiesUtil.getInstance(jasperReportsContext)
                .getProperties(JDT_PROPERTIES_PREFIX);
        for (Iterator<JRPropertiesUtil.PropertySuffix> it = properties.iterator(); it.hasNext();) {
            JRPropertiesUtil.PropertySuffix property = it.next();
            String propVal = property.getValue();
            if (propVal != null && propVal.length() > 0) {
                settings.put(property.getKey(), propVal);
            }
        }

        Properties systemProps = System.getProperties();
        for (Enumeration<String> it = (Enumeration<String>) systemProps.propertyNames(); it
                .hasMoreElements();) {
            String propName = it.nextElement();
            if (propName.startsWith(JDT_PROPERTIES_PREFIX)) {
                String propVal = systemProps.getProperty(propName);
                if (propVal != null && propVal.length() > 0) {
                    settings.put(propName, propVal);
                }
            }
        }
    }
    return settings;
}

From source file:net.sf.jasperreports.engine.design.JRJdtCompiler.java

License:LGPL

protected Map getJdtSettings() {
    final Map settings = new HashMap();
    settings.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
    settings.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
    settings.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE);
    //      if (ctxt.getOptions().getJavaEncoding() != null) 
    //      {/*  w w w. j a  va  2 s.com*/
    //         settings.put(CompilerOptions.OPTION_Encoding, ctxt.getOptions().getJavaEncoding());
    //      }
    //      if (ctxt.getOptions().getClassDebugInfo()) 
    //      {
    //         settings.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
    //      }

    List properties = JRProperties.getProperties(JDT_PROPERTIES_PREFIX);
    for (Iterator it = properties.iterator(); it.hasNext();) {
        JRProperties.PropertySuffix property = (JRProperties.PropertySuffix) it.next();
        String propVal = property.getValue();
        if (propVal != null && propVal.length() > 0) {
            settings.put(property.getKey(), propVal);
        }
    }

    Properties systemProps = System.getProperties();
    for (Enumeration it = systemProps.propertyNames(); it.hasMoreElements();) {
        String propName = (String) it.nextElement();
        if (propName.startsWith(JDT_PROPERTIES_PREFIX)) {
            String propVal = systemProps.getProperty(propName);
            if (propVal != null && propVal.length() > 0) {
                settings.put(propName, propVal);
            }
        }
    }

    return settings;
}

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

License:Open Source License

/**
 * <p>//from   w  w  w.  j a  va 2  s  . 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.ant4eclipse.ant.jdt.ecj.JavacCompilerAdapter.java

License:Open Source License

/**
 * Calculates the debugging options according to the supplied description.
 * //from w  w  w. j  ava  2s.co  m
 * @param description
 *          The descriptional instance providing all information to run a compile job. Not <code>null</code>.
 * 
 * @return The compile options used for the generation of byte code. Not <code>null</code>.
 */
private String getDebugOptions(CompileJobDescription description) {
    this._buffer.setLength(0);
    if (description.getCompilerOptions().containsKey(CompilerOptions.OPTION_LineNumberAttribute)) {
        this._buffer.append("lines");
    }
    if (description.getCompilerOptions().containsKey(CompilerOptions.OPTION_LocalVariableAttribute)) {
        if (this._buffer.length() > 0) {
            this._buffer.append(",");
        }
        this._buffer.append("vars");
    }
    if (description.getCompilerOptions().containsKey(CompilerOptions.OPTION_SourceFileAttribute)) {
        if (this._buffer.length() > 0) {
            this._buffer.append(",");
        }
        this._buffer.append("source");
    }
    if (this._buffer.length() == 0) {
        // nothing has been specified
        this._buffer.append("none");
    }
    return this._buffer.toString();
}