Skip to content

Package: ExceptionFileWriter

ExceptionFileWriter

nameinstructionbranchcomplexitylinemethod
ExceptionFileWriter(boolean)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getStringContent(GenClass)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
setAttributes(GenException, Context)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setOperations(GenException, Context)
M: 0 C: 30
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
setUpContext(GenException, Context)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
writeJavaExceptionClass(GenException, File)
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
writeJavaExceptionClassToString(GenException)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package de.fhdw.wtf.generator.writer.writer;
2:
3: import java.io.File;
4: import java.util.ArrayList;
5: import java.util.Collection;
6:
7: import org.apache.velocity.context.Context;
8:
9: import de.fhdw.wtf.generator.java.generatorModel.GenClass;
10: import de.fhdw.wtf.generator.java.generatorModel.GenException;
11: import de.fhdw.wtf.generator.java.generatorModel.GenJavaOperation;
12:
13: /**
14: * Generate {@link GenException} classes whilst transferring form java model to generated Java application.
15: */
16: public class ExceptionFileWriter extends ClassClassFileWriter {
17:         
18:         /**
19:          * Creates a new ExceptionFileWriter.
20:          *
21:          * @param fullyQualified
22:          * Boolean parameter. If value is {@code true}: Generate fully qualified name including package name for
23:          * Types. If value is {@code false} Generate simple name for Types without package name.
24:          */
25:         public ExceptionFileWriter(final boolean fullyQualified) {
26:                 super(TEMPLATE_FILE_NAME, fullyQualified);
27:         }
28:         
29:         private static final String TEMPLATE_FILE_NAME = "de/fhdw/wtf/generator/templates/modelclass.vm";
30:         
31:         private void setUpContext(final GenException exceptionClass, final Context currentContext) {
32:                 this.setAttributes(exceptionClass, currentContext);
33:                 this.setOperations(exceptionClass, currentContext);
34:         }
35:         
36:         private void setOperations(final GenException exceptionClass, final Context currentContext) {
37:                 currentContext.put(PARSED_OPERATIONS_KEY, this.getParsedOperations(exceptionClass.getOperations()));
38:                 final Collection<GenJavaOperation> operationsWithSimple = new ArrayList<>();
39:                 operationsWithSimple.addAll(exceptionClass.getOperations());
40:                 operationsWithSimple.addAll(exceptionClass.getConstructors());
41:                 currentContext.put(SIMPLE_OPERATIONS_KEY, this.getSimpleOperations(operationsWithSimple));
42:         }
43:         
44:         /**
45:          * Writes the file for the given {@link de.fhdw.wtf.generator.java.generatorModel.GenException}
46:          * {@code exceptionClass}.
47:          *
48:          * @param exceptionClass
49:          * Exception to write the file for
50:          */
51:         public void writeJavaExceptionClass(final GenException exceptionClass, final File rootdir) {
52:                 this.writeClassClass(exceptionClass);
53:                 this.setUpContext(exceptionClass, this.getCurrentContext());
54:                 this.writeToFile(exceptionClass, rootdir);
55:         }
56:         
57:         /**
58:          * Writes the given {@link GenException} exception to a String.
59:          *
60:          * @param exceptionClass
61:          * The class to write.
62:          * @return A String representation of the GenException in java-syntax.
63:          */
64:         public String writeJavaExceptionClassToString(final GenException exceptionClass) {
65:                 this.writeClassClass(exceptionClass);
66:                 this.setUpContext(exceptionClass, this.getCurrentContext());
67:                 return this.writeToString();
68:         }
69:         
70:         /**
71:          * Sets all values for the attribute declaration of {@link de.fhdw.wtf.generator.java.generatorModel.GenException}
72:          * {@code exceptionClass} to the {@link Context}.
73:          *
74:          * @param exceptionClass
75:          * @param currentContext
76:          */
77:         private void setAttributes(final GenException exceptionClass, final Context currentContext) {
78:                 currentContext.put(ATTRIBUTES_KEY, this.getAttributes(exceptionClass.getAttributes()));
79:         }
80:         
81:         @Override
82:         public String getStringContent(final GenClass clazz) {
83:                 final GenException clazzAsGenException = (GenException) clazz;
84:                 this.writeClassClass(clazzAsGenException);
85:                 this.setUpContext(clazzAsGenException, this.getCurrentContext());
86:                 return this.writeToString();
87:         }
88: }