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

review: Remove deprecated from Spoon 5.9.0 #1518

Merged
merged 8 commits into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 0 additions & 16 deletions src/main/java/spoon/SpoonModelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,22 +285,6 @@ interface InputType {
*/
void forceBuild(SpoonResource source);

/**
* Sets the encoding to use when different from the system encoding.
* @deprecated encoding is directly used from Environment
*/
@Deprecated
void setEncoding(String encoding);

/**
* Gets the encoding used by this compiler. Null means that it uses the
* system encoding.
*
* @deprecated encoding is directly used from Environment
*/
@Deprecated
String getEncoding();

/**
* Returns the working factory
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
package spoon.reflect.visitor.filter;
package spoon.legacy;

import spoon.reflect.declaration.CtNamedElement;
import spoon.reflect.visitor.Filter;
import spoon.reflect.visitor.filter.NamedElementFilter;


/**
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/spoon/legacy/package.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--

Copyright (C) 2006-2017 INRIA and contributors
Spoon - http://spoon.gforge.inria.fr/

This software is governed by the CeCILL-C License under French law and
abiding by the rules of distribution of free software. You can use, modify
and/or redistribute the software under the terms of the CeCILL-C license as
circulated by CEA, CNRS and INRIA at http://www.cecill.info.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.

The fact that you are presently reading this means that you have had
knowledge of the CeCILL-C license and that you accept its terms.

-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
</head>
<body bgcolor="white">

<p>This package contains legacy code of Spoon. This code is kept for sake of maximum compatibility but no support is provided anymore.</p>

<h2>Related Documentation</h2>

<ul>
<li><a href="http://spoon.gforge.inria.fr/">Spoon Official Web Site</a>
</ul>

<!-- Put @see and @since tags down here. -->

</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -1820,12 +1820,6 @@ public <T> void visitCtUnboundVariableReference(CtUnboundVariableReference<T> re
printer.write(reference.getSimpleName());
}

@Override
@Deprecated
public String getPackageDeclaration() {
return printPackageInfo(context.currentTopLevel.getPackage());
}

@Override
public String printPackageInfo(CtPackage pack) {
reset();
Expand All @@ -1843,8 +1837,7 @@ public String getResult() {
return printer.toString();
}

@Override
public void reset() {
private void reset() {
printer.reset();
context = new PrintingContext();
if (env.isAutoImports()) {
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/spoon/reflect/visitor/PrettyPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
*/
public interface PrettyPrinter {

/**
* Gets the package declaration contents.
*/
@Deprecated
String getPackageDeclaration();

/**
* Prints the package info.
* It always resets the printing context at the beginning of this process.
Expand All @@ -45,14 +39,6 @@ public interface PrettyPrinter {
*/
String getResult();

/**
* It does not have to be called by clients now.
* The printing buffer is reset automatically at the beginning of #printPackageInfo or #calculate call
* So this method can be removed from the API, but should be kept in internal implementation and inherited PrettyPrinters
*/
@Deprecated
void reset();

/**
* Calculates the resulting source file for a list of types. The source
* compilation unit is required for calculating the line numbers mapping.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.CtExecutable;
import spoon.reflect.declaration.CtField;
import spoon.reflect.declaration.CtNamedElement;
import spoon.reflect.declaration.CtPackage;
import spoon.reflect.declaration.CtParameter;
import spoon.reflect.declaration.CtType;
Expand Down Expand Up @@ -93,7 +94,7 @@ public void apply(CtElement input, CtConsumer<Object> outputConsumer) {
.select(new TypeFilter<>(CtVariable.class));
if (variableName != null) {
//variable name is defined so we have to search only for variables with that name
siblingsQuery = siblingsQuery.select(new NameFilter<>(variableName));
siblingsQuery = siblingsQuery.select(new NamedElementFilter<>(CtNamedElement.class, variableName));
}

CtElement scopeElement = input;
Expand Down
11 changes: 1 addition & 10 deletions src/main/java/spoon/support/compiler/jdt/FileCompilerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import spoon.SpoonException;
import spoon.SpoonModelBuilder;
import spoon.compiler.SpoonFile;
import spoon.compiler.SpoonFolder;

import org.apache.commons.io.IOUtils;
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit;
Expand All @@ -50,14 +49,6 @@ public FileCompilerConfig(List<SpoonFile> files) {
this.files = files;
}

/*
* This method is not used now, so let's get rid of it.
*/
@Deprecated
public FileCompilerConfig(SpoonFolder folder) {
this(folder.getAllJavaFiles());
}

@Override
public void initializeCompiler(JDTBatchCompiler compiler) {
JDTBasedSpoonCompiler jdtCompiler = compiler.getJdtCompiler();
Expand All @@ -73,7 +64,7 @@ public void initializeCompiler(JDTBatchCompiler compiler) {

String fName = f.isActualFile() ? f.getPath() : f.getName();
inputStream = f.getContent();
char[] content = IOUtils.toCharArray(inputStream, jdtCompiler.getEncoding());
char[] content = IOUtils.toCharArray(inputStream, jdtCompiler.getEnvironment().getEncoding());
cuList.add(new CompilationUnit(content, fName, null));
IOUtils.closeQuietly(inputStream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,11 @@ public class JDTBasedSpoonCompiler implements spoon.SpoonModelBuilder {
protected List<SpoonResource> forceBuildList = new ArrayList<>();
protected List<CompilationUnitFilter> compilationUnitFilters = new ArrayList<>();

/**
* @deprecated The encoding of Environment should be used instead
*/
@Deprecated
protected String encoding;

/**
* Default constructor
*/
public JDTBasedSpoonCompiler(Factory factory) {
this.factory = factory;
this.encoding = factory.getEnvironment().getEncoding().displayName();
}

@Override
Expand Down Expand Up @@ -150,7 +143,7 @@ public boolean compile(InputType... types) {


final String[] args = new JDTBuilderImpl() //
.classpathOptions(new ClasspathOptions().encoding(this.getEncoding()).classpath(getSourceClasspath()).binaries(getBinaryOutputDirectory())) //
.classpathOptions(new ClasspathOptions().encoding(this.getEnvironment().getEncoding().displayName()).classpath(getSourceClasspath()).binaries(getBinaryOutputDirectory())) //
.complianceOptions(new ComplianceOptions().compliance(javaCompliance)) //
.annotationProcessingOptions(new AnnotationProcessingOptions().compileProcessors()) //
.advancedOptions(new AdvancedOptions().preserveUnusedVars().continueExecution().enableJavadoc()) //
Expand Down Expand Up @@ -334,16 +327,6 @@ public void forceBuild(SpoonResource source) {
forceBuildList.add(source);
}

@Override
public String getEncoding() {
return this.encoding;
}

@Override
public void setEncoding(String encoding) {
this.encoding = encoding;
}

@Override
public Factory getFactory() {
return factory;
Expand Down Expand Up @@ -395,7 +378,7 @@ protected CompilationUnitDeclaration[] buildUnits(JDTBuilder jdtBuilder, SpoonFo
String[] args;
if (jdtBuilder == null) {
args = new JDTBuilderImpl() //
.classpathOptions(new ClasspathOptions().encoding(this.getEncoding()).classpath(classpath)) //
.classpathOptions(new ClasspathOptions().encoding(this.getEnvironment().getEncoding().displayName()).classpath(classpath)) //
.complianceOptions(new ComplianceOptions().compliance(javaCompliance)) //
.advancedOptions(new AdvancedOptions().preserveUnusedVars().continueExecution().enableJavadoc()) //
.sources(new SourceOptions().sources(sourceFiles)) // no sources, handled by the JDTBatchCompiler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import spoon.reflect.factory.Factory;
import spoon.reflect.reference.CtFieldReference;
import spoon.reflect.reference.CtReference;
import spoon.reflect.visitor.filter.NameFilter;
import spoon.reflect.visitor.filter.NamedElementFilter;

import java.util.Collection;
import java.util.HashSet;
Expand Down Expand Up @@ -115,7 +115,7 @@ public void build() {
}
}
} else {
List<CtNamedElement> methodOrFields = klass.getElements(new NameFilter<>(methodOrFieldName));
List<CtNamedElement> methodOrFields = klass.getElements(new NamedElementFilter<>(CtNamedElement.class, methodOrFieldName));

if (methodOrFields.size() > 0) {
this.imports.add(methodOrFields.get(0).getReference());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import spoon.reflect.visitor.Query;
import spoon.reflect.visitor.chain.CtConsumer;
import spoon.reflect.visitor.filter.AllTypeMembersFunction;
import spoon.reflect.visitor.filter.NameFilter;
import spoon.reflect.visitor.filter.NamedElementFilter;
import spoon.reflect.visitor.filter.ReferenceTypeFilter;
import spoon.support.UnsettableProperty;
import spoon.support.comparator.CtLineElementComparator;
Expand Down Expand Up @@ -235,7 +235,7 @@ public CtFieldReference<?> getDeclaredField(String name) {

@Override
public CtFieldReference<?> getDeclaredOrInheritedField(String fieldName) {
CtField<?> field = map(new AllTypeMembersFunction(CtField.class)).select(new NameFilter<>(fieldName)).first();
CtField<?> field = map(new AllTypeMembersFunction(CtField.class)).select(new NamedElementFilter<>(CtField.class, fieldName)).first();
return field == null ? null : field.getReference();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import spoon.reflect.reference.CtExecutableReference;
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.visitor.CtVisitor;
import spoon.reflect.visitor.filter.NameFilter;
import spoon.reflect.visitor.filter.NamedElementFilter;
import spoon.support.reflect.declaration.CtElementImpl;
import spoon.support.util.RtHelper;
import spoon.support.visitor.ClassTypingContext;
Expand Down Expand Up @@ -173,7 +173,7 @@ private CtExecutable<T> getCtExecutable(CtType<?> typeDecl) {
Launcher.LOGGER.error(e.getMessage(), e);
}
} else if (method == null && getSimpleName().startsWith(CtExecutableReference.LAMBDA_NAME_PREFIX)) {
final List<CtLambda<T>> elements = (List<CtLambda<T>>) typeDecl.getElements(new NameFilter<CtLambda<T>>(getSimpleName()));
final List<CtLambda> elements = (List<CtLambda>) typeDecl.getElements(new NamedElementFilter<>(CtLambda.class, getSimpleName()));
if (elements.size() == 0) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/spoon/LauncherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void testInitEnvironmentDefault() throws Exception {
final SpoonModelBuilder builder = launcher.getModelBuilder();
assertEquals(new File("spooned"), builder.getSourceOutputDirectory());
assertEquals(0, builder.getInputSources().size());
assertEquals("UTF-8", builder.getEncoding());
assertEquals("UTF-8", environment.getEncoding().displayName());
}

@Test
Expand All @@ -67,7 +67,7 @@ public void testInitEnvironment() throws Exception {
// the input directories
List<File> inputSources = new ArrayList<>(builder.getInputSources());
assertTrue(inputSources.get(0).getPath().replace('\\', '/').contains("src/main/java"));
assertEquals("UTF-16", builder.getEncoding());
assertEquals("UTF-16", environment.getEncoding().displayName());

}

Expand Down
Loading