List of usage examples for org.eclipse.jdt.internal.compiler.impl Constant stringValue
public String stringValue()
From source file:com.android.tools.lint.psi.EcjPsiManager.java
License:Apache License
@Nullable static Object getConstantValue(@Nullable Constant value) { if (value == null || value == Constant.NotAConstant) { return null; } else if (value instanceof StringConstant) { return value.stringValue(); } else if (value instanceof IntConstant) { return value.intValue(); } else if (value instanceof BooleanConstant) { return value.booleanValue(); } else if (value instanceof FloatConstant) { return value.floatValue(); } else if (value instanceof LongConstant) { return value.longValue(); } else if (value instanceof DoubleConstant) { return value.doubleValue(); } else if (value instanceof ShortConstant) { return value.shortValue(); } else if (value instanceof CharConstant) { return value.charValue(); } else if (value instanceof ByteConstant) { return value.byteValue(); }// w w w . j ava 2 s . com return null; }
From source file:com.codenvy.ide.ext.java.server.internal.core.Member.java
License:Open Source License
/** * Converts a field constant from the compiler's representation * to the Java Model constant representation (Number or String). *///from w w w. j av a2 s .c o m protected static Object convertConstant(Constant constant) { if (constant == null) return null; if (constant == Constant.NotAConstant) { return null; } switch (constant.typeID()) { case TypeIds.T_boolean: return constant.booleanValue() ? Boolean.TRUE : Boolean.FALSE; case TypeIds.T_byte: return new Byte(constant.byteValue()); case TypeIds.T_char: return new Character(constant.charValue()); case TypeIds.T_double: return new Double(constant.doubleValue()); case TypeIds.T_float: return new Float(constant.floatValue()); case TypeIds.T_int: return new Integer(constant.intValue()); case TypeIds.T_long: return new Long(constant.longValue()); case TypeIds.T_short: return new Short(constant.shortValue()); case TypeIds.T_JavaLangString: return constant.stringValue(); default: return null; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.util.Util.java
License:Open Source License
public static Object getAnnotationMemberValue(MemberValuePair memberValuePair, Constant constant) { if (constant == null) { memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN; return null; }// ww w . j a va 2 s . c o m switch (constant.typeID()) { case TypeIds.T_int: memberValuePair.valueKind = IMemberValuePair.K_INT; return new Integer(constant.intValue()); case TypeIds.T_byte: memberValuePair.valueKind = IMemberValuePair.K_BYTE; return new Byte(constant.byteValue()); case TypeIds.T_short: memberValuePair.valueKind = IMemberValuePair.K_SHORT; return new Short(constant.shortValue()); case TypeIds.T_char: memberValuePair.valueKind = IMemberValuePair.K_CHAR; return new Character(constant.charValue()); case TypeIds.T_float: memberValuePair.valueKind = IMemberValuePair.K_FLOAT; return new Float(constant.floatValue()); case TypeIds.T_double: memberValuePair.valueKind = IMemberValuePair.K_DOUBLE; return new Double(constant.doubleValue()); case TypeIds.T_boolean: memberValuePair.valueKind = IMemberValuePair.K_BOOLEAN; return Boolean.valueOf(constant.booleanValue()); case TypeIds.T_long: memberValuePair.valueKind = IMemberValuePair.K_LONG; return new Long(constant.longValue()); case TypeIds.T_JavaLangString: memberValuePair.valueKind = IMemberValuePair.K_STRING; return constant.stringValue(); default: memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN; return null; } }
From source file:com.redhat.ceylon.eclipse.core.model.loader.JDTUtils.java
License:Open Source License
public static Object fromConstant(Constant constant) { switch (constant.typeID()) { case Constant.T_boolean: return new Boolean(constant.booleanValue()); case Constant.T_byte: return new Byte(constant.byteValue()); case Constant.T_char: return new Character(constant.charValue()); case Constant.T_double: return new Double(constant.doubleValue()); case Constant.T_float: return new Float(constant.floatValue()); case Constant.T_int: return new Integer(constant.intValue()); case Constant.T_JavaLangString: return new String(constant.stringValue()); }/*from w ww .ja v a2 s. co m*/ return null; }
From source file:com.redhat.ceylon.eclipse.core.model.mirror.JDTUtils.java
License:Open Source License
public static Object fromConstant(Constant constant) { switch (constant.typeID()) { case Constant.T_boolean: return new Boolean(constant.booleanValue()); case Constant.T_byte: return new Byte(constant.byteValue()); case Constant.T_char: return new Character(constant.charValue()); case Constant.T_double: return new Double(constant.doubleValue()); case Constant.T_float: return new Float(constant.floatValue()); case Constant.T_int: return new Integer(constant.intValue()); case Constant.T_short: return new Short(constant.shortValue()); case Constant.T_long: return new Long(constant.longValue()); case Constant.T_JavaLangString: return new String(constant.stringValue()); }//w ww . j av a2s . c om return null; }
From source file:io.takari.maven.plugins.compile.jdt.ClassfileDigester.java
License:Open Source License
private void updateConstant(Constant constant) { updateInt(constant.typeID());//from w w w. j a v a2 s.c o m updateString(constant.getClass().getName()); switch (constant.typeID()) { case TypeIds.T_int: updateInt(constant.intValue()); break; case TypeIds.T_byte: updateByte(constant.byteValue()); break; case TypeIds.T_short: updateShort(constant.shortValue()); break; case TypeIds.T_char: updateChar(constant.charValue()); break; case TypeIds.T_long: updateLong(constant.longValue()); break; case TypeIds.T_float: updateFloat(constant.floatValue()); break; case TypeIds.T_double: updateDouble(constant.doubleValue()); break; case TypeIds.T_boolean: updateBoolean(constant.booleanValue()); break; case TypeIds.T_JavaLangString: updateString(constant.stringValue()); break; default: throw new IllegalArgumentException("Unexpected constant typeID=" + constant.typeID()); } }
From source file:org.eclipse.che.jdt.BinaryTypeConvector.java
License:Open Source License
public static JsonElement toJsonConstant(Constant constant) { if (constant == null) return JsonNull.INSTANCE; JsonObject con = new JsonObject(); con.addProperty("typeId", constant.typeID()); JsonElement val; switch (constant.typeID()) { case T_int: val = new JsonPrimitive(constant.intValue()); break;// ww w .j av a 2 s. com case T_byte: val = new JsonPrimitive(constant.byteValue()); break; case T_short: val = new JsonPrimitive(constant.shortValue()); break; case T_char: val = new JsonPrimitive(constant.charValue()); break; case T_float: val = new JsonPrimitive(String.valueOf(constant.floatValue())); break; case T_double: if (Constant.NotAConstant.equals(constant)) { val = new JsonPrimitive("NaN"); con.addProperty("NotAConstant", 1); } else { val = new JsonPrimitive(constant.stringValue()); } break; case T_boolean: val = new JsonPrimitive(constant.booleanValue()); break; case T_long: val = new JsonPrimitive(String.valueOf(constant.longValue())); break; case T_JavaLangString: val = new JsonPrimitive(constant.stringValue()); break; default: val = JsonNull.INSTANCE; } con.add("value", val); return con; }
From source file:org.jboss.tools.seam.internal.core.scanner.lib.TypeScanner.java
License:Open Source License
public static String getValue(IBinaryAnnotation a, String method) { try {/*from w w w . java 2 s.co m*/ IBinaryElementValuePair[] ps = a.getElementValuePairs(); if (ps != null) for (int i = 0; i < ps.length; i++) { if (method.equals(new String(ps[i].getName()))) { Object v = ps[i].getValue(); if (v == null) return null; if (v instanceof EnumConstantSignature) { EnumConstantSignature cs = (EnumConstantSignature) v; char[] cv = cs.getEnumConstantName(); return cv == null ? null : new String(cv); } else if (v instanceof Constant) { Constant ic = (Constant) v; return ic.stringValue(); } v = v.toString(); return (String) v; } } } catch (Throwable e) { SeamCorePlugin.getPluginLog().logError(e); } return null; }