@NotNull @Override public DictionaryIdentifier getIdentifier() { DictionaryIdentifier myIdentifier = null; XmlAttribute nameAttr = myXmlElement.getAttribute("name"); if (nameAttr != null) { XmlAttributeValue attrValue = nameAttr.getValueElement(); if (attrValue != null) { myIdentifier = new DictionaryIdentifierImpl(this, getName(), attrValue); } } else { for (XmlAttribute anyAttr : myXmlElement.getAttributes()) { myIdentifier = new DictionaryIdentifierImpl(this, getName(), anyAttr); } } return myIdentifier != null ? myIdentifier : new DictionaryIdentifierImpl(this, getName(), myXmlElement.getAttributes()[0]); }
@Nullable private static IProperty getResolvedProperty(@NotNull final XmlAttributeValue codeValue) { return CachedValuesManager.getCachedValue(codeValue, KEY, () -> { List<IProperty> allProperties = new SmartList<>(); for (PsiReference nextRef : codeValue.getReferences()) { if (nextRef instanceof PsiPolyVariantReference) { Arrays.stream(((PsiPolyVariantReference) nextRef).multiResolve(false)) .filter(ResolveResult::isValidResult) .map(ResolveResult::getElement) .map(o -> ObjectUtils.tryCast(o, IProperty.class)) .filter(Objects::nonNull) .forEach(allProperties::add); } else { Optional.ofNullable(nextRef.resolve()) .map(o -> ObjectUtils.tryCast(o, IProperty.class)) .ifPresent(allProperties::add); } } IProperty theChosenOne = chooseForLocale(allProperties); return new CachedValueProvider.Result<>(theChosenOne, PsiModificationTracker.MODIFICATION_COUNT); }); }
private static Collection<XmlAttributeValue> findAlternativeDoms(@NotNull final ItemType source) { final String code = source.getCode().getStringValue(); if (StringUtil.isEmpty(code)) { return Collections.emptyList(); } final XmlElement element = source.getXmlElement(); final PsiFile psiFile = element == null ? null : element.getContainingFile(); if (psiFile == null) { return Collections.emptyList(); } final TSMetaModel externalModel = TSMetaModelAccess.getInstance(psiFile.getProject()). getExternalTypeSystemMeta(psiFile); return Optional.ofNullable(externalModel.findMetaClassForDom(source)) .map(TSMetaClass::retrieveAllDomsStream) .orElse(Stream.empty()) .filter(dom -> !dom.equals(source)) .map(ItemType::getCode) .map(GenericAttributeValue::getXmlAttributeValue) .collect(Collectors.toList()); }
private static Template buildTemplate(@NotNull XmlAttribute attr, List<XmlTag> refs) { //XmlFile containingFile = (XmlFile)attr.getContainingFile(); PsiElement commonParent = PsiTreeUtil.findCommonParent(refs); TemplateBuilderImpl builder = new TemplateBuilderImpl(attr); XmlAttributeValue attrValue = attr.getValueElement(); PsiElement valuePsi = attrValue.getFirstChild().getNextSibling(); String flowNameValue = new String(attrValue.getValue()); builder.replaceElement(valuePsi,"PrimaryVariable", new TextExpression(flowNameValue), true); /* for (XmlTag ref : refs) { if (ref.getContainingFile().equals(attr.getContainingFile())) { XmlAttribute nextAttr = ref.getAttribute(MuleConfigConstants.NAME_ATTRIBUTE); XmlAttributeValue nextValue = nextAttr.getValueElement(); PsiElement nextValuePsi = nextValue.getFirstChild().getNextSibling(); builder.replaceElement(nextValuePsi, "OtherVariable", "PrimaryVariable",false); } } */ return builder.buildInlineTemplate(); }
public boolean isReferenceTo(PsiElement element) { if (element == null) return false; PsiElement parent = PsiTreeUtil.getParentOfType(element, XmlTag.class); if (parent != null && parent instanceof XmlTag && (MuleConfigConstants.FLOW_TAG_NAME.equals(((XmlTag)parent).getName()) || MuleConfigConstants.SUB_FLOW_TAG_NAME.equals(((XmlTag)parent).getName()))) { //It's a <flow> tag or <sub-flow> tag if (element instanceof XmlAttributeValue && ((XmlAttributeValue)element).getValue().equals(getFlowName())) { return true; } } return false; }
private PsiElement findDeclaration(PsiElement element, String type) { if (!(element instanceof XmlAttributeValue)) { return null; } JSObjectLiteralExpression exports = WeexFileUtil.getExportsStatement(element); if (exports == null) { return null; } else { String valueName = CodeUtil.getVarNameFromMustache(((XmlAttributeValue) element).getValue()); if ("function".equals(type)) { return WeexFileUtil.getFunctionDeclaration(value, valueName); } else { return WeexFileUtil.getVarDeclaration(value, valueName); } } }
@NotNull public PsiReference[] inject(@Nullable String unresolvedText, @NotNull PsiElement element, @NotNull ConvertContext context) { if (element instanceof XmlAttributeValue) { final XmlAttributeValue xmlAttributeValue = (XmlAttributeValue)element; final List<PsiReference> refs = PsiReferenceListSpinAllocator.alloc(); try { addPropertyReferences(context, xmlAttributeValue, refs); addMacrodefParameterRefs(xmlAttributeValue, refs); return refs.size() == 0? PsiReference.EMPTY_ARRAY : ContainerUtil.toArray(refs, new PsiReference[refs.size()]); } finally { PsiReferenceListSpinAllocator.dispose(refs); } } return PsiReference.EMPTY_ARRAY; }
@Override public Optional<String> extractTextFromElement(PsiElement element, boolean concatString, boolean stripWhitespace) { // maybe its xml then try that if (element instanceof XmlAttributeValue) { return Optional.ofNullable(((XmlAttributeValue) element).getValue()); } else if (element instanceof XmlText) { return Optional.ofNullable(((XmlText) element).getValue()); } else if (element instanceof XmlToken) { // it may be a token which is a part of an combined attribute if (concatString) { XmlAttributeValue xml = PsiTreeUtil.getParentOfType(element, XmlAttributeValue.class); if (xml != null) { return Optional.ofNullable(getInnerText(xml.getValue())); } } else { String returnText = element.getText(); final PsiElement prevSibling = element.getPrevSibling(); if (prevSibling != null && prevSibling.getText().equalsIgnoreCase("&")) { returnText = prevSibling.getText() + returnText; } return Optional.ofNullable(getInnerText(returnText)); } } return Optional.empty(); }
@NotNull public static PsiField[] findIdFields(@NotNull XmlAttribute attribute) { final XmlAttributeValue value = attribute.getValueElement(); if (value != null && isIdDeclaration(value)) { final String id = getResourceNameByReferenceText(attribute.getValue()); if (id != null) { final AndroidFacet facet = AndroidFacet.getInstance(attribute); if (facet != null) { return findResourceFields(facet, ResourceType.ID.getName(), id, false); } } } return PsiField.EMPTY_ARRAY; }
@NotNull @Override public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly, @NotNull LocalInspectionToolSession session) { return new XmlElementVisitor() { @Override public void visitXmlTag(XmlTag tag) { if (tag.getValue().getTextElements().length > 0) { checkReferences(tag, holder); } } @Override public void visitXmlAttributeValue(XmlAttributeValue value) { checkReferences(value, holder); } }; }
@Override @NotNull protected Pair<TextRange, PsiElement> computeProblemRange() { final PsiReference reference = myReference; PsiElement element = reference.getElement(); if (element instanceof XmlAttributeValue && element.getTextLength() == 0) return NO_PROBLEM; final TextRange referenceRange = reference.getRangeInElement(); if (referenceRange.isEmpty()) { int startOffset = referenceRange.getStartOffset(); return element instanceof XmlAttributeValue ? Pair.create((TextRange)new UnfairTextRange(startOffset - 1, startOffset + 1), element) : Pair.create(TextRange.from(startOffset, 1), element); } return Pair.create(referenceRange, element); }
@Nullable private PsiElement getPsiElement() { if (myDomElement instanceof DomFileElement) { return ((DomFileElement)myDomElement).getFile(); } if (myDomElement instanceof GenericAttributeValue) { final GenericAttributeValue attributeValue = (GenericAttributeValue)myDomElement; final XmlAttributeValue value = attributeValue.getXmlAttributeValue(); return value != null && StringUtil.isNotEmpty(value.getText()) ? value : attributeValue.getXmlElement(); } final XmlTag tag = myDomElement.getXmlTag(); if (myDomElement instanceof GenericValue && tag != null) { final XmlText[] textElements = tag.getValue().getTextElements(); if (textElements.length > 0) { return textElements[0]; } } return tag; }
private boolean domKnowsBetter(final CompletionParameters parameters, final CompletionResultSet result) { final XmlAttributeValue element = PsiTreeUtil.getParentOfType(parameters.getPosition(), XmlAttributeValue.class); if (element == null) { return false; } if (isSchemaEnumerated(element)) { return false; } final PsiElement parent = element.getParent(); if (parent instanceof XmlAttribute) { XmlAttributeDescriptor descriptor = ((XmlAttribute)parent).getDescriptor(); if (descriptor != null && descriptor.getDefaultValue() != null) { final PsiReference[] references = myProvider.getReferencesByElement(element, new ProcessingContext()); if (references.length > 0) { return LegacyCompletionContributor.completeReference(parameters, result); } } } return false; }
public static boolean isSchemaEnumerated(final PsiElement element) { if (element instanceof XmlTag) { final XmlTag simpleContent = XmlUtil.getSchemaSimpleContent((XmlTag)element); if (simpleContent != null && XmlUtil.collectEnumerationValues(simpleContent, new HashSet<String>())) { return true; } } if (element instanceof XmlAttributeValue) { final PsiElement parent = element.getParent(); if (parent instanceof XmlAttribute) { final XmlAttributeDescriptor descriptor = ((XmlAttribute)parent).getDescriptor(); if (descriptor != null && descriptor.isEnumerated()) { return true; } String[] enumeratedValues = XmlAttributeValueGetter.getEnumeratedValues((XmlAttribute)parent); if (enumeratedValues != null && enumeratedValues.length > 0) { String value = descriptor == null ? null : descriptor.getDefaultValue(); if (value == null || enumeratedValues.length != 1 || !value.equals(enumeratedValues[0])) { return true; } } } } return false; }
@Nullable public SmartPsiElementPointer<XmlTag> doFix(Project project, ProblemDescriptor descriptor, boolean reformat) { PsiElement element = descriptor.getPsiElement(); if (element instanceof XmlAttributeValue) { element = element.getParent(); } else if (!(element instanceof XmlAttribute)) { return null; } XmlAttribute attribute = (XmlAttribute)element; XmlTag parent = attribute.getParent(); if (!FileModificationService.getInstance().prepareFileForWrite(parent.getContainingFile())) return null; SmartPsiElementPointer<XmlTag> pointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(parent); doRemove(project, attribute, parent); if (reformat) { reformatStartTag(project, pointer); } return pointer; }
@NotNull @Override public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) { return new XmlElementVisitor() { @Override public void visitXmlAttributeValue(XmlAttributeValue value) { checkRefs(value, holder, isOnTheFly); } @Override public void visitXmlDoctype(XmlDoctype xmlDoctype) { checkRefs(xmlDoctype, holder, isOnTheFly); } @Override public void visitXmlTag(XmlTag tag) { checkRefs(tag, holder, isOnTheFly); } }; }
private static PsiFile resolveByLocation(PsiFile baseFile, String location) { if (baseFile instanceof XmlFile) { XmlTag tag = ((XmlFile)baseFile).getRootTag(); if (tag != null) { XmlAttribute attribute = tag.getAttribute("schemaLocation", XmlUtil.XML_SCHEMA_INSTANCE_URI); if (attribute != null) { XmlAttributeValue element = attribute.getValueElement(); if (element != null) { PsiReference[] references = element.getReferences(); for (PsiReference reference : references) { if (location.equals(reference.getCanonicalText())) { PsiElement resolve = reference.resolve(); return resolve instanceof PsiFile ? (PsiFile)resolve : null; } } } } } } return null; }
@Nullable @Override public LocalQuickFix[] getQuickFixes() { final XmlAttributeValue valueElement = myAttribute.getValueElement(); if (valueElement != null) { return new LocalQuickFix[] { new CreateNSDeclarationIntentionFix(valueElement, getCanonicalText()) { @Override public boolean showHint(@NotNull Editor editor) { return false; } } }; } return LocalQuickFix.EMPTY_ARRAY; }
public static XmlTag getIncludedRoot(XmlTag context) { if (context == null) return null; final XmlAttribute xmlAttribute = context.getAttribute(FxmlConstants.FX_ELEMENT_SOURCE); if (xmlAttribute != null) { final XmlAttributeValue valueElement = xmlAttribute.getValueElement(); if (valueElement != null) { final PsiReference reference = valueElement.getReference(); if (reference != null) { final PsiElement resolve = reference.resolve(); if (resolve instanceof XmlFile) { final XmlTag rootTag = ((XmlFile)resolve).getRootTag(); if (rootTag != null) { return rootTag; } } } } } return null; }
@Override public PsiLanguageInjectionHost updateText(@NotNull String text) { try { final String quoteChar = getTextLength() > 0 ? getText().substring(0, 1) : ""; String contents = StringUtil.containsAnyChar(quoteChar, "'\"") ? StringUtil.trimEnd(StringUtil.trimStart(text, quoteChar), quoteChar) : text; XmlAttribute newAttribute = XmlElementFactory.getInstance(getProject()).createXmlAttribute("q", contents); XmlAttributeValue newValue = newAttribute.getValueElement(); CheckUtil.checkWritable(this); replaceAllChildrenToChildrenOf(newValue.getNode()); } catch (IncorrectOperationException e) { LOG.error(e); } return this; }
public void testNavigationInPlatformXml3() throws Exception { final VirtualFile file = LocalFileSystem.getInstance().findFileByPath( getTestSdkPath() + "/platforms/" + getPlatformDir() + "/data/res/values/resources.xml"); myFixture.configureFromExistingVirtualFile(file); myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(5, 44)); PsiElement[] targets = GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset()); assertNotNull(targets); assertEquals(1, targets.length); final PsiElement targetElement = LazyValueResourceElementWrapper.computeLazyElement(targets[0]); assertInstanceOf(targetElement, XmlAttributeValue.class); final XmlAttributeValue targetAttrValue = (XmlAttributeValue)targetElement; assertEquals("my_white", targetAttrValue.getValue()); assertEquals("name", ((XmlAttribute)targetAttrValue.getParent()).getName()); assertEquals("color", ((XmlTag)targetAttrValue.getParent().getParent()).getName()); assertEquals(file, targetElement.getContainingFile().getVirtualFile()); }
public void testNavigationInPlatformXml2() throws Exception { final VirtualFile file = LocalFileSystem.getInstance().findFileByPath( getTestSdkPath() + "/platforms/" + getPlatformDir() + "/data/res/values/resources.xml"); myFixture.configureFromExistingVirtualFile(file); myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(19, 17)); PsiElement[] targets = GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset()); assertNotNull(targets); assertEquals(1, targets.length); final PsiElement targetElement = LazyValueResourceElementWrapper.computeLazyElement(targets[0]); assertInstanceOf(targetElement, XmlAttributeValue.class); final XmlAttributeValue targetAttrValue = (XmlAttributeValue)targetElement; assertEquals("Theme", targetAttrValue.getValue()); assertEquals("name", ((XmlAttribute)targetAttrValue.getParent()).getName()); assertEquals("style", ((XmlTag)targetAttrValue.getParent().getParent()).getName()); assertEquals(file, targetElement.getContainingFile().getVirtualFile()); }
private static boolean isUnused(PsiElement obj, Query<PsiReference> query) { if (obj instanceof XsltParameter) { final Collection<PsiReference> references = query.findAll(); int n = references.size(); for (PsiReference reference : references) { final PsiElement element = reference.getElement(); if (element instanceof XmlAttributeValue) { final XmlAttribute parent = (XmlAttribute)element.getParent(); if ("name".equals(parent.getName())) { final XmlTag tag = parent.getParent(); if (tag != null && "with-param".equals(tag.getLocalName())) { n--; } } } } return n == 0; } else { return query.findFirst() == null; } }
@Override public String getElementDescription(@NotNull final PsiElement element, @NotNull final ElementDescriptionLocation location) { if (location instanceof UsageViewShortNameLocation) { if (element instanceof XmlAttributeValue) { return ((XmlAttributeValue)element).getValue(); } } if (location instanceof UsageViewLongNameLocation) { if (element instanceof XmlTag) { return ((XmlTag)element).getName(); } else if (element instanceof XmlAttributeValue) { return ((XmlAttributeValue)element).getValue(); } } return null; }
private static void collectResDir(Module module, XmlAttributeValue styleNameAttrValue, String styleName, List<VirtualFile> resDirs) { final AndroidFacet f = AndroidFacet.getInstance(module); if (f == null) { return; } final List<ValueResourceInfoImpl> resolvedStyles = f.getLocalResourceManager().findValueResourceInfos( ResourceType.STYLE.getName(), styleName, true, false); if (resolvedStyles.size() == 1) { final XmlAttributeValue resolvedStyleNameElement = resolvedStyles.get(0).computeXmlElement(); if (resolvedStyleNameElement != null && resolvedStyleNameElement.equals(styleNameAttrValue)) { resDirs.addAll(f.getAllResourceDirectories()); } } }
@NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { final XmlAttributeValue attributeValue = (XmlAttributeValue)element; final PsiElement parent = attributeValue.getParent(); if (parent instanceof XmlAttribute) { final XmlAttributeDescriptor descriptor = ((XmlAttribute)parent).getDescriptor(); if (descriptor instanceof JavaFxPropertyAttributeDescriptor) { final PsiElement declaration = descriptor.getDeclaration(); if (declaration instanceof PsiField) { final PsiField field = (PsiField)declaration; final PsiClassType propertyClassType = JavaFxPsiUtil.getPropertyClassType(field); if (propertyClassType != null && InheritanceUtil.isInheritor(propertyClassType, JavaFxCommonClassNames.JAVAFX_SCENE_PAINT)) { return new PsiReference[] {new JavaFxColorReference(attributeValue)}; } } } } return PsiReference.EMPTY_ARRAY; }
@Override @NotNull public Object[] getVariants() { final ProcessingContext context = new ProcessingContext(); context.put(VARIANTS, new HashSet<XmlAttributeValue>()); final ResolvingVisitor visitor = new ResolvingVisitor(PATTERN.with(AddValueCondition.create(VARIANTS)), context) { @Override public void visitXmlTag(XmlTag tag) { super.visitXmlTag(tag); visitSubTags(tag); } }; process(visitor); return AttributeValueFunction.toStrings(context.get(VARIANTS)); }
@Nullable public static AndroidResourceReferenceBase getAndroidResourceReference(@Nullable GenericAttributeValue<ResourceValue> attribute, boolean localOnly) { if (attribute == null) { return null; } final ResourceValue resValue = attribute.getValue(); if (resValue == null || (localOnly && resValue.getPackage() != null)) { return null; } final XmlAttributeValue value = attribute.getXmlAttributeValue(); if (value == null) { return null; } for (PsiReference reference : value.getReferences()) { if (reference instanceof AndroidResourceReferenceBase) { return (AndroidResourceReferenceBase)reference; } } return null; }
public Collection<PsiElement> getEventElements(final String name, final GlobalSearchScope scope) { Collection<PsiElement> result = new ArrayList<>(); Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(EventNameIndex.KEY, name, scope); for (VirtualFile virtualFile : virtualFiles) { XmlFile xmlFile = (XmlFile) PsiManager.getInstance(project).findFile(virtualFile); Collection<XmlAttributeValue> valueElements = XmlPsiTreeUtil .findAttributeValueElements(xmlFile, "event", "name", name); result.addAll(valueElements); } return result; }
@Override public String getPlaceholderText(@NotNull ASTNode node) { final PsiElement element = node.getPsi(); if (element instanceof XmlAttributeValue) { IProperty property = getResolvedProperty((XmlAttributeValue) element); return property == null ? element.getText() : "{" + property.getValue() + "}"; } return element.getText(); }
public static PsiField resolveToPsiField(@NotNull final Property property, @Nullable final String name) { if (StringUtil.isEmptyOrSpaces(name)) { return null; } if (!(property.getParent() instanceof Bean)) { return null; } final Bean bean = (Bean) property.getParent(); final GenericAttributeValue<String> clazz = bean.getClazz(); if (!clazz.exists()) { return null; } final XmlAttributeValue xmlValue = clazz.getXmlAttributeValue(); if (xmlValue == null) { return null; } return Arrays.stream(xmlValue.getReferences()) .map(PsiReference::resolve) .map(o -> ObjectUtils.tryCast(o, PsiClass.class)) .filter(Objects::nonNull) .map(nextClass -> nextClass.findFieldByName(name, false)) .filter(Objects::nonNull) .findAny() .orElse(null); }
protected static <D extends DomElement> XmlAttributeValue navigateToValue( @Nullable final D dom, @NotNull final Function<? super D, GenericAttributeValue<?>> attribute ) { return Optional.ofNullable(dom) .map(attribute) .map(GenericAttributeValue::getXmlAttributeValue) .orElse(null); }
@Override public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectedLanguagePlaces) { if (MuleConfigUtils.isMuleFile(host.getContainingFile())) { if (host instanceof XmlAttributeValue) { // Try to inject a language, somewhat abusing the lazy evaluation of predicates :( for (Pair<String, String> language : languages) { if (tryInjectLanguage(language.getFirst(), language.getSecond(), host, injectedLanguagePlaces)) { break; } } } else if (host instanceof XmlText) { final XmlTag tag = ((XmlText) host).getParentTag(); if (tag != null) { final QName tagName = MuleConfigUtils.getQName(tag); if (tagName.equals(globalFunctions) || tagName.equals(expressionComponent) || tagName.equals(expressionTransformer)) { final String scriptingName = MelLanguage.MEL_LANGUAGE_ID; injectLanguage(host, injectedLanguagePlaces, scriptingName); } else if (tagName.equals(scriptingScript)) { final String engine = tag.getAttributeValue("engine"); if (engine != null) { injectLanguage(host, injectedLanguagePlaces, StringUtil.capitalize(engine)); } } else if (tagName.equals(dwSetPayload) || tagName.equals(dwSetProperty) || tagName.equals(dwSetVariable) || tagName.equals(dwSetSessionVar)) { injectLanguage(host, injectedLanguagePlaces, WEAVE_LANGUAGE_ID); } } } } }
private JavaFxIdReferenceBase(XmlAttributeValue element, Map<String, XmlAttributeValue> fileIds, Set<String> acceptableIds, String referencesId) { super(element); myFileIds = fileIds; myAcceptableIds = acceptableIds; myReferencesId = referencesId; }
@NotNull @Override public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) { if (element instanceof XmlAttributeValue && !isMelExpression((XmlAttributeValue) element)) { final XmlAttributeValue attribute = (XmlAttributeValue) element; return new PsiReference[]{new FlowRefPsiReference(attribute)}; } return PsiReference.EMPTY_ARRAY; }
@NotNull @Override public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) { if (element instanceof XmlAttributeValue) { final XmlAttributeValue attribute = (XmlAttributeValue) element; return new PsiReference[]{new ConfigRefPsiReference(attribute)}; } return PsiReference.EMPTY_ARRAY; }
@Override public XmlAttributeValue computeXmlElement() { final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(myFile); if (!(psiFile instanceof XmlFile)) { return null; } final Ref<XmlAttributeValue> result = Ref.create(); psiFile.accept(new XmlRecursiveElementVisitor() { @Override public void visitXmlAttributeValue(XmlAttributeValue attributeValue) { if (!result.isNull()) { return; } if (AndroidResourceUtil.isIdDeclaration(attributeValue)) { final String idInAttr = AndroidResourceUtil.getResourceNameByReferenceText(attributeValue.getValue()); if (myName.equals(idInAttr)) { result.set(attributeValue); } } } }); return result.get(); }
@NotNull public List<XmlAttributeValue> findIdDeclarations(@NotNull final String id) { if (!isResourcePublic(ResourceType.ID.getName(), id)) { return Collections.emptyList(); } final List<XmlAttributeValue> declarations = new ArrayList<XmlAttributeValue>(); final Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(AndroidIdIndex.INDEX_ID, "+" + id, GlobalSearchScope.allScope(myProject)); final Set<VirtualFile> fileSet = new HashSet<VirtualFile>(files); final PsiManager psiManager = PsiManager.getInstance(myProject); for (VirtualFile subdir : getResourceSubdirsToSearchIds()) { for (VirtualFile file : subdir.getChildren()) { if (fileSet.contains(file)) { final PsiFile psiFile = psiManager.findFile(file); if (psiFile instanceof XmlFile) { psiFile.accept(new XmlRecursiveElementVisitor() { @Override public void visitXmlAttributeValue(XmlAttributeValue attributeValue) { if (AndroidResourceUtil.isIdDeclaration(attributeValue)) { final String idInAttr = AndroidResourceUtil.getResourceNameByReferenceText(attributeValue.getValue()); if (id.equals(idInAttr)) { declarations.add(attributeValue); } } } }); } } } } return declarations; }
@Override public boolean isAcceptable(Object element, @Nullable PsiElement context) { if (element instanceof XmlAttributeValue && context != null && context.getContainingFile() instanceof JSFile) { final XmlAttributeValue value = (XmlAttributeValue) element; final XmlAttribute xmlAttribute = PsiTreeUtil.getParentOfType(value, XmlAttribute.class); if (xmlAttribute != null) { return xmlAttribute.getName().equals("styleName"); } } return false; }
public ValueResourceElementWrapper(@NotNull XmlAttributeValue wrappeeElement) { if (!(wrappeeElement instanceof NavigationItem)) { throw new IllegalArgumentException(); } if (!(wrappeeElement instanceof PsiMetaOwner)) { throw new IllegalArgumentException(); } myWrappee = wrappeeElement; final PsiFile file = getContainingFile(); myFileName = file != null ? file.getName() : null; final PsiDirectory dir = file != null ? file.getContainingDirectory() : null; myDirName = dir != null ? dir.getName() : null; }