01 package net.sourceforge.pmd.util.viewer.model;
02
03
04 import net.sourceforge.pmd.lang.ast.xpath.Attribute;
05
06
07 /**
08 * A toolkit for vaious attribute translations
09 *
10 * @author Boris Gruschko ( boris at gruschko.org )
11 * @version $Id: AttributeToolkit.java 6496 2008-09-18 09:17:50Z rgustav $
12 */
13
14 public class AttributeToolkit {
15
16 /**
17 * formats a value for its usage in XPath expressions
18 *
19 * @param attribute atribute which value should be formatted
20 * @return formmated value
21 */
22 public static String formatValueForXPath(Attribute attribute) {
23 return '\'' + attribute.getStringValue() + '\'';
24 }
25
26 /**
27 * constructs a predicate from the given attribute
28 *
29 * @param attribute attribute to be formatted as predicate
30 * @return predicate
31 */
32 public static String constructPredicate(Attribute attribute) {
33 return "[@" + attribute.getName() + '=' +
34 formatValueForXPath(attribute) + ']';
35 }
36 }
|