Search in sources :

Example 41 with IErlProject

use of org.erlide.engine.model.root.IErlProject in project erlide_eclipse by erlang.

the class HandleEdocLinksLocationListener method changing.

@Override
public void changing(final LocationEvent event) {
    ErlangBrowserInformationControlInput input = null;
    if (control != null) {
        input = control.getInput();
    } else if (edocView != null) {
        input = edocView.getInput();
    }
    if (input != null) {
        final AbstractErlangEditor editor = input.getEditor();
        String moduleName = "";
        final Object inputElement = input.getInputElement();
        if (inputElement instanceof OpenResult) {
            final OpenResult or = (OpenResult) inputElement;
            moduleName = or.getName();
        }
        final ErlangFunctionCall functionCall = HoverUtil.eventToErlangFunctionCall(moduleName, event);
        if (functionCall != null) {
            final IErlProject project = ErlangEngine.getInstance().getModelUtilService().getProject(editor.getModule());
            if (project == null) {
                return;
            }
            final IOtpRpc backend = BackendCore.getBuildBackend(project);
            final OtpErlangTuple otpDoc = (OtpErlangTuple) ErlangEngine.getInstance().getOtpDocService().getOtpDoc(backend, functionCall);
            if (Util.isOk(otpDoc)) {
                final String docStr = Util.stringValue(otpDoc.elementAt(1));
                final StringBuffer result = new StringBuffer(docStr);
                String docPath = "";
                String anchor = "";
                if (otpDoc.arity() > 4) {
                    docPath = Util.stringValue(otpDoc.elementAt(3));
                    anchor = Util.stringValue(otpDoc.elementAt(4));
                }
                if (result.length() > 0) {
                    final String html = HoverUtil.getHTML(result);
                    final Object element = new OpenResult(otpDoc.elementAt(2));
                    input = new ErlangBrowserInformationControlInput(input, editor, element, html, 20, HoverUtil.getDocumentationURL(docPath, anchor));
                }
            }
        }
    }
    if (input != null) {
        if (control != null) {
            if (control.hasDelayedInputChangeListener()) {
                control.notifyDelayedInputChange(input);
            } else {
                control.setInput(input);
            }
        } else if (edocView != null) {
            edocView.setInfo(input);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ErlangFunctionCall(org.erlide.util.ErlangFunctionCall) OpenResult(org.erlide.engine.services.search.OpenResult) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc)

Example 42 with IErlProject

use of org.erlide.engine.model.root.IErlProject in project erlide_eclipse by erlang.

the class AbstractErlSelection method getSearchPath.

@Override
public OtpErlangList getSearchPath() {
    final IProject project = file.getProject();
    final IErlModel model = ErlangEngine.getInstance().getModel();
    final IErlProject actualProject = model.getErlangProject(project);
    final IPath projectLocation = actualProject.getWorkspaceProject().getLocation();
    final Collection<IPath> sourcDirs = actualProject.getProperties().getSourceDirs();
    final OtpErlangString[] searchPath = new OtpErlangString[sourcDirs.size()];
    int i = 0;
    for (final IPath src : sourcDirs) {
        searchPath[i++] = new OtpErlangString(projectLocation.append(src).toOSString());
    }
    return new OtpErlangList(searchPath);
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModel(org.erlide.engine.model.root.IErlModel) IPath(org.eclipse.core.runtime.IPath) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) IProject(org.eclipse.core.resources.IProject) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 43 with IErlProject

use of org.erlide.engine.model.root.IErlProject in project erlide_eclipse by erlang.

the class IErlModelTest method findIncludeFromModule.

// IErlModule findIncludeFromModule(IErlModule module, String includeName,
// String includePath, Scope scope) throws ErlModelException;
@Test
public void findIncludeFromModule() throws Exception {
    File externalIncludeFile = null;
    final IErlProject myProject = ErlModelTestBase.projects[0];
    final IProject workspaceProject = myProject.getWorkspaceProject();
    final IProject[] referencedProjects = workspaceProject.getReferencedProjects();
    final Collection<IPath> includeDirs = myProject.getProperties().getIncludeDirs();
    // directory as the module
    try {
        final String xxHrl = "xx.hrl";
        externalIncludeFile = ErlideTestUtils.createTmpFile(xxHrl, "-record(rec2, {field, another=def}.");
        final String externalIncludePath = externalIncludeFile.getAbsolutePath();
        final IPath p = new Path(externalIncludePath).removeLastSegments(1);
        final List<IPath> newIncludeDirs = Lists.newArrayList(includeDirs);
        newIncludeDirs.add(p);
        ((ErlProject) myProject).setIncludeDirs(newIncludeDirs);
        final IErlModule include = ErlideTestUtils.createInclude(myProject, "yy.hrl", "-define(Y, include).\n");
        final IErlProject project1 = ErlModelTestBase.projects[1];
        final IErlModule referencedInclude = ErlideTestUtils.createInclude(project1, "zz.hrl", "-define(Z, referenced).\n");
        final IErlModule includeInModuleDir = ErlideTestUtils.createModule(myProject, "ww.hrl", "-define(WW, x).\n");
        myProject.open(null);
        // when
        // looking for includes
        final String xx = "xx";
        final IErlModule x1 = model.findIncludeFromModule(module, xx, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule x2 = model.findIncludeFromModule(module, xx, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule x3 = model.findIncludeFromModule(module, xx, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final String yy = "yy";
        final IErlModule y1 = model.findIncludeFromModule(module, yy, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule y2 = model.findIncludeFromModule(module, yy, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule y3 = model.findIncludeFromModule(module, yy, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final String zz = "zz";
        final IErlModule z1 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule z2 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule z3 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final IProjectDescription description = workspaceProject.getDescription();
        description.setReferencedProjects(new IProject[] { project1.getWorkspaceProject() });
        workspaceProject.setDescription(description, null);
        myProject.open(null);
        final IErlModule z4 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule z5 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule z6 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final String ww = "ww";
        final IErlModule w1 = model.findIncludeFromModule(module, ww, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlElementLocator mymodel = ErlangEngine.getInstance().getModel();
        final IErlModule w2 = mymodel.findIncludeFromProject(myProject, ww, null, IErlElementLocator.Scope.PROJECT_ONLY);
        // then
        // scope should be respected
        assertNotNull(x1);
        assertEquals(xxHrl, x1.getName());
        assertNotNull(x2);
        assertEquals(xxHrl, x2.getName());
        assertNotNull(x3);
        assertEquals(xxHrl, x3.getName());
        assertEquals(include, y1);
        assertEquals(include, y2);
        assertEquals(include, y3);
        assertNull(z1);
        assertEquals(referencedInclude, z2);
        assertNull(z3);
        assertNull(z4);
        assertEquals(referencedInclude, z5);
        assertEquals(referencedInclude, z6);
        assertEquals(includeInModuleDir, w1);
        assertNull(w2);
    } finally {
        if (externalIncludeFile != null && externalIncludeFile.exists()) {
            externalIncludeFile.delete();
        }
        ((ErlProject) myProject).setIncludeDirs(includeDirs);
        final IProjectDescription description = workspaceProject.getDescription();
        description.setReferencedProjects(referencedProjects);
        workspaceProject.setDescription(description, null);
    }
}
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) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) IProject(org.eclipse.core.resources.IProject) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 44 with IErlProject

use of org.erlide.engine.model.root.IErlProject in project erlide_eclipse by erlang.

the class IErlModelTest method findModuleFromProject.

// enum Scope {
// PROJECT_ONLY, REFERENCED_PROJECTS, ALL_PROJECTS
// }
// IErlModule findModuleFromProject(IErlProject project, String moduleName,
// String modulePath, Scope scope) throws ErlModelException;
@Test
public void findModuleFromProject() throws Exception {
    File externalModuleFile = null;
    File externalsFile = null;
    final IErlProject aProject = ErlModelTestBase.projects[0];
    final IProject workspaceProject = aProject.getWorkspaceProject();
    final IProject[] referencedProjects = workspaceProject.getReferencedProjects();
    final String externalModulesString = aProject.getProperties().getExternalModules();
    // referenced project with a module
    try {
        final String xxErl = "xx.erl";
        externalModuleFile = ErlideTestUtils.createTmpFile(xxErl, "-module(xx).\n");
        final String externalModulePath = externalModuleFile.getAbsolutePath();
        externalsFile = ErlideTestUtils.createTmpFile(IErlModelTest.XX_ERLIDEX, externalModulePath);
        ((ErlProject) aProject).setExternalModulesFile(externalsFile.getAbsolutePath());
        final IErlModule aModule = ErlideTestUtils.createModule(aProject, "yy.erl", "-module(yy).\n");
        final IErlProject project1 = ErlModelTestBase.projects[1];
        final IErlModule referencedModule = ErlideTestUtils.createModule(project1, "zz.erl", "-module(zz).\n");
        aProject.open(null);
        // when
        // looking for modules
        final String xx = "xx";
        final IErlModule x1 = model.findModuleFromProject(aProject, xx, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule x2 = model.findModuleFromProject(aProject, xx, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule x3 = model.findModuleFromProject(aProject, xx, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final String yy = "yy";
        final IErlModule y1 = model.findModuleFromProject(aProject, yy, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule y2 = model.findModuleFromProject(aProject, yy, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule y3 = model.findModuleFromProject(aProject, yy, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final IErlModule y4 = model.findModuleFromProject(project1, yy, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule y5 = model.findModuleFromProject(project1, yy, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule y6 = model.findModuleFromProject(project1, yy, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final String zz = "zz";
        final IErlModule z1 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule z2 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule z3 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final IProjectDescription description = workspaceProject.getDescription();
        description.setReferencedProjects(new IProject[] { project1.getWorkspaceProject() });
        workspaceProject.setDescription(description, null);
        aProject.open(null);
        final IErlModule z4 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule z5 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule z6 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        // then
        // scope should be respected
        assertNotNull(x1);
        assertEquals(xxErl, x1.getName());
        assertNotNull(x2);
        assertEquals(xxErl, x2.getName());
        assertNotNull(x3);
        assertEquals(xxErl, x3.getName());
        assertEquals(aModule, y1);
        assertEquals(aModule, y2);
        assertEquals(aModule, y3);
        assertNull(y4);
        assertEquals(aModule, y5);
        assertNull(y6);
        assertNull(z1);
        assertEquals(referencedModule, z2);
        assertNull(z3);
        assertNull(z4);
        assertEquals(referencedModule, z5);
        assertEquals(referencedModule, z6);
    } finally {
        if (externalModuleFile != null && externalModuleFile.exists()) {
            externalModuleFile.delete();
        }
        if (externalsFile != null && externalsFile.exists()) {
            externalsFile.delete();
        }
        ((ErlProject) aProject).setExternalModulesFile(externalModulesString);
        final IProjectDescription description = workspaceProject.getDescription();
        description.setReferencedProjects(referencedProjects);
        workspaceProject.setDescription(description, null);
    }
}
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) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 45 with IErlProject

use of org.erlide.engine.model.root.IErlProject in project erlide_eclipse by erlang.

the class IErlModelTest method findModuleFromProject_preferProjectFile.

@Test
public void findModuleFromProject_preferProjectFile() throws Exception {
    File externalModuleFile = null;
    File externalsFile = null;
    final IErlProject aProject = ErlModelTestBase.projects[0];
    final IProject workspaceProject = aProject.getWorkspaceProject();
    final IProject[] referencedProjects = workspaceProject.getReferencedProjects();
    final String externalModulesString = aProject.getProperties().getExternalModules();
    // referenced project with an include, both have same name
    try {
        final String zzErl = "zz.erl";
        final String xxxContents = "-module(zz).\n";
        externalModuleFile = ErlideTestUtils.createTmpFile(zzErl, xxxContents);
        final String externalModulePath = externalModuleFile.getAbsolutePath();
        externalsFile = ErlideTestUtils.createTmpFile(IErlModelTest.XX_ERLIDEX, externalModulePath);
        ((ErlProject) aProject).setExternalModulesFile(externalsFile.getAbsolutePath());
        final IErlProject project1 = ErlModelTestBase.projects[1];
        final IErlModule referencedModule = ErlideTestUtils.createModule(project1, zzErl, xxxContents);
        aProject.open(null);
        // when
        // looking for module
        final String zz = "zz";
        final IErlModule zz1 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule zz2 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule zz3 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final IProjectDescription description = workspaceProject.getDescription();
        description.setReferencedProjects(new IProject[] { project1.getWorkspaceProject() });
        workspaceProject.setDescription(description, null);
        aProject.open(null);
        final IErlModule zz4 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule zz5 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule zz6 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        // then
        // the non-external should be preferred
        assertNotNull(zz1);
        assertEquals(zzErl, zz1.getName());
        assertNotSame(referencedModule, zz1);
        assertEquals(referencedModule, zz2);
        assertNotNull(zz3);
        assertEquals(zzErl, zz3.getName());
        assertNotSame(referencedModule, zz3);
        assertNotNull(zz4);
        assertNotSame(referencedModule, zz4);
        assertEquals(referencedModule, zz5);
        assertEquals(referencedModule, zz6);
    } finally {
        if (externalModuleFile != null && externalModuleFile.exists()) {
            externalModuleFile.delete();
        }
        if (externalsFile != null && externalsFile.exists()) {
            externalsFile.delete();
        }
        final IProjectDescription description = workspaceProject.getDescription();
        description.setReferencedProjects(referencedProjects);
        workspaceProject.setDescription(description, null);
        ((ErlProject) aProject).setExternalModulesFile(externalModulesString);
    }
}
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) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Aggregations

IErlProject (org.erlide.engine.model.root.IErlProject)123 IErlModule (org.erlide.engine.model.root.IErlModule)57 Test (org.junit.Test)47 IPath (org.eclipse.core.runtime.IPath)30 IProject (org.eclipse.core.resources.IProject)29 ErlProject (org.erlide.engine.internal.model.root.ErlProject)25 File (java.io.File)19 Path (org.eclipse.core.runtime.Path)16 CoreException (org.eclipse.core.runtime.CoreException)13 ErlModelException (org.erlide.engine.model.ErlModelException)13 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)13 IErlModel (org.erlide.engine.model.root.IErlModel)13 ArrayList (java.util.ArrayList)11 IErlElement (org.erlide.engine.model.IErlElement)10 IFile (org.eclipse.core.resources.IFile)9 IResource (org.eclipse.core.resources.IResource)9 HashSet (java.util.HashSet)7 IProjectDescription (org.eclipse.core.resources.IProjectDescription)7 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)6 IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)6