Search in sources :

Example 1 with JSCommaExpression

use of com.intellij.lang.javascript.psi.JSCommaExpression in project intellij-plugins by JetBrains.

the class AngularMessageFormatCompletion method messageFormatCompletion.

static boolean messageFormatCompletion(CompletionParameters parameters, CompletionResultSet result) {
    final PsiElement originalPosition = parameters.getOriginalPosition();
    if (originalPosition == null)
        return false;
    final PsiElement parent = originalPosition.getParent();
    if (parent instanceof JSReferenceExpression && parent.getParent() instanceof JSCommaExpression) {
        final PsiElement[] children = parent.getParent().getChildren();
        if (children.length >= 2 && children[1] == parent) {
            messageFormatExtensions(result);
            return true;
        }
    }
    if (parent instanceof AngularJSMessageFormatExpression) {
        final AngularJSMessageFormatExpression amfe = (AngularJSMessageFormatExpression) parent;
        if (originalPosition == amfe.getExtensionTypeElement()) {
            messageFormatExtensions(result);
            return true;
        }
        if (originalPosition.getNode().getElementType() == AngularJSElementTypes.MESSAGE_FORMAT_SELECTION_KEYWORD) {
            messageFormatSelectionKeywords(((AngularJSMessageFormatExpression) parent).getExtensionType(), result);
            return true;
        }
        if (originalPosition.getNode().getElementType() == JSTokenTypes.WHITE_SPACE) {
            if (originalPosition.getNextSibling() != null && originalPosition.getNextSibling().getNode().getElementType() == AngularJSElementTypes.MESSAGE_FORMAT_SELECTION_KEYWORD || originalPosition.getPrevSibling() != null && originalPosition.getPrevSibling().getNode().getElementType() == JSTokenTypes.RBRACE) {
                messageFormatSelectionKeywords(((AngularJSMessageFormatExpression) parent).getExtensionType(), result);
                return true;
            }
        }
    }
    final PsiElement sibling = originalPosition.getPrevSibling();
    if (sibling instanceof AngularJSMessageFormatExpression) {
        messageFormatSelectionKeywords(((AngularJSMessageFormatExpression) sibling).getExtensionType(), result);
    } else if (sibling instanceof JSExpressionStatement && sibling.getFirstChild() instanceof AngularJSMessageFormatExpression) {
        messageFormatSelectionKeywords(((AngularJSMessageFormatExpression) sibling.getFirstChild()).getExtensionType(), result);
    }
    return false;
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSCommaExpression(com.intellij.lang.javascript.psi.JSCommaExpression) AngularJSMessageFormatExpression(org.angularjs.lang.psi.AngularJSMessageFormatExpression) PsiElement(com.intellij.psi.PsiElement) JSExpressionStatement(com.intellij.lang.javascript.psi.JSExpressionStatement)

Aggregations

JSCommaExpression (com.intellij.lang.javascript.psi.JSCommaExpression)1 JSExpressionStatement (com.intellij.lang.javascript.psi.JSExpressionStatement)1 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)1 PsiElement (com.intellij.psi.PsiElement)1 AngularJSMessageFormatExpression (org.angularjs.lang.psi.AngularJSMessageFormatExpression)1