public static EnergyType getEnergyTypeFromOrdinal(int ordinal) {
   if (ordinal == CORPOREAL.ordinal()) {
     return CORPOREAL;
   } else if (ordinal == KINETIC.ordinal()) {
     return KINETIC;
   } else if (ordinal == TEMPORAL.ordinal()) {
     return TEMPORAL;
   } else if (ordinal == ESSENTIA.ordinal()) {
     return ESSENTIA;
   } else if (ordinal == AMORPHOUS.ordinal()) {
     return AMORPHOUS;
   } else if (ordinal == VOID.ordinal()) {
     return VOID;
   } else if (ordinal == OMNI.ordinal()) {
     return OMNI;
   } else {
     return UNKNOWN;
   }
 }
Exemplo n.º 2
0
  public void delegateMethodsTo(
      TYPE_TYPE type,
      MethodDescriptor[] methodDescriptors,
      Expression<?> receiver,
      Map<String, String> methodMapper) {
    for (MethodDescriptor methodDesc : methodDescriptors) {
      List<TypeRef> argTypes = new ArrayList<>();
      List<Argument> methodArgs = new ArrayList<>();
      List<Expression<?>> callArgs = new ArrayList<>();
      int argCounter = 0;
      for (MethodDescriptor.Type argType : methodDesc.arguments) {
        String argName = "arg" + argCounter++;
        TypeRef argTypeRef = asTypeRef(argType);
        argTypes.add(argTypeRef);
        Argument arg = Arg(argTypeRef, argName);
        if (argType.annotations.length > 0) {
          List<Annotation> annotations = new ArrayList<>();
          for (int i = 0; i < argType.annotations.length; i++) {
            annotations.add(Annotation(asTypeRef(argType.annotations[i])));
          }
          arg.withAnnotations(annotations);
        }
        methodArgs.add(arg);
        callArgs.add(Name(argName));
      }

      if (type.hasMethodIncludingSupertypes(
          methodDesc.methodName, argTypes.toArray(new TypeRef[argTypes.size()]))) {
        continue;
      }

      String delegateMethodName = methodMapper.get(methodDesc.methodName);
      if (delegateMethodName == null) {
        delegateMethodName = methodDesc.methodName;
      }

      Call methodCall = Call(receiver, delegateMethodName).withArguments(callArgs);
      MethodDecl methodDecl =
          MethodDecl(asTypeRef(methodDesc.returnType), methodDesc.methodName)
              .makePublic()
              .withArguments(methodArgs);
      if (VOID.equals(methodDesc.returnType.type)) {
        methodDecl.withStatement(methodCall);
      } else {
        methodDecl.withStatement(Return(methodCall));
      }
      if (methodDesc.typeParameters.length > 0) {
        List<TypeParam> types = new ArrayList<>();
        for (int i = 0; i < methodDesc.typeParameters.length; i++) {
          types.add(asTypeParam(methodDesc.typeParameters[i]));
        }
        methodDecl.withTypeParameters(types);
      }
      if (methodDesc.exceptions.length > 0) {
        List<TypeRef> exceptions = new ArrayList<>();
        for (int i = 0; i < methodDesc.exceptions.length; i++) {
          exceptions.add(asTypeRef(methodDesc.exceptions[i]));
        }
        methodDecl.withThrownExceptions(exceptions);
      }
      if (methodDesc.annotations.length > 0) {
        List<Annotation> annotations = new ArrayList<>();
        for (int i = 0; i < methodDesc.annotations.length; i++) {
          annotations.add(Annotation(asTypeRef(methodDesc.annotations[i])));
        }
        methodDecl.withAnnotations(annotations);
      }

      type.editor().injectMethod(methodDecl);
    }
  }