use of org.erlide.engine.internal.model.root.ErlProject in project erlide_eclipse by erlang.
the class ErlProjectTest method findExternalModule.
@Test
public void findExternalModule() throws Exception {
File externalFile = null;
IErlProject project = null;
try {
// given
// an erlang project with an external file
project = ErlideTestUtils.createErlProject("testproject");
final String externalFileName = "external5.erl";
externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-module(external5).\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);
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
// when
// looking for it
final IErlModule externalModule = model.findModuleFromProject(project, externalFileName, null, IErlElementLocator.Scope.PROJECT_ONLY);
// then
// we should find it
assertThat(externalModule).isNotNull();
assertThat(FilePathUtils.equalFilePaths(absolutePath, externalModule.getFilePath(), EFS.getLocalFileSystem().isCaseSensitive())).isTrue();
} finally {
if (externalFile != null && externalFile.exists()) {
externalFile.delete();
}
if (project != null) {
ErlideTestUtils.deleteProject(project);
}
}
}
use of org.erlide.engine.internal.model.root.ErlProject in project erlide_eclipse by erlang.
the class IErlFolderTest method setUpBeforeClass.
@BeforeClass
public static void setUpBeforeClass() throws Exception {
ErlModelTestBase.setUpBeforeClass();
IErlFolderTest.project2 = ErlModelTestBase.projects[1];
final IProject workspaceProject = IErlFolderTest.project2.getWorkspaceProject();
final String src = "src";
final IFolder folder = workspaceProject.getFolder(src);
final String below = "below";
final IFolder folder2 = folder.getFolder(below);
ErlideTestUtils.createFolderHelper(folder2);
final IPath belowPath = new Path(src).append(below);
final Collection<IPath> sourceDirs = Lists.newArrayList(belowPath);
((ErlProject) IErlFolderTest.project2).setSourceDirs(sourceDirs);
}
use of org.erlide.engine.internal.model.root.ErlProject in project erlide_eclipse by erlang.
the class ModelUtilsTest method findExternalIncludeFromPath.
@Test
public void findExternalIncludeFromPath() 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 = "external1.hrl";
externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-define(EX, ex).\n");
final String absolutePath = externalFile.getAbsolutePath();
final String externalsFileName = "x.erlidex";
final File externalsFile = ErlideTestUtils.createTmpFile(externalsFileName, absolutePath + "\n");
((ErlProject) project).setExternalIncludesFile(externalsFile.getAbsolutePath());
project.open(null);
System.out.println("##### " + project);
// when
// looking for it
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
final IErlModule module = modelFindService.findInclude(model, project, null, externalFileName, absolutePath);
// 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.internal.model.root.ErlProject in project erlide_eclipse by erlang.
the class ModelUtilsTest method getExternalModuleWithPrefix.
@Test
public void getExternalModuleWithPrefix() 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 = "external3.erl";
externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-module(external3).\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 via prefix
final List<String> moduleNames0 = modelUtilService.findUnitsWithPrefix("ex", project, false, false);
final List<String> modules1 = modelUtilService.findUnitsWithPrefix("ex", project, true, false);
final List<String> listModules = modelUtilService.findUnitsWithPrefix("list", project, true, false);
// then
// we should find it iff we check externals
assertEquals(0, moduleNames0.size());
assertEquals(1, modules1.size());
assertEquals(SystemConfiguration.withoutExtension(externalFileName), modules1.get(0));
assertEquals(1, listModules.size());
assertEquals("lists", listModules.get(0));
} finally {
if (externalFile != null && externalFile.exists()) {
externalFile.delete();
}
if (project != null) {
ErlideTestUtils.deleteProject(project);
}
}
}
use of org.erlide.engine.internal.model.root.ErlProject in project erlide_eclipse by erlang.
the class ModelUtilsTest method getModuleFromExternalModulePath.
@Test
public void getModuleFromExternalModulePath() 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 = "external4.erl";
externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-module(external4).\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 with its external module path
final IErlModel model = ErlangEngine.getInstance().getModel();
final IErlModule module = modelFindService.findModule(model, null, null, absolutePath, IErlElementLocator.Scope.ALL_PROJECTS);
assertNotNull(module);
final String externalModulePath = ErlangEngine.getInstance().getModelUtilService().getExternalModulePath(model, module);
System.out.println(" >> %s" + externalModulePath);
final IErlModule module2 = modelUtilService.getModuleFromExternalModulePath(model, externalModulePath);
// then
// we should find it
assertNotNull(module2);
assertEquals(externalFileName, module.getName());
assertEquals(module, module2);
} finally {
if (externalFile != null && externalFile.exists()) {
externalFile.delete();
}
if (project != null) {
ErlideTestUtils.deleteProject(project);
}
}
}
Aggregations