@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(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)) { return null; 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 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({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 null; Tree t = treePath.getLeaf(); int start = (int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), t); int end = (int) info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), t);
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; }