public static <T extends DomElement, V> GenericAttributeValue<V> expectDomAttributeValue( @NotNull final PsiElement element, @NotNull final Class<? extends T> domTagClass, @NotNull final Function<T, GenericAttributeValue<V>> domGetter ) { final DomManager domManager = DomManager.getDomManager(element.getProject()); if (!(element instanceof XmlElement)) { return null; } final XmlAttribute xmlAttribute = PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false); if (xmlAttribute == null) { return null; } final XmlTag xmlParentTag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false); DomElement domParentTag = domManager.getDomElement(xmlParentTag); return Optional.ofNullable(domParentTag) .map(o -> ObjectUtils.tryCast(o, domTagClass)) .map(domGetter) .filter(val -> val == domManager.getDomElement(xmlAttribute)) .orElse(null); }
private void resolveModifier( final GenericAttributeValue<Boolean> attribute, final String methodName, final List<String> resultList ) { if (attribute == null) { return; } final Boolean value = BooleanUtils.toBooleanObject(attribute.getStringValue()); if (value == null) { return; } if (value) { resultList.add(methodName); } else { resultList.add(methodName + "(false)"); } }
private static Collection<XmlAttributeValue> findAlternativeDoms(@NotNull final ItemType source) { final String code = source.getCode().getStringValue(); if (StringUtil.isEmpty(code)) { return Collections.emptyList(); } final XmlElement element = source.getXmlElement(); final PsiFile psiFile = element == null ? null : element.getContainingFile(); if (psiFile == null) { return Collections.emptyList(); } final TSMetaModel externalModel = TSMetaModelAccess.getInstance(psiFile.getProject()). getExternalTypeSystemMeta(psiFile); return Optional.ofNullable(externalModel.findMetaClassForDom(source)) .map(TSMetaClass::retrieveAllDomsStream) .orElse(Stream.empty()) .filter(dom -> !dom.equals(source)) .map(ItemType::getCode) .map(GenericAttributeValue::getXmlAttributeValue) .collect(Collectors.toList()); }
/** * Returns the value of the name child. * * @return the value of the name child. */ @NotNull @Required //NOTE: We have to avoid @Convert since PsiField is in the read-only file and thus can't be renamed by platform //NOTE: Instead we are renaming the attribute value itself, see BeansRenamePsiElementProcessor //@Convert(soft = true, value = BeansPropertyNameConverter.class) GenericAttributeValue<String> getName();
public static PsiField resolveToPsiField(@NotNull final Property property, @Nullable final String name) { if (StringUtil.isEmptyOrSpaces(name)) { return null; } if (!(property.getParent() instanceof Bean)) { return null; } final Bean bean = (Bean) property.getParent(); final GenericAttributeValue<String> clazz = bean.getClazz(); if (!clazz.exists()) { return null; } final XmlAttributeValue xmlValue = clazz.getXmlAttributeValue(); if (xmlValue == null) { return null; } return Arrays.stream(xmlValue.getReferences()) .map(PsiReference::resolve) .map(o -> ObjectUtils.tryCast(o, PsiClass.class)) .filter(Objects::nonNull) .map(nextClass -> nextClass.findFieldByName(name, false)) .filter(Objects::nonNull) .findAny() .orElse(null); }
protected static <D extends DomElement, R> R useAttributeValue( @Nullable final D dom, @NotNull final Function<? super D, GenericAttributeValue<R>> attribute ) { return Optional.ofNullable(dom) .map(attribute) .map(GenericAttributeValue::getValue) .orElse(null); }
protected static <D extends DomElement> XmlAttributeValue navigateToValue( @Nullable final D dom, @NotNull final Function<? super D, GenericAttributeValue<?>> attribute ) { return Optional.ofNullable(dom) .map(attribute) .map(GenericAttributeValue::getXmlAttributeValue) .orElse(null); }
private static Collection<PsiElement> findAllExtendingXmlAttributes(@NotNull final ItemType source) { return getExtendingMetaClassNamesStream(source) .flatMap(TSMetaClass::retrieveAllDomsStream) .map(ItemType::getCode) .map(GenericAttributeValue::getXmlAttributeValue) .filter(Objects::nonNull) .collect(Collectors.toList()); }
@Nullable @Override public PsiElement getElement() { final GenericAttributeValue<String> codeAttr = myDomItemType.getCode(); return codeAttr == null ? null : codeAttr.getXmlAttributeValue(); }
private String resolveValue(final GenericAttributeValue<String> attributeValue) { if (attributeValue != null) { return attributeValue.getStringValue(); } return null; }
/** * Returns the value of the extends child. * <pre> * <h3>Attribute null:extends documentation</h3> * Defines the class which will be extended. Default is 'java.lang.Object'. * </pre> * * @return the value of the extends child. */ @NotNull @com.intellij.util.xml.Attribute("extends") GenericAttributeValue<String> getExtends();
/** * Returns the value of the scope child. * * @return the value of the scope child. */ @NotNull GenericAttributeValue<Scope> getScope();
/** * Returns the value of the extends child. * * @return the value of the extends child. */ @NotNull GenericAttributeValue<String> getExtends();
/** * Returns the value of the type child. * <pre> * <h3>Attribute null:type documentation</h3> * Defines the type of bean. Allowed are 'bean' or 'event'. * </pre> * * @return the value of the type child. */ @NotNull GenericAttributeValue<String> getType();
/** * Returns the value of the deprecated child. * <pre> * <h3>Attribute null:deprecated documentation</h3> * Marks bean as deprecated. Allows defining a message. * </pre> * * @return the value of the deprecated child. */ @NotNull GenericAttributeValue<String> getDeprecated();
/** * Returns the value of the abstract child. * * @return the value of the abstract child. */ @NotNull GenericAttributeValue<Boolean> getAbstract();
/** * Returns the value of the superEquals child. * * @return the value of the superEquals child. */ @NotNull GenericAttributeValue<Boolean> getSuperEquals();
/** * Returns the value of the class child. * * @return the value of the class child. */ @NotNull @Attribute("class") @Required GenericAttributeValue<String> getClazz();
/** * Returns the value of the template child. * * @return the value of the template child. */ @NotNull GenericAttributeValue<String> getTemplate();
/** * Returns the value of the type child. * * @return the value of the type child. */ @NotNull @Required GenericAttributeValue<String> getType();
/** * Returns the value of the code child. * <pre> * <h3>Attribute null:code documentation</h3> * The unique code of this element. * </pre> * * @return the value of the code child. */ @NotNull @com.intellij.util.xml.Attribute("code") @Required GenericAttributeValue<String> getCode();
/** * Returns the value of the deprecated child. * <pre> * <h3>Attribute null:deprecated documentation</h3> * Marks property as deprecated. Allows defining a message. * </pre> * * @return the value of the deprecated child. */ @NotNull GenericAttributeValue<String> getDeprecated();
/** * Returns the value of the static child. * * @return the value of the static child. */ @NotNull GenericAttributeValue<Boolean> getStatic();
/** * Returns the value of the redeclare child. * <pre> * <h3>Attribute null:redeclare documentation</h3> * Lets you re-define the attribute definition from an inherited type. In essence, you can use a different type of attribute as well as different modifier combinations than on the supertype. Default is 'false'. * </pre> * * @return the value of the redeclare child. */ @NotNull @com.intellij.util.xml.Attribute("redeclare") GenericAttributeValue<Boolean> getRedeclare();
/** * Returns the value of the qualifier child. * <pre> * <h3>Attribute null:qualifier documentation</h3> * Qualifier of this attribute. Attribute qualifiers must be unique across a single type. * </pre> * * @return the value of the qualifier child. */ @NotNull @com.intellij.util.xml.Attribute("qualifier") @Required GenericAttributeValue<String> getQualifier();
/** * Returns the value of the type child. * <pre> * <h3>Attribute null:type documentation</h3> * The type of the attribute, such as 'Product', 'int' or 'java.lang.String'. Primitive java types will be mapped to the corresponding atomic type. For example: 'int' will be mapped to the atomic type 'java.lang.Integer' with implicit default value. * </pre> * * @return the value of the type child. */ @NotNull @com.intellij.util.xml.Attribute("type") @Required @Convert(value = CompositeConverter.AnyClassifier.class, soft = true) GenericAttributeValue<String> getType();
/** * Returns the value of the metatype child. * <pre> * <h3>Attribute null:metatype documentation</h3> * Advanced setting. Specifies the metatype for the attributes definition. Must be a type extending AttributeDescriptor. Default is 'AttributeDescriptor'. * </pre> * * @return the value of the metatype child. */ @NotNull @com.intellij.util.xml.Attribute("metatype") GenericAttributeValue<String> getMetaType();
/** * Returns the value of the autocreate child. * <pre> * <h3>Attribute null:autocreate documentation</h3> * If 'true', the attribute descriptor will be created during initialization. Default is 'true'. * </pre> * * @return the value of the autocreate child. */ @NotNull @com.intellij.util.xml.Attribute("autocreate") GenericAttributeValue<Boolean> getAutoCreate();
/** * Returns the value of the generate child. * <pre> * <h3>Attribute null:generate documentation</h3> * If 'true', getter and setter methods for this attribute will be generated during a hybris Suite build. Default is 'true'. * </pre> * * @return the value of the generate child. */ @NotNull @com.intellij.util.xml.Attribute("generate") GenericAttributeValue<Boolean> getGenerate();
/** * Returns the value of the isSelectionOf child. * <pre> * <h3>Attribute null:isSelectionOf documentation</h3> * References an attribute of the same type. Only values of the referenced attribute can be selected as values for this attribute. Typical example: the default delivery address of a customer must be one of the addresses set for the customer. Default is 'false'. * </pre> * * @return the value of the isSelectionOf child. */ @NotNull @com.intellij.util.xml.Attribute("isSelectionOf") GenericAttributeValue<String> getIsSelectionOf();
/** * Returns the value of the name child. * <pre> * <h3>Attribute null:name documentation</h3> * The name of the custom property. * </pre> * * @return the value of the name child. */ @NotNull @com.intellij.util.xml.Attribute("name") @Required GenericAttributeValue<String> getName();
/** * Returns the value of the read child. * <pre> * <h3>Attribute null:read documentation</h3> * Defines if this attribute is readable (that is, if a getter method will be generated). Default is 'true'. The visibility of the getter depends on the value of the private attribute. * </pre> * * @return the value of the read child. */ @NotNull @com.intellij.util.xml.Attribute("read") GenericAttributeValue<Boolean> getRead();
/** * Returns the value of the write child. * <pre> * <h3>Attribute null:write documentation</h3> * Defines if this attribute is writable (that is, if a setter method will be generated). Default is 'true'. The visibility of the setter depends on the value of the private attribute. * </pre> * * @return the value of the write child. */ @NotNull @com.intellij.util.xml.Attribute("write") GenericAttributeValue<Boolean> getWrite();