diff --git a/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java b/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java index c18a7fb..7c8855d 100644 --- a/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java +++ b/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java @@ -68,6 +68,7 @@ import org.eclipse.jdt.core.dom.VariableDeclarationFragment; import org.eclipse.jdt.core.dom.VariableDeclarationStatement; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; +import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; import org.eclipse.jdt.core.dom.rewrite.ListRewrite; import org.eclipse.jdt.core.search.IJavaSearchConstants; import org.eclipse.jdt.core.search.IJavaSearchScope; @@ -82,6 +83,7 @@ import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages; import org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange; import org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange; +import org.eclipse.jdt.ui.CodeStyleConfiguration; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; @@ -185,20 +187,33 @@ } }); ASTRewrite dstUnitRewrite = ASTRewrite.create(dstDec[0].getAST()); + //ASTRewrite dstUnitRewrite = ASTRewrite.create(dstUnit.getAST()); + String srcValue = annotationValueCase(descriptor.getSourceClassName()); String dstValue = annotationValueCase(descriptor.getDistinationClassName()); String pullrefCode = "@PullReference(\"" + srcValue + "\")" + System.getProperty("line.separator") + "@Pushable" + System.getProperty("line.separator") + "String " + srcValue + "= " + "\"/" + srcValue + "\";"; // @PullReference���t�^���ꂽ�t�B�[���h��lj� addStatement(dstUnitRewrite, dstUnit, dstDec[0], pullrefCode); - + + String importPullRef = "import pushPullRefactor.PullReference;" + System.getProperty("line.separator") + + "import pushPullRefactor.Pushable;" + System.getProperty("line.separator") + + System.getProperty("line.separator") ; + addStatement(dstUnitRewrite, dstUnit, dstDec[0],importPullRef,TypeDeclaration.MODIFIERS2_PROPERTY); + + if(!hasClient(dstUnit)) { + addStatement(dstUnitRewrite, dstUnit, dstDec[0],"import javax.ws.rs.client.*;" + System.getProperty("line.separator"),TypeDeclaration.MODIFIERS2_PROPERTY); + addStatement(dstUnitRewrite, dstUnit, dstDec[0], "private Client client = ClientBuilder.newClient();"+ System.getProperty("line.separator")); + } + // @State���t�^���ꂽ�t�B�[���h���폜 deleteASTNode(dstUnitRewrite, dstUnit, searchFieldDeclaration(descriptor.getDistinationClass(), "State")); // @Message���t�^���ꂽ���\�b�h���폜 +// deleteASTNode(dstUnitRewrite, dstUnit, +// searchMethodDeclaration(dstUnit, "Message", annotationValueCase(descriptor.getSourceClassName()))); deleteASTNode(dstUnitRewrite, dstUnit, searchMethodDeclaration(dstUnit, "Message", annotationValueCase(descriptor.getSourceClassName()))); - // @Getter���t�^���ꂽ���\�b�h�̕Ԃ�l�����̏�Ōv�Z����悤�ɕύX var srcState = searchFieldDeclaration(srcUnit, "State"); Type srcType = srcState.getType(); @@ -248,7 +263,7 @@ deleteASTNode(srcUnitRewrite, srcUnit, searchFieldDeclaration(descriptor.getSourceClass(), "PushReference", dstValue)); - System.out.println(); + System.out.println(dstUnitRewrite.toString()); try { applyRewrite(srcUnit, srcUnitRewrite, pm); applyRewrite(dstUnit, dstUnitRewrite, pm); @@ -259,7 +274,31 @@ } } + private void addImport(CompilationUnit cu, String importString, IProgressMonitor pm) throws Exception { + ImportRewrite importRewrite = CodeStyleConfiguration.createImportRewrite(cu, true); + AST ast = cu.getAST(); + Type rtype = ast.newSimpleType(ast.newName(importRewrite.addImport(importString))); + TextEdit importEdit = importRewrite.rewriteImports(null); + IPath path = cu.getJavaElement().getPath(); + ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager(); + bufferManager.connect(path, LocationKind.IFILE, pm); + ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(path, LocationKind.IFILE); + IDocument document = textFileBuffer.getDocument(); + importEdit.apply(document); + } + private boolean hasClient(ASTNode astNode) { + boolean[] result = {false} ; + astNode.accept(new ASTVisitor() { + public boolean visit(FieldDeclaration node) { + if(node.getType().toString().equals("Client")) { + result[0] = true; + } + return false; + } + }); + return result[0]; + } private void applyRewrite(CompilationUnit unit, ASTRewrite unitRewrite, IProgressMonitor pm) throws Exception { IPath path = unit.getJavaElement().getPath(); IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); @@ -544,6 +583,11 @@ + System.getProperty("line.separator") + "String " + dstValue + "= " + "\"/" + dstValue + "\";"; addStatement(srcUnitRewrite, srcUnit, srcDec[0], pushrefCode); + String importPushRef = "import pushPullRefactor.PushReference;" + System.getProperty("line.separator") + + "import pushPullRefactor.Pullable;" + System.getProperty("line.separator") + + System.getProperty("line.separator") ; + addStatement(srcUnitRewrite, srcUnit, srcDec[0],importPushRef,TypeDeclaration.MODIFIERS2_PROPERTY); + // Handling �N���X�� updateAvailable() ���\�b�h�� updateRequest() ���\�b�h�̍Ō�ɁCShipping �N���X�� // updateHandling() ���\�b�h���t�B�[���h value �������Ƃ��ēn���ČĂяo���s��lj�����D Type srcType = searchFieldDeclaration(srcUnit, "State").getType();