use of org.erlide.engine.model.erlang.IErlFunction 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.erlang.IErlFunction in project erlide_eclipse by erlang.
the class ErlTextHover method internalGetHoverInfo.
private static ErlangBrowserInformationControlInput internalGetHoverInfo(final AbstractErlangEditor editor, final ITextViewer textViewer, final IRegion hoverRegion) {
if (editor == null) {
return null;
}
final StringBuffer result = new StringBuffer();
OpenResult element = null;
// TODO our model is too coarse, here we need access to expressions
final Collection<OtpErlangObject> fImports = ErlangEngine.getInstance().getModelUtilService().getImportsAsList(editor.getModule());
final int offset = hoverRegion.getOffset();
final int length = hoverRegion.getLength();
final String debuggerVar = ErlTextHover.makeDebuggerVariableHover(textViewer, offset, length);
if (!debuggerVar.isEmpty()) {
result.append(debuggerVar);
}
final IErlProject erlProject = editor.getProject();
String docPath = "";
String anchor = "";
try {
if (erlProject == null) {
return null;
}
final IOtpRpc backend = BackendCore.getBuildBackend(erlProject);
if (backend == null) {
return null;
}
final IErlModel model = ErlangEngine.getInstance().getModel();
final String externalModulesString = erlProject.getProperties().getExternalModules();
final OtpErlangTuple t = (OtpErlangTuple) ErlangEngine.getInstance().getOtpDocService().getOtpDoc(backend, offset, editor.getScannerName(), fImports, externalModulesString, model.getPathVars());
if (Util.isOk(t)) {
element = new OpenResult(t.elementAt(2));
final String docStr = Util.stringValue(t.elementAt(1));
result.append(docStr);
if (t.arity() > 4) {
docPath = Util.stringValue(t.elementAt(3));
anchor = Util.stringValue(t.elementAt(4));
}
} else {
element = new OpenResult(t);
final Object found = new OpenUtils().findOpenResult(editor, editor.getModule(), erlProject, element, editor.getElementAt(offset, false));
if (found instanceof IErlFunction) {
final IErlFunction function = (IErlFunction) found;
final String comment = DocumentationFormatter.getDocumentationString(function.getComments(), function.getTypespec());
if (comment.isEmpty()) {
return null;
}
result.append(comment);
} else if (found instanceof IErlPreprocessorDef) {
final IErlPreprocessorDef preprocessorDef = (IErlPreprocessorDef) found;
result.append(preprocessorDef.getExtra());
}
}
} catch (final Exception e) {
ErlLogger.warn(e);
return null;
}
final String strResult = HoverUtil.getHTML(result);
return new ErlangBrowserInformationControlInput(null, editor, element, strResult, 20, HoverUtil.getDocumentationURL(docPath, anchor));
}
use of org.erlide.engine.model.erlang.IErlFunction in project erlide_eclipse by erlang.
the class ErlangCompletionService method getDeclaredFunctions.
List<CompletionData> getDeclaredFunctions(final int offset, final String prefix, final boolean unexportedOnly, final boolean arityOnly) throws ErlModelException {
final List<CompletionData> result = new ArrayList<>();
for (final IErlElement e : module.getChildren()) {
if (e instanceof IErlFunction) {
final IErlFunction f = (IErlFunction) e;
if (unexportedOnly && f.isExported()) {
continue;
}
addFunctionCompletion(offset, prefix, result, f, arityOnly);
}
}
return result;
}
use of org.erlide.engine.model.erlang.IErlFunction 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.IErlFunction in project erlide_eclipse by erlang.
the class SearchPatternFactory method getSearchPatternFromErlElementAndLimitTo.
public ErlangSearchPattern getSearchPatternFromErlElementAndLimitTo(final IErlElement element, final LimitTo limitTo) {
if (element instanceof IErlFunction) {
final IErlFunction function = (IErlFunction) element;
final String withoutExtension = SystemConfiguration.withoutExtension(function.getModuleName());
return new FunctionPattern(withoutExtension, function.getFunctionName(), function.getArity(), limitTo, true, modelUtilService.getModule(function), !function.isExported());
} else if (element instanceof IErlMacroDef) {
final IErlMacroDef m = (IErlMacroDef) element;
final String unquoted = StringUtils.unquote(m.getDefinedName());
return new MacroPattern(unquoted, limitTo);
} else if (element instanceof IErlRecordDef) {
final IErlRecordDef r = (IErlRecordDef) element;
final String unquoted = StringUtils.unquote(r.getDefinedName());
return new RecordPattern(unquoted, limitTo);
} else if (element instanceof IErlFunctionClause) {
final IErlFunctionClause clause = (IErlFunctionClause) element;
return getSearchPatternFromErlElementAndLimitTo((IErlElement) clause.getParent(), limitTo);
} else if (element instanceof IErlAttribute) {
final IErlAttribute a = (IErlAttribute) element;
if (a.getName().startsWith("include")) {
final String s = Util.stringValue(a.getValue());
return new IncludePattern(s, limitTo);
}
}
return null;
}
Aggregations