New upstream version 3.6.22
Emmanuel Bourg
2 years ago
0 | Version 3.6.22 | |
1 | ------------------ | |
2 | [issues resolved](https://github.com/javaparser/javaparser/milestone/106?closed=1) | |
3 | ||
0 | 4 | Version 3.6.21 |
1 | 5 | ------------------ |
6 | [issues resolved](https://github.com/javaparser/javaparser/milestone/105?closed=1) | |
7 | ||
8 | Version 3.6.20 | |
9 | ------------------ | |
2 | 10 | [issues resolved](https://github.com/javaparser/javaparser/milestone/104?closed=1) |
3 | 11 | |
4 | Version 3.6.20 | |
12 | Version 3.6.19 | |
5 | 13 | ------------------ |
6 | 14 | [issues resolved](https://github.com/javaparser/javaparser/milestone/103?closed=1) |
7 | ||
8 | Version 3.6.19 | |
9 | ------------------ | |
10 | [issues resolved](https://github.com/javaparser/javaparser/milestone/102?closed=1) | |
11 | 15 | |
12 | 16 | Version 3.6.18 |
13 | 17 | ------------------ |
1 | 1 | <parent> |
2 | 2 | <artifactId>javaparser-parent</artifactId> |
3 | 3 | <groupId>com.github.javaparser</groupId> |
4 | <version>3.6.21</version> | |
4 | <version>3.6.22</version> | |
5 | 5 | </parent> |
6 | 6 | <modelVersion>4.0.0</modelVersion> |
7 | 7 |
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Outputs a JSON file containing the AST meant for inspecting it. |
18 | * | |
19 | * @deprecated this class was mostly used for serialization purposes. | |
20 | * Use JavaParserJsonSerializer in the javaparser-core-serialization module for that. | |
18 | 21 | */ |
22 | @Deprecated | |
19 | 23 | public class JsonPrinter { |
20 | 24 | private final boolean outputNodeType; |
21 | 25 |
2 | 2 | <parent> |
3 | 3 | <artifactId>javaparser-parent</artifactId> |
4 | 4 | <groupId>com.github.javaparser</groupId> |
5 | <version>3.6.21</version> | |
5 | <version>3.6.22</version> | |
6 | 6 | </parent> |
7 | 7 | <modelVersion>4.0.0</modelVersion> |
8 | 8 |
2 | 2 | <parent> |
3 | 3 | <artifactId>javaparser-parent</artifactId> |
4 | 4 | <groupId>com.github.javaparser</groupId> |
5 | <version>3.6.21</version> | |
5 | <version>3.6.22</version> | |
6 | 6 | </parent> |
7 | 7 | <modelVersion>4.0.0</modelVersion> |
8 | 8 |
1 | 1 | <parent> |
2 | 2 | <artifactId>javaparser-parent</artifactId> |
3 | 3 | <groupId>com.github.javaparser</groupId> |
4 | <version>3.6.21</version> | |
4 | <version>3.6.22</version> | |
5 | 5 | </parent> |
6 | 6 | <modelVersion>4.0.0</modelVersion> |
7 | 7 |
1 | 1 | <parent> |
2 | 2 | <artifactId>javaparser-parent</artifactId> |
3 | 3 | <groupId>com.github.javaparser</groupId> |
4 | <version>3.6.21</version> | |
4 | <version>3.6.22</version> | |
5 | 5 | </parent> |
6 | 6 | <modelVersion>4.0.0</modelVersion> |
7 | 7 |
2 | 2 | <parent> |
3 | 3 | <artifactId>javaparser-parent</artifactId> |
4 | 4 | <groupId>com.github.javaparser</groupId> |
5 | <version>3.6.21</version> | |
5 | <version>3.6.22</version> | |
6 | 6 | </parent> |
7 | 7 | <modelVersion>4.0.0</modelVersion> |
8 | 8 |
+8
-4
88 | 88 | visible = ((HasAccessSpecifier) resolvedReferenceTypeDeclaration).accessSpecifier() != AccessSpecifier.PRIVATE; |
89 | 89 | } |
90 | 90 | } |
91 | if (internalTypeDeclaration.getName().equals(name) && visible) { | |
92 | return internalTypeDeclaration; | |
91 | if (internalTypeDeclaration.getName().equals(name)) { | |
92 | if (visible) { | |
93 | return internalTypeDeclaration; | |
94 | } else { | |
95 | return null; | |
96 | } | |
93 | 97 | } |
94 | 98 | } |
95 | 99 | // check recursively the ancestors of this ancestor |
112 | 116 | // We want to avoid infinite recursion in case of Object having Object as ancestor |
113 | 117 | if (!Object.class.getCanonicalName().equals(typeDeclaration.getQualifiedName())) { |
114 | 118 | for (ResolvedReferenceType ancestor : typeDeclaration.getAncestors(true)) { |
115 | // Avoid recursion on self | |
119 | // Avoid recursion on self | |
116 | 120 | if (typeDeclaration != ancestor.getTypeDeclaration()) { |
117 | 121 | candidateMethods.addAll(ancestor.getAllMethodsVisibleToInheritors() |
118 | 122 | .stream() |
126 | 130 | if (res.isSolved()) { |
127 | 131 | candidateMethods.add(res.getCorrespondingDeclaration()); |
128 | 132 | } |
129 | } | |
133 | } | |
130 | 134 | } |
131 | 135 | } |
132 | 136 | // We want to avoid infinite recursion when a class is using its own method |
+3
-3
1 | 1 | |
2 | 2 | import com.github.javaparser.ast.body.AnnotationDeclaration; |
3 | 3 | import com.github.javaparser.ast.body.AnnotationMemberDeclaration; |
4 | import com.github.javaparser.ast.expr.AnnotationExpr; | |
4 | 5 | import com.github.javaparser.resolution.declarations.*; |
5 | 6 | import com.github.javaparser.resolution.types.ResolvedReferenceType; |
6 | 7 | import com.github.javaparser.resolution.types.ResolvedType; |
55 | 56 | } |
56 | 57 | |
57 | 58 | @Override |
58 | public boolean hasDirectlyAnnotation(String qualifiedName) { | |
59 | // TODO #1839 | |
60 | throw new UnsupportedOperationException(); | |
59 | public boolean hasDirectlyAnnotation(String canonicalName) { | |
60 | return AstResolutionUtils.hasDirectlyAnnotation(wrappedNode, typeSolver, canonicalName); | |
61 | 61 | } |
62 | 62 | |
63 | 63 | @Override |
+9
-8
21 | 21 | import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; |
22 | 22 | import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; |
23 | 23 | import javassist.CtClass; |
24 | import javassist.bytecode.AnnotationsAttribute; | |
25 | import javassist.bytecode.annotation.Annotation; | |
24 | 26 | |
25 | 27 | import java.util.Collections; |
26 | 28 | import java.util.List; |
41 | 43 | @Override |
42 | 44 | public String toString() { |
43 | 45 | return getClass().getSimpleName() + "{" + |
44 | "ctClass=" + ctClass.getName() + | |
45 | ", typeSolver=" + typeSolver + | |
46 | '}'; | |
46 | "ctClass=" + ctClass.getName() + | |
47 | ", typeSolver=" + typeSolver + | |
48 | '}'; | |
47 | 49 | } |
48 | 50 | |
49 | 51 | public JavassistAnnotationDeclaration(CtClass ctClass, TypeSolver typeSolver) { |
63 | 65 | @Override |
64 | 66 | public String getClassName() { |
65 | 67 | String qualifiedName = getQualifiedName(); |
66 | if(qualifiedName.contains(".")) { | |
68 | if (qualifiedName.contains(".")) { | |
67 | 69 | return qualifiedName.substring(qualifiedName.lastIndexOf(".") + 1, qualifiedName.length()); |
68 | 70 | } else { |
69 | 71 | return qualifiedName; |
105 | 107 | |
106 | 108 | @Override |
107 | 109 | public boolean hasDirectlyAnnotation(String canonicalName) { |
108 | // TODO #1839 | |
109 | throw new UnsupportedOperationException(); | |
110 | return ctClass.hasAnnotation(canonicalName); | |
110 | 111 | } |
111 | 112 | |
112 | 113 | @Override |
134 | 135 | @Override |
135 | 136 | public List<ResolvedAnnotationMemberDeclaration> getAnnotationMembers() { |
136 | 137 | return Stream.of(ctClass.getDeclaredMethods()) |
137 | .map(m -> new JavassistAnnotationMemberDeclaration(m, typeSolver)) | |
138 | .collect(Collectors.toList()); | |
138 | .map(m -> new JavassistAnnotationMemberDeclaration(m, typeSolver)) | |
139 | .collect(Collectors.toList()); | |
139 | 140 | } |
140 | 141 | } |
+4
-3
15 | 15 | |
16 | 16 | package com.github.javaparser.symbolsolver.reflectionmodel; |
17 | 17 | |
18 | import com.github.javaparser.ast.expr.AnnotationExpr; | |
18 | 19 | import com.github.javaparser.resolution.declarations.*; |
19 | 20 | import com.github.javaparser.resolution.types.ResolvedReferenceType; |
20 | 21 | import com.github.javaparser.resolution.types.ResolvedType; |
21 | 22 | import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration; |
22 | 23 | import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; |
23 | 24 | |
25 | import java.lang.annotation.Annotation; | |
24 | 26 | import java.util.Collections; |
25 | 27 | import java.util.List; |
26 | 28 | import java.util.Optional; |
116 | 118 | } |
117 | 119 | |
118 | 120 | @Override |
119 | public boolean hasDirectlyAnnotation(String qualifiedName) { | |
120 | // TODO #1839 | |
121 | throw new UnsupportedOperationException(); | |
121 | public boolean hasDirectlyAnnotation(String canonicalName) { | |
122 | return reflectionClassAdapter.hasDirectlyAnnotation(canonicalName); | |
122 | 123 | } |
123 | 124 | |
124 | 125 | @Override |
2 | 2 | <parent> |
3 | 3 | <artifactId>javaparser-parent</artifactId> |
4 | 4 | <groupId>com.github.javaparser</groupId> |
5 | <version>3.6.21</version> | |
5 | <version>3.6.22</version> | |
6 | 6 | </parent> |
7 | 7 | <modelVersion>4.0.0</modelVersion> |
8 | 8 |
2 | 2 | <parent> |
3 | 3 | <artifactId>javaparser-parent</artifactId> |
4 | 4 | <groupId>com.github.javaparser</groupId> |
5 | <version>3.6.21</version> | |
5 | <version>3.6.22</version> | |
6 | 6 | </parent> |
7 | 7 | <modelVersion>4.0.0</modelVersion> |
8 | 8 |
2 | 2 | <parent> |
3 | 3 | <artifactId>javaparser-parent</artifactId> |
4 | 4 | <groupId>com.github.javaparser</groupId> |
5 | <version>3.6.21</version> | |
5 | <version>3.6.22</version> | |
6 | 6 | </parent> |
7 | 7 | <modelVersion>4.0.0</modelVersion> |
8 | 8 |
+59
-0
3 | 3 | import com.github.javaparser.ast.CompilationUnit; |
4 | 4 | import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; |
5 | 5 | import com.github.javaparser.ast.body.MethodDeclaration; |
6 | import com.github.javaparser.ast.expr.AnnotationExpr; | |
6 | 7 | import com.github.javaparser.ast.expr.MarkerAnnotationExpr; |
7 | 8 | import com.github.javaparser.ast.expr.NormalAnnotationExpr; |
8 | 9 | import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; |
9 | 10 | import com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration; |
10 | 11 | import com.github.javaparser.symbolsolver.JavaSymbolSolver; |
11 | 12 | import com.github.javaparser.symbolsolver.javaparser.Navigator; |
13 | import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnnotationDeclaration; | |
14 | import com.github.javaparser.symbolsolver.javassistmodel.JavassistAnnotationDeclaration; | |
15 | import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionAnnotationDeclaration; | |
12 | 16 | import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; |
13 | 17 | import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; |
14 | 18 | import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; |
19 | 23 | import java.io.IOException; |
20 | 24 | |
21 | 25 | import static org.junit.Assert.assertEquals; |
26 | import static org.junit.Assert.assertFalse; | |
27 | import static org.junit.Assert.assertTrue; | |
22 | 28 | |
23 | 29 | /** |
24 | 30 | * Tests resolution of annotation expressions. |
177 | 183 | assertEquals("org.junit", resolved.getPackageName()); |
178 | 184 | assertEquals("Test", resolved.getName()); |
179 | 185 | } |
186 | ||
187 | @Test | |
188 | public void solveJavaParserMetaAnnotations() { | |
189 | // parse compilation unit and get annotation expression | |
190 | CompilationUnit cu = parseSample("Annotations"); | |
191 | ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "CA"); | |
192 | AnnotationExpr annotationExpr = clazz.getAnnotation(0); | |
193 | ||
194 | // resolve annotation expression @MyAnnotation | |
195 | JavaParserAnnotationDeclaration resolved = (JavaParserAnnotationDeclaration) annotationExpr.resolve(); | |
196 | ||
197 | // check that the annotation @MyAnnotation has the annotations @Target and @Retention, but not @Documented | |
198 | assertEquals("foo.bar.MyAnnotation", resolved.getQualifiedName()); | |
199 | assertTrue(resolved.hasDirectlyAnnotation("java.lang.annotation.Target")); | |
200 | assertTrue(resolved.hasDirectlyAnnotation("java.lang.annotation.Retention")); | |
201 | assertFalse(resolved.hasDirectlyAnnotation("java.lang.annotation.Documented")); | |
202 | } | |
203 | ||
204 | @Test | |
205 | public void solveReflectionMetaAnnotations() { | |
206 | // parse compilation unit and get annotation expression | |
207 | CompilationUnit cu = parseSample("Annotations"); | |
208 | ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "CA"); | |
209 | MethodDeclaration method = Navigator.demandMethod(clazz, "equals"); | |
210 | MarkerAnnotationExpr annotationExpr = (MarkerAnnotationExpr) method.getAnnotation(0); | |
211 | ||
212 | // resolve annotation expression @Override | |
213 | ReflectionAnnotationDeclaration resolved = (ReflectionAnnotationDeclaration) annotationExpr.resolve(); | |
214 | ||
215 | // check that the annotation @Override has the annotations @Target and @Retention, but not @Documented | |
216 | assertEquals("java.lang.Override", resolved.getQualifiedName()); | |
217 | assertTrue(resolved.hasDirectlyAnnotation("java.lang.annotation.Target")); | |
218 | assertTrue(resolved.hasDirectlyAnnotation("java.lang.annotation.Retention")); | |
219 | assertFalse(resolved.hasDirectlyAnnotation("java.lang.annotation.Documented")); | |
220 | } | |
221 | ||
222 | @Test | |
223 | public void solveJavassistMetaAnnotation() throws IOException { | |
224 | // parse compilation unit and get annotation expression | |
225 | CompilationUnit cu = parseSample("Annotations"); | |
226 | ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "CD"); | |
227 | MethodDeclaration method = Navigator.demandMethod(clazz, "testSomethingElse"); | |
228 | AnnotationExpr annotationExpr = method.getAnnotation(0); | |
229 | ||
230 | // resolve annotation expression @Test | |
231 | JavassistAnnotationDeclaration resolved = (JavassistAnnotationDeclaration) annotationExpr.resolve(); | |
232 | ||
233 | // check that the annotation @Test has the annotations @Target and @Retention, but not @Documented | |
234 | assertEquals("org.junit.Test", resolved.getQualifiedName()); | |
235 | assertTrue(resolved.hasDirectlyAnnotation("java.lang.annotation.Target")); | |
236 | assertTrue(resolved.hasDirectlyAnnotation("java.lang.annotation.Retention")); | |
237 | assertFalse(resolved.hasDirectlyAnnotation("java.lang.annotation.Documented")); | |
238 | } | |
180 | 239 | } |
0 | 0 | package foo.bar; |
1 | 1 | |
2 | import java.lang.annotation.*; | |
2 | 3 | import org.junit.*; |
3 | 4 | |
5 | @Target(ElementType.TYPE) | |
6 | @Retention(RetentionPolicy.RUNTIME) | |
4 | 7 | public @interface MyAnnotation { |
5 | 8 | } |
6 | 9 |
9 | 9 | } |
10 | 10 | } |
11 | 11 | |
12 | class ParentClass { | |
12 | class ParentClass extends SuperParentClass { | |
13 | 13 | private class ResolveMe { |
14 | 14 | public String s = "incorrect"; |
15 | 15 | } |
16 | } | |
17 | ||
18 | class SuperParentClass { | |
19 | public class ResolveMe { | |
20 | public String s = "also incorrect"; | |
21 | } | |
16 | 22 | }⏎ |
14 | 14 | <groupId>com.github.javaparser</groupId> |
15 | 15 | <artifactId>javaparser-parent</artifactId> |
16 | 16 | <packaging>pom</packaging> |
17 | <version>3.6.21</version> | |
17 | <version>3.6.22</version> | |
18 | 18 | |
19 | 19 | <name>javaparser-parent</name> |
20 | 20 | <url>https://github.com/javaparser</url> |
134 | 134 | <connection>scm:git:git://github.com/javaparser/javaparser.git</connection> |
135 | 135 | <developerConnection>scm:git:git@github.com:javaparser/javaparser.git</developerConnection> |
136 | 136 | <url>https://github.com/javaparser/javaparser.git</url> |
137 | <tag>javaparser-parent-3.6.21</tag> | |
137 | <tag>javaparser-parent-3.6.22</tag> | |
138 | 138 | </scm> |
139 | 139 | |
140 | 140 | <issueManagement> |
27 | 27 | <dependency> |
28 | 28 | <groupId>com.github.javaparser</groupId> |
29 | 29 | <artifactId>javaparser-symbol-solver-core</artifactId> |
30 | <version>3.6.21</version> | |
30 | <version>3.6.22</version> | |
31 | 31 | </dependency> |
32 | 32 | ``` |
33 | 33 | |
34 | 34 | **Gradle**: |
35 | 35 | |
36 | 36 | ``` |
37 | compile 'com.github.javaparser:javaparser-symbol-solver-core:3.6.21' | |
37 | compile 'com.github.javaparser:javaparser-symbol-solver-core:3.6.22' | |
38 | 38 | ``` |
39 | 39 | |
40 | 40 | Since Version 3.5.10, the JavaParser project includes the JavaSymbolSolver. |
49 | 49 | <dependency> |
50 | 50 | <groupId>com.github.javaparser</groupId> |
51 | 51 | <artifactId>javaparser-core</artifactId> |
52 | <version>3.6.21</version> | |
52 | <version>3.6.22</version> | |
53 | 53 | </dependency> |
54 | 54 | ``` |
55 | 55 | |
56 | 56 | **Gradle**: |
57 | 57 | |
58 | 58 | ``` |
59 | compile 'com.github.javaparser:javaparser-core:3.6.21' | |
59 | compile 'com.github.javaparser:javaparser-core:3.6.22' | |
60 | 60 | ``` |
61 | 61 | |
62 | 62 | Since version 3.6.17 the AST can be serialized to JSON. |
68 | 68 | <dependency> |
69 | 69 | <groupId>com.github.javaparser</groupId> |
70 | 70 | <artifactId>javaparser-core-serialization</artifactId> |
71 | <version>3.6.21</version> | |
71 | <version>3.6.22</version> | |
72 | 72 | </dependency> |
73 | 73 | ``` |
74 | 74 | |
75 | 75 | **Gradle**: |
76 | 76 | |
77 | 77 | ``` |
78 | compile 'com.github.javaparser:javaparser-core-serialization:3.6.21' | |
78 | compile 'com.github.javaparser:javaparser-core-serialization:3.6.22' | |
79 | 79 | ``` |
80 | 80 | |
81 | 81 | ## How To Compile Sources |