use of org.erlide.engine.model.root.IErlProject in project erlide_eclipse by erlang.
the class ModelUtilsTest method findPreprocessorDefTest.
@Test
public void findPreprocessorDefTest() throws Exception {
// given
// a module with includes and record
final IErlProject project = ModelUtilsTest.projects[0];
final IErlModule include = ErlideTestUtils.createInclude(project, "a.hrl", "-record(rec1, {field, another=def}).\n-define(MACRO(A), lists:reverse(A)).\n");
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);
project.open(null);
final IErlPreprocessorDef preprocessorDef1 = modelFindService.findPreprocessorDef(module, "rec1", ErlElementKind.RECORD_DEF);
final IErlPreprocessorDef preprocessorDef2 = modelFindService.findPreprocessorDef(include, "rec1", ErlElementKind.RECORD_DEF);
final IErlPreprocessorDef preprocessorDef3 = modelFindService.findPreprocessorDef(Arrays.asList(ModelUtilsTest.projects), "f.erl", "rec2", ErlElementKind.RECORD_DEF);
// then
// the record should be returned
assertNotNull(module);
assertNotNull(preprocessorDef1);
assertTrue(preprocessorDef1 instanceof IErlRecordDef);
assertEquals(preprocessorDef1, preprocessorDef2);
assertEquals(preprocessorDef1.getParent(), include);
assertNotNull(preprocessorDef3);
assertEquals(preprocessorDef3.getParent(), module);
}
use of org.erlide.engine.model.root.IErlProject 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.IErlProject 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.IErlProject 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.IErlProject 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