use of org.erlide.engine.internal.model.root.ErlProject in project erlide_eclipse by erlang.
the class IErlProjectTest method getExternalIncludes.
// Collection<IErlModule> getExternalIncludes() throws ErlModelException;
// void setExternalIncludesFile(String absolutePath)
// throws BackingStoreException;
@Test
public void getExternalIncludes() throws Exception {
File externalFile = null;
File externalsFile = null;
final IErlProject aProject = ErlModelTestBase.projects[0];
final String externalIncludesString = aProject.getProperties().getExternalIncludes();
try {
// given
// an erlang project and an external file not in any project
final String externalFileName = "external.hrl";
externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-define(E, hej).\n");
final String absolutePath = externalFile.getAbsolutePath();
final String externalsFileName = IErlProjectTest.XX_ERLIDEX;
externalsFile = ErlideTestUtils.createTmpFile(externalsFileName, absolutePath);
aProject.open(null);
final Collection<IErlModule> otpIncludes = aProject.getExternalIncludes();
((ErlProject) aProject).setExternalIncludesFile(externalsFile.getAbsolutePath());
aProject.open(null);
// when
// fetching all external includes
final Collection<IErlModule> externalIncludes = aProject.getExternalIncludes();
// then
// the external file should be returned
final Set<IErlModule> otpSet = Sets.newHashSet(otpIncludes);
final Set<IErlModule> externalSet = Sets.newHashSet(externalIncludes);
final Set<IErlModule> difference = Sets.difference(externalSet, otpSet);
assertEquals(1, difference.size());
final IErlModule externalInclude = difference.iterator().next();
assertNotNull(externalInclude);
assertEquals(absolutePath, externalInclude.getFilePath());
} finally {
if (externalFile != null && externalFile.exists()) {
externalFile.delete();
}
if (externalsFile != null && externalsFile.exists()) {
externalsFile.delete();
}
((ErlProject) aProject).setExternalIncludesFile(externalIncludesString);
}
}
use of org.erlide.engine.internal.model.root.ErlProject in project erlide_eclipse by erlang.
the class ErlProjectTest method findExternalIncludeFileOnIncludePath.
@Test
public void findExternalIncludeFileOnIncludePath() throws Exception {
File externalInclude = null;
IErlProject project = null;
// a project with an include dir outside the model
try {
final String projectName = "testprojectx";
project = ErlideTestUtils.createErlProject(projectName);
final String includeName = "x.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));
// when
// looking for the include file
// String includeFile =
// ErlangEngine.getInstance().getModelUtilService().findIncludeFile(erlProject,
// "x.hrl", "");
project.open(null);
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
final IErlModule module = model.findIncludeFromProject(project, null, includePath, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final IErlModule module2 = model.findModuleFromProject(project, includeName, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
// then
// it should be found in the model
assertNotNull(module);
assertEquals(module, module2);
} 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 ErlProjectTest method findIncludeFileOnIncludePathInOtherProject.
@Test
public void findIncludeFileOnIncludePathInOtherProject() throws Exception {
// http://www.assembla.com/spaces/erlide/tickets/756-navigation--external-include-files-are-not-found
IErlModule externalInclude = null;
IErlProject project = null;
IErlProject project2 = null;
// a project with an include dir outside the model
try {
final String projectName = "testprojectx";
project = ErlideTestUtils.createErlProject(projectName);
final String projectName2 = "testprojecty";
project2 = ErlideTestUtils.createErlProject(projectName2);
final String includeName = "x.hrl";
externalInclude = ErlideTestUtils.createInclude(project2, "x.hrl", "-record(rec2, {field, another=def}.");
final String includePath = externalInclude.getFilePath();
final IPath p = new Path(includePath).removeLastSegments(1);
((ErlProject) project).setIncludeDirs(Lists.newArrayList(p));
// when
// looking for the include file
project.open(null);
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
final IErlModule module = model.findIncludeFromProject(project, includeName, null, IErlElementLocator.Scope.ALL_PROJECTS);
// then
// it should be found in the project defining it
assertNotNull(module);
assertEquals(project2, ErlangEngine.getInstance().getModelUtilService().getProject(module));
} finally {
if (project != null) {
ErlideTestUtils.deleteProject(project);
}
if (project2 != null) {
ErlideTestUtils.deleteProject(project2);
}
}
}
use of org.erlide.engine.internal.model.root.ErlProject 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);
}
}
use of org.erlide.engine.internal.model.root.ErlProject in project erlide_eclipse by erlang.
the class IErlModelTest method findInclude_preferProjectFile.
@Test
public void findInclude_preferProjectFile() 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, both have same name
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 IErlProject project1 = ErlModelTestBase.projects[1];
final IErlModule referencedInclude = ErlideTestUtils.createInclude(project1, xxHrl, "-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 IProjectDescription description = workspaceProject.getDescription();
description.setReferencedProjects(new IProject[] { project1.getWorkspaceProject() });
workspaceProject.setDescription(description, null);
aProject.open(null);
final IErlModule x4 = model.findIncludeFromProject(aProject, xx, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule x5 = model.findIncludeFromProject(aProject, xx, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule x6 = model.findIncludeFromProject(aProject, xx, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
// then
// the non-external should be preferred
assertNotNull(x1);
assertEquals(xxHrl, x1.getName());
assertNotSame(referencedInclude, x1);
assertEquals(referencedInclude, x2);
assertNotNull(x3);
assertEquals(xxHrl, x3.getName());
assertNotSame(referencedInclude, x3);
assertNotNull(x4);
assertNotSame(referencedInclude, x4);
assertEquals(referencedInclude, x5);
assertEquals(referencedInclude, x6);
} 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