Search in sources :

Example 71 with IErlElement

use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.

the class SearchUtil method getWorkingSetsScope.

public static ErlSearchScope getWorkingSetsScope(final IWorkingSet[] workingSets, final boolean addExternals, final boolean addOTP) throws CoreException {
    final ErlSearchScope result = new ErlSearchScope();
    final Set<String> externalModulePaths = new HashSet<>();
    if (workingSets == null) {
        return result;
    }
    for (final IWorkingSet ws : workingSets) {
        final IAdaptable[] elements = ws.getElements();
        for (final IAdaptable a : elements) {
            final IResource r = a.getAdapter(IResource.class);
            SearchCoreUtil.addResourceToScope(result, r);
            IParent parent = null;
            Object o = a.getAdapter(IErlElement.class);
            if (o instanceof IParent) {
                parent = (IParent) o;
            } else {
                o = a.getAdapter(IResource.class);
                if (o != null) {
                    final IResource resource = (IResource) o;
                    final IErlElement element = ErlangEngine.getInstance().getModel().findElement(resource);
                    if (element instanceof IParent) {
                        parent = (IParent) element;
                    }
                }
            }
            if (parent != null) {
                SearchCoreUtil.addExternalModules(parent, result, externalModulePaths, addExternals, addOTP);
            }
        }
    }
    return result;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IAdaptable(org.eclipse.core.runtime.IAdaptable) IParent(org.erlide.engine.model.IParent) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ErlSearchScope(org.erlide.engine.services.search.ErlSearchScope) IWorkingSet(org.eclipse.ui.IWorkingSet) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 72 with IErlElement

use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.

the class FindAction method getProjects.

protected Collection<IProject> getProjects() {
    final TextEditor editor = getEditor();
    if (editor != null) {
        final IEditorInput editorInput = editor.getEditorInput();
        if (editorInput instanceof IFileEditorInput) {
            final IFileEditorInput input = (IFileEditorInput) editorInput;
            final IFile file = input.getFile();
            final IProject project = file.getProject();
            return Lists.newArrayList(project);
        }
    } else {
        final IWorkbenchSite site = getSite();
        final ISelection selection = site.getSelectionProvider().getSelection();
        if (selection instanceof IStructuredSelection) {
            final IStructuredSelection ss = (IStructuredSelection) selection;
            final Collection<IProject> result = Sets.newHashSet();
            for (final Object element : ss.toList()) {
                if (element instanceof IErlElement) {
                    final IErlElement e = (IErlElement) element;
                    result.add(e.getResource().getProject());
                } else if (element instanceof IResource) {
                    final IResource r = (IResource) element;
                    result.add(r.getProject());
                }
            }
            return result;
        }
    }
    return null;
}
Also used : IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) IErlElement(org.erlide.engine.model.IErlElement) TextEditor(org.eclipse.ui.editors.text.TextEditor) IFile(org.eclipse.core.resources.IFile) IFileEditorInput(org.eclipse.ui.IFileEditorInput) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorInput(org.eclipse.ui.IEditorInput) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Example 73 with IErlElement

use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.

the class ErlElementDelta method getAncestors.

private List<IParent> getAncestors(final IErlElement element0) {
    IErlElement element = element0;
    IParent parent = element.getParent();
    if (parent == null) {
        return null;
    }
    final ArrayList<IParent> parents = Lists.newArrayList();
    while (!parent.equals(fElement)) {
        parents.add(parent);
        if (parent instanceof IErlElement) {
            element = (IErlElement) parent;
            parent = element.getParent();
        } else {
            break;
        }
        if (parent == null) {
            break;
        }
    }
    parents.trimToSize();
    return parents;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IParent(org.erlide.engine.model.IParent)

Example 74 with IErlElement

use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.

the class ErlElementDelta method createDeltaTree.

/**
 * Creates the nested delta deltas based on the affected element its delta, and the
 * root of this delta tree. Returns the root of the created delta tree.
 */
protected ErlElementDelta createDeltaTree(final IErlElement element, final ErlElementDelta delta) {
    ErlElementDelta childDelta = delta;
    final List<IParent> ancestors = getAncestors(element);
    if (ancestors == null) {
        if (equalsAndSameParent(delta.getElement(), getElement())) {
            // handle case of two jars that can be equals but not in the
            // same project
            // the element being changed is the root element
            fKind = delta.fKind;
            fFlags = delta.fFlags;
            fMovedToElement = delta.fMovedToElement;
            fMovedFromElement = delta.fMovedFromElement;
        } else {
        // the given delta is not the root or a child - illegal
        // Assert.isTrue(false);
        }
    } else {
        for (final IParent ancestor : ancestors) {
            final IErlElement element2 = (IErlElement) ancestor;
            final ErlElementDelta ancestorDelta = new ErlElementDelta(0, 0, element2);
            ancestorDelta.addAffectedChild(childDelta);
            childDelta = ancestorDelta;
        }
    }
    return childDelta;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IParent(org.erlide.engine.model.IParent) IErlElementDelta(org.erlide.engine.model.root.IErlElementDelta)

Example 75 with IErlElement

use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.

the class ErlModule method getIncludeFiles.

@Override
public Collection<ErlangIncludeFile> getIncludeFiles() throws ErlModelException {
    if (!isStructureKnown()) {
        open(null);
    }
    final List<ErlangIncludeFile> r = Lists.newArrayList();
    synchronized (getModelLock()) {
        for (final IErlElement m : internalGetChildren()) {
            if (m instanceof IErlAttribute) {
                final IErlAttribute a = (IErlAttribute) m;
                final OtpErlangObject v = a.getValue();
                if (v instanceof OtpErlangString) {
                    final String s = ((OtpErlangString) v).stringValue();
                    if ("include".equals(a.getName())) {
                        r.add(new ErlangIncludeFile(false, s));
                    } else if ("include_lib".equals(a.getName())) {
                        r.add(new ErlangIncludeFile(true, s));
                    }
                }
            }
        }
    }
    return r;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlangIncludeFile(org.erlide.engine.model.erlang.ErlangIncludeFile) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

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