-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2549174
commit 3e0dd7c
Showing
40 changed files
with
1,205 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source.. = src/ | ||
bin.includes = META-INF/,\ | ||
.,\ | ||
plugin.xml,\ | ||
build.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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> |
84 changes: 84 additions & 0 deletions
84
sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/JUnitCleanUpFixCore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
}; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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()); | ||
} | ||
} |
Oops, something went wrong.