use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class ModelUtilsTest method getPreprocessorDefs.
@Test
public void getPreprocessorDefs() throws Exception {
final IErlProject project = ModelUtilsTest.projects[0];
final IErlModule module = ErlideTestUtils.createModule(project, "a.erl", "-module(g).\n" + "-include_lib(\"kernel/include/file.hrl\").\n" + "-export([f/0]).\n" + "-define(A(B), '++B++').\n" + "-record(rec2, {a, b}).\n" + "f() ->\n" + " lists:reverse([1, 0]),\n" + " lists:reverse([1, 0], [2]).\n");
module.open(null);
final List<IErlPreprocessorDef> macroDefs = ErlangCompletionService.getAllPreprocessorDefs(module, ErlElementKind.MACRO_DEF);
final List<IErlPreprocessorDef> recordDefs = ErlangCompletionService.getAllPreprocessorDefs(module, ErlElementKind.RECORD_DEF);
assertEquals(2, macroDefs.size());
assertEquals(3, recordDefs.size());
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class ModelUtilsTest method findPreprocessorDefExternalIncludePathTest.
@Test
public void findPreprocessorDefExternalIncludePathTest() throws Exception {
File externalInclude = null;
IErlProject project = null;
// contains a record def
try {
final String projectName = "testprojectx";
project = ErlideTestUtils.createErlProject(projectName);
final IErlModule module = ErlideTestUtils.createModule(project, "a.erl", "-include(\"y.hrl\").\n");
final String includeName = "y.hrl";
externalInclude = ErlideTestUtils.createTmpFile(includeName, "-record(rec2, {field, another=def}.");
final String includePath = externalInclude.getAbsolutePath();
final String externalsFileName = "x.erlidex";
final File externalsFile = ErlideTestUtils.createTmpFile(externalsFileName, includePath);
((ErlProject) project).setExternalIncludesFile(externalsFile.getAbsolutePath());
project.open(null);
// when
// looking for the record def
final IErlPreprocessorDef preprocessorDef = modelFindService.findPreprocessorDef(module, "rec2", ErlElementKind.RECORD_DEF);
final Collection<IErlProject> myprojects = Lists.newArrayList(project);
modelFindService.findPreprocessorDef(myprojects, "a.erl", "rec2", ErlElementKind.RECORD_DEF);
// then
// it should be found
assertNotNull(preprocessorDef);
} finally {
if (project != null) {
ErlideTestUtils.deleteProject(project);
}
if (externalInclude != null && externalInclude.exists()) {
externalInclude.delete();
}
}
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class ModelUtilsTest method getModulesWithReferencedProjectsWithPrefix.
@Test
public void getModulesWithReferencedProjectsWithPrefix() throws Exception {
// given
// two erlang projects, the first references the second, second has
// an erlang module
final IProject project = ModelUtilsTest.projects[0].getWorkspaceProject();
final IProjectDescription description = project.getDescription();
final IProject[] refs = { ModelUtilsTest.projects[1].getWorkspaceProject() };
description.setReferencedProjects(refs);
project.setDescription(description, null);
final IErlModule module = ErlideTestUtils.createModule(ModelUtilsTest.projects[1], "abc.erl", "-module(abc).\n-export(f/0)\nf() ->\n {abc, ok}.\n");
ErlideTestUtils.createModule(ModelUtilsTest.projects[0], "bbc.erl", "-module(bbc).\n-export(f/0)\nf() ->\n {abc, ok}.\n");
// when
// looking for module with prefix, it should be found
final List<String> moduleNames = modelUtilService.findUnitsWithPrefix("a", ModelUtilsTest.projects[0], false, false);
// then
// we should find it
assertNotNull(moduleNames);
assertEquals(1, moduleNames.size());
assertEquals(module.getModuleName(), moduleNames.get(0));
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class ModelUtilsTest method findPreprocessorDefOtpIncludeTest.
@Test
public void findPreprocessorDefOtpIncludeTest() throws Exception {
// given
// a module with includes and record
final IErlProject project = ModelUtilsTest.projects[0];
final IErlModule module = ErlideTestUtils.createModule(project, "g.erl", "-module(g).\n-include_lib(\"kernel/include/file.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 record
final IErlPreprocessorDef preprocessorDef = modelFindService.findPreprocessorDef(module, "file_info", ErlElementKind.RECORD_DEF);
// then
// the record should be returned
assertNotNull(module);
assertNotNull(preprocessorDef);
assertTrue(preprocessorDef instanceof IErlRecordDef);
assertEquals(ErlangEngine.getInstance().getModelUtilService().getProject(preprocessorDef), project);
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class ModelUtilsTest method findPreprocessorDefExternalIncludeOnIncludePathTest.
@Test
public void findPreprocessorDefExternalIncludeOnIncludePathTest() throws Exception {
File externalInclude = null;
IErlProject project = null;
// given
// a project with an include dir outside the model, the include file
// contains a record def
final String projectName = "testprojectx";
try {
// ErlModelCache.getDefault().setNoModelCache(true);
// ErlModelCache.getDefault().clearModelCache();
project = ErlideTestUtils.createErlProject(projectName);
final IErlModule module = ErlideTestUtils.createModule(project, "a.erl", "-include(\"z.hrl\").\n");
final String includeName = "z.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));
project.open(null);
// when
// looking for the record def
final IErlPreprocessorDef preprocessorDef = modelFindService.findPreprocessorDef(module, "rec2", ErlElementKind.RECORD_DEF);
final Collection<IErlProject> myprojects = Lists.newArrayList(project);
ErlangEngine.getInstance().getModelFindService().findPreprocessorDef(myprojects, "a.erl", "rec2", ErlElementKind.RECORD_DEF);
// then
// it should be found
assertNotNull(preprocessorDef);
} finally {
if (project != null) {
ErlideTestUtils.deleteProject(project);
}
if (externalInclude != null && externalInclude.exists()) {
externalInclude.delete();
}
new File(ErlideTestUtils.getTmpPath(projectName).removeLastSegments(1).toPortableString()).delete();
// ErlModelCache.getDefault().setNoModelCache(false);
}
}
Aggregations