use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class ErlangCompletionService method getDeclaredFunctions.
List<CompletionData> getDeclaredFunctions(final int offset, final String prefix, final boolean unexportedOnly, final boolean arityOnly) throws ErlModelException {
final List<CompletionData> result = new ArrayList<>();
for (final IErlElement e : module.getChildren()) {
if (e instanceof IErlFunction) {
final IErlFunction f = (IErlFunction) e;
if (unexportedOnly && f.isExported()) {
continue;
}
addFunctionCompletion(offset, prefix, result, f, arityOnly);
}
}
return result;
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class ErlParser method parse.
public boolean parse(final IErlModule module, final String scannerName, final boolean initialParse, final String path, final String initialText, final boolean updateSearchServer) {
if (module == null) {
return false;
}
OtpErlangList forms = null;
OtpErlangList comments = null;
OtpErlangTuple res = null;
if (initialParse) {
final String stateDir = ErlangEngine.getInstance().getStateDir();
final String pathNotNull = path == null ? "" : path;
res = ErlideNoparse.initialParse(backend, scannerName, pathNotNull, initialText, stateDir, updateSearchServer);
} else {
res = ErlideNoparse.reparse(backend, scannerName, updateSearchServer);
}
if (Util.isOk(res)) {
final OtpErlangTuple t = (OtpErlangTuple) res.elementAt(1);
forms = (OtpErlangList) t.elementAt(1);
comments = (OtpErlangList) t.elementAt(2);
} else {
ErlLogger.error("error when parsing %s: %s", path, res);
}
if (forms == null) {
module.setChildren(null);
} else {
final List<IErlElement> children = createForms(module, forms);
module.setChildren(children);
}
if (comments == null) {
module.setComments(null);
} else {
final List<IErlComment> moduleComments = createComments(module, comments);
module.setComments(moduleComments);
}
attachFunctionComments(module);
String cached = "reparsed";
if (res != null && res.arity() > 2) {
final OtpErlangObject res2 = res.elementAt(2);
if (res2 instanceof OtpErlangAtom) {
final OtpErlangAtom atom = (OtpErlangAtom) res2;
cached = atom.atomValue();
}
}
if (ErlParser.TRACE) {
ErlLogger.debug("Parsed %d forms and %d comments (%s)", forms != null ? forms.arity() : 0, comments != null ? comments.arity() : 0, cached);
}
return forms != null && comments != null;
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class ErlProject method buildStructure.
@Override
public boolean buildStructure(final IProgressMonitor pm) throws ErlModelException {
final IResource r = getCorrespondingResource();
// check whether the Erlang project can be opened
if (!(r instanceof IContainer) || !r.isAccessible()) {
ErlLogger.warn("Project %s has no resources: res:%s acc:%s cont:%s", getName(), r, r == null ? "?" : r.isAccessible(), r instanceof IContainer);
throw new ErlModelException(new ErlModelStatus(ErlModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this));
}
addConfigurationChangeListeners();
try {
final IContainer c = (IContainer) r;
final IResource[] elems = c.members();
final List<IErlElement> children = new ArrayList<>(elems.length + 1);
// ErlLogger.debug(">>adding externals");
addExternals(children);
// ErlLogger.debug("childcount %d", children.size());
// ErlLogger.debug(">>adding otp");
addOtpExternals(children);
// ErlLogger.debug("childcount %d", children.size());
final IErlModel model = ErlangEngine.getInstance().getModel();
for (final IResource element : elems) {
if (element instanceof IFolder) {
final IFolder folder = (IFolder) element;
final IErlFolder erlFolder = (IErlFolder) model.create(folder);
children.add(erlFolder);
} else if (element instanceof IFile) {
final IFile file = (IFile) element;
if (CommonUtils.isErlangFileContentFileName(file.getName())) {
final IErlModule m = (IErlModule) model.create(file);
children.add(m);
}
}
}
setChildren(children);
} catch (final CoreException e) {
ErlLogger.error(e);
setChildren(new ArrayList<IErlModule>());
return false;
}
return true;
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class ErlProject method dispose.
@Override
public void dispose() {
removeConfigurationChangeListeners();
clearCaches();
try {
accept(new IErlElementVisitor() {
@Override
public boolean visit(final IErlElement element) throws ErlModelException {
element.dispose();
return false;
}
}, EnumSet.of(AcceptFlags.CHILDREN_FIRST, AcceptFlags.LEAFS_ONLY), ErlElementKind.MODULE);
} catch (final ErlModelException e) {
}
super.dispose();
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class ErlProject method getExternalModules.
@Override
public Collection<IErlModule> getExternalModules() throws ErlModelException {
final List<IErlModule> result = Lists.newArrayList();
accept(new IErlElementVisitor() {
@Override
public boolean visit(final IErlElement element) throws ErlModelException {
final boolean isExternalOrProject = element.getKind() == ErlElementKind.EXTERNAL_ROOT || element.getKind() == ErlElementKind.EXTERNAL_APP || element.getKind() == ErlElementKind.EXTERNAL_FOLDER || element.getKind() == ErlElementKind.PROJECT;
if (element instanceof IErlModule) {
final IErlModule module = (IErlModule) element;
if (module.getAncestorOfKind(ErlElementKind.PROJECT) == ErlProject.this) {
result.add(module);
}
return false;
} else if (isExternalOrProject && element instanceof IOpenable) {
final IOpenable openable = (IOpenable) element;
openable.open(null);
}
return isExternalOrProject;
}
}, EnumSet.noneOf(AcceptFlags.class), ErlElementKind.MODULE);
return result;
}
Aggregations