Search in sources :

Example 76 with IErlModule

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

the class IErlModuleTest method getIncludedFiles.

// Collection<ErlangIncludeFile> getIncludedFiles() throws
// ErlModelException;
@Test
public void getIncludedFiles() throws Exception {
    // ErlideTestUtils.createInclude(project, "yy.hrl",
    // "-define(A, hej).\n");
    final IErlModule includeLibModule = ErlideTestUtils.createModule(project, "zz.erl", "-module(zz).\n-include_lib(\"kernel/include/file.hrl\").\nf(_) -> ok");
    module.open(null);
    includeLibModule.open(null);
    final Collection<ErlangIncludeFile> includeFiles = module.getIncludeFiles();
    final Collection<ErlangIncludeFile> includeFiles2 = includeLibModule.getIncludeFiles();
    assertEquals(1, includeFiles.size());
    assertEquals("yy.hrl", includeFiles.iterator().next().getFilenameLastPart());
    assertEquals(1, includeFiles2.size());
    assertEquals("file.hrl", includeFiles2.iterator().next().getFilenameLastPart());
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) Test(org.junit.Test)

Example 77 with IErlModule

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

the class IErlModuleTest method getPreprocessorDefs.

// public Collection<IErlPreprocessorDef> getPreprocessorDefs(final Kind
// kind);
@Test
public void getPreprocessorDefs() throws Exception {
    final IErlModule preprocessorDefModule = ErlideTestUtils.createModule(project, "yy.erl", "-module(yy).\n-define(A, hej).\n-define(B(x), x).\n" + "-record(?MODULE, {a, b}).\nf(L) -> reverse(L).\n");
    preprocessorDefModule.open(null);
    final Collection<IErlPreprocessorDef> records = preprocessorDefModule.getPreprocessorDefs(ErlElementKind.RECORD_DEF);
    final Collection<IErlPreprocessorDef> macros = preprocessorDefModule.getPreprocessorDefs(ErlElementKind.MACRO_DEF);
    assertEquals(1, records.size());
    assertEquals(2, macros.size());
    final Iterator<IErlPreprocessorDef> iterator = macros.iterator();
    assertEquals("A", iterator.next().getDefinedName());
    assertEquals("B", iterator.next().getDefinedName());
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) Test(org.junit.Test)

Example 78 with IErlModule

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

the class IErlModuleTest method findAllIncludedFiles.

// void addComment(IErlComment c);
// List<IErlModule> findAllIncludedFiles() throws CoreException;
@Test
public void findAllIncludedFiles() throws Exception {
    module.open(null);
    final Collection<IErlModule> includedFiles = ErlangEngine.getInstance().getModelFindService().findAllIncludedFiles(module);
    final String yyHrl = "yy.hrl";
    final IErlModule include = ErlideTestUtils.createInclude(project, yyHrl, "-include(\"zz.hrl\").\n-define(A, hej).\n");
    final IErlModule include2 = ErlideTestUtils.createInclude(project, "zz.hrl", "-define(B(X), lists:reverse(X)).\n");
    module.open(null);
    final List<IErlModule> includedFiles2 = Lists.newArrayList(ErlangEngine.getInstance().getModelFindService().findAllIncludedFiles(module));
    assertEquals(0, includedFiles.size());
    assertEquals(2, includedFiles2.size());
    assertEquals(include, includedFiles2.get(0));
    assertEquals(include2, includedFiles2.get(1));
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) Test(org.junit.Test)

Example 79 with IErlModule

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

the class IErlModuleTest method isOnSourcePath.

// boolean isOnSourcePath();
@Test
public void isOnSourcePath() throws Exception {
    final IErlModule module2 = ErlideTestUtils.createInclude(project, "yy.erl", "-module(yy).\n");
    assertTrue(module.isOnSourcePath());
    assertFalse(module2.isOnSourcePath());
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) Test(org.junit.Test)

Example 80 with IErlModule

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

the class IErlProjectTest method getModule.

// IErlModule getModule(String name) throws ErlModelException;
@Test
public void getModule() throws Exception {
    final IErlProject aProject = ErlModelTestBase.projects[0];
    final Collection<IPath> sourceDirs = aProject.getProperties().getSourceDirs();
    try {
        // given
        // an Erlang project and a module
        final IErlModule aModule = ErlideTestUtils.createModule(aProject, "aa.erl", "-module(aa).\n");
        final IPath srcxPath = new Path("srcx");
        final List<IPath> srcxDirs = Lists.newArrayList(srcxPath);
        aProject.open(null);
        // when
        // setting source dirs so the module is on source path
        final IErlModule module2 = aProject.getModule("aa");
        final IErlModule nullModule = aProject.getModule("aa.hrl");
        final IErlModule nullModule2 = aProject.getModule("AA");
        final IErlModule nullModule3 = aProject.getModule("aA");
        final IErlModule nullModule4 = aProject.getModule("AA.erl");
        final IErlModule module4 = aProject.getModule("aa.erl");
        ((ErlProject) aProject).setSourceDirs(srcxDirs);
        aProject.open(null);
        final IErlModule srcxModule = aProject.getModule("aa");
        ((ErlProject) aProject).setSourceDirs(sourceDirs);
        aProject.open(null);
        final IErlModule module3 = aProject.getModule("aa");
        // then
        // the it should be returned, but not otherwise
        assertEquals(aModule, module2);
        assertNull(srcxModule);
        assertNull(nullModule);
        assertNull(nullModule2);
        assertNull(nullModule3);
        assertNull(nullModule4);
        assertEquals(aModule, module3);
        assertEquals(aModule, module4);
    } finally {
        ((ErlProject) aProject).setSourceDirs(sourceDirs);
    }
}
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) 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