javax.annotation.processing.SupportedSourceVersion Java Examples

The following examples show how to use javax.annotation.processing.SupportedSourceVersion. 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: AbstractCommandSpecProcessor.java    From picocli with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the max supported source version.
 * Returns {@link SourceVersion#latest()} by default,
 * subclasses may override or may use the {@link SupportedSourceVersion} annotation.
 * @return the max supported source version
 */
@Override
public SourceVersion getSupportedSourceVersion() {
    SupportedSourceVersion ssv = this.getClass().getAnnotation(SupportedSourceVersion.class);
    SourceVersion sv = null;
    if (ssv == null) {
        return SourceVersion.latest();
    } else {
        return ssv.value();
    }
}
 
Example #2
Source File: LayerGeneratingProcessor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * If the subclass itself does not define SupportedSourceVersion, assume latest(). If it does
 * (was recommended prior to 9.17), returns the subclass' value for compatibility.
 * @return max supported source version.
 * @since 9.17
 */
@Override
public SourceVersion getSupportedSourceVersion() {
    SupportedSourceVersion ssv = this.getClass().getAnnotation(SupportedSourceVersion.class);
    SourceVersion sv;
    if (ssv == null) {
        sv = SourceVersion.latest();
    } else
        sv = ssv.value();
    return sv;
}
 
Example #3
Source File: AbstractServiceProviderProcessor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * If the subclass itself does not define SupportedSourceVersion, assume latest(). If it does
 * (was recommended prior to 8.40), returns the subclass' value.
 * @return max supported source version.
 * @since 8.40
 */
@Override
public SourceVersion getSupportedSourceVersion() {
    SupportedSourceVersion ssv = this.getClass().getAnnotation(SupportedSourceVersion.class);
    SourceVersion sv;
    if (ssv == null) {
        sv = SourceVersion.latest();
    } else
        sv = ssv.value();
    return sv;
}
 
Example #4
Source File: AbstractGenerator.java    From immutables with Apache License 2.0 5 votes vote down vote up
@Override
public SourceVersion getSupportedSourceVersion() {
  @Nullable SupportedSourceVersion sourceVersion = this.getClass().getAnnotation(SupportedSourceVersion.class);
  if (sourceVersion != null) {
    return sourceVersion.value();
  }
  return SourceVersion.latestSupported();
}
 
Example #5
Source File: AnnotationProcessors.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * 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()
        );
    }
}