Skip to content

Commit 5ae9e8a

Browse files
author
emmanue1
committed
Add type arguments on variable declaration of type 'Class'
1 parent 41262a9 commit 5ae9e8a

File tree

7 files changed

+34
-17
lines changed

7 files changed

+34
-17
lines changed

src/main/java/org/jd/core/v1/model/javasyntax/expression/TypeReferenceDotClassExpression.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
@@ -13,14 +13,17 @@
1313
public class TypeReferenceDotClassExpression implements Expression {
1414
protected int lineNumber;
1515
protected Type typeDotClass;
16+
protected Type type;
1617

1718
public TypeReferenceDotClassExpression(Type typeDotClass) {
1819
this.typeDotClass = typeDotClass;
20+
this.type = ObjectType.TYPE_CLASS.createType(typeDotClass);
1921
}
2022

2123
public TypeReferenceDotClassExpression(int lineNumber, Type typeDotClass) {
2224
this.lineNumber = lineNumber;
2325
this.typeDotClass = typeDotClass;
26+
this.type = ObjectType.TYPE_CLASS.createType(typeDotClass);
2427
}
2528

2629
@Override
@@ -34,7 +37,7 @@ public Type getTypeDotClass() {
3437

3538
@Override
3639
public Type getType() {
37-
return ObjectType.TYPE_CLASS;
40+
return type;
3841
}
3942

4043
@Override

src/main/java/org/jd/core/v1/service/converter/classfiletojavasyntax/model/localvariable/ObjectLocalVariable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
@@ -156,7 +156,7 @@ public void leftReduce(Type otherType) {
156156
} else if ((dimension == 0) && (otherType.getDimension() == 0) && otherType.isObject()) {
157157
ObjectType otherObjectType = (ObjectType) otherType;
158158

159-
if (!toType.getInternalName().equals(otherObjectType.getInternalName()) && objectTypeMaker.isAssignable(otherObjectType, toType)) {
159+
if (toType.getInternalName().equals(otherObjectType.getInternalName()) || objectTypeMaker.isAssignable(otherObjectType, toType)) {
160160
if (toType.getTypeArguments() == null) {
161161
toType = otherObjectType;
162162
} else if (otherObjectType.getTypeArguments() == null) {

src/main/java/org/jd/core/v1/service/fragmenter/javasyntaxtojavafragment/JavaSyntaxToJavaFragmentProcessor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
@@ -26,14 +26,15 @@ public class JavaSyntaxToJavaFragmentProcessor implements Processor {
2626
public void process(Message message) throws Exception {
2727
Loader loader = message.getHeader("loader");
2828
String mainInternalTypeName = message.getHeader("mainInternalTypeName");
29+
int majorVersion = message.getHeader("majorVersion");
2930
CompilationUnit compilationUnit = message.getBody();
3031

3132
SearchImportsVisitor importsVisitor = new SearchImportsVisitor(mainInternalTypeName);
3233
importsVisitor.visit(compilationUnit);
3334
ImportsFragment importsFragment = importsVisitor.getImportsFragment();
3435
message.setHeader("maxLineNumber", importsVisitor.getMaxLineNumber());
3536

36-
CompilationUnitVisitor visitor = new CompilationUnitVisitor(loader, mainInternalTypeName, importsFragment);
37+
CompilationUnitVisitor visitor = new CompilationUnitVisitor(loader, mainInternalTypeName, majorVersion, importsFragment);
3738
visitor.visit(compilationUnit);
3839
message.setBody(visitor.getFragments());
3940
}

src/main/java/org/jd/core/v1/service/fragmenter/javasyntaxtojavafragment/visitor/CompilationUnitVisitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
@@ -49,8 +49,8 @@ public class CompilationUnitVisitor extends StatementVisitor {
4949
protected SingleLineStatementVisitor singleLineStatementVisitor = new SingleLineStatementVisitor();
5050
protected String mainInternalName;
5151

52-
public CompilationUnitVisitor(Loader loader, String mainInternalTypeName, ImportsFragment importsFragment) {
53-
super(loader, mainInternalTypeName, importsFragment);
52+
public CompilationUnitVisitor(Loader loader, String mainInternalTypeName, int majorVersion, ImportsFragment importsFragment) {
53+
super(loader, mainInternalTypeName, majorVersion, importsFragment);
5454
this.mainInternalName = mainInternalTypeName;
5555
}
5656

src/main/java/org/jd/core/v1/service/fragmenter/javasyntaxtojavafragment/visitor/ExpressionVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public class ExpressionVisitor extends TypeVisitor {
5454
protected String currentTypeName;
5555
protected HexaExpressionVisitor hexaExpressionVisitor = new HexaExpressionVisitor();
5656

57-
public ExpressionVisitor(Loader loader, String mainInternalTypeName, ImportsFragment importsFragment) {
58-
super(loader, mainInternalTypeName, importsFragment);
57+
public ExpressionVisitor(Loader loader, String mainInternalTypeName, int majorVersion, ImportsFragment importsFragment) {
58+
super(loader, mainInternalTypeName, majorVersion, importsFragment);
5959
}
6060

6161
public DefaultList<Fragment> getFragments() {

src/main/java/org/jd/core/v1/service/fragmenter/javasyntaxtojavafragment/visitor/StatementVisitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
@@ -43,8 +43,8 @@ public class StatementVisitor extends ExpressionVisitor {
4343
public static final KeywordToken TRY = new KeywordToken("try");
4444
public static final KeywordToken WHILE = new KeywordToken("while");
4545

46-
public StatementVisitor(Loader loader, String mainInternalTypeName, ImportsFragment importsFragment) {
47-
super(loader, mainInternalTypeName, importsFragment);
46+
public StatementVisitor(Loader loader, String mainInternalTypeName, int majorVersion, ImportsFragment importsFragment) {
47+
super(loader, mainInternalTypeName, majorVersion, importsFragment);
4848
}
4949

5050
@Override

src/main/java/org/jd/core/v1/service/fragmenter/javasyntaxtojavafragment/visitor/TypeVisitor.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
@@ -21,6 +21,7 @@
2121
import java.util.HashMap;
2222
import java.util.List;
2323

24+
import static org.jd.core.v1.model.javasyntax.type.ObjectType.TYPE_CLASS;
2425
import static org.jd.core.v1.model.javasyntax.type.PrimitiveType.*;
2526

2627
public class TypeVisitor extends AbstractJavaSyntaxVisitor {
@@ -50,14 +51,16 @@ public class TypeVisitor extends AbstractJavaSyntaxVisitor {
5051

5152
protected Loader loader;
5253
protected String internalPackageName;
54+
protected int majorVersion;
5355
protected ImportsFragment importsFragment;
5456
protected Tokens tokens;
5557
protected int maxLineNumber = 0;
5658
protected String currentInternalTypeName;
5759
protected HashMap<String, TextToken> textTokenCache = new HashMap<>();
5860

59-
public TypeVisitor(Loader loader, String mainInternalTypeName, ImportsFragment importsFragment) {
61+
public TypeVisitor(Loader loader, String mainInternalTypeName, int majorVersion, ImportsFragment importsFragment) {
6062
this.loader = loader;
63+
this.majorVersion = majorVersion;
6164
this.importsFragment = importsFragment;
6265

6366
int index = mainInternalTypeName.lastIndexOf('/');
@@ -104,7 +107,17 @@ public void visit(ObjectType type) {
104107
tokens.add(newTypeReferenceToken(type, currentInternalTypeName));
105108

106109
// Build token for type arguments
107-
visitTypeArgumentList(type.getTypeArguments());
110+
BaseTypeArgument typeArguments = type.getTypeArguments();
111+
112+
if (majorVersion >= 49) { // (majorVersion >= Java 5)
113+
if (typeArguments != null) {
114+
visitTypeArgumentList(typeArguments);
115+
} else if (type.equals(TYPE_CLASS)) {
116+
tokens.add(TextToken.LEFTANGLEBRACKET);
117+
tokens.add(TextToken.QUESTIONMARK);
118+
tokens.add(TextToken.RIGHTANGLEBRACKET);
119+
}
120+
}
108121

109122
// Build token for dimension
110123
visitDimension(type.getDimension());

0 commit comments

Comments
 (0)