@Override
  public void handle(
      final AnnotationValues<ListenerSupport> annotation,
      final JCAnnotation source,
      final JavacNode annotationNode) {
    deleteAnnotationIfNeccessary(annotationNode, ListenerSupport.class);

    JavacType type = JavacType.typeOf(annotationNode, source);
    if (type.isAnnotation() || type.isInterface()) {
      annotationNode.addError(canBeUsedOnClassAndEnumOnly(ListenerSupport.class));
      return;
    }

    List<Object> listenerInterfaces = annotation.getActualExpressions("value");
    if (listenerInterfaces.isEmpty()) {
      annotationNode.addError(
          String.format(
              "@%s has no effect since no interface types were specified.",
              ListenerSupport.class.getName()));
      return;
    }
    List<TypeSymbol> resolvedInterfaces =
        resolveInterfaces(annotationNode, ListenerSupport.class, listenerInterfaces);
    for (TypeSymbol interfaze : resolvedInterfaces) {
      handler.addListenerField(type, interfaze);
      handler.addAddListenerMethod(type, interfaze);
      handler.addRemoveListenerMethod(type, interfaze);
      addFireListenerMethods(type, interfaze);
    }

    type.editor().rebuild();
  }
 private List<TypeSymbol> resolveInterfaces(
     final JavacNode annotationNode,
     final Class<? extends java.lang.annotation.Annotation> annotationType,
     final List<Object> listenerInterfaces) {
   List<TypeSymbol> resolvedInterfaces = new ArrayList<TypeSymbol>();
   for (Object listenerInterface : listenerInterfaces) {
     if (listenerInterface instanceof JCFieldAccess) {
       JCFieldAccess interfaze = (JCFieldAccess) listenerInterface;
       if ("class".equals(As.string(interfaze.name))) {
         Type interfaceType = CLASS.resolveMember(annotationNode, interfaze.selected);
         if (interfaceType == null) continue;
         if (interfaceType.isInterface()) {
           TypeSymbol interfaceSymbol = interfaceType.asElement();
           if (interfaceSymbol != null) resolvedInterfaces.add(interfaceSymbol);
         } else {
           annotationNode.addWarning(
               String.format(
                   "@%s works only with interfaces. %s was skipped",
                   annotationType.getName(), listenerInterface));
         }
       }
     }
   }
   return resolvedInterfaces;
 }
Beispiel #3
0
 public void addSelectAlias(String alias, String spacedAlias) {
   selectAliases.add(alias);
   if (!StringUtils.isBlank(spacedAlias)) {
     selectFinalAliases.add("`" + spacedAlias + "`");
   } else {
     selectFinalAliases.add(alias);
   }
 }
Beispiel #4
0
  private void getQLString(
      QBJoinTree joinTree,
      StringBuilder builder,
      CandidateFact fact,
      Map<Dimension, CandidateDim> dimsToQuery)
      throws LensException {
    List<String> joiningTables = new ArrayList<>();
    if (joinTree.getBaseSrc()[0] == null) {
      if (joinTree.getJoinSrc() != null) {
        getQLString(joinTree.getJoinSrc(), builder, fact, dimsToQuery);
      }
    } else { // (joinTree.getBaseSrc()[0] != null){
      String alias = joinTree.getBaseSrc()[0].toLowerCase();
      builder.append(getStorageStringWithAlias(fact, dimsToQuery, alias));
      joiningTables.add(alias);
    }
    if (joinTree.getJoinCond() != null) {
      builder.append(JoinUtils.getJoinTypeStr(joinTree.getJoinCond()[0].getJoinType()));
      builder.append(" JOIN ");
    }
    if (joinTree.getBaseSrc()[1] == null) {
      if (joinTree.getJoinSrc() != null) {
        getQLString(joinTree.getJoinSrc(), builder, fact, dimsToQuery);
      }
    } else { // (joinTree.getBaseSrc()[1] != null){
      String alias = joinTree.getBaseSrc()[1].toLowerCase();
      builder.append(getStorageStringWithAlias(fact, dimsToQuery, alias));
      joiningTables.add(alias);
    }

    String joinCond = joinConds.get(joinTree);
    if (joinCond != null) {
      builder.append(" ON ");
      builder.append(joinCond);
      // joining tables will contain all tables involved in joins.
      // we need to push storage filters for Dimensions into join conditions, thus the following
      // code
      // takes care of the same.
      for (String joiningTable : joiningTables) {
        if (cubeTbls.get(joiningTable) instanceof Dimension) {
          DimOnlyHQLContext.appendWhereClause(
              builder, getWhereClauseWithAlias(dimsToQuery, joiningTable), true);
          dimsToQuery.get(cubeTbls.get(joiningTable)).setWhereClauseAdded(joiningTable);
        }
      }
    } else {
      throw new LensException(LensCubeErrorCode.NO_JOIN_CONDITION_AVAILABLE.getLensErrorInfo());
    }
  }
Beispiel #5
0
 @Override
 public void setTypeVariables(List<TypeVariable> typeVariables) {
   declaration.setTypeParameters(
       typeVariables
           .stream()
           .map(getContext()::unresolveTypeVariable)
           .collect(Collectors.toList()));
 }
 @Override
 protected void createParamsAndArgs(
     final Object method, final List<Argument> params, final List<Expression<?>> args) {
   MethodType mtype = (MethodType) type(method);
   if (mtype.argtypes.isEmpty()) return;
   int argCounter = 0;
   for (Type parameter : mtype.getParameterTypes()) {
     String arg = "arg" + argCounter++;
     params.add(Arg(Type(parameter), arg));
     args.add(Name(arg));
   }
 }
Beispiel #7
0
 public Call withTypeArgument(final TypeRef typeArg) {
   typeArgs.add(child(typeArg));
   return this;
 }
Beispiel #8
0
 private List<Annotation> getAnnotationsInternal(List<AnnotationExpr> l) {
   return l.stream()
       .map(AnnotationParser::annotationFromAnnotationExpr)
       .collect(Collectors.toList());
 }
Beispiel #9
0
 public String getSelectFinalAlias(int index) {
   return selectFinalAliases.get(index);
 }