Package lombok.ast

Examples of lombok.ast.IntegralLiteral


      Expression literal = null;
      switch (node.getKind()) {
      case INT_LITERAL:
        int intValue = ((Number)val).intValue();
        negative = intValue < 0;
        if (intValue == Integer.MIN_VALUE) literal = new IntegralLiteral().astIntValue(Integer.MIN_VALUE);
        else if (negative) literal = new IntegralLiteral().astIntValue(-intValue);
        else literal = new IntegralLiteral().astIntValue(intValue);
        break;
      case LONG_LITERAL:
        long longValue = ((Number)val).longValue();
        negative = longValue < 0;
        if (longValue == Long.MIN_VALUE) literal = new IntegralLiteral().astLongValue(Long.MIN_VALUE);
        else if (negative) literal = new IntegralLiteral().astLongValue(-longValue);
        else literal = new IntegralLiteral().astLongValue(longValue);
        break;
      case FLOAT_LITERAL:
        set(node, new FloatingPointLiteral().astFloatValue(((Number)val).floatValue()));
        return;
      case DOUBLE_LITERAL:
View Full Code Here


  public Node createBooleanLiteral(String raw) {
    return posify(new BooleanLiteral().rawValue(raw));
  }
 
  public Node createNumberLiteral(String raw) {
    if (raw == null) return posify(new IntegralLiteral());
   
    String v = raw.trim().toLowerCase();
   
    if (v.startsWith("0x")) {
      if (v.contains("p")) return posify(new FloatingPointLiteral().rawValue(raw));
      return posify(new IntegralLiteral().rawValue(raw));
    }
   
    if (v.contains(".") || v.endsWith("d") || v.endsWith("f") || v.contains("e")) {
      return posify(new FloatingPointLiteral().rawValue(raw));
    }
    else return posify(new IntegralLiteral().rawValue(raw));
  }
View Full Code Here

import org.junit.Test;

public class IntegralLiteralTest {
  @Test
  public void testBasics() {
    IntegralLiteral n = new IntegralLiteral().astIntValue(0);
    assertFalse(n.astMarkedAsLong());
    assertNull(n.getErrorReasonForValue());
    n.astLongValue(0);
    assertTrue(n.astMarkedAsLong());
    assertNull(n.getErrorReasonForValue());
  }
View Full Code Here

    assertNull(n.getErrorReasonForValue());
  }
 
  @Test
  public void testIntMinValue() {
    IntegralLiteral n = new IntegralLiteral().astIntValue(Integer.MIN_VALUE);
    testMinValue(n);
  }
View Full Code Here

    testMinValue(n);
  }
 
  @Test
  public void testLongMinValue() {
    IntegralLiteral n = new IntegralLiteral().astLongValue(Long.MIN_VALUE);
    testMinValue(n);
  }
View Full Code Here

    assertNotNull(n.getErrorReasonForValue());
  }
 
  @Test
  public void testIntNegativeValue() {
    IntegralLiteral n = new IntegralLiteral().astIntValue(-1);
    testNegativeValue(n);
  }
View Full Code Here

    testNegativeValue(n);
  }
 
  @Test
  public void testLongNegativeValue() {
    IntegralLiteral n = new IntegralLiteral().astLongValue(-1L);
    testNegativeValue(n);
  }
View Full Code Here

    assertNotNull(n.getErrorReasonForValue());
  }
 
  @Test
  public void testToRaw() {
    IntegralLiteral n = new IntegralLiteral().astLongValue(32);
    assertEquals("32L", n.rawValue());
    n.astLiteralType(LiteralType.HEXADECIMAL);
    assertEquals("0x20L", n.rawValue());
    assertNull(n.getErrorReasonForValue());
    n.astLiteralType(LiteralType.OCTAL);
    assertEquals("040L", n.rawValue());
   
    n.astIntValue(0);
    n.astLiteralType(LiteralType.DECIMAL);
    assertEquals("0", n.rawValue());
    n.astLiteralType(LiteralType.HEXADECIMAL);
    assertEquals("0x0", n.rawValue());
    assertNull(n.getErrorReasonForValue());
    n.astLiteralType(LiteralType.OCTAL);
    assertEquals("00", n.rawValue());
   
    n.astLiteralType(LiteralType.DECIMAL);
    n.astIntValue(Integer.MIN_VALUE);
    assertEquals("2147483648", n.rawValue());
    n.astLongValue(Long.MIN_VALUE);
    assertEquals("9223372036854775808L", n.rawValue());
  }
View Full Code Here

    assertEquals("9223372036854775808L", n.rawValue());
  }
 
  @Test
  public void testFromRaw() {
    IntegralLiteral n = new IntegralLiteral();
   
    n.rawValue("0");
    assertEquals(LiteralType.DECIMAL, n.astLiteralType());
    assertEquals(0, n.astIntValue());
    assertFalse(n.astMarkedAsLong());
    n.rawValue("00");
    assertEquals(LiteralType.OCTAL, n.astLiteralType());
    assertEquals(0, n.astIntValue());
    assertFalse(n.astMarkedAsLong());
    assertNull(n.getErrorReasonForValue());
    n.rawValue("0x0");
    assertEquals(LiteralType.HEXADECIMAL, n.astLiteralType());
    assertEquals(0, n.astIntValue());
    assertFalse(n.astMarkedAsLong());
    n.rawValue("00L");
    assertEquals(LiteralType.OCTAL, n.astLiteralType());
    assertEquals(0, n.astLongValue());
    assertTrue(n.astMarkedAsLong());
    assertNull(n.getErrorReasonForValue());
   
    n.rawValue("0x801291FD");
    assertEquals(LiteralType.HEXADECIMAL, n.astLiteralType());
    assertEquals(0x801291FD, n.astIntValue());
    assertFalse(n.astMarkedAsLong());
    assertNull(n.getErrorReasonForValue());
   
    n.rawValue("0xAC45005D12DEAAFFL");
    assertEquals(LiteralType.HEXADECIMAL, n.astLiteralType());
    assertEquals(0xAC45005D12DEAAFFL, n.astLongValue());
    assertTrue(n.astMarkedAsLong());
    assertNull(n.getErrorReasonForValue());
   
    n.rawValue("0xAC45005D12DEAAFF");
    assertEquals(LiteralType.HEXADECIMAL, n.astLiteralType());
    assertFalse(n.astMarkedAsLong());
    assertNotNull(n.getErrorReasonForValue());
  }
View Full Code Here

    assertNotNull(n.getErrorReasonForValue());
  }
 
  @Test
  public void testOversizedNumbers() {
    IntegralLiteral n = new IntegralLiteral().rawValue("100000000000");
    assertNotNull(n.getErrorReasonForValue());
   
    n.rawValue("100000000000L");
    assertNull(n.getErrorReasonForValue());
   
    n.rawValue("100000000000000000000000000L");
    assertNotNull(n.getErrorReasonForValue());
  }
View Full Code Here

TOP

Related Classes of lombok.ast.IntegralLiteral

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.