diff --git a/src/org/ntlab/pushPullRefactoring/PushPullRefactoringHandler.java b/src/org/ntlab/pushPullRefactoring/PushPullRefactoringHandler.java index 7a3d3f5..faac29c 100644 --- a/src/org/ntlab/pushPullRefactoring/PushPullRefactoringHandler.java +++ b/src/org/ntlab/pushPullRefactoring/PushPullRefactoringHandler.java @@ -1,7 +1,6 @@ package org.ntlab.pushPullRefactoring; import java.lang.reflect.InvocationTargetException; - import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.IHandler; @@ -13,6 +12,7 @@ import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IMemberValuePair; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.ITypeRoot; @@ -67,7 +67,7 @@ // TODO Auto-generated method stub } - + private IJavaProject javaProject; /** * ���j���[�ŁuPushPullRefactoring...�v���������ꂽ�Ƃ��Ɏ��s */ @@ -79,7 +79,7 @@ SourceField targetField = getTargetField(event); CompilationUnit srcNode = (CompilationUnit) getASTNode(targetField.getCompilationUnit()); ASTNode targetNode = targetField.findNode(srcNode); - + javaProject = targetField.getJavaProject(); String annotationValue =""; if(!(targetNode instanceof FieldDeclaration))return null; for(var modifier : ((FieldDeclaration) targetNode).modifiers()) { @@ -115,8 +115,10 @@ try { if(isPushToPull) { + srcUnit = getCompilationUnitByEvent(event); dstUnit = getAnotherCompilationUnit(event, annotationValue); + //dstUnit = getAnotherCompilationUnit(event, annotationValue, javaProject); }else { srcUnit = getAnotherCompilationUnit(event, annotationValue); @@ -279,7 +281,10 @@ SearchPattern searchPattern = createSearchPattern(); SearchParticipant[] participants = { SearchEngine.getDefaultSearchParticipant() }; - IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); + + //IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); + IJavaSearchScope scope = SearchEngine + .createJavaSearchScope(new IJavaElement[] { javaProject }, false); ICompilationUnit[] icus = new ICompilationUnit[1]; SearchRequestor requestor = new SearchRequestor() { @@ -332,6 +337,50 @@ e.printStackTrace(); } + ASTParser parser = ASTParser.newParser(AST.JLS8); + parser.setKind(ASTParser.K_COMPILATION_UNIT); + parser.setResolveBindings(true); + parser.setBindingsRecovery(true); + parser.setSource(icus[0]); + ASTNode result = parser.createAST(new NullProgressMonitor()); + ((CompilationUnit) result).recordModifications(); + + return (CompilationUnit)result; + } + +private CompilationUnit getAnotherCompilationUnit(ExecutionEvent event, String resourceName ,IJavaProject javaProject) throws JavaModelException { + SearchPattern pattern = SearchPattern.createPattern(resourceName, + IJavaSearchConstants.CLASS, // �N���X�����B + IJavaSearchConstants.DECLARATIONS, // �錾��T���B + SearchPattern.R_EXACT_MATCH); // ���m�Ƀ}�b�`�B + SearchParticipant[] participants = { SearchEngine.getDefaultSearchParticipant() }; + + //IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); + IJavaSearchScope scope = SearchEngine + .createJavaSearchScope(new IJavaElement[] { javaProject }); + + ICompilationUnit[] icus = new ICompilationUnit[1]; + // �N���X���������P�B + // new SearchEngine().search���g���ꍇ�̓t�b�N����N���X��SearchRequestor�B + SearchRequestor requestor = new SearchRequestor() { + public void acceptSearchMatch(SearchMatch match) + throws CoreException { + Object javaElement = match.getElement(); + System.out.println(javaElement); + if (javaElement instanceof IType) { + IType type = (IType) javaElement; + String typeName = type.getFullyQualifiedName(); + icus[0] = ((SourceType) javaElement).getCompilationUnit(); + } + } + }; + + try { + new SearchEngine().search(pattern, participants, scope, requestor, new NullProgressMonitor()); + } catch (CoreException e) { + e.printStackTrace(); + } + ASTParser parser = ASTParser.newParser(AST.JLS4); parser.setKind(ASTParser.K_COMPILATION_UNIT); parser.setResolveBindings(true); @@ -342,6 +391,7 @@ return (CompilationUnit)result; } + private IAnnotation[] getValidAnnotations(ExecutionEvent event) { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);