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;
}
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);
}
}
}
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;
}
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;
}
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;
}
Aggregations