1
Eclipse 플러그인의 메소드에 주석을 추가하려고합니다. 특정 방법을 나타내는 IJavaElement
에 액세스 할 수 있습니다.Eclipse 플러그인의 메소드에 주석 추가
이 경우 Eclipse JDT를 사용할 때 가장 좋은 방법은 무엇입니까?
Eclipse 플러그인의 메소드에 주석을 추가하려고합니다. 특정 방법을 나타내는 IJavaElement
에 액세스 할 수 있습니다.Eclipse 플러그인의 메소드에 주석 추가
이 경우 Eclipse JDT를 사용할 때 가장 좋은 방법은 무엇입니까?
예 JDT는이 문제에 대한 좋은 접근 방법입니다.
다음 코드는 동일한 작업을 수행하는 방법에 대한 아이디어를 제공합니다.
(참고 : 코드 테스트 또는 컴파일되지 않음)
if (javaElement instanceof IMethod) {
// Get the compilation unit for traversing AST
final ASTParser parser = ASTParser.newParser(AST.JLS4);
parser.setSource(javaElement.getCompilationUnit());
parser.setResolveBindings(true);
final CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null);
// Record modification - to be later written with ASTRewrite
compilationUnit.recordModifications();
// Get AST node for IMethod
int methodIndex = javaElement.getCompilationUnit().getSource().indexOf(javaElement.getSource());
ASTNode methodASTNode = NodeFinder.perform(compilationUnit.getRoot(), methodIndex, javaElement.getSource().length());
// Create the annotation
final NormalAnnotation newNormalAnnotation = methodASTNode.getAST().newNormalAnnotation();
newNormalAnnotation.setTypeName(methodASTNode.getAST().newName("AnnotationTest"));
// Add logic for writing the AST here.
}
감사합니다. 나는 [annotationUtils] (http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.jst.ws.jaxws.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjst%)를 사용했다. 2Fws % 2Fannotations % 2Fcore % 2Futils % 2FAnnotationUtils.html)이 간단한 apis를 사용할 수있는 일식 루나에서. –