Search in sources :

Example 6 with IErlFunctionClause

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;
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) IErlModule(org.erlide.engine.model.root.IErlModule) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause) FunctionRef(org.erlide.engine.model.erlang.FunctionRef)

Example 7 with IErlFunctionClause

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);
            }
        }
    });
}
Also used : IFile(org.eclipse.core.resources.IFile) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) IErlModule(org.erlide.engine.model.root.IErlModule) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableViewer(org.eclipse.jface.viewers.TableViewer) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause)

Example 8 with IErlFunctionClause

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();
}
Also used : ErlElementKind(org.erlide.engine.model.ErlElementKind) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause)

Example 9 with IErlFunctionClause

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;
}
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)

Example 10 with IErlFunctionClause

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;
}
Also used : ArrayList(java.util.ArrayList) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause)

Aggregations

IErlFunctionClause (org.erlide.engine.model.erlang.IErlFunctionClause)13 IErlElement (org.erlide.engine.model.IErlElement)6 ErlModelException (org.erlide.engine.model.ErlModelException)4 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)4 IErlModule (org.erlide.engine.model.root.IErlModule)4 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)3 ArrayList (java.util.ArrayList)3 IFile (org.eclipse.core.resources.IFile)3 IErlAttribute (org.erlide.engine.model.erlang.IErlAttribute)3 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)2 ISelection (org.eclipse.jface.viewers.ISelection)2 FunctionRef (org.erlide.engine.model.erlang.FunctionRef)2 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)1 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)1 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IProject (org.eclipse.core.resources.IProject)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1