### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding.java,v retrieving revision 1.28 diff -u -r1.28 ParameterizedMethodBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding.java 8 Jan 2009 20:51:05 -0000 1.28 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding.java 4 Feb 2010 10:39:59 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; +import java.lang.ref.WeakReference; +import java.util.Map; +import java.util.WeakHashMap; import org.eclipse.jdt.internal.compiler.ast.Wildcard; /** @@ -20,6 +23,7 @@ */ public class ParameterizedMethodBinding extends MethodBinding { + private static Map getClassMethodBindingCache; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=300734 protected MethodBinding originalMethod; /** @@ -249,7 +253,17 @@ * The type of x.getClass() is substituted from 'Class' into: 'Class */ public static ParameterizedMethodBinding instantiateGetClass(TypeBinding receiverType, MethodBinding originalMethod, Scope scope) { - ParameterizedMethodBinding method = new ParameterizedMethodBinding(); + ParameterizedMethodBinding method; + if (getClassMethodBindingCache != null) { + WeakReference w = (WeakReference) getClassMethodBindingCache.get(receiverType); + if (w != null) { + method = (ParameterizedMethodBinding) w.get(); + if (method != null) { + return method; + } + } + } + method = new ParameterizedMethodBinding(); method.modifiers = originalMethod.modifiers; method.selector = originalMethod.selector; method.declaringClass = originalMethod.declaringClass; @@ -268,6 +282,10 @@ if ((method.returnType.tagBits & TagBits.HasMissingType) != 0) { method.tagBits |= TagBits.HasMissingType; } + if (getClassMethodBindingCache == null) { + getClassMethodBindingCache = new WeakHashMap(); + } + getClassMethodBindingCache.put(receiverType, new WeakReference(method)); // method refers back to key return method; } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTestJLS3.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTestJLS3.java,v retrieving revision 1.7 diff -u -r1.7 ASTConverterBugsTestJLS3.java --- src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTestJLS3.java 27 Jun 2008 16:02:37 -0000 1.7 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTestJLS3.java 4 Feb 2010 10:40:13 -0000 @@ -18,6 +18,11 @@ import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.ExpressionStatement; +import org.eclipse.jdt.core.dom.IMethodBinding; +import org.eclipse.jdt.core.dom.MethodDeclaration; +import org.eclipse.jdt.core.dom.MethodInvocation; /** * Test suite to verify that DOM/AST bugs are fixed. @@ -1042,4 +1047,21 @@ "Syntax error on token \",\", < expected\n", result); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=300734 +public void testBug300734() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/Converter15/src/Bug300734.java", + "public class Bug300734 {\n" + + " public void foo(String x) {\n" + + " x.getClass();\n" + + " x.getClass();\n" + + " }\n" + + "}" + ); + CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/); + MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0); + IMethodBinding methodBinding1 = ((MethodInvocation) ((ExpressionStatement) methodDeclaration.getBody().statements().get(0)).getExpression()).resolveMethodBinding(); + IMethodBinding methodBinding2 = ((MethodInvocation) ((ExpressionStatement) methodDeclaration.getBody().statements().get(1)).getExpression()).resolveMethodBinding(); + assertTrue("Bindings differ", methodBinding1 == methodBinding2); +} }