@Override
 public void processAnnotationRemoved(
     ApplicationMetaModel metaModel, AnnotationKey key, AnnotationState removed) {
   ElementHandle.Package pkg = metaModel.getHandle();
   if (key.getElement().getPackage().equals(pkg.getPackage())) {
     servlets.remove(pkg);
   }
 }
 @Override
 public void processAnnotationAdded(
     ModuleMetaModel metaModel, AnnotationKey key, AnnotationState added) {
   if (key.getType().equals(APPLICATION)) {
     ElementHandle.Package pkg = (ElementHandle.Package) key.getElement();
     String name = (String) added.get("name");
     add(metaModel, pkg, name);
   }
 }
 @Override
 public void processAnnotationRemoved(
     ModuleMetaModel metaModel, AnnotationKey key, AnnotationState removed) {
   if (key.getType().equals(APPLICATION)) {
     ElementHandle.Package pkg = (ElementHandle.Package) key.getElement();
     ApplicationMetaModel mm = metaModel.getChild(Key.of(pkg, ApplicationMetaModel.class));
     if (mm != null) {
       context.remove(mm);
       mm.remove();
     }
   }
 }
 @Override
 public void processAnnotationUpdated(
     ModuleMetaModel metaModel,
     AnnotationKey key,
     AnnotationState removed,
     AnnotationState added) {
   if (key.getType().equals(APPLICATION)) {
     ElementHandle.Package pkg = (ElementHandle.Package) key.getElement();
     ApplicationMetaModel application =
         metaModel.getChild(Key.of(pkg, ApplicationMetaModel.class));
     application.modified = true;
   }
 }
Пример #5
0
  void addMethod(ModuleMetaModel context, AnnotationKey key2, AnnotationState annotation) {

    //
    String id = (String) annotation.get("id");

    ExecutableElement methodElt =
        (ExecutableElement) context.processingContext.get(key2.getElement());

    //
    for (Phase phase : Phase.values()) {
      if (phase.annotation.getName().equals(key2.getType().toString())) {
        ElementHandle.Method origin = (ElementHandle.Method) key2.getElement();

        // First remove the previous method
        Key<MethodMetaModel> key = Key.of(origin, MethodMetaModel.class);
        if (getChild(key) == null) {
          // Parameters
          ArrayList<ParameterMetaModel> parameters = new ArrayList<ParameterMetaModel>();
          List<? extends TypeMirror> parameterTypeMirrors =
              ((ExecutableType) methodElt.asType()).getParameterTypes();
          List<? extends VariableElement> parameterVariableElements = methodElt.getParameters();
          for (int i = 0; i < parameterTypeMirrors.size(); i++) {
            VariableElement parameterVariableElt = parameterVariableElements.get(i);
            TypeMirror parameterTypeMirror = parameterTypeMirrors.get(i);
            String typeLiteral = context.processingContext.getLiteralName(parameterTypeMirror);

            //
            String parameterName = parameterVariableElt.getSimpleName().toString();

            // Determine cardinality
            TypeMirror parameterSimpleTypeMirror;
            Cardinality parameterCardinality;
            switch (parameterTypeMirror.getKind()) {
              case DECLARED:
                DeclaredType dt = (DeclaredType) parameterTypeMirror;
                TypeElement col = context.processingContext.getTypeElement("java.util.List");
                TypeMirror tm = context.processingContext.erasure(col.asType());
                TypeMirror err = context.processingContext.erasure(dt);
                // context.env.isSubtype(err, tm)
                if (err.equals(tm)) {
                  if (dt.getTypeArguments().size() != 1) {
                    throw CONTROLLER_METHOD_PARAMETER_NOT_RESOLVED.failure(parameterVariableElt);
                  } else {
                    parameterCardinality = Cardinality.LIST;
                    parameterSimpleTypeMirror = dt.getTypeArguments().get(0);
                  }
                } else {
                  parameterCardinality = Cardinality.SINGLE;
                  parameterSimpleTypeMirror = parameterTypeMirror;
                }
                break;
              case ARRAY:
                // Unwrap array
                ArrayType arrayType = (ArrayType) parameterTypeMirror;
                parameterCardinality = Cardinality.ARRAY;
                parameterSimpleTypeMirror = arrayType.getComponentType();
                break;
              default:
                throw CONTROLLER_METHOD_PARAMETER_NOT_RESOLVED.failure(parameterVariableElt);
            }
            if (parameterSimpleTypeMirror.getKind() != TypeKind.DECLARED) {
              throw CONTROLLER_METHOD_PARAMETER_NOT_RESOLVED.failure(parameterVariableElt);
            }

            //
            TypeElement te =
                (TypeElement) context.processingContext.asElement(parameterSimpleTypeMirror);
            ElementHandle.Type a = ElementHandle.Type.create(te);

            //
            if (te.toString().equals("java.lang.String")
                || te.getAnnotation(Mapped.class) != null) {
              // Not sure we should use @Param for this (i.e for now it looks hackish)
              // however it does make sense later to use the regex part for non router
              // parameters
              Param param = parameterVariableElt.getAnnotation(Param.class);
              String alias = param != null && param.name().length() > 0 ? param.name() : null;
              parameters.add(
                  new PhaseParameterMetaModel(
                      parameterName, parameterCardinality, a, typeLiteral, alias));
            } else {
              parameters.add(new ContextualParameterMetaModel(parameterName, typeLiteral));
            }
          }

          //
          MethodMetaModel method =
              new MethodMetaModel(
                  origin, id, phase, methodElt.getSimpleName().toString(), parameters);
          addChild(key, method);
          modified = true;
        }
        break;
      }
    }
  }