Search in sources :

Example 1 with IErlElement

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

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;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IErlFolder(org.erlide.engine.model.root.IErlFolder)

Example 3 with IErlElement

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();
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlElement(org.erlide.engine.model.IErlElement) IErlModel(org.erlide.engine.model.root.IErlModel) OpenResult(org.erlide.engine.services.search.OpenResult) IErlModule(org.erlide.engine.model.root.IErlModule) ScannerService(org.erlide.engine.services.parsing.ScannerService) Test(org.junit.Test)

Example 4 with IErlElement

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));
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) Test(org.junit.Test)

Example 5 with IErlElement

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());
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IFile(org.eclipse.core.resources.IFile) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Aggregations

IErlElement (org.erlide.engine.model.IErlElement)123 Test (org.junit.Test)36 IErlModule (org.erlide.engine.model.root.IErlModule)35 ErlModelException (org.erlide.engine.model.ErlModelException)28 IParent (org.erlide.engine.model.IParent)17 IFile (org.eclipse.core.resources.IFile)16 ArrayList (java.util.ArrayList)12 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)11 IResource (org.eclipse.core.resources.IResource)11 IErlProject (org.erlide.engine.model.root.IErlProject)10 IOpenable (org.erlide.engine.model.root.IOpenable)10 IProject (org.eclipse.core.resources.IProject)9 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)8 IErlModel (org.erlide.engine.model.root.IErlModel)8 WranglerException (org.erlide.wrangler.refactoring.exception.WranglerException)8 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)7 IFolder (org.eclipse.core.resources.IFolder)7 CoreException (org.eclipse.core.runtime.CoreException)7 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)6 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)6