use of com.intellij.psi.xml.XmlAttributeValue in project intellij-plugins by JetBrains.
the class AngularUiRouterTest method checkNavigation.
private void checkNavigation(PsiFile file, String state, String referencedTextExpected, String appStatesFileName) {
referencedTextExpected = referencedTextExpected == null ? state : referencedTextExpected;
final PsiElement inObj = getElement(file, "ui-sref=\"" + state + "\"");
Assert.assertEquals("ui-sref", inObj.getText());
Assert.assertTrue(inObj.getParent() instanceof XmlAttribute);
final XmlAttributeValue element = ((XmlAttribute) inObj.getParent()).getValueElement();
Assert.assertNotNull(element);
final PsiReference reference = element.getReference();
Assert.assertEquals(state, reference.getCanonicalText());
final ResolveResult[] results = ((PsiPolyVariantReference) reference).multiResolve(false);
if (results.length > 1) {
for (ResolveResult result : results) {
final PsiElement resolvedElement = result.getElement();
Assert.assertEquals(appStatesFileName, resolvedElement.getContainingFile().getName());
if (StringUtil.equals(referencedTextExpected, StringUtil.unquoteString(resolvedElement.getNavigationElement().getText()))) {
return;
}
}
Assert.assertTrue(false);
} else {
final PsiElement resolve = reference.resolve();
Assert.assertNotNull(state, resolve);
Assert.assertEquals(appStatesFileName, resolve.getContainingFile().getName());
Assert.assertEquals(referencedTextExpected, StringUtil.unquoteString(resolve.getNavigationElement().getText()));
}
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-plugins by JetBrains.
the class AngularJSReferencesContributor method xmlAttributePattern.
private static PsiElementPattern.Capture<XmlAttributeValue> xmlAttributePattern(@NotNull final String attributeName) {
return PlatformPatterns.psiElement(XmlAttributeValue.class).and(new FilterPattern(new ElementFilter() {
@Override
public boolean isAcceptable(Object element, @Nullable PsiElement context) {
final XmlAttributeValue attributeValue = (XmlAttributeValue) element;
final PsiElement parent = attributeValue.getParent();
if (parent instanceof XmlAttribute && attributeName.equals(((XmlAttribute) parent).getName())) {
return AngularIndexUtil.hasAngularJS(attributeValue.getProject());
}
return false;
}
@Override
public boolean isClassAcceptable(Class hintClass) {
return true;
}
}));
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-plugins by JetBrains.
the class FlexResolveHelper method bindReferenceToElement.
@Override
public JSReferenceExpression bindReferenceToElement(JSReferenceExpression ref, String qName, String newName, boolean justMakeQualified, PsiNamedElement element) {
PsiFile file;
if (qName != null && (element instanceof XmlBackedJSClass || (element instanceof XmlFile && JavaScriptSupportLoader.isFlexMxmFile((PsiFile) element)) || (file = element.getContainingFile()) == null || file.getLanguage().isKindOf(JavaScriptSupportLoader.ECMA_SCRIPT_L4))) {
boolean qualify;
boolean doImport;
if (justMakeQualified || ref.getParent() instanceof JSImportStatement || element instanceof PsiDirectoryContainer || (ref.getParent() instanceof JSReferenceListMember && ref.getContainingFile().getContext() instanceof XmlAttributeValue)) {
qualify = true;
doImport = false;
} else {
doImport = JSImportHandlingUtil.evaluateImportStatus(newName, ref) == JSImportHandlingUtil.ImportStatus.ABSENT && JSImportHandlingUtil.evaluateImportStatus(ref.getReferencedName(), ref) == JSImportHandlingUtil.ImportStatus.ABSENT;
JSQualifiedNamedElement qualifiedElement = null;
if (element instanceof JSQualifiedNamedElement) {
qualifiedElement = (JSQualifiedNamedElement) element;
} else if (element instanceof JSFile) {
qualifiedElement = JSPsiImplUtils.findQualifiedElement((JSFile) element);
} else if (element instanceof XmlFile) {
qualifiedElement = XmlBackedJSClassFactory.getXmlBackedClass(((XmlFile) element));
}
assert qualifiedElement != null : qualifiedElement.getClass();
// at this moment package declaration is out of date so element has it's original qName
qualify = JSResolveUtil.shortReferenceIsAmbiguousOrUnequal(newName, ref, qualifiedElement.getQualifiedName(), null);
}
if (qualify) {
ASTNode newChild = JSChangeUtil.createExpressionFromText(ref.getProject(), qName);
ref.getParent().getNode().replaceChild(ref.getNode(), newChild);
ref = (JSReferenceExpression) newChild.getPsi();
}
if (doImport && qName.indexOf('.') != -1 && !StringUtil.getPackageName(qName).equals(JSResolveUtil.getPackageNameFromPlace(ref))) {
final SmartPsiElementPointer<JSReferenceExpression> refPointer = SmartPointerManager.getInstance(ref.getProject()).createSmartPsiElementPointer(ref);
ImportUtils.doImport(ref, qName, false);
ref = refPointer.getElement();
}
}
return ref;
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-plugins by JetBrains.
the class FxDefinitionBackedDescriptor method getDeclarationByFxDefinitionTag.
@Nullable
private static XmlAttributeValue getDeclarationByFxDefinitionTag(@NotNull final XmlTag xmlTag) {
if (!xmlTag.isValid() || xmlTag.getParent() instanceof XmlDocument) {
return null;
}
XmlTag rootTag = xmlTag;
XmlTag parent;
while ((parent = rootTag.getParentTag()) != null) {
rootTag = parent;
}
final XmlTag[] subTags = rootTag.getSubTags();
final XmlTag libraryTag = subTags.length > 0 && FlexPredefinedTagNames.LIBRARY.equals(subTags[0].getLocalName()) && JavaScriptSupportLoader.MXML_URI3.equals(subTags[0].getNamespace()) ? subTags[0] : null;
final XmlTag[] definitionTags = libraryTag == null ? XmlTag.EMPTY : libraryTag.findSubTags(CodeContext.DEFINITION_TAG_NAME, JavaScriptSupportLoader.MXML_URI3);
final String localName = xmlTag.getLocalName();
for (final XmlTag definitionTag : definitionTags) {
final XmlAttribute nameAttribute = definitionTag.getAttribute(MxmlLanguageTagsUtil.NAME_ATTRIBUTE);
final XmlAttributeValue attributeValue = nameAttribute == null ? null : nameAttribute.getValueElement();
if (attributeValue != null && localName.equals(attributeValue.getValue())) {
return attributeValue;
}
}
return null;
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class AndroidGotoRelatedTest method testActivityToLayoutAndManifest.
public void testActivityToLayoutAndManifest() throws Exception {
final VirtualFile layout = myFixture.copyFileToProject(BASE_PATH + "layout1.xml", "res/layout/layout.xml");
final VirtualFile manifestFile = myFixture.copyFileToProject(BASE_PATH + "Manifest.xml", SdkConstants.FN_ANDROID_MANIFEST_XML);
final VirtualFile activityFile = myFixture.copyFileToProject(BASE_PATH + "Activity1.java", "src/p1/p2/MyActivity.java");
AndroidGotoRelatedProvider.ourAddDeclarationToManifest = true;
final List<GotoRelatedItem> items;
try {
items = doGotoRelatedFile(activityFile);
} finally {
AndroidGotoRelatedProvider.ourAddDeclarationToManifest = false;
}
assertEquals(2, items.size());
XmlAttributeValue manifestDeclarationTarget = null;
PsiFile psiFileTarget = null;
for (GotoRelatedItem item : items) {
final PsiElement element = item.getElement();
if (element instanceof PsiFile) {
psiFileTarget = (PsiFile) element;
} else if (element instanceof XmlAttributeValue) {
manifestDeclarationTarget = (XmlAttributeValue) element;
} else {
fail("Unexpected element: " + element);
}
}
assertEquals(layout, psiFileTarget.getVirtualFile());
assertEquals(manifestFile, manifestDeclarationTarget.getContainingFile().getVirtualFile());
}
Aggregations