diff --git a/.github/workflows/codacy.yml b/.github/workflows/codacy.yml
index 3d1976b6..7b787898 100644
--- a/.github/workflows/codacy.yml
+++ b/.github/workflows/codacy.yml
@@ -33,6 +33,12 @@ jobs:
name: Codacy Security Scan
runs-on: ubuntu-latest
steps:
+ - name: Set up JDK 21
+ uses: actions/setup-java@v4
+ with:
+ java-version: '21'
+ distribution: 'temurin'
+ cache: maven
- name: Set up Maven
uses: stCarolas/setup-maven@d6af6abeda15e98926a57b5aa970a96bb37f97d1 # v5
with:
diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
index 3e87d893..dc594791 100644
--- a/.github/workflows/codeql.yml
+++ b/.github/workflows/codeql.yml
@@ -47,8 +47,9 @@ jobs:
- name: Setup Java JDK
uses: actions/setup-java@v4
with:
- distribution: 'temurin' # See 'Supported distributions' for available options
- java-version: '17'
+ java-version: '21'
+ distribution: 'temurin'
+ cache: maven
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
diff --git a/pom.xml b/pom.xml
index 78e5fe19..6042995d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
Sandbox central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
pom
4.0.9
@@ -44,6 +44,9 @@
sandbox_jface_cleanup
sandbox_jface_cleanup_feature
sandbox_jface_cleanup_test
+ sandbox_junit_cleanup
+ sandbox_junit_cleanup_feature
+ sandbox_junit_cleanup_test
sandbox_usage_view
sandbox_usage_view_feature
sandbox_product
@@ -57,7 +60,7 @@
eclipse
p2
- https://download.eclipse.org/releases/2024-06
+ https://download.eclipse.org/releases/2024-09
babel
@@ -67,13 +70,13 @@
orbit
p2
- https://download.eclipse.org/tools/orbit/downloads/drops/R20230531010532/repository/
+ https://download.eclipse.org/tools/orbit/simrel/orbit-aggregation/2024-09/
-
+
@@ -322,6 +325,21 @@
sandbox_jface_cleanup_test
${project.version}
+
+ org.sandbox
+ sandbox_junit_cleanup
+ ${project.version}
+
+
+ org.sandbox
+ sandbox_junit_cleanup_feature
+ ${project.version}
+
+
+ org.sandbox
+ sandbox_junit_cleanup_test
+ ${project.version}
+
org.sandbox
sandbox_usage_view
diff --git a/sandbox_cleanup_application/META-INF/MANIFEST.MF b/sandbox_cleanup_application/META-INF/MANIFEST.MF
index d032df8d..206d4523 100644
--- a/sandbox_cleanup_application/META-INF/MANIFEST.MF
+++ b/sandbox_cleanup_application/META-INF/MANIFEST.MF
@@ -3,9 +3,9 @@ Bundle-ManifestVersion: 2
Bundle-Name: sandbox_cleanup_application
Bundle-SymbolicName: sandbox_cleanup_application;singleton:=true
Bundle-Vendor: sandbox
-Bundle-Version: 1.1.0.qualifier
+Bundle-Version: 1.2.0.qualifier
Automatic-Module-Name: ui.sandbox.fragment
-Bundle-RequiredExecutionEnvironment: JavaSE-17
+Bundle-RequiredExecutionEnvironment: JavaSE-21
Bundle-ActivationPolicy: lazy
Eclipse-BuddyPolicy: global
Require-Bundle: org.eclipse.core.runtime,
diff --git a/sandbox_cleanup_application/pom.xml b/sandbox_cleanup_application/pom.xml
index 7a334750..57688c4d 100644
--- a/sandbox_cleanup_application/pom.xml
+++ b/sandbox_cleanup_application/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_cleanup_application
Sandbox cleanup application
diff --git a/sandbox_cleanup_application_feature/feature.xml b/sandbox_cleanup_application_feature/feature.xml
index 49e7c742..fddb43cc 100644
--- a/sandbox_cleanup_application_feature/feature.xml
+++ b/sandbox_cleanup_application_feature/feature.xml
@@ -2,7 +2,7 @@
diff --git a/sandbox_cleanup_application_feature/pom.xml b/sandbox_cleanup_application_feature/pom.xml
index 6193b022..49779b04 100644
--- a/sandbox_cleanup_application_feature/pom.xml
+++ b/sandbox_cleanup_application_feature/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_cleanup_application_feature
Sandbox cleanup application Feature
diff --git a/sandbox_common/META-INF/MANIFEST.MF b/sandbox_common/META-INF/MANIFEST.MF
index 55e07bde..f15b8cba 100644
--- a/sandbox_common/META-INF/MANIFEST.MF
+++ b/sandbox_common/META-INF/MANIFEST.MF
@@ -3,8 +3,8 @@ Bundle-ManifestVersion: 2
Bundle-Name: sandbox_common
Bundle-SymbolicName: sandbox_common;singleton:=true
Bundle-Vendor: sandbox
-Bundle-Version: 1.1.0.qualifier
-Bundle-RequiredExecutionEnvironment: JavaSE-17
+Bundle-Version: 1.2.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-21
Bundle-ActivationPolicy: lazy
Eclipse-BuddyPolicy: global
Require-Bundle: org.eclipse.core.runtime,
diff --git a/sandbox_common/pom.xml b/sandbox_common/pom.xml
index 055a3ef5..08c99f9b 100644
--- a/sandbox_common/pom.xml
+++ b/sandbox_common/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_common
Sandbox common
diff --git a/sandbox_common/src/org/sandbox/jdt/internal/common/HelperVisitor.java b/sandbox_common/src/org/sandbox/jdt/internal/common/HelperVisitor.java
index 0dd2c0b1..5bc27046 100644
--- a/sandbox_common/src/org/sandbox/jdt/internal/common/HelperVisitor.java
+++ b/sandbox_common/src/org/sandbox/jdt/internal/common/HelperVisitor.java
@@ -45,7 +45,19 @@ public class HelperVisitor,V,T> {
*
*/
public static final String METHODNAME = "methodname"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public static final String ANNOTATIONNAME = "annotationname"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public static final String IMPORT = "import"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public static final String SUPERCLASSNAME = "superclassname"; //$NON-NLS-1$
/**
*
*/
@@ -529,6 +541,20 @@ public BiPredicate extends ASTNode, E> addFieldDeclaration(BiPredicate addFieldDeclaration(String annotationname, String superclassname, BiPredicate bs) {
+ predicatedata.put(VisitorEnum.FieldDeclaration, Map.ofEntries(
+ new AbstractMap.SimpleEntry<>(SUPERCLASSNAME, superclassname),
+ new AbstractMap.SimpleEntry<>(ANNOTATIONNAME, annotationname)
+ ));
+ return predicatemap.put(VisitorEnum.FieldDeclaration, bs);
+ }
+
/**
*
* @param bs
@@ -556,6 +582,18 @@ public BiPredicate extends ASTNode, E> addImportDeclaration(BiPredicate addImportDeclaration(String importname, BiPredicate bs) {
+ predicatedata.put(VisitorEnum.ImportDeclaration, Map.ofEntries(
+ new AbstractMap.SimpleEntry<>(IMPORT, importname)
+ ));
+ return predicatemap.put(VisitorEnum.ImportDeclaration, bs);
+ }
+
/**
*
* @param bs
@@ -637,6 +675,18 @@ public BiPredicate extends ASTNode, E> addMarkerAnnotation(BiPredicate addMarkerAnnotation(String name, BiPredicate bs) {
+ predicatedata.put(VisitorEnum.MarkerAnnotation, Map.ofEntries(
+ new AbstractMap.SimpleEntry<>(ANNOTATIONNAME, name)
+ ));
+ return predicatemap.put(VisitorEnum.MarkerAnnotation, bs);
+ }
+
/**
*
* @param bs
@@ -720,6 +770,40 @@ public BiPredicate extends ASTNode, E> addMethodInvocation(Class> typeof, St
predicatedata.put(VisitorEnum.MethodInvocation, map);
return predicatemap.put(VisitorEnum.MethodInvocation, bs);
}
+
+ /**
+ * @param typeof
+ * @param methodname
+ * @param bs
+ * @return old BiPredicate assigned for nodetype
+ */
+ public BiPredicate extends ASTNode, E> addMethodInvocation(String typeof, String methodname,
+ BiPredicate bs) {
+ Map map = Map.ofEntries(
+ new AbstractMap.SimpleEntry<>(METHODNAME, methodname),
+ new AbstractMap.SimpleEntry<>(TYPEOF, typeof)
+ );
+ predicatedata.put(VisitorEnum.MethodInvocation, map);
+ return predicatemap.put(VisitorEnum.MethodInvocation, bs);
+ }
+
+ /**
+ * @param typeof
+ * @param methodname
+ * @param bs
+ * @param params
+ * @return
+ */
+ public BiPredicate extends ASTNode, E> addMethodInvocation(String typeof, String methodname,
+ BiPredicate bs, String[] params) {
+ Map map = Map.ofEntries(
+ new AbstractMap.SimpleEntry<>(PARAMTYPENAMES, params),
+ new AbstractMap.SimpleEntry<>(METHODNAME, methodname),
+ new AbstractMap.SimpleEntry<>(TYPEOF, typeof)
+ );
+ predicatedata.put(VisitorEnum.MethodInvocation, map);
+ return predicatemap.put(VisitorEnum.MethodInvocation, bs);
+ }
/**
*
* @param bs
@@ -765,6 +849,17 @@ public BiPredicate extends ASTNode, E> addNormalAnnotation(BiPredicate addNormalAnnotation(String name, BiPredicate bs) {
+ predicatedata.put(VisitorEnum.NormalAnnotation, Map.ofEntries(
+ new AbstractMap.SimpleEntry<>(ANNOTATIONNAME, name)
+ ));
+ return predicatemap.put(VisitorEnum.NormalAnnotation, bs);
+ }
/**
*
* @param bs
@@ -945,7 +1040,19 @@ public BiPredicate extends ASTNode, E> addSimpleType(BiPredicate addSingleMemberAnnotation(BiPredicate bs) {
return predicatemap.put(VisitorEnum.SingleMemberAnnotation, bs);
}
-
+
+ /**
+ * @param name
+ * @param bs
+ * @return old BiPredicate assigned for nodetype
+ */
+ public BiPredicate extends ASTNode, E> addSingleMemberAnnotation(String name, BiPredicate bs) {
+ predicatedata.put(VisitorEnum.SingleMemberAnnotation, Map.ofEntries(
+ new AbstractMap.SimpleEntry<>(ANNOTATIONNAME, name)
+ ));
+ return predicatemap.put(VisitorEnum.SingleMemberAnnotation, bs);
+ }
+
/**
*
* @param bs
@@ -1101,6 +1208,17 @@ public BiPredicate extends ASTNode, E> addTypeDeclaration(BiPredicate addTypeDeclaration(String derivedfrom, BiPredicate bs) {
+ predicatedata.put(VisitorEnum.TypeDeclaration, Map.ofEntries(
+ new AbstractMap.SimpleEntry<>(SUPERCLASSNAME, derivedfrom)
+ ));
+ return predicatemap.put(VisitorEnum.TypeDeclaration, bs);
+ }
/**
*
* @param bs
@@ -3979,6 +4097,24 @@ public static void callFieldDeclarationVisitor(ASTNode node, ReferenceHol
hv.addFieldDeclaration(bs);
hv.build(node);
}
+
+ /**
+ * @param
+ * @param
+ * @param annotationname
+ * @param withsuperclass
+ * @param node
+ * @param dataholder
+ * @param nodesprocessed
+ * @param bs
+ */
+ public static void callFieldDeclarationVisitor(String annotationname, String withsuperclass, ASTNode node, ReferenceHolder dataholder, Set nodesprocessed,
+ BiPredicate> bs) {
+
+ HelperVisitor,V,T> hv= new HelperVisitor<>(nodesprocessed, dataholder);
+ hv.addFieldDeclaration(annotationname, withsuperclass, bs);
+ hv.build(node);
+ }
/**
*
@@ -4031,6 +4167,23 @@ public static void callImportDeclarationVisitor(ASTNode node, ReferenceHo
hv.build(node);
}
+ /**
+ * @param
+ * @param
+ * @param importname
+ * @param node
+ * @param dataholder
+ * @param nodesprocessed
+ * @param bs
+ */
+ public static void callImportDeclarationVisitor(String importname, ASTNode node, ReferenceHolder dataholder, Set nodesprocessed,
+ BiPredicate> bs) {
+
+ HelperVisitor,V,T> hv= new HelperVisitor<>(nodesprocessed, dataholder);
+ hv.addImportDeclaration(importname, bs);
+ hv.build(node);
+ }
+
/**
*
* @param
@@ -4184,6 +4337,23 @@ public static void callMarkerAnnotationVisitor(ASTNode node, ReferenceHol
hv.build(node);
}
+ /**
+ * @param
+ * @param
+ * @param name
+ * @param node
+ * @param dataholder
+ * @param nodesprocessed
+ * @param bs
+ */
+ public static void callMarkerAnnotationVisitor(String name, ASTNode node, ReferenceHolder dataholder, Set nodesprocessed,
+ BiPredicate> bs) {
+
+ HelperVisitor,V,T> hv= new HelperVisitor<>(nodesprocessed, dataholder);
+ hv.addMarkerAnnotation(name, bs);
+ hv.build(node);
+ }
+
/**
*
* @param
@@ -4321,6 +4491,43 @@ public static void callMethodInvocationVisitor(Class> methodof, String
hv.addMethodInvocation(methodof, methodname, bs);
hv.build(node);
}
+
+ /**
+ * @param
+ * @param
+ * @param methodof
+ * @param methodname
+ * @param node
+ * @param dataholder
+ * @param nodesprocessed
+ * @param bs
+ */
+ public static void callMethodInvocationVisitor(String methodof, String methodname, ASTNode node, ReferenceHolder dataholder, Set nodesprocessed,
+ BiPredicate> bs) {
+
+ HelperVisitor,V,T> hv= new HelperVisitor<>(nodesprocessed, dataholder);
+ hv.addMethodInvocation(methodof, methodname, bs);
+ hv.build(node);
+ }
+
+ /**
+ * @param
+ * @param
+ * @param methodof
+ * @param methodname
+ * @param node
+ * @param dataholder
+ * @param nodesprocessed
+ * @param bs
+ * @param params
+ */
+ public static void callMethodInvocationVisitor(String methodof, String methodname, ASTNode node, ReferenceHolder dataholder, Set nodesprocessed,
+ BiPredicate> bs, String[] params) {
+
+ HelperVisitor,V,T> hv= new HelperVisitor<>(nodesprocessed, dataholder);
+ hv.addMethodInvocation(methodof, methodname, bs, params);
+ hv.build(node);
+ }
/**
*
@@ -4407,6 +4614,23 @@ public static void callNormalAnnotationVisitor(ASTNode node, ReferenceHol
hv.build(node);
}
+ /**
+ * @param
+ * @param
+ * @param name
+ * @param node
+ * @param dataholder
+ * @param nodesprocessed
+ * @param bs
+ */
+ public static void callNormalAnnotationVisitor(String name, ASTNode node, ReferenceHolder dataholder, Set nodesprocessed,
+ BiPredicate> bs) {
+
+ HelperVisitor,V,T> hv= new HelperVisitor<>(nodesprocessed, dataholder);
+ hv.addNormalAnnotation(name, bs);
+ hv.build(node);
+ }
+
/**
*
* @param
@@ -4733,6 +4957,23 @@ public static void callSingleMemberAnnotationVisitor(ASTNode node, Refere
hv.build(node);
}
+ /**
+ * @param
+ * @param
+ * @param name
+ * @param node
+ * @param dataholder
+ * @param nodesprocessed
+ * @param bs
+ */
+ public static void callSingleMemberAnnotationVisitor(String name, ASTNode node, ReferenceHolder dataholder, Set nodesprocessed,
+ BiPredicate> bs) {
+
+ HelperVisitor,V,T> hv= new HelperVisitor<>(nodesprocessed, dataholder);
+ hv.addSingleMemberAnnotation(name, bs);
+ hv.build(node);
+ }
+
/**
*
* @param
@@ -5022,6 +5263,23 @@ public static void callTypeDeclarationVisitor(ASTNode node, ReferenceHold
hv.build(node);
}
+ /**
+ * @param
+ * @param
+ * @param derivedfrom
+ * @param node
+ * @param dataholder
+ * @param nodesprocessed
+ * @param bs
+ */
+ public static void callTypeDeclarationVisitor(String derivedfrom, ASTNode node, ReferenceHolder dataholder, Set nodesprocessed,
+ BiPredicate> bs) {
+
+ HelperVisitor,V,T> hv= new HelperVisitor<>(nodesprocessed, dataholder);
+ hv.addTypeDeclaration(derivedfrom, bs);
+ hv.build(node);
+ }
+
/**
*
* @param
diff --git a/sandbox_common/src/org/sandbox/jdt/internal/common/LambdaASTVisitor.java b/sandbox_common/src/org/sandbox/jdt/internal/common/LambdaASTVisitor.java
index f95b2f11..36726358 100644
--- a/sandbox_common/src/org/sandbox/jdt/internal/common/LambdaASTVisitor.java
+++ b/sandbox_common/src/org/sandbox/jdt/internal/common/LambdaASTVisitor.java
@@ -351,12 +351,47 @@ public boolean visit(FieldAccess node) {
@Override
public boolean visit(FieldDeclaration node) {
if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.FieldDeclaration)) {
- return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.FieldDeclaration)))
- .test(node, this.helperVisitor.dataholder);
+ Map map=(Map) this.helperVisitor.getSupplierData().get(VisitorEnum.FieldDeclaration);
+ if(map != null) {
+ String superclassname=(String) map.get(HelperVisitor.SUPERCLASSNAME);
+ String annotationclass=(String) map.get(HelperVisitor.ANNOTATIONNAME);
+ if(superclassname != null && annotationclass != null) {
+ boolean bothmatch=false;
+ for (Object modifier : node.modifiers()) {
+ if (modifier instanceof Annotation annotation) {
+ ITypeBinding anotbinding = annotation.resolveTypeBinding();
+ String annotationName = anotbinding.getQualifiedName();
+ if (annotationName.equals(annotationclass)) {
+ // Feld- oder Klassentyp des @Rule-Felds bestimmen
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) node.fragments().get(0);
+ ITypeBinding binding = fragment.resolveBinding().getType();
+ // Prüfen, ob die Klasse von ExternalResource erbt
+ if (isExternalResource(binding,superclassname)) {
+ bothmatch=true;
+ }
+ }
+ }
+ }
+ if(!bothmatch) {
+ return true;
+ }
+ }
+ }
+ return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.FieldDeclaration))).test(node, this.helperVisitor.dataholder);
}
return true;
}
+ private static boolean isExternalResource(ITypeBinding typeBinding, String qualifiedname) {
+ while (typeBinding != null) {
+ if (typeBinding.getQualifiedName().equals(qualifiedname)) {
+ return true;
+ }
+ typeBinding = typeBinding.getSuperclass();
+ }
+ return false;
+ }
+
@Override
public boolean visit(ForStatement node) {
if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.ForStatement)) {
@@ -378,8 +413,15 @@ public boolean visit(IfStatement node) {
@Override
public boolean visit(ImportDeclaration node) {
if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.ImportDeclaration)) {
- return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.ImportDeclaration)))
- .test(node, this.helperVisitor.dataholder);
+ Map map=(Map) this.helperVisitor.getSupplierData().get(VisitorEnum.ImportDeclaration);
+ if(map != null) {
+ String data=(String) map.get(HelperVisitor.IMPORT);
+ String fullyQualifiedName = node.getName().getFullyQualifiedName();
+ if ((data!= null) && !fullyQualifiedName.equals(data)) {
+ return true;
+ }
+ }
+ return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.ImportDeclaration))).test(node, this.helperVisitor.dataholder);
}
return true;
}
@@ -459,8 +501,21 @@ public boolean visit(LineComment node) {
@Override
public boolean visit(MarkerAnnotation node) {
if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.MarkerAnnotation)) {
- return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.MarkerAnnotation)))
- .test(node, this.helperVisitor.dataholder);
+ Map map=(Map) this.helperVisitor.getSupplierData().get(VisitorEnum.MarkerAnnotation);
+ if(map != null) {
+ String data=(String) map.get(HelperVisitor.ANNOTATIONNAME);
+ ITypeBinding binding = node.resolveTypeBinding();
+ String fullyQualifiedName;
+ if (binding != null) {
+ fullyQualifiedName = binding.getQualifiedName();
+ }else {
+ fullyQualifiedName = node.getTypeName().getFullyQualifiedName();
+ }
+ if ((data!= null) && !fullyQualifiedName.equals(data)) {
+ return true;
+ }
+ }
+ return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.MarkerAnnotation))).test(node, this.helperVisitor.dataholder);
}
return true;
}
@@ -519,17 +574,22 @@ public boolean visit(MethodInvocation node) {
if ((data!= null) && !node.getName().getIdentifier().equals(data)) {
return true;
}
- Class> typeof=(Class>) map.get(HelperVisitor.TYPEOF);
- String[] parameterTypesQualifiedNames=(String[]) map.get(HelperVisitor.PARAMTYPENAMES);
-
- if(typeof!=null) {
+ Object object = map.get(HelperVisitor.TYPEOF);
+ String canonicaltype;
+ if(object!=null) {
+ if(object instanceof Class typeof) {
+ canonicaltype= typeof.getCanonicalName();
+ } else {
+ canonicaltype= (String)object;
+ }
+ String[] parameterTypesQualifiedNames=(String[]) map.get(HelperVisitor.PARAMTYPENAMES);
if(parameterTypesQualifiedNames==null) {
- if (ASTNodes.usesGivenSignature(node, typeof.getCanonicalName(), data)) {
- return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.MethodInvocation))).test(node, this.helperVisitor.dataholder);
+ if (!usesGivenSignature(node, canonicaltype, data)) {
+ return true;
}
} else
- if (ASTNodes.usesGivenSignature(node, typeof.getCanonicalName(), data, parameterTypesQualifiedNames)) {
- return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.MethodInvocation))).test(node, this.helperVisitor.dataholder);
+ if (!ASTNodes.usesGivenSignature(node, canonicaltype, data, parameterTypesQualifiedNames)) {
+ return true;
}
}
}
@@ -538,6 +598,52 @@ public boolean visit(MethodInvocation node) {
return true;
}
+ private static boolean usesGivenSignature(MethodInvocation node, String canonicaltype, String methodName) {
+ IMethodBinding methodBinding= node.resolveMethodBinding();
+ if(methodBinding==null) {
+ if(!methodName.equals(node.getName().getIdentifier())){
+ return false;
+ }
+ } else {
+ if(!methodName.equals(methodBinding.getName())){
+ return false;
+ }
+ }
+ if(isClassQualifiedNameMatching(node,canonicaltype)){
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @param methodInvocation
+ * @param qualifiedName
+ * @return result
+ */
+ public static boolean isClassQualifiedNameMatching(MethodInvocation methodInvocation, String qualifiedName) {
+ Expression expression = methodInvocation.getExpression();
+ if (expression != null) {
+ ITypeBinding typeBinding = expression.resolveTypeBinding();
+ if (typeBinding != null && !typeBinding.isRecovered()) {
+ return qualifiedName.equals(typeBinding.getQualifiedName());
+ }
+ if (expression instanceof SimpleName) {
+ String startswith=typeBinding.toString().substring(9);
+ startswith=startswith.substring(0, startswith.length()-1);
+ return qualifiedName.endsWith(startswith);
+ }
+ } else {
+ IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
+ if (methodBinding != null) {
+ ITypeBinding declaringClass = methodBinding.getDeclaringClass();
+ if (declaringClass != null) {
+ return qualifiedName.equals(declaringClass.getQualifiedName());
+ }
+ }
+ }
+ return false;
+ }
+
@Override
public boolean visit(Modifier node) {
if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.Modifier)) {
@@ -577,8 +683,21 @@ public boolean visit(NameQualifiedType node) {
@Override
public boolean visit(NormalAnnotation node) {
if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.NormalAnnotation)) {
- return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.NormalAnnotation)))
- .test(node, this.helperVisitor.dataholder);
+ Map map=(Map) this.helperVisitor.getSupplierData().get(VisitorEnum.NormalAnnotation);
+ if(map != null) {
+ String data=(String) map.get(HelperVisitor.ANNOTATIONNAME);
+ ITypeBinding binding = node.resolveTypeBinding();
+ String fullyQualifiedName;
+ if (binding != null) {
+ fullyQualifiedName = binding.getQualifiedName();
+ }else {
+ fullyQualifiedName = node.getTypeName().getFullyQualifiedName();
+ }
+ if ((data!= null) && !fullyQualifiedName.equals(data)) {
+ return true;
+ }
+ }
+ return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.NormalAnnotation))).test(node, this.helperVisitor.dataholder);
}
return true;
}
@@ -757,8 +876,21 @@ public boolean visit(SimpleType node) {
@Override
public boolean visit(SingleMemberAnnotation node) {
if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.SingleMemberAnnotation)) {
- return ((BiPredicate) (this.helperVisitor.predicatemap
- .get(VisitorEnum.SingleMemberAnnotation))).test(node, this.helperVisitor.dataholder);
+ Map map=(Map) this.helperVisitor.getSupplierData().get(VisitorEnum.SingleMemberAnnotation);
+ if(map != null) {
+ String data=(String) map.get(HelperVisitor.ANNOTATIONNAME);
+ ITypeBinding binding = node.resolveTypeBinding();
+ String fullyQualifiedName;
+ if (binding != null) {
+ fullyQualifiedName = binding.getQualifiedName();
+ }else {
+ fullyQualifiedName = node.getTypeName().getFullyQualifiedName();
+ }
+ if ((data!= null) && !fullyQualifiedName.equals(data)) {
+ return true;
+ }
+ }
+ return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.SingleMemberAnnotation))).test(node, this.helperVisitor.dataholder);
}
return true;
}
@@ -910,8 +1042,21 @@ public boolean visit(TryStatement node) {
@Override
public boolean visit(TypeDeclaration node) {
if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.TypeDeclaration)) {
- return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.TypeDeclaration)))
- .test(node, this.helperVisitor.dataholder);
+ Map map=(Map) this.helperVisitor.getSupplierData().get(VisitorEnum.TypeDeclaration);
+ if(map != null) {
+ String superclassname=(String) map.get(HelperVisitor.SUPERCLASSNAME);
+ if(superclassname != null) {
+ boolean bothmatch=false;
+ ITypeBinding binding = node.resolveBinding();
+ if (isExternalResource(binding,superclassname)) {
+ bothmatch=true;
+ }
+ if(!bothmatch) {
+ return true;
+ }
+ }
+ }
+ return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.TypeDeclaration))).test(node, this.helperVisitor.dataholder);
}
return true;
}
@@ -1378,6 +1523,20 @@ public void endVisit(LineComment node) {
@Override
public void endVisit(MarkerAnnotation node) {
if (this.helperVisitor.consumermap.containsKey(VisitorEnum.MarkerAnnotation)) {
+ Map map=(Map) this.helperVisitor.getConsumerData().get(VisitorEnum.MarkerAnnotation);
+ if(map != null) {
+ String data=(String) map.get(HelperVisitor.ANNOTATIONNAME);
+ ITypeBinding binding = node.resolveTypeBinding();
+ String fullyQualifiedName;
+ if (binding != null) {
+ fullyQualifiedName = binding.getQualifiedName();
+ }else {
+ fullyQualifiedName = node.getTypeName().getFullyQualifiedName();
+ }
+ if ((data!= null) && !fullyQualifiedName.equals(data)) {
+ return;
+ }
+ }
((BiConsumer) (this.helperVisitor.consumermap.get(VisitorEnum.MarkerAnnotation))).accept(node,
this.helperVisitor.dataholder);
}
@@ -1430,9 +1589,15 @@ public void endVisit(MethodInvocation node) {
if ((data!= null) && !node.getName().getIdentifier().equals(data)) {
return;
}
- Class> typeof=(Class>) map.get(HelperVisitor.TYPEOF);
- if(typeof!=null) {
- if (!ASTNodes.usesGivenSignature(node, typeof.getCanonicalName(), data)) {
+ Object object = map.get(HelperVisitor.TYPEOF);
+ String canonicaltype;
+ if(object!=null) {
+ if(object instanceof Class typeof) {
+ canonicaltype= typeof.getCanonicalName();
+ } else {
+ canonicaltype= (String)object;
+ }
+ if (!ASTNodes.usesGivenSignature(node, canonicaltype, data)) {
return;
}
}
@@ -1476,6 +1641,20 @@ public void endVisit(NameQualifiedType node) {
@Override
public void endVisit(NormalAnnotation node) {
if (this.helperVisitor.consumermap.containsKey(VisitorEnum.NormalAnnotation)) {
+ Map map=(Map) this.helperVisitor.getConsumerData().get(VisitorEnum.NormalAnnotation);
+ if(map != null) {
+ String data=(String) map.get(HelperVisitor.ANNOTATIONNAME);
+ ITypeBinding binding = node.resolveTypeBinding();
+ String fullyQualifiedName;
+ if (binding != null) {
+ fullyQualifiedName = binding.getQualifiedName();
+ }else {
+ fullyQualifiedName = node.getTypeName().getFullyQualifiedName();
+ }
+ if ((data!= null) && !fullyQualifiedName.equals(data)) {
+ return;
+ }
+ }
((BiConsumer) (this.helperVisitor.consumermap.get(VisitorEnum.NormalAnnotation))).accept(node,
this.helperVisitor.dataholder);
}
diff --git a/sandbox_common/src/org/sandbox/jdt/internal/corext/fix2/MYCleanUpConstants.java b/sandbox_common/src/org/sandbox/jdt/internal/corext/fix2/MYCleanUpConstants.java
index 24813153..5873996d 100644
--- a/sandbox_common/src/org/sandbox/jdt/internal/corext/fix2/MYCleanUpConstants.java
+++ b/sandbox_common/src/org/sandbox/jdt/internal/corext/fix2/MYCleanUpConstants.java
@@ -71,6 +71,62 @@ public class MYCleanUpConstants {
*
*/
public static final String XML_CLEANUP= "cleanup.xmlcleanup"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public static final String JUNIT_CLEANUP= "cleanup.junitcleanup"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public static final String JUNIT_CLEANUP_4_ASSERT= "cleanup.junitcleanup_4_assert"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public static final String JUNIT_CLEANUP_4_ASSUME= "cleanup.junitcleanup_4_assume"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public static final String JUNIT_CLEANUP_4_SUITE= "cleanup.junitcleanup_4_suite"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public static final String JUNIT_CLEANUP_4_BEFORE= "cleanup.junitcleanup_4_before"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public static final String JUNIT_CLEANUP_4_AFTER= "cleanup.junitcleanup_4_after"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public static final String JUNIT_CLEANUP_4_BEFORECLASS= "cleanup.junitcleanup_4_beforeclass"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public static final String JUNIT_CLEANUP_4_AFTERCLASS= "cleanup.junitcleanup_4_afterclass"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public static final String JUNIT_CLEANUP_4_IGNORE= "cleanup.junitcleanup_4_ignore"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public static final String JUNIT_CLEANUP_4_TEST= "cleanup.junitcleanup_4_test"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public static final String JUNIT_CLEANUP_4_RULETEMPORARYFOLDER= "cleanup.junitcleanup_4_ruletemporaryfolder"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public static final String JUNIT_CLEANUP_4_RULETESTNAME= "cleanup.junitcleanup_4_ruletestname"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public static final String JUNIT_CLEANUP_4_EXTERNALRESOURCE= "cleanup.junitcleanup_4_externalresource"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public static final String JUNIT_CLEANUP_4_RUNWITH= "cleanup.junitcleanup_4_runwith"; //$NON-NLS-1$
/**
*
*/
diff --git a/sandbox_coverage/pom.xml b/sandbox_coverage/pom.xml
index 26c5c1bb..566165e8 100644
--- a/sandbox_coverage/pom.xml
+++ b/sandbox_coverage/pom.xml
@@ -5,7 +5,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_coverage
pom
@@ -90,5 +90,15 @@
sandbox_jface_cleanup_test
test
+
+ org.sandbox
+ sandbox_junit_cleanup
+ compile
+
+
+ org.sandbox
+ sandbox_junit_cleanup_test
+ test
+
\ No newline at end of file
diff --git a/sandbox_encoding_quickfix/META-INF/MANIFEST.MF b/sandbox_encoding_quickfix/META-INF/MANIFEST.MF
index d88461b0..72f1f29e 100644
--- a/sandbox_encoding_quickfix/META-INF/MANIFEST.MF
+++ b/sandbox_encoding_quickfix/META-INF/MANIFEST.MF
@@ -4,8 +4,8 @@ Automatic-Module-Name: sandbox.encoding.quickfix
Bundle-Name: Tool
Bundle-SymbolicName: sandbox_encoding_quickfix;singleton:=true
Bundle-Vendor: sandbox
-Bundle-Version: 1.1.0.qualifier
-Bundle-RequiredExecutionEnvironment: JavaSE-17
+Bundle-Version: 1.2.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-21
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.filebuffers,
org.eclipse.core.filesystem,
diff --git a/sandbox_encoding_quickfix/pom.xml b/sandbox_encoding_quickfix/pom.xml
index e7c514c9..17cfe191 100644
--- a/sandbox_encoding_quickfix/pom.xml
+++ b/sandbox_encoding_quickfix/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_encoding_quickfix
Sandbox encoding quickfix
diff --git a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/UseExplicitEncodingFixCore.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/UseExplicitEncodingFixCore.java
index 495d1880..e00dd585 100644
--- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/UseExplicitEncodingFixCore.java
+++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/UseExplicitEncodingFixCore.java
@@ -16,19 +16,15 @@
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
-
-import org.eclipse.text.edits.TextEditGroup;
-
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.rewrite.TargetSourceRangeComputer;
-
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
-import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation;
import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
import org.eclipse.jdt.internal.corext.fix.LinkedProposalModelCore;
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
import org.eclipse.jdt.internal.corext.util.Messages;
+import org.eclipse.text.edits.TextEditGroup;
import org.sandbox.jdt.internal.common.ReferenceHolder;
import org.sandbox.jdt.internal.corext.fix.helper.AbstractExplicitEncoding;
import org.sandbox.jdt.internal.corext.fix.helper.AbstractExplicitEncoding.ChangeBehavior;
@@ -113,4 +109,9 @@ public SourceRange computeSourceRange(final ASTNode nodeWithComment) {
return super.computeSourceRange(nodeWithComment);
}
};
+
+ @Override
+ public String toString() {
+ return explicitencoding.toString();
+ }
}
diff --git a/sandbox_encoding_quickfix_feature/feature.xml b/sandbox_encoding_quickfix_feature/feature.xml
index aab9ccc0..714ba5c7 100644
--- a/sandbox_encoding_quickfix_feature/feature.xml
+++ b/sandbox_encoding_quickfix_feature/feature.xml
@@ -2,7 +2,7 @@
diff --git a/sandbox_encoding_quickfix_feature/pom.xml b/sandbox_encoding_quickfix_feature/pom.xml
index c776779b..929f91fd 100644
--- a/sandbox_encoding_quickfix_feature/pom.xml
+++ b/sandbox_encoding_quickfix_feature/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_encoding_quickfix_feature
Sandbox encoding quickfix Feature
diff --git a/sandbox_encoding_quickfix_test/META-INF/MANIFEST.MF b/sandbox_encoding_quickfix_test/META-INF/MANIFEST.MF
index 82422984..5a167427 100644
--- a/sandbox_encoding_quickfix_test/META-INF/MANIFEST.MF
+++ b/sandbox_encoding_quickfix_test/META-INF/MANIFEST.MF
@@ -3,9 +3,9 @@ Bundle-ManifestVersion: 2
Bundle-Name: Tool tests
Bundle-SymbolicName: sandbox_encoding_quickfix_test;singleton:=true
Bundle-Vendor: sandbox
-Bundle-Version: 1.1.0.qualifier
+Bundle-Version: 1.2.0.qualifier
Fragment-Host: sandbox_encoding_quickfix
-Bundle-RequiredExecutionEnvironment: JavaSE-17
+Bundle-RequiredExecutionEnvironment: JavaSE-21
Require-Bundle: org.junit,
sandbox_test_commons
Bundle-ActivationPolicy: lazy
diff --git a/sandbox_encoding_quickfix_test/pom.xml b/sandbox_encoding_quickfix_test/pom.xml
index 5ab23027..46e328dd 100644
--- a/sandbox_encoding_quickfix_test/pom.xml
+++ b/sandbox_encoding_quickfix_test/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_encoding_quickfix_test
Sandbox encoding quickfix test
diff --git a/sandbox_extra_search/META-INF/MANIFEST.MF b/sandbox_extra_search/META-INF/MANIFEST.MF
index a462469e..9e3f2d08 100644
--- a/sandbox_extra_search/META-INF/MANIFEST.MF
+++ b/sandbox_extra_search/META-INF/MANIFEST.MF
@@ -3,9 +3,9 @@ Bundle-ManifestVersion: 2
Bundle-Name: sandbox_extra_search
Bundle-SymbolicName: sandbox_extra_search;singleton:=true
Bundle-Vendor: sandbox
-Bundle-Version: 1.1.0.qualifier
+Bundle-Version: 1.2.0.qualifier
Automatic-Module-Name: ui.sandbox.fragment
-Bundle-RequiredExecutionEnvironment: JavaSE-17
+Bundle-RequiredExecutionEnvironment: JavaSE-21
Bundle-ActivationPolicy: lazy
Eclipse-BuddyPolicy: global
Require-Bundle: org.eclipse.core.runtime,
diff --git a/sandbox_extra_search/pom.xml b/sandbox_extra_search/pom.xml
index 84b7c078..069db239 100644
--- a/sandbox_extra_search/pom.xml
+++ b/sandbox_extra_search/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_extra_search
Sandbox extra search
diff --git a/sandbox_extra_search_feature/feature.xml b/sandbox_extra_search_feature/feature.xml
index 02656a58..d367ba49 100644
--- a/sandbox_extra_search_feature/feature.xml
+++ b/sandbox_extra_search_feature/feature.xml
@@ -2,7 +2,7 @@
diff --git a/sandbox_extra_search_feature/pom.xml b/sandbox_extra_search_feature/pom.xml
index cdcce76b..a7456044 100644
--- a/sandbox_extra_search_feature/pom.xml
+++ b/sandbox_extra_search_feature/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_extra_search_feature
Sandbox extra search Feature
diff --git a/sandbox_functional_converter/META-INF/MANIFEST.MF b/sandbox_functional_converter/META-INF/MANIFEST.MF
index 902330d4..88b26945 100644
--- a/sandbox_functional_converter/META-INF/MANIFEST.MF
+++ b/sandbox_functional_converter/META-INF/MANIFEST.MF
@@ -2,8 +2,8 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: functional_converter
Bundle-SymbolicName: sandbox_functional_converter;singleton:=true
-Bundle-Version: 1.1.0.qualifier
-Bundle-RequiredExecutionEnvironment: JavaSE-17
+Bundle-Version: 1.2.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-21
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.filebuffers,
org.eclipse.core.filesystem,
diff --git a/sandbox_functional_converter/pom.xml b/sandbox_functional_converter/pom.xml
index eb57e20e..c1da897a 100644
--- a/sandbox_functional_converter/pom.xml
+++ b/sandbox_functional_converter/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_functional_converter
Sandbox functional converter
diff --git a/sandbox_functional_converter_feature/feature.xml b/sandbox_functional_converter_feature/feature.xml
index 7120b197..db4d637f 100644
--- a/sandbox_functional_converter_feature/feature.xml
+++ b/sandbox_functional_converter_feature/feature.xml
@@ -2,7 +2,7 @@
@@ -32,19 +32,16 @@
-
-
-
-
+
+
+
+
+ version="1.2.0.qualifier"/>
diff --git a/sandbox_functional_converter_feature/pom.xml b/sandbox_functional_converter_feature/pom.xml
index 005c527d..c948a2b0 100644
--- a/sandbox_functional_converter_feature/pom.xml
+++ b/sandbox_functional_converter_feature/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_functional_converter_feature
Sandbox functional converter Feature
diff --git a/sandbox_functional_converter_test/META-INF/MANIFEST.MF b/sandbox_functional_converter_test/META-INF/MANIFEST.MF
index 30f46c15..c79a2fd6 100644
--- a/sandbox_functional_converter_test/META-INF/MANIFEST.MF
+++ b/sandbox_functional_converter_test/META-INF/MANIFEST.MF
@@ -2,9 +2,9 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Tool tests
Bundle-SymbolicName: sandbox_functional_converter_test;singleton:=true
-Bundle-Version: 1.1.0.qualifier
+Bundle-Version: 1.2.0.qualifier
Fragment-Host: sandbox_functional_converter
-Bundle-RequiredExecutionEnvironment: JavaSE-17
+Bundle-RequiredExecutionEnvironment: JavaSE-21
Require-Bundle: sandbox_test_commons
Bundle-ActivationPolicy: lazy
Eclipse-BundleShape: dir
@@ -21,5 +21,5 @@ Import-Package: org.junit.jupiter.api,
org.junit.jupiter.params.converter,
org.junit.jupiter.params.provider,
org.junit.jupiter.params.support,
- org.opentest4j;version="1.2.0"
+ org.opentest4j
Automatic-Module-Name: sandbox.functional.converter.test
diff --git a/sandbox_functional_converter_test/pom.xml b/sandbox_functional_converter_test/pom.xml
index 5a71deab..ecbf9200 100644
--- a/sandbox_functional_converter_test/pom.xml
+++ b/sandbox_functional_converter_test/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_functional_converter_test
Sandbox functional converter test
diff --git a/sandbox_functional_converter_test/src/org/sandbox/jdt/ui/tests/quickfix/MatcherTest.java b/sandbox_functional_converter_test/src/org/sandbox/jdt/ui/tests/quickfix/MatcherTest.java
index b6aa1159..fc2b4c87 100644
--- a/sandbox_functional_converter_test/src/org/sandbox/jdt/ui/tests/quickfix/MatcherTest.java
+++ b/sandbox_functional_converter_test/src/org/sandbox/jdt/ui/tests/quickfix/MatcherTest.java
@@ -23,7 +23,7 @@ public void hui(Collection arr) {
coll.add(var);
}
}
- }""";
+ }"""; //$NON-NLS-1$
char[] source = code.toCharArray();
parser.setSource(source);
Map options = JavaCore.getOptions();
diff --git a/sandbox_jface_cleanup/.settings/org.eclipse.jdt.core.prefs b/sandbox_jface_cleanup/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000..62ef3488
--- /dev/null
+++ b/sandbox_jface_cleanup/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,9 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/sandbox_jface_cleanup/META-INF/MANIFEST.MF b/sandbox_jface_cleanup/META-INF/MANIFEST.MF
index e602bb8e..4ad0608b 100644
--- a/sandbox_jface_cleanup/META-INF/MANIFEST.MF
+++ b/sandbox_jface_cleanup/META-INF/MANIFEST.MF
@@ -2,8 +2,8 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: jface_cleanup
Bundle-SymbolicName: sandbox_jface_cleanup;singleton:=true
-Bundle-Version: 1.1.0.qualifier
-Bundle-RequiredExecutionEnvironment: JavaSE-17
+Bundle-Version: 1.2.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-21
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.filebuffers,
org.eclipse.core.filesystem,
diff --git a/sandbox_jface_cleanup/pom.xml b/sandbox_jface_cleanup/pom.xml
index 6232de9f..4096a44f 100644
--- a/sandbox_jface_cleanup/pom.xml
+++ b/sandbox_jface_cleanup/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_jface_cleanup
Sandbox jface cleanup
diff --git a/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/JFacePlugin.java b/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/JFacePlugin.java
index b130a0e9..c223fb59 100644
--- a/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/JFacePlugin.java
+++ b/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/JFacePlugin.java
@@ -88,9 +88,7 @@ public static class MonitorHolder {
public void find(JfaceCleanUpFixCore fixcore, CompilationUnit compilationUnit,
Set operations, Set nodesprocessed,
boolean createForOnlyIfVarUsed) {
- int i = 0;
ReferenceHolder dataholder = new ReferenceHolder<>();
-
ASTProcessor, Integer, MonitorHolder> astp = new ASTProcessor<>(
dataholder, nodesprocessed);
astp.callMethodInvocationVisitor(IProgressMonitor.class, "beginTask", (node, holder) -> { //$NON-NLS-1$
diff --git a/sandbox_jface_cleanup_feature/feature.xml b/sandbox_jface_cleanup_feature/feature.xml
index 53809eb0..499d7bd5 100644
--- a/sandbox_jface_cleanup_feature/feature.xml
+++ b/sandbox_jface_cleanup_feature/feature.xml
@@ -2,7 +2,7 @@
@@ -32,19 +32,12 @@
-
-
-
-
+ version="1.2.0.qualifier"/>
diff --git a/sandbox_jface_cleanup_feature/pom.xml b/sandbox_jface_cleanup_feature/pom.xml
index 714be6d5..825e1112 100644
--- a/sandbox_jface_cleanup_feature/pom.xml
+++ b/sandbox_jface_cleanup_feature/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_jface_cleanup_feature
Sandbox jface cleanup Feature
diff --git a/sandbox_jface_cleanup_test/META-INF/MANIFEST.MF b/sandbox_jface_cleanup_test/META-INF/MANIFEST.MF
index eb8978b5..c33ff2f8 100644
--- a/sandbox_jface_cleanup_test/META-INF/MANIFEST.MF
+++ b/sandbox_jface_cleanup_test/META-INF/MANIFEST.MF
@@ -2,9 +2,9 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: jface cleanup tests
Bundle-SymbolicName: sandbox_jface_cleanup_test;singleton:=true
-Bundle-Version: 1.1.0.qualifier
+Bundle-Version: 1.2.0.qualifier
Fragment-Host: sandbox_jface_cleanup
-Bundle-RequiredExecutionEnvironment: JavaSE-17
+Bundle-RequiredExecutionEnvironment: JavaSE-21
Require-Bundle: org.junit,
sandbox_test_commons
Bundle-ActivationPolicy: lazy
diff --git a/sandbox_jface_cleanup_test/pom.xml b/sandbox_jface_cleanup_test/pom.xml
index 0455784a..0d0a8e6d 100644
--- a/sandbox_jface_cleanup_test/pom.xml
+++ b/sandbox_jface_cleanup_test/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_jface_cleanup_test
Sandbox jface cleanup test
diff --git a/sandbox_jface_cleanup_test/src/org/sandbox/jdt/ui/tests/quickfix/Java8CleanUpTest.java b/sandbox_jface_cleanup_test/src/org/sandbox/jdt/ui/tests/quickfix/Java8CleanUpTest.java
index c10ad414..ba9c8654 100644
--- a/sandbox_jface_cleanup_test/src/org/sandbox/jdt/ui/tests/quickfix/Java8CleanUpTest.java
+++ b/sandbox_jface_cleanup_test/src/org/sandbox/jdt/ui/tests/quickfix/Java8CleanUpTest.java
@@ -30,78 +30,78 @@ public class Java8CleanUpTest {
AbstractEclipseJava context= new EclipseJava8();
enum JFaceCleanupCases{
- PositiveCase("""
- package test;
- import java.util.*;
- import org.eclipse.core.runtime.CoreException;
- import org.eclipse.core.runtime.IProgressMonitor;
- import org.eclipse.core.runtime.SubProgressMonitor;
- import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
- public class Test extends ArrayList {
- public void createPackageFragmentRoot(IProgressMonitor monitor) throws CoreException, InterruptedException {
- monitor.beginTask(NewWizardMessages.NewSourceFolderWizardPage_operation, 3);
- IProgressMonitor subProgressMonitor= new SubProgressMonitor(monitor, 1);
- IProgressMonitor subProgressMonitor2= new SubProgressMonitor(monitor, 2);
- }
- }
- """, //$NON-NLS-1$
-
- """
- package test;
- import java.util.*;
- import org.eclipse.core.runtime.CoreException;
- import org.eclipse.core.runtime.IProgressMonitor;
- import org.eclipse.core.runtime.SubMonitor;
- import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
- public class Test extends ArrayList {
- public void createPackageFragmentRoot(IProgressMonitor monitor) throws CoreException, InterruptedException {
- SubMonitor subMonitor=SubMonitor.convert(monitor,NewWizardMessages.NewSourceFolderWizardPage_operation,3);
- IProgressMonitor subProgressMonitor= subMonitor.split(1);
- IProgressMonitor subProgressMonitor2= subMonitor.split(2);
- }
- }
- """), //$NON-NLS-1$
- Twice("""
- package test;
- import java.util.*;
- import org.eclipse.core.runtime.CoreException;
- import org.eclipse.core.runtime.IProgressMonitor;
- import org.eclipse.core.runtime.SubProgressMonitor;
- import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
- public class Test extends ArrayList {
- public void createPackageFragmentRoot(IProgressMonitor monitor) throws CoreException, InterruptedException {
- monitor.beginTask(NewWizardMessages.NewSourceFolderWizardPage_operation, 3);
- IProgressMonitor subProgressMonitor= new SubProgressMonitor(monitor, 1);
- IProgressMonitor subProgressMonitor2= new SubProgressMonitor(monitor, 2);
- }
- public void createPackageFragmentRoot2(IProgressMonitor monitor) throws CoreException, InterruptedException {
- monitor.beginTask(NewWizardMessages.NewSourceFolderWizardPage_operation, 3);
- IProgressMonitor subProgressMonitor3= new SubProgressMonitor(monitor, 1);
- IProgressMonitor subProgressMonitor4= new SubProgressMonitor(monitor, 2);
- }
- }
- """, //$NON-NLS-1$
-
- """
- package test;
- import java.util.*;
- import org.eclipse.core.runtime.CoreException;
- import org.eclipse.core.runtime.IProgressMonitor;
- import org.eclipse.core.runtime.SubMonitor;
- import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
- public class Test extends ArrayList {
- public void createPackageFragmentRoot(IProgressMonitor monitor) throws CoreException, InterruptedException {
- SubMonitor subMonitor=SubMonitor.convert(monitor,NewWizardMessages.NewSourceFolderWizardPage_operation,3);
- IProgressMonitor subProgressMonitor= subMonitor.split(1);
- IProgressMonitor subProgressMonitor2= subMonitor.split(2);
- }
- public void createPackageFragmentRoot2(IProgressMonitor monitor) throws CoreException, InterruptedException {
- SubMonitor subMonitor=SubMonitor.convert(monitor,NewWizardMessages.NewSourceFolderWizardPage_operation,3);
- IProgressMonitor subProgressMonitor3= subMonitor.split(1);
- IProgressMonitor subProgressMonitor4= subMonitor.split(2);
- }
- }
- """); //$NON-NLS-1$
+ PositiveCase(
+"""
+package test;
+import java.util.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
+public class Test extends ArrayList {
+ public void createPackageFragmentRoot(IProgressMonitor monitor) throws CoreException, InterruptedException {
+ monitor.beginTask(NewWizardMessages.NewSourceFolderWizardPage_operation, 3);
+ IProgressMonitor subProgressMonitor= new SubProgressMonitor(monitor, 1);
+ IProgressMonitor subProgressMonitor2= new SubProgressMonitor(monitor, 2);
+ }
+}
+""", //$NON-NLS-1$
+"""
+package test;
+import java.util.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
+public class Test extends ArrayList {
+ public void createPackageFragmentRoot(IProgressMonitor monitor) throws CoreException, InterruptedException {
+ SubMonitor subMonitor=SubMonitor.convert(monitor,NewWizardMessages.NewSourceFolderWizardPage_operation,3);
+ IProgressMonitor subProgressMonitor= subMonitor.split(1);
+ IProgressMonitor subProgressMonitor2= subMonitor.split(2);
+ }
+}
+"""), //$NON-NLS-1$
+ Twice(
+"""
+package test;
+import java.util.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
+public class Test extends ArrayList {
+ public void createPackageFragmentRoot(IProgressMonitor monitor) throws CoreException, InterruptedException {
+ monitor.beginTask(NewWizardMessages.NewSourceFolderWizardPage_operation, 3);
+ IProgressMonitor subProgressMonitor= new SubProgressMonitor(monitor, 1);
+ IProgressMonitor subProgressMonitor2= new SubProgressMonitor(monitor, 2);
+ }
+ public void createPackageFragmentRoot2(IProgressMonitor monitor) throws CoreException, InterruptedException {
+ monitor.beginTask(NewWizardMessages.NewSourceFolderWizardPage_operation, 3);
+ IProgressMonitor subProgressMonitor3= new SubProgressMonitor(monitor, 1);
+ IProgressMonitor subProgressMonitor4= new SubProgressMonitor(monitor, 2);
+ }
+}
+""", //$NON-NLS-1$
+"""
+package test;
+import java.util.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
+public class Test extends ArrayList {
+ public void createPackageFragmentRoot(IProgressMonitor monitor) throws CoreException, InterruptedException {
+ SubMonitor subMonitor=SubMonitor.convert(monitor,NewWizardMessages.NewSourceFolderWizardPage_operation,3);
+ IProgressMonitor subProgressMonitor= subMonitor.split(1);
+ IProgressMonitor subProgressMonitor2= subMonitor.split(2);
+ }
+ public void createPackageFragmentRoot2(IProgressMonitor monitor) throws CoreException, InterruptedException {
+ SubMonitor subMonitor=SubMonitor.convert(monitor,NewWizardMessages.NewSourceFolderWizardPage_operation,3);
+ IProgressMonitor subProgressMonitor3= subMonitor.split(1);
+ IProgressMonitor subProgressMonitor4= subMonitor.split(2);
+ }
+}
+"""); //$NON-NLS-1$
String given;
String expected;
@@ -123,25 +123,24 @@ public void testJFaceCleanupParametrized(JFaceCleanupCases test) throws CoreExce
}
enum NOJFaceCleanupCases {
-
- NOCase(
- """
- package test;
- import java.util.*;
- public class Test {
- void m(List strings) {
- Iterator it = strings.iterator();
- while (it.hasNext()) {
- String s = (String) it.next();
- if (s.isEmpty()) {
- it.remove();
- } else {
- System.out.println(s);
- }
- }
- }
- }
- """) //$NON-NLS-1$
+NOCase(
+"""
+package test;
+import java.util.*;
+public class Test {
+ void m(List strings) {
+ Iterator it = strings.iterator();
+ while (it.hasNext()) {
+ String s = (String) it.next();
+ if (s.isEmpty()) {
+ it.remove();
+ } else {
+ System.out.println(s);
+ }
+ }
+ }
+}
+""") //$NON-NLS-1$
;
NOJFaceCleanupCases(String given) {
diff --git a/sandbox_junit_cleanup/.classpath b/sandbox_junit_cleanup/.classpath
new file mode 100644
index 00000000..eabb7bcf
--- /dev/null
+++ b/sandbox_junit_cleanup/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/sandbox_junit_cleanup/.gitignore b/sandbox_junit_cleanup/.gitignore
new file mode 100644
index 00000000..b83d2226
--- /dev/null
+++ b/sandbox_junit_cleanup/.gitignore
@@ -0,0 +1 @@
+/target/
diff --git a/sandbox_junit_cleanup/.project b/sandbox_junit_cleanup/.project
new file mode 100644
index 00000000..e0994cde
--- /dev/null
+++ b/sandbox_junit_cleanup/.project
@@ -0,0 +1,34 @@
+
+
+ sandbox_junit_cleanup
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.pde.ManifestBuilder
+
+
+
+
+ org.eclipse.pde.SchemaBuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.m2e.core.maven2Nature
+ org.eclipse.pde.PluginNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/sandbox_junit_cleanup/META-INF/MANIFEST.MF b/sandbox_junit_cleanup/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..e1b33638
--- /dev/null
+++ b/sandbox_junit_cleanup/META-INF/MANIFEST.MF
@@ -0,0 +1,29 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: junit cleanup
+Bundle-SymbolicName: sandbox_junit_cleanup;singleton:=true
+Bundle-Version: 1.2.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-21
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.core.filebuffers,
+ org.eclipse.core.filesystem,
+ org.eclipse.core.resources,
+ org.eclipse.core.expressions,
+ org.eclipse.jdt.core,
+ org.eclipse.jdt.ui,
+ org.eclipse.ltk.core.refactoring,
+ org.eclipse.text,
+ org.eclipse.swt,
+ org.eclipse.jface,
+ org.eclipse.ui.workbench,
+ org.eclipse.jdt.core.manipulation,
+ sandbox_common,
+ org.junit,
+ org.eclipse.jdt.junit.runtime,
+ org.eclipse.jdt.junit4.runtime
+Bundle-ActivationPolicy: lazy
+Eclipse-RegisterBuddy: org.eclipse.jdt.core.manipulation
+Import-Package: org.sandbox.jdt.internal.common,
+ org.sandbox.jdt.internal.corext.fix2
+Eclipse-BuddyPolicy: global
+Automatic-Module-Name: sandbox.junit.cleanup
diff --git a/sandbox_junit_cleanup/build.properties b/sandbox_junit_cleanup/build.properties
new file mode 100644
index 00000000..8be33378
--- /dev/null
+++ b/sandbox_junit_cleanup/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ build.properties
diff --git a/sandbox_junit_cleanup/plugin.xml b/sandbox_junit_cleanup/plugin.xml
new file mode 100644
index 00000000..5b981c33
--- /dev/null
+++ b/sandbox_junit_cleanup/plugin.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sandbox_junit_cleanup/pom.xml b/sandbox_junit_cleanup/pom.xml
new file mode 100644
index 00000000..801d7adb
--- /dev/null
+++ b/sandbox_junit_cleanup/pom.xml
@@ -0,0 +1,17 @@
+
+
+ 4.0.0
+
+ org.sandbox
+ central
+ 1.2.0-SNAPSHOT
+
+ sandbox_junit_cleanup
+ Sandbox junit cleanup
+ eclipse-plugin
+
+ ${project.basedir}/src
+
+
\ No newline at end of file
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/JUnitCleanUpFixCore.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/JUnitCleanUpFixCore.java
new file mode 100644
index 00000000..a2f2101e
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/JUnitCleanUpFixCore.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.corext.fix;
+
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
+import org.eclipse.jdt.internal.corext.fix.LinkedProposalModelCore;
+import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
+import org.eclipse.jdt.internal.corext.refactoring.util.TightSourceRangeComputer;
+import org.eclipse.jdt.internal.corext.util.Messages;
+import org.eclipse.text.edits.TextEditGroup;
+import org.sandbox.jdt.internal.common.ReferenceHolder;
+import org.sandbox.jdt.internal.corext.fix.helper.AbstractTool;
+import org.sandbox.jdt.internal.corext.fix.helper.AfterClassJUnitPlugin;
+import org.sandbox.jdt.internal.corext.fix.helper.AfterJUnitPlugin;
+import org.sandbox.jdt.internal.corext.fix.helper.AssertJUnitPlugin;
+import org.sandbox.jdt.internal.corext.fix.helper.AssumeJUnitPlugin;
+import org.sandbox.jdt.internal.corext.fix.helper.BeforeClassJUnitPlugin;
+import org.sandbox.jdt.internal.corext.fix.helper.BeforeJUnitPlugin;
+import org.sandbox.jdt.internal.corext.fix.helper.ExternalResourceJUnitPlugin;
+import org.sandbox.jdt.internal.corext.fix.helper.IgnoreJUnitPlugin;
+import org.sandbox.jdt.internal.corext.fix.helper.JunitHolder;
+import org.sandbox.jdt.internal.corext.fix.helper.RuleExternalResourceJUnitPlugin;
+import org.sandbox.jdt.internal.corext.fix.helper.RuleTemporayFolderJUnitPlugin;
+import org.sandbox.jdt.internal.corext.fix.helper.RuleTestnameJUnitPlugin;
+import org.sandbox.jdt.internal.corext.fix.helper.RunWithJUnitPlugin;
+import org.sandbox.jdt.internal.corext.fix.helper.TestJUnitPlugin;
+import org.sandbox.jdt.internal.ui.fix.MultiFixMessages;
+
+public enum JUnitCleanUpFixCore {
+
+ BEFORE(new BeforeJUnitPlugin()),
+ AFTER(new AfterJUnitPlugin()),
+ TEST(new TestJUnitPlugin()),
+ BEFORECLASS(new BeforeClassJUnitPlugin()),
+ AFTERCLASS(new AfterClassJUnitPlugin()),
+ IGNORE(new IgnoreJUnitPlugin()),
+ RUNWITH(new RunWithJUnitPlugin()),
+ ASSERT(new AssertJUnitPlugin()),
+ ASSUME(new AssumeJUnitPlugin()),
+ RULEEXTERNALRESOURCE(new RuleExternalResourceJUnitPlugin()),
+ RULETESTNAME(new RuleTestnameJUnitPlugin()),
+ RULETEMPORARYFOLDER(new RuleTemporayFolderJUnitPlugin()),
+ EXTERNALRESOURCE(new ExternalResourceJUnitPlugin());
+
+ AbstractTool> junitfound;
+
+ @SuppressWarnings("unchecked")
+ JUnitCleanUpFixCore(AbstractTool extends ReferenceHolder> junitprocess) {
+ this.junitfound= (AbstractTool>) junitprocess;
+ }
+
+ public String getPreview(boolean i) {
+ long countother= junitfound.getPreview(!i).lines().count();
+ StringBuilder preview= new StringBuilder(junitfound.getPreview(i));
+ long countnow= preview.toString().lines().count();
+ if(countnow operations, final Set nodesprocessed) {
+ junitfound.find(this, compilationUnit, operations, nodesprocessed);
+ }
+
+ public CompilationUnitRewriteOperationWithSourceRange rewrite(final ReferenceHolder hit) {
+ return new CompilationUnitRewriteOperationWithSourceRange() {
+ @Override
+ public void rewriteASTInternal(final CompilationUnitRewrite cuRewrite,
+ final LinkedProposalModelCore linkedModel) throws CoreException {
+ TextEditGroup group= createTextEditGroup(Messages.format(MultiFixMessages.JUnitCleanUp_description,
+ new Object[] { JUnitCleanUpFixCore.this.toString() }), cuRewrite);
+ TightSourceRangeComputer rangeComputer;
+ ASTRewrite rewrite= cuRewrite.getASTRewrite();
+ if (rewrite.getExtendedSourceRangeComputer() instanceof TightSourceRangeComputer) {
+ rangeComputer= (TightSourceRangeComputer) rewrite.getExtendedSourceRangeComputer();
+ } else {
+ rangeComputer= new TightSourceRangeComputer();
+ }
+ rangeComputer.addTightSourceNode(hit.get(0).minv);
+ rewrite.setTargetSourceRangeComputer(rangeComputer);
+ junitfound.rewrite(JUnitCleanUpFixCore.this, hit, cuRewrite, group);
+ }
+ };
+ }
+
+ @Override
+ public String toString() {
+ return junitfound.toString();
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java
new file mode 100644
index 00000000..90eee4ab
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java
@@ -0,0 +1,809 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.corext.fix.helper;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeHierarchy;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
+import org.eclipse.jdt.core.dom.Assignment;
+import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.BodyDeclaration;
+import org.eclipse.jdt.core.dom.ClassInstanceCreation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.ExpressionStatement;
+import org.eclipse.jdt.core.dom.FieldAccess;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.MarkerAnnotation;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.Modifier;
+import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.PrimitiveType;
+import org.eclipse.jdt.core.dom.QualifiedType;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.SimpleType;
+import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
+import org.eclipse.jdt.core.dom.SuperMethodInvocation;
+import org.eclipse.jdt.core.dom.Type;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.core.dom.TypeLiteral;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
+import org.eclipse.jdt.internal.corext.dom.AbortSearchException;
+import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer;
+import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
+import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
+import org.eclipse.text.edits.TextEditGroup;
+import org.sandbox.jdt.internal.corext.fix.JUnitCleanUpFixCore;
+
+/**
+ * @param Type found in Visitor
+ */
+public abstract class AbstractTool {
+
+ private static final String TEST_NAME= "testName";
+ private static final String METHOD_AFTER_EACH= "afterEach";
+ private static final String METHOD_BEFORE_EACH= "beforeEach";
+ private static final String ORG_JUNIT_JUPITER_API_EXTENSION_EXTENSION_CONTEXT= "org.junit.jupiter.api.extension.ExtensionContext";
+ private static final String AFTER_EACH_CALLBACK= "AfterEachCallback";
+ private static final String BEFORE_EACH_CALLBACK= "BeforeEachCallback";
+ private static final String ANNOTATION_REGISTER_EXTENSION= "RegisterExtension";
+ protected static final String ORG_JUNIT_RULE= "org.junit.Rule";
+ private static final String ORG_JUNIT_JUPITER_API_EXTENSION_AFTER_EACH_CALLBACK= "org.junit.jupiter.api.extension.AfterEachCallback";
+ private static final String ORG_JUNIT_JUPITER_API_EXTENSION_BEFORE_EACH_CALLBACK= "org.junit.jupiter.api.extension.BeforeEachCallback";
+ private static final String ORG_JUNIT_JUPITER_API_EXTENSION_REGISTER_EXTENSION= "org.junit.jupiter.api.extension.RegisterExtension";
+ private static final String ANNOTATION_EXTEND_WITH= "ExtendWith";
+ protected static final String METHOD_AFTER= "after";
+ protected static final String METHOD_BEFORE= "before";
+ private static final String VARIABLE_NAME_CONTEXT= "context";
+ private static final String EXTENSION_CONTEXT= "ExtensionContext";
+ protected static final String ORG_JUNIT_RULES_EXTERNAL_RESOURCE= "org.junit.rules.ExternalResource";
+ protected static final String ORG_JUNIT_JUPITER_API_EXTENSION_EXTEND_WITH= "org.junit.jupiter.api.extension.ExtendWith";
+ protected static final String ORG_JUNIT_AFTER= "org.junit.After";
+ protected static final String ORG_JUNIT_JUPITER_API_AFTER_EACH= "org.junit.jupiter.api.AfterEach";
+ protected static final String ANNOTATION_AFTER_EACH= "AfterEach";
+ protected static final String ORG_JUNIT_BEFORE= "org.junit.Before";
+ protected static final String ANNOTATION_BEFORE_EACH= "BeforeEach";
+ protected static final String ORG_JUNIT_AFTERCLASS= "org.junit.AfterClass";
+ protected static final String ORG_JUNIT_JUPITER_API_AFTER_ALL= "org.junit.jupiter.api.AfterAll";
+ protected static final String ANNOTATION_AFTER_ALL= "AfterAll";
+ protected static final String ASSERTIONS= "Assertions";
+ protected static final String ORG_JUNIT_JUPITER_API_ASSERTIONS= "org.junit.jupiter.api.Assertions";
+ protected static final String ORG_JUNIT_ASSERT= "org.junit.Assert";
+ protected static final String ORG_JUNIT_BEFORECLASS= "org.junit.BeforeClass";
+ protected static final String ORG_JUNIT_JUPITER_API_BEFORE_ALL= "org.junit.jupiter.api.BeforeAll";
+ protected static final String ANNOTATION_BEFORE_ALL= "BeforeAll";
+ protected static final String ORG_JUNIT_IGNORE= "org.junit.Ignore";
+ protected static final String ORG_JUNIT_JUPITER_DISABLED= "org.junit.jupiter.api.Disabled";
+ protected static final String ANNOTATION_DISABLED= "Disabled";
+ protected static final String ORG_JUNIT_JUPITER_API_IO_TEMP_DIR= "org.junit.jupiter.api.io.TempDir";
+ protected static final String ORG_JUNIT_RULES_TEMPORARY_FOLDER= "org.junit.rules.TemporaryFolder";
+ protected static final String ORG_JUNIT_JUPITER_API_TEST_INFO= "org.junit.jupiter.api.TestInfo";
+ protected static final String ORG_JUNIT_RULES_TEST_NAME= "org.junit.rules.TestName";
+ protected static final String ORG_JUNIT_JUPITER_API_BEFORE_EACH= "org.junit.jupiter.api.BeforeEach";
+ protected static final String ORG_JUNIT_PLATFORM_SUITE_API_SELECT_CLASSES= "org.junit.platform.suite.api.SelectClasses";
+ protected static final String ANNOTATION_SELECT_CLASSES= "SelectClasses";
+ protected static final String ORG_JUNIT_RUNWITH= "org.junit.runner.RunWith";
+ protected static final String ORG_JUNIT_JUPITER_SUITE= "org.junit.platform.suite.api.Suite";
+ protected static final String ANNOTATION_SUITE= "Suite";
+ protected static final String ORG_JUNIT_SUITE= "org.junit.runners.Suite";
+ protected static final String ORG_JUNIT_SUITE_SUITECLASSES= "org.junit.runners.Suite.SuiteClasses";
+ protected static final String ORG_JUNIT_TEST= "org.junit.Test";
+ protected static final String ORG_JUNIT_JUPITER_TEST= "org.junit.jupiter.api.Test";
+ protected static final String ANNOTATION_TEST= "Test";
+ protected static final String ORG_JUNIT_JUPITER_API_ASSUMPTIONS= "org.junit.jupiter.api.Assumptions";
+ protected static final String ORG_JUNIT_ASSUME= "org.junit.Assume";
+ protected static final String ASSUMPTIONS= "Assumptions";
+
+ public static Collection getUsedVariableNames(ASTNode node) {
+ CompilationUnit root= (CompilationUnit) node.getRoot();
+ return new ScopeAnalyzer(root).getUsedVariableNames(node.getStartPosition(), node.getLength());
+ }
+
+ protected static boolean isOfType(ITypeBinding typeBinding, String typename) {
+ if (typeBinding == null) {
+ throw new AbortSearchException();
+ }
+ if (typeBinding.isArray()) {
+ typeBinding= typeBinding.getElementType();
+ }
+ return typeBinding.getQualifiedName().equals(typename);
+ }
+
+ private void adaptBeforeAfterCallsInTestClass(TypeDeclaration testClass, String fieldName, ASTRewrite rewriter,
+ AST ast, TextEditGroup group) {
+ testClass.accept(new ASTVisitor() {
+ @Override
+ public boolean visit(MethodInvocation node) {
+ if (node.getExpression() instanceof SimpleName
+ && ((SimpleName) node.getExpression()).getIdentifier().equals(fieldName)) {
+ String methodName= node.getName().getIdentifier();
+ if (METHOD_BEFORE.equals(methodName)) {
+ // Ersetze "before()" durch "beforeEach(context)"
+ rewriter.replace(node.getName(), ast.newSimpleName(METHOD_BEFORE_EACH), group);
+ addContextParameterIfMissing(node, rewriter, ast, group);
+ } else if (METHOD_AFTER.equals(methodName)) {
+ // Ersetze "after()" durch "afterEach()"
+ rewriter.replace(node.getName(), ast.newSimpleName(METHOD_AFTER_EACH), group);
+ }
+ }
+ return super.visit(node);
+ }
+ });
+ }
+
+ private void addContextParameterIfMissing(MethodInvocation node, ASTRewrite rewriter, AST ast,
+ TextEditGroup group) {
+ if (node.arguments().isEmpty()) {
+ ListRewrite argsRewrite= rewriter.getListRewrite(node, MethodInvocation.ARGUMENTS_PROPERTY);
+ argsRewrite.insertFirst(ast.newSimpleName("context"), group);
+ }
+ }
+
+ protected Optional getInnerTypeDeclaration(FieldDeclaration fieldDeclaration) {
+ for (Object fragment : fieldDeclaration.fragments()) {
+ if (fragment instanceof VariableDeclarationFragment) {
+ VariableDeclarationFragment variableFragment = (VariableDeclarationFragment) fragment;
+
+ // Prüfen, ob die Initialisierung eine anonyme Klasse ist
+ Expression initializer = variableFragment.getInitializer();
+ if (initializer instanceof ClassInstanceCreation) {
+ ClassInstanceCreation classInstance = (ClassInstanceCreation) initializer;
+
+ // Anonyme Klasse gefunden
+ if (classInstance.getAnonymousClassDeclaration() != null) {
+ return Optional.of(classInstance.getAnonymousClassDeclaration());
+ }
+
+ // Falls keine anonyme Klasse, den Typ der inneren Klasse prüfen
+ ITypeBinding typeBinding = classInstance.getType().resolveBinding();
+ if (typeBinding != null && typeBinding.isClass() && typeBinding.getJavaElement() instanceof IType) {
+ IType type = (IType) typeBinding.getJavaElement();
+ IJavaProject javaProject = type.getJavaProject();
+ String typeName = type.getElementName();
+
+ // Verwende nun den Projektnamen und den Typnamen
+ TypeDeclaration innerTypeDecl = findTypeDeclaration(javaProject, typeName);
+ if (innerTypeDecl != null) {
+ return Optional.of(innerTypeDecl);
+ }
+ }
+ }
+ }
+ }
+ return Optional.empty(); // Keine innere oder anonyme Klasse gefunden
+ }
+
+ protected void modifyExternalResourceClass(TypeDeclaration node, ASTRewrite rewriter, AST ast, TextEditGroup group,
+ ImportRewrite importRewriter) {
+ ITypeBinding binding= node.resolveBinding();
+ if (binding == null || !isExternalResource(binding)) {
+ return;
+ }
+ if (isDirectlyExtendingExternalResource(binding)) {
+ refactorToImplementCallbacks(node, rewriter, ast, group, importRewriter);
+ }
+ for (MethodDeclaration method : node.getMethods()) {
+ if (isLifecycleMethod(method, METHOD_BEFORE) || isLifecycleMethod(method, METHOD_AFTER)) {
+ setPublicVisibilityIfProtected(method, rewriter, ast, group);
+ String replacement= METHOD_BEFORE.equals(method.getName().getIdentifier()) ? METHOD_BEFORE_EACH
+ : METHOD_AFTER_EACH;
+ adaptSuperBeforeCalls(method.getName().getIdentifier(), replacement, method, rewriter, ast, group);
+ if (METHOD_BEFORE.equals(method.getName().getIdentifier())) {
+ removeThrowsThrowable(method, rewriter, group);
+ }
+ refactorMethod(rewriter, ast, method, replacement, group, importRewriter);
+ }
+ }
+// importRewriter.removeImport(ORG_JUNIT_RULE);
+ }
+
+ private void updateLifecycleMethods(TypeDeclaration typeDecl, ASTRewrite rewrite, AST ast, TextEditGroup group,
+ ImportRewrite importRewrite) {
+ for (MethodDeclaration method : typeDecl.getMethods()) {
+ String methodName= method.getName().getIdentifier();
+ if (METHOD_BEFORE.equals(methodName) || METHOD_AFTER.equals(methodName)) {
+ setPublicVisibilityIfProtected(method, rewrite, ast, group);
+ String replacement= METHOD_BEFORE.equals(methodName) ? METHOD_BEFORE_EACH : METHOD_AFTER_EACH;
+ adaptSuperBeforeCalls(methodName, replacement, method, rewrite, ast, group);
+ if (METHOD_BEFORE.equals(methodName)) {
+ removeThrowsThrowable(method, rewrite, group);
+ }
+ rewrite.replace(method.getName(), ast.newSimpleName(replacement), group);
+ ensureExtensionContextParameter(method, rewrite, ast, group, importRewrite);
+ }
+ }
+ }
+
+ private void setPublicVisibilityIfProtected(MethodDeclaration method, ASTRewrite rewrite, AST ast,
+ TextEditGroup group) {
+ // Durchlaufe die Modifiers und suche nach einem geschützten (protected)
+ // Modifier
+ for (Object modifier : method.modifiers()) {
+ if (modifier instanceof Modifier) {
+ Modifier mod= (Modifier) modifier;
+ if (mod.isProtected()) {
+ ListRewrite modifierRewrite= rewrite.getListRewrite(method, MethodDeclaration.MODIFIERS2_PROPERTY);
+ Modifier publicModifier= ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD);
+ modifierRewrite.replace(mod, publicModifier, group);
+ break; // Stoppe die Schleife, sobald der Modifier ersetzt wurde
+ }
+ }
+ }
+ }
+
+ private void adaptExternalResourceHierarchy(ITypeBinding typeBinding, ASTRewrite rewrite, AST ast,
+ ImportRewrite importRewrite, TextEditGroup group) {
+ while (typeBinding != null && isExternalResource(typeBinding)) {
+ TypeDeclaration typeDecl= findTypeDeclarationInProject(typeBinding);
+ if (typeDecl != null) {
+ adaptTypeDeclaration(typeDecl, rewrite, ast, importRewrite, group);
+ }
+ typeBinding= typeBinding.getSuperclass();
+ }
+ }
+
+ private TypeDeclaration findTypeDeclarationInProject(ITypeBinding typeBinding) {
+ IType type= (IType) typeBinding.getJavaElement();
+ return type != null ? findTypeDeclaration(type.getJavaProject(), type.getElementName()) : null;
+ }
+
+ private void adaptTypeDeclaration(TypeDeclaration typeDecl, ASTRewrite rewrite, AST ast,
+ ImportRewrite importRewrite, TextEditGroup group) {
+ removeSuperclassType(typeDecl, rewrite, group);
+ addBeforeAndAfterEachCallbacks(typeDecl, rewrite, ast, importRewrite, group);
+ updateLifecycleMethods(typeDecl, rewrite, ast, group, importRewrite);
+ importRewrite.addImport(ORG_JUNIT_JUPITER_API_EXTENSION_BEFORE_EACH_CALLBACK);
+ importRewrite.addImport(ORG_JUNIT_JUPITER_API_EXTENSION_AFTER_EACH_CALLBACK);
+ }
+
+ private void adaptSuperBeforeCalls(String vorher, String nachher, MethodDeclaration method, ASTRewrite rewriter,
+ AST ast, TextEditGroup group) {
+ method.accept(new ASTVisitor() {
+ @Override
+ public boolean visit(SuperMethodInvocation node) {
+ if (vorher.equals(node.getName().getIdentifier())) {
+ rewriter.replace(node.getName(), ast.newSimpleName(nachher), group);
+ addContextArgumentIfAbsent(node, rewriter, ast, group);
+ }
+ return super.visit(node);
+ }
+ });
+ }
+
+ private void addContextArgumentIfAbsent(SuperMethodInvocation node, ASTRewrite rewriter, AST ast,
+ TextEditGroup group) {
+ if (node.arguments().isEmpty()) {
+ rewriter.getListRewrite(node, SuperMethodInvocation.ARGUMENTS_PROPERTY)
+ .insertFirst(ast.newSimpleName(VARIABLE_NAME_CONTEXT), group);
+ }
+ }
+
+ private void addBeforeAndAfterEachCallbacks(TypeDeclaration typeDecl, ASTRewrite rewrite, AST ast,
+ ImportRewrite importRewrite, TextEditGroup group) {
+ ListRewrite listRewrite= rewrite.getListRewrite(typeDecl, TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY);
+ listRewrite.insertLast(ast.newSimpleType(ast.newName(BEFORE_EACH_CALLBACK)), group);
+ listRewrite.insertLast(ast.newSimpleType(ast.newName(AFTER_EACH_CALLBACK)), group);
+ }
+
+ protected void addExtendWithAnnotation(ASTRewrite rewrite, AST ast, TextEditGroup group,
+ ImportRewrite importRewriter, String className, FieldDeclaration field) {
+ TypeDeclaration parentClass= getParentTypeDeclaration(field);
+ if (parentClass == null) {
+ return;
+ }
+ SingleMemberAnnotation newAnnotation= ast.newSingleMemberAnnotation();
+ newAnnotation.setTypeName(ast.newName(ANNOTATION_EXTEND_WITH));
+ final TypeLiteral newTypeLiteral= ast.newTypeLiteral();
+ newTypeLiteral.setType(ast.newSimpleType(ast.newSimpleName(className)));
+ newAnnotation.setValue(newTypeLiteral);
+ ListRewrite modifierListRewrite= rewrite.getListRewrite(parentClass, TypeDeclaration.MODIFIERS2_PROPERTY);
+ modifierListRewrite.insertFirst(newAnnotation, group);
+ importRewriter.addImport(ORG_JUNIT_JUPITER_API_EXTENSION_EXTEND_WITH);
+ }
+
+ /**
+ * Adds an import to the class. This method should be used for every class
+ * reference added to the generated code.
+ *
+ * @param typeName a fully qualified name of a type
+ * @param cuRewrite CompilationUnitRewrite
+ * @param ast AST
+ * @return simple name of a class if the import was added and fully qualified
+ * name if there was a conflict
+ */
+ protected Name addImport(String typeName, final CompilationUnitRewrite cuRewrite, AST ast) {
+ String importedName= cuRewrite.getImportRewrite().addImport(typeName);
+ return ast.newName(importedName);
+ }
+
+ private void addInterfaceCallback(ListRewrite listRewrite, AST ast, String callbackName, TextEditGroup group) {
+ listRewrite.insertLast(ast.newSimpleType(ast.newName(callbackName)), group);
+ }
+
+ private void addRegisterExtensionAnnotation(FieldDeclaration field, ASTRewrite rewrite, AST ast,
+ ImportRewrite importRewrite, TextEditGroup group) {
+ MarkerAnnotation registerExtensionAnnotation= ast.newMarkerAnnotation();
+ registerExtensionAnnotation.setTypeName(ast.newName(ANNOTATION_REGISTER_EXTENSION));
+ rewrite.getListRewrite(field, FieldDeclaration.MODIFIERS2_PROPERTY).insertFirst(registerExtensionAnnotation,
+ group);
+ }
+
+ private void ensureExtensionContextParameter(MethodDeclaration method, ASTRewrite rewrite, AST ast,
+ TextEditGroup group, ImportRewrite importRewrite) {
+ boolean hasExtensionContext= method.parameters().stream()
+ .anyMatch(param -> param instanceof SingleVariableDeclaration
+ && ((SingleVariableDeclaration) param).getType().toString().equals(EXTENSION_CONTEXT));
+ if (!hasExtensionContext) {
+ SingleVariableDeclaration newParam= ast.newSingleVariableDeclaration();
+ newParam.setType(ast.newSimpleType(ast.newName(EXTENSION_CONTEXT)));
+ newParam.setName(ast.newSimpleName(VARIABLE_NAME_CONTEXT));
+ ListRewrite listRewrite= rewrite.getListRewrite(method, MethodDeclaration.PARAMETERS_PROPERTY);
+ listRewrite.insertLast(newParam, group);
+ importRewrite.addImport(ORG_JUNIT_JUPITER_API_EXTENSION_EXTENSION_CONTEXT);
+ }
+ }
+
+ public String extractClassNameFromField(FieldDeclaration field) {
+ for (Object fragmentObj : field.fragments()) {
+ VariableDeclarationFragment fragment= (VariableDeclarationFragment) fragmentObj;
+ Expression initializer= fragment.getInitializer();
+ if (initializer instanceof ClassInstanceCreation) {
+ ClassInstanceCreation creation= (ClassInstanceCreation) initializer;
+ Type createdType= creation.getType();
+ if (createdType instanceof QualifiedType) {
+ QualifiedType qualifiedType= (QualifiedType) createdType;
+ return extractQualifiedTypeName(qualifiedType);
+ } else if (createdType instanceof SimpleType) {
+ return ((SimpleType) createdType).getName().getFullyQualifiedName();
+ }
+ }
+ }
+ return null;
+ }
+
+ protected String extractQualifiedTypeName(QualifiedType qualifiedType) {
+ StringBuilder fullClassName= new StringBuilder(qualifiedType.getName().getFullyQualifiedName());
+ for (Type qualifier= qualifiedType
+ .getQualifier(); qualifier instanceof QualifiedType; qualifier= ((QualifiedType) qualifier)
+ .getQualifier()) {
+ fullClassName.insert(0, ".");
+ fullClassName.insert(0, ((QualifiedType) qualifier).getName().getFullyQualifiedName());
+ }
+ return fullClassName.toString();
+ }
+
+ public abstract void find(JUnitCleanUpFixCore fixcore, CompilationUnit compilationUnit,
+ Set operations, Set nodesprocessed);
+
+ public TypeDeclaration findTypeDeclaration(IJavaProject javaProject, String fullyQualifiedTypeName) {
+ try {
+ IType type= javaProject.findType(fullyQualifiedTypeName);
+ if (type != null && type.exists()) {
+ CompilationUnit unit= parseCompilationUnit(type.getCompilationUnit());
+ return (TypeDeclaration) unit.types().get(0);
+ }
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ protected TypeDeclaration getParentTypeDeclaration(ASTNode node) {
+ while (node != null && !(node instanceof TypeDeclaration)) {
+ node= node.getParent();
+ }
+ return (TypeDeclaration) node;
+ }
+
+ public abstract String getPreview(boolean afterRefactoring);
+
+ protected boolean hasDefaultConstructorOrNoConstructor(TypeDeclaration classNode) {
+ boolean hasConstructor= false;
+ for (Object bodyDecl : classNode.bodyDeclarations()) {
+ if (bodyDecl instanceof MethodDeclaration) {
+ MethodDeclaration method= (MethodDeclaration) bodyDecl;
+ if (method.isConstructor()) {
+ hasConstructor= true;
+ if (method.parameters().isEmpty() && method.getBody() != null
+ && method.getBody().statements().isEmpty()) {
+ return true;
+ }
+ }
+ }
+ }
+ return !hasConstructor;
+ }
+
+ private boolean isAnnotatedWithRule(BodyDeclaration declaration) {
+ for (Object modifier : declaration.modifiers()) {
+ if (modifier instanceof Annotation) {
+ Annotation annotation= (Annotation) modifier;
+ ITypeBinding binding= annotation.resolveTypeBinding();
+ if (binding != null && ORG_JUNIT_RULE.equals(binding.getQualifiedName())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public boolean isAnonymousClass(VariableDeclarationFragment fragmentObj) {
+ VariableDeclarationFragment fragment= fragmentObj;
+ Expression initializer= fragment.getInitializer();
+ if (initializer instanceof ClassInstanceCreation) {
+ ClassInstanceCreation classInstanceCreation= (ClassInstanceCreation) initializer;
+ AnonymousClassDeclaration anonymousClassDeclaration= classInstanceCreation.getAnonymousClassDeclaration();
+ if (anonymousClassDeclaration != null) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected boolean isDirect(ITypeBinding fieldTypeBinding) {
+ return ORG_JUNIT_RULES_EXTERNAL_RESOURCE.equals(fieldTypeBinding.getQualifiedName());
+ }
+
+ protected boolean isDirectlyExtendingExternalResource(ITypeBinding binding) {
+ return ORG_JUNIT_RULES_EXTERNAL_RESOURCE.equals(binding.getSuperclass().getQualifiedName());
+ }
+
+ private boolean isExternalResource(FieldDeclaration field) {
+ VariableDeclarationFragment fragment= (VariableDeclarationFragment) field.fragments().get(0);
+ ITypeBinding binding= fragment.resolveBinding().getType();
+ return isExternalResource(binding);
+ }
+
+ protected boolean isExternalResource(ITypeBinding typeBinding) {
+ while (typeBinding != null) {
+ if (ORG_JUNIT_RULES_EXTERNAL_RESOURCE.equals(typeBinding.getQualifiedName())) {
+ return true;
+ }
+ typeBinding= typeBinding.getSuperclass();
+ }
+ return false;
+ }
+
+ protected boolean isLifecycleMethod(MethodDeclaration method, String methodName) {
+ return method.getName().getIdentifier().equals(methodName);
+ }
+
+ private boolean isStringType(Expression expression) {
+ ITypeBinding typeBinding= expression.resolveTypeBinding();
+ return typeBinding != null && String.class.getCanonicalName().equals(typeBinding.getQualifiedName());
+ }
+
+ public void migrateRuleToRegisterExtensionAndAdaptHierarchy(Optional innerTypeDeclaration, TypeDeclaration testClass, ASTRewrite rewrite, AST ast,
+ ImportRewrite importRewrite, TextEditGroup group, String varname) {
+ if(innerTypeDeclaration.isPresent() && innerTypeDeclaration.get() instanceof TypeDeclaration) {
+ adaptBeforeAfterCallsInTestClass((TypeDeclaration) innerTypeDeclaration.get(), varname, rewrite, ast, group);
+ }
+ for (FieldDeclaration field : testClass.getFields()) {
+ if (isAnnotatedWithRule(field) && isExternalResource(field)) {
+ removeRuleAnnotation(field, rewrite, group, importRewrite);
+ addRegisterExtensionAnnotation(field, rewrite, ast, importRewrite, group);
+ importRewrite.addImport(ORG_JUNIT_JUPITER_API_EXTENSION_REGISTER_EXTENSION);
+ ITypeBinding fieldType= ((VariableDeclarationFragment) field.fragments().get(0)).resolveBinding()
+ .getType();
+ adaptExternalResourceHierarchy(fieldType, rewrite, ast, importRewrite, group);
+ }
+ }
+ }
+
+ private CompilationUnit parseCompilationUnit(ICompilationUnit iCompilationUnit) {
+ ASTParser parser= ASTParser.newParser(AST.getJLSLatest());
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
+ parser.setSource(iCompilationUnit);
+ parser.setResolveBindings(true);
+ return (CompilationUnit) parser.createAST(null);
+ }
+
+ public void process(Annotation node, IJavaProject jproject, ASTRewrite rewrite, AST ast, TextEditGroup group,
+ ImportRewrite importRewriter, CompilationUnit cu, String className) {
+ if (!ORG_JUNIT_RULE.equals(node.resolveTypeBinding().getQualifiedName())) {
+ return;
+ }
+ FieldDeclaration field= (FieldDeclaration) node.getParent();
+ ITypeBinding fieldTypeBinding= ((VariableDeclarationFragment) field.fragments().get(0)).resolveBinding()
+ .getType();
+ if (!isExternalResource(fieldTypeBinding) || fieldTypeBinding.isAnonymous()) {
+ return;
+ }
+ if (isDirect(fieldTypeBinding)) {
+ rewrite.remove(field, group);
+ importRewriter.removeImport(ORG_JUNIT_RULE);
+ }
+ addExtendWithAnnotation(rewrite, ast, group, importRewriter, className, field);
+ importRewriter.removeImport(ORG_JUNIT_RULES_EXTERNAL_RESOURCE);
+ }
+
+ private void refactorMethod(ASTRewrite rewriter, AST ast, MethodDeclaration method, String newMethodName,
+ TextEditGroup group, ImportRewrite importRewriter) {
+ rewriter.replace(method.getName(), ast.newSimpleName(newMethodName), group);
+ ensureExtensionContextParameter(method, rewriter, ast, group, importRewriter);
+ }
+
+ private void refactorToImplementCallbacks(TypeDeclaration node, ASTRewrite rewriter, AST ast, TextEditGroup group,
+ ImportRewrite importRewriter) {
+ rewriter.remove(node.getSuperclassType(), group);
+ importRewriter.removeImport(ORG_JUNIT_RULES_EXTERNAL_RESOURCE);
+ ListRewrite listRewrite= rewriter.getListRewrite(node, TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY);
+ addInterfaceCallback(listRewrite, ast, BEFORE_EACH_CALLBACK, group);
+ addInterfaceCallback(listRewrite, ast, AFTER_EACH_CALLBACK, group);
+ importRewriter.addImport(ORG_JUNIT_JUPITER_API_EXTENSION_BEFORE_EACH_CALLBACK);
+ importRewriter.addImport(ORG_JUNIT_JUPITER_API_EXTENSION_AFTER_EACH_CALLBACK);
+ }
+
+ private void removeRuleAnnotation(BodyDeclaration declaration, ASTRewrite rewriter, TextEditGroup group,
+ ImportRewrite importRewriter) {
+ List> modifiers= declaration.modifiers();
+ for (Object modifier : modifiers) {
+ if (modifier instanceof Annotation) {
+ Annotation annotation= (Annotation) modifier;
+ ITypeBinding binding= annotation.resolveTypeBinding();
+ if (binding != null && binding.getQualifiedName().equals(ORG_JUNIT_RULE)) {
+ rewriter.remove(annotation, group);
+ importRewriter.removeImport(ORG_JUNIT_RULE);
+ break;
+ }
+ }
+ }
+ }
+
+ private void removeSuperclassType(TypeDeclaration typeDecl, ASTRewrite rewrite, TextEditGroup group) {
+ if (typeDecl.getSuperclassType() != null) {
+ rewrite.remove(typeDecl.getSuperclassType(), group);
+ }
+ }
+
+ private void removeThrowsThrowable(MethodDeclaration method, ASTRewrite rewriter, TextEditGroup group) {
+ List> thrownExceptionTypes= method.thrownExceptionTypes();
+ for (Object exceptionType : thrownExceptionTypes) {
+ if (exceptionType instanceof SimpleType) {
+ SimpleType exception= (SimpleType) exceptionType;
+ if ("Throwable".equals(exception.getName().getFullyQualifiedName())) {
+ ListRewrite listRewrite= rewriter.getListRewrite(method,
+ MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY);
+ listRewrite.remove(exception, group);
+ }
+ }
+ }
+ }
+
+ private void reorderParameters(ASTRewrite rewriter, MethodInvocation node, TextEditGroup group, int... order) {
+ ListRewrite listRewrite= rewriter.getListRewrite(node, MethodInvocation.ARGUMENTS_PROPERTY);
+ List arguments= node.arguments();
+ Expression[] newArguments= new Expression[arguments.size()];
+ for (int i= 0; i < order.length; i++) {
+ newArguments[i]= (Expression) ASTNode.copySubtree(node.getAST(), arguments.get(order[i]));
+ }
+ if (!isStringType(arguments.get(0))) {
+ return;
+ }
+ for (int i= 0; i < arguments.size(); i++) {
+ listRewrite.replace(arguments.get(i), newArguments[i], group);
+ }
+ }
+
+ public void reorderParameters(MethodInvocation node, ASTRewrite rewriter, TextEditGroup group, Set oneparam,
+ Set twoparam) {
+ String methodName= node.getName().getIdentifier();
+ List arguments= node.arguments();
+ switch (arguments.size()) {
+ case 2:
+ if (oneparam.contains(methodName)) {
+ reorderParameters(rewriter, node, group, 1, 0);
+ }
+ break;
+ case 3:
+ if (twoparam.contains(methodName)) {
+ reorderParameters(rewriter, node, group, 1, 2, 0); // expected, actual, message
+ }
+ break;
+ case 4:
+ reorderParameters(rewriter, node, group, 1, 2, 3, 0); // expected, actual, delta, message
+ break;
+ default:
+ break;
+ }
+ }
+
+ public abstract void rewrite(JUnitCleanUpFixCore useExplicitEncodingFixCore, T holder,
+ CompilationUnitRewrite cuRewrite, TextEditGroup group);
+
+ protected void refactorTestname(TextEditGroup group, ASTRewrite rewriter, AST ast, ImportRewrite importrewriter,
+ FieldDeclaration node) {
+ rewriter.remove(node, group);
+ TypeDeclaration parentClass= (TypeDeclaration) node.getParent();
+ addBeforeEachInitMethod(parentClass, rewriter, group);
+ addTestNameField(parentClass, rewriter, group);
+ for (MethodDeclaration method : parentClass.getMethods()) {
+ if (method.getBody() != null) {
+ method.getBody().accept(new ASTVisitor() {
+ @Override
+ public boolean visit(MethodInvocation node) {
+ if (node.getExpression() != null && node.getExpression().resolveTypeBinding().getQualifiedName()
+ .equals(ORG_JUNIT_RULES_TEST_NAME)) {
+ SimpleName newFieldAccess= ast.newSimpleName(TEST_NAME);
+ rewriter.replace(node, newFieldAccess, group);
+ }
+ return super.visit(node);
+ }
+ });
+ }
+ }
+ importrewriter.addImport(ORG_JUNIT_JUPITER_API_TEST_INFO);
+ importrewriter.addImport(ORG_JUNIT_JUPITER_API_BEFORE_EACH);
+ importrewriter.removeImport(ORG_JUNIT_RULE);
+ importrewriter.removeImport(ORG_JUNIT_RULES_TEST_NAME);
+ }
+
+ private void addTestNameField(TypeDeclaration parentClass, ASTRewrite rewriter, TextEditGroup group) {
+ AST ast= parentClass.getAST();
+ VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
+ fragment.setName(ast.newSimpleName(TEST_NAME));
+
+ FieldDeclaration fieldDeclaration= ast.newFieldDeclaration(fragment);
+ fieldDeclaration.setType(ast.newSimpleType(ast.newName("String")));
+ fieldDeclaration.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD));
+
+ ListRewrite listRewrite= rewriter.getListRewrite(parentClass, TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
+ listRewrite.insertFirst(fieldDeclaration, group);
+ }
+
+ private void addBeforeEachInitMethod(TypeDeclaration parentClass, ASTRewrite rewriter, TextEditGroup group) {
+ AST ast= parentClass.getAST();
+
+ MethodDeclaration methodDeclaration= ast.newMethodDeclaration();
+ methodDeclaration.setName(ast.newSimpleName("init"));
+ methodDeclaration.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID));
+
+ SingleVariableDeclaration param= ast.newSingleVariableDeclaration();
+ param.setType(ast.newSimpleType(ast.newName("TestInfo")));
+ param.setName(ast.newSimpleName("testInfo"));
+ methodDeclaration.parameters().add(param);
+
+ Block body= ast.newBlock();
+ Assignment assignment= ast.newAssignment();
+ FieldAccess fieldAccess= ast.newFieldAccess();
+ fieldAccess.setExpression(ast.newThisExpression());
+ fieldAccess.setName(ast.newSimpleName(TEST_NAME));
+ assignment.setLeftHandSide(fieldAccess);
+
+ MethodInvocation methodInvocation= ast.newMethodInvocation();
+ methodInvocation.setExpression(ast.newSimpleName("testInfo"));
+ methodInvocation.setName(ast.newSimpleName("getDisplayName"));
+
+ assignment.setRightHandSide(methodInvocation);
+
+ ExpressionStatement statement= ast.newExpressionStatement(assignment);
+ body.statements().add(statement);
+ methodDeclaration.setBody(body);
+
+ MarkerAnnotation beforeEachAnnotation= ast.newMarkerAnnotation();
+ beforeEachAnnotation.setTypeName(ast.newName("BeforeEach"));
+
+ ListRewrite listRewrite= rewriter.getListRewrite(parentClass, TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
+ listRewrite.insertFirst(methodDeclaration, group);
+
+ listRewrite= rewriter.getListRewrite(methodDeclaration, MethodDeclaration.MODIFIERS2_PROPERTY);
+ listRewrite.insertFirst(beforeEachAnnotation, group);
+ }
+
+ private List getAllSubclasses(ITypeBinding typeBinding) {
+ List subclasses= new ArrayList<>();
+
+ try {
+ // Erzeuge den entsprechenden IType des gegebenen ITypeBindings
+ IType type= (IType) typeBinding.getJavaElement();
+
+ // Erzeuge die Typ-Hierarchie für den übergebenen Typ innerhalb des Projekts
+ ITypeHierarchy typeHierarchy= type.newTypeHierarchy(null); // null verwendet das gesamte Projekt
+
+ // Durchlaufe alle direkten und indirekten Subtypen und füge sie der Liste hinzu
+ for (IType subtype : typeHierarchy.getAllSubtypes(type)) {
+ ITypeBinding subtypeBinding= (ITypeBinding) subtype.getAdapter(ITypeBinding.class);
+ if (subtypeBinding != null) {
+ subclasses.add(subtypeBinding);
+ }
+ }
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+ return subclasses;
+ }
+
+ protected void refactorTestnameInClassAndSubclasses(TextEditGroup group, ASTRewrite rewriter, AST ast,
+ ImportRewrite importRewrite, FieldDeclaration node) {
+ // Refactoring in der aktuellen Klasse
+ refactorTestnameInClass(group, rewriter, ast, importRewrite, node);
+
+ // Ermittlung aller abgeleiteten Klassen
+ ITypeBinding typeBinding= ((TypeDeclaration) node.getParent()).resolveBinding();
+ List subclasses= getAllSubclasses(typeBinding);
+
+ for (ITypeBinding subclassBinding : subclasses) {
+ IType subclassType= (IType) subclassBinding.getJavaElement();
+
+ // Hole die AST-Darstellung der Subklasse (zum Beispiel durch ASTParser)
+ CompilationUnit subclassUnit= parseCompilationUnit(subclassType.getCompilationUnit());
+ subclassUnit.accept(new ASTVisitor() {
+ @Override
+ public boolean visit(TypeDeclaration subclassNode) {
+ if (subclassNode.resolveBinding().equals(subclassBinding)) {
+ refactorTestnameInClass(group, rewriter, subclassNode.getAST(), importRewrite, node);
+ }
+ return false; // Nur das passende Typ-Deklarations-Element verarbeiten
+ }
+ });
+ }
+ }
+
+ protected void refactorTestnameInClass(TextEditGroup group, ASTRewrite rewriter, AST ast,
+ ImportRewrite importRewrite, FieldDeclaration node) {
+ // Entferne das alte TestName-Feld
+ rewriter.remove(node, group);
+
+ // Füge ein neues TestName-Feld hinzu und erzeuge eine BeforeEach-Init-Methode
+ TypeDeclaration parentClass= (TypeDeclaration) node.getParent();
+ addBeforeEachInitMethod(parentClass, rewriter, group);
+ addTestNameField(parentClass, rewriter, group);
+
+ // Ersetze alle Zugriffe auf das alte TestName-Feld durch das neue Feld
+ // "testName"
+ for (MethodDeclaration method : parentClass.getMethods()) {
+ if (method.getBody() != null) {
+ method.getBody().accept(new ASTVisitor() {
+ @Override
+ public boolean visit(MethodInvocation node) {
+ // Prüfen, ob der Aufruf auf das alte TestName-Feld verweist
+ if (node.getExpression() != null && ORG_JUNIT_RULES_TEST_NAME
+ .equals(node.getExpression().resolveTypeBinding().getQualifiedName())) {
+ // Ersetze den Zugriff durch "testName"
+ SimpleName newFieldAccess= ast.newSimpleName(TEST_NAME);
+ rewriter.replace(node, newFieldAccess, group);
+ }
+ return super.visit(node);
+ }
+ });
+ }
+ }
+
+ // Importanpassungen für JUnit 5
+ importRewrite.addImport(ORG_JUNIT_JUPITER_API_TEST_INFO);
+ importRewrite.addImport(ORG_JUNIT_JUPITER_API_BEFORE_EACH);
+ importRewrite.removeImport(ORG_JUNIT_RULE);
+ importRewrite.removeImport(ORG_JUNIT_RULES_TEST_NAME);
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AfterClassJUnitPlugin.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AfterClassJUnitPlugin.java
new file mode 100644
index 00000000..873b592d
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AfterClassJUnitPlugin.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.corext.fix.helper;
+
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.MarkerAnnotation;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.internal.corext.dom.ASTNodes;
+import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
+import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
+import org.eclipse.text.edits.TextEditGroup;
+import org.sandbox.jdt.internal.common.HelperVisitor;
+import org.sandbox.jdt.internal.common.ReferenceHolder;
+import org.sandbox.jdt.internal.corext.fix.JUnitCleanUpFixCore;
+
+/**
+ *
+ *
+ */
+public class AfterClassJUnitPlugin extends AbstractTool> {
+
+ @Override
+ public void find(JUnitCleanUpFixCore fixcore, CompilationUnit compilationUnit,
+ Set operations, Set nodesprocessed) {
+ ReferenceHolder dataholder= new ReferenceHolder<>();
+ HelperVisitor.callMarkerAnnotationVisitor(ORG_JUNIT_AFTERCLASS, compilationUnit, dataholder, nodesprocessed,
+ (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder));
+ }
+
+ private boolean processFoundNode(JUnitCleanUpFixCore fixcore,
+ Set operations, MarkerAnnotation node,
+ ReferenceHolder dataholder) {
+ JunitHolder mh= new JunitHolder();
+ mh.minv= node;
+ mh.minvname= node.getTypeName().getFullyQualifiedName();
+ dataholder.put(dataholder.size(), mh);
+ operations.add(fixcore.rewrite(dataholder));
+ return false;
+ }
+
+ @Override
+ public void rewrite(JUnitCleanUpFixCore upp, final ReferenceHolder hit,
+ final CompilationUnitRewrite cuRewrite, TextEditGroup group) {
+ ASTRewrite rewrite= cuRewrite.getASTRewrite();
+ AST ast= cuRewrite.getRoot().getAST();
+ ImportRewrite importRewriter= cuRewrite.getImportRewrite();
+ for (Entry entry : hit.entrySet()) {
+ JunitHolder mh= entry.getValue();
+ Annotation minv= mh.getAnnotation();
+ MarkerAnnotation newAnnotation= ast.newMarkerAnnotation();
+ newAnnotation.setTypeName(ast.newSimpleName(ANNOTATION_AFTER_ALL));
+ importRewriter.addImport(ORG_JUNIT_JUPITER_API_AFTER_ALL);
+ ASTNodes.replaceButKeepComment(rewrite, minv, newAnnotation, group);
+ importRewriter.removeImport(ORG_JUNIT_AFTERCLASS);
+ }
+ }
+
+ @Override
+ public String getPreview(boolean afterRefactoring) {
+ if (afterRefactoring) {
+ return """
+ @AfterAll
+ public static void tearDownAfterClass() throws Exception {
+ }
+ """; //$NON-NLS-1$
+ }
+ return """
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ } ;
+ """; //$NON-NLS-1$
+ }
+
+ @Override
+ public String toString() {
+ return "AfterClass"; //$NON-NLS-1$
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AfterJUnitPlugin.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AfterJUnitPlugin.java
new file mode 100644
index 00000000..93aaa456
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AfterJUnitPlugin.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.corext.fix.helper;
+
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.MarkerAnnotation;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.internal.corext.dom.ASTNodes;
+import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
+import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
+import org.eclipse.text.edits.TextEditGroup;
+import org.sandbox.jdt.internal.common.HelperVisitor;
+import org.sandbox.jdt.internal.common.ReferenceHolder;
+import org.sandbox.jdt.internal.corext.fix.JUnitCleanUpFixCore;
+
+/**
+ *
+ *
+ */
+public class AfterJUnitPlugin extends AbstractTool> {
+
+ @Override
+ public void find(JUnitCleanUpFixCore fixcore, CompilationUnit compilationUnit,
+ Set operations, Set nodesprocessed) {
+ ReferenceHolder dataholder= new ReferenceHolder<>();
+ HelperVisitor.callMarkerAnnotationVisitor(ORG_JUNIT_AFTER, compilationUnit, dataholder, nodesprocessed,
+ (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder));
+ }
+
+ private boolean processFoundNode(JUnitCleanUpFixCore fixcore,
+ Set operations, MarkerAnnotation node,
+ ReferenceHolder dataholder) {
+ JunitHolder mh= new JunitHolder();
+ mh.minv= node;
+ mh.minvname= node.getTypeName().getFullyQualifiedName();
+ dataholder.put(dataholder.size(), mh);
+ operations.add(fixcore.rewrite(dataholder));
+ return false;
+ }
+
+ @Override
+ public void rewrite(JUnitCleanUpFixCore upp, final ReferenceHolder hit,
+ final CompilationUnitRewrite cuRewrite, TextEditGroup group) {
+ ASTRewrite rewrite= cuRewrite.getASTRewrite();
+ AST ast= cuRewrite.getRoot().getAST();
+ ImportRewrite importRewriter= cuRewrite.getImportRewrite();
+ for (Entry entry : hit.entrySet()) {
+ JunitHolder mh= entry.getValue();
+ Annotation minv= mh.getAnnotation();
+ MarkerAnnotation newAnnotation= ast.newMarkerAnnotation();
+ newAnnotation.setTypeName(ast.newSimpleName(ANNOTATION_AFTER_EACH));
+ importRewriter.addImport(ORG_JUNIT_JUPITER_API_AFTER_EACH);
+ ASTNodes.replaceButKeepComment(rewrite, minv, newAnnotation, group);
+ importRewriter.removeImport(ORG_JUNIT_AFTER);
+ }
+ }
+
+ @Override
+ public String getPreview(boolean afterRefactoring) {
+ if (afterRefactoring) {
+ return """
+ @AfterEach
+ public void tearDown() throws Exception {
+ }
+ """; //$NON-NLS-1$
+ }
+ return """
+ @After
+ public void tearDown() throws Exception {
+ } ;
+ """; //$NON-NLS-1$
+ }
+
+ @Override
+ public String toString() {
+ return "After"; //$NON-NLS-1$
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AssertJUnitPlugin.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AssertJUnitPlugin.java
new file mode 100644
index 00000000..c8b0fd07
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AssertJUnitPlugin.java
@@ -0,0 +1,156 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.corext.fix.helper;
+
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
+import org.eclipse.jdt.internal.corext.dom.ASTNodes;
+import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
+import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
+import org.eclipse.text.edits.TextEditGroup;
+import org.sandbox.jdt.internal.common.HelperVisitor;
+import org.sandbox.jdt.internal.common.ReferenceHolder;
+import org.sandbox.jdt.internal.corext.fix.JUnitCleanUpFixCore;
+
+/**
+ *
+ *
+ */
+public class AssertJUnitPlugin extends AbstractTool> {
+
+ static final Set twoparam= Set.of("assertEquals", "assertNotEquals", "assertArrayEquals",
+ "assertSame","assertNotSame","assertThat");
+ static final Set oneparam= Set.of("assertTrue", "assertFalse", "assertNull", "assertNotNull");
+ private static final Set noparam= Set.of("fail");
+ private static final Set allassertionmethods= Stream.of(twoparam, oneparam, noparam).flatMap(Set::stream)
+ .collect(Collectors.toSet());
+
+ @Override
+ public void find(JUnitCleanUpFixCore fixcore, CompilationUnit compilationUnit,
+ Set operations, Set nodesprocessed) {
+ ReferenceHolder dataholder= new ReferenceHolder<>();
+ allassertionmethods.forEach(assertionmethod -> {
+ HelperVisitor.callMethodInvocationVisitor(ORG_JUNIT_ASSERT, assertionmethod, compilationUnit, dataholder,
+ nodesprocessed, (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder));
+ });
+ allassertionmethods.forEach(assertionmethod -> {
+ HelperVisitor.callImportDeclarationVisitor(ORG_JUNIT_ASSERT + "." + assertionmethod, compilationUnit,
+ dataholder, nodesprocessed,
+ (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder));
+ });
+ HelperVisitor.callImportDeclarationVisitor(ORG_JUNIT_ASSERT, compilationUnit, dataholder, nodesprocessed,
+ (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder));
+ }
+
+ private boolean processFoundNode(JUnitCleanUpFixCore fixcore,
+ Set operations, ASTNode node,
+ ReferenceHolder dataholder) {
+ JunitHolder mh= new JunitHolder();
+ mh.minv= node;
+ dataholder.put(dataholder.size(), mh);
+ operations.add(fixcore.rewrite(dataholder));
+ return false;
+ }
+
+ @Override
+ public void rewrite(JUnitCleanUpFixCore upp, final ReferenceHolder hit,
+ final CompilationUnitRewrite cuRewrite, TextEditGroup group) {
+ ASTRewrite rewrite= cuRewrite.getASTRewrite();
+ AST ast= cuRewrite.getRoot().getAST();
+ ImportRewrite importRewrite= cuRewrite.getImportRewrite();
+ for (Entry entry : hit.entrySet()) {
+ JunitHolder mh= entry.getValue();
+ if (mh.minv instanceof MethodInvocation) {
+ MethodInvocation node= mh.getMethodInvocation();
+ Expression assertexpression= node.getExpression();
+ if ("assertThat".equals(node.getName().getIdentifier()) &&
+ assertexpression instanceof SimpleName &&
+ "Assert".equals(((SimpleName) assertexpression).getIdentifier())) {
+ rewrite.set(node, MethodInvocation.EXPRESSION_PROPERTY, null, group);
+ importRewrite.addStaticImport("org.hamcrest.MatcherAssert", "assertThat", false);
+ importRewrite.removeImport("org.junit.Assert");
+ if (node.arguments().size() == 3) {
+ Expression errorMessage = (Expression) node.arguments().get(0);
+ Expression actualValue = (Expression) node.arguments().get(1);
+ Expression matcher = (Expression) node.arguments().get(2);
+ ListRewrite argumentRewrite = rewrite.getListRewrite(node, MethodInvocation.ARGUMENTS_PROPERTY);
+ argumentRewrite.replace((ASTNode) node.arguments().get(0), errorMessage, group);
+ argumentRewrite.replace((ASTNode) node.arguments().get(1), actualValue, group);
+ argumentRewrite.replace((ASTNode) node.arguments().get(2), matcher, group);
+ }
+ } else {
+ reorderParameters(node, rewrite, group, oneparam, twoparam);
+ SimpleName newQualifier= ast.newSimpleName(ASSERTIONS);
+ Expression expression= assertexpression;
+ if (expression != null) {
+ ASTNodes.replaceButKeepComment(rewrite, expression, newQualifier, group);
+ }
+ }
+ } else {
+ changeImportDeclaration(mh.getImportDeclaration(), importRewrite, group);
+ }
+ }
+ }
+
+ public void changeImportDeclaration(ImportDeclaration node, ImportRewrite importRewriter, TextEditGroup group) {
+ String importName= node.getName().getFullyQualifiedName();
+ if (node.isStatic() && importName.equals(ORG_JUNIT_ASSERT)) {
+ importRewriter.removeStaticImport(ORG_JUNIT_ASSERT + ".*");
+ importRewriter.addStaticImport(ORG_JUNIT_JUPITER_API_ASSERTIONS, "*", false);
+ return;
+ }
+ if (importName.equals(ORG_JUNIT_ASSERT)) {
+ importRewriter.removeImport(ORG_JUNIT_ASSERT);
+ importRewriter.addImport(ORG_JUNIT_JUPITER_API_ASSERTIONS);
+ return;
+ }
+ if (node.isStatic() && importName.startsWith(ORG_JUNIT_ASSERT + ".")) {
+ String methodName= importName.substring((ORG_JUNIT_ASSERT + ".").length());
+ importRewriter.removeStaticImport(ORG_JUNIT_ASSERT + "." + methodName);
+ importRewriter.addStaticImport(ORG_JUNIT_JUPITER_API_ASSERTIONS, methodName, false);
+ }
+ }
+
+ @Override
+ public String getPreview(boolean afterRefactoring) {
+ if (afterRefactoring) {
+ return """
+ Assertions.assertNotEquals(5,result, "failuremessage"); // expected = 5, actual = result
+ Assertions.assertTrue(false,"failuremessage");
+ """; //$NON-NLS-1$
+ }
+ return """
+ Assert.assertNotEquals("failuremessage",5, result); // expected = 5, actual = result
+ Assert.assertTrue("failuremessage",false);
+ """; //$NON-NLS-1$
+ }
+
+ @Override
+ public String toString() {
+ return "Assert"; //$NON-NLS-1$
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AssumeJUnitPlugin.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AssumeJUnitPlugin.java
new file mode 100644
index 00000000..02382e18
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AssumeJUnitPlugin.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.corext.fix.helper;
+
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.IMethodBinding;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.internal.corext.dom.ASTNodes;
+import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
+import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
+import org.eclipse.text.edits.TextEditGroup;
+import org.sandbox.jdt.internal.common.HelperVisitor;
+import org.sandbox.jdt.internal.common.ReferenceHolder;
+import org.sandbox.jdt.internal.corext.fix.JUnitCleanUpFixCore;
+
+/**
+ *
+ *
+ */
+public class AssumeJUnitPlugin extends AbstractTool> {
+
+ private static final Set twoparam= Set.of("assumeTrue", "assumeFalse", "assumeNotNull","assumeThat");
+ private static final Set oneparam= Set.of("assumeTrue", "assumeFalse", "assumeNotNull");
+ private static final Set allassumemethods= Stream.of(twoparam, oneparam).flatMap(Set::stream)
+ .collect(Collectors.toSet());
+
+ @Override
+ public void find(JUnitCleanUpFixCore fixcore, CompilationUnit compilationUnit,
+ Set operations, Set nodesprocessed) {
+ ReferenceHolder dataholder= new ReferenceHolder<>();
+ allassumemethods.forEach(assertionmethod -> {
+ HelperVisitor.callMethodInvocationVisitor(ORG_JUNIT_ASSUME, assertionmethod, compilationUnit, dataholder,
+ nodesprocessed, (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder));
+ });
+ allassumemethods.forEach(assertionmethod -> {
+ HelperVisitor.callImportDeclarationVisitor(ORG_JUNIT_ASSUME + "." + assertionmethod, compilationUnit,
+ dataholder, nodesprocessed,
+ (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder));
+ });
+ HelperVisitor.callImportDeclarationVisitor(ORG_JUNIT_ASSUME, compilationUnit, dataholder, nodesprocessed,
+ (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder));
+ }
+
+ private boolean processFoundNode(JUnitCleanUpFixCore fixcore,
+ Set operations, ASTNode node,
+ ReferenceHolder dataholder) {
+ JunitHolder mh= new JunitHolder();
+ mh.minv= node;
+ dataholder.put(dataholder.size(), mh);
+ operations.add(fixcore.rewrite(dataholder));
+ return false;
+ }
+
+ @Override
+ public void rewrite(JUnitCleanUpFixCore upp, final ReferenceHolder hit,
+ final CompilationUnitRewrite cuRewrite, TextEditGroup group) {
+ ASTRewrite rewrite= cuRewrite.getASTRewrite();
+ AST ast= cuRewrite.getRoot().getAST();
+ ImportRewrite importRewriter= cuRewrite.getImportRewrite();
+ for (Entry entry : hit.entrySet()) {
+ JunitHolder mh= entry.getValue();
+ if (mh.minv instanceof MethodInvocation) {
+ MethodInvocation minv= mh.getMethodInvocation();
+ if ("assumeThat".equals(minv.getName().getIdentifier()) && isJUnitAssume(minv)) {
+ importRewriter.addStaticImport("org.hamcrest.junit.MatcherAssume", "assumeThat", true);
+ importRewriter.removeStaticImport("org.junit.Assume.assumeThat");
+ MethodInvocation newAssumeThatCall = ast.newMethodInvocation();
+ newAssumeThatCall.setName(ast.newSimpleName("assumeThat"));
+ for (Object arg : minv.arguments()) {
+ newAssumeThatCall.arguments().add(rewrite.createCopyTarget((ASTNode) arg));
+ }
+ ASTNodes.replaceButKeepComment(rewrite,minv, newAssumeThatCall, group);
+ } else {
+ reorderParameters(minv, rewrite, group, oneparam, twoparam);
+ SimpleName newQualifier= ast.newSimpleName(ASSUMPTIONS);
+ Expression expression= minv.getExpression();
+ if (expression != null) {
+ ASTNodes.replaceButKeepComment(rewrite, expression, newQualifier, group);
+ }
+ }
+ } else {
+ changeImportDeclaration(mh.getImportDeclaration(), importRewriter, group);
+ }
+ }
+ }
+
+ // Helper-Methode, um zu prüfen, ob `assumeThat` zu `org.junit.Assume` gehört
+ private boolean isJUnitAssume(MethodInvocation node) {
+ IMethodBinding binding = node.resolveMethodBinding();
+ return binding != null && ORG_JUNIT_ASSUME.equals(binding.getDeclaringClass().getQualifiedName());
+ }
+
+ public void changeImportDeclaration(ImportDeclaration node, ImportRewrite importRewriter, TextEditGroup group) {
+ String importName= node.getName().getFullyQualifiedName();
+ if (node.isStatic() && importName.equals(ORG_JUNIT_ASSUME)) {
+ importRewriter.removeStaticImport(ORG_JUNIT_ASSUME + ".*");
+ importRewriter.addStaticImport(ORG_JUNIT_JUPITER_API_ASSUMPTIONS, "*", false);
+ return;
+ }
+ if (importName.equals(ORG_JUNIT_ASSUME)) {
+ importRewriter.removeImport(ORG_JUNIT_ASSUME);
+ importRewriter.addImport(ORG_JUNIT_JUPITER_API_ASSUMPTIONS);
+ return;
+ }
+ if (node.isStatic() && importName.startsWith(ORG_JUNIT_ASSUME + ".")) {
+ String methodName= importName.substring((ORG_JUNIT_ASSUME + ".").length());
+ importRewriter.removeStaticImport(ORG_JUNIT_ASSUME + "." + methodName);
+ importRewriter.addStaticImport(ORG_JUNIT_JUPITER_API_ASSUMPTIONS, methodName, false);
+ }
+ }
+
+ @Override
+ public String getPreview(boolean afterRefactoring) {
+ if (afterRefactoring) {
+ return """
+ Assumptions.assumeNotNull(object,"failuremessage");
+ Assumptions.assertTrue(condition,"failuremessage");
+ """; //$NON-NLS-1$
+ }
+ return """
+ Assume.assumeNotNull("failuremessage", object);
+ Assume.assertTrue("failuremessage",condition);
+ """; //$NON-NLS-1$
+ }
+
+ @Override
+ public String toString() {
+ return "Assume"; //$NON-NLS-1$
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/BeforeClassJUnitPlugin.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/BeforeClassJUnitPlugin.java
new file mode 100644
index 00000000..8e924553
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/BeforeClassJUnitPlugin.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.corext.fix.helper;
+
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.MarkerAnnotation;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.internal.corext.dom.ASTNodes;
+import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
+import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
+import org.eclipse.text.edits.TextEditGroup;
+import org.sandbox.jdt.internal.common.HelperVisitor;
+import org.sandbox.jdt.internal.common.ReferenceHolder;
+import org.sandbox.jdt.internal.corext.fix.JUnitCleanUpFixCore;
+
+/**
+ *
+ *
+ */
+public class BeforeClassJUnitPlugin extends AbstractTool> {
+
+ @Override
+ public void find(JUnitCleanUpFixCore fixcore, CompilationUnit compilationUnit,
+ Set operations, Set nodesprocessed) {
+ ReferenceHolder dataholder= new ReferenceHolder<>();
+ HelperVisitor.callMarkerAnnotationVisitor(ORG_JUNIT_BEFORECLASS, compilationUnit, dataholder, nodesprocessed,
+ (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder));
+ }
+
+ private boolean processFoundNode(JUnitCleanUpFixCore fixcore,
+ Set operations, MarkerAnnotation node,
+ ReferenceHolder dataholder) {
+ JunitHolder mh= new JunitHolder();
+ mh.minv= node;
+ mh.minvname= node.getTypeName().getFullyQualifiedName();
+ dataholder.put(dataholder.size(), mh);
+ operations.add(fixcore.rewrite(dataholder));
+ return false;
+ }
+
+ @Override
+ public void rewrite(JUnitCleanUpFixCore upp, final ReferenceHolder hit,
+ final CompilationUnitRewrite cuRewrite, TextEditGroup group) {
+ ASTRewrite rewrite= cuRewrite.getASTRewrite();
+ AST ast= cuRewrite.getRoot().getAST();
+ ImportRewrite importRewriter= cuRewrite.getImportRewrite();
+ for (Entry entry : hit.entrySet()) {
+ JunitHolder mh= entry.getValue();
+ Annotation minv= mh.getAnnotation();
+ MarkerAnnotation newAnnotation= ast.newMarkerAnnotation();
+ newAnnotation.setTypeName(ast.newSimpleName(ANNOTATION_BEFORE_ALL));
+ importRewriter.addImport(ORG_JUNIT_JUPITER_API_BEFORE_ALL);
+ ASTNodes.replaceButKeepComment(rewrite, minv, newAnnotation, group);
+ importRewriter.removeImport(ORG_JUNIT_BEFORECLASS);
+ }
+ }
+
+ @Override
+ public String getPreview(boolean afterRefactoring) {
+ if (afterRefactoring) {
+ return """
+ @BeforeAll
+ public static void setUpBeforeClass() throws Exception {
+ }
+ """; //$NON-NLS-1$
+ }
+ return """
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+ """; //$NON-NLS-1$
+ }
+
+ @Override
+ public String toString() {
+ return "BeforeClass"; //$NON-NLS-1$
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/BeforeJUnitPlugin.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/BeforeJUnitPlugin.java
new file mode 100644
index 00000000..b6889252
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/BeforeJUnitPlugin.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.corext.fix.helper;
+
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.MarkerAnnotation;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.internal.corext.dom.ASTNodes;
+import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
+import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
+import org.eclipse.text.edits.TextEditGroup;
+import org.sandbox.jdt.internal.common.HelperVisitor;
+import org.sandbox.jdt.internal.common.ReferenceHolder;
+import org.sandbox.jdt.internal.corext.fix.JUnitCleanUpFixCore;
+
+/**
+ *
+ *
+ */
+public class BeforeJUnitPlugin extends AbstractTool> {
+
+ @Override
+ public void find(JUnitCleanUpFixCore fixcore, CompilationUnit compilationUnit,
+ Set operations, Set nodesprocessed) {
+ ReferenceHolder dataholder= new ReferenceHolder<>();
+ HelperVisitor.callMarkerAnnotationVisitor(ORG_JUNIT_BEFORE, compilationUnit, dataholder, nodesprocessed,
+ (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder));
+ }
+
+ private boolean processFoundNode(JUnitCleanUpFixCore fixcore,
+ Set operations, MarkerAnnotation node,
+ ReferenceHolder dataholder) {
+ JunitHolder mh= new JunitHolder();
+ mh.minv= node;
+ mh.minvname= node.getTypeName().getFullyQualifiedName();
+ dataholder.put(dataholder.size(), mh);
+ operations.add(fixcore.rewrite(dataholder));
+ return false;
+ }
+
+ @Override
+ public void rewrite(JUnitCleanUpFixCore upp, final ReferenceHolder hit,
+ final CompilationUnitRewrite cuRewrite, TextEditGroup group) {
+ ASTRewrite rewrite= cuRewrite.getASTRewrite();
+ AST ast= cuRewrite.getRoot().getAST();
+ ImportRewrite importRewriter= cuRewrite.getImportRewrite();
+ for (Entry entry : hit.entrySet()) {
+ JunitHolder mh= entry.getValue();
+ Annotation minv= mh.getAnnotation();
+ MarkerAnnotation newAnnotation= ast.newMarkerAnnotation();
+ newAnnotation.setTypeName(ast.newSimpleName(ANNOTATION_BEFORE_EACH));
+ importRewriter.addImport(ORG_JUNIT_JUPITER_API_BEFORE_EACH);
+ ASTNodes.replaceButKeepComment(rewrite, minv, newAnnotation, group);
+ importRewriter.removeImport(ORG_JUNIT_BEFORE);
+ }
+ }
+
+ @Override
+ public String getPreview(boolean afterRefactoring) {
+ if (afterRefactoring) {
+ return """
+ @BeforeEach
+ public static void setUp() throws Exception {
+ }
+ """; //$NON-NLS-1$
+ }
+ return """
+ @Before
+ public static void setUp() throws Exception {
+ }
+ """; //$NON-NLS-1$
+ }
+
+ @Override
+ public String toString() {
+ return "Before"; //$NON-NLS-1$
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/ExternalResourceJUnitPlugin.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/ExternalResourceJUnitPlugin.java
new file mode 100644
index 00000000..e8ea84ac
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/ExternalResourceJUnitPlugin.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.corext.fix.helper;
+
+import java.util.Set;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
+import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
+import org.eclipse.text.edits.TextEditGroup;
+import org.sandbox.jdt.internal.common.HelperVisitor;
+import org.sandbox.jdt.internal.common.ReferenceHolder;
+import org.sandbox.jdt.internal.corext.fix.JUnitCleanUpFixCore;
+
+/**
+ *
+ *
+ */
+public class ExternalResourceJUnitPlugin extends AbstractTool> {
+
+ @Override
+ public void find(JUnitCleanUpFixCore fixcore, CompilationUnit compilationUnit,
+ Set operations, Set nodesprocessed) {
+ ReferenceHolder dataholder= new ReferenceHolder<>();
+ HelperVisitor.callTypeDeclarationVisitor(ORG_JUNIT_RULES_EXTERNAL_RESOURCE, compilationUnit, dataholder,
+ nodesprocessed, (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder,nodesprocessed));
+ }
+
+ private boolean processFoundNode(JUnitCleanUpFixCore fixcore,
+ Set operations, TypeDeclaration node,
+ ReferenceHolder dataholder, Set nodesprocessed) {
+ if (!nodesprocessed.contains(node)) {
+ if (!isDirectlyExtendingExternalResource(node.resolveBinding())) {
+ boolean nothingtochange=true;
+ for (MethodDeclaration method : node.getMethods()) {
+ if (isLifecycleMethod(method, METHOD_BEFORE) || isLifecycleMethod(method, METHOD_AFTER)) {
+ nothingtochange=false;
+ }
+ }
+ if(nothingtochange) {
+ return false;
+ }
+ }
+ nodesprocessed.add(node);
+ JunitHolder mh= new JunitHolder();
+ mh.minv= node;
+ dataholder.put(dataholder.size(), mh);
+ operations.add(fixcore.rewrite(dataholder));
+ }
+ return false;
+ }
+
+ @Override
+ public void rewrite(JUnitCleanUpFixCore upp, final ReferenceHolder hit,
+ final CompilationUnitRewrite cuRewrite, TextEditGroup group) {
+ ASTRewrite rewriter= cuRewrite.getASTRewrite();
+ AST ast= cuRewrite.getRoot().getAST();
+ ImportRewrite importRewriter= cuRewrite.getImportRewrite();
+ hit.values().forEach(holder -> {
+ TypeDeclaration node= holder.getTypeDeclaration();
+ modifyExternalResourceClass(node, rewriter, ast, group, importRewriter);
+ });
+ }
+
+ @Override
+ public String getPreview(boolean afterRefactoring) {
+ if (afterRefactoring) {
+ return """
+ private String testName;
+
+ @BeforeEach
+ void init(TestInfo testInfo) {
+ this.testName = testInfo.getDisplayName();
+ }
+ @Test
+ public void test(){
+ System.out.println("Test name: " + testName);
+ }
+ """; //$NON-NLS-1$
+ }
+ return """
+ @Rule
+ public TestName tn = new TestName();
+
+ @Test
+ public void test(){
+ System.out.println("Test name: " + tn.getMethodName());
+ }
+ """; //$NON-NLS-1$
+ }
+
+ @Override
+ public String toString() {
+ return "ExternalResource"; //$NON-NLS-1$
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/IgnoreJUnitPlugin.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/IgnoreJUnitPlugin.java
new file mode 100644
index 00000000..71a29685
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/IgnoreJUnitPlugin.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.corext.fix.helper;
+
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.internal.corext.dom.ASTNodes;
+import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
+import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
+import org.eclipse.text.edits.TextEditGroup;
+import org.sandbox.jdt.internal.common.HelperVisitor;
+import org.sandbox.jdt.internal.common.ReferenceHolder;
+import org.sandbox.jdt.internal.corext.fix.JUnitCleanUpFixCore;
+
+/**
+ *
+ *
+ */
+public class IgnoreJUnitPlugin extends AbstractTool> {
+
+ @Override
+ public void find(JUnitCleanUpFixCore fixcore, CompilationUnit compilationUnit,
+ Set operations, Set nodesprocessed) {
+ ReferenceHolder dataholder= new ReferenceHolder<>();
+ HelperVisitor.callMarkerAnnotationVisitor(ORG_JUNIT_IGNORE, compilationUnit, dataholder, nodesprocessed,
+ (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder));
+ HelperVisitor.callNormalAnnotationVisitor(ORG_JUNIT_IGNORE, compilationUnit, dataholder, nodesprocessed,
+ (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder));
+ HelperVisitor.callSingleMemberAnnotationVisitor(ORG_JUNIT_IGNORE, compilationUnit, dataholder, nodesprocessed,
+ (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder));
+ }
+
+ private boolean processFoundNode(JUnitCleanUpFixCore fixcore,
+ Set operations, Annotation node,
+ ReferenceHolder dataholder) {
+ JunitHolder mh= new JunitHolder();
+ mh.minv= node;
+ mh.minvname= node.getTypeName().getFullyQualifiedName();
+ if (node instanceof SingleMemberAnnotation mynode) {
+ Expression value= mynode.getValue();
+ mh.value= value.toString();
+ }
+ dataholder.put(dataholder.size(), mh);
+ operations.add(fixcore.rewrite(dataholder));
+ return false;
+ }
+
+ @Override
+ public void rewrite(JUnitCleanUpFixCore upp, final ReferenceHolder hit,
+ final CompilationUnitRewrite cuRewrite, TextEditGroup group) {
+ ASTRewrite rewrite= cuRewrite.getASTRewrite();
+ AST ast= cuRewrite.getRoot().getAST();
+ ImportRewrite importRewriter= cuRewrite.getImportRewrite();
+ for (Entry entry : hit.entrySet()) {
+ JunitHolder mh= entry.getValue();
+ Annotation minv= mh.getAnnotation();
+ Annotation newAnnotation= null;
+ if (minv instanceof SingleMemberAnnotation mynode) {
+ newAnnotation= ast.newSingleMemberAnnotation();
+ ((SingleMemberAnnotation) newAnnotation)
+ .setValue(ASTNodes.createMoveTarget(rewrite, mynode.getValue()));
+ } else {
+ newAnnotation= ast.newMarkerAnnotation();
+ }
+ newAnnotation.setTypeName(ast.newSimpleName(ANNOTATION_DISABLED));
+ importRewriter.addImport(ORG_JUNIT_JUPITER_DISABLED);
+ ASTNodes.replaceButKeepComment(rewrite, minv, newAnnotation, group);
+ importRewriter.removeImport(ORG_JUNIT_IGNORE);
+ }
+ }
+
+ @Override
+ public String getPreview(boolean afterRefactoring) {
+ if (afterRefactoring) {
+ return """
+ @Disabled("not implemented")
+ @Test
+ public void test() {
+ fail("Not yet implemented");
+ }
+ """; //$NON-NLS-1$
+ }
+ return """
+ @Ignore("not implemented")
+ @Test
+ public void test() {
+ fail("Not yet implemented");
+ }
+ """; //$NON-NLS-1$
+ }
+
+ @Override
+ public String toString() {
+ return "Ignore"; //$NON-NLS-1$
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/JunitHolder.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/JunitHolder.java
new file mode 100644
index 00000000..5f0cb762
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/JunitHolder.java
@@ -0,0 +1,39 @@
+package org.sandbox.jdt.internal.corext.fix.helper;
+
+import java.util.Set;
+
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+
+public class JunitHolder {
+ public ASTNode minv;
+ public String minvname;
+ public Set nodesprocessed;
+ public String value;
+ public MethodInvocation method;
+ public int count;
+
+ public Annotation getAnnotation() {
+ return (Annotation) minv;
+ }
+
+ public MethodInvocation getMethodInvocation() {
+ return (MethodInvocation) minv;
+ }
+
+ public ImportDeclaration getImportDeclaration() {
+ return (ImportDeclaration) minv;
+ }
+
+ public FieldDeclaration getFieldDeclaration() {
+ return (FieldDeclaration) minv;
+ }
+
+ public TypeDeclaration getTypeDeclaration() {
+ return (TypeDeclaration) minv;
+ }
+}
\ No newline at end of file
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/RuleExternalResourceJUnitPlugin.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/RuleExternalResourceJUnitPlugin.java
new file mode 100644
index 00000000..cfa0f86f
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/RuleExternalResourceJUnitPlugin.java
@@ -0,0 +1,125 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.corext.fix.helper;
+
+import java.util.Optional;
+import java.util.Set;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
+import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
+import org.eclipse.text.edits.TextEditGroup;
+import org.sandbox.jdt.internal.common.HelperVisitor;
+import org.sandbox.jdt.internal.common.ReferenceHolder;
+import org.sandbox.jdt.internal.corext.fix.JUnitCleanUpFixCore;
+
+/**
+ *
+ *
+ */
+public class RuleExternalResourceJUnitPlugin extends AbstractTool> {
+
+ @Override
+ public void find(JUnitCleanUpFixCore fixcore, CompilationUnit compilationUnit,
+ Set operations, Set nodesprocessed) {
+ ReferenceHolder dataholder= new ReferenceHolder<>();
+ HelperVisitor.callFieldDeclarationVisitor(ORG_JUNIT_RULE, ORG_JUNIT_RULES_EXTERNAL_RESOURCE, compilationUnit,
+ dataholder, nodesprocessed,
+ (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder));
+ }
+
+ private boolean processFoundNode(JUnitCleanUpFixCore fixcore,
+ Set operations, FieldDeclaration node,
+ ReferenceHolder dataholder) {
+ JunitHolder mh= new JunitHolder();
+ VariableDeclarationFragment fragment= (VariableDeclarationFragment) node.fragments().get(0);
+ ITypeBinding binding= fragment.resolveBinding().getType();
+ if (
+ isAnonymousClass(fragment)
+ || (binding == null)
+ || ORG_JUNIT_RULES_TEST_NAME.equals(binding.getQualifiedName())
+ || ORG_JUNIT_RULES_TEMPORARY_FOLDER.equals(binding.getQualifiedName())) {
+ return false;
+ }
+ mh.minv= node;
+ dataholder.put(dataholder.size(), mh);
+ operations.add(fixcore.rewrite(dataholder));
+ return false;
+ }
+
+ @Override
+ public void rewrite(JUnitCleanUpFixCore upp, ReferenceHolder hit,
+ CompilationUnitRewrite cuRewrite, TextEditGroup group) {
+ ASTRewrite rewrite= cuRewrite.getASTRewrite();
+ AST ast= cuRewrite.getRoot().getAST();
+ ImportRewrite importRewriter= cuRewrite.getImportRewrite();
+ hit.values().forEach(mh -> {
+ FieldDeclaration fieldDeclaration= mh.getFieldDeclaration();
+ Optional innerTypeDeclaration= getInnerTypeDeclaration(fieldDeclaration);
+ for (Object fragment : fieldDeclaration.fragments()) {
+ VariableDeclarationFragment variable = (VariableDeclarationFragment) fragment;
+ String fieldName = variable.getName().getIdentifier();
+ migrateRuleToRegisterExtensionAndAdaptHierarchy(innerTypeDeclaration,getParentTypeDeclaration(fieldDeclaration),rewrite, ast, importRewriter,group ,fieldName);
+ }
+ });
+ }
+
+ @Override
+ public String getPreview(boolean afterRefactoring) {
+ if (afterRefactoring) {
+ return """
+ ExtendWith(MyTest.MyExternalResource.class)
+ public class MyTest {
+
+ final class MyExternalResource implements BeforeEachCallback, AfterEachCallback {
+ @Override
+ protected void beforeEach() throws Throwable {
+ }
+
+ @Override
+ protected void afterEach() {
+ }
+ }
+ """; //$NON-NLS-1$
+ }
+ return """
+ public class MyTest {
+
+ final class MyExternalResource extends ExternalResource {
+ @Override
+ protected void before() throws Throwable {
+ }
+
+ @Override
+ protected void after() {
+ }
+ }
+
+ @Rule
+ public ExternalResource er= new MyExternalResource();
+ """; //$NON-NLS-1$
+ }
+
+ @Override
+ public String toString() {
+ return "RuleExternalResource"; //$NON-NLS-1$
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/RuleTemporayFolderJUnitPlugin.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/RuleTemporayFolderJUnitPlugin.java
new file mode 100644
index 00000000..7a3fcf93
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/RuleTemporayFolderJUnitPlugin.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.corext.fix.helper;
+
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.MarkerAnnotation;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
+import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
+import org.eclipse.text.edits.TextEditGroup;
+import org.sandbox.jdt.internal.common.HelperVisitor;
+import org.sandbox.jdt.internal.common.ReferenceHolder;
+import org.sandbox.jdt.internal.corext.fix.JUnitCleanUpFixCore;
+
+/**
+ *
+ *
+ */
+public class RuleTemporayFolderJUnitPlugin extends AbstractTool> {
+
+ @Override
+ public void find(JUnitCleanUpFixCore fixcore, CompilationUnit compilationUnit,
+ Set operations, Set nodesprocessed) {
+ ReferenceHolder dataholder= new ReferenceHolder<>();
+ HelperVisitor.callFieldDeclarationVisitor(ORG_JUNIT_RULE, ORG_JUNIT_RULES_TEMPORARY_FOLDER, compilationUnit,
+ dataholder, nodesprocessed,
+ (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder));
+ }
+
+ private boolean processFoundNode(JUnitCleanUpFixCore fixcore,
+ Set operations, FieldDeclaration node,
+ ReferenceHolder dataholder) {
+ JunitHolder mh= new JunitHolder();
+ mh.minv= node;
+ dataholder.put(dataholder.size(), mh);
+ operations.add(fixcore.rewrite(dataholder));
+ return false;
+ }
+
+ @Override
+ public void rewrite(JUnitCleanUpFixCore upp, final ReferenceHolder hit,
+ final CompilationUnitRewrite cuRewrite, TextEditGroup group) {
+ ASTRewrite rewriter= cuRewrite.getASTRewrite();
+ AST ast= cuRewrite.getRoot().getAST();
+ ImportRewrite importRemover= cuRewrite.getImportRewrite();
+ for (Entry entry : hit.entrySet()) {
+ JunitHolder mh= entry.getValue();
+ FieldDeclaration field= mh.getFieldDeclaration();
+ rewriter.remove(field, group);
+ TypeDeclaration parentClass= (TypeDeclaration) field.getParent();
+
+ addImport(ORG_JUNIT_JUPITER_API_IO_TEMP_DIR, cuRewrite, ast);
+ importRemover.removeImport(ORG_JUNIT_RULE);
+ importRemover.removeImport(ORG_JUNIT_RULES_TEMPORARY_FOLDER);
+
+ VariableDeclarationFragment originalFragment= (VariableDeclarationFragment) field.fragments().get(0);
+ String originalName= originalFragment.getName().getIdentifier();
+
+ VariableDeclarationFragment tempDirFragment= ast.newVariableDeclarationFragment();
+ tempDirFragment.setName(ast.newSimpleName(originalName));
+
+ FieldDeclaration tempDirField= ast.newFieldDeclaration(tempDirFragment);
+ tempDirField.setType(ast.newSimpleType(ast.newName("Path")));
+
+ MarkerAnnotation tempDirAnnotation= ast.newMarkerAnnotation();
+ tempDirAnnotation.setTypeName(ast.newName("TempDir"));
+ rewriter.getListRewrite(tempDirField, FieldDeclaration.MODIFIERS2_PROPERTY).insertFirst(tempDirAnnotation,
+ group);
+
+ rewriter.getListRewrite(parentClass, TypeDeclaration.BODY_DECLARATIONS_PROPERTY).insertFirst(tempDirField,
+ group);
+
+ for (MethodDeclaration method : parentClass.getMethods()) {
+ method.accept(new ASTVisitor() {
+ @Override
+ public boolean visit(MethodInvocation node) {
+ if (node.getName().getIdentifier().equals("newFile")) {
+ MethodInvocation resolveInvocation= ast.newMethodInvocation();
+ resolveInvocation.setExpression(ast.newSimpleName("tempFolder"));
+ resolveInvocation.setName(ast.newSimpleName("resolve"));
+ resolveInvocation.arguments().addAll(ASTNode.copySubtrees(ast, node.arguments()));
+
+ MethodInvocation toFileInvocation= ast.newMethodInvocation();
+ toFileInvocation.setExpression(resolveInvocation);
+ toFileInvocation.setName(ast.newSimpleName("toFile"));
+
+ rewriter.replace(node, toFileInvocation, group);
+ }
+ return super.visit(node);
+ }
+ });
+ }
+ }
+ }
+
+ @Override
+ public String getPreview(boolean afterRefactoring) {
+ if (afterRefactoring) {
+ return """
+ @TempDir
+ Path tempFolder;
+
+ @Test
+ public void test3() throws IOException{
+ File newFile = tempFolder.resolve("myfile.txt").toFile();
+ }
+ """; //$NON-NLS-1$
+ }
+ return """
+ @Rule
+ public TemporaryFolder tempFolder = new TemporaryFolder();
+
+ @Test
+ public void test3() throws IOException{
+ File newFile = tempFolder.newFile("myfile.txt");
+ } ;
+ """; //$NON-NLS-1$
+ }
+
+ @Override
+ public String toString() {
+ return "RuleTemporaryFolder"; //$NON-NLS-1$
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/RuleTestnameJUnitPlugin.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/RuleTestnameJUnitPlugin.java
new file mode 100644
index 00000000..3b5358d0
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/RuleTestnameJUnitPlugin.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.corext.fix.helper;
+
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
+import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
+import org.eclipse.text.edits.TextEditGroup;
+import org.sandbox.jdt.internal.common.HelperVisitor;
+import org.sandbox.jdt.internal.common.ReferenceHolder;
+import org.sandbox.jdt.internal.corext.fix.JUnitCleanUpFixCore;
+
+/**
+ *
+ *
+ */
+public class RuleTestnameJUnitPlugin extends AbstractTool> {
+
+ @Override
+ public void find(JUnitCleanUpFixCore fixcore, CompilationUnit compilationUnit,
+ Set operations, Set nodesprocessed) {
+ ReferenceHolder dataholder= new ReferenceHolder<>();
+ HelperVisitor.callFieldDeclarationVisitor(ORG_JUNIT_RULE, ORG_JUNIT_RULES_TEST_NAME, compilationUnit,
+ dataholder, nodesprocessed,
+ (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder));
+ }
+
+ private boolean processFoundNode(JUnitCleanUpFixCore fixcore,
+ Set operations, FieldDeclaration node,
+ ReferenceHolder dataholder) {
+ JunitHolder mh= new JunitHolder();
+ VariableDeclarationFragment fragment= (VariableDeclarationFragment) node.fragments().get(0);
+ ITypeBinding binding= fragment.resolveBinding().getType();
+ if (binding != null && ORG_JUNIT_RULES_TEST_NAME.equals(binding.getQualifiedName())) {
+ mh.minv= node;
+ dataholder.put(dataholder.size(), mh);
+ operations.add(fixcore.rewrite(dataholder));
+ }
+ return false;
+ }
+
+ @Override
+ public void rewrite(JUnitCleanUpFixCore upp, final ReferenceHolder hit,
+ final CompilationUnitRewrite cuRewrite, TextEditGroup group) {
+ ASTRewrite rewriter= cuRewrite.getASTRewrite();
+ AST ast= cuRewrite.getRoot().getAST();
+ ImportRewrite importrewriter= cuRewrite.getImportRewrite();
+ for (Entry entry : hit.entrySet()) {
+ JunitHolder mh= entry.getValue();
+ FieldDeclaration node= mh.getFieldDeclaration();
+ refactorTestnameInClassAndSubclasses(group, rewriter, ast, importrewriter, node);
+ }
+ }
+
+ @Override
+ public String getPreview(boolean afterRefactoring) {
+ if (afterRefactoring) {
+ return """
+ private String testName;
+
+ @BeforeEach
+ void init(TestInfo testInfo) {
+ this.testName = testInfo.getDisplayName();
+ }
+ @Test
+ public void test(){
+ System.out.println("Test name: " + testName);
+ }
+ """; //$NON-NLS-1$
+ }
+ return """
+ @Rule
+ public TestName tn = new TestName();
+
+ @Test
+ public void test(){
+ System.out.println("Test name: " + tn.getMethodName());
+ }
+ """; //$NON-NLS-1$
+ }
+
+ @Override
+ public String toString() {
+ return "RuleTestname"; //$NON-NLS-1$
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/RunWithJUnitPlugin.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/RunWithJUnitPlugin.java
new file mode 100644
index 00000000..373ece45
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/RunWithJUnitPlugin.java
@@ -0,0 +1,142 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.corext.fix.helper;
+
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
+import org.eclipse.jdt.core.dom.TypeLiteral;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.internal.corext.dom.ASTNodes;
+import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
+import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
+import org.eclipse.text.edits.TextEditGroup;
+import org.sandbox.jdt.internal.common.HelperVisitor;
+import org.sandbox.jdt.internal.common.ReferenceHolder;
+import org.sandbox.jdt.internal.corext.fix.JUnitCleanUpFixCore;
+
+/**
+ *
+ *
+ */
+public class RunWithJUnitPlugin extends AbstractTool> {
+
+ @Override
+ public void find(JUnitCleanUpFixCore fixcore, CompilationUnit compilationUnit,
+ Set operations, Set nodesprocessed) {
+ ReferenceHolder dataholder= new ReferenceHolder<>();
+ HelperVisitor.callSingleMemberAnnotationVisitor(ORG_JUNIT_RUNWITH, compilationUnit, dataholder, nodesprocessed,
+ (visited, aholder) -> processFoundNodeRunWith(fixcore, operations, visited, aholder));
+ HelperVisitor.callSingleMemberAnnotationVisitor(ORG_JUNIT_SUITE_SUITECLASSES, compilationUnit, dataholder,
+ nodesprocessed, (visited, aholder) -> processFoundNodeSuite(fixcore, operations, visited, aholder));
+ }
+
+ private boolean processFoundNodeRunWith(JUnitCleanUpFixCore fixcore,
+ Set operations, Annotation node,
+ ReferenceHolder dataholder) {
+ JunitHolder mh= new JunitHolder();
+ mh.minv= node;
+ mh.minvname= node.getTypeName().getFullyQualifiedName();
+ if (node instanceof SingleMemberAnnotation mynode) {
+ Expression value= mynode.getValue();
+ if (value instanceof TypeLiteral myvalue) {
+ ITypeBinding classBinding= myvalue.resolveTypeBinding();
+ if (classBinding != null && classBinding.isParameterizedType()) {
+ ITypeBinding[] typeArguments= classBinding.getTypeArguments();
+ if (typeArguments.length > 0) {
+ ITypeBinding actualTypeBinding= typeArguments[0];
+ if (ORG_JUNIT_SUITE.equals(actualTypeBinding.getQualifiedName())) {
+ mh.value= ORG_JUNIT_RUNWITH;
+ dataholder.put(dataholder.size(), mh);
+ operations.add(fixcore.rewrite(dataholder));
+ }
+ return false;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean processFoundNodeSuite(JUnitCleanUpFixCore fixcore,
+ Set operations, Annotation node,
+ ReferenceHolder dataholder) {
+ JunitHolder mh= new JunitHolder();
+ mh.minv= node;
+ mh.minvname= node.getTypeName().getFullyQualifiedName();
+ mh.value= ORG_JUNIT_SUITE_SUITECLASSES;
+ dataholder.put(dataholder.size(), mh);
+ operations.add(fixcore.rewrite(dataholder));
+ return false;
+ }
+
+ @Override
+ public void rewrite(JUnitCleanUpFixCore upp, final ReferenceHolder hit,
+ final CompilationUnitRewrite cuRewrite, TextEditGroup group) {
+ ASTRewrite rewrite= cuRewrite.getASTRewrite();
+ AST ast= cuRewrite.getRoot().getAST();
+ ImportRewrite importrewriter= cuRewrite.getImportRewrite();
+ for (Entry entry : hit.entrySet()) {
+ JunitHolder mh= entry.getValue();
+ Annotation minv= mh.getAnnotation();
+ Annotation newAnnotation= null;
+ SingleMemberAnnotation mynode= (SingleMemberAnnotation) minv;
+ if (ORG_JUNIT_SUITE_SUITECLASSES.equals(mh.value)) {
+ newAnnotation= ast.newSingleMemberAnnotation();
+ ((SingleMemberAnnotation) newAnnotation)
+ .setValue(ASTNodes.createMoveTarget(rewrite, mynode.getValue()));
+ newAnnotation.setTypeName(ast.newSimpleName(ANNOTATION_SELECT_CLASSES));
+ importrewriter.addImport(ORG_JUNIT_PLATFORM_SUITE_API_SELECT_CLASSES);
+ } else {
+ newAnnotation= ast.newMarkerAnnotation();
+ newAnnotation.setTypeName(ast.newSimpleName(ANNOTATION_SUITE));
+ importrewriter.addImport(ORG_JUNIT_JUPITER_SUITE);
+ }
+ ASTNodes.replaceButKeepComment(rewrite, minv, newAnnotation, group);
+ importrewriter.removeImport(ORG_JUNIT_SUITE);
+ importrewriter.removeImport(ORG_JUNIT_RUNWITH);
+ }
+ }
+
+ @Override
+ public String getPreview(boolean afterRefactoring) {
+ if (afterRefactoring) {
+ return """
+ @Suite
+ @SelectClasses({
+ MyTest2.class
+ })
+ """; //$NON-NLS-1$
+ }
+ return """
+ @RunWith(Suite.class)
+ @Suite.SuiteClasses({
+ MyTest.class
+ })
+ """; //$NON-NLS-1$
+ }
+
+ @Override
+ public String toString() {
+ return "RunWith"; //$NON-NLS-1$
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/TestJUnitPlugin.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/TestJUnitPlugin.java
new file mode 100644
index 00000000..ec718992
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/TestJUnitPlugin.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.corext.fix.helper;
+
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.MarkerAnnotation;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.internal.corext.dom.ASTNodes;
+import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
+import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
+import org.eclipse.text.edits.TextEditGroup;
+import org.sandbox.jdt.internal.common.HelperVisitor;
+import org.sandbox.jdt.internal.common.ReferenceHolder;
+import org.sandbox.jdt.internal.corext.fix.JUnitCleanUpFixCore;
+
+/**
+ *
+ *
+ */
+public class TestJUnitPlugin extends AbstractTool> {
+
+ @Override
+ public void find(JUnitCleanUpFixCore fixcore, CompilationUnit compilationUnit,
+ Set operations, Set nodesprocessed) {
+ ReferenceHolder dataholder= new ReferenceHolder<>();
+ HelperVisitor.callMarkerAnnotationVisitor(ORG_JUNIT_TEST, compilationUnit, dataholder, nodesprocessed,
+ (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder));
+ }
+
+ private boolean processFoundNode(JUnitCleanUpFixCore fixcore,
+ Set operations, MarkerAnnotation node,
+ ReferenceHolder dataholder) {
+ JunitHolder mh= new JunitHolder();
+ mh.minv= node;
+ mh.minvname= node.getTypeName().getFullyQualifiedName();
+ dataholder.put(dataholder.size(), mh);
+ operations.add(fixcore.rewrite(dataholder));
+ return false;
+ }
+
+ @Override
+ public void rewrite(JUnitCleanUpFixCore upp, final ReferenceHolder hit,
+ final CompilationUnitRewrite cuRewrite, TextEditGroup group) {
+ ASTRewrite rewrite= cuRewrite.getASTRewrite();
+ AST ast= cuRewrite.getRoot().getAST();
+ ImportRewrite importrewriter= cuRewrite.getImportRewrite();
+ for (Entry entry : hit.entrySet()) {
+ JunitHolder mh= entry.getValue();
+ Annotation minv= mh.getAnnotation();
+ MarkerAnnotation newAnnotation= ast.newMarkerAnnotation();
+ newAnnotation.setTypeName(ast.newSimpleName(ANNOTATION_TEST));
+ ASTNodes.replaceButKeepComment(rewrite, minv, newAnnotation, group);
+ importrewriter.removeImport(ORG_JUNIT_TEST);
+ importrewriter.addImport(ORG_JUNIT_JUPITER_TEST);
+ }
+ }
+
+ @Override
+ public String getPreview(boolean afterRefactoring) {
+ if (afterRefactoring) {
+ return """
+ import org.junit.jupiter.api.Test;
+ """; //$NON-NLS-1$
+ }
+ return """
+ import org.junit.Test;
+ """; //$NON-NLS-1$
+ }
+
+ @Override
+ public String toString() {
+ return "Test"; //$NON-NLS-1$
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/JUnitCleanUp.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/JUnitCleanUp.java
new file mode 100644
index 00000000..0e763d54
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/JUnitCleanUp.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.ui.fix;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.eclipse.jdt.internal.ui.fix.AbstractCleanUpCoreWrapper;
+
+/**
+ */
+public class JUnitCleanUp extends AbstractCleanUpCoreWrapper {
+ public JUnitCleanUp(final Map options) {
+ super(options, new JUnitCleanUpCore());
+ }
+
+ public JUnitCleanUp() {
+ this(Collections.emptyMap());
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/JUnitCleanUpCore.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/JUnitCleanUpCore.java
new file mode 100644
index 00000000..fdfe5c53
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/JUnitCleanUpCore.java
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.ui.fix;
+
+import static org.sandbox.jdt.internal.corext.fix2.MYCleanUpConstants.JUNIT_CLEANUP;
+import static org.sandbox.jdt.internal.ui.fix.MultiFixMessages.JUnitCleanUpFix_refactor;
+import static org.sandbox.jdt.internal.ui.fix.MultiFixMessages.JUnitCleanUp_description;
+
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore;
+import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
+import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
+import org.eclipse.jdt.internal.corext.util.Messages;
+import org.eclipse.jdt.internal.ui.fix.AbstractCleanUp;
+import org.eclipse.jdt.ui.cleanup.CleanUpContext;
+import org.eclipse.jdt.ui.cleanup.CleanUpRequirements;
+import org.eclipse.jdt.ui.cleanup.ICleanUpFix;
+import org.sandbox.jdt.internal.corext.fix.JUnitCleanUpFixCore;
+import org.sandbox.jdt.internal.corext.fix2.MYCleanUpConstants;
+
+public class JUnitCleanUpCore extends AbstractCleanUp {
+ public JUnitCleanUpCore(final Map options) {
+ super(options);
+ }
+
+ /**
+ *
+ */
+ public JUnitCleanUpCore() {
+ }
+
+ @Override
+ public CleanUpRequirements getRequirements() {
+ return new CleanUpRequirements(requireAST(), false, false, null);
+ }
+
+ public boolean requireAST() {
+ return isEnabled(JUNIT_CLEANUP);
+ }
+
+ @Override
+ public ICleanUpFix createFix(final CleanUpContext context) throws CoreException {
+ CompilationUnit compilationUnit= context.getAST();
+ if (compilationUnit == null) {
+ return null;
+ }
+ EnumSet computeFixSet= computeFixSet();
+ if (!isEnabled(JUNIT_CLEANUP) || computeFixSet.isEmpty()
+ || !JavaModelUtil.is1d8OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
+ return null;
+ }
+ Set operations= new LinkedHashSet<>();
+ Set nodesprocessed= new HashSet<>();
+ computeFixSet.forEach(i -> i.findOperations(compilationUnit, operations, nodesprocessed));
+ if (operations.isEmpty()) {
+ return null;
+ }
+ return new CompilationUnitRewriteOperationsFixCore(JUnitCleanUpFix_refactor, compilationUnit,
+ operations.toArray(new CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation[0]));
+ }
+
+ @Override
+ public String[] getStepDescriptions() {
+ List result= new ArrayList<>();
+ if (isEnabled(JUNIT_CLEANUP)) {
+ result.add(Messages.format(JUnitCleanUp_description, new Object[] { String.join(",", //$NON-NLS-1$
+ computeFixSet().stream().map(JUnitCleanUpFixCore::toString).collect(Collectors.toList())) }));
+ }
+ return result.toArray(new String[0]);
+ }
+
+ @Override
+ public String getPreview() {
+ StringBuilder sb= new StringBuilder();
+ EnumSet computeFixSet= computeFixSet();
+ EnumSet.allOf(JUnitCleanUpFixCore.class).forEach(e -> sb.append(e.getPreview(computeFixSet.contains(e))));
+ return sb.toString();
+ }
+
+
+
+ private EnumSet computeFixSet() {
+ EnumSet fixSet = isEnabled(JUNIT_CLEANUP)
+ ? EnumSet.allOf(JUnitCleanUpFixCore.class)
+ : EnumSet.noneOf(JUnitCleanUpFixCore.class);
+ Map cleanupMappings = Map.of(
+ MYCleanUpConstants.JUNIT_CLEANUP_4_ASSERT, JUnitCleanUpFixCore.ASSERT,
+ MYCleanUpConstants.JUNIT_CLEANUP_4_ASSUME, JUnitCleanUpFixCore.ASSUME,
+ MYCleanUpConstants.JUNIT_CLEANUP_4_AFTER, JUnitCleanUpFixCore.AFTER,
+ MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORE, JUnitCleanUpFixCore.BEFORE,
+ MYCleanUpConstants.JUNIT_CLEANUP_4_AFTERCLASS, JUnitCleanUpFixCore.AFTERCLASS,
+ MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORECLASS, JUnitCleanUpFixCore.BEFORECLASS,
+ MYCleanUpConstants.JUNIT_CLEANUP_4_TEST, JUnitCleanUpFixCore.TEST,
+ MYCleanUpConstants.JUNIT_CLEANUP_4_IGNORE, JUnitCleanUpFixCore.IGNORE,
+ MYCleanUpConstants.JUNIT_CLEANUP_4_RULETEMPORARYFOLDER, JUnitCleanUpFixCore.RULETEMPORARYFOLDER,
+ MYCleanUpConstants.JUNIT_CLEANUP_4_RULETESTNAME, JUnitCleanUpFixCore.RULETESTNAME
+ );
+ cleanupMappings.forEach((config, fix) -> {
+ if (!isEnabled(config)) {
+ fixSet.remove(fix);
+ }
+ });
+ return fixSet;
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/MultiFixMessages.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/MultiFixMessages.java
new file mode 100644
index 00000000..0d54bab8
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/MultiFixMessages.java
@@ -0,0 +1,15 @@
+package org.sandbox.jdt.internal.ui.fix;
+
+import org.eclipse.osgi.util.NLS;
+
+public class MultiFixMessages {
+ private static final String BUNDLE_NAME= "org.sandbox.jdt.internal.ui.fix.MultiFixMessages"; //$NON-NLS-1$
+
+ public static String JUnitCleanUp_description;
+ public static String JUnitCleanUpFix_refactor;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, MultiFixMessages.class);
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/MultiFixMessages.properties b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/MultiFixMessages.properties
new file mode 100644
index 00000000..c3d64092
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/MultiFixMessages.properties
@@ -0,0 +1,2 @@
+JUnitCleanUp_description=Update junit ''{0}''
+JUnitCleanUpFix_refactor=Update junit
\ No newline at end of file
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java
new file mode 100644
index 00000000..16702af2
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.ui.preferences.cleanup;
+
+import org.eclipse.osgi.util.NLS;
+
+public class CleanUpMessages {
+ private static final String BUNDLE_NAME= "org.sandbox.jdt.internal.ui.preferences.cleanup.CleanUpMessages"; //$NON-NLS-1$
+ public static String JavaFeatureTabPage_GroupName_JUnit;
+ public static String JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP;
+ public static String JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_ASSERT;
+ public static String JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_ASSUME;
+ public static String JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_IGNORE;
+ public static String JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_TEST;
+ public static String JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_BEFORE;
+ public static String JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_AFTER;
+ public static String JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_BEFORECLASS;
+ public static String JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_AFTERCLASS;
+ public static String JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_RULETEMPORARYFOLDER;
+ public static String JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_RULETESTNAME;
+ public static String JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_EXTERNALRESOURCE;
+ public static String JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_RUNWITH;
+
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, CleanUpMessages.class);
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties
new file mode 100644
index 00000000..af0bab99
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties
@@ -0,0 +1,2 @@
+JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP=JUNIT_CLEANUP
+JavaFeatureTabPage_GroupName_JUnit=JUnit
\ No newline at end of file
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/DefaultCleanUpOptionsInitializer.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/DefaultCleanUpOptionsInitializer.java
new file mode 100644
index 00000000..ec7a8f4e
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/DefaultCleanUpOptionsInitializer.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.ui.preferences.cleanup;
+
+import org.eclipse.jdt.ui.cleanup.CleanUpOptions;
+import org.eclipse.jdt.ui.cleanup.ICleanUpOptionsInitializer;
+import org.sandbox.jdt.internal.corext.fix2.MYCleanUpConstants;
+
+public class DefaultCleanUpOptionsInitializer implements ICleanUpOptionsInitializer {
+
+ @Override
+ public void setDefaultOptions(CleanUpOptions options) {
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTER, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORE, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTERCLASS, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORECLASS, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSUME, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSERT, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_IGNORE, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_TEST, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETESTNAME, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETEMPORARYFOLDER, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_EXTERNALRESOURCE, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_RUNWITH, CleanUpOptions.FALSE);
+ }
+}
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/SandboxCodeTabPage.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/SandboxCodeTabPage.java
new file mode 100644
index 00000000..0acdbd6b
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/SandboxCodeTabPage.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.ui.preferences.cleanup;
+
+import java.util.Map;
+
+import org.eclipse.jdt.internal.ui.fix.AbstractCleanUp;
+import org.eclipse.jdt.internal.ui.preferences.cleanup.AbstractCleanUpTabPage;
+import org.eclipse.jdt.ui.cleanup.CleanUpOptions;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.sandbox.jdt.internal.corext.fix2.MYCleanUpConstants;
+import org.sandbox.jdt.internal.ui.fix.JUnitCleanUp;
+
+public class SandboxCodeTabPage extends AbstractCleanUpTabPage {
+
+ /**
+ * Constant array for boolean selection
+ */
+ static final String[] FALSE_TRUE= { CleanUpOptions.FALSE, CleanUpOptions.TRUE };
+
+ public static final String ID= "org.eclipse.jdt.ui.cleanup.tabpage.sandbox"; //$NON-NLS-1$
+
+ @Override
+ protected AbstractCleanUp[] createPreviewCleanUps(Map values) {
+ return new AbstractCleanUp[] { new JUnitCleanUp(values) };
+ }
+
+ @Override
+ protected void doCreatePreferences(Composite composite, int numColumns) {
+ Group junitGroup= createGroup(numColumns, composite, CleanUpMessages.JavaFeatureTabPage_GroupName_JUnit);
+ final CheckboxPreference junitcb= createCheckboxPref(junitGroup, numColumns,
+ CleanUpMessages.JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP, MYCleanUpConstants.JUNIT_CLEANUP,
+ FALSE_TRUE);
+ intent(junitGroup);
+ final CheckboxPreference junit_assert= createCheckboxPref(junitGroup, numColumns,
+ CleanUpMessages.JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_ASSERT, MYCleanUpConstants.JUNIT_CLEANUP_4_ASSERT,
+ FALSE_TRUE);
+ final CheckboxPreference junit_assume= createCheckboxPref(junitGroup, numColumns,
+ CleanUpMessages.JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_ASSUME, MYCleanUpConstants.JUNIT_CLEANUP_4_ASSUME,
+ FALSE_TRUE);
+ final CheckboxPreference junit_ignore= createCheckboxPref(junitGroup, numColumns,
+ CleanUpMessages.JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_IGNORE, MYCleanUpConstants.JUNIT_CLEANUP_4_IGNORE,
+ FALSE_TRUE);
+ final CheckboxPreference junit_test= createCheckboxPref(junitGroup, numColumns,
+ CleanUpMessages.JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_TEST, MYCleanUpConstants.JUNIT_CLEANUP_4_TEST,
+ FALSE_TRUE);
+ registerSlavePreference(junitcb, new CheckboxPreference[] {junit_assert, junit_assume,junit_ignore,junit_test});
+ intent(junitGroup);
+
+ registerPreference(junitcb);
+ }
+}
\ No newline at end of file
diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/SaveActionCleanUpOptionsInitializer.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/SaveActionCleanUpOptionsInitializer.java
new file mode 100644
index 00000000..f24a4f33
--- /dev/null
+++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/SaveActionCleanUpOptionsInitializer.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Carsten Hammer.
+ *
+ * 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:
+ * Carsten Hammer
+ *******************************************************************************/
+package org.sandbox.jdt.internal.ui.preferences.cleanup;
+
+import org.eclipse.jdt.ui.cleanup.CleanUpOptions;
+import org.eclipse.jdt.ui.cleanup.ICleanUpOptionsInitializer;
+import org.sandbox.jdt.internal.corext.fix2.MYCleanUpConstants;
+
+public class SaveActionCleanUpOptionsInitializer implements ICleanUpOptionsInitializer {
+
+ @Override
+ public void setDefaultOptions(CleanUpOptions options) {
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTER, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORE, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTERCLASS, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORECLASS, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSUME, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSERT, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_IGNORE, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_TEST, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETESTNAME, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETEMPORARYFOLDER, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_EXTERNALRESOURCE, CleanUpOptions.FALSE);
+ options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_RUNWITH, CleanUpOptions.FALSE);
+ }
+}
diff --git a/sandbox_junit_cleanup_feature/.gitignore b/sandbox_junit_cleanup_feature/.gitignore
new file mode 100644
index 00000000..b83d2226
--- /dev/null
+++ b/sandbox_junit_cleanup_feature/.gitignore
@@ -0,0 +1 @@
+/target/
diff --git a/sandbox_junit_cleanup_feature/.project b/sandbox_junit_cleanup_feature/.project
new file mode 100644
index 00000000..e4825b41
--- /dev/null
+++ b/sandbox_junit_cleanup_feature/.project
@@ -0,0 +1,23 @@
+
+
+ sandbox_junit_cleanup_feature
+
+
+
+
+
+ org.eclipse.pde.FeatureBuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.m2e.core.maven2Nature
+ org.eclipse.pde.FeatureNature
+
+
diff --git a/sandbox_junit_cleanup_feature/build.properties b/sandbox_junit_cleanup_feature/build.properties
new file mode 100644
index 00000000..e4762c45
--- /dev/null
+++ b/sandbox_junit_cleanup_feature/build.properties
@@ -0,0 +1 @@
+bin.includes=.
\ No newline at end of file
diff --git a/sandbox_junit_cleanup_feature/feature.xml b/sandbox_junit_cleanup_feature/feature.xml
new file mode 100644
index 00000000..39a4608a
--- /dev/null
+++ b/sandbox_junit_cleanup_feature/feature.xml
@@ -0,0 +1,44 @@
+
+
+
+
+ %description
+
+
+
+ %copyright
+
+
+
+ %license
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sandbox_junit_cleanup_feature/pom.xml b/sandbox_junit_cleanup_feature/pom.xml
new file mode 100644
index 00000000..777b74e1
--- /dev/null
+++ b/sandbox_junit_cleanup_feature/pom.xml
@@ -0,0 +1,14 @@
+
+
+ 4.0.0
+
+ org.sandbox
+ central
+ 1.2.0-SNAPSHOT
+
+ sandbox_junit_cleanup_feature
+ Sandbox junit cleanup Feature
+ eclipse-feature
+
\ No newline at end of file
diff --git a/sandbox_junit_cleanup_test/.classpath b/sandbox_junit_cleanup_test/.classpath
new file mode 100644
index 00000000..6f2bbb60
--- /dev/null
+++ b/sandbox_junit_cleanup_test/.classpath
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sandbox_junit_cleanup_test/.gitignore b/sandbox_junit_cleanup_test/.gitignore
new file mode 100644
index 00000000..0f630157
--- /dev/null
+++ b/sandbox_junit_cleanup_test/.gitignore
@@ -0,0 +1,2 @@
+/target/
+/bin/
diff --git a/sandbox_junit_cleanup_test/.project b/sandbox_junit_cleanup_test/.project
new file mode 100644
index 00000000..3ab272cb
--- /dev/null
+++ b/sandbox_junit_cleanup_test/.project
@@ -0,0 +1,34 @@
+
+
+ sandbox_junit_cleanup_test
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.pde.ManifestBuilder
+
+
+
+
+ org.eclipse.pde.SchemaBuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.m2e.core.maven2Nature
+ org.eclipse.pde.PluginNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/sandbox_junit_cleanup_test/META-INF/MANIFEST.MF b/sandbox_junit_cleanup_test/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..66733847
--- /dev/null
+++ b/sandbox_junit_cleanup_test/META-INF/MANIFEST.MF
@@ -0,0 +1,28 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: junit cleanup tests
+Bundle-SymbolicName: sandbox_junit_cleanup_test;singleton:=true
+Bundle-Version: 1.2.0.qualifier
+Fragment-Host: sandbox_junit_cleanup
+Bundle-RequiredExecutionEnvironment: JavaSE-21
+Require-Bundle: org.junit,
+ sandbox_test_commons
+Bundle-ActivationPolicy: lazy
+Eclipse-BundleShape: dir
+Eclipse-BuddyPolicy: global
+Import-Package: org.junit.jupiter.api;version="5.7.1",
+ org.junit.jupiter.api.condition;version="5.7.1",
+ org.junit.jupiter.api.extension;version="5.7.1",
+ org.junit.jupiter.api.extension.support;version="5.7.1",
+ org.junit.jupiter.api.function;version="5.7.1",
+ org.junit.jupiter.api.io;version="5.7.1",
+ org.junit.jupiter.api.parallel;version="5.7.1",
+ org.junit.jupiter.params;version="5.7.1",
+ org.junit.jupiter.params.aggregator;version="5.7.1",
+ org.junit.jupiter.params.converter;version="5.7.1",
+ org.junit.jupiter.params.provider;version="5.7.1",
+ org.junit.jupiter.params.support;version="5.7.1",
+ org.opentest4j;version="1.2.0",
+ org.sandbox.jdt.internal.common,
+ org.sandbox.jdt.internal.corext.fix2
+Automatic-Module-Name: sandbox.junit.cleanup.test
diff --git a/sandbox_junit_cleanup_test/build.properties b/sandbox_junit_cleanup_test/build.properties
new file mode 100644
index 00000000..99ca9c2f
--- /dev/null
+++ b/sandbox_junit_cleanup_test/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+bin.includes = META-INF/,\
+ .,\
+ fragment.xml,\
+ build.properties
diff --git a/sandbox_junit_cleanup_test/fragment.xml b/sandbox_junit_cleanup_test/fragment.xml
new file mode 100644
index 00000000..79151e03
--- /dev/null
+++ b/sandbox_junit_cleanup_test/fragment.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/sandbox_junit_cleanup_test/pom.xml b/sandbox_junit_cleanup_test/pom.xml
new file mode 100644
index 00000000..a782915b
--- /dev/null
+++ b/sandbox_junit_cleanup_test/pom.xml
@@ -0,0 +1,44 @@
+
+
+ 4.0.0
+
+ org.sandbox
+ central
+ 1.2.0-SNAPSHOT
+
+ sandbox_junit_cleanup_test
+ Sandbox junit cleanup test
+ eclipse-test-plugin
+
+
+ src
+
+
+ org.eclipse.tycho
+ tycho-surefire-plugin
+ ${tycho-version}
+
+ BREE
+ false
+ true
+
+
+ eclipse-plugin
+ org.sandbox
+ sandbox_junit_cleanup
+
+ 0.0.0
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnitMigrationCleanUpTest.java b/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnitMigrationCleanUpTest.java
new file mode 100644
index 00000000..f3b294eb
--- /dev/null
+++ b/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnitMigrationCleanUpTest.java
@@ -0,0 +1,1195 @@
+/*******************************************************************************
+ * Copyright (c) 2022
+ *
+ * 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:
+ * Carsten Hammer initial implementation
+ *******************************************************************************/
+package org.eclipse.jdt.ui.tests.quickfix.Java8;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.junit.JUnitCore;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.sandbox.jdt.internal.corext.fix2.MYCleanUpConstants;
+import org.sandbox.jdt.ui.tests.quickfix.rules.AbstractEclipseJava;
+import org.sandbox.jdt.ui.tests.quickfix.rules.EclipseJava17;
+
+
+public class JUnitMigrationCleanUpTest {
+
+ @RegisterExtension
+ AbstractEclipseJava context4junit4= new EclipseJava17();
+
+ @RegisterExtension
+ AbstractEclipseJava context4junit5= new EclipseJava17();
+
+ IPackageFragmentRoot fRootJUnit4;
+ IPackageFragmentRoot fRootJUnit5;
+
+ @BeforeEach
+ public void setup() throws CoreException {
+ fRootJUnit4= context4junit4.createClasspathForJUnit(JUnitCore.JUNIT4_CONTAINER_PATH);
+ fRootJUnit5= context4junit5.createClasspathForJUnit(JUnitCore.JUNIT5_CONTAINER_PATH);
+ }
+
+ enum JUnitCleanupCases{
+ PositiveCase("""
+package test;
+import org.junit.Assert;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.Assume;
+import static org.junit.Assume.assumeTrue;
+import org.hamcrest.CoreMatchers;
+
+/**
+ *
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ MyTest.class
+})
+public class MyTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Ignore
+ @Test
+ public void test() {
+ Assert.fail("Not yet implemented");
+ Object o1,o2;
+ o1="foo";
+ o2=o1;
+ Assert.assertSame("ohno", o1, o2);
+ }
+
+ @Ignore("not implemented")
+ @Test
+ public void test2() {
+ Assert.fail("Not yet implemented");
+ }
+
+ @Test
+ public void test3() {
+ boolean condition=true;
+ Assume.assumeFalse("Bedingung nicht erfüllt", condition);
+ Assume.assumeFalse(condition);
+ assumeTrue("Bedingung nicht erfüllt", condition);
+ assumeTrue(condition);
+ Assert.assertEquals("expected", "actual");
+ Assume.assumeNotNull(" ");
+ Assume.assumeThat(1, CoreMatchers.is(1));
+ Assert.assertThat(1, CoreMatchers.is(1));
+ }
+
+ @Test
+ public void test4() {
+ Assert.assertEquals("failuremessage", "expected", "actual");
+ int result=5;
+ Assert.assertEquals(5, result); // expected = 5, actual = result
+ Assert.assertNotEquals("failuremessage",5, result); // expected = 5, actual = result
+ Assert.assertNotEquals(5, result); // expected = 5, actual = result
+ Assert.assertTrue("failuremessage",false);
+ Assert.assertTrue(false);
+ Assert.assertFalse("failuremessage",false);
+ Assert.assertFalse(false);
+ Assert.assertNull("failuremessage", null);
+ Assert.assertNull(null);
+ }
+}
+""", //$NON-NLS-1$
+
+"""
+package test;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.junit.MatcherAssume.assumeThat;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import org.hamcrest.CoreMatchers;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.platform.suite.api.SelectClasses;
+import org.junit.platform.suite.api.Suite;
+
+/**
+ *
+ */
+@Suite
+@SelectClasses({
+ MyTest.class
+})
+public class MyTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeAll
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterAll
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeEach
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterEach
+ public void tearDown() throws Exception {
+ }
+
+ @Disabled
+ @Test
+ public void test() {
+ Assertions.fail("Not yet implemented");
+ Object o1,o2;
+ o1="foo";
+ o2=o1;
+ Assertions.assertSame(o1, o2, "ohno");
+ }
+
+ @Disabled("not implemented")
+ @Test
+ public void test2() {
+ Assertions.fail("Not yet implemented");
+ }
+
+ @Test
+ public void test3() {
+ boolean condition=true;
+ Assumptions.assumeFalse(condition, "Bedingung nicht erfüllt");
+ Assumptions.assumeFalse(condition);
+ assumeTrue(condition, "Bedingung nicht erfüllt");
+ assumeTrue(condition);
+ Assertions.assertEquals("expected", "actual");
+ Assumptions.assumeNotNull(" ");
+ assumeThat(1, CoreMatchers.is(1));
+ assertThat(1, CoreMatchers.is(1));
+ }
+
+ @Test
+ public void test4() {
+ Assertions.assertEquals("expected", "actual", "failuremessage");
+ int result=5;
+ Assertions.assertEquals(5, result); // expected = 5, actual = result
+ Assertions.assertNotEquals(5,result, "failuremessage"); // expected = 5, actual = result
+ Assertions.assertNotEquals(5, result); // expected = 5, actual = result
+ Assertions.assertTrue(false,"failuremessage");
+ Assertions.assertTrue(false);
+ Assertions.assertFalse(false,"failuremessage");
+ Assertions.assertFalse(false);
+ Assertions.assertNull(null, "failuremessage");
+ Assertions.assertNull(null);
+ }
+}
+"""),
+ AlreadyJunit5Case(
+"""
+package test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+/**
+ *
+ */
+public class MyTest {
+
+ @Test
+ public void test3() {
+ assertEquals("expected", "actual");
+ }
+}
+""", //$NON-NLS-1$
+"""
+package test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+/**
+ *
+ */
+public class MyTest {
+
+ @Test
+ public void test3() {
+ assertEquals("expected", "actual");
+ }
+}
+"""),
+ StaticImportCase("""
+ package test;
+ import static org.junit.Assert.*;
+
+ import org.junit.After;
+ import org.junit.AfterClass;
+ import org.junit.Before;
+ import org.junit.BeforeClass;
+ import org.junit.Ignore;
+ import org.junit.Test;
+ import org.junit.runner.RunWith;
+ import org.junit.runners.Suite;
+
+ /**
+ *
+ */
+ @RunWith(Suite.class)
+ @Suite.SuiteClasses({
+ MyTest.class
+ })
+ public class MyTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Ignore
+ @Test
+ public void test() {
+ fail("Not yet implemented");
+ }
+
+ @Ignore("not implemented")
+ @Test
+ public void test2() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void test3() {
+ assertEquals("expected", "actual");
+ }
+
+ @Test
+ public void test4() {
+ assertEquals("failuremessage", "expected", "actual");
+ int result=5;
+ assertEquals(5, result); // expected = 5, actual = result
+ assertNotEquals("failuremessage",5, result); // expected = 5, actual = result
+ assertTrue("failuremessage",false);
+ assertFalse("failuremessage",false);
+ assertTrue(false);
+ assertFalse(false);
+ }
+ }
+ """, //$NON-NLS-1$
+
+ """
+ package test;
+ import static org.junit.jupiter.api.Assertions.*;
+
+ import org.junit.jupiter.api.AfterAll;
+ import org.junit.jupiter.api.AfterEach;
+ import org.junit.jupiter.api.BeforeAll;
+ import org.junit.jupiter.api.BeforeEach;
+ import org.junit.jupiter.api.Disabled;
+ import org.junit.jupiter.api.Test;
+ import org.junit.platform.suite.api.SelectClasses;
+ import org.junit.platform.suite.api.Suite;
+
+ /**
+ *
+ */
+ @Suite
+ @SelectClasses({
+ MyTest.class
+ })
+ public class MyTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeAll
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterAll
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeEach
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterEach
+ public void tearDown() throws Exception {
+ }
+
+ @Disabled
+ @Test
+ public void test() {
+ fail("Not yet implemented");
+ }
+
+ @Disabled("not implemented")
+ @Test
+ public void test2() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void test3() {
+ assertEquals("expected", "actual");
+ }
+
+ @Test
+ public void test4() {
+ assertEquals("expected", "actual", "failuremessage");
+ int result=5;
+ assertEquals(5, result); // expected = 5, actual = result
+ assertNotEquals(5,result, "failuremessage"); // expected = 5, actual = result
+ assertTrue(false,"failuremessage");
+ assertFalse(false,"failuremessage");
+ assertTrue(false);
+ assertFalse(false);
+ }
+ }
+ """),
+ StaticExplicitImportCase("""
+ package test;
+ import static org.junit.Assert.fail;
+ import static org.junit.Assert.assertEquals;
+ import static org.junit.Assert.assertNotEquals;
+ import static org.junit.Assert.assertTrue;
+ import static org.junit.Assert.assertFalse;
+
+ import org.junit.After;
+ import org.junit.AfterClass;
+ import org.junit.Before;
+ import org.junit.BeforeClass;
+ import org.junit.Ignore;
+ import org.junit.Test;
+ import org.junit.runner.RunWith;
+ import org.junit.runners.Suite;
+
+ /**
+ *
+ */
+ @RunWith(Suite.class)
+ @Suite.SuiteClasses({
+ MyTest.class
+ })
+ public class MyTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Ignore
+ @Test
+ public void test() {
+ fail("Not yet implemented");
+ }
+
+ @Ignore("not implemented")
+ @Test
+ public void test2() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void test3() {
+ assertEquals("expected", "actual");
+ }
+
+ @Test
+ public void test4() {
+ assertEquals("failuremessage", "expected", "actual");
+ int result=5;
+ assertEquals(5, result); // expected = 5, actual = result
+ assertNotEquals("failuremessage",5, result); // expected = 5, actual = result
+ assertTrue("failuremessage",false);
+ assertFalse("failuremessage",false);
+ assertTrue(false);
+ assertFalse(false);
+ }
+ }
+ """, //$NON-NLS-1$
+
+ """
+ package test;
+ import static org.junit.jupiter.api.Assertions.assertEquals;
+ import static org.junit.jupiter.api.Assertions.assertFalse;
+ import static org.junit.jupiter.api.Assertions.assertNotEquals;
+ import static org.junit.jupiter.api.Assertions.assertTrue;
+ import static org.junit.jupiter.api.Assertions.fail;
+
+ import org.junit.jupiter.api.AfterAll;
+ import org.junit.jupiter.api.AfterEach;
+ import org.junit.jupiter.api.BeforeAll;
+ import org.junit.jupiter.api.BeforeEach;
+ import org.junit.jupiter.api.Disabled;
+ import org.junit.jupiter.api.Test;
+ import org.junit.platform.suite.api.SelectClasses;
+ import org.junit.platform.suite.api.Suite;
+
+ /**
+ *
+ */
+ @Suite
+ @SelectClasses({
+ MyTest.class
+ })
+ public class MyTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeAll
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterAll
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeEach
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterEach
+ public void tearDown() throws Exception {
+ }
+
+ @Disabled
+ @Test
+ public void test() {
+ fail("Not yet implemented");
+ }
+
+ @Disabled("not implemented")
+ @Test
+ public void test2() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void test3() {
+ assertEquals("expected", "actual");
+ }
+
+ @Test
+ public void test4() {
+ assertEquals("expected", "actual", "failuremessage");
+ int result=5;
+ assertEquals(5, result); // expected = 5, actual = result
+ assertNotEquals(5,result, "failuremessage"); // expected = 5, actual = result
+ assertTrue(false,"failuremessage");
+ assertFalse(false,"failuremessage");
+ assertTrue(false);
+ assertFalse(false);
+ }
+ }
+ """),
+ RuleAnonymousExternalResource(
+"""
+package test;
+import org.junit.Test;
+import org.junit.Rule;
+import org.junit.rules.ExternalResource;
+/**
+ *
+ */
+public class MyTest {
+
+ @Rule
+ public ExternalResource er= new ExternalResource() {
+ @Override
+ protected void before() throws Throwable {
+ };
+
+ @Override
+ protected void after() {
+ };
+ };
+
+ @Test
+ public void test3() {
+ }
+}
+""", //$NON-NLS-1$
+"""
+package test;
+import org.junit.Rule;
+import org.junit.jupiter.api.Test;
+import org.junit.rules.ExternalResource;
+/**
+ *
+ */
+public class MyTest {
+
+ @Rule
+ public ExternalResource er= new ExternalResource() {
+ @Override
+ protected void before() throws Throwable {
+ };
+
+ @Override
+ protected void after() {
+ };
+ };
+
+ @Test
+ public void test3() {
+ }
+}
+"""),
+RuleNestedExternalResource(
+"""
+package test;
+import org.junit.Test;
+import org.junit.Rule;
+import org.junit.rules.ExternalResource;
+/**
+ *
+ */
+public class MyTest {
+
+ final class MyExternalResource extends ExternalResource {
+ @Override
+ protected void before() throws Throwable {
+ super.before();
+ int i=4;
+ }
+
+ @Override
+ protected void after() {
+ super.after();
+ }
+ }
+
+ @Rule
+ public ExternalResource er= new MyExternalResource();
+
+ @Test
+ public void test3() {
+ }
+}
+""", //$NON-NLS-1$
+"""
+package test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.RegisterExtension;
+/**
+ *
+ */
+public class MyTest {
+
+ final class MyExternalResource implements BeforeEachCallback, AfterEachCallback {
+ @Override
+ public void beforeEach(ExtensionContext context) {
+ super.beforeEach(context);
+ int i=4;
+ }
+
+ @Override
+ public void afterEach(ExtensionContext context) {
+ super.afterEach(context);
+ }
+ }
+
+ @RegisterExtension
+ public ExternalResource er= new MyExternalResource();
+
+ @Test
+ public void test3() {
+ }
+}
+"""),
+ TestnameRule(
+"""
+package test;
+import java.io.File;
+import java.io.IOException;
+import org.junit.Test;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+import org.junit.rules.TemporaryFolder;
+/**
+ *
+ */
+public class MyTest {
+
+ private static final String SRC= "src";
+
+ @Rule
+ public TemporaryFolder tempFolder = new TemporaryFolder();
+
+ @Rule
+ public TestName tn = new TestName();
+
+ @Test
+ public void test3() throws IOException{
+ System.out.println("Test name: " + tn.getMethodName());
+ File newFile = tempFolder.newFile("myfile.txt");
+ }
+}
+""", //$NON-NLS-1$
+"""
+package test;
+import java.io.File;
+import java.io.IOException;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.io.TempDir;
+/**
+ *
+ */
+public class MyTest {
+
+ @TempDir
+ Path tempFolder;
+
+ private String testName;
+
+ @BeforeEach
+ void init(TestInfo testInfo) {
+ this.testName = testInfo.getDisplayName();
+ }
+
+ private static final String SRC= "src";
+
+ @Test
+ public void test3() throws IOException{
+ System.out.println("Test name: " + testName);
+ File newFile = tempFolder.resolve("myfile.txt").toFile();
+ }
+}
+"""); //$NON-NLS-1$
+
+ String given;
+ String expected;
+
+ JUnitCleanupCases(String given, String expected) {
+ this.given=given;
+ this.expected=expected;
+ }
+ }
+
+ @ParameterizedTest
+ @EnumSource(JUnitCleanupCases.class)
+ public void testJUnitCleanupParametrized(JUnitCleanupCases test) throws CoreException {
+ IPackageFragment pack= fRootJUnit4.createPackageFragment("test", true, null);
+ ICompilationUnit cu= pack.createCompilationUnit("MyTest.java", test.given, true, null); //$NON-NLS-1$
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSERT);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSUME);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_SUITE);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORE);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTER);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORECLASS);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTERCLASS);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_IGNORE);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_TEST);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETEMPORARYFOLDER);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETESTNAME);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_EXTERNALRESOURCE);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RUNWITH);
+ context4junit4.assertRefactoringResultAsExpected(new ICompilationUnit[] {cu}, new String[] {test.expected}, null);
+ }
+
+ enum NOJUnitCleanupCases {
+
+NOCase(
+"""
+package test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+/**
+ *
+ */
+public class MyTest {
+
+ @Test
+ public void test3() {
+ assertEquals("expected", "actual");
+ }
+}
+"""), //$NON-NLS-1$
+UnrelatedCodeCase(
+"""
+package test;
+/**
+ *
+ */
+public class MyTest {
+
+}
+""") //$NON-NLS-1$
+ ;
+
+ NOJUnitCleanupCases(String given) {
+ this.given=given;
+ }
+
+ String given;
+ }
+
+ @ParameterizedTest
+ @EnumSource(NOJUnitCleanupCases.class)
+ public void testJUnitCleanupdonttouch(NOJUnitCleanupCases test) throws CoreException {
+ IPackageFragment pack= fRootJUnit5.createPackageFragment("test", true, null);
+ ICompilationUnit cu= pack.createCompilationUnit("MyTest.java",test.given,false, null); //$NON-NLS-1$
+ context4junit5.enable(MYCleanUpConstants.JUNIT_CLEANUP);
+ context4junit5.assertRefactoringHasNoChange(new ICompilationUnit[] { cu });
+ }
+
+ @Test
+ public void testJUnitCleanupTwoFiles() throws CoreException {
+ IPackageFragment pack= fRootJUnit4.createPackageFragment("test", true, null);
+ ICompilationUnit cu= pack.createCompilationUnit("MyTest.java",
+"""
+package test;
+import org.junit.Test;
+import org.junit.Rule;
+import test.MyExternalResource;
+/**
+ *
+ */
+public class MyTest {
+
+ @Rule
+ public MyExternalResource er= new MyExternalResource();
+
+ @Before
+ public void genericbefore(){
+ er.start();
+ }
+
+ @Test
+ public void test3() {
+ }
+}
+""", false, null); //$NON-NLS-1$
+ ICompilationUnit cu2= pack.createCompilationUnit("MyExternalResource.java",
+"""
+package test;
+import org.junit.rules.ExternalResource;
+/**
+ *
+ */
+public class MyExternalResource extends ExternalResource {
+ @Override
+ protected void before() throws Throwable {
+ int i=4;
+ }
+
+ @Override
+ protected void after() {
+ }
+
+ public start(){
+ }
+}
+""", false, null); //$NON-NLS-1$
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSERT);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSUME);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_SUITE);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORE);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTER);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORECLASS);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTERCLASS);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_IGNORE);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_TEST);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETEMPORARYFOLDER);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETESTNAME);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_EXTERNALRESOURCE);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RUNWITH);
+ context4junit4.assertRefactoringResultAsExpected(new ICompilationUnit[] {cu,cu2}, new String[] {
+"""
+package test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import test.MyExternalResource;
+/**
+ *
+ */
+public class MyTest {
+
+ @RegisterExtension
+ public MyExternalResource er= new MyExternalResource();
+
+ @Before
+ public void genericbefore(){
+ er.start();
+ }
+
+ @Test
+ public void test3() {
+ }
+}
+"""
+,
+"""
+package test;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+/**
+ *
+ */
+public class MyExternalResource implements BeforeEachCallback, AfterEachCallback {
+ @Override
+ public void beforeEach(ExtensionContext context) {
+ int i=4;
+ }
+
+ @Override
+ public void afterEach(ExtensionContext context) {
+ }
+
+ public start(){
+ }
+}
+"""
+}, null);
+ }
+
+ @Test
+ public void testJUnitCleanupTwoFilesb() throws CoreException {
+ IPackageFragment pack= fRootJUnit4.createPackageFragment("test", true, null);
+ ICompilationUnit cu= pack.createCompilationUnit("MyTest.java",
+"""
+package test;
+import test.MyExternalResource;
+/**
+ *
+ */
+public class MyTest extends MyExternalResource {
+
+}
+""", false, null); //$NON-NLS-1$
+ ICompilationUnit cu2= pack.createCompilationUnit("MyExternalResource.java",
+"""
+package test;
+import org.junit.rules.ExternalResource;
+/**
+ *
+ */
+public class MyExternalResource extends ExternalResource {
+ @Override
+ protected void before() throws Throwable {
+ int i=4;
+ }
+
+ @Override
+ protected void after() {
+ }
+
+ public start(){
+ }
+}
+""", false, null); //$NON-NLS-1$
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSERT);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSUME);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_SUITE);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORE);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTER);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORECLASS);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTERCLASS);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_IGNORE);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_TEST);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETEMPORARYFOLDER);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETESTNAME);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_EXTERNALRESOURCE);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RUNWITH);
+ context4junit4.assertRefactoringResultAsExpected(new ICompilationUnit[] {cu,cu2}, new String[] {
+"""
+package test;
+import test.MyExternalResource;
+/**
+ *
+ */
+public class MyTest extends MyExternalResource {
+
+}
+"""
+,
+"""
+package test;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+/**
+ *
+ */
+public class MyExternalResource implements BeforeEachCallback, AfterEachCallback {
+ @Override
+ public void beforeEach(ExtensionContext context) {
+ int i=4;
+ }
+
+ @Override
+ public void afterEach(ExtensionContext context) {
+ }
+
+ public start(){
+ }
+}
+"""
+}, null);
+ }
+
+ @Test
+ public void testJUnitCleanupThreeFiles() throws CoreException {
+ IPackageFragment pack= fRootJUnit4.createPackageFragment("test", true, null);
+ ICompilationUnit cu= pack.createCompilationUnit("MyTest.java",
+"""
+package test;
+import org.junit.Test;
+import org.junit.Rule;
+import test.MyExternalResource;
+
+public class MyTest {
+
+ @Rule
+ public MyExternalResource er= new MyExternalResource();
+
+ @Test
+ public void test3() {
+ }
+}
+""", false, null); //$NON-NLS-1$
+ ICompilationUnit cu2= pack.createCompilationUnit("MyExternalResource.java",
+"""
+package test;
+import test.MyExternalResource2;
+
+public class MyExternalResource extends MyExternalResource2 {
+ @Override
+ protected void before() throws Throwable {
+ super.before();
+ int i=4;
+ }
+
+ @Override
+ protected void after() {
+ }
+}
+""", false, null); //$NON-NLS-1$
+
+ ICompilationUnit cu3= pack.createCompilationUnit("MyExternalResource2.java",
+"""
+package test;
+import org.junit.rules.ExternalResource;
+
+public class MyExternalResource2 extends ExternalResource {
+ @Override
+ protected void before() throws Throwable {
+ super.before();
+ int i=4;
+ }
+
+ @Override
+ protected void after() {
+ }
+}
+""", false, null); //$NON-NLS-1$
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSERT);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSUME);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_SUITE);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORE);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTER);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORECLASS);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTERCLASS);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_IGNORE);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_TEST);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETEMPORARYFOLDER);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETESTNAME);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_EXTERNALRESOURCE);
+ context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RUNWITH);
+ context4junit4.assertRefactoringResultAsExpected(new ICompilationUnit[] {cu,cu2,cu3}, new String[] {
+"""
+package test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import test.MyExternalResource;
+
+public class MyTest {
+
+ @RegisterExtension
+ public MyExternalResource er= new MyExternalResource();
+
+ @Test
+ public void test3() {
+ }
+}
+"""
+,
+"""
+package test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+import test.MyExternalResource2;
+
+public class MyExternalResource extends MyExternalResource2 {
+ @Override
+ public void beforeEach(ExtensionContext context) {
+ super.beforeEach(context);
+ int i=4;
+ }
+
+ @Override
+ public void afterEach(ExtensionContext context) {
+ }
+}
+""",
+"""
+package test;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+public class MyExternalResource2 implements BeforeEachCallback, AfterEachCallback {
+ @Override
+ public void beforeEach(ExtensionContext context) {
+ super.beforeEach(context);
+ int i=4;
+ }
+
+ @Override
+ public void afterEach(ExtensionContext context) {
+ }
+}
+"""
+}, null);
+ }
+}
diff --git a/sandbox_junit_cleanup_test/testresources/rtstubs18.jar b/sandbox_junit_cleanup_test/testresources/rtstubs18.jar
new file mode 100644
index 00000000..225d9100
Binary files /dev/null and b/sandbox_junit_cleanup_test/testresources/rtstubs18.jar differ
diff --git a/sandbox_junit_cleanup_test/testresources/rtstubs9.jar b/sandbox_junit_cleanup_test/testresources/rtstubs9.jar
new file mode 100644
index 00000000..21fe246e
Binary files /dev/null and b/sandbox_junit_cleanup_test/testresources/rtstubs9.jar differ
diff --git a/sandbox_junit_cleanup_test/testresources/rtstubs_17.jar b/sandbox_junit_cleanup_test/testresources/rtstubs_17.jar
new file mode 100644
index 00000000..fb6cb938
Binary files /dev/null and b/sandbox_junit_cleanup_test/testresources/rtstubs_17.jar differ
diff --git a/sandbox_oomph/sandbox.setup b/sandbox_oomph/sandbox.setup
index 64841e86..1b3d15e8 100644
--- a/sandbox_oomph/sandbox.setup
+++ b/sandbox_oomph/sandbox.setup
@@ -78,7 +78,7 @@
value="${installation.location/}${installation.relativeProductFolder}"/>
+ requiredJavaVersion="21">
@@ -219,7 +219,7 @@
+ url="http://download.eclipse.org/releases/2024-06"/>
diff --git a/sandbox_oomph/sandboxproject.setup b/sandbox_oomph/sandboxproject.setup
index eafa0e0f..9df8a34f 100644
--- a/sandbox_oomph/sandboxproject.setup
+++ b/sandbox_oomph/sandboxproject.setup
@@ -62,8 +62,8 @@
label="Git Clone location"/>
+ version="JavaSE-21"
+ location="${jre.location-21}">
Define the JRE needed to compile and run the Java projects of ${scope.project.label}
The dynamic working sets for ${scope.project.label}
-
-
-
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_platform_helper
Sandbox platform helper
diff --git a/sandbox_platform_helper_feature/feature.xml b/sandbox_platform_helper_feature/feature.xml
index 0eabb771..fd936473 100644
--- a/sandbox_platform_helper_feature/feature.xml
+++ b/sandbox_platform_helper_feature/feature.xml
@@ -2,7 +2,7 @@
diff --git a/sandbox_platform_helper_feature/pom.xml b/sandbox_platform_helper_feature/pom.xml
index a6e57881..d1e67701 100644
--- a/sandbox_platform_helper_feature/pom.xml
+++ b/sandbox_platform_helper_feature/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_platform_helper_feature
Sandbox platform helper Feature
diff --git a/sandbox_platform_helper_test/META-INF/MANIFEST.MF b/sandbox_platform_helper_test/META-INF/MANIFEST.MF
index 077cfb79..04eabe73 100644
--- a/sandbox_platform_helper_test/META-INF/MANIFEST.MF
+++ b/sandbox_platform_helper_test/META-INF/MANIFEST.MF
@@ -3,9 +3,9 @@ Bundle-ManifestVersion: 2
Bundle-Name: platform helper tests
Bundle-SymbolicName: sandbox_platform_helper_test;singleton:=true
Bundle-Vendor: sandbox
-Bundle-Version: 1.1.0.qualifier
+Bundle-Version: 1.2.0.qualifier
Fragment-Host: sandbox_platform_helper
-Bundle-RequiredExecutionEnvironment: JavaSE-17
+Bundle-RequiredExecutionEnvironment: JavaSE-21
Require-Bundle: org.junit,
sandbox_test_commons
Bundle-ActivationPolicy: lazy
diff --git a/sandbox_platform_helper_test/pom.xml b/sandbox_platform_helper_test/pom.xml
index c4fc71f9..1b1298c4 100644
--- a/sandbox_platform_helper_test/pom.xml
+++ b/sandbox_platform_helper_test/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_platform_helper_test
Sandbox platform helper test
diff --git a/sandbox_product/category.xml b/sandbox_product/category.xml
index e939e6ba..279c1700 100644
--- a/sandbox_product/category.xml
+++ b/sandbox_product/category.xml
@@ -21,11 +21,17 @@
+
+
+
+
+
+
Description of sandbox category
-
-
+
+
diff --git a/sandbox_product/pom.xml b/sandbox_product/pom.xml
index d7a08fac..b8146f4a 100644
--- a/sandbox_product/pom.xml
+++ b/sandbox_product/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_product
Sandbox product
@@ -24,6 +24,10 @@
org.sandbox
sandbox_jface_cleanup_feature
+
+ org.sandbox
+ sandbox_junit_cleanup_feature
+
org.sandbox
sandbox_tools_feature
@@ -42,7 +46,7 @@
- sandbox.repository_${rcp-version}-1.1.0
+ sandbox.repository_${rcp-version}-1.2.0
org.eclipse.tycho
diff --git a/sandbox_product/sandbox.product b/sandbox_product/sandbox.product
index 16b84bfe..cfb22cd0 100644
--- a/sandbox_product/sandbox.product
+++ b/sandbox_product/sandbox.product
@@ -1,7 +1,7 @@
-
+
@@ -13,7 +13,7 @@
-Xmx1024m
-XX:+UseG1GC
-XX:+UseStringDeduplication
--Dosgi.requiredJavaVersion=11
+-Dosgi.requiredJavaVersion=21
-Dosgi.dataAreaRequiresExplicitInit=true
-Dorg.eclipse.swt.graphics.Resource.reportNonDisposed=true
--add-modules=ALL-SYSTEM
@@ -190,33 +190,13 @@ United States, other countries, or both.
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -224,26 +204,26 @@ United States, other countries, or both.
-
-
+
+
+
+
+
+
-
+
-
+
-
-
-
-
-
-
+
+
diff --git a/sandbox_product/sandbox.product.launch b/sandbox_product/sandbox.product.launch
index f1a619ee..dbc18273 100644
--- a/sandbox_product/sandbox.product.launch
+++ b/sandbox_product/sandbox.product.launch
@@ -1,15 +1,15 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
@@ -29,79 +29,47 @@
-
-
+
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -114,894 +82,232 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
diff --git a/sandbox_target/eclipse.target b/sandbox_target/eclipse.target
index 0e6e8420..6f63be26 100644
--- a/sandbox_target/eclipse.target
+++ b/sandbox_target/eclipse.target
@@ -2,78 +2,83 @@
-
-
-
-
+
-
+ -->
+
@@ -88,61 +93,168 @@ Failed to resolve target definition C:\Users\chammer\git\sandbox\sandbox_target\
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sandbox_target/pom.xml b/sandbox_target/pom.xml
index 15afb1ca..a75e7a6f 100644
--- a/sandbox_target/pom.xml
+++ b/sandbox_target/pom.xml
@@ -5,7 +5,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_target
Sandbox target
diff --git a/sandbox_test_commons/.classpath b/sandbox_test_commons/.classpath
index 53a714c3..62a22e28 100644
--- a/sandbox_test_commons/.classpath
+++ b/sandbox_test_commons/.classpath
@@ -4,15 +4,8 @@
-
-
-
-
-
-
-
-
+
diff --git a/sandbox_test_commons/META-INF/MANIFEST.MF b/sandbox_test_commons/META-INF/MANIFEST.MF
index 0fb14d65..4f62289f 100644
--- a/sandbox_test_commons/META-INF/MANIFEST.MF
+++ b/sandbox_test_commons/META-INF/MANIFEST.MF
@@ -2,19 +2,30 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: sandbox test commons
Bundle-SymbolicName: sandbox_test_commons;singleton:=true
-Bundle-Version: 1.1.0.qualifier
-Bundle-RequiredExecutionEnvironment: JavaSE-17
+Bundle-Version: 1.2.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-21
Automatic-Module-Name: sandbox.test.commons.singleton.true
Eclipse-BuddyPolicy: global
Eclipse-BundleShape: dir
-Import-Package: org.junit.jupiter.api;version="5.7.1",
- org.junit.jupiter.api.extension;version="5.7.1"
+Import-Package: org.junit.jupiter.api,
+ org.junit.jupiter.api.condition,
+ org.junit.jupiter.api.extension,
+ org.junit.jupiter.api.extension.support,
+ org.junit.jupiter.api.function,
+ org.junit.jupiter.api.io,
+ org.junit.jupiter.api.parallel,
+ org.junit.jupiter.params
Bundle-ActivationPolicy: lazy
-Require-Bundle: org.junit,
- org.eclipse.jdt.ui,
+Require-Bundle: org.eclipse.jdt.ui,
org.eclipse.jdt.core,
org.eclipse.osgi,
org.eclipse.core.resources,
org.eclipse.core.runtime,
- org.eclipse.ltk.core.refactoring
+ org.eclipse.ltk.core.refactoring,
+ org.eclipse.jdt.junit4.runtime,
+ org.eclipse.jdt.junit5.runtime,
+ org.junit,
+ org.eclipse.jdt.junit;visibility:=reexport,
+ org.eclipse.jdt.junit.core;visibility:=reexport,
+ org.eclipse.jdt.junit.runtime
Export-Package: org.sandbox.jdt.ui.tests.quickfix.rules
diff --git a/sandbox_test_commons/pom.xml b/sandbox_test_commons/pom.xml
index 95c515f0..ad9bef54 100644
--- a/sandbox_test_commons/pom.xml
+++ b/sandbox_test_commons/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_test_commons
Sandbox test commons
diff --git a/sandbox_test_commons/src/org/sandbox/jdt/ui/tests/quickfix/rules/AbstractEclipseJava.java b/sandbox_test_commons/src/org/sandbox/jdt/ui/tests/quickfix/rules/AbstractEclipseJava.java
index 6f20daf7..f67c9ff5 100644
--- a/sandbox_test_commons/src/org/sandbox/jdt/ui/tests/quickfix/rules/AbstractEclipseJava.java
+++ b/sandbox_test_commons/src/org/sandbox/jdt/ui/tests/quickfix/rules/AbstractEclipseJava.java
@@ -78,8 +78,9 @@ public class AbstractEclipseJava implements AfterEachCallback, BeforeEachCallbac
private final String testresources_stubs;
private final String compliance;
private static final String TEST_SETUP_PROJECT= "TestSetupProject"; //$NON-NLS-1$
- private IPackageFragmentRoot fSourceFolder;
+ private IPackageFragmentRoot fSourceFolder;
private CustomProfile fProfile;
+ private IJavaProject javaProject;
public AbstractEclipseJava(String stubs, String compilerversion) {
this.testresources_stubs= stubs;
@@ -88,11 +89,11 @@ public AbstractEclipseJava(String stubs, String compilerversion) {
@Override
public void beforeEach(ExtensionContext context) throws CoreException {
- IJavaProject javaProject= createJavaProject(TEST_SETUP_PROJECT, "bin"); //$NON-NLS-1$
- javaProject.setRawClasspath(getDefaultClasspath(), null);
- Map options= javaProject.getOptions(false);
+ setJavaProject(createJavaProject(TEST_SETUP_PROJECT, "bin")); //$NON-NLS-1$
+ getJavaProject().setRawClasspath(getDefaultClasspath(), null);
+ Map options= getJavaProject().getOptions(false);
JavaCore.setComplianceOptions(compliance, options);
- javaProject.setOptions(options);
+ getJavaProject().setOptions(options);
setfSourceFolder(addSourceContainer(getProject(TEST_SETUP_PROJECT), "src", new Path[0], //$NON-NLS-1$
new Path[0], null, new IClasspathAttribute[0]));
Map settings= new HashMap<>();
@@ -103,6 +104,15 @@ public void beforeEach(ExtensionContext context) throws CoreException {
fProfile.getID());
disableAll();
}
+
+ public IPackageFragmentRoot createClasspathForJUnit(IPath junitContainerPath) throws JavaModelException, CoreException {
+ IJavaProject fProject = getJavaProject();
+ fProject.setRawClasspath(getDefaultClasspath(), null);
+ IClasspathEntry cpe= JavaCore.newContainerEntry(junitContainerPath);
+ AbstractEclipseJava.addToClasspath(fProject, cpe);
+ fSourceFolder= AbstractEclipseJava.addSourceContainer(fProject, "src");
+ return fSourceFolder;
+ }
@Override
public void afterEach(ExtensionContext context) throws CoreException {
@@ -290,6 +300,56 @@ public static IPackageFragmentRoot addSourceContainer(IJavaProject jproject, Str
return root;
}
+ /**
+ * Adds a source container to a IJavaProject.
+ * @param jproject The parent project
+ * @param containerName The name of the new source container
+ * @return The handle to the new source container
+ * @throws CoreException Creation failed
+ */
+ public static IPackageFragmentRoot addSourceContainer(IJavaProject jproject, String containerName) throws CoreException {
+ return addSourceContainer(jproject, containerName, new Path[0]);
+ }
+
+ /**
+ * Adds a source container to a IJavaProject.
+ * @param jproject The parent project
+ * @param containerName The name of the new source container
+ * @param exclusionFilters Exclusion filters to set
+ * @return The handle to the new source container
+ * @throws CoreException Creation failed
+ */
+ public static IPackageFragmentRoot addSourceContainer(IJavaProject jproject, String containerName, IPath[] exclusionFilters) throws CoreException {
+ return addSourceContainer(jproject, containerName, new Path[0], exclusionFilters);
+ }
+
+ /**
+ * Adds a source container to a IJavaProject.
+ * @param jproject The parent project
+ * @param containerName The name of the new source container
+ * @param inclusionFilters Inclusion filters to set
+ * @param exclusionFilters Exclusion filters to set
+ * @return The handle to the new source container
+ * @throws CoreException Creation failed
+ */
+ public static IPackageFragmentRoot addSourceContainer(IJavaProject jproject, String containerName, IPath[] inclusionFilters, IPath[] exclusionFilters) throws CoreException {
+ return addSourceContainer(jproject, containerName, inclusionFilters, exclusionFilters, null);
+ }
+
+ /**
+ * Adds a source container to a IJavaProject.
+ * @param jproject The parent project
+ * @param containerName The name of the new source container
+ * @param inclusionFilters Inclusion filters to set
+ * @param exclusionFilters Exclusion filters to set
+ * @param outputLocation The location where class files are written to, null for project output folder
+ * @return The handle to the new source container
+ * @throws CoreException Creation failed
+ */
+ public static IPackageFragmentRoot addSourceContainer(IJavaProject jproject, String containerName, IPath[] inclusionFilters, IPath[] exclusionFilters, String outputLocation) throws CoreException {
+ return addSourceContainer(jproject, containerName, inclusionFilters, exclusionFilters, outputLocation,
+ new IClasspathAttribute[0]);
+ }
public static void addToClasspath(IJavaProject jproject, IClasspathEntry cpe) throws JavaModelException {
IClasspathEntry[] oldEntries= jproject.getRawClasspath();
for (IClasspathEntry oldEntry : oldEntries) {
@@ -471,4 +531,12 @@ public IPackageFragmentRoot getfSourceFolder() {
public void setfSourceFolder(IPackageFragmentRoot fSourceFolder) {
this.fSourceFolder = fSourceFolder;
}
+
+ public IJavaProject getJavaProject() {
+ return javaProject;
+ }
+
+ public void setJavaProject(IJavaProject javaProject) {
+ this.javaProject = javaProject;
+ }
}
diff --git a/sandbox_tools/META-INF/MANIFEST.MF b/sandbox_tools/META-INF/MANIFEST.MF
index 04a053a9..2bba2274 100644
--- a/sandbox_tools/META-INF/MANIFEST.MF
+++ b/sandbox_tools/META-INF/MANIFEST.MF
@@ -2,8 +2,8 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: tools
Bundle-SymbolicName: sandbox_tools;singleton:=true
-Bundle-Version: 1.1.0.qualifier
-Bundle-RequiredExecutionEnvironment: JavaSE-17
+Bundle-Version: 1.2.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-21
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.filebuffers,
org.eclipse.core.filesystem,
diff --git a/sandbox_tools/pom.xml b/sandbox_tools/pom.xml
index fb65e2b4..bb7213f5 100644
--- a/sandbox_tools/pom.xml
+++ b/sandbox_tools/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_tools
Sandbox tools
diff --git a/sandbox_tools_feature/feature.xml b/sandbox_tools_feature/feature.xml
index e08756d0..79f840c2 100644
--- a/sandbox_tools_feature/feature.xml
+++ b/sandbox_tools_feature/feature.xml
@@ -2,7 +2,7 @@
diff --git a/sandbox_tools_feature/pom.xml b/sandbox_tools_feature/pom.xml
index e448f127..48fbdfb1 100644
--- a/sandbox_tools_feature/pom.xml
+++ b/sandbox_tools_feature/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_tools_feature
Sandbox tools Feature
diff --git a/sandbox_tools_test/META-INF/MANIFEST.MF b/sandbox_tools_test/META-INF/MANIFEST.MF
index 4c0be004..e9bd81ac 100644
--- a/sandbox_tools_test/META-INF/MANIFEST.MF
+++ b/sandbox_tools_test/META-INF/MANIFEST.MF
@@ -2,9 +2,9 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Tools tests
Bundle-SymbolicName: sandbox_tools_test;singleton:=true
-Bundle-Version: 1.1.0.qualifier
+Bundle-Version: 1.2.0.qualifier
Fragment-Host: sandbox_tools
-Bundle-RequiredExecutionEnvironment: JavaSE-17
+Bundle-RequiredExecutionEnvironment: JavaSE-21
Require-Bundle: sandbox_test_commons
Bundle-ActivationPolicy: lazy
Eclipse-BundleShape: dir
diff --git a/sandbox_tools_test/pom.xml b/sandbox_tools_test/pom.xml
index 19ad1907..86e210dc 100644
--- a/sandbox_tools_test/pom.xml
+++ b/sandbox_tools_test/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_tools_test
Sandbox tools test
diff --git a/sandbox_usage_view/META-INF/MANIFEST.MF b/sandbox_usage_view/META-INF/MANIFEST.MF
index 46d2c66b..636e3092 100644
--- a/sandbox_usage_view/META-INF/MANIFEST.MF
+++ b/sandbox_usage_view/META-INF/MANIFEST.MF
@@ -2,9 +2,9 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: sandbox_usage_view
Bundle-SymbolicName: sandbox_usage_view;singleton:=true
-Bundle-Version: 1.1.0.qualifier
+Bundle-Version: 1.2.0.qualifier
Automatic-Module-Name: ui.sandbox.fragment
-Bundle-RequiredExecutionEnvironment: JavaSE-17
+Bundle-RequiredExecutionEnvironment: JavaSE-21
Bundle-ActivationPolicy: lazy
Eclipse-BuddyPolicy: global
Require-Bundle: org.eclipse.core.runtime,
diff --git a/sandbox_usage_view/pom.xml b/sandbox_usage_view/pom.xml
index 87c24d47..646f87e7 100644
--- a/sandbox_usage_view/pom.xml
+++ b/sandbox_usage_view/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_usage_view
Sandbox usage view
diff --git a/sandbox_usage_view_feature/feature.xml b/sandbox_usage_view_feature/feature.xml
index 1fa8659b..55ba66dc 100644
--- a/sandbox_usage_view_feature/feature.xml
+++ b/sandbox_usage_view_feature/feature.xml
@@ -2,7 +2,7 @@
diff --git a/sandbox_usage_view_feature/pom.xml b/sandbox_usage_view_feature/pom.xml
index a0120dcd..a350af71 100644
--- a/sandbox_usage_view_feature/pom.xml
+++ b/sandbox_usage_view_feature/pom.xml
@@ -4,7 +4,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_usage_view_feature
Sandbox usage view Feature
diff --git a/sandbox_web/.settings/org.eclipse.core.resources.prefs b/sandbox_web/.settings/org.eclipse.core.resources.prefs
index 4824b802..4c28b1a8 100644
--- a/sandbox_web/.settings/org.eclipse.core.resources.prefs
+++ b/sandbox_web/.settings/org.eclipse.core.resources.prefs
@@ -1,2 +1,4 @@
eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding//src/test/java=UTF-8
encoding/=UTF-8
diff --git a/sandbox_web/pom.xml b/sandbox_web/pom.xml
index 34117108..60fc2a11 100644
--- a/sandbox_web/pom.xml
+++ b/sandbox_web/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_web
RCP Sandbox p2 update site
@@ -24,6 +24,10 @@
org.sandbox
sandbox_jface_cleanup_feature
+
+ org.sandbox
+ sandbox_junit_cleanup_feature
+
org.sandbox
sandbox_platform_helper_feature
diff --git a/sandbox_xml_cleanup/META-INF/MANIFEST.MF b/sandbox_xml_cleanup/META-INF/MANIFEST.MF
index b8ecb9dc..1eb7810e 100644
--- a/sandbox_xml_cleanup/META-INF/MANIFEST.MF
+++ b/sandbox_xml_cleanup/META-INF/MANIFEST.MF
@@ -2,8 +2,8 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: xml_cleanup
Bundle-SymbolicName: sandbox_xml_cleanup;singleton:=true
-Bundle-Version: 1.1.0.qualifier
-Bundle-RequiredExecutionEnvironment: JavaSE-17
+Bundle-Version: 1.2.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-21
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.filebuffers,
org.eclipse.core.filesystem,
diff --git a/sandbox_xml_cleanup/pom.xml b/sandbox_xml_cleanup/pom.xml
index b0872d54..9150161c 100644
--- a/sandbox_xml_cleanup/pom.xml
+++ b/sandbox_xml_cleanup/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_xml_cleanup
Sandbox xml cleanup
diff --git a/sandbox_xml_cleanup_feature/feature.xml b/sandbox_xml_cleanup_feature/feature.xml
index c211519e..6f9e658c 100644
--- a/sandbox_xml_cleanup_feature/feature.xml
+++ b/sandbox_xml_cleanup_feature/feature.xml
@@ -2,7 +2,7 @@
@@ -33,15 +33,11 @@
-
+ version="0.0.0"/>
diff --git a/sandbox_xml_cleanup_feature/pom.xml b/sandbox_xml_cleanup_feature/pom.xml
index 58a6e565..10ed5a37 100644
--- a/sandbox_xml_cleanup_feature/pom.xml
+++ b/sandbox_xml_cleanup_feature/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_xml_cleanup_feature
Sandbox xml cleanup Feature
diff --git a/sandbox_xml_cleanup_test/META-INF/MANIFEST.MF b/sandbox_xml_cleanup_test/META-INF/MANIFEST.MF
index 0e5924b1..28f2ec95 100644
--- a/sandbox_xml_cleanup_test/META-INF/MANIFEST.MF
+++ b/sandbox_xml_cleanup_test/META-INF/MANIFEST.MF
@@ -2,9 +2,9 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: xml cleanup tests
Bundle-SymbolicName: sandbox_xml_cleanup_test;singleton:=true
-Bundle-Version: 1.1.0.qualifier
+Bundle-Version: 1.2.0.qualifier
Fragment-Host: sandbox_xml_cleanup
-Bundle-RequiredExecutionEnvironment: JavaSE-17
+Bundle-RequiredExecutionEnvironment: JavaSE-21
Require-Bundle: org.junit,
org.eclipse.jdt.ui,
org.eclipse.jdt.core,
diff --git a/sandbox_xml_cleanup_test/pom.xml b/sandbox_xml_cleanup_test/pom.xml
index d3d42ab9..d3c54cc4 100644
--- a/sandbox_xml_cleanup_test/pom.xml
+++ b/sandbox_xml_cleanup_test/pom.xml
@@ -6,7 +6,7 @@
org.sandbox
central
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
sandbox_xml_cleanup_test
Sandbox xml cleanup test