use of org.erlide.engine.model.root.IErlModule 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);
}
}
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class ErlProjectTest method findFunctionInExternalFilesTest.
@Test
public void findFunctionInExternalFilesTest() throws Exception {
// given
// a module with calls to the lists module
final IErlProject project = ErlProjectTest.projects[0];
final IErlModule moduleE = ErlideTestUtils.createModule(project, "e.erl", "-module(e).\n-export([f/0]).\nf() ->\n lists:reverse([1, 0]),\n lists:reverse([1, 0], [2]).\n");
final ScannerService scanner = moduleE.getScanner();
try {
moduleE.open(null);
// when
// looking for lists:reverse/2 and lists:reverse/1
final IErlModel model = ErlangEngine.getInstance().getModel();
final OpenResult res = ErlangEngine.getInstance().getOpenService().open(moduleE.getScannerName(), 49, ErlangEngine.getInstance().getModelUtilService().getImportsAsList(moduleE), project.getProperties().getExternalModules(), model.getPathVars());
final IErlFunction function = ErlangEngine.getInstance().getModelFindService().findFunction(model, project, moduleE, res.getName(), res.getPath(), res.getFunction(), IErlElementLocator.Scope.PROJECT_ONLY);
assertNotNull(function);
final IErlElement module = model.findModuleFromProject(project, function.getModuleName(), res.getPath(), IErlElementLocator.Scope.PROJECT_ONLY);
// then
// the function should be returned and the module, in External Files
assertNotNull(module);
assertEquals(function.getParent(), module);
assertEquals(ErlangEngine.getInstance().getModelUtilService().getProject(function), project);
} finally {
scanner.dispose();
}
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class ErlProjectTest method findIncludeFile.
@Test
public void findIncludeFile() throws Exception {
// given
// a project with a module and an include including file.hrl
final IErlProject project = ErlProjectTest.projects[0];
final String includeName = "a.hrl";
final IErlModule include = ErlideTestUtils.createModule(project, includeName, "-include_lib(\"kernel/include/file.hrl\").\n-record(rec1, {field, another=def}).\n-define(MACRO(A), lists:reverse(A)).\n");
include.open(null);
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);
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
// when
// looking for the include
final IErlModule include1 = model.findIncludeFromModule(module, includeName, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule include2 = model.findIncludeFromProject(project, "file.hrl", null, IErlElementLocator.Scope.PROJECT_ONLY);
// then
// it should be found
assertEquals(include, include1);
assertNotNull(include2);
}
use of org.erlide.engine.model.root.IErlModule 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.model.root.IErlModule in project erlide_eclipse by erlang.
the class IErlElementTest method getCorrespondingResource.
// IResource getCorrespondingResource();
@Test
public void getCorrespondingResource() throws Exception {
project.open(null);
final IProject workspaceProject = project.getWorkspaceProject();
final IFolder srcFolder = workspaceProject.getFolder("src");
final IFile file = srcFolder.getFile("xx.erl");
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
final IErlModule otpFile = model.findModuleFromProject(project, "file.erl", null, IErlElementLocator.Scope.PROJECT_ONLY);
module.open(null);
final IErlElement element = module.getElementAtLine(3);
assertEquals(file, module.getCorrespondingResource());
assertNull(otpFile.getCorrespondingResource());
assertNull(element.getCorrespondingResource());
}
Aggregations