use of com.intellij.util.xml.reflect.DomGenericInfo in project intellij-community by JetBrains.
the class DomBasicsTest method testChildrenReflection.
public void testChildrenReflection() throws Throwable {
final MyElement element = createElement("<a><child/><child-element/><child-element/></a>");
final DomGenericInfo info = element.getGenericInfo();
final DomFixedChildDescription foo = info.getFixedChildDescription("foo");
assertFixedChildDescription(foo, element.getFoo(), "foo");
final DomFixedChildDescription child = info.getFixedChildDescription("child");
assertFixedChildDescription(child, element.getChild(), "child");
final DomFixedChildDescription genericChild = info.getFixedChildDescription("generic-value");
assertGenericChildDescription(genericChild, element.getGenericValue(), "generic-value");
final DomCollectionChildDescription collectionChild = info.getCollectionChildDescription("child-element");
assertEquals(element.getChildElements(), collectionChild.getValues(element));
assertEquals("child-element", collectionChild.getXmlElementName());
assertEquals(MyElement.class, collectionChild.getType());
assertEquals(MyElement.class.getMethod("getChildElements"), collectionChild.getGetterMethod().getMethod());
assertEquals(new HashSet(Arrays.asList(foo, child, collectionChild, genericChild, info.getAttributeChildrenDescriptions().get(0))), new HashSet(info.getChildrenDescriptions()));
}
use of com.intellij.util.xml.reflect.DomGenericInfo in project intellij-community by JetBrains.
the class DomNamespacesTest method testFindChildDescriptionWithoutNamespace.
public void testFindChildDescriptionWithoutNamespace() throws Throwable {
final DomGenericInfo info = getDomManager().getGenericInfo(MyListOrSet.class);
assertNotNull(info.getAttributeChildDescription("attr"));
assertNotNull(info.getAttributeChildDescription("attr").getType());
assertNotNull(info.getCollectionChildDescription("child"));
assertNotNull(info.getCollectionChildDescription("child").getType());
assertNotNull(info.getFixedChildDescription("ref"));
assertNotNull(info.getFixedChildDescription("ref").getType());
}
use of com.intellij.util.xml.reflect.DomGenericInfo in project intellij-community by JetBrains.
the class ResolvingElementQuickFix method getChildDescription.
@Nullable
public static <T extends DomElement> DomCollectionChildDescription getChildDescription(final List<DomElement> contexts, Class<T> clazz) {
if (contexts.size() == 0) {
return null;
}
final DomElement context = contexts.get(0);
final DomGenericInfo genericInfo = context.getGenericInfo();
final List<? extends DomCollectionChildDescription> descriptions = genericInfo.getCollectionChildrenDescriptions();
for (DomCollectionChildDescription description : descriptions) {
final Type type = description.getType();
if (type.equals(clazz)) {
return description;
}
}
return null;
}
use of com.intellij.util.xml.reflect.DomGenericInfo in project intellij-community by JetBrains.
the class DomBasicsTest method testAddChildrenByReflection.
public void testAddChildrenByReflection() throws Throwable {
final MyElement element = createElement("<a><child-element/></a>");
final DomGenericInfo info = element.getGenericInfo();
final DomCollectionChildDescription collectionChild = info.getCollectionChildDescription("child-element");
final List<? extends DomElement> values = collectionChild.getValues(element);
MyElement newChild = (MyElement) collectionChild.addValue(element);
List<DomElement> newChildren = Arrays.asList(values.get(0), newChild);
assertEquals(newChildren, element.getChildElements());
assertEquals(newChildren, collectionChild.getValues(element));
MyElement lastChild = (MyElement) collectionChild.addValue(element, 0);
newChildren = Arrays.asList(lastChild, values.get(0), newChild);
assertEquals(newChildren, element.getChildElements());
assertEquals(newChildren, collectionChild.getValues(element));
}
use of com.intellij.util.xml.reflect.DomGenericInfo 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();
}
Aggregations