Search in sources :

Example 1 with JSExpressionStatement

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

the class ActionScriptCompletionKeywordsContributor method process.

@Override
public boolean process(KeywordCompletionConsumer consumer, PsiElement context) {
    if (JSCompletionContributor.getInstance().isDoingSmartCodeCompleteAction())
        return false;
    final PsiElement parent = context.getParent();
    final PsiElement grandParent = parent != null ? parent.getParent() : null;
    final PsiElement grandGrandParent = grandParent != null ? grandParent.getParent() : null;
    if (parent instanceof JSReferenceExpression && ((JSReferenceExpression) parent).getQualifier() == null && (JSResolveUtil.isExprInTypeContext((JSReferenceExpression) parent) || grandParent instanceof JSExpressionStatement && (JSResolveUtil.isPlaceWhereNsCanBe(grandParent) || grandGrandParent instanceof JSFile && grandGrandParent.getContext() == null) || grandParent instanceof JSAttributeList || parent instanceof JSAttributeNameValuePair)) {
        if (!(grandParent instanceof JSImportStatement) && (grandParent instanceof JSAttributeList || JSResolveUtil.isPlaceWhereNsCanBe(grandParent) || grandGrandParent instanceof JSFile) && (!(grandParent instanceof JSFunction) || ((JSFunction) grandParent).getReturnTypeElement() != parent)) {
            consumer.consume(JSLookupPriority.SMART_KEYWORDS_PRIORITY, true, accessModifiers);
            consumer.consume(JSLookupPriority.SMART_KEYWORDS_PRIORITY, true, "class", "function", "interface", "namespace", "package", "extends", "implements", "import", "override", "static", "dynamic", "var", "const", "use", "final");
        }
        return false;
    }
    if (JSResolveUtil.isInPlaceWhereTypeCanBeDuringCompletion(parent) && JSResolveUtil.isPlaceWhereNsCanBe(grandParent)) {
        consumer.consume(JSLookupPriority.KEYWORDS_PRIORITY, false, JSKeywordsCompletionProvider.TYPE_LITERAL_VALUES);
        consumer.consume(JSLookupPriority.KEYWORDS_PRIORITY, false, "function");
        consumer.consume(JSLookupPriority.KEYWORDS_PRIORITY, true, accessModifiers);
        consumer.consume(JSLookupPriority.KEYWORDS_PRIORITY, true, "extends", "implements", "include", "import", "static", "override", "namespace", "class", "interface", "var", "use");
        return false;
    }
    return true;
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSImportStatement(com.intellij.lang.javascript.psi.ecmal4.JSImportStatement) JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) JSFile(com.intellij.lang.javascript.psi.JSFile) PsiElement(com.intellij.psi.PsiElement) JSExpressionStatement(com.intellij.lang.javascript.psi.JSExpressionStatement)

Example 2 with JSExpressionStatement

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

the class CreateEventHandlerIntention method isAvailable.

@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
    // keep consistency with JavaScriptGenerateEventHandler.GenerateEventHandlerFix.beforeInvoke()
    final XmlAttribute xmlAttribute = ActionScriptGenerateEventHandler.getXmlAttribute(file, editor);
    final String eventType = xmlAttribute == null ? null : ActionScriptGenerateEventHandler.getEventType(xmlAttribute);
    if (eventType != null) {
        return true;
    }
    final JSCallExpression callExpression = ActionScriptGenerateEventHandler.getEventListenerCallExpression(file, editor);
    if (callExpression != null) {
        return true;
    }
    final Trinity<JSExpressionStatement, String, String> eventConstantInfo = ActionScriptGenerateEventHandler.getEventConstantInfo(file, editor);
    if (eventConstantInfo != null) {
        return true;
    }
    return false;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) JSExpressionStatement(com.intellij.lang.javascript.psi.JSExpressionStatement)

Example 3 with JSExpressionStatement

use of com.intellij.lang.javascript.psi.JSExpressionStatement 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)

Example 4 with JSExpressionStatement

use of com.intellij.lang.javascript.psi.JSExpressionStatement in project oxy-template-support-plugin by mutant-industries.

the class JsMacroNameDataIndexer method map.

@Override
@NotNull
public Map<String, JsMacroNameIndexedElement> map(@NotNull final FileContent inputData) {
    PsiFile jsFile = inputData.getPsiFile().getViewProvider().getPsi(OxyTemplateInnerJs.INSTANCE);
    Map<String, JsMacroNameIndexedElement> result = new HashMap<>();
    for (PsiElement psiElement : jsFile.getChildren()) {
        if (psiElement instanceof JSExpressionStatement && (psiElement = PsiTreeUtil.getChildOfAnyType(psiElement, JSAssignmentExpression.class)) != null && psiElement.getFirstChild() instanceof JSDefinitionExpression) {
            String rootNamespace = psiElement.getFirstChild().getText().replace(MACRO_REGISTRY_NAMESPACE + ".", "");
            boolean firstIteration = true;
            for (JSReferenceExpression ref : PsiTreeUtil.findChildrenOfType(psiElement.getFirstChild(), JSReferenceExpression.class)) {
                String namespace = ref.getText().replace(MACRO_REGISTRY_NAMESPACE + ".", "");
                if (!namespace.equals(DEFAULT_NAMESPACE) && !namespace.equals(MACRO_REGISTRY_NAMESPACE)) {
                    result.put(ref.getText().replace(MACRO_REGISTRY_NAMESPACE + ".", ""), new JsMacroNameIndexedElement(firstIteration && psiElement.getLastChild() instanceof JSFunctionExpression, ref.getTextOffset() + ref.getTextLength() - 1));
                }
                firstIteration = false;
            }
            if (psiElement.getLastChild() instanceof JSObjectLiteralExpression) {
                processObjectLiteralExpression((JSObjectLiteralExpression) psiElement.getLastChild(), rootNamespace, result);
            }
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) JSFunctionExpression(com.intellij.lang.javascript.psi.JSFunctionExpression) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSDefinitionExpression(com.intellij.lang.javascript.psi.JSDefinitionExpression) PsiFile(com.intellij.psi.PsiFile) JSObjectLiteralExpression(com.intellij.lang.javascript.psi.JSObjectLiteralExpression) PsiElement(com.intellij.psi.PsiElement) JSExpressionStatement(com.intellij.lang.javascript.psi.JSExpressionStatement) JSAssignmentExpression(com.intellij.lang.javascript.psi.JSAssignmentExpression) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JSExpressionStatement (com.intellij.lang.javascript.psi.JSExpressionStatement)4 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)3 PsiElement (com.intellij.psi.PsiElement)3 JSAssignmentExpression (com.intellij.lang.javascript.psi.JSAssignmentExpression)1 JSCallExpression (com.intellij.lang.javascript.psi.JSCallExpression)1 JSCommaExpression (com.intellij.lang.javascript.psi.JSCommaExpression)1 JSDefinitionExpression (com.intellij.lang.javascript.psi.JSDefinitionExpression)1 JSFile (com.intellij.lang.javascript.psi.JSFile)1 JSFunction (com.intellij.lang.javascript.psi.JSFunction)1 JSFunctionExpression (com.intellij.lang.javascript.psi.JSFunctionExpression)1 JSObjectLiteralExpression (com.intellij.lang.javascript.psi.JSObjectLiteralExpression)1 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)1 JSAttributeNameValuePair (com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair)1 JSImportStatement (com.intellij.lang.javascript.psi.ecmal4.JSImportStatement)1 PsiFile (com.intellij.psi.PsiFile)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 HashMap (java.util.HashMap)1 AngularJSMessageFormatExpression (org.angularjs.lang.psi.AngularJSMessageFormatExpression)1 NotNull (org.jetbrains.annotations.NotNull)1