Search in sources :

Example 16 with JSReferenceExpression

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

the class AngularJSTargetElementEvaluator method getElementByReference.

@Nullable
@Override
public PsiElement getElementByReference(@NotNull PsiReference ref, int flags) {
    if (ref instanceof JSTextReference) {
        final PsiElement element = ref.getElement();
        final JSCallExpression call = PsiTreeUtil.getParentOfType(element, JSCallExpression.class);
        final JSExpression expression = call != null ? call.getMethodExpression() : null;
        if (expression instanceof JSReferenceExpression) {
            JSReferenceExpression callee = (JSReferenceExpression) expression;
            JSExpression qualifier = callee.getQualifier();
            if (qualifier != null && AngularJSIndexingHandler.INTERESTING_METHODS.contains(callee.getReferencedName()) && AngularIndexUtil.hasAngularJS(element.getProject())) {
                return element;
            }
        }
    }
    return null;
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSTextReference(com.intellij.lang.javascript.psi.impl.JSTextReference) JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) JSExpression(com.intellij.lang.javascript.psi.JSExpression) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with JSReferenceExpression

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

the class JstdResolveTest method testResolveTestCaseFunction.

public void testResolveTestCaseFunction() throws Exception {
    String fileText = "Test<ref>Case('', {});";
    JSReferenceExpression ref = (JSReferenceExpression) configureByFileText(fileText, "sample.js");
    final PsiElement resolved = doResolve(ref);
    assertTrue(resolved instanceof JSFunction);
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSFunction(com.intellij.lang.javascript.psi.JSFunction) PsiElement(com.intellij.psi.PsiElement)

Example 18 with JSReferenceExpression

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

the class FlexReferenceImporter method doAutoImportReferenceAt.

private static boolean doAutoImportReferenceAt(final Editor editor, final PsiFile file, final int offset) {
    if (!ActionScriptAutoImportOptionsProvider.isAddUnambiguousImportsOnTheFly())
        return false;
    if (!(file instanceof JSFile) || file.getLanguage() != JavaScriptSupportLoader.ECMA_SCRIPT_L4)
        return false;
    Document document = editor.getDocument();
    int lineNumber = document.getLineNumber(offset);
    int startOffset = document.getLineStartOffset(lineNumber);
    int endOffset = document.getLineEndOffset(lineNumber);
    List<PsiElement> elements = CollectHighlightsUtil.getElementsInRange(file, startOffset, endOffset);
    for (PsiElement element : elements) {
        if (element instanceof JSReferenceExpression && ((JSReferenceExpression) element).getQualifier() == null) {
            if (((JSReferenceExpression) element).multiResolve(false).length == 0) {
                new AddImportECMAScriptClassOrFunctionAction(editor, (PsiPolyVariantReference) element, true).execute();
                return true;
            }
        }
    }
    return false;
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSFile(com.intellij.lang.javascript.psi.JSFile) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) PsiPolyVariantReference(com.intellij.psi.PsiPolyVariantReference)

Example 19 with JSReferenceExpression

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

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

the class JsTestDriverTestCaseWithoutTestsInspection method createVisitor.

@NotNull
@Override
protected PsiElementVisitor createVisitor(ProblemsHolder holder, LocalInspectionToolSession session) {
    JSFile jsFile = ObjectUtils.tryCast(holder.getFile(), JSFile.class);
    if (jsFile == null) {
        return JSElementVisitor.NOP_ELEMENT_VISITOR;
    }
    Project project = holder.getProject();
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
        if (!JstdSettingsUtil.areJstdConfigFilesInProjectCached(project)) {
            return JSElementVisitor.NOP_ELEMENT_VISITOR;
        }
    }
    VirtualFile virtualFile = jsFile.getVirtualFile();
    if (virtualFile != null) {
        boolean inScope = JstdLibraryUtil.isFileInJstdLibScope(project, virtualFile);
        if (!inScope) {
            return JSElementVisitor.NOP_ELEMENT_VISITOR;
        }
    }
    JstdTestFileStructure testFileStructure = JstdTestFileStructureBuilder.getInstance().fetchCachedTestFileStructure(jsFile);
    for (JstdTestCaseStructure structure : testFileStructure.getTestCaseStructures()) {
        if (structure.getTestCount() == 0) {
            JSCallExpression callExpression = structure.getEnclosingCallExpression();
            if (callExpression.isValid()) {
                JSReferenceExpression methodExpression = ObjectUtils.tryCast(callExpression.getMethodExpression(), JSReferenceExpression.class);
                if (methodExpression != null) {
                    int startOffset = methodExpression.getStartOffsetInParent();
                    TextRange rangeInElement = TextRange.create(startOffset, startOffset + methodExpression.getTextLength());
                    holder.registerProblem(callExpression, "TestCase has no tests. Tests names should have 'test' prefix.", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, rangeInElement, LocalQuickFix.EMPTY_ARRAY);
                }
            }
        }
    }
    return JSElementVisitor.NOP_ELEMENT_VISITOR;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) TextRange(com.intellij.openapi.util.TextRange) JSFile(com.intellij.lang.javascript.psi.JSFile) NotNull(org.jetbrains.annotations.NotNull)

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