@Hint(displayName = "#DN_CfgProcMissingHint", description = "#DESC_CfgProcMissingHint", category = "Spring Boot") @TriggerPatterns({ @TriggerPattern("org.springframework.boot.context.properties.ConfigurationProperties") ,@TriggerPattern("org.springframework.boot.context.properties.EnableConfigurationProperties") }) @Messages({ "DN_CfgProcMissingHint=Missing Spring Boot configuration processor", "DESC_CfgProcMissingHint=Warns if @ConfigurationProperties and @EnableConfigurationProperties annotations are used without the <i>spring-boot-configuration-processor</i> dependency in the project pom", "ERR_CfgProcMissingHint=Missing Spring Boot configuration processor in project pom" }) public static ErrorDescription cfgProps(HintContext ctx) { return annotationWarning(ctx, "spring-boot-configuration-processor", Bundle.ERR_CfgProcMissingHint(), true); }
@Hint(displayName = "#JavaxFacesBeanIsGonnaBeDeprecated.display.name", description = "#JavaxFacesBeanIsGonnaBeDeprecated.err", id = "o.n.m.web.jsf.hints.JavaxFacesBeanIsGonnaBeDeprecated",
@TriggerTreeKind(Tree.Kind.CLASS) @Messages("ERR_CreateTestClassHint=Create Test Class") public static ErrorDescription computeWarning(HintContext context) { TreePath tp = context.getPath(); ClassTree cls = (ClassTree) tp.getLeaf(); CompilationInfo info = context.getInfo(); SourcePositions sourcePositions = info.getTrees().getSourcePositions(); int startPos = (int) sourcePositions.getStartPosition(tp.getCompilationUnit(), cls); int caret = context.getCaretLocation(); String code = context.getInfo().getText(); if (startPos < 0 || caret < 0 || caret < startPos || caret >= code.length()) { return null; return ErrorDescriptionFactory.forTree(context, context.getPath(), Bundle.ERR_CreateTestClassHint(), fixes.toArray(new Fix[fixes.size()]));
@TriggerTreeKind({Kind.MEMBER_SELECT, Kind.IDENTIFIER}) public static List<ErrorDescription> run(HintContext context) { CompilationInfo info = context.getInfo(); TreePath treePath = context.getPath(); Element el = info.getTrees().getElement(treePath); if (el == null) { return Collections.<ErrorDescription>singletonList( ErrorDescriptionFactory.createErrorDescription( context.getSeverity(), Bundle.OptionalEE7APIsHint_DisplayName(), fixes,
private static ErrorDescription annotationWarning(HintContext ctx, String artifactId, String hintMex, boolean optional) { final TreePath tp = ctx.getPath(); final TreePath tpParent = tp.getParentPath(); if (tpParent != null) { if (tpParent.getLeaf().getKind() == ANNOTATION) { Project prj = FileOwnerQuery.getOwner(ctx.getInfo().getFileObject()); if (prj != null) { SpringBootService sbs = prj.getLookup().lookup(SpringBootService.class); if (sbs != null) { // check first if the pom has at least one spring boot dependencies if (sbs.hasPomDependency("spring-boot") && !sbs.hasPomDependency(artifactId)) { NbMavenProject mPrj = prj.getLookup().lookup(NbMavenProject.class); if (mPrj != null) { return ErrorDescriptionFactory.forName(ctx, tp, hintMex, new AddDepFix(mPrj, artifactId, optional)); } else { return ErrorDescriptionFactory.forName(ctx, tp, hintMex); } } } } } } return null; }
@Hint(displayName = "#DN_MvcMissingHint", description = "#DESC_MvcMissingHint", category = "Spring Boot") @TriggerPattern("org.springframework.stereotype.Controller") @Messages({ "DN_MvcMissingHint=Missing Spring Boot MVC starter", "DESC_MvcMissingHint=Warns if @Controller annotation is used without the <i>spring-boot-starter-web</i> dependency in the project pom", "ERR_MvcMissingHint=Missing Spring MVC boot starter in project pom" }) public static ErrorDescription controllers(HintContext ctx) { return annotationWarning(ctx, "spring-boot-starter-web", Bundle.ERR_MvcMissingHint(), false); }
@TriggerTreeKind(Tree.Kind.CLASS) public static Collection<ErrorDescription> run(HintContext hintContext) { List<ErrorDescription> problems = new ArrayList<>(); final JsfHintsContext ctx = JsfHintsUtils.getOrCacheContext(hintContext); if (ctx.getJsfVersion() == null || !ctx.getJsfVersion().isAtLeast(JSFVersion.JSF_2_2)) { return problems; } CompilationInfo info = ctx.getCompilationInfo(); for (TypeElement typeElement : info.getTopLevelElements()) { for (AnnotationMirror annotationMirror : typeElement.getAnnotationMirrors()) { if (annotationMirror.getAnnotationType().toString().startsWith(JAVAX_FACES_BEAN)) { // it's javax.faces.bean annotation Tree tree = info.getTrees().getTree(typeElement, annotationMirror); List<Fix> fixes = getFixesForType(info, typeElement, annotationMirror); problems.add(JsfHintsUtils.createProblem( tree, info, Bundle.JavaxFacesBeanIsGonnaBeDeprecated_display_name(), Severity.HINT, fixes)); } } } return problems; }
@TriggerTreeKind(Tree.Kind.METHOD) @Messages("ERR_CreateTestMethodsHint=Generate All Test Methods") public static ErrorDescription computeWarning(HintContext context) { final TreePath tp = context.getPath(); final MethodTree method = (MethodTree) tp.getLeaf(); if (method.getModifiers().getFlags().contains(Modifier.PRIVATE)) { CompilationInfo info = context.getInfo(); SourcePositions sourcePositions = info.getTrees().getSourcePositions(); int startPos = (int) sourcePositions.getStartPosition(tp.getCompilationUnit(), method); int caret = context.getCaretLocation(); String code = context.getInfo().getText(); if (startPos < 0 || caret < 0 || caret < startPos || caret >= code.length()) { return null; return ErrorDescriptionFactory.forTree(context, context.getPath(), Bundle.ERR_CreateTestMethodsHint(), fixes.toArray(new Fix[fixes.size()]));
private static ErrorDescription importWarning(HintContext ctx, String artifactId, String hintMex, String[] fixArtifactIds) { final TreePath tp = ctx.getPath(); final TreePath tpParent = tp.getParentPath(); if (tpParent != null) { if (tpParent.getLeaf().getKind() == IMPORT) { Project prj = FileOwnerQuery.getOwner(ctx.getInfo().getFileObject()); if (prj != null) { SpringBootService sbs = prj.getLookup().lookup(SpringBootService.class); if (sbs != null) { // check first if the pom has at least one spring boot dependencies if (sbs.hasPomDependency("spring-boot") && !sbs.hasPomDependency(artifactId)) { NbMavenProject mPrj = prj.getLookup().lookup(NbMavenProject.class); if (mPrj != null) { Fix[] fixes = new Fix[fixArtifactIds.length]; for (int i = 0; i < fixArtifactIds.length; i++) { fixes[i] = new AddDepFix(mPrj, fixArtifactIds[i], false); } return ErrorDescriptionFactory.forName(ctx, tp, hintMex, fixes); } else { return ErrorDescriptionFactory.forName(ctx, tp, hintMex); } } } } } } return null; }
@Hint(displayName = "#DN_RstMissingHint", description = "#DESC_RstMissingHint", category = "Spring Boot") @TriggerPattern("org.springframework.web.bind.annotation.RestController") @Messages({ "DN_RstMissingHint=Missing Spring MVC starter (alternative)", "DESC_RstMissingHint=Warns if @RestController annotation is used without the <i>spring-boot-starter-web</i> dependency in the project pom" }) public static ErrorDescription rstCtrl(HintContext ctx) { return importWarning(ctx, "spring-boot-starter-web", Bundle.ERR_MvcMissingHint(), new String[]{"spring-boot-starter-web"}); }
@Hint(displayName = "#DN_CreateTestClassHint", description = "#DESC_CreateTestClassHint", category = "suggestions", hintKind = Hint.Kind.ACTION, severity = Severity.HINT) @Messages({ "DN_CreateTestClassHint=Create Test Class",
@Hint(displayName = "#DN_DataMissingHint", description = "#DESC_DataMissingHint", category = "Spring Boot") @TriggerPatterns({ @TriggerPattern("org.springframework.data.repository.Repository") ,@TriggerPattern("org.springframework.data.repository.CrudRepository") ,@TriggerPattern("org.springframework.data.repository.PagingAndSortingRepository") }) @Messages({ "DN_DataMissingHint=Missing one of Spring Data starters", "DESC_DataMissingHint=Warns if Spring Data repository annotations are used without one of the <i>spring-boot-starter-data-###</i> dependencies in the project pom", "ERR_DataMissingHint=Missing one of the Spring Data boot starters in project pom" }) public static ErrorDescription dataRepos(HintContext ctx) { return importWarning(ctx, "spring-boot-starter-data", Bundle.ERR_DataMissingHint(), new String[]{ "spring-boot-starter-data-jpa", "spring-boot-starter-data-mongodb", "spring-boot-starter-data-cassandra", "spring-boot-starter-data-redis", "spring-boot-starter-data-solr", "spring-boot-starter-data-couchbase" }); }
/** * Gets problem context used by standard JSF hints. * Uses cached value if found, otherwise creates a new one which stores into the CompilationInfo. * * @param context Hints API context * @return {@code JsfHintsContext} */ public static JsfHintsContext getOrCacheContext(HintContext context) { Object cached = context.getInfo().getCachedValue(CACHED_CONTEXT); if (cached == null) { LOG.log(Level.FINEST, "HintContext doesn't contain cached JsfHintsContext which is going to be created."); JsfHintsContext newContext = createJsfHintsContext(context); context.getInfo().putCachedValue(CACHED_CONTEXT, newContext, CompilationInfo.CacheClearPolicy.ON_SIGNATURE_CHANGE); return newContext; } else { LOG.log(Level.FINEST, "JsfHintsContext cached value used."); return (JsfHintsContext) cached; } }
@TriggerTreeKind(Tree.Kind.CLASS) public static Collection<ErrorDescription> run(HintContext hintContext) { List<ErrorDescription> problems = new ArrayList<>(); final JsfHintsContext ctx = JsfHintsUtils.getOrCacheContext(hintContext); Project project = ctx.getProject(); if (project == null) { return problems; } CompilationInfo info = ctx.getCompilationInfo(); for (TypeElement typeElement : info.getTopLevelElements()) { for (AnnotationMirror annotationMirror : typeElement.getAnnotationMirrors()) { if (FLOW_SCOPED.equals(annotationMirror.getAnnotationType().toString())) { // it's FlowScoped bean -> check the CDI CdiUtil cdiUtil = project.getLookup().lookup(CdiUtil.class); if (cdiUtil == null || !cdiUtil.isCdiEnabled()) { Tree tree = info.getTrees().getTree(typeElement, annotationMirror); problems.add(JsfHintsUtils.createProblem( tree, info, Bundle.FlowScopedBeanWithoutCdi_display_name(), Severity.WARNING, Arrays.<Fix>asList(new FixCdiAvailability(project)))); } } } } return problems; }
@Hint(displayName = "#DN_MongoMissingHint", description = "#DESC_MongoMissingHint", category = "Spring Boot") @TriggerPattern("org.springframework.data.mongodb.repository.MongoRepository") @Messages({ "DN_MongoMissingHint=Missing Spring Data Mongo starter", "DESC_MongoMissingHint=Warns if Spring Data @MongoRepository annotations are used without the <i>spring-boot-starter-data-mongodb</i> dependency in the project pom", "ERR_MongoMissingHint=Missing Spring Data Mongo boot starter in project pom" }) public static ErrorDescription mongoRepos(HintContext ctx) { return importWarning(ctx, "spring-boot-starter-data-mongodb", Bundle.ERR_MongoMissingHint(), new String[]{"spring-boot-starter-data-mongodb"}); }
@Hint(id="OptionalEE7APIsHint", category="api", displayName="#OptionalEE7APIsHint_DisplayName", description="#OptionalEE7APIsHint_Description", options=Hint.Options.QUERY) @Messages({ "OptionalEE7APIsHint_DisplayName=Be aware that this API will be optional in Java EE 7 platform.",
@Hint(displayName = "#DN_JpaMissingHint", description = "#DESC_JpaMissingHint", category = "Spring Boot") @TriggerPattern("org.springframework.data.jpa.repository.JpaRepository") @Messages({ "DN_JpaMissingHint=Missing Spring Data JPA starter", "DESC_JpaMissingHint=Warns if Spring Data JPA repository annotations are used without the <i>spring-boot-starter-data-jpa</i> dependency in the project pom", "ERR_JpaMissingHint=Missing Spring Data JPA boot starter in project pom" }) public static ErrorDescription jpaRepos(HintContext ctx) { return importWarning(ctx, "spring-boot-starter-data-jpa", Bundle.ERR_JpaMissingHint(), new String[]{"spring-boot-starter-data-jpa"}); }
@Hint(displayName = "#FlowScopedBeanWithoutCdi.display.name", description = "#FlowScopedBeanWithoutCdi.err", id = "o.n.m.web.jsf.hints.FlowScopedBeanWithoutCdi",
@Hint(displayName = "#DN_CreateTestMethodsHint", description = "#DESC_CreateTestMethodsHint", category = "suggestions", hintKind = Hint.Kind.ACTION, severity = Severity.HINT) @Messages({ "DN_CreateTestMethodsHint=Generate All Test Methods",