Search in sources :

Example 1 with CfmlComponent

use of com.intellij.coldFusion.model.psi.CfmlComponent 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 CfmlComponent

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

the class CfmlTagPropertyImpl method checkBooleanAttribute.

private boolean checkBooleanAttribute(String attributeName) {
    PsiElement attributeValue = getAttributeValueElement(attributeName);
    if (attributeValue != null) {
        if ("true".equalsIgnoreCase(attributeValue.getText())) {
            return true;
        }
        return false;
    }
    CfmlComponent component = getComponent();
    return component != null ? component.hasImplicitAccessors() : false;
}
Also used : CfmlComponent(com.intellij.coldFusion.model.psi.CfmlComponent) PsiElement(com.intellij.psi.PsiElement)

Aggregations

CfmlComponent (com.intellij.coldFusion.model.psi.CfmlComponent)2 PsiElement (com.intellij.psi.PsiElement)2 TailType (com.intellij.codeInsight.TailType)1 CfmlAttributeDescription (com.intellij.coldFusion.model.info.CfmlAttributeDescription)1 CfmlTag (com.intellij.coldFusion.model.psi.CfmlTag)1 CfmlAttributeImpl (com.intellij.coldFusion.model.psi.impl.CfmlAttributeImpl)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