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);
}
}
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);
}
}
}
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);
}
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));
}
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);
}
Aggregations