Search in sources :

Example 11 with IErlPreprocessorDef

use of org.erlide.engine.model.erlang.IErlPreprocessorDef 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 12 with IErlPreprocessorDef

use of org.erlide.engine.model.erlang.IErlPreprocessorDef in project erlide_eclipse by erlang.

the class ModelFindUtil method resolveMacroValue.

@Override
public String resolveMacroValue(final String definedName, final IErlModule module) {
    if (module != null) {
        if ("?MODULE".equals(definedName)) {
            return module.getModuleName();
        }
        final IErlPreprocessorDef def = module.findPreprocessorDef(ModelFindUtil.withoutInterrogationMark(definedName), ErlElementKind.MACRO_DEF);
        if (def != null) {
            final String extra = def.getExtra();
            final int p = extra.indexOf(',');
            if (p != -1) {
                final String s = extra.substring(p + 1).trim();
                if (!s.isEmpty()) {
                    return s;
                }
            }
        }
    }
    return definedName;
}
Also used : IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef)

Example 13 with IErlPreprocessorDef

use of org.erlide.engine.model.erlang.IErlPreprocessorDef in project erlide_eclipse by erlang.

the class ErlangCompletionService method getRecordFieldCompletions.

List<CompletionData> getRecordFieldCompletions(final String recordName, final int offset, final String prefix, final int hashMarkPos, final List<String> fieldsSoFar) {
    if (module == null) {
        return ErlangCompletionService.EMPTY_COMPLETIONS;
    }
    IErlPreprocessorDef pd;
    try {
        pd = ErlangEngine.getInstance().getModelFindService().findPreprocessorDef(module, recordName, ErlElementKind.RECORD_DEF);
    } catch (final CoreException e) {
        return ErlangCompletionService.EMPTY_COMPLETIONS;
    }
    if (pd instanceof IErlRecordDef) {
        final List<CompletionData> result = new ArrayList<>();
        try {
            for (final IErlElement i : pd.getChildren()) {
                final IErlRecordField field = (IErlRecordField) i;
                final String fieldName = field.getFieldName();
                if (!fieldsSoFar.contains(fieldName)) {
                    addIfMatches(fieldName, prefix, offset, result);
                }
            }
        } catch (final ErlModelException e) {
        }
        return result;
    }
    return ErlangCompletionService.EMPTY_COMPLETIONS;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) CompletionData(org.erlide.engine.services.codeassist.CompletionData) FunctionCompletionData(org.erlide.engine.services.codeassist.FunctionCompletionData) CoreException(org.eclipse.core.runtime.CoreException) IErlRecordDef(org.erlide.engine.model.erlang.IErlRecordDef) ErlModelException(org.erlide.engine.model.ErlModelException) ArrayList(java.util.ArrayList) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) IErlRecordField(org.erlide.engine.model.erlang.IErlRecordField)

Example 14 with IErlPreprocessorDef

use of org.erlide.engine.model.erlang.IErlPreprocessorDef in project erlide_eclipse by erlang.

the class ErlangCompletionService method getMacroOrRecordCompletions.

List<CompletionData> getMacroOrRecordCompletions(final int offset, final String prefix, final ErlElementKind kind) {
    if (module == null) {
        return ErlangCompletionService.EMPTY_COMPLETIONS;
    }
    final List<CompletionData> result = new ArrayList<>();
    try {
        final List<IErlPreprocessorDef> defs = ErlangCompletionService.getAllPreprocessorDefs(module, kind);
        for (final IErlPreprocessorDef pd : defs) {
            final String name = pd.getDefinedName();
            addIfMatches(name, prefix, offset, result);
        }
    } catch (final CoreException e) {
        ErlLogger.error(e);
    }
    if (kind == ErlElementKind.MACRO_DEF) {
        final String[] names = ErlangEngine.getInstance().getModelUtilService().getPredefinedMacroNames();
        for (final String name : names) {
            addIfMatches(name, prefix, offset, result);
        }
    }
    return result;
}
Also used : CompletionData(org.erlide.engine.services.codeassist.CompletionData) FunctionCompletionData(org.erlide.engine.services.codeassist.FunctionCompletionData) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef)

Aggregations

IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)14 IErlModule (org.erlide.engine.model.root.IErlModule)7 IErlProject (org.erlide.engine.model.root.IErlProject)6 Test (org.junit.Test)5 IErlRecordDef (org.erlide.engine.model.erlang.IErlRecordDef)4 CoreException (org.eclipse.core.runtime.CoreException)3 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)2 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ErlProject (org.erlide.engine.internal.model.root.ErlProject)2 IErlElement (org.erlide.engine.model.IErlElement)2 IErlAttribute (org.erlide.engine.model.erlang.IErlAttribute)2 CompletionData (org.erlide.engine.services.codeassist.CompletionData)2 FunctionCompletionData (org.erlide.engine.services.codeassist.FunctionCompletionData)2 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)1 HashSet (java.util.HashSet)1 IPath (org.eclipse.core.runtime.IPath)1