本文整理汇总了Java中org.netbeans.spi.editor.hints.Fix类的典型用法代码示例。如果您正苦于以下问题:Java Fix类的具体用法?Java Fix怎么用?Java Fix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Fix类属于org.netbeans.spi.editor.hints包,在下文中一共展示了Fix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: performTestAnalysisTest
import org.netbeans.spi.editor.hints.Fix; //导入依赖的package包/类
protected void performTestAnalysisTest(String className, int offset, Set<String> golden) throws Exception {
prepareTest(className);
DataObject od = DataObject.find(info.getFileObject());
EditorCookie ec = (EditorCookie) od.getLookup().lookup(EditorCookie.class);
Document doc = ec.openDocument();
ChangeMethodParameters cmp = new ChangeMethodParameters();
List<Fix> fixes = cmp.run(info, null, offset, null, null);
Set<String> real = new HashSet<String>();
for (Fix f : fixes) {
if (f instanceof ChangeParametersFix) {
real.add(((ChangeParametersFix) f).getText());
continue;
}
}
assertEquals(golden, real);
}
示例2: right
import org.netbeans.spi.editor.hints.Fix; //导入依赖的package包/类
public boolean right() {
Fix f = (Fix) getSelectedValue();
Iterable<? extends Fix> subfixes = HintsControllerImpl.getSubfixes(f);
if (subfixes.iterator().hasNext()) {
Rectangle r = getCellBounds(getSelectedIndex(), getSelectedIndex());
Point p = new Point(r.getLocation());
SwingUtilities.convertPointToScreen(p, this);
p.x += r.width;
// p.y += r.height;
HintsUI.getDefault().openSubList(subfixes, p);
return true;
}
return false;
}
示例3: run
import org.netbeans.spi.editor.hints.Fix; //导入依赖的package包/类
@Override
public List<Fix> run(CompilationInfo compilationInfo, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
EnumSet<Kind> supportedKinds = EnumSet.of(Kind.ANNOTATION_TYPE, Kind.CLASS, Kind.ENUM, Kind.VARIABLE, Kind.INTERFACE, Kind.METHOD);
boolean isSupported = (supportedKinds.contains(treePath.getLeaf().getKind()));
if (!isSupported) {
return null;
}
String invalidMod = getInvalidModifier(compilationInfo, treePath, CODES);
if (null==invalidMod)
{
return null;
}
//support multiple invalid modifiers
Collection<Modifier> modss=convertToModifiers(invalidMod.split(","));
TreePath modifierTreePath = TreePath.getPath(treePath, getModifierTree(treePath));
Fix removeModifiersFix = FixFactory.removeModifiersFix(compilationInfo, modifierTreePath, new HashSet<>(modss), NbBundle.getMessage(RemoveInvalidModifier.class, "FIX_RemoveInvalidModifier", invalidMod, modss.size()));
return Arrays.asList(removeModifiersFix);
}
示例4: testSubFixesLeak
import org.netbeans.spi.editor.hints.Fix; //导入依赖的package包/类
public void testSubFixesLeak() throws Exception {
class TestFix implements Fix {
@Override public String getText() { return null; }
@Override public ChangeInfo implement() throws Exception { return null; }
}
Fix main = new TestFix();
Fix sub = new TestFix();
HintsControllerImpl.attachSubfixes(main, Collections.singletonList(sub));
Reference<Fix> mainRef = new WeakReference<Fix>(main);
Reference<Fix> subRef = new WeakReference<Fix>(sub);
main = null;
sub = null;
assertGC("main", mainRef);
assertGC("sub", subRef);
}
示例5: check
import org.netbeans.spi.editor.hints.Fix; //导入依赖的package包/类
public Collection<ErrorDescription> check(JPAProblemContext ctx, HintContext hc, AttributeWrapper attrib) {
String temporal = attrib.getTemporal();
if (temporal == null || temporal.length() == 0) {
if (temporalTypes.contains(attrib.getType().toString())) {
Fix fix = new CreateTemporalAnnotationHint(ctx.getFileObject(),
ElementHandle.create(attrib.getJavaElement()));
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(TemporalFieldsAnnotated.class, "MSG_TemporalAttrNotAnnotatedProperly"),
fix);//TODO: may need to have "error" as default
return Collections.singleton(error);
}
}
return null;
}
示例6: forBLOCK
import org.netbeans.spi.editor.hints.Fix; //导入依赖的package包/类
@Hint(displayName = "#LBL_Empty_BLOCK", description = "#DSC_Empty_BLOCK", category = "empty", hintKind = Hint.Kind.INSPECTION, severity = Severity.VERIFIER, suppressWarnings = SUPPRESS_WARNINGS_KEY, id = "EmptyStatements_BLOCK")
@TriggerTreeKind(Tree.Kind.EMPTY_STATEMENT)
@NbBundle.Messages({"ERR_EmptyBLOCK=Remove semicolon"})
public static ErrorDescription forBLOCK(HintContext ctx) {
Tree parent = ctx.getPath().getParentPath().getLeaf();
if (!EnumSet.of(Kind.BLOCK).contains(parent.getKind())) {
return null;
}
final List<Fix> fixes = new ArrayList<>();
fixes.add(FixFactory.createSuppressWarningsFix(ctx.getInfo(), ctx.getPath(), SUPPRESS_WARNINGS_KEY));
fixes.add(JavaFixUtilities.removeFromParent(ctx, Bundle.ERR_EmptyBLOCK(), ctx.getPath()));
return createErrorDescription(ctx, ctx.getPath().getLeaf(), fixes, Kind.BLOCK);
}
示例7: prepareCreateInnerClassFix
import org.netbeans.spi.editor.hints.Fix; //导入依赖的package包/类
private static List<Fix> prepareCreateInnerClassFix(CompilationInfo info, TreePath invocation, TypeElement target, Set<Modifier> modifiers, String simpleName, List<? extends ExpressionTree> realArguments, TypeMirror superType, ElementKind kind, int numTypeParameters) {
Pair<List<? extends TypeMirror>, List<String>> formalArguments = invocation != null ? Utilities.resolveArguments(info, invocation, realArguments, target) : Pair.<List<? extends TypeMirror>, List<String>>of(null, null);
if (formalArguments == null) {
return Collections.<Fix>emptyList();
}
//IZ 111048 -- don't offer anything if target file isn't writable
if (!Utilities.isTargetWritable(target, info))
return Collections.<Fix>emptyList();
FileObject targetFile = SourceUtils.getFile(target, info.getClasspathInfo());
if (targetFile == null)
return Collections.<Fix>emptyList();
final CreateInnerClassFix fix = new CreateInnerClassFix(info, simpleName, modifiers, target, formalArguments.first(), formalArguments.second(), superType, kind, numTypeParameters, targetFile);
fix.setPriority(PRIO_INNER);
return Collections.<Fix>singletonList(fix);
}
示例8: forName
import org.netbeans.spi.editor.hints.Fix; //导入依赖的package包/类
public static ErrorDescription forName(HintContext context, Tree tree, String text, Fix... fixes) {
int[] span;
if (context.getHintMetadata().kind == Hint.Kind.INSPECTION) {
span = computeNameSpan(tree, context);
} else {
span = new int[] {context.getCaretLocation(), context.getCaretLocation()};
}
if (span != null && span[0] != (-1) && span[1] != (-1)) {
LazyFixList fixesForED = org.netbeans.spi.editor.hints.ErrorDescriptionFactory.lazyListForFixes(resolveDefaultFixes(context, fixes));
return org.netbeans.spi.editor.hints.ErrorDescriptionFactory.createErrorDescription("text/x-java:" + context.getHintMetadata().id, context.getSeverity(), text, context.getHintMetadata().description, fixesForED, context.getInfo().getFileObject(), span[0], span[1]);
}
return null;
}
示例9: createSuppressWarningsFix
import org.netbeans.spi.editor.hints.Fix; //导入依赖的package包/类
/** Creates a fix, which when invoked adds @SuppresWarnings(keys) to
* nearest declaration.
* @param compilationInfo CompilationInfo to work on
* @param treePath TreePath to a tree. The method will find nearest outer
* declaration. (type, method, field or local variable)
* @param keys keys to be contained in the SuppresWarnings annotation. E.g.
* @SuppresWarnings( "key" ) or @SuppresWarnings( {"key1", "key2", ..., "keyN" } ).
* @throws IllegalArgumentException if keys are null or empty or id no suitable element
* to put the annotation on is found (e.g. if TreePath to CompilationUnit is given")
*/
static Fix createSuppressWarningsFix(CompilationInfo compilationInfo, TreePath treePath, String... keys ) {
Parameters.notNull("compilationInfo", compilationInfo);
Parameters.notNull("treePath", treePath);
Parameters.notNull("keys", keys);
if (keys.length == 0) {
throw new IllegalArgumentException("key must not be empty"); // NOI18N
}
if (!isSuppressWarningsSupported(compilationInfo)) {
return null;
}
while (treePath.getLeaf().getKind() != Kind.COMPILATION_UNIT && !DECLARATION.contains(treePath.getLeaf().getKind())) {
treePath = treePath.getParentPath();
}
if (treePath.getLeaf().getKind() != Kind.COMPILATION_UNIT) {
return new FixImpl(TreePathHandle.create(treePath, compilationInfo), compilationInfo.getFileObject(), keys);
} else {
return null;
}
}
示例10: createSuppressWarnings
import org.netbeans.spi.editor.hints.Fix; //导入依赖的package包/类
/** Creates a fix, which when invoked adds @SuppresWarnings(keys) to
* nearest declaration.
* @param compilationInfo CompilationInfo to work on
* @param treePath TreePath to a tree. The method will find nearest outer
* declaration. (type, method, field or local variable)
* @param keys keys to be contained in the SuppresWarnings annotation. E.g.
* @SuppresWarnings( "key" ) or @SuppresWarnings( {"key1", "key2", ..., "keyN" } ).
* @throws IllegalArgumentException if keys are null or empty or id no suitable element
* to put the annotation on is found (e.g. if TreePath to CompilationUnit is given")
*/
static List<Fix> createSuppressWarnings(CompilationInfo compilationInfo, TreePath treePath, String... keys ) {
Parameters.notNull("compilationInfo", compilationInfo);
Parameters.notNull("treePath", treePath);
Parameters.notNull("keys", keys);
if (keys.length == 0) {
throw new IllegalArgumentException("key must not be empty"); // NOI18N
}
Fix f = createSuppressWarningsFix(compilationInfo, treePath, keys);
if (f != null) {
return Collections.<Fix>singletonList(f);
} else {
return Collections.emptyList();
}
}
示例11: performArithmeticTest
import org.netbeans.spi.editor.hints.Fix; //导入依赖的package包/类
private void performArithmeticTest(String orig, String nue) throws Exception {
String code = replace("0");
prepareTest("Test.java", code);
ClassTree clazz = (ClassTree) info.getCompilationUnit().getTypeDecls().get(0);
VariableTree variable = (VariableTree) clazz.getMembers().get(1);
ExpressionTree init = variable.getInitializer();
TreePath tp = new TreePath(new TreePath(new TreePath(new TreePath(info.getCompilationUnit()), clazz), variable), init);
Fix fix = JavaFixUtilities.rewriteFix(info, "A", tp, orig, Collections.<String, TreePath>emptyMap(), Collections.<String, Collection<? extends TreePath>>emptyMap(), Collections.<String, String>emptyMap(), Collections.<String, TypeMirror>emptyMap(), Collections.<String, String>emptyMap());
fix.implement();
String golden = replace(nue);
String out = doc.getText(0, doc.getLength());
assertEquals(golden, out);
LifecycleManager.getDefault().saveAll();
}
示例12: performRemoveFromParentTest
import org.netbeans.spi.editor.hints.Fix; //导入依赖的package包/类
public void performRemoveFromParentTest(String code, String rule, String golden) throws Exception {
prepareTest("test/Test.java", code);
HintDescription hd = HintDescriptionFactory.create()
.setTrigger(PatternDescription.create(rule, Collections.<String, String>emptyMap()))
.setWorker(new HintDescription.Worker() {
@Override public Collection<? extends ErrorDescription> createErrors(HintContext ctx) {
return Collections.singletonList(ErrorDescriptionFactory.forName(ctx, ctx.getPath(), "", JavaFixUtilities.removeFromParent(ctx, "", ctx.getPath())));
}
}).produce();
List<ErrorDescription> computeHints = new HintsInvoker(HintsSettings.getGlobalSettings(), new AtomicBoolean()).computeHints(info, Collections.singleton(hd));
assertEquals(computeHints.toString(), 1, computeHints.size());
Fix fix = computeHints.get(0).getFixes().getFixes().get(0);
fix.implement();
assertEquals(golden, doc.getText(0, doc.getLength()));
}
示例13: forIF
import org.netbeans.spi.editor.hints.Fix; //导入依赖的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());
}
示例14: performAnalysisTest
import org.netbeans.spi.editor.hints.Fix; //导入依赖的package包/类
protected void performAnalysisTest(String fileName, String code, int pos, String... golden) throws Exception {
prepareTest(fileName, code);
String diagnosticCode;
if (pos == (-1)) {
Diagnostic<?> d = findPositionForErrors();
pos = (int) ErrorHintsProvider.getPrefferedPosition(info, d);
diagnosticCode = d.getCode();
} else {
diagnosticCode = null;
}
TreePath path = info.getTreeUtilities().pathFor(pos);
List<Fix> fixes = computeFixes(info, diagnosticCode, pos, path);
List<String> fixesNames = new LinkedList<String>();
fixes = fixes != null ? fixes : Collections.<Fix>emptyList();
for (Fix e : fixes) {
fixesNames.add(toDebugString(info, e));
}
assertTrue(fixesNames.toString(), Arrays.equals(golden, fixesNames.toArray(new String[0])));
}
示例15: run
import org.netbeans.spi.editor.hints.Fix; //导入依赖的package包/类
@Override
public List<Fix> run(CompilationInfo info, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
if (treePath == null || !TreeUtilities.CLASS_TREE_KINDS.contains(treePath.getLeaf().getKind())) {
return null;
}
if (treePath.getLeaf().getKind() == Tree.Kind.INTERFACE) {
return null;
}
TypeElement type = (TypeElement) info.getTrees().getElement(treePath);
if (type == null) {
return null;
}
List<Fix> fixes = new ArrayList<Fix>();
fixes.add(new FixImpl(TreePathHandle.create(treePath, info), false).toEditorFix());
// fixes.add(new FixImpl(TreePathHandle.create(treePath, info), true));
if (!type.getNestingKind().equals(NestingKind.ANONYMOUS)) {
// add SuppressWarning only to non-anonymous class
fixes.addAll(FixFactory.createSuppressWarnings(info, treePath, SERIAL));
}
return fixes;
}