KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > structure > ReferenceAnalyzer


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
31  * Updates references to moved static members.
32  * Accepts <code>CompilationUnit</code>s.
33  */

34 /* package */ 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     //---- Moved members are handled by the MovedMemberAnalyzer --------------
45

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         //see bug 42383: multiple VariableDeclarationFragments not supported:
64
VariableDeclarationFragment singleFragment= (VariableDeclarationFragment) node.fragments().get(0);
65         if (isMovedMember(singleFragment.resolveBinding()))
66             return false; // don't update javadoc of moved field here
67
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     //---- types and fields --------------------------
78

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 JavaDoc 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     //---- method invocations ----------------------------------
109

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     //---- javadoc references ----------------------------------
121

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