Search in sources :

Example 11 with IErlElementLocator

use of org.erlide.engine.model.root.IErlElementLocator in project erlide_eclipse by erlang.

the class ErlProject method getModulesAndIncludes.

@Override
public Collection<IErlModule> getModulesAndIncludes() throws ErlModelException {
    final List<IErlModule> result = new ArrayList<>();
    final ErlModelCache erlModelCache = ErlModelCache.getDefault();
    final List<IErlModule> modulesForProject = erlModelCache.getModulesForProject(this);
    final List<IErlModule> includesForProject = erlModelCache.getIncludesForProject(this);
    if (modulesForProject != null && includesForProject != null) {
        result.addAll(modulesForProject);
        result.addAll(includesForProject);
    } else {
        final List<IErlModule> cached = erlModelCache.getModulesForProject(this);
        final IErlElementLocator model = ErlangEngine.getInstance().getModel();
        if (cached == null) {
            final List<IErlModule> modules = ErlProject.getModulesOrIncludes(fProject, model, getProperties().getSourceDirs(), true);
            result.addAll(modules);
        } else {
            result.addAll(cached);
        }
        final Collection<IErlModule> includes = getIncludes();
        result.addAll(includes);
    }
    return result;
}
Also used : ErlModelCache(org.erlide.engine.internal.model.cache.ErlModelCache) IErlModule(org.erlide.engine.model.root.IErlModule) ArrayList(java.util.ArrayList) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator)

Example 12 with IErlElementLocator

use of org.erlide.engine.model.root.IErlElementLocator in project erlide_eclipse by erlang.

the class DebuggerTraceView method gotoModuleLine.

// @Override
// public void createPartControl(final Composite parent) {
// viewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL
// | SWT.MULTI | SWT.FULL_SELECTION));
// setViewer(viewer);
// super.createPartControl(parent);
// // parent.setLayout(new FillLayout());
// 
// viewer.getTree().setLinesVisible(true);
// viewer.setUseHashlookup(true);
// 
// createColumns();
// 
// viewer.setContentProvider(getContentProvider());
// viewer.setLabelProvider(new ColumnLabelProvider());
// getSite().setSelectionProvider(viewer);
// 
// viewer.setInput(this);
// DebugPlugin.getDefault().addDebugEventListener(this);
// 
// // viewer.getTree().addTreeListener(new TreeAdapter() {
// // @Override
// // public void treeCollapsed(final TreeEvent e) {
// // removeExpandedCategory((MarkerCategory) e.item.getData());
// // }
// //
// // @Override
// // public void treeExpanded(final TreeEvent e) {
// // addExpandedCategory((MarkerCategory) e.item.getData());
// // }
// // });
// 
// // // Set help on the view itself
// // viewer.getControl().addHelpListener(new HelpListener() {
// // public void helpRequested(HelpEvent e) {
// // Object provider = getAdapter(IContextProvider.class);
// // if (provider == null) {
// // return;
// // }
// //
// // IContext context = ((IContextProvider) provider)
// // .getContext(viewer.getControl());
// // PlatformUI.getWorkbench().getHelpSystem().displayHelp(context);
// // }
// //
// // });
// 
// viewer.getTree().addSelectionListener(new SelectionAdapter() {
// @Override
// public void widgetSelected(final SelectionEvent e) {
// final Object o = getSelectedInTree();
// final String msg = o == null ? "" : o.toString(); //$NON-NLS-1$
// getViewSite().getActionBars().getStatusLineManager()
// .setMessage(msg);
// 
// }
// });
// 
// viewer.getTree().addMouseListener(new MouseListener() {
// 
// public void mouseDoubleClick(final MouseEvent e) {
// final Object o = getSelectedInTree();
// if (o instanceof OtpErlangTuple) {
// final OtpErlangTuple t = (OtpErlangTuple) o;
// final OtpErlangTuple t2 = (OtpErlangTuple) t.elementAt(1);
// final OtpErlangTuple ieval = (OtpErlangTuple) t2
// .elementAt(0);
// final OtpErlangAtom mod = (OtpErlangAtom) ieval
// .elementAt(3);
// final String module = mod.atomValue();
// final OtpErlangLong lin = (OtpErlangLong) ieval
// .elementAt(2);
// try {
// final int line = lin.intValue();
// gotoModuleLine(module, line);
// } catch (final OtpErlangRangeException e1) {
// }
// 
// }
// }
// 
// public void mouseDown(final MouseEvent e) {
// }
// 
// public void mouseUp(final MouseEvent e) {
// }
// 
// });
// // PlatformUI.getWorkbench().getWorkingSetManager()
// // .addPropertyChangeListener(getWorkingSetListener());
// 
// // registerContextMenu();
// // initDragAndDrop();
// 
// }
protected void gotoModuleLine(final String moduleName, final int line) {
    final IWorkbenchWindow window = ErlideUIPlugin.getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    final IWorkbenchPage page = window.getActivePage();
    if (page == null) {
        return;
    }
    IEditorPart part = null;
    final IErlElementLocator model = ErlangEngine.getInstance().getModel();
    IErlModule module;
    try {
        module = model.findModule(moduleName);
    } catch (final ErlModelException e) {
        ErlLogger.error(e);
        return;
    }
    IEditorInput input = null;
    input = EditorUtility.getEditorInput(module);
    if (input != null) {
        final String editorId = EditorUtility.getEditorID(input, module);
        if (editorId != null) {
            try {
                part = page.openEditor(input, editorId);
            } catch (final PartInitException e) {
                ErlideUIPlugin.errorDialog(window.getShell(), "Go to File", "Exception occurred", // 
                e);
            }
        }
    }
    if (part instanceof ErlangEditor) {
        part.setFocus();
        final ErlangEditor ee = (ErlangEditor) part;
        final IDocument d = ee.getDocument();
        int lineStart;
        int lineLength;
        try {
            lineStart = d.getLineOffset(line - 1);
            lineLength = d.getLineLength(line - 1);
            EditorUtility.revealInEditor(ee, lineStart, lineLength - 1);
        } catch (final BadLocationException e) {
            ErlLogger.error(e);
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) IEditorPart(org.eclipse.ui.IEditorPart) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) ErlangEditor(org.erlide.ui.editors.erl.ErlangEditor)

Example 13 with IErlElementLocator

use of org.erlide.engine.model.root.IErlElementLocator in project erlide_eclipse by erlang.

the class BreakpointUtils method getElement.

public static IErlElement getElement(final ILineBreakpoint breakpoint) {
    final IErlElementLocator model = ErlangEngine.getInstance().getModel();
    final IErlElement element = model.findElement(breakpoint.getMarker().getResource());
    if (element instanceof IErlModule) {
        final IErlModule m = (IErlModule) element;
        try {
            m.open(null);
            final int lineNumber = breakpoint.getLineNumber();
            return m.getElementAtLine(lineNumber - 1);
        } catch (final Exception e) {
            ErlLogger.warn(e);
        }
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) ILineBreakpoint(org.eclipse.debug.core.model.ILineBreakpoint)

Example 14 with IErlElementLocator

use of org.erlide.engine.model.root.IErlElementLocator in project erlide_eclipse by erlang.

the class OpenUtils method findLocalCall.

private IErlElement findLocalCall(final IErlModule module, final IErlProject erlProject, final OpenResult res, final IErlElement element, final IErlElementLocator.Scope scope) throws RpcException, CoreException {
    if (isTypeDefOrRecordDef(element, res)) {
        return modelFindService.findTypespec(module, res.getFun());
    }
    final IErlFunction foundElement = module.findFunction(res.getFunction());
    if (foundElement != null) {
        return foundElement;
    }
    // imported functions
    OtpErlangObject res2 = null;
    String moduleName = null;
    final IErlImport ei = module.findImport(res.getFunction());
    if (ei != null) {
        final IErlModel model = ErlangEngine.getInstance().getModel();
        moduleName = ei.getImportModule();
        res2 = ErlangEngine.getInstance().getOpenService().getSourceFromModule(model.getPathVars(), moduleName, erlProject.getProperties().getExternalModules());
    }
    if (res2 instanceof OtpErlangString && moduleName != null) {
        // imported from otp module
        final OtpErlangString otpErlangString = (OtpErlangString) res2;
        final String modulePath = otpErlangString.stringValue();
        final IErlElementLocator model = ErlangEngine.getInstance().getModel();
        return modelFindService.findFunction(model, erlProject, module, moduleName, modulePath, res.getFunction(), scope);
    }
    // functions defined in include files
    final Collection<IErlModule> allIncludedFiles = ErlangEngine.getInstance().getModelFindService().findAllIncludedFiles(module);
    for (final IErlModule includedModule : allIncludedFiles) {
        final IErlFunction function = includedModule.findFunction(res.getFunction());
        if (function != null) {
            return function;
        }
    }
    return null;
}
Also used : IErlModel(org.erlide.engine.model.root.IErlModel) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) IErlImport(org.erlide.engine.model.erlang.IErlImport) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 15 with IErlElementLocator

use of org.erlide.engine.model.root.IErlElementLocator in project erlide_eclipse by erlang.

the class MarkerUtils method findResourceForFileName.

private static IResource findResourceForFileName(final IResource resource, final Entry<String, List<OtpErlangTuple>> entry, final String fileName) {
    IResource res = resource;
    if (!ResourceUtil.samePath(resource.getLocation().toString(), fileName)) {
        final IProject project = resource.getProject();
        res = ResourceUtil.findResourceByLocation(project, fileName);
        if (res == null) {
            try {
                final IErlElementLocator model = ErlangEngine.getInstance().getModel();
                final IErlProject erlProject = model.findProject(project);
                if (erlProject != null) {
                    final IErlModule includeFile = model.findIncludeFromProject(erlProject, fileName, fileName, IErlElementLocator.Scope.REFERENCED_PROJECTS);
                    if (includeFile == null) {
                        res = resource;
                    } else {
                        res = includeFile.getResource();
                    }
                } else {
                    res = resource;
                }
            } catch (final Exception e) {
                ErlLogger.warn(e);
            }
        }
    }
    return res;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException)

Aggregations

IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)33 IErlModule (org.erlide.engine.model.root.IErlModule)26 Test (org.junit.Test)17 IErlProject (org.erlide.engine.model.root.IErlProject)13 ErlProject (org.erlide.engine.internal.model.root.ErlProject)8 File (java.io.File)7 IFile (org.eclipse.core.resources.IFile)7 IErlElement (org.erlide.engine.model.IErlElement)6 IProject (org.eclipse.core.resources.IProject)5 IPath (org.eclipse.core.runtime.IPath)5 Path (org.eclipse.core.runtime.Path)5 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)3 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)3 IFolder (org.eclipse.core.resources.IFolder)3 CoreException (org.eclipse.core.runtime.CoreException)3 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)3 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)2 ArrayList (java.util.ArrayList)2 IMarker (org.eclipse.core.resources.IMarker)2 IResource (org.eclipse.core.resources.IResource)2