Search in sources :

Example 1 with ScannerService

use of org.erlide.engine.services.parsing.ScannerService 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 2 with ScannerService

use of org.erlide.engine.services.parsing.ScannerService in project erlide_eclipse by erlang.

the class ErlangEditor method getModule.

@Override
public IErlModule getModule() {
    if (fModule == null) {
        try {
            fModule = ErlModelUtils.getModule(getEditorInput());
            fModule.createScanner();
            final ScannerService erlScanner = fModule.getScanner();
            erlScanner.dispose();
        } catch (final CoreException e) {
        }
    }
    return fModule;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ScannerService(org.erlide.engine.services.parsing.ScannerService)

Example 3 with ScannerService

use of org.erlide.engine.services.parsing.ScannerService in project erlide_eclipse by erlang.

the class AddRefacHandler method checkType.

// check if the refactoring is elementary or composite
private RefacType checkType(final String callbackModule) {
    try {
        final IErlModule module = ErlangEngine.getInstance().getModel().findModule(callbackModule);
        final ScannerService scanner = module.getScanner();
        try {
            module.resetAndCacheScannerAndParser(null);
        } finally {
            scanner.dispose();
        }
        for (final IErlElement el : module.getChildrenOfKind(ErlElementKind.ATTRIBUTE)) {
            final IErlAttribute attr = (IErlAttribute) el;
            if ("behaviour".equals(attr.getName()) || "behavior".equals(attr.getName())) {
                if (attr.getValue().toString().contains("gen_refac")) {
                    return RefacType.ELEMENTARY;
                } else if (attr.getValue().toString().contains("gen_composite_refac")) {
                    return RefacType.COMPOSITE;
                }
            }
        }
        return null;
    } catch (final ErlModelException e) {
        return null;
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) ScannerService(org.erlide.engine.services.parsing.ScannerService)

Example 4 with ScannerService

use of org.erlide.engine.services.parsing.ScannerService in project erlide_eclipse by erlang.

the class IErlModuleTest method getScannerTokenAt.

// ErlToken getScannerTokenAt(int offset);
@Test
public void getScannerTokenAt() throws Exception {
    final ScannerService scanner = module.getScanner();
    try {
        module.open(null);
        final ErlToken token = scanner.getTokenAt(-1);
        final ErlToken token2 = scanner.getTokenAt(0);
        final ErlToken token3 = scanner.getTokenAt(1);
        final ErlToken token4 = scanner.getTokenAt(10);
        final ErlToken token5 = scanner.getTokenAt(24);
        final ErlToken token6 = scanner.getTokenAt(61);
        final ErlToken token7 = scanner.getTokenAt(62);
        assertNull(token);
        assertNotNull(token2);
        assertEquals(ErlToken.KIND_OTHER, token2.getKind());
        assertNotNull(token3);
        assertEquals(ErlToken.KIND_ATOM, token3.getKind());
        assertNotNull(token4);
        assertEquals(ErlToken.KIND_OTHER, token4.getKind());
        assertNotNull(token5);
        assertEquals(ErlToken.KIND_STRING, token5.getKind());
        assertNotNull(token6);
        assertEquals(ErlToken.KIND_OTHER, token6.getKind());
        assertNull(token7);
    } finally {
        scanner.dispose();
    }
}
Also used : ErlToken(org.erlide.engine.services.parsing.ErlToken) ScannerService(org.erlide.engine.services.parsing.ScannerService) Test(org.junit.Test)

Example 5 with ScannerService

use of org.erlide.engine.services.parsing.ScannerService in project erlide_eclipse by erlang.

the class ErlangScratchPad method getNewScanner.

@Override
protected ScannerService getNewScanner() {
    final IFile file = getFile();
    if (file == null) {
        return null;
    }
    try {
        final String filePath = file.getLocation().toPortableString();
        String initialText;
        initialText = Util.getInputStreamAsString(file.getContents(), file.getCharset());
        final ScannerService scanner = ErlangEngine.getInstance().getScannerProviderService().get(getScannerName());
        scanner.initialScan(initialText, filePath, false);
        return scanner;
    } catch (final CoreException e) {
        ErlLogger.warn(e);
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ScannerService(org.erlide.engine.services.parsing.ScannerService)

Aggregations

ScannerService (org.erlide.engine.services.parsing.ScannerService)7 Test (org.junit.Test)4 IErlElement (org.erlide.engine.model.IErlElement)3 IErlModule (org.erlide.engine.model.root.IErlModule)3 CoreException (org.eclipse.core.runtime.CoreException)2 IFile (org.eclipse.core.resources.IFile)1 ErlModelException (org.erlide.engine.model.ErlModelException)1 IErlAttribute (org.erlide.engine.model.erlang.IErlAttribute)1 IErlTypespec (org.erlide.engine.model.erlang.IErlTypespec)1 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)1 IErlModel (org.erlide.engine.model.root.IErlModel)1 IErlProject (org.erlide.engine.model.root.IErlProject)1 ErlToken (org.erlide.engine.services.parsing.ErlToken)1 OpenResult (org.erlide.engine.services.search.OpenResult)1