diff --git a/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/DecoupleClassesRefactoringProcessor.java b/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/DecoupleClassesRefactoringProcessor.java index 8c3060b..bfdcb42 100644 --- a/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/DecoupleClassesRefactoringProcessor.java +++ b/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/DecoupleClassesRefactoringProcessor.java @@ -227,9 +227,14 @@ workingCopy.discardWorkingCopy(); + // TODO: �SCfrom�ɂ����Ő��������N���X��import����lj� + // add refactor for(Node refactor : refactoringTasks) { - change.add((RefactoringApplication)refactor); + RefactoringApplication app = (RefactoringApplication)refactor; + app.setWrapperClass(typeDeclaration); + app.setTargetClass(descriptor.getTargetType()); + change.add(app); } return change; diff --git a/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/RefactoringTaskGenerator.java b/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/RefactoringTaskGenerator.java index 1ef9333..7a176d8 100644 --- a/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/RefactoringTaskGenerator.java +++ b/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/RefactoringTaskGenerator.java @@ -6,7 +6,6 @@ import java.util.List; import java.util.Map; -import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.dom.AST; @@ -19,14 +18,12 @@ import org.eclipse.jdt.core.dom.IBinding; import org.eclipse.jdt.core.dom.IMethodBinding; import org.eclipse.jdt.core.dom.ITypeBinding; -import org.eclipse.jdt.core.dom.IVariableBinding; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.MethodInvocation; import org.eclipse.jdt.core.dom.Name; import org.eclipse.jdt.core.dom.ReturnStatement; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; import org.eclipse.jdt.core.dom.TypeDeclaration; -import org.eclipse.jdt.core.dom.VariableDeclarationFragment; import org.eclipse.jdt.core.dom.VariableDeclarationStatement; import org.ntlab.refactoring.decouplingClasses.refactoringApplication.ContractedRefactoring; import org.ntlab.refactoring.decouplingClasses.refactoringApplication.HideDelegate; diff --git a/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/refactoringApplication/IntroduceReturnValueObject.java b/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/refactoringApplication/IntroduceReturnValueObject.java index 2c25790..86feff8 100644 --- a/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/refactoringApplication/IntroduceReturnValueObject.java +++ b/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/refactoringApplication/IntroduceReturnValueObject.java @@ -14,10 +14,13 @@ import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.ClassInstanceCreation; import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.ConstructorInvocation; import org.eclipse.jdt.core.dom.IMethodBinding; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.MethodInvocation; +import org.eclipse.jdt.core.dom.ReturnStatement; import org.eclipse.jdt.core.dom.Type; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; import org.eclipse.jface.text.BadLocationException; @@ -51,6 +54,7 @@ return null; } + // TODO: refactoring @Override public Change perform(IProgressMonitor pm) throws CoreException { System.out.println("perform: " + getName()); @@ -60,8 +64,9 @@ IPath path = cu.getJavaElement().getPath(); ASTRewrite rewrite = ASTRewrite.create(cu.getAST()); ASTNode node = getNode(); + ReturnStatement returnNode = (ReturnStatement)node; AST ast = methodDecl.getAST(); - Type t = ast.newSimpleType(ast.newSimpleName("CNew")); + Type t = ast.newSimpleType(ast.newSimpleName(wrapperClass.getName().toString())); rewrite.set(methodDecl, MethodDeclaration.RETURN_TYPE2_PROPERTY, t, null); IMethodBinding methodBinding = methodDecl.resolveBinding(); @@ -73,7 +78,11 @@ // return����Cnew(ctarget)�ƂȂ�悤rewrite��K�p // �����Ɏ��� - + AST newAST = AST.newAST(AST.JLS8); + ClassInstanceCreation newClassInstanceInvocation = newAST.newClassInstanceCreation(); + newClassInstanceInvocation.setType(newAST.newSimpleType(newAST.newSimpleName(wrapperClass.getName().toString()))); + newClassInstanceInvocation.arguments().add(newAST.newSimpleName(returnNode.getExpression().toString())); + rewrite.replace(returnNode.getExpression(), newClassInstanceInvocation, null); try { ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager(); @@ -93,7 +102,40 @@ // TODO Auto-generated catch block e.printStackTrace(); } - + + // CompilationUnit���Ƃ�getCTarget�̕t�^�����Ă��� + for(CompilationUnit cu : clients.keySet()) { + IPath cupath = cu.getJavaElement().getPath(); + ArrayList nodes = clients.get(cu); + ASTRewrite rewrite2 = ASTRewrite.create(cu.getAST()); + for(MethodInvocation invocation : nodes) { + MethodInvocation copiedNode = (MethodInvocation) ASTNode.copySubtree(invocation.getAST(), invocation); + AST ast2 = copiedNode.getAST(); + // getCTarget�̕t�^ + MethodInvocation newInvocation = ast2.newMethodInvocation(); + newInvocation.setExpression(copiedNode); + newInvocation.setName(ast2.newSimpleName("get" + targetClass.getElementName().toString())); + rewrite2.replace(invocation, newInvocation, null); + } + try { + ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager(); + bufferManager.connect(cupath, null); + ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(cupath); + IDocument document = textFileBuffer.getDocument(); + TextEdit edit = rewrite2.rewriteAST(document, null); + edit.apply(document); + textFileBuffer.commit(null /* ProgressMonitor */, true /* Overwrite */); + } catch (MalformedTreeException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (BadLocationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } return null; } diff --git a/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/refactoringApplication/RefactoringApplication.java b/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/refactoringApplication/RefactoringApplication.java index 06ab324..9a18dd5 100644 --- a/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/refactoringApplication/RefactoringApplication.java +++ b/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/refactoringApplication/RefactoringApplication.java @@ -1,6 +1,8 @@ package org.ntlab.refactoring.decouplingClasses.refactoringApplication; +import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.TypeDeclaration; import org.eclipse.ltk.core.refactoring.Change; import test.pseudocode.core.Node; @@ -9,6 +11,8 @@ protected String name = ""; private boolean visited = false; private RefactoringApplication parent = null; + protected TypeDeclaration wrapperClass = null; + protected IType targetClass = null; public RefactoringApplication(String name) { this.name = name; @@ -45,4 +49,12 @@ public void setParent(RefactoringApplication parent) { this.parent = parent; } + + public void setWrapperClass(TypeDeclaration type) { + wrapperClass = type; + } + + public void setTargetClass(IType type) { + targetClass = type; + } } diff --git a/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/refactoringApplication/ReturnWholeObject.java b/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/refactoringApplication/ReturnWholeObject.java index f0c1363..b98bf08 100644 --- a/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/refactoringApplication/ReturnWholeObject.java +++ b/org.ntlab.refactoring.decouplingClasses/src/org/ntlab/refactoring/decouplingClasses/refactoringApplication/ReturnWholeObject.java @@ -69,7 +69,8 @@ // TODO Auto-generated method stub return new RefactoringStatus(); } - + + // TODO: refactoring @Override public Change perform(IProgressMonitor pm) throws CoreException { // DOTO: �ق����t�@�N�^�����O�̎����p�Ɉꎞ�I�ɓ�����~�߂邽�߂̃R�����g�̉��� @@ -85,7 +86,7 @@ // ASTNode node = getNode(); // AST ast = methodDecl.getAST(); // -// Type t = ast.newSimpleType(ast.newSimpleName("CNew")); +// Type t = ast.newSimpleType(ast.newSimpleName(wrapperClass.getName().toString())); // rewrite.set(methodDecl, MethodDeclaration.RETURN_TYPE2_PROPERTY, t, null); // // IMethodBinding methodBinding = methodDecl.resolveBinding();