use of org.erlide.engine.model.erlang.IErlFunction in project erlide_eclipse by erlang.
the class ModelUtilsTest method findExternalFunctionModuleTest.
@Test
public void findExternalFunctionModuleTest() throws Exception {
// given
// a module with functions and functions
final IErlModule moduleD = ErlideTestUtils.createModule(ModelUtilsTest.projects[0], "d.erl", "-module(d).\n-export([f/0]).\nf() ->\n ok.\ng() ->\n ?MODULE:f().\n");
moduleD.open(null);
// when
// looking for it with ?MODULE
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
final IErlElement element1 = modelFindService.findFunction(model, ModelUtilsTest.projects[0], moduleD, "?MODULE", null, new ErlangFunction("f", 0), IErlElementLocator.Scope.PROJECT_ONLY);
// then
// it should be found
assertTrue(element1 instanceof IErlFunction);
}
use of org.erlide.engine.model.erlang.IErlFunction in project erlide_eclipse by erlang.
the class ErlangCompareUtilities method getErlElementID.
/**
* Returns a name for the given Erlang element
*/
static String getErlElementID(final IErlElement e) {
final StringBuilder sb = new StringBuilder();
final ErlElementKind kind = e.getKind();
sb.append(kind);
if (kind == ErlElementKind.FUNCTION) {
final IErlFunction f = (IErlFunction) e;
sb.append(f.getNameWithArity());
} else if (kind == ErlElementKind.CLAUSE) {
final IErlFunctionClause fc = (IErlFunctionClause) e;
sb.append(fc.getHead());
} else if (kind == ErlElementKind.ATTRIBUTE) {
final IErlAttribute a = (IErlAttribute) e;
sb.append(a.getName());
if (a.getValue() != null) {
sb.append(a.getValue().toString());
}
} else if (kind == ErlElementKind.RECORD_DEF || kind == ErlElementKind.MACRO_DEF) {
final IErlPreprocessorDef pd = (IErlPreprocessorDef) e;
sb.append(pd.getDefinedName());
}
return sb.toString();
}
use of org.erlide.engine.model.erlang.IErlFunction in project erlide_eclipse by erlang.
the class OpenItemAction method run.
@Override
public void run() {
log.info("Open item!");
final ISelection selection = viewer.getSelection();
if (!(selection instanceof ITreeSelection)) {
final IStatus executionStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Internall error occured: bad sellection type", null);
StatusManager.getManager().handle(executionStatus, StatusManager.SHOW);
return;
}
final ITreeSelection treeSelection = (ITreeSelection) selection;
final StatsTreeObject obj = (StatsTreeObject) treeSelection.getFirstElement();
if (obj.getClass().equals(ModuleStats.class)) {
openInEditor(obj.getLabel() + ".erl");
} else if (obj.getClass().equals(FunctionStats.class)) {
final FunctionStats fs = (FunctionStats) obj;
final String moduleName = ((StatsTreeObject) fs.getParent()).getLabel();
final IEditorPart p = openInEditor(moduleName + ".erl");
if (p == null || !(p instanceof ErlangEditor)) {
return;
}
final ErlangEditor editor = (ErlangEditor) p;
IErlModule module;
try {
module = ErlangEngine.getInstance().getModel().findModule(moduleName);
final IErlFunction f = module.findFunction(new ErlangFunction(fs.getLabel(), fs.getArity()));
editor.setSelection(f);
} catch (final ErlModelException e) {
ErlLogger.error(e);
}
} else {
// disabled
}
}
use of org.erlide.engine.model.erlang.IErlFunction in project erlide_eclipse by erlang.
the class FunctionStats method getLineStart.
/**
* First line of the function
*
* @return
*/
public int getLineStart() {
if (lineStart != 0) {
return lineStart;
}
final String mName = ((StatsTreeObject) getParent()).getLabel();
IErlModule m;
try {
m = ErlangEngine.getInstance().getModel().findModule(mName);
final IErlFunction f = m.findFunction(new ErlangFunction(getLabel(), getArity()));
lineStart = f.getLineStart();
} catch (final ErlModelException e) {
ErlLogger.error(e);
}
return lineStart;
}
use of org.erlide.engine.model.erlang.IErlFunction in project erlide_eclipse by erlang.
the class ModelFindUtil method findFunction.
@Override
public IErlFunction findFunction(final IErlElementLocator model, final IErlProject project, final IErlModule module, final String moduleName0, final String modulePath, final ErlangFunction erlangFunction, final IErlElementLocator.Scope scope) throws CoreException {
if (moduleName0 != null) {
final String moduleName = resolveMacroValue(moduleName0, module);
final IErlModule module2 = findModule(model, project, moduleName, modulePath, scope);
if (module2 != null) {
module2.open(null);
final IErlFunction function = module2.findFunction(erlangFunction);
if (function != null) {
return function;
}
return null;
}
}
return null;
}
Aggregations