Search in sources :

Example 26 with IErlElementLocator

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;
}
Also used : ErlElementKind(org.erlide.engine.model.ErlElementKind) IErlRecordDef(org.erlide.engine.model.erlang.IErlRecordDef) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) ISourceReference(org.erlide.engine.model.erlang.ISourceReference) ISourceRange(org.erlide.engine.model.erlang.ISourceRange)

Example 27 with IErlElementLocator

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);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) File(java.io.File) Test(org.junit.Test)

Example 28 with IErlElementLocator

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();
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlTypespec(org.erlide.engine.model.erlang.IErlTypespec) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) ScannerService(org.erlide.engine.services.parsing.ScannerService) Test(org.junit.Test)

Example 29 with IErlElementLocator

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();
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) File(java.io.File) Test(org.junit.Test)

Example 30 with IErlElementLocator

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);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) Test(org.junit.Test)

Aggregations

IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)33 IErlModule (org.erlide.engine.model.root.IErlModule)26 Test (org.junit.Test)17 IErlProject (org.erlide.engine.model.root.IErlProject)13 ErlProject (org.erlide.engine.internal.model.root.ErlProject)8 File (java.io.File)7 IFile (org.eclipse.core.resources.IFile)7 IErlElement (org.erlide.engine.model.IErlElement)6 IProject (org.eclipse.core.resources.IProject)5 IPath (org.eclipse.core.runtime.IPath)5 Path (org.eclipse.core.runtime.Path)5 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)3 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)3 IFolder (org.eclipse.core.resources.IFolder)3 CoreException (org.eclipse.core.runtime.CoreException)3 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)3 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)2 ArrayList (java.util.ArrayList)2 IMarker (org.eclipse.core.resources.IMarker)2 IResource (org.eclipse.core.resources.IResource)2