Index: src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java,v retrieving revision 1.152 diff -u -r1.152 ASTConverter15Test.java --- src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 12 May 2005 02:40:26 -0000 1.152 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 13 May 2005 13:59:29 -0000 @@ -5227,22 +5227,14 @@ " }\n" + " void foo() {\n" + " Number n= null;\n" + - " num().add(null);\n" + - " num().add(n);\n" + + " /*start1*/num().add(null)/*end1*/;\n" + + " /*start2*/num().add(n)/*end2*/;\n" + " }\n" + "}\n"; - CompilationUnit compilationUnit = (CompilationUnit) buildAST( - contents, - this.workingCopy); - MarkerInfo info = new MarkerInfo(contents); - info.astStart = contents.indexOf("num().add(null);"); - info.astEnd = info.astStart + "num().add(null)".length(); - MethodInvocation invocation = (MethodInvocation) findNode(compilationUnit, info); + ASTNode[] nodes = buildASTs(contents, this.workingCopy); + MethodInvocation invocation = (MethodInvocation) nodes[0]; IMethodBinding binding1 = invocation.resolveMethodBinding(); - info = new MarkerInfo(contents); - info.astStart = contents.indexOf("num().add(n);"); - info.astEnd = info.astStart + "num().add(n)".length(); - invocation = (MethodInvocation) findNode(compilationUnit, info); + invocation = (MethodInvocation) nodes[1]; IMethodBinding binding2 = invocation.resolveMethodBinding(); assertTrue("2 different capture bindings should not be equals", !binding1.isEqualTo(binding2)); } @@ -5443,4 +5435,29 @@ assertTrue("Not a wildcard type", typeBinding.isWildcardType()); assertFalse("Not an class", typeBinding.isClass()); } + + /* + * Ensures that 2 different parameterized type bindings are not "isEqualTo(...)". + * (regression test for bug 93408 ITypeBinding#isEqualTo(..) does not resolve type variables) + */ + public void test0181() throws JavaModelException { + this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/); + String contents = + "public class X {\n" + + " /*start1*/Y/*end1*/ y;\n" + + " static class Other {\n" + + " /*start2*/Y/*end2*/ y;\n" + + " }\n" + + "}\n" + + "class Y {\n" + + "}"; + ASTNode[] nodes = buildASTs(contents, this.workingCopy); + ParameterizedType type = (ParameterizedType) nodes[0]; + ITypeBinding binding1 = type.resolveBinding(); + type = (ParameterizedType) nodes[1]; + ITypeBinding binding2 = type.resolveBinding(); + assertTrue("2 different parameterrized type bindings should not be equals", !binding1.isEqualTo(binding2)); + } + + } \ No newline at end of file Index: src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java,v retrieving revision 1.15 diff -u -r1.15 AbstractASTTests.java --- src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java 14 Apr 2005 09:40:01 -0000 1.15 +++ src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java 13 May 2005 13:59:29 -0000 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.jdt.core.tests.dom; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -51,13 +52,20 @@ int astStart, astEnd; public MarkerInfo(String source) { - this(null, source); + this(null, source, -1); + } + public MarkerInfo(String source, int markerIndex) { + this(null, source, markerIndex); } public MarkerInfo(String path, String source) { + this(path, source, -1); + } + public MarkerInfo(String path, String source, int markerIndex) { this.path = path; this.source = source; - String markerStart = "/*start*/"; - String markerEnd = "/*end*/"; + String markerNumber = markerIndex == -1 ? "" : Integer.toString(markerIndex); + String markerStart = "/*start" + markerNumber + "*/"; + String markerEnd = "/*end" + markerNumber + "*/"; this.astStart = source.indexOf(markerStart); // start of AST inclusive this.source = new String(CharOperation.replace(this.source.toCharArray(), markerStart.toCharArray(), CharOperation.NO_CHAR)); this.astEnd = this.source.indexOf(markerEnd); // end of AST exclusive @@ -180,6 +188,10 @@ return findNode(unit, markerInfo); } + protected ASTNode buildAST(String contents, ICompilationUnit cu) throws JavaModelException { + return buildAST(contents, cu, true); + } + protected ASTNode buildAST(MarkerInfo markerInfo, IClassFile classFile) throws JavaModelException { return buildAST(markerInfo, classFile, true); } @@ -190,8 +202,35 @@ * by "*start*" and "*end*". */ protected ASTNode buildAST(String contents, ICompilationUnit cu, boolean reportErrors) throws JavaModelException { - MarkerInfo markerInfo = new MarkerInfo(contents); - contents = markerInfo.source; + ASTNode[] nodes = buildASTs(contents, cu, reportErrors); + if (nodes.length == 0) return null; + return nodes[0]; + } + + protected ASTNode[] buildASTs(String contents, ICompilationUnit cu) throws JavaModelException { + return buildASTs(contents, cu, true); + } + + /* + * Removes the marker comments "*start?*" and "*end?*" from the given contents + * (where ? is either empty or a number). + * Builds an AST from the resulting source. + * For each of the pairs, returns the AST node that was delimited by "*start?*" and "*end?*". + */ + protected ASTNode[] buildASTs(String contents, ICompilationUnit cu, boolean reportErrors) throws JavaModelException { + ArrayList infos = new ArrayList(); + MarkerInfo markerInfo; + int markerIndex = 0; + while (contents.indexOf("/*start" + ++markerIndex + "*/") != -1) { + markerInfo = new MarkerInfo(contents, markerIndex); + infos.add(markerInfo); + contents = markerInfo.source; + } + if (contents.indexOf("/*start*/") != -1 || infos.size() == 0) { + markerInfo = new MarkerInfo(contents); + infos.add(markerInfo); + contents = markerInfo.source; + } cu.getBuffer().setContents(contents); CompilationUnit unit = cu.reconcile(AST.JLS3, false, null, null); @@ -205,11 +244,14 @@ System.err.println(buffer.toString()); } - return findNode(unit, markerInfo); - } - - protected ASTNode buildAST(String contents, ICompilationUnit cu) throws JavaModelException { - return buildAST(contents, cu, true); + int length = infos.size(); + ASTNode[] nodes = new ASTNode[length]; + for (int i = 0; i < length; i++) { + MarkerInfo info = (MarkerInfo) infos.get(i); + nodes[i] = findNode(unit, info); + } + + return nodes; } protected MarkerInfo[] createMarkerInfos(String[] pathAndSources) {