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);
}
}
}
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 ErlModel method createErlangProject.
private IErlProject createErlangProject(final IProject project) {
final IErlProject ep = new ErlProject(project, this);
addChild(ep);
final ErlModelCache cache = getModelCache();
cache.newProjectCreated();
return ep;
}
use of org.erlide.engine.internal.model.root.ErlProject in project erlide_eclipse by erlang.
the class IErlModelTest method findIncludeFromModule.
// IErlModule findIncludeFromModule(IErlModule module, String includeName,
// String includePath, Scope scope) throws ErlModelException;
@Test
public void findIncludeFromModule() throws Exception {
File externalIncludeFile = null;
final IErlProject myProject = ErlModelTestBase.projects[0];
final IProject workspaceProject = myProject.getWorkspaceProject();
final IProject[] referencedProjects = workspaceProject.getReferencedProjects();
final Collection<IPath> includeDirs = myProject.getProperties().getIncludeDirs();
// directory as the module
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) myProject).setIncludeDirs(newIncludeDirs);
final IErlModule include = ErlideTestUtils.createInclude(myProject, "yy.hrl", "-define(Y, include).\n");
final IErlProject project1 = ErlModelTestBase.projects[1];
final IErlModule referencedInclude = ErlideTestUtils.createInclude(project1, "zz.hrl", "-define(Z, referenced).\n");
final IErlModule includeInModuleDir = ErlideTestUtils.createModule(myProject, "ww.hrl", "-define(WW, x).\n");
myProject.open(null);
// when
// looking for includes
final String xx = "xx";
final IErlModule x1 = model.findIncludeFromModule(module, xx, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule x2 = model.findIncludeFromModule(module, xx, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule x3 = model.findIncludeFromModule(module, xx, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final String yy = "yy";
final IErlModule y1 = model.findIncludeFromModule(module, yy, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule y2 = model.findIncludeFromModule(module, yy, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule y3 = model.findIncludeFromModule(module, yy, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final String zz = "zz";
final IErlModule z1 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule z2 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule z3 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final IProjectDescription description = workspaceProject.getDescription();
description.setReferencedProjects(new IProject[] { project1.getWorkspaceProject() });
workspaceProject.setDescription(description, null);
myProject.open(null);
final IErlModule z4 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule z5 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule z6 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final String ww = "ww";
final IErlModule w1 = model.findIncludeFromModule(module, ww, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlElementLocator mymodel = ErlangEngine.getInstance().getModel();
final IErlModule w2 = mymodel.findIncludeFromProject(myProject, ww, null, IErlElementLocator.Scope.PROJECT_ONLY);
// 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(z1);
assertEquals(referencedInclude, z2);
assertNull(z3);
assertNull(z4);
assertEquals(referencedInclude, z5);
assertEquals(referencedInclude, z6);
assertEquals(includeInModuleDir, w1);
assertNull(w2);
} finally {
if (externalIncludeFile != null && externalIncludeFile.exists()) {
externalIncludeFile.delete();
}
((ErlProject) myProject).setIncludeDirs(includeDirs);
final IProjectDescription description = workspaceProject.getDescription();
description.setReferencedProjects(referencedProjects);
workspaceProject.setDescription(description, null);
}
}
Aggregations