use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class IParentTest method addChild.
// void addChild(IErlElement child);
@Test
public void addChild() throws Exception {
module.open(null);
final int childCount = module.getChildCount();
final String aname = "test_a";
final IErlAttribute attribute = new ErlAttribute(module, aname, null, "test");
module.addChild(attribute);
final int childCount2 = module.getChildCount();
final IErlElement childNamed = module.getChildNamed(aname);
assertEquals(childCount + 1, childCount2);
assertEquals(attribute, childNamed);
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class IParentTest method removeChild.
// void removeChild(IErlElement e);
@Test
public void removeChild() throws Exception {
module.open(null);
final int childCount = module.getChildCount();
final IErlElement element = module.getChildrenOfKind(ErlElementKind.ATTRIBUTE).iterator().next();
final IErlElement childNamed = module.getChildNamed(element.getName());
module.removeChild(element);
final int childCount2 = module.getChildCount();
final IErlElement childNamed2 = module.getChildNamed(element.getName());
assertEquals(childCount - 1, childCount2);
assertNotNull(childNamed);
assertNull(childNamed2);
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class ModelUtilsTest method getImportsAsListTest.
@Test
public void getImportsAsListTest() throws Exception {
// given
// an Erlang module with imports
final IErlModule moduleA = ErlideTestUtils.createModule(ModelUtilsTest.projects[0], "ax.erl", "-module(ax).\n-import(lists, [reverse/1, foldl/3].\n");
moduleA.open(null);
// when
// fetching imports as list of OtpErlangTuple
final Collection<IErlElement> children = moduleA.getChildren();
final Collection<IErlImport> imports2 = moduleA.getImports();
final List<OtpErlangObject> imports = modelUtilService.getImportsAsList(moduleA);
// then
// they should be returned
assertEquals(2, children.size());
assertEquals(1, imports2.size());
assertEquals(1, imports.size());
final OtpErlangAtom listAtom = new OtpErlangAtom("lists");
assertEquals(new OtpErlangTuple(new OtpErlangObject[] { listAtom, new OtpErlangList(new OtpErlangObject[] { makeTuple2("reverse", 1), makeTuple2("foldl", 3) }) }), imports.get(0));
}
use of org.erlide.engine.model.IErlElement 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.IErlElement in project erlide_eclipse by erlang.
the class ISourceReferenceTest method getLineX.
// public int getLineStart();
// public int getLineEnd();
@Test
public void getLineX() throws Exception {
module.open(null);
final IErlElement element = module.getElementAtLine(0);
final ISourceReference sourceReference = (ISourceReference) element;
final IErlElement element2 = module.getElementAtLine(1);
final ISourceReference sourceReference2 = (ISourceReference) element2;
assertEquals(0, sourceReference.getLineStart());
assertEquals(0, sourceReference.getLineEnd());
assertEquals(1, sourceReference2.getLineStart());
assertEquals(1, sourceReference2.getLineEnd());
}
Aggregations