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 8806be6..1e82c00 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,6 +6,8 @@ import java.util.List; import java.util.Map; +import org.eclipse.core.runtime.IPath; +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; @@ -26,6 +28,7 @@ import org.eclipse.jdt.core.dom.TypeDeclaration; import org.eclipse.jdt.core.dom.VariableDeclaration; import org.eclipse.jdt.core.dom.VariableDeclarationStatement; +import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; import org.ntlab.refactoring.decouplingClasses.refactoringApplication.ContractedRefactoring; import org.ntlab.refactoring.decouplingClasses.refactoringApplication.HideDelegate; import org.ntlab.refactoring.decouplingClasses.refactoringApplication.IntroduceParameterObject; @@ -532,10 +535,36 @@ FieldDeclaration l = (FieldDeclaration) applicationPoint; TypeDeclaration parentType = (TypeDeclaration) l.getParent(); for (MethodDeclaration m: parentType.getMethods()) { + System.out.println(m); refactoring.dependsOn(findRefactorings(m, new Class[] {IntroduceParameterObject.class, PreserveWholeObject.class})); - for (MethodInvocation l2: m.getInvocations()) { - MethodDeclaration mDash = l2.getDeclaration(); - refactoring.dependsOn(findRefactorings(mDash, new Class[] {ReturnWholeObject.class, IntroduceReturnValueObject.class})); + + // �S�Ă�invocation���擾 + IMethodBinding methodBinding = m.resolveBinding(); + final IMethod iMethod = (IMethod) methodBinding.getJavaElement(); + IType tt = iMethod.getDeclaringType(); + final ArrayList invocations = new ArrayList<>(); + m.accept(new ASTVisitor() { + public boolean visit(MethodInvocation node) { + IMethodBinding methodBinding = node.resolveMethodBinding(); + IMethod calledObjectMethod = (IMethod) methodBinding.getJavaElement(); + ITypeBinding typeBind = methodBinding.getReturnType(); + IType type = (IType)typeBind.getJavaElement(); + IType ct = targetClass; + if (type != null && type.getElementName().equals(targetClass.getElementName()) + && type.getPackageFragment().equals(targetClass.getPackageFragment())) { + invocations.add(node); + System.out.println("invoke: " + node.toString()); + } + return super.visit(node); + } + }); + System.out.println(invocations); + for (MethodInvocation l2: invocations) { + IMethodBinding bind = l2.resolveMethodBinding(); + IJavaElement elem = bind.getMethodDeclaration().getJavaElement(); + System.out.println((IMethod)elem); +// MethodDeclaration mDash = l2.getDeclaration(); +// refactoring.dependsOn(findRefactorings(mDash, new Class[] {ReturnWholeObject.class, IntroduceReturnValueObject.class})); } } } @@ -544,10 +573,10 @@ MethodDeclaration ml = m(l); refactoring.dependsOn(findRefactorings(ml, new Class[] {IntroduceParameterObject.class, PreserveWholeObject.class})); - for (MethodInvocation l2: ml.getInvocations()) { - MethodDeclaration m = l2.getDeclaration(); - refactoring.dependsOn(findRefactorings(m, new Class[] {ReturnWholeObject.class, IntroduceReturnValueObject.class})); - } +// for (MethodInvocation l2: ml.getInvocations()) { +// MethodDeclaration m = l2.getDeclaration(); +// refactoring.dependsOn(findRefactorings(m, new Class[] {ReturnWholeObject.class, IntroduceReturnValueObject.class})); +// } } refactoring.dependsOn(findRefactorings(applicationPoint, new Class[] {IntroduceParameterObject.class, PreserveWholeObject.class})); } else if (refactoring.isInstanceOf(HideDelegate.class)) { @@ -571,25 +600,25 @@ refactoring.dependsOn(findRefactorings(type, new Class[] {ReplaceTypeByHiding.class})); // �Ăяo����̒�`�ɑ΂���߂�l�̌^�ύX�Ɉˑ�����B - for (MethodInvocation invocation: enclosing.getInvocations()) { - if (invocation.equals(applicationPoint)) { - continue; - } - MethodDeclaration declaration = invocation.getDeclaration(); - refactoring.dependsOn(findRefactorings(declaration, new Class[] { ReturnWholeObject.class, - IntroduceReturnValueObject.class})); - } +// for (MethodInvocation invocation: enclosing.getInvocations()) { +// if (invocation.equals(applicationPoint)) { +// continue; +// } +// MethodDeclaration declaration = invocation.getDeclaration(); +// refactoring.dependsOn(findRefactorings(declaration, new Class[] { ReturnWholeObject.class, +// IntroduceReturnValueObject.class})); +// } } else if (refactoring.isInstanceOf(ReturnWholeObject.class)) { // �e�Ăяo����̒�`�ɑ΂���߂�l�̌^�ύX�Ɉˑ�����B - ReturnValue returnStatement = (ReturnValue) refactoring.getApplicationPoint(); - MethodDeclaration enclosing = (MethodDeclaration) m(returnStatement); - refactoring.dependsOn(findRefactorings(enclosing, new Class[] {IntroduceParameterObject.class, PreserveWholeObject.class})); - TypeDeclaration type = (TypeDeclaration) enclosing.getParent(); - refactoring.dependsOn(findRefactorings(type, new Class[] {ReplaceTypeByHiding.class})); - for (MethodInvocation invocation: enclosing.getInvocations()) { - MethodDeclaration invokeeDeclaration = invocation.getDeclaration(); - refactoring.dependsOn(findRefactorings(invokeeDeclaration, new Class[] {IntroduceReturnValueObject.class, ReturnWholeObject.class})); - } +// ReturnValue returnStatement = (ReturnValue) refactoring.getApplicationPoint(); +// MethodDeclaration enclosing = (MethodDeclaration) m(returnStatement); +// refactoring.dependsOn(findRefactorings(enclosing, new Class[] {IntroduceParameterObject.class, PreserveWholeObject.class})); +// TypeDeclaration type = (TypeDeclaration) enclosing.getParent(); +// refactoring.dependsOn(findRefactorings(type, new Class[] {ReplaceTypeByHiding.class})); +// for (MethodInvocation invocation: enclosing.getInvocations()) { +// MethodDeclaration invokeeDeclaration = invocation.getDeclaration(); +// refactoring.dependsOn(findRefactorings(invokeeDeclaration, new Class[] {IntroduceReturnValueObject.class, ReturnWholeObject.class})); +// } } }