コード例 #1
0
  public void load(SymbolTable table, List<TypeParameter> typeParams, SymbolType thisType) {
    if (typeParams != null && !typeParams.isEmpty()) {

      List<SymbolType> parameterizedTypes = new LinkedList<SymbolType>();
      for (TypeParameter tp : typeParams) {
        List<ClassOrInterfaceType> typeBounds = tp.getTypeBound();
        List<SymbolType> bounds = new LinkedList<SymbolType>();
        SymbolType st = null;
        if (typeBounds != null) {
          for (ClassOrInterfaceType type : typeBounds) {
            SymbolType paramType = ASTSymbolTypeResolver.getInstance().valueOf(type);
            if (paramType == null) {
              paramType = new SymbolType(Object.class);
            }
            bounds.add(paramType);
          }
          st = new SymbolType(bounds);

        } else {
          st = new SymbolType(Object.class);
        }
        st.setTemplateVariable(tp.getName());
        table.pushSymbol(tp.getName(), ReferenceType.TYPE_PARAM, st, tp);

        parameterizedTypes.add(st);
      }
      Map<String, SymbolType> typeParamsMap = table.getTypeParams();

      for (String key : typeParamsMap.keySet()) {
        SymbolType st = typeParamsMap.get(key);
        recursiveTemplateSubstitution(st, typeParamsMap);
      }

      if (thisType != null && !parameterizedTypes.isEmpty()) {
        thisType.setParameterizedTypes(parameterizedTypes);
      }
    }
  }
コード例 #2
0
    private void processSuperGenerics(
        SymbolTable table, Symbol<?> symbol, ClassOrInterfaceType type) {
      if (type != null) {

        Map<String, SymbolType> typeResolution = new HashMap<String, SymbolType>();

        ASTSymbolTypeResolver res = new ASTSymbolTypeResolver(typeResolution, table);
        SymbolType superType = type.accept(res, null);

        List<SymbolType> params = superType.getParameterizedTypes();
        Map<String, SymbolType> typeMapping = table.getTypeParams();
        if (params != null) {
          Symbol<?> superSymbol = symbol.getInnerScope().findSymbol("super");
          Scope innerScope = superSymbol.getInnerScope();

          Scope aux = null;

          if (innerScope != null) {
            aux = new Scope(superSymbol);

          } else {
            aux = new Scope();
          }
          superSymbol.setInnerScope(aux);

          table.pushScope(aux);

          Symbol<?> intermediateSuper =
              new Symbol("super", superSymbol.getType(), superSymbol.getLocation());

          if (innerScope != null) {
            intermediateSuper.setInnerScope(innerScope);
          }

          table.pushSymbol(intermediateSuper);

          // extends a parameterizable type
          TypeVariable<?>[] tps = superType.getClazz().getTypeParameters();
          for (int i = 0; i < tps.length; i++) {

            table.pushSymbol(tps[i].getName(), ReferenceType.TYPE_PARAM, params.get(i), null);
          }
          table.popScope(true);
        }
        Set<String> genericLetters = typeMapping.keySet();
        if (genericLetters != null) {
          for (String letter : genericLetters) {

            if (typeResolution.containsKey(letter)) {
              table.pushSymbol(letter, ReferenceType.TYPE, typeMapping.get(letter), null);
            }
          }
        }
      }
    }