use of org.erlide.engine.model.root.IErlElementLocator in project erlide_eclipse by erlang.
the class OpenUtils method findOpenResult.
public Object findOpenResult(final ITextEditor editor, final IErlModule module, final IErlProject project, final OpenResult openResult, final IErlElement element) throws CoreException, ErlModelException, OtpErlangRangeException, RpcException, BadLocationException {
final IErlElementLocator.Scope scope = NavigationPreferencePage.getCheckAllProjects() ? IErlElementLocator.Scope.ALL_PROJECTS : IErlElementLocator.Scope.REFERENCED_PROJECTS;
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
Object found = null;
if (openResult.isExternalCall()) {
found = findExternalCallOrType(module, openResult, project, element, scope);
} else if (openResult.isInclude()) {
found = modelFindService.findInclude(model, project, module, openResult.getName(), openResult.getPath());
} else if (openResult.isLocalCall()) {
found = findLocalCall(module, project, openResult, element, scope);
} else if (openResult.isVariable() && element instanceof ISourceReference) {
final ISourceReference sref = (ISourceReference) element;
final ISourceRange range = sref.getSourceRange();
final String elementText = editor.getDocumentProvider().getDocument(editor.getEditorInput()).get(range.getOffset(), range.getLength());
found = modelFindService.findVariable(range, openResult.getName(), elementText);
} else if (openResult.isRecord() || openResult.isMacro()) {
final ErlElementKind kind = openResult.isMacro() ? ErlElementKind.MACRO_DEF : ErlElementKind.RECORD_DEF;
found = modelFindService.findPreprocessorDef(module, openResult.getName(), kind);
} else if (openResult.isField()) {
final IErlRecordDef def = (IErlRecordDef) modelFindService.findPreprocessorDef(module, openResult.getFun(), ErlElementKind.RECORD_DEF);
if (def != null) {
found = def.getFieldNamed(openResult.getName());
}
}
return found;
}
use of org.erlide.engine.model.root.IErlElementLocator in project erlide_eclipse by erlang.
the class ModelUtilsTest method findExternalIncludeFromPath.
@Test
public void findExternalIncludeFromPath() throws Exception {
File externalFile = null;
IErlProject project = null;
try {
// given
// an erlang project and an external file not in any project
project = ErlideTestUtils.createErlProject("testproject");
final String externalFileName = "external1.hrl";
externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-define(EX, ex).\n");
final String absolutePath = externalFile.getAbsolutePath();
final String externalsFileName = "x.erlidex";
final File externalsFile = ErlideTestUtils.createTmpFile(externalsFileName, absolutePath + "\n");
((ErlProject) project).setExternalIncludesFile(externalsFile.getAbsolutePath());
project.open(null);
System.out.println("##### " + project);
// when
// looking for it
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
final IErlModule module = modelFindService.findInclude(model, project, null, externalFileName, absolutePath);
// then
// we should find it
assertThat(module).isNotNull();
assertThat(externalFileName).isEqualTo(module.getName());
} 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 ModelUtilsTest method findExternalTypeTest.
@Test
public void findExternalTypeTest() throws Exception {
// given
// an Erlang module with typedef
final IErlModule moduleB = ErlideTestUtils.createModule(ModelUtilsTest.projects[0], "bx.erl", "-module(bx).\n-type concat_thing() :: atom() | integer() | float() | string().\n");
// final IErlModule moduleC =
// ErlideTestUtils.createErlModule(projects[1],
// "c.erl", "-module(c).\n-type cc() :: b:concat_thing().\n");
final ScannerService scanner = moduleB.getScanner();
try {
moduleB.open(null);
ModelUtilsTest.projects[0].open(null);
// moduleC.open(null);
// when
// looking for it
// within project
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
final IErlElement element1 = modelFindService.findTypeDef(model, ModelUtilsTest.projects[0], moduleB, "bx", "concat_thing", moduleB.getResource().getLocation().toPortableString(), IErlElementLocator.Scope.PROJECT_ONLY);
// in other project but path given
final IErlElement element2 = modelFindService.findTypeDef(model, ModelUtilsTest.projects[1], moduleB, "bx", "concat_thing", moduleB.getResource().getLocation().toPortableString(), IErlElementLocator.Scope.PROJECT_ONLY);
// in other project no path given, search all projects true
final IErlElement element3 = modelFindService.findTypeDef(model, ModelUtilsTest.projects[1], moduleB, "bx", "concat_thing", null, IErlElementLocator.Scope.ALL_PROJECTS);
// in other project no path given, search all projects false, ->
// null
final IErlElement element4 = modelFindService.findTypeDef(model, ModelUtilsTest.projects[1], moduleB, "bx", "concat_thing", null, IErlElementLocator.Scope.PROJECT_ONLY);
// then
// it should be returned if found
assertTrue(element1 instanceof IErlTypespec);
assertNull(element2);
assertTrue(element3 instanceof IErlTypespec);
assertNull(element4);
} finally {
scanner.dispose();
}
}
use of org.erlide.engine.model.root.IErlElementLocator 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.model.root.IErlElementLocator 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);
}
}
}
Aggregations