Search in sources :

Example 1 with JSLiteralExpression

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

the class AngularUiRouterTest method emptyViewNavigatesToFilesDefaultView.

private void emptyViewNavigatesToFilesDefaultView(PsiFile file, String str) {
    final PsiElement inObj = getElement(file, str);
    Assert.assertTrue(inObj.getParent() instanceof JSLiteralExpression);
    Assert.assertTrue(inObj.getParent().getParent() instanceof JSProperty);
    final JSProperty templateUrl = (JSProperty) inObj.getParent().getParent();
    Assert.assertEquals("templateUrl", templateUrl.getName());
    final PsiElement parentProperty = templateUrl.getParent().getParent();
    Assert.assertTrue(parentProperty instanceof JSProperty);
    final PsiReference reference = parentProperty.getReference();
    Assert.assertNotNull(reference);
    Assert.assertEquals("", reference.getCanonicalText());
    final PsiElement resolve = reference.resolve();
    Assert.assertNotNull(resolve);
    Assert.assertEquals(StringUtil.unquoteString(str), resolve.getContainingFile().getName());
    Assert.assertEquals("", ((JSPsiNamedElementBase) resolve).getName());
    final PsiElement element = ((JSOffsetBasedImplicitElement) resolve).getElementAtOffset();
    Assert.assertEquals("ui-view", element.getText());
}
Also used : JSLiteralExpression(com.intellij.lang.javascript.psi.JSLiteralExpression) JSOffsetBasedImplicitElement(com.intellij.lang.javascript.psi.impl.JSOffsetBasedImplicitElement) JSProperty(com.intellij.lang.javascript.psi.JSProperty)

Example 2 with JSLiteralExpression

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

the class RoutingTest method assertModuleReferenceIsUnderCaret.

private void assertModuleReferenceIsUnderCaret(boolean value) {
    final JSLiteralExpression literal = PsiTreeUtil.getParentOfType(myFixture.getFile().findElementAt(myFixture.getCaretOffset()), JSLiteralExpression.class);
    assertNotNull(literal);
    final boolean accepts = AngularJSReferencesContributor.MODULE_PATTERN.accepts(literal);
    assertEquals(value, accepts);
}
Also used : JSLiteralExpression(com.intellij.lang.javascript.psi.JSLiteralExpression)

Example 3 with JSLiteralExpression

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

the class KarmaBasePathFinder method buildBasePath.

@Nullable
private static String buildBasePath(@NotNull JSFile jsFile) {
    final Ref<String> basePathRef = Ref.create(null);
    JSElementVisitor visitor = new JSElementVisitor() {

        @Override
        public void visitJSProperty(JSProperty property) {
            String name = JsPsiUtils.getPropertyName(property);
            if (BASE_PATH_VAR_NAME.equals(name)) {
                JSLiteralExpression value = ObjectUtils.tryCast(property.getValue(), JSLiteralExpression.class);
                if (value != null && value.isQuotedLiteral()) {
                    basePathRef.set(StringUtil.unquoteString(value.getText()));
                }
            }
        }

        @Override
        public void visitElement(PsiElement element) {
            ProgressIndicatorProvider.checkCanceled();
            if (basePathRef.isNull()) {
                element.acceptChildren(this);
            }
        }
    };
    visitor.visitJSFile(jsFile);
    return basePathRef.get();
}
Also used : JSLiteralExpression(com.intellij.lang.javascript.psi.JSLiteralExpression) JSProperty(com.intellij.lang.javascript.psi.JSProperty) JSElementVisitor(com.intellij.lang.javascript.psi.JSElementVisitor) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JSLiteralExpression (com.intellij.lang.javascript.psi.JSLiteralExpression)3 JSProperty (com.intellij.lang.javascript.psi.JSProperty)2 JSElementVisitor (com.intellij.lang.javascript.psi.JSElementVisitor)1 JSOffsetBasedImplicitElement (com.intellij.lang.javascript.psi.impl.JSOffsetBasedImplicitElement)1 PsiElement (com.intellij.psi.PsiElement)1 Nullable (org.jetbrains.annotations.Nullable)1