| 1 | /******************************************************************************* |
|---|---|
| 2 | * Copyright (c) 2000, 2005 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 | |
| 15 | package org.eclipse.jdt.astview.views; |
| 16 | |
| 17 | import org.eclipse.jdt.core.IJavaElement; |
| 18 | |
| 19 | import java.util.Objects; |
| 20 | |
| 21 | import org.eclipse.swt.graphics.Image; |
| 22 | |
| 23 | import org.eclipse.jdt.ui.JavaElementLabels; |
| 24 | |
| 25 | |
| 26 | |
| 27 | public class JavaElement extends ASTAttribute { |
| 28 | |
| 29 | private static final long LABEL_OPTIONS= |
| 30 | JavaElementLabels.F_APP_TYPE_SIGNATURE | JavaElementLabels.M_PARAMETER_TYPES | |
| 31 | JavaElementLabels.M_APP_RETURNTYPE | JavaElementLabels.ALL_FULLY_QUALIFIED | |
| 32 | JavaElementLabels.T_TYPE_PARAMETERS |JavaElementLabels.USE_RESOLVED; |
| 33 | |
| 34 | private final IJavaElement fJavaElement; |
| 35 | private final Object fParent; |
| 36 | |
| 37 | public JavaElement(Object parent, IJavaElement javaElement) { |
| 38 | fParent= parent; |
| 39 | fJavaElement= javaElement; |
| 40 | } |
| 41 | |
| 42 | public IJavaElement getJavaElement() { |
| 43 | return fJavaElement; |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public Object getParent() { |
| 48 | return fParent; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public Object[] getChildren() { |
| 53 | return EMPTY; |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public String getLabel() { |
| 58 | if (fJavaElement == null) { |
| 59 | return ">java element: null"; //$NON-NLS-1$ |
| 60 | } else { |
| 61 | String classname= fJavaElement.getClass().getName(); |
| 62 | return "> " + classname.substring(classname.lastIndexOf('.') + 1) + ": " //$NON-NLS-1$ //$NON-NLS-2$ |
| 63 | + JavaElementLabels.getElementLabel(fJavaElement, LABEL_OPTIONS) |
| 64 | + (fJavaElement.exists() ? "" : " (does not exist)"); //$NON-NLS-1$//$NON-NLS-2$ |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public Image getImage() { |
| 70 | return null; |
| 71 | //TODO: looks ugly when not all nodes have an icon |
| 72 | // return new JavaElementImageProvider().getImageLabel(fJavaElement, JavaElementImageProvider.SMALL_ICONS | JavaElementImageProvider.OVERLAY_ICONS); |
| 73 | } |
| 74 | |
| 75 | /* |
| 76 | * @see java.lang.Object#equals(java.lang.Object) |
| 77 | */ |
| 78 | @Override |
| 79 | public boolean equals(Object obj) { |
| 80 | if (this == obj) |
| 81 | return true; |
| 82 | if (obj == null || !obj.getClass().equals(getClass())) { |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | JavaElement other= (JavaElement) obj; |
| 87 | if (!Objects.equals(fParent, other.fParent)) { |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | if (!Objects.equals(fJavaElement, other.fJavaElement)) { |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | return true; |
| 96 | } |
| 97 | |
| 98 | /* |
| 99 | * @see java.lang.Object#hashCode() |
| 100 | */ |
| 101 | @Override |
| 102 | public int hashCode() { |
| 103 | return (fParent != null ? fParent.hashCode() : 0) + (fJavaElement != null ? fJavaElement.hashCode() : 0); |
| 104 | } |
| 105 | } |
| 106 |
Members