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());
}
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);
}
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();
}
Aggregations