Search in sources :

Example 6 with IErlAttribute

use of org.erlide.engine.model.erlang.IErlAttribute 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)

Example 7 with IErlAttribute

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

the class ErlParser method addOtherAttribute.

private IErlAttribute addOtherAttribute(final IErlModule module, final OtpErlangObject pos, final OtpErlangObject val, final OtpErlangObject extra, final String nameS) {
    // user-defined attribute? or maybe if else endif...
    // OtpErlangObject val1 = concreteTerm(val);
    // if (val instanceof OtpErlangList) {
    // final OtpErlangList list = (OtpErlangList) val;
    // if (list.arity() == 0) {
    // val1 = null;
    // }
    // }
    // final ErlAttribute a = new ErlAttribute(parent, nameS, val1, null);
    OtpErlangObject o = val;
    if (o instanceof OtpErlangAtom) {
        final OtpErlangAtom u = (OtpErlangAtom) o;
        if ("u".equals(u.atomValue())) {
            o = null;
        }
    }
    final ErlAttribute a = new ErlAttribute(module, nameS, o, Util.stringValue(extra));
    setPos(a, pos);
    // a.setParseTree(val);
    return a;
}
Also used : IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) ErlAttribute(org.erlide.engine.internal.model.erlang.ErlAttribute) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 8 with IErlAttribute

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

the class ErlangEditor method setSelection.

public void setSelection(final ISourceReference reference, final boolean moveCursor) {
    if (getSelectionProvider() == null) {
        return;
    }
    final ISelection selection = getSelectionProvider().getSelection();
    if (selection instanceof TextSelection) {
        final TextSelection textSelection = (TextSelection) selection;
        if (moveCursor && (textSelection.getOffset() != 0 || textSelection.getLength() != 0)) {
            markInNavigationHistory();
        }
    }
    if (reference != null) {
        StyledText textWidget = null;
        final ISourceViewer sourceViewer = getSourceViewer();
        if (sourceViewer == null) {
            return;
        }
        textWidget = sourceViewer.getTextWidget();
        if (textWidget == null) {
            return;
        }
        try {
            ISourceRange range = null;
            range = reference.getSourceRange();
            if (range == null) {
                return;
            }
            int offset = range.getOffset();
            int length = range.getLength();
            if (offset < 0 || length < 0) {
                return;
            }
            setHighlightRange(offset, length, moveCursor);
            if (!moveCursor) {
                return;
            }
            offset = -1;
            length = -1;
            if (reference instanceof IErlMember) {
                range = ((IErlMember) reference).getNameRange();
                if (range != null) {
                    offset = range.getOffset();
                    length = range.getLength();
                }
            } else if (reference instanceof IErlAttribute) {
                range = ((IErlAttribute) reference).getNameRange();
                if (range != null) {
                    offset = range.getOffset();
                    length = range.getLength();
                }
            } else if (reference instanceof IErlFunctionClause) {
                range = ((IErlFunctionClause) reference).getNameRange();
                if (range != null) {
                    offset = range.getOffset();
                    length = range.getLength();
                }
            }
            if (offset > -1 && length > 0) {
                try {
                    textWidget.setRedraw(false);
                    sourceViewer.revealRange(offset, length);
                    sourceViewer.setSelectedRange(offset, length);
                } finally {
                    textWidget.setRedraw(true);
                }
                markInNavigationHistory();
            }
        } catch (final IllegalArgumentException x) {
        }
    } else if (moveCursor) {
        resetHighlightRange();
        markInNavigationHistory();
    }
}
Also used : IErlMember(org.erlide.engine.model.erlang.IErlMember) StyledText(org.eclipse.swt.custom.StyledText) ITextSelection(org.eclipse.jface.text.ITextSelection) TextSelection(org.eclipse.jface.text.TextSelection) ISelection(org.eclipse.jface.viewers.ISelection) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) Point(org.eclipse.swt.graphics.Point) ISourceRange(org.erlide.engine.model.erlang.ISourceRange) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause)

Aggregations

IErlAttribute (org.erlide.engine.model.erlang.IErlAttribute)8 IErlElement (org.erlide.engine.model.IErlElement)4 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)3 IErlFunctionClause (org.erlide.engine.model.erlang.IErlFunctionClause)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)2 ErlAttribute (org.erlide.engine.internal.model.erlang.ErlAttribute)2 IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)2 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 TextSelection (org.eclipse.jface.text.TextSelection)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 ISelection (org.eclipse.jface.viewers.ISelection)1 StyledText (org.eclipse.swt.custom.StyledText)1 Point (org.eclipse.swt.graphics.Point)1 ErlElementKind (org.erlide.engine.model.ErlElementKind)1 ErlModelException (org.erlide.engine.model.ErlModelException)1 ErlangIncludeFile (org.erlide.engine.model.erlang.ErlangIncludeFile)1 IErlImportExport (org.erlide.engine.model.erlang.IErlImportExport)1 IErlMacroDef (org.erlide.engine.model.erlang.IErlMacroDef)1