use of org.erlide.engine.model.IErlElement 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.IErlElement in project erlide_eclipse by erlang.
the class DialyzerUtils method collectModulesFromResource.
public static Set<IErlModule> collectModulesFromResource(final IErlElementLocator model, final IResource resource) throws ErlModelException {
final Set<IErlModule> result = Sets.newHashSet();
final IErlElement element = model.findElement(resource, true);
if (element == null) {
return result;
}
if (element instanceof IErlFolder) {
final IErlFolder folder = (IErlFolder) element;
folder.open(null);
result.addAll(folder.getModules());
} else if (element instanceof IErlModule) {
final IErlModule module = (IErlModule) element;
result.add(module);
} else if (element instanceof IErlProject) {
final IErlProject project = (IErlProject) element;
project.open(null);
result.addAll(project.getModules());
}
return result;
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class ErlProjectTest method findFunctionInExternalFilesTest.
@Test
public void findFunctionInExternalFilesTest() throws Exception {
// given
// a module with calls to the lists module
final IErlProject project = ErlProjectTest.projects[0];
final IErlModule moduleE = ErlideTestUtils.createModule(project, "e.erl", "-module(e).\n-export([f/0]).\nf() ->\n lists:reverse([1, 0]),\n lists:reverse([1, 0], [2]).\n");
final ScannerService scanner = moduleE.getScanner();
try {
moduleE.open(null);
// when
// looking for lists:reverse/2 and lists:reverse/1
final IErlModel model = ErlangEngine.getInstance().getModel();
final OpenResult res = ErlangEngine.getInstance().getOpenService().open(moduleE.getScannerName(), 49, ErlangEngine.getInstance().getModelUtilService().getImportsAsList(moduleE), project.getProperties().getExternalModules(), model.getPathVars());
final IErlFunction function = ErlangEngine.getInstance().getModelFindService().findFunction(model, project, moduleE, res.getName(), res.getPath(), res.getFunction(), IErlElementLocator.Scope.PROJECT_ONLY);
assertNotNull(function);
final IErlElement module = model.findModuleFromProject(project, function.getModuleName(), res.getPath(), IErlElementLocator.Scope.PROJECT_ONLY);
// then
// the function should be returned and the module, in External Files
assertNotNull(module);
assertEquals(function.getParent(), module);
assertEquals(ErlangEngine.getInstance().getModelUtilService().getProject(function), project);
} finally {
scanner.dispose();
}
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class IErlElementTest method getProject.
// IErlProject getProject();
@Test
public void getProject() throws Exception {
assertEquals(project, ErlangEngine.getInstance().getModelUtilService().getProject(module));
assertEquals(project, ErlangEngine.getInstance().getModelUtilService().getProject(project));
module.open(null);
final IErlElement element = module.getElementAtLine(3);
assertEquals(project, ErlangEngine.getInstance().getModelUtilService().getProject(element));
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class IErlElementTest method getCorrespondingResource.
// IResource getCorrespondingResource();
@Test
public void getCorrespondingResource() throws Exception {
project.open(null);
final IProject workspaceProject = project.getWorkspaceProject();
final IFolder srcFolder = workspaceProject.getFolder("src");
final IFile file = srcFolder.getFile("xx.erl");
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
final IErlModule otpFile = model.findModuleFromProject(project, "file.erl", null, IErlElementLocator.Scope.PROJECT_ONLY);
module.open(null);
final IErlElement element = module.getElementAtLine(3);
assertEquals(file, module.getCorrespondingResource());
assertNull(otpFile.getCorrespondingResource());
assertNull(element.getCorrespondingResource());
}
Aggregations