本文整理汇总了Java中com.sun.tools.javac.code.Type类的典型用法代码示例。如果您正苦于以下问题:Java Type类的具体用法?Java Type怎么用?Java Type使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Type类属于com.sun.tools.javac.code包,在下文中一共展示了Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypeString
import com.sun.tools.javac.code.Type; //导入依赖的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();
}
}
示例2: recordTypeUsage
import com.sun.tools.javac.code.Type; //导入依赖的package包/类
private void recordTypeUsage(
final TypeMirror type,
final Map<Pair<BinaryName, String>, UsagesData<String>> p) {
List<TypeMirror> types = new LinkedList<TypeMirror>();
types.add(type);
while (!types.isEmpty()) {
TypeMirror currentType = types.remove(0);
if (currentType == null) continue;
switch (currentType.getKind()) {
case DECLARED:
final Symbol typeSym = ((Type) currentType).tsym;
if (typeSym != null && (typeSym.getKind().isClass() || typeSym.getKind().isInterface())) {
addUsage (typeSym, activeClass.peek(), p, ClassIndexImpl.UsageType.TYPE_REFERENCE);
}
types.addAll(((DeclaredType) currentType).getTypeArguments());
break;
case ARRAY:
types.add(((ArrayType) currentType).getComponentType());
break;
}
}
}
示例3: alreadyDefinedIn
import com.sun.tools.javac.code.Type; //导入依赖的package包/类
public boolean alreadyDefinedIn(CharSequence name, TypeMirror returnType, List<TypeMirror> paramTypes, TypeElement enclClass) {
ClassSymbol clazz = (ClassSymbol)enclClass;
Scope scope = clazz.members();
Name n = names.fromString(name.toString());
ListBuffer<Type> buff = new ListBuffer<>();
for (TypeMirror tm : paramTypes) {
buff.append((Type)tm);
}
for (Symbol sym : scope.getSymbolsByName(n, Scope.LookupKind.NON_RECURSIVE)) {
if(sym.type instanceof ExecutableType &&
jctypes.containsTypeEquivalent(sym.type.asMethodType().getParameterTypes(), buff.toList()) &&
jctypes.isSameType(sym.type.asMethodType().getReturnType(), (Type)returnType))
return true;
}
return false;
}
示例4: visitClassType
import com.sun.tools.javac.code.Type; //导入依赖的package包/类
@Override
public Type visitClassType( Type.ClassType t, Void s )
{
boolean erased = false;
Type erasure = _types.erasure( t );
Type base = visitType( erasure, s );
if( base != erasure )
{
erased = true;
}
ArrayList<Type> params = new ArrayList<>();
for( Type arg : t.allparams() )
{
Type param = visit( arg );
params.add( param );
if( param != arg )
{
erased = true;
}
}
if( erased )
{
return new Type.ClassType( t.getEnclosingType(), List.from( params ), base.tsym );
}
return t;
}
示例5: visitLambda
import com.sun.tools.javac.code.Type; //导入依赖的package包/类
@Override
public void visitLambda( JCTree.JCLambda tree )
{
super.visitLambda( tree );
if( _tp.isGenerate() && !shouldProcessForGeneration() )
{
// Don't process tree during GENERATE, unless the tree was generated e.g., a bridge method
return;
}
tree.type = eraseStructureType( tree.type );
ArrayList<Type> types = new ArrayList<>();
for( Type target : tree.targets )
{
types.add( eraseStructureType( target ) );
}
tree.targets = List.from( types );
}
示例6: solveLegacy
import com.sun.tools.javac.code.Type; //导入依赖的package包/类
/**
* Instantiate inference variables in legacy mode (JLS 15.12.2.7, 15.12.2.8).
* During overload resolution, instantiation is done by doing a partial
* inference process using eq/lower bound instantiation. During check,
* we also instantiate any remaining vars by repeatedly using eq/upper
* instantiation, until all variables are solved.
*/
public void solveLegacy(boolean partial, Warner warn, EnumSet<InferenceStep> steps) {
while (true) {
List<Type> solvedVars = solveBasic(steps);
if (restvars().isEmpty() || partial) {
//all variables have been instantiated - exit
break;
} else if (solvedVars.isEmpty()) {
//some variables could not be instantiated because of cycles in
//upper bounds - provide a (possibly recursive) default instantiation
infer.instantiateAsUninferredVars(restvars(), this);
break;
} else {
//some variables have been instantiated - replace newly instantiated
//variables in remaining upper bounds and continue
for (Type t : undetvars) {
UndetVar uv = (UndetVar)t;
uv.substBounds(solvedVars, asInstTypes(solvedVars), types);
}
}
}
infer.doIncorporation(this, warn);
}
示例7: compose
import com.sun.tools.javac.code.Type; //导入依赖的package包/类
public boolean compose(@NonNull final Type returnType,
@RetRx final String type,
@NonNull final MethodSpec.Builder builder) {
if (RetRx.EMPTY.equals(type)) {
// rx.Observable.empty();
builder.addStatement("return $T.empty()", rx.Observable.class);
return true;
}
if (RetRx.ERROR.equals(type)) {
// rx.Observable.error(new UnsupportedOperationException("unsupported method call"));
builder.addStatement("return $T.error(new $T($S))",
rx.Observable.class,
UnsupportedOperationException.class,
"unsupported method call");
return true;
}
return false;
}
示例8: wildcardTypeToString
import com.sun.tools.javac.code.Type; //导入依赖的package包/类
/**
* Return the string form of a wildcard type ("?") along with any
* "extends" or "super" clause. Delimiting brackets are not
* included. Class names are qualified if "full" is true.
*/
static String wildcardTypeToString(DocEnv env,
Type.WildcardType wildThing, boolean full) {
if (env.legacyDoclet) {
return TypeMaker.getTypeName(env.types.erasure(wildThing), full);
}
StringBuilder s = new StringBuilder("?");
List<Type> bounds = getExtendsBounds(wildThing);
if (bounds.nonEmpty()) {
s.append(" extends ");
} else {
bounds = getSuperBounds(wildThing);
if (bounds.nonEmpty()) {
s.append(" super ");
}
}
boolean first = true; // currently only one bound is allowed
for (Type b : bounds) {
if (!first) {
s.append(" & ");
}
s.append(TypeMaker.getTypeString(env, b, full));
first = false;
}
return s.toString();
}
示例9: overloadCheck
import com.sun.tools.javac.code.Type; //导入依赖的package包/类
@Override
Type overloadCheck(ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) {
ResultInfo localInfo = resultInfo.dup(attr.conditionalContext(resultInfo.checkContext));
if (speculativeTree.isStandalone()) {
return localInfo.check(speculativeTree, speculativeTree.type);
} else if (resultInfo.pt.hasTag(VOID)) {
//this means we are returning a poly conditional from void-compatible lambda expression
resultInfo.checkContext.report(tree, attr.diags.fragment(Fragments.ConditionalTargetCantBeVoid));
return attr.types.createErrorType(resultInfo.pt);
} else {
//poly
checkSpeculative(speculativeTree.truepart, localInfo);
checkSpeculative(speculativeTree.falsepart, localInfo);
return localInfo.pt;
}
}
示例10: put
import com.sun.tools.javac.code.Type; //导入依赖的package包/类
/** Place an object in the pool, unless it is already there.
* If object is a symbol also enter its owner unless the owner is a
* package. Return the object's index in the pool.
*/
public int put(Object value) {
value = makePoolValue(value);
Assert.check(!(value instanceof Type.TypeVar));
Assert.check(!(value instanceof Types.UniqueType &&
((UniqueType) value).type instanceof Type.TypeVar));
Integer index = indices.get(value);
if (index == null) {
index = pp;
indices.put(value, index);
pool = ArrayUtils.ensureCapacity(pool, pp);
pool[pp++] = value;
if (value instanceof Long || value instanceof Double) {
pool = ArrayUtils.ensureCapacity(pool, pp);
pool[pp++] = null;
}
}
return index.intValue();
}
示例11: makeNestedType
import com.sun.tools.javac.code.Type; //导入依赖的package包/类
private SrcType makeNestedType( Type type )
{
String fqn = type.toString();
Type enclosingType = type.getEnclosingType();
SrcType srcType;
if( enclosingType != null && !(enclosingType instanceof NoType) && fqn.length() > enclosingType.toString().length() )
{
String simpleName = fqn.substring( enclosingType.toString().length() + 1 );
srcType = new SrcType( simpleName );
srcType.setEnclosingType( makeNestedType( enclosingType ) );
}
else
{
srcType = new SrcType( fqn );
}
return srcType;
}
示例12: hasParameterTypes
import com.sun.tools.javac.code.Type; //导入依赖的package包/类
private boolean hasParameterTypes(MethodSymbol method, String[] argTypes) {
if (argTypes == null) {
// wildcard
return true;
}
int i = 0;
List<Type> types = method.type.getParameterTypes();
if (argTypes.length != types.length()) {
return false;
}
for (Type t : types) {
String argType = argTypes[i++];
// For vararg method, "T..." matches type T[].
if (i == argTypes.length) {
argType = argType.replace("...", "[]");
}
if (!hasTypeName(env.types.erasure(t), argType)) { //###(gj)
return false;
}
}
return true;
}
示例13: visitUses
import com.sun.tools.javac.code.Type; //导入依赖的package包/类
@Override
public void visitUses(JCUses tree) {
Type st = attr.attribType(tree.qualid, env, syms.objectType);
Symbol sym = TreeInfo.symbol(tree.qualid);
if ((sym.flags() & ENUM) != 0) {
log.error(tree.qualid.pos(), Errors.ServiceDefinitionIsEnum(st.tsym));
} else if (st.hasTag(CLASS)) {
ClassSymbol service = (ClassSymbol) st.tsym;
if (allUses.add(service)) {
Directive.UsesDirective d = new Directive.UsesDirective(service);
msym.uses = msym.uses.prepend(d);
msym.directives = msym.directives.prepend(d);
} else {
log.error(tree.pos(), Errors.DuplicateUses(service));
}
}
}
示例14: matches
import com.sun.tools.javac.code.Type; //导入依赖的package包/类
@Override
public boolean matches(ExpressionTree tree, VisitorState state) {
if (!(tree instanceof MethodInvocationTree)) {
return false;
}
MethodInvocationTree invTree = (MethodInvocationTree) tree;
final MemberSelectTree memberTree = (MemberSelectTree) invTree.getMethodSelect();
if (!memberTree.getIdentifier().contentEquals(TO)) {
return false;
}
for (MethodMatchers.MethodNameMatcher nameMatcher : METHOD_NAME_MATCHERS) {
if (nameMatcher.matches(invTree, state)) {
ExpressionTree arg = invTree.getArguments().get(0);
final Type scoper = state.getTypeFromString("com.uber.autodispose.Scoper");
return ASTHelpers.isSubtype(ASTHelpers.getType(arg), scoper, state);
}
}
return false;
}
示例15: assertSameType
import com.sun.tools.javac.code.Type; //导入依赖的package包/类
/** assert that 's' is/is not the same type as 't' */
public void assertSameType(Type s, Type t, boolean expected) {
if (types.isSameType(s, t) != expected) {
String msg = expected ?
" is not the same type as " :
" is the same type as ";
error(s + msg + t);
}
}