296 lines
12 KiB
Diff
296 lines
12 KiB
Diff
From f386ad4a22d650388b718aca4fea928f8d7ed04a Mon Sep 17 00:00:00 2001
|
|
From: Mat Booth <mat.booth@redhat.com>
|
|
Date: Thu, 14 Feb 2019 10:40:37 +0000
|
|
Subject: [PATCH] Port to latest version of javaparser
|
|
|
|
---
|
|
basic/pom.xml | 6 +-
|
|
.../inheritance/util/JavaTypeParser.java | 26 ++++-----
|
|
.../util/TypeToJTypeConvertingVisitor.java | 56 ++++++++++---------
|
|
.../inheritance/tests/JavaTypeParserTest.java | 34 +++++------
|
|
pom.xml | 6 +-
|
|
5 files changed, 64 insertions(+), 64 deletions(-)
|
|
|
|
diff --git a/basic/pom.xml b/basic/pom.xml
|
|
index ab5f477..37f9dda 100644
|
|
--- a/basic/pom.xml
|
|
+++ b/basic/pom.xml
|
|
@@ -31,8 +31,8 @@
|
|
<scope>provided</scope>
|
|
</dependency>
|
|
<dependency>
|
|
- <groupId>com.google.code.javaparser</groupId>
|
|
- <artifactId>javaparser</artifactId>
|
|
+ <groupId>com.github.javaparser</groupId>
|
|
+ <artifactId>javaparser-core</artifactId>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.jvnet.jaxb2.maven2</groupId>
|
|
@@ -97,4 +97,4 @@
|
|
</plugins>
|
|
</pluginManagement>
|
|
</build>
|
|
-</project>
|
|
\ No newline at end of file
|
|
+</project>
|
|
diff --git a/basic/src/main/java/org/jvnet/jaxb2_commons/plugin/inheritance/util/JavaTypeParser.java b/basic/src/main/java/org/jvnet/jaxb2_commons/plugin/inheritance/util/JavaTypeParser.java
|
|
index 2d5d07a..6e94f62 100644
|
|
--- a/basic/src/main/java/org/jvnet/jaxb2_commons/plugin/inheritance/util/JavaTypeParser.java
|
|
+++ b/basic/src/main/java/org/jvnet/jaxb2_commons/plugin/inheritance/util/JavaTypeParser.java
|
|
@@ -1,16 +1,16 @@
|
|
package org.jvnet.jaxb2_commons.plugin.inheritance.util;
|
|
|
|
-import japa.parser.JavaParser;
|
|
-import japa.parser.ParseException;
|
|
-import japa.parser.ast.CompilationUnit;
|
|
-import japa.parser.ast.body.ClassOrInterfaceDeclaration;
|
|
-import japa.parser.ast.body.TypeDeclaration;
|
|
-import japa.parser.ast.type.ClassOrInterfaceType;
|
|
+import com.github.javaparser.JavaParser;
|
|
+import com.github.javaparser.ParseProblemException;
|
|
+import com.github.javaparser.ast.CompilationUnit;
|
|
+import com.github.javaparser.ast.NodeList;
|
|
+import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
|
+import com.github.javaparser.ast.body.TypeDeclaration;
|
|
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.util.Collections;
|
|
-import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.apache.commons.lang3.Validate;
|
|
@@ -52,18 +52,16 @@ public class JavaTypeParser {
|
|
final String text = "public class Ignored extends " + type + " {}";
|
|
try {
|
|
CompilationUnit compilationUnit = JavaParser.parse(
|
|
- new ByteArrayInputStream(text.getBytes("UTF-8")), "UTF-8");
|
|
- final List<TypeDeclaration> typeDeclarations = compilationUnit
|
|
- .getTypes();
|
|
- final TypeDeclaration typeDeclaration = typeDeclarations.get(0);
|
|
+ new ByteArrayInputStream(text.getBytes("UTF-8")));
|
|
+ final TypeDeclaration typeDeclaration = compilationUnit.getType(0);
|
|
final ClassOrInterfaceDeclaration classDeclaration = (ClassOrInterfaceDeclaration) typeDeclaration;
|
|
- final List<ClassOrInterfaceType> _extended = classDeclaration
|
|
- .getExtends();
|
|
+ final NodeList<ClassOrInterfaceType> _extended = classDeclaration
|
|
+ .getExtendedTypes();
|
|
final ClassOrInterfaceType classOrInterfaceType = _extended.get(0);
|
|
|
|
return classOrInterfaceType.accept(
|
|
this.typeToJTypeConvertingVisitor, codeModel);
|
|
- } catch (ParseException pex) {
|
|
+ } catch (ParseProblemException pex) {
|
|
throw new IllegalArgumentException(
|
|
"Could not parse the type definition [" + type + "].", pex);
|
|
} catch (UnsupportedEncodingException uex) {
|
|
diff --git a/basic/src/main/java/org/jvnet/jaxb2_commons/plugin/inheritance/util/TypeToJTypeConvertingVisitor.java b/basic/src/main/java/org/jvnet/jaxb2_commons/plugin/inheritance/util/TypeToJTypeConvertingVisitor.java
|
|
index 5b8a4b7..9f7ae21 100644
|
|
--- a/basic/src/main/java/org/jvnet/jaxb2_commons/plugin/inheritance/util/TypeToJTypeConvertingVisitor.java
|
|
+++ b/basic/src/main/java/org/jvnet/jaxb2_commons/plugin/inheritance/util/TypeToJTypeConvertingVisitor.java
|
|
@@ -1,12 +1,15 @@
|
|
package org.jvnet.jaxb2_commons.plugin.inheritance.util;
|
|
|
|
-import japa.parser.ast.type.ClassOrInterfaceType;
|
|
-import japa.parser.ast.type.PrimitiveType;
|
|
-import japa.parser.ast.type.ReferenceType;
|
|
-import japa.parser.ast.type.Type;
|
|
-import japa.parser.ast.type.VoidType;
|
|
-import japa.parser.ast.type.WildcardType;
|
|
-import japa.parser.ast.visitor.GenericVisitorAdapter;
|
|
+import com.github.javaparser.ast.NodeList;
|
|
+import com.github.javaparser.ast.type.ArrayType;
|
|
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
|
|
+import com.github.javaparser.ast.type.PrimitiveType;
|
|
+import com.github.javaparser.ast.type.PrimitiveType.Primitive;
|
|
+import com.github.javaparser.ast.type.ReferenceType;
|
|
+import com.github.javaparser.ast.type.Type;
|
|
+import com.github.javaparser.ast.type.VoidType;
|
|
+import com.github.javaparser.ast.type.WildcardType;
|
|
+import com.github.javaparser.ast.visitor.GenericVisitorAdapter;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
@@ -36,21 +39,21 @@ public class TypeToJTypeConvertingVisitor extends
|
|
@Override
|
|
public JType visit(PrimitiveType type, JCodeModel codeModel) {
|
|
switch (type.getType()) {
|
|
- case Boolean:
|
|
+ case BOOLEAN:
|
|
return codeModel.BOOLEAN;
|
|
- case Char:
|
|
+ case CHAR:
|
|
return codeModel.CHAR;
|
|
- case Byte:
|
|
+ case BYTE:
|
|
return codeModel.BYTE;
|
|
- case Short:
|
|
+ case SHORT:
|
|
return codeModel.SHORT;
|
|
- case Int:
|
|
+ case INT:
|
|
return codeModel.INT;
|
|
- case Long:
|
|
+ case LONG:
|
|
return codeModel.LONG;
|
|
- case Float:
|
|
+ case FLOAT:
|
|
return codeModel.FLOAT;
|
|
- case Double:
|
|
+ case DOUBLE:
|
|
return codeModel.DOUBLE;
|
|
default:
|
|
throw new AssertionError("Unknown primitive type ["
|
|
@@ -59,11 +62,11 @@ public class TypeToJTypeConvertingVisitor extends
|
|
}
|
|
|
|
@Override
|
|
- public JType visit(ReferenceType type, JCodeModel codeModel) {
|
|
- final JType referencedType = type.getType().accept(this, codeModel);
|
|
+ public JType visit(ArrayType type, JCodeModel codeModel) {
|
|
+ final JType referencedType = type.getComponentType().accept(this, codeModel);
|
|
|
|
JType referencedTypeArray = referencedType;
|
|
- for (int index = 0; index < type.getArrayCount(); index++) {
|
|
+ for (int index = 0; index < type.getArrayLevel(); index++) {
|
|
referencedTypeArray = referencedTypeArray.array();
|
|
}
|
|
return referencedTypeArray;
|
|
@@ -72,8 +75,8 @@ public class TypeToJTypeConvertingVisitor extends
|
|
@Override
|
|
public JType visit(WildcardType type, JCodeModel codeModel) {
|
|
|
|
- if (type.getExtends() != null) {
|
|
- final ReferenceType _extends = type.getExtends();
|
|
+ if (type.getExtendedType().isPresent()) {
|
|
+ final ReferenceType _extends = type.getExtendedType().get();
|
|
final JType boundType = _extends.accept(this, codeModel);
|
|
|
|
if (!(boundType instanceof JClass)) {
|
|
@@ -83,7 +86,7 @@ public class TypeToJTypeConvertingVisitor extends
|
|
|
|
final JClass boundClass = (JClass) boundType;
|
|
return boundClass.wildcard();
|
|
- } else if (type.getSuper() != null) {
|
|
+ } else if (type.getSuperType().isPresent()) {
|
|
// TODO
|
|
throw new IllegalArgumentException(
|
|
"Wildcard types with super clause are not supported at the moment.");
|
|
@@ -99,10 +102,10 @@ public class TypeToJTypeConvertingVisitor extends
|
|
final JClass knownClass = this.knownClasses.get(name);
|
|
final JClass jclass = knownClass != null ? knownClass : codeModel
|
|
.ref(name);
|
|
- final List<Type> typeArgs = type.getTypeArgs();
|
|
- if (typeArgs == null || typeArgs.isEmpty()) {
|
|
+ if (!type.getTypeArguments().isPresent() || type.getTypeArguments().get().isEmpty()) {
|
|
return jclass;
|
|
} else {
|
|
+ final NodeList<Type> typeArgs = type.getTypeArguments().get();
|
|
final List<JClass> jtypeArgs = new ArrayList<JClass>(
|
|
typeArgs.size());
|
|
for (Type typeArg : typeArgs) {
|
|
@@ -119,12 +122,11 @@ public class TypeToJTypeConvertingVisitor extends
|
|
}
|
|
|
|
private String getName(ClassOrInterfaceType type) {
|
|
- final String name = type.getName();
|
|
- final ClassOrInterfaceType scope = type.getScope();
|
|
- if (scope == null) {
|
|
+ final String name = type.getName().asString();
|
|
+ if (!type.getScope().isPresent()) {
|
|
return name;
|
|
} else {
|
|
- return getName(scope) + "." + name;
|
|
+ return getName(type.getScope().get()) + "." + name;
|
|
}
|
|
}
|
|
}
|
|
diff --git a/basic/src/test/java/org/jvnet/jaxb2_commons/plugin/inheritance/tests/JavaTypeParserTest.java b/basic/src/test/java/org/jvnet/jaxb2_commons/plugin/inheritance/tests/JavaTypeParserTest.java
|
|
index 8566557..8903526 100644
|
|
--- a/basic/src/test/java/org/jvnet/jaxb2_commons/plugin/inheritance/tests/JavaTypeParserTest.java
|
|
+++ b/basic/src/test/java/org/jvnet/jaxb2_commons/plugin/inheritance/tests/JavaTypeParserTest.java
|
|
@@ -1,15 +1,15 @@
|
|
package org.jvnet.jaxb2_commons.plugin.inheritance.tests;
|
|
|
|
-import japa.parser.JavaParser;
|
|
-import japa.parser.ast.CompilationUnit;
|
|
-import japa.parser.ast.body.ClassOrInterfaceDeclaration;
|
|
-import japa.parser.ast.body.TypeDeclaration;
|
|
-import japa.parser.ast.type.ClassOrInterfaceType;
|
|
-import japa.parser.ast.type.ReferenceType;
|
|
-import japa.parser.ast.type.Type;
|
|
+import com.github.javaparser.JavaParser;
|
|
+import com.github.javaparser.ast.CompilationUnit;
|
|
+import com.github.javaparser.ast.NodeList;
|
|
+import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
|
+import com.github.javaparser.ast.body.TypeDeclaration;
|
|
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
|
|
+import com.github.javaparser.ast.type.ReferenceType;
|
|
+import com.github.javaparser.ast.type.Type;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
-import java.util.List;
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
@@ -20,29 +20,29 @@ public class JavaTypeParserTest extends TestCase {
|
|
final String text = "public class Dummy implements java.util.Comparator<java.lang.Integer>{}";
|
|
|
|
final CompilationUnit compilationUnit = JavaParser.parse(
|
|
- new ByteArrayInputStream(text.getBytes("UTF-8")), "UTF-8");
|
|
- final List<TypeDeclaration> typeDeclarations = compilationUnit
|
|
+ new ByteArrayInputStream(text.getBytes("UTF-8")));
|
|
+ final NodeList<TypeDeclaration<?>> typeDeclarations = compilationUnit
|
|
.getTypes();
|
|
assertEquals(1, typeDeclarations.size());
|
|
final TypeDeclaration typeDeclaration = typeDeclarations.get(0);
|
|
assertTrue(typeDeclaration instanceof ClassOrInterfaceDeclaration);
|
|
final ClassOrInterfaceDeclaration classDeclaration = (ClassOrInterfaceDeclaration) typeDeclaration;
|
|
- assertEquals("Dummy", classDeclaration.getName());
|
|
- final List<ClassOrInterfaceType> implementedInterfaces = classDeclaration
|
|
- .getImplements();
|
|
+ assertEquals("Dummy", classDeclaration.getName().asString());
|
|
+ final NodeList<ClassOrInterfaceType> implementedInterfaces = classDeclaration
|
|
+ .getImplementedTypes();
|
|
assertEquals(1, implementedInterfaces.size());
|
|
final ClassOrInterfaceType implementedInterface = implementedInterfaces
|
|
.get(0);
|
|
- assertEquals("Comparator", implementedInterface.getName());
|
|
- final List<Type> typeArgs = implementedInterface.getTypeArgs();
|
|
+ assertEquals("Comparator", implementedInterface.getName().asString());
|
|
+ final NodeList<Type> typeArgs = implementedInterface.getTypeArguments().get();
|
|
assertEquals(1, typeArgs.size());
|
|
final Type typeArg = typeArgs.get(0);
|
|
assertTrue(typeArg instanceof ReferenceType);
|
|
final ReferenceType referenceTypeArg = (ReferenceType) typeArg;
|
|
- final Type referencedType = referenceTypeArg.getType();
|
|
+ final Type referencedType = referenceTypeArg.getElementType();
|
|
assertTrue(referencedType instanceof ClassOrInterfaceType);
|
|
final ClassOrInterfaceType typeArgType = (ClassOrInterfaceType) referencedType;
|
|
- assertEquals("Integer", typeArgType.getName());
|
|
+ assertEquals("Integer", typeArgType.getName().asString());
|
|
|
|
}
|
|
}
|
|
diff --git a/pom.xml b/pom.xml
|
|
index a6c566e..4da4247 100644
|
|
--- a/pom.xml
|
|
+++ b/pom.xml
|
|
@@ -250,9 +250,9 @@
|
|
</dependency>
|
|
<!-- Java Parser -->
|
|
<dependency>
|
|
- <groupId>com.google.code.javaparser</groupId>
|
|
- <artifactId>javaparser</artifactId>
|
|
- <version>1.0.11</version>
|
|
+ <groupId>com.github.javaparser</groupId>
|
|
+ <artifactId>javaparser-core</artifactId>
|
|
+ <version>3.3.5</version>
|
|
</dependency>
|
|
</dependencies>
|
|
</dependencyManagement>
|
|
--
|
|
2.20.1
|
|
|