use of org.erlide.engine.model.root.IErlElementLocator 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.IErlElementLocator 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.IErlElementLocator 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.IErlElementLocator 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());
}
use of org.erlide.engine.model.root.IErlElementLocator in project erlide_eclipse by erlang.
the class ErlangElementImageProvider method computeDescriptor.
private ImageDescriptor computeDescriptor(final Object element, final int flags) {
if (element instanceof IErlElement) {
return ErlangElementImageProvider.getErlImageDescriptor((IErlElement) element, flags);
} else if (element instanceof IFile) {
final IFile file = (IFile) element;
if ("erl".equals(file.getFileExtension())) {
// $NON-NLS-1$
return getErlResourceImageDescriptor(file, flags);
// image for a CU not on the build path
}
return getWorkbenchImageDescriptor(file, flags);
} else if (element instanceof IFolder) {
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
final IErlFolder ef = (IErlFolder) model.findElement((IResource) element);
if (ef != null && (ef.isOnSourcePath() || ef.isOnIncludePath())) {
return ErlangElementImageProvider.getErlImageDescriptor(ef, flags);
}
} else if (element instanceof IAdaptable) {
return getWorkbenchImageDescriptor((IAdaptable) element, flags);
}
return null;
}
Aggregations