Search in sources :

Example 1 with CfmlTag

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

the class CfmlFoldingBuilder method addFoldingDescriptors.

private static void addFoldingDescriptors(final List<FoldingDescriptor> descriptors, final PsiElement tag, @NotNull Document document) {
    TextRange elementRange = tag.getTextRange();
    final int start = elementRange.getStartOffset();
    final int end = elementRange.getEndOffset();
    if (start + 1 < end) {
        TextRange range = null;
        ASTNode astNode = tag.getNode();
        IElementType astType = astNode.getElementType();
        if (tag instanceof CfmlTag) {
            //if (tag instanceof CfmlTagFunctionImpl || tag instanceof CfmlTagComponentImpl || tag instanceof CfmlTagScriptImpl) {
            range = buildRangeForBraces(range, astNode, CfmlTokenTypes.R_ANGLEBRACKET, CfmlTokenTypes.LSLASH_ANGLEBRACKET);
        //}
        } else if (astType == CfmlElementTypes.FUNCTIONBODY || astType == CfmlElementTypes.BLOCK_OF_STATEMENTS) {
            range = buildRange(range, start, end);
        } else if (astType == CfmlElementTypes.SWITCHEXPRESSION) {
            ASTNode lparen = astNode.findChildByType(CfscriptTokenTypes.L_CURLYBRACKET);
            ASTNode rparen = astNode.findChildByType(CfscriptTokenTypes.R_CURLYBRACKET);
            if (lparen != null && rparen != null) {
                range = buildRange(range, lparen.getStartOffset(), rparen.getTextRange().getEndOffset());
            }
        } else if (tag instanceof PsiComment) {
            boolean isColdFusionComment = astNode.getElementType() == CfmlTokenTypes.COMMENT;
            int endIndex = astNode.getText().lastIndexOf(isColdFusionComment ? "--->" : "*/");
            if (endIndex != -1) {
                String commentText = astNode.getText().substring(0, endIndex);
                if (commentText.contains("\n")) {
                    int startOffset = tag.getTextRange().getStartOffset();
                    range = buildRange(range, startOffset + (isColdFusionComment ? "<!---" : "/*").length(), startOffset + commentText.length());
                }
            }
        }
        if (range != null) {
            descriptors.add(new FoldingDescriptor(astNode, range));
        }
        // TODO: insert condition
        addFoldingDescriptorsFromChildren(descriptors, tag, document);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiComment(com.intellij.psi.PsiComment) FoldingDescriptor(com.intellij.lang.folding.FoldingDescriptor) ASTNode(com.intellij.lang.ASTNode) TextRange(com.intellij.openapi.util.TextRange) CfmlTag(com.intellij.coldFusion.model.psi.CfmlTag)

Example 2 with CfmlTag

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

the class CfmlFileReferenceInspection method buildVisitor.

@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    return new PsiElementVisitor() {

        public void visitElement(final PsiElement element) {
            PsiElement tagParent = PsiTreeUtil.getParentOfType((element), CfmlTag.class);
            if ((element.getNode().getElementType() == CfmlTokenTypes.STRING_TEXT)) {
                if ((tagParent == null || (!((CfmlTag) tagParent).getTagName().equalsIgnoreCase("cfinclude") && !((CfmlTag) tagParent).getTagName().equalsIgnoreCase("cfmodule")))) {
                    PsiElement superParent = element.getParent() != null ? element.getParent().getParent() : null;
                    ASTNode superParentNode = superParent != null ? superParent.getNode() : null;
                    if ((superParentNode == null || superParentNode.getElementType() != CfmlElementTypes.INCLUDEEXPRESSION)) {
                        return;
                    }
                }
                final PsiReference[] refs = element.getParent().getReferences();
                for (int i = 0, refsLength = refs.length; i < refsLength; i++) {
                    PsiReference ref = refs[i];
                    if (!(ref instanceof FileReference))
                        continue;
                    if (ref.resolve() == null) {
                        PsiDirectory dir;
                        if (i > 0) {
                            final PsiElement target = refs[i - 1].resolve();
                            dir = target instanceof PsiDirectory ? (PsiDirectory) target : null;
                        } else {
                            dir = element.getContainingFile().getParent();
                        }
                        holder.registerProblem(ref.getElement(), ref.getRangeInElement(), isOnTheFly ? "Path '" + ref.getCanonicalText() + "' not found" : "Path not found", isOnTheFly && dir != null ? new LocalQuickFix[] { new CreateFileFix(i < refs.length - 1, ref.getCanonicalText(), dir) } : LocalQuickFix.EMPTY_ARRAY);
                        //                       ProblemHighlightType.ERROR);
                        break;
                    }
                }
            }
        }
    };
}
Also used : CreateFileFix(com.intellij.codeInsight.daemon.quickFix.CreateFileFix) PsiDirectory(com.intellij.psi.PsiDirectory) ASTNode(com.intellij.lang.ASTNode) PsiReference(com.intellij.psi.PsiReference) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) CfmlTag(com.intellij.coldFusion.model.psi.CfmlTag) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) FileReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with CfmlTag

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

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

the class CfmlUnitQualifiedNameLocationProvider method findElement.

@Nullable
private static PsiElement findElement(String link, Project project) {
    String[] location = link.split("::");
    int tokensNumber = location.length;
    if (tokensNumber <= 0 || tokensNumber > 3) {
        return null;
    }
    PsiElement result;
    String filePath = location[0];
    VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(filePath);
    if (virtualFile != null) {
        result = PsiManager.getInstance(project).findFile(virtualFile);
        if (result == null || !(result instanceof CfmlFile)) {
            return null;
        }
        // TODO: to move to index
        final CfmlTag[] tags = PsiTreeUtil.getChildrenOfType(result, CfmlTag.class);
        if (tags == null || tags.length == 0) {
            return result;
        }
        for (CfmlTag tag : tags) {
            if ("cfcomponent".equals(tag.getTagName().toLowerCase(Locale.ENGLISH))) {
                result = tag;
                break;
            }
        }
    } else {
        return null;
    }
    if (tokensNumber > 1) {
        String functionName = location[1];
        final CfmlTagFunctionImpl[] functions = PsiTreeUtil.getChildrenOfType(result, CfmlTagFunctionImpl.class);
        if (functions != null) {
            for (CfmlTagFunctionImpl function : functions) {
                if (functionName.equals(function.getName())) {
                    result = function.getNavigationElement();
                    break;
                }
            }
        }
        final CfmlFunctionImpl[] scriptFunctions = PsiTreeUtil.getChildrenOfType(result, CfmlFunctionImpl.class);
        if (scriptFunctions != null) {
            for (CfmlFunctionImpl function : scriptFunctions) {
                if (functionName.equals(function.getName())) {
                    result = function.getNavigationElement();
                    break;
                }
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CfmlFile(com.intellij.coldFusion.model.files.CfmlFile) CfmlTagFunctionImpl(com.intellij.coldFusion.model.psi.impl.CfmlTagFunctionImpl) CfmlFunctionImpl(com.intellij.coldFusion.model.psi.impl.CfmlFunctionImpl) CfmlTag(com.intellij.coldFusion.model.psi.CfmlTag) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with CfmlTag

use of com.intellij.coldFusion.model.psi.CfmlTag 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)6 PsiElement (com.intellij.psi.PsiElement)5 CfmlAttributeImpl (com.intellij.coldFusion.model.psi.impl.CfmlAttributeImpl)2 ASTNode (com.intellij.lang.ASTNode)2 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)2 TailType (com.intellij.codeInsight.TailType)1 CreateFileFix (com.intellij.codeInsight.daemon.quickFix.CreateFileFix)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 CfmlFile (com.intellij.coldFusion.model.files.CfmlFile)1 CfmlAttributeDescription (com.intellij.coldFusion.model.info.CfmlAttributeDescription)1 CfmlComponent (com.intellij.coldFusion.model.psi.CfmlComponent)1 CfmlFunctionImpl (com.intellij.coldFusion.model.psi.impl.CfmlFunctionImpl)1 CfmlPropertyImpl (com.intellij.coldFusion.model.psi.impl.CfmlPropertyImpl)1 CfmlTagFunctionImpl (com.intellij.coldFusion.model.psi.impl.CfmlTagFunctionImpl)1 FoldingDescriptor (com.intellij.lang.folding.FoldingDescriptor)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 TextRange (com.intellij.openapi.util.TextRange)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1