Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * JBoss, Home of Professional Open Source
   * Copyright 2012, 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
  * 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.util.reflection;
 import java.util.Map;
Builds a special TypeResolver capable of resolving type variables by using a combination of two type hierarchies. The special resolver is only necessary for situations where the type of the event object contains an unresolved type variable which cannot be resolved using the selected event type because the selected event type is a subtype of the event object. For example: private Event<List<String>> event; ArrayList<String>()); The event object type is java.util.ArrayList (raw type due to type erasure) The selected type is List<String> We cannot simply infer the correct type (ArrayList<String>) from the runtime type nor from the selected type. What this special resolver does is that it combines the following type variable assignments: L -> E L -> String and resolves E to String. The resolver is capable of doing it recursively for parameterized types.

Jozef Hartinger
     private final Map<TypeVariable<?>, TypeselectedTypeVariables;
     private final Map<TypeVariable<?>, TypeeventTypeVariables;
     private final Map<TypeVariable<?>, TyperesolvedTypes;
     public EventObjectTypeResolverBuilder(Map<TypeVariable<?>, TypeselectedTypeVariables,
             Map<TypeVariable<?>, TypeeventTypeVariables) {
         this. = selectedTypeVariables;
         this. = eventTypeVariables;
         this. = new HashMap<TypeVariable<?>, Type>();
     public TypeResolver build() {
         Map<TypeVariable<?>, TypemergedVariables = new HashMap<TypeVariable<?>, Type>();
         return new TypeResolver(mergedVariables);
     protected void resolveTypeVariables() {
         for (Entry<TypeVariable<?>, Typeentry : .entrySet()) {
             // the event object does not have this variable resolved
             TypeVariable<?> key = entry.getKey();
             Type typeWithTypeVariables = entry.getValue();
             Type value = .get(key);
             if (value == null) {
     protected void resolveTypeVariables(Type type1Type type2) {
         if (type1 instanceof TypeVariable<?>) {
             resolveTypeVariables((TypeVariable<?>) type1type2);
         if (type1 instanceof ParameterizedType) {
     protected void resolveTypeVariables(TypeVariable<?> type1Type type2) {
        if (type2 instanceof TypeVariable) {
            // we cannot resolve this
    protected void resolveTypeVariables(ParameterizedType type1Type type2) {
        if (type2 instanceof ParameterizedType) {
            Type[] type1Arguments = type1.getActualTypeArguments();
            Type[] type2Arguments = ((ParameterizedTypetype2).getActualTypeArguments();
            if (type1Arguments.length == type2Arguments.length) {
                for (int i = 0; i < type1Arguments.lengthi++) {
                    resolveTypeVariables(type1Arguments[i], type2Arguments[i]);
    public Map<TypeVariable<?>, TypegetResolvedTypes() {
        return ;
New to GrepCode? Check out our FAQ X