Search in sources :

Example 71 with IErlModule

use of org.erlide.engine.model.root.IErlModule 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 72 with IErlModule

use of org.erlide.engine.model.root.IErlModule 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 73 with IErlModule

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

the class IErlModelTest method findModule_namePath.

// IErlModule findModule(String moduleName, String modulePath)
// throws ErlModelException;
@Test
public void findModule_namePath() throws Exception {
    final IErlModule findModule = model.findModule("xx", null);
    final IErlModule findModule2 = model.findModule("xx.erl", null);
    final String filePath = module.getFilePath();
    final IErlModule findModule3 = model.findModule(null, filePath);
    final IErlModule findModule4 = model.findModule("apa", filePath);
    assertEquals(module, findModule);
    assertEquals(module, findModule2);
    assertEquals(module, findModule3);
    assertEquals(module, findModule4);
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) Test(org.junit.Test)

Example 74 with IErlModule

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

the class IErlModelTest method addModelChangeListener.

// void addModelChangeListener(IErlModelChangeListener listener);
// void removeModelChangeListener(IErlModelChangeListener listener);
@Test
public void addModelChangeListener() throws Exception {
    final List<IErlElement> changed = Lists.newArrayList();
    final IErlModelChangeListener listener = new IErlModelChangeListener() {

        @Override
        public void elementChanged(final IErlElement element) {
            changed.add(element);
        }
    };
    final IErlModule module2 = ErlideTestUtils.createModule(project, "zz.erl", "-module(zz).\n");
    final IErlModule module3 = ErlideTestUtils.createModule(project, "tt.erl", "-module(tt).\n");
    model.addModelChangeListener(listener);
    module2.open(null);
    model.removeModelChangeListener(listener);
    module3.open(null);
    final List<IErlElement> changed2 = Lists.newArrayList(changed);
    changed.clear();
    final List<IErlElement> changed3 = Lists.newArrayList(changed);
    changed.clear();
    assertEquals(1, changed2.size());
    assertEquals(0, changed3.size());
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlModule(org.erlide.engine.model.root.IErlModule) IErlModelChangeListener(org.erlide.engine.model.root.IErlModelChangeListener) Test(org.junit.Test)

Example 75 with IErlModule

use of org.erlide.engine.model.root.IErlModule 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

IErlModule (org.erlide.engine.model.root.IErlModule)191 Test (org.junit.Test)66 IErlProject (org.erlide.engine.model.root.IErlProject)57 IErlElement (org.erlide.engine.model.IErlElement)35 IFile (org.eclipse.core.resources.IFile)26 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)26 ErlModelException (org.erlide.engine.model.ErlModelException)22 IPath (org.eclipse.core.runtime.IPath)21 ErlProject (org.erlide.engine.internal.model.root.ErlProject)21 File (java.io.File)20 IErlModel (org.erlide.engine.model.root.IErlModel)18 Path (org.eclipse.core.runtime.Path)17 IProject (org.eclipse.core.resources.IProject)16 IResource (org.eclipse.core.resources.IResource)14 ArrayList (java.util.ArrayList)13 CoreException (org.eclipse.core.runtime.CoreException)10 IEditorPart (org.eclipse.ui.IEditorPart)10 IParent (org.erlide.engine.model.IParent)10 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)9 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)9