1 /*******************************************************************************
2  * Copyright (c) 2000, 2014 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 package org.eclipse.jdt.internal.debug.ui.actions;
15 
16 import java.util.Iterator;
17 
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.core.runtime.Status;
21 import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants;
22 import org.eclipse.jdt.internal.debug.core.model.JDIInterfaceType;
23 import org.eclipse.jdt.internal.debug.core.model.JDIObjectValue;
24 import org.eclipse.jdt.internal.debug.core.model.JDIVariable;
25 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
26 import org.eclipse.jface.action.IAction;
27 import org.eclipse.jface.viewers.IStructuredSelection;
28 
29 /**
30  * Opens the concrete type hierarhcy of variable - i.e. it's value's actual type.
31  */
32 public class OpenVariableConcreteTypeHierarchyAction extends OpenVariableConcreteTypeAction {
33 
34 	/* (non-Javadoc)
35 	 * @see org.eclipse.jdt.internal.debug.ui.actions.OpenTypeAction#isHierarchy()
36 	 */
37 	@Override
isHierarchy()38 	protected boolean isHierarchy() {
39 		return true;
40 	}
41 
42 	@Override
run(IAction action)43 	public void run(IAction action) {
44 		IStructuredSelection selection = getCurrentSelection();
45 		if (selection == null) {
46 			return;
47 		}
48 		Iterator<?> itr = selection.iterator();
49 		try {
50 			while (itr.hasNext()) {
51 				Object element = itr.next();
52 				if (element instanceof JDIVariable && ((JDIVariable) element).getJavaType() instanceof JDIInterfaceType) {
53 					JDIObjectValue val = (JDIObjectValue) ((JDIVariable) element).getValue();
54 					if (val.getJavaType().toString().contains("$$Lambda$")) { //$NON-NLS-1$
55 						OpenVariableDeclaredTypeAction declaredAction = new OpenVariableDeclaredTypeHierarchyAction();
56 						declaredAction.setActivePart(action, getPart());
57 						declaredAction.run(action);
58 						return;
59 					}
60 				}
61 				Object sourceElement = resolveSourceElement(element);
62 				if (sourceElement != null) {
63 					openInEditor(sourceElement);
64 				} else {
65 					IStatus status = new Status(IStatus.INFO, IJavaDebugUIConstants.PLUGIN_ID, IJavaDebugUIConstants.INTERNAL_ERROR, "Source not found", null); //$NON-NLS-1$
66 					throw new CoreException(status);
67 				}
68 			}
69 		}
70 		catch (CoreException e) {
71 			JDIDebugUIPlugin.statusDialog(e.getStatus());
72 		}
73 	}
74 }
75