org.eclipse.jdt.internal.compiler.ast.IntLiteral Java Examples

The following examples show how to use org.eclipse.jdt.internal.compiler.ast.IntLiteral. 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: HandleEqualsAndHashCode.java    From EasyMPermission with MIT License 6 votes vote down vote up
public IfStatement generateCompareFloatOrDouble(Expression thisRef, Expression otherRef, char[] floatOrDouble, ASTNode source) {
	int pS = source.sourceStart, pE = source.sourceEnd;
	/* if (Float.compare(fieldName, other.fieldName) != 0) return false */
	MessageSend floatCompare = new MessageSend();
	floatCompare.sourceStart = pS; floatCompare.sourceEnd = pE;
	setGeneratedBy(floatCompare, source);
	floatCompare.receiver = generateQualifiedNameRef(source, TypeConstants.JAVA, TypeConstants.LANG, floatOrDouble);
	floatCompare.selector = "compare".toCharArray();
	floatCompare.arguments = new Expression[] {thisRef, otherRef};
	IntLiteral int0 = makeIntLiteral("0".toCharArray(), source);
	EqualExpression ifFloatCompareIsNot0 = new EqualExpression(floatCompare, int0, OperatorIds.NOT_EQUAL);
	ifFloatCompareIsNot0.sourceStart = pS; ifFloatCompareIsNot0.sourceEnd = pE;
	setGeneratedBy(ifFloatCompareIsNot0, source);
	FalseLiteral falseLiteral = new FalseLiteral(pS, pE);
	setGeneratedBy(falseLiteral, source);
	ReturnStatement returnFalse = new ReturnStatement(falseLiteral, pS, pE);
	setGeneratedBy(returnFalse, source);
	IfStatement ifStatement = new IfStatement(ifFloatCompareIsNot0, returnFalse, pS, pE);
	setGeneratedBy(ifStatement, source);
	return ifStatement;
}
 
Example #2
Source File: HandleEqualsAndHashCode.java    From EasyMPermission with MIT License 6 votes vote down vote up
/** Give 2 clones! */
public Expression longToIntForHashCode(Expression ref1, Expression ref2, ASTNode source) {
	int pS = source.sourceStart, pE = source.sourceEnd;
	/* (int)(ref >>> 32 ^ ref) */
	IntLiteral int32 = makeIntLiteral("32".toCharArray(), source);
	BinaryExpression higherBits = new BinaryExpression(ref1, int32, OperatorIds.UNSIGNED_RIGHT_SHIFT);
	setGeneratedBy(higherBits, source);
	BinaryExpression xorParts = new BinaryExpression(ref2, higherBits, OperatorIds.XOR);
	setGeneratedBy(xorParts, source);
	TypeReference intRef = TypeReference.baseTypeReference(TypeIds.T_int, 0);
	intRef.sourceStart = pS; intRef.sourceEnd = pE;
	setGeneratedBy(intRef, source);
	CastExpression expr = makeCastExpression(xorParts, intRef, source);
	expr.sourceStart = pS; expr.sourceEnd = pE;
	return expr;
}
 
Example #3
Source File: EclipseSingularsRecipes.java    From EasyMPermission with MIT License 6 votes vote down vote up
/** Generates 'this.<em>name</em>.size()' as an expression; if nullGuard is true, it's this.name == null ? 0 : this.name.size(). */
protected Expression getSize(EclipseNode builderType, char[] name, boolean nullGuard) {
	MessageSend invoke = new MessageSend();
	ThisReference thisRef = new ThisReference(0, 0);
	FieldReference thisDotName = new FieldReference(name, 0L);
	thisDotName.receiver = thisRef;
	invoke.receiver = thisDotName;
	invoke.selector = SIZE_TEXT;
	if (!nullGuard) return invoke;
	
	ThisReference cdnThisRef = new ThisReference(0, 0);
	FieldReference cdnThisDotName = new FieldReference(name, 0L);
	cdnThisDotName.receiver = cdnThisRef;
	NullLiteral nullLiteral = new NullLiteral(0, 0);
	EqualExpression isNull = new EqualExpression(cdnThisDotName, nullLiteral, OperatorIds.EQUAL_EQUAL);
	IntLiteral zeroLiteral = makeIntLiteral(new char[] {'0'}, null);
	ConditionalExpression conditional = new ConditionalExpression(isNull, zeroLiteral, invoke);
	return conditional;
}
 
Example #4
Source File: SetGeneratedByVisitor.java    From EasyMPermission with MIT License 4 votes vote down vote up
@Override public boolean visit(IntLiteral node, BlockScope scope) {
	fixPositions(setGeneratedBy(node, source));
	return super.visit(node, scope);
}
 
Example #5
Source File: BinaryExpressionFragmentBuilder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean visit(IntLiteral intLiteral, BlockScope scope) {
	addSmallFragment(intLiteral);
	return false;
}
 
Example #6
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);
}