Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.TypeIds#T_long

The following examples show how to use org.eclipse.jdt.internal.compiler.lookup.TypeIds#T_long . 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 vote down vote up
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: StackMapFrame.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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 3
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 4
Source File: CodeSnippetQualifiedNameReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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: ArrayReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 6
Source File: LambdaExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void addSyntheticArgument(LocalVariableBinding actualOuterLocalVariable) {
	
	if (this.original != this || this.binding == null) 
		return; // Do not bother tracking outer locals for clones created during overload resolution.
	
	SyntheticArgumentBinding syntheticLocal = null;
	int newSlot = this.outerLocalVariables.length;
	for (int i = 0; i < newSlot; i++) {
		if (this.outerLocalVariables[i].actualOuterLocalVariable == actualOuterLocalVariable)
			return;
	}
	System.arraycopy(this.outerLocalVariables, 0, this.outerLocalVariables = new SyntheticArgumentBinding[newSlot + 1], 0, newSlot);
	this.outerLocalVariables[newSlot] = syntheticLocal = new SyntheticArgumentBinding(actualOuterLocalVariable);
	syntheticLocal.resolvedPosition = this.outerLocalVariablesSlotSize; // may need adjusting later if we need to generate an instance method for the lambda.
	syntheticLocal.declaringScope = this.scope;
	int parameterCount = this.binding.parameters.length;
	TypeBinding [] newParameters = new TypeBinding[parameterCount + 1];
	newParameters[newSlot] = actualOuterLocalVariable.type;
	for (int i = 0, j = 0; i < parameterCount; i++, j++) {
		if (i == newSlot) j++;
		newParameters[j] = this.binding.parameters[i];
	}
	this.binding.parameters = newParameters;
	switch (syntheticLocal.type.id) {
		case TypeIds.T_long :
		case TypeIds.T_double :
			this.outerLocalVariablesSlotSize  += 2;
			break;
		default :
			this.outerLocalVariablesSlotSize++;
			break;
	}		
}
 
Example 7
Source File: FieldInfo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Return a wrapper that contains the constant of the field.
 * @return java.lang.Object
 */
public Object getWrappedConstantValue() {

	if (this.wrappedConstantValue == null) {
		if (hasConstant()) {
			Constant fieldConstant = getConstant();
			switch (fieldConstant.typeID()) {
				case TypeIds.T_int :
					this.wrappedConstantValue = new Integer(fieldConstant.intValue());
					break;
				case TypeIds.T_byte :
					this.wrappedConstantValue = new Byte(fieldConstant.byteValue());
					break;
				case TypeIds.T_short :
					this.wrappedConstantValue = new Short(fieldConstant.shortValue());
					break;
				case TypeIds.T_char :
					this.wrappedConstantValue = new Character(fieldConstant.charValue());
					break;
				case TypeIds.T_float :
					this.wrappedConstantValue = new Float(fieldConstant.floatValue());
					break;
				case TypeIds.T_double :
					this.wrappedConstantValue = new Double(fieldConstant.doubleValue());
					break;
				case TypeIds.T_boolean :
					this.wrappedConstantValue = Util.toBoolean(fieldConstant.booleanValue());
					break;
				case TypeIds.T_long :
					this.wrappedConstantValue = new Long(fieldConstant.longValue());
					break;
				case TypeIds.T_JavaLangString :
					this.wrappedConstantValue = fieldConstant.stringValue();
			}
		}
	}
	return this.wrappedConstantValue;
}
 
Example 8
Source File: ClassfileDigester.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
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: Eclipse.java    From EasyMPermission with MIT License 5 votes vote down vote up
/**
 * Returns the actual value of the given Literal or Literal-like node.
 */
public static Object calculateValue(Expression e) {
	if (e instanceof Literal) {
		((Literal)e).computeConstant();
		switch (e.constant.typeID()) {
		case TypeIds.T_int: return e.constant.intValue();
		case TypeIds.T_byte: return e.constant.byteValue();
		case TypeIds.T_short: return e.constant.shortValue();
		case TypeIds.T_char: return e.constant.charValue();
		case TypeIds.T_float: return e.constant.floatValue();
		case TypeIds.T_double: return e.constant.doubleValue();
		case TypeIds.T_boolean: return e.constant.booleanValue();
		case TypeIds.T_long: return e.constant.longValue();
		case TypeIds.T_JavaLangString: return e.constant.stringValue();
		default: return null;
		}
	} else if (e instanceof ClassLiteralAccess) {
		return Eclipse.toQualifiedName(((ClassLiteralAccess)e).type.getTypeName());
	} else if (e instanceof SingleNameReference) {
		return new String(((SingleNameReference)e).token);
	} else if (e instanceof QualifiedNameReference) {
		String qName = Eclipse.toQualifiedName(((QualifiedNameReference)e).tokens);
		int idx = qName.lastIndexOf('.');
		return idx == -1 ? qName : qName.substring(idx+1);
	}
	
	return null;
}
 
Example 10
Source File: CodeSnippetFieldReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 11
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 12
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 13
Source File: AnnotationValueImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@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 14
Source File: CodeSnippetSingleNameReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) {
	switch (this.bits & RestrictiveFlagMASK) {
		case Binding.FIELD : // assigning to a field
			FieldBinding codegenField = ((FieldBinding) this.binding).original();
			if (codegenField.canBeSeenBy(getReceiverType(currentScope), this, currentScope)) {
				super.generatePostIncrement(currentScope, codeStream, postIncrement, valueRequired);
			} else {
				if (codegenField.isStatic()) {
					codeStream.aconst_null();
				} else {
					if ((this.bits & DepthMASK) != 0) {
						// internal error, per construction we should have found it
						// not yet supported
						currentScope.problemReporter().needImplementation(this);
					} else {
						generateReceiver(codeStream);
					}
				}
				codeStream.generateEmulatedReadAccessForField(codegenField);
				if (valueRequired) {
					switch (codegenField.type.id) {
						case TypeIds.T_long :
						case TypeIds.T_double :
							codeStream.dup2();
							break;
						default:
							codeStream.dup();
							break;
					}
				}
				codeStream.generateEmulationForField(codegenField);
				switch (codegenField.type.id) {
					case TypeIds.T_long :
					case TypeIds.T_double :
						codeStream.dup_x2();
						codeStream.pop();
						if (codegenField.isStatic()) {
							codeStream.aconst_null();
						} else {
							generateReceiver(codeStream);
						}
						codeStream.dup_x2();
						codeStream.pop();
						break;
					default:
						codeStream.dup_x1();
					codeStream.pop();
					if (codegenField.isStatic()) {
						codeStream.aconst_null();
					} else {
						generateReceiver(codeStream);
					}
					codeStream.dup_x1();
					codeStream.pop();
						break;
				}
				codeStream.generateConstant(postIncrement.expression.constant, this.implicitConversion);
				codeStream.sendOperator(postIncrement.operator, codegenField.type.id);
				codeStream.generateImplicitConversion(postIncrement.preAssignImplicitConversion);
				codeStream.generateEmulatedWriteAccessForField(codegenField);
			}
			return;
		case Binding.LOCAL : // assigning to a local variable
			super.generatePostIncrement(currentScope, codeStream, postIncrement, valueRequired);
	}
}
 
Example 15
Source File: CodeSnippetFieldReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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 16
Source File: CodeSnippetQualifiedNameReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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 17
Source File: VerificationTypeInfo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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: 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 19
Source File: SingleNameReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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);
			}
	}
}
 
Example 20
Source File: QualifiedNameReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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);
}