Search in sources :

Example 1 with TLDFunction

use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDFunction in project webtools.sourceediting by eclipse.

the class JSPELCompletionProposalComputer method getFunctionProposals.

/**
 * <p>Get the EL function proposals, ex: ${fn:| }</p>
 * @param prefix
 * @param viewer
 * @param offset
 * @return
 */
private List getFunctionProposals(String prefix, ITextViewer viewer, int offset) {
    TLDCMDocumentManager docMgr = TaglibController.getTLDCMDocumentManager(viewer.getDocument());
    ArrayList completionList = new ArrayList();
    if (docMgr == null)
        return null;
    Iterator taglibs = docMgr.getCMDocumentTrackers(offset).iterator();
    while (taglibs.hasNext()) {
        TaglibTracker tracker = (TaglibTracker) taglibs.next();
        if (tracker.getPrefix().equals(prefix)) {
            CMDocumentImpl doc = (CMDocumentImpl) tracker.getDocument();
            List functions = doc.getFunctions();
            for (Iterator it = functions.iterator(); it.hasNext(); ) {
                TLDFunction function = (TLDFunction) it.next();
                CustomCompletionProposal proposal = new // $NON-NLS-1$
                CustomCompletionProposal(// $NON-NLS-1$
                function.getName() + "()", offset, 0, function.getName().length() + 1, null, function.getName() + " - " + function.getSignature(), null, null, // $NON-NLS-1$
                1);
                completionList.add(proposal);
            }
        }
    }
    return completionList;
}
Also used : TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) TaglibTracker(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal) ArrayList(java.util.ArrayList) List(java.util.List) TLDFunction(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDFunction) CMDocumentImpl(org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMDocumentImpl)

Example 2 with TLDFunction

use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDFunction in project webtools.sourceediting by eclipse.

the class CMDocumentFactoryTLD method loadDocument.

private CMDocument loadDocument(String baseLocation, Node taglib) {
    Node root = taglib;
    // create the CMDocument
    CMDocumentImpl document = new CMDocumentImpl();
    document.setBaseLocation(baseLocation);
    if (root == null) {
        if (_debug) {
            // $NON-NLS-1$
            System.out.println("null \"taglib\" element for TLD " + baseLocation);
        }
        return document;
    }
    // populate the CMDocument
    Node child = root.getFirstChild();
    while (child != null) {
        if (child.getNodeType() != Node.ELEMENT_NODE) {
            child = child.getNextSibling();
            continue;
        }
        String nodeName = child.getNodeName();
        if (nodeName.indexOf(':') > 0) {
            nodeName = nodeName.substring(nodeName.indexOf(':'));
        }
        // tag
        if (nodeName.equals(JSP11TLDNames.TAG)) {
            CMElementDeclaration ed = createElementDeclaration(document, child);
            if (ed != null) {
                document.fElements.setNamedItem(ed.getNodeName(), ed);
            }
        } else // tag-file
        if (nodeName.equals(JSP20TLDNames.TAG_FILE) && child.getNodeType() == Node.ELEMENT_NODE && child.hasChildNodes()) {
            Element tagFileElement = (Element) child;
            Node path = tagFileElement.getFirstChild();
            while (path != null) {
                if (path.getNodeType() == Node.ELEMENT_NODE && (JSP20TLDNames.PATH.equals(path.getNodeName()) || JSP20TLDNames.PATH.equals(path.getLocalName()))) {
                    String pathValue = getContainedText(path);
                    if (pathValue != null && pathValue.length() > 0) {
                        CMElementDeclarationImpl ed = (CMElementDeclarationImpl) createElementDeclaration(document, tagFileElement, pathValue);
                        if (ed != null) {
                            document.fElements.setNamedItem(ed.getNodeName(), ed);
                        }
                    }
                }
                path = path.getNextSibling();
            }
        } else // JSP version
        if ((nodeName.equals(JSP11TLDNames.JSPVERSION) || nodeName.equals(JSP12TLDNames.JSP_VERSION)) && child.hasChildNodes()) {
            document.setJspversion(getContainedText(child));
        } else // tag library version
        if ((nodeName.equals(JSP11TLDNames.TLIBVERSION) || nodeName.equals(JSP12TLDNames.TLIB_VERSION)) && child.hasChildNodes()) {
            document.setTlibversion(getContainedText(child));
        } else // short name
        if ((nodeName.equals(JSP11TLDNames.SHORTNAME) || nodeName.equals(JSP12TLDNames.SHORT_NAME)) && child.hasChildNodes()) {
            document.setShortname(getContainedText(child));
        } else // URI/URN
        if ((nodeName.equals(JSP11TLDNames.URI) || nodeName.equals(JSP11TLDNames.URN)) && child.hasChildNodes()) {
            // $NON-NLS-1$
            document.setUri(getContainedText(child));
        } else // info
        if (nodeName.equals(JSP11TLDNames.INFO) && child.hasChildNodes()) {
            document.setInfo(getContainedText(child));
        } else // description
        if (nodeName.equals(JSP12TLDNames.DESCRIPTION) && child.hasChildNodes()) {
            document.setDescription(getContainedText(child));
        } else // display name
        if (nodeName.equals(JSP12TLDNames.DISPLAY_NAME) && child.hasChildNodes()) {
            document.setDisplayName(getContainedText(child));
        } else // large icon
        if (nodeName.equals(JSP12TLDNames.LARGE_ICON) && child.hasChildNodes()) {
            document.setLargeIcon(getContainedText(child));
        } else // small icon
        if (nodeName.equals(JSP12TLDNames.SMALL_ICON) && child.hasChildNodes()) {
            document.setSmallIcon(getContainedText(child));
        } else // validator
        if (nodeName.equals(JSP12TLDNames.VALIDATOR)) {
            document.setValidator(createValidator(child));
        } else // listener
        if (nodeName.equals(JSP12TLDNames.LISTENER)) {
            document.getListeners().add(createListener(child));
        } else if (nodeName.equals(JSP20TLDNames.FUNCTION)) {
            TLDFunction function = createFunction(document, child);
            if (function != null) {
                document.getFunctions().add(function);
            }
        } else if (nodeName.equals(JSP20TLDNames.TAGLIB_EXTENSION)) {
            document.getExtensions().add(child);
        }
        child = child.getNextSibling();
    }
    return document;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) TLDFunction(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDFunction)

Example 3 with TLDFunction

use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDFunction in project webtools.sourceediting by eclipse.

the class JSPELContentAssistProcessor method getFunctionProposals.

protected List getFunctionProposals(String prefix, StructuredTextViewer viewer, int offset) {
    TLDCMDocumentManager docMgr = TaglibController.getTLDCMDocumentManager(viewer.getDocument());
    ArrayList completionList = new ArrayList();
    if (docMgr == null)
        return null;
    Iterator taglibs = docMgr.getCMDocumentTrackers(offset).iterator();
    while (taglibs.hasNext()) {
        TaglibTracker tracker = (TaglibTracker) taglibs.next();
        if (tracker.getPrefix().equals(prefix)) {
            CMDocumentImpl doc = (CMDocumentImpl) tracker.getDocument();
            List functions = doc.getFunctions();
            for (Iterator it = functions.iterator(); it.hasNext(); ) {
                TLDFunction function = (TLDFunction) it.next();
                CustomCompletionProposal proposal = new // $NON-NLS-1$
                CustomCompletionProposal(// $NON-NLS-1$
                function.getName() + "()", offset, 0, function.getName().length() + 1, null, function.getName() + " - " + function.getSignature(), null, null, // $NON-NLS-1$
                1);
                completionList.add(proposal);
            }
        }
    }
    return completionList;
}
Also used : TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) TaglibTracker(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal) ArrayList(java.util.ArrayList) List(java.util.List) TLDFunction(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDFunction) CMDocumentImpl(org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMDocumentImpl)

Example 4 with TLDFunction

use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDFunction in project webtools.sourceediting by eclipse.

the class ELGeneratorVisitor method genFunction.

/**
 * Generate a function invocation.
 *
 * @param fullFunctionName
 * @return
 */
protected String genFunction(String fullFunctionName) {
    TLDCMDocumentManager docMgr = TaglibController.getTLDCMDocumentManager(fDocument);
    int colonIndex = fullFunctionName.indexOf(':');
    String prefix = fullFunctionName.substring(0, colonIndex);
    String functionName = fullFunctionName.substring(colonIndex + 1);
    if (docMgr == null)
        return null;
    Iterator taglibs = docMgr.getCMDocumentTrackers(fCurrentNode.getStartOffset()).iterator();
    while (taglibs.hasNext()) {
        TaglibTracker tracker = (TaglibTracker) taglibs.next();
        if (tracker.getPrefix().equals(prefix)) {
            CMDocumentImpl doc = (CMDocumentImpl) tracker.getDocument();
            List functions = doc.getFunctions();
            for (Iterator it = functions.iterator(); it.hasNext(); ) {
                TLDFunction function = (TLDFunction) it.next();
                if (function.getName().equals(functionName)) {
                    String javaFuncName = getFunctionNameFromSignature(function.getSignature());
                    if (javaFuncName == null)
                        javaFuncName = functionName;
                    // $NON-NLS-1$
                    return function.getClassName() + "." + javaFuncName;
                }
            }
        }
    }
    return null;
}
Also used : TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) TaglibTracker(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) TLDFunction(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDFunction) CMDocumentImpl(org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMDocumentImpl)

Aggregations

TLDFunction (org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDFunction)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 List (java.util.List)3 CMDocumentImpl (org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMDocumentImpl)3 TLDCMDocumentManager (org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager)3 TaglibTracker (org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker)3 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)2 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1