use of org.erlide.ui.actions.OpenUtils 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.ui.actions.OpenUtils in project erlide_eclipse by erlang.
the class SearchUtil method getSearchPatternFromOpenResultAndLimitTo.
public static ErlangSearchPattern getSearchPatternFromOpenResultAndLimitTo(final IErlModule module, final int offset, final OpenResult res, final LimitTo limitTo, final boolean matchAnyFunctionDefinition) throws ErlModelException {
if (res == null) {
return null;
}
if (res.isLocalCall()) {
String moduleName;
if (module != null) {
moduleName = module.getModuleName();
if (offset != -1) {
final IErlElement e = module.getElementAt(offset);
if (new OpenUtils().isTypeDefOrRecordDef(e, res)) {
return new TypeRefPattern(moduleName, res.getFun(), limitTo);
}
}
} else {
moduleName = res.getName();
}
return new FunctionPattern(moduleName, res.getFun(), res.getArity(), limitTo, matchAnyFunctionDefinition, module, true);
}
String moduleName = res.getName();
if (moduleName == null) {
return null;
}
final String unquoted = StringUtils.unquote(moduleName);
if (res.isExternalCall()) {
if (module != null && offset != -1) {
final IErlElement e = module.getElementAt(offset);
if (e != null && (e.getKind() == ErlElementKind.TYPESPEC || e.getKind() == ErlElementKind.RECORD_DEF)) {
return new TypeRefPattern(moduleName, res.getFun(), limitTo);
}
}
String oldName;
moduleName = unquoted;
do {
oldName = moduleName;
moduleName = ErlangEngine.getInstance().getModelFindService().resolveMacroValue(moduleName, module);
} while (!moduleName.equals(oldName));
return new FunctionPattern(moduleName, res.getFun(), res.getArity(), limitTo, matchAnyFunctionDefinition, module, false);
} else if (res.isMacro()) {
return new MacroPattern(unquoted, limitTo);
} else if (res.isRecord()) {
return new RecordPattern(unquoted, limitTo);
} else if (res.isInclude()) {
return new IncludePattern(moduleName, limitTo);
} else if (res.isVariable()) {
if (module != null) {
if (offset != -1) {
final IErlElement e = module.getElementAt(offset);
if (e instanceof IErlFunctionClause) {
final IErlFunctionClause c = (IErlFunctionClause) e;
return new VariablePattern(c.getFunctionName(), c.getArity(), c.getHead(), res.getName(), limitTo, module);
}
}
}
} else if (res.isField()) {
return new RecordFieldPattern(res.getFun(), unquoted, limitTo);
}
return null;
}
Aggregations