Search in sources :

Example 1 with IErlTypespec

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

the class ParserDB method handleModule.

public void handleModule(final IErlModule module) throws ErlModelException {
    module.open(null);
    final int numForms = module.getChildCount();
    final String path = module.getResource().getLocation().toPortableString();
    ParserDB.out.println(path + " " + numForms + " " + isTest(path));
    System.out.println(path + " " + numForms + " " + isTest(path));
    for (final IErlElement form : module.getChildren()) {
        ParserDB.out.print(" " + form.getKind() + " ");
        if (form instanceof IErlImportExport) {
            final IErlImportExport export = (IErlImportExport) form;
            ParserDB.out.println(export.getFunctions().size());
        } else if (form instanceof IErlPreprocessorDef) {
            final IErlPreprocessorDef def = (IErlPreprocessorDef) form;
            ParserDB.out.println(fix(def.getDefinedName()));
        } else if (form instanceof IErlTypespec) {
            final IErlTypespec attribute = (IErlTypespec) form;
            ParserDB.out.println("TYPESPEC " + fix(attribute.getName()));
        } else if (form instanceof IErlAttribute) {
            final IErlAttribute attribute = (IErlAttribute) form;
            ParserDB.out.println(fix(attribute.getName()));
        } else if (form instanceof IErlFunction) {
            final IErlFunction function = (IErlFunction) form;
            int numClauses = function.getChildCount();
            numClauses = numClauses == 0 ? 1 : numClauses;
            ParserDB.out.println(fix(function.getName()) + " " + function.getArity() + " " + numClauses);
        } else {
            ParserDB.out.println("?? " + form.getClass().getName());
        }
    }
    module.close();
    module.dispose();
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlTypespec(org.erlide.engine.model.erlang.IErlTypespec) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlImportExport(org.erlide.engine.model.erlang.IErlImportExport) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute)

Example 2 with IErlTypespec

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

the class ModelFindUtil method findTypespec.

@Override
public IErlTypespec findTypespec(final IErlModule module, final String name) throws CoreException {
    IErlTypespec typespec = module.findTypespec(name);
    if (typespec != null) {
        return typespec;
    }
    final Collection<IErlModule> includedFiles = findAllIncludedFiles(module);
    for (final IErlModule includedFile : includedFiles) {
        typespec = includedFile.findTypespec(name);
        if (typespec != null) {
            return typespec;
        }
    }
    return null;
}
Also used : IErlTypespec(org.erlide.engine.model.erlang.IErlTypespec) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 3 with IErlTypespec

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

the class ErlParser method considerPrevious.

private int considerPrevious(final int i, final List<IErlMember> all, final Deque<IErlComment> comments, final IErlFunction function) {
    final int j = i - 1;
    if (j > 0) {
        final IErlMember member = all.get(i);
        final IErlMember prevMember = all.get(j);
        if (prevMember instanceof IErlComment) {
            if (prevMember.getLineEnd() + ErlParser.FUNCTION_COMMENT_THRESHOLD >= member.getLineStart()) {
                comments.addFirst((IErlComment) prevMember);
            }
        } else if (prevMember instanceof IErlTypespec) {
            final IErlTypespec spec = (IErlTypespec) prevMember;
            if (spec.getName().equals(function.getName()) && spec.getArity() == function.getArity() && prevMember.getLineEnd() + ErlParser.FUNCTION_COMMENT_THRESHOLD >= member.getLineStart()) {
                function.setTypespec(spec);
            }
        } else {
            return -1;
        }
    }
    return j;
}
Also used : IErlComment(org.erlide.engine.model.erlang.IErlComment) IErlMember(org.erlide.engine.model.erlang.IErlMember) IErlTypespec(org.erlide.engine.model.erlang.IErlTypespec)

Example 4 with IErlTypespec

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

the class ModelUtilsTest method findExternalTypeTest.

@Test
public void findExternalTypeTest() throws Exception {
    // given
    // an Erlang module with typedef
    final IErlModule moduleB = ErlideTestUtils.createModule(ModelUtilsTest.projects[0], "bx.erl", "-module(bx).\n-type concat_thing() :: atom() | integer() | float() | string().\n");
    // final IErlModule moduleC =
    // ErlideTestUtils.createErlModule(projects[1],
    // "c.erl", "-module(c).\n-type cc() :: b:concat_thing().\n");
    final ScannerService scanner = moduleB.getScanner();
    try {
        moduleB.open(null);
        ModelUtilsTest.projects[0].open(null);
        // moduleC.open(null);
        // when
        // looking for it
        // within project
        final IErlElementLocator model = ErlangEngine.getInstance().getModel();
        final IErlElement element1 = modelFindService.findTypeDef(model, ModelUtilsTest.projects[0], moduleB, "bx", "concat_thing", moduleB.getResource().getLocation().toPortableString(), IErlElementLocator.Scope.PROJECT_ONLY);
        // in other project but path given
        final IErlElement element2 = modelFindService.findTypeDef(model, ModelUtilsTest.projects[1], moduleB, "bx", "concat_thing", moduleB.getResource().getLocation().toPortableString(), IErlElementLocator.Scope.PROJECT_ONLY);
        // in other project no path given, search all projects true
        final IErlElement element3 = modelFindService.findTypeDef(model, ModelUtilsTest.projects[1], moduleB, "bx", "concat_thing", null, IErlElementLocator.Scope.ALL_PROJECTS);
        // in other project no path given, search all projects false, ->
        // null
        final IErlElement element4 = modelFindService.findTypeDef(model, ModelUtilsTest.projects[1], moduleB, "bx", "concat_thing", null, IErlElementLocator.Scope.PROJECT_ONLY);
        // then
        // it should be returned if found
        assertTrue(element1 instanceof IErlTypespec);
        assertNull(element2);
        assertTrue(element3 instanceof IErlTypespec);
        assertNull(element4);
    } finally {
        scanner.dispose();
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlTypespec(org.erlide.engine.model.erlang.IErlTypespec) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) ScannerService(org.erlide.engine.services.parsing.ScannerService) Test(org.junit.Test)

Example 5 with IErlTypespec

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

the class ModelUtilsTest method findTypespec.

@Test
public void findTypespec() throws Exception {
    // given
    // a project with a module and an include with a typespec
    final IErlProject project = ModelUtilsTest.projects[0];
    final String includeName = "a.hrl";
    final IErlModule include = ErlideTestUtils.createModule(project, includeName, "-type date() :: {pos_integer(), pos_integer(), pos_integer()}.\n");
    include.open(null);
    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);
    // when
    // looking for the typespec
    final IErlTypespec typespec = modelFindService.findTypespec(module, "date");
    // then
    // it should be found
    assertNotNull(typespec);
    assertEquals(typespec.getParent(), include);
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlTypespec(org.erlide.engine.model.erlang.IErlTypespec) IErlModule(org.erlide.engine.model.root.IErlModule) Test(org.junit.Test)

Aggregations

IErlTypespec (org.erlide.engine.model.erlang.IErlTypespec)5 IErlModule (org.erlide.engine.model.root.IErlModule)3 IErlElement (org.erlide.engine.model.IErlElement)2 Test (org.junit.Test)2 IErlAttribute (org.erlide.engine.model.erlang.IErlAttribute)1 IErlComment (org.erlide.engine.model.erlang.IErlComment)1 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)1 IErlImportExport (org.erlide.engine.model.erlang.IErlImportExport)1 IErlMember (org.erlide.engine.model.erlang.IErlMember)1 IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)1 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)1 IErlProject (org.erlide.engine.model.root.IErlProject)1 ScannerService (org.erlide.engine.services.parsing.ScannerService)1