Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.TypeIds#T_double
The following examples show how to use
org.eclipse.jdt.internal.compiler.lookup.TypeIds#T_double .
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: PrimitiveTypeImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static TypeKind getKind(BaseTypeBinding binding) { switch (binding.id) { case TypeIds.T_boolean: return TypeKind.BOOLEAN; case TypeIds.T_byte: return TypeKind.BYTE; case TypeIds.T_char: return TypeKind.CHAR; case TypeIds.T_double: return TypeKind.DOUBLE; case TypeIds.T_float: return TypeKind.FLOAT; case TypeIds.T_int: return TypeKind.INT; case TypeIds.T_long: return TypeKind.LONG; case TypeIds.T_short: return TypeKind.SHORT; default: throw new IllegalArgumentException("BaseTypeBinding of unexpected id " + binding.id); //$NON-NLS-1$ } }
Example 2
Source File: VariableBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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: StackMapFrame.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public int getNumberOfLocals() { if (this.numberOfLocals != -1) { return this.numberOfLocals; } int result = 0; final int length = this.locals == null ? 0 : this.locals.length; for(int i = 0; i < length; i++) { if (this.locals[i] != null) { switch(this.locals[i].id()) { case TypeIds.T_double : case TypeIds.T_long : i++; } result++; } } this.numberOfLocals = result; return result; }
Example 4
Source File: CodeSnippetQualifiedNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Check and/or redirect the field access to the delegate receiver if any */ public void generateAssignment(BlockScope currentScope, CodeStream codeStream, Assignment assignment, boolean valueRequired) { FieldBinding lastFieldBinding = this.otherBindings == null ? (FieldBinding) this.binding : this.otherBindings[this.otherBindings.length-1]; if (lastFieldBinding.canBeSeenBy(getFinalReceiverType(), this, currentScope)) { super.generateAssignment(currentScope, codeStream, assignment, valueRequired); return; } lastFieldBinding = generateReadSequence(currentScope, codeStream); codeStream.generateEmulationForField(lastFieldBinding); codeStream.swap(); assignment.expression.generateCode(currentScope, codeStream, true); if (valueRequired) { switch (lastFieldBinding.type.id) { case TypeIds.T_long : case TypeIds.T_double : codeStream.dup2_x2(); break; default : codeStream.dup_x2(); break; } } codeStream.generateEmulatedWriteAccessForField(lastFieldBinding); if (valueRequired) { codeStream.generateImplicitConversion(assignment.implicitConversion); } }
Example 5
Source File: VerificationTypeInfo.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void setBinding(TypeBinding binding) { this.constantPoolName = binding.constantPoolName(); final int typeBindingId = binding.id; this.id = typeBindingId; switch(typeBindingId) { case TypeIds.T_boolean : case TypeIds.T_byte : case TypeIds.T_char : case TypeIds.T_int : case TypeIds.T_short : this.tag = VerificationTypeInfo.ITEM_INTEGER; break; case TypeIds.T_float : this.tag = VerificationTypeInfo.ITEM_FLOAT; break; case TypeIds.T_long : this.tag = VerificationTypeInfo.ITEM_LONG; break; case TypeIds.T_double : this.tag = VerificationTypeInfo.ITEM_DOUBLE; break; case TypeIds.T_null : this.tag = VerificationTypeInfo.ITEM_NULL; break; default: this.tag = VerificationTypeInfo.ITEM_OBJECT; } }
Example 6
Source File: ArrayReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) { this.receiver.generateCode(currentScope, codeStream, true); if (this.receiver instanceof CastExpression // ((type[])null)[0] && ((CastExpression)this.receiver).innermostCastedExpression().resolvedType == TypeBinding.NULL){ codeStream.checkcast(this.receiver.resolvedType); } this.position.generateCode(currentScope, codeStream, true); codeStream.dup2(); codeStream.arrayAt(this.resolvedType.id); if (valueRequired) { switch(this.resolvedType.id) { case TypeIds.T_long : case TypeIds.T_double : codeStream.dup2_x2(); break; default : codeStream.dup_x2(); break; } } codeStream.generateImplicitConversion(this.implicitConversion); codeStream.generateConstant( postIncrement.expression.constant, this.implicitConversion); codeStream.sendOperator(postIncrement.operator, this.implicitConversion & TypeIds.COMPILE_TYPE_MASK); codeStream.generateImplicitConversion( postIncrement.preAssignImplicitConversion); codeStream.arrayAtPut(this.resolvedType.id, false); }
Example 7
Source File: CodeSnippetFieldReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void generateAssignment(BlockScope currentScope, CodeStream codeStream, Assignment assignment, boolean valueRequired) { FieldBinding codegenBinding = this.binding.original(); if (codegenBinding.canBeSeenBy(this.actualReceiverType, this, currentScope)) { this.receiver.generateCode(currentScope, codeStream, !codegenBinding.isStatic()); assignment.expression.generateCode(currentScope, codeStream, true); fieldStore(currentScope, codeStream, codegenBinding, null, this.actualReceiverType, this.receiver.isImplicitThis(), valueRequired); } else { codeStream.generateEmulationForField(codegenBinding); this.receiver.generateCode(currentScope, codeStream, !codegenBinding.isStatic()); if (codegenBinding.isStatic()) { // need a receiver? codeStream.aconst_null(); } assignment.expression.generateCode(currentScope, codeStream, true); if (valueRequired) { switch (codegenBinding.type.id) { case TypeIds.T_long : case TypeIds.T_double : codeStream.dup2_x2(); break; default : codeStream.dup_x2(); break; } } codeStream.generateEmulatedWriteAccessForField(codegenBinding); } if (valueRequired){ codeStream.generateImplicitConversion(assignment.implicitConversion); } }
Example 8
Source File: ClassfileDigester.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
private void updateConstant(Constant constant) { updateInt(constant.typeID()); 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()); } }
Example 9
Source File: Util.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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 10
Source File: Member.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * 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 11
Source File: VariableElementImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@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 12
Source File: AnnotationValueImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings("unchecked") // Need to cast Object _value to a List<AnnotationValue> @Override public <R, P> R accept(AnnotationValueVisitor<R, P> v, P p) { switch (_kind) { case TypeIds.T_boolean: return v.visitBoolean((Boolean)_value, p); case TypeIds.T_byte: return v.visitByte((Byte)_value, p); case TypeIds.T_char: return v.visitChar((Character)_value, p); case TypeIds.T_double: return v.visitDouble((Double)_value, p); case TypeIds.T_float: return v.visitFloat((Float)_value, p); case TypeIds.T_int: return v.visitInt((Integer)_value, p); case TypeIds.T_JavaLangString: return v.visitString((String)_value, p); case TypeIds.T_long: return v.visitLong((Long)_value, p); case TypeIds.T_short: return v.visitShort((Short)_value, p); case T_EnumConstant: return v.visitEnumConstant((VariableElement)_value, p); case T_ClassObject: return v.visitType((TypeMirror)_value, p); case T_AnnotationMirror: return v.visitAnnotation((AnnotationMirror)_value, p); case T_ArrayType: return v.visitArray((List<AnnotationValue>)_value, p); default: return null; } }
Example 13
Source File: CodeSnippetFieldReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) { boolean isStatic; FieldBinding codegenBinding = this.binding.original(); if (codegenBinding.canBeSeenBy(this.actualReceiverType, this, currentScope)) { super.generatePostIncrement(currentScope, codeStream, postIncrement, valueRequired); } else { this.receiver.generateCode(currentScope, codeStream, !(isStatic = codegenBinding.isStatic())); if (isStatic) { codeStream.aconst_null(); } // the actual stack is: receiver codeStream.dup(); // the actual stack is: receiver receiver codeStream.generateEmulatedReadAccessForField(codegenBinding); // the actual stack is: receiver value // receiver value // value receiver value dup_x1 or dup2_x1 if value required // value value receiver value dup_x1 or dup2_x1 // value value receiver pop or pop2 // value value receiver field generateEmulationForField // value value field receiver swap // value field receiver value field receiver dup2_x1 or dup2_x2 // value field receiver value pop2 // value field receiver newvalue generate constant + op // value store int typeID; switch (typeID = codegenBinding.type.id) { case TypeIds.T_long : case TypeIds.T_double : if (valueRequired) { codeStream.dup2_x1(); } codeStream.dup2_x1(); codeStream.pop2(); break; default : if (valueRequired) { codeStream.dup_x1(); } codeStream.dup_x1(); codeStream.pop(); break; } codeStream.generateEmulationForField(codegenBinding); codeStream.swap(); switch (typeID) { case TypeIds.T_long : case TypeIds.T_double : codeStream.dup2_x2(); break; default : codeStream.dup2_x1(); break; } codeStream.pop2(); codeStream.generateConstant(postIncrement.expression.constant, this.implicitConversion); codeStream.sendOperator(postIncrement.operator, codegenBinding.type.id); codeStream.generateImplicitConversion(postIncrement.preAssignImplicitConversion); codeStream.generateEmulatedWriteAccessForField(codegenBinding); } }
Example 14
Source File: CodeSnippetQualifiedNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) { FieldBinding lastFieldBinding = this.otherBindings == null ? (FieldBinding) this.binding : this.otherBindings[this.otherBindings.length-1]; if (lastFieldBinding.canBeSeenBy(getFinalReceiverType(), this, currentScope)) { super.generateCompoundAssignment(currentScope, codeStream, expression, operator, assignmentImplicitConversion, valueRequired); return; } lastFieldBinding = generateReadSequence(currentScope, codeStream); if (lastFieldBinding.isStatic()){ codeStream.generateEmulationForField(lastFieldBinding); codeStream.swap(); codeStream.aconst_null(); codeStream.swap(); codeStream.generateEmulatedReadAccessForField(lastFieldBinding); } else { codeStream.generateEmulationForField(lastFieldBinding); codeStream.swap(); codeStream.dup(); codeStream.generateEmulatedReadAccessForField(lastFieldBinding); } // the last field access is a write access // perform the actual compound operation int operationTypeID; if ((operationTypeID = (this.implicitConversion & IMPLICIT_CONVERSION_MASK) >> 4) == T_JavaLangString) { codeStream.generateStringConcatenationAppend(currentScope, null, expression); } else { // promote the array reference to the suitable operation type codeStream.generateImplicitConversion(this.implicitConversion); // generate the increment value (will by itself be promoted to the operation value) if (expression == IntLiteral.One){ // prefix operation codeStream.generateConstant(expression.constant, this.implicitConversion); } else { expression.generateCode(currentScope, codeStream, true); } // perform the operation codeStream.sendOperator(operator, operationTypeID); // cast the value back to the array reference type codeStream.generateImplicitConversion(assignmentImplicitConversion); } // actual assignment // current stack is: // field receiver value if (valueRequired) { switch (lastFieldBinding.type.id) { case TypeIds.T_long : case TypeIds.T_double : codeStream.dup2_x2(); break; default : codeStream.dup_x2(); break; } } // current stack is: // value field receiver value codeStream.generateEmulatedWriteAccessForField(lastFieldBinding); }
Example 15
Source File: CodeSnippetQualifiedNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) { FieldBinding lastFieldBinding = this.otherBindings == null ? (FieldBinding) this.binding : this.otherBindings[this.otherBindings.length-1]; if (lastFieldBinding.canBeSeenBy(getFinalReceiverType(), this, currentScope)) { super.generatePostIncrement(currentScope, codeStream, postIncrement, valueRequired); return; } lastFieldBinding = generateReadSequence(currentScope, codeStream); codeStream.generateEmulatedReadAccessForField(lastFieldBinding); if (valueRequired) { switch (lastFieldBinding.type.id) { case TypeIds.T_long : case TypeIds.T_double : codeStream.dup2(); break; default : codeStream.dup(); break; } } codeStream.generateEmulationForField(lastFieldBinding); if ((TypeBinding.equalsEquals(lastFieldBinding.type, TypeBinding.LONG)) || (TypeBinding.equalsEquals(lastFieldBinding.type, TypeBinding.DOUBLE))) { codeStream.dup_x2(); codeStream.pop(); if (lastFieldBinding.isStatic()) { codeStream.aconst_null(); } else { generateReadSequence(currentScope, codeStream); } codeStream.dup_x2(); codeStream.pop(); } else { codeStream.dup_x1(); codeStream.pop(); if (lastFieldBinding.isStatic()) { codeStream.aconst_null(); } else { generateReadSequence(currentScope, codeStream); } codeStream.dup_x1(); codeStream.pop(); } codeStream.generateConstant(postIncrement.expression.constant, this.implicitConversion); codeStream.sendOperator(postIncrement.operator, lastFieldBinding.type.id); codeStream.generateImplicitConversion(postIncrement.preAssignImplicitConversion); codeStream.generateEmulatedWriteAccessForField(lastFieldBinding); }
Example 16
Source File: MemberValuePairBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
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 17
Source File: VerificationTypeInfo.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void replaceWithElementType() { if (this.constantPoolName[1] == 'L') { this.constantPoolName = CharOperation.subarray(this.constantPoolName, 2, this.constantPoolName.length - 1); } else { this.constantPoolName = CharOperation.subarray(this.constantPoolName, 1, this.constantPoolName.length); if (this.constantPoolName.length == 1) { switch(this.constantPoolName[0]) { case 'I' : this.id = TypeIds.T_int; break; case 'B' : this.id = TypeIds.T_byte; break; case 'S' : this.id = TypeIds.T_short; break; case 'C' : this.id = TypeIds.T_char; break; case 'J' : this.id = TypeIds.T_long; break; case 'F' : this.id = TypeIds.T_float; break; case 'D' : this.id = TypeIds.T_double; break; case 'Z' : this.id = TypeIds.T_boolean; break; case 'N' : this.id = TypeIds.T_null; break; case 'V' : this.id = TypeIds.T_void; break; } } } }
Example 18
Source File: ClassFileReader.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
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; }
Example 19
Source File: QualifiedNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) { FieldBinding lastFieldBinding = generateReadSequence(currentScope, codeStream); // check if this post increment is the only usage of a private field reportOnlyUselesslyReadPrivateField(currentScope, lastFieldBinding, valueRequired); boolean isFirst = lastFieldBinding == this.binding && (this.indexOfFirstFieldBinding == 1 || TypeBinding.equalsEquals(lastFieldBinding.declaringClass, currentScope.enclosingReceiverType())) && this.otherBindings == null; // could be dup: next.next.next TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, lastFieldBinding, getFinalReceiverType(), isFirst); SyntheticMethodBinding accessor = this.syntheticReadAccessors == null ? null : this.syntheticReadAccessors[this.syntheticReadAccessors.length - 1]; if (lastFieldBinding.isStatic()) { if (accessor == null) { codeStream.fieldAccess(Opcodes.OPC_getstatic, lastFieldBinding, constantPoolDeclaringClass); } else { codeStream.invoke(Opcodes.OPC_invokestatic, accessor, constantPoolDeclaringClass); } } else { codeStream.dup(); if (accessor == null) { codeStream.fieldAccess(Opcodes.OPC_getfield, lastFieldBinding, null /* default declaringClass */); } else { codeStream.invoke(Opcodes.OPC_invokestatic, accessor, null /* default declaringClass */); } } TypeBinding requiredGenericCast = getGenericCast(this.otherBindings == null ? 0 : this.otherBindings.length); TypeBinding operandType; if (requiredGenericCast != null) { codeStream.checkcast(requiredGenericCast); operandType = requiredGenericCast; } else { operandType = lastFieldBinding.type; } // duplicate the old field value if (valueRequired) { if (lastFieldBinding.isStatic()) { switch (operandType.id) { case TypeIds.T_long : case TypeIds.T_double : codeStream.dup2(); break; default: codeStream.dup(); break; } } else { // Stack: [owner][old field value] ---> [old field value][owner][old field value] switch (operandType.id) { case TypeIds.T_long : case TypeIds.T_double : codeStream.dup2_x1(); break; default: codeStream.dup_x1(); break; } } } codeStream.generateImplicitConversion(this.implicitConversion); codeStream.generateConstant( postIncrement.expression.constant, this.implicitConversion); codeStream.sendOperator(postIncrement.operator, this.implicitConversion & TypeIds.COMPILE_TYPE_MASK); codeStream.generateImplicitConversion( postIncrement.preAssignImplicitConversion); fieldStore(currentScope, codeStream, lastFieldBinding, this.syntheticWriteAccessor, getFinalReceiverType(), false /*implicit this*/, false); }
Example 20
Source File: SingleNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void generateAssignment(BlockScope currentScope, CodeStream codeStream, Assignment assignment, boolean valueRequired) { // optimizing assignment like: i = i + 1 or i = 1 + i if (assignment.expression.isCompactableOperation()) { BinaryExpression operation = (BinaryExpression) assignment.expression; int operator = (operation.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT; SingleNameReference variableReference; if ((operation.left instanceof SingleNameReference) && ((variableReference = (SingleNameReference) operation.left).binding == this.binding)) { // i = i + value, then use the variable on the right hand side, since it has the correct implicit conversion variableReference.generateCompoundAssignment(currentScope, codeStream, this.syntheticAccessors == null ? null : this.syntheticAccessors[SingleNameReference.WRITE], operation.right, operator, operation.implicitConversion, valueRequired); if (valueRequired) { codeStream.generateImplicitConversion(assignment.implicitConversion); } return; } if ((operation.right instanceof SingleNameReference) && ((operator == OperatorIds.PLUS) || (operator == OperatorIds.MULTIPLY)) // only commutative operations && ((variableReference = (SingleNameReference) operation.right).binding == this.binding) && (operation.left.constant != Constant.NotAConstant) // exclude non constant expressions, since could have side-effect && (((operation.left.implicitConversion & TypeIds.IMPLICIT_CONVERSION_MASK) >> 4) != TypeIds.T_JavaLangString) // exclude string concatenation which would occur backwards && (((operation.right.implicitConversion & TypeIds.IMPLICIT_CONVERSION_MASK) >> 4) != TypeIds.T_JavaLangString)) { // exclude string concatenation which would occur backwards // i = value + i, then use the variable on the right hand side, since it has the correct implicit conversion variableReference.generateCompoundAssignment(currentScope, codeStream, this.syntheticAccessors == null ? null : this.syntheticAccessors[SingleNameReference.WRITE], operation.left, operator, operation.implicitConversion, valueRequired); if (valueRequired) { codeStream.generateImplicitConversion(assignment.implicitConversion); } return; } } switch (this.bits & ASTNode.RestrictiveFlagMASK) { case Binding.FIELD : // assigning to a field int pc = codeStream.position; FieldBinding codegenBinding = ((FieldBinding) this.binding).original(); if (!codegenBinding.isStatic()) { // need a receiver? if ((this.bits & ASTNode.DepthMASK) != 0) { ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT); Object[] emulationPath = currentScope.getEmulationPath(targetType, true /*only exact match*/, false/*consider enclosing arg*/); codeStream.generateOuterAccess(emulationPath, this, targetType, currentScope); } else { generateReceiver(codeStream); } } codeStream.recordPositionsFrom(pc, this.sourceStart); assignment.expression.generateCode(currentScope, codeStream, true); fieldStore(currentScope, codeStream, codegenBinding, this.syntheticAccessors == null ? null : this.syntheticAccessors[SingleNameReference.WRITE], this.actualReceiverType, true /*implicit this*/, valueRequired); if (valueRequired) { codeStream.generateImplicitConversion(assignment.implicitConversion); } // no need for generic cast as value got dupped return; case Binding.LOCAL : // assigning to a local variable LocalVariableBinding localBinding = (LocalVariableBinding) this.binding; if (localBinding.resolvedPosition != -1) { assignment.expression.generateCode(currentScope, codeStream, true); } else { if (assignment.expression.constant != Constant.NotAConstant) { // assigning an unused local to a constant value = no actual assignment is necessary if (valueRequired) { codeStream.generateConstant(assignment.expression.constant, assignment.implicitConversion); } } else { assignment.expression.generateCode(currentScope, codeStream, true); /* Even though the value may not be required, we force it to be produced, and discard it later on if it was actually not necessary, so as to provide the same behavior as JDK1.2beta3. */ if (valueRequired) { codeStream.generateImplicitConversion(assignment.implicitConversion); // implicit conversion } else { switch(localBinding.type.id) { case TypeIds.T_long : case TypeIds.T_double : codeStream.pop2(); break; default : codeStream.pop(); break; } } } return; } // 26903, need extra cast to store null in array local var if (localBinding.type.isArrayType() && ((assignment.expression instanceof CastExpression) // arrayLoc = (type[])null && (((CastExpression)assignment.expression).innermostCastedExpression().resolvedType == TypeBinding.NULL))){ codeStream.checkcast(localBinding.type); } // normal local assignment (since cannot store in outer local which are final locations) codeStream.store(localBinding, valueRequired); if ((this.bits & ASTNode.FirstAssignmentToLocal) != 0) { // for local variable debug attributes localBinding.recordInitializationStartPC(codeStream.position); } // implicit conversion if (valueRequired) { codeStream.generateImplicitConversion(assignment.implicitConversion); } } }