Search in sources :

Example 46 with IErlElement

use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.

the class IErlImportTest method getImportModule.

// public String getImportModule();
@Test
public void getImportModule() throws Exception {
    final IErlModule module2 = ErlideTestUtils.createModule(project, "zz.erl", "-module(zz).\n" + "-import(lists, [foldl/3, reverse/1, reverse/2]).\n");
    module2.open(null);
    final List<IErlElement> imports = module2.getChildrenOfKind(ErlElementKind.IMPORT);
    final IErlImport import1 = (IErlImport) imports.get(0);
    final String importModule = import1.getImportModule();
    assertEquals("lists", importModule);
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlModule(org.erlide.engine.model.root.IErlModule) Test(org.junit.Test)

Example 47 with IErlElement

use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.

the class IErlMemberTest method setNameRange.

// void setNameRange(int offset, int length);
@Test
public void setNameRange() throws Exception {
    module.open(null);
    final IErlElement element = module.getElementAt(1);
    final IErlAttribute attribute = (IErlAttribute) element;
    final int offset = 1;
    final int length = 2;
    attribute.setNameRange(offset, length);
    final ISourceRange nameRange = attribute.getNameRange();
    assertEquals(offset, nameRange.getOffset());
    assertEquals(length, nameRange.getLength());
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) Test(org.junit.Test)

Example 48 with IErlElement

use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.

the class IErlMemberTest method getNameRange.

// ISourceRange getNameRange();
@Test
public void getNameRange() throws Exception {
    module.open(null);
    final IErlElement element = module.getElementAt(1);
    final IErlAttribute attribute = (IErlAttribute) element;
    final ISourceRange nameRange = attribute.getNameRange();
    assertEquals(0, nameRange.getOffset());
    assertEquals(12, nameRange.getLength());
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) Test(org.junit.Test)

Example 49 with IErlElement

use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.

the class IErlModelTest method findElement.

// IErlElement findElement(IResource resource);
@Test
public void findElement() throws Exception {
    final IProject workspaceProject = project.getWorkspaceProject();
    final IErlElement findElement = model.findElement(workspaceProject);
    final IErlElement findElement2 = model.findElement(module.getCorrespondingResource());
    final IErlElement findElement3 = model.findElement(workspaceProject.getFolder("no_way"));
    final IErlElement findElement4 = model.findElement(workspaceProject.getParent());
    final IErlElement parent = (IErlElement) module.getParent();
    final IFolder folder = (IFolder) parent.getResource();
    final IErlElement findElement5 = model.findElement(folder);
    project.open(null);
    final IErlElement srcFolder = project.getChildNamed("src");
    assertEquals(project, findElement);
    assertEquals(module, findElement2);
    assertNull(findElement3);
    assertNull(findElement4);
    assertEquals(srcFolder, findElement5);
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 50 with IErlElement

use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.

the class IErlModelTest method addModelChangeListener.

// void addModelChangeListener(IErlModelChangeListener listener);
// void removeModelChangeListener(IErlModelChangeListener listener);
@Test
public void addModelChangeListener() throws Exception {
    final List<IErlElement> changed = Lists.newArrayList();
    final IErlModelChangeListener listener = new IErlModelChangeListener() {

        @Override
        public void elementChanged(final IErlElement element) {
            changed.add(element);
        }
    };
    final IErlModule module2 = ErlideTestUtils.createModule(project, "zz.erl", "-module(zz).\n");
    final IErlModule module3 = ErlideTestUtils.createModule(project, "tt.erl", "-module(tt).\n");
    model.addModelChangeListener(listener);
    module2.open(null);
    model.removeModelChangeListener(listener);
    module3.open(null);
    final List<IErlElement> changed2 = Lists.newArrayList(changed);
    changed.clear();
    final List<IErlElement> changed3 = Lists.newArrayList(changed);
    changed.clear();
    assertEquals(1, changed2.size());
    assertEquals(0, changed3.size());
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlModule(org.erlide.engine.model.root.IErlModule) IErlModelChangeListener(org.erlide.engine.model.root.IErlModelChangeListener) 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