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

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


  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


   * 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()) {
          return true;
        }
      }
    }
    return false;
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

        this.constants = new int[length];
        CaseStatement[] duplicateCaseStatements = null;
        int duplicateCaseStatementsCounter = 0;
        int counter = 0;
        for (int i = 0; i < length; i++) {
          Constant constant;
          final Statement statement = this.statements[i];
          if ((constant = statement.resolveCase(this.scope, expressionType, this)) != Constant.NotAConstant) {
            int key = constant.intValue();
            //----check for duplicate case statement------------
            for (int j = 0; j < counter; j++) {
              if (this.constants[j] == key) {
                final CaseStatement currentCaseStatement = (CaseStatement) statement;
                if (duplicateCaseStatements == null) {
View Full Code Here

        if (value instanceof ArrayInitializer) {
          ArrayInitializer initializer = (ArrayInitializer) value;
          Expression[] inits = initializer.expressions;
          if (inits != null) {
            for (int j = 0, initsLength = inits.length; j < initsLength; j++) {
              Constant cst = inits[j].constant;
              if (cst != Constant.NotAConstant && cst.typeID() == T_JavaLangString) {
                IrritantSet irritants = CompilerOptions.warningTokenToIrritants(cst.stringValue());
                if (irritants != null) {
                  if (suppressWarningIrritants == null) {
                    suppressWarningIrritants = new IrritantSet(irritants);
                  } else if (suppressWarningIrritants.set(irritants) == null) {
                      scope.problemReporter().unusedWarningToken(inits[j]);
                  }
                } else {
                  scope.problemReporter().unhandledWarningToken(inits[j]);
                }
              }
            }
          }
        } else {
          Constant cst = value.constant;
          if (cst != Constant.NotAConstant && cst.typeID() == T_JavaLangString) {
            IrritantSet irritants = CompilerOptions.warningTokenToIrritants(cst.stringValue());
            if (irritants != null) {
              suppressWarningIrritants = new IrritantSet(irritants);
              // TODO: should check for unused warning token against enclosing annotation as well ?
            } else {
              scope.problemReporter().unhandledWarningToken(value);
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){
      if (this.contentsOffset + 8 >= this.contents.length) {
        resizeContents(8);
      }
      // Now we generate the constant attribute corresponding to the fieldBinding
      int constantValueNameIndex =
        this.constantPool.literalIndex(AttributeNamesConstants.ConstantValueName);
      this.contents[this.contentsOffset++] = (byte) (constantValueNameIndex >> 8);
      this.contents[this.contentsOffset++] = (byte) constantValueNameIndex;
      // The attribute length = 2 in case of a constantValue attribute
      this.contents[this.contentsOffset++] = 0;
      this.contents[this.contentsOffset++] = 0;
      this.contents[this.contentsOffset++] = 0;
      this.contents[this.contentsOffset++] = 2;
      attributesNumber++;
      // Need to add the constant_value_index
      switch (fieldConstant.typeID()) {
        case T_boolean :
          int booleanValueIndex =
            this.constantPool.literalIndex(fieldConstant.booleanValue() ? 1 : 0);
          this.contents[this.contentsOffset++] = (byte) (booleanValueIndex >> 8);
          this.contents[this.contentsOffset++] = (byte) booleanValueIndex;
          break;
        case T_byte :
        case T_char :
        case T_int :
        case T_short :
          int integerValueIndex =
            this.constantPool.literalIndex(fieldConstant.intValue());
          this.contents[this.contentsOffset++] = (byte) (integerValueIndex >> 8);
          this.contents[this.contentsOffset++] = (byte) integerValueIndex;
          break;
        case T_float :
          int floatValueIndex =
            this.constantPool.literalIndex(fieldConstant.floatValue());
          this.contents[this.contentsOffset++] = (byte) (floatValueIndex >> 8);
          this.contents[this.contentsOffset++] = (byte) floatValueIndex;
          break;
        case T_double :
          int doubleValueIndex =
            this.constantPool.literalIndex(fieldConstant.doubleValue());
          this.contents[this.contentsOffset++] = (byte) (doubleValueIndex >> 8);
          this.contents[this.contentsOffset++] = (byte) doubleValueIndex;
          break;
        case T_long :
          int longValueIndex =
            this.constantPool.literalIndex(fieldConstant.longValue());
          this.contents[this.contentsOffset++] = (byte) (longValueIndex >> 8);
          this.contents[this.contentsOffset++] = (byte) longValueIndex;
          break;
        case T_JavaLangString :
          int stringValueIndex =
View Full Code Here

    return;
  } else {
    switch (this.bits & ASTNode.RestrictiveFlagMASK) {
      case Binding.FIELD : // reading a field
        FieldBinding codegenField = ((FieldBinding) this.binding).original();
        Constant fieldConstant = codegenField.constant();
        if (fieldConstant != Constant.NotAConstant) {
          // directly use inlined value for constant fields
          if (valueRequired) {
            codeStream.generateConstant(fieldConstant, this.implicitConversion);
          }
View Full Code Here

            codeStream.dup();
          }
          codeStream.store(localBinding, false);
          return;
        case T_int :
          Constant assignConstant;
          if (((assignConstant = expression.constant) != Constant.NotAConstant)
              && (assignConstant.typeID() != TypeIds.T_float) // only for integral types
              && (assignConstant.typeID() != TypeIds.T_double)) {// TODO (philippe) is this test needed ?
            switch (operator) {
              case PLUS :
                int increment  = assignConstant.intValue();
                if (increment != (short) increment) break; // not representable as a 16-bits value
                codeStream.iinc(localBinding.resolvedPosition, increment);
                if (valueRequired) {
                  codeStream.load(localBinding);
                }
                return;
              case MINUS :
                increment  = -assignConstant.intValue();
                if (increment != (short) increment) break; // not representable as a 16-bits value
                codeStream.iinc(localBinding.resolvedPosition, increment);
                if (valueRequired) {
                  codeStream.load(localBinding);
                }
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.