60e88ae08e93c90c9822e222c86e3e155fda4500
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / SourceField.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
12
13 import net.sourceforge.phpdt.core.IJavaElement;
14 import net.sourceforge.phpdt.internal.core.JavaElement;
15
16 import net.sourceforge.phpdt.core.IField;
17 import net.sourceforge.phpdt.core.IType;
18 import net.sourceforge.phpdt.core.JavaModelException;
19 import net.sourceforge.phpdt.core.Signature;
20 import net.sourceforge.phpdt.core.jdom.IDOMNode;
21
22 /**
23  * @see IField
24  */
25
26 /* package */ class SourceField extends Member implements IField {
27
28         /**
29          * Constructs a handle to the field with the given name in the specified type. 
30          */
31         protected SourceField(JavaElement parent, String name) {
32                 super(parent, name);
33         }
34         public boolean equals(Object o) {
35                 if (!(o instanceof SourceField)) return false;
36                 return super.equals(o);
37         }
38 /**
39  * @see JavaElement#equalsDOMNode
40  */
41 protected boolean equalsDOMNode(IDOMNode node) throws JavaModelException {
42         return (node.getNodeType() == IDOMNode.FIELD) && super.equalsDOMNode(node);
43 }
44 /**
45  * @see IField
46  */
47 public Object getConstant() throws JavaModelException {
48         SourceFieldElementInfo info = (SourceFieldElementInfo) getElementInfo();
49         return info.initializationSource;
50 }
51 /**
52  * @see IJavaElement
53  */
54 public int getElementType() {
55         return FIELD;
56 }
57 /**
58  * @see JavaElement#getHandleMemento()
59  */
60 protected char getHandleMementoDelimiter() {
61         return JavaElement.JEM_FIELD;
62 }
63 /**
64  * @see IField
65  */
66 public String getTypeSignature() throws JavaModelException {
67         SourceFieldElementInfo info = (SourceFieldElementInfo) getElementInfo();
68         return info.getTypeSignature();
69 }
70 /**
71  * @private Debugging purposes
72  */
73 protected void toStringInfo(int tab, StringBuffer buffer, Object info) {
74         buffer.append(this.tabString(tab));
75         if (info == null) {
76                 buffer.append(getElementName());
77                 buffer.append(" (not open)"); //$NON-NLS-1$
78         } else if (info == NO_INFO) {
79                 buffer.append(getElementName());
80         } else {
81                 try {
82                         buffer.append(Signature.toString(this.getTypeSignature()));
83                         buffer.append(" "); //$NON-NLS-1$
84                         buffer.append(this.getElementName());
85                 } catch (JavaModelException e) {
86                         buffer.append("<JavaModelException in toString of " + getElementName()); //$NON-NLS-1$
87                 }
88         }
89 }
90 }