KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > BinaryMember


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.core;
12
13 import java.util.HashMap JavaDoc;
14
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.jdt.core.IJavaElement;
17 import org.eclipse.jdt.core.IJavaModelStatusConstants;
18 import org.eclipse.jdt.core.ISourceRange;
19 import org.eclipse.jdt.core.JavaModelException;
20 import org.eclipse.jdt.core.compiler.CharOperation;
21
22 /**
23  * Common functionality for Binary member handles.
24  */

25 public abstract class BinaryMember extends NamedMember {
26 /*
27  * Constructs a binary member.
28  */

29 protected BinaryMember(JavaElement parent, String JavaDoc name) {
30     super(parent, name);
31 }
32 /*
33  * @see ISourceManipulation
34  */

35 public void copy(IJavaElement container, IJavaElement sibling, String JavaDoc rename, boolean force, IProgressMonitor monitor) throws JavaModelException {
36     throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.READ_ONLY, this));
37 }
38 /*
39  * @see JavaElement#generateInfos
40  */

41 protected void generateInfos(Object JavaDoc info, HashMap JavaDoc newElements, IProgressMonitor pm) throws JavaModelException {
42     Openable openableParent = (Openable) getOpenableParent();
43     if (JavaModelManager.getJavaModelManager().getInfo(openableParent) == null) {
44         openableParent.generateInfos(openableParent.createElementInfo(), newElements, pm);
45     }
46 }
47 public String JavaDoc[] getCategories() throws JavaModelException {
48     SourceMapper mapper= getSourceMapper();
49     if (mapper != null) {
50         // ensure the class file's buffer is open so that categories are computed
51
((ClassFile)getClassFile()).getBuffer();
52         
53         if (mapper.categories != null) {
54             String JavaDoc[] categories = (String JavaDoc[]) mapper.categories.get(this);
55             if (categories != null)
56                 return categories;
57         }
58     }
59     return CharOperation.NO_STRINGS;
60 }
61 public String JavaDoc getKey() {
62     try {
63         return getKey(false/*don't open*/);
64     } catch (JavaModelException e) {
65         // happen only if force open is true
66
return null;
67     }
68 }
69 /**
70  * @see org.eclipse.jdt.internal.compiler.lookup.Binding#computeUniqueKey()
71  */

72 public abstract String JavaDoc getKey(boolean forceOpen) throws JavaModelException;
73 /*
74  * @see ISourceReference
75  */

76 public ISourceRange getNameRange() throws JavaModelException {
77     SourceMapper mapper= getSourceMapper();
78     if (mapper != null) {
79         // ensure the class file's buffer is open so that source ranges are computed
80
((ClassFile)getClassFile()).getBuffer();
81         
82         return mapper.getNameRange(this);
83     } else {
84         return SourceMapper.UNKNOWN_RANGE;
85     }
86 }
87 /*
88  * @see ISourceReference
89  */

90 public ISourceRange getSourceRange() throws JavaModelException {
91     SourceMapper mapper= getSourceMapper();
92     if (mapper != null) {
93         // ensure the class file's buffer is open so that source ranges are computed
94
((ClassFile)getClassFile()).getBuffer();
95
96         return mapper.getSourceRange(this);
97     } else {
98         return SourceMapper.UNKNOWN_RANGE;
99     }
100 }
101 /*
102  * @see IMember
103  */

104 public boolean isBinary() {
105     return true;
106 }
107 /*
108  * @see IJavaElement
109  */

110 public boolean isStructureKnown() throws JavaModelException {
111     return ((IJavaElement)getOpenableParent()).isStructureKnown();
112 }
113 /*
114  * @see ISourceManipulation
115  */

116 public void move(IJavaElement container, IJavaElement sibling, String JavaDoc rename, boolean force, IProgressMonitor monitor) throws JavaModelException {
117     throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.READ_ONLY, this));
118 }
119 /*
120  * @see ISourceManipulation
121  */

122 public void rename(String JavaDoc newName, boolean force, IProgressMonitor monitor) throws JavaModelException {
123     throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.READ_ONLY, this));
124 }
125 /*
126  * Sets the contents of this element.
127  * Throws an exception as this element is read only.
128  */

129 public void setContents(String JavaDoc contents, IProgressMonitor monitor) throws JavaModelException {
130     throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.READ_ONLY, this));
131 }
132 }
133
Popular Tags