From d06db453edc82405d56e2c3a168c67c9c7fb972d Mon Sep 17 00:00:00 2001 From: Rob Stryker Date: Thu, 14 Mar 2024 16:47:44 -0400 Subject: [PATCH] Add a test case for fred with super method invocations Signed-off-by: Rob Stryker --- .../eclipse/jdt/core/dom/JavacConverter.java | 4 +- .../core/tests/dom/ASTConverterBugsTest.java | 80 +---------- .../tests/dom/ASTConverterBugsTestSetup.java | 124 ++++++++++++++++++ .../dom/JavacASTConverterBugsTestJLS.java | 101 ++++++++++++++ 4 files changed, 228 insertions(+), 81 deletions(-) create mode 100644 org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTestSetup.java create mode 100644 org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/JavacASTConverterBugsTestJLS.java diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java index 4f63d5b28f8..4d094b7b5be 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java @@ -705,8 +705,8 @@ private Expression convertExpression(JCExpression javac) { commonSettings(name, ident); res.setName(name); } else if (nameExpr instanceof JCFieldAccess access) { - boolean superCall1 = access.getExpression() instanceof JCFieldAccess && Objects.equals(Names.instance(this.context)._super, ((JCFieldAccess)access.getExpression()).getIdentifier()); - boolean superCall2 = access instanceof JCFieldAccess && Objects.equals(Names.instance(this.context)._super.toString(), access.getExpression().toString()); + boolean superCall1 = access.getExpression() instanceof JCFieldAccess && Objects.equals(Names.instance(this.context)._super, ((JCFieldAccess)access.getExpression()).getIdentifier()); + boolean superCall2 = access instanceof JCFieldAccess && Objects.equals(Names.instance(this.context)._super.toString(), access.getExpression().toString()); if (superCall1 || superCall2) { JCFieldAccess fa = superCall1 ? ((JCFieldAccess)access.getExpression()) : access; SuperMethodInvocation res2 = this.ast.newSuperMethodInvocation(); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java index 54fb2328342..967b3739c78 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java @@ -15,17 +15,14 @@ import java.io.IOException; import java.util.List; -import java.util.Map; import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.IClassFile; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.WorkingCopyOwner; import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTParser; @@ -46,7 +43,7 @@ import junit.framework.Test; @SuppressWarnings("rawtypes") -public class ASTConverterBugsTest extends ConverterTestSetup { +public class ASTConverterBugsTest extends ASTConverterBugsTestSetup { @Override public void setUpSuite() throws Exception { @@ -64,81 +61,6 @@ public static Test suite() { return buildModelTestSuite(ASTConverterBugsTest.class); } -protected void checkParameterAnnotations(String message, String expected, IMethodBinding methodBinding) { - ITypeBinding[] parameterTypes = methodBinding.getParameterTypes(); - int size = parameterTypes == null ? 0 : parameterTypes.length; - StringBuilder buffer = new StringBuilder(); - for (int i=0; i options, boolean resolveBindings) { - return runConversion(this.testLevel, source, unitName, project, options, resolveBindings); -} -@Override -public ASTNode runConversion(char[] source, String unitName, IJavaProject project, Map options) { - return runConversion(this.testLevel, source, unitName, project, options); -} - -public ASTNode runConversion( - ICompilationUnit unit, - boolean resolveBindings, - boolean statementsRecovery, - boolean bindingsRecovery) { - ASTParser parser = createASTParser(); - parser.setSource(unit); - parser.setResolveBindings(resolveBindings); - parser.setStatementsRecovery(statementsRecovery); - parser.setBindingsRecovery(bindingsRecovery); - parser.setWorkingCopyOwner(this.wcOwner); - return parser.createAST(null); -} - -@Override -protected void resolveASTs(ICompilationUnit[] cus, String[] bindingKeys, ASTRequestor requestor, IJavaProject project, WorkingCopyOwner owner) { - ASTParser parser = createASTParser(); - parser.setResolveBindings(true); - parser.setProject(project); - parser.setWorkingCopyOwner(owner); - parser.createASTs(cus, bindingKeys, requestor, null); -} - /** * bug 186410: [dom] StackOverflowError due to endless superclass bindings hierarchy * test Ensures that the superclass of "java.lang.Object" class is null even when it's a recovered binding diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTestSetup.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTestSetup.java new file mode 100644 index 00000000000..b06968ffd6f --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTestSetup.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2000, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.dom; + +import java.util.Map; + +import org.eclipse.jdt.core.IClassFile; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.WorkingCopyOwner; +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.ASTParser; +import org.eclipse.jdt.core.dom.ASTRequestor; +import org.eclipse.jdt.core.dom.IAnnotationBinding; +import org.eclipse.jdt.core.dom.IMethodBinding; +import org.eclipse.jdt.core.dom.ITypeBinding; + +import junit.framework.Test; + +@SuppressWarnings("rawtypes") +public class ASTConverterBugsTestSetup extends ConverterTestSetup { + +@Override +public void setUpSuite() throws Exception { +// PROJECT_SETUP = true; // do not copy Converter* directories + super.setUpSuite(); +// setUpJCLClasspathVariables("1.5"); + waitUntilIndexesReady(); +} + +public ASTConverterBugsTestSetup(String name) { + super(name); +} + +public static Test suite() { + return buildModelTestSuite(ASTConverterBugsTestSetup.class); +} + +protected void checkParameterAnnotations(String message, String expected, IMethodBinding methodBinding) { + ITypeBinding[] parameterTypes = methodBinding.getParameterTypes(); + int size = parameterTypes == null ? 0 : parameterTypes.length; + StringBuilder buffer = new StringBuilder(); + for (int i=0; i options, boolean resolveBindings) { + return runConversion(this.testLevel, source, unitName, project, options, resolveBindings); +} +@Override +public ASTNode runConversion(char[] source, String unitName, IJavaProject project, Map options) { + return runConversion(this.testLevel, source, unitName, project, options); +} + +public ASTNode runConversion( + ICompilationUnit unit, + boolean resolveBindings, + boolean statementsRecovery, + boolean bindingsRecovery) { + ASTParser parser = createASTParser(); + parser.setSource(unit); + parser.setResolveBindings(resolveBindings); + parser.setStatementsRecovery(statementsRecovery); + parser.setBindingsRecovery(bindingsRecovery); + parser.setWorkingCopyOwner(this.wcOwner); + return parser.createAST(null); +} + +@Override +protected void resolveASTs(ICompilationUnit[] cus, String[] bindingKeys, ASTRequestor requestor, IJavaProject project, WorkingCopyOwner owner) { + ASTParser parser = createASTParser(); + parser.setResolveBindings(true); + parser.setProject(project); + parser.setWorkingCopyOwner(owner); + parser.createASTs(cus, bindingKeys, requestor, null); +} +} diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/JavacASTConverterBugsTestJLS.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/JavacASTConverterBugsTestJLS.java new file mode 100644 index 00000000000..3afcc4c2808 --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/JavacASTConverterBugsTestJLS.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2011, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.dom; + +import java.io.IOException; +import java.util.List; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.dom.AST; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Test suite to verify that DOM/AST bugs are fixed. + * + * Note that only specific JLS8 tests are defined in this test suite, but when + * running it, all superclass {@link ASTConverterBugsTest} tests will be run + * as well. + */ +@SuppressWarnings("rawtypes") +public class JavacASTConverterBugsTestJLS extends ASTConverterBugsTestSetup { + public JavacASTConverterBugsTestJLS(String name) { + super(name); + this.testLevel = AST.getJLSLatest(); + } + + public static Test suite() { + TestSuite suite = new Suite(JavacASTConverterBugsTestJLS.class.getName()); + List tests = buildTestsList(JavacASTConverterBugsTestJLS.class, 1, 0/* do not sort*/); + for (int index=0, size=tests.size(); index