本文整理匯總了Java中javax.lang.model.type.TypeKind.TYPEVAR屬性的典型用法代碼示例。如果您正苦於以下問題:Java TypeKind.TYPEVAR屬性的具體用法?Java TypeKind.TYPEVAR怎麽用?Java TypeKind.TYPEVAR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類javax.lang.model.type.TypeKind
的用法示例。
在下文中一共展示了TypeKind.TYPEVAR屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: resolveReturnType
static TypeMirror resolveReturnType(
ProcessingEnvironment processing,
ExecutableElement method,
TypeElement typeElement) {
method = CachingElements.getDelegate(method);
TypeMirror returnType = method.getReturnType();
// We do not support parametrized accessor methods,
// but we do support inheriting parametrized accessors, which
// we supposedly parametrized with actual type parameters as
// our target class could not define formal type parameters also.
if (returnType.getKind() == TypeKind.TYPEVAR) {
return asInheritedMemberReturnType(processing, typeElement, method);
} else if (returnType.getKind() == TypeKind.DECLARED
|| returnType.getKind() == TypeKind.ERROR) {
if (!((DeclaredType) returnType).getTypeArguments().isEmpty()) {
return asInheritedMemberReturnType(processing, typeElement, method);
}
}
return returnType;
}
示例2: visitTypeVariable
@Override
public StringBuilder visitTypeVariable(TypeVariable t, Boolean p) {
Element e = t.asElement();
if (e != null) {
String name = e.getSimpleName().toString();
if (!CAPTURED_WILDCARD.equals(name))
return DEFAULT_VALUE.append(name);
}
DEFAULT_VALUE.append("?"); //NOI18N
TypeMirror bound = t.getLowerBound();
if (bound != null && bound.getKind() != TypeKind.NULL) {
DEFAULT_VALUE.append(" super "); //NOI18N
visit(bound, p);
} else {
bound = t.getUpperBound();
if (bound != null && bound.getKind() != TypeKind.NULL) {
DEFAULT_VALUE.append(" extends "); //NOI18N
if (bound.getKind() == TypeKind.TYPEVAR)
bound = ((TypeVariable)bound).getLowerBound();
visit(bound, p);
}
}
return DEFAULT_VALUE;
}
示例3: checkParameters
@Override
protected Problem checkParameters(CompilationController javac) throws IOException {
Problem problem = null;
javac.toPhase(JavaSource.Phase.RESOLVED);
TreePath constrPath = treePathHandle.resolve(javac);
if (constrPath == null || constrPath.getLeaf().getKind() != Tree.Kind.METHOD) {
return new Problem(true, ERR_ReplaceWrongType());
}
TypeElement type = (TypeElement) javac.getTrees().getElement(constrPath.getParentPath());
for (Setter setter : refactoring.getSetters()) {
if(setter.isOptional()) {
TypeMirror parsed = javac.getTreeUtilities().parseType(setter.getType(), type);
if(parsed != null && parsed.getKind() == TypeKind.TYPEVAR) {
problem = JavaPluginUtils.chainProblems(problem, new Problem(true, NbBundle.getMessage(ReplaceConstructorWithBuilderPlugin.class, "ERR_GenericOptional", setter.getVarName())));
}
}
}
return problem;
}
示例4: getTypeClass
private static String getTypeClass(TypeMirror type, CompilationInfo javac) {
TypeKind kind = type.getKind();
if (kind.isPrimitive()) {
return type.toString();
} else if (kind == TypeKind.ARRAY) {
return resolveArrayClass((ArrayType) type, javac);
} else if (kind == TypeKind.DECLARED) {
return ((TypeElement) ((DeclaredType) type).asElement()).getQualifiedName().toString();
} else if (kind == TypeKind.ERROR) {
return type.toString();
} else if (kind == TypeKind.TYPEVAR) {
return javac.getTypes().erasure(type).toString();
} else {
throw new IllegalStateException("Unknown type: " + type + ", " + type.getKind()); // NOI18N
}
}
示例5: interfaceParameterIsIntersectionType
/**
* 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;
}
示例6: resolveTypeName
/**
* uses FQNs where possible since javadoc does not match imports for
* parameter types
*/
private CharSequence resolveTypeName(TypeMirror asType, boolean isVarArgs) {
CharSequence ptype;
if (asType.getKind() == TypeKind.DECLARED) {
// snip generics
Element e = ((DeclaredType) asType).asElement();
ptype = e.getKind().isClass() || e.getKind().isInterface()
? ((TypeElement) e).getQualifiedName()
: e.getSimpleName();
} else if (asType.getKind() == TypeKind.TYPEVAR) {
do {
// Type Erasure JLS 4.6
asType = ((TypeVariable) asType).getUpperBound();
} while (asType.getKind() == TypeKind.TYPEVAR);
ptype = resolveTypeName(asType, isVarArgs);
} else if (isVarArgs && asType.getKind() == TypeKind.ARRAY) {
ptype = resolveTypeName(((ArrayType)asType).getComponentType(), false) + "..."; //NOI18N
} else {
ptype = asType.toString();
}
return ptype;
}
示例7: visitTypeVariable
@Override
public Void visitTypeVariable(TypeVariable type, Void p) {
Element e = type.asElement();
if (e != null) {
CharSequence name = e.getSimpleName();
if (!CAPTURED_WILDCARD.contentEquals(name)) {
builder.append(name);
return null;
}
}
builder.append("?"); //NOI18N
TypeMirror bound = type.getLowerBound();
if (bound != null && bound.getKind() != TypeKind.NULL) {
builder.append(" super "); //NOI18N
visit(bound);
} else {
bound = type.getUpperBound();
if (bound != null && bound.getKind() != TypeKind.NULL) {
builder.append(" extends "); //NOI18N
if (bound.getKind() == TypeKind.TYPEVAR)
bound = ((TypeVariable)bound).getLowerBound();
visit(bound);
}
}
return null;
}
示例8: interfaceParameterIsIntersectionType
/**
* Erasure destroys the implementation parameter subtype
* relationship for intersection types
*/
boolean interfaceParameterIsIntersectionType() {
List<Type> tl = tree.getDescriptorType(types).getParameterTypes();
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;
}
示例9: checkTypesAssignable
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;
}
示例10: buildEqualsMethod
@Nonnull
private MethodSpec buildEqualsMethod()
throws ArezProcessorException
{
final String idMethod =
null == _componentId ? GeneratorUtil.ID_FIELD_NAME : _componentId.getSimpleName().toString();
final MethodSpec.Builder method =
MethodSpec.methodBuilder( "equals" ).
addModifiers( Modifier.PUBLIC, Modifier.FINAL ).
addAnnotation( Override.class ).
addParameter( Object.class, "o", Modifier.FINAL ).
returns( TypeName.BOOLEAN );
final ClassName generatedClass = ClassName.get( getPackageName(), getArezClassName() );
final CodeBlock.Builder codeBlock = CodeBlock.builder();
codeBlock.beginControlFlow( "if ( this == o )" );
codeBlock.addStatement( "return true" );
codeBlock.nextControlFlow( "else if ( null == o || !(o instanceof $T) )", generatedClass );
codeBlock.addStatement( "return false" );
codeBlock.nextControlFlow( "else" );
codeBlock.addStatement( "final $T that = ($T) o;", generatedClass, generatedClass );
final TypeKind kind = null != _componentId ? _componentId.getReturnType().getKind() : TypeKind.LONG;
if ( kind == TypeKind.DECLARED || kind == TypeKind.TYPEVAR )
{
codeBlock.addStatement( "return null != $N() && $N().equals( that.$N() )", idMethod, idMethod, idMethod );
}
else
{
codeBlock.addStatement( "return $N() == that.$N()", idMethod, idMethod );
}
codeBlock.endControlFlow();
method.addCode( codeBlock.build() );
return method.build();
}
示例11: containsTypeVar
private boolean containsTypeVar(DeclaredType dt, boolean typeVar) {
List<? extends TypeMirror> args = dt.getTypeArguments();
for (TypeMirror arg : args) {
if (arg.getKind() == TypeKind.TYPEVAR) {
typeVar = true;
}
if (arg.getKind() == TypeKind.DECLARED) {
typeVar = typeVar || containsTypeVar((DeclaredType) arg, typeVar);
}
}
return typeVar;
}
示例12: visitTypeVariable
@Override
public StringBuilder visitTypeVariable(TypeVariable t, Boolean p) {
Element e = t.asElement();
if (e != null) {
String name = e.getSimpleName().toString();
if (!CAPTURED_WILDCARD.equals(name))
return DEFAULT_VALUE.append(name);
}
DEFAULT_VALUE.append("?"); //NOI18N
if (!insideCapturedWildcard) {
insideCapturedWildcard = true;
TypeMirror bound = t.getLowerBound();
if (bound != null && bound.getKind() != TypeKind.NULL) {
DEFAULT_VALUE.append(" super "); //NOI18N
visit(bound, p);
} else {
bound = t.getUpperBound();
if (bound != null && bound.getKind() != TypeKind.NULL) {
DEFAULT_VALUE.append(" extends "); //NOI18N
if (bound.getKind() == TypeKind.TYPEVAR)
bound = ((TypeVariable)bound).getLowerBound();
visit(bound, p);
}
}
insideCapturedWildcard = false;
}
return DEFAULT_VALUE;
}
示例13: getTypeName
private static String getTypeName(TypeMirror type) {
if (type.getKind() == TypeKind.ARRAY) {
return getTypeName(((javax.lang.model.type.ArrayType) type).getComponentType())+"[]";
}
if (type.getKind() == TypeKind.TYPEVAR) {
TypeVariable tv = (TypeVariable) type;
return getTypeName(tv.getUpperBound());
}
if (type.getKind() == TypeKind.DECLARED) {
return ElementUtilities.getBinaryName((TypeElement) ((DeclaredType) type).asElement());
}
return type.toString();
}
示例14: getEffectTypeVar
private AnnotatedTypeVariable getEffectTypeVar(TypeMirror typeMirror) {
if (typeMirror == null) {
return null;
} else if (typeMirror.getKind() == TypeKind.WILDCARD) {
return getEffectTypeVar(((WildcardType) typeMirror).getExtendsBound());
} else if (typeMirror.getKind() == TypeKind.TYPEVAR) {
TypeVariable typevar = ((TypeVariable) typeMirror);
AnnotatedTypeMirror atm =
analysis.getTypeFactory().getAnnotatedType(typevar.asElement());
return (AnnotatedTypeVariable) atm;
} else {
return null;
}
}
示例15: encodeAsString
public static String encodeAsString(TypeDesc td) {
if (td.typeKind.isPrimitive() || td.typeKind == TypeKind.VOID)
return StringUtils.toLowerCase(td.typeKind.toString());
if (td.typeKind == TypeKind.ARRAY)
return encodeAsString(((ArrayTypeDesc) td).compTypeDesc) + "[]";
if (td.typeKind == TypeKind.TYPEVAR)
return "#" + ((TypeVarTypeDesc) td).identifier;
if (td.typeKind == TypeKind.DECLARED)
return ((ReferenceTypeDesc) td).javaType.toString();
throw new AssertionError("Unhandled type: " + td.typeKind);
}