本文整理汇总了Java中org.netbeans.spi.java.hints.HintContext类的典型用法代码示例。如果您正苦于以下问题:Java HintContext类的具体用法?Java HintContext怎么用?Java HintContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HintContext类属于org.netbeans.spi.java.hints包,在下文中一共展示了HintContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.netbeans.spi.java.hints.HintContext; //导入依赖的package包/类
@TriggerTreeKind(Kind.MEMBER_SELECT)
public static List<ErrorDescription> run(HintContext ctx) {
CompilationInfo compilationInfo = ctx.getInfo();
TreePath treePath = ctx.getPath();
int[] span = new int[2];
int[] kind = new int[1];
String[] simpleName = new String[1];
Fix fix = computeFixes(compilationInfo, treePath, span, kind, simpleName);
if (fix == null) {
return null;
}
ErrorDescription ed = ErrorDescriptionFactory.forName(
ctx,
ctx.getPath(),
NbBundle.getMessage(StaticAccess.class, "MSG_StaticAccess", kind[0], simpleName[0]), // NOI18N
fix
);
return Collections.singletonList(ed);
}
示例2: sizeNotEqualsZero
import org.netbeans.spi.java.hints.HintContext; //导入依赖的package包/类
@TriggerPatterns({
@TriggerPattern(value="$subj.size() != 0",
constraints = @ConstraintVariableType(type = "java.util.Collection", variable = "$subj")),
@TriggerPattern(value="$subj.size() != 0",
constraints = @ConstraintVariableType(type = "java.util.Map", variable = "$subj")),
@TriggerPattern(value="0 != $subj.size()",
constraints = @ConstraintVariableType(type = "java.util.Collection", variable = "$subj")),
@TriggerPattern(value="0 != $subj.size()",
constraints = @ConstraintVariableType(type = "java.util.Map", variable = "$subj")),
})
public static ErrorDescription sizeNotEqualsZero(HintContext ctx) {
if (!ctx.getPreferences().getBoolean(CHECK_NOT_EQUALS, CHECK_NOT_EQUALS_DEFAULT)) {
return null;
}
return sizeEqualsZeroHint(ctx, true);
}
示例3: check
import org.netbeans.spi.java.hints.HintContext; //导入依赖的package包/类
public Collection<ErrorDescription> check(JPAProblemContext ctx, HintContext hc, AttributeWrapper attrib) {
if (!(attrib.getModelElement() instanceof Id)) {
if (Utilities.hasAnnotation(attrib.getJavaElement(), JPAAnnotations.GENERATED_VALUE)) {
Tree elementTree = ctx.getCompilationInfo().getTrees().getTree(attrib.getJavaElement());
Utilities.TextSpan underlineSpan = Utilities.getUnderlineSpan(
ctx.getCompilationInfo(), elementTree);
ErrorDescription error = ErrorDescriptionFactory.forSpan(
hc,
underlineSpan.getStartOffset(),
underlineSpan.getEndOffset(),
NbBundle.getMessage(GeneratedValueIsId.class, "MSG_GeneratedValueIsId"));
return Collections.singletonList(error);
}
}
return null;
}
示例4: tooDeepNesting
import org.netbeans.spi.java.hints.HintContext; //导入依赖的package包/类
@Hint(
category = "metrics",
displayName = "#DN_MethodTooDeepNesting",
description = "#DESC_MethodTooDeepNesting",
options = { Hint.Options.QUERY, Hint.Options.HEAVY },
enabled = false
)
@TriggerTreeKind(Tree.Kind.METHOD)
@UseOptions(value = { OPTION_NESTING_LIMIT })
public static ErrorDescription tooDeepNesting(HintContext ctx) {
Tree t = ctx.getPath().getLeaf();
MethodTree method = (MethodTree)t;
DepthVisitor v = new DepthVisitor();
v.scan(ctx.getPath(), null);
int depth = v.getDepth();
int treshold = ctx.getPreferences().getInt(OPTION_NESTING_LIMIT, DEFAULT_NESTING_LIMIT);
if (depth <= treshold) {
return null;
}
return ErrorDescriptionFactory.forName(ctx, t,
methodOrConstructor(ctx) ?
TEXT_ConstructorTooDeepNesting(depth) :
TEXT_MethodTooDeepNesting(method.getName().toString(), depth)
);
}
示例5: forIF
import org.netbeans.spi.java.hints.HintContext; //导入依赖的package包/类
@Hint(displayName = "#LBL_Empty_IF", description = "#DSC_Empty_IF", category = "empty", hintKind = Hint.Kind.INSPECTION, severity = Severity.VERIFIER, suppressWarnings = SUPPRESS_WARNINGS_KEY, id = "EmptyStatements_IF", enabled = false)
@TriggerTreeKind(Tree.Kind.EMPTY_STATEMENT)
public static ErrorDescription forIF(HintContext ctx) {
final TreePath treePath = ctx.getPath();
Tree parent = treePath.getParentPath().getLeaf();
if (!EnumSet.of(Kind.IF).contains(parent.getKind())) {
return null;
}
TreePath treePathForWarning = treePath;
IfTree it = (IfTree) parent;
if (it.getThenStatement() != null
&& it.getThenStatement().getKind() == Tree.Kind.EMPTY_STATEMENT) {
treePathForWarning = treePath.getParentPath();
}
if (it.getElseStatement() != null
&& it.getElseStatement().getKind() == Tree.Kind.EMPTY_STATEMENT) {
treePathForWarning = treePath;
}
final List<Fix> fixes = new ArrayList<>();
fixes.add(FixFactory.createSuppressWarningsFix(ctx.getInfo(), treePathForWarning, SUPPRESS_WARNINGS_KEY));
return createErrorDescription(ctx, parent, fixes, parent.getKind());
}
示例6: multipleLoops
import org.netbeans.spi.java.hints.HintContext; //导入依赖的package包/类
@Hint(
category = "metrics",
displayName = "#DN_MethodMultipleLoops",
description = "#DESC_MethodMultipleLoops",
options = { Hint.Options.QUERY, Hint.Options.HEAVY },
enabled = false
)
@TriggerTreeKind(Tree.Kind.METHOD)
@UseOptions({ OPTION_LOOPS_LIMIT })
public static ErrorDescription multipleLoops(HintContext ctx) {
Tree t = ctx.getPath().getLeaf();
MethodTree method = (MethodTree)t;
LoopFinder v = new LoopFinder();
v.scan(ctx.getPath(), null);
int count = v.getLoopCount();
int limit = ctx.getPreferences().getInt(OPTION_LOOPS_LIMIT, DEFAULT_LOOPS_LIMIT);
if (count > limit) {
return ErrorDescriptionFactory.forName(ctx, t,
TEXT_MethodMultipleLoops(method.getName().toString(), count)
);
} else {
return null;
}
}
示例7: clone
import org.netbeans.spi.java.hints.HintContext; //导入依赖的package包/类
@TriggerPattern("$mods$ $type clone() throws $exc$ { $stmts$; }") // NOI18N
@Hint(category = "bugs",
displayName = "#DN_CloneAndCloneable_cloneWithoutSuperClone", // NOI18N
description = "#DESC_CloneAndCloneable_cloneWithoutSuperClone", // NOI18N
suppressWarnings={"CloneDoesntCallSuperClone"}, // NOI18N
options= Hint.Options.QUERY
)
public static ErrorDescription cloneWithoutSuperClone(HintContext ctx) {
ExecutableElement me = (ExecutableElement)ctx.getInfo().getTrees().getElement(ctx.getPath());
if (me == null) {
return null;
}
ExecutableElement sup = ctx.getInfo().getElementUtilities().getOverriddenMethod(me);
if (sup == null) {
return null;
}
SuperCloneFinder f = new SuperCloneFinder(ctx.getInfo(), sup);
if (f.scan(ctx.getPath(), null) == Boolean.TRUE) {
return null;
}
return ErrorDescriptionFactory.forName(ctx, ctx.getPath(),
TEXT_CloneWithoutSuperClone());
}
示例8: tooCoupledClass
import org.netbeans.spi.java.hints.HintContext; //导入依赖的package包/类
@Hint(
displayName = "#DN_ClassTooCoupled",
description = "#DESC_ClassTooCoupled",
category = "metrics",
options = { Hint.Options.HEAVY, Hint.Options.QUERY },
enabled = false
)
@UseOptions({ OPTION_COUPLING_LIMIT, OPTION_COUPLING_IGNORE_JAVA })
@TriggerTreeKind(Tree.Kind.CLASS)
public static ErrorDescription tooCoupledClass(HintContext ctx) {
ClassTree clazz = (ClassTree)ctx.getPath().getLeaf();
DependencyCollector col = new DependencyCollector(ctx.getInfo());
boolean ignoreJava = ctx.getPreferences().getBoolean(OPTION_COUPLING_IGNORE_JAVA, DEFAULT_COUPLING_IGNORE_JAVA);
col.setIgnoreJavaLibraries(ignoreJava);
col.scan(ctx.getPath(), null);
int coupling = col.getSeenQNames().size();
int limit = ctx.getPreferences().getInt(OPTION_COUPLING_LIMIT, DEFAULT_COUPLING_LIMIT);
if (coupling > limit) {
return ErrorDescriptionFactory.forName(ctx,
ctx.getPath(),
TEXT_ClassTooCoupled(clazz.getSimpleName().toString(), coupling));
} else {
return null;
}
}
示例9: unusedAssignment
import org.netbeans.spi.java.hints.HintContext; //导入依赖的package包/类
@Hint(displayName = "#DN_org.netbeans.modules.java.hints.bugs.UnusedAssignmentOrBranch.unusedAssignment", description = "#DESC_org.netbeans.modules.java.hints.bugs.UnusedAssignmentOrBranch.unusedAssignment", category="bugs", id=UNUSED_ASSIGNMENT_ID, options={Options.QUERY}, suppressWarnings="UnusedAssignment")
@TriggerPatterns({
@TriggerPattern("$var = $value"),
@TriggerPattern("$mods$ $type $var = $value;")
})
public static ErrorDescription unusedAssignment(final HintContext ctx) {
final String unusedAssignmentLabel = NbBundle.getMessage(UnusedAssignmentOrBranch.class, "LBL_UNUSED_ASSIGNMENT_LABEL");
Pair<Set<Tree>, Set<Element>> computedAssignments = computeUsedAssignments(ctx);
if (ctx.isCanceled() || computedAssignments == null) return null;
final CompilationInfo info = ctx.getInfo();
final Set<Tree> usedAssignments = computedAssignments.first();
final Set<Element> usedVariables = computedAssignments.second();
Element var = info.getTrees().getElement(ctx.getVariables().get("$var"));
TreePath valuePath = ctx.getVariables().get("$value");
Tree value = (valuePath == null ? ctx.getPath() : valuePath).getLeaf();
if (var != null && LOCAL_VARIABLES.contains(var.getKind()) && !usedAssignments.contains(value) && usedVariables.contains(var)) {
return ErrorDescriptionFactory.forTree(ctx, value, unusedAssignmentLabel);
}
return null;
}
示例10: exlucded
import org.netbeans.spi.java.hints.HintContext; //导入依赖的package包/类
@Hint(displayName = "#DN_Imports_EXCLUDED", description = "#DESC_Imports_EXCLUDED", category="imports", id="Imports_EXCLUDED", options=Options.QUERY)
@TriggerTreeKind(Kind.IMPORT)
public static ErrorDescription exlucded(HintContext ctx) throws IOException {
ImportTree it = (ImportTree) ctx.getPath().getLeaf();
if (it.isStatic() || !(it.getQualifiedIdentifier() instanceof MemberSelectTree)) {
return null; // XXX
}
MemberSelectTree ms = (MemberSelectTree) it.getQualifiedIdentifier();
String pkg = ms.getExpression().toString();
String klass = ms.getIdentifier().toString();
String exp = pkg + "." + (!klass.equals("*") ? klass : ""); //NOI18N
if (Utilities.isExcluded(exp)) {
return ErrorDescriptionFactory.forTree(ctx, ctx.getPath(), NbBundle.getMessage(Imports.class, "DN_Imports_EXCLUDED"));
}
return null;
}
示例11: hint
import org.netbeans.spi.java.hints.HintContext; //导入依赖的package包/类
@TriggerTreeKind(Tree.Kind.METHOD_INVOCATION)
public static ErrorDescription hint(HintContext ctx) {
MethodInvocationTree mit = (MethodInvocationTree) ctx.getPath().getLeaf();
CompilationInfo info = ctx.getInfo();
Element e = info.getTrees().getElement(new TreePath(ctx.getPath(), mit.getMethodSelect()));
if (e == null || e.getKind() != ElementKind.METHOD) {
return null;
}
String simpleName = e.getSimpleName().toString();
String parent = e.getEnclosingElement().getSimpleName().toString();
Pair<String, String> pair = map.get(simpleName);
if (pair != null && pair.first().equals(parent)) {
return ErrorDescriptionFactory.forName(ctx, mit, pair.second());
}
return null;
// return ErrorDescriptionFactory.forName(ctx, mit, "Use of forbidden method");
}
示例12: assignsTo
import org.netbeans.spi.java.hints.HintContext; //导入依赖的package包/类
/**
* Determines whether the catch exception parameter is assigned to.
*
* @param ctx HintContext - for CompilationInfo
* @param variable the inspected variable
* @param statements statements that should be checked for assignment
* @return true if 'variable' is assigned to within 'statements'
*/
public static boolean assignsTo(final HintContext ctx, TreePath variable, Iterable<? extends TreePath> statements) {
final Element tEl = ctx.getInfo().getTrees().getElement(variable);
if (tEl == null || tEl.getKind() != ElementKind.EXCEPTION_PARAMETER) return true;
final boolean[] result = new boolean[1];
for (TreePath tp : statements) {
new ErrorAwareTreePathScanner<Void, Void>() {
@Override
public Void visitAssignment(AssignmentTree node, Void p) {
if (tEl.equals(ctx.getInfo().getTrees().getElement(new TreePath(getCurrentPath(), node.getVariable())))) {
result[0] = true;
}
return super.visitAssignment(node, p);
}
}.scan(tp, null);
}
return result[0];
}
示例13: findOuterIf
import org.netbeans.spi.java.hints.HintContext; //导入依赖的package包/类
private static TreePath findOuterIf(HintContext ctx, TreePath treePath) {
while (!ctx.isCanceled()) {
treePath = treePath.getParentPath();
if (treePath == null) {
break;
}
Tree leaf = treePath.getLeaf();
if (leaf.getKind() == Kind.IF) {
return treePath;
}
if (leaf.getKind() == Kind.BLOCK) {
BlockTree b = (BlockTree)leaf;
if (b.getStatements().size() == 1) {
// ok, empty blocks can be around synchronized(this)
// statements
continue;
}
}
return null;
}
return null;
}
示例14: getErr
import org.netbeans.spi.java.hints.HintContext; //导入依赖的package包/类
private static Collection<ErrorDescription> getErr(JPAProblemContext ctx, HintContext hc, AttributeWrapper attrib, String msgKey, String msgPar) {
Tree elementTree = ctx.getCompilationInfo().getTrees().getTree(attrib.getJavaElement());
if(elementTree == null) {
return null;
}
Utilities.TextSpan underlineSpan = Utilities.getUnderlineSpan(
ctx.getCompilationInfo(), elementTree);
ErrorDescription error = ErrorDescriptionFactory.forSpan(
hc,
underlineSpan.getStartOffset(),
underlineSpan.getEndOffset(),
NbBundle.getMessage(ValidColumnName.class, msgKey, msgPar));//TODO: may need to have "error" as default
return Collections.singleton(error);
}
示例15: run
import org.netbeans.spi.java.hints.HintContext; //导入依赖的package包/类
@TriggerTreeKind(Tree.Kind.ASSERT)
public static ErrorDescription run(HintContext ctx) {
CompilationInfo ci = ctx.getInfo();
AssertTree at = (AssertTree)ctx.getPath().getLeaf();
TreePath condPath = new TreePath(ctx.getPath(), at.getCondition());
if (ci.getTreeUtilities().isCompileTimeConstantExpression(condPath)) {
return null;
}
SideEffectVisitor visitor = new SideEffectVisitor(ctx);
Tree culprit;
try {
visitor.scan(new TreePath(ctx.getPath(), at.getCondition()), null);
return null;
} catch (StopProcessing stop) {
culprit = stop.getValue();
}
return ErrorDescriptionFactory.forTree(ctx, culprit, TEXT_AssertWithSideEffects());
}