Search in sources :

Example 6 with IErlPreprocessorDef

use of org.erlide.engine.model.erlang.IErlPreprocessorDef 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 7 with IErlPreprocessorDef

use of org.erlide.engine.model.erlang.IErlPreprocessorDef 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 8 with IErlPreprocessorDef

use of org.erlide.engine.model.erlang.IErlPreprocessorDef 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 9 with IErlPreprocessorDef

use of org.erlide.engine.model.erlang.IErlPreprocessorDef 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 10 with IErlPreprocessorDef

use of org.erlide.engine.model.erlang.IErlPreprocessorDef 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

IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)14 IErlModule (org.erlide.engine.model.root.IErlModule)7 IErlProject (org.erlide.engine.model.root.IErlProject)6 Test (org.junit.Test)5 IErlRecordDef (org.erlide.engine.model.erlang.IErlRecordDef)4 CoreException (org.eclipse.core.runtime.CoreException)3 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)2 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ErlProject (org.erlide.engine.internal.model.root.ErlProject)2 IErlElement (org.erlide.engine.model.IErlElement)2 IErlAttribute (org.erlide.engine.model.erlang.IErlAttribute)2 CompletionData (org.erlide.engine.services.codeassist.CompletionData)2 FunctionCompletionData (org.erlide.engine.services.codeassist.FunctionCompletionData)2 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)1 HashSet (java.util.HashSet)1 IPath (org.eclipse.core.runtime.IPath)1