/* * (non-Javadoc) Method declared on SelectionDispatchAction. */ @Override public void run(final ITextSelection selection) { final ErlangEditor editor = (ErlangEditor) getSite().getPage().getActiveEditor(); editor.reconcileNow(); final IErlModule module = editor.getModule(); if (module == null) { return; } final Backend b = ErlangCore.getBackendManager().getIdeBackend(); final int offset = selection.getOffset(); try { final IErlProject erlProject = module.getErlProject(); final IErlModel model = ErlangCore.getModel(); final OpenResult res = ErlideOpen.open( b, ErlangToolkit.createScannerModuleName(module), offset, ErlModelUtils.getImportsAsList(module), model.getExternalModules(erlProject), model.getPathVars()); ErlLogger.debug("open " + res); openOpenResult(editor, module, b, offset, erlProject, res); } catch (final Exception e) { ErlLogger.warn(e); } }
public void elementChanged(final IErlElement element) { if (element instanceof IErlModule) { final IErlModule m = (IErlModule) element; final IResource r = m.getResource(); if (r instanceof IFile) { doRefresh((IFile) r); } } }
/** * Load the model from the given file, if possible. * * @param modelFile The IFile which contains the persisted model */ public Object getParent(final Object element) { if (element instanceof IErlElement) { final IErlElement elt = (IErlElement) element; final IErlElement parent = elt.getParent(); if (parent instanceof IErlModule) { final IErlModule mod = (IErlModule) parent; try { return mod.getCorrespondingResource(); } catch (final ErlModelException e) { ErlLogger.warn(e); } } } return null; }
public static IMarker createSearchResultMarker( final IErlModule module, final String type, final int offset, final int length) throws CoreException { boolean setPath = false; IResource resource = module.getCorrespondingResource(); if (resource == null) { resource = ResourcesPlugin.getWorkspace().getRoot(); setPath = true; } final IMarker marker = resource.createMarker(type); marker.setAttribute(IMarker.CHAR_START, offset); marker.setAttribute(IMarker.CHAR_END, offset + length); if (setPath) { marker.setAttribute(PATH_ATTRIBUTE, module.getFilePath()); } return marker; }
@SuppressWarnings("unused") private static void getMarkersFor(final IResource resource, final IErlProject p) throws ErlModelException { final IErlModule m = p.getModule(resource.getName()); if (m == null) { return; } m.getScanner(); final Collection<IErlComment> cl = m.getComments(); for (final IErlComment c : cl) { final String text = c.getName(); final int line = c.getLineStart(); mkMarker(resource, line, text, "TODO", IMarker.PRIORITY_NORMAL); mkMarker(resource, line, text, "XXX", IMarker.PRIORITY_NORMAL); mkMarker(resource, line, text, "FIXME", IMarker.PRIORITY_HIGH); } m.disposeScanner(); }
private static IErlElement findLocalCall( final IErlModule module, final Backend backend, final IErlProject erlProject, final OpenResult res, final IProject project, final IErlElement element, final boolean checkAllProjects) throws ErlModelException, BackendException { if (ErlModelUtils.isTypeDefOrRecordDef(element)) { return ModelUtils.findTypespec(module, res.getFun()); } final IErlFunction foundElement = ModelUtils.findFunction(module, res.getFunction()); if (foundElement != null) { return foundElement; } // not local imports OtpErlangObject res2 = null; String moduleName = null; if (module != null) { final IErlImport ei = module.findImport(res.getFunction()); if (ei != null) { moduleName = ei.getImportModule(); final IErlModel model = ErlangCore.getModel(); res2 = ErlideOpen.getSourceFromModule( backend, model.getPathVars(), moduleName, model.getExternalModules(erlProject)); } } if (res2 instanceof OtpErlangString && moduleName != null) { final OtpErlangString otpErlangString = (OtpErlangString) res2; final String modulePath = otpErlangString.stringValue(); return ErlModelUtils.findExternalFunction( moduleName, res.getFunction(), modulePath, project, checkAllProjects, module); } else { return ErlModelUtils.findExternalFunction( moduleName, res.getFunction(), null, project, checkAllProjects, module); } }
private static IErlElement findInclude( final IErlModule module, final IErlProject erlProject, final OpenResult res, final IErlModel model, final IProject project) throws CoreException { final IContainer parent = module == null ? null : module.getResource().getParent(); IResource r = ResourceUtil.recursiveFindNamedResourceWithReferences( project, res.getName(), PluginUtils.getIncludePathFilter(project, parent)); if (r == null) { final String includeFile = ModelUtils.findIncludeFile(project, res.getName(), model.getExternalIncludes(erlProject)); if (includeFile != null) { r = ResourceUtil.openExternal(includeFile); } } if (r instanceof IFile) { final IFile file = (IFile) r; return model.findModule(file); } return null; }