List of usage examples for org.eclipse.jdt.internal.compiler.impl CompilerOptions ERROR
String ERROR
To view the source code for org.eclipse.jdt.internal.compiler.impl CompilerOptions ERROR.
Click Source Link
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 w w .j av a 2 s . c om 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.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
protected Map getCompilerOptions() { Map defaultOptions = super.getCompilerOptions(); if (setNullRelatedOptions) { defaultOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); defaultOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.ERROR); defaultOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); defaultOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); defaultOptions.put(CompilerOptions.OPTION_IncludeNullInfoFromAsserts, CompilerOptions.ENABLED); defaultOptions.put(//from ww w . j a v a 2 s. c o m CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, CompilerOptions.DISABLED); // enable null annotations: defaultOptions.put(NullCompilerOptions.OPTION_AnnotationBasedNullAnalysis, CompilerOptions.ENABLED); // leave other new options at these defaults: // defaultOptions.put(CompilerOptions.OPTION_ReportNullSpecViolation, CompilerOptions.ERROR); // defaultOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, CompilerOptions.ERROR); // defaultOptions.put(CompilerOptions.OPTION_ReportNullSpecInsufficientInfo, CompilerOptions.WARNING); // defaultOptions.put(CompilerOptions.OPTION_ReportRedundantNullAnnotation, CompilerOptions.WARNING); // defaultOptions.put(CompilerOptions.OPTION_NullableAnnotationName, "org.eclipse.jdt.annotation.Nullable"); // defaultOptions.put(CompilerOptions.OPTION_NonNullAnnotationName, "org.eclipse.jdt.annotation.NonNull"); } return defaultOptions; }
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
public void test_nonnull_parameter_006() { Map customOptions = getCompilerOptions(); customOptions.put(NullCompilerOptions.OPTION_ReportNullSpecInsufficientInfo, CompilerOptions.ERROR); runConformTestWithLibs(/* w ww. j av a 2 s. co m*/ new String[] { "X.java", "import org.eclipse.jdt.annotation.*;\n" + "public class X {\n" + " void m1(@NonNull String a) {}\n" + " void m2(@Nullable String b) {\n" + " m1(b == null ? \"\" : b);\n" + " }\n" + "}\n" }, customOptions, "" /* compiler output */); }
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
public void test_nonnull_parameter_007() { Map customOptions = getCompilerOptions(); customOptions.put(NullCompilerOptions.OPTION_ReportNullSpecInsufficientInfo, CompilerOptions.ERROR); runNegativeTestWithLibs(new String[] { "XSub.java", "import org.eclipse.jdt.annotation.*;\n" + "public class XSub extends XSuper {\n" + " XSub(@Nullable String b) {\n" + " super(b);\n" + " }\n" + "}\n", "XSuper.java", "import org.eclipse.jdt.annotation.*;\n" + "public class XSuper {\n" + " XSuper(@NonNull String b) {\n" + " }\n" + "}\n" }, customOptions,/*from ww w . java2s. c om*/ "----------\n" + "1. ERROR in XSub.java (at line 4)\n" + " super(b);\n" + " ^\n" + "Type mismatch: required \'@NonNull String\' but the provided value can be null\n" + "----------\n"); }
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
public void test_nonnull_parameter_008() { Map customOptions = getCompilerOptions(); customOptions.put(NullCompilerOptions.OPTION_ReportNullSpecInsufficientInfo, CompilerOptions.ERROR); runNegativeTestWithLibs(//from w w w.j a v a 2s . c o m new String[] { "X.java", "import org.eclipse.jdt.annotation.*;\n" + "public class X {\n" + " X(@NonNull String a) {}\n" + " static X create(@Nullable String b) {\n" + " return new X(b);\n" + " }\n" + "}\n" }, customOptions, "----------\n" + "1. ERROR in X.java (at line 5)\n" + " return new X(b);\n" + " ^\n" + "Type mismatch: required \'@NonNull String\' but the provided value can be null\n" + "----------\n" /* compiler output */); }
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
public void test_nonnull_parameter_009() { Map customOptions = getCompilerOptions(); customOptions.put(NullCompilerOptions.OPTION_ReportNullSpecInsufficientInfo, CompilerOptions.ERROR); runNegativeTestWithLibs(//from w ww . j ava 2s. c o m new String[] { "X.java", "import org.eclipse.jdt.annotation.*;\n" + "public class X {\n" + " class Local {\n" + " Local(@NonNull String a) {}\n" + " }\n" + " Local create(@Nullable String b) {\n" + " return this.new Local(b);\n" + " }\n" + "}\n" }, customOptions, "----------\n" + "1. ERROR in X.java (at line 7)\n" + " return this.new Local(b);\n" + " ^\n" + "Type mismatch: required \'@NonNull String\' but the provided value can be null\n" + "----------\n" /* compiler output */); }
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
public void test_parameter_specification_inheritance_008() { Map options = getCompilerOptions(); options.put(NullCompilerOptions.OPTION_ReportNullSpecInsufficientInfo, CompilerOptions.ERROR); runConformTestWithLibs(//from w ww.j a v a2s . co m new String[] { "IX.java", "import org.eclipse.jdt.annotation.*;\n" + "public interface IX {\n" + " void printObject(@NonNull Object o);\n" + "}\n" }, null /*customOptions*/, ""); runNegativeTestWithLibs(false, // don't flush new String[] { "X.java", "public class X implements IX {\n" + " public void printObject(Object o) { System.out.print(o.toString()); }\n" + "}\n", "M.java", "public class M{\n" + " void foo(IX x, Object o) {\n" + " x.printObject(o);\n" + " }\n" + "}\n" }, options, "----------\n" + // additional error: "1. ERROR in X.java (at line 2)\n" + " public void printObject(Object o) { System.out.print(o.toString()); }\n" + " ^^^^^^\n" + "Missing null annotation: inherited method from IX declares this parameter as @NonNull\n" + "----------\n" + // main error: "----------\n" + "1. ERROR in M.java (at line 3)\n" + " x.printObject(o);\n" + " ^\n" + "Potential type mismatch: required \'@NonNull Object\' but nullness of the provided value is unknown\n" + "----------\n"); }
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
public void test_parameter_specification_inheritance_010() { Map customOptions = getCompilerOptions(); customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); customOptions.put(NullCompilerOptions.OPTION_ReportNullSpecInsufficientInfo, CompilerOptions.ERROR); runConformTestWithLibs(/*from w w w. ja v a 2 s.c o m*/ new String[] { "p1/X.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "@NonNullByDefault\n" + "public class X {\n" + " protected String getString(String s) {\n" + " if (Character.isLowerCase(s.charAt(0)))\n" + " return getString(s);\n" + " return s;\n" + " }\n" + "}\n", "p1/Y.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "@NonNullByDefault\n" + "public class Y extends X {\n" + " @Override\n" + " protected String getString(String s) {\n" + " return super.getString(s);\n" + " }\n" + "}\n", }, customOptions, ""); }
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
public void test_parameter_specification_inheritance_011() { Map customOptions = getCompilerOptions(); customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); customOptions.put(NullCompilerOptions.OPTION_ReportNullSpecInsufficientInfo, CompilerOptions.ERROR); runNegativeTestWithLibs(/* www. j a v a2s.c om*/ new String[] { "p1/X.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "@NonNullByDefault\n" + "public class X {\n" + " protected String getString(String s) {\n" + " if (Character.isLowerCase(s.charAt(0)))\n" + " return getString(s);\n" + " return s;\n" + " }\n" + "}\n", "p1/Y.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "@NonNullByDefault\n" + "public class Y extends X {\n" + " @Override\n" + " protected String getString(String s) {\n" + " return super.getString(null);\n" + " }\n" + "}\n", }, customOptions, "----------\n" + "1. ERROR in p1\\Y.java (at line 7)\n" + " return super.getString(null);\n" + " ^^^^\n" + "Type mismatch: required \'@NonNull String\' but the provided value is null\n" + "----------\n"); }
From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationTest.java
License:Open Source License
public void test_parameter_specification_inheritance_012() { Map customOptions = getCompilerOptions(); customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); customOptions.put(NullCompilerOptions.OPTION_ReportNullSpecInsufficientInfo, CompilerOptions.ERROR); runConformTestWithLibs(new String[] { "p1/X.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "public class X {\n" + " public @Nullable String getString(String s1, @Nullable String s2, @NonNull String s3) {\n" + " return s1;\n" + " }\n" + "}\n", "p1/IY.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "public interface IY {\n" + " @NonNull String getString(@NonNull String s1, @NonNull String s2, @Nullable String s3);\n" + "}\n", "p1/Y.java", "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n" + "public class Y extends X implements IY {\n" + " @Override\n" + " public @NonNull String getString(@Nullable String s1, @Nullable String s2, @Nullable String s3) {\n" + " return \"\";\n" + " }\n" + "}\n", }, customOptions, ""); }