@Override public boolean isType(Class<?> clazz) { Class<?> clazzComponentType = clazz.getComponentType(); if (clazzComponentType != null) { return component.isType(clazzComponentType); } return false; }
@Override public boolean isType(Class<?> clazz) { if (components == null) return false; if (isSynonym()) { for(LightweightTypeReference component: components) { if (component.isType(clazz)) return true; } return false; } else { for(LightweightTypeReference component: components) { if (!component.isType(clazz)) return false; } return true; } }
private String getAsString(Function<LightweightTypeReference, String> format, boolean simpleName) { if (lowerBound != null) { return "? super " + format.apply(lowerBound); } if (simpleName) { if (upperBounds != null && upperBounds.size() == 1 && upperBounds.get(0).isType(Object.class)) { return "?"; } } return "?" + ( upperBounds != null ? " extends " + Joiner.on(" & ").join(Iterables.transform(upperBounds, format)) : ""); }
@Override public boolean isType(Class<?> clazz) { if (internalIsResolved()) { return resolvedTo.isType(clazz); } return false; }
@Override public boolean isVoidTypeAllowed() { LightweightTypeReference expectedType = getExpectedType(); if (expectedType != null && expectedType.isType(Void.TYPE)) { return true; } return false; }
protected boolean isMapLiteral(LightweightTypeReference expectation, LightweightTypeReference elementType) { if (isIterableExpectation(expectation)) { return false; } return elementType.isType(Pair.class) && elementType.getTypeArguments().size() == 2; }
/** * @param context unused in this context but required for dispatching * @param indicator unused in this context but required for dispatching */ protected Object _doEvaluate(XStringLiteral literal, IEvaluationContext context, CancelIndicator indicator) { LightweightTypeReference type = typeResolver.resolveTypes(literal).getActualType(literal); if (type != null && (type.isType(Character.TYPE) || type.isType(Character.class))) { return literal.getValue().charAt(0); } return literal.getValue(); }
protected boolean hasThrowableExpectation(ITypeComputationState state) { List<? extends ITypeExpectation> expectations = state.getExpectations(); for (ITypeExpectation typeExpectation : expectations) { LightweightTypeReference expected = typeExpectation.getExpectedType(); if (expected != null && expected.isType(Throwable.class)) return true; } return false; }
protected LightweightTypeReference resolveType(XExpression element, Class<?> clazz) { LightweightTypeReference elementType = typeResolver.resolveTypes(element).getActualType(element); return elementType != null && elementType.isType(clazz) ? elementType : null; }
protected LightweightTypeReference resolveType(XExpression element, Class<?> clazz) { LightweightTypeReference elementType = batchTypeResolver.resolveTypes(element).getActualType(element); return elementType != null && elementType.isType(clazz) ? elementType : null; }
/** * Determines if this type reference denotes the same type or a supertype of * the given {@code clazz}. */ public boolean isAssignableFrom(Class<?> clazz) { if (isType(clazz)) { return true; } JvmType type = findType(clazz); if (type == null) { return false; } return isAssignableFrom(type); }
@Override protected void doVisitWildcardTypeReference(WildcardTypeReference reference, StringBuilder param) { param.append("?"); if (reference.getLowerBound() != null) { param.append(" super "); reference.getLowerBound().accept(this, param); } else { List<LightweightTypeReference> upperBounds = reference.getUpperBounds(); if (!upperBounds.isEmpty()) { if (upperBounds.size() == 1 && upperBounds.get(0).isType(Object.class)) { return; } param.append(" extends "); for(int i = 0; i < upperBounds.size(); i++) { if (i != 0) { param.append(" & "); } upperBounds.get(i).accept(this, param); } } } }
/** * Determines if this type reference denotes the same type or a subtype of * the given {@code clazz}. */ public boolean isSubtypeOf(Class<?> clazz) { if (isType(clazz)) { return true; } // TODO interfaces don't inherit from non-interfaces, primitives, arrays, object // A final type does not have any subtypes JvmType type = findType(clazz); if (type == null) { return false; } return isSubtypeOf(type); }
@Check public void checkOperandTypesForTripleEquals(XBinaryOperation binaryOperation) { if(isTripleEqualsOperation(binaryOperation)){ LightweightTypeReference left = getActualType(binaryOperation.getLeftOperand()); LightweightTypeReference right = getActualType(binaryOperation.getRightOperand()); if(left.isArray() != right.isArray()) { if (left.isArray()) { if (right.isAny() || right.isType(Object.class) || right.isType(Serializable.class) || right.isType(Cloneable.class)) { return; } } else { if (left.isAny() || left.isType(Object.class) || left.isType(Serializable.class) || left.isType(Cloneable.class)) { return; } } error("Incompatible operand types " + left.getHumanReadableName() + " and " + right.getHumanReadableName(), null, INVALID_OPERAND_TYPES); } } }
public void _toJavaExpression(RichString richString, ITreeAppendable b) { b.append(getVarName(richString, b)); if(getLightweightType(richString).isType(String.class)) b.append(".toString()"); }
protected void _computeTypes(final QuantityLiteral assignment, ITypeComputationState state) { LightweightTypeReference qt = null; for (ITypeExpectation exp : state.getExpectations()) { if (exp.getExpectedType() == null) { continue; } if (exp.getExpectedType().isType(Number.class)) { qt = getRawTypeForName(Number.class, state); } if (exp.getExpectedType().isType(State.class)) { qt = getRawTypeForName(Number.class, state); } if (exp.getExpectedType().isType(Command.class)) { qt = getRawTypeForName(Number.class, state); } } if (qt == null) { qt = getRawTypeForName(QuantityType.class, state); } state.acceptActualType(qt); }
protected void initializeConstraintMapping(JvmTypeParameter typeParameter, UnboundTypeParameterPreservingSubstitutor substitutor, UnboundTypeReference typeReference) { if (!typeReference.internalIsResolved()) { List<JvmTypeConstraint> constraints = typeParameter.getConstraints(); for(JvmTypeConstraint constraint: constraints) { JvmTypeReference constraintReference = constraint.getTypeReference(); if (constraintReference != null) { LightweightTypeReference substitute = substitutor.substitute(constraintReference); if (!substitute.isType(Object.class) && !substitute.isPrimitiveVoid()) { typeReference.acceptHint(substitute, BoundTypeArgumentSource.CONSTRAINT, constraint, VarianceInfo.OUT, VarianceInfo.OUT); } } } } }
/** * @since 2.4 */ protected void toJavaExpression(XStringLiteral literal, ITreeAppendable appendable, boolean useUnicodeEscapes) { LightweightTypeReference type = getLightweightType(literal); if (type.isType(Character.TYPE)) { String javaString = Strings.convertToJavaString(literal.getValue(), useUnicodeEscapes); appendable.append("'").append(javaString).append("'"); } else if (type.isType(Character.class)) { String javaString = Strings.convertToJavaString(literal.getValue(), useUnicodeEscapes); appendable.append("Character.valueOf('").append(javaString).append("')"); } else { String javaString = Strings.convertToJavaString(literal.getValue(), useUnicodeEscapes); appendable.append("\"").append(javaString).append("\""); } }
/** * Same as {@link LightweightTypeReference#isSubtypeOf(Class)} but does not accept synonym types as subtypes. */ protected boolean isSubtypeButNotSynonym(LightweightTypeReference expectation, Class<?> clazz) { if (expectation.isType(clazz)) { return true; } ITypeReferenceOwner owner = expectation.getOwner(); JvmType declaredType = owner.getServices().getTypeReferences().findDeclaredType(clazz, owner.getContextResourceSet()); if (declaredType == null) { return false; } LightweightTypeReference superType = owner.newParameterizedTypeReference(declaredType); // don't allow synonyms, e.g. Iterable is not considered to be a supertype of Functions.Function0 boolean result = superType.isAssignableFrom(expectation.getRawTypeReference(), new TypeConformanceComputationArgument(false, false, true, true, false, false)); return result; }
protected int doIsConformant(LightweightTypeReference left, UnboundTypeReference right, int flags) { if (left.getType() == right.getType() || left.isType(Object.class)) { return flags | SUCCESS; } if ((flags & ALLOW_UNBOXING) == 0 && left.isPrimitive()) { return flags; } boolean doesNotHaveSignificantHints = false; if (((flags & RAW_TYPE) == 0) && (right.canResolveTo(left) || (flags & AS_TYPE_ARGUMENT) != 0 && (doesNotHaveSignificantHints = !right.hasSignificantHints()))) { if ((flags & UNBOUND_COMPUTATION_ADDS_HINTS) != 0 && doesNotHaveSignificantHints) { right.acceptHint(left, BoundTypeArgumentSource.INFERRED_LATER, left, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT); } return flags | SUCCESS; } right.tryResolve(false); LightweightTypeReference resolvedTo = right.getResolvedTo(); if (resolvedTo != null) { return doIsConformant(left, resolvedTo, flags); } return flags; }