1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 536255 - Extension point for open call hierarchy view

Adding a new extension point that makes possible to extend content from
the Open Call Hierarchy View by adding a new node at the top of the
tree.

Change-Id: I9ac79896a4e8fffc9ed51cdb1be3c70f30d117c4
Signed-off-by: Lidia Popescu <lidia.popescu@windriver.com>
This commit is contained in:
Lidia Popescu 2018-06-28 20:49:56 +03:00 committed by Jonah Graham
parent 8a73297c10
commit 0cf1ee7fde
16 changed files with 827 additions and 47 deletions

View file

@ -283,4 +283,15 @@
</menuContribution>
</extension>
<extension
point="org.eclipse.cdt.ui.CCallHierarchy">
<CallHierarchyLabelProvider
class="org.eclipse.cdt.ui.tests.callhierarchy.extension.CHLabelProvider"
id="org.eclipse.cdt.ui.tests.callhierarchy.extension.CHLabelProvider">
</CallHierarchyLabelProvider>
<CallHierarchyContentProvider
class="org.eclipse.cdt.ui.tests.callhierarchy.extension.CHContentProvider"
id="org.eclipse.cdt.ui.tests.callhierarchy.extension.CHContentProvider">
</CallHierarchyContentProvider>
</extension>
</plugin>

View file

@ -25,6 +25,7 @@ import org.junit.runners.Suite;
org.eclipse.cdt.ui.tests.outline.OutlineTestSuite.class,
org.eclipse.cdt.ui.tests.viewsupport.ViewSupportTestSuite.class,
org.eclipse.cdt.ui.tests.callhierarchy.CallHierarchyTestSuite.class,
org.eclipse.cdt.ui.tests.callhierarchy.extension.CHExtensionTest.class,
org.eclipse.cdt.ui.tests.typehierarchy.TypeHierarchyTestSuite.class,
org.eclipse.cdt.ui.tests.includebrowser.IncludeBrowserTestSuite.class,
org.eclipse.cdt.ui.tests.text.contentassist.ContentAssistTestSuite.class,

View file

@ -0,0 +1,61 @@
/*******************************************************************************
* Copyright (c) 2018 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Lidia Popescu - [536255] initial API and implementation. Extension point for open call hierarchy view
*******************************************************************************/
package org.eclipse.cdt.ui.tests.callhierarchy.extension;
import org.eclipse.jface.viewers.IOpenListener;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.ui.ICHEContentProvider;
import org.eclipse.cdt.internal.core.model.ext.FunctionDeclarationHandle;
/**
* This class implements ICHEProvider and provides test information
* */
public class CHContentProvider implements ICHEContentProvider {
@Override
public Object[] asyncComputeExtendedRoot(Object parentElement) {
Object[] object =null;
if (parentElement instanceof ICElement) {
ICElement element = (ICElement)parentElement;
if ( isDslFunction(element)) {
// check if this function declaration comes from a DSL file
DslNode node = new DslNode(element);
node.setProject(element.getCProject());
return new Object[]{node};
}
}
return object;
}
@Override
public IOpenListener getCCallHierarchyOpenListener() {
return new CHOpenListener();
}
/**
* E.g. A custom implementation, suppose that functions that ends with
* "_dsl" have been originally declared in a DSL file.
* @param cElement
* @return
*/
private static boolean isDslFunction(ICElement cElement) {
if (cElement instanceof FunctionDeclarationHandle) {
FunctionDeclarationHandle f = (FunctionDeclarationHandle)cElement;
if (f.getElementName() !=null & f.getElementName().endsWith("_dsl")) {
return true;
}
}
return false;
}
}

View file

@ -0,0 +1,106 @@
/*******************************************************************************
* Copyright (c) 2018 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Lidia Popescu - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.callhierarchy.extension;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.tests.callhierarchy.CallHierarchyBaseTest;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import junit.framework.TestSuite;
/**
* @author Lidia Popescu
*
*/
public class CHExtensionTest extends CallHierarchyBaseTest {
private static final String FILE_NAME_MAIN_C = "CallHierarchy_main.c";
private static final String FILE_NAME_DSL = "CallHierarchy_test.java";
private static final String FILE_NAME_C = "CallHierarchy_test.c";
public CHExtensionTest(String name) {
super(name);
}
public static TestSuite suite() {
return new TestSuite(CHExtensionTest.class);
}
// {CallHierarchy_main.c}
// extern void function_c(void);
// extern void function_dsl(void);
//
// void main(void)
// {
// function_c();
// function_dsl();
// }
// {CallHierarchy_test.c}
// void function_c(void)
// {
// printf("Hello, world!\n");
// }
// {CallHierarchy_test.java}
// /** Suppose this code is written in a different custom programming language, any DSL, e.g. Java*/
// class CallHierarchy_test {
// public static void function_dsl() {
// System.out.println("Hello, world!");
// }
// }
public void testCallHierarchy() throws Exception {
assertNotNull(Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.cdt.ui.CCallHierarchy"));
ImageDescriptor imageDesc = AbstractUIPlugin.imageDescriptorFromPlugin(CUIPlugin.PLUGIN_ID, CHLabelProvider.ICON_PATH);
assertNotNull(imageDesc);
Image image = imageDesc.createImage(); //$NON-NLS-1$
assertNotNull(image);
String content = readTaggedComment(FILE_NAME_DSL);
assertNotNull(content);
IFile file= createFile(getProject(), FILE_NAME_DSL, content);
content = readTaggedComment(FILE_NAME_C);
assertNotNull(content);
file= createFile(getProject(), FILE_NAME_C, content);
waitUntilFileIsIndexed(fIndex, file);
content = readTaggedComment(FILE_NAME_MAIN_C);
assertNotNull(content);
file= createFile(getProject(), FILE_NAME_MAIN_C, content);
waitUntilFileIsIndexed(fIndex, file);
CEditor editor = openEditor(file);
String functionName ="function_c";
editor.selectAndReveal(content.indexOf(functionName), functionName.length());
openCallHierarchy(editor);
Tree tree = getCHTreeViewer().getTree();
checkTreeNode(tree, 0, "function_c() : void");
checkTreeNode(tree, 0, 0 ,"main() : void");
functionName ="function_dsl";
editor.selectAndReveal(content.indexOf(functionName), functionName.length());
openCallHierarchy(editor);
tree = getCHTreeViewer().getTree();
checkTreeNode(tree, 0, "JAVA function function_dsl()");
checkTreeNode(tree, 0, 0, "function_dsl() : void");
}
}

View file

@ -0,0 +1,72 @@
/*******************************************************************************
* Copyright (c) 2018 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Lidia Popescu - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.callhierarchy.extension;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.ui.CUIPlugin;
public class CHLabelProvider implements IStyledLabelProvider {
public static String ICON_PATH= "$nl$/icons/obj16/container_obj.gif";
@Override
public void addListener(ILabelProviderListener listener) {
}
@Override
public void dispose() {
}
@Override
public boolean isLabelProperty(Object element, String property) {
return true;
}
@Override
public void removeListener(ILabelProviderListener listener) {
}
@Override
public StyledString getStyledText(Object element) {
if (element instanceof DslNode) {
DslNode node = (DslNode)element;
ICElement decl = node.getRepresentedDeclaration();
if (decl !=null) {
StyledString label = new StyledString();
label.append(decl.getElementName());
if (node.getDslNodeName() != null) {
return StyledCellLabelProvider.styleDecoratedString(node.getDslNodeName(), StyledString.DECORATIONS_STYLER, label);
}
return label;
}
}
return null;
}
@Override
public Image getImage(Object element) {
if (element instanceof DslNode) {
Image img = AbstractUIPlugin.imageDescriptorFromPlugin(
CUIPlugin.PLUGIN_ID, ICON_PATH).createImage(); //$NON-NLS-1$
return img;
}
return null;
}
}

View file

@ -0,0 +1,92 @@
/*******************************************************************************
* Copyright (c) 2018 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Lidia Popescu - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.callhierarchy.extension;
import java.util.HashMap;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.IOpenListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.OpenEvent;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.progress.UIJob;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
public class CHOpenListener implements IOpenListener {
/** On Node click open corresponding file */
@Override
public void open(OpenEvent event) {
if (event !=null ) {
ISelection selection = event.getSelection();
if (selection instanceof TreeSelection ) {
TreeSelection treeSelection = (TreeSelection)selection;
Object element = treeSelection.getFirstElement();
if (element instanceof DslNode) {
DslNode node = (DslNode)element;
ICProject project = node.getProject();
/**
* Based on a custom algorithm the corresponding file and line should be found and open. Suppose that the file
* 'CallHierarchy_test.java' has been found, and the line number '3' where the function 'function_dsl' is defined.
*/
IFile file = project.getProject().getFile("CallHierarchy_test.java");
IWorkbenchPage page= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite().getPage();
IEditorInput input = new FileEditorInput(file);
IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(input.getName());
UIJob ui = new UIJob("Open File") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
try {
String editorId = null;
if (desc == null || desc.isOpenExternal()) {
editorId = "org.eclipse.ui.DefaultTextEditor";
} else {
editorId = desc.getId();
}
IEditorPart editor = page.openEditor(input, editorId);
IMarker fMarker = file.createMarker(IMarker.TEXT);
HashMap<String, Object> map = new HashMap<String, Object>();
map.put(IMarker.LINE_NUMBER, 3);
fMarker.setAttributes(map);
IDE.gotoMarker(editor,fMarker);
} catch (PartInitException e) {
e.printStackTrace();
} catch (CoreException e) {
e.printStackTrace();
}
return new Status(IStatus.OK, CTestPlugin.PLUGIN_ID, "");
}
};
ui.schedule();
}
}
}
}
}

View file

@ -0,0 +1,76 @@
/*******************************************************************************
* Copyright (c) 2018 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Lidia Popescu - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.callhierarchy.extension;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.ICHENode;
/**
* The dsl node sample
* */
public class DslNode implements IAdaptable, ICHENode {
private ICElement fRepresentedDecl;
private ICProject mProject;
private String mDslNodeName;
/**
* Constructor used for Open Call Hierarchy command
* */
public DslNode(ICElement decl) {
this.fRepresentedDecl = decl;
}
/**
* Constructor used for Open Dsl declaration command
* */
public DslNode() {
}
public ICProject getProject() {
return mProject;
}
public void setProject(ICProject mProject) {
this.mProject = mProject;
}
@Override
public ICElement getRepresentedDeclaration() {
return fRepresentedDecl;
}
@Override
public <T> T getAdapter(Class<T> adapterClass) {
if (adapterClass == ICElement.class) {
return (T)getRepresentedDeclaration();
}
return null;
}
/**
* Should be displayed with an indication that this is the dsl,
* e.g. "Java function <function_name>".
* */
public String getDslNodeName() {
if ( mDslNodeName == null ) {
mDslNodeName = "JAVA function " + fRepresentedDecl.getElementName()+"()";
}
return mDslNodeName;
}
}

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.ui; singleton:=true
Bundle-Version: 6.3.1.qualifier
Bundle-Version: 6.4.0.qualifier
Bundle-Activator: org.eclipse.cdt.ui.CUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin

View file

@ -32,6 +32,7 @@
<extension-point id="RefreshExclusionContributor" name="%RefreshExclusionContributorExtensionPoint" schema="schema/RefreshExclusionContributor.exsd"/>
<extension-point id="semanticHighlighting" name="%semanticHighlightingExtensionPoint" schema="schema/semanticHighlighting.exsd"/>
<extension-point id="newToolChainWizards" name="New ToolChain Wizards" schema="schema/newToolChainWizards.exsd"/>
<extension-point id="CCallHierarchy" name="The Call Hierarchy Tree Extension" schema="schema/CCallHierarchy.exsd"/>
<extension
point="org.eclipse.core.runtime.adapters">

View file

@ -0,0 +1,148 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.cdt.ui" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.eclipse.cdt.ui" id="CCallHierarchy" name="The Call Hierarchy Tree Extension"/>
</appInfo>
<documentation>
This Call Hierarchy Tree Extension makes possible to extend the CH tree content by adding a new node at the top of the tree, respectivity to customize it&apos;s icon and style text, and to add additional click listeners. This could be usefull for mixed source projects, when original declaration of a CDT node comes from a different programming language.
</documentation>
</annotation>
<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<sequence>
<element ref="CallHierarchyContentProvider"/>
<element ref="CallHierarchyLabelProvider"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="CallHierarchyContentProvider">
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="identifier"/>
</appInfo>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.ui.ICHEContentProvider"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="CallHierarchyLabelProvider">
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="identifier"/>
</appInfo>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider$IStyledLabelProvider"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
6.4
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
A full sample of implementation is provided in org.eclipse.cdt.ui.tests plugin.
&lt;extension
point=&quot;org.eclipse.cdt.ui.CCallHierarchy&quot;&gt;
&lt;CallHierarchyLabelProvider
class=&quot;org.eclipse.cdt.ui.tests.callhierarchy.extension.CHLabelProvider&quot;
id=&quot;org.eclipse.cdt.ui.tests.callhierarchy.extension.CHLabelProvider&quot;&gt;
&lt;/CallHierarchyLabelProvider&gt;
&lt;CallHierarchyContentProvider
class=&quot;org.eclipse.cdt.ui.tests.callhierarchy.extension.CHContentProvider&quot;
id=&quot;org.eclipse.cdt.ui.tests.callhierarchy.extension.CHContentProvider&quot;&gt;
&lt;/CallHierarchyContentProvider&gt;
&lt;/extension&gt;
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="apiinfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2014 Wind River Systems, Inc. and others.
* Copyright (c) 2018 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors:
* Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
* Lidia Popescu (Wind River) [536255] Extension point for open call hierarchy view
*******************************************************************************/
package org.eclipse.cdt.internal.ui.callhierarchy;
@ -33,6 +34,8 @@ import org.eclipse.cdt.core.model.IMethod;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IVariable;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.ICHEContentProvider;
import org.eclipse.cdt.ui.ICHENode;
import org.eclipse.cdt.internal.corext.util.CModelUtil;
@ -91,6 +94,19 @@ public class CHContentProvider extends AsyncTreeContentProvider {
@Override
protected Object[] asyncronouslyComputeChildren(Object parentElement, IProgressMonitor monitor) {
try {
ICHEContentProvider[] providers = fView.getContentProviders();
if (providers != null) {
for (ICHEContentProvider provider : providers) {
Object[] object = provider.asyncComputeExtendedRoot(parentElement);
if (object != null) {
return object;
}
}
}
if (parentElement instanceof ICHENode) {
return asyncComputeRoot(((ICHENode)parentElement).getRepresentedDeclaration());
}
if (parentElement instanceof ICElement) {
return asyncComputeRoot((ICElement) parentElement);
}

View file

@ -0,0 +1,97 @@
/*******************************************************************************
* Copyright (c) 2018 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Lidia Popescu - [536255] initial API and implementation. Extension point for open call hierarchy view
*******************************************************************************/
package org.eclipse.cdt.internal.ui.callhierarchy;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.jface.viewers.IOpenListener;
import org.eclipse.cdt.ui.ICHEContentProvider;
/**
* The Call Hierarchy Extension provider Settings
* Responsible to load all available extensions for EXTENSION_POINT_ID
* */
public class CHEProviderSettings {
private static final String EXTENSION_POINT_ID = "org.eclipse.cdt.ui.CCallHierarchy"; //$NON-NLS-1$
private static final String ELEMENT_NAME_CONTENT = "CallHierarchyContentProvider"; //$NON-NLS-1$
private static final String ELEMENT_NAME_LABEL = "CallHierarchyLabelProvider"; //$NON-NLS-1$
private static final String ATTRIB_CLASS = "class"; //$NON-NLS-1$
IOpenListener[] openListeners =null;
static ICHEContentProvider[] chContentProviders = null;
static IStyledLabelProvider[] chLabelProviders = null;
private static void loadExtensions() {
List<ICHEContentProvider> chCProviders = new ArrayList<ICHEContentProvider>();
List<IStyledLabelProvider> chLProviders = new ArrayList<IStyledLabelProvider>();
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(EXTENSION_POINT_ID);
if (extensionPoint != null) {
IExtension[] extensions = extensionPoint.getExtensions();
if (extensions != null) {
for (IExtension ex : extensions) {
for (IConfigurationElement el : ex.getConfigurationElements()) {
if (el.getName().equals(ELEMENT_NAME_CONTENT)) {
ICHEContentProvider provider = null;
try {
provider = (ICHEContentProvider) el.createExecutableExtension(ATTRIB_CLASS);
} catch (CoreException e) {
e.printStackTrace();
}
if (provider != null) {
chCProviders.add(provider);
}
}
if (el.getName().equals(ELEMENT_NAME_LABEL)) {
IStyledLabelProvider provider = null;
try {
provider = (IStyledLabelProvider) el.createExecutableExtension(ATTRIB_CLASS);
} catch (CoreException e) {
e.printStackTrace();
}
if (provider != null) {
chLProviders.add(provider);
}
}
}
}
}
}
chLabelProviders = chLProviders.toArray(new IStyledLabelProvider[chLProviders.size()]);
chContentProviders = chCProviders.toArray(new ICHEContentProvider[chCProviders.size()]);
}
public static IStyledLabelProvider[] getCCallHierarchyLabelProviders() {
if ( chLabelProviders == null) {
loadExtensions();
}
return chLabelProviders;
}
public static ICHEContentProvider[] getCCallHierarchyContentProviders() {
if ( chContentProviders == null) {
loadExtensions();
}
return chContentProviders;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 Wind River Systems, Inc. and others.
* Copyright (c) 2018 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,12 +8,14 @@
* Contributors:
* Markus Schorn - initial API and implementation
* Patrick Hofer [bug 325799]
* Lidia Popescu (Wind River) [536255] Extension point for open call hierarchy view
*******************************************************************************/
package org.eclipse.cdt.internal.ui.callhierarchy;
import java.util.HashMap;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.osgi.util.NLS;
@ -42,14 +44,27 @@ public class CHLabelProvider extends AppearanceAwareLabelProvider {
private CHContentProvider fContentProvider;
private HashMap<String, Image> fCachedImages= new HashMap<String, Image>();
private Color fColorInactive;
private IStyledLabelProvider[] fProviders;
private CHViewPart fView;
public CHLabelProvider(Display display, CHContentProvider cp) {
public CHLabelProvider(CHViewPart view, Display display, CHContentProvider cp) {
fColorInactive= display.getSystemColor(SWT.COLOR_DARK_GRAY);
fContentProvider= cp;
fView = view;
}
@Override
public Image getImage(Object element) {
if (fProviders == null ) {
fProviders = fView.getLabelProviders();
}
if ( fProviders != null ) {
for (IStyledLabelProvider provider : fProviders) {
Image img = provider.getImage(element);
if (img != null)
return img;
}
}
if (element instanceof CHNode) {
CHNode node= (CHNode) element;
Image image= null;
@ -99,6 +114,16 @@ public class CHLabelProvider extends AppearanceAwareLabelProvider {
@Override
public StyledString getStyledText(Object element) {
if (fProviders == null ) {
fProviders = fView.getLabelProviders();
}
if (fProviders != null) {
for (IStyledLabelProvider provider : fProviders) {
StyledString styledString = provider.getStyledText(element);
if (styledString != null)
return styledString;
}
}
if (element instanceof CHNode) {
CHNode node= (CHNode) element;
ICElement decl= node.getOneRepresentedDeclaration();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2015 Wind River Systems, Inc. and others.
* Copyright (c) 2018 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors:
* Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
* Lidia Popescu (Wind River) [536255] Extension point for open call hierarchy view
*******************************************************************************/
package org.eclipse.cdt.internal.ui.callhierarchy;
@ -24,6 +25,7 @@ import org.eclipse.jface.bindings.BindingManagerEvent;
import org.eclipse.jface.bindings.IBindingManagerListener;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.jface.viewers.IOpenListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@ -72,6 +74,7 @@ import org.eclipse.cdt.core.model.IFunction;
import org.eclipse.cdt.core.model.IMethod;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.ICHEContentProvider;
import org.eclipse.cdt.ui.actions.CdtActionConstants;
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
import org.eclipse.cdt.ui.refactoring.actions.CRefactoringActionGroup;
@ -149,6 +152,8 @@ public class CHViewPart extends ViewPart {
private IBindingService bindingService;
private IBindingManagerListener bindingManagerListener;
private ICHEContentProvider[] fProviders;
private IStyledLabelProvider[] fLabelProviders;
@Override
public void setFocus() {
@ -391,8 +396,11 @@ public class CHViewPart extends ViewPart {
fViewerPage.setSize(100, 100);
fViewerPage.setLayout(new FillLayout());
fProviders = CHEProviderSettings.getCCallHierarchyContentProviders();
fLabelProviders = CHEProviderSettings.getCCallHierarchyLabelProviders();
fContentProvider= new CHContentProvider(this, display);
fLabelProvider= new CHLabelProvider(display, fContentProvider);
fLabelProvider = new CHLabelProvider(this, display, fContentProvider);
fTreeViewer= new ExtendedTreeViewer(fViewerPage);
fTreeViewer.setContentProvider(fContentProvider);
fTreeViewer.setLabelProvider(new DecoratingCLabelProvider(fLabelProvider));
@ -403,6 +411,11 @@ public class CHViewPart extends ViewPart {
onShowSelectedReference(event.getSelection());
}
});
if (fProviders !=null) {
for (ICHEContentProvider provider : fProviders) {
fTreeViewer.addOpenListener(provider.getCCallHierarchyOpenListener());
}
}
}
private void createInfoPage() {
@ -896,4 +909,18 @@ public class CHViewPart extends ViewPart {
boolean isPinned() {
return fIsPinned;
}
/**
* @return an array of {@link ICHEContentProvider} for Extended Call Hierarchy
*/
public ICHEContentProvider[] getContentProviders() {
return fProviders;
}
/**
* @return an array of {@link IStyledLabelProvider} for Extended Call Hierarchy
*/
public IStyledLabelProvider[] getLabelProviders() {
return fLabelProviders;
}
}

View file

@ -0,0 +1,24 @@
/*******************************************************************************
* Copyright (c) 2018 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Lidia Popescu - [536255] initial API and implementation. Extension point for open call hierarchy view
*******************************************************************************/
package org.eclipse.cdt.ui;
import org.eclipse.jface.viewers.IOpenListener;
/**
* The Call Hierarchy Extension Content Provider Interface
* @since 6.4
* */
public interface ICHEContentProvider {
Object[] asyncComputeExtendedRoot(Object parentElement);
IOpenListener getCCallHierarchyOpenListener();
}

View file

@ -0,0 +1,23 @@
/*******************************************************************************
* Copyright (c) 2018 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Lidia Popescu - [536255] initial API and implementation. Extension point for open call hierarchy view
*******************************************************************************/
package org.eclipse.cdt.ui;
import org.eclipse.cdt.core.model.ICElement;
/**
* The Call Hierarchy Extension Node
* @since 6.4
*/
public interface ICHENode {
ICElement getRepresentedDeclaration();
}