Package org.eclipse.jdt.internal.compiler.impl

Examples of org.eclipse.jdt.internal.compiler.impl.Constant


   * Returns <code>true</code> if JDT optimized the condition to
   * <code>false</code>.
   */
  private static boolean isOptimizedFalse(Expression condition) {
    if (condition != null) {
      Constant cst = condition.optimizedBooleanConstant();
      if (cst != Constant.NotAConstant) {
        if (cst.booleanValue() == false) {
          return true;
        }
      }
    }
    return false;
View Full Code Here


   * Returns <code>true</code> if JDT optimized the condition to
   * <code>true</code>.
   */
  private static boolean isOptimizedTrue(Expression condition) {
    if (condition != null) {
      Constant cst = condition.optimizedBooleanConstant();
      if (cst != Constant.NotAConstant) {
        if (cst.booleanValue() == true) {
          return true;
        }
      }
    }
    return false;
View Full Code Here

      /*
       * Rely on JDT's computed constant value to deal with an
       * AnnotationElementValue expression whose resolved type is a primitive or
       * a string.
       */
      Constant constant = elementValueExpression.constant;
      int expectedTypeId = expectedElementValueType.id;

      if (expectedElementValueType.isArrayType()) {
        /*
         * This can happen when an element value is an array with a single
         * element. In this case JLS 3.0 section 9.7 allows for the
         * ArrayInitializer expression to be implicit. Since, element values can
         * only be single dimensional arrays, we take the leaf type of the
         * expected array type as our resultant element value type.
         */
        assert (!elementValueExpression.resolvedType.isArrayType() && expectedElementValueType.dimensions() == 1);

        expectedTypeId = expectedElementValueType.leafComponentType().id;
      }

      if (elementValueExpression.resolvedType.id != expectedTypeId) {
        /*
         * Narrowing and widening conversions are handled by the following
         * Constant.castTo call. JDT wants the upper four bits of this mask to
         * be the target type id and the lower four bits to be the source type
         * id. See Constant.castTo for more details.
         */
        constant = constant.castTo((expectedTypeId << 4)
            + elementValueExpression.resolvedType.id);
      }

      elementValue = getConstantValue(constant);
    } else if (elementValueExpression instanceof ClassLiteralAccess) {
View Full Code Here

   * Returns <code>true</code> if JDT optimized the condition to
   * <code>false</code>.
   */
  private static boolean isOptimizedFalse(Expression condition) {
    if (condition != null) {
      Constant cst = condition.optimizedBooleanConstant();
      if (cst != Constant.NotAConstant) {
        if (cst.booleanValue() == false) {
          return true;
        }
      }
    }
    return false;
View Full Code Here

   * Returns <code>true</code> if JDT optimized the condition to
   * <code>true</code>.
   */
  private static boolean isOptimizedTrue(Expression condition) {
    if (condition != null) {
      Constant cst = condition.optimizedBooleanConstant();
      if (cst != Constant.NotAConstant) {
        if (cst.booleanValue() == true) {
          return true;
        }
      }
    }
    return false;
View Full Code Here

  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;
}
View Full Code Here

*/
public void generateOptimizedBoolean(BlockScope currentScope, CodeStream codeStream, BranchLabel trueLabel, BranchLabel falseLabel, boolean valueRequired) {
  // a label valued to nil means: by default we fall through the case...
  // both nil means we leave the value on the stack

  Constant cst = optimizedBooleanConstant();
  generateCode(currentScope, codeStream, valueRequired && cst == Constant.NotAConstant);
  if ((cst != Constant.NotAConstant) && (cst.typeID() == TypeIds.T_boolean)) {
    int pc = codeStream.position;
    if (cst.booleanValue() == true) {
      // constant == true
      if (valueRequired) {
        if (falseLabel == null) {
          // implicit falling through the FALSE case
          if (trueLabel != null) {
View Full Code Here

   */
  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;
View Full Code Here

  private int addFieldAttributes(FieldBinding fieldBinding, int fieldAttributeOffset) {
    int attributesNumber = 0;
    // 4.7.2 only static constant fields get a ConstantAttribute
    // Generate the constantValueAttribute
    Constant fieldConstant = fieldBinding.constant();
    if (fieldConstant != Constant.NotAConstant){
      attributesNumber += generateConstantValueAttribute(fieldConstant, fieldBinding, fieldAttributeOffset);
    }
    if (this.targetJDK < ClassFileConstants.JDK1_5 && fieldBinding.isSynthetic()) {
      attributesNumber += generateSyntheticAttribute();
View Full Code Here

  }
  private void generateElementValue(
      Expression defaultValue,
      TypeBinding memberValuePairReturnType,
      int attributeOffset) {
    Constant constant = defaultValue.constant;
    TypeBinding defaultValueBinding = defaultValue.resolvedType;
    if (defaultValueBinding == null) {
      this.contentsOffset = attributeOffset;
    } else {
      if (memberValuePairReturnType.isArrayType() && !defaultValueBinding.isArrayType()) {
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.impl.Constant

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.