Search in sources :

Example 56 with IErlProject

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

the class ModelUtilsTest method findPreprocessorDefTest.

@Test
public void findPreprocessorDefTest() throws Exception {
    // given
    // a module with includes and record
    final IErlProject project = ModelUtilsTest.projects[0];
    final IErlModule include = ErlideTestUtils.createInclude(project, "a.hrl", "-record(rec1, {field, another=def}).\n-define(MACRO(A), lists:reverse(A)).\n");
    final IErlModule module = ErlideTestUtils.createModule(project, "f.erl", "-module(f).\n-include(\"a.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);
    project.open(null);
    final IErlPreprocessorDef preprocessorDef1 = modelFindService.findPreprocessorDef(module, "rec1", ErlElementKind.RECORD_DEF);
    final IErlPreprocessorDef preprocessorDef2 = modelFindService.findPreprocessorDef(include, "rec1", ErlElementKind.RECORD_DEF);
    final IErlPreprocessorDef preprocessorDef3 = modelFindService.findPreprocessorDef(Arrays.asList(ModelUtilsTest.projects), "f.erl", "rec2", ErlElementKind.RECORD_DEF);
    // then
    // the record should be returned
    assertNotNull(module);
    assertNotNull(preprocessorDef1);
    assertTrue(preprocessorDef1 instanceof IErlRecordDef);
    assertEquals(preprocessorDef1, preprocessorDef2);
    assertEquals(preprocessorDef1.getParent(), include);
    assertNotNull(preprocessorDef3);
    assertEquals(preprocessorDef3.getParent(), module);
}
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 57 with IErlProject

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

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

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

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

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