KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > code > ParameterData


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.code;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.jdt.core.dom.ASTNode;
17 import org.eclipse.jdt.core.dom.ITypeBinding;
18 import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
19
20 import org.eclipse.jdt.internal.corext.refactoring.code.flow.FlowInfo;
21
22 /* package */ class ParameterData {
23
24     public static final String JavaDoc PROPERTY= ParameterData.class.getName();
25
26     private SingleVariableDeclaration fDeclaration;
27     private int fAccessMode;
28     private List JavaDoc fReferences;
29     private int fOperatorPrecedence;
30
31     public ParameterData(SingleVariableDeclaration decl) {
32         super();
33         fDeclaration= decl;
34         fAccessMode= FlowInfo.UNUSED;
35         fReferences= new ArrayList JavaDoc(2);
36         fOperatorPrecedence= -1;
37     }
38
39     public String JavaDoc getName() {
40         return fDeclaration.getName().getIdentifier();
41     }
42     
43     public ITypeBinding getTypeBinding() {
44         return fDeclaration.resolveBinding().getType();
45     }
46     
47     public void addReference(ASTNode node) {
48         fReferences.add(node);
49     }
50     
51     public List JavaDoc references() {
52         return fReferences;
53     }
54     
55     public void setAccessMode(int mode) {
56         fAccessMode= mode;
57     }
58     
59     public boolean isUnused() {
60         return fAccessMode == FlowInfo.UNUSED;
61     }
62     
63     public boolean isReadOnly() {
64         return (fAccessMode & (FlowInfo.READ | FlowInfo.READ_POTENTIAL)) != 0;
65     }
66     
67     public boolean isWrite() {
68         return (fAccessMode & (FlowInfo.WRITE | FlowInfo.WRITE_POTENTIAL | FlowInfo.UNKNOWN)) != 0;
69     }
70     
71     public int getSimplifiedAccessMode() {
72         if (isWrite())
73             return FlowInfo.WRITE;
74         if (isReadOnly())
75             return FlowInfo.READ;
76         return FlowInfo.UNUSED;
77     }
78     
79     public int getNumberOfAccesses() {
80         return fReferences.size();
81     }
82     
83     public boolean needsEvaluation() {
84         if (fReferences.size() <= 1)
85             return false;
86         return true;
87     }
88
89     public void setOperatorPrecedence(ASTNode node, int precedence) {
90         setOperatorPrecedence(precedence);
91     }
92     
93     private void setOperatorPrecedence(int newValue) {
94         if (newValue == -1) {
95             fOperatorPrecedence= newValue;
96         } else if (fOperatorPrecedence == -1) {
97             fOperatorPrecedence= newValue;
98         } else {
99             fOperatorPrecedence= Math.min(fOperatorPrecedence, newValue);
100         }
101     }
102
103     public int getOperatorPrecedence() {
104         return fOperatorPrecedence;
105     }
106 }
107
Popular Tags