use of org.erlide.engine.model.erlang.IErlPreprocessorDef 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.IErlPreprocessorDef in project erlide_eclipse by erlang.
the class IndexedErlangValue method checkRecord.
private IErlRecordDef checkRecord(final OtpErlangObject o) {
if (o instanceof OtpErlangTuple) {
final OtpErlangTuple t = (OtpErlangTuple) o;
final OtpErlangObject h = t.elementAt(0);
if (h instanceof OtpErlangAtom) {
final OtpErlangAtom a = (OtpErlangAtom) h;
final ErlangDebugTarget target = getErlangDebugTarget();
IErlPreprocessorDef pd;
try {
pd = ErlangEngine.getInstance().getModelFindService().findPreprocessorDef(getErlProjects(target.getProjects()), moduleName, a.atomValue(), ErlElementKind.RECORD_DEF);
if (pd instanceof IErlRecordDef) {
final IErlRecordDef r = (IErlRecordDef) pd;
if (r.hasChildren() && r.getChildCount() + 1 == t.arity()) {
return r;
}
}
} catch (final CoreException e) {
}
}
}
return null;
}
use of org.erlide.engine.model.erlang.IErlPreprocessorDef in project erlide_eclipse by erlang.
the class ErlTextHover method internalGetHoverInfo.
private static ErlangBrowserInformationControlInput internalGetHoverInfo(final AbstractErlangEditor editor, final ITextViewer textViewer, final IRegion hoverRegion) {
if (editor == null) {
return null;
}
final StringBuffer result = new StringBuffer();
OpenResult element = null;
// TODO our model is too coarse, here we need access to expressions
final Collection<OtpErlangObject> fImports = ErlangEngine.getInstance().getModelUtilService().getImportsAsList(editor.getModule());
final int offset = hoverRegion.getOffset();
final int length = hoverRegion.getLength();
final String debuggerVar = ErlTextHover.makeDebuggerVariableHover(textViewer, offset, length);
if (!debuggerVar.isEmpty()) {
result.append(debuggerVar);
}
final IErlProject erlProject = editor.getProject();
String docPath = "";
String anchor = "";
try {
if (erlProject == null) {
return null;
}
final IOtpRpc backend = BackendCore.getBuildBackend(erlProject);
if (backend == null) {
return null;
}
final IErlModel model = ErlangEngine.getInstance().getModel();
final String externalModulesString = erlProject.getProperties().getExternalModules();
final OtpErlangTuple t = (OtpErlangTuple) ErlangEngine.getInstance().getOtpDocService().getOtpDoc(backend, offset, editor.getScannerName(), fImports, externalModulesString, model.getPathVars());
if (Util.isOk(t)) {
element = new OpenResult(t.elementAt(2));
final String docStr = Util.stringValue(t.elementAt(1));
result.append(docStr);
if (t.arity() > 4) {
docPath = Util.stringValue(t.elementAt(3));
anchor = Util.stringValue(t.elementAt(4));
}
} else {
element = new OpenResult(t);
final Object found = new OpenUtils().findOpenResult(editor, editor.getModule(), erlProject, element, editor.getElementAt(offset, false));
if (found instanceof IErlFunction) {
final IErlFunction function = (IErlFunction) found;
final String comment = DocumentationFormatter.getDocumentationString(function.getComments(), function.getTypespec());
if (comment.isEmpty()) {
return null;
}
result.append(comment);
} else if (found instanceof IErlPreprocessorDef) {
final IErlPreprocessorDef preprocessorDef = (IErlPreprocessorDef) found;
result.append(preprocessorDef.getExtra());
}
}
} catch (final Exception e) {
ErlLogger.warn(e);
return null;
}
final String strResult = HoverUtil.getHTML(result);
return new ErlangBrowserInformationControlInput(null, editor, element, strResult, 20, HoverUtil.getDocumentationURL(docPath, anchor));
}
use of org.erlide.engine.model.erlang.IErlPreprocessorDef in project erlide_eclipse by erlang.
the class ErlangCompletionService method getAllPreprocessorDefs.
public static List<IErlPreprocessorDef> getAllPreprocessorDefs(final IErlModule module, final ErlElementKind kind) throws CoreException {
final List<IErlPreprocessorDef> result = Lists.newArrayList();
final List<IErlModule> modulesWithIncludes = Lists.newArrayList(ErlangEngine.getInstance().getModelFindService().findAllIncludedFiles(module));
modulesWithIncludes.add(module);
for (final IErlModule m : modulesWithIncludes) {
result.addAll(m.getPreprocessorDefs(kind));
}
return result;
}
use of org.erlide.engine.model.erlang.IErlPreprocessorDef in project erlide_eclipse by erlang.
the class ModelFindUtil method findPreprocessorDef.
@Override
public IErlPreprocessorDef findPreprocessorDef(final IErlModule module, final String definedName, final ErlElementKind kind) throws CoreException {
String unquoted = StringUtils.unquote(definedName);
final String quoted = StringUtils.quote(definedName);
final Set<String> names = new HashSet<>(3);
if (kind == ErlElementKind.RECORD_DEF) {
while (names.add(unquoted)) {
unquoted = resolveMacroValue(unquoted, module);
}
} else {
names.add(unquoted);
}
names.add(quoted);
names.add(definedName);
final List<IErlModule> allIncludedFiles = Lists.newArrayList(findAllIncludedFiles(module));
allIncludedFiles.add(0, module);
for (final IErlModule includedFile : allIncludedFiles) {
for (final String name : names) {
includedFile.open(null);
final IErlPreprocessorDef preprocessorDef = includedFile.findPreprocessorDef(name, kind);
if (preprocessorDef != null) {
return preprocessorDef;
}
}
}
return null;
}
Aggregations