Skip to content

Commit c00e0ac

Browse files
author
emmanue1
committed
Improvement in determination of types of local variables
1 parent 57a2884 commit c00e0ac

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

src/main/java/org/jd/core/v1/model/javasyntax/type/PrimitiveType.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,14 @@ public String toString() {
183183
public int getJavaPrimitiveFlags() {
184184
if ((flags & FLAG_BOOLEAN) != 0)
185185
return FLAG_BOOLEAN;
186-
else if ((flags & FLAG_BYTE) != 0)
187-
return FLAG_BYTE;
186+
else if ((flags & FLAG_INT) != 0)
187+
return FLAG_INT;
188188
else if ((flags & FLAG_CHAR) != 0)
189189
return FLAG_CHAR;
190190
else if ((flags & FLAG_SHORT) != 0)
191191
return FLAG_SHORT;
192+
else if ((flags & FLAG_BYTE) != 0)
193+
return FLAG_BYTE;
192194

193195
return flags;
194196
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,15 +974,17 @@ private AbstractLocalVariable getLocalVariableInAssignment(int index, int offset
974974
if (value.isNullExpression()) {
975975
return localVariableMaker.getLocalVariableInNullAssignment(index, offset, valueType);
976976
} else if (value.isLocalVariableReferenceExpression()) {
977-
return localVariableMaker.getLocalVariableInAssignment(typeBounds, index, offset, ((ClassFileLocalVariableReferenceExpression)value).getLocalVariable());
977+
AbstractLocalVariable valueLocalVariable = ((ClassFileLocalVariableReferenceExpression)value).getLocalVariable();
978+
AbstractLocalVariable lv = localVariableMaker.getLocalVariableInAssignment(typeBounds, index, offset, valueLocalVariable);
979+
valueLocalVariable.variableOnLeft(typeBounds, lv);
980+
return lv;
978981
} else if (value.isMethodInvocationExpression()) {
979982
if (valueType.isObjectType()) {
980983
// Remove type arguments
981984
valueType = ((ObjectType)valueType).createType(null);
982985
} else if (valueType.isGenericType()) {
983986
valueType = TYPE_UNDEFINED_OBJECT;
984987
}
985-
986988
return localVariableMaker.getLocalVariableInAssignment(typeBounds, index, offset, valueType);
987989
} else {
988990
return localVariableMaker.getLocalVariableInAssignment(typeBounds, index, offset, valueType);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ public void testJdk170NoDebugInfoBasic() throws Exception {
118118

119119
assertTrue(source.matches(PatternMaker.make("String str1 = \"3 == \" + (paramInt + 1) + \" ?\";")));
120120
assertTrue(source.indexOf("String str2 = String.valueOf(\"abc \\b \\f \\n \\r \\t \\\" \\007 def\");") != -1);
121-
assertTrue(source.matches(PatternMaker.make("char c2 = '€';")));
122-
assertTrue(source.matches(PatternMaker.make("char c4 = c3 = c2 = c1 = Character.toUpperCase('x');")));
121+
assertTrue(source.matches(PatternMaker.make("int j = 8364;")));
122+
assertTrue(source.matches(PatternMaker.make("int m = k = j = i = Character.toUpperCase('x');")));
123123
assertTrue(source.matches(PatternMaker.make("Class<String> clazz3 = String.class;")));
124124
assertTrue(source.matches(PatternMaker.make("Class<String> clazz2 = clazz3;")));
125125
assertTrue(source.matches(PatternMaker.make("Class<String> clazz1 = clazz2;")));

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,11 @@ public void testJdk170NoDebugInfoFor() throws Exception {
308308
String source = decompile(loader, new PlainTextPrinter(), internalClassName);
309309

310310
// Check decompiled source code
311-
assertTrue(source.matches(PatternMaker.make("for (byte b = 0; b < 10; b++)")));
312-
assertTrue(source.matches(PatternMaker.make("for (byte b = 0;; b++)")));
313-
assertTrue(source.matches(PatternMaker.make("for (byte b = 0; b < 10; b++)")));
311+
assertTrue(source.matches(PatternMaker.make("for (int i = 0; i < 10; i++)")));
312+
assertTrue(source.matches(PatternMaker.make("for (int i = 0;; i++)")));
314313
assertTrue(source.matches(PatternMaker.make("for (String str : paramList)")));
315314
assertTrue(source.matches(PatternMaker.make("for (paramInt = 0; paramInt < 10; paramInt++)")));
316-
assertTrue(source.matches(PatternMaker.make("for (int i : new int[] { 4 })")));
315+
assertTrue(source.matches(PatternMaker.make("for (int j : new int[] { 4 })")));
317316
assertTrue(source.matches(PatternMaker.make("for (String str : paramArrayOfString)")));
318317
assertTrue(source.matches(PatternMaker.make("for (String str : paramList)")));
319318

@@ -330,16 +329,16 @@ public void testJdk150For() throws Exception {
330329
String source = decompile(loader, new PlainTextPrinter(), internalClassName, configuration);
331330

332331
// Check decompiled source code
333-
assertTrue(source.matches(PatternMaker.make(": 20 */", "for (byte b = 0; b < 10; b++)")));
332+
assertTrue(source.matches(PatternMaker.make(": 20 */", "for (int i = 0; i < 10; i++)")));
334333
assertTrue(source.matches(PatternMaker.make(": 88 */", "while (paramInt < 10)")));
335334
assertTrue(source.matches(PatternMaker.make(": 273 */", "for (paramInt = 0; paramInt < 10; paramInt++)")));
336-
assertTrue(source.matches(PatternMaker.make(": 310 */", "for (int i : new int[] { 4 })")));
335+
assertTrue(source.matches(PatternMaker.make(": 310 */", "for (int j : new int[] { 4 })")));
337336
assertTrue(source.matches(PatternMaker.make("/* 347: 0 */", "do {")));
338-
assertTrue(source.matches(PatternMaker.make(": 349 */", "while (b < 10);")));
337+
assertTrue(source.matches(PatternMaker.make(": 349 */", "while (i < 10);")));
339338
assertTrue(source.matches(PatternMaker.make(": 385 */", "for (String str : paramArrayOfString)")));
340339
assertTrue(source.matches(PatternMaker.make(": 399 */", "for (String str : paramList)")));
341340
assertTrue(source.matches(PatternMaker.make(": 411 */", "Iterator<Class<?>> iterator = Arrays.<Class<?>>asList(getClass().getInterfaces()).iterator()")));
342-
assertTrue(source.matches(PatternMaker.make(": 427 */", "for (byte b = 0; b < 3; b++)")));
341+
assertTrue(source.matches(PatternMaker.make(": 427 */", "for (int i = 0; i < 3; i++)")));
343342

344343
// Recompile decompiled source code and check errors
345344
assertTrue(CompilerUtil.compile("1.5", new JavaSourceFileObject(internalClassName, source)));

0 commit comments

Comments
 (0)