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