Search in sources :

Example 86 with IErlModule

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

the class IErlProjectTest method setSourceDirs.

// void setSourceDirs(Collection<IPath> sourceDirs)
// throws BackingStoreException;
@Test
public void setSourceDirs() throws Exception {
    final IErlProject aProject = ErlModelTestBase.projects[0];
    final Collection<IPath> sourceDirs = aProject.getProperties().getSourceDirs();
    try {
        // given
        // an Erlang project and a module
        final IPath srcxPath = new Path("srcx");
        final List<IPath> srcxDirs = Lists.newArrayList(srcxPath);
        aProject.open(null);
        // when
        // setting source dirs so the module is on source path
        final Collection<IErlModule> modules = aProject.getModules();
        ((ErlProject) aProject).setSourceDirs(srcxDirs);
        aProject.open(null);
        final Collection<IErlModule> srcxModules = aProject.getModules();
        ((ErlProject) aProject).setSourceDirs(sourceDirs);
        aProject.open(null);
        final Collection<IErlModule> modulesAgain = aProject.getModules();
        // then
        // the it should be returned, but not otherwise
        assertEquals(0, srcxModules.size());
        assertEquals(1, modules.size());
        assertEquals(module, modules.iterator().next());
        assertEquals(1, modulesAgain.size());
        assertEquals(module, modulesAgain.iterator().next());
    } finally {
        ((ErlProject) aProject).setSourceDirs(sourceDirs);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) Test(org.junit.Test)

Example 87 with IErlModule

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

the class ModelUtilsTest method findExternalModuleFromPath.

@Test
public void findExternalModuleFromPath() throws Exception {
    File externalFile = null;
    IErlProject project = null;
    try {
        // given
        // an erlang project and an external file not in any project
        project = ErlideTestUtils.createErlProject("testproject");
        final String externalFileName = "external2.erl";
        externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-module(external2).\nf([_ | _]=L ->\n    atom_to_list(L).\n");
        final String absolutePath = externalFile.getAbsolutePath();
        final String externalsFileName = "x.erlidex";
        final File externalsFile = ErlideTestUtils.createTmpFile(externalsFileName, absolutePath);
        ((ErlProject) project).setExternalModulesFile(externalsFile.getAbsolutePath());
        project.open(null);
        // when
        // looking for it
        final IErlElementLocator model = ErlangEngine.getInstance().getModel();
        final IErlModule module = modelFindService.findModule(model, null, null, absolutePath, IErlElementLocator.Scope.ALL_PROJECTS);
        // then
        // we should find it
        assertThat(module).isNotNull();
        assertThat(externalFileName).isEqualTo(module.getName());
    } finally {
        if (externalFile != null && externalFile.exists()) {
            externalFile.delete();
        }
        if (project != null) {
            ErlideTestUtils.deleteProject(project);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) File(java.io.File) Test(org.junit.Test)

Example 88 with IErlModule

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

the class ModelUtilsTest method findPreprocessorDefTest.

@Test
public void findPreprocessorDefTest() throws Exception {
    // given
    // a module with includes and record
    final IErlProject project = ModelUtilsTest.projects[0];
    final IErlModule include = ErlideTestUtils.createInclude(project, "a.hrl", "-record(rec1, {field, another=def}).\n-define(MACRO(A), lists:reverse(A)).\n");
    final IErlModule module = ErlideTestUtils.createModule(project, "f.erl", "-module(f).\n-include(\"a.hrl\").\n-export([f/0]).\n-record(rec2, {a, b}).\n" + "f() ->\n    lists:reverse([1, 0]),\n    lists:reverse([1, 0], [2]).\n");
    module.open(null);
    project.open(null);
    final IErlPreprocessorDef preprocessorDef1 = modelFindService.findPreprocessorDef(module, "rec1", ErlElementKind.RECORD_DEF);
    final IErlPreprocessorDef preprocessorDef2 = modelFindService.findPreprocessorDef(include, "rec1", ErlElementKind.RECORD_DEF);
    final IErlPreprocessorDef preprocessorDef3 = modelFindService.findPreprocessorDef(Arrays.asList(ModelUtilsTest.projects), "f.erl", "rec2", ErlElementKind.RECORD_DEF);
    // then
    // the record should be returned
    assertNotNull(module);
    assertNotNull(preprocessorDef1);
    assertTrue(preprocessorDef1 instanceof IErlRecordDef);
    assertEquals(preprocessorDef1, preprocessorDef2);
    assertEquals(preprocessorDef1.getParent(), include);
    assertNotNull(preprocessorDef3);
    assertEquals(preprocessorDef3.getParent(), module);
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlRecordDef(org.erlide.engine.model.erlang.IErlRecordDef) IErlModule(org.erlide.engine.model.root.IErlModule) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) Test(org.junit.Test)

Example 89 with IErlModule

use of org.erlide.engine.model.root.IErlModule 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 90 with IErlModule

use of org.erlide.engine.model.root.IErlModule 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)

Aggregations

IErlModule (org.erlide.engine.model.root.IErlModule)191 Test (org.junit.Test)66 IErlProject (org.erlide.engine.model.root.IErlProject)57 IErlElement (org.erlide.engine.model.IErlElement)35 IFile (org.eclipse.core.resources.IFile)26 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)26 ErlModelException (org.erlide.engine.model.ErlModelException)22 IPath (org.eclipse.core.runtime.IPath)21 ErlProject (org.erlide.engine.internal.model.root.ErlProject)21 File (java.io.File)20 IErlModel (org.erlide.engine.model.root.IErlModel)18 Path (org.eclipse.core.runtime.Path)17 IProject (org.eclipse.core.resources.IProject)16 IResource (org.eclipse.core.resources.IResource)14 ArrayList (java.util.ArrayList)13 CoreException (org.eclipse.core.runtime.CoreException)10 IEditorPart (org.eclipse.ui.IEditorPart)10 IParent (org.erlide.engine.model.IParent)10 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)9 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)9