Search in sources :

Example 51 with IErlElement

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);
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlAttribute(org.erlide.engine.internal.model.erlang.ErlAttribute) Test(org.junit.Test)

Example 52 with IErlElement

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);
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) Test(org.junit.Test)

Example 53 with IErlElement

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));
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) IErlModule(org.erlide.engine.model.root.IErlModule) IErlImport(org.erlide.engine.model.erlang.IErlImport) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) Test(org.junit.Test)

Example 54 with IErlElement

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);
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlModule(org.erlide.engine.model.root.IErlModule) ErlangFunction(org.erlide.engine.model.erlang.ErlangFunction) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) Test(org.junit.Test)

Example 55 with IErlElement

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());
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) Test(org.junit.Test)

Aggregations

IErlElement (org.erlide.engine.model.IErlElement)123 Test (org.junit.Test)36 IErlModule (org.erlide.engine.model.root.IErlModule)35 ErlModelException (org.erlide.engine.model.ErlModelException)28 IParent (org.erlide.engine.model.IParent)17 IFile (org.eclipse.core.resources.IFile)16 ArrayList (java.util.ArrayList)12 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)11 IResource (org.eclipse.core.resources.IResource)11 IErlProject (org.erlide.engine.model.root.IErlProject)10 IOpenable (org.erlide.engine.model.root.IOpenable)10 IProject (org.eclipse.core.resources.IProject)9 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)8 IErlModel (org.erlide.engine.model.root.IErlModel)8 WranglerException (org.erlide.wrangler.refactoring.exception.WranglerException)8 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)7 IFolder (org.eclipse.core.resources.IFolder)7 CoreException (org.eclipse.core.runtime.CoreException)7 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)6 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)6