Search in sources :

Example 56 with IErlModule

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

the class ErlangExternalsContentProvider method hasChildren.

@Override
public boolean hasChildren(final Object element0) {
    Object element = element0;
    if (element instanceof IProject) {
        final IProject project = (IProject) element;
        if (project.isOpen()) {
            element = ErlangEngine.getInstance().getModel().findProject(project);
        }
    }
    if (element instanceof IErlModule) {
        return erlangFileContentProvider.hasChildren(element);
    }
    if (element instanceof IParent) {
        if (element instanceof IErlExternalRoot || element instanceof IErlProject || element instanceof IErlModel) {
            // we know these have children
            return true;
        }
        final Stopwatch clock = Stopwatch.createStarted();
        if (element instanceof IOpenable) {
            final IOpenable openable = (IOpenable) element;
            try {
                openable.open(null);
            } catch (final ErlModelException e) {
            }
        }
        final IParent parent = (IParent) element;
        final boolean result = parent.hasChildrenOfKind(ErlElementKind.EXTERNAL_ROOT, ErlElementKind.EXTERNAL_APP, ErlElementKind.EXTERNAL_FOLDER, ErlElementKind.MODULE);
        if (clock.elapsed(TimeUnit.MILLISECONDS) > 100) {
            ErlLogger.debug("TIME open " + element.getClass() + " " + element + "  " + clock.elapsed(TimeUnit.MILLISECONDS) + " ms");
        }
        return result;
    }
    return false;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IOpenable(org.erlide.engine.model.root.IOpenable) IErlModel(org.erlide.engine.model.root.IErlModel) IParent(org.erlide.engine.model.IParent) ErlModelException(org.erlide.engine.model.ErlModelException) IErlExternalRoot(org.erlide.engine.model.root.IErlExternalRoot) IErlModule(org.erlide.engine.model.root.IErlModule) Stopwatch(com.google.common.base.Stopwatch) IProject(org.eclipse.core.resources.IProject)

Example 57 with IErlModule

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

the class ErlangFileContentProvider method elementChanged.

@Override
public void elementChanged(final IErlElement element) {
    if (element instanceof IErlModule) {
        final IErlModule m = (IErlModule) element;
        final IResource r = m.getResource();
        if (r instanceof IFile) {
            doRefresh((IFile) r);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IErlModule(org.erlide.engine.model.root.IErlModule) IResource(org.eclipse.core.resources.IResource)

Example 58 with IErlModule

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

the class ErlangFileContentProvider method getParent.

/**
 * Load the model from the given file, if possible.
 *
 * @param modelFile
 *            The IFile which contains the persisted model
 */
@Override
public Object getParent(final Object element) {
    if (element instanceof IErlElement) {
        final IErlElement elt = (IErlElement) element;
        final IParent parent = elt.getParent();
        if (parent instanceof IErlModule || parent instanceof IErlProject) {
            final IErlElement e = (IErlElement) parent;
            return e.getCorrespondingResource();
        }
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlProject(org.erlide.engine.model.root.IErlProject) IParent(org.erlide.engine.model.IParent) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 59 with IErlModule

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

the class FindAction method run.

/*
     * Method declared on SelectionChangedAction.
     */
@Override
public void run(final ITextSelection selection) {
    try {
        final IErlModule module = fEditor.getModule();
        if (module == null) {
            return;
        }
        final ISelection sel = getSelection();
        final ITextSelection textSel = (ITextSelection) sel;
        final int offset = textSel.getOffset();
        final OpenResult res = ErlangEngine.getInstance().getOpenService().open(module.getScannerName(), offset, ErlangEngine.getInstance().getModelUtilService().getImportsAsList(module), "", ErlangEngine.getInstance().getModel().getPathVars());
        ErlLogger.debug("find " + res);
        final ErlangSearchPattern ref = SearchUtil.getSearchPatternFromOpenResultAndLimitTo(module, offset, res, getLimitTo(), true);
        if (ref != null) {
            SearchUtil.runQuery(ref, getScope(), getScopeDescription(), getShell());
        }
    } catch (final Exception e) {
        handleException(e);
    }
}
Also used : OpenResult(org.erlide.engine.services.search.OpenResult) IErlModule(org.erlide.engine.model.root.IErlModule) ISelection(org.eclipse.jface.viewers.ISelection) ErlangSearchPattern(org.erlide.engine.services.search.ErlangSearchPattern) ITextSelection(org.eclipse.jface.text.ITextSelection) CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 60 with IErlModule

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

the class ErlangAbstractHandler method getTextSelection.

/**
 * Provide the text selection that is needed to execute the command. Default
 * implementation, extend to Erlang elements selected.
 *
 * @param document
 *            text {@link IDocument}
 * @param selection
 *            selection affected by command (extended by extendSelection)
 * @return new {@link ITextSelection} with all text up to selection
 */
protected ITextSelection getTextSelection(final IDocument document, final ITextSelection selection, final ITextEditor editor) {
    if (editor instanceof ErlangEditor) {
        final AbstractErlangEditor erlangEditor = (AbstractErlangEditor) editor;
        final IErlModule module = erlangEditor.getModule();
        if (module != null) {
            final int offset1 = selection.getOffset();
            final int offset2 = offset1 + selection.getLength();
            try {
                final IErlElement e1 = module.getElementAt(offset1);
                final IErlElement e2 = module.getElementAt(offset2);
                if (e1 instanceof ISourceReference) {
                    final ISourceReference ref1 = (ISourceReference) e1;
                    final ISourceRange r1 = ref1.getSourceRange();
                    final int offset = r1.getOffset();
                    int length = r1.getLength();
                    if (e1 == e2) {
                        final int docLength = document.getLength();
                        if (offset + length > docLength) {
                            length = docLength - offset;
                        }
                        return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, length));
                    } else if (e2 == null) {
                        return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, selection.getLength() + selection.getOffset() - offset));
                    } else if (e2 instanceof ISourceReference) {
                        final ISourceReference ref2 = (ISourceReference) e2;
                        final ISourceRange r2 = ref2.getSourceRange();
                        return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, r2.getOffset() - offset + r2.getLength()));
                    }
                }
            } catch (final ErlModelException e) {
            }
        }
    }
    return ErlangAbstractHandler.extendSelectionToWholeLines(document, selection);
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlModelException(org.erlide.engine.model.ErlModelException) ITextSelection(org.eclipse.jface.text.ITextSelection) TextSelection(org.eclipse.jface.text.TextSelection) IErlModule(org.erlide.engine.model.root.IErlModule) ISourceReference(org.erlide.engine.model.erlang.ISourceReference) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor) ErlangEditor(org.erlide.ui.editors.erl.ErlangEditor) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor) ISourceRange(org.erlide.engine.model.erlang.ISourceRange)

Aggregations

IErlModule (org.erlide.engine.model.root.IErlModule)191 Test (org.junit.Test)66 IErlProject (org.erlide.engine.model.root.IErlProject)57 IErlElement (org.erlide.engine.model.IErlElement)35 IFile (org.eclipse.core.resources.IFile)26 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)26 ErlModelException (org.erlide.engine.model.ErlModelException)22 IPath (org.eclipse.core.runtime.IPath)21 ErlProject (org.erlide.engine.internal.model.root.ErlProject)21 File (java.io.File)20 IErlModel (org.erlide.engine.model.root.IErlModel)18 Path (org.eclipse.core.runtime.Path)17 IProject (org.eclipse.core.resources.IProject)16 IResource (org.eclipse.core.resources.IResource)14 ArrayList (java.util.ArrayList)13 CoreException (org.eclipse.core.runtime.CoreException)10 IEditorPart (org.eclipse.ui.IEditorPart)10 IParent (org.erlide.engine.model.IParent)10 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)9 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)9