@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; }
@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; }
/** * 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; } }