use of org.erlide.engine.internal.model.root.ErlProject 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.internal.model.root.ErlProject in project erlide_eclipse by erlang.
the class ModelUtilsTest method findPreprocessorDefExternalIncludePathTest.
@Test
public void findPreprocessorDefExternalIncludePathTest() throws Exception {
File externalInclude = null;
IErlProject project = null;
// contains a record def
try {
final String projectName = "testprojectx";
project = ErlideTestUtils.createErlProject(projectName);
final IErlModule module = ErlideTestUtils.createModule(project, "a.erl", "-include(\"y.hrl\").\n");
final String includeName = "y.hrl";
externalInclude = ErlideTestUtils.createTmpFile(includeName, "-record(rec2, {field, another=def}.");
final String includePath = externalInclude.getAbsolutePath();
final String externalsFileName = "x.erlidex";
final File externalsFile = ErlideTestUtils.createTmpFile(externalsFileName, includePath);
((ErlProject) project).setExternalIncludesFile(externalsFile.getAbsolutePath());
project.open(null);
// when
// looking for the record def
final IErlPreprocessorDef preprocessorDef = modelFindService.findPreprocessorDef(module, "rec2", ErlElementKind.RECORD_DEF);
final Collection<IErlProject> myprojects = Lists.newArrayList(project);
modelFindService.findPreprocessorDef(myprojects, "a.erl", "rec2", ErlElementKind.RECORD_DEF);
// then
// it should be found
assertNotNull(preprocessorDef);
} finally {
if (project != null) {
ErlideTestUtils.deleteProject(project);
}
if (externalInclude != null && externalInclude.exists()) {
externalInclude.delete();
}
}
}
use of org.erlide.engine.internal.model.root.ErlProject in project erlide_eclipse by erlang.
the class ModelUtilsTest method findPreprocessorDefExternalIncludeOnIncludePathTest.
@Test
public void findPreprocessorDefExternalIncludeOnIncludePathTest() throws Exception {
File externalInclude = null;
IErlProject project = null;
// given
// a project with an include dir outside the model, the include file
// contains a record def
final String projectName = "testprojectx";
try {
// ErlModelCache.getDefault().setNoModelCache(true);
// ErlModelCache.getDefault().clearModelCache();
project = ErlideTestUtils.createErlProject(projectName);
final IErlModule module = ErlideTestUtils.createModule(project, "a.erl", "-include(\"z.hrl\").\n");
final String includeName = "z.hrl";
externalInclude = ErlideTestUtils.createTmpFile(includeName, "-record(rec2, {field, another=def}.");
final String includePath = externalInclude.getAbsolutePath();
final IPath p = new Path(includePath).removeLastSegments(1);
((ErlProject) project).setIncludeDirs(Lists.newArrayList(p));
project.open(null);
// when
// looking for the record def
final IErlPreprocessorDef preprocessorDef = modelFindService.findPreprocessorDef(module, "rec2", ErlElementKind.RECORD_DEF);
final Collection<IErlProject> myprojects = Lists.newArrayList(project);
ErlangEngine.getInstance().getModelFindService().findPreprocessorDef(myprojects, "a.erl", "rec2", ErlElementKind.RECORD_DEF);
// then
// it should be found
assertNotNull(preprocessorDef);
} finally {
if (project != null) {
ErlideTestUtils.deleteProject(project);
}
if (externalInclude != null && externalInclude.exists()) {
externalInclude.delete();
}
new File(ErlideTestUtils.getTmpPath(projectName).removeLastSegments(1).toPortableString()).delete();
// ErlModelCache.getDefault().setNoModelCache(false);
}
}
use of org.erlide.engine.internal.model.root.ErlProject in project erlide_eclipse by erlang.
the class IErlProjectTest method getModule.
// IErlModule getModule(String name) throws ErlModelException;
@Test
public void getModule() throws Exception {
final IErlProject aProject = ErlModelTestBase.projects[0];
final Collection<IPath> sourceDirs = aProject.getProperties().getSourceDirs();
try {
// given
// an Erlang project and a module
final IErlModule aModule = ErlideTestUtils.createModule(aProject, "aa.erl", "-module(aa).\n");
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 IErlModule module2 = aProject.getModule("aa");
final IErlModule nullModule = aProject.getModule("aa.hrl");
final IErlModule nullModule2 = aProject.getModule("AA");
final IErlModule nullModule3 = aProject.getModule("aA");
final IErlModule nullModule4 = aProject.getModule("AA.erl");
final IErlModule module4 = aProject.getModule("aa.erl");
((ErlProject) aProject).setSourceDirs(srcxDirs);
aProject.open(null);
final IErlModule srcxModule = aProject.getModule("aa");
((ErlProject) aProject).setSourceDirs(sourceDirs);
aProject.open(null);
final IErlModule module3 = aProject.getModule("aa");
// then
// the it should be returned, but not otherwise
assertEquals(aModule, module2);
assertNull(srcxModule);
assertNull(nullModule);
assertNull(nullModule2);
assertNull(nullModule3);
assertNull(nullModule4);
assertEquals(aModule, module3);
assertEquals(aModule, module4);
} finally {
((ErlProject) aProject).setSourceDirs(sourceDirs);
}
}
use of org.erlide.engine.internal.model.root.ErlProject in project erlide_eclipse by erlang.
the class ErlModelCacheTest method checkThatNewModulesInNewProjectsAreCorrect.
@Test
public void checkThatNewModulesInNewProjectsAreCorrect() throws Exception {
IErlProject project = null;
IErlProject project2 = null;
try {
// given
// a project with an external module and searching for it so the
// cache
// is updated
final String projectName = "testprojecta";
project = ErlideTestUtils.createErlProject(projectName);
final String externalName = "xyz.erl";
final File externalFile = ErlideTestUtils.createTmpFile(externalName, "-module(xyz).\nf([_ | _]=L ->\n atom_to_list(L).\n");
final String absolutePath = externalFile.getAbsolutePath();
final File externalsFile = ErlideTestUtils.createTmpFile("x.erlidex", absolutePath);
((ErlProject) project).setExternalModulesFile(externalsFile.getAbsolutePath());
project.open(null);
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
final IErlModule findModule = model.findModuleFromProject(project, externalName, null, IErlElementLocator.Scope.PROJECT_ONLY);
// final ErlModelCache cache = ErlModelCache.getDefault();
// final Set<IErlModule> modulesByName = cache
// .getModulesByName(ListsUtils
// .withoutExtension(externalName));
// when
// creating a new project with a module with the same name and
// searching
// for it
final String projectName2 = "testprojectb";
project2 = ErlideTestUtils.createErlProject(projectName2);
final IErlModule module = ErlideTestUtils.createModule(project2, externalName, "-module(xyz).\n");
final IErlModule findModule2 = model.findModuleFromProject(project, externalName, null, IErlElementLocator.Scope.ALL_PROJECTS);
// final Set<IErlModule> modulesByName2 = cache
// .getModulesByName(ListsUtils
// .withoutExtension(externalName));
// then
// the new module should be found
assertNotNull(findModule);
assertEquals(module, findModule2);
// assertTrue(modulesByName2.contains(module));
// final SetView<IErlModule> difference = Sets.difference(
// modulesByName2, modulesByName);
// assertEquals(1, difference.size());
// assertEquals(module, difference.toArray()[0]);
} finally {
if (project != null && project.exists()) {
ErlideTestUtils.deleteProject(project);
}
if (project2 != null && project2.exists()) {
ErlideTestUtils.deleteProject(project2);
}
}
}
Aggregations