use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class DomElementProblemDescriptorImpl method getPsiElement.
@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;
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class DomTarget method getTarget.
@Nullable
public static DomTarget getTarget(DomElement element, GenericDomValue nameElement) {
if (nameElement instanceof GenericAttributeValue) {
final GenericAttributeValue genericAttributeValue = (GenericAttributeValue) nameElement;
final XmlAttributeValue attributeValue = genericAttributeValue.getXmlAttributeValue();
if (attributeValue == null) {
return null;
}
final int length = attributeValue.getTextLength();
if (length >= 2) {
return new DomTarget(element, attributeValue, new TextRange(1, length - 1), nameElement);
}
}
final XmlTag tag = nameElement.getXmlTag();
if (tag == null) {
return null;
}
XmlTagValue tagValue = tag.getValue();
if (StringUtil.isEmpty(tagValue.getTrimmedText())) {
return null;
}
return new DomTarget(element, tag, XmlTagUtil.getTrimmedValueRange(tag), nameElement);
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class DomHardCoreTestCase method getReference.
protected PsiReference getReference(final GenericAttributeValue value) {
final XmlAttributeValue attributeValue = value.getXmlAttributeValue();
assertNotNull(attributeValue);
final PsiReference reference = attributeValue.getContainingFile().findReferenceAt(attributeValue.getTextRange().getStartOffset() + 1);
assertNotNull(reference);
assertEquals(attributeValue, reference.resolve());
return reference;
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class XmlAttributeValueImpl method updateText.
@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()).createAttribute("q", contents, this);
XmlAttributeValue newValue = newAttribute.getValueElement();
CheckUtil.checkWritable(this);
replaceAllChildrenToChildrenOf(newValue.getNode());
} catch (IncorrectOperationException e) {
LOG.error(e);
}
return this;
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class JavaFxEventHandlerInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly, @NotNull LocalInspectionToolSession session) {
if (!JavaFxFileTypeFactory.isFxml(session.getFile()))
return PsiElementVisitor.EMPTY_VISITOR;
return new XmlElementVisitor() {
@Override
public void visitXmlAttributeValue(XmlAttributeValue xmlAttributeValue) {
super.visitXmlAttributeValue(xmlAttributeValue);
final PsiElement valueParent = xmlAttributeValue.getParent();
if (!(valueParent instanceof XmlAttribute))
return;
final XmlAttribute attribute = (XmlAttribute) valueParent;
final List<PsiMethod> eventHandlerMethods = getEventHandlerMethods(attribute);
if (eventHandlerMethods.size() == 0)
return;
if (eventHandlerMethods.size() != 1) {
holder.registerProblem(xmlAttributeValue, "Ambiguous event handler name: more than one matching method found");
}
if (myDetectNonVoidReturnType) {
eventHandlerMethods.stream().map(PsiMethod::getReturnType).filter(returnType -> !PsiType.VOID.equals(returnType)).findAny().ifPresent(ignored -> holder.registerProblem(xmlAttributeValue, "Return type of event handler should be void"));
}
final PsiClassType declaredType = JavaFxPsiUtil.getDeclaredEventType(attribute);
if (declaredType == null)
return;
for (PsiMethod method : eventHandlerMethods) {
final PsiParameter[] parameters = method.getParameterList().getParameters();
if (parameters.length == 1) {
final PsiType actualType = parameters[0].getType();
if (actualType instanceof PsiClassType) {
if (!actualType.isAssignableFrom(declaredType)) {
final LocalQuickFix parameterTypeFix = new ChangeParameterTypeQuickFix(attribute, method, declaredType);
final PsiClassType actualRawType = ((PsiClassType) actualType).rawType();
final PsiClassType expectedRawType = declaredType.rawType();
if (actualRawType.isAssignableFrom(expectedRawType)) {
final List<LocalQuickFix> quickFixes = new ArrayList<>();
quickFixes.add(parameterTypeFix);
collectFieldTypeFixes(attribute, (PsiClassType) actualType, quickFixes);
holder.registerProblem(xmlAttributeValue, "Incompatible generic parameter of event handler argument: " + actualType.getCanonicalText() + " is not assignable from " + declaredType.getCanonicalText(), quickFixes.toArray(LocalQuickFix.EMPTY_ARRAY));
} else {
holder.registerProblem(xmlAttributeValue, "Incompatible event handler argument: " + actualRawType.getCanonicalText() + " is not assignable from " + expectedRawType.getCanonicalText(), parameterTypeFix);
}
}
}
}
}
}
};
}
Aggregations