use of org.erlide.engine.model.erlang.IErlImport in project erlide_eclipse by erlang.
the class ErlangCompletionService method getImportedFunctions.
List<CompletionData> getImportedFunctions(final IOtpRpc backend, final int offset, final String prefix) {
final List<CompletionData> result = new ArrayList<>();
for (final IErlImport imp : module.getImports()) {
final OtpErlangObject res = ErlangEngine.getInstance().getOtpDocService().getProposalsWithDoc(backend, imp.getImportModule(), prefix);
addFunctionProposalsWithDoc(offset, prefix, result, res, imp, false);
}
return result;
}
use of org.erlide.engine.model.erlang.IErlImport in project erlide_eclipse by erlang.
the class ErlangCompletionService method computeCompletions.
@Override
public List<CompletionData> computeCompletions(final IOtpRpc backend, IErlProject project0, IErlModule module0, String elementBefore0, final int offset, final String before0, final boolean inString) throws CoreException {
// FIXME these should be passed on as parameters, where needed
project = project0;
module = module0;
elementBefore = elementBefore0;
String before = before0;
final int commaPos = before.lastIndexOf(',');
final int colonPos = before.lastIndexOf(':');
final boolean doubleColon = colonPos >= 0 && before.charAt(colonPos - 1) == ':';
final int hashMarkPos = before.lastIndexOf('#');
final int dotPos = before.lastIndexOf('.');
final int parenPos = before.lastIndexOf('(');
final int leftBracketPos = before.lastIndexOf('{');
final int interrogationMarkPos = before.lastIndexOf('?');
final int arrowPos = before.lastIndexOf("->");
final String prefix = getPrefix(before);
List<String> fieldsSoFar = null;
List<CompletionData> result;
EnumSet<CompletionFlag> flags = EnumSet.noneOf(CompletionFlag.class);
int pos;
String moduleOrRecord = null;
IErlElement element = getElementAt(offset);
for (int i = 1; element == null && i <= 15; ++i) {
element = getElementAt(offset - i);
}
RecordCompletion rc = null;
if (hashMarkPos >= 0) {
final IErlProject aproject = project;
if (aproject != null) {
rc = contextAssistService.checkRecordCompletion(backend, before);
}
}
if (rc != null && rc.isNameWanted()) {
flags = EnumSet.of(CompletionFlag.RECORD_DEFS);
pos = hashMarkPos;
before = rc.getPrefix();
} else if (rc != null && rc.isFieldWanted()) {
flags = EnumSet.of(CompletionFlag.RECORD_FIELDS);
pos = hashMarkPos;
if (dotPos > hashMarkPos) {
pos = dotPos;
} else if (leftBracketPos > hashMarkPos) {
pos = leftBracketPos;
} else {
assert false;
}
before = rc.getPrefix();
moduleOrRecord = rc.getName();
fieldsSoFar = rc.getFields();
} else if (colonPos > commaPos && colonPos > parenPos) {
if (doubleColon) {
flags = EnumSet.of(CompletionFlag.TYPES);
pos = colonPos;
before = before.substring(colonPos + 1);
} else {
moduleOrRecord = StringUtils.unquote(getPrefix(before.substring(0, colonPos)));
flags = EnumSet.of(CompletionFlag.EXTERNAL_FUNCTIONS);
pos = colonPos;
before = before.substring(colonPos + 1);
}
} else if (interrogationMarkPos > hashMarkPos && interrogationMarkPos > commaPos && interrogationMarkPos > colonPos && interrogationMarkPos > arrowPos) {
flags = EnumSet.of(CompletionFlag.MACRO_DEFS);
pos = interrogationMarkPos;
before = before.substring(interrogationMarkPos + 1);
} else {
pos = colonPos;
before = prefix;
if (element != null) {
switch(element.getKind()) {
case EXPORT:
flags = EnumSet.of(CompletionFlag.DECLARED_FUNCTIONS, CompletionFlag.ARITY_ONLY, CompletionFlag.UNEXPORTED_ONLY);
break;
case IMPORT:
final IErlImport i = (IErlImport) element;
moduleOrRecord = i.getImportModule();
flags = EnumSet.of(CompletionFlag.EXTERNAL_FUNCTIONS, CompletionFlag.ARITY_ONLY);
break;
case FUNCTION:
case CLAUSE:
flags = EnumSet.of(CompletionFlag.MODULES);
if (module != null) {
flags.addAll(EnumSet.of(CompletionFlag.VARIABLES, CompletionFlag.DECLARED_FUNCTIONS, CompletionFlag.IMPORTED_FUNCTIONS, CompletionFlag.AUTO_IMPORTED_FUNCTIONS));
}
break;
case ATTRIBUTE:
if ("include".equals(element.getName())) {
flags = EnumSet.of(CompletionFlag.INCLUDES);
} else if ("include_lib".equals(element.getName())) {
flags = EnumSet.of(CompletionFlag.INCLUDE_LIBS);
}
break;
default:
break;
}
} else {
if (doubleColon) {
flags = EnumSet.of(CompletionFlag.TYPES);
} else {
flags = EnumSet.of(CompletionFlag.MODULES);
}
}
}
// TODO flags = filterFlags(flags);
result = addCompletions(backend, flags, offset, before, moduleOrRecord, pos, fieldsSoFar, inString);
return result;
}
use of org.erlide.engine.model.erlang.IErlImport in project erlide_eclipse by erlang.
the class OpenUtils method findLocalCall.
private IErlElement findLocalCall(final IErlModule module, final IErlProject erlProject, final OpenResult res, final IErlElement element, final IErlElementLocator.Scope scope) throws RpcException, CoreException {
if (isTypeDefOrRecordDef(element, res)) {
return modelFindService.findTypespec(module, res.getFun());
}
final IErlFunction foundElement = module.findFunction(res.getFunction());
if (foundElement != null) {
return foundElement;
}
// imported functions
OtpErlangObject res2 = null;
String moduleName = null;
final IErlImport ei = module.findImport(res.getFunction());
if (ei != null) {
final IErlModel model = ErlangEngine.getInstance().getModel();
moduleName = ei.getImportModule();
res2 = ErlangEngine.getInstance().getOpenService().getSourceFromModule(model.getPathVars(), moduleName, erlProject.getProperties().getExternalModules());
}
if (res2 instanceof OtpErlangString && moduleName != null) {
// imported from otp module
final OtpErlangString otpErlangString = (OtpErlangString) res2;
final String modulePath = otpErlangString.stringValue();
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
return modelFindService.findFunction(model, erlProject, module, moduleName, modulePath, res.getFunction(), scope);
}
// functions defined in include files
final Collection<IErlModule> allIncludedFiles = ErlangEngine.getInstance().getModelFindService().findAllIncludedFiles(module);
for (final IErlModule includedModule : allIncludedFiles) {
final IErlFunction function = includedModule.findFunction(res.getFunction());
if (function != null) {
return function;
}
}
return null;
}
use of org.erlide.engine.model.erlang.IErlImport in project erlide_eclipse by erlang.
the class ModelUtilsTest method getImportsAsListTest.
@Test
public void getImportsAsListTest() throws Exception {
// given
// an Erlang module with imports
final IErlModule moduleA = ErlideTestUtils.createModule(ModelUtilsTest.projects[0], "ax.erl", "-module(ax).\n-import(lists, [reverse/1, foldl/3].\n");
moduleA.open(null);
// when
// fetching imports as list of OtpErlangTuple
final Collection<IErlElement> children = moduleA.getChildren();
final Collection<IErlImport> imports2 = moduleA.getImports();
final List<OtpErlangObject> imports = modelUtilService.getImportsAsList(moduleA);
// then
// they should be returned
assertEquals(2, children.size());
assertEquals(1, imports2.size());
assertEquals(1, imports.size());
final OtpErlangAtom listAtom = new OtpErlangAtom("lists");
assertEquals(new OtpErlangTuple(new OtpErlangObject[] { listAtom, new OtpErlangList(new OtpErlangObject[] { makeTuple2("reverse", 1), makeTuple2("foldl", 3) }) }), imports.get(0));
}
use of org.erlide.engine.model.erlang.IErlImport in project erlide_eclipse by erlang.
the class ErlModule method getImports.
@Override
public Collection<IErlImport> getImports() {
final List<IErlImport> result = new ArrayList<>();
synchronized (getModelLock()) {
for (final IErlElement e : internalGetChildren()) {
if (e instanceof IErlImport) {
final IErlImport ei = (IErlImport) e;
result.add(ei);
}
}
}
return result;
}
Aggregations