use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class PrefixReferenceProvider method getReferencesByElement.
@Override
@NotNull
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
final XmlAttributeValue value = (XmlAttributeValue) element;
final String s = value.getValue();
final int i = s.indexOf(':');
if (i <= 0 || s.startsWith("xml:")) {
return PsiReference.EMPTY_ARRAY;
}
return new PsiReference[] { new PrefixReference(value, i) };
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class PropertyKeyReferenceProvider method getReferencesByElement.
@NotNull
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
if (myTagMode && element instanceof XmlTag) {
return getTagReferences(((XmlTag) element));
}
if (element instanceof XmlAttributeValue) {
final XmlAttribute xmlAttribute = (XmlAttribute) element.getParent();
if (element.getTextLength() < 2) {
return PsiReference.EMPTY_ARRAY;
}
final XmlTag tag = xmlAttribute.getParent();
String value = null;
String bundle = tag.getAttributeValue("bundle");
if ("key".equals(xmlAttribute.getName())) {
value = xmlAttribute.getValue();
} else if (myFallbackKeyName.equals(xmlAttribute.getName())) {
value = xmlAttribute.getValue();
final String groupBundle = tag.getAttributeValue(myFallbackGroupName);
if (groupBundle != null) {
bundle = groupBundle;
}
}
if (value != null) {
return new PsiReference[] { new MyPropertyReference(value, xmlAttribute.getValueElement(), bundle) };
}
}
return PsiReference.EMPTY_ARRAY;
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class AntCreatePropertyFix method applyFix.
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement psiElement = descriptor.getPsiElement();
final PsiFile containingFile = psiElement.getContainingFile();
final FileModificationService modificationService = FileModificationService.getInstance();
Navigatable result = null;
if (myPropFile != null) {
final VirtualFile vFile = myPropFile.getVirtualFile();
boolean canModify = true;
if (myPropFile instanceof PsiFile) {
canModify = modificationService.prepareFileForWrite((PsiFile) myPropFile);
} else if (vFile != null) {
canModify = modificationService.prepareVirtualFilesForWrite(project, Collections.singleton(vFile));
}
if (canModify) {
final IProperty generatedProperty = myPropFile.addProperty(myCanonicalText, "");
result = vFile != null ? new OpenFileDescriptor(project, vFile, generatedProperty.getPsiElement().getTextRange().getEndOffset()) : generatedProperty;
}
} else {
if (containingFile instanceof XmlFile) {
final XmlFile xmlFile = (XmlFile) containingFile;
final XmlTag rootTag = xmlFile.getRootTag();
if (rootTag != null && modificationService.prepareFileForWrite(xmlFile)) {
final XmlTag propTag = rootTag.createChildTag(PROPERTY, rootTag.getNamespace(), null, false);
propTag.setAttribute(NAME_ATTR, myCanonicalText);
propTag.setAttribute(VALUE_ATTR, "");
final DomElement contextElement = DomUtil.getDomElement(descriptor.getPsiElement());
PsiElement generated;
if (contextElement == null) {
generated = rootTag.addSubTag(propTag, true);
} else {
final AntDomTarget containingTarget = contextElement.getParentOfType(AntDomTarget.class, false);
final DomElement anchor = containingTarget != null ? containingTarget : contextElement;
final XmlTag tag = anchor.getXmlTag();
if (!rootTag.equals(tag)) {
generated = tag.getParent().addBefore(propTag, tag);
} else {
generated = rootTag.addSubTag(propTag, true);
}
}
if (generated instanceof XmlTag) {
final XmlAttribute valueAttrib = ((XmlTag) generated).getAttribute(VALUE_ATTR);
if (valueAttrib != null) {
final XmlAttributeValue valueElement = valueAttrib.getValueElement();
if (valueElement instanceof Navigatable) {
result = (Navigatable) valueElement;
}
}
}
if (result == null && generated instanceof Navigatable) {
result = (Navigatable) generated;
}
}
}
}
if (result != null) {
result.navigate(true);
}
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class AntDomTargetDependsListConverter method createReferences.
@NotNull
public PsiReference[] createReferences(GenericDomValue<TargetResolver.Result> value, PsiElement element, ConvertContext context) {
final XmlElement xmlElement = value.getXmlElement();
if (!(xmlElement instanceof XmlAttribute)) {
return PsiReference.EMPTY_ARRAY;
}
final XmlAttributeValue valueElement = ((XmlAttribute) xmlElement).getValueElement();
if (valueElement == null) {
return PsiReference.EMPTY_ARRAY;
}
final String refsString = value.getStringValue();
if (refsString == null) {
return PsiReference.EMPTY_ARRAY;
}
final List<PsiReference> refs = new ArrayList<>();
final AntDomTargetReference.ReferenceGroup group = new AntDomTargetReference.ReferenceGroup();
final TextRange wholeStringRange = ElementManipulators.getValueTextRange(valueElement);
final StringTokenizer tokenizer = new StringTokenizer(refsString, ",", false);
while (tokenizer.hasMoreTokens()) {
final String token = tokenizer.nextToken();
int tokenStartOffset = tokenizer.getCurrentPosition() - token.length();
final String ref = token.trim();
if (ref.length() != token.length()) {
for (int idx = 0; idx < token.length(); idx++) {
if (Character.isWhitespace(token.charAt(idx))) {
tokenStartOffset++;
} else {
break;
}
}
}
refs.add(new AntDomTargetReference(element, TextRange.from(wholeStringRange.getStartOffset() + tokenStartOffset, ref.length()), group));
}
return refs.toArray(new PsiReference[refs.size()]);
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-plugins by JetBrains.
the class DartiumDebuggerEngine method isHtmlFileWithDartScript.
private static boolean isHtmlFileWithDartScript(@Nullable PsiFile psiFile) {
if (psiFile == null || !HtmlUtil.isHtmlFile(psiFile)) {
return false;
}
final String text = psiFile.getText();
int i = -1;
while ((i = text.indexOf(DartLanguage.DART_MIME_TYPE, i + 1)) != -1) {
final PsiElement element = psiFile.findElementAt(i);
if (element != null && element.getParent() instanceof XmlAttributeValue) {
if (HtmlUtil.isScriptTag(PsiTreeUtil.getParentOfType(element, XmlTag.class))) {
return true;
}
}
}
return false;
}
Aggregations