EclipseJDT ASTViewer Source Viewer

Home|eclipse_jdt_astviewer/src/org/eclipse/jdt/astview/views/DynamicAttributeProperty.java
1/*******************************************************************************
2 * Copyright (c) 2000, 2006 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 *******************************************************************************/
14
15package org.eclipse.jdt.astview.views;
16
17import org.eclipse.jdt.core.dom.IBinding;
18
19import org.eclipse.swt.graphics.Image;
20
21
22public abstract class DynamicAttributeProperty extends ExceptionAttribute {
23
24    protected static final String N_A"N/A"//$NON-NLS-1$
25    private final Object fParent;
26    private final String fName;
27
28    private Object fViewerElement;
29    private String fLabel"<unknown>";
30
31    public DynamicAttributeProperty(Object parentAttributeString name) {
32        fParentparentAttribute;
33        fNamename;
34    }
35
36    @Override
37    public Object getParent() {
38        return fParent;
39    }
40
41    @Override
42    public Object[] getChildren() {
43        return EMPTY;
44    }
45
46    public void setViewerElement(Object viewerAttribute) {
47        if (fViewerElement == viewerAttribute)
48            return;
49
50        fViewerElementviewerAttribute;
51        fExceptionnull;
52        Object trayObjectASTView.unwrapAttribute(fParent);
53        StringBuilder buf= new StringBuilder(fName);
54        if (viewerAttribute != null) {
55            Object viewerObjectASTView.unwrapAttribute(viewerAttribute);
56            try {
57                String queryResultexecuteQuery(viewerObjecttrayObject);
58                buf.append(queryResult);
59            } catch (RuntimeException e) {
60                fExceptione;
61                buf.append(e.getClass().getName());
62                buf.append(" for \""); //$NON-NLS-1$
63                if (viewerObject == null)
64                    buf.append("null"); //$NON-NLS-1$
65                else
66                    buf.append('"').append(objectToString(viewerObject));
67                buf.append("\" and "); //$NON-NLS-1$
68                buf.append(objectToString(trayObject)).append('"');
69            }
70        } else {
71            buf.append(N_A);
72        }
73        fLabelbuf.toString();
74    }
75
76    private String objectToString(Object object) {
77        if (object instanceof IBinding) {
78            return ((IBindingobject).getKey();
79        } else {
80            return String.valueOf(object);
81        }
82    }
83
84    /**
85     * Executes this dynamic attribute property's query in a protected environment.
86     * A {@link RuntimeException} thrown by this method is made available via
87     * {@link #getException()}.
88     *
89     * @param viewerObject the object of the element selected in the AST viewer, or <code>null</code> iff none
90     * @param trayObject the object of the element selected in the comparison tray, or <code>null</code> iff none
91     * @return this property's result
92     */
93    protected abstract String executeQuery(Object viewerObjectObject trayObject);
94
95    @Override
96    public String getLabel() {
97        return fLabel;
98    }
99
100    @Override
101    public Image getImage() {
102        return null;
103    }
104}
105
MembersX
DynamicAttributeProperty:getLabel
DynamicAttributeProperty:fViewerElement
DynamicAttributeProperty:fLabel
DynamicAttributeProperty:DynamicAttributeProperty
DynamicAttributeProperty:setViewerElement:Block:buf
DynamicAttributeProperty:getChildren
DynamicAttributeProperty:setViewerElement:Block:Block:Block:queryResult
DynamicAttributeProperty:setViewerElement:Block:Block:viewerObject
DynamicAttributeProperty:fParent
DynamicAttributeProperty:executeQuery
DynamicAttributeProperty:N_A
DynamicAttributeProperty:objectToString
DynamicAttributeProperty:getImage
DynamicAttributeProperty:fName
DynamicAttributeProperty:setViewerElement
DynamicAttributeProperty:getParent
DynamicAttributeProperty:setViewerElement:Block:trayObject
Members
X