@Override public Description matchNewClass(NewClassTree tree, VisitorState state) { if (ASTHelpers.isSameType( state.getSymtab().stringBuilderType, ASTHelpers.getType(tree.getIdentifier()), state) && tree.getArguments().size() == 1) { ExpressionTree argument = tree.getArguments().get(0); Type type = ((JCTree) argument).type; if (type.getKind() == TypeKind.CHAR) { if (argument.getKind() == Kind.CHAR_LITERAL) { char ch = (Character) ((LiteralTree) argument).getValue(); return describeMatch( tree, SuggestedFix.replace(argument, "\"" + Convert.quote(Character.toString(ch)) + "\"")); } else { return describeMatch( tree, SuggestedFix.replace( tree, "new StringBuilder().append(" + state.getSourceForNode((JCTree) argument) + ")")); } } } return Description.NO_MATCH; } }
/** Return all bytes of a given array in Utf8 representation * as an array of characters. * @param src The array holding the bytes. */ public static char[] utf2chars(byte[] src) { return utf2chars(src, 0, src.length); }
/** Return all characters in given array as an array of bytes * in Utf8 representation. * @param src The array holding the characters. */ public static byte[] chars2utf(char[] src) { return chars2utf(src, 0, src.length); }
/** Make a package, given its fully qualified name. */ public PackageSymbol enterPackage(Name fullname) { PackageSymbol p = packages.get(fullname); if (p == null) { assert !fullname.isEmpty() : "rootPackage missing!"; p = new PackageSymbol( Convert.shortName(fullname), enterPackage(Convert.packagePart(fullname))); p.completer = this; packages.put(fullname, p); } return p; }
/** * Tries to complete lexically enclosing classes if c looks like a * nested class. This is similar to completeOwners but handles * the situation when a nested class is accessed directly as it is * possible with the Tree API or javax.lang.model.*. */ private void completeEnclosing(ClassSymbol c) { if (c.owner.kind == PCK) { Symbol owner = c.owner; for (Name name : Convert.enclosingCandidates(Convert.shortName(c.name))) { Symbol encl = owner.members().lookup(name).sym; if (encl == null) encl = classes.get(TypeSymbol.formFlatName(name, owner)); if (encl != null) encl.complete(); } } }
t = F.at(pos).Literal( TypeTag.INT, Convert.string2int(strval(prefix), token.radix())); } catch (NumberFormatException ex) { error(token.pos, "int.number.too.large", strval(prefix)); t = F.at(pos).Literal( TypeTag.LONG, new Long(Convert.string2long(strval(prefix), token.radix()))); } catch (NumberFormatException ex) { error(token.pos, "int.number.too.large", strval(prefix));
tree.name = Convert.shortName(currentClass.flatName());
/** Print string, replacing all non-ascii character with unicode escapes. */ public void print(Object s) throws IOException { out.write(Convert.escapeUnicode(s.toString())); }
/** * Escapes a character if it has an escape sequence or is * non-printable ASCII. Leaves non-ASCII characters alone. */ public static String quote(char ch) { switch (ch) { case '\b': return "\\b"; case '\f': return "\\f"; case '\n': return "\\n"; case '\r': return "\\r"; case '\t': return "\\t"; case '\'': return "\\'"; case '\"': return "\\\""; case '\\': return "\\\\"; default: return (ch > 127 || isPrintableAscii(ch)) ? String.valueOf(ch) : String.format("\\%03o", (int) ch); } }
/** Make a package, given its fully qualified name. */ public PackageSymbol enterPackage(Name fullname) { PackageSymbol p = packages.get(fullname); if (p == null) { assert !fullname.isEmpty() : "rootPackage missing!"; p = new PackageSymbol( Convert.shortName(fullname), enterPackage(Convert.packagePart(fullname))); p.completer = this; packages.put(fullname, p); } return p; }
/** * Tries to complete lexically enclosing classes if c looks like a * nested class. This is similar to completeOwners but handles * the situation when a nested class is accessed directly as it is * possible with the Tree API or javax.lang.model.*. */ private void completeEnclosing(ClassSymbol c) { if (c.owner.kind == PCK) { Symbol owner = c.owner; for (Name name : Convert.enclosingCandidates(Convert.shortName(c.name))) { Symbol encl = owner.members().lookup(name).sym; if (encl == null) encl = classes.get(TypeSymbol.formFlatName(name, owner)); if (encl != null) encl.complete(); } } }
t = F.at(pos).Literal( TypeTag.INT, Convert.string2int(strval(prefix), token.radix())); } catch (NumberFormatException ex) { error(token.pos, "int.number.too.large", strval(prefix)); t = F.at(pos).Literal( TypeTag.LONG, new Long(Convert.string2long(strval(prefix), token.radix()))); } catch (NumberFormatException ex) { error(token.pos, "int.number.too.large", strval(prefix));
tree.name = Convert.shortName(currentClass.flatName());
/** Print string, replacing all non-ascii character with unicode escapes. */ public void print(Object s) throws IOException { out.write(Convert.escapeUnicode(s.toString())); }
/** * Escapes a character if it has an escape sequence or is * non-printable ASCII. Leaves non-ASCII characters alone. */ public static String quote(char ch) { switch (ch) { case '\b': return "\\b"; case '\f': return "\\f"; case '\n': return "\\n"; case '\r': return "\\r"; case '\t': return "\\t"; case '\'': return "\\'"; case '\"': return "\\\""; case '\\': return "\\\\"; default: return (isPrintableAscii(ch)) ? String.valueOf(ch) : String.format("\\u%04x", (int) ch); } }
private static String formatString(String s) { return '"' + Convert.quote(s) + '"'; } }
/** Make a package, given its fully qualified name. */ public PackageSymbol enterPackage(Name fullname) { PackageSymbol p = packages.get(fullname); if (p == null) { Assert.check(!fullname.isEmpty(), "rootPackage missing!"); p = new PackageSymbol( Convert.shortName(fullname), enterPackage(Convert.packagePart(fullname))); p.completer = thisCompleter; packages.put(fullname, p); } return p; }
/** Return all bytes of a given array in Utf8 representation * as an array of characters. * @param src The array holding the bytes. */ public static char[] utf2chars(byte[] src) { return utf2chars(src, 0, src.length); }
/** Return all characters in given array as an array of bytes * in Utf8 representation. * @param src The array holding the characters. */ public static byte[] chars2utf(char[] src) { return chars2utf(src, 0, src.length); }
/** * Tries to complete lexically enclosing classes if c looks like a * nested class. This is similar to completeOwners but handles * the situation when a nested class is accessed directly as it is * possible with the Tree API or javax.lang.model.*. */ private void completeEnclosing(ClassSymbol c) { if (c.owner.kind == PCK) { Symbol owner = c.owner; for (Name name : Convert.enclosingCandidates(Convert.shortName(c.name))) { Symbol encl = owner.members().lookup(name).sym; if (encl == null) encl = classes.get(TypeSymbol.formFlatName(name, owner)); if (encl != null) encl.complete(); } } }