aboutsummaryrefslogtreecommitdiffstats
path: root/org.aspectj.matcher/src/test/java/org/aspectj/weaver/patterns/SimpleScopeTest.java
blob: 7c2fec4d154f08c9d62e1f3082626d1a3f1501c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/* *******************************************************************
 * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
 * All rights reserved.
 * This program and the accompanying materials are made available
 * under the terms of the Eclipse Public License v 2.0
 * which accompanies this distribution and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
 *
 * Contributors:
 *     PARC     initial implementation
 * ******************************************************************/

package org.aspectj.weaver.patterns;

import org.aspectj.weaver.UnresolvedType;
import org.aspectj.weaver.World;
import org.aspectj.weaver.reflect.ReflectionWorld;

public class SimpleScopeTest extends PatternsTestCase {

	public World getWorld() {
		return new ReflectionWorld(true, this.getClass().getClassLoader());
	}

	public void testTestScope() {
		SimpleScope scope = makeTestScope();

		FormalBinding formalBinding = scope.lookupFormal("i");
		assertEquals("i", formalBinding.getName());
		assertEquals("I", formalBinding.getType().getSignature());

		formalBinding = scope.lookupFormal("string");
		assertEquals("string", formalBinding.getName());
		assertEquals("Ljava/lang/String;", formalBinding.getType().getSignature());
	}

	public void test1() {
		SimpleScope scope = makeTestScope();
		UnresolvedType unresolvedType = scope.lookupType("void", null);
		System.out.println(unresolvedType);
	}

	public static final String[] ZERO_STRINGS = new String[0];

	private TestScope makeTestScope() {
		// i = int
		// string = String
		return new TestScope(new String[] { "int", "java.lang.String" }, new String[] { "i", "string" }, world);
	}
	//
	// public void testStaticMatch() {
	// checkMatch("java.lang.Object", "java.lang.Object", true);
	// checkMatch("java.lang.Object+", "java.lang.Object", true);
	// checkMatch("java.lang.Object+", "java.lang.String", true);
	// checkMatch("java.lang.String+", "java.lang.Object", false);
	// checkMatch("java.lang.Integer", "java.lang.String", false);
	//
	// checkMatch("java.lang.Integer", "int", false);
	//
	// checkMatch("java.lang.Number+", "java.lang.Integer", true);
	//
	// checkMatch("java..*", "java.lang.Integer", true);
	// checkMatch("java..*", "java.lang.reflect.Modifier", true);
	// checkMatch("java..*", "int", false);
	// checkMatch("java..*", "javax.swing.Action", false);
	// checkMatch("java..*+", "javax.swing.Action", true);
	//
	// checkMatch("*.*.Object", "java.lang.Object", true);
	// checkMatch("*.Object", "java.lang.Object", false);
	// checkMatch("*..*", "java.lang.Object", true);
	// checkMatch("*..*", "int", false);
	// checkMatch("java..Modifier", "java.lang.reflect.Modifier", true);
	// checkMatch("java.lang.reflect.Mod..ifier", "java.lang.reflect.Modifier", false);
	//
	// checkMatch("java..reflect..Modifier", "java.lang.reflect.Modifier", true);
	// checkMatch("java..lang..Modifier", "java.lang.reflect.Modifier", true);
	// checkMatch("java..*..Modifier", "java.lang.reflect.Modifier", true);
	// checkMatch("java..*..*..Modifier", "java.lang.reflect.Modifier", true);
	// checkMatch("java..*..*..*..Modifier", "java.lang.reflect.Modifier", false);
	// // checkMatch("java..reflect..Modifier", "java.lang.reflect.Modxifier", false);
	// checkMatch("ja*va..Modifier", "java.lang.reflect.Modifier", true);
	// checkMatch("java..*..Mod*ifier", "java.lang.reflect.Modifier", true);
	//
	// }
	//
	// // three levels:
	// // 0. defined in current compilation unit, or imported by name
	// // 1. defined in current package/type/whatever
	// // 2. defined in package imported by *
	// /**
	// * We've decided not to test this here, but rather in any compilers
	// */
	// public void testImportResolve() {
	// // checkIllegalImportResolution("List", new String[] { "java.util", "java.awt", },
	// // ZERO_STRINGS);
	//
	// }
	//
	// // Assumption for bcweaver: Already resolved type patterns with no *s or ..'s into exact type
	// // patterns. Exact type patterns don't have import lists. non-exact-type pattens don't
	// // care about precedence, so the current package can be included with all the other packages,
	// // and we don't care about compilation units, and we don't care about ordering.
	//
	// // only giving this wild-type patterns
	// public void testImportMatch() {
	//
	// checkImportMatch("*List", new String[] { "java.awt.", }, ZERO_STRINGS, "java.awt.List", true);
	// checkImportMatch("*List", new String[] { "java.awt.", }, ZERO_STRINGS, "java.awt.List", true);
	// checkImportMatch("*List", new String[] { "java.awt.", }, ZERO_STRINGS, "java.util.List", false);
	// checkImportMatch("*List", new String[] { "java.util.", }, ZERO_STRINGS, "java.awt.List", false);
	// checkImportMatch("*List", new String[] { "java.util.", }, ZERO_STRINGS, "java.util.List", true);
	//
	// checkImportMatch("*List", ZERO_STRINGS, new String[] { "java.awt.List", }, "java.awt.List", true);
	//
	// checkImportMatch("awt.*List", ZERO_STRINGS, new String[] { "java.awt.List", }, "java.awt.List", false);
	// checkImportMatch("*Foo", ZERO_STRINGS, new String[] { "java.awt.List", }, "java.awt.List", false);
	//
	// checkImportMatch("*List", new String[] { "java.util.", "java.awt.", }, ZERO_STRINGS, "java.util.List", true);
	// checkImportMatch("*List", new String[] { "java.util.", "java.awt.", }, ZERO_STRINGS, "java.awt.List", true);
	//
	// checkImportMatch("*..List", new String[] { "java.util." }, ZERO_STRINGS, "java.util.List", true);
	// checkImportMatch("*..List", new String[] { "java.util." }, ZERO_STRINGS, "java.awt.List", true);
	//
	// }
	//
	// public void testImportMatchWithInners() {
	// // checkImportMatch("*Entry", new String[] { "java.util.", "java.util.Map$" }, ZERO_STRINGS, "java.util.Map$Entry", true);
	// //
	// // checkImportMatch("java.util.Map.*Entry", ZERO_STRINGS, ZERO_STRINGS, "java.util.Map$Entry", true);
	// //
	// // checkImportMatch("*Entry", new String[] { "java.util.", }, ZERO_STRINGS, "java.util.Map$Entry", false);
	// //
	// // checkImportMatch("*.Entry", new String[] { "java.util.", }, ZERO_STRINGS, "java.util.Map$Entry", true);
	// //
	// // checkImportMatch("Map.*", new String[] { "java.util.", }, ZERO_STRINGS, "java.util.Map$Entry", true);
	//
	// checkImportMatch("Map.*", ZERO_STRINGS, new String[] { "java.util.Map" }, "java.util.Map$Entry", true);
	// }
	//
	// private void checkImportMatch(String wildPattern, String[] importedPackages, String[] importedNames, String matchName,
	// boolean shouldMatch) {
	// WildTypePattern p = makeResolvedWildTypePattern(wildPattern, importedPackages, importedNames);
	// checkPatternMatch(p, matchName, shouldMatch);
	// }
	//
	// private WildTypePattern makeResolvedWildTypePattern(String wildPattern, String[] importedPackages, String[] importedNames) {
	// WildTypePattern unresolved = (WildTypePattern) new PatternParser(wildPattern).parseTypePattern();
	//
	// WildTypePattern resolved = resolve(unresolved, importedPackages, importedNames);
	// return resolved;
	//
	// }
	//
	// private WildTypePattern resolve(WildTypePattern unresolved, String[] importedPrefixes, String[] importedNames) {
	//
	// TestScope scope = makeTestScope();
	// scope.setImportedPrefixes(importedPrefixes);
	// scope.setImportedNames(importedNames);
	// return (WildTypePattern) unresolved.resolveBindings(scope, Bindings.NONE, false, false);
	// }
	//

	//
	// public void testInstanceofMatch() {
	//
	// checkInstanceofMatch("java.lang.Object", "java.lang.Object", FuzzyBoolean.YES);
	//
	// checkIllegalInstanceofMatch("java.lang.Object+", "java.lang.Object");
	// checkIllegalInstanceofMatch("java.lang.Object+", "java.lang.String");
	// checkIllegalInstanceofMatch("java.lang.String+", "java.lang.Object");
	// checkIllegalInstanceofMatch("java.lang.*", "java.lang.Object");
	// checkInstanceofMatch("java.lang.Integer", "java.lang.String", FuzzyBoolean.NO);
	//
	// checkInstanceofMatch("java.lang.Number", "java.lang.Integer", FuzzyBoolean.YES);
	// checkInstanceofMatch("java.lang.Integer", "java.lang.Number", FuzzyBoolean.MAYBE);
	//
	// checkIllegalInstanceofMatch("java..Integer", "java.lang.Integer");
	//
	// checkInstanceofMatch("*", "java.lang.Integer", FuzzyBoolean.YES);
	//
	// }
	//
	// public void testArrayMatch() {
	// checkMatch("*[][]", "java.lang.Object", false);
	// checkMatch("*[]", "java.lang.Object[]", true);
	// checkMatch("*[][]", "java.lang.Object[][]", true);
	// checkMatch("java.lang.Object+", "java.lang.Object[]", true);
	// checkMatch("java.lang.Object[]", "java.lang.Object", false);
	// checkMatch("java.lang.Object[]", "java.lang.Object[]", true);
	// checkMatch("java.lang.Object[][]", "java.lang.Object[][]", true);
	// checkMatch("java.lang.String[]", "java.lang.Object", false);
	// checkMatch("java.lang.String[]", "java.lang.Object[]", false);
	// checkMatch("java.lang.String[][]", "java.lang.Object[][]", false);
	// checkMatch("java.lang.Object+[]", "java.lang.String[][]", true);
	// checkMatch("java.lang.Object+[]", "java.lang.String[]", true);
	// checkMatch("java.lang.Object+[]", "int[][]", true);
	// checkMatch("java.lang.Object+[]", "int[]", false);
	// }
	//
	// private void checkIllegalInstanceofMatch(String pattern, String name) {
	// try {
	// TypePattern p = makeTypePattern(pattern);
	// ResolvedType type = world.resolve(name);
	// p.matchesInstanceof(type);
	// } catch (Throwable e) {
	// return;
	// }
	// assertTrue("matching " + pattern + " with " + name + " should fail", false);
	// }
	//
	// private void checkInstanceofMatch(String pattern, String name, FuzzyBoolean shouldMatch) {
	// TypePattern p = makeTypePattern(pattern);
	// ResolvedType type = world.resolve(name);
	//
	// p = p.resolveBindings(makeTestScope(), null, false, false);
	//
	// // System.out.println("type: " + p);
	// FuzzyBoolean result = p.matchesInstanceof(type);
	// String msg = "matches " + pattern + " to " + type;
	// assertEquals(msg, shouldMatch, result);
	// }
	//
	//
	// private TypePattern makeTypePattern(String pattern) {
	// PatternParser pp = new PatternParser(pattern);
	// TypePattern tp = pp.parseSingleTypePattern();
	// pp.checkEof();
	// return tp;
	// }
	//
	// private void checkMatch(String pattern, String name, boolean shouldMatch) {
	// TypePattern p = makeTypePattern(pattern);
	// p = p.resolveBindings(makeTestScope(), null, false, false);
	// checkPatternMatch(p, name, shouldMatch);
	// }
	//
	// private void checkPatternMatch(TypePattern p, String name, boolean shouldMatch) {
	// ResolvedType type = world.resolve(name);
	// // System.out.println("type: " + type);
	// boolean result = p.matchesStatically(type);
	// String msg = "matches " + p + " to " + type + " expected ";
	// if (shouldMatch) {
	// assertTrue(msg + shouldMatch, result);
	// } else {
	// assertTrue(msg + shouldMatch, !result);
	// }
	// }
	//
	// public void testSerialization() throws IOException {
	// String[] patterns = new String[] { "java.lang.Object", "java.lang.Object+", "java.lang.Integer", "int", "java..*",
	// "java..util..*", "*.*.Object", "*", };
	//
	// for (int i = 0, len = patterns.length; i < len; i++) {
	// checkSerialization(patterns[i]);
	// }
	// }
	//
	// /**
	// * Method checkSerialization.
	// *
	// * @param string
	// */
	// private void checkSerialization(String string) throws IOException {
	// TypePattern p = makeTypePattern(string);
	// ByteArrayOutputStream bo = new ByteArrayOutputStream();
	// ConstantPoolSimulator cps = new ConstantPoolSimulator();
	// CompressingDataOutputStream out = new CompressingDataOutputStream(bo, cps);
	// p.write(out);
	// out.close();
	//
	// ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
	// VersionedDataInputStream in = new VersionedDataInputStream(bi, cps);
	// TypePattern newP = TypePattern.read(in, null);
	//
	// assertEquals("write/read", p, newP);
	// }

}