Search in sources :

Example 1 with CfmlReferenceExpression

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

the class CfmlPredefinedVariablesCompletion method getNameForCfmlTag.

@Nullable
private static String getNameForCfmlTag(@NotNull CompletionParameters pars) {
    PsiElement elem = pars.getPosition().getParent().getFirstChild();
    if (elem instanceof CfmlReferenceExpression) {
        PsiElement resElem = ((CfmlReferenceExpression) elem).resolve();
        if (resElem != null) {
            PsiElement parent = resElem.getParent();
            if (!(parent instanceof CfmlTagImpl)) {
                return null;
            }
            String name = ((CfmlTagImpl) parent).getTagName();
            return name.startsWith("cf") ? name.substring(2) : name;
        }
    }
    return null;
}
Also used : CfmlReferenceExpression(com.intellij.coldFusion.model.psi.CfmlReferenceExpression) CfmlTagImpl(com.intellij.coldFusion.model.psi.impl.CfmlTagImpl) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with CfmlReferenceExpression

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

the class CfmlUtil method isPredefinedTagVariables.

public static boolean isPredefinedTagVariables(CfmlReferenceExpression cfmlRef, Project project) {
    String predefVarText = cfmlRef.getLastChild() != null ? cfmlRef.getLastChild().getText() : null;
    //try to find tag type by name//
    PsiElement referenceName = cfmlRef.getFirstChild();
    if (!(referenceName instanceof CfmlReferenceExpression) || predefVarText == null) {
        return false;
    }
    referenceName = ((CfmlReferenceExpression) referenceName).resolve();
    referenceName = referenceName != null ? referenceName.getParent() : null;
    if (!(referenceName instanceof CfmlTagImpl)) {
        return false;
    }
    String tagName = ((CfmlTagImpl) referenceName).getTagName();
    String tagNameWithoutCf = tagName.startsWith("cf") ? tagName.substring(2) : tagName;
    return CfmlLangInfo.getInstance(anyProject(project)).getPredefinedVariables().keySet().contains(tagNameWithoutCf.toLowerCase() + "." + predefVarText.toLowerCase());
}
Also used : CfmlReferenceExpression(com.intellij.coldFusion.model.psi.CfmlReferenceExpression) CfmlTagImpl(com.intellij.coldFusion.model.psi.impl.CfmlTagImpl) PsiElement(com.intellij.psi.PsiElement)

Example 3 with CfmlReferenceExpression

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

the class CfmlVariableSurroundDescriptor method getElementsToSurround.

@NotNull
@Override
public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) {
    final FileViewProvider viewProvider = file.getViewProvider();
    PsiElement elementAt = PsiTreeUtil.findElementOfClassAtRange(file, startOffset, endOffset, CfmlReferenceExpression.class);
    if (elementAt != null) {
        return !(elementAt.getParent() instanceof CfmlReferenceExpression) ? new PsiElement[] { elementAt } : PsiElement.EMPTY_ARRAY;
    }
    for (Language language : viewProvider.getLanguages()) {
        elementAt = viewProvider.findElementAt(startOffset, language);
        if (elementAt != null && (!language.is(CfmlLanguage.INSTANCE) || elementAt.getNode().getElementType() == CfmlTokenTypes.STRING_TEXT) && elementAt.getNode().getText().matches("(\\S)+") && elementAt.getTextRange().getStartOffset() == startOffset && elementAt.getTextRange().getEndOffset() == endOffset) {
            return new PsiElement[] { elementAt };
        }
    }
    return PsiElement.EMPTY_ARRAY;
}
Also used : FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) CfmlLanguage(com.intellij.coldFusion.model.CfmlLanguage) CfmlReferenceExpression(com.intellij.coldFusion.model.psi.CfmlReferenceExpression) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

CfmlReferenceExpression (com.intellij.coldFusion.model.psi.CfmlReferenceExpression)3 PsiElement (com.intellij.psi.PsiElement)3 CfmlTagImpl (com.intellij.coldFusion.model.psi.impl.CfmlTagImpl)2 CfmlLanguage (com.intellij.coldFusion.model.CfmlLanguage)1 Language (com.intellij.lang.Language)1 FileViewProvider (com.intellij.psi.FileViewProvider)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1