something wrong with org.eclipse.jdt.core.IAnnotation.exist() [message #257648] |
Wed, 03 December 2008 00:45 |
Eclipse User |
|
|
|
I have a requirement like this: in the source editor, I will add
annotation on a method.so I have to judge that if the method have the
annotation. if exist , I will update it, and if not exist. I will append
it.
however, in test I found: it is normal when the first run it. and It can
append the annotation. then I use ctrl+z to remove the annotation that
just appended right now. then run it again, it can't work
I judge if the annotation is existed through something wrong with
org.eclipse.jdt.core.IAnnotation.exist() method. and I found that after
the first time add the annotation, IAnnotation.exist() will return true
all the time , no matter if I have remove this annotation in the source
editor.
why ?
code as following:
FileEditorInput input = (FileEditorInput) editor.getEditorInput();
IWorkingCopyManager manager = JavaUI.getWorkingCopyManager();
try {
manager.connect(input);
ICompilationUnit cu = manager.getWorkingCopy(input);
System.out.println(cu.getSource());
for (String s : IConst.BLOC_IMPORTS) {
IImportDeclaration im = cu.getImport(s);
if (im == null || !im.exists()) {
cu.createImport(s, null, null);
}
}
IBuffer buffer = cu.getBuffer();
IType[] types = cu.getTypes();
IMethod selected = null;
for (IType t : types) {
IMethod[] methods = t.getMethods();
selected = methods[0];
if (selected != null) {
IAnnotation anno = selected
.getAnnotation(procedureType.getRoot());
String source = page.construction.getSource();
if(!anno.exists()){
IAnnotation anno2 = selected
.getAnnotation("Procedure");
buffer.replace(anno2.getSourceRange().getOffset()+
anno2.getSourceRange().getLength(),0, source);
}else{
buffer.replace(anno.getSourceRange().getOffset(),
anno.getSourceRange().getLength(), source);
}
}
cu.reconcile(AST.JLS3, true, null, null);
cu.commitWorkingCopy(true, null);
manager.disconnect(input);
} catch (Exception e2) {
e2.printStackTrace();
}
|
|
|
Powered by
FUDForum. Page generated in 0.07446 seconds