/** Replies if the given closure could be represented by an not static anonymous class. * * @param closure the closure. * @param typeRef the type of the closure. * @param operation the operation to implement. * @return {@code true} if the given closure could be represented by a not-static anonymous class. * @since 0.8.6 */ @SuppressWarnings("static-method") protected boolean canBeNotStaticAnonymousClass(XClosure closure, LightweightTypeReference typeRef, JvmOperation operation) { return !typeRef.isSubtypeOf(Serializable.class); }
protected boolean hasUnhandledException(List<LightweightTypeReference> thrownExceptions, Collection<JvmTypeReference> declaredExceptions) { for(LightweightTypeReference thrownException: thrownExceptions) { if (!thrownException.isSubtypeOf(RuntimeException.class) && !thrownException.isSubtypeOf(Error.class)) { if (isUnhandledException(thrownException, declaredExceptions)) { return true; } } } return false; }
/** * Determine whether the given switch expression is valid for Java version 6 or lower. */ public boolean isJavaSwitchExpression(final XSwitchExpression it) { boolean _xblockexpression = false; { final LightweightTypeReference switchType = this.getSwitchVariableType(it); if ((switchType == null)) { return false; } boolean _isSubtypeOf = switchType.isSubtypeOf(Integer.TYPE); if (_isSubtypeOf) { return true; } boolean _isSubtypeOf_1 = switchType.isSubtypeOf(Enum.class); if (_isSubtypeOf_1) { return true; } _xblockexpression = false; } return _xblockexpression; }
protected boolean isUnhandledException(LightweightTypeReference thrownException, Collection<JvmTypeReference> declaredExceptions) { for(JvmTypeReference declaredException: declaredExceptions) { if (thrownException.isSubtypeOf(declaredException.getType())) { return false; } } return true; }
public boolean isConformant(final EObject context, final Class<?> expected, final JvmTypeReference actual) { boolean _xblockexpression = false; { final LightweightTypeReference actualType = this.toLightweightTypeReference(actual, context); _xblockexpression = actualType.isSubtypeOf(expected); } return _xblockexpression; }
@Override protected boolean canCompileToJavaLambda(XClosure closure, LightweightTypeReference typeRef, JvmOperation operation) { // This function overrides the super one in order to avoid the generation of a Java 8 lambda when // the implemented interface is serializable. In this case, it will avoid issue for serialization and // deserialization of the closure. return !typeRef.isSubtypeOf(Serializable.class) && super.canCompileToJavaLambda(closure, typeRef, operation); }
/** Replies if the given JVM element is a SARL behavior. * * @param type the JVM type to test. * @return {@code true} if the given type is a SARL behavior, or not. * @since 0.8 */ public boolean isSarlBehavior(LightweightTypeReference type) { return !type.isInterfaceType() && (getSarlElementEcoreType(type) == SarlPackage.SARL_BEHAVIOR || type.isSubtypeOf(Behavior.class)); }
/** Replies if the given JVM element is a SARL agent. * * @param type the JVM type to test. * @return {@code true} if the given type is a SARL agent, or not. * @since 0.8 */ public boolean isSarlAgent(LightweightTypeReference type) { return !type.isInterfaceType() && (getSarlElementEcoreType(type) == SarlPackage.SARL_AGENT || type.isSubtypeOf(Agent.class)); }
/** Replies if the given JVM element is a SARL event. * * @param type the JVM type to test. * @return {@code true} if the given type is a SARL event, or not. * @since 0.8 */ public boolean isSarlEvent(LightweightTypeReference type) { return !type.isInterfaceType() && (getSarlElementEcoreType(type) == SarlPackage.SARL_EVENT || type.isSubtypeOf(Event.class)); }
@Override public void accept(LightweightTypeReference type) { for(LightweightTypeReference caughtException: caughtExceptions) { if (type.isSubtypeOf(caughtException.getType())) { return; } } delegate.accept(type); }
/** Replies if the given JVM element is a SARL capacity. * * @param type the JVM type to test. * @return {@code true} if the given type is a SARL capacity, or not. * @since 0.8 */ public boolean isSarlCapacity(LightweightTypeReference type) { return type.isInterfaceType() && (getSarlElementEcoreType(type) == SarlPackage.SARL_CAPACITY || type.isSubtypeOf(Capacity.class)); }
@Override public List<LightweightTypeReference> getIllegallyDeclaredExceptions() { if (getDeclaration().getExceptions().isEmpty()) return Collections.emptyList(); List<IResolvedOperation> overriddenAndImplemented = getOverriddenAndImplementedMethods(); if (overriddenAndImplemented.isEmpty()) return Collections.emptyList(); List<LightweightTypeReference> exceptions = getResolvedExceptions(); List<LightweightTypeReference> result = Lists.newArrayListWithCapacity(exceptions.size()); for(LightweightTypeReference exception: exceptions) { if (!exception.isSubtypeOf(RuntimeException.class) && !exception.isSubtypeOf(Error.class)) { if (isIllegallyDeclaredException(exception, overriddenAndImplemented)) { result.add(exception); } } } return result; }
/** Replies if the given JVM element is a SARL skill. * * @param type the JVM type to test. * @return {@code true} if the given type is a SARL skill, or not. * @since 0.8 */ public boolean isSarlSkill(LightweightTypeReference type) { return !type.isInterfaceType() && (getSarlElementEcoreType(type) == SarlPackage.SARL_SKILL || type.isSubtypeOf(Skill.class)); }
/** * 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); }
protected LightweightTypeReference getCollectionElementType(XCollectionLiteral literal) { LightweightTypeReference type = getLightweightType(literal); if (type == null) throw new IllegalStateException(); if(type.isArray()) { LightweightTypeReference result = type.getComponentType(); if (result == null) throw new IllegalStateException(); return result; } else if(type.isSubtypeOf(Collection.class) && type.hasTypeArguments()) { return type.getTypeArguments().get(0).getInvariantBoundSubstitute(); } return type.getOwner().newReferenceToObject(); }
@Override public boolean isImmutable(LightweightTypeReference type) { assert type != null; final LightweightTypeReference ref = type.getPrimitiveIfWrapperType(); if (ref.isArray()) { return false; } if (ref.isPrimitive() || ref.isPrimitiveVoid()) { return true; } for (final Class<?> jvmType : IMMUTABLE_TYPES) { if (type.isSubtypeOf(jvmType)) { return true; } } return false; }
@Check public void checkTypes(XCatchClause catchClause) { LightweightTypeReference parameterType = getActualType(catchClause, catchClause.getDeclaredParam()); if (parameterType != null && !parameterType.isSubtypeOf(Throwable.class)) { error("No exception of type " + parameterType.getHumanReadableName() + " can be thrown; an exception type must be a subclass of Throwable", catchClause.getDeclaredParam(), TypesPackage.Literals.JVM_FORMAL_PARAMETER__PARAMETER_TYPE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INCOMPATIBLE_TYPES); } }
/** * @param context unused in this context but required for dispatching * @param indicator unused in this context but required for dispatching */ @SuppressWarnings("unchecked") protected Object _doEvaluate(XNumberLiteral literal, IEvaluationContext context, CancelIndicator indicator) { IResolvedTypes resolvedTypes = typeResolver.resolveTypes(literal); LightweightTypeReference expectedType = resolvedTypes.getExpectedType(literal); Class<? extends Number> type = numberLiterals.getJavaType(literal); if (expectedType != null && expectedType.isSubtypeOf(Number.class)) { try { Class<?> expectedClassType = getJavaType(expectedType.toJavaCompliantTypeReference().getType()); if (expectedClassType.isPrimitive()) { expectedClassType = ReflectionUtil.getObjectType(expectedClassType); } if (Number.class != expectedClassType && Number.class.isAssignableFrom(expectedClassType)) { type = (Class<? extends Number>) expectedClassType; } } catch (ClassNotFoundException e) { } } return numberLiterals.numberValue(literal, type); }
protected Object wrapOrUnwrapArray(Object result, LightweightTypeReference expectedType) { if (expectedType.isArray() && !(result instanceof Object[])) { Class<?> arrayType; try { arrayType = getJavaType(expectedType.getComponentType().getType()); return Conversions.unwrapArray(result, arrayType); } catch (ClassNotFoundException e) { return result; } } else if (!expectedType.isArray() && expectedType.isSubtypeOf(Iterable.class)) { return Conversions.doWrapArray(result); } return result; }
/** Replies if the first parameter is a subtype of the second parameter. * * @param context the context. * @param subType the subtype to test. * @param superType the expected super type. * @return the type reference. */ @Pure protected boolean isSubTypeOf(EObject context, JvmTypeReference subType, JvmTypeReference superType) { if (isTypeReference(superType) && isTypeReference(subType)) { StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, context); LightweightTypeReferenceFactory factory = new LightweightTypeReferenceFactory(owner, false); LightweightTypeReference reference = factory.toLightweightReference(subType); return reference.isSubtypeOf(superType.getType()); } return false; }