本文整理汇总了Java中org.netbeans.spi.editor.hints.ChangeInfo类的典型用法代码示例。如果您正苦于以下问题:Java ChangeInfo类的具体用法?Java ChangeInfo怎么用?Java ChangeInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChangeInfo类属于org.netbeans.spi.editor.hints包,在下文中一共展示了ChangeInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSubFixesLeak
import org.netbeans.spi.editor.hints.ChangeInfo; //导入依赖的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);
}
示例2: testSubFixesEquals
import org.netbeans.spi.editor.hints.ChangeInfo; //导入依赖的package包/类
public void testSubFixesEquals() throws Exception {
class TestFix implements Fix {
@Override public String getText() { return null; }
@Override public ChangeInfo implement() throws Exception { return null; }
@Override public int hashCode() { return 0; }
@Override public boolean equals(Object obj) {
return obj != null && this.getClass() == obj.getClass();
}
}
class SubFix implements Fix {
@Override public String getText() { return null; }
@Override public ChangeInfo implement() throws Exception { return null; }
}
Fix first = new TestFix();
Fix firstSub = new SubFix();
Fix second = new TestFix();
Fix secondSub = new SubFix();
HintsControllerImpl.attachSubfixes(first, Collections.singletonList(firstSub));
HintsControllerImpl.attachSubfixes(second, Collections.singletonList(secondSub));
assertSame(firstSub, HintsControllerImpl.getSubfixes(first).iterator().next());
assertSame(secondSub, HintsControllerImpl.getSubfixes(second).iterator().next());
}
示例3: implement
import org.netbeans.spi.editor.hints.ChangeInfo; //导入依赖的package包/类
public ChangeInfo implement() throws Exception {
FileObject file = Accessor.INSTANCE.getFile(jf);
BatchUtilities.fixDependencies(file, Collections.singletonList(jf), new IdentityHashMap<Project, Set<String>>());
JavaSource js = JavaSource.forFileObject(file);
js.runModificationTask(new Task<WorkingCopy>() {
public void run(WorkingCopy wc) throws Exception {
if (wc.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) {
return;
}
Map<FileObject, byte[]> resourceContentChanges = new HashMap<FileObject, byte[]>();
Accessor.INSTANCE.process(jf, wc, true, resourceContentChanges, /*Ignored in editor:*/new ArrayList<RefactoringElementImplementation>());
Map<FileObject, List<Difference>> resourceContentDiffs = new HashMap<FileObject, List<Difference>>();
BatchUtilities.addResourceContentChanges(resourceContentChanges, resourceContentDiffs);
JavaSourceAccessor.getINSTANCE().createModificationResult(resourceContentDiffs, Collections.<Object, int[]>emptyMap()).commit();
}
}).commit();
return null;
}
示例4: implement
import org.netbeans.spi.editor.hints.ChangeInfo; //导入依赖的package包/类
@Override
public ChangeInfo implement() throws Exception {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (transform) {
final InspectAndTransformOpener o = Lookup.getDefault().lookup(InspectAndTransformOpener.class);
if (o != null) {
o.openIAT(metadata);
} else {
//warn
}
} else {
CodeAnalysis.open(WarningDescription.create("text/x-java:" + metadata.id, null, null, null));
}
}
});
return null;
}
示例5: implement
import org.netbeans.spi.editor.hints.ChangeInfo; //导入依赖的package包/类
@Override
public ChangeInfo implement() throws Exception {
final FileObject file = handle.getFileObject();
final JTextComponent comp = EditorRegistry.lastFocusedComponent();
if (file != null && file == getFileObject(comp)) {
final int[] pos = new int[]{-1};
JavaSource.forFileObject(file).runUserActionTask(new Task<CompilationController>(){
@Override
public void run(CompilationController info) throws Exception {
info.toPhase(JavaSource.Phase.PARSED);
final TreePath tp = handle.resolve(info);
if (tp != null && tp.getLeaf().getKind() == Tree.Kind.VARIABLE) {
pos[0] = (int) info.getTrees().getSourcePositions().getEndPosition(
tp.getCompilationUnit(),
((VariableTree)tp.getLeaf()).getType()) + 1;
}
}
}, true);
invokeRefactoring (comp, pos[0]);
}
return null;
}
示例6: implement
import org.netbeans.spi.editor.hints.ChangeInfo; //导入依赖的package包/类
@Override
public ChangeInfo implement() throws Exception {
final FileObject file = handle.getFileObject();
final JTextComponent component = EditorRegistry.lastFocusedComponent();
if (file != null && file == getFileObject(component)) {
final int[] position = new int[] {-1};
JavaSource.forFileObject(file).runUserActionTask(new Task<CompilationController>() {
@Override
public void run(CompilationController controller) throws Exception {
controller.toPhase(JavaSource.Phase.PARSED);
final TreePath tp = handle.resolve(controller);
if (tp != null && TreeUtilities.CLASS_TREE_KINDS.contains(tp.getLeaf().getKind())) {
position[0] = (int) controller.getTrees().getSourcePositions().getStartPosition(
tp.getCompilationUnit(),
(ClassTree)tp.getLeaf())+1;
}
}
}, true);
invokeRefactoring(component, position[0]);
}
return null;
}
示例7: implement
import org.netbeans.spi.editor.hints.ChangeInfo; //导入依赖的package包/类
@Override
public ChangeInfo implement() throws IOException, BadLocationException {
JButton btnOk = new JButton(NbBundle.getMessage(IntroduceHint.class, "LBL_Ok"));
btnOk.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(IntroduceHint.class, "AD_IntrHint_OK"));
JButton btnCancel = new JButton(NbBundle.getMessage(IntroduceHint.class, "LBL_Cancel"));
btnCancel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(IntroduceHint.class, "AD_IntrHint_Cancel"));
IntroduceFieldPanel panel = createPanel(btnOk);
FieldValidator fv = new FieldValidator(js, null, this.handle);
if (targetIsInterface) {
panel.setAllowAccess(false);
}
DialogDescriptor dd = new DialogDescriptor(panel, getCaption(), true, new Object[]{btnOk, btnCancel}, btnOk, DialogDescriptor.DEFAULT_ALIGN, null, null);
panel.setNotifier(dd.createNotificationLineSupport());
panel.setTarget(targetHandle);
panel.setValidator(fv);
if (DialogDisplayer.getDefault().notify(dd) != btnOk) {
return null; //cancel
}
js.runModificationTask(new Worker(panel.getFieldName(), permitDuplicates && panel.isReplaceAll(),
panel.isDeclareFinal(), panel.getAccess(), panel.getInitializeIn(),
fv.getLastResult(),
panel.isRefactorExisting())).commit();
return null;
}
示例8: implement
import org.netbeans.spi.editor.hints.ChangeInfo; //导入依赖的package包/类
public ChangeInfo implement() throws Exception {
JButton btnOk = new JButton(NbBundle.getMessage(IntroduceHint.class, "LBL_Ok"));
JButton btnCancel = new JButton(NbBundle.getMessage(IntroduceHint.class, "LBL_Cancel"));
IntroduceMethodPanel panel = new IntroduceMethodPanel("", duplicatesCount, targets, targetIsInterface); //NOI18N
String caption = NbBundle.getMessage(IntroduceHint.class, "CAP_IntroduceMethod");
DialogDescriptor dd = new DialogDescriptor(panel, caption, true, new Object[]{btnOk, btnCancel}, btnOk, DialogDescriptor.DEFAULT_ALIGN, null, null);
NotificationLineSupport notifier = dd.createNotificationLineSupport();
MethodValidator val = new MethodValidator(js, parameters, returnType);
panel.setNotifier(notifier);
panel.setValidator(val);
panel.setOkButton(btnOk);
if (DialogDisplayer.getDefault().notify(dd) != btnOk) {
return null; //cancel
}
boolean redoReferences = panel.isRefactorExisting();
final String name = panel.getMethodName();
final Set<Modifier> access = panel.getAccess();
final boolean replaceOther = panel.getReplaceOther();
final TargetDescription target = panel.getSelectedTarget();
js.runModificationTask(new TaskImpl(access, name, target, replaceOther, val.getResult(), redoReferences)).commit();
return null;
}
示例9: implement
import org.netbeans.spi.editor.hints.ChangeInfo; //导入依赖的package包/类
public ChangeInfo implement() throws IOException {
JavaSource js = JavaSource.forFileObject(file);
js.runModificationTask(new Task<WorkingCopy>() {
public void run(WorkingCopy copy) throws Exception {
copy.toPhase(Phase.PARSED);
CompilationUnitTree cut = copy.getCompilationUnit();
if (packageName.length() == 0) {
copy.rewrite(cut, copy.getTreeMaker().CompilationUnit(cut.getPackageAnnotations(), null, cut.getImports(), cut.getTypeDecls(), cut.getSourceFile()));
} else {
if (cut.getPackageName() == null) {
copy.rewrite(cut, copy.getTreeMaker().CompilationUnit(cut.getPackageAnnotations(), createForFQN(copy, packageName), cut.getImports(), cut.getTypeDecls(), cut.getSourceFile()));
} else {
copy.rewrite(cut.getPackageName(), createForFQN(copy, packageName));
}
}
}
}).commit();
return null;
}
示例10: implement
import org.netbeans.spi.editor.hints.ChangeInfo; //导入依赖的package包/类
public ChangeInfo implement() throws IOException {
js.runModificationTask(new Task<WorkingCopy>() {
public void run(WorkingCopy wc) throws Exception {
wc.toPhase(Phase.RESOLVED);
Tree tree = wc.getTrees().getTree(method.resolve(wc));
if (tree == null) {
Logger.getLogger(UncaughtException.class.getName()).log(Level.WARNING, "Cannot resolve Handle." +
"fqn: " + fqn +
"method: " + Arrays.asList(SourceUtils.getJVMSignature(method)).toString());
return;
}
assert tree.getKind() == Kind.METHOD;
MethodTree nue = wc.getTreeMaker().addMethodThrows((MethodTree) tree, (ExpressionTree) wc.getTreeMaker().Type(thandle.resolve(wc)));
wc.rewrite(tree, nue);
}
}).commit();
return null;
}
示例11: implement
import org.netbeans.spi.editor.hints.ChangeInfo; //导入依赖的package包/类
@Override
public ChangeInfo implement() throws Exception {
try {
ModificationResult.runModificationTask(Collections.singleton(source), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
WorkingCopy wc = WorkingCopy.get(resultIterator.getParserResult(offset));
wc.toPhase(Phase.PARSED);
TreePath path = pathHandle.resolve(wc);
if (path != null && path.getLeaf().getKind() == Kind.METHOD) {
MethodTree mt = (MethodTree) path.getLeaf();
wc.rewrite(mt, wc.getTreeMaker().setLabel(mt, newConstructorName));
}
}
}).commit();
} catch (IOException e) {
Exceptions.printStackTrace(e);
}
return null;
}
示例12: implement
import org.netbeans.spi.editor.hints.ChangeInfo; //导入依赖的package包/类
@Override
public ChangeInfo implement() throws Exception {
ChangeInfo info = new ChangeInfo();
if (!mdl.getState().equals(Model.State.VALID)) {
return info;
}
PomModelUtils.implementInTransaction(mdl, new Runnable() {
@Override
public void run() {
org.netbeans.modules.maven.model.pom.Project prj = mdl.getProject();
ModelUtils.updatePluginVersion(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER, "3.6.1", prj);
ModelUtils.openAtPlugin(mdl, Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER);
}
});
return info;
}
示例13: implement
import org.netbeans.spi.editor.hints.ChangeInfo; //导入依赖的package包/类
public ChangeInfo implement(){
CancellableTask<WorkingCopy> task = new CancellableTask<WorkingCopy>(){
public void cancel() {}
public void run(WorkingCopy workingCopy) throws Exception {
workingCopy.toPhase(JavaSource.Phase.RESOLVED);
TypeElement clazz = classHandle.resolve(workingCopy);
if (clazz != null){
ClassTree clazzTree = workingCopy.getTrees().getTree(clazz);
GenerationUtils genUtils = GenerationUtils.newInstance(workingCopy);
ClassTree modifiedClazz = genUtils.addImplementsClause(clazzTree, "java.io.Serializable"); // NOI18N
workingCopy.rewrite(clazzTree, modifiedClazz);
}
}
};
JavaSource javaSource = JavaSource.forFileObject(fileObject);
try{
javaSource.runModificationTask(task).commit();
} catch (IOException e){
JPAProblemFinder.LOG.log(Level.SEVERE, e.getMessage(), e);
}
return null;
}
示例14: createChangeInfo
import org.netbeans.spi.editor.hints.ChangeInfo; //导入依赖的package包/类
protected ChangeInfo createChangeInfo( ModificationResult... results )
throws IOException
{
ChangeInfo changeInfo = new ChangeInfo();
for (ModificationResult result : results) {
List<? extends Difference> differences =
result.getDifferences(getFileObject());
if (differences != null) {
for (Difference difference : differences) {
changeInfo.add(getFileObject(), difference.getStartPosition(),
difference.getEndPosition());
}
}
}
return changeInfo;
}
示例15: doImplement
import org.netbeans.spi.editor.hints.ChangeInfo; //导入依赖的package包/类
protected ChangeInfo doImplement( String stateFqn ) throws IOException {
ModificationResult result =
addGetStateMethod(JavaSource.forFileObject(getFileObject()),
getHandle(), stateFqn);
if (result == null) {
return null;
}
if (getPairHandle() == null) {
return createChangeInfo(result);
}
else {
ModificationResult pairResult =
addGetStateMethod(
JavaSource.forFileObject(myPairFileObject),
getPairHandle(), stateFqn);
return createChangeInfo(result, pairResult);
}
}