~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRefactoringArgument.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
 * Copyright (c) 2004, 2008 Wind River Systems, Inc. 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
 
 *    Markus Schorn - initial API and implementation 
10
 
 ******************************************************************************/ 
11
 
package org.eclipse.cdt.internal.ui.refactoring.rename;
12
 
 
13
 
import org.eclipse.core.resources.IFile;
14
 
 
15
 
import org.eclipse.cdt.core.dom.ast.DOMException;
16
 
import org.eclipse.cdt.core.dom.ast.IASTName;
17
 
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
18
 
import org.eclipse.cdt.core.dom.ast.IBinding;
19
 
import org.eclipse.cdt.core.dom.ast.ICompositeType;
20
 
import org.eclipse.cdt.core.dom.ast.IEnumeration;
21
 
import org.eclipse.cdt.core.dom.ast.IEnumerator;
22
 
import org.eclipse.cdt.core.dom.ast.IField;
23
 
import org.eclipse.cdt.core.dom.ast.IFunction;
24
 
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
25
 
import org.eclipse.cdt.core.dom.ast.IParameter;
26
 
import org.eclipse.cdt.core.dom.ast.IScope;
27
 
import org.eclipse.cdt.core.dom.ast.ITypedef;
28
 
import org.eclipse.cdt.core.dom.ast.IVariable;
29
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
30
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
31
 
import org.eclipse.cdt.core.model.CModelException;
32
 
import org.eclipse.cdt.core.model.ICElement;
33
 
import org.eclipse.cdt.core.model.ISourceRange;
34
 
import org.eclipse.cdt.core.model.ISourceReference;
35
 
import org.eclipse.cdt.ui.CUIPlugin;
36
 
 
37
 
 
38
 
/**
39
 
 * Represents the input to a refactoring. Important is file and offset the rest
40
 
 * can be calculated from the AST.
41
 
 */
42
 
public class CRefactoringArgument {
43
 
    private int fOffset=0;
44
 
    private int fLength= 0;
45
 
    private String fText= ""; //$NON-NLS-1$
46
 
    private int fKind= CRefactory.ARGUMENT_UNKNOWN;
47
 
    private IFile fFile;
48
 
    
49
 
    private IBinding fBinding;
50
 
    private IScope fScope;
51
 
    private IASTTranslationUnit fTranslationUnit;
52
 
 
53
 
    public CRefactoringArgument(IFile file, int offset, int length) {
54
 
        fKind= CRefactory.ARGUMENT_UNKNOWN;
55
 
        fFile= file;
56
 
        fOffset= offset;
57
 
        fLength= length;
58
 
    }
59
 
    
60
 
    public CRefactoringArgument(ICElement elem) {
61
 
        fKind= CRefactory.ARGUMENT_UNKNOWN;
62
 
        if (elem instanceof ISourceReference) {
63
 
                ISourceReference sref= (ISourceReference) elem;
64
 
                ISourceRange sr;
65
 
                        try {
66
 
                                sr = sref.getSourceRange();
67
 
                        fFile= (IFile) sref.getTranslationUnit().getResource();
68
 
                        fOffset= sr.getIdStartPos();
69
 
                        fLength= sr.getIdLength();
70
 
                        } catch (CModelException e) {
71
 
                                CUIPlugin.log(e);
72
 
                        }
73
 
        }
74
 
    }
75
 
        
76
 
    // overrider
77
 
    public String getName() {
78
 
        return fText;
79
 
    }
80
 
 
81
 
    // overrider
82
 
    public IFile getSourceFile() {
83
 
        return fFile;
84
 
    }
85
 
 
86
 
    // overrider
87
 
    public int getArgumentKind() {
88
 
        return fKind;
89
 
    }
90
 
 
91
 
    // overrider
92
 
    public int getOffset() {
93
 
        return fOffset;
94
 
    }
95
 
    
96
 
    public int getLength() {
97
 
        return fLength;
98
 
    }
99
 
 
100
 
    public void setName(IASTName name) {
101
 
        fText= name.toString();
102
 
    }
103
 
    
104
 
    public void setBinding(IASTTranslationUnit tu, IBinding binding, IScope scope) {
105
 
        fTranslationUnit= tu;
106
 
        fBinding= binding;
107
 
        fScope= scope;
108
 
        if (binding instanceof IVariable) {
109
 
            IVariable var= (IVariable) binding;
110
 
            if (binding instanceof IField) {
111
 
                fKind= CRefactory.ARGUMENT_FIELD;
112
 
            }
113
 
            else if (binding instanceof IParameter) {
114
 
                fKind= CRefactory.ARGUMENT_PARAMETER;
115
 
            }
116
 
            else {
117
 
                if (ASTManager.isLocalVariable(var, scope)) {
118
 
                    fKind= CRefactory.ARGUMENT_LOCAL_VAR;
119
 
                }
120
 
                else {
121
 
                    boolean isStatic= false;
122
 
                    try {
123
 
                        isStatic= var.isStatic();
124
 
                    } catch (DOMException e) {
125
 
                    }
126
 
                    if (isStatic) {
127
 
                        fKind= CRefactory.ARGUMENT_FILE_LOCAL_VAR;
128
 
                    }
129
 
                    else {
130
 
                        fKind= CRefactory.ARGUMENT_GLOBAL_VAR;
131
 
                    }
132
 
                }
133
 
            }
134
 
        }
135
 
        else if (binding instanceof IEnumerator) {
136
 
            fKind= CRefactory.ARGUMENT_ENUMERATOR;
137
 
        }
138
 
        else if (binding instanceof IFunction) {
139
 
            fKind= CRefactory.ARGUMENT_NON_VIRTUAL_METHOD;
140
 
            IFunction func= (IFunction) binding;
141
 
            if (binding instanceof ICPPMethod) {
142
 
                ICPPMethod method= (ICPPMethod) binding;
143
 
                int isVirtual= ASTManager.UNKNOWN;
144
 
                try {
145
 
                    isVirtual = ASTManager.isVirtualMethod(method);
146
 
                } catch (DOMException e) {
147
 
                }
148
 
                if (isVirtual == ASTManager.TRUE) {
149
 
                    fKind= CRefactory.ARGUMENT_VIRTUAL_METHOD;
150
 
                }
151
 
            }
152
 
            else {
153
 
                boolean isStatic= false;
154
 
                try {
155
 
                    isStatic= func.isStatic();
156
 
                } catch (DOMException e) {
157
 
                }
158
 
                if (isStatic) {
159
 
                    fKind= CRefactory.ARGUMENT_FILE_LOCAL_FUNCTION;
160
 
                }
161
 
                else {
162
 
                    fKind= CRefactory.ARGUMENT_GLOBAL_FUNCTION;
163
 
                }
164
 
            }
165
 
        }
166
 
        else if (binding instanceof ICompositeType) {
167
 
            fKind= CRefactory.ARGUMENT_CLASS_TYPE;
168
 
        }
169
 
        else if (binding instanceof IEnumeration || binding instanceof ITypedef) {
170
 
            fKind= CRefactory.ARGUMENT_TYPE;
171
 
        }
172
 
        else if (binding instanceof ICPPNamespace) {
173
 
            fKind= CRefactory.ARGUMENT_NAMESPACE;
174
 
        }
175
 
        else if (binding instanceof IMacroBinding) {
176
 
            fKind= CRefactory.ARGUMENT_MACRO;
177
 
        }
178
 
    }
179
 
 
180
 
    public IScope getScope() {
181
 
        return fScope;
182
 
    }
183
 
 
184
 
    public IBinding getBinding() {
185
 
        return fBinding;
186
 
    }
187
 
 
188
 
    public IASTTranslationUnit getTranslationUnit() {
189
 
        return fTranslationUnit;
190
 
    }
191
 
}