Search in sources :

Example 1 with ICElement

use of org.eclipse.cdt.core.model.ICElement in project linuxtools by eclipse.

the class ProfileUIUtils method findCProjectWithAbsolutePath.

/**
 * Find an ICProject that contains the specified absolute path.
 *
 * @param absPath An absolute path (usually to some file/folder in a project)
 * @return an ICProject corresponding to the project that contains the absolute path
 * @throws CoreException can be thrown if visiting (accepting) a project walking the ICElement tree fails.
 */
public static ICProject findCProjectWithAbsolutePath(final String absPath) throws CoreException {
    final String workspaceLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString();
    final ArrayList<ICProject> ret = new ArrayList<>();
    // visitor object to check for the matching path string
    ICElementVisitor vis = element -> {
        if (element.getElementType() == ICElement.C_CCONTAINER || element.getElementType() == ICElement.C_PROJECT) {
            return true;
        } else if (absPath.equals(workspaceLoc + element.getPath().toFile().getAbsolutePath())) {
            ret.add(element.getCProject());
        }
        return false;
    };
    ICProject[] cProjects = CCorePlugin.getDefault().getCoreModel().getCModel().getCProjects();
    for (ICProject proj : cProjects) {
        // visit every project
        proj.accept(vis);
    }
    // is it possible to find more than one matching project ?
    return ret.isEmpty() ? null : ret.get(0);
}
Also used : IDebugModelPresentation(org.eclipse.debug.ui.IDebugModelPresentation) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) IDE(org.eclipse.ui.ide.IDE) CDebugCorePlugin(org.eclipse.cdt.debug.core.CDebugCorePlugin) HashMap(java.util.HashMap) CoreException(org.eclipse.core.runtime.CoreException) DebugUITools(org.eclipse.debug.ui.DebugUITools) ArrayList(java.util.ArrayList) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IDocument(org.eclipse.jface.text.IDocument) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IProject(org.eclipse.core.resources.IProject) IPath(org.eclipse.core.runtime.IPath) PartInitException(org.eclipse.ui.PartInitException) Map(java.util.Map) IndexFilter(org.eclipse.cdt.core.index.IndexFilter) IFile(org.eclipse.core.resources.IFile) BadLocationException(org.eclipse.jface.text.BadLocationException) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) URI(java.net.URI) IIndexFile(org.eclipse.cdt.core.index.IIndexFile) RemoteProxyManager(org.eclipse.linuxtools.profiling.launch.RemoteProxyManager) ICProject(org.eclipse.cdt.core.model.ICProject) EFS(org.eclipse.core.filesystem.EFS) IEditorPart(org.eclipse.ui.IEditorPart) IFunction(org.eclipse.cdt.core.dom.ast.IFunction) IFileStore(org.eclipse.core.filesystem.IFileStore) IBinding(org.eclipse.cdt.core.dom.ast.IBinding) LocalFileStorage(org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage) IRegion(org.eclipse.jface.text.IRegion) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IEditorInput(org.eclipse.ui.IEditorInput) ICElement(org.eclipse.cdt.core.model.ICElement) ProfileUIPlugin(org.eclipse.linuxtools.internal.profiling.ui.ProfileUIPlugin) IOException(java.io.IOException) ISourceLookupResult(org.eclipse.debug.ui.sourcelookup.ISourceLookupResult) File(java.io.File) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IIndexName(org.eclipse.cdt.core.index.IIndexName) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IIndexManager(org.eclipse.cdt.core.index.IIndexManager) Path(org.eclipse.core.runtime.Path) ICElementVisitor(org.eclipse.cdt.core.model.ICElementVisitor) IIndex(org.eclipse.cdt.core.index.IIndex) URIUtil(org.eclipse.core.filesystem.URIUtil) ICElementVisitor(org.eclipse.cdt.core.model.ICElementVisitor) ICProject(org.eclipse.cdt.core.model.ICProject) ArrayList(java.util.ArrayList)

Example 2 with ICElement

use of org.eclipse.cdt.core.model.ICElement in project linuxtools by eclipse.

the class CachegrindFunction method findElement.

private ICElement findElement(String name, IParent parent) throws CModelException {
    ICElement element = null;
    List<ICElement> dom = parent.getChildrenOfType(ICElement.C_FUNCTION);
    dom.addAll(parent.getChildrenOfType(ICElement.C_METHOD));
    for (int i = 0; i < dom.size(); i++) {
        ICElement func = dom.get(i);
        if ((func instanceof IFunction || func instanceof IMethod) && func.getElementName().equals(name)) {
            element = func;
        }
    }
    return element;
}
Also used : IMethod(org.eclipse.cdt.core.model.IMethod) ICElement(org.eclipse.cdt.core.model.ICElement) IFunction(org.eclipse.cdt.core.model.IFunction)

Example 3 with ICElement

use of org.eclipse.cdt.core.model.ICElement in project linuxtools by eclipse.

the class GcovAnnotationModelTracker method annotateCEditor.

private void annotateCEditor(IWorkbenchPartReference partref) {
    IWorkbenchPart part = partref.getPart(false);
    if (part instanceof ICEditor) {
        ICEditor editor = (ICEditor) part;
        ICElement element = CDTUITools.getEditorInputCElement(editor.getEditorInput());
        IProject project = element.getCProject().getProject();
        // Attach our annotation model to any compatible editor. (ICEditor)
        GcovAnnotationModel.attach((ITextEditor) part);
        // If a user triggers a build we will not render annotations.
        ResourcesPlugin.getWorkspace().addResourceChangeListener(new ProjectBuildListener(project, editor), IResourceChangeEvent.POST_BUILD);
    }
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ICElement(org.eclipse.cdt.core.model.ICElement) IProject(org.eclipse.core.resources.IProject) ICEditor(org.eclipse.cdt.ui.ICEditor)

Example 4 with ICElement

use of org.eclipse.cdt.core.model.ICElement in project linuxtools by eclipse.

the class ListTreeContentProvider method getElements.

@Override
public Object[] getElements(Object inputElement) {
    if (inputElement instanceof List) {
        for (Object element : (List<?>) inputElement) if (element instanceof ICContainer)
            try {
                ICElement[] array = ((ICContainer) element).getChildren();
                ArrayList<ICElement> output = new ArrayList<>();
                for (ICElement item : array) {
                    if ((item instanceof ICContainer) && checkForValidChildren((ICContainer) item)) {
                        output.add(item);
                    }
                    if (SystemTapLaunchShortcut.validElement(item)) {
                        output.add(item);
                    }
                }
                return output.toArray();
            } catch (CModelException e) {
                e.printStackTrace();
            }
    }
    return null;
}
Also used : ICContainer(org.eclipse.cdt.core.model.ICContainer) CModelException(org.eclipse.cdt.core.model.CModelException) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ICElement(org.eclipse.cdt.core.model.ICElement)

Example 5 with ICElement

use of org.eclipse.cdt.core.model.ICElement in project linuxtools by eclipse.

the class SystemTapOptionsTab method setDefaults.

@Override
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_VERBOSE, LaunchConfigurationConstants.DEFAULT_COMMAND_VERBOSE);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_KEEP_TEMPORARY, LaunchConfigurationConstants.DEFAULT_COMMAND_KEEP_TEMPORARY);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_GURU, LaunchConfigurationConstants.DEFAULT_COMMAND_GURU);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_PROLOGUE_SEARCH, LaunchConfigurationConstants.DEFAULT_COMMAND_PROLOGUE_SEARCH);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_NO_CODE_ELISION, LaunchConfigurationConstants.DEFAULT_COMMAND_NO_CODE_ELISION);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_DISABLE_WARNINGS, LaunchConfigurationConstants.DEFAULT_COMMAND_DISABLE_WARNINGS);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_BULK_MODE, LaunchConfigurationConstants.DEFAULT_COMMAND_BULK_MODE);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_TIMING_INFO, LaunchConfigurationConstants.DEFAULT_COMMAND_TIMING_INFO);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_SKIP_BADVARS, LaunchConfigurationConstants.DEFAULT_COMMAND_SKIP_BADVARS);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_IGNORE_DWARF, LaunchConfigurationConstants.DEFAULT_COMMAND_IGNORE_DWARF);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_TAPSET_COVERAGE, LaunchConfigurationConstants.DEFAULT_COMMAND_TAPSET_COVERAGE);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_LEAVE_RUNNING, LaunchConfigurationConstants.DEFAULT_COMMAND_LEAVE_RUNNING);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_PASS, LaunchConfigurationConstants.DEFAULT_COMMAND_PASS);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_BUFFER_BYTES, LaunchConfigurationConstants.DEFAULT_COMMAND_BUFFER_BYTES);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_TARGET_PID, LaunchConfigurationConstants.DEFAULT_COMMAND_TARGET_PID);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_C_DIRECTIVES, LaunchConfigurationConstants.DEFAULT_COMMAND_C_DIRECTIVES);
    configuration.setAttribute(LaunchConfigurationConstants.BINARY_PATH, LaunchConfigurationConstants.DEFAULT_BINARY_PATH);
    configuration.setAttribute(LaunchConfigurationConstants.SCRIPT_PATH, LaunchConfigurationConstants.DEFAULT_SCRIPT_PATH);
    configuration.setAttribute(LaunchConfigurationConstants.OUTPUT_PATH, LaunchConfigurationConstants.DEFAULT_OUTPUT_PATH);
    configuration.setAttribute(LaunchConfigurationConstants.ARGUMENTS, LaunchConfigurationConstants.DEFAULT_ARGUMENTS);
    configuration.setAttribute(LaunchConfigurationConstants.BINARY_ARGUMENTS, LaunchConfigurationConstants.DEFAULT_BINARY_ARGUMENTS);
    configuration.setAttribute(LaunchConfigurationConstants.GENERATED_SCRIPT, LaunchConfigurationConstants.DEFAULT_GENERATED_SCRIPT);
    configuration.setAttribute(LaunchConfigurationConstants.NEED_TO_GENERATE, LaunchConfigurationConstants.DEFAULT_NEED_TO_GENERATE);
    configuration.setAttribute(LaunchConfigurationConstants.PARSER_CLASS, LaunchConfigurationConstants.DEFAULT_PARSER_CLASS);
    configuration.setAttribute(LaunchConfigurationConstants.VIEW_CLASS, LaunchConfigurationConstants.DEFAULT_VIEW_CLASS);
    configuration.setAttribute(LaunchConfigurationConstants.USE_COLOUR, LaunchConfigurationConstants.DEFAULT_USE_COLOUR);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_LIST, ConfigurationOptionsSetter.setOptions(configuration));
    ICElement cElement = null;
    cElement = getContext(configuration, getPlatform(configuration));
    if (cElement != null) {
        initializeCProject(cElement, configuration);
    } else {
        // don't want to remember the interim value from before
        configuration.setMappedResources(null);
    }
    IBinary bin = getBinary(configuration);
    if (bin != null) {
        String programName = bin.getResource().getProjectRelativePath().toString();
        configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, programName);
        configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
        LaunchStapGraph launch = new LaunchStapGraph();
        // Do not run callgraph
        launch.setTestMode(true);
        // $NON-NLS-1$
        launch.launch(bin, "", configuration);
    }
}
Also used : IBinary(org.eclipse.cdt.core.model.IBinary) ICElement(org.eclipse.cdt.core.model.ICElement)

Aggregations

ICElement (org.eclipse.cdt.core.model.ICElement)12 ArrayList (java.util.ArrayList)4 ICContainer (org.eclipse.cdt.core.model.ICContainer)3 CoreException (org.eclipse.core.runtime.CoreException)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 IASTTranslationUnit (org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)2 CModelException (org.eclipse.cdt.core.model.CModelException)2 IBinary (org.eclipse.cdt.core.model.IBinary)2 IProject (org.eclipse.core.resources.IProject)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 File (java.io.File)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 List (java.util.List)1 Map (java.util.Map)1 CCorePlugin (org.eclipse.cdt.core.CCorePlugin)1 IASTDeclaration (org.eclipse.cdt.core.dom.ast.IASTDeclaration)1 IASTFunctionDeclarator (org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator)1