Skip to content

Commit

Permalink
Merge pull request #1440 from tazmaniax/fix-generics_and_deprecation_…
Browse files Browse the repository at this point in the history
…warnings

Fix warnings with generics
  • Loading branch information
xael-fry authored Jul 15, 2023
2 parents c0e166c + 501166a commit ccd502d
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 72 deletions.
22 changes: 11 additions & 11 deletions framework/src/play/classloading/ApplicationClassloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
public Class<?> loadApplicationClass(String name) {

if (ApplicationClass.isClass(name)) {
Class maybeAlreadyLoaded = findLoadedClass(name);
Class<?> maybeAlreadyLoaded = findLoadedClass(name);
if (maybeAlreadyLoaded != null) {
return maybeAlreadyLoaded;
}
Expand Down Expand Up @@ -401,9 +401,9 @@ private int computePathHash() {
*
* @return The list of well defined Class
*/
public List<Class> getAllClasses() {
public List<Class<?>> getAllClasses() {
if (allClasses == null) {
List<Class> result = new ArrayList<>();
List<Class<?>> result = new ArrayList<>();

if (Play.usePrecompiled) {

Expand All @@ -412,7 +412,7 @@ public List<Class> getAllClasses() {
Play.classes.clear();
for (ApplicationClass applicationClass : applicationClasses) {
Play.classes.add(applicationClass);
Class clazz = loadApplicationClass(applicationClass.name);
Class<?> clazz = loadApplicationClass(applicationClass.name);
applicationClass.javaClass = clazz;
applicationClass.compiled = true;
result.add(clazz);
Expand All @@ -439,7 +439,7 @@ public List<Class> getAllClasses() {
}

for (ApplicationClass applicationClass : Play.classes.all()) {
Class clazz = loadApplicationClass(applicationClass.name);
Class<?> clazz = loadApplicationClass(applicationClass.name);
if (clazz != null) {
result.add(clazz);
}
Expand All @@ -462,7 +462,7 @@ public List<Class> getAllClasses() {
return allClasses;
}

private List<Class> allClasses;
private List<Class<?>> allClasses;
private Map<String, ApplicationClass> allClassesByNormalizedName;

/**
Expand Down Expand Up @@ -497,7 +497,7 @@ public List<Class> getAssignableClasses(Class clazz) {
* The class name.
* @return a class
*/
public Class getClassIgnoreCase(String name) {
public Class<?> getClassIgnoreCase(String name) {
getAllClasses();
String nameLowerCased = name.toLowerCase();
ApplicationClass c = allClassesByNormalizedName.get(nameLowerCased);
Expand All @@ -517,17 +517,17 @@ public Class getClassIgnoreCase(String name) {
* The annotation class.
* @return A list of class
*/
public List<Class> getAnnotatedClasses(Class<? extends Annotation> clazz) {
public List<Class<?>> getAnnotatedClasses(Class<? extends Annotation> clazz) {
getAllClasses();
List<Class> results = new ArrayList<>();
List<Class<?>> results = new ArrayList<>();
for (ApplicationClass c : Play.classes.getAnnotatedClasses(clazz)) {
results.add(c.javaClass);
}
return results;
}

public List<Class> getAnnotatedClasses(Class[] clazz) {
List<Class> results = new ArrayList<>();
public List<Class<?>> getAnnotatedClasses(Class<? extends Annotation>[] clazz) {
List<Class<?>> results = new ArrayList<>();
for (Class<? extends Annotation> cl : clazz) {
results.addAll(getAnnotatedClasses(cl));
}
Expand Down
18 changes: 9 additions & 9 deletions framework/src/play/data/binding/Binder.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,11 @@ private static Object bindEnum(Class<?> clazz, ParamNode paramNode) {
}

private static Object bindMap(Type type, ParamNode paramNode, BindingAnnotations bindingAnnotations) {
Class keyClass = String.class;
Class valueClass = String.class;
Class<?> keyClass = String.class;
Class<?> valueClass = String.class;
if (type instanceof ParameterizedType) {
keyClass = (Class) ((ParameterizedType) type).getActualTypeArguments()[0];
valueClass = (Class) ((ParameterizedType) type).getActualTypeArguments()[1];
keyClass = (Class<?>) ((ParameterizedType) type).getActualTypeArguments()[0];
valueClass = (Class<?>) ((ParameterizedType) type).getActualTypeArguments()[1];
}

Map<Object, Object> r = new HashMap<>();
Expand Down Expand Up @@ -510,11 +510,11 @@ private static Object bindCollection(Class<?> clazz, Type type, ParamNode paramN
}
}

Collection l;
Collection<Object> l;
if (clazz.equals(EnumSet.class)) {
l = EnumSet.noneOf(componentClass);
} else {
l = (Collection) createNewInstance(clazz);
l = (Collection<Object>) createNewInstance(clazz);
}
boolean hasMissing = false;
for (String paramNodeValue : values) {
Expand All @@ -537,11 +537,11 @@ private static Object bindCollection(Class<?> clazz, Type type, ParamNode paramN
return l;
}

Collection r = (Collection) createNewInstance(clazz);
Collection<Object> r = (Collection<Object>) createNewInstance(clazz);

if (List.class.isAssignableFrom(clazz)) {
// Must add items at position resolved from each child's key
List l = (List) r;
List<Object> l = (List<Object>) r;

// must get all indexes and sort them so we add items in correct order.
Set<String> indexes = new TreeSet<>((arg0, arg1) -> {
Expand Down Expand Up @@ -690,7 +690,7 @@ private static Object internalDirectBind(String name, Annotation[] annotations,
// application custom types have higher priority. If unable to bind proceed with the next one
for (Class<TypeBinder<?>> c : Play.classloader.getAssignableClasses(TypeBinder.class)) {
if (c.isAnnotationPresent(Global.class)) {
Class<?> forType = (Class) ((ParameterizedType) c.getGenericInterfaces()[0]).getActualTypeArguments()[0];
Class<?> forType = (Class<?>) ((ParameterizedType) c.getGenericInterfaces()[0]).getActualTypeArguments()[0];
if (forType.isAssignableFrom(clazz)) {
Object result = createNewInstance(c).bind(name, annotations, value, clazz, type);
if (result != null) {
Expand Down
8 changes: 4 additions & 4 deletions framework/src/play/db/jpa/JPAPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ public void onApplicationStart() {
JPQL.instance = new JPQL();
}

private List<Class> entityClasses(String dbName) {
List<Class> entityClasses = new ArrayList<>();
private List<Class<?>> entityClasses(String dbName) {
List<Class<?>> entityClasses = new ArrayList<>();

List<Class> classes = Play.classloader.getAnnotatedClasses(Entity.class);
List<Class<?>> classes = Play.classloader.getAnnotatedClasses(Entity.class);
for (Class<?> clazz : classes) {
if (clazz.isAnnotationPresent(Entity.class)) {
// Do we have a transactional annotation matching our dbname?
Expand Down Expand Up @@ -196,7 +196,7 @@ protected EntityManagerFactory newEntityManagerFactory(String dbName, Configurat
}

protected PersistenceUnitInfoImpl persistenceUnitInfo(String dbName, Configuration dbConfig) {
final List<Class> managedClasses = entityClasses(dbName);
final List<Class<?>> managedClasses = entityClasses(dbName);
final Properties properties = properties(dbName, dbConfig);
properties.put(org.hibernate.cfg.AvailableSettings.LOADED_CLASSES,managedClasses);
return new PersistenceUnitInfoImpl(dbName,
Expand Down
4 changes: 2 additions & 2 deletions framework/src/play/db/jpa/PersistenceUnitInfoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class PersistenceUnitInfoImpl implements PersistenceUnitInfo {

private PersistenceUnitTransactionType transactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL;

private final List<Class> managedClasses;
private final List<Class<?>> managedClasses;
private final List<String> mappingFileNames;

private final Properties properties;
Expand All @@ -34,7 +34,7 @@ public class PersistenceUnitInfoImpl implements PersistenceUnitInfo {

private DataSource nonJtaDataSource;

public PersistenceUnitInfoImpl(String persistenceUnitName, List<Class> managedClasses, List<String> mappingFileNames, Properties properties) {
public PersistenceUnitInfoImpl(String persistenceUnitName, List<Class<?>> managedClasses, List<String> mappingFileNames, Properties properties) {
this.persistenceUnitName = persistenceUnitName;
this.managedClasses = managedClasses;
this.mappingFileNames = mappingFileNames;
Expand Down
16 changes: 8 additions & 8 deletions framework/src/play/jobs/JobsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class JobsPlugin extends PlayPlugin {

public static ScheduledThreadPoolExecutor executor;
public static final List<Job> scheduledJobs = new ArrayList<>();
public static final List<Job<?>> scheduledJobs = new ArrayList<>();
private static final ThreadLocal<List<Callable<?>>> afterInvocationActions = new ThreadLocal<>();

@Override
Expand All @@ -49,7 +49,7 @@ public String getStatus() {
out.println();
out.println("Scheduled jobs (" + scheduledJobs.size() + "):");
out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~");
for (Job job : scheduledJobs) {
for (Job<?> job : scheduledJobs) {
out.print(job);
if (job.getClass().isAnnotationPresent(OnApplicationStart.class)
&& !(job.getClass().isAnnotationPresent(On.class) || job.getClass().isAnnotationPresent(Every.class))) {
Expand Down Expand Up @@ -85,9 +85,9 @@ public String getStatus() {
out.println();
out.println("Waiting jobs:");
out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~");
ScheduledFuture[] q = executor.getQueue().toArray(new ScheduledFuture[executor.getQueue().size()]);
ScheduledFuture<?>[] q = executor.getQueue().toArray(new ScheduledFuture[executor.getQueue().size()]);

for (ScheduledFuture task : q) {
for (ScheduledFuture<?> task : q) {
out.println(Java.extractUnderlyingCallable((FutureTask<?>) task) + " will run in " + task.getDelay(TimeUnit.SECONDS)
+ " seconds");
}
Expand All @@ -98,7 +98,7 @@ public String getStatus() {
@Override
public void afterApplicationStart() {
List<Class<?>> jobs = new ArrayList<>();
for (Class clazz : Play.classloader.getAllClasses()) {
for (Class<?> clazz : Play.classloader.getAllClasses()) {
if (Job.class.isAssignableFrom(clazz)) {
jobs.add(clazz);
}
Expand Down Expand Up @@ -133,7 +133,7 @@ public void afterApplicationStart() {
Job<?> job = createJob(clazz);
// start running job now in the background
@SuppressWarnings("unchecked")
Callable<Job> callable = (Callable<Job>) job;
Callable<Job<?>> callable = (Callable<Job<?>>) job;
executor.submit(callable);
} catch (InstantiationException | IllegalAccessException ex) {
throw new UnexpectedException("Cannot instantiate Job " + clazz.getName(), ex);
Expand All @@ -153,7 +153,7 @@ public void afterApplicationStart() {
// @Every
if (clazz.isAnnotationPresent(Every.class)) {
try {
Job job = createJob(clazz);
Job<?> job = createJob(clazz);
String value = clazz.getAnnotation(Every.class).value();
if (value.startsWith("cron.")) {
value = Play.configuration.getProperty(value);
Expand Down Expand Up @@ -228,7 +228,7 @@ public void onApplicationStop() {

List<Class> jobs = Play.classloader.getAssignableClasses(Job.class);

for (Class clazz : jobs) {
for (Class<?> clazz : jobs) {
// @OnApplicationStop
if (clazz.isAnnotationPresent(OnApplicationStop.class)) {
try {
Expand Down
10 changes: 5 additions & 5 deletions framework/src/play/libs/F.java
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,9 @@ public synchronized Promise<List<IndexedEvent<T>>> nextEvents(long lastEventSeen
return filter;
}

public synchronized List<IndexedEvent> availableEvents(long lastEventSeen) {
List<IndexedEvent> result = new ArrayList<>();
for (IndexedEvent event : events) {
public synchronized List<IndexedEvent<?>> availableEvents(long lastEventSeen) {
List<IndexedEvent<?>> result = new ArrayList<>();
for (IndexedEvent<?> event : events) {
if (event.id > lastEventSeen) {
result.add(event);
}
Expand All @@ -695,7 +695,7 @@ public synchronized void publish(T event) {
Logger.warn("Dropping message. If this is catastrophic to your app, use a BlockingEvenStream instead");
events.poll();
}
events.offer(new IndexedEvent(event));
events.offer(new IndexedEvent<T>(event));
notifyNewEvent();
for (EventStream<T> eventStream : pipedStreams) {
eventStream.publish(event);
Expand Down Expand Up @@ -765,7 +765,7 @@ public static <T> Some<T> Some(T value) {
}

public static <A> Some<A> Some(A a) {
return new Some(a);
return new Some<A>(a);
}

public static class None<T> extends Option<T> {
Expand Down
4 changes: 2 additions & 2 deletions framework/src/play/plugins/PluginCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public void reloadApplicationPlugins() throws Exception {
// Is this plugin an application-supplied-plugin?
if (isLoadedByApplicationClassloader(plugin)) {
// This plugin is application-supplied - Must reload it
Class pluginClazz = Play.classloader.loadClass(plugin.getClass().getName());
Class<?> pluginClazz = Play.classloader.loadClass(plugin.getClass().getName());
PlayPlugin newPlugin = (PlayPlugin) Injector.getBeanOfType(pluginClazz);
newPlugin.index = plugin.index;
// Replace this plugin
Expand Down Expand Up @@ -458,7 +458,7 @@ public <T> F.Option<PlayPlugin.Filter<T>> composeFilters() {
Iterator<PlayPlugin> itr = pluginsWithFilters.iterator();
PlayPlugin.Filter<T> ret = itr.next().getFilter();
while (itr.hasNext()) {
ret = ret.<T> decorate(itr.next().getFilter());
ret = ret.decorate(itr.next().getFilter());
}
return F.Option.Some(ret);
}
Expand Down
4 changes: 2 additions & 2 deletions framework/src/play/server/HttpServerPipelineFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class HttpServerPipelineFactory implements ChannelPipelineFactory {

protected static final Map<String, Class> classes = new HashMap<>();
protected static final Map<String, Class<?>> classes = new HashMap<>();

private final String pipelineConfig = Play.configuration.getProperty("play.netty.pipeline", "play.server.FlashPolicyHandler,org.jboss.netty.handler.codec.http.HttpRequestDecoder,play.server.StreamChunkAggregator,org.jboss.netty.handler.codec.http.HttpResponseEncoder,org.jboss.netty.handler.stream.ChunkedWriteHandler,play.server.PlayHandler");

Expand Down Expand Up @@ -68,7 +68,7 @@ protected String getName(String name) {

protected ChannelHandler getInstance(String name) throws Exception {

Class clazz = classes.computeIfAbsent(name, className -> {
Class<?> clazz = classes.computeIfAbsent(name, className -> {
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/templates/BaseTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class BaseTemplate extends Template {
public String compiledSource;
public Map<Integer, Integer> linesMatrix = new HashMap<>();
public Set<Integer> doBodyLines = new HashSet<>();
public Class compiledTemplate;
public Class<?> compiledTemplate;
public String compiledTemplateName;

public BaseTemplate(String name, String source) {
Expand Down
10 changes: 5 additions & 5 deletions framework/src/play/templates/GroovyTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public TClassLoader() {
super(Play.classloader);
}

public Class defineTemplate(String name, byte[] byteCode) {
public Class<?> defineTemplate(String name, byte[] byteCode) {
return defineClass(name, byteCode, 0, byteCode.length, Play.classloader.protectionDomain);
}
}
Expand All @@ -113,7 +113,7 @@ void directLoad(byte[] code) throws Exception {
for (int i = 4; i < lines.length; i = i + 2) {
String className = lines[i];
byte[] byteCode = Codec.decodeBASE64(lines[i + 1]);
Class c = tClassLoader.defineTemplate(className, byteCode);
Class<?> c = tClassLoader.defineTemplate(className, byteCode);
if (compiledTemplate == null) {
compiledTemplate = c;
}
Expand Down Expand Up @@ -153,7 +153,7 @@ public void compile() {
// default output operation with the Play Groovy class handler.
Field phasesF = compilationUnit.getClass().getDeclaredField("phaseOperations");
phasesF.setAccessible(true);
Collection[] phases = (Collection[]) phasesF.get(compilationUnit);
Collection<?>[] phases = (Collection[]) phasesF.get(compilationUnit);
LinkedList<IGroovyClassOperation> output = new LinkedList<>();
phases[Phases.OUTPUT] = output;
output.add(groovyClassesForThisTemplate::add);
Expand Down Expand Up @@ -409,7 +409,7 @@ public Object getProperty(String property) {
}
}

public void invokeTag(Integer fromLine, String tag, Map<String, Object> attrs, Closure body) {
public void invokeTag(Integer fromLine, String tag, Map<String, Object> attrs, Closure<?> body) {
String templateName = tag.replace('.', '/');
String callerExtension = (extension != null) ? extension : "tag";

Expand Down Expand Up @@ -466,7 +466,7 @@ public void invokeTag(Integer fromLine, String tag, Map<String, Object> attrs, C
* @throws Exception
* if problem occured when loading the class
*/
public Class __loadClass(String className) throws Exception {
public Class<?> __loadClass(String className) throws Exception {
try {
return Play.classloader.loadClass(className);
} catch (ClassNotFoundException e) {
Expand Down
3 changes: 1 addition & 2 deletions framework/src/play/templates/GroovyTemplateCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -68,7 +67,7 @@ protected String checkScalaCompatibility(String source) {
// Static access
List<String> names = new ArrayList<>();
Map<String, String> originalNames = new HashMap<>();
for (Class clazz : Play.classloader.getAllClasses()) {
for (Class<?> clazz : Play.classloader.getAllClasses()) {
if (clazz.getName().endsWith("$")) {
String name = clazz.getName().substring(0, clazz.getName().length() - 1).replace('$', '.') + '$';
names.add(name);
Expand Down
Loading

0 comments on commit ccd502d

Please sign in to comment.