コード例 #1
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);
            }
          }
        }
      }
    }
コード例 #2
0
  @Override
  public void doPush(Symbol<?> symbol, SymbolTable table) {

    Node n = symbol.getLocation();
    if (n != null) {
      if (n instanceof ClassOrInterfaceDeclaration || n instanceof ObjectCreationExpr) {
        ProcessGenerics<?> gen = new ProcessGenerics<Object>(symbol, table);
        n.accept(gen, null);
      }
    }
  }
コード例 #3
0
    @Override
    public void visit(ClassOrInterfaceDeclaration declaration, A ctx) {
      List<TypeParameter> typeParams = declaration.getTypeParameters();
      SymbolType thisType = symbol.getType();

      load(table, typeParams, thisType);

      if (!declaration.isInterface()) {
        List<ClassOrInterfaceType> extendsList = declaration.getExtends();
        if (extendsList != null && !extendsList.isEmpty()) {
          processSuperGenerics(table, symbol, extendsList.get(0));
        }
      }
    }