Search in sources :

Example 81 with IErlModule

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

the class IErlProjectTest method getModulesAndIncludes.

// Collection<IErlModule> getModulesAndIncludes() throws ErlModelException;
@Test
public void getModulesAndIncludes() throws Exception {
    ErlideTestUtils.createInclude(ErlModelTestBase.projects[0], "bb.erl", "-module(bb).\n");
    ErlideTestUtils.createModule(ErlModelTestBase.projects[0], "cc.hrl", "-define(A, hej).\n");
    final IErlModule includeD = ErlideTestUtils.createInclude(ErlModelTestBase.projects[0], "dd.hrl", "-define(B, du).\n");
    final List<IErlModule> expected = Lists.newArrayList(module, includeD);
    final Collection<IErlModule> includes = ErlModelTestBase.projects[0].getModulesAndIncludes();
    assertEquals(expected, includes);
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) Test(org.junit.Test)

Example 82 with IErlModule

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

the class IErlProjectTest method setIncludeDirs.

// void setIncludeDirs(Collection<IPath> includeDirs)
// throws BackingStoreException;
@Test
public void setIncludeDirs() throws Exception {
    File externalFile = null;
    final IErlProject aProject = ErlModelTestBase.projects[0];
    final Collection<IPath> includeDirs = aProject.getProperties().getIncludeDirs();
    try {
        // given
        // an erlang project and an external file not in any project
        final String externalFileName = "external.hrl";
        externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-define(E, hej).\n");
        final String absolutePath = externalFile.getAbsolutePath();
        final List<IPath> newIncludeDirs = Lists.newArrayList(includeDirs);
        aProject.open(null);
        final Collection<IErlModule> otpIncludes = aProject.getExternalIncludes();
        final IPath absoluteDir = new Path(absolutePath).removeLastSegments(1);
        newIncludeDirs.add(absoluteDir);
        ((ErlProject) aProject).setIncludeDirs(newIncludeDirs);
        aProject.open(null);
        // when
        // fetching all external includes
        final Collection<IErlModule> externalIncludes = aProject.getExternalIncludes();
        // then
        // the external file should be returned
        final Set<IErlModule> otpSet = Sets.newHashSet(otpIncludes);
        final Set<IErlModule> externalSet = Sets.newHashSet(externalIncludes);
        final Set<IErlModule> difference = Sets.difference(externalSet, otpSet);
        assertEquals(1, difference.size());
        final IErlModule externalInclude = difference.iterator().next();
        assertNotNull(externalInclude);
        assertEquals(new Path(absolutePath), new Path(externalInclude.getFilePath()));
    } finally {
        if (externalFile != null && externalFile.exists()) {
            externalFile.delete();
        }
        ((ErlProject) aProject).setIncludeDirs(includeDirs);
    }
}
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) File(java.io.File) Test(org.junit.Test)

Example 83 with IErlModule

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

the class IErlProjectTest method getExternalIncludes_includeDirs.

@Test
public void getExternalIncludes_includeDirs() throws Exception {
    File externalFile = null;
    final IErlProject aProject = ErlModelTestBase.projects[0];
    final Collection<IPath> includeDirs = aProject.getProperties().getIncludeDirs();
    try {
        // given
        // an erlang project and an external file not in any project, but on
        // the include-path
        final String externalFileName = "external.hrl";
        externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-define(E, hej).\n");
        final String absolutePath = externalFile.getAbsolutePath();
        final List<IPath> newIncludeDirs = Lists.newArrayList(includeDirs);
        aProject.open(null);
        final Collection<IErlModule> otpIncludes = aProject.getExternalIncludes();
        final IPath absoluteDir = new Path(absolutePath).removeLastSegments(1);
        newIncludeDirs.add(absoluteDir);
        ((ErlProject) aProject).setIncludeDirs(newIncludeDirs);
        aProject.open(null);
        // when
        // fetching all external includes
        final Collection<IErlModule> externalIncludes = aProject.getExternalIncludes();
        // then
        // the external file should be returned
        final Set<IErlModule> otpSet = Sets.newHashSet(otpIncludes);
        final Set<IErlModule> externalSet = Sets.newHashSet(externalIncludes);
        final Set<IErlModule> difference = Sets.difference(externalSet, otpSet);
        final IErlModule externalInclude = difference.iterator().next();
        assertNotNull(externalInclude);
        assertEquals(absolutePath, externalInclude.getFilePath());
    } finally {
        if (externalFile != null && externalFile.exists()) {
            externalFile.delete();
        }
        ((ErlProject) aProject).setIncludeDirs(includeDirs);
    }
}
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) File(java.io.File) Test(org.junit.Test)

Example 84 with IErlModule

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

the class IErlProjectTest method getIncludes.

// FIXME write tests that gives exceptions!
// Collection<IErlModule> getIncludes() throws ErlModelException;
@Test
public void getIncludes() throws Exception {
    ErlideTestUtils.createModule(ErlModelTestBase.projects[0], "aa.erl", "-module(aa).\n");
    ErlideTestUtils.createInclude(ErlModelTestBase.projects[0], "bb.erl", "-module(bb).\n");
    ErlideTestUtils.createModule(ErlModelTestBase.projects[0], "cc.hrl", "-define(A, hej).\n");
    final IErlModule includeDD = ErlideTestUtils.createInclude(ErlModelTestBase.projects[0], "dd.hrl", "-define(B, du).\n");
    final List<IErlModule> expected = Lists.newArrayList(includeDD);
    final Collection<IErlModule> includes = ErlModelTestBase.projects[0].getIncludes();
    assertEquals(expected, includes);
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) Test(org.junit.Test)

Example 85 with IErlModule

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

the class IErlProjectTest method getExternalModules.

// Collection<IErlModule> getExternalModules() throws ErlModelException;
// void setExternalModulesFile(String absolutePath)
// throws BackingStoreException;
@Test
public void getExternalModules() throws Exception {
    File externalFile = null;
    File externalsFile = null;
    final IErlProject aProject = ErlModelTestBase.projects[0];
    final String externalModulesString = aProject.getProperties().getExternalModules();
    try {
        // given
        // an erlang project and an external file not in any project
        final String externalFileName = "external6.erl";
        externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-module(external6).\nf([_ | _]=L ->\n    atom_to_list(L).\n");
        final String absolutePath = externalFile.getAbsolutePath();
        externalsFile = ErlideTestUtils.createTmpFile(IErlProjectTest.XX_ERLIDEX, absolutePath);
        aProject.open(null);
        final Collection<IErlModule> otpModules = aProject.getExternalModules();
        ((ErlProject) aProject).setExternalModulesFile(externalsFile.getAbsolutePath());
        aProject.open(null);
        // when
        // fetching all external modules
        final Collection<IErlModule> externalModules = aProject.getExternalModules();
        // then
        // the external file should be returned
        final Set<IErlModule> otpSet = Sets.newHashSet(otpModules);
        final Set<IErlModule> externalSet = Sets.newHashSet(externalModules);
        final Set<IErlModule> difference = Sets.difference(externalSet, otpSet);
        assertEquals(1, difference.size());
        final IErlModule externalModule = difference.iterator().next();
        assertNotNull(externalModule);
        assertEquals(absolutePath, externalModule.getFilePath());
    } finally {
        if (externalFile != null && externalFile.exists()) {
            externalFile.delete();
        }
        if (externalsFile != null && externalsFile.exists()) {
            externalsFile.delete();
        }
        ((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) File(java.io.File) 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