当前位置: 首页>>代码示例>>Java>>正文


Java TypeVar类代码示例

本文整理汇总了Java中com.sun.tools.javac.code.Type.TypeVar的典型用法代码示例。如果您正苦于以下问题:Java TypeVar类的具体用法?Java TypeVar怎么用?Java TypeVar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TypeVar类属于com.sun.tools.javac.code.Type包,在下文中一共展示了TypeVar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: interfaceParameterIsIntersectionType

import com.sun.tools.javac.code.Type.TypeVar; //导入依赖的package包/类
/**
 * Erasure destroys the implementation parameter subtype
 * relationship for intersection types
 */
boolean interfaceParameterIsIntersectionType() {
    List<Type> tl = tree.getDescriptorType(types).getParameterTypes();
    if (tree.kind == ReferenceKind.UNBOUND) {
        tl = tl.tail;
    }
    for (; tl.nonEmpty(); tl = tl.tail) {
        Type pt = tl.head;
        if (pt.getKind() == TypeKind.TYPEVAR) {
            TypeVar tv = (TypeVar) pt;
            if (tv.bound.getKind() == TypeKind.INTERSECTION) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:LambdaToMethod.java

示例2: visitTypeVar

import com.sun.tools.javac.code.Type.TypeVar; //导入依赖的package包/类
@Override
public Type visitTypeVar(TypeVar t, Boolean upward) {
    if (vars.contains(t)) {
        try {
            if (seen.add(t)) {
                return (upward ?
                        t.getUpperBound() :
                        (t.getLowerBound() == null) ?
                                syms.botType :
                                t.getLowerBound())
                            .map(this, upward);
            } else {
                //cycle
                return syms.objectType;
            }
        } finally {
            seen.remove(t);
        }
    } else {
        return t;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:VarTypePrinter.java

示例3: visitTypeVar

import com.sun.tools.javac.code.Type.TypeVar; //导入依赖的package包/类
@Override
public UTypeVar visitTypeVar(TypeVar type, Void v) {
  /*
   * In order to handle recursively bounded type variables without a stack overflow, we first
   * cache a type var with no bounds, then we template the bounds.
   */
  TypeSymbol tsym = type.asElement();
  if (typeVariables.containsKey(tsym)) {
    return typeVariables.get(tsym);
  }
  UTypeVar var = UTypeVar.create(tsym.getSimpleName().toString());
  typeVariables.put(tsym, var); // so the type variable can be used recursively in the bounds
  var.setLowerBound(type.getLowerBound().accept(this, null));
  var.setUpperBound(type.getUpperBound().accept(this, null));
  return var;
}
 
开发者ID:sivakumar-kailasam,项目名称:refactor-faster,代码行数:17,代码来源:UTemplater.java

示例4: getUpperBound

import com.sun.tools.javac.code.Type.TypeVar; //导入依赖的package包/类
/**
 * Returns the upper bound of a type if it has one, or the type itself if not. Correctly handles
 * wildcards and capture variables.
 */
public static Type getUpperBound(Type type, Types types) {
  if (type.hasTag(TypeTag.WILDCARD)) {
    return types.wildUpperBound(type);
  }

  if (type.hasTag(TypeTag.TYPEVAR) && ((TypeVar) type).isCaptured()) {
    return types.cvarUpperBound(type);
  }

  if (type.getUpperBound() != null) {
    return type.getUpperBound();
  }

  // concrete type, e.g. java.lang.String, or a case we haven't considered
  return type;
}
 
开发者ID:google,项目名称:error-prone,代码行数:21,代码来源:ASTHelpers.java

示例5: visitTypeVar

import com.sun.tools.javac.code.Type.TypeVar; //导入依赖的package包/类
@Override
public UTypeVar visitTypeVar(TypeVar type, Void v) {
  /*
   * In order to handle recursively bounded type variables without a stack overflow, we first
   * cache a type var with no bounds, then we template the bounds.
   */
  TypeSymbol tsym = type.asElement();
  if (typeVariables.containsKey(tsym)) {
    return typeVariables.get(tsym);
  }
  UTypeVar var = UTypeVar.create(tsym.getSimpleName().toString());
  typeVariables.put(
      tsym, var); // so the type variable can be used recursively in the bounds
  var.setLowerBound(type.getLowerBound().accept(this, null));
  var.setUpperBound(type.getUpperBound().accept(this, null));
  return var;
}
 
开发者ID:google,项目名称:error-prone,代码行数:18,代码来源:UTemplater.java

示例6: visitTypeVar

import com.sun.tools.javac.code.Type.TypeVar; //导入依赖的package包/类
@Override
public Violation visitTypeVar(TypeVar type, Void s) {
  TypeVariableSymbol tyvar = (TypeVariableSymbol) type.tsym;
  if (containerTypeParameters.contains(tyvar.getSimpleName().toString())) {
    return Violation.absent();
  }
  if (isThreadSafeTypeParameter(tyvar)) {
    return Violation.absent();
  }
  String message;
  if (!allowContainerTypeParameters) {
    message =
        String.format("'%s' is not annotated @ImmutableTypeParameter", tyvar.getSimpleName());
  } else if (!containerTypeParameters.isEmpty()) {
    message =
        String.format(
            "'%s' is a mutable type variable (not in '%s')",
            tyvar.getSimpleName(), Joiner.on(", ").join(containerTypeParameters));
  } else {
    message = String.format("'%s' is a mutable type variable", tyvar.getSimpleName());
  }
  return Violation.of(message);
}
 
开发者ID:google,项目名称:error-prone,代码行数:24,代码来源:ThreadSafety.java

示例7: visitTypeVar

import com.sun.tools.javac.code.Type.TypeVar; //导入依赖的package包/类
@Override
public Void visitTypeVar(TypeVar t, Void s) {
    if (t.bound instanceof PlaceholderType)
        t.bound = ((PlaceholderType)t.bound).delegate;
    else if (t.bound != null)
        t.bound.accept(this, s);
    if (t.lower instanceof PlaceholderType)
        t.lower = ((PlaceholderType)t.lower).delegate;
    else if (t.lower != null)
        t.lower.accept(this, s);
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:TypeMirrorHandle.java

示例8: checkTypesAssignable

import com.sun.tools.javac.code.Type.TypeVar; //导入依赖的package包/类
public static boolean checkTypesAssignable(CompilationInfo info, TypeMirror from, TypeMirror to) {
    Context c = ((JavacTaskImpl) info.impl.getJavacTask()).getContext();
    if (from.getKind() == TypeKind.TYPEVAR) {
        Types types = Types.instance(c);
        TypeVar t = types.substBound((TypeVar)from, com.sun.tools.javac.util.List.of((Type)from), com.sun.tools.javac.util.List.of(types.boxedTypeOrType((Type)to)));
        return info.getTypes().isAssignable(t.getUpperBound(), to)
                || info.getTypes().isAssignable(to, t.getUpperBound());
    }
    if (from.getKind() == TypeKind.WILDCARD) {
        from = Types.instance(c).wildUpperBound((Type)from);
    }
    return Check.instance(c).checkType(null, (Type)from, (Type)to).getKind() != TypeKind.ERROR;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:SourceUtils.java

示例9: unique

import com.sun.tools.javac.code.Type.TypeVar; //导入依赖的package包/类
private boolean unique(TypeVar typevar) {
    int found = 0;
    for (Type t : whereClauses.get(WhereClauseKind.TYPEVAR).keySet()) {
        if (t.toString().equals(typevar.toString())) {
            found++;
        }
    }
    if (found < 1)
        throw new AssertionError("Missing type variable in where clause " + typevar);
    return found == 1;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:12,代码来源:RichDiagnosticFormatter.java

示例10: visitTypeVar

import com.sun.tools.javac.code.Type.TypeVar; //导入依赖的package包/类
@Override
public String visitTypeVar(TypeVar t, Locale locale) {
    if (unique(t) ||
            !getConfiguration().isEnabled(RichFormatterFeature.UNIQUE_TYPEVAR_NAMES)) {
        return t.toString();
    } else {
        return localize(locale,
                "compiler.misc.type.var",
                t.toString(), indexOf(t, WhereClauseKind.TYPEVAR));
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:12,代码来源:RichDiagnosticFormatter.java

示例11: visitTypeParameter

import com.sun.tools.javac.code.Type.TypeVar; //导入依赖的package包/类
/** Class enter visitor method for type parameters.
 *  Enter a symbol for type parameter in local scope, after checking that it
 *  is unique.
 */
@Override
public void visitTypeParameter(JCTypeParameter tree) {
    TypeVar a = (tree.type != null)
        ? (TypeVar)tree.type
        : new TypeVar(tree.name, env.info.scope.owner, syms.botType);
    tree.type = a;
    if (chk.checkUnique(tree.pos(), a.tsym, env.info.scope)) {
        env.info.scope.enter(a.tsym);
    }
    result = a;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:16,代码来源:Enter.java

示例12: typeVarToString

import com.sun.tools.javac.code.Type.TypeVar; //导入依赖的package包/类
/**
 * Return the string form of a type variable along with any
 * "extends" clause.  Class names are qualified if "full" is true.
 */
static String typeVarToString(DocEnv env, TypeVar v, boolean full) {
    StringBuilder s = new StringBuilder(v.toString());
    List<Type> bounds = getBounds(v, env);
    if (bounds.nonEmpty()) {
        boolean first = true;
        for (Type b : bounds) {
            s.append(first ? " extends " : " & ");
            s.append(TypeMaker.getTypeString(env, b, full));
            first = false;
        }
    }
    return s.toString();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:TypeVariableImpl.java

示例13: getBounds

import com.sun.tools.javac.code.Type.TypeVar; //导入依赖的package包/类
/**
 * Get the bounds of a type variable as listed in the "extends" clause.
 */
private static List<Type> getBounds(TypeVar v, DocEnv env) {
    final Type upperBound = v.getUpperBound();
    Name boundname = upperBound.tsym.getQualifiedName();
    if (boundname == boundname.table.names.java_lang_Object
        && !upperBound.isAnnotated()) {
        return List.nil();
    } else {
        return env.types.getBounds(v);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:TypeVariableImpl.java

示例14: getType

import com.sun.tools.javac.code.Type.TypeVar; //导入依赖的package包/类
@SuppressWarnings("fallthrough")
public static com.sun.javadoc.Type getType(DocEnv env, Type t,
        boolean errToClassDoc, boolean considerAnnotations) {
    if (env.legacyDoclet) {
        t = env.types.erasure(t);
    }

    if (considerAnnotations && t.isAnnotated()) {
        return new AnnotatedTypeImpl(env, t);
    }

    switch (t.getTag()) {
    case CLASS:
        if (ClassDocImpl.isGeneric((ClassSymbol)t.tsym)) {
            return env.getParameterizedType((ClassType)t);
        } else {
            return env.getClassDoc((ClassSymbol)t.tsym);
        }
    case WILDCARD:
        Type.WildcardType a = (Type.WildcardType)t;
        return new WildcardTypeImpl(env, a);
    case TYPEVAR: return new TypeVariableImpl(env, (TypeVar)t);
    case ARRAY: return new ArrayTypeImpl(env, t);
    case BYTE: return PrimitiveType.byteType;
    case CHAR: return PrimitiveType.charType;
    case SHORT: return PrimitiveType.shortType;
    case INT: return PrimitiveType.intType;
    case LONG: return PrimitiveType.longType;
    case FLOAT: return PrimitiveType.floatType;
    case DOUBLE: return PrimitiveType.doubleType;
    case BOOLEAN: return PrimitiveType.booleanType;
    case VOID: return PrimitiveType.voidType;
    case ERROR:
        if (errToClassDoc)
            return env.getClassDoc((ClassSymbol)t.tsym);
        // FALLTHRU
    default:
        return new PrimitiveType(t.tsym.getQualifiedName().toString());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:TypeMaker.java

示例15: typeParametersString

import com.sun.tools.javac.code.Type.TypeVar; //导入依赖的package包/类
/**
 * Return the formal type parameters of a class or method as an
 * angle-bracketed string.  Each parameter is a type variable with
 * optional bounds.  Class names are qualified if "full" is true.
 * Return "" if there are no type parameters or we're hiding generics.
 */
static String typeParametersString(DocEnv env, Symbol sym, boolean full) {
    if (env.legacyDoclet || sym.type.getTypeArguments().isEmpty()) {
        return "";
    }
    StringBuilder s = new StringBuilder();
    for (Type t : sym.type.getTypeArguments()) {
        s.append(s.length() == 0 ? "<" : ", ");
        s.append(TypeVariableImpl.typeVarToString(env, (TypeVar)t, full));
    }
    s.append(">");
    return s.toString();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:TypeMaker.java


注:本文中的com.sun.tools.javac.code.Type.TypeVar类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。