Example usage for org.eclipse.jdt.internal.compiler.impl IrritantSet COMPILER_DEFAULT_WARNINGS

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

Introduction

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

Prototype

IrritantSet COMPILER_DEFAULT_WARNINGS

To view the source code for org.eclipse.jdt.internal.compiler.impl IrritantSet COMPILER_DEFAULT_WARNINGS.

Click Source Link

Usage

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 {/*from w  w  w.j a  v a2s. 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:org.eclipse.objectteams.internal.jdt.nullity.CompilerAdaptation.java

License:Open Source License

public CompilerAdaptation() {
     // add more irritants to IrritantSet:
     IrritantSet.COMPILER_DEFAULT_ERRORS
             .set(NullCompilerOptions.NullSpecViolation | NullCompilerOptions.PotentialNullSpecViolation);
     IrritantSet.COMPILER_DEFAULT_WARNINGS
             .set(NullCompilerOptions.NullSpecInsufficientInfo | NullCompilerOptions.RedundantNullAnnotation);
     IrritantSet.NULL.set(NullCompilerOptions.NullSpecViolation | NullCompilerOptions.PotentialNullSpecViolation
             | NullCompilerOptions.NullSpecInsufficientInfo | NullCompilerOptions.RedundantNullAnnotation);
 }