本文整理汇总了Java中com.sun.tools.javac.code.Type.ArrayType类的典型用法代码示例。如果您正苦于以下问题:Java ArrayType类的具体用法?Java ArrayType怎么用?Java ArrayType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArrayType类属于com.sun.tools.javac.code.Type包,在下文中一共展示了ArrayType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printMethodArgs
import com.sun.tools.javac.code.Type.ArrayType; //导入依赖的package包/类
/**
* Converts a set of method argument types into their corresponding
* localized string representation.
*
* @param args arguments to be rendered
* @param varArgs if true, the last method argument is regarded as a vararg
* @param locale the locale in which the string is to be rendered
* @return localized string representation
*/
protected String printMethodArgs(List<Type> args, boolean varArgs, Locale locale) {
if (!varArgs) {
return visitTypes(args, locale);
} else {
StringBuffer buf = new StringBuffer();
while (args.tail.nonEmpty()) {
buf.append(visit(args.head, locale));
args = args.tail;
buf.append(',');
}
if (args.head.tag == ARRAY) {
buf.append(visit(((ArrayType) args.head).elemtype, locale));
buf.append("...");
} else {
buf.append(visit(args.head, locale));
}
return buf.toString();
}
}
示例2: getTypeName
import com.sun.tools.javac.code.Type.ArrayType; //导入依赖的package包/类
public static String getTypeName(Type t, boolean full) {
switch (t.getTag()) {
case ARRAY:
StringBuilder s = new StringBuilder();
while (t.hasTag(ARRAY)) {
s.append("[]");
t = ((ArrayType)t).elemtype;
}
s.insert(0, getTypeName(t, full));
return s.toString();
case CLASS:
return ClassDocImpl.getClassName((ClassSymbol)t.tsym, full);
default:
return t.tsym.getQualifiedName().toString();
}
}
示例3: printMethodArgs
import com.sun.tools.javac.code.Type.ArrayType; //导入依赖的package包/类
/**
* Converts a set of method argument types into their corresponding
* localized string representation.
*
* @param args arguments to be rendered
* @param varArgs if true, the last method argument is regarded as a vararg
* @param locale the locale in which the string is to be rendered
* @return localized string representation
*/
protected String printMethodArgs(List<Type> args, boolean varArgs, Locale locale) {
if (!varArgs) {
return visitTypes(args, locale);
} else {
StringBuilder buf = new StringBuilder();
while (args.tail.nonEmpty()) {
buf.append(visit(args.head, locale));
args = args.tail;
buf.append(',');
}
if (args.head.unannotatedType().hasTag(TypeTag.ARRAY)) {
buf.append(visit(((ArrayType) args.head.unannotatedType()).elemtype, locale));
if (args.head.getAnnotationMirrors().nonEmpty()) {
buf.append(' ');
buf.append(args.head.getAnnotationMirrors());
buf.append(' ');
}
buf.append("...");
} else {
buf.append(visit(args.head, locale));
}
return buf.toString();
}
}
示例4: printMethodArgs
import com.sun.tools.javac.code.Type.ArrayType; //导入依赖的package包/类
/**
* Converts a set of method argument types into their corresponding
* localized string representation.
*
* @param args arguments to be rendered
* @param varArgs if true, the last method argument is regarded as a vararg
* @param locale the locale in which the string is to be rendered
* @return localized string representation
*/
protected String printMethodArgs(List<Type> args, boolean varArgs, Locale locale) {
if (!varArgs) {
return visitTypes(args, locale);
} else {
StringBuilder buf = new StringBuilder();
while (args.tail.nonEmpty()) {
buf.append(visit(args.head, locale));
args = args.tail;
buf.append(',');
}
if (args.head.hasTag(TypeTag.ARRAY)) {
buf.append(visit(((ArrayType) args.head).elemtype, locale));
if (args.head.getAnnotationMirrors().nonEmpty()) {
buf.append(' ');
buf.append(args.head.getAnnotationMirrors());
buf.append(' ');
}
buf.append("...");
} else {
buf.append(visit(args.head, locale));
}
return buf.toString();
}
}
示例5: getType
import com.sun.tools.javac.code.Type.ArrayType; //导入依赖的package包/类
/** Build an instance of a Type. */
public Type getType(Type baseType, boolean isArray, List<Type> typeParams) {
boolean isGeneric = typeParams != null && !typeParams.isEmpty();
if (!isArray && !isGeneric) {
// Simple type.
return baseType;
} else if (isArray && !isGeneric) {
// Array type, not generic.
ClassSymbol arraySymbol = getSymtab().arrayClass;
return new ArrayType(baseType, arraySymbol);
} else if (!isArray && isGeneric) {
// Generic type, not array.
com.sun.tools.javac.util.List<Type> typeParamsCopy =
com.sun.tools.javac.util.List.from(typeParams);
return new ClassType(Type.noType, typeParamsCopy, baseType.tsym);
} else {
throw new IllegalArgumentException("Unsupported arguments to getType");
}
}
示例6: matchMethodInvocation
import com.sun.tools.javac.code.Type.ArrayType; //导入依赖的package包/类
@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
if (!ARRAYS_AS_LIST_SINGLE_ARRAY.matches(tree, state)) {
return NO_MATCH;
}
ExpressionTree array = Iterables.getOnlyElement(tree.getArguments());
Type componentType = ((ArrayType) ASTHelpers.getType(array)).getComponentType();
if (!componentType.isPrimitive()) {
return NO_MATCH;
}
String guavaUtils = GUAVA_UTILS.get(componentType.getKind());
if (guavaUtils == null) {
return NO_MATCH;
}
Fix fix =
SuggestedFix.builder()
.addImport("com.google.common.primitives." + guavaUtils)
.replace(tree.getMethodSelect(), guavaUtils + ".asList")
.build();
return describeMatch(tree, fix);
}
示例7: getTypeName
import com.sun.tools.javac.code.Type.ArrayType; //导入依赖的package包/类
public static String getTypeName(Type t, boolean full) {
switch (t.tag) {
case ARRAY:
StringBuilder s = new StringBuilder();
while (t.tag == ARRAY) {
s.append("[]");
t = ((ArrayType)t).elemtype;
}
s.insert(0, getTypeName(t, full));
return s.toString();
case CLASS:
return ClassDocImpl.getClassName((ClassSymbol)t.tsym, full);
default:
return t.tsym.getQualifiedName().toString();
}
}
示例8: matchMethodInvocation
import com.sun.tools.javac.code.Type.ArrayType; //导入依赖的package包/类
@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
if (ARRAYS_AS_LIST_SINGLE_ARRAY.matches(tree, state)) {
JCTree array = (JCTree) tree.getArguments().get(0);
Type componentType = ((ArrayType) array.type).getComponentType();
String guavaUtils = GUAVA_UTILS.get(componentType.getKind());
if (guavaUtils != null) {
Fix fix = new SuggestedFix()
.addImport("com.google.common.primitives." + guavaUtils)
.replace(tree.getMethodSelect(), guavaUtils + ".asList");
return describeMatch(tree, fix);
}
}
return Description.NO_MATCH;
}
示例9: getType
import com.sun.tools.javac.code.Type.ArrayType; //导入依赖的package包/类
/**
* Build an instance of a Type.
*/
public Type getType(Type baseType, boolean isArray, List<Type> typeParams) {
boolean isGeneric = typeParams != null && !typeParams.equals(List.nil());
if (!isArray && !isGeneric) {
// Simple type.
return baseType;
} else if (isArray && !isGeneric) {
// Array type, not generic.
ClassSymbol arraySymbol = getSymtab().arrayClass;
return new ArrayType(baseType, arraySymbol);
} else if (!isArray && isGeneric) {
return new ClassType(Type.noType, typeParams, baseType.tsym);
} else {
throw new IllegalArgumentException("Unsupported arguments to getType");
}
}
示例10: visitArray
import com.sun.tools.javac.code.Type.ArrayType; //导入依赖的package包/类
public void visitArray(Attribute.Array a) {
Name elemName = ((ArrayType) a.type).elemtype.tsym.getQualifiedName();
if (elemName.equals(elemName.table.names.java_lang_Class)) { // Class[]
// Construct a proxy for a MirroredTypesException
ListBuffer<TypeMirror> elems = new ListBuffer<TypeMirror>();
for (Attribute value : a.values) {
Type elem = ((Attribute.Class) value).type;
elems.append(elem);
}
value = new MirroredTypesExceptionProxy(elems.toList());
} else {
int len = a.values.length;
Class<?> returnClassSaved = returnClass;
returnClass = returnClass.getComponentType();
try {
Object res = Array.newInstance(returnClass, len);
for (int i = 0; i < len; i++) {
a.values[i].accept(this);
if (value == null || value instanceof ExceptionProxy) {
return;
}
try {
Array.set(res, i, value);
} catch (IllegalArgumentException e) {
value = null; // indicates a type mismatch
return;
}
}
value = res;
} finally {
returnClass = returnClassSaved;
}
}
}
示例11: visitArrayType
import com.sun.tools.javac.code.Type.ArrayType; //导入依赖的package包/类
@Override
public Boolean visitArrayType(ArrayType t, Type s) {
if (t == s)
return true;
if (s.isPartial())
return visit(s, t);
return s.hasTag(ARRAY)
&& visit(t.elemtype, types.elemtype(s));
}
示例12: visitArray
import com.sun.tools.javac.code.Type.ArrayType; //导入依赖的package包/类
public void visitArray(Attribute.Array a) {
Name elemName = ((ArrayType) a.type).elemtype.tsym.getQualifiedName();
if (elemName.equals(elemName.table.names.java_lang_Class)) { // Class[]
// Construct a proxy for a MirroredTypesException
ListBuffer<TypeMirror> elems = new ListBuffer<TypeMirror>();
for (Attribute value : a.values) {
Type elem = ((Attribute.Class) value).classType;
elems.append(elem);
}
value = new MirroredTypesExceptionProxy(elems.toList());
} else {
int len = a.values.length;
Class<?> returnClassSaved = returnClass;
returnClass = returnClass.getComponentType();
try {
Object res = Array.newInstance(returnClass, len);
for (int i = 0; i < len; i++) {
a.values[i].accept(this);
if (value == null || value instanceof ExceptionProxy) {
return;
}
try {
Array.set(res, i, value);
} catch (IllegalArgumentException e) {
value = null; // indicates a type mismatch
return;
}
}
value = res;
} finally {
returnClass = returnClassSaved;
}
}
}
示例13: visitArrayType
import com.sun.tools.javac.code.Type.ArrayType; //导入依赖的package包/类
@Override
public String visitArrayType(ArrayType t, Locale locale) {
StringBuilder res = new StringBuilder();
printBaseElementType(t, res, locale);
printBrackets(t, res, locale);
return res.toString();
}
示例14: printBaseElementType
import com.sun.tools.javac.code.Type.ArrayType; //导入依赖的package包/类
void printBaseElementType(Type t, StringBuilder sb, Locale locale) {
Type arrel = t;
while (arrel.hasTag(TypeTag.ARRAY)) {
arrel = arrel.unannotatedType();
arrel = ((ArrayType) arrel).elemtype;
}
sb.append(visit(arrel, locale));
}
示例15: printBrackets
import com.sun.tools.javac.code.Type.ArrayType; //导入依赖的package包/类
void printBrackets(Type t, StringBuilder sb, Locale locale) {
Type arrel = t;
while (arrel.hasTag(TypeTag.ARRAY)) {
if (arrel.isAnnotated()) {
sb.append(' ');
sb.append(arrel.getAnnotationMirrors());
sb.append(' ');
}
sb.append("[]");
arrel = arrel.unannotatedType();
arrel = ((ArrayType) arrel).elemtype;
}
}