private Element createPropertyDefinitionElementBR(PropertyDescriptor<?> propertyDescriptor) { final Element propertyElement = createPropertyValueElement(propertyDescriptor, propertyDescriptor.defaultValue()); propertyElement.setAttribute(PropertyDescriptorField.TYPE.attributeName(), PropertyTypeId.typeIdFor(propertyDescriptor.type(), propertyDescriptor.isMultiValue())); Map<PropertyDescriptorField, String> propertyValuesById = propertyDescriptor.attributeValuesById(); for (Map.Entry<PropertyDescriptorField, String> entry : propertyValuesById.entrySet()) { propertyElement.setAttribute(entry.getKey().attributeName(), entry.getValue()); } return propertyElement; }
@Override public PropertyDescriptor<?> getPropertyDescriptor(String name) { for (PropertyDescriptor<?> propertyDescriptor : propertyDescriptors) { if (name.equals(propertyDescriptor.name())) { return propertyDescriptor; } } return null; }
private static String getReports() { StringBuilder buf = new StringBuilder(); for (String reportName : RendererFactory.REPORT_FORMAT_TO_RENDERER.keySet()) { Renderer renderer = RendererFactory.createRenderer(reportName, new Properties()); buf.append(" ").append(reportName).append(": "); if (!reportName.equals(renderer.getName())) { buf.append(" Deprecated alias for '" + renderer.getName()).append(PMD.EOL); continue; } buf.append(renderer.getDescription()).append(PMD.EOL); for (PropertyDescriptor<?> property : renderer.getPropertyDescriptors()) { buf.append(" ").append(property.name()).append(" - "); buf.append(property.description()); Object deflt = property.defaultValue(); if (deflt != null) { buf.append(" default: ").append(deflt); } buf.append(PMD.EOL); } } return buf.toString(); }
private Element createPropertyValueElement(PropertyDescriptor propertyDescriptor, Object value) { Element propertyElement = document.createElementNS(RULESET_2_0_0_NS_URI, "property"); propertyElement.setAttribute("name", propertyDescriptor.name()); String valueString = propertyDescriptor.asDelimitedString(value); if (XPathRule.XPATH_DESCRIPTOR.equals(propertyDescriptor)) { Element valueElement = createCDATASectionElement("value", valueString); propertyElement.appendChild(valueElement); } else { propertyElement.setAttribute("value", valueString); } return propertyElement; }
lines.add("|----|-------------|-----------|-----------|"); for (PropertyDescriptor<?> propertyDescriptor : properties) { String description = propertyDescriptor.description(); boolean isDeprecated = false; if (description != null && description.toLowerCase(Locale.ROOT) if (propertyDescriptor.defaultValue() != null) { if (propertyDescriptor.isMultiValue()) { @SuppressWarnings("unchecked") // multi valued properties are using a List MultiValuePropertyDescriptor<List<?>> multiPropertyDescriptor = (MultiValuePropertyDescriptor<List<?>>) propertyDescriptor; " " + multiPropertyDescriptor.multiValueDelimiter() + " "); } else { defaultValue = String.valueOf(propertyDescriptor.defaultValue()); if (propertyDescriptor.isMultiValue()) { MultiValuePropertyDescriptor<?> multiValuePropertyDescriptor = (MultiValuePropertyDescriptor<?>) propertyDescriptor; lines.add("|" + EscapeUtils.escapeMarkdown(StringEscapeUtils.escapeHtml4(propertyDescriptor.name())) + "|" + EscapeUtils.escapeMarkdown(StringEscapeUtils.escapeHtml4(defaultValue)) + "|" + EscapeUtils.escapeMarkdown((isDeprecated ? DEPRECATION_LABEL_SMALL : "")
@Override public <T> T getProperty(PropertyDescriptor<T> propertyDescriptor) { checkValidPropertyDescriptor(propertyDescriptor); T result = propertyDescriptor.defaultValue(); if (propertyValuesByDescriptor.containsKey(propertyDescriptor)) { @SuppressWarnings("unchecked") T value = (T) propertyValuesByDescriptor.get(propertyDescriptor); result = value; } return result; }
String propertyName = property.name().replaceAll("\\_", "\\\\_"); if (INTERNAL_DEV_PROPERTIES.contains(propertyName)) { continue; PropertyDescriptor<T> typed = (PropertyDescriptor<T>) property; T value = rule.getProperty(typed); String propertyValue = typed.asDelimitedString(value); if (propertyValue == null) { propertyValue = ""; result += propertyName + " | " + propertyValue + " | " + property.description() + "\\n";
if (propertyDescriptor.isDefinedExternally()) { if (propertiesByPropertyDescriptor != null) { Object defaultValue = propertyDescriptor.defaultValue(); Object value = propertiesByPropertyDescriptor.get(propertyDescriptor); if (value != defaultValue && (value == null || !value.equals(defaultValue))) { Object defaultValue = propertyDescriptor.defaultValue(); Object value = entry.getValue(); if (value != defaultValue && (value == null || !value.equals(defaultValue))) {
private <T> void setRulePropertyCapture(Rule rule, PropertyDescriptor<T> descriptor, String value) { rule.setProperty(descriptor, descriptor.valueFrom(value)); }
private ValueRepresentation getRepresentation(final PropertyDescriptor<?> descriptor, final Object value) { if (descriptor.isMultiValue()) { final List<?> val = (List<?>) value; if (val.isEmpty()) { return EmptySequence.getInstance(); } final Item[] converted = new Item[val.size()]; for (int i = 0; i < val.size(); i++) { converted[i] = getAtomicRepresentation(val.get(i)); } return new SequenceExtent(converted); } else { return getAtomicRepresentation(value); } }
Object value2 = rule2.getProperty(propertyDescriptors2.get(j)); if (propertyDescriptors1.get(j).type() == Pattern.class) { value1 = ((Pattern) value1).pattern(); value2 = ((Pattern) value2).pattern();
private <T> String errorForPropCapture(PropertyDescriptor<T> descriptor) { return descriptor.errorFor(getProperty(descriptor)); } }
@Override public Map<PropertyDescriptor<?>, Object> getPropertiesByPropertyDescriptor() { if (propertyDescriptors.isEmpty()) { return Collections.emptyMap(); } Map<PropertyDescriptor<?>, Object> propertiesByPropertyDescriptor = new HashMap<>(propertyDescriptors.size()); // Fill with existing explicitly values propertiesByPropertyDescriptor.putAll(this.propertyValuesByDescriptor); // Add default values for anything not yet set for (PropertyDescriptor<?> propertyDescriptor : this.propertyDescriptors) { if (!propertiesByPropertyDescriptor.containsKey(propertyDescriptor)) { propertiesByPropertyDescriptor.put(propertyDescriptor, propertyDescriptor.defaultValue()); } } return Collections.unmodifiableMap(propertiesByPropertyDescriptor); }
String propertyName = property.name().replaceAll("\\_", "\\\\_"); if (INTERNAL_DEV_PROPERTIES.contains(propertyName)) { continue; PropertyDescriptor<T> typed = (PropertyDescriptor<T>) property; T value = rule.getProperty(typed); String propertyValue = typed.asDelimitedString(value); if (propertyValue == null) { propertyValue = ""; result += propertyName + " | " + propertyValue + " | " + property.description() + "\\n";
private Element createPropertyValueElement(PropertyDescriptor propertyDescriptor, Object value) { Element propertyElement = document.createElementNS(RULESET_2_0_0_NS_URI, "property"); propertyElement.setAttribute("name", propertyDescriptor.name()); String valueString = propertyDescriptor.asDelimitedString(value); if (XPathRule.XPATH_DESCRIPTOR.equals(propertyDescriptor)) { Element valueElement = createCDATASectionElement("value", valueString); propertyElement.appendChild(valueElement); } else { propertyElement.setAttribute("value", valueString); } return propertyElement; }
if (propertyDescriptor.isDefinedExternally()) { if (propertiesByPropertyDescriptor != null) { Object defaultValue = propertyDescriptor.defaultValue(); Object value = propertiesByPropertyDescriptor.get(propertyDescriptor); if (value != defaultValue && (value == null || !value.equals(defaultValue))) { Object defaultValue = propertyDescriptor.defaultValue(); Object value = entry.getValue(); if (value != defaultValue && (value == null || !value.equals(defaultValue))) {
Object value = propertyDescriptor.valueFrom((String) entry.getValue()); rule.setProperty(propertyDescriptor, value);
private ValueRepresentation getRepresentation(final PropertyDescriptor<?> descriptor, final Object value) { if (descriptor.isMultiValue()) { final List<?> val = (List<?>) value; if (val.isEmpty()) { return EmptySequence.getInstance(); } final Item[] converted = new Item[val.size()]; for (int i = 0; i < val.size(); i++) { converted[i] = getAtomicRepresentation(val.get(i)); } return new SequenceExtent(converted); } else { return getAtomicRepresentation(value); } }