Skip to content

Commit

Permalink
Fix deprecation warnings (#134)
Browse files Browse the repository at this point in the history
* Skip deprecated setters of DataObjects
* Skip deprecated DataObjects entirely
  • Loading branch information
oliver-brm authored Dec 26, 2023
1 parent a1a513d commit 97fb081
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 269 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
<version>4.5.2-SNAPSHOT</version>
<packaging>pom</packaging>
<inceptionYear>2016</inceptionYear>

<organization>
<name>vert.x</name>
<url>http://vertx.io</url>
</organization>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
Expand All @@ -29,11 +31,12 @@
<distribution>repo</distribution>
</license>
</licenses>

<properties>
<scala.version>3.3.1</scala.version>
<stack.version>${project.version}</stack.version>
<asciidoc.dir>${project.basedir}/src/main/asciidoc</asciidoc.dir>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
Expand Down Expand Up @@ -82,17 +85,14 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.8.1</version>
<configuration>
<args>
<arg>java-output-version 8</arg>
<arg>java-output-version 11</arg>
<arg>-feature</arg>
<arg>-deprecation</arg>
</args>
Expand Down
3 changes: 3 additions & 0 deletions vertx-lang-scala-codegen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.vertx</groupId>
<artifactId>vertx-lang-scala-parent</artifactId>
<version>4.5.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>vertx-lang-scala-codegen</artifactId>
<name>Codegen for Scala</name>

<dependencies>
<dependency>
<groupId>io.vertx</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package io.vertx.lang.scala.codegen;

import io.vertx.codegen.*;
import io.vertx.codegen.type.*;
import io.vertx.codegen.Generator;
import io.vertx.codegen.MethodInfo;
import io.vertx.codegen.Model;
import io.vertx.codegen.TypeParamInfo;
import io.vertx.codegen.doc.Doc;
import io.vertx.codegen.type.ClassTypeInfo;
import io.vertx.codegen.type.TypeInfo;
import io.vertx.lang.scala.codegen.gen.Imports;
import io.vertx.lang.scala.codegen.gen.Templates;

Expand All @@ -21,17 +25,15 @@ public class ClassCodeGenerator extends Generator<Model> {
public Map<String, Set<String>> fileToImports = new HashMap<>();

public static final List<String> ignoredPackages;

static {
List<String> temp = new ArrayList<>();
temp.add("io.vertx.redis");
temp.add("io.vertx.ext.consul.token");
ignoredPackages = Collections.unmodifiableList(temp);
}
public static final List<String> ignoreClassname;
static {
List<String> temp = new ArrayList<>();
ignoreClassname = Collections.unmodifiableList(temp);
}

public static final List<String> ignoreClassname = Collections.unmodifiableList(new ArrayList<>());

public ClassCodeGenerator() {
LogManager.getLogManager().reset();
Expand All @@ -45,7 +47,10 @@ public void load(ProcessingEnvironment processingEnv) {

@Override
public String filename(Model model) {
if(!((TypeInfo)model.getVars().get("type")).getName().equals("io.vertx.core.buffer.Buffer") && !(model.getFqn().contains(".impl.") || model.getFqn().endsWith(".impl"))) {
if (!((TypeInfo) model.getVars().get("type")).getName().equals("io.vertx.core.buffer.Buffer")
&& !(model.getFqn().contains(".impl.") || model.getFqn().endsWith(".impl"))
&& model.getAnnotations().stream().noneMatch(annotation -> annotation.getSimpleName().equals("Deprecated"))) {

String fileName = filenameForModel(model);
fileToImports.put(fileName, new HashSet<>());

Expand All @@ -67,7 +72,7 @@ String filenameForModel(Model model) {
public String render(Model model, int index, int size, Map<String, Object> session) {
Map<String, Object> modelVars = model.getVars();
ClassTypeInfo type = ((ClassTypeInfo) modelVars.get("type"));
if(!ignoredPackages.contains(type.getPackageName()) && !ignoreClassname.contains(type.getSimpleName())) {
if (!ignoredPackages.contains(type.getPackageName()) && !ignoreClassname.contains(type.getSimpleName())) {
try {
return Templates.renderPackageObject(
model,
Expand All @@ -81,9 +86,8 @@ public String render(Model model, int index, int size, Map<String, Object> sessi
(List<MethodInfo>) modelVars.get("instanceMethods"),
(List<MethodInfo>) modelVars.get("staticMethods"),
(Collection<TypeParamInfo>) modelVars.get("typeParams")
);
}
catch (IOException ioe) {
);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
Expand All @@ -96,14 +100,14 @@ public Set<String> adjustedImports(ClassTypeInfo type, Set<TypeInfo> importedTyp
//Change
//import io.vertx.scala.ext.web.common.template.TemplateEngine

if(type.getName().equals("io.vertx.ext.web.templ.TemplateEngine")) {
if (type.getName().equals("io.vertx.ext.web.templ.TemplateEngine")) {

imps.remove("io.vertx.scala.ext.web.common.template.TemplateEngine");
imps.add("io.vertx.scala.ext.web.common.template.{TemplateEngine => STemplateEngine}");
imps.remove("io.vertx.ext.web.common.template.{TemplateEngine => JTemplateEngine}");
}

if(type.getName().equals("io.vertx.core.Vertx")) {
if (type.getName().equals("io.vertx.core.Vertx")) {
imps.add("io.vertx.lang.scala.ScalaVerticle");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.vertx.codegen.Helper;
import io.vertx.codegen.MethodInfo;
import io.vertx.codegen.ParamInfo;
import io.vertx.codegen.type.ClassKind;
import io.vertx.codegen.type.ParameterizedTypeInfo;
import io.vertx.codegen.type.TypeInfo;
Expand Down Expand Up @@ -58,11 +57,10 @@ public static Set<String> generateImports(TypeInfo type, Collection<TypeInfo> im
importForType(Helper.getPackageName(type.getName()), imported, ret);
}
}
for (MethodInfo method : methods) {
for (ParamInfo param : method.getParams()) {
importForType(Helper.getPackageName(type.getName()), param.getType(), ret);
}
}
methods.stream()
.filter(methodInfo -> !methodInfo.isDeprecated())
.flatMap(methodInfo -> methodInfo.getParams().stream())
.forEach(paramInfo -> importForType(Helper.getPackageName(type.getName()), paramInfo.getType(), ret));
return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import io.vertx.codegen.*;
import io.vertx.codegen.doc.Doc;
import io.vertx.codegen.type.*;
import io.vertx.codegen.type.ClassKind;
import io.vertx.codegen.type.ClassTypeInfo;
import io.vertx.codegen.type.ParameterizedTypeInfo;
import io.vertx.codegen.type.TypeInfo;

import java.io.IOException;
import java.util.*;
Expand Down Expand Up @@ -460,7 +463,8 @@ private static String renderNullableMethod(ClassTypeInfo type, MethodInfo method
private static String renderDataobject(DataObjectModel model, String className, ClassTypeInfo type) {
String constructor = "";

if ((model.hasEmptyConstructor() || model.hasJsonConstructor()) && model.getPropertyMap().entrySet().stream().anyMatch(entry -> entry.getValue().isSetter())) {
if ((model.hasEmptyConstructor() || model.hasJsonConstructor())
&& model.getPropertyMap().values().stream().anyMatch(pi -> pi.isSetter() && !pi.isDeprecated())) {
if (model.hasJsonConstructor()) {
constructor =
applyDataObject(model, type) + " = {\n" +
Expand All @@ -482,7 +486,6 @@ private static String renderDataobject(DataObjectModel model, String className,
if (model.isConcrete()) {
return " type " + className + " = " + getNonGenericType(type.getName()) + "\n" +
" object " + Helper.getSimpleName(type.getName()) + " {\n" +
(model.hasEmptyConstructor() ? " def apply() = new " + Helper.getSimpleName(type.getName()) + "()\n" : "") +
(model.hasJsonConstructor() ? " def apply(json: JsonObject) = new " + Helper.getSimpleName(type.getName()) + "(json)\n" : "") +
(model.hasStringConstructor() ? " def apply(str: String) = new " + Helper.getSimpleName(type.getName()) + "(str)\n" : "") +
constructor + "\n" +
Expand All @@ -493,6 +496,7 @@ private static String renderDataobject(DataObjectModel model, String className,

private static String applyDataObject(DataObjectModel model, ClassTypeInfo type) {
return " def apply( " + model.getPropertyMap().entrySet().stream()
.filter(e -> !e.getValue().isDeprecated())
.map(entry -> {
String propertyName = entry.getKey();
PropertyInfo propertyType = entry.getValue();
Expand All @@ -514,11 +518,12 @@ private static String applyDataObject(DataObjectModel model, ClassTypeInfo type)
return null;
})
.filter(Objects::nonNull)
.collect(Collectors.joining(", ")) + "): " + Helper.getSimpleName(type.getName()) + "";
.collect(Collectors.joining(", ")) + "): " + Helper.getSimpleName(type.getName());
}

private static String dataObjectSetters(DataObjectModel model, ClassTypeInfo type) {
return model.getPropertyMap().entrySet().stream()
.filter(e -> !e.getValue().isDeprecated())
.map(entry -> {
String propertyName = entry.getKey();
PropertyInfo propertyType = entry.getValue();
Expand Down Expand Up @@ -588,7 +593,7 @@ private static String renderClass(ClassTypeInfo type, Doc doc, String className,
* Main entry point which renders the package-object.
* It takes care of the incremental rendering part.
*/
public static String renderPackageObject(Model model, ClassTypeInfo type, int incrementalIndex, int incrementalSize, Set<String> imps, Boolean concrete, Boolean hasEmptyConstructor, Doc doc, List<MethodInfo> instanceMethods, List<MethodInfo> staticMethods, Collection<TypeParamInfo> typeParams) throws IOException{
public static String renderPackageObject(Model model, ClassTypeInfo type, int incrementalIndex, int incrementalSize, Set<String> imps, Boolean concrete, Boolean hasEmptyConstructor, Doc doc, List<MethodInfo> instanceMethods, List<MethodInfo> staticMethods, Collection<TypeParamInfo> typeParams) throws IOException {
String nonGenericType = getNonGenericType(type.toString());
String translatedPackage = type.getModule().translatePackageName("scala");
String modulePackage = translatedPackage.substring(0, translatedPackage.lastIndexOf('.'));
Expand Down Expand Up @@ -622,7 +627,7 @@ public static String renderPackageObject(Model model, ClassTypeInfo type, int in
}

String body = "";
if (model instanceof DataObjectModel) {
if (model instanceof DataObjectModel && !((DataObjectModel) model).isDeprecated()) {
body = renderDataobject((DataObjectModel) model, type.getSimpleName(), type) + "\n";
} else if (type.getKind() != HANDLER && !futureMethods.isEmpty()) {
body = renderClass(type, doc, type.getSimpleName(), nullableMethods, futureMethods, basicMethods, nonGenericType, typeParams) + "\n";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package io.vertx.lang.scala

import io.vertx.core.{DeploymentOptions, Vertx}
import org.scalatest.flatspec.AnyFlatSpec
import io.vertx.core.{DeploymentOptions, ThreadingModel, Vertx}
import org.scalatest.concurrent.PatienceConfiguration.Timeout
import org.scalatest.concurrent.Waiters.{Waiter, *}
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.time.{Millis, Span}

import scala.concurrent.Future
import scala.util.{Failure, Success}

/**
Expand Down Expand Up @@ -47,7 +46,7 @@ class VertxTest extends AnyFlatSpec, Matchers:
waiter.dismiss()
}
}
}, new DeploymentOptions().setWorker(true))
}, new DeploymentOptions().setThreadingModel(ThreadingModel.WORKER))
waiter.await(dismissals(1))
}

Expand Down Expand Up @@ -82,7 +81,7 @@ class VertxTest extends AnyFlatSpec, Matchers:
waiter.dismiss()
}
}
}, new DeploymentOptions().setWorker(true))
}, new DeploymentOptions().setThreadingModel(ThreadingModel.WORKER))
future.onComplete {
case Success(_) => futureWaiter.dismiss()
case Failure(t) => t.printStackTrace()
Expand Down

This file was deleted.

Loading

0 comments on commit 97fb081

Please sign in to comment.