Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove @Deprecated methods #3184

Merged
merged 7 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/first_transformation.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ public class ClassProcessor extends AbstractProcessor<CtClass<?>> {

## Refactoring transformations

Spoon can be used for automated refactoring such as renaming variables programmatically.
Spoon provides some methods for automated refactoring:.

* [Local Variable Refactoring](http://spoon.gforge.inria.fr/mvnsites/spoon-core/apidocs/spoon/refactoring/CtRenameLocalVariableRefactoring.html)
class, renames local variables and includes extra checking to ensure program correctness after renaming,
* [Generic Variable Refactoring](http://spoon.gforge.inria.fr/mvnsites/spoon-core/apidocs/spoon/refactoring/CtRenameGenericVariableRefactoring.html)
class, renames any variable type (field, parameter, local), but does not do any extra checking to ensure program correctness.
* `Refactoring` contains helper methods for refactoring, incl. one for automated removal of deprecated methods.
1 change: 0 additions & 1 deletion src/main/java/.cvsignore

This file was deleted.

34 changes: 34 additions & 0 deletions src/main/java/spoon/refactoring/Refactoring.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/
package spoon.refactoring;

import spoon.Launcher;
import spoon.SpoonException;
import spoon.processing.AbstractProcessor;
import spoon.reflect.code.CtLocalVariable;
import spoon.reflect.declaration.CtExecutable;
import spoon.reflect.declaration.CtField;
Expand All @@ -17,6 +19,7 @@
import spoon.reflect.visitor.CtScanner;
import spoon.reflect.visitor.Query;
import spoon.reflect.visitor.filter.TypeFilter;
import spoon.support.sniper.SniperJavaPrettyPrinter;

import java.util.List;

Expand Down Expand Up @@ -205,4 +208,35 @@ public <T> void visitCtFieldReference(CtFieldReference<T> reference) {
public static void changeLocalVariableName(CtLocalVariable<?> localVariable, String newName) throws RefactoringException {
new CtRenameLocalVariableRefactoring().setTarget(localVariable).setNewName(newName).refactor();
}

/** Deletes all deprecated methods in the given path */
public static void removeDeprecatedMethods(String path) {
Launcher spoon = new Launcher();
spoon.addInputResource(path);
spoon.setSourceOutputDirectory(path);
spoon.addProcessor(new AbstractProcessor<CtMethod>() {
@Override
public void process(CtMethod method) {
if (method.hasAnnotation(Deprecated.class)) {
method.delete();
}
}
});

// does not work, see https://github.com/INRIA/spoon/issues/3183
// spoon.addProcessor(new AbstractProcessor<CtType>() {
// @Override
// public void process(CtType type) {
// if (type.hasAnnotation(Deprecated.class)) {
// type.delete();
// }
// }
// });

spoon.getEnvironment().setPrettyPrinterCreator(() -> {
return new SniperJavaPrettyPrinter(spoon.getEnvironment());
}
);
spoon.run();
}
}
33 changes: 0 additions & 33 deletions src/main/java/spoon/reflect/cu/CompilationUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,4 @@
* public type declaration and other secondary types declarations (not public).
*/
public interface CompilationUnit extends CtCompilationUnit {
surli marked this conversation as resolved.
Show resolved Hide resolved


/**
* Helper method to get the begin index of the line that corresponds to the
* given index.
*
* @param index
* an arbitrary index in the source code
* @return the index where the line starts
*/
@Deprecated
int beginOfLineIndex(int index);

/**
* Helper method to get the begin index of the line that corresponds to the
* next line of the given index.
*
* @param index
* an arbitrary index in the source code
* @return the index where the next line starts
*/
@Deprecated
int nextLineIndex(int index);

/**
* Gets the number of tabulations for a given line.
*
* @param index
* the index where the line starts in the source code
* @return the number of tabs for this line
*/
@Deprecated
int getTabCount(int index);
}
34 changes: 0 additions & 34 deletions src/main/java/spoon/reflect/visitor/DefaultJavaPrettyPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -1990,25 +1989,6 @@ public void reset() {
context = new PrintingContext();
}


/**
* Write the compilation unit header.
*/
@Deprecated
public DefaultJavaPrettyPrinter writeHeader(List<CtType<?>> types, Collection<CtImport> imports) {
elementPrinterHelper.writeHeader(types, imports);
return this;
}

/**
* Write the compilation unit footer.
*/
@Deprecated
public DefaultJavaPrettyPrinter writeFooter(List<CtType<?>> types) {
elementPrinterHelper.writeFooter(types);
return this;
}

@Override
public void calculate(CtCompilationUnit sourceCompilationUnit, List<CtType<?>> types) {
if (types.isEmpty()) {
Expand Down Expand Up @@ -2046,20 +2026,6 @@ private boolean hasSameTypes(CtCompilationUnit compilationUnit, List<CtType<?>>
return cuQnames.equals(qnames);
}

@Deprecated
protected void printTypes(List<CtType<?>> types) {
for (CtType<?> t : types) {
scan(t);
if (!env.isPreserveLineNumbers()) {
// saving lines and chars
printer.writeln().writeln();
} else {
getPrinterHelper().adjustEndPosition(t);
}
}
this.writeFooter(types);
}

@Override
public Map<Integer, Integer> getLineNumberMapping() {
return getPrinterHelper().getLineNumberMapping();
Expand Down
31 changes: 0 additions & 31 deletions src/main/java/spoon/reflect/visitor/ElementPrinterHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,37 +346,6 @@ public void writeImports(Collection<CtImport> imports) {
}
}

/**
* Write the compilation unit header.
*/
@Deprecated
public void writeHeader(List<CtType<?>> types, Collection<CtImport> imports) {
if (!types.isEmpty()) {
for (CtType<?> ctType : types) {
writeComment(ctType, CommentOffset.TOP_FILE);
}
// writing the header package
if (!types.get(0).getPackage().isUnnamedPackage()) {
writePackageLine(types.get(0).getPackage().getQualifiedName());
}
this.writeImports(imports);
printer.writeln();
printer.writeln();
}
}

/**
* Write the compilation unit footer.
*/
@Deprecated
public void writeFooter(List<CtType<?>> types) {
if (!types.isEmpty()) {
for (CtType<?> ctType : types) {
writeComment(ctType, CommentOffset.BOTTOM_FILE);
}
}
}

public void writePackageLine(String packageQualifiedName) {
printer.writeKeyword("package").writeSpace();
writeQualifiedName(packageQualifiedName).writeSeparator(";").writeln();
Expand Down
44 changes: 0 additions & 44 deletions src/main/java/spoon/reflect/visitor/ImportScanner.java

This file was deleted.

Loading