Search in sources :

Example 1 with RecordPattern

use of org.erlide.engine.services.search.RecordPattern 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;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) TypeRefPattern(org.erlide.engine.services.search.TypeRefPattern) FunctionPattern(org.erlide.engine.services.search.FunctionPattern) VariablePattern(org.erlide.engine.services.search.VariablePattern) IncludePattern(org.erlide.engine.services.search.IncludePattern) OpenUtils(org.erlide.ui.actions.OpenUtils) RecordPattern(org.erlide.engine.services.search.RecordPattern) RecordFieldPattern(org.erlide.engine.services.search.RecordFieldPattern) MacroPattern(org.erlide.engine.services.search.MacroPattern) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause)

Aggregations

IErlElement (org.erlide.engine.model.IErlElement)1 IErlFunctionClause (org.erlide.engine.model.erlang.IErlFunctionClause)1 FunctionPattern (org.erlide.engine.services.search.FunctionPattern)1 IncludePattern (org.erlide.engine.services.search.IncludePattern)1 MacroPattern (org.erlide.engine.services.search.MacroPattern)1 RecordFieldPattern (org.erlide.engine.services.search.RecordFieldPattern)1 RecordPattern (org.erlide.engine.services.search.RecordPattern)1 TypeRefPattern (org.erlide.engine.services.search.TypeRefPattern)1 VariablePattern (org.erlide.engine.services.search.VariablePattern)1 OpenUtils (org.erlide.ui.actions.OpenUtils)1