Search in sources :

Example 91 with IErlElement

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

Example 92 with IErlElement

use of org.erlide.engine.model.IErlElement 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);
    }
}
Also used : IErlComment(org.erlide.engine.model.erlang.IErlComment) IErlElement(org.erlide.engine.model.IErlElement) IErlMember(org.erlide.engine.model.erlang.IErlMember) ErlModelException(org.erlide.engine.model.ErlModelException)

Example 93 with IErlElement

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

the class ErlangLineBreakpointPropertyPage method createTypeSpecificLabels.

@Override
protected void createTypeSpecificLabels(final Composite parent) {
    createLabel(parent, "Module:");
    final String moduleName = getBreakpoint().getMarker().getResource().getName();
    createText(parent, SWT.READ_ONLY, moduleName).setBackground(parent.getBackground());
    // Line number
    final ILineBreakpoint breakpoint = (ILineBreakpoint) getBreakpoint();
    final StringBuilder lineNumber = new StringBuilder(4);
    try {
        final int lNumber = breakpoint.getLineNumber();
        if (lNumber > 0) {
            lineNumber.append(lNumber);
        }
    } catch (final CoreException ce) {
        ErlLogger.error(ce);
    }
    if (lineNumber.length() > 0) {
        createLabel(parent, "&Line Number:");
        final String string = lineNumber.toString();
        createText(parent, SWT.READ_ONLY, string).setBackground(parent.getBackground());
    }
    final IErlElement element = BreakpointUtils.getElement(breakpoint);
    if (element == null) {
        return;
    }
    createLabel(parent, "Function:");
    createText(parent, SWT.READ_ONLY, element.toString()).setBackground(parent.getBackground());
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) CoreException(org.eclipse.core.runtime.CoreException) ILineBreakpoint(org.eclipse.debug.core.model.ILineBreakpoint) ILineBreakpoint(org.eclipse.debug.core.model.ILineBreakpoint) IErlangBreakpoint(org.erlide.backend.debug.IErlangBreakpoint)

Example 94 with IErlElement

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

the class ErlangLinkHelperAction method activateEditor.

@Override
public void activateEditor(final IWorkbenchPage page, final IStructuredSelection selection) {
    final Object element = selection.getFirstElement();
    final IEditorPart part = EditorUtility.isOpenInEditor(element);
    if (part != null) {
        page.bringToTop(part);
        if (element instanceof IErlElement) {
            EditorUtility.revealInEditor(part, (IErlElement) element);
        }
    }
// if (selection == null || selection.isEmpty()) {
// return;
// }
// 
// final Object firstElement = selection.getFirstElement();
// 
// if (firstElement instanceof IErlElement) {
// final IErlElement e = (IErlElement) firstElement;
// 
// }
// // if it is an erlang element, let's first get the actual object for
// // finding the editor
// 
// // and now, if it is really a file...
// if (firstElement instanceof IFile) {
// final IEditorInput fileInput = new FileEditorInput(
// (IFile) firstElement);
// IEditorPart editor = null;
// if ((editor = page.findEditor(fileInput)) != null) {
// page.bringToTop(editor);
// }
// }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IEditorPart(org.eclipse.ui.IEditorPart)

Example 95 with IErlElement

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

the class ErlangFileLabelProvider method getImage.

@Override
public Image getImage(final Object element) {
    if (element instanceof IErlElement) {
        final IErlElement e = (IErlElement) element;
        final ImageDescriptor desc = ErlangElementImageProvider.getErlImageDescriptor(e, ErlangElementImageProvider.SMALL_ICONS);
        final Image img = ErlideUIPlugin.getImageDescriptorRegistry().get(desc);
        return fProblemDecorator.decorateImage(img, e);
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Image(org.eclipse.swt.graphics.Image)

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