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

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

Introduction

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

Prototype

public CompilerOptions() 

Source Link

Document

Initializing the compiler options with defaults

Usage

From source file:br.com.objectos.code.JdtCompilerBuilderPojo.java

License:Apache License

@Override
public JdtCompiler build() {
    NameEnvironment environment = new NameEnvironment();
    IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.exitAfterAllProblems();
    CompilerOptions options = new CompilerOptions();
    options.set(optionMap.build());/* w w w . ja  v a2 s. com*/
    IProblemFactory problemFactory = ProblemFactory.getProblemFactory(Locale.getDefault());
    Compiler delegate = new Compiler(environment, policy, options, requestor, problemFactory);
    annotationProcessorManager.set(delegate);
    return new JdtCompiler(delegate);
}

From source file:ch.uzh.ifi.seal.changedistiller.ast.java.JavaCompilationUtils.java

License:Apache License

private static CompilerOptions getDefaultCompilerOptions(long version) {
    CompilerOptions options = new CompilerOptions();
    options.docCommentSupport = true;//  w ww  . jav a  2  s .c  o  m
    options.complianceLevel = version;
    options.sourceLevel = version;
    options.targetJDK = version;
    return options;
}

From source file:ch.uzh.ifi.seal.changedistiller.ast.java.JavaCompilationUtils.java

License:Apache License

private static CompilerOptions getDefaultCompilerOptions() {
    CompilerOptions options = new CompilerOptions();
    options.docCommentSupport = true;//from   w ww  .  j  av a2 s .c  om
    options.complianceLevel = ClassFileConstants.JDK1_6;
    options.sourceLevel = ClassFileConstants.JDK1_6;
    options.targetJDK = ClassFileConstants.JDK1_6;
    return options;
}

From source file:com.android.tools.idea.lint.LombokPsiConverterTest.java

License:Apache License

@Nullable
private static Node parse(String code) {
    CompilerOptions options = new CompilerOptions();
    options.complianceLevel = options.sourceLevel = options.targetJDK = ClassFileConstants.JDK1_7;
    options.parseLiteralExpressionsAsConstants = true;
    ProblemReporter problemReporter = new ProblemReporter(DefaultErrorHandlingPolicies.exitOnFirstError(),
            options, new DefaultProblemFactory());
    Parser parser = new Parser(problemReporter, options.parseLiteralExpressionsAsConstants);
    parser.javadocParser.checkDocComment = false;
    EcjTreeConverter converter = new EcjTreeConverter();
    org.eclipse.jdt.internal.compiler.batch.CompilationUnit sourceUnit = new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(
            code.toCharArray(), "unitTest", "UTF-8");
    CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
    CompilationUnitDeclaration unit = parser.parse(sourceUnit, compilationResult);
    if (unit == null) {
        return null;
    }/* w  ww  .  j ava  2  s  .c om*/
    converter.visit(code, unit);
    List<? extends Node> nodes = converter.getAll();
    for (lombok.ast.Node node : nodes) {
        if (node instanceof lombok.ast.CompilationUnit) {
            return node;
        }
    }
    return null;
}

From source file:com.android.tools.lint.EcjParser.java

License:Apache License

/**
 * Create the default compiler options//www . ja v  a 2s .co  m
 */
public static CompilerOptions createCompilerOptions() {
    CompilerOptions options = new CompilerOptions();

    // Always using JDK 7 rather than basing it on project metadata since we
    // don't do compilation error validation in lint (we leave that to the IDE's
    // error parser or the command line build's compilation step); we want an
    // AST that is as tolerant as possible.
    long languageLevel = ClassFileConstants.JDK1_7;
    options.complianceLevel = languageLevel;
    options.sourceLevel = languageLevel;
    options.targetJDK = languageLevel;
    options.originalComplianceLevel = languageLevel;
    options.originalSourceLevel = languageLevel;
    options.inlineJsrBytecode = true; // >1.5

    options.parseLiteralExpressionsAsConstants = true;
    options.analyseResourceLeaks = false;
    options.docCommentSupport = false;
    options.defaultEncoding = UTF_8;
    options.suppressOptionalErrors = true;
    options.generateClassFiles = false;
    options.isAnnotationBasedNullAnalysisEnabled = false;
    options.reportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable = false;
    options.reportUnusedDeclaredThrownExceptionIncludeDocCommentReference = false;
    options.reportUnusedDeclaredThrownExceptionWhenOverriding = false;
    options.reportUnusedParameterIncludeDocCommentReference = false;
    options.reportUnusedParameterWhenImplementingAbstract = false;
    options.reportUnusedParameterWhenOverridingConcrete = false;
    options.suppressWarnings = true;
    options.processAnnotations = true;
    options.storeAnnotations = true;
    options.verbose = false;
    return options;
}

From source file:com.google.gwt.dev.javac.BinaryTypeReferenceRestrictionsCheckerTest.java

License:Apache License

private static LookupEnvironment createMockLookupEnvironment() {
    LookupEnvironment lookupEnvironment = new LookupEnvironment(null, new CompilerOptions(), null, null);
    return lookupEnvironment;
}

From source file:com.google.gwt.dev.javac.JavaSourceParser.java

License:Open Source License

/**
 * Parse Java source.//from w ww.  j  a v  a  2 s  . co m
 * 
 * @param javaSource String containing Java source to parse
 * @return a CompilationUnitDeclaration or null if parsing failed
 */
private static CompilationUnitDeclaration parseJava(String javaSource) {
    CodeSnippetParsingUtil parsingUtil = new CodeSnippetParsingUtil();
    CompilerOptions options = new CompilerOptions();
    options.complianceLevel = ClassFileConstants.JDK1_5;
    options.sourceLevel = ClassFileConstants.JDK1_5;
    CompilationUnitDeclaration unit = parsingUtil.parseCompilationUnit(javaSource.toString().toCharArray(),
            options.getMap(), true);
    if (unit.compilationResult().hasProblems()) {
        return null;
    }
    return unit;
}

From source file:com.google.gwt.dev.javac.JdtCompiler.java

License:Open Source License

public static CompilerOptions getCompilerOptions() {
    CompilerOptions options = new CompilerOptions();
    options.complianceLevel = options.sourceLevel = options.targetJDK = ClassFileConstants.JDK1_6;

    // Generate debug info for debugging the output.
    options.produceDebugAttributes = ClassFileConstants.ATTR_VARS | ClassFileConstants.ATTR_LINES
            | ClassFileConstants.ATTR_SOURCE;
    // Tricks like "boolean stopHere = true;" depend on this setting.
    options.preserveAllLocalVariables = true;

    // Turn off all warnings, saves some memory / speed.
    options.reportUnusedDeclaredThrownExceptionIncludeDocCommentReference = false;
    options.reportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable = false;
    // Instantiations    options.warningThreshold = 0;
    options.inlineJsrBytecode = true;//w  ww .j  a v a 2  s. co m
    return options;
}

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();
    }//  www  .  jav  a  2s.c  o  m

    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:fr.inria.astor.core.manipulation.compiler.bytecode.JDTByteCodeCompiler.java

License:Open Source License

public CompilerOptions getCompilerOption() {
    if (compilerOption == null) {
        compilerOption = new CompilerOptions();
        compilerOption.sourceLevel = ClassFileConstants.JDK1_6;//ClassFileConstants.JDK1_5;
        compilerOption.suppressWarnings = true;

        ///*from  www.  j a  v a  2s  .c o  m*/

        compilerOption.targetJDK = ClassFileConstants.JDK1_6; //was 6

        compilerOption.produceDebugAttributes = ClassFileConstants.ATTR_SOURCE | ClassFileConstants.ATTR_LINES
                | ClassFileConstants.ATTR_VARS;
        compilerOption.preserveAllLocalVariables = true;
        compilerOption.inlineJsrBytecode = true;

        //MM
        compilerOption.tolerateIllegalAmbiguousVarargsInvocation = true;
    }
    return compilerOption;
}