| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.kuali.student.contract.writer; |
| 17 |
|
|
| 18 |
|
import java.io.ByteArrayOutputStream; |
| 19 |
|
import java.io.File; |
| 20 |
|
import java.io.FileNotFoundException; |
| 21 |
|
import java.io.FileOutputStream; |
| 22 |
|
import java.io.PrintStream; |
| 23 |
|
import java.util.Set; |
| 24 |
|
import java.util.TreeSet; |
| 25 |
|
import java.util.regex.Matcher; |
| 26 |
|
import java.util.regex.Pattern; |
| 27 |
|
|
| 28 |
|
import org.kuali.student.contract.exception.DictionaryExecutionException; |
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
@author |
| 33 |
|
|
|
|
|
| 0% |
Uncovered Elements: 94 (94) |
Complexity: 22 |
Complexity Density: 0.33 |
|
| 34 |
|
public abstract class JavaClassWriter extends XmlWriter { |
| 35 |
|
|
| 36 |
|
private String rootDirectory; |
| 37 |
|
private String packageName; |
| 38 |
|
private String className; |
| 39 |
|
private String fileName; |
| 40 |
|
private String directory; |
| 41 |
|
private ByteArrayOutputStream body; |
| 42 |
|
private Set<String> imports; |
| 43 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
| 44 |
0
|
public JavaClassWriter(String rootDirectory, String packageName,... |
| 45 |
|
String className) { |
| 46 |
0
|
super(); |
| 47 |
0
|
this.body = new ByteArrayOutputStream(1000); |
| 48 |
0
|
this.setOut(new PrintStream(body)); |
| 49 |
0
|
this.setIndent(0); |
| 50 |
0
|
this.rootDirectory = rootDirectory; |
| 51 |
|
|
| 52 |
0
|
this.packageName = packageName; |
| 53 |
0
|
this.className = className; |
| 54 |
0
|
this.fileName = |
| 55 |
|
new JavaClassFileNameBuilder(rootDirectory, packageName, className).build(); |
| 56 |
0
|
this.directory = |
| 57 |
|
new JavaClassFileNameBuilder(rootDirectory, packageName, className).buildDirectory(); |
| 58 |
0
|
this.imports = new TreeSet(); |
| 59 |
|
} |
| 60 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 61 |
0
|
public ByteArrayOutputStream getBody() {... |
| 62 |
0
|
return body; |
| 63 |
|
} |
| 64 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 65 |
0
|
public String getClassName() {... |
| 66 |
0
|
return className; |
| 67 |
|
} |
| 68 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 69 |
0
|
public String getDirectory() {... |
| 70 |
0
|
return directory; |
| 71 |
|
} |
| 72 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 73 |
0
|
public String getFileName() {... |
| 74 |
0
|
return fileName; |
| 75 |
|
} |
| 76 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 77 |
0
|
public String getPackageName() {... |
| 78 |
0
|
return packageName; |
| 79 |
|
} |
| 80 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 81 |
0
|
public String getRootDirectory() {... |
| 82 |
0
|
return rootDirectory; |
| 83 |
|
} |
| 84 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 85 |
0
|
public void importsAdd(String pack) {... |
| 86 |
0
|
this.imports.add(pack); |
| 87 |
|
} |
| 88 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
|
| 89 |
0
|
public void writeHeader() {... |
| 90 |
0
|
indentPrintln("/*"); |
| 91 |
0
|
indentPrintln(" * Copyright 2011 The Kuali Foundation"); |
| 92 |
0
|
indentPrintln(" *"); |
| 93 |
0
|
indentPrintln(" * Licensed under the Educational Community License, Version 2.0 (the \"License\");"); |
| 94 |
0
|
indentPrintln(" * you may not use this file except in compliance with the License."); |
| 95 |
0
|
indentPrintln(" * You may obtain a copy of the License at"); |
| 96 |
0
|
indentPrintln(" *"); |
| 97 |
0
|
indentPrintln(" * http://www.osedu.org/licenses/ECL-2.0"); |
| 98 |
0
|
indentPrintln(" *"); |
| 99 |
0
|
indentPrintln(" * Unless required by applicable law or agreed to in writing, software"); |
| 100 |
0
|
indentPrintln(" * distributed under the License is distributed on an \"AS IS\" BASIS,"); |
| 101 |
0
|
indentPrintln(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied."); |
| 102 |
0
|
indentPrintln(" * See the License for the specific language governing permissions and"); |
| 103 |
0
|
indentPrintln(" * limitations under the License."); |
| 104 |
0
|
indentPrintln(" */"); |
| 105 |
0
|
indentPrintln("package " + packageName + ";"); |
| 106 |
0
|
indentPrintln(""); |
| 107 |
|
} |
| 108 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 109 |
0
|
public void writeImports() {... |
| 110 |
0
|
if (imports.size() == 0) { |
| 111 |
0
|
return; |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
|
| 115 |
0
|
for (String imprt : imports) { |
| 116 |
|
|
| 117 |
0
|
if (imprt.startsWith(packageName)) { |
| 118 |
|
|
| 119 |
0
|
if (!imprt.substring(packageName.length() + 1).contains(".")) { |
| 120 |
0
|
continue; |
| 121 |
|
} |
| 122 |
|
} |
| 123 |
0
|
indentPrintln("import " + imprt + ";"); |
| 124 |
|
} |
| 125 |
0
|
indentPrintln(""); |
| 126 |
|
} |
| 127 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 4 |
Complexity Density: 0.31 |
|
| 128 |
0
|
public void writeJavaClassAndImportsOutToFile() {... |
| 129 |
|
|
| 130 |
0
|
File dir = new File(this.directory); |
| 131 |
|
|
| 132 |
|
|
| 133 |
0
|
if (!dir.exists()) { |
| 134 |
0
|
if (!dir.mkdirs()) { |
| 135 |
0
|
throw new DictionaryExecutionException("Could not create directory " |
| 136 |
|
+ this.directory); |
| 137 |
|
} |
| 138 |
|
} |
| 139 |
0
|
try { |
| 140 |
0
|
PrintStream out = new PrintStream(new FileOutputStream(fileName, false)); |
| 141 |
0
|
this.setOut(out); |
| 142 |
|
} catch (FileNotFoundException ex) { |
| 143 |
0
|
throw new DictionaryExecutionException(ex); |
| 144 |
|
} |
| 145 |
0
|
writeHeader(); |
| 146 |
0
|
indentPrintln(""); |
| 147 |
0
|
writeImports(); |
| 148 |
0
|
indentPrintln(""); |
| 149 |
0
|
indentPrintln(body.toString()); |
| 150 |
|
} |
| 151 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 152 |
0
|
public void openBrace() {... |
| 153 |
0
|
indentPrintln("{"); |
| 154 |
0
|
incrementIndent(); |
| 155 |
|
} |
| 156 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 157 |
0
|
public void closeBrace() {... |
| 158 |
0
|
decrementIndent(); |
| 159 |
0
|
indentPrintln("}"); |
| 160 |
|
} |
| 161 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 162 |
0
|
public void indentPrintWrappedComment(String str) {... |
| 163 |
0
|
Pattern pattern = Pattern.compile(".{0,79}(?:\\S(?:-| |$)|$)"); |
| 164 |
0
|
Matcher m = pattern.matcher(str); |
| 165 |
0
|
while (m.find()) { |
| 166 |
|
|
| 167 |
0
|
if (m.group().equals("")) { |
| 168 |
0
|
continue; |
| 169 |
|
} |
| 170 |
0
|
indentPrint("* "); |
| 171 |
0
|
println(m.group()); |
| 172 |
|
} |
| 173 |
|
} |
| 174 |
|
} |