Search in sources :

Example 11 with IErlElement

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;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) CompletionData(org.erlide.engine.services.codeassist.CompletionData) FunctionCompletionData(org.erlide.engine.services.codeassist.FunctionCompletionData) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) ArrayList(java.util.ArrayList)

Example 12 with IErlElement

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;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlComment(org.erlide.engine.model.erlang.IErlComment) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 13 with IErlElement

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) IErlModel(org.erlide.engine.model.root.IErlModel) ErlModelStatus(org.erlide.engine.model.ErlModelStatus) ArrayList(java.util.ArrayList) IErlFolder(org.erlide.engine.model.root.IErlFolder) IErlElement(org.erlide.engine.model.IErlElement) CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 14 with IErlElement

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();
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlModelException(org.erlide.engine.model.ErlModelException) IErlElementVisitor(org.erlide.engine.model.IErlElementVisitor)

Example 15 with IErlElement

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;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IOpenable(org.erlide.engine.model.root.IOpenable) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementVisitor(org.erlide.engine.model.IErlElementVisitor)

Aggregations

IErlElement (org.erlide.engine.model.IErlElement)123 Test (org.junit.Test)36 IErlModule (org.erlide.engine.model.root.IErlModule)35 ErlModelException (org.erlide.engine.model.ErlModelException)28 IParent (org.erlide.engine.model.IParent)17 IFile (org.eclipse.core.resources.IFile)16 ArrayList (java.util.ArrayList)12 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)11 IResource (org.eclipse.core.resources.IResource)11 IErlProject (org.erlide.engine.model.root.IErlProject)10 IOpenable (org.erlide.engine.model.root.IOpenable)10 IProject (org.eclipse.core.resources.IProject)9 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)8 IErlModel (org.erlide.engine.model.root.IErlModel)8 WranglerException (org.erlide.wrangler.refactoring.exception.WranglerException)8 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)7 IFolder (org.eclipse.core.resources.IFolder)7 CoreException (org.eclipse.core.runtime.CoreException)7 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)6 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)6