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();
}
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;
}
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;
}
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();
}
}
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);
}
Aggregations