EclipseJDT ASTViewer Source Viewer

Home|eclipse_jdt_astviewer/src/org/eclipse/jdt/astview/views/NodeProperty.java
1/*******************************************************************************
2 * Copyright (c) 2000, 2015 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 *     IBM Corporation - initial API and implementation
13 *******************************************************************************/
14package org.eclipse.jdt.astview.views;
15
16import java.util.List;
17
18import org.eclipse.swt.graphics.Image;
19
20import org.eclipse.jdt.core.dom.ASTNode;
21import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
22
23public class NodeProperty extends ASTAttribute {
24
25    private ASTNode fParent;
26    private StructuralPropertyDescriptor fProperty;
27
28    public NodeProperty(ASTNode parentStructuralPropertyDescriptor property) {
29        fParentparent;
30        fPropertyproperty;
31    }
32
33    @Override
34    public Object getParent() {
35        return fParent;
36    }
37
38    @Override
39    public Object[] getChildren() {
40        Object childgetNode();
41        if (child instanceof List) {
42            return ((List<?>) child).toArray();
43        } else if (child instanceof ASTNode) {
44            return new Object[] { child };
45        }
46        return EMPTY;
47    }
48
49    @Override
50    public String getLabel() {
51        StringBuilder buf= new StringBuilder();
52        buf.append(getPropertyName());
53
54        if (fProperty.isSimpleProperty()) {
55            buf.append(": "); //$NON-NLS-1$
56            Object nodegetNode();
57            if (node != null) {
58                buf.append('\'');
59                buf.append(getNode().toString());
60                buf.append('\'');
61            } else {
62                buf.append("null"); //$NON-NLS-1$
63            }
64        } else if (fProperty.isChildListProperty()) {
65            List<?> node= (List<?>) getNode();
66            buf.append(" (").append(node.size()).append(')'); //$NON-NLS-1$
67        } else { // child property
68            if (getNode() == null) {
69                buf.append(": null"); //$NON-NLS-1$
70            }
71        }
72        return buf.toString();
73    }
74
75    @Override
76    public Image getImage() {
77        return null;
78    }
79
80    public Object getNode() {
81        return fParent.getStructuralProperty(fProperty);
82    }
83
84    public String getPropertyName() {
85        return toConstantName(fProperty.getId());
86    }
87
88    private static String toConstantName(String string) {
89        StringBuilder buf= new StringBuilder();
90        for (int i0i < string.length(); i++) {
91            char chstring.charAt(i);
92            if (i != 0 && Character.isUpperCase(ch)) {
93                buf.append('_');
94            }
95            buf.append(Character.toUpperCase(ch));
96        }
97        return buf.toString();
98    }
99
100    @Override
101    public boolean equals(Object o) {
102        if (this == o) {
103            return true;
104        }
105        if (o == null || !o.getClass().equals(getClass())) {
106            return false;
107        }
108        NodeProperty castedObj= (NodePropertyo;
109        return  fParent.equals(castedObj.fParent) && (fProperty == castedObj.fProperty);
110    }
111
112    @Override
113    public int hashCode() {
114        return fParent.hashCode() * 31 + fProperty.hashCode();
115    }
116
117    @Override
118    public String toString() {
119        return getLabel();
120
121    }
122}
123
MembersX
NodeProperty:getChildren
NodeProperty:getLabel:Block:buf
NodeProperty:getParent
NodeProperty:getPropertyName
NodeProperty:getNode
NodeProperty:toString
NodeProperty:getChildren:Block:child
NodeProperty:toConstantName
NodeProperty:fParent
NodeProperty:hashCode
NodeProperty:getImage
NodeProperty:toConstantName:Block:Block:ch
NodeProperty:fProperty
NodeProperty:NodeProperty
NodeProperty:equals
NodeProperty:getLabel:Block:Block:node
NodeProperty:toConstantName:Block:buf
NodeProperty:getLabel
NodeProperty:equals:Block:castedObj
Members
X