Project

Profile

Help

Revision 60b49097

Added by Michael Kay 8 months ago

Fix for bug #4693 - retain original text for patterns and use it in diagnostics

View differences:

latest10/hej/net/sf/saxon/lib/StandardDiagnostics.java
103 103
                kind = "parameter";
104 104
            } else if (loc instanceof GlobalVariable) {
105 105
                kind = "variable";
106
            } else if (loc instanceof Mode) {
107
                kind = "mode";
106 108
            }
107 109
            systemId = loc.getSystemId();
108 110
            lineNumber = loc.getLineNumber();
109 111
            nodeMessage = "at " + kind + " ";
110 112
            StructuredQName name = ((Actor) loc).getComponentName();
111 113
            if (name != null) {
112
                nodeMessage += name.toString();
114
                String n = name.toString();
115
                if (n.equals("xsl:unnamed")) {
116
                    n = "(unnamed)";
117
                }
118
                nodeMessage += n;
113 119
                nodeMessage += " ";
114 120
            }
115 121
        }
116 122
        if (lineNumber == -1) {
117 123
            lineNumber = loc.getLineNumber();
118 124
        }
119
        boolean containsLineNumber = lineNumber != -1;
125
        boolean containsLineNumber = lineNumber > 0;
120 126
        if (node != null && !containsLineNumber) {
121 127
            nodeMessage = "at " + Navigator.getPath(node) + ' ';
122 128
        }
latest10/hej/net/sf/saxon/pattern/AncestorQualifiedPattern.java
321 321
     * Get the original pattern text
322 322
     */
323 323
    @Override
324
    public String toString() {
324
    public String reconstruct() {
325 325
        return upperPattern + (upwardsAxis == AxisInfo.PARENT ? "/" : "//") + basePattern;
326 326
    }
327 327

  
......
372 372
        AncestorQualifiedPattern n = new AncestorQualifiedPattern(basePattern.copy(rebindings),
373 373
                                                                  upperPattern.copy(rebindings), upwardsAxis);
374 374
        ExpressionTool.copyLocationInfo(this, n);
375
        n.setOriginalText(getOriginalText());
375 376
        return n;
376 377
    }
377 378

  
latest10/hej/net/sf/saxon/pattern/AnchorPattern.java
108 108
        return AnyNodeTest.getInstance();
109 109
    }
110 110

  
111
    /*@NotNull*/
112
    public String toString() {
111
    @Override
112
    public String reconstruct() {
113 113
        return ".";
114 114
    }
115 115

  
latest10/hej/net/sf/saxon/pattern/BasePatternWithPredicate.java
262 262
     * Display the pattern for diagnostics
263 263
     */
264 264

  
265
    public String toString() {
265
    @Override
266
    public String reconstruct() {
266 267
        return getBasePattern() + "[" + getPredicate() + "]";
267 268
    }
268 269

  
......
285 286
        BasePatternWithPredicate n = new BasePatternWithPredicate(
286 287
                getBasePattern().copy(rebindings), getPredicate().copy(rebindings));
287 288
        ExpressionTool.copyLocationInfo(this, n);
289
        n.setOriginalText(getOriginalText());
288 290
        return n;
289 291
    }
290 292

  
latest10/hej/net/sf/saxon/pattern/BooleanExpressionPattern.java
180 180
     * Display the pattern for diagnostics
181 181
     */
182 182

  
183
    public String toString() {
183
    @Override
184
    public String reconstruct() {
184 185
        return ".[" + getPredicate() + "]";
185 186
    }
186 187

  
......
216 217
    public Pattern copy(RebindingMap rebindings) {
217 218
        BooleanExpressionPattern n = new BooleanExpressionPattern(getPredicate().copy(rebindings));
218 219
        ExpressionTool.copyLocationInfo(this, n);
220
        n.setOriginalText(getOriginalText());
219 221
        return n;
220 222
    }
221 223

  
latest10/hej/net/sf/saxon/pattern/ExceptPattern.java
165 165
    public Pattern copy(RebindingMap rebindings) {
166 166
        ExceptPattern n = new ExceptPattern(p1.copy(rebindings), p2.copy(rebindings));
167 167
        ExpressionTool.copyLocationInfo(this, n);
168
        n.setOriginalText(getOriginalText());
168 169
        return n;
169 170
    }
170 171

  
latest10/hej/net/sf/saxon/pattern/GeneralNodePattern.java
313 313
    public Pattern copy(RebindingMap rebindings) {
314 314
        GeneralNodePattern n = new GeneralNodePattern(equivalentExpr.copy(rebindings), itemType);
315 315
        ExpressionTool.copyLocationInfo(this, n);
316
        n.setOriginalText(getOriginalText());
316 317
        return n;
317 318
    }
318 319

  
latest10/hej/net/sf/saxon/pattern/GeneralPositionalPattern.java
361 361
    public Pattern copy(RebindingMap rebindings) {
362 362
        GeneralPositionalPattern n = new GeneralPositionalPattern(nodeTest.copy(), positionExpr.copy(rebindings));
363 363
        ExpressionTool.copyLocationInfo(this, n);
364
        n.setOriginalText(getOriginalText());
364 365
        return n;
365 366
    }
366 367

  
......
370 371
     * in legal pattern syntax.
371 372
     */
372 373
    @Override
373
    public String toString() {
374
    public String reconstruct() {
374 375
        return nodeTest + "[" + positionExpr + "]";
375 376
    }
376 377

  
latest10/hej/net/sf/saxon/pattern/IntersectPattern.java
165 165
    public Pattern copy(RebindingMap rebindings) {
166 166
        IntersectPattern n = new IntersectPattern(p1.copy(rebindings), p2.copy(rebindings));
167 167
        ExpressionTool.copyLocationInfo(this, n);
168
        n.setOriginalText(getOriginalText());
168 169
        return n;
169 170
    }
170 171

  
latest10/hej/net/sf/saxon/pattern/ItemTypePattern.java
77 77
     * Display the pattern for diagnostics
78 78
     */
79 79

  
80
    public String toString() {
80
    @Override
81
    public String reconstruct() {
81 82
        return itemType.toString();
82 83
    }
83 84

  
latest10/hej/net/sf/saxon/pattern/NodeSetPattern.java
252 252
    public Pattern copy(RebindingMap rebindings) {
253 253
        NodeSetPattern n = new NodeSetPattern(getSelectionExpression().copy(rebindings));
254 254
        ExpressionTool.copyLocationInfo(this, n);
255
        n.setOriginalText(getOriginalText());
255 256
        return n;
256 257
    }
257 258

  
latest10/hej/net/sf/saxon/pattern/NodeTestPattern.java
87 87
     * Display the pattern for diagnostics
88 88
     */
89 89

  
90
    public String toString() {
90
    @Override
91
    public String reconstruct() {
91 92
        return nodeTest.toString();
92 93
    }
93 94

  
94 95
    @Override
95 96
    public String toShortString() {
96
        return nodeTest.toShortString();
97
        if (getOriginalText() != null) {
98
            return getOriginalText();
99
        } else {
100
            return nodeTest.toShortString();
101
        }
97 102
    }
98 103

  
99 104
    /**
......
165 170
        NodeTestPattern n = new NodeTestPattern(nodeTest.copy());
166 171
        n.setPriority(getDefaultPriority());
167 172
        ExpressionTool.copyLocationInfo(this, n);
173
        n.setOriginalText(getOriginalText());
168 174
        return n;
169 175
    }
170 176

  
latest10/hej/net/sf/saxon/pattern/Pattern.java
35 35

  
36 36
    private double priority = 0.5;
37 37
    private boolean recoverable = true;
38
    private String originalText;
38 39

  
39 40
    /**
40 41
     * Static factory method to make a Pattern by parsing a String. <br>
......
129 130
     */
130 131

  
131 132
    public void setOriginalText(String text) {
132
        /*originalText = text;*/
133
        originalText = text;
133 134
    }
134 135

  
135 136
    /**
......
405 406
        return priority;
406 407
    }
407 408

  
409
    /**
410
     * Get the original text of the pattern, if known
411
     * @return the original text of the pattern as written; this may be null
412
     * in the case of a pattern constructed programmatically
413
     */
414

  
415
    public String getOriginalText() {
416
        return originalText;
417
    }
418

  
408 419
    /**
409 420
     * Get a string representation of the pattern. This will be in a form similar to the
410 421
     * original pattern text, but not necessarily identical. It is not guaranteed to be
......
412 423
     */
413 424

  
414 425
    public String toString() {
426
        if (originalText != null) {
427
            return originalText;
428
        } else {
429
            return reconstruct();
430

  
431
        }
432
    }
433

  
434
    /**
435
     * Reconstruct a string representation of the pattern in cases where the original
436
     * string is not available
437
     */
438

  
439
    public String reconstruct() {
415 440
        return "pattern matching " + getItemType();
416 441
    }
417 442

  
latest10/hej/net/sf/saxon/pattern/PatternParser30.java
131 131
            } catch (XPathException e) {
132 132
                pat = PatternMaker.fromExpression(exp.simplify(), env.getConfiguration(), true);
133 133
            }
134
            pat.setOriginalText(pattern);
134 135
            if (exp instanceof FilterExpression && ((FilterExpression)exp).getBase() instanceof ContextItemExpression) {
135 136
                if (allowSaxonExtensions && (pattern.startsWith("tuple") || pattern.startsWith("map") || pattern.startsWith("array") || pattern.startsWith("union"))) {
136 137
                    // no action, this is OK
latest10/hej/net/sf/saxon/pattern/PatternThatSetsCurrent.java
172 172
     * Get the original pattern text
173 173
     */
174 174
    @Override
175
    public String toString() {
175
    public String reconstruct() {
176 176
        return wrappedPattern.toString();
177 177
    }
178 178

  
......
247 247
        rebindings.put(binding, newCurrent);
248 248
        PatternThatSetsCurrent n = new PatternThatSetsCurrent(wrappedPattern.copy(rebindings), newCurrent);
249 249
        ExpressionTool.copyLocationInfo(this, n);
250
        n.setOriginalText(getOriginalText());
250 251
        return n;
251 252
    }
252 253

  
latest10/hej/net/sf/saxon/pattern/SimplePositionalPattern.java
176 176
    public Pattern copy(RebindingMap rebindings) {
177 177
        SimplePositionalPattern n = new SimplePositionalPattern(nodeTest.copy(), position);
178 178
        ExpressionTool.copyLocationInfo(this, n);
179
        n.setOriginalText(getOriginalText());
179 180
        return n;
180 181
    }
181 182

  
......
183 184
     * Get the original pattern text
184 185
     */
185 186
    @Override
186
    public String toString() {
187
    public String reconstruct() {
187 188
        return nodeTest + "[" + position + "]";
188 189
    }
189 190

  
latest10/hej/net/sf/saxon/pattern/StreamingFunctionArgumentPattern.java
93 93
        return AnyNodeTest.getInstance();
94 94
    }
95 95

  
96
    /*@NotNull*/
97
    public String toString() {
96
    @Override
97
    public String reconstruct() {
98 98
        return "$$";
99 99
    }
100 100

  
latest10/hej/net/sf/saxon/pattern/UnionPattern.java
157 157
    public Pattern copy(RebindingMap rebindings) {
158 158
        UnionPattern n = new UnionPattern(p1.copy(rebindings), p2.copy(rebindings));
159 159
        ExpressionTool.copyLocationInfo(this, n);
160
        n.setOriginalText(getOriginalText());
160 161
        return n;
161 162
    }
162 163

  
latest10/hej/net/sf/saxon/pattern/UniversalPattern.java
80 80
     * Display the pattern for diagnostics
81 81
     */
82 82

  
83
    public String toString() {
83
    @Override
84
    public String reconstruct() {
84 85
        return ".";
85 86
    }
86 87

  
latest10/hej/net/sf/saxon/pattern/VennPattern.java
234 234
    protected abstract String getOperatorName();
235 235

  
236 236
    /**
237
     * Get the original pattern text
237
     * Get the pattern text for diagnostics
238 238
     */
239 239
    @Override
240
    public String toString() {
240
    public String reconstruct() {
241 241
        return p1 + " " + getOperatorName() + " " + p2;
242 242
    }
243 243

  
latest10/hej/net/sf/saxon/style/StyleElement.java
717 717
        try {
718 718
            StaticContext env = getStaticContext(new StructuredQName("", "", attributeName));
719 719
            Pattern p = Pattern.make(pattern, env, getCompilation().getPackageData());
720
            p.setOriginalText(pattern);
720 721
            p.setLocation(allocateLocation());
721 722
            return p;
722 723
        } catch (XPathException err) {

Also available in: Unified diff