Search in sources :

Example 1 with CfmlAttributeImpl

use of com.intellij.coldFusion.model.psi.impl.CfmlAttributeImpl in project intellij-plugins by JetBrains.

the class CfmlAttributeNamesCompletionProvider method addCompletions.

public void addCompletions(@NotNull final CompletionParameters parameters, final ProcessingContext context, @NotNull final CompletionResultSet result) {
    PsiElement element = parameters.getPosition();
    String tagName = "";
    while (element != null && !(element instanceof CfmlTag) && !(element instanceof CfmlComponent) && !(element instanceof CfmlPropertyImpl)) {
        PsiElement prevNode = element.getPrevSibling();
        PsiElement superPrevNode = prevNode != null ? prevNode.getPrevSibling() : null;
        if (superPrevNode != null && superPrevNode.getText().equalsIgnoreCase("property")) {
            tagName = "cfproperty";
            break;
        }
        element = element.getParent();
    }
    if (element == null) {
        return;
    }
    if (tagName.isEmpty()) {
        tagName = element instanceof CfmlTag ? ((CfmlTag) element).getTagName() : element instanceof CfmlPropertyImpl ? "cfproperty" : "cfcomponent";
    }
    Set<String> excluded = new HashSet<>();
    final CfmlAttributeImpl[] attributes = PsiTreeUtil.getChildrenOfType(element, CfmlAttributeImpl.class);
    if (attributes != null) {
        for (CfmlAttributeImpl attribute : attributes) {
            excluded.add(attribute.getAttributeName());
        }
    }
    for (CfmlAttributeDescription s : CfmlUtil.getAttributes(tagName, element.getProject())) {
        if (s.getName() == null) {
            continue;
        }
        if (excluded.contains(s.getName())) {
            continue;
        }
        result.addElement(TailTypeDecorator.withTail(LookupElementBuilder.create(s.getName()).withCaseSensitivity(false), new TailType() {

            public int processTail(Editor editor, int tailOffset) {
                HighlighterIterator iterator = ((EditorEx) editor).getHighlighter().createIterator(tailOffset);
                if (!iterator.atEnd() && iterator.getTokenType() == CfmlTokenTypes.WHITE_SPACE)
                    iterator.advance();
                if (!iterator.atEnd() && iterator.getTokenType() == CfmlTokenTypes.ASSIGN) {
                    iterator.advance();
                } else {
                    editor.getDocument().insertString(tailOffset, "=\"\"");
                    return moveCaret(editor, tailOffset, 2);
                }
                int offset = iterator.getStart();
                if (!iterator.atEnd() && iterator.getTokenType() == CfmlTokenTypes.WHITE_SPACE)
                    iterator.advance();
                if (!iterator.atEnd() && CfmlTokenTypes.STRING_ELEMENTS.contains(iterator.getTokenType())) {
                    return tailOffset;
                }
                editor.getDocument().insertString(offset, "\"\"");
                return moveCaret(editor, tailOffset, offset - tailOffset + 1);
            }
        }));
    }
}
Also used : TailType(com.intellij.codeInsight.TailType) CfmlAttributeDescription(com.intellij.coldFusion.model.info.CfmlAttributeDescription) CfmlAttributeImpl(com.intellij.coldFusion.model.psi.impl.CfmlAttributeImpl) CfmlComponent(com.intellij.coldFusion.model.psi.CfmlComponent) CfmlPropertyImpl(com.intellij.coldFusion.model.psi.impl.CfmlPropertyImpl) CfmlTag(com.intellij.coldFusion.model.psi.CfmlTag) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) HashSet(com.intellij.util.containers.HashSet)

Example 2 with CfmlAttributeImpl

use of com.intellij.coldFusion.model.psi.impl.CfmlAttributeImpl in project intellij-plugins by JetBrains.

the class CfmlAttributeValuesCompletionProvider method addCompletions.

public void addCompletions(@NotNull final CompletionParameters parameters, final ProcessingContext context, @NotNull final CompletionResultSet result) {
    PsiElement element = parameters.getPosition();
    while (element != null && !(element instanceof CfmlAttributeImpl)) {
        element = element.getParent();
    }
    if (element == null) {
        return;
    }
    CfmlAttributeImpl attribute = (CfmlAttributeImpl) element;
    String attributeName = attribute.getFirstChild().getText();
    while (element != null && !(element instanceof CfmlTag)) {
        element = element.getParent();
    }
    if (element == null) {
        return;
    }
    CfmlTag tag = (CfmlTag) element;
    String tagName = tag.getTagName();
    String[] attributeValue = CfmlUtil.getAttributeValues(tagName, attributeName, parameters.getPosition().getProject());
    if ("type".equalsIgnoreCase(attributeName) && "cfargument".equalsIgnoreCase(tagName) || "returntype".equalsIgnoreCase(attributeName) && "cffunction".equalsIgnoreCase(tagName)) {
        Object[] objects = CfmlComponentReference.buildVariants(attribute.getPureAttributeValue(), element.getContainingFile(), element.getProject(), null, true);
        for (Object o : objects) {
            result.addElement((LookupElement) o);
        }
    }
    for (String s : attributeValue) {
        result.addElement(LookupElementBuilder.create(s).withCaseSensitivity(false));
    }
}
Also used : CfmlAttributeImpl(com.intellij.coldFusion.model.psi.impl.CfmlAttributeImpl) CfmlTag(com.intellij.coldFusion.model.psi.CfmlTag) PsiElement(com.intellij.psi.PsiElement)

Aggregations

CfmlTag (com.intellij.coldFusion.model.psi.CfmlTag)2 CfmlAttributeImpl (com.intellij.coldFusion.model.psi.impl.CfmlAttributeImpl)2 PsiElement (com.intellij.psi.PsiElement)2 TailType (com.intellij.codeInsight.TailType)1 CfmlAttributeDescription (com.intellij.coldFusion.model.info.CfmlAttributeDescription)1 CfmlComponent (com.intellij.coldFusion.model.psi.CfmlComponent)1 CfmlPropertyImpl (com.intellij.coldFusion.model.psi.impl.CfmlPropertyImpl)1 Editor (com.intellij.openapi.editor.Editor)1 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)1 HashSet (com.intellij.util.containers.HashSet)1