com.sun.tools.javac.tree.JCTree.JCLiteral Java Examples

The following examples show how to use com.sun.tools.javac.tree.JCTree.JCLiteral. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ULiteral.java    From Refaster with Apache License 2.0 6 votes vote down vote up
@Override
public JCLiteral inline(Inliner inliner) {
  Object value = this.getValue();
  switch (getKind()) {
    case CHAR_LITERAL:
      // Why do they do it like this?  I wish I knew.
      value = (int) ((Character) value).charValue();
      break;
    case BOOLEAN_LITERAL:
      value = ((Boolean) value) ? 1 : 0;
      break;
    default:
      // do nothing
  }
  return inliner.maker().Literal(LIT_KIND_TAG.get(getKind()), value);
}
 
Example #2
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 6 votes vote down vote up
public void visitLiteral(JCLiteral tree) {
	TypeTag typeTag = typeTag(tree);
	try {
		if (CTC_INT.equals(typeTag)) print(tree.value.toString());
		else if (CTC_LONG.equals(typeTag)) print(tree.value + "L");
		else if (CTC_FLOAT.equals(typeTag)) print(tree.value + "F");
		else if (CTC_DOUBLE.equals(typeTag)) print(tree.value.toString());
		else if (CTC_CHAR.equals(typeTag)) {
			print("\'" + quoteChar((char)((Number)tree.value).intValue()) + "\'");
		}
		else if (CTC_BOOLEAN.equals(typeTag)) print(((Number)tree.value).intValue() == 1 ? "true" : "false");
		else if (CTC_BOT.equals(typeTag)) print("null");
		else print("\"" + quoteChars(tree.value.toString()) + "\"");
	} catch (IOException e) {
		throw new UncheckedIOException(e);
	}
}
 
Example #3
Source File: Javac.java    From EasyMPermission with MIT License 6 votes vote down vote up
/**
 * Turns an expression into a guessed intended literal. Only works for
 * literals, as you can imagine.
 * 
 * Will for example turn a TrueLiteral into 'Boolean.valueOf(true)'.
 */
public static Object calculateGuess(JCExpression expr) {
	if (expr instanceof JCLiteral) {
		JCLiteral lit = (JCLiteral) expr;
		if (lit.getKind() == com.sun.source.tree.Tree.Kind.BOOLEAN_LITERAL) {
			return ((Number) lit.value).intValue() == 0 ? false : true;
		}
		return lit.value;
	} else if (expr instanceof JCIdent || expr instanceof JCFieldAccess) {
		String x = expr.toString();
		if (x.endsWith(".class")) x = x.substring(0, x.length() - 6);
		else {
			int idx = x.lastIndexOf('.');
			if (idx > -1) x = x.substring(idx + 1);
		}
		return x;
	} else
		return null;
}
 
Example #4
Source File: TypeEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * If a list of annotations contains a reference to java.lang.Deprecated,
 * set the DEPRECATED flag.
 * If the annotation is marked forRemoval=true, also set DEPRECATED_REMOVAL.
 **/
private void handleDeprecatedAnnotations(List<JCAnnotation> annotations, Symbol sym) {
    for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) {
        JCAnnotation a = al.head;
        if (a.annotationType.type == syms.deprecatedType) {
            sym.flags_field |= (Flags.DEPRECATED | Flags.DEPRECATED_ANNOTATION);
           StreamSupport.stream(a.args)
                    .filter(e -> e.hasTag(ASSIGN))
                    .map(e -> (JCAssign) e)
                    .filter(assign -> TreeInfo.name(assign.lhs) == names.forRemoval)
                    .findFirst()
                    .ifPresent(assign -> {
                        JCExpression rhs = TreeInfo.skipParens(assign.rhs);
                        if (rhs.hasTag(LITERAL)
                                && Boolean.TRUE.equals(((JCLiteral) rhs).getValue())) {
                            sym.flags_field |= DEPRECATED_REMOVAL;
                        }
                    });
        }
    }
}
 
Example #5
Source File: MakeLiteralTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void test(Object value, TypeTag tag, Type type, Object constValue) {
    JCLiteral l = maker.Literal(value);
    if (!l.type.hasTag(tag))
        error("unexpected tag: " + l.getTag() + ": expected: " + tag);
    if (!types.isSameType(l.type, type))
        error("unexpected type: " + l.type + ": expected: " + type);
    if (l.type.constValue().getClass() != constValue.getClass()
            || !constValue.equals(l.type.constValue()))  {
        error("unexpected const value: "
                + l.type.constValue().getClass() + " " + l.type.constValue()
                + ": expected:" + constValue.getClass() + " " + constValue);
    }
    if (l.getValue().getClass() != value.getClass()
            || !value.equals(l.getValue()))  {
        error("unexpected const value: "
                + l.getValue().getClass() + " " + l.type.constValue()
                + ": expected:" + value.getClass() + " " + value);
    }
}
 
Example #6
Source File: MakeLiteralTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void test(Object value, TypeTag tag, Type type, Object constValue) {
    JCLiteral l = maker.Literal(value);
    if (!l.type.hasTag(tag))
        error("unexpected tag: " + l.getTag() + ": expected: " + tag);
    if (!types.isSameType(l.type, type))
        error("unexpected type: " + l.type + ": expected: " + type);
    if (l.type.constValue().getClass() != constValue.getClass()
            || !constValue.equals(l.type.constValue()))  {
        error("unexpected const value: "
                + l.type.constValue().getClass() + " " + l.type.constValue()
                + ": expected:" + constValue.getClass() + " " + constValue);
    }
}
 
Example #7
Source File: HandleNonNull.java    From EasyMPermission with MIT License 5 votes vote down vote up
/**
 * Checks if the statement is of the form 'if (x == null) {throw WHATEVER;},
 * where the block braces are optional. If it is of this form, returns "x".
 * If it is not of this form, returns null.
 */
public String returnVarNameIfNullCheck(JCStatement stat) {
	if (!(stat instanceof JCIf)) return null;
	
	/* Check that the if's statement is a throw statement, possibly in a block. */ {
		JCStatement then = ((JCIf) stat).thenpart;
		if (then instanceof JCBlock) {
			List<JCStatement> stats = ((JCBlock) then).stats;
			if (stats.length() == 0) return null;
			then = stats.get(0);
		}
		if (!(then instanceof JCThrow)) return null;
	}
	
	/* Check that the if's conditional is like 'x == null'. Return from this method (don't generate
	   a nullcheck) if 'x' is equal to our own variable's name: There's already a nullcheck here. */ {
		JCExpression cond = ((JCIf) stat).cond;
		while (cond instanceof JCParens) cond = ((JCParens) cond).expr;
		if (!(cond instanceof JCBinary)) return null;
		JCBinary bin = (JCBinary) cond;
		if (!CTC_EQUAL.equals(treeTag(bin))) return null;
		if (!(bin.lhs instanceof JCIdent)) return null;
		if (!(bin.rhs instanceof JCLiteral)) return null;
		if (!CTC_BOT.equals(typeTag(bin.rhs))) return null;
		return ((JCIdent) bin.lhs).name.toString();
	}
}
 
Example #8
Source File: MakeLiteralTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
void test(Object value, TypeTag tag, Type type, Object constValue) {
    JCLiteral l = maker.Literal(value);
    if (!l.type.hasTag(tag))
        error("unexpected tag: " + l.getTag() + ": expected: " + tag);
    if (!types.isSameType(l.type, type))
        error("unexpected type: " + l.type + ": expected: " + type);
    if (l.type.constValue().getClass() != constValue.getClass()
            || !constValue.equals(l.type.constValue()))  {
        error("unexpected const value: "
                + l.type.constValue().getClass() + " " + l.type.constValue()
                + ": expected:" + constValue.getClass() + " " + constValue);
    }
}
 
Example #9
Source File: GenStubs.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * field definitions: replace initializers with 0, 0.0, false etc
 * when possible -- i.e. leave public, protected initializers alone
 */
@Override
public void visitVarDef(JCVariableDecl tree) {
    tree.mods = translate(tree.mods);
    tree.vartype = translate(tree.vartype);
    if (tree.init != null) {
        if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0)
            tree.init = translate(tree.init);
        else {
            String t = tree.vartype.toString();
            if (t.equals("boolean"))
                tree.init = new JCLiteral(TypeTag.BOOLEAN, 0) { };
            else if (t.equals("byte"))
                tree.init = new JCLiteral(TypeTag.BYTE, 0) { };
            else if (t.equals("char"))
                tree.init = new JCLiteral(TypeTag.CHAR, 0) { };
            else if (t.equals("double"))
                tree.init = new JCLiteral(TypeTag.DOUBLE, 0.d) { };
            else if (t.equals("float"))
                tree.init = new JCLiteral(TypeTag.FLOAT, 0.f) { };
            else if (t.equals("int"))
                tree.init = new JCLiteral(TypeTag.INT, 0) { };
            else if (t.equals("long"))
                tree.init = new JCLiteral(TypeTag.LONG, 0) { };
            else if (t.equals("short"))
                tree.init = new JCLiteral(TypeTag.SHORT, 0) { };
            else
                tree.init = new JCLiteral(TypeTag.BOT, null) { };
        }
    }
    result = tree;
}
 
Example #10
Source File: MakeLiteralTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
void test(Object value, TypeTag tag, Type type, Object constValue) {
    JCLiteral l = maker.Literal(value);
    if (!l.type.hasTag(tag))
        error("unexpected tag: " + l.getTag() + ": expected: " + tag);
    if (!types.isSameType(l.type, type))
        error("unexpected type: " + l.type + ": expected: " + type);
    if (l.type.constValue().getClass() != constValue.getClass()
            || !constValue.equals(l.type.constValue()))  {
        error("unexpected const value: "
                + l.type.constValue().getClass() + " " + l.type.constValue()
                + ": expected:" + constValue.getClass() + " " + constValue);
    }
}
 
Example #11
Source File: GenStubs.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * field definitions: replace initializers with 0, 0.0, false etc
 * when possible -- i.e. leave public, protected initializers alone
 */
@Override
public void visitVarDef(JCVariableDecl tree) {
    tree.mods = translate(tree.mods);
    tree.vartype = translate(tree.vartype);
    if (tree.init != null) {
        if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0)
            tree.init = translate(tree.init);
        else {
            String t = tree.vartype.toString();
            if (t.equals("boolean"))
                tree.init = new JCLiteral(TypeTag.BOOLEAN, 0) { };
            else if (t.equals("byte"))
                tree.init = new JCLiteral(TypeTag.BYTE, 0) { };
            else if (t.equals("char"))
                tree.init = new JCLiteral(TypeTag.CHAR, 0) { };
            else if (t.equals("double"))
                tree.init = new JCLiteral(TypeTag.DOUBLE, 0.d) { };
            else if (t.equals("float"))
                tree.init = new JCLiteral(TypeTag.FLOAT, 0.f) { };
            else if (t.equals("int"))
                tree.init = new JCLiteral(TypeTag.INT, 0) { };
            else if (t.equals("long"))
                tree.init = new JCLiteral(TypeTag.LONG, 0) { };
            else if (t.equals("short"))
                tree.init = new JCLiteral(TypeTag.SHORT, 0) { };
            else
                tree.init = new JCLiteral(TypeTag.BOT, null) { };
        }
    }
    result = tree;
}
 
Example #12
Source File: MakeLiteralTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
void test(Object value, TypeTag tag, Type type, Object constValue) {
    JCLiteral l = maker.Literal(value);
    if (!l.type.hasTag(tag))
        error("unexpected tag: " + l.getTag() + ": expected: " + tag);
    if (!types.isSameType(l.type, type))
        error("unexpected type: " + l.type + ": expected: " + type);
    if (l.type.constValue().getClass() != constValue.getClass()
            || !constValue.equals(l.type.constValue()))  {
        error("unexpected const value: "
                + l.type.constValue().getClass() + " " + l.type.constValue()
                + ": expected:" + constValue.getClass() + " " + constValue);
    }
}
 
Example #13
Source File: GenStubs.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * field definitions: replace initializers with 0, 0.0, false etc
 * when possible -- i.e. leave public, protected initializers alone
 */
@Override
public void visitVarDef(JCVariableDecl tree) {
    tree.mods = translate(tree.mods);
    tree.vartype = translate(tree.vartype);
    if (tree.init != null) {
        if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0)
            tree.init = translate(tree.init);
        else {
            String t = tree.vartype.toString();
            if (t.equals("boolean"))
                tree.init = new JCLiteral(TypeTag.BOOLEAN, 0) { };
            else if (t.equals("byte"))
                tree.init = new JCLiteral(TypeTag.BYTE, 0) { };
            else if (t.equals("char"))
                tree.init = new JCLiteral(TypeTag.CHAR, 0) { };
            else if (t.equals("double"))
                tree.init = new JCLiteral(TypeTag.DOUBLE, 0.d) { };
            else if (t.equals("float"))
                tree.init = new JCLiteral(TypeTag.FLOAT, 0.f) { };
            else if (t.equals("int"))
                tree.init = new JCLiteral(TypeTag.INT, 0) { };
            else if (t.equals("long"))
                tree.init = new JCLiteral(TypeTag.LONG, 0) { };
            else if (t.equals("short"))
                tree.init = new JCLiteral(TypeTag.SHORT, 0) { };
            else
                tree.init = new JCLiteral(TypeTag.BOT, null) { };
        }
    }
    result = tree;
}
 
Example #14
Source File: GenStubs.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * field definitions: replace initializers with 0, 0.0, false etc
 * when possible -- i.e. leave public, protected initializers alone
 */
@Override
public void visitVarDef(JCVariableDecl tree) {
    tree.mods = translate(tree.mods);
    tree.vartype = translate(tree.vartype);
    if (tree.init != null) {
        if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0)
            tree.init = translate(tree.init);
        else {
            String t = tree.vartype.toString();
            if (t.equals("boolean"))
                tree.init = new JCLiteral(TypeTag.BOOLEAN, 0) { };
            else if (t.equals("byte"))
                tree.init = new JCLiteral(TypeTag.BYTE, 0) { };
            else if (t.equals("char"))
                tree.init = new JCLiteral(TypeTag.CHAR, 0) { };
            else if (t.equals("double"))
                tree.init = new JCLiteral(TypeTag.DOUBLE, 0.d) { };
            else if (t.equals("float"))
                tree.init = new JCLiteral(TypeTag.FLOAT, 0.f) { };
            else if (t.equals("int"))
                tree.init = new JCLiteral(TypeTag.INT, 0) { };
            else if (t.equals("long"))
                tree.init = new JCLiteral(TypeTag.LONG, 0) { };
            else if (t.equals("short"))
                tree.init = new JCLiteral(TypeTag.SHORT, 0) { };
            else
                tree.init = new JCLiteral(TypeTag.BOT, null) { };
        }
    }
    result = tree;
}
 
Example #15
Source File: GenStubs.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * field definitions: replace initializers with 0, 0.0, false etc
 * when possible -- i.e. leave public, protected initializers alone
 */
@Override
public void visitVarDef(JCVariableDecl tree) {
    tree.mods = translate(tree.mods);
    tree.vartype = translate(tree.vartype);
    if (tree.init != null) {
        if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0)
            tree.init = translate(tree.init);
        else {
            String t = tree.vartype.toString();
            if (t.equals("boolean"))
                tree.init = new JCLiteral(TypeTag.BOOLEAN, 0) { };
            else if (t.equals("byte"))
                tree.init = new JCLiteral(TypeTag.BYTE, 0) { };
            else if (t.equals("char"))
                tree.init = new JCLiteral(TypeTag.CHAR, 0) { };
            else if (t.equals("double"))
                tree.init = new JCLiteral(TypeTag.DOUBLE, 0.d) { };
            else if (t.equals("float"))
                tree.init = new JCLiteral(TypeTag.FLOAT, 0.f) { };
            else if (t.equals("int"))
                tree.init = new JCLiteral(TypeTag.INT, 0) { };
            else if (t.equals("long"))
                tree.init = new JCLiteral(TypeTag.LONG, 0) { };
            else if (t.equals("short"))
                tree.init = new JCLiteral(TypeTag.SHORT, 0) { };
            else
                tree.init = new JCLiteral(TypeTag.BOT, null) { };
        }
    }
    result = tree;
}
 
Example #16
Source File: GenStubs.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * field definitions: replace initializers with 0, 0.0, false etc
 * when possible -- i.e. leave public, protected initializers alone
 */
@Override
public void visitVarDef(JCVariableDecl tree) {
    tree.mods = translate(tree.mods);
    tree.vartype = translate(tree.vartype);
    if (tree.init != null) {
        if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0)
            tree.init = translate(tree.init);
        else {
            String t = tree.vartype.toString();
            if (t.equals("boolean"))
                tree.init = new JCLiteral(TypeTag.BOOLEAN, 0) { };
            else if (t.equals("byte"))
                tree.init = new JCLiteral(TypeTag.BYTE, 0) { };
            else if (t.equals("char"))
                tree.init = new JCLiteral(TypeTag.CHAR, 0) { };
            else if (t.equals("double"))
                tree.init = new JCLiteral(TypeTag.DOUBLE, 0.d) { };
            else if (t.equals("float"))
                tree.init = new JCLiteral(TypeTag.FLOAT, 0.f) { };
            else if (t.equals("int"))
                tree.init = new JCLiteral(TypeTag.INT, 0) { };
            else if (t.equals("long"))
                tree.init = new JCLiteral(TypeTag.LONG, 0) { };
            else if (t.equals("short"))
                tree.init = new JCLiteral(TypeTag.SHORT, 0) { };
            else
                tree.init = new JCLiteral(TypeTag.BOT, null) { };
        }
    }
    result = tree;
}
 
Example #17
Source File: MakeLiteralTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
void test(Object value, TypeTag tag, Type type, Object constValue) {
    JCLiteral l = maker.Literal(value);
    if (!l.type.hasTag(tag))
        error("unexpected tag: " + l.getTag() + ": expected: " + tag);
    if (!types.isSameType(l.type, type))
        error("unexpected type: " + l.type + ": expected: " + type);
    if (l.type.constValue().getClass() != constValue.getClass()
            || !constValue.equals(l.type.constValue()))  {
        error("unexpected const value: "
                + l.type.constValue().getClass() + " " + l.type.constValue()
                + ": expected:" + constValue.getClass() + " " + constValue);
    }
}
 
Example #18
Source File: GenStubs.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * field definitions: replace initializers with 0, 0.0, false etc
 * when possible -- i.e. leave public, protected initializers alone
 */
@Override
public void visitVarDef(JCVariableDecl tree) {
    tree.mods = translate(tree.mods);
    tree.vartype = translate(tree.vartype);
    if (tree.init != null) {
        if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0)
            tree.init = translate(tree.init);
        else {
            String t = tree.vartype.toString();
            if (t.equals("boolean"))
                tree.init = new JCLiteral(TypeTag.BOOLEAN, 0) { };
            else if (t.equals("byte"))
                tree.init = new JCLiteral(TypeTag.BYTE, 0) { };
            else if (t.equals("char"))
                tree.init = new JCLiteral(TypeTag.CHAR, 0) { };
            else if (t.equals("double"))
                tree.init = new JCLiteral(TypeTag.DOUBLE, 0.d) { };
            else if (t.equals("float"))
                tree.init = new JCLiteral(TypeTag.FLOAT, 0.f) { };
            else if (t.equals("int"))
                tree.init = new JCLiteral(TypeTag.INT, 0) { };
            else if (t.equals("long"))
                tree.init = new JCLiteral(TypeTag.LONG, 0) { };
            else if (t.equals("short"))
                tree.init = new JCLiteral(TypeTag.SHORT, 0) { };
            else
                tree.init = new JCLiteral(TypeTag.BOT, null) { };
        }
    }
    result = tree;
}
 
Example #19
Source File: MakeLiteralTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void test(Object value, TypeTag tag, Type type, Object constValue) {
    JCLiteral l = maker.Literal(value);
    if (!l.type.hasTag(tag))
        error("unexpected tag: " + l.getTag() + ": expected: " + tag);
    if (!types.isSameType(l.type, type))
        error("unexpected type: " + l.type + ": expected: " + type);
    if (l.type.constValue().getClass() != constValue.getClass()
            || !constValue.equals(l.type.constValue()))  {
        error("unexpected const value: "
                + l.type.constValue().getClass() + " " + l.type.constValue()
                + ": expected:" + constValue.getClass() + " " + constValue);
    }
}
 
Example #20
Source File: GenStubs.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * field definitions: replace initializers with 0, 0.0, false etc
 * when possible -- i.e. leave public, protected initializers alone
 */
@Override
public void visitVarDef(JCVariableDecl tree) {
    tree.mods = translate(tree.mods);
    tree.vartype = translate(tree.vartype);
    if (tree.init != null) {
        if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0)
            tree.init = translate(tree.init);
        else {
            String t = tree.vartype.toString();
            if (t.equals("boolean"))
                tree.init = new JCLiteral(TypeTag.BOOLEAN, 0) { };
            else if (t.equals("byte"))
                tree.init = new JCLiteral(TypeTag.BYTE, 0) { };
            else if (t.equals("char"))
                tree.init = new JCLiteral(TypeTag.CHAR, 0) { };
            else if (t.equals("double"))
                tree.init = new JCLiteral(TypeTag.DOUBLE, 0.d) { };
            else if (t.equals("float"))
                tree.init = new JCLiteral(TypeTag.FLOAT, 0.f) { };
            else if (t.equals("int"))
                tree.init = new JCLiteral(TypeTag.INT, 0) { };
            else if (t.equals("long"))
                tree.init = new JCLiteral(TypeTag.LONG, 0) { };
            else if (t.equals("short"))
                tree.init = new JCLiteral(TypeTag.SHORT, 0) { };
            else
                tree.init = new JCLiteral(TypeTag.BOT, null) { };
        }
    }
    result = tree;
}
 
Example #21
Source File: MakeLiteralTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
void test(Object value, TypeTag tag, Type type, Object constValue) {
    JCLiteral l = maker.Literal(value);
    if (!l.type.hasTag(tag))
        error("unexpected tag: " + l.getTag() + ": expected: " + tag);
    if (!types.isSameType(l.type, type))
        error("unexpected type: " + l.type + ": expected: " + type);
    if (l.type.constValue().getClass() != constValue.getClass()
            || !constValue.equals(l.type.constValue()))  {
        error("unexpected const value: "
                + l.type.constValue().getClass() + " " + l.type.constValue()
                + ": expected:" + constValue.getClass() + " " + constValue);
    }
}
 
Example #22
Source File: CRTable.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitLiteral(JCLiteral tree) {
    SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
    result = sr;
}
 
Example #23
Source File: HandleBuilder.java    From EasyMPermission with MIT License 4 votes vote down vote up
private static final boolean toBoolean(Object expr, boolean defaultValue) {
	if (expr == null) return defaultValue;
	if (expr instanceof JCLiteral) return ((Integer) ((JCLiteral) expr).value) != 0;
	return ((Boolean) expr).booleanValue();
}
 
Example #24
Source File: JavacTreeMaker.java    From EasyMPermission with MIT License 4 votes vote down vote up
public JCLiteral Literal(Object value) {
	return invoke(LiteralWithValue, value);
}
 
Example #25
Source File: JavacTreeMaker.java    From EasyMPermission with MIT License 4 votes vote down vote up
public JCLiteral Literal(TypeTag tag, Object value) {
	return invoke(Literal, tag.value, value);
}
 
Example #26
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 4 votes vote down vote up
private static NumberLiteral convertCharLiteral(JCLiteral literal) {
  return NumberLiteral.fromChar((Character) literal.getValue());
}
 
Example #27
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
JCLiteral forConstant(VarSymbol v) {
    Integer result = values.get(v);
    if (result == null)
        values.put(v, result = next++);
    return make.Literal(result);
}
 
Example #28
Source File: MemberEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void visitLiteral(JCLiteral that) {}
 
Example #29
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 4 votes vote down vote up
private static StringLiteral convertStringLiteral(JCLiteral literal) {
  return new StringLiteral((String) literal.getValue());
}
 
Example #30
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 4 votes vote down vote up
private static BooleanLiteral convertBooleanLiteral(JCLiteral literal) {
  return BooleanLiteral.get((Boolean) literal.getValue());
}