use of org.erlide.engine.model.erlang.IErlAttribute in project erlide_eclipse by erlang.
the class ParserDB method handleModule.
public void handleModule(final IErlModule module) throws ErlModelException {
module.open(null);
final int numForms = module.getChildCount();
final String path = module.getResource().getLocation().toPortableString();
ParserDB.out.println(path + " " + numForms + " " + isTest(path));
System.out.println(path + " " + numForms + " " + isTest(path));
for (final IErlElement form : module.getChildren()) {
ParserDB.out.print(" " + form.getKind() + " ");
if (form instanceof IErlImportExport) {
final IErlImportExport export = (IErlImportExport) form;
ParserDB.out.println(export.getFunctions().size());
} else if (form instanceof IErlPreprocessorDef) {
final IErlPreprocessorDef def = (IErlPreprocessorDef) form;
ParserDB.out.println(fix(def.getDefinedName()));
} else if (form instanceof IErlTypespec) {
final IErlTypespec attribute = (IErlTypespec) form;
ParserDB.out.println("TYPESPEC " + fix(attribute.getName()));
} else if (form instanceof IErlAttribute) {
final IErlAttribute attribute = (IErlAttribute) form;
ParserDB.out.println(fix(attribute.getName()));
} else if (form instanceof IErlFunction) {
final IErlFunction function = (IErlFunction) form;
int numClauses = function.getChildCount();
numClauses = numClauses == 0 ? 1 : numClauses;
ParserDB.out.println(fix(function.getName()) + " " + function.getArity() + " " + numClauses);
} else {
ParserDB.out.println("?? " + form.getClass().getName());
}
}
module.close();
module.dispose();
}
use of org.erlide.engine.model.erlang.IErlAttribute in project erlide_eclipse by erlang.
the class ErlParser method addModuleAttribute.
private IErlAttribute addModuleAttribute(final IErlModule module, final OtpErlangObject pos, final OtpErlangAtom value, final OtpErlangObject extra, final String nameS) {
final String s = Util.stringValue(extra);
final ErlAttribute r = new ErlAttribute(module, nameS, value, s);
setPos(r, pos);
return r;
}
use of org.erlide.engine.model.erlang.IErlAttribute in project erlide_eclipse by erlang.
the class SearchPatternFactory method getSearchPatternFromErlElementAndLimitTo.
public ErlangSearchPattern getSearchPatternFromErlElementAndLimitTo(final IErlElement element, final LimitTo limitTo) {
if (element instanceof IErlFunction) {
final IErlFunction function = (IErlFunction) element;
final String withoutExtension = SystemConfiguration.withoutExtension(function.getModuleName());
return new FunctionPattern(withoutExtension, function.getFunctionName(), function.getArity(), limitTo, true, modelUtilService.getModule(function), !function.isExported());
} else if (element instanceof IErlMacroDef) {
final IErlMacroDef m = (IErlMacroDef) element;
final String unquoted = StringUtils.unquote(m.getDefinedName());
return new MacroPattern(unquoted, limitTo);
} else if (element instanceof IErlRecordDef) {
final IErlRecordDef r = (IErlRecordDef) element;
final String unquoted = StringUtils.unquote(r.getDefinedName());
return new RecordPattern(unquoted, limitTo);
} else if (element instanceof IErlFunctionClause) {
final IErlFunctionClause clause = (IErlFunctionClause) element;
return getSearchPatternFromErlElementAndLimitTo((IErlElement) clause.getParent(), limitTo);
} else if (element instanceof IErlAttribute) {
final IErlAttribute a = (IErlAttribute) element;
if (a.getName().startsWith("include")) {
final String s = Util.stringValue(a.getValue());
return new IncludePattern(s, limitTo);
}
}
return null;
}
use of org.erlide.engine.model.erlang.IErlAttribute in project erlide_eclipse by erlang.
the class AddRefacHandler method checkType.
// check if the refactoring is elementary or composite
private RefacType checkType(final String callbackModule) {
try {
final IErlModule module = ErlangEngine.getInstance().getModel().findModule(callbackModule);
final ScannerService scanner = module.getScanner();
try {
module.resetAndCacheScannerAndParser(null);
} finally {
scanner.dispose();
}
for (final IErlElement el : module.getChildrenOfKind(ErlElementKind.ATTRIBUTE)) {
final IErlAttribute attr = (IErlAttribute) el;
if ("behaviour".equals(attr.getName()) || "behavior".equals(attr.getName())) {
if (attr.getValue().toString().contains("gen_refac")) {
return RefacType.ELEMENTARY;
} else if (attr.getValue().toString().contains("gen_composite_refac")) {
return RefacType.COMPOSITE;
}
}
}
return null;
} catch (final ErlModelException e) {
return null;
}
}
use of org.erlide.engine.model.erlang.IErlAttribute 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();
}
Aggregations