Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Syntax for bitwise AND operator
Syntax for bitwise AND operator [message #1793116] Tue, 31 July 2018 10:52 Go to next message
shubhankar chowdhury is currently offline shubhankar chowdhuryFriend
Messages: 17
Registered: January 2018
Junior Member
Hi ,

I have an if condition in which i want to test all the condition and if all are TRUE then enter the condition.

but in xtend i dont know the syntax of bitwise or as in java it is '&'


Regards,
Shubhankar
Re: Syntax for bitwise AND operator [message #1793117 is a reply to message #1793116] Tue, 31 July 2018 10:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
you can use

1.bitwiseOr(2)
1.bitwiseAnd(2)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Syntax for bitwise AND operator [message #1793122 is a reply to message #1793117] Tue, 31 July 2018 11:18 Go to previous messageGo to next message
shubhankar chowdhury is currently offline shubhankar chowdhuryFriend
Messages: 17
Registered: January 2018
Junior Member
both my condition are boolean condition. when i try to implement

(booleanValue1).bitwiseAnd(booleanVlaue2), I am geting the error as:
The method bitwiseAnd(boolean) is undefined for the type boolean

Do I need to import any package?

[Updated on: Tue, 31 July 2018 11:26]

Report message to a moderator

Re: Syntax for bitwise AND operator [message #1793129 is a reply to message #1793122] Tue, 31 July 2018 12:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
bytewise and for java ???
what exactly should that do different from a normal &&


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 31 July 2018 12:25]

Report message to a moderator

Re: Syntax for bitwise AND operator [message #1793130 is a reply to message #1793129] Tue, 31 July 2018 12:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
of course you can do something like

java util
package a;

import org.eclipse.xtext.xbase.lib.Inline;
import org.eclipse.xtext.xbase.lib.Pure;

public class Lala {
	
	@Pure
	@Inline(value="($1 & $2)", constantExpression=true)
	public static boolean bytewiseAnd(boolean a, boolean b) {
		return a&b;
	}
	
	@Pure
	@Inline(value="($1 | $2)", constantExpression=true)
	public static boolean bytewiseOr(boolean a, boolean b) {
		return a|b;
	}

}

xtend code
package a

import static extension a.Lala.*

class Demo { 
	def main() {
		val x = 1.bitwiseOr(2)
		val y = 1.bitwiseAnd(2)
		val a = true.bytewiseAnd(false)
		val a2 = true.bytewiseOr(false) 
	}
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Syntax for bitwise AND operator [message #1794935 is a reply to message #1793129] Tue, 11 September 2018 10:16 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Christian Dietrich wrote on Tue, 31 July 2018 12:25
bytewise and for java ???
what exactly should that do different from a normal &&


& and | as boolean operators are eager as opposed to && and || which are lazy.


Previous Topic:XText importing a specific file extension
Next Topic:Operator == with null operand
Goto Forum:
  


Current Time: Tue Apr 16 08:46:19 GMT 2024

Powered by FUDForum. Page generated in 0.06204 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top