@Override public PropertyDescriptor<?> getPropertyDescriptor(String name) { for (PropertyDescriptor<?> propertyDescriptor : propertyDescriptors) { if (name.equals(propertyDescriptor.name())) { return propertyDescriptor; } } return null; }
@Override String kindDisplayName(ASTMethodDeclaration node, PropertyDescriptor<Pattern> descriptor) { return DESCRIPTOR_TO_DISPLAY_NAME.get(descriptor.name()); } }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (obj instanceof PropertyDescriptor) { return name.equals(((PropertyDescriptor<?>) obj).name()); } return false; }
@Override public void definePropertyDescriptor(PropertyDescriptor<?> propertyDescriptor) { // Check to ensure the property does not already exist. if (getPropertyDescriptor(propertyDescriptor.name()) != null) { throw new IllegalArgumentException("There is already a PropertyDescriptor with name '" + propertyDescriptor.name() + "' defined on " + getPropertySourceType() + " " + getName() + "."); } propertyDescriptors.add(propertyDescriptor); // Sort in UI order Collections.sort(propertyDescriptors); }
private void commentRequiredViolation(Object data, AbstractJavaNode node, PropertyDescriptor<CommentRequirement> descriptor) { addViolationWithMessage(data, node, DESCRIPTOR_NAME_TO_COMMENT_TYPE.get(descriptor.name()) + " are " + getProperty(descriptor).label.toLowerCase(Locale.ROOT)); }
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; }
private BaseXPath createXPath(final String xpathQueryString, final Navigator navigator) throws JaxenException { final BaseXPath xpath = new BaseXPath(xpathQueryString, navigator); if (properties.size() > 1) { final SimpleVariableContext vc = new SimpleVariableContext(); for (Entry<PropertyDescriptor<?>, Object> e : properties.entrySet()) { final String propName = e.getKey().name(); if (!"xpath".equals(propName)) { final Object value = e.getValue(); vc.setVariableValue(propName, value != null ? value.toString() : null); } } xpath.setVariableContext(vc); } return xpath; } }
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(); }
/** * Attempt to create a dynamic context on which to evaluate the {@link #xpathExpression}. * * @param elementNode the node on which to create the context; generally this node is the root node of the Saxon * Tree * @return the dynamic context on which to run the query * @throws XPathException if the supplied value does not conform to the required type of the * variable, when setting up the dynamic context; or if the supplied value contains a node that does not belong to * this Configuration (or another Configuration that shares the same namePool) */ private XPathDynamicContext createDynamicContext(final ElementNode elementNode) throws XPathException { final XPathDynamicContext dynamicContext = xpathExpression.createDynamicContext(elementNode); // Set variable values on the dynamic context for (final XPathVariable xpathVariable : xpathVariables) { final String variableName = xpathVariable.getVariableQName().getLocalName(); for (final Map.Entry<PropertyDescriptor<?>, Object> entry : super.properties.entrySet()) { if (variableName.equals(entry.getKey().name())) { final ValueRepresentation valueRepresentation = getRepresentation(entry.getKey(), entry.getValue()); dynamicContext.setVariable(xpathVariable, valueRepresentation); } } } return dynamicContext; }
String value = properties.getProperty(prop.name()); if (value != null) { @SuppressWarnings("unchecked")
final String name = propertyDescriptor.name(); if (!"xpath".equals(name)) { final XPathVariable xpathVariable = xpathStaticContext.declareVariable(null, name);
String propertyName = property.name().replaceAll("\\_", "\\\\_"); if (INTERNAL_DEV_PROPERTIES.contains(propertyName)) { continue;
lines.add("|" + EscapeUtils.escapeMarkdown(StringEscapeUtils.escapeHtml4(propertyDescriptor.name())) + "|" + EscapeUtils.escapeMarkdown(StringEscapeUtils.escapeHtml4(defaultValue)) + "|" + EscapeUtils.escapeMarkdown((isDeprecated ? DEPRECATION_LABEL_SMALL : "")
for (final PropertyDescriptor<?> prop : getPropertyDescriptors()) { if (rule.getPropertyDescriptor(prop.name()) == null) {
@Override String kindDisplayName(ASTMethodDeclaration node, PropertyDescriptor<Pattern> descriptor) { return DESCRIPTOR_TO_DISPLAY_NAME.get(descriptor.name()); } }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (obj instanceof PropertyDescriptor) { return name.equals(((PropertyDescriptor<?>) obj).name()); } return false; }
@Override public PropertyDescriptor<?> getPropertyDescriptor(String name) { for (PropertyDescriptor<?> propertyDescriptor : propertyDescriptors) { if (name.equals(propertyDescriptor.name())) { return propertyDescriptor; } } return null; }
@Override public void definePropertyDescriptor(PropertyDescriptor<?> propertyDescriptor) { // Check to ensure the property does not already exist. if (getPropertyDescriptor(propertyDescriptor.name()) != null) { throw new IllegalArgumentException("There is already a PropertyDescriptor with name '" + propertyDescriptor.name() + "' defined on " + getPropertySourceType() + " " + getName() + "."); } propertyDescriptors.add(propertyDescriptor); // Sort in UI order Collections.sort(propertyDescriptors); }
private void commentRequiredViolation(Object data, AbstractJavaNode node, PropertyDescriptor<CommentRequirement> descriptor) { addViolationWithMessage(data, node, DESCRIPTOR_NAME_TO_COMMENT_TYPE.get(descriptor.name()) + " are " + getProperty(descriptor).label.toLowerCase(Locale.ROOT)); }
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; }