Example #1
0
 public void genConversionOperation(
     FixedPrecisionType type, Context ctx, TabbedWriter out, AsExpression arg) {
   Type toType = arg.getEType();
   Type fromType = arg.getObjectExpr().getType();
   if ((arg.getConversionOperation() != null) && TypeUtils.isNumericType(fromType)) {
     if (needsConversion(fromType, toType)
         && CommonUtilities.proceedWithConversion(ctx, arg.getConversionOperation())) {
       out.print(ctx.getNativeImplementationMapping(toType) + '.');
       out.print(CommonUtilities.getOpName(ctx, arg.getConversionOperation()));
       out.print("(");
       Expression objectExpr = arg.getObjectExpr();
       if (objectExpr instanceof BoxingExpression) {
         objectExpr = ((BoxingExpression) objectExpr).getExpr();
       }
       ctx.invoke(genExpression, objectExpr, ctx, out);
       ctx.invoke(genTypeDependentOptions, arg.getEType(), ctx, out, arg);
       out.print(")");
     } else {
       ctx.invoke(genExpression, arg.getObjectExpr(), ctx, out);
     }
   } else {
     // we need to invoke the logic in type template to call back to the other conversion
     // situations
     ctx.invokeSuper(this, genConversionOperation, type, ctx, out, arg);
   }
 }
Example #2
0
 protected boolean needsConversion(Operation conOp) {
   boolean result = true;
   Type fromType = conOp.getParameters().get(0).getType();
   Type toType = conOp.getReturnType();
   // don't convert matching types
   if (CommonUtilities.getEglNameForTypeCamelCase(toType)
       .equals(CommonUtilities.getEglNameForTypeCamelCase(fromType))) result = false;
   if (toType.getTypeSignature().equalsIgnoreCase("eglx.lang.ENumber")) result = true;
   else if (TypeUtils.isNumericType(fromType)
       && (TypeUtils.Type_DECIMAL.equals(fromType) || TypeUtils.Type_MONEY.equals(fromType)))
     result = conOp.isNarrowConversion();
   return result;
 }
  public void validate(
      Node errorNode,
      Node target,
      Element targetElement,
      Map<String, Object> allAnnotationsAndFields,
      IProblemRequestor problemRequestor,
      ICompilerOptions compilerOptions) {
    Type type = null;
    if (targetElement instanceof Type) {
      type = (Type) targetElement;
    } else if (targetElement instanceof TypedElement) {
      type = ((TypedElement) targetElement).getType();
    }

    if (type == null) {
      return;
    }

    // Numerics cannot have decimals.
    if (type instanceof FixedPrecisionType) {
      if (((FixedPrecisionType) type).getDecimals() > 0) {
        problemRequestor.acceptProblem(
            errorNode,
            RUIResourceKeys.PROPERTY_INVALID_FOR_DECIMALS,
            IMarker.SEVERITY_ERROR,
            new String[] {IEGLConstants.PROPERTY_TIMEFORMAT},
            RUIResourceKeys.getResourceBundleForKeys());
      }
      return;
    }

    if (type instanceof ParameterizedType) {
      type = ((ParameterizedType) type).getParameterizableType();
    }

    // string, time, and numerics are valid. everything else is invalid.
    if (TypeUtils.Type_STRING.equals(type)
        || TypeUtils.Type_TIME.equals(type)
        || TypeUtils.isNumericType(type)) {
      return;
    }

    problemRequestor.acceptProblem(
        errorNode,
        RUIResourceKeys.PROPERTY_INVALID_FOR_TYPE,
        IMarker.SEVERITY_ERROR,
        new String[] {
          IEGLConstants.PROPERTY_TIMEFORMAT, BindingUtil.getShortTypeString(type, false)
        },
        RUIResourceKeys.getResourceBundleForKeys());
  }
Example #4
0
  private void fillPageDataModel(EGLEditor editor, PageDataModel model) {
    if (editor != null) {
      IEditorInput editorInput = editor.getEditorInput();
      if (editorInput instanceof FileEditorInput) {
        FileEditorInput fileEditorInput = (FileEditorInput) editorInput;

        // process handler
        HandlerFieldsResolver handlerFieldsResolver =
            new HandlerFieldsResolver(fileEditorInput.getFile());
        handlerFieldsResolver.resolve();
        Handler handler = handlerFieldsResolver.getRUIHandler();
        if (handler != null) {
          HandlerPageDataNode handlerPageDataNode =
              (HandlerPageDataNode)
                  PageDataNodeFactory.newPageDataNode(
                      getName(handler), PageDataNodeFactory.HANDLER_PAGE_DATA_NODE);
          model.addRootPageDataNode(handlerPageDataNode);

          // process class fields
          List contents = handler.getContents();
          for (int i = 0; i < contents.size(); i++) {
            if (contents.get(i) instanceof ClassDataDeclaration) {
              ClassDataDeclaration classDataDeclaration = (ClassDataDeclaration) contents.get(i);
              List names = classDataDeclaration.getNames();
              for (int j = 0; j < names.size(); j++) {
                Object oName = names.get(j);
                if (oName instanceof SimpleName) {
                  SimpleName simpleName = (SimpleName) oName;
                  Member dataBinding = simpleName.resolveMember();
                  Type typeBinding = simpleName.resolveType();
                  if (dataBinding != null) {
                    if (typeBinding != null && isAcceptType(typeBinding)) {
                      if (typeBinding instanceof ParameterizedType) {
                        typeBinding = ((ParameterizedType) typeBinding).getParameterizableType();
                      }

                      // Single
                      if (TypeUtils.isPrimitive(typeBinding)
                          //													|| typeBinding.getKind() == ITypeBinding.DATAITEM_BINDING
                          || typeBinding instanceof Record) {
                        if (!TypeUtils.Type_ANY.equals(typeBinding)) {
                          DataFieldPageDataNode dataFieldPageDataNode = null;
                          if (classDataDeclaration.isPrivate()) {
                            dataFieldPageDataNode =
                                (DataFieldPageDataNode)
                                    PageDataNodeFactory.newPageDataNode(
                                        getName(dataBinding),
                                        PageDataNodeFactory.DATA_FIELD_PAGE_DATA_NODE_PRIVATE);
                          } else {
                            dataFieldPageDataNode =
                                (DataFieldPageDataNode)
                                    PageDataNodeFactory.newPageDataNode(
                                        getName(dataBinding),
                                        PageDataNodeFactory.DATA_FIELD_PAGE_DATA_NODE_PUBLIC);
                          }
                          dataFieldPageDataNode.setDataBindingName(
                              dataBinding.getCaseSensitiveName());
                          handlerPageDataNode.addChild(dataFieldPageDataNode);
                        }
                      }
                      // Array
                      if (typeBinding instanceof ArrayType) {
                        ArrayType arrayTypeBinding = (ArrayType) typeBinding;
                        Type elementTypeBinding = arrayTypeBinding.getElementType();
                        if (TypeUtils.isPrimitive(elementTypeBinding)
                            //														|| elementTypeBinding.getKind() ==
                            // ITypeBinding.DATAITEM_BINDING
                            || elementTypeBinding instanceof Record) {
                          if (!TypeUtils.Type_ANY.equals(elementTypeBinding)) {
                            DataFieldPageDataNode dataFieldPageDataNode = null;
                            if (classDataDeclaration.isPrivate()) {
                              dataFieldPageDataNode =
                                  (DataFieldPageDataNode)
                                      PageDataNodeFactory.newPageDataNode(
                                          getName(dataBinding),
                                          PageDataNodeFactory.DATA_FIELD_PAGE_DATA_NODE_PRIVATE);
                            } else {
                              dataFieldPageDataNode =
                                  (DataFieldPageDataNode)
                                      PageDataNodeFactory.newPageDataNode(
                                          getName(dataBinding),
                                          PageDataNodeFactory.DATA_FIELD_PAGE_DATA_NODE_PUBLIC);
                            }
                            dataFieldPageDataNode.setDataBindingName(
                                dataBinding.getCaseSensitiveName());
                            handlerPageDataNode.addChild(dataFieldPageDataNode);
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
Example #5
0
 protected boolean needsConversion(Type fromType, Type toType) {
   boolean result = true;
   if (TypeUtils.isNumericType(fromType) && !CommonUtilities.needsConversion(fromType, toType))
     result = !CommonUtilities.isJavaScriptBigDecimal(toType);
   return result;
 }