use of org.erlide.engine.model.root.IErlProject 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.model.root.IErlProject 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);
}
}
}
use of org.erlide.engine.model.root.IErlProject in project erlide_eclipse by erlang.
the class ModelUtilsTest method findTypespec.
@Test
public void findTypespec() throws Exception {
// given
// a project with a module and an include with a typespec
final IErlProject project = ModelUtilsTest.projects[0];
final String includeName = "a.hrl";
final IErlModule include = ErlideTestUtils.createModule(project, includeName, "-type date() :: {pos_integer(), pos_integer(), pos_integer()}.\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);
// when
// looking for the typespec
final IErlTypespec typespec = modelFindService.findTypespec(module, "date");
// then
// it should be found
assertNotNull(typespec);
assertEquals(typespec.getParent(), include);
}
use of org.erlide.engine.model.root.IErlProject in project erlide_eclipse by erlang.
the class ModelUtilsTest method setUpBeforeClass.
@BeforeClass
public static void setUpBeforeClass() throws Exception {
ErlideTestUtils.initProjects();
final IErlProject erlProject1 = ErlideTestUtils.createErlProject("testproject1");
final IErlProject erlProject2 = ErlideTestUtils.createErlProject("testproject2");
ModelUtilsTest.projects = new IErlProject[] { erlProject1, erlProject2 };
}
use of org.erlide.engine.model.root.IErlProject in project erlide_eclipse by erlang.
the class IErlModelTest method findIncludeFromProject.
// IErlModule findIncludeFromProject(IErlProject project, String
// includeName, String includePath, Scope scope) throws ErlModelException;
@Test
public void findIncludeFromProject() throws Exception {
File externalIncludeFile = null;
final IErlProject aProject = ErlModelTestBase.projects[0];
final IProject workspaceProject = aProject.getWorkspaceProject();
final IProject[] referencedProjects = workspaceProject.getReferencedProjects();
final Collection<IPath> includeDirs = aProject.getProperties().getIncludeDirs();
// referenced project with an include
try {
final String xxHrl = "xx.hrl";
externalIncludeFile = ErlideTestUtils.createTmpFile(xxHrl, "-record(rec2, {field, another=def}.");
final String externalIncludePath = externalIncludeFile.getAbsolutePath();
final IPath p = new Path(externalIncludePath).removeLastSegments(1);
final List<IPath> newIncludeDirs = Lists.newArrayList(includeDirs);
newIncludeDirs.add(p);
((ErlProject) aProject).setIncludeDirs(newIncludeDirs);
final IErlModule include = ErlideTestUtils.createInclude(aProject, "yy.hrl", "-define(Y, include).\n");
final IErlProject project1 = ErlModelTestBase.projects[1];
final IErlModule referencedInclude = ErlideTestUtils.createInclude(project1, "zz.hrl", "-define(Z, referenced).\n");
aProject.open(null);
// when
// looking for includes
final String xx = "xx";
final IErlModule x1 = model.findIncludeFromProject(aProject, xx, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule x2 = model.findIncludeFromProject(aProject, xx, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule x3 = model.findIncludeFromProject(aProject, xx, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final String yy = "yy";
final IErlModule y1 = model.findIncludeFromProject(aProject, yy, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule y2 = model.findIncludeFromProject(aProject, yy, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule y3 = model.findIncludeFromProject(aProject, yy, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final IErlModule y4 = model.findIncludeFromProject(project1, yy, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule y5 = model.findIncludeFromProject(project1, yy, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule y6 = model.findIncludeFromProject(project1, yy, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final String zz = "zz";
final IErlModule z1 = model.findIncludeFromProject(aProject, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule z2 = model.findIncludeFromProject(aProject, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule z3 = model.findIncludeFromProject(aProject, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final IProjectDescription description = workspaceProject.getDescription();
description.setReferencedProjects(new IProject[] { project1.getWorkspaceProject() });
workspaceProject.setDescription(description, null);
aProject.open(null);
final IErlModule z4 = model.findIncludeFromProject(aProject, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule z5 = model.findIncludeFromProject(aProject, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule z6 = model.findIncludeFromProject(aProject, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
// then
// scope should be respected
assertNotNull(x1);
assertEquals(xxHrl, x1.getName());
assertNotNull(x2);
assertEquals(xxHrl, x2.getName());
assertNotNull(x3);
assertEquals(xxHrl, x3.getName());
assertEquals(include, y1);
assertEquals(include, y2);
assertEquals(include, y3);
assertNull(y4);
assertEquals(include, y5);
assertNull(y6);
assertNull(z1);
assertEquals(referencedInclude, z2);
assertNull(z3);
assertNull(z4);
assertEquals(referencedInclude, z5);
assertEquals(referencedInclude, z6);
} finally {
if (externalIncludeFile != null && externalIncludeFile.exists()) {
externalIncludeFile.delete();
}
((ErlProject) aProject).setIncludeDirs(includeDirs);
final IProjectDescription description = workspaceProject.getDescription();
description.setReferencedProjects(referencedProjects);
workspaceProject.setDescription(description, null);
}
}
Aggregations