package sds.decompile;

import sds.assemble.BaseContent;
import sds.assemble.BaseContent.AnnotationContent;
import sds.assemble.FieldContent;

/**
 * This class is for decompiling contents of field.
 * @author inagaki
 */
public class FieldDecompiler extends AbstractDecompiler {
	/**
	 * constructor.
	 * @param result decompiled source 
	 */
	public FieldDecompiler(DecompiledResult result) {
		super(result);
	}

	@Override
	public void decompile(BaseContent content) {
		FieldContent field = (FieldContent)content;
		AnnotationContent annotation = field.getAnnotation();
		if(annotation != null) {
			if(annotation.getAnnotations(true).length > 0) {
				for(String ann : annotation.getAnnotations(true)) {
					result.write(ann);
				}
			}
			if(annotation.getAnnotations(false).length > 0) {
				for(String ann : annotation.getAnnotations(false)) {
					result.write(ann);
				}
			}
		}
		StringBuilder fieldDeclaration = new StringBuilder();
		fieldDeclaration.append(field.getAccessFlag()).append(field.getDescriptor())
						.append(" ").append(field.getName());
		if(field.getConstVal() != null) {
			fieldDeclaration.append(" = ").append(field.getConstVal());
		}
		fieldDeclaration.append(";");
		result.write(fieldDeclaration.toString());
	}
}
@@ -334,10 +334,9 @@
 urce
- 
 %0A
+
 %09 */
@@ -517,27 +517,12 @@
 ;%0A%09%09
-AnnotationContent a
+addA
 nnot
@@ -526,19 +526,17 @@
 notation
- = 
+(
 field.ge
@@ -552,328 +552,140 @@
 on()
+)
 ;%0A%09%09
-if(annotation != null) %7B%0A%09%09%09if(annotation.getAnnotations(true).length %3E 0) %7B%0A%09%09%09%09for(String ann : annotation.getAnnotations(true)) %7B%0A%09%09%09%09%09result.write(ann);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09if(annotation.getAnnotations(false).length %3E 0) %7B%0A%09%09%09%09for(String ann : annotation.getAnnotations(false)) %7B%0A%09%09%09%09%09result.write(ann);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D
+addDeclaration(field);%0A%09%7D%0A%0A%09@Override%0A%09void addDeclaration(BaseContent content) %7B%0A%09%09FieldContent field = (FieldContent)content;
 %0A%09%09S

implement abstract methods.