Search in sources :

Example 11 with JSReferenceExpression

use of com.intellij.lang.javascript.psi.JSReferenceExpression 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 12 with JSReferenceExpression

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

the class CreateJSEventMethod method addParameters.

@Override
protected void addParameters(Template template, JSReferenceExpression refExpr, PsiFile file) {
    Expression expression = new MyExpression("event");
    template.addVariable("$event$", expression, expression, true);
    template.addTextSegment(":");
    String text = myEventTypeGenerator.compute();
    text = ImportUtils.importAndShortenReference(text, refExpr, true, true).first;
    template.addTextSegment(text);
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) Expression(com.intellij.codeInsight.template.Expression)

Example 13 with JSReferenceExpression

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

the class ActionScriptResolveTest method testResolveInClassDynamic.

public void testResolveInClassDynamic() throws Exception {
    String fileText = "public class T {\n" + "  public function m() : String {\n" + "    return \"m\";\n" + "  }\n" + "\n" + "  public function test() : String {\n" + "    function foo():String {\n" + "      return this.<ref>m();\n" + "    }\n" + "    return foo();\n" + "  }\n" + "}\n" + "function m() {}";
    JSReferenceExpression ref = (JSReferenceExpression) configureByFileText(fileText, "sample.js2");
    ResolveResult[] results = ref.multiResolve(false);
    assertEquals(2, results.length);
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) ResolveResult(com.intellij.psi.ResolveResult)

Example 14 with JSReferenceExpression

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

the class ActionScriptResolveTest method testResolveVectorMember.

public void testResolveVectorMember() throws Exception {
    String fileText = "package {\n" + "public class Vector$object {\n" + "    function reverse():Vector$object {}\n" + "}\n" + "}\n" + "var x:Vector.<int>\n" + "x.rev<ref>erse()";
    JSReferenceExpression ref = (JSReferenceExpression) configureByFileText(fileText, "sample.as");
    final PsiElement resolved = ref.resolve();
    assertNotNull(resolved);
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) PsiElement(com.intellij.psi.PsiElement)

Example 15 with JSReferenceExpression

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

the class ActionScriptResolveTest method testObjectProperties.

public void testObjectProperties() throws Exception {
    String fileText = "package {\n" + "public class Foo {\n" + "    function bar() {" + "        var x:Object = {};\n" + "        x.toStri<ref>ng();\n" + "    }\n" + "}\n" + "}";
    JSReferenceExpression ref = (JSReferenceExpression) configureByFileText(fileText, "sample.as");
    final PsiElement resolved = ref.resolve();
    assertNotNull(resolved);
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) PsiElement(com.intellij.psi.PsiElement)

Aggregations

JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)24 PsiElement (com.intellij.psi.PsiElement)10 JSFunction (com.intellij.lang.javascript.psi.JSFunction)7 JSFile (com.intellij.lang.javascript.psi.JSFile)6 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)5 NotNull (org.jetbrains.annotations.NotNull)4 JSCallExpression (com.intellij.lang.javascript.psi.JSCallExpression)3 JSExpression (com.intellij.lang.javascript.psi.JSExpression)3 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)3 TextRange (com.intellij.openapi.util.TextRange)3 JSExpressionStatement (com.intellij.lang.javascript.psi.JSExpressionStatement)2 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)2 JSImportStatement (com.intellij.lang.javascript.psi.ecmal4.JSImportStatement)2 FormatFixer (com.intellij.lang.javascript.refactoring.FormatFixer)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ResolveResult (com.intellij.psi.ResolveResult)2 XmlFile (com.intellij.psi.xml.XmlFile)2 NonCodeUsageInfo (com.intellij.refactoring.util.NonCodeUsageInfo)2 Expression (com.intellij.codeInsight.template.Expression)1