77
88package org .jd .core .v1 ;
99
10- import junit .framework .TestCase ;
1110import org .jd .core .v1 .api .loader .Loader ;
12- import org .jd .core .v1 .api .printer .Printer ;
1311import org .jd .core .v1 .compiler .CompilerUtil ;
1412import org .jd .core .v1 .compiler .JavaSourceFileObject ;
1513import org .jd .core .v1 .loader .ZipLoader ;
16- import org .jd .core .v1 .model .classfile .ClassFile ;
17- import org .jd .core .v1 .model .message .DecompileContext ;
1814import org .jd .core .v1 .printer .PlainTextPrinter ;
1915import org .jd .core .v1 .regex .PatternMaker ;
20- import org .jd .core .v1 .service .converter .classfiletojavasyntax .ClassFileToJavaSyntaxProcessor ;
21- import org .jd .core .v1 .service .deserializer .classfile .ClassFileDeserializer ;
22- import org .jd .core .v1 .service .fragmenter .javasyntaxtojavafragment .JavaSyntaxToJavaFragmentProcessor ;
23- import org .jd .core .v1 .service .layouter .LayoutFragmentProcessor ;
24- import org .jd .core .v1 .service .tokenizer .javafragmenttotoken .JavaFragmentToTokenProcessor ;
25- import org .jd .core .v1 .service .writer .WriteTokenProcessor ;
2616import org .junit .Test ;
2717
2818import java .io .InputStream ;
29- import java .util .Collections ;
30- import java .util .Map ;
31-
32- public class JavaAnnotationTest extends TestCase {
33- protected ClassFileDeserializer deserializer = new ClassFileDeserializer ();
34- protected ClassFileToJavaSyntaxProcessor converter = new ClassFileToJavaSyntaxProcessor ();
35- protected JavaSyntaxToJavaFragmentProcessor fragmenter = new JavaSyntaxToJavaFragmentProcessor ();
36- protected LayoutFragmentProcessor layouter = new LayoutFragmentProcessor ();
37- //protected TestTokenizeJavaFragmentProcessor tokenizer = new TestTokenizeJavaFragmentProcessor();
38- protected JavaFragmentToTokenProcessor tokenizer = new JavaFragmentToTokenProcessor ();
39- protected WriteTokenProcessor writer = new WriteTokenProcessor ();
4019
20+ public class JavaAnnotationTest extends AbstractJdTest {
4121 @ Test
4222 public void testJdk170AnnotatedClass () throws Exception {
4323 String internalClassName = "org/jd/core/test/AnnotatedClass" ;
4424 InputStream is = this .getClass ().getResourceAsStream ("/zip/data-java-jdk-1.7.0.zip" );
4525 Loader loader = new ZipLoader (is );
46- String source = decompile (loader , new PlainTextPrinter (), internalClassName );
26+ String source = decompileSuccess (loader , new PlainTextPrinter (), internalClassName );
4727
4828 // Check decompiled source code
4929 assertTrue (source .indexOf ("@Quality(Quality.Level.HIGH)" ) != -1 );
@@ -76,7 +56,7 @@ public void testJdk170AnnotationAuthor() throws Exception {
7656 String internalClassName = "org/jd/core/test/annotation/Author" ;
7757 InputStream is = this .getClass ().getResourceAsStream ("/zip/data-java-jdk-1.7.0.zip" );
7858 Loader loader = new ZipLoader (is );
79- String source = decompile (loader , new PlainTextPrinter (), internalClassName );
59+ String source = decompileSuccess (loader , new PlainTextPrinter (), internalClassName );
8060
8161 // Check decompiled source code
8262 assertTrue (source .matches (PatternMaker .make ("/* 3: 0 */" , "public @interface Author" )));
@@ -96,7 +76,7 @@ public void testJdk170AnnotationValue() throws Exception {
9676 String internalClassName = "org/jd/core/test/annotation/Value" ;
9777 InputStream is = this .getClass ().getResourceAsStream ("/zip/data-java-jdk-1.7.0.zip" );
9878 Loader loader = new ZipLoader (is );
99- String source = decompile (loader , new PlainTextPrinter (), internalClassName );
79+ String source = decompileSuccess (loader , new PlainTextPrinter (), internalClassName );
10080
10181 // Check decompiled source code
10282 assertTrue (source .matches (PatternMaker .make ("/* 8: 0 */" , "@Retention(RetentionPolicy.RUNTIME)" )));
@@ -110,39 +90,4 @@ public void testJdk170AnnotationValue() throws Exception {
11090 // Recompile decompiled source code and check errors
11191 assertTrue (CompilerUtil .compile ("1.7" , new JavaSourceFileObject (internalClassName , source )));
11292 }
113-
114- protected String decompile (Loader loader , Printer printer , String internalTypeName ) throws Exception {
115- return decompile (loader , printer , internalTypeName , Collections .emptyMap ());
116- }
117-
118- protected String decompile (Loader loader , Printer printer , String internalTypeName , Map <String , Object > configuration ) throws Exception {
119- DecompileContext decompileContext = new DecompileContext ();
120- decompileContext .setLoader (loader );
121- decompileContext .setPrinter (printer );
122- decompileContext .setMainInternalTypeName (internalTypeName );
123- decompileContext .setConfiguration (configuration );
124-
125- ClassFile classFile = deserializer .loadClassFile (loader , internalTypeName );
126- decompileContext .setBody (classFile );
127-
128- converter .process (decompileContext );
129- fragmenter .process (decompileContext );
130- layouter .process (decompileContext );
131- tokenizer .process (decompileContext );
132- writer .process (decompileContext );
133-
134- String source = printer .toString ();
135-
136- printSource (source );
137-
138- assertTrue (source .indexOf ("// Byte code:" ) == -1 );
139-
140- return source ;
141- }
142-
143- protected void printSource (String source ) {
144- System .out .println ("- - - - - - - - " );
145- System .out .println (source );
146- System .out .println ("- - - - - - - - " );
147- }
14893}
0 commit comments