use of org.erlide.engine.services.search.FunctionPattern 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