Пример #1
0
  private void setScriptURIOnField(final FieldNode fieldNode, final AnnotationNode node) {
    if (fieldNode.hasInitialExpression()) {
      addError(
          "Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", fieldNode);
      return;
    }

    URI uri = getSourceURI(node);

    if (uri == null) {
      addError("Unable to get the URI for the source of this class!", fieldNode);
    } else {
      // Set the RHS to '= URI.create("string for this URI")'.
      // That may throw an IllegalArgumentExpression wrapping the URISyntaxException.
      fieldNode.setInitialValueExpression(getExpression(uri));
    }
  }
 public static Statement createConstructorStatementDefault(FieldNode fNode) {
   final String name = fNode.getName();
   final ClassNode fType = fNode.getType();
   final Expression fieldExpr = propX(varX("this"), name);
   Expression initExpr = fNode.getInitialValueExpression();
   Statement assignInit;
   if (initExpr == null
       || (initExpr instanceof ConstantExpression
           && ((ConstantExpression) initExpr).isNullExpression())) {
     if (ClassHelper.isPrimitiveType(fType)) {
       assignInit = EmptyStatement.INSTANCE;
     } else {
       assignInit = assignS(fieldExpr, ConstantExpression.EMPTY_EXPRESSION);
     }
   } else {
     assignInit = assignS(fieldExpr, initExpr);
   }
   fNode.setInitialValueExpression(null);
   Expression value = findArg(name);
   return ifElseS(equalsNullX(value), assignInit, assignS(fieldExpr, castX(fType, value)));
 }
 private void initializeField(FieldNode fieldNode, Expression init) {
   if (!fieldNode.hasInitialExpression()) fieldNode.setInitialValueExpression(init);
 }