Search in sources :

Example 1 with JSConditionalCompilationDefinitionsProvider

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

the class ActionScriptReferenceExpressionResolver method resolveConditionalCompilationVariable.

private static ResolveResult[] resolveConditionalCompilationVariable(final JSReferenceExpression jsReferenceExpression) {
    final String namespace;
    final String constantName;
    final PsiElement parent = jsReferenceExpression.getParent();
    if (parent instanceof JSE4XNamespaceReference) {
        final PsiElement namespaceReference = ((JSE4XNamespaceReference) parent).getNamespaceReference();
        final PsiElement parentParent = parent.getParent();
        PsiElement sibling = parent.getNextSibling();
        while (sibling instanceof PsiWhiteSpace) {
            sibling = sibling.getNextSibling();
        }
        if (namespaceReference != null && parentParent instanceof JSReferenceExpression && sibling != null && sibling.getNextSibling() == null && sibling.getNode() != null && sibling.getNode().getElementType() == JSTokenTypes.IDENTIFIER) {
            namespace = namespaceReference.getText();
            constantName = sibling.getText();
        } else {
            return new ResolveResult[] { new JSResolveResult(jsReferenceExpression, null, "javascript.unresolved.symbol.message") };
        }
    } else {
        final JSE4XNamespaceReference namespaceElement = PsiTreeUtil.getChildOfType(jsReferenceExpression, JSE4XNamespaceReference.class);
        final PsiElement namespaceReference = namespaceElement == null ? null : namespaceElement.getNamespaceReference();
        PsiElement sibling = namespaceElement == null ? null : namespaceElement.getNextSibling();
        while (sibling instanceof PsiWhiteSpace) {
            sibling = sibling.getNextSibling();
        }
        if (namespaceElement != null && sibling != null && sibling.getNextSibling() == null && sibling.getNode() != null && sibling.getNode().getElementType() == JSTokenTypes.IDENTIFIER) {
            namespace = namespaceReference.getText();
            constantName = sibling.getText();
        } else {
            return new ResolveResult[] { new JSResolveResult(jsReferenceExpression, null, "javascript.unresolved.symbol.message") };
        }
    }
    for (JSConditionalCompilationDefinitionsProvider provider : JSConditionalCompilationDefinitionsProvider.EP_NAME.getExtensions()) {
        if (provider.containsConstant(ModuleUtilCore.findModuleForPsiElement(jsReferenceExpression), namespace, constantName)) {
            return new ResolveResult[] { new JSResolveResult(jsReferenceExpression) };
        }
    }
    return new ResolveResult[] { new JSResolveResult(jsReferenceExpression, null, "javascript.unresolved.symbol.message") };
}
Also used : JSE4XNamespaceReference(com.intellij.lang.javascript.psi.e4x.JSE4XNamespaceReference) JSConditionalCompilationDefinitionsProvider(com.intellij.lang.javascript.JSConditionalCompilationDefinitionsProvider) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Aggregations

JSConditionalCompilationDefinitionsProvider (com.intellij.lang.javascript.JSConditionalCompilationDefinitionsProvider)1 JSE4XNamespaceReference (com.intellij.lang.javascript.psi.e4x.JSE4XNamespaceReference)1 PsiElement (com.intellij.psi.PsiElement)1 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)1 ResolveResult (com.intellij.psi.ResolveResult)1