Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2014, Red Hat, Inc., and individual contributors
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.jboss.weld.resolution;
 
 import java.util.Set;

Base class for AssignabilityRules implementations.

Author(s):
Jozef Hartinger
 
 public abstract class AbstractAssignabilityRules implements AssignabilityRules {
 
     @Override
     public boolean matches(Set<TyperequiredTypesSet<TypebeanTypes) {
         for (Type requiredType : requiredTypes) {
             if (matches(requiredTypebeanTypes)) {
                 return true;
             }
         }
         return false;
     }
 
     @Override
     public boolean matches(Type requiredTypeSet<? extends TypebeanTypes) {
         for (Type beanType : beanTypes) {
             if (matches(requiredTypebeanType)) {
                 return true;
             }
         }
         return false;
     }
 
     /*
      * TypeVariable bounds are treated specially - CDI assignability rules are applied.
      * Standard Java covariant assignability rules are applied to all other types of bounds.
      * This is not explicitly mentioned in the specification but is implied.
      */
     protected Type[] getUppermostTypeVariableBounds(TypeVariable<?> bound) {
         if (bound.getBounds()[0] instanceof TypeVariable<?>) {
             return getUppermostTypeVariableBounds((TypeVariable<?>) bound.getBounds()[0]);
         }
         return bound.getBounds();
     }
 
     private Type[] getUppermostBounds(Type[] bounds) {
         // if a type variable (or wildcard) declares a bound which is a type variable, it can declare no other bound
         if (bounds[0] instanceof TypeVariable<?>) {
             return getUppermostTypeVariableBounds((TypeVariable<?>) bounds[0]);
         }
         return bounds;
     }

    
Returns true iff for each upper bound T, there is at least one bound from stricterUpperBounds assignable to T. This reflects that stricterUpperBounds are at least as strict as upperBounds are.

Arguments passed to this method must be legal java bounds, i.e. bounds returned by java.lang.reflect.TypeVariable.getBounds(), java.lang.reflect.WildcardType.getUpperBounds() or java.lang.reflect.WildcardType.getLowerBounds().

 
     protected boolean boundsMatch(Type[] upperBoundsType[] stricterUpperBounds) {
         // getUppermostBounds to make sure that both arrays of bounds contain ONLY ACTUAL TYPES! otherwise, the CovariantTypes
         // assignability rules do not reflect our needs
         upperBounds = getUppermostBounds(upperBounds);
         stricterUpperBounds = getUppermostBounds(stricterUpperBounds);
         for (Type upperBound : upperBounds) {
             if (!CovariantTypes.isAssignableFromAtLeastOne(upperBoundstricterUpperBounds)) {
                 return false;
             }
         }
         return true;
     }
 
     protected boolean lowerBoundsOfWildcardMatch(Type parameterWildcardType requiredParameter) {
         return lowerBoundsOfWildcardMatch(new Type[] { parameter }, requiredParameter);
     }
 
     protected boolean lowerBoundsOfWildcardMatch(Type[] beanParameterBoundsWildcardType requiredParameter) {
         if (requiredParameter.getLowerBounds().length > 0) {
             Type[] lowerBounds = requiredParameter.getLowerBounds();
             if (!boundsMatch(beanParameterBoundslowerBounds)) {
                return false;
            }
        }
        return true;
    }
    protected boolean upperBoundsOfWildcardMatch(WildcardType requiredParameterType parameter) {
        return boundsMatch(requiredParameter.getUpperBounds(), new Type[] { parameter });
    }
New to GrepCode? Check out our FAQ X