forked from eclipse-jdt/eclipse.jdt.core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test case for fred with super method invocations
Signed-off-by: Rob Stryker <stryker@redhat.com>
- Loading branch information
Rob Stryker
committed
Mar 25, 2024
1 parent
aa0893c
commit d06db45
Showing
4 changed files
with
228 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
...se.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTestSetup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<size; i++) { | ||
buffer.append("----- param "); | ||
buffer.append(i+1); | ||
buffer.append("-----\n"); | ||
IAnnotationBinding[] bindings= methodBinding.getParameterAnnotations(i); | ||
int length = bindings.length; | ||
for (int j=0; j<length; j++) { | ||
buffer.append(bindings[j].getKey()); | ||
buffer.append('\n'); | ||
} | ||
} | ||
assertEquals(message, expected, buffer.toString()); | ||
} | ||
|
||
@Override | ||
public ASTNode runConversion(ICompilationUnit unit, boolean resolveBindings) { | ||
return runConversion(this.testLevel, unit, resolveBindings); | ||
} | ||
|
||
@Override | ||
public ASTNode runConversion(ICompilationUnit unit, int position, boolean resolveBindings) { | ||
return runConversion(this.testLevel, unit, position, resolveBindings); | ||
} | ||
|
||
@Override | ||
public ASTNode runConversion(IClassFile classFile, int position, boolean resolveBindings) { | ||
return runConversion(this.testLevel, classFile, position, resolveBindings); | ||
} | ||
|
||
@Override | ||
public ASTNode runConversion(char[] source, String unitName, IJavaProject project) { | ||
return runConversion(this.testLevel, source, unitName, project); | ||
} | ||
|
||
@Override | ||
public ASTNode runConversion(char[] source, String unitName, IJavaProject project, boolean resolveBindings) { | ||
return runConversion(this.testLevel, source, unitName, project, resolveBindings); | ||
} | ||
|
||
@Override | ||
public ASTNode runConversion(char[] source, String unitName, IJavaProject project, Map<String, String> options, boolean resolveBindings) { | ||
return runConversion(this.testLevel, source, unitName, project, options, resolveBindings); | ||
} | ||
@Override | ||
public ASTNode runConversion(char[] source, String unitName, IJavaProject project, Map<String, String> 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); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
...jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/JavacASTConverterBugsTestJLS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<size; index++) { | ||
suite.addTest((Test)tests.get(index)); | ||
} | ||
return suite; | ||
} | ||
|
||
/** | ||
*/ | ||
public void testMethodSuperCall() throws CoreException, IOException { | ||
try { | ||
createJavaProject("P", new String[] {""}, new String[0], ""); | ||
createFile("P/A.java", | ||
""" | ||
public class A { | ||
public class Q { | ||
public Q() { | ||
super(); | ||
} | ||
public void doSomething() {} | ||
} | ||
public class Q2 extends Q { | ||
public Q() { | ||
super(); | ||
} | ||
public void doSomething() { | ||
super.doSomething(); | ||
} | ||
} | ||
}""" | ||
); | ||
ICompilationUnit cuA = getCompilationUnit("P/A.java"); | ||
runConversion(this.testLevel, cuA, true, true, true); | ||
} finally { | ||
deleteProject("P"); | ||
} | ||
} | ||
|
||
|
||
/** | ||
*/ | ||
public void testPlusEquals() throws CoreException, IOException { | ||
try { | ||
createJavaProject("P", new String[] {""}, new String[0], ""); | ||
createFile("P/A.java", | ||
""" | ||
public class A { | ||
public void foo() { | ||
int x = 3; | ||
x += 5; | ||
} | ||
}""" | ||
); | ||
ICompilationUnit cuA = getCompilationUnit("P/A.java"); | ||
runConversion(this.testLevel, cuA, true, true, true); | ||
} finally { | ||
deleteProject("P"); | ||
} | ||
} | ||
} |