use of org.erlide.engine.model.ErlModelException 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.ErlModelException in project erlide_eclipse by erlang.
the class ErlangCompletionService method addFunctionsFromModule.
boolean addFunctionsFromModule(final int offset, final String prefix, final boolean arityOnly, final List<CompletionData> proposals, final IErlModule m) {
boolean result = false;
try {
m.open(null);
for (final IErlElement e : m.getChildren()) {
if (e instanceof IErlFunction) {
final IErlFunction f = (IErlFunction) e;
if (f.isExported()) {
addFunctionCompletion(offset, prefix, proposals, f, arityOnly);
result = true;
}
}
}
} catch (final ErlModelException e) {
ErlLogger.error(e);
}
return result;
}
use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.
the class ErlParser method attachFunctionComments.
/**
* attach local function documentation with heuristics: if a comment is within 3 lines
* before function, or a sequence of comment, -spec, comment, then they should be
* added to function documentation
*
* If any typespec is available for the function (wherever it is located), then it
* should be attached too.
*
* @param module
*/
private void attachFunctionComments(final IErlModule module) {
// TODO rewrite in Erlang? would be so much less code...
try {
final Collection<IErlComment> comments = module.getComments();
final List<IErlElement> children = module.getChildren();
final List<IErlMember> all = Lists.newArrayListWithCapacity(children.size() + comments.size());
all.addAll(comments);
for (final IErlElement element : children) {
if (element instanceof IErlMember) {
all.add((IErlMember) element);
}
}
all.sort(new SourceOffsetComparator());
for (int i = 1; i < all.size(); i++) {
checkForComment(all, i);
}
} catch (final ErlModelException e) {
ErlLogger.warn(e);
}
}
use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.
the class InterpretedModuleListContentProvider method addModules.
/**
* Find modules from string list add to IFile-list
*
* @param interpret
* the list of strings from prefs (projectName:fileName;... or
* moduleName;...)
*/
public void addModules(final Collection<String> interpret) {
final IErlModel model = ErlangEngine.getInstance().getModel();
for (final String projectColonModule : interpret) {
// project:module | module
final String[] projectModule = projectColonModule.split(":");
IErlModule module = null;
if (projectModule.length > 1) {
final IErlProject project = (IErlProject) model.getChildNamed(projectModule[0]);
if (project != null) {
final String mName = projectModule[1];
try {
final boolean isErlangFile = CommonUtils.isErlangFileContentFileName(mName);
final String s = isErlangFile ? mName : mName + ".erl";
module = project.getModule(s);
} catch (final ErlModelException e) {
ErlLogger.warn(e);
}
}
} else {
try {
module = model.findModule(projectColonModule);
} catch (final ErlModelException e) {
}
}
addModule(module);
}
}
use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.
the class RunDialyzerHandler method collectModulesFromSelection.
private Set<IErlModule> collectModulesFromSelection(final ISelection selection) {
final Set<IErlModule> modules = Sets.newHashSet();
if (selection instanceof IStructuredSelection) {
final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
final IErlModel model = ErlangEngine.getInstance().getModel();
try {
model.open(null);
for (final Object i : structuredSelection.toList()) {
if (i instanceof IResource) {
final IResource r = (IResource) i;
modules.addAll(DialyzerUtils.collectModulesFromResource(model, r));
}
}
} catch (final ErlModelException e) {
ErlLogger.debug(e);
}
}
return modules;
}
Aggregations