Search in sources :

Example 91 with IErlModule

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

the class ModelUtilsTest method getPreprocessorDefs.

@Test
public void getPreprocessorDefs() throws Exception {
    final IErlProject project = ModelUtilsTest.projects[0];
    final IErlModule module = ErlideTestUtils.createModule(project, "a.erl", "-module(g).\n" + "-include_lib(\"kernel/include/file.hrl\").\n" + "-export([f/0]).\n" + "-define(A(B), '++B++').\n" + "-record(rec2, {a, b}).\n" + "f() ->\n" + "    lists:reverse([1, 0]),\n" + "    lists:reverse([1, 0], [2]).\n");
    module.open(null);
    final List<IErlPreprocessorDef> macroDefs = ErlangCompletionService.getAllPreprocessorDefs(module, ErlElementKind.MACRO_DEF);
    final List<IErlPreprocessorDef> recordDefs = ErlangCompletionService.getAllPreprocessorDefs(module, ErlElementKind.RECORD_DEF);
    assertEquals(2, macroDefs.size());
    assertEquals(3, recordDefs.size());
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) Test(org.junit.Test)

Example 92 with IErlModule

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

the class ModelUtilsTest method findPreprocessorDefExternalIncludePathTest.

@Test
public void findPreprocessorDefExternalIncludePathTest() throws Exception {
    File externalInclude = null;
    IErlProject project = null;
    // contains a record def
    try {
        final String projectName = "testprojectx";
        project = ErlideTestUtils.createErlProject(projectName);
        final IErlModule module = ErlideTestUtils.createModule(project, "a.erl", "-include(\"y.hrl\").\n");
        final String includeName = "y.hrl";
        externalInclude = ErlideTestUtils.createTmpFile(includeName, "-record(rec2, {field, another=def}.");
        final String includePath = externalInclude.getAbsolutePath();
        final String externalsFileName = "x.erlidex";
        final File externalsFile = ErlideTestUtils.createTmpFile(externalsFileName, includePath);
        ((ErlProject) project).setExternalIncludesFile(externalsFile.getAbsolutePath());
        project.open(null);
        // when
        // looking for the record def
        final IErlPreprocessorDef preprocessorDef = modelFindService.findPreprocessorDef(module, "rec2", ErlElementKind.RECORD_DEF);
        final Collection<IErlProject> myprojects = Lists.newArrayList(project);
        modelFindService.findPreprocessorDef(myprojects, "a.erl", "rec2", ErlElementKind.RECORD_DEF);
        // then
        // it should be found
        assertNotNull(preprocessorDef);
    } finally {
        if (project != null) {
            ErlideTestUtils.deleteProject(project);
        }
        if (externalInclude != null && externalInclude.exists()) {
            externalInclude.delete();
        }
    }
}
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) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) Test(org.junit.Test)

Example 93 with IErlModule

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

the class ModelUtilsTest method getModulesWithReferencedProjectsWithPrefix.

@Test
public void getModulesWithReferencedProjectsWithPrefix() throws Exception {
    // given
    // two erlang projects, the first references the second, second has
    // an erlang module
    final IProject project = ModelUtilsTest.projects[0].getWorkspaceProject();
    final IProjectDescription description = project.getDescription();
    final IProject[] refs = { ModelUtilsTest.projects[1].getWorkspaceProject() };
    description.setReferencedProjects(refs);
    project.setDescription(description, null);
    final IErlModule module = ErlideTestUtils.createModule(ModelUtilsTest.projects[1], "abc.erl", "-module(abc).\n-export(f/0)\nf() ->\n   {abc, ok}.\n");
    ErlideTestUtils.createModule(ModelUtilsTest.projects[0], "bbc.erl", "-module(bbc).\n-export(f/0)\nf() ->\n   {abc, ok}.\n");
    // when
    // looking for module with prefix, it should be found
    final List<String> moduleNames = modelUtilService.findUnitsWithPrefix("a", ModelUtilsTest.projects[0], false, false);
    // then
    // we should find it
    assertNotNull(moduleNames);
    assertEquals(1, moduleNames.size());
    assertEquals(module.getModuleName(), moduleNames.get(0));
}
Also used : IProjectDescription(org.eclipse.core.resources.IProjectDescription) IErlModule(org.erlide.engine.model.root.IErlModule) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 94 with IErlModule

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

the class ModelUtilsTest method findPreprocessorDefOtpIncludeTest.

@Test
public void findPreprocessorDefOtpIncludeTest() throws Exception {
    // given
    // a module with includes and record
    final IErlProject project = ModelUtilsTest.projects[0];
    final IErlModule module = ErlideTestUtils.createModule(project, "g.erl", "-module(g).\n-include_lib(\"kernel/include/file.hrl\").\n-export([f/0]).\n-record(rec2, {a, b}).\n" + "f() ->\n    lists:reverse([1, 0]),\n    lists:reverse([1, 0], [2]).\n");
    module.open(null);
    // when
    // looking for the record
    final IErlPreprocessorDef preprocessorDef = modelFindService.findPreprocessorDef(module, "file_info", ErlElementKind.RECORD_DEF);
    // then
    // the record should be returned
    assertNotNull(module);
    assertNotNull(preprocessorDef);
    assertTrue(preprocessorDef instanceof IErlRecordDef);
    assertEquals(ErlangEngine.getInstance().getModelUtilService().getProject(preprocessorDef), project);
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlRecordDef(org.erlide.engine.model.erlang.IErlRecordDef) IErlModule(org.erlide.engine.model.root.IErlModule) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) Test(org.junit.Test)

Example 95 with IErlModule

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

the class ModelUtilsTest method findPreprocessorDefExternalIncludeOnIncludePathTest.

@Test
public void findPreprocessorDefExternalIncludeOnIncludePathTest() throws Exception {
    File externalInclude = null;
    IErlProject project = null;
    // given
    // a project with an include dir outside the model, the include file
    // contains a record def
    final String projectName = "testprojectx";
    try {
        // ErlModelCache.getDefault().setNoModelCache(true);
        // ErlModelCache.getDefault().clearModelCache();
        project = ErlideTestUtils.createErlProject(projectName);
        final IErlModule module = ErlideTestUtils.createModule(project, "a.erl", "-include(\"z.hrl\").\n");
        final String includeName = "z.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));
        project.open(null);
        // when
        // looking for the record def
        final IErlPreprocessorDef preprocessorDef = modelFindService.findPreprocessorDef(module, "rec2", ErlElementKind.RECORD_DEF);
        final Collection<IErlProject> myprojects = Lists.newArrayList(project);
        ErlangEngine.getInstance().getModelFindService().findPreprocessorDef(myprojects, "a.erl", "rec2", ErlElementKind.RECORD_DEF);
        // then
        // it should be found
        assertNotNull(preprocessorDef);
    } finally {
        if (project != null) {
            ErlideTestUtils.deleteProject(project);
        }
        if (externalInclude != null && externalInclude.exists()) {
            externalInclude.delete();
        }
        new File(ErlideTestUtils.getTmpPath(projectName).removeLastSegments(1).toPortableString()).delete();
    // ErlModelCache.getDefault().setNoModelCache(false);
    }
}
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) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) 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