Java Code Examples for org.eclipse.jdt.internal.compiler.impl.Constant#longValue()

The following examples show how to use org.eclipse.jdt.internal.compiler.impl.Constant#longValue() . 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: Util.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static Object getNegativeAnnotationMemberValue(MemberValuePair memberValuePair, Constant constant) {
	if (constant == null) {
		memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
		return null;
	}
	switch (constant.typeID()) {
		case TypeIds.T_int :
			memberValuePair.valueKind = IMemberValuePair.K_INT;
			return new Integer(constant.intValue() * -1);
		case TypeIds.T_float :
			memberValuePair.valueKind = IMemberValuePair.K_FLOAT;
			return new Float(constant.floatValue() * -1.0f);
		case TypeIds.T_double :
			memberValuePair.valueKind = IMemberValuePair.K_DOUBLE;
			return new Double(constant.doubleValue() * -1.0);
		case TypeIds.T_long :
			memberValuePair.valueKind = IMemberValuePair.K_LONG;
			return new Long(constant.longValue() * -1L);
		default:
			memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
			return null;
	}
}
 
Example 2
Source File: VariableBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public Object getConstantValue() {
	Constant c = this.binding.constant();
	if (c == null || c == Constant.NotAConstant) return null;
	switch (c.typeID()) {
		case TypeIds.T_boolean:
			return Boolean.valueOf(c.booleanValue());
		case TypeIds.T_byte:
			return new Byte(c.byteValue());
		case TypeIds.T_char:
			return new Character(c.charValue());
		case TypeIds.T_double:
			return new Double(c.doubleValue());
		case TypeIds.T_float:
			return new Float(c.floatValue());
		case TypeIds.T_int:
			return new Integer(c.intValue());
		case TypeIds.T_long:
			return new Long(c.longValue());
		case TypeIds.T_short:
			return new Short(c.shortValue());
		case TypeIds.T_JavaLangString:
			return c.stringValue();
	}
	return null;
}
 
Example 3
Source File: DefaultBindingResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
Object resolveConstantExpressionValue(Expression expression) {
	org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression);
	if (node instanceof org.eclipse.jdt.internal.compiler.ast.Expression) {
		org.eclipse.jdt.internal.compiler.ast.Expression compilerExpression = (org.eclipse.jdt.internal.compiler.ast.Expression) node;
		Constant constant = compilerExpression.constant;
		if (constant != null && constant != Constant.NotAConstant) {
			switch (constant.typeID()) {
				case TypeIds.T_int : return new Integer(constant.intValue());
				case TypeIds.T_byte : return new Byte(constant.byteValue());
				case TypeIds.T_short : return new Short(constant.shortValue());
				case TypeIds.T_char : return new Character(constant.charValue());
				case TypeIds.T_float : return new Float(constant.floatValue());
				case TypeIds.T_double : return new Double(constant.doubleValue());
				case TypeIds.T_boolean : return constant.booleanValue() ? Boolean.TRUE : Boolean.FALSE;
				case TypeIds.T_long : return new Long(constant.longValue());
				case TypeIds.T_JavaLangString : return constant.stringValue();
			}
			return null;
		}
	}
	return null;
}
 
Example 4
Source File: VariableElementImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object getConstantValue() {
	VariableBinding variableBinding = (VariableBinding) _binding;
	Constant constant = variableBinding.constant();
	if (constant == null || constant == Constant.NotAConstant) return null;
	TypeBinding type = variableBinding.type;
	switch (type.id) {
		case TypeIds.T_boolean:
			return constant.booleanValue();
		case TypeIds.T_byte:
			return constant.byteValue();
		case TypeIds.T_char:
			return constant.charValue();
		case TypeIds.T_double:
			return constant.doubleValue();
		case TypeIds.T_float:
			return constant.floatValue();
		case TypeIds.T_int:
			return constant.intValue();
		case TypeIds.T_JavaLangString:
			return constant.stringValue();
		case TypeIds.T_long:
			return constant.longValue();
		case TypeIds.T_short:
			return constant.shortValue();
	}
	return null;
}
 
Example 5
Source File: Member.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Converts a field constant from the compiler's representation
 * to the Java Model constant representation (Number or String).
 */
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;
	}
}
 
Example 6
Source File: Util.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static Object getAnnotationMemberValue(MemberValuePair memberValuePair, Constant constant) {
	if (constant == null) {
		memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
		return null;
	}
	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;
	}
}
 
Example 7
Source File: MemberValuePairBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
static Object buildDOMValue(final Object internalObject, BindingResolver resolver) {
	if (internalObject == null)
		return null;

	if (internalObject instanceof Constant) {
		Constant constant = (Constant) internalObject;
		switch (constant.typeID()) {
			case TypeIds.T_boolean:
				return Boolean.valueOf(constant.booleanValue());
			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());
			default:
				// TypeIds.T_JavaLangString:
				return constant.stringValue();
		}
	} else if (internalObject instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
		return resolver.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) internalObject);
	} else if (internalObject instanceof org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding) {
		return resolver.getAnnotationInstance((org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding) internalObject);
	} else if (internalObject instanceof org.eclipse.jdt.internal.compiler.lookup.FieldBinding) {
		return resolver.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.FieldBinding) internalObject);
	} else if (internalObject instanceof Object[]) {
		Object[] elements = (Object[]) internalObject;
		int length = elements.length;
		Object[] values = length == 0 ? EmptyArray : new Object[length];
		for (int i = 0; i < length; i++)
			values[i] = buildDOMValue(elements[i], resolver);
		return values;
	}
	return null;
}
 
Example 8
Source File: ClassFileReader.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private boolean hasStructuralFieldChanges(FieldInfo currentFieldInfo, FieldInfo otherFieldInfo) {
	// generic signature
	if (!CharOperation.equals(currentFieldInfo.getGenericSignature(), otherFieldInfo.getGenericSignature()))
		return true;
	if (currentFieldInfo.getModifiers() != otherFieldInfo.getModifiers())
		return true;
	if ((currentFieldInfo.getTagBits() & TagBits.AnnotationDeprecated) != (otherFieldInfo.getTagBits() & TagBits.AnnotationDeprecated))
		return true;
	if (hasStructuralAnnotationChanges(currentFieldInfo.getAnnotations(), otherFieldInfo.getAnnotations()))
		return true;
	if (!CharOperation.equals(currentFieldInfo.getName(), otherFieldInfo.getName()))
		return true;
	if (!CharOperation.equals(currentFieldInfo.getTypeName(), otherFieldInfo.getTypeName()))
		return true;
	if (currentFieldInfo.hasConstant() != otherFieldInfo.hasConstant())
		return true;
	if (currentFieldInfo.hasConstant()) {
		Constant currentConstant = currentFieldInfo.getConstant();
		Constant otherConstant = otherFieldInfo.getConstant();
		if (currentConstant.typeID() != otherConstant.typeID())
			return true;
		if (!currentConstant.getClass().equals(otherConstant.getClass()))
			return true;
		switch (currentConstant.typeID()) {
			case TypeIds.T_int :
				return currentConstant.intValue() != otherConstant.intValue();
			case TypeIds.T_byte :
				return currentConstant.byteValue() != otherConstant.byteValue();
			case TypeIds.T_short :
				return currentConstant.shortValue() != otherConstant.shortValue();
			case TypeIds.T_char :
				return currentConstant.charValue() != otherConstant.charValue();
			case TypeIds.T_long :
				return currentConstant.longValue() != otherConstant.longValue();
			case TypeIds.T_float :
				return currentConstant.floatValue() != otherConstant.floatValue();
			case TypeIds.T_double :
				return currentConstant.doubleValue() != otherConstant.doubleValue();
			case TypeIds.T_boolean :
				return currentConstant.booleanValue() != otherConstant.booleanValue();
			case TypeIds.T_JavaLangString :
				return !currentConstant.stringValue().equals(otherConstant.stringValue());
		}
	}
	return false;
}