Java Code Examples for javax.lang.model.SourceVersion#compareTo()
The following examples show how to use
javax.lang.model.SourceVersion#compareTo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodeGeneration.java From requery with Apache License 2.0 | 6 votes |
static void addGeneratedAnnotation(ProcessingEnvironment processingEnvironment, TypeSpec.Builder builder) { Elements elements = processingEnvironment.getElementUtils(); SourceVersion sourceVersion = processingEnvironment.getSourceVersion(); AnnotationSpec.Builder annotationBuilder = null; if (sourceVersion.compareTo(SourceVersion.RELEASE_8) > 0) { ClassName name = ClassName.bestGuess("javax.annotation.processing.Generated"); annotationBuilder = AnnotationSpec.builder(name); } else { if (elements.getTypeElement(Generated.class.getCanonicalName()) != null) { annotationBuilder = AnnotationSpec.builder(Generated.class); } } if (annotationBuilder != null) { builder.addAnnotation(annotationBuilder .addMember("value", "$S", EntityProcessor.class.getCanonicalName()).build()); } }
Example 2
Source File: JavacProcessingEnvironment.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Checks whether or not a processor's source version is * compatible with the compilation source version. The * processor's source version needs to be greater than or * equal to the source version of the compile. */ private void checkSourceVersionCompatibility(Source source, Log log) { SourceVersion procSourceVersion = processor.getSupportedSourceVersion(); if (procSourceVersion.compareTo(Source.toSourceVersion(source)) < 0 ) { log.warning("proc.processor.incompatible.source.version", procSourceVersion, processor.getClass().getName(), source.name); } }
Example 3
Source File: Java.java From RADL with Apache License 2.0 | 5 votes |
public static String getVersion() { Iterator<SourceVersion> versions = getCompiler().getSourceVersions().iterator(); SourceVersion result = versions.next(); while (versions.hasNext()) { SourceVersion version = versions.next(); if (version.compareTo(result) > 0) { result = version; } } return "1." + result.toString().substring("RELEASE_".length()); }
Example 4
Source File: JavacProcessingEnvironment.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Checks whether or not a processor's source version is * compatible with the compilation source version. The * processor's source version needs to be greater than or * equal to the source version of the compile. */ private void checkSourceVersionCompatibility(Source source, Log log) { SourceVersion procSourceVersion = processor.getSupportedSourceVersion(); if (procSourceVersion.compareTo(Source.toSourceVersion(source)) < 0 ) { log.warning("proc.processor.incompatible.source.version", procSourceVersion, processor.getClass().getName(), source.name); } }
Example 5
Source File: JavacProcessingEnvironment.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Checks whether or not a processor's source version is * compatible with the compilation source version. The * processor's source version needs to be greater than or * equal to the source version of the compile. */ private void checkSourceVersionCompatibility(Source source, Log log) { SourceVersion procSourceVersion = processor.getSupportedSourceVersion(); if (procSourceVersion.compareTo(Source.toSourceVersion(source)) < 0 ) { log.warning("proc.processor.incompatible.source.version", procSourceVersion, processor.getClass().getName(), source.name); } }
Example 6
Source File: JavacProcessingEnvironment.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Checks whether or not a processor's source version is * compatible with the compilation source version. The * processor's source version needs to be greater than or * equal to the source version of the compile. */ private void checkSourceVersionCompatibility(Source source, Log log) { SourceVersion procSourceVersion = processor.getSupportedSourceVersion(); if (procSourceVersion.compareTo(Source.toSourceVersion(source)) < 0 ) { log.warning("proc.processor.incompatible.source.version", procSourceVersion, processor.getClass().getName(), source.name); } }
Example 7
Source File: TestPackageElement.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void testEnclosingElement(PackageElement javaLang) { SourceVersion version = processingEnv.getSourceVersion(); Element enclosing = javaLang.getEnclosingElement(); Element expectedEnclosing = (version.compareTo(RELEASE_9) < 0) ? // No modules null : eltUtils.getModuleElement("java.base"); if (!Objects.equals(enclosing, expectedEnclosing)) throw new RuntimeException("Unexpected enclosing element under source version " + version); }
Example 8
Source File: JavacProcessingEnvironment.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Checks whether or not a processor's source version is * compatible with the compilation source version. The * processor's source version needs to be greater than or * equal to the source version of the compile. */ private void checkSourceVersionCompatibility(Source source, Log log) { SourceVersion procSourceVersion = processor.getSupportedSourceVersion(); if (procSourceVersion.compareTo(Source.toSourceVersion(source)) < 0 ) { log.warning("proc.processor.incompatible.source.version", procSourceVersion, processor.getClass().getName(), source.name); } }
Example 9
Source File: JavacProcessingEnvironment.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * Checks whether or not a processor's source version is * compatible with the compilation source version. The * processor's source version needs to be greater than or * equal to the source version of the compile. */ private void checkSourceVersionCompatibility(Source source, Log log) { SourceVersion procSourceVersion = processor.getSupportedSourceVersion(); if (procSourceVersion.compareTo(Source.toSourceVersion(source)) < 0 ) { log.warning("proc.processor.incompatible.source.version", procSourceVersion, processor.getClass().getName(), source.name); } }
Example 10
Source File: JavacProcessingEnvironment.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Checks whether or not a processor's source version is * compatible with the compilation source version. The * processor's source version needs to be greater than or * equal to the source version of the compile. */ private void checkSourceVersionCompatibility(Source source, Log log) { SourceVersion procSourceVersion = processor.getSupportedSourceVersion(); if (procSourceVersion.compareTo(Source.toSourceVersion(source)) < 0 ) { log.warning("proc.processor.incompatible.source.version", procSourceVersion, processor.getClass().getName(), source.name); } }
Example 11
Source File: HintsInvoker.java From netbeans with Apache License 2.0 | 5 votes |
@CheckForNull public Map<HintDescription, List<ErrorDescription>> computeHints(CompilationInfo info, TreePath startAt, boolean recursive, Iterable<? extends HintDescription> hints, Collection<? super MessageImpl> problems) { Map<Class, List<HintDescription>> triggerKind2Hints = new HashMap<Class, List<HintDescription>>(); for (Class<? extends Trigger> c : TRIGGER_KINDS) { triggerKind2Hints.put(c, new ArrayList<HintDescription>()); } SourceVersion srcVersion = info.getSourceVersion(); for (HintDescription hd : hints) { SourceVersion hVersion = hd.getMetadata().sourceVersion; if (hVersion != null && (srcVersion.compareTo(hVersion) < 0)) { continue; } List<HintDescription> sorted = triggerKind2Hints.get(hd.getTrigger().getClass()); sorted.add(hd); } if (caret != -1) { TreePath tp = info.getTreeUtilities().pathFor(caret); return computeSuggestions(info, tp, true, triggerKind2Hints, problems); } else { if (from != (-1) && to != (-1)) { return computeHintsInSpan(info, triggerKind2Hints, problems); } else if (!recursive) { return computeSuggestions(info, startAt, false, triggerKind2Hints, problems); } else { return computeHintsImpl(info, startAt, triggerKind2Hints, problems); } } }
Example 12
Source File: JavacProcessingEnvironment.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Checks whether or not a processor's source version is * compatible with the compilation source version. The * processor's source version needs to be greater than or * equal to the source version of the compile. */ private void checkSourceVersionCompatibility(Source source, Log log) { SourceVersion procSourceVersion = processor.getSupportedSourceVersion(); if (procSourceVersion.compareTo(Source.toSourceVersion(source)) < 0 ) { log.warning(Warnings.ProcProcessorIncompatibleSourceVersion(procSourceVersion, processor.getClass().getName(), source.name)); } }
Example 13
Source File: JavacProcessingEnvironment.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Checks whether or not a processor's source version is * compatible with the compilation source version. The * processor's source version needs to be greater than or * equal to the source version of the compile. */ private void checkSourceVersionCompatibility(Source source, Log log) { SourceVersion procSourceVersion = processor.getSupportedSourceVersion(); if (procSourceVersion.compareTo(Source.toSourceVersion(source)) < 0 ) { log.warning("proc.processor.incompatible.source.version", procSourceVersion, processor.getClass().getName(), source.name); } }
Example 14
Source File: JavacProcessingEnvironment.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
/** * Checks whether or not a processor's source version is * compatible with the compilation source version. The * processor's source version needs to be greater than or * equal to the source version of the compile. */ private void checkSourceVersionCompatibility(Source source, Log log) { SourceVersion procSourceVersion = processor.getSupportedSourceVersion(); if (procSourceVersion.compareTo(Source.toSourceVersion(source)) < 0 ) { log.warning("proc.processor.incompatible.source.version", procSourceVersion, processor.getClass().getName(), source.name); } }
Example 15
Source File: JavacProcessingEnvironment.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Checks whether or not a processor's source version is * compatible with the compilation source version. The * processor's source version needs to be greater than or * equal to the source version of the compile. */ private void checkSourceVersionCompatibility(Source source, Log log) { SourceVersion procSourceVersion = processor.getSupportedSourceVersion(); if (procSourceVersion.compareTo(Source.toSourceVersion(source)) < 0 ) { log.warning("proc.processor.incompatible.source.version", procSourceVersion, processor.getClass().getName(), source.name); } }
Example 16
Source File: AnnotationProcessors.java From netbeans with Apache License 2.0 | 4 votes |
DeclareCurrentSourceFix(CompilationInfo info, TreePath tp, SourceVersion target) { super(info, tp); this.target = target; this.project = target.compareTo(info.getSourceVersion()) == 0; }
Example 17
Source File: AnnotationProcessors.java From netbeans with Apache License 2.0 | 4 votes |
/** * Warns on incorrect @{@link SupportedSourceVersion} annotation. The hint triggers in * following cases, if the class does <b>not</b> override {@link javax.annotation.processing.Processor#getSupportedSourceVersion()}. * <ul> * <li>Class derived from AbstractProcessor with no annotation at all: defaults to 1.6, which * is almost certainly wrong. * <li>Declares {@code @SupportedSourceVersion} earlier than the project's source level. * </ul> * Offers a hint to declare a {@code @SupportedSourceVersion} or to override the {@code getSupportedSourceVersion} * to return {@link SourceVersion#latest()}. * @param ctx * @return */ @Hint( category = "rules15", displayName = "#DN_AnnoProcessor_ObsoleteSupportedSource", description = "#DESC_AnnoProcessor_ObsoleteSupportedSource", id = "obsoleteAnnotationSupportedSource", suppressWarnings = "ObsoleteAnnotationSupportedSource" ) @TriggerPattern( value = "$modifiers$ class $name extends $superClass$ implements $superInterfaces$ { $body$; }", constraints = @ConstraintVariableType( variable = "$superInterfaces", type = "javax.annotation.processing.Processor" ) ) @NbBundle.Messages({ "DN_AnnoProcessor_ObsoleteSupportedSource=Missing or obsolete @SupportedSourceVersion", "HINT_AnnoProcessor_DeclaredSourceObsolete=Annoration declares older source version than the project source level.", "HINT_AnnoProcessor_NoSupportedSource=No @SupportedSourceVersion is declared, the default (1.6) is older than project source level." }) public static ErrorDescription annotatedByObsoleteSource(HintContext ctx) { CompilationInfo info = ctx.getInfo(); ProcessorHintSupport helper = new ProcessorHintSupport(ctx.getInfo(), ctx.getPath()); if (!helper.initialize()) { return null; } // not an AbstractProcessor; or overrides the getSupported method. if (!helper.canOverrideAbstract(true)) { return null; } SupportedSourceVersion ssv = helper.getProcessor().getAnnotation(SupportedSourceVersion.class); SourceVersion current = info.getSourceVersion(); if (ssv != null) { SourceVersion declared = ssv.value(); if (declared.compareTo(current) >= 0) { // OK return null; } TreePath rewriteAt = helper.findSupportedAnnotation(); if (rewriteAt == null) { return null; } return ErrorDescriptionFactory.forTree(ctx, rewriteAt, Bundle.HINT_AnnoProcessor_DeclaredSourceObsolete(), // suggest to generate latest() new OverrideReturnLatest(info, helper.getProcessorPath(), false).toEditorFix(), new OverrideReturnLatest(info, helper.getProcessorPath(), true).toEditorFix(), // suggest change to the current version changeToCurrentSource(ctx, helper, info.getSourceVersion()) ); } else { TreePath path = helper.getProcessorPath(); return ErrorDescriptionFactory.forTree(ctx, path, Bundle.HINT_AnnoProcessor_NoSupportedSource(), new OverrideReturnLatest(info, path, false).toEditorFix(), new OverrideReturnLatest(info, path, true).toEditorFix(), new DeclareCurrentSourceFix(info, path, info.getSourceVersion()).toEditorFix() ); } }
Example 18
Source File: HintsInvoker.java From netbeans with Apache License 2.0 | 4 votes |
private List<ErrorDescription> computeHints(CompilationInfo info, TreePath startAt) { List<HintDescription> descs = new LinkedList<HintDescription>(); Map<HintMetadata, ? extends Collection<? extends HintDescription>> allHints = RulesManager.getInstance().readHints(info, null, cancel); if (allHints == null || cancel.get()) return null; SourceVersion sourceLevel = info.getSourceVersion(); for (Entry<HintMetadata, ? extends Collection<? extends HintDescription>> e : allHints.entrySet()) { HintMetadata m = e.getKey(); SourceVersion hintSourceLevel = m.sourceVersion; // hint requires a higher source level than the current compilation is configured for if (hintSourceLevel != null && (sourceLevel.compareTo(hintSourceLevel) < 0)) { continue; } if (!settings.isEnabled(m)) { continue; } if (caret != -1) { if (m.kind == Hint.Kind.ACTION) { descs.addAll(e.getValue()); } else { if (settings.getSeverity(m) == Severity.HINT) { descs.addAll(e.getValue()); } } } else { if (m.kind == Hint.Kind.INSPECTION) { if (settings.getSeverity(m) != Severity.HINT) { descs.addAll(e.getValue()); } } } } List<ErrorDescription> errors = join(computeHints(info, startAt, descs, new LinkedList<MessageImpl>())); dumpTimeSpentInHints(); return errors; }
Example 19
Source File: ClasspathAvailability.java From immutables with Apache License 2.0 | 4 votes |
public boolean isJava8() { SourceVersion sourceVersion = StaticEnvironment.processing().getSourceVersion(); return sourceVersion.compareTo(SourceVersion.RELEASE_7) > 0; }