Skip to content

Commit 0bc5912

Browse files
author
emmanue1
committed
Fix syntax errors in decompiled sources
1 parent e216332 commit 0bc5912

File tree

9 files changed

+54
-35
lines changed

9 files changed

+54
-35
lines changed

src/main/java/org/jd/core/v1/model/javasyntax/AbstractJavaSyntaxVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void visit(ConstructorInvocationExpression expression) {
6868
public void visit(ConstructorDeclaration declaration) {
6969
safeAccept(declaration.getAnnotationReferences());
7070
safeAccept(declaration.getFormalParameters());
71-
safeAccept(declaration.getExceptions());
71+
safeAccept(declaration.getExceptionTypes());
7272
safeAccept(declaration.getStatements());
7373
}
7474

src/main/java/org/jd/core/v1/model/javasyntax/declaration/ConstructorDeclaration.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ConstructorDeclaration implements MemberDeclaration {
1717
protected int flags;
1818
protected BaseTypeParameter typeParameters;
1919
protected BaseFormalParameter formalParameters;
20-
protected BaseType exceptions;
20+
protected BaseType exceptionTypes;
2121
protected String descriptor;
2222
protected BaseStatement statements;
2323

@@ -28,12 +28,12 @@ public ConstructorDeclaration(int flags, BaseFormalParameter formalParameters, S
2828
this.statements = statements;
2929
}
3030

31-
public ConstructorDeclaration(BaseAnnotationReference annotationReferences, int flags, BaseTypeParameter typeParameters, BaseFormalParameter formalParameters, BaseType exceptions, String descriptor, BaseStatement statements) {
31+
public ConstructorDeclaration(BaseAnnotationReference annotationReferences, int flags, BaseTypeParameter typeParameters, BaseFormalParameter formalParameters, BaseType exceptionTypes, String descriptor, BaseStatement statements) {
3232
this.annotationReferences = annotationReferences;
3333
this.flags = flags;
3434
this.typeParameters = typeParameters;
3535
this.formalParameters = formalParameters;
36-
this.exceptions = exceptions;
36+
this.exceptionTypes = exceptionTypes;
3737
this.descriptor = descriptor;
3838
this.statements = statements;
3939
}
@@ -54,8 +54,8 @@ public BaseFormalParameter getFormalParameters() {
5454
return formalParameters;
5555
}
5656

57-
public BaseType getExceptions() {
58-
return exceptions;
57+
public BaseType getExceptionTypes() {
58+
return exceptionTypes;
5959
}
6060

6161
public String getDescriptor() {

src/main/java/org/jd/core/v1/service/converter/classfiletojavasyntax/model/javasyntax/declaration/ClassFileConstructorDeclaration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public class ClassFileConstructorDeclaration extends ConstructorDeclaration impl
3131

3232
public ClassFileConstructorDeclaration(
3333
ClassFileBodyDeclaration bodyDeclaration, ClassFile classFile, Method method, BaseAnnotationReference annotationReferences,
34-
BaseTypeParameter typeParameters, BaseType parameterTypes, BaseType exceptions, Map<String, TypeArgument> bindings,
34+
BaseTypeParameter typeParameters, BaseType parameterTypes, BaseType exceptionTypes, Map<String, TypeArgument> bindings,
3535
Map<String, BaseType> typeBounds, int firstLineNumber) {
36-
super(annotationReferences, method.getAccessFlags(), typeParameters, null, exceptions, method.getDescriptor(), null);
36+
super(annotationReferences, method.getAccessFlags(), typeParameters, null, exceptionTypes, method.getDescriptor(), null);
3737
this.bodyDeclaration = bodyDeclaration;
3838
this.classFile = classFile;
3939
this.method = method;

src/main/java/org/jd/core/v1/service/converter/classfiletojavasyntax/model/javasyntax/declaration/ClassFileMethodDeclaration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ public ClassFileMethodDeclaration(
5959

6060
public ClassFileMethodDeclaration(
6161
ClassFileBodyDeclaration bodyDeclaration, ClassFile classFile, Method method, BaseAnnotationReference annotationReferences,
62-
String name, BaseTypeParameter typeParameters, Type returnedType, BaseType parameterTypes, BaseType exceptions,
62+
String name, BaseTypeParameter typeParameters, Type returnedType, BaseType parameterTypes, BaseType exceptionTypes,
6363
ElementValue defaultAnnotationValue, Map<String, TypeArgument> bindings,
6464
Map<String, BaseType> typeBounds, int firstLineNumber) {
65-
super(annotationReferences, method.getAccessFlags(), name, typeParameters, returnedType, null, exceptions, method.getDescriptor(), null, defaultAnnotationValue);
65+
super(annotationReferences, method.getAccessFlags(), name, typeParameters, returnedType, null, exceptionTypes, method.getDescriptor(), null, defaultAnnotationValue);
6666
this.bodyDeclaration = bodyDeclaration;
6767
this.classFile = classFile;
6868
this.method = method;

src/main/java/org/jd/core/v1/service/converter/classfiletojavasyntax/processor/ConvertClassFileProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,13 @@ protected List<ClassFileConstructorOrMethodDeclaration> convertMethods(TypeMaker
220220
if ("<init>".equals(name)) {
221221
list.add(new ClassFileConstructorDeclaration(
222222
bodyDeclaration, classFile, method, annotationReferences, methodTypes.typeParameters,
223-
methodTypes.parameterTypes, methodTypes.exceptions, bindings, typeBounds, firstLineNumber));
223+
methodTypes.parameterTypes, methodTypes.exceptionTypes, bindings, typeBounds, firstLineNumber));
224224
} else if ("<clinit>".equals(name)) {
225225
list.add(new ClassFileStaticInitializerDeclaration(bodyDeclaration, classFile, method, bindings, typeBounds, firstLineNumber));
226226
} else {
227227
ClassFileMethodDeclaration methodDeclaration = new ClassFileMethodDeclaration(
228228
bodyDeclaration, classFile, method, annotationReferences, name, methodTypes.typeParameters,
229-
methodTypes.returnedType, methodTypes.parameterTypes, methodTypes.exceptions, defaultAnnotationValue,
229+
methodTypes.returnedType, methodTypes.parameterTypes, methodTypes.exceptionTypes, defaultAnnotationValue,
230230
bindings, typeBounds, firstLineNumber);
231231
if ((classFile.getAccessFlags() & Constants.ACC_INTERFACE) != 0) {
232232
if (methodDeclaration.getFlags() == Constants.ACC_PUBLIC) {

src/main/java/org/jd/core/v1/service/converter/classfiletojavasyntax/util/TypeMaker.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ private MethodTypes parseMethodSignature(String descriptor, String signature, St
251251
mt.typeParameters = mtSignature.typeParameters;
252252
mt.parameterTypes = mtDescriptor.parameterTypes;
253253
mt.returnedType = mtSignature.returnedType;
254-
mt.exceptions = mtSignature.exceptions;
254+
mt.exceptionTypes = mtSignature.exceptionTypes;
255255

256256
return mt;
257257
} else if (mtDescriptor.parameterTypes.size() == mtSignature.parameterTypes.size()) {
@@ -266,7 +266,7 @@ private MethodTypes parseMethodSignature(String descriptor, String signature, St
266266
mt.typeParameters = mtSignature.typeParameters;
267267
mt.parameterTypes = parameterTypes;
268268
mt.returnedType = mtSignature.returnedType;
269-
mt.exceptions = mtSignature.exceptions;
269+
mt.exceptionTypes = mtSignature.exceptionTypes;
270270

271271
return mt;
272272
}
@@ -340,22 +340,22 @@ private MethodTypes parseMethodSignature(String signature, String[] exceptionTyp
340340
// Signature does not contain exceptions
341341
if (exceptionTypeNames != null) {
342342
if (exceptionTypeNames.length == 1) {
343-
methodTypes.exceptions = makeFromInternalTypeName(exceptionTypeNames[0]);
343+
methodTypes.exceptionTypes = makeFromInternalTypeName(exceptionTypeNames[0]);
344344
} else {
345345
UnmodifiableTypes list = new UnmodifiableTypes(exceptionTypeNames.length);
346346

347347
for (String exceptionTypeName : exceptionTypeNames) {
348348
list.add(makeFromInternalTypeName(exceptionTypeName));
349349
}
350350

351-
methodTypes.exceptions = list;
351+
methodTypes.exceptionTypes = list;
352352
}
353353
}
354354
} else {
355355
Type nextException = parseExceptionSignature(reader);
356356

357357
if (nextException == null) {
358-
methodTypes.exceptions = firstException;
358+
methodTypes.exceptionTypes = firstException;
359359
} else {
360360
UnmodifiableTypes list = new UnmodifiableTypes();
361361

@@ -366,7 +366,7 @@ private MethodTypes parseMethodSignature(String signature, String[] exceptionTyp
366366
nextException = parseExceptionSignature(reader);
367367
} while (nextException != null);
368368

369-
methodTypes.exceptions = list;
369+
methodTypes.exceptionTypes = list;
370370
}
371371
}
372372

@@ -1336,7 +1336,7 @@ private MethodTypes loadMethodTypes(ObjectType objectType, String methodName, St
13361336
newMethodTypes.returnedType = (Type)bindTypeParametersToTypeArgumentsVisitor.getType();
13371337

13381338
newMethodTypes.typeParameters = null;
1339-
newMethodTypes.exceptions = methodTypes.exceptions;
1339+
newMethodTypes.exceptionTypes = methodTypes.exceptionTypes;
13401340

13411341
methodTypes = newMethodTypes;
13421342
}
@@ -1774,6 +1774,6 @@ public static class MethodTypes {
17741774
public BaseTypeParameter typeParameters;
17751775
public BaseType parameterTypes;
17761776
public Type returnedType;
1777-
public BaseType exceptions;
1777+
public BaseType exceptionTypes;
17781778
}
17791779
}

src/main/java/org/jd/core/v1/service/converter/classfiletojavasyntax/visitor/AddCastExpressionVisitor.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class AddCastExpressionVisitor extends AbstractJavaSyntaxVisitor {
3232
protected TypeMaker typeMaker;
3333
protected Map<String, BaseType> typeBounds;
3434
protected Type returnedType;
35+
protected BaseType exceptionTypes;
3536
protected Type type;
3637

3738
public AddCastExpressionVisitor(TypeMaker typeMaker) {
@@ -99,10 +100,13 @@ public void visit(ConstructorDeclaration declaration) {
99100

100101
if (statements != null) {
101102
Map<String, BaseType> tb = typeBounds;
103+
BaseType et = exceptionTypes;
102104

103105
typeBounds = ((ClassFileConstructorDeclaration)declaration).getTypeBounds();
106+
exceptionTypes = declaration.getExceptionTypes();
104107
statements.accept(this);
105108
typeBounds = tb;
109+
exceptionTypes = et;
106110
}
107111
}
108112

@@ -112,13 +116,16 @@ public void visit(MethodDeclaration declaration) {
112116

113117
if (statements != null) {
114118
Map<String, BaseType> tb = typeBounds;
115-
Type t = returnedType;
119+
Type rt = returnedType;
120+
BaseType et = exceptionTypes;
116121

117122
typeBounds = ((ClassFileMethodDeclaration)declaration).getTypeBounds();
118123
returnedType = declaration.getReturnedType();
124+
exceptionTypes = declaration.getExceptionTypes();
119125
statements.accept(this);
120126
typeBounds = tb;
121-
returnedType = t;
127+
returnedType = rt;
128+
exceptionTypes = et;
122129
}
123130
}
124131

@@ -127,18 +134,30 @@ public void visit(LambdaIdentifiersExpression expression) {
127134
BaseStatement statements = expression.getStatements();
128135

129136
if (statements != null) {
130-
Type t = returnedType;
137+
Type rt = returnedType;
131138

132139
returnedType = expression.getReturnedType();
133140
statements.accept(this);
134-
returnedType = t;
141+
returnedType = rt;
135142
}
136143
}
137144

138-
@Override public void visit(ReturnExpressionStatement statement) {
145+
@Override
146+
public void visit(ReturnExpressionStatement statement) {
139147
statement.setExpression(updateExpression(returnedType, statement.getExpression()));
140148
}
141149

150+
@Override
151+
public void visit(ThrowStatement statement) {
152+
if ((exceptionTypes != null) && (exceptionTypes.size() == 1)) {
153+
Type exceptionType = exceptionTypes.getFirst();
154+
155+
if (exceptionType.isGeneric() && !statement.getExpression().getType().equals(exceptionType)) {
156+
statement.setExpression(addCastExpression(exceptionType, statement.getExpression()));
157+
}
158+
}
159+
}
160+
142161
@Override
143162
public void visit(LocalVariableDeclaration declaration) {
144163
Type t = type;

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
@@ -368,13 +368,13 @@ public void visit(ConstructorDeclaration declaration) {
368368
tokens.add(EndBlockToken.END_PARAMETERS_BLOCK);
369369
}
370370

371-
BaseType exceptions = declaration.getExceptions();
371+
BaseType exceptionTypes = declaration.getExceptionTypes();
372372

373-
if (exceptions != null) {
373+
if (exceptionTypes != null) {
374374
tokens.add(TextToken.SPACE);
375375
tokens.add(THROWS);
376376
tokens.add(TextToken.SPACE);
377-
exceptions.accept(this);
377+
exceptionTypes.accept(this);
378378
}
379379

380380
BaseStatement statements = declaration.getStatements();

src/test/java/org/jd/core/v1/SignatureParserTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void testAnnotatedClass() throws Exception {
102102
Assert.assertEquals("int", source);
103103

104104
// Check exceptions
105-
assertNull(methodTypes.exceptions);
105+
assertNull(methodTypes.exceptionTypes);
106106

107107
// Check method 'ping'
108108
// public void ping(String host) throws UnknownHostException, UnsatisfiedLinkError
@@ -133,10 +133,10 @@ public void testAnnotatedClass() throws Exception {
133133
Assert.assertEquals("void", source);
134134

135135
// Check exceptions
136-
assertNotNull(methodTypes.exceptions);
136+
assertNotNull(methodTypes.exceptionTypes);
137137

138138
visitor.reset();
139-
methodTypes.exceptions.accept(visitor);
139+
methodTypes.exceptionTypes.accept(visitor);
140140
source = visitor.toString();
141141

142142
Assert.assertEquals("java.net.UnknownHostException, java.lang.UnsatisfiedLinkError", source);
@@ -248,10 +248,10 @@ public void testGenericClass() throws Exception {
248248
Assert.assertEquals("java.util.List<? extends java.lang.Number>", source);
249249

250250
// Check exceptions
251-
assertNotNull(methodTypes.exceptions);
251+
assertNotNull(methodTypes.exceptionTypes);
252252

253253
visitor.reset();
254-
methodTypes.exceptions.accept(visitor);
254+
methodTypes.exceptionTypes.accept(visitor);
255255
source = visitor.toString();
256256

257257
Assert.assertEquals("java.security.InvalidParameterException, java.lang.ClassCastException", source);
@@ -290,10 +290,10 @@ public void testGenericClass() throws Exception {
290290
Assert.assertEquals("java.util.List<? extends java.lang.Number>", source);
291291

292292
// Check exceptions
293-
assertNotNull(methodTypes.exceptions);
293+
assertNotNull(methodTypes.exceptionTypes);
294294

295295
visitor.reset();
296-
methodTypes.exceptions.accept(visitor);
296+
methodTypes.exceptionTypes.accept(visitor);
297297
source = visitor.toString();
298298

299299
Assert.assertEquals("T2, java.security.InvalidParameterException", source);

0 commit comments

Comments
 (0)