View | Details | Raw Unified | Return to bug 93408 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java (-13 / +30 lines)
Lines 5227-5248 Link Here
5227
			"  }\n" +
5227
			"  }\n" +
5228
			"  void foo() {\n" + 
5228
			"  void foo() {\n" + 
5229
			"    Number n= null;\n" + 
5229
			"    Number n= null;\n" + 
5230
			"    num().add(null);\n" + 
5230
			"    /*start1*/num().add(null)/*end1*/;\n" + 
5231
			"    num().add(n);\n" + 
5231
			"    /*start2*/num().add(n)/*end2*/;\n" + 
5232
			"  }\n" +
5232
			"  }\n" +
5233
			"}\n";
5233
			"}\n";
5234
	   	CompilationUnit compilationUnit = (CompilationUnit) buildAST(
5234
	   	ASTNode[] nodes = buildASTs(contents, this.workingCopy);
5235
			contents,
5235
	   	MethodInvocation invocation = (MethodInvocation) nodes[0];
5236
    		this.workingCopy);
5237
	   	MarkerInfo info = new MarkerInfo(contents);
5238
	   	info.astStart = contents.indexOf("num().add(null);");
5239
	   	info.astEnd = info.astStart + "num().add(null)".length();
5240
	   	MethodInvocation invocation = (MethodInvocation) findNode(compilationUnit, info);
5241
	   	IMethodBinding binding1 = invocation.resolveMethodBinding();
5236
	   	IMethodBinding binding1 = invocation.resolveMethodBinding();
5242
	   	info = new MarkerInfo(contents);
5237
	   	invocation = (MethodInvocation) nodes[1];
5243
	   	info.astStart = contents.indexOf("num().add(n);");
5244
	   	info.astEnd = info.astStart + "num().add(n)".length();
5245
	   	invocation = (MethodInvocation) findNode(compilationUnit, info);
5246
	   	IMethodBinding binding2 = invocation.resolveMethodBinding();
5238
	   	IMethodBinding binding2 = invocation.resolveMethodBinding();
5247
	   	assertTrue("2 different capture bindings should not be equals", !binding1.isEqualTo(binding2));
5239
	   	assertTrue("2 different capture bindings should not be equals", !binding1.isEqualTo(binding2));
5248
	}
5240
	}
Lines 5443-5446 Link Here
5443
		assertTrue("Not a wildcard type", typeBinding.isWildcardType());
5435
		assertTrue("Not a wildcard type", typeBinding.isWildcardType());
5444
		assertFalse("Not an class", typeBinding.isClass());
5436
		assertFalse("Not an class", typeBinding.isClass());
5445
    }
5437
    }
5438
    
5439
	/*
5440
	 * Ensures that 2 different parameterized type bindings are not "isEqualTo(...)".
5441
	 * (regression test for bug 93408 ITypeBinding#isEqualTo(..) does not resolve type variables)
5442
	 */
5443
	public void test0181() throws JavaModelException {
5444
    	this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
5445
    	String contents =
5446
			"public class X<E> {\n" + 
5447
			"	/*start1*/Y<E>/*end1*/ y;\n" + 
5448
			"	static class Other<E> {\n" + 
5449
			"		/*start2*/Y<E>/*end2*/ y;\n" + 
5450
			"	}\n" + 
5451
			"}\n" + 
5452
			"class Y<E> {\n" + 
5453
			"}";
5454
	   	ASTNode[] nodes = buildASTs(contents, this.workingCopy);
5455
	   	ParameterizedType type = (ParameterizedType) nodes[0];
5456
	   	ITypeBinding binding1 = type.resolveBinding();
5457
	   	type = (ParameterizedType) nodes[1];
5458
	   	ITypeBinding binding2 = type.resolveBinding();
5459
	   	assertTrue("2 different parameterrized type bindings should not be equals", !binding1.isEqualTo(binding2));
5460
	}
5461
	
5462
    
5446
}
5463
}
(-)src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java (-10 / +52 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.dom;
11
package org.eclipse.jdt.core.tests.dom;
12
12
13
import java.util.ArrayList;
13
import java.util.HashMap;
14
import java.util.HashMap;
14
import java.util.Iterator;
15
import java.util.Iterator;
15
import java.util.List;
16
import java.util.List;
Lines 51-63 Link Here
51
		int astStart, astEnd;
52
		int astStart, astEnd;
52
		
53
		
53
		public MarkerInfo(String source) {
54
		public MarkerInfo(String source) {
54
			this(null, source);
55
			this(null, source, -1);
56
		}
57
		public MarkerInfo(String source, int markerIndex) {
58
			this(null, source, markerIndex);
55
		}
59
		}
56
		public MarkerInfo(String path, String source) {
60
		public MarkerInfo(String path, String source) {
61
			this(path, source, -1);
62
		}
63
		public MarkerInfo(String path, String source, int markerIndex) {
57
			this.path = path;
64
			this.path = path;
58
			this.source = source;
65
			this.source = source;
59
			String markerStart = "/*start*/";
66
			String markerNumber = markerIndex == -1 ? "" : Integer.toString(markerIndex);
60
			String markerEnd = "/*end*/";
67
			String markerStart = "/*start" + markerNumber + "*/";
68
			String markerEnd = "/*end" + markerNumber + "*/";
61
			this.astStart = source.indexOf(markerStart); // start of AST inclusive
69
			this.astStart = source.indexOf(markerStart); // start of AST inclusive
62
			this.source = new String(CharOperation.replace(this.source.toCharArray(), markerStart.toCharArray(), CharOperation.NO_CHAR));
70
			this.source = new String(CharOperation.replace(this.source.toCharArray(), markerStart.toCharArray(), CharOperation.NO_CHAR));
63
			this.astEnd = this.source.indexOf(markerEnd); // end of AST exclusive
71
			this.astEnd = this.source.indexOf(markerEnd); // end of AST exclusive
Lines 180-185 Link Here
180
		return findNode(unit, markerInfo);
188
		return findNode(unit, markerInfo);
181
	}
189
	}
182
190
191
	protected ASTNode buildAST(String contents, ICompilationUnit cu) throws JavaModelException {
192
		return buildAST(contents, cu, true);
193
	}
194
	
183
	protected ASTNode buildAST(MarkerInfo markerInfo, IClassFile classFile) throws JavaModelException {
195
	protected ASTNode buildAST(MarkerInfo markerInfo, IClassFile classFile) throws JavaModelException {
184
		return buildAST(markerInfo, classFile, true);
196
		return buildAST(markerInfo, classFile, true);
185
	}
197
	}
Lines 190-197 Link Here
190
	 * by "*start*" and "*end*".
202
	 * by "*start*" and "*end*".
191
	 */
203
	 */
192
	protected ASTNode buildAST(String contents, ICompilationUnit cu, boolean reportErrors) throws JavaModelException {
204
	protected ASTNode buildAST(String contents, ICompilationUnit cu, boolean reportErrors) throws JavaModelException {
193
		MarkerInfo markerInfo = new MarkerInfo(contents);
205
		ASTNode[] nodes = buildASTs(contents, cu, reportErrors);
194
		contents = markerInfo.source;
206
		if (nodes.length == 0) return null;
207
		return nodes[0];
208
	}
209
210
	protected ASTNode[] buildASTs(String contents, ICompilationUnit cu) throws JavaModelException {
211
		return buildASTs(contents, cu, true);
212
	}
213
214
	/*
215
	 * Removes the marker comments "*start?*" and "*end?*" from the given contents
216
	 * (where ? is either empty or a number).
217
	 * Builds an AST from the resulting source.
218
	 * For each of the pairs, returns the AST node that was delimited by "*start?*" and "*end?*".
219
	 */
220
	protected ASTNode[] buildASTs(String contents, ICompilationUnit cu, boolean reportErrors) throws JavaModelException {
221
		ArrayList infos = new ArrayList();
222
		MarkerInfo markerInfo;
223
		int markerIndex = 0;
224
		while (contents.indexOf("/*start" + ++markerIndex + "*/") != -1) {
225
			markerInfo = new MarkerInfo(contents, markerIndex);
226
			infos.add(markerInfo);
227
			contents = markerInfo.source;
228
		}
229
		if (contents.indexOf("/*start*/") != -1 || infos.size() == 0) {
230
			markerInfo = new MarkerInfo(contents);
231
			infos.add(markerInfo);
232
			contents = markerInfo.source;
233
		}
195
234
196
		cu.getBuffer().setContents(contents);
235
		cu.getBuffer().setContents(contents);
197
		CompilationUnit unit = cu.reconcile(AST.JLS3, false, null, null);
236
		CompilationUnit unit = cu.reconcile(AST.JLS3, false, null, null);
Lines 205-215 Link Here
205
				System.err.println(buffer.toString());
244
				System.err.println(buffer.toString());
206
		}
245
		}
207
246
208
		return findNode(unit, markerInfo);
247
		int length = infos.size();
209
	}
248
		ASTNode[] nodes = new ASTNode[length];
210
249
		for (int i = 0; i < length; i++) {
211
	protected ASTNode buildAST(String contents, ICompilationUnit cu) throws JavaModelException {
250
			MarkerInfo info = (MarkerInfo) infos.get(i);
212
		return buildAST(contents, cu, true);
251
			nodes[i] = findNode(unit, info);
252
		}
253
		
254
		return nodes;
213
	}
255
	}
214
256
215
	protected MarkerInfo[] createMarkerInfos(String[] pathAndSources) {
257
	protected MarkerInfo[] createMarkerInfos(String[] pathAndSources) {

Return to bug 93408