use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.
the class DomHighlightingHelperImpl method checkRequired.
@Override
@NotNull
public List<DomElementProblemDescriptor> checkRequired(final DomElement element, final DomElementAnnotationHolder holder) {
final Required required = element.getAnnotation(Required.class);
if (required != null) {
final XmlElement xmlElement = element.getXmlElement();
if (xmlElement == null) {
if (required.value()) {
final String xmlElementName = element.getXmlElementName();
String namespace = element.getXmlElementNamespace();
if (element instanceof GenericAttributeValue) {
return Collections.singletonList(holder.createProblem(element, IdeBundle.message("attribute.0.should.be.defined", xmlElementName), new DefineAttributeQuickFix(xmlElementName, namespace)));
}
return Collections.singletonList(holder.createProblem(element, HighlightSeverity.ERROR, IdeBundle.message("child.tag.0.should.be.defined", xmlElementName), new AddRequiredSubtagFix(xmlElementName, namespace)));
}
} else if (element instanceof GenericDomValue) {
return ContainerUtil.createMaybeSingletonList(checkRequiredGenericValue((GenericDomValue) element, required, holder));
}
}
if (DomUtil.hasXml(element)) {
final SmartList<DomElementProblemDescriptor> list = new SmartList<>();
final DomGenericInfo info = element.getGenericInfo();
for (final AbstractDomChildrenDescription description : info.getChildrenDescriptions()) {
if (description instanceof DomCollectionChildDescription && description.getValues(element).isEmpty()) {
final DomCollectionChildDescription childDescription = (DomCollectionChildDescription) description;
final Required annotation = description.getAnnotation(Required.class);
if (annotation != null && annotation.value()) {
list.add(holder.createProblem(element, childDescription, IdeBundle.message("child.tag.0.should.be.defined", ((DomCollectionChildDescription) description).getXmlElementName())));
}
}
}
return list;
}
return Collections.emptyList();
}
use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.
the class DomHighlightingHelperImpl method checkResolveProblems.
@Override
@NotNull
public List<DomElementProblemDescriptor> checkResolveProblems(GenericDomValue element, final DomElementAnnotationHolder holder) {
if (StringUtil.isEmpty(element.getStringValue())) {
final Required required = element.getAnnotation(Required.class);
if (required != null && !required.nonEmpty())
return Collections.emptyList();
}
final XmlElement valueElement = DomUtil.getValueElement(element);
if (valueElement != null && !isSoftReference(element)) {
final SmartList<DomElementProblemDescriptor> list = new SmartList<>();
final PsiReference[] psiReferences = myProvider.getReferencesByElement(valueElement, new ProcessingContext());
GenericDomValueReference domReference = ContainerUtil.findInstance(psiReferences, GenericDomValueReference.class);
final Converter converter = WrappingConverter.getDeepestConverter(element.getConverter(), element);
boolean hasBadResolve = false;
if (domReference == null || !isDomResolveOK(element, domReference, converter)) {
for (final PsiReference reference : psiReferences) {
if (reference != domReference && hasBadResolve(reference)) {
hasBadResolve = true;
list.add(holder.createResolveProblem(element, reference));
}
}
final boolean isResolvingConverter = converter instanceof ResolvingConverter;
//noinspection unchecked
if (!hasBadResolve && (domReference != null || isResolvingConverter && hasBadResolve(domReference = new GenericDomValueReference(element)))) {
hasBadResolve = true;
final String errorMessage = converter.getErrorMessage(element.getStringValue(), ConvertContextFactory.createConvertContext(DomManagerImpl.getDomInvocationHandler(element)));
if (errorMessage != null) {
list.add(holder.createResolveProblem(element, domReference));
}
}
}
if (!hasBadResolve && psiReferences.length == 0 && element.getValue() == null && !PsiTreeUtil.hasErrorElements(valueElement)) {
final String errorMessage = converter.getErrorMessage(element.getStringValue(), ConvertContextFactory.createConvertContext(DomManagerImpl.getDomInvocationHandler(element)));
if (errorMessage != null) {
list.add(holder.createProblem(element, errorMessage));
}
}
return list;
}
return Collections.emptyList();
}
use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.
the class DomInvocationHandler method createChildTag.
protected final XmlTag createChildTag(final EvaluatedXmlName tagName) {
final String localName = tagName.getXmlName().getLocalName();
if (localName.contains(":")) {
try {
return XmlElementFactory.getInstance(myManager.getProject()).createTagFromText("<" + localName + "/>");
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
final XmlElement element = getXmlElement();
assert element != null;
return getXmlTag().createChildTag(localName, tagName.getNamespace(element, getFile()), null, false);
}
use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.
the class PhysicalDomParentStrategy method strategyEquals.
public static boolean strategyEquals(DomParentStrategy strategy, final Object o) {
if (strategy == o)
return true;
if (!(o instanceof DomParentStrategy))
return false;
final XmlElement thatElement = ((DomParentStrategy) o).getXmlElement();
if (thatElement == null)
return false;
XmlElement element = strategy.getXmlElement();
if (element == null)
return false;
if (xmlElementsEqual(element, thatElement)) {
if (element != thatElement) {
final PsiElement nav1 = element.getNavigationElement();
final PsiElement nav2 = thatElement.getNavigationElement();
if (nav1 != nav2) {
PsiElement curContext = findIncluder(element);
PsiElement navContext = findIncluder(nav1);
LOG.error(LogMessageEx.createEvent("x:include processing error", "nav1,nav2=" + nav1 + ", " + nav2 + ";\n" + nav1.getContainingFile() + ":" + nav1.getTextRange().getStartOffset() + "!=" + nav2.getContainingFile() + ":" + nav2.getTextRange().getStartOffset() + ";\n" + (nav1 == element) + ";" + (nav2 == thatElement) + ";\n" + "contexts equal: " + (curContext == navContext) + ";\n" + "curContext?.physical=" + (curContext != null && curContext.isPhysical()) + ";\n" + "navContext?.physical=" + (navContext != null && navContext.isPhysical()) + ";\n" + "myElement.physical=" + element.isPhysical() + ";\n" + "thatElement.physical=" + thatElement.isPhysical() + "\n" + DebugUtil.currentStackTrace(), new Attachment("Including tag text 1.xml", curContext == null ? "null" : curContext.getText()), new Attachment("Including tag text 2.xml", navContext == null ? "null" : navContext.getText())));
throw new AssertionError();
}
}
return true;
}
return false;
}
use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.
the class XmlElementImpl method findElementByTokenType.
public XmlElement findElementByTokenType(final IElementType type) {
final XmlElement[] result = new XmlElement[1];
result[0] = null;
processElements(new PsiElementProcessor() {
@Override
public boolean execute(@NotNull PsiElement element) {
if (element instanceof TreeElement && ((ASTNode) element).getElementType() == type) {
result[0] = (XmlElement) element;
return false;
}
return true;
}
}, this);
return result[0];
}
Aggregations