File tree Expand file tree Collapse file tree 12 files changed +151
-13
lines changed
src/main/java/org/jd/core/v1
service/converter/classfiletojavasyntax Expand file tree Collapse file tree 12 files changed +151
-13
lines changed Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2008- 2019 Emmanuel Dupuy.
2+ * Copyright (c) 2008, 2019 Emmanuel Dupuy.
33 * This project is distributed under the GPLv3 license.
44 * This is a Copyleft license that gives the user the right to use,
55 * copy and modify the code freely for non-commercial purposes.
99
1010import org .jd .core .v1 .util .DefaultList ;
1111
12+ import java .util .Iterator ;
1213import java .util .List ;
1314
1415public class ArrayTypeArguments extends DefaultList <TypeArgument > implements BaseTypeArgument {
@@ -22,4 +23,28 @@ public ArrayTypeArguments(List<TypeArgument> list) {
2223 public void accept (TypeVisitor visitor ) {
2324 visitor .visit (this );
2425 }
26+
27+ @ Override
28+ public boolean isTypeArgumentAssignableFrom (BaseTypeArgument typeArgument ) {
29+ if (typeArgument .getClass () != ArrayTypeArguments .class ) {
30+ return false ;
31+ }
32+
33+ ArrayTypeArguments ata = (ArrayTypeArguments )typeArgument ;
34+
35+ if (size () != ata .size ()) {
36+ return false ;
37+ }
38+
39+ Iterator <TypeArgument > iterator1 = iterator ();
40+ Iterator <TypeArgument > iterator2 = ata .iterator ();
41+
42+ while (iterator1 .hasNext ()) {
43+ if (!iterator1 .next ().isTypeArgumentAssignableFrom (iterator2 .next ())) {
44+ return false ;
45+ }
46+ }
47+
48+ return true ;
49+ }
2550}
Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2008- 2019 Emmanuel Dupuy.
2+ * Copyright (c) 2008, 2019 Emmanuel Dupuy.
33 * This project is distributed under the GPLv3 license.
44 * This is a Copyleft license that gives the user the right to use,
55 * copy and modify the code freely for non-commercial purposes.
88package org .jd .core .v1 .model .javasyntax .type ;
99
1010public interface BaseTypeArgument extends TypeVisitable {
11+ boolean isTypeArgumentAssignableFrom (BaseTypeArgument typeArgument );
1112}
Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2008- 2019 Emmanuel Dupuy.
2+ * Copyright (c) 2008, 2019 Emmanuel Dupuy.
33 * This project is distributed under the GPLv3 license.
44 * This is a Copyleft license that gives the user the right to use,
55 * copy and modify the code freely for non-commercial purposes.
@@ -16,4 +16,9 @@ protected DiamondTypeArgument() {}
1616 public void accept (TypeVisitor visitor ) {
1717 visitor .visit (this );
1818 }
19+
20+ @ Override
21+ public boolean isTypeArgumentAssignableFrom (BaseTypeArgument typeArgument ) {
22+ return true ;
23+ }
1924}
Original file line number Diff line number Diff line change @@ -65,13 +65,26 @@ public void accept(TypeVisitor visitor) {
6565 visitor .visit (this );
6666 }
6767
68+ @ Override
69+ public boolean isTypeArgumentAssignableFrom (BaseTypeArgument typeArgument ) {
70+ return equals (typeArgument );
71+ }
72+
6873 @ Override
6974 public boolean isGeneric () {
7075 return true ;
7176 }
7277
7378 @ Override
7479 public String toString () {
75- return "GenericType{" + name + "}" ;
80+ StringBuilder sb = new StringBuilder ("GenericType{" );
81+
82+ sb .append (name );
83+
84+ if (dimension > 0 ) {
85+ sb .append (", dimension=" ).append (dimension );
86+ }
87+
88+ return sb .append ('}' ).toString ();
7689 }
7790}
Original file line number Diff line number Diff line change @@ -191,6 +191,27 @@ public void accept(TypeVisitor visitor) {
191191 visitor .visit (this );
192192 }
193193
194+ @ Override
195+ public boolean isTypeArgumentAssignableFrom (BaseTypeArgument typeArgument ) {
196+ if (typeArgument .getClass () != ObjectType .class ) {
197+ return false ;
198+ }
199+
200+ ObjectType ot = (ObjectType )typeArgument ;
201+
202+ if ((dimension != ot .getDimension ()) || !internalName .equals (ot .getInternalName ())) {
203+ return false ;
204+ }
205+
206+ if (ot .getTypeArguments () == null ) {
207+ return (typeArgument == null );
208+ } else if (typeArgument == null ) {
209+ return false ;
210+ } else {
211+ return typeArguments .isTypeArgumentAssignableFrom (ot .getTypeArguments ());
212+ }
213+ }
214+
194215 @ Override
195216 public boolean isObject () {
196217 return true ;
Original file line number Diff line number Diff line change @@ -153,6 +153,11 @@ public void accept(TypeVisitor visitor) {
153153 visitor .visit (this );
154154 }
155155
156+ @ Override
157+ public boolean isTypeArgumentAssignableFrom (BaseTypeArgument typeArgument ) {
158+ return equals (typeArgument );
159+ }
160+
156161 @ Override
157162 public boolean isPrimitive () {
158163 return true ;
Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2008- 2019 Emmanuel Dupuy.
2+ * Copyright (c) 2008, 2019 Emmanuel Dupuy.
33 * This project is distributed under the GPLv3 license.
44 * This is a Copyleft license that gives the user the right to use,
55 * copy and modify the code freely for non-commercial purposes.
@@ -23,6 +23,17 @@ public void accept(TypeVisitor visitor) {
2323 visitor .visit (this );
2424 }
2525
26+ @ Override
27+ public boolean isTypeArgumentAssignableFrom (BaseTypeArgument typeArgument ) {
28+ if (typeArgument .getClass () == WildcardExtendsTypeArgument .class ) {
29+ return type .isTypeArgumentAssignableFrom (((WildcardExtendsTypeArgument )typeArgument ).getType ());
30+ } else if (typeArgument instanceof Type ) {
31+ return type .isTypeArgumentAssignableFrom (typeArgument );
32+ }
33+
34+ return false ;
35+ }
36+
2637 @ Override
2738 public String toString () {
2839 return "WildcardExtendsTypeArgument{? extends " + type + "}" ;
Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2008- 2019 Emmanuel Dupuy.
2+ * Copyright (c) 2008, 2019 Emmanuel Dupuy.
33 * This project is distributed under the GPLv3 license.
44 * This is a Copyleft license that gives the user the right to use,
55 * copy and modify the code freely for non-commercial purposes.
@@ -23,6 +23,17 @@ public void accept(TypeVisitor visitor) {
2323 visitor .visit (this );
2424 }
2525
26+ @ Override
27+ public boolean isTypeArgumentAssignableFrom (BaseTypeArgument typeArgument ) {
28+ if (typeArgument .getClass () == WildcardSuperTypeArgument .class ) {
29+ return type .isTypeArgumentAssignableFrom (((WildcardSuperTypeArgument )typeArgument ).getType ());
30+ } else if (typeArgument instanceof Type ) {
31+ return type .isTypeArgumentAssignableFrom (typeArgument );
32+ }
33+
34+ return false ;
35+ }
36+
2637 @ Override
2738 public String toString () {
2839 return "WildcardSuperTypeArgument{? super " + type + "}" ;
Original file line number Diff line number Diff line change @@ -18,4 +18,9 @@ public void accept(TypeVisitor visitor) {
1818 public String toString () {
1919 return "Wildcard{?}" ;
2020 }
21+
22+ @ Override
23+ public boolean isTypeArgumentAssignableFrom (BaseTypeArgument typeArgument ) {
24+ return true ;
25+ }
2126}
Original file line number Diff line number Diff line change @@ -40,7 +40,22 @@ public void accept(LocalVariableVisitor visitor) {
4040
4141 @ Override
4242 public String toString () {
43- return "GenericLocalVariable{" + type + ", index=" + index + "}" ;
43+ StringBuilder sb = new StringBuilder ();
44+
45+ sb .append ("GenericLocalVariable{" );
46+ sb .append (type .getName ());
47+
48+ if (type .getDimension () > 0 ) {
49+ sb .append (new String (new char [type .getDimension ()]).replaceAll ("\0 " , "[]" ));
50+ }
51+
52+ sb .append (' ' ).append (name ).append (", index=" ).append (index );
53+
54+ if (next != null ) {
55+ sb .append (", next=" ).append (next );
56+ }
57+
58+ return sb .append ("}" ).toString ();
4459 }
4560
4661 @ Override public boolean isAssignableFrom (Type otherType ) {
You can’t perform that action at this time.
0 commit comments