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