本文整理汇总了Java中com.sun.tools.javac.code.Type.ClassType类的典型用法代码示例。如果您正苦于以下问题:Java ClassType类的具体用法?Java ClassType怎么用?Java ClassType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClassType类属于com.sun.tools.javac.code.Type包,在下文中一共展示了ClassType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitClassType
import com.sun.tools.javac.code.Type.ClassType; //导入依赖的package包/类
@Override
public String visitClassType(ClassType t, Locale locale) {
StringBuffer buf = new StringBuffer();
if (t.getEnclosingType().tag == CLASS && t.tsym.owner.kind == Kinds.TYP) {
buf.append(visit(t.getEnclosingType(), locale));
buf.append(".");
buf.append(className(t, false, locale));
} else {
buf.append(className(t, true, locale));
}
if (t.getTypeArguments().nonEmpty()) {
buf.append('<');
buf.append(visitTypes(t.getTypeArguments(), locale));
buf.append(">");
}
return buf.toString();
}
示例2: getTypeString
import com.sun.tools.javac.code.Type.ClassType; //导入依赖的package包/类
/**
* Return the string representation of a type use. Bounds of type
* variables are not included; bounds of wildcard types are.
* Class names are qualified if "full" is true.
*/
static String getTypeString(DocEnv env, Type t, boolean full) {
// TODO: should annotations be included here?
if (t.isAnnotated()) {
t = t.unannotatedType();
}
switch (t.getTag()) {
case ARRAY:
StringBuilder s = new StringBuilder();
while (t.hasTag(ARRAY)) {
s.append("[]");
t = env.types.elemtype(t);
}
s.insert(0, getTypeString(env, t, full));
return s.toString();
case CLASS:
return ParameterizedTypeImpl.
parameterizedTypeToString(env, (ClassType)t, full);
case WILDCARD:
Type.WildcardType a = (Type.WildcardType)t;
return WildcardTypeImpl.wildcardTypeToString(env, a, full);
default:
return t.tsym.getQualifiedName().toString();
}
}
示例3: parameterizedTypeToString
import com.sun.tools.javac.code.Type.ClassType; //导入依赖的package包/类
static String parameterizedTypeToString(DocEnv env, ClassType cl,
boolean full) {
if (env.legacyDoclet) {
return TypeMaker.getTypeName(cl, full);
}
StringBuilder s = new StringBuilder();
if (!(cl.getEnclosingType().hasTag(CLASS))) { // if not an inner class...
s.append(TypeMaker.getTypeName(cl, full));
} else {
ClassType encl = (ClassType)cl.getEnclosingType();
s.append(parameterizedTypeToString(env, encl, full))
.append('.')
.append(cl.tsym.name.toString());
}
s.append(TypeMaker.typeArgumentsString(env, cl, full));
return s.toString();
}
示例4: synthesizeEmptyInterfaceIfMissing
import com.sun.tools.javac.code.Type.ClassType; //导入依赖的package包/类
public void synthesizeEmptyInterfaceIfMissing(final Type type) {
final Completer completer = type.tsym.completer;
type.tsym.completer = new Completer() {
@Override
public void complete(Symbol sym) throws CompletionFailure {
try {
completer.complete(sym);
} catch (CompletionFailure e) {
sym.flags_field |= (PUBLIC | INTERFACE);
((ClassType) sym.type).supertype_field = objectType;
}
}
@Override
public boolean isTerminal() {
return completer.isTerminal();
}
};
}
示例5: getTypeString
import com.sun.tools.javac.code.Type.ClassType; //导入依赖的package包/类
/**
* Return the string representation of a type use. Bounds of type
* variables are not included; bounds of wildcard types are.
* Class names are qualified if "full" is true.
*/
static String getTypeString(DocEnv env, Type t, boolean full) {
// TODO: should annotations be included here?
switch (t.getTag()) {
case ARRAY:
StringBuilder s = new StringBuilder();
while (t.hasTag(ARRAY)) {
s.append("[]");
t = env.types.elemtype(t);
}
s.insert(0, getTypeString(env, t, full));
return s.toString();
case CLASS:
return ParameterizedTypeImpl.
parameterizedTypeToString(env, (ClassType)t, full);
case WILDCARD:
Type.WildcardType a = (Type.WildcardType)t;
return WildcardTypeImpl.wildcardTypeToString(env, a, full);
default:
return t.tsym.getQualifiedName().toString();
}
}
示例6: getTypeString
import com.sun.tools.javac.code.Type.ClassType; //导入依赖的package包/类
/**
* Return the string representation of a type use. Bounds of type
* variables are not included; bounds of wildcard types are.
* Class names are qualified if "full" is true.
*/
static String getTypeString(DocEnv env, Type t, boolean full) {
switch (t.tag) {
case ARRAY:
StringBuffer dimension = new StringBuffer();
while (t.tag == ARRAY) {
dimension = dimension.append("[]");
t = env.types.elemtype(t);
}
return getTypeString(env, t, full) + dimension;
case CLASS:
return ParameterizedTypeImpl.
parameterizedTypeToString(env, (ClassType)t, full);
case WILDCARD:
Type.WildcardType a = (Type.WildcardType)t;
return WildcardTypeImpl.wildcardTypeToString(env, a, full);
default:
return t.tsym.getQualifiedName().toString();
}
}
示例7: parameterizedTypeToString
import com.sun.tools.javac.code.Type.ClassType; //导入依赖的package包/类
static String parameterizedTypeToString(DocEnv env, ClassType cl,
boolean full) {
if (env.legacyDoclet) {
return TypeMaker.getTypeName(cl, full);
}
StringBuffer s = new StringBuffer();
if (cl.getEnclosingType().tag != CLASS) { // if not an inner class...
s.append(TypeMaker.getTypeName(cl, full));
} else {
ClassType encl = (ClassType)cl.getEnclosingType();
s.append(parameterizedTypeToString(env, encl, full))
.append('.')
.append(cl.tsym.name.toString());
}
s.append(TypeMaker.typeArgumentsString(env, cl, full));
return s.toString();
}
示例8: visitClass
import com.sun.tools.javac.code.Type.ClassType; //导入依赖的package包/类
@Override
public Object visitClass (ClassTree classTree, Trees trees) {
Tree extendTree = classTree.getExtendsClause();
if (extendTree instanceof JCTypeApply) { //generic classes case
JCTypeApply generic = (JCTypeApply) extendTree;
extendTree = generic.clazz;
}
if (extendTree instanceof JCIdent) {
JCIdent tree = (JCIdent) extendTree;
Scope members = tree.sym.members();
if (checkScope(members))
return super.visitClass(classTree, trees);
if (checkSuperTypes((ClassType) tree.type))
return super.visitClass(classTree, trees);
}
callSuperUsed = false;
return super.visitClass(classTree, trees);
}
示例9: matches
import com.sun.tools.javac.code.Type.ClassType; //导入依赖的package包/类
@Override
public boolean matches(ExpressionTree t, VisitorState state) {
Type type = ((JCTree) t).type;
// Expect a class type.
if (!(type instanceof ClassType)) {
return false;
}
// Expect one type argument, the type of the JUnit class runner to use.
com.sun.tools.javac.util.List<Type> typeArgs = ((ClassType) type).getTypeArguments();
if (typeArgs.size() != 1) {
return false;
}
Type runnerType = typeArgs.get(0);
for (String testRunner : TEST_RUNNERS) {
Symbol parent = state.getSymbolFromString(testRunner);
if (parent == null) {
continue;
}
if (runnerType.tsym.isSubClass(parent, state.getTypes())) {
return true;
}
}
return false;
}
示例10: findIdent
import com.sun.tools.javac.code.Type.ClassType; //导入依赖的package包/类
/** Finds a declaration with the given name and type that is in scope at the current location. */
public static Symbol findIdent(String name, VisitorState state, KindSelector kind) {
ClassType enclosingClass = ASTHelpers.getType(state.findEnclosing(ClassTree.class));
if (enclosingClass == null || enclosingClass.tsym == null) {
return null;
}
Env<AttrContext> env = Enter.instance(state.context).getClassEnv(enclosingClass.tsym);
MethodTree enclosingMethod = state.findEnclosing(MethodTree.class);
if (enclosingMethod != null) {
env = MemberEnter.instance(state.context).getMethodEnv((JCMethodDecl) enclosingMethod, env);
}
try {
Method method =
Resolve.class.getDeclaredMethod("findIdent", Env.class, Name.class, KindSelector.class);
method.setAccessible(true);
Symbol result =
(Symbol) method.invoke(Resolve.instance(state.context), env, state.getName(name), kind);
return result.exists() ? result : null;
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
}
}
示例11: getType
import com.sun.tools.javac.code.Type.ClassType; //导入依赖的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");
}
}
示例12: visitClassType
import com.sun.tools.javac.code.Type.ClassType; //导入依赖的package包/类
@Override
public JCExpression visitClassType(ClassType type, Inliner inliner) {
ClassSymbol classSym = (ClassSymbol) type.tsym;
JCExpression classExpr =
inliner
.importPolicy()
.classReference(
inliner,
classSym.outermostClass().getQualifiedName().toString(),
classSym.getQualifiedName().toString());
List<JCExpression> argExprs = List.nil();
for (Type argType : type.getTypeArguments()) {
argExprs = argExprs.append(visit(argType, inliner));
}
return argExprs.isEmpty() ? classExpr : inliner.maker().TypeApply(classExpr, argExprs);
}
示例13: matches
import com.sun.tools.javac.code.Type.ClassType; //导入依赖的package包/类
@Override
public boolean matches(ExpressionTree tree, VisitorState state) {
Types types = state.getTypes();
Type classType = state.getSymtab().classType;
Type runtimeExceptionType = state.getSymtab().runtimeExceptionType;
Type argType = getType(tree);
// Make sure that the argument is a Class<Something> (and not null/bottom).
if (!isSubtype(argType, classType, state) || argType.getTag() == BOT) {
return false;
}
List<Type> typeArguments = ((ClassType) argType).getTypeArguments();
Type exceptionType = typeArguments.isEmpty() ? null : typeArguments.get(0);
return types.isSubtype(exceptionType, runtimeExceptionType);
}
示例14: getMethodReturnTypes
import com.sun.tools.javac.code.Type.ClassType; //导入依赖的package包/类
private static ImmutableSet<ClassType> getMethodReturnTypes(MethodTree methodTree) {
ImmutableSet.Builder<ClassType> returnTypes = ImmutableSet.builder();
methodTree.accept(
new TreeScanner<Void, Void>() {
@Override
public Void visitReturn(ReturnTree node, Void unused) {
Type type = ASTHelpers.getType(node.getExpression());
if (type instanceof ClassType) {
returnTypes.add((ClassType) type);
}
return null;
}
},
null /* unused */);
return returnTypes.build();
}
示例15: mutableEnclosingInstance
import com.sun.tools.javac.code.Type.ClassType; //导入依赖的package包/类
/** Returns an enclosing instance for the specified type if it is thread-safe. */
public Type mutableEnclosingInstance(Optional<ClassTree> tree, ClassType type) {
if (tree.isPresent()
&& !CanBeStaticAnalyzer.referencesOuter(
tree.get(), ASTHelpers.getSymbol(tree.get()), state)) {
return null;
}
Type enclosing = type.getEnclosingType();
while (!Type.noType.equals(enclosing)) {
if (getMarkerOrAcceptedAnnotation(enclosing.tsym, state) == null
&& isThreadSafeType(
/* allowContainerTypeParameters= */ false,
/* containerTypeParameters= */ ImmutableSet.of(),
enclosing)
.isPresent()) {
return enclosing;
}
enclosing = enclosing.getEnclosingType();
}
return null;
}