diff --git a/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java b/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java index bed88d2..473e9fa 100644 --- a/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java +++ b/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java @@ -225,6 +225,8 @@ deletePutMethodInvocation(srcUnitRewrite, srcUnit, dstValue); // @PushReference���t�^���ꂽ�t�B�[���h���폜 deleteASTNode(srcUnitRewrite, srcUnit, searchFieldDeclaration(descriptor.getSourceClass(), "PushReference", dstValue)); + + System.out.println(); try { applyRewrite(srcUnit, srcUnitRewrite, pm); applyRewrite(dstUnit, dstUnitRewrite, pm); @@ -233,19 +235,7 @@ // TODO Auto-generated catch block e1.printStackTrace(); } -// // �V�K�t�@�C���쐬 -// try { -// IPath dstPath = dstUnit.getJavaElement().getPath(); -// ITextFileBufferManager dstBufferManager = FileBuffers.getTextFileBufferManager(); -// dstBufferManager.connect(dstPath, LocationKind.IFILE, pm); -// ITextFileBuffer dstTextFileBuffer = dstBufferManager.getTextFileBuffer(dstPath, LocationKind.IFILE); -// IDocument dstDocument = dstTextFileBuffer.getDocument(); -// TextEdit dstEdit = dstUnitRewrite.rewriteAST(dstDocument, null); -// UndoEdit dstUndo = dstEdit.apply(dstDocument); -// dstTextFileBuffer.commit(pm /* ProgressMonitor */, true/* Overwrite */); -// } catch (Exception e) { -// e.printStackTrace(); -// } + } private void applyRewrite(CompilationUnit unit, ASTRewrite unitRewrite, IProgressMonitor pm) throws Exception { IPath path = unit.getJavaElement().getPath(); @@ -324,7 +314,7 @@ } - private MethodDeclaration[] searchMethodDeclarations(CompilationUnit cu, String annotationName, String... values) { + public MethodDeclaration[] searchMethodDeclarations(CompilationUnit cu, String annotationName, String... values) { List result = new ArrayList(); cu.accept(new ASTVisitor() { @Override @@ -359,6 +349,11 @@ return result; } + /** + * Map.Entry��Map�ɕϊ����郁�\�b�h + * @param type + * @return + */ private String convertType(Type type) { if ((type instanceof ParameterizedType diff --git a/src/org/ntlab/pushPullRefactoring/PushPullRefactoringHandler.java b/src/org/ntlab/pushPullRefactoring/PushPullRefactoringHandler.java index c9a1099..7656e2b 100644 --- a/src/org/ntlab/pushPullRefactoring/PushPullRefactoringHandler.java +++ b/src/org/ntlab/pushPullRefactoring/PushPullRefactoringHandler.java @@ -78,50 +78,62 @@ //�I��Ώۂ�AST���擾��,�������A�m�e�[�V�������t�^����Ă��邩���`�F�b�N. SourceField targetField = getTargetField(event); CompilationUnit srcNode = (CompilationUnit) getASTNode(targetField.getCompilationUnit()); - srcNode.accept(new ASTVisitor() { - public boolean visit(FieldDeclaration node) { - for(var astNode : node.modifiers()) { - if(astNode instanceof SingleMemberAnnotation) { - SingleMemberAnnotation annotation = (SingleMemberAnnotation)astNode; - String annotationName = ((Annotation)annotation).getTypeName().toString(); - String annotationValue = annotation.getValue().toString(); - - if(annotationName.equals("PushReference")) { - isPossible = true; - try { - srcUnit = getCompilationUnitByEvent(event); - dstUnit = getAnotherCompilationUnit(event, annotationValue); - isPushToPull = true; - } catch (JavaModelException e) { - e.printStackTrace(); - } - - }else if(annotationName.equals("PullReference")) { - isPossible = true; - try { - - dstUnit = getCompilationUnitByEvent(event); - srcUnit = getAnotherCompilationUnit(event, annotationValue); - isPushToPull = false; - } catch (JavaModelException e) { - e.printStackTrace(); - } + ASTNode targetNode = targetField.findNode(srcNode); - } - System.out.println( annotation.getValue().toString()); - } + String annotationValue =""; + if(!(targetNode instanceof FieldDeclaration))return null; + for(var modifier : ((FieldDeclaration) targetNode).modifiers()) { + if(modifier instanceof SingleMemberAnnotation) { + var annotation =(SingleMemberAnnotation) modifier; + String name = annotation.getTypeName().toString(); + String value = annotation.getValue().toString(); + + if(name.equals("PushReference")) { + annotationValue = value; + isPushToPull = true; + }else if(name.equals("PullReference")) { + annotationValue = value; + isPushToPull = false; } - return true; + + if(name.equals("Pullable")&&value.equals("\"direct\"")) { + isPossible = true; + } + } - }); - - + if(modifier instanceof MarkerAnnotation) { + var annotation =(SingleMemberAnnotation) modifier; + String name = annotation.getTypeName().toString(); + if(name.equals("Pushable")) { + isPossible = true; + } + } + } + + if(!isPossible)return null; + + + try { + if(isPushToPull) { + srcUnit = getCompilationUnitByEvent(event); + dstUnit = getAnotherCompilationUnit(event, annotationValue); + }else { + + srcUnit = getAnotherCompilationUnit(event, annotationValue); + dstUnit = getCompilationUnitByEvent(event); + } + } catch (JavaModelException e) { + e.printStackTrace(); + } + + + } catch (JavaModelException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } - if(!isPossible)return null; + PushPullRefactoringContribution contribution = (PushPullRefactoringContribution)RefactoringCore.getRefactoringContribution(PushPullRefactoring.ID); PushPullDescriptor descriptor = (PushPullDescriptor) contribution.createDescriptor(); @@ -269,7 +281,6 @@ SearchParticipant[] participants = { SearchEngine.getDefaultSearchParticipant() }; IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); - IJavaElement[] elementDst = new IJavaElement[1]; ICompilationUnit[] icus = new ICompilationUnit[1]; SearchRequestor requestor = new SearchRequestor() { @Override