diff --git a/src/org/ntlab/pushPullRefactoring/PushPullRefactoringHandler.java b/src/org/ntlab/pushPullRefactoring/PushPullRefactoringHandler.java index 26784d0..9397721 100644 --- a/src/org/ntlab/pushPullRefactoring/PushPullRefactoringHandler.java +++ b/src/org/ntlab/pushPullRefactoring/PushPullRefactoringHandler.java @@ -24,8 +24,11 @@ import org.eclipse.jdt.core.dom.Annotation; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.FieldDeclaration; +import org.eclipse.jdt.core.dom.MarkerAnnotation; +import org.eclipse.jdt.core.dom.NormalAnnotation; import org.eclipse.jdt.core.dom.SimpleType; import org.eclipse.jdt.core.dom.SingleMemberAnnotation; +import org.eclipse.jdt.core.dom.TypeDeclaration; import org.eclipse.jdt.core.dom.VariableDeclarationFragment; import org.eclipse.jdt.core.search.IJavaSearchConstants; import org.eclipse.jdt.core.search.IJavaSearchScope; @@ -85,6 +88,8 @@ isPossible = true; try { srcUnit = getCompilationUnitByEvent(event); + String str = annotation.getValue().toString(); + dstUnit = getAnotherCompilationUnit(event, str); } catch (JavaModelException e) { e.printStackTrace(); } @@ -115,6 +120,7 @@ srcUnit = getSourceCompilationUnit(event); + dstUnit = getDistinationCompilationUnit(event, dstNode[0].toString()); } catch (JavaModelException e1) { @@ -284,7 +290,36 @@ IJavaElement element = (IJavaElement) match.getElement(); System.out.println(element.getElementType()); + + ASTParser parser = ASTParser.newParser(AST.JLS4); + parser.setKind(ASTParser.K_COMPILATION_UNIT); + parser.setResolveBindings(true); + parser.setBindingsRecovery(true); + parser.setSource(((SourceType) element).getCompilationUnit()); + ASTNode result = parser.createAST(new NullProgressMonitor()); + ((CompilationUnit) result).recordModifications(); + result.accept(new ASTVisitor() { + @Override + public boolean visit(TypeDeclaration node) { + var modifiers = node.modifiers(); + for(var annotation : modifiers) { + if(annotation instanceof SingleMemberAnnotation) { + var singleMemberAnnotation = ( SingleMemberAnnotation)annotation; + var annotationName = singleMemberAnnotation.getValue().toString(); + if( singleMemberAnnotation.getTypeName().toString().equals("Resource") + && annotationName.equals(resourceName)) { + dstUnit = (CompilationUnit)result; + } + String annoName = ((Annotation)annotation).getTypeName().toString(); + } + + + } + return true; + } + }); + icus[0] = ((SourceType) element).getCompilationUnit(); elementDst[0] = element;