Skip to content

Commit dede475

Browse files
author
emmanue1
committed
Fix bug on the declarations of the volatile fields
1 parent e5faeac commit dede475

File tree

9 files changed

+299
-34
lines changed

9 files changed

+299
-34
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ apply plugin: 'com.jfrog.bintray'
66

77
dependencies {
88
testCompile 'junit:junit:4.12'
9+
testCompile 'org.apache.commons:commons-collections4:4.1'
910
}
1011

1112
version='1.0.7'

src/main/java/org/jd/core/v1/model/classfile/Constants.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.
@@ -20,7 +20,7 @@ public interface Constants {
2020
int ACC_TRANSITIVE = 0x0020; // . . . . . MR . .
2121
int ACC_VOLATILE = 0x0040; // . F . . . . . .
2222
int ACC_BRIDGE = 0x0040; // . . M . . . . .
23-
int ACC_STATIC_PHASE = 0x0040; // . . M . . MR . .
23+
int ACC_STATIC_PHASE = 0x0040; // . . . . . MR . .
2424
int ACC_TRANSIENT = 0x0080; // . F . . . . . .
2525
int ACC_VARARGS = 0x0080; // . . M . . . . .
2626
int ACC_NATIVE = 0x0100; // . . M . . . . .

src/main/java/org/jd/core/v1/model/javasyntax/declaration/Declaration.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.
@@ -20,7 +20,7 @@ public interface Declaration {
2020
int FLAG_TRANSITIVE = 0x0020; // . . . . . MR . .
2121
int FLAG_VOLATILE = 0x0040; // . F . . . . . .
2222
int FLAG_BRIDGE = 0x0040; // . . M . . . . .
23-
int FLAG_STATIC_PHASE = 0x0040; // . . M . . MR . .
23+
int FLAG_STATIC_PHASE = 0x0040; // . . . . . MR . .
2424
int FLAG_TRANSIENT = 0x0080; // . F . . . . . .
2525
int FLAG_VARARGS = 0x0080; // . . M . . . . .
2626
int FLAG_NATIVE = 0x0100; // . . M . . . . .

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

Lines changed: 94 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public CompilationUnitVisitor(Loader loader, String mainInternalTypeName, int ma
5656

5757
@Override
5858
public void visit(AnnotationDeclaration declaration) {
59-
if ((declaration.getFlags() & (FLAG_SYNTHETIC | FLAG_BRIDGE)) == 0) {
59+
if ((declaration.getFlags() & FLAG_SYNTHETIC) == 0) {
6060
fragments.add(StartMovableJavaBlockFragment.START_MOVABLE_TYPE_BLOCK);
6161

6262
buildFragmentsForTypeDeclaration(declaration, declaration.getFlags() & ~FLAG_ABSTRACT, ANNOTATION);
@@ -209,7 +209,7 @@ public void visit(BodyDeclaration declaration) {
209209

210210
@Override
211211
public void visit(ClassDeclaration declaration) {
212-
if ((declaration.getFlags() & (FLAG_SYNTHETIC | FLAG_BRIDGE)) == 0) {
212+
if ((declaration.getFlags() & FLAG_SYNTHETIC) == 0) {
213213
fragments.add(StartMovableJavaBlockFragment.START_MOVABLE_TYPE_BLOCK);
214214

215215
buildFragmentsForClassOrInterfaceDeclaration(declaration, declaration.getFlags(), CLASS);
@@ -336,7 +336,7 @@ public void visit(ConstructorDeclaration declaration) {
336336
}
337337

338338
// Build tokens for access
339-
buildTokensForAccessFlags(declaration.getFlags());
339+
buildTokensForMethodAccessFlags(declaration.getFlags());
340340

341341
// Build tokens for type parameters
342342
BaseTypeParameter typeParameters = declaration.getTypeParameters();
@@ -465,7 +465,7 @@ public void visit(ElementValuePair reference) {
465465

466466
@Override
467467
public void visit(EnumDeclaration declaration) {
468-
if ((declaration.getFlags() & (FLAG_SYNTHETIC | FLAG_BRIDGE)) == 0) {
468+
if ((declaration.getFlags() & FLAG_SYNTHETIC) == 0) {
469469
fragments.add(StartMovableJavaBlockFragment.START_MOVABLE_TYPE_BLOCK);
470470

471471
buildFragmentsForTypeDeclaration(declaration, declaration.getFlags(), ENUM);
@@ -607,7 +607,7 @@ public void visit(ExpressionVariableInitializer declaration) {
607607

608608
@Override
609609
public void visit(FieldDeclaration declaration) {
610-
if ((declaration.getFlags() & (FLAG_SYNTHETIC | FLAG_BRIDGE)) == 0) {
610+
if ((declaration.getFlags() & FLAG_SYNTHETIC) == 0) {
611611
fragments.add(StartMovableJavaBlockFragment.START_MOVABLE_FIELD_BLOCK);
612612

613613
tokens = new Tokens();
@@ -623,7 +623,7 @@ public void visit(FieldDeclaration declaration) {
623623
}
624624

625625
// Build tokens for access
626-
buildTokensForAccessFlags(declaration.getFlags());
626+
buildTokensForFieldAccessFlags(declaration.getFlags());
627627
declaration.getType().accept(this);
628628

629629
tokens.add(StartBlockToken.START_DECLARATION_OR_STATEMENT_BLOCK);
@@ -757,7 +757,7 @@ public void visit(InstanceInitializerDeclaration declaration) {
757757

758758
@Override
759759
public void visit(InterfaceDeclaration declaration) {
760-
if ((declaration.getFlags() & (FLAG_SYNTHETIC | FLAG_BRIDGE)) == 0) {
760+
if ((declaration.getFlags() & FLAG_SYNTHETIC) == 0) {
761761
fragments.add(StartMovableJavaBlockFragment.START_MOVABLE_TYPE_BLOCK);
762762

763763
buildFragmentsForClassOrInterfaceDeclaration(declaration, declaration.getFlags() & ~FLAG_ABSTRACT, INTERFACE);
@@ -1085,7 +1085,7 @@ public void visit(MethodDeclaration declaration) {
10851085
}
10861086

10871087
// Build tokens for access
1088-
buildTokensForAccessFlags(declaration.getFlags());
1088+
buildTokensForMethodAccessFlags(declaration.getFlags());
10891089

10901090
// Build tokens for type parameters
10911091
BaseTypeParameter typeParameters = declaration.getTypeParameters();
@@ -1248,7 +1248,7 @@ protected void buildFragmentsForTypeDeclaration(TypeDeclaration declaration, int
12481248
}
12491249

12501250
// Build tokens for access
1251-
buildTokensForAccessFlags(flags);
1251+
buildTokensForTypeAccessFlags(flags);
12521252
tokens.add(keyword);
12531253
tokens.add(TextToken.SPACE);
12541254

@@ -1269,21 +1269,50 @@ protected void buildFragmentsForClassOrInterfaceDeclaration(InterfaceDeclaration
12691269
}
12701270
}
12711271

1272-
protected void buildTokensForAccessFlags(int flags) {
1272+
protected void buildTokensForTypeAccessFlags(int flags) {
12731273
if ((flags & FLAG_PUBLIC) != 0) {
12741274
tokens.add(PUBLIC);
12751275
tokens.add(TextToken.SPACE);
12761276
}
1277+
if ((flags & FLAG_PROTECTED) != 0) {
1278+
tokens.add(PROTECTED);
1279+
tokens.add(TextToken.SPACE);
1280+
}
12771281
if ((flags & FLAG_PRIVATE) != 0) {
12781282
tokens.add(PRIVATE);
12791283
tokens.add(TextToken.SPACE);
12801284
}
1285+
if ((flags & FLAG_STATIC) != 0) {
1286+
tokens.add(STATIC);
1287+
tokens.add(TextToken.SPACE);
1288+
}
1289+
if ((flags & FLAG_FINAL) != 0) {
1290+
tokens.add(FINAL);
1291+
tokens.add(TextToken.SPACE);
1292+
}
1293+
if ((flags & FLAG_ABSTRACT) != 0) {
1294+
tokens.add(ABSTRACT);
1295+
tokens.add(TextToken.SPACE);
1296+
}
1297+
if ((flags & FLAG_SYNTHETIC) != 0) {
1298+
tokens.add(StartMarkerToken.COMMENT);
1299+
tokens.add(COMMENT_SYNTHETIC);
1300+
tokens.add(EndMarkerToken.COMMENT);
1301+
tokens.add(TextToken.SPACE);
1302+
}
1303+
}
1304+
1305+
protected void buildTokensForFieldAccessFlags(int flags) {
1306+
if ((flags & FLAG_PUBLIC) != 0) {
1307+
tokens.add(PUBLIC);
1308+
tokens.add(TextToken.SPACE);
1309+
}
12811310
if ((flags & FLAG_PROTECTED) != 0) {
12821311
tokens.add(PROTECTED);
12831312
tokens.add(TextToken.SPACE);
12841313
}
1285-
if ((flags & FLAG_DEFAULT) != 0) {
1286-
tokens.add(DEFAULT);
1314+
if ((flags & FLAG_PRIVATE) != 0) {
1315+
tokens.add(PRIVATE);
12871316
tokens.add(TextToken.SPACE);
12881317
}
12891318
if ((flags & FLAG_STATIC) != 0) {
@@ -1294,12 +1323,45 @@ protected void buildTokensForAccessFlags(int flags) {
12941323
tokens.add(FINAL);
12951324
tokens.add(TextToken.SPACE);
12961325
}
1297-
if ((flags & FLAG_NATIVE) != 0) {
1298-
tokens.add(NATIVE);
1326+
if ((flags & FLAG_VOLATILE) != 0) {
1327+
tokens.add(VOLATILE);
12991328
tokens.add(TextToken.SPACE);
13001329
}
1301-
if ((flags & FLAG_ABSTRACT) != 0) {
1302-
tokens.add(ABSTRACT);
1330+
if ((flags & FLAG_TRANSIENT) != 0) {
1331+
tokens.add(TRANSIENT);
1332+
tokens.add(TextToken.SPACE);
1333+
}
1334+
if ((flags & FLAG_SYNTHETIC) != 0) {
1335+
tokens.add(StartMarkerToken.COMMENT);
1336+
tokens.add(COMMENT_SYNTHETIC);
1337+
tokens.add(EndMarkerToken.COMMENT);
1338+
tokens.add(TextToken.SPACE);
1339+
}
1340+
}
1341+
1342+
protected void buildTokensForMethodAccessFlags(int flags) {
1343+
if ((flags & FLAG_PUBLIC) != 0) {
1344+
tokens.add(PUBLIC);
1345+
tokens.add(TextToken.SPACE);
1346+
}
1347+
if ((flags & FLAG_PROTECTED) != 0) {
1348+
tokens.add(PROTECTED);
1349+
tokens.add(TextToken.SPACE);
1350+
}
1351+
if ((flags & FLAG_PRIVATE) != 0) {
1352+
tokens.add(PRIVATE);
1353+
tokens.add(TextToken.SPACE);
1354+
}
1355+
if ((flags & FLAG_STATIC) != 0) {
1356+
tokens.add(STATIC);
1357+
tokens.add(TextToken.SPACE);
1358+
}
1359+
if ((flags & FLAG_FINAL) != 0) {
1360+
tokens.add(FINAL);
1361+
tokens.add(TextToken.SPACE);
1362+
}
1363+
if ((flags & FLAG_SYNCHRONIZED) != 0) {
1364+
tokens.add(SYNCHRONIZED);
13031365
tokens.add(TextToken.SPACE);
13041366
}
13051367
if ((flags & FLAG_BRIDGE) != 0) {
@@ -1308,12 +1370,28 @@ protected void buildTokensForAccessFlags(int flags) {
13081370
tokens.add(EndMarkerToken.COMMENT);
13091371
tokens.add(TextToken.SPACE);
13101372
}
1373+
if ((flags & FLAG_NATIVE) != 0) {
1374+
tokens.add(NATIVE);
1375+
tokens.add(TextToken.SPACE);
1376+
}
1377+
if ((flags & FLAG_ABSTRACT) != 0) {
1378+
tokens.add(ABSTRACT);
1379+
tokens.add(TextToken.SPACE);
1380+
}
1381+
if ((flags & FLAG_STRICT) != 0) {
1382+
tokens.add(STRICT);
1383+
tokens.add(TextToken.SPACE);
1384+
}
13111385
if ((flags & FLAG_SYNTHETIC) != 0) {
13121386
tokens.add(StartMarkerToken.COMMENT);
13131387
tokens.add(COMMENT_SYNTHETIC);
13141388
tokens.add(EndMarkerToken.COMMENT);
13151389
tokens.add(TextToken.SPACE);
13161390
}
1391+
if ((flags & FLAG_DEFAULT) != 0) {
1392+
tokens.add(DEFAULT);
1393+
tokens.add(TextToken.SPACE);
1394+
}
13171395
}
13181396

13191397
protected class AnnotationVisitor extends AbstractJavaSyntaxVisitor {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ public class StatementVisitor extends ExpressionVisitor {
3737
public static final KeywordToken FOR = new KeywordToken("for");
3838
public static final KeywordToken IF = new KeywordToken("if");
3939
public static final KeywordToken RETURN = new KeywordToken("return");
40+
public static final KeywordToken STRICT = new KeywordToken("strictfp");
4041
public static final KeywordToken SYNCHRONIZED = new KeywordToken("synchronized");
4142
public static final KeywordToken SWITCH = new KeywordToken("switch");
4243
public static final KeywordToken THROW = new KeywordToken("throw");
44+
public static final KeywordToken TRANSIENT = new KeywordToken("transient");
4345
public static final KeywordToken TRY = new KeywordToken("try");
46+
public static final KeywordToken VOLATILE = new KeywordToken("volatile");
4447
public static final KeywordToken WHILE = new KeywordToken("while");
4548

4649
public StatementVisitor(Loader loader, String mainInternalTypeName, int majorVersion, ImportsFragment importsFragment) {

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

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.junit.Test;
2525

2626
import java.io.InputStream;
27+
import java.util.Arrays;
2728
import java.util.Collections;
2829
import java.util.HashMap;
2930
import java.util.Map;
@@ -1117,8 +1118,11 @@ public void testJdk150AnonymousClass() throws Exception {
11171118
assertTrue(source.indexOf("// Byte code:") == -1);
11181119

11191120
// Recompile decompiled source code and check errors
1120-
assertTrue(CompilerUtil.compile("1.5", new JavaSourceFileObject(internalClassName, source),
1121-
new JavaSourceFileObject("org/jd/core/test/annotation/Name", "package org.jd.core.test.annotation; public @interface Name {String value();}")));
1121+
assertTrue(CompilerUtil.compile(
1122+
"1.5",
1123+
new JavaSourceFileObject(internalClassName, source),
1124+
new JavaSourceFileObject("org/jd/core/test/annotation/Name", "package org.jd.core.test.annotation; public @interface Name {String value();}")
1125+
));
11221126
}
11231127

11241128
@Test
@@ -1587,6 +1591,8 @@ public void testEclipseJavaCompiler321TryCatchFinally() throws Exception {
15871591

15881592
assertTrue(source.matches(PatternMaker.make(": 166 */", "return System.currentTimeMillis();")));
15891593

1594+
// TODO assertTrue(source.matches(PatternMaker.make("/* 217:", "inCatch1();")));
1595+
15901596
assertTrue(source.indexOf("/* 888: 888 */") != -1);
15911597

15921598
assertTrue(source.indexOf("long l = System.currentTimeMillis(); return l;") == -1);
@@ -1599,6 +1605,9 @@ public void testEclipseJavaCompiler321TryCatchFinally() throws Exception {
15991605

16001606
// Recompile decompiled source code and check errors
16011607
assertTrue(CompilerUtil.compile("1.5", new JavaSourceFileObject(internalClassName, source)));
1608+
1609+
System.out.println(ClassFileToJavaSourceTest.class.getProtectionDomain().getCodeSource().getLocation().getPath());
1610+
System.out.println(System.getProperty("java.class.path"));
16021611
}
16031612

16041613
@Test
@@ -1943,11 +1952,14 @@ public void testJdk170AnnotatedClass() throws Exception {
19431952
assertTrue(source.indexOf("// Byte code:") == -1);
19441953

19451954
// Recompile decompiled source code and check errors
1946-
assertTrue(CompilerUtil.compile("1.7", new JavaSourceFileObject(internalClassName, source),
1955+
assertTrue(CompilerUtil.compile(
1956+
"1.7",
1957+
new JavaSourceFileObject(internalClassName, source),
19471958
new JavaSourceFileObject("org/jd/core/test/annotation/Author", "package org.jd.core.test.annotation; public @interface Author {Name value(); Name[] contributors() default {};}"),
19481959
new JavaSourceFileObject("org/jd/core/test/annotation/Name", "package org.jd.core.test.annotation; public @interface Name {String salutation() default \"\"; String value(); String last() default \"\";}"),
19491960
new JavaSourceFileObject("org/jd/core/test/annotation/Quality", "package org.jd.core.test.annotation; public @interface Quality {enum Level {LOW,MIDDLE,HIGH}; Level value();}"),
1950-
new JavaSourceFileObject("org/jd/core/test/annotation/Value", "package org.jd.core.test.annotation; public @interface Value {boolean z() default true; byte b() default 1; short s() default 1; int i() default 1; long l() default 1L; float f() default 1.0F; double d() default 1.0D; String str() default \"str\"; Class clazz() default Object.class;}")));
1961+
new JavaSourceFileObject("org/jd/core/test/annotation/Value", "package org.jd.core.test.annotation; public @interface Value {boolean z() default true; byte b() default 1; short s() default 1; int i() default 1; long l() default 1L; float f() default 1.0F; double d() default 1.0D; String str() default \"str\"; Class clazz() default Object.class;}")
1962+
));
19511963
}
19521964

19531965
@Test
@@ -2003,8 +2015,11 @@ public void testJdk170AnonymousClass() throws Exception {
20032015
assertTrue(source.indexOf("// Byte code:") == -1);
20042016

20052017
// Recompile decompiled source code and check errors
2006-
assertTrue(CompilerUtil.compile("1.7", new JavaSourceFileObject(internalClassName, source),
2007-
new JavaSourceFileObject("org/jd/core/test/annotation/Name", "package org.jd.core.test.annotation; public @interface Name {String value();}")));
2018+
assertTrue(CompilerUtil.compile(
2019+
"1.7",
2020+
new JavaSourceFileObject(internalClassName, source),
2021+
new JavaSourceFileObject("org/jd/core/test/annotation/Name", "package org.jd.core.test.annotation; public @interface Name {String value();}")
2022+
));
20082023
}
20092024

20102025
@Test
@@ -2054,8 +2069,11 @@ public void testJdk170GenericClass() throws Exception {
20542069
assertTrue(source.indexOf("// Byte code:") == -1);
20552070

20562071
// Recompile decompiled source code and check errors
2057-
assertTrue(CompilerUtil.compile("1.7", new JavaSourceFileObject(internalClassName, source),
2058-
new JavaSourceFileObject("org/jd/core/test/AnnotatedClass", "package org.jd.core.test; public class AnnotatedClass {}")));
2072+
assertTrue(CompilerUtil.compile(
2073+
"1.7",
2074+
new JavaSourceFileObject(internalClassName, source),
2075+
new JavaSourceFileObject("org/jd/core/test/AnnotatedClass", "package org.jd.core.test; public class AnnotatedClass {}")
2076+
));
20592077
}
20602078

20612079
@Test
@@ -2090,8 +2108,11 @@ public void testJdk170AnnotationAuthor() throws Exception {
20902108
assertTrue(source.indexOf("// Byte code:") == -1);
20912109

20922110
// Recompile decompiled source code and check errors
2093-
assertTrue(CompilerUtil.compile("1.7", new JavaSourceFileObject(internalClassName, source),
2094-
new JavaSourceFileObject("org/jd/core/test/annotation/Name", "package org.jd.core.test.annotation; public @interface Name {String value();}")));
2111+
assertTrue(CompilerUtil.compile(
2112+
"1.7",
2113+
new JavaSourceFileObject(internalClassName, source),
2114+
new JavaSourceFileObject("org/jd/core/test/annotation/Name", "package org.jd.core.test.annotation; public @interface Name {String value();}")
2115+
));
20952116
}
20962117

20972118
@Test

0 commit comments

Comments
 (0)