Java Code Examples for javax.lang.model.type.TypeKind#NULL
The following examples show how to use
javax.lang.model.type.TypeKind#NULL .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventAssignabilityChecker.java From netbeans with Apache License 2.0 | 6 votes |
@Override protected boolean checkParameter( TypeMirror argType, TypeMirror varTypeArg ) { if ( varTypeArg.getKind()== TypeKind.TYPEVAR ){ Types types = getImplementation().getHelper().getCompilationController(). getTypes(); TypeMirror upperBound = ((TypeVariable)varTypeArg).getUpperBound(); if ( upperBound == null || upperBound.getKind() == TypeKind.NULL ){ return true; } else { return checkIsAssignable(types, argType, upperBound); } } return super.checkParameter(argType, varTypeArg); }
Example 2
Source File: TurbineTypeMirror.java From turbine with Apache License 2.0 | 6 votes |
@Override public TypeKind getKind() { switch (type.primkind()) { case CHAR: return TypeKind.CHAR; case SHORT: return TypeKind.SHORT; case INT: return TypeKind.INT; case LONG: return TypeKind.LONG; case FLOAT: return TypeKind.FLOAT; case DOUBLE: return TypeKind.DOUBLE; case BOOLEAN: return TypeKind.BOOLEAN; case BYTE: return TypeKind.BYTE; case NULL: return TypeKind.NULL; case STRING: } throw new AssertionError(type.primkind()); }
Example 3
Source File: Util.java From revapi with Apache License 2.0 | 6 votes |
@Override public Void visitTypeVariable(TypeVariable t, StringBuilderAndState<TypeMirror> state) { if (state.visitingMethod) { TypeMirror upperBound = IgnoreCompletionFailures.in(t::getUpperBound); upperBound.accept(this, state); return null; } if (state.visitedObjects.contains(t)) { state.bld.append("%"); return null; } state.visitedObjects.add(t); TypeMirror lowerBound = IgnoreCompletionFailures.in(t::getLowerBound); if (lowerBound != null && lowerBound.getKind() != TypeKind.NULL) { lowerBound.accept(this, state); state.bld.append("-"); } IgnoreCompletionFailures.in(t::getUpperBound).accept(this, state); state.bld.append("+"); return null; }
Example 4
Source File: DelegateAssignabilityChecker.java From netbeans with Apache License 2.0 | 6 votes |
@Override protected boolean handleBothTypeVars( TypeMirror argType, TypeMirror varTypeArg, Types types ) { /* * Implementation of spec item : * the delegate type parameter and the bean type parameter are both * type variables and the upper bound of the bean type * parameter is assignable to the upper bound, * if any, of the delegate type parameter */ TypeMirror upper = ((TypeVariable)argType).getUpperBound(); TypeMirror upperVar = ((TypeVariable)varTypeArg).getUpperBound(); if ( upperVar == null || upperVar.getKind() == TypeKind.NULL ){ return true; } if ( upper == null || upper.getKind() == TypeKind.NULL ){ return false; } return checkIsAssignable(types, upper, upperVar); }
Example 5
Source File: Util.java From revapi with Apache License 2.0 | 6 votes |
@Override protected Void doVisitTypeVariable(TypeVariable t, StringBuilderAndState<TypeMirror> state) { Name tName = t.asElement().getSimpleName(); if (state.depth > state.anticipatedTypeVarDeclDepth && state.forwardTypeVarDecls.contains(tName)) { state.bld.append(tName); return null; } state.bld.append(t.asElement().getSimpleName()); TypeMirror lowerBound = IgnoreCompletionFailures.in(t::getLowerBound); if (lowerBound != null && lowerBound.getKind() != TypeKind.NULL) { state.bld.append(" super "); lowerBound.accept(this, state); } TypeMirror upperBound = IgnoreCompletionFailures.in(t::getUpperBound); if (!isJavaLangObject.visit(upperBound)) { state.bld.append(" extends "); upperBound.accept(this, state); } return null; }
Example 6
Source File: MoreTypes.java From doma with Apache License 2.0 | 6 votes |
public boolean isSameTypeWithErasure(TypeMirror t1, TypeMirror t2) { assertNotNull(t1, t2); if (t1.getKind() == TypeKind.NONE || t2.getKind() == TypeKind.NONE) { return false; } if (t1.getKind() == TypeKind.NULL) { return t2.getKind() == TypeKind.NULL; } if (t2.getKind() == TypeKind.NULL) { return t1.getKind() == TypeKind.NULL; } if (t1.getKind() == TypeKind.VOID) { return t2.getKind() == TypeKind.VOID; } if (t2.getKind() == TypeKind.VOID) { return t1.getKind() == TypeKind.VOID; } TypeMirror erasureType1 = typeUtils.erasure(t1); TypeMirror erasureType2 = typeUtils.erasure(t2); return typeUtils.isSameType(erasureType1, erasureType2) || erasureType1.equals(erasureType2); }
Example 7
Source File: AddCast.java From netbeans with Apache License 2.0 | 6 votes |
public List<Fix> run(CompilationInfo info, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) { List<Fix> result = new ArrayList<Fix>(); List<TypeMirror> targetType = new ArrayList<TypeMirror>(); TreePath[] tmTree = new TreePath[1]; ExpressionTree[] expression = new ExpressionTree[1]; Tree[] leaf = new Tree[1]; computeType(info, offset, targetType, tmTree, expression, leaf); if (!targetType.isEmpty()) { TreePath expressionPath = TreePath.getPath(info.getCompilationUnit(), expression[0]); //XXX: performance for (TypeMirror type : targetType) { if (type.getKind() != TypeKind.NULL) { result.add(new AddCastFix(info, expressionPath, tmTree[0], type).toEditorFix()); } } } return result; }
Example 8
Source File: CreateEnumConstant.java From netbeans with Apache License 2.0 | 6 votes |
public CreateEnumConstant(CompilationInfo info, String name, Set<Modifier> modifiers, TypeElement target, TypeMirror proposedType, FileObject targetFile) { this.name = name; this.inFQN = target.getQualifiedName().toString(); this.cpInfo = info.getClasspathInfo(); this.targetFile = targetFile; this.target = ElementHandle.create(target); if (proposedType.getKind() == TypeKind.NULL) { TypeElement tel = info.getElements().getTypeElement("java.lang.Object"); // NOI18N if (tel != null) { proposedType = tel.asType(); this.proposedType = TypeMirrorHandle.create(proposedType); } else { this.proposedType = null; } } else { this.proposedType = TypeMirrorHandle.create(proposedType); } }
Example 9
Source File: SpringXMLConfigCompletionItem.java From netbeans with Apache License 2.0 | 6 votes |
@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; }
Example 10
Source File: DelegateAssignabilityChecker.java From netbeans with Apache License 2.0 | 6 votes |
@Override protected boolean handleRequiredTypeVar( TypeMirror argType, TypeMirror varTypeArg, Types types ) { /* * Implementation of spec item : the delegate type parameter is a * type variable, the bean type parameter is an actual type, and the * actual type is assignable to the upper bound, if any, of the type variable */ TypeMirror upper = ((TypeVariable)varTypeArg).getUpperBound(); if ( upper == null || upper.getKind()== TypeKind.NULL ){ return true; } return checkIsAssignable(types, argType, upper); }
Example 11
Source File: ChangeMethodReturnType.java From netbeans with Apache License 2.0 | 5 votes |
private TypeMirror purify(CompilationInfo info, TypeMirror targetType) { if (targetType != null && targetType.getKind() == TypeKind.ERROR) { targetType = info.getTrees().getOriginalType((ErrorType) targetType); } if (targetType == null || targetType.getKind() == /*XXX:*/TypeKind.ERROR || targetType.getKind() == TypeKind.NONE || targetType.getKind() == TypeKind.NULL) return null; return Utilities.resolveTypeForDeclaration(info, targetType); }
Example 12
Source File: MethodModelSupport.java From netbeans with Apache License 2.0 | 5 votes |
@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; }
Example 13
Source File: Utilities.java From netbeans with Apache License 2.0 | 5 votes |
@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; }
Example 14
Source File: AbstractAssignabilityChecker.java From netbeans with Apache License 2.0 | 5 votes |
protected boolean handleWildCardActualType( TypeMirror argType, Types types, TypeMirror upperBound, TypeMirror lowerBound ){ /* * Implementation of spec item : the required type parameter is * a wildcard, the bean type parameter is an actual type and the * actual type is assignable to the upper bound, if any, of the * wildcard and assignable from the lower bound, if any, of the * wildcard */ if ( upperBound == null || upperBound.getKind() == TypeKind.NULL){ if ( lowerBound == null || lowerBound.getKind() == TypeKind.NULL){ return true; } else { return checkIsAssignable(types, lowerBound, argType); } } else { if ( lowerBound == null || lowerBound.getKind() == TypeKind.NULL){ return checkIsAssignable(types, argType, upperBound); } else { return checkIsAssignable(types, argType, upperBound) && checkIsAssignable(types, lowerBound, argType); } } }
Example 15
Source File: ModelBuilder.java From vertx-codetrans with Apache License 2.0 | 5 votes |
/** * Resolve the type variable, basically some kind of inference: * * for the method {@code <T> void m(T t)} * - resolveType(<T>,T,m("s")) -> String * - resolveType(<T>,T,m(null)) -> null * for the method {@code <T> void m(List<T> t)} * - resolveType(<T>,List<T>,m(Arrays.asList("s"))) -> String * - resolveType(<T>,List<T>,m(BooleanList)) where BooleanList extends List<Boolean> -> Boolean * - resolveType(<T>,List<T>,m(null)) -> null */ private TypeMirror resolveTypeVariable(TypeVariable typeVar, TypeMirror parameterType, TypeMirror argumentType) { if (typeVar.equals(parameterType) && argumentType.getKind() != TypeKind.NULL) { return argumentType; } else { TypeParameterElement ttt = resolveTypeParameterElement(typeVar, parameterType); if (ttt != null && argumentType.getKind() == TypeKind.DECLARED) { TypeMirror resolved = io.vertx.codegen.Helper.resolveTypeParameter(typeUtils, (DeclaredType) argumentType, ttt); if (resolved != null) { return resolved; } } } return null; }
Example 16
Source File: AssignabilityChecker.java From netbeans with Apache License 2.0 | 4 votes |
@Override protected boolean handleWildCardTypeVar( TypeMirror argType, Types types, TypeMirror upperBound, TypeMirror lowerBound ) { /* * Implementation of spec item : * the required type parameter is a wildcard, * the bean type parameter is a type variable and the upper bound of the type * variable is assignable to or assignable from the upper bound, * if any, of the wildcard and assignable from the lower * bound, if any, of the wildcard */ TypeMirror typeUpper = ((TypeVariable) argType).getUpperBound(); if (typeUpper == null || typeUpper.getKind() == TypeKind.NULL) { return upperBound == null || upperBound.getKind() == TypeKind.NULL; } if (upperBound == null || upperBound.getKind() == TypeKind.NULL) { if (lowerBound == null || lowerBound.getKind() == TypeKind.NULL) { return true; } else { return checkIsAssignable(types, lowerBound, typeUpper); } } else { if (lowerBound == null || lowerBound.getKind() == TypeKind.NULL) { return checkIsAssignable(types, typeUpper, upperBound) || checkIsAssignable(types, upperBound, typeUpper); } else { if ((isAssignable(typeUpper, upperBound, types) || isAssignable( upperBound, typeUpper, types)) && isAssignable(lowerBound, typeUpper, types)) { return true; } else if (typeUpper instanceof ReferenceType && lowerBound instanceof ReferenceType) { return (checkAssignability((ReferenceType) upperBound, (ReferenceType) typeUpper) || checkAssignability( (ReferenceType) typeUpper, (ReferenceType) upperBound)) && checkAssignability((ReferenceType) typeUpper, (ReferenceType) lowerBound); } else { return false; } } } }
Example 17
Source File: Type.java From javaide with GNU General Public License v3.0 | 4 votes |
@Override public TypeKind getKind() { return TypeKind.NULL; }
Example 18
Source File: TurbineTypeMirror.java From turbine with Apache License 2.0 | 4 votes |
@Override public TypeKind getKind() { return TypeKind.NULL; }
Example 19
Source File: NullTypeImpl.java From FreeBuilder with Apache License 2.0 | 4 votes |
@Override public TypeKind getKind() { return TypeKind.NULL; }
Example 20
Source File: JavaEnvironment.java From j2cl with Apache License 2.0 | 4 votes |
/** * Creates a type descriptor for the given TypeMirror, taking into account nullability. * * @param typeMirror the type provided by javac, used to create the type descriptor. * @param elementAnnotations the annotations on the element */ private TypeDescriptor createTypeDescriptorWithNullability( TypeMirror typeMirror, List<? extends AnnotationMirror> elementAnnotations) { if (typeMirror == null || typeMirror.getKind() == TypeKind.NONE) { return null; } if (typeMirror.getKind().isPrimitive() || typeMirror.getKind() == TypeKind.VOID) { return PrimitiveTypes.get(asElement(typeMirror).getSimpleName().toString()); } if (typeMirror.getKind() == TypeKind.INTERSECTION) { return createIntersectionType((IntersectionClassType) typeMirror); } if (typeMirror.getKind() == TypeKind.UNION) { return createUnionType((UnionClassType) typeMirror); } if (typeMirror.getKind() == TypeKind.NULL) { return TypeDescriptors.get().javaLangObject; } if (typeMirror.getKind() == TypeKind.TYPEVAR) { return createTypeVariable((javax.lang.model.type.TypeVariable) typeMirror); } if (typeMirror.getKind() == TypeKind.WILDCARD) { return createWildcardTypeVariable( ((javax.lang.model.type.WildcardType) typeMirror).getExtendsBound()); } boolean isNullable = isNullable(typeMirror, elementAnnotations); if (typeMirror.getKind() == TypeKind.ARRAY) { ArrayType arrayType = (ArrayType) typeMirror; TypeDescriptor componentTypeDescriptor = createTypeDescriptor(arrayType.getComponentType()); return ArrayTypeDescriptor.newBuilder() .setComponentTypeDescriptor(componentTypeDescriptor) .setNullable(isNullable) .build(); } return withNullability(createDeclaredType((ClassType) typeMirror), isNullable); }