System.out.println("> Decorating " + file.getCanonicalPath() + "..."); | System.out.println("> Decorating " + file.getCanonicalPath() + "..."); | ||||
BufferedReader reader = new BufferedReader(new FileReader(file)); | BufferedReader reader = new BufferedReader(new FileReader(file)); | ||||
StringBuffer fileContents = new StringBuffer(); | |||||
StringBuilder fileContents = new StringBuilder(); | |||||
String line = reader.readLine(); | String line = reader.readLine(); | ||||
while (line != null) { | while (line != null) { | ||||
fileContents.append(line + "\n"); | fileContents.append(line + "\n"); | ||||
fos.close(); | fos.close(); | ||||
} | } | ||||
static void addAspectDocumentation(IProgramElement node, StringBuffer fileBuffer, int index) { | |||||
static void addAspectDocumentation(IProgramElement node, StringBuilder fileBuffer, int index) { | |||||
List<IProgramElement> pointcuts = new ArrayList<>(); | List<IProgramElement> pointcuts = new ArrayList<>(); | ||||
List<IProgramElement> advice = new ArrayList<>(); | List<IProgramElement> advice = new ArrayList<>(); | ||||
List<IProgramElement> declares = new ArrayList<>(); | List<IProgramElement> declares = new ArrayList<>(); | ||||
} | } | ||||
} | } | ||||
static void insertDeclarationsSummary(StringBuffer fileBuffer, List decls, String kind, int index) { | |||||
static void insertDeclarationsSummary(StringBuilder fileBuffer, List decls, String kind, int index) { | |||||
if (!declsAboveVisibilityExist(decls)) | if (!declsAboveVisibilityExist(decls)) | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
static void insertDeclarationsDetails(StringBuffer fileBuffer, List decls, String kind, int index) { | |||||
static void insertDeclarationsDetails(StringBuilder fileBuffer, List decls, String kind, int index) { | |||||
if (!declsAboveVisibilityExist(decls)) | if (!declsAboveVisibilityExist(decls)) | ||||
return; | return; | ||||
int insertIndex = findDetailsIndex(fileBuffer, index); | int insertIndex = findDetailsIndex(fileBuffer, index); | ||||
/** | /** | ||||
* TODO: don't place the summary first. | * TODO: don't place the summary first. | ||||
*/ | */ | ||||
static int findSummaryIndex(StringBuffer fileBuffer, int index) { | |||||
static int findSummaryIndex(StringBuilder fileBuffer, int index) { | |||||
String fbs = fileBuffer.toString(); | String fbs = fileBuffer.toString(); | ||||
String MARKER_1 = "<!-- =========== FIELD SUMMARY =========== -->"; | String MARKER_1 = "<!-- =========== FIELD SUMMARY =========== -->"; | ||||
String MARKER_2 = "<!-- ======== CONSTRUCTOR SUMMARY ======== -->"; | String MARKER_2 = "<!-- ======== CONSTRUCTOR SUMMARY ======== -->"; | ||||
} | } | ||||
} | } | ||||
static int findDetailsIndex(StringBuffer fileBuffer, int index) { | |||||
static int findDetailsIndex(StringBuilder fileBuffer, int index) { | |||||
String fbs = fileBuffer.toString(); | String fbs = fileBuffer.toString(); | ||||
String MARKER_1 = "<!-- ========= CONSTRUCTOR DETAIL ======== -->"; | String MARKER_1 = "<!-- ========= CONSTRUCTOR DETAIL ======== -->"; | ||||
String MARKER_2 = "<!-- ============ FIELD DETAIL =========== -->"; | String MARKER_2 = "<!-- ============ FIELD DETAIL =========== -->"; | ||||
} | } | ||||
} | } | ||||
static void decorateDocWithRel(IProgramElement node, StringBuffer fileContentsBuffer, int index, List targets, | |||||
static void decorateDocWithRel(IProgramElement node, StringBuilder fileContentsBuffer, int index, List targets, | |||||
HtmlRelationshipKind relKind) { | HtmlRelationshipKind relKind) { | ||||
if (targets != null && !targets.isEmpty()) { | if (targets != null && !targets.isEmpty()) { | ||||
String adviceDoc = "<TABLE WIDTH=\"100%\" BGCOLOR=#FFFFFF><TR>" | String adviceDoc = "<TABLE WIDTH=\"100%\" BGCOLOR=#FFFFFF><TR>" | ||||
} | } | ||||
} | } | ||||
static void decorateMemberDocumentation(IProgramElement node, StringBuffer fileContentsBuffer, int index) { | |||||
static void decorateMemberDocumentation(IProgramElement node, StringBuilder fileContentsBuffer, int index) { | |||||
List<String> targets = StructureUtil.getTargets(node, IRelationship.Kind.ADVICE); | List<String> targets = StructureUtil.getTargets(node, IRelationship.Kind.ADVICE); | ||||
decorateDocWithRel(node, fileContentsBuffer, index, targets, HtmlRelationshipKind.ADVISED_BY); | decorateDocWithRel(node, fileContentsBuffer, index, targets, HtmlRelationshipKind.ADVISED_BY); | ||||
return ch == 'T' || ch == 'L'; | return ch == 'T' || ch == 'L'; | ||||
} | } | ||||
private static final void matchIdent(MyByteArrayInputStream in, StringBuffer buf) { | |||||
private static final void matchIdent(MyByteArrayInputStream in, StringBuilder buf) { | |||||
int ch; | int ch; | ||||
if ((ch = in.read()) == -1) | if ((ch = in.read()) == -1) | ||||
in.unread(); | in.unread(); | ||||
} | } | ||||
private static final void matchGJIdent(MyByteArrayInputStream in, StringBuffer buf) { | |||||
private static final void matchGJIdent(MyByteArrayInputStream in, StringBuilder buf) { | |||||
int ch; | int ch; | ||||
matchIdent(in, buf); | matchIdent(in, buf); | ||||
public static String translate(String s) { | public static String translate(String s) { | ||||
// System.out.println("Sig:" + s); | // System.out.println("Sig:" + s); | ||||
StringBuffer buf = new StringBuffer(); | |||||
StringBuilder buf = new StringBuilder(); | |||||
matchGJIdent(new MyByteArrayInputStream(s), buf); | matchGJIdent(new MyByteArrayInputStream(s), buf); | ||||
// These routines call BCEL to determine if it can correctly translate from one form to the other. | // These routines call BCEL to determine if it can correctly translate from one form to the other. | ||||
private void checkClassTypeSignature(String sig, String expected) { | private void checkClassTypeSignature(String sig, String expected) { | ||||
StringBuffer result = new StringBuffer(); | |||||
StringBuilder result = new StringBuilder(); | |||||
int p = GenericSignatureParsingTest.readClassTypeSignatureFrom(sig,0,result,false); | int p = GenericSignatureParsingTest.readClassTypeSignatureFrom(sig,0,result,false); | ||||
assertTrue("Only swallowed "+p+" chars of this sig "+sig+" (len="+sig.length()+")",p==sig.length()); | assertTrue("Only swallowed "+p+" chars of this sig "+sig+" (len="+sig.length()+")",p==sig.length()); | ||||
assertTrue("Expected '"+expected+"' but got '"+result.toString()+"'",result.toString().equals(expected)); | assertTrue("Expected '"+expected+"' but got '"+result.toString()+"'",result.toString().equals(expected)); | ||||
* | * | ||||
* FIXME asc this should also create some kind of object you can query for information about whether its parameterized, what the bounds are, etc... | * FIXME asc this should also create some kind of object you can query for information about whether its parameterized, what the bounds are, etc... | ||||
*/ | */ | ||||
public static final int readClassTypeSignatureFrom(String signature, int posn, StringBuffer result, boolean chopit) { | |||||
public static final int readClassTypeSignatureFrom(String signature, int posn, StringBuilder result, boolean chopit) { | |||||
int idx = posn; | int idx = posn; | ||||
try { | try { | ||||
switch (signature.charAt(idx)) { | switch (signature.charAt(idx)) { | ||||
public static final String readClassTypeSignatureFrom(String signature) { | public static final String readClassTypeSignatureFrom(String signature) { | ||||
StringBuffer sb = new StringBuffer(); | |||||
StringBuilder sb = new StringBuilder(); | |||||
GenericSignatureParsingTest.readClassTypeSignatureFrom(signature,0,sb,false); | GenericSignatureParsingTest.readClassTypeSignatureFrom(signature,0,sb,false); | ||||
return sb.toString(); | return sb.toString(); | ||||
} | } |
private String handleSigForReference(TypeReference ref, TypeBinding tb, MethodScope scope) { | private String handleSigForReference(TypeReference ref, TypeBinding tb, MethodScope scope) { | ||||
try { | try { | ||||
StringBuffer sb = new StringBuffer(); | |||||
StringBuilder sb = new StringBuilder(); | |||||
createHandleSigForReference(ref, tb, scope, sb); | createHandleSigForReference(ref, tb, scope, sb); | ||||
return sb.toString(); | return sb.toString(); | ||||
} catch (Throwable t) { | } catch (Throwable t) { | ||||
* handle. Whether a type is qualified or unqualified in its source reference is actually reflected in the handle and this code | * handle. Whether a type is qualified or unqualified in its source reference is actually reflected in the handle and this code | ||||
* allows for that. | * allows for that. | ||||
*/ | */ | ||||
private void createHandleSigForReference(TypeReference ref, TypeBinding tb, MethodScope scope, StringBuffer handleSig) { | |||||
private void createHandleSigForReference(TypeReference ref, TypeBinding tb, MethodScope scope, StringBuilder handleSig) { | |||||
if (ref instanceof Wildcard) { | if (ref instanceof Wildcard) { | ||||
Wildcard w = (Wildcard) ref; | Wildcard w = (Wildcard) ref; | ||||
if (w.bound == null) { | if (w.bound == null) { |
* append nothing if numItems is 0, numItems + label + (numItems > 1? "s" : "") otherwise, prefixing with " " if sink has | * append nothing if numItems is 0, numItems + label + (numItems > 1? "s" : "") otherwise, prefixing with " " if sink has | ||||
* content | * content | ||||
*/ | */ | ||||
private static void appendNLabel(StringBuffer sink, String label, int numItems) { | |||||
private static void appendNLabel(StringBuilder sink, String label, int numItems) { | |||||
if (0 == numItems) { | if (0 == numItems) { | ||||
return; | return; | ||||
} | } | ||||
if (holder == ourHandler) { | if (holder == ourHandler) { | ||||
lastErrors = holder.numMessages(IMessage.ERROR, false); | lastErrors = holder.numMessages(IMessage.ERROR, false); | ||||
int warnings = holder.numMessages(IMessage.WARNING, false); | int warnings = holder.numMessages(IMessage.WARNING, false); | ||||
StringBuffer sb = new StringBuffer(); | |||||
StringBuilder sb = new StringBuilder(); | |||||
appendNLabel(sb, "fail|abort", lastFails); | appendNLabel(sb, "fail|abort", lastFails); | ||||
appendNLabel(sb, "error", lastErrors); | appendNLabel(sb, "error", lastErrors); | ||||
appendNLabel(sb, "warning", warnings); | appendNLabel(sb, "warning", warnings); |
private static void createCSV() { | private static void createCSV() { | ||||
String NL = System.getProperty("line.separator", "\n"); | String NL = System.getProperty("line.separator", "\n"); | ||||
StringBuffer csv = new StringBuffer(1000); | |||||
StringBuilder csv = new StringBuilder(1000); | |||||
csv.append("Test Results"); | csv.append("Test Results"); | ||||
return (getVMInfo() + "_" + getDateAndTime()).replace('.', '_') + ".csv"; | return (getVMInfo() + "_" + getDateAndTime()).replace('.', '_') + ".csv"; | ||||
} | } | ||||
private static StringBuffer getDateAndTime() { | |||||
private static StringBuilder getDateAndTime() { | |||||
Calendar c = Calendar.getInstance(); | Calendar c = Calendar.getInstance(); | ||||
StringBuffer sb = new StringBuffer(15); | |||||
StringBuilder sb = new StringBuilder(15); | |||||
sb.append(c.get(Calendar.YEAR)); | sb.append(c.get(Calendar.YEAR)); | ||||
int month = (c.get(Calendar.MONTH)) + 1; | int month = (c.get(Calendar.MONTH)) + 1; | ||||
if(month < 10) sb.append(0); | if(month < 10) sb.append(0); | ||||
return sb; | return sb; | ||||
} | } | ||||
private static StringBuffer getVMInfo() { | |||||
StringBuffer sb = new StringBuffer(40); | |||||
private static StringBuilder getVMInfo() { | |||||
StringBuilder sb = new StringBuilder(40); | |||||
String vm = System.getProperty("java.vm.vendor"); | String vm = System.getProperty("java.vm.vendor"); | ||||
throw new Error("did not get definitions"); | throw new Error("did not get definitions"); | ||||
} | } | ||||
MessageHandler compilerMessages = new MessageHandler(); | MessageHandler compilerMessages = new MessageHandler(); | ||||
StringBuffer commandLine = new StringBuffer(); | |||||
StringBuilder commandLine = new StringBuilder(); | |||||
for (int i = 1; result && (i < 10); i++) { | for (int i = 1; result && (i < 10); i++) { | ||||
String fromSuffix = "." + i + "0.java"; | String fromSuffix = "." + i + "0.java"; | ||||
// copy files, collecting as we go... | // copy files, collecting as we go... | ||||
File sandboxClassesDir, | File sandboxClassesDir, | ||||
Definition def, | Definition def, | ||||
IMessageHolder compilerMessages, | IMessageHolder compilerMessages, | ||||
StringBuffer commandLine, | |||||
StringBuilder commandLine, | |||||
IMessageHandler handler) { | IMessageHandler handler) { | ||||
log("verifyCompile - iteration ", iteration, handler); | log("verifyCompile - iteration ", iteration, handler); | ||||
log("verifyCompile - def ", def, handler); | log("verifyCompile - def ", def, handler); |
boolean infosEmpty = expected.isIgnoringInfoMessages() || missingInfos.isEmpty() && extraInfos.isEmpty(); | boolean infosEmpty = expected.isIgnoringInfoMessages() || missingInfos.isEmpty() && extraInfos.isEmpty(); | ||||
if (!(missingFails.isEmpty() && missingWarnings.isEmpty() && missingErrors.isEmpty() && missingWeaves.isEmpty() | if (!(missingFails.isEmpty() && missingWarnings.isEmpty() && missingErrors.isEmpty() && missingWeaves.isEmpty() | ||||
&& extraFails.isEmpty() && extraWarnings.isEmpty() && extraErrors.isEmpty() && extraWeaves.isEmpty() && infosEmpty)) { | && extraFails.isEmpty() && extraWarnings.isEmpty() && extraErrors.isEmpty() && extraWeaves.isEmpty() && infosEmpty)) { | ||||
StringBuffer failureReport = new StringBuffer(assertionFailedMessage); | |||||
StringBuilder failureReport = new StringBuilder(assertionFailedMessage); | |||||
failureReport.append("\n"); | failureReport.append("\n"); | ||||
if (!expected.isIgnoringInfoMessages()) { | if (!expected.isIgnoringInfoMessages()) { | ||||
addMissing(failureReport, "info", missingInfos); | addMissing(failureReport, "info", missingInfos); | ||||
} | } | ||||
} | } | ||||
lastRunResult = null; | lastRunResult = null; | ||||
StringBuffer cp = new StringBuffer(); | |||||
StringBuilder cp = new StringBuilder(); | |||||
if (classpath != null) { | if (classpath != null) { | ||||
// allow replacing this special variable, rather than copying all files to allow tests of jars that don't end in .jar | // allow replacing this special variable, rather than copying all files to allow tests of jars that don't end in .jar | ||||
cp.append(substituteSandbox(classpath)); | cp.append(substituteSandbox(classpath)); | ||||
cp.append(ajc.getSandboxDirectory().getAbsolutePath()); | cp.append(ajc.getSandboxDirectory().getAbsolutePath()); | ||||
getAnyJars(ajc.getSandboxDirectory(), cp); | getAnyJars(ajc.getSandboxDirectory(), cp); | ||||
} | } | ||||
StringBuffer mp = new StringBuffer(); | |||||
StringBuilder mp = new StringBuilder(); | |||||
if (modulepath != null) { | if (modulepath != null) { | ||||
mp.append(substituteSandbox(modulepath)); | mp.append(substituteSandbox(modulepath)); | ||||
mp.append(File.pathSeparator); | mp.append(File.pathSeparator); | ||||
} | } | ||||
} | } | ||||
private void addMissing(StringBuffer buff, String type, List<AjcTestCase.Message> messages) { | |||||
private void addMissing(StringBuilder buff, String type, List<AjcTestCase.Message> messages) { | |||||
if (!messages.isEmpty()) { | if (!messages.isEmpty()) { | ||||
buff.append("Missing expected "); | buff.append("Missing expected "); | ||||
buff.append(type); | buff.append(type); | ||||
} | } | ||||
} | } | ||||
private void addExtra(StringBuffer buff, String type, List messages) { | |||||
private void addExtra(StringBuilder buff, String type, List messages) { | |||||
if (!messages.isEmpty()) { | if (!messages.isEmpty()) { | ||||
buff.append("Unexpected "); | buff.append("Unexpected "); | ||||
buff.append(type); | buff.append(type); | ||||
} | } | ||||
// add any jars in the directory to the classpath | // add any jars in the directory to the classpath | ||||
private void getAnyJars(File dir, StringBuffer buff) { | |||||
private void getAnyJars(File dir, StringBuilder buff) { | |||||
File[] files = dir.listFiles(); | File[] files = dir.listFiles(); | ||||
for (File file : files) { | for (File file : files) { | ||||
if (file.getName().endsWith(".jar")) { | if (file.getName().endsWith(".jar")) { |
return new UnresolvedType(signature, signatureErasure, UnresolvedType.NONE); | return new UnresolvedType(signature, signatureErasure, UnresolvedType.NONE); | ||||
} else { | } else { | ||||
int endOfParams = locateMatchingEndAngleBracket(signature, startOfParams); | int endOfParams = locateMatchingEndAngleBracket(signature, startOfParams); | ||||
StringBuffer erasureSig = new StringBuffer(signature); | |||||
StringBuilder erasureSig = new StringBuilder(signature); | |||||
erasureSig.setCharAt(0, 'L'); | erasureSig.setCharAt(0, 'L'); | ||||
while (startOfParams != -1) { | while (startOfParams != -1) { | ||||
erasureSig.delete(startOfParams, endOfParams + 1); | erasureSig.delete(startOfParams, endOfParams + 1); | ||||
return new UnresolvedType(signature); | return new UnresolvedType(signature); | ||||
} else { | } else { | ||||
int endOfParams = locateMatchingEndAngleBracket(signature, leftAngleBracket); | int endOfParams = locateMatchingEndAngleBracket(signature, leftAngleBracket); | ||||
StringBuffer erasureSig = new StringBuffer(signature); | |||||
StringBuilder erasureSig = new StringBuilder(signature); | |||||
erasureSig.setCharAt(0, 'L'); | erasureSig.setCharAt(0, 'L'); | ||||
while (leftAngleBracket != -1) { | while (leftAngleBracket != -1) { | ||||
erasureSig.delete(leftAngleBracket, endOfParams + 1); | erasureSig.delete(leftAngleBracket, endOfParams + 1); | ||||
return idx; | return idx; | ||||
} | } | ||||
private static int locateFirstBracket(StringBuffer signature) { | |||||
private static int locateFirstBracket(StringBuilder signature) { | |||||
int idx = 0; | int idx = 0; | ||||
int max = signature.length(); | int max = signature.length(); | ||||
while (idx < max) { | while (idx < max) { |
private ClassTypeSignature parseClassTypeSignature() { | private ClassTypeSignature parseClassTypeSignature() { | ||||
SimpleClassTypeSignature outerType = null; | SimpleClassTypeSignature outerType = null; | ||||
SimpleClassTypeSignature[] nestedTypes = new SimpleClassTypeSignature[0]; | SimpleClassTypeSignature[] nestedTypes = new SimpleClassTypeSignature[0]; | ||||
StringBuffer ret = new StringBuffer(); | |||||
StringBuilder ret = new StringBuilder(); | |||||
String identifier = eatIdentifier(); | String identifier = eatIdentifier(); | ||||
ret.append(identifier); | ret.append(identifier); | ||||
while (maybeEat("/")) { | while (maybeEat("/")) { | ||||
* Helper method to digest nested types, slightly more complex than necessary to cope with some android related | * Helper method to digest nested types, slightly more complex than necessary to cope with some android related | ||||
* incorrect classes (see bug 406167) | * incorrect classes (see bug 406167) | ||||
*/ | */ | ||||
private SimpleClassTypeSignature[] parseNestedTypesHelper(StringBuffer ret) { | |||||
private SimpleClassTypeSignature[] parseNestedTypesHelper(StringBuilder ret) { | |||||
boolean brokenSignature = false; | boolean brokenSignature = false; | ||||
SimpleClassTypeSignature[] nestedTypes; | SimpleClassTypeSignature[] nestedTypes; | ||||
List<SimpleClassTypeSignature> nestedTypeList = new ArrayList<>(); | List<SimpleClassTypeSignature> nestedTypeList = new ArrayList<>(); |
@Override | @Override | ||||
public String toString() { | public String toString() { | ||||
StringBuffer sb = new StringBuffer(); | |||||
StringBuilder sb = new StringBuilder(); | |||||
append(sb, fromProcess, "process"); | append(sb, fromProcess, "process"); | ||||
append(sb, fromOutPipe, " stdout"); | append(sb, fromOutPipe, " stdout"); | ||||
append(sb, fromErrPipe, " stderr"); | append(sb, fromErrPipe, " stderr"); | ||||
} | } | ||||
} | } | ||||
private void append(StringBuffer sb, Throwable thrown, String label) { | |||||
private void append(StringBuilder sb, Throwable thrown, String label) { | |||||
if (null != thrown) { | if (null != thrown) { | ||||
sb.append("from " + label + ": "); | sb.append("from " + label + ": "); | ||||
sb.append(LangUtil.renderExceptionShort(thrown)); | sb.append(LangUtil.renderExceptionShort(thrown)); |