use of org.erlide.engine.model.erlang.IErlFunctionClause in project erlide_eclipse by erlang.
the class SimpleCodeInspectionHandler method extractFunction.
private IErlFunctionClause extractFunction(final OtpErlangTuple fTuple) throws OtpErlangRangeException, ErlModelException {
final IErlModule mod = extractModule(fTuple.elementAt(0));
final String function = ((OtpErlangAtom) fTuple.elementAt(1)).atomValue();
final int arity = ((OtpErlangLong) fTuple.elementAt(2)).intValue();
final IErlFunctionClause f = ErlangEngine.getInstance().getModel().findFunction(new FunctionRef(mod.getModuleName(), function, arity));
return f;
}
use of org.erlide.engine.model.erlang.IErlFunctionClause in project erlide_eclipse by erlang.
the class CodeInspectionResultsView method createPartControl.
@Override
public void createPartControl(final Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
viewer.setContentProvider(new ViewContentProvider());
viewer.setLabelProvider(new ViewLabelProvider());
viewer.setInput(getViewSite());
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(final DoubleClickEvent event) {
final IStructuredSelection s = (IStructuredSelection) event.getSelection();
final Object o = s.getFirstElement();
if (o instanceof IErlModule) {
final IErlModule m = (IErlModule) o;
WranglerUtils.openFile((IFile) m.getResource());
} else if (o instanceof IErlFunctionClause) {
WranglerUtils.highlightSelection((IErlFunctionClause) o);
}
}
});
}
use of org.erlide.engine.model.erlang.IErlFunctionClause in project erlide_eclipse by erlang.
the class ErlangCompareUtilities method getErlElementID.
/**
* Returns a name for the given Erlang element
*/
static String getErlElementID(final IErlElement e) {
final StringBuilder sb = new StringBuilder();
final ErlElementKind kind = e.getKind();
sb.append(kind);
if (kind == ErlElementKind.FUNCTION) {
final IErlFunction f = (IErlFunction) e;
sb.append(f.getNameWithArity());
} else if (kind == ErlElementKind.CLAUSE) {
final IErlFunctionClause fc = (IErlFunctionClause) e;
sb.append(fc.getHead());
} else if (kind == ErlElementKind.ATTRIBUTE) {
final IErlAttribute a = (IErlAttribute) e;
sb.append(a.getName());
if (a.getValue() != null) {
sb.append(a.getValue().toString());
}
} else if (kind == ErlElementKind.RECORD_DEF || kind == ErlElementKind.MACRO_DEF) {
final IErlPreprocessorDef pd = (IErlPreprocessorDef) e;
sb.append(pd.getDefinedName());
}
return sb.toString();
}
use of org.erlide.engine.model.erlang.IErlFunctionClause 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;
}
use of org.erlide.engine.model.erlang.IErlFunctionClause in project erlide_eclipse by erlang.
the class ErlangCompletionService method getParameterNames.
List<String> getParameterNames(final IErlFunction function) {
final List<String> parameters = function.getParameters();
final int arity = function.getArity();
final List<String> result = new ArrayList<>(arity);
addEmptyParameterNames(arity, result);
addParametersFromFunctionParameters(parameters, result);
for (final IErlFunctionClause clause : function.getClauses()) {
addParametersFromFunctionParameters(clause.getParameters(), result);
}
return result;
}
Aggregations