use of com.intellij.util.xml.reflect.AbstractDomChildrenDescription in project intellij-community by JetBrains.
the class DomAnchorImpl method createAnchor.
public static <T extends DomElement> DomAnchor<T> createAnchor(@NotNull T t, boolean usePsi) {
DomInvocationHandler handler = DomManagerImpl.getNotNullHandler(t);
if (handler.getStub() != null) {
return new StubAnchor<>(handler);
}
if (usePsi) {
final XmlElement element = t.getXmlElement();
if (element != null) {
return new PsiBasedDomAnchor<>(PsiAnchor.create(element), element.getProject());
}
}
final DomElement parent = t.getParent();
if (parent == null) {
LOG.error("Parent null: " + t);
}
if (parent instanceof DomFileElementImpl) {
final DomFileElementImpl fileElement = (DomFileElementImpl) parent;
//noinspection unchecked
return new RootAnchor<>(fileElement.getFile(), fileElement.getRootElementClass());
}
final DomAnchor<DomElement> parentAnchor = createAnchor(parent);
final String name = t.getGenericInfo().getElementName(t);
final AbstractDomChildrenDescription description = t.getChildDescription();
final List<? extends DomElement> values = description.getValues(parent);
if (name != null) {
int i = 0;
for (DomElement value : values) {
if (value.equals(t)) {
return new NamedAnchor<>(parentAnchor, description, name, i);
}
if (name.equals(value.getGenericInfo().getElementName(value))) {
i++;
}
}
}
final int index = values.indexOf(t);
if (index < 0) {
diagnoseNegativeIndex2(t, parent, description, values);
}
return new IndexedAnchor<>(parentAnchor, description, index);
}
use of com.intellij.util.xml.reflect.AbstractDomChildrenDescription in project intellij-community by JetBrains.
the class BasicDomElementComponent method bindProperties.
protected final void bindProperties(final DomElement domElement) {
if (domElement == null)
return;
DomElementAnnotationsManager.getInstance(domElement.getManager().getProject()).addHighlightingListener(new DomElementAnnotationsManager.DomHighlightingListener() {
@Override
public void highlightingFinished(@NotNull final DomFileElement element) {
ApplicationManager.getApplication().invokeLater(() -> {
if (getComponent().isShowing() && element.isValid()) {
updateHighlighting();
}
});
}
}, this);
for (final AbstractDomChildrenDescription description : domElement.getGenericInfo().getChildrenDescriptions()) {
final JComponent boundComponent = getBoundComponent(description);
if (boundComponent != null) {
if (description instanceof DomFixedChildDescription && DomUtil.isGenericValueType(description.getType())) {
if ((description.getValues(domElement)).size() == 1) {
final GenericDomValue element = domElement.getManager().createStableValue(() -> domElement.isValid() ? (GenericDomValue) description.getValues(domElement).get(0) : null);
doBind(DomUIFactory.createControl(element, commitOnEveryChange(element)), boundComponent);
} else {
//todo not bound
}
} else if (description instanceof DomCollectionChildDescription) {
doBind(DomUIFactory.getDomUIFactory().createCollectionControl(domElement, (DomCollectionChildDescription) description), boundComponent);
}
}
}
reset();
}
use of com.intellij.util.xml.reflect.AbstractDomChildrenDescription in project intellij-community by JetBrains.
the class DomStubBuilderVisitor method visitXmlElement.
void visitXmlElement(XmlElement element, ElementStub parent, int index) {
DomInvocationHandler handler = myManager.getDomHandler(element);
if (handler == null || handler.getAnnotation(Stubbed.class) == null && !handler.getChildDescription().isStubbed())
return;
AbstractDomChildrenDescription description = handler.getChildDescription();
String nsKey = description instanceof DomChildrenDescription ? ((DomChildrenDescription) description).getXmlName().getNamespaceKey() : "";
if (element instanceof XmlTag) {
XmlTag tag = (XmlTag) element;
String elementClass = null;
if (handler.getAnnotation(StubbedOccurrence.class) != null) {
final Type type = description.getType();
elementClass = ((Class) type).getName();
}
ElementStub stub = new ElementStub(parent, StringRef.fromString(tag.getName()), StringRef.fromNullableString(nsKey), index, description instanceof CustomDomChildrenDescription, elementClass == null ? null : StringRef.fromNullableString(elementClass), tag.getSubTags().length == 0 ? tag.getValue().getTrimmedText() : "");
for (XmlAttribute attribute : tag.getAttributes()) {
visitXmlElement(attribute, stub, 0);
}
Map<String, Integer> indices = new HashMap<>();
for (final XmlTag subTag : tag.getSubTags()) {
String name = subTag.getName();
Integer i = indices.get(name);
i = i == null ? 0 : i + 1;
visitXmlElement(subTag, stub, i);
indices.put(name, i);
}
} else if (element instanceof XmlAttribute) {
new AttributeStub(parent, StringRef.fromString(((XmlAttribute) element).getLocalName()), StringRef.fromNullableString(nsKey), ((XmlAttribute) element).getValue());
}
}
use of com.intellij.util.xml.reflect.AbstractDomChildrenDescription 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.util.xml.reflect.AbstractDomChildrenDescription in project intellij-community by JetBrains.
the class DomGenericInfoEx method findChildrenDescription.
@Nullable
public final AbstractDomChildrenDescription findChildrenDescription(DomInvocationHandler handler, final String localName, String namespace, boolean attribute, final String qName) {
for (final AbstractDomChildrenDescription description : getChildrenDescriptions()) {
if (description instanceof DomChildDescriptionImpl && description instanceof AttributeChildDescriptionImpl == attribute) {
final XmlName xmlName = ((DomChildDescriptionImpl) description).getXmlName();
if (attribute && StringUtil.isEmpty(namespace) && xmlName.getLocalName().equals(localName))
return description;
final EvaluatedXmlName evaluatedXmlName = handler.createEvaluatedXmlName(xmlName);
if (DomImplUtil.isNameSuitable(evaluatedXmlName, localName, qName, namespace, handler.getFile())) {
return description;
}
}
}
List<? extends CustomDomChildrenDescription> list = getCustomNameChildrenDescription();
for (CustomDomChildrenDescription description : list) {
if (attribute) {
// todo
} else if (description.getTagNameDescriptor() != null) {
return description;
}
}
return null;
}
Aggregations