Skip to content

Commit

Permalink
add skeleton with only renamings
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenartur committed Oct 12, 2024
1 parent 2549174 commit 3e0dd7c
Show file tree
Hide file tree
Showing 40 changed files with 1,205 additions and 17 deletions.
18 changes: 18 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<module>sandbox_jface_cleanup</module>
<module>sandbox_jface_cleanup_feature</module>
<module>sandbox_jface_cleanup_test</module>
<module>sandbox_junit_cleanup</module>
<module>sandbox_junit_cleanup_feature</module>
<module>sandbox_junit_cleanup_test</module>
<module>sandbox_usage_view</module>
<module>sandbox_usage_view_feature</module>
<module>sandbox_product</module>
Expand Down Expand Up @@ -322,6 +325,21 @@
<artifactId>sandbox_jface_cleanup_test</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.sandbox</groupId>
<artifactId>sandbox_junit_cleanup</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.sandbox</groupId>
<artifactId>sandbox_junit_cleanup_feature</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.sandbox</groupId>
<artifactId>sandbox_junit_cleanup_test</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.sandbox</groupId>
<artifactId>sandbox_usage_view</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ 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$
/**
*
*/
Expand Down
9 changes: 9 additions & 0 deletions sandbox_jface_cleanup/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions sandbox_junit_cleanup/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
1 change: 1 addition & 0 deletions sandbox_junit_cleanup/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
34 changes: 34 additions & 0 deletions sandbox_junit_cleanup/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>sandbox_junit_cleanup</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
26 changes: 26 additions & 0 deletions sandbox_junit_cleanup/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: junit_cleanup
Bundle-SymbolicName: sandbox_junit_cleanup;singleton:=true
Bundle-Version: 1.1.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-17
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
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
5 changes: 5 additions & 0 deletions sandbox_junit_cleanup/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source.. = src/
bin.includes = META-INF/,\
.,\
plugin.xml,\
build.properties
12 changes: 12 additions & 0 deletions sandbox_junit_cleanup/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<extension point="org.eclipse.jdt.ui.cleanUps">
<cleanUpConfigurationUI class="org.sandbox.jdt.internal.ui.preferences.cleanup.SandboxCodeTabPage" cleanUpKind="cleanUp" name="SandboxCode" />
<cleanUpConfigurationUI class="org.sandbox.jdt.internal.ui.preferences.cleanup.SandboxCodeTabPage" name="SandboxCode" cleanUpKind="saveAction" />
<cleanUpOptionsInitializer class="org.sandbox.jdt.internal.ui.preferences.cleanup.DefaultCleanUpOptionsInitializer" cleanUpKind="cleanUp"></cleanUpOptionsInitializer>
<cleanUpOptionsInitializer class="org.sandbox.jdt.internal.ui.preferences.cleanup.SaveActionCleanUpOptionsInitializer" cleanUpKind="saveAction"></cleanUpOptionsInitializer>

<cleanUp class="org.sandbox.jdt.internal.ui.fix.JUnitCleanUp" id="org.eclipse.jdt.ui.cleanup.junitcleanup" />
<!-- runAfter="org.eclipse.jdt.ui.cleanup.unboxing" -->
</extension>
</plugin>
17 changes: 17 additions & 0 deletions sandbox_junit_cleanup/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sandbox</groupId>
<artifactId>central</artifactId>
<version>1.1.0-SNAPSHOT</version>
</parent>
<artifactId>sandbox_junit_cleanup</artifactId>
<name>Sandbox junit cleanup</name>
<packaging>eclipse-plugin</packaging>
<build>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*******************************************************************************
* 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.CompilationUnitRewriteOperation;
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.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.JUnitPlugin;
import org.sandbox.jdt.internal.corext.fix.helper.JUnitPlugin.MonitorHolder;
import org.sandbox.jdt.internal.ui.fix.MultiFixMessages;

public enum JUnitCleanUpFixCore {

MONITOR(new JUnitPlugin());

AbstractTool<ReferenceHolder<Integer, MonitorHolder>> junitfound;

@SuppressWarnings("unchecked")
JUnitCleanUpFixCore(AbstractTool<? extends ReferenceHolder<Integer, MonitorHolder>> xmlsimplify) {
this.junitfound= (AbstractTool<ReferenceHolder<Integer, MonitorHolder>>) xmlsimplify;
}

public String getPreview(boolean i) {
return junitfound.getPreview(i);
}

/**
* Compute set of CompilationUnitRewriteOperation to refactor supported
* situations
*
* @param compilationUnit unit to search in
* @param operations set of all CompilationUnitRewriteOperations
* created already
* @param nodesprocessed list to remember nodes already processed
* @param createForOnlyIfVarUsed true if for loop should be created only only if
* loop var used within
*/
public void findOperations(final CompilationUnit compilationUnit,
final Set<CompilationUnitRewriteOperation> operations, final Set<ASTNode> nodesprocessed,
boolean createForOnlyIfVarUsed) {
junitfound.find(this, compilationUnit, operations, nodesprocessed, createForOnlyIfVarUsed);
}

public CompilationUnitRewriteOperation rewrite(final ReferenceHolder<Integer, MonitorHolder> hit) {
return new CompilationUnitRewriteOperation() {
@Override
public void rewriteAST(final CompilationUnitRewrite cuRewrite, final LinkedProposalModelCore linkedModel)
throws CoreException {
TextEditGroup group= createTextEditGroup(MultiFixMessages.JUnitCleanUp_description, 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);
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*******************************************************************************
* 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.Collection;
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.ITypeBinding;
import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.internal.corext.dom.AbortSearchException;
import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer;
import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation;
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
import org.eclipse.text.edits.TextEditGroup;
import org.sandbox.jdt.internal.corext.fix.JUnitCleanUpFixCore;

/**
* @param <T> Type found in Visitor
*/
public abstract class AbstractTool<T> {

protected static boolean isOfType(ITypeBinding typeBinding, String typename) {
if (typeBinding == null) {
throw new AbortSearchException();
}
if (typeBinding.isArray()) {
typeBinding= typeBinding.getElementType();

Check notice

Code scanning / Pmd (reported by Codacy)

Avoid reassigning parameters such as 'typeBinding' Note

Avoid reassigning parameters such as 'typeBinding'
}
return typeBinding.getQualifiedName().equals(typename);
}

public abstract void find(JUnitCleanUpFixCore fixcore, CompilationUnit compilationUnit,
Set<CompilationUnitRewriteOperation> operations, Set<ASTNode> nodesprocessed,
boolean createForIfVarNotUsed);

public abstract void rewrite(JUnitCleanUpFixCore useExplicitEncodingFixCore, T holder,
CompilationUnitRewrite cuRewrite, TextEditGroup group);

/**
* 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);
}

public abstract String getPreview(boolean afterRefactoring);

public static Collection<String> getUsedVariableNames(ASTNode node) {
CompilationUnit root= (CompilationUnit) node.getRoot();
return new ScopeAnalyzer(root).getUsedVariableNames(node.getStartPosition(), node.getLength());
}
}
Loading

0 comments on commit 3e0dd7c

Please sign in to comment.