1 /* |
1 /* |
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
|
3 * @LastModified: Oct 2017 |
3 */ |
4 */ |
4 /* |
5 /* |
5 * Licensed to the Apache Software Foundation (ASF) under one or more |
6 * Licensed to the Apache Software Foundation (ASF) under one or more |
6 * contributor license agreements. See the NOTICE file distributed with |
7 * contributor license agreements. See the NOTICE file distributed with |
7 * this work for additional information regarding copyright ownership. |
8 * this work for additional information regarding copyright ownership. |
26 import com.sun.org.apache.bcel.internal.generic.GOTO_W; |
27 import com.sun.org.apache.bcel.internal.generic.GOTO_W; |
27 import com.sun.org.apache.bcel.internal.generic.InstructionHandle; |
28 import com.sun.org.apache.bcel.internal.generic.InstructionHandle; |
28 import com.sun.org.apache.bcel.internal.generic.InstructionList; |
29 import com.sun.org.apache.bcel.internal.generic.InstructionList; |
29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; |
30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; |
30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; |
31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; |
31 import java.util.Dictionary; |
32 import java.util.ArrayList; |
|
33 import java.util.List; |
32 import java.util.Map; |
34 import java.util.Map; |
33 import java.util.Vector; |
|
34 |
35 |
35 /** |
36 /** |
36 * A test sequence is a sequence of patterns that |
37 * A test sequence is a sequence of patterns that |
37 * |
38 * |
38 * (1) occured in templates in the same mode |
39 * (1) occured in templates in the same mode |
54 * Integer code for the kernel type of this test sequence |
55 * Integer code for the kernel type of this test sequence |
55 */ |
56 */ |
56 private int _kernelType; |
57 private int _kernelType; |
57 |
58 |
58 /** |
59 /** |
59 * Vector of all patterns in the test sequence. May include |
60 * ArrayList of all patterns in the test sequence. May include |
60 * patterns with "*", "@*" or "node()" kernel. |
61 * patterns with "*", "@*" or "node()" kernel. |
61 */ |
62 */ |
62 private Vector _patterns = null; |
63 private List<LocationPathPattern> _patterns = null; |
63 |
64 |
64 /** |
65 /** |
65 * A reference to the Mode object. |
66 * A reference to the Mode object. |
66 */ |
67 */ |
67 private Mode _mode = null; |
68 private Mode _mode = null; |
82 private InstructionHandle _start = null; |
83 private InstructionHandle _start = null; |
83 |
84 |
84 /** |
85 /** |
85 * Creates a new test sequence given a set of patterns and a mode. |
86 * Creates a new test sequence given a set of patterns and a mode. |
86 */ |
87 */ |
87 public TestSeq(Vector patterns, Mode mode) { |
88 public TestSeq(List<LocationPathPattern> patterns, Mode mode) { |
88 this(patterns, -2, mode); |
89 this(patterns, -2, mode); |
89 } |
90 } |
90 |
91 |
91 public TestSeq(Vector patterns, int kernelType, Mode mode) { |
92 public TestSeq(List<LocationPathPattern> patterns, int kernelType, Mode mode) { |
92 _patterns = patterns; |
93 _patterns = patterns; |
93 _kernelType = kernelType; |
94 _kernelType = kernelType; |
94 _mode = mode; |
95 _mode = mode; |
95 } |
96 } |
96 |
97 |
102 public String toString() { |
103 public String toString() { |
103 final int count = _patterns.size(); |
104 final int count = _patterns.size(); |
104 final StringBuffer result = new StringBuffer(); |
105 final StringBuffer result = new StringBuffer(); |
105 |
106 |
106 for (int i = 0; i < count; i++) { |
107 for (int i = 0; i < count; i++) { |
107 final LocationPathPattern pattern = |
108 final LocationPathPattern pattern = _patterns.get(i); |
108 (LocationPathPattern) _patterns.elementAt(i); |
|
109 |
109 |
110 if (i == 0) { |
110 if (i == 0) { |
111 result.append("Testseq for kernel ").append(_kernelType) |
111 result.append("Testseq for kernel ").append(_kernelType) |
112 .append('\n'); |
112 .append('\n'); |
113 } |
113 } |
129 * Return the highest priority for a pattern in this test |
129 * Return the highest priority for a pattern in this test |
130 * sequence. This is either the priority of the first or |
130 * sequence. This is either the priority of the first or |
131 * of the default pattern. |
131 * of the default pattern. |
132 */ |
132 */ |
133 public double getPriority() { |
133 public double getPriority() { |
134 final Template template = (_patterns.size() == 0) ? _default |
134 final Template template = (_patterns.isEmpty()) ? _default |
135 : ((Pattern) _patterns.elementAt(0)).getTemplate(); |
135 : ((Pattern) _patterns.get(0)).getTemplate(); |
136 return template.getPriority(); |
136 return template.getPriority(); |
137 } |
137 } |
138 |
138 |
139 /** |
139 /** |
140 * Returns the position of the highest priority pattern in |
140 * Returns the position of the highest priority pattern in |
141 * this test sequence. |
141 * this test sequence. |
142 */ |
142 */ |
143 public int getPosition() { |
143 public int getPosition() { |
144 final Template template = (_patterns.size() == 0) ? _default |
144 final Template template = (_patterns.isEmpty()) ? _default |
145 : ((Pattern) _patterns.elementAt(0)).getTemplate(); |
145 : ((Pattern) _patterns.get(0)).getTemplate(); |
146 return template.getPosition(); |
146 return template.getPosition(); |
147 } |
147 } |
148 |
148 |
149 /** |
149 /** |
150 * Reduce the patterns in this test sequence. Creates a new |
150 * Reduce the patterns in this test sequence. Creates a new |
151 * vector of patterns and sets the default pattern if it |
151 * vector of patterns and sets the default pattern if it |
152 * finds a patterns that is fully reduced. |
152 * finds a patterns that is fully reduced. |
153 */ |
153 */ |
154 public void reduce() { |
154 public void reduce() { |
155 final Vector newPatterns = new Vector(); |
155 final List<LocationPathPattern> newPatterns = new ArrayList<>(); |
156 |
156 |
157 final int count = _patterns.size(); |
157 for (LocationPathPattern pattern : _patterns) { |
158 for (int i = 0; i < count; i++) { |
|
159 final LocationPathPattern pattern = |
|
160 (LocationPathPattern)_patterns.elementAt(i); |
|
161 |
|
162 // Reduce this pattern |
158 // Reduce this pattern |
163 pattern.reduceKernelPattern(); |
159 pattern.reduceKernelPattern(); |
164 |
160 |
165 // Is this pattern fully reduced? |
161 // Is this pattern fully reduced? |
166 if (pattern.isWildcard()) { |
162 if (pattern.isWildcard()) { |
167 _default = pattern.getTemplate(); |
163 _default = pattern.getTemplate(); |
168 break; // Ignore following patterns |
164 break; // Ignore following patterns |
169 } |
165 } |
170 else { |
166 else { |
171 newPatterns.addElement(pattern); |
167 newPatterns.add(pattern); |
172 } |
168 } |
173 } |
169 } |
174 _patterns = newPatterns; |
170 _patterns = newPatterns; |
175 } |
171 } |
176 |
172 |
181 */ |
177 */ |
182 public void findTemplates(Map<Template, Object> templates) { |
178 public void findTemplates(Map<Template, Object> templates) { |
183 if (_default != null) { |
179 if (_default != null) { |
184 templates.put(_default, this); |
180 templates.put(_default, this); |
185 } |
181 } |
186 for (int i = 0; i < _patterns.size(); i++) { |
182 for (LocationPathPattern pattern : _patterns) { |
187 final LocationPathPattern pattern = |
|
188 (LocationPathPattern)_patterns.elementAt(i); |
|
189 templates.put(pattern.getTemplate(), this); |
183 templates.put(pattern.getTemplate(), this); |
190 } |
184 } |
191 } |
185 } |
192 |
186 |
193 /** |
187 /** |