1 11 package org.eclipse.jdt.internal.corext.refactoring.structure; 12 13 import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration; 14 import org.eclipse.jdt.core.dom.EnumDeclaration; 15 import org.eclipse.jdt.core.dom.FieldAccess; 16 import org.eclipse.jdt.core.dom.FieldDeclaration; 17 import org.eclipse.jdt.core.dom.IBinding; 18 import org.eclipse.jdt.core.dom.IMethodBinding; 19 import org.eclipse.jdt.core.dom.ITypeBinding; 20 import org.eclipse.jdt.core.dom.ImportDeclaration; 21 import org.eclipse.jdt.core.dom.MemberRef; 22 import org.eclipse.jdt.core.dom.MethodDeclaration; 23 import org.eclipse.jdt.core.dom.MethodInvocation; 24 import org.eclipse.jdt.core.dom.MethodRef; 25 import org.eclipse.jdt.core.dom.QualifiedName; 26 import org.eclipse.jdt.core.dom.SimpleName; 27 import org.eclipse.jdt.core.dom.TypeDeclaration; 28 import org.eclipse.jdt.core.dom.VariableDeclarationFragment; 29 30 34 class ReferenceAnalyzer extends MoveStaticMemberAnalyzer { 35 36 public ReferenceAnalyzer(CompilationUnitRewrite cuRewrite, IBinding[] members, ITypeBinding target, ITypeBinding source) { 37 super(cuRewrite, members, source, target); 38 } 39 40 public boolean needsTargetImport() { 41 return fNeedsImport; 42 } 43 44 46 public boolean visit(TypeDeclaration node) { 47 ITypeBinding binding= node.resolveBinding(); 48 if (binding != null) { 49 binding= binding.getTypeDeclaration(); 50 if (isMovedMember(binding)) 51 return false; 52 } 53 return super.visit(node); 54 } 55 56 public boolean visit(VariableDeclarationFragment node) { 57 if (isMovedMember(node.resolveBinding())) 58 return false; 59 return super.visit(node); 60 } 61 62 public boolean visit(FieldDeclaration node) { 63 VariableDeclarationFragment singleFragment= (VariableDeclarationFragment) node.fragments().get(0); 65 if (isMovedMember(singleFragment.resolveBinding())) 66 return false; return super.visit(node); 68 } 69 70 public boolean visit(MethodDeclaration node) { 71 if (isMovedMember(node.resolveBinding())) 72 return false; 73 return super.visit(node); 74 } 75 76 77 79 public boolean visit(SimpleName node) { 80 if (! node.isDeclaration() && isMovedMember(node.resolveBinding()) && ! isProcessed(node)) 81 rewrite(node, fTarget); 82 return false; 83 } 84 85 public boolean visit(QualifiedName node) { 86 if (isMovedMember(node.resolveBinding())) { 87 if (node.getParent() instanceof ImportDeclaration) { 88 ITypeBinding typeBinding= node.resolveTypeBinding(); 89 if (typeBinding != null) 90 fCuRewrite.getImportRewrite().removeImport(typeBinding.getQualifiedName()); 91 String imp= fCuRewrite.getImportRewrite().addImport(fTarget.getQualifiedName() + '.' + node.getName().getIdentifier()); 92 fCuRewrite.getImportRemover().registerAddedImport(imp); 93 } else { 94 rewrite(node, fTarget); 95 } 96 return false; 97 } else { 98 return super.visit(node); 99 } 100 } 101 102 public boolean visit(FieldAccess node) { 103 if (isMovedMember(node.resolveFieldBinding())) 104 rewrite(node, fTarget); 105 return super.visit(node); 106 } 107 108 110 public boolean visit(MethodInvocation node) { 111 IMethodBinding binding= node.resolveMethodBinding(); 112 if (binding != null) { 113 binding= binding.getMethodDeclaration(); 114 if (isMovedMember(binding)) 115 rewrite(node, fTarget); 116 } 117 return super.visit(node); 118 } 119 120 122 public boolean visit(MemberRef node) { 123 if (isMovedMember(node.resolveBinding())) 124 rewrite(node, fTarget); 125 return false; 126 } 127 128 public boolean visit(MethodRef node) { 129 if (isMovedMember(node.resolveBinding())) 130 rewrite(node, fTarget); 131 return false; 132 } 133 134 public boolean visit(AnnotationTypeDeclaration node) { 135 if (isMovedMember(node.resolveBinding())) 136 return false; 137 return super.visit(node); 138 } 139 140 public boolean visit(EnumDeclaration node) { 141 if (isMovedMember(node.resolveBinding())) 142 return false; 143 return super.visit(node); 144 } 145 } 146 | Popular Tags |