org.eclipse.xtext.xbase.XNumberLiteral Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.XNumberLiteral.
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: TypeComputationStateTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testTypeOnlyRegisteredOnce_04() throws Exception { XNumberLiteral expression = ((XNumberLiteral) expression("1")); resolver.initializeFrom(expression); PublicResolvedTypes resolution = new PublicResolvedTypes(resolver); AnyTypeReference any = resolution.getReferenceOwner().newAnyTypeReference(); new ExpressionBasedRootTypeComputationState(resolution, resolver.getBatchScopeProvider().newSession(expression.eResource()), expression, any).computeTypes(); Map<XExpression, List<TypeData>> expressionTypes = resolution.basicGetExpressionTypes(); TreeIterator<EObject> allContents = expression.eAllContents(); while (allContents.hasNext()) { EObject o = allContents.next(); List<TypeData> types = expressionTypes.get((o)); assertEquals(types.toString(), 1, size(filter(types, it -> !it.isReturnType()))); } }
Example #2
Source File: ShouldExtensions.java From sarl with Apache License 2.0 | 6 votes |
/** Ensure that the given number literal is equal to the given value. * * @param actual the number literal to test. * @param expected the expected value. * @return the validation status */ public static boolean shouldBe(XNumberLiteral actual, Object expected) { if (actual == null) { return false; } final Number number; if (expected instanceof Number) { number = (Number) expected; } else { try { number = NumberFormat.getInstance().parse(expected.toString()); } catch (Throwable exception) { return false; } } final Number anumber = cleanNumber(actual.getValue()); return number.doubleValue() == anumber.doubleValue(); }
Example #3
Source File: NumberLiterals.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected Class<? extends Number> getExplicitJavaType(XNumberLiteral literal) { String typeQualifier = getTypeQualifier(literal); if (equal("", typeQualifier)) return null; else if (equal("f", typeQualifier)) return Float.TYPE; else if (equal("l", typeQualifier)) return Long.TYPE; else if (equal("d", typeQualifier)) return Double.TYPE; else if (equal("bi", typeQualifier)) return BigInteger.class; else if (equal("bd", typeQualifier)) return BigDecimal.class; else throw new IllegalArgumentException("Invalid type qualifier " + typeQualifier); }
Example #4
Source File: Bug92Test.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlParsing") public void attributeDeclarationSyntax_inferredDouble() throws Exception { SarlScript mas = file(getParseHelper(), multilineString( "agent A1 {", " var myDouble = 0d", "}" )); validate(getValidationHelper(), getInjector(), mas).assertNoErrors(); assertEquals(1, mas.getXtendTypes().size()); assertInstance(SarlAgent.class, mas.getXtendTypes().get(0)); SarlAgent ag = (SarlAgent) mas.getXtendTypes().get(0); assertEquals(1, ag.getMembers().size()); assertInstance(SarlField.class, ag.getMembers().get(0)); SarlField attr = (SarlField) ag.getMembers().get(0); assertEquals("myDouble", attr.getName()); assertFalse(attr.isFinal()); assertNull(attr.getType()); assertInstance(XNumberLiteral.class, attr.getInitialValue()); XNumberLiteral literal = (XNumberLiteral) attr.getInitialValue(); assertEquals("0d", literal.getValue()); }
Example #5
Source File: ArgDefaultValueParsingTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlParsing") public void action_5p_3() throws Exception { SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString( "capacity C1 {", "def myaction(arg0 : int, arg1 : String, arg2 : int, arg3 : int = 34, arg4 : String)", "}" )); assertEquals(1, mas.getXtendTypes().size()); // assertTrue(Strings.isNullOrEmpty(mas.getPackage())); // SarlCapacity capacity = (SarlCapacity) mas.getXtendTypes().get(0); assertEquals("C1", capacity.getName()); assertTypeReferenceIdentifiers(capacity.getExtends()); assertEquals(1, capacity.getMembers().size()); // SarlAction signature = (SarlAction) capacity.getMembers().get(0); assertParameterNames(signature.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4"); assertParameterTypes(signature.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String"); assertParameterDefaultValues(signature.getParameters(), null, null, null, XNumberLiteral.class, "34", null); }
Example #6
Source File: Bug92Test.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlParsing") public void attributeDeclarationSyntax_Double() throws Exception { SarlScript mas = file(getParseHelper(), multilineString( "agent A1 {", " var myDouble : Double = 0d", "}" )); validate(getValidationHelper(), getInjector(), mas).assertNoErrors(); assertEquals(1, mas.getXtendTypes().size()); assertInstance(SarlAgent.class, mas.getXtendTypes().get(0)); SarlAgent ag = (SarlAgent) mas.getXtendTypes().get(0); assertEquals(1, ag.getMembers().size()); assertInstance(SarlField.class, ag.getMembers().get(0)); SarlField attr = (SarlField) ag.getMembers().get(0); assertEquals("myDouble", attr.getName()); assertFalse(attr.isFinal()); assertInstance(JvmParameterizedTypeReference.class, attr.getType()); JvmParameterizedTypeReference type = (JvmParameterizedTypeReference) attr.getType(); assertEquals(createType(Double.class).getQualifiedName(), type.getType().getQualifiedName()); assertInstance(XNumberLiteral.class, attr.getInitialValue()); XNumberLiteral literal = (XNumberLiteral) attr.getInitialValue(); assertEquals("0d", literal.getValue()); }
Example #7
Source File: DataTypeParsingTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlParsing") public void doubleToDouble_1() throws Exception { SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString( "agent A1 {", " var internalTime : Double = 0.0", "}" )); assertEquals(1, mas.getXtendTypes().size()); // assertTrue(Strings.isNullOrEmpty(mas.getPackage())); // SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0); assertEquals("A1", agent.getName()); assertNull(agent.getExtends()); assertEquals(1, agent.getMembers().size()); // SarlField attr = (SarlField) agent.getMembers().get(0); assertEquals("internalTime", attr.getName()); assertTypeReferenceIdentifier(attr.getType(), "java.lang.Double"); assertXExpression(attr.getInitialValue(), XNumberLiteral.class, "0.0"); }
Example #8
Source File: NumberLiterals.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected String getTypeQualifier(XNumberLiteral literal) { String valueAsLowerCase = literal.getValue().toLowerCase(); switch (getBase(literal)) { case 16: int index = valueAsLowerCase.indexOf('#'); if (index != -1) return valueAsLowerCase.substring(index + 1); else return ""; case 10: if (valueAsLowerCase.endsWith("bi") || valueAsLowerCase.endsWith("bd")) return valueAsLowerCase.substring(valueAsLowerCase.length() - 2); char lastChar = valueAsLowerCase.charAt(literal.getValue().length() - 1); switch (lastChar) { case 'l': case 'd': case 'f': return Character.toString(lastChar); default: return ""; } default: throw new IllegalArgumentException("Invalid number literal base " + getBase(literal)); } }
Example #9
Source File: ArgDefaultValueParsingTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlParsing") public void action_1p() throws Exception { SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString( "capacity C1 {", "def myaction(arg : int=4)", "}" )); assertEquals(1, mas.getXtendTypes().size()); // assertTrue(Strings.isNullOrEmpty(mas.getPackage())); // SarlCapacity capacity = (SarlCapacity) mas.getXtendTypes().get(0); assertEquals("C1", capacity.getName()); assertTypeReferenceIdentifiers(capacity.getExtends()); assertEquals(1, capacity.getMembers().size()); // SarlAction signature = (SarlAction) capacity.getMembers().get(0); assertParameterNames(signature.getParameters(), "arg"); assertParameterTypes(signature.getParameters(), "int"); assertParameterDefaultValues(signature.getParameters(), XNumberLiteral.class, "4"); }
Example #10
Source File: NumberLiterals.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public String getExponent(XNumberLiteral literal, String digits) { if (isHex(literal)) return null; int e = digits.indexOf('e'); if (e == -1) { e = digits.indexOf('E'); } if (e != -1) { if (e != digits.length() - 1 && (digits.charAt(e + 1) == '+' || digits.charAt(e + 1) == '-')) { e++; } if (e < digits.length() - 1) { String exponent = digits.substring(e + 1); return exponent; } } return null; }
Example #11
Source File: DataTypeParsingTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlParsing") public void doubleToDouble_4() throws Exception { SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString( "agent A1 {", " var internalTime : Double = 0d", "}" )); assertEquals(1, mas.getXtendTypes().size()); // assertTrue(Strings.isNullOrEmpty(mas.getPackage())); // SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0); assertEquals("A1", agent.getName()); assertNull(agent.getExtends()); assertEquals(1, agent.getMembers().size()); // SarlField attr = (SarlField) agent.getMembers().get(0); assertEquals("internalTime", attr.getName()); assertTypeReferenceIdentifier(attr.getType(), "java.lang.Double"); assertXExpression(attr.getInitialValue(), XNumberLiteral.class, "0d"); }
Example #12
Source File: ArgDefaultValueParsingTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlParsing") public void action_5p_0() throws Exception { SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString( "capacity C1 {", "def myaction(arg0 : int=4, arg1 : String, arg2 : int, arg3 : int, arg4 : String)", "}" )); assertEquals(1, mas.getXtendTypes().size()); // assertTrue(Strings.isNullOrEmpty(mas.getPackage())); // SarlCapacity capacity = (SarlCapacity) mas.getXtendTypes().get(0); assertEquals("C1", capacity.getName()); assertTypeReferenceIdentifiers(capacity.getExtends()); assertEquals(1, capacity.getMembers().size()); // SarlAction signature = (SarlAction) capacity.getMembers().get(0); assertParameterNames(signature.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4"); assertParameterTypes(signature.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String"); assertParameterDefaultValues(signature.getParameters(), XNumberLiteral.class, "4", null, null, null, null); }
Example #13
Source File: LiteralsCompiler.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override protected void internalToConvertedExpression(XExpression obj, ITreeAppendable appendable) { if (obj instanceof XStringLiteral) { _toJavaExpression((XStringLiteral) obj, appendable); } else if (obj instanceof XNumberLiteral) { _toJavaExpression((XNumberLiteral) obj, appendable); } else if (obj instanceof XNullLiteral) { _toJavaExpression((XNullLiteral) obj, appendable); } else if (obj instanceof XBooleanLiteral) { _toJavaExpression((XBooleanLiteral) obj, appendable); } else if (obj instanceof XTypeLiteral) { _toJavaExpression((XTypeLiteral) obj, appendable); } else { super.internalToConvertedExpression(obj, appendable); } }
Example #14
Source File: ArgDefaultValueParsingTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlParsing") public void action_5p_0_3_4() throws Exception { SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString( "capacity C1 {", "def myaction(arg0 : int=4, arg1 : String, arg2 : int, arg3 : int=56, arg4 : String=\"def\")", "}" )); assertEquals(1, mas.getXtendTypes().size()); // assertTrue(Strings.isNullOrEmpty(mas.getPackage())); // SarlCapacity capacity = (SarlCapacity) mas.getXtendTypes().get(0); assertEquals("C1", capacity.getName()); assertTypeReferenceIdentifiers(capacity.getExtends()); assertEquals(1, capacity.getMembers().size()); // SarlAction signature = (SarlAction) capacity.getMembers().get(0); assertParameterNames(signature.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4"); assertParameterTypes(signature.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String"); assertParameterDefaultValues(signature.getParameters(), XNumberLiteral.class, "4", null, null, XNumberLiteral.class, "56", XStringLiteral.class, "def"); }
Example #15
Source File: StandardFeatureCallArgumentsTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void test_10() { final IFeatureCallArguments arguments = this.toArgumentsWithReceiver("String s", "\"\", 1"); Assert.assertTrue(arguments.hasUnprocessedArguments()); Assert.assertEquals(3, arguments.getArgumentCount()); final IFeatureCallArgumentSlot valid = arguments.getNextUnprocessedArgumentSlot(); Assert.assertFalse(valid.isVarArg()); Assert.assertFalse(valid.isSuperfluous()); XExpression _argumentExpression = valid.getArgumentExpression(); Assert.assertTrue((_argumentExpression instanceof XStringLiteral)); valid.markProcessed(); Assert.assertTrue(arguments.hasUnprocessedArguments()); Assert.assertTrue(arguments.isProcessed(1)); final IFeatureCallArgumentSlot superfluous = arguments.getNextUnprocessedArgumentSlot(); Assert.assertFalse(superfluous.isVarArg()); Assert.assertTrue(superfluous.isSuperfluous()); XExpression _argumentExpression_1 = superfluous.getArgumentExpression(); Assert.assertTrue((_argumentExpression_1 instanceof XNumberLiteral)); Assert.assertFalse(arguments.isProcessed(2)); superfluous.markProcessed(); Assert.assertTrue(arguments.isProcessed(2)); Assert.assertFalse(arguments.hasUnprocessedArguments()); }
Example #16
Source File: VarArgFeatureCallArgumentsTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void test_04() { final IFeatureCallArguments arguments = this.toArgumentsWithoutReceiver("String s, int i", "\"\", 1"); Assert.assertEquals(2, arguments.getArgumentCount()); Assert.assertTrue(arguments.hasUnprocessedArguments()); final IFeatureCallArgumentSlot firstSlot = arguments.getNextUnprocessedArgumentSlot(); Assert.assertFalse(firstSlot.isVarArg()); Assert.assertFalse(firstSlot.isSuperfluous()); XExpression _argumentExpression = firstSlot.getArgumentExpression(); Assert.assertTrue((_argumentExpression instanceof XStringLiteral)); Assert.assertEquals("String", firstSlot.getDeclaredType().getSimpleName()); Assert.assertFalse(arguments.isProcessed(0)); firstSlot.markProcessed(); Assert.assertTrue(arguments.isProcessed(0)); Assert.assertTrue(arguments.hasUnprocessedArguments()); final IFeatureCallArgumentSlot secondSlot = arguments.getNextUnprocessedArgumentSlot(); Assert.assertTrue(secondSlot.isVarArg()); Assert.assertFalse(secondSlot.isSuperfluous()); XExpression _argumentExpression_1 = secondSlot.getArgumentExpression(); Assert.assertTrue((_argumentExpression_1 instanceof XNumberLiteral)); Assert.assertEquals("int", secondSlot.getDeclaredType().getSimpleName()); Assert.assertFalse(arguments.isProcessed(1)); secondSlot.markProcessed(); Assert.assertTrue(arguments.isProcessed(1)); Assert.assertFalse(arguments.hasUnprocessedArguments()); }
Example #17
Source File: ArgDefaultValueParsingTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlParsing") public void action_5p_0_2_4() throws Exception { SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString( "capacity C1 {", "def myaction(arg0 : int=4, arg1 : String, arg2 : int=18, arg3 : int, arg4 : String=\"def\")", "}" )); assertEquals(1, mas.getXtendTypes().size()); // assertTrue(Strings.isNullOrEmpty(mas.getPackage())); // SarlCapacity capacity = (SarlCapacity) mas.getXtendTypes().get(0); assertEquals("C1", capacity.getName()); assertTypeReferenceIdentifiers(capacity.getExtends()); assertEquals(1, capacity.getMembers().size()); // SarlAction signature = (SarlAction) capacity.getMembers().get(0); assertParameterNames(signature.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4"); assertParameterTypes(signature.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String"); assertParameterDefaultValues(signature.getParameters(), XNumberLiteral.class, "4", null, XNumberLiteral.class, "18", null, XStringLiteral.class, "def"); }
Example #18
Source File: VarArgFeatureCallArgumentsTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void test_09() { final IFeatureCallArguments arguments = this.toArgumentsWithoutReceiver("String s", "\"\", 1"); Assert.assertTrue(arguments.hasUnprocessedArguments()); Assert.assertEquals(2, arguments.getArgumentCount()); final IFeatureCallArgumentSlot valid = arguments.getNextUnprocessedArgumentSlot(); Assert.assertTrue(valid.isVarArg()); Assert.assertFalse(valid.isSuperfluous()); final List<XExpression> expressions = valid.getArgumentExpressions(); Assert.assertEquals(2, expressions.size()); XExpression _head = IterableExtensions.<XExpression>head(expressions); Assert.assertTrue((_head instanceof XStringLiteral)); XExpression _last = IterableExtensions.<XExpression>last(expressions); Assert.assertTrue((_last instanceof XNumberLiteral)); valid.markProcessed(); Assert.assertTrue(arguments.isProcessed(0)); Assert.assertTrue(arguments.isProcessed(1)); Assert.assertFalse(arguments.hasUnprocessedArguments()); }
Example #19
Source File: VarArgFeatureCallArgumentsTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void test_10() { final IFeatureCallArguments arguments = this.toArgumentsWithReceiver("String s", "\"\", 1"); Assert.assertTrue(arguments.hasUnprocessedArguments()); Assert.assertEquals(3, arguments.getArgumentCount()); final IFeatureCallArgumentSlot valid = arguments.getNextUnprocessedArgumentSlot(); Assert.assertTrue(valid.isVarArg()); Assert.assertFalse(valid.isSuperfluous()); final List<XExpression> expressions = valid.getArgumentExpressions(); Assert.assertEquals(2, expressions.size()); XExpression _head = IterableExtensions.<XExpression>head(expressions); Assert.assertTrue((_head instanceof XStringLiteral)); XExpression _last = IterableExtensions.<XExpression>last(expressions); Assert.assertTrue((_last instanceof XNumberLiteral)); Assert.assertTrue(arguments.isProcessed(0)); Assert.assertFalse(arguments.isProcessed(1)); Assert.assertFalse(arguments.isProcessed(2)); valid.markProcessed(); Assert.assertTrue(arguments.isProcessed(0)); Assert.assertTrue(arguments.isProcessed(1)); Assert.assertTrue(arguments.isProcessed(2)); Assert.assertFalse(arguments.hasUnprocessedArguments()); }
Example #20
Source File: XbaseInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * @param context unused in this context but required for dispatching * @param indicator unused in this context but required for dispatching */ @SuppressWarnings("unchecked") protected Object _doEvaluate(XNumberLiteral literal, IEvaluationContext context, CancelIndicator indicator) { IResolvedTypes resolvedTypes = typeResolver.resolveTypes(literal); LightweightTypeReference expectedType = resolvedTypes.getExpectedType(literal); Class<? extends Number> type = numberLiterals.getJavaType(literal); if (expectedType != null && expectedType.isSubtypeOf(Number.class)) { try { Class<?> expectedClassType = getJavaType(expectedType.toJavaCompliantTypeReference().getType()); if (expectedClassType.isPrimitive()) { expectedClassType = ReflectionUtil.getObjectType(expectedClassType); } if (Number.class != expectedClassType && Number.class.isAssignableFrom(expectedClassType)) { type = (Class<? extends Number>) expectedClassType; } } catch (ClassNotFoundException e) { } } return numberLiterals.numberValue(literal, type); }
Example #21
Source File: ReorderedFeatureCallArgumentsTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void test_01() { final IFeatureCallArguments arguments = this.toArgumentsWithoutReceiver("String s, int i", "[], 1"); Assert.assertEquals(2, arguments.getArgumentCount()); Assert.assertTrue(arguments.hasUnprocessedArguments()); final IFeatureCallArgumentSlot firstSlot = arguments.getNextUnprocessedArgumentSlot(); Assert.assertFalse(firstSlot.isVarArg()); Assert.assertFalse(firstSlot.isSuperfluous()); XExpression _argumentExpression = firstSlot.getArgumentExpression(); Assert.assertTrue((_argumentExpression instanceof XNumberLiteral)); Assert.assertEquals("int", firstSlot.getDeclaredType().getSimpleName()); Assert.assertFalse(arguments.isProcessed(0)); firstSlot.markProcessed(); Assert.assertTrue(arguments.isProcessed(0)); Assert.assertTrue(arguments.hasUnprocessedArguments()); final IFeatureCallArgumentSlot secondSlot = arguments.getNextUnprocessedArgumentSlot(); Assert.assertFalse(secondSlot.isVarArg()); Assert.assertFalse(secondSlot.isSuperfluous()); XExpression _argumentExpression_1 = secondSlot.getArgumentExpression(); Assert.assertTrue((_argumentExpression_1 instanceof XClosure)); Assert.assertEquals("String", secondSlot.getDeclaredType().getSimpleName()); Assert.assertFalse(arguments.isProcessed(1)); secondSlot.markProcessed(); Assert.assertTrue(arguments.isProcessed(1)); Assert.assertFalse(arguments.hasUnprocessedArguments()); }
Example #22
Source File: LiteralsCompiler.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override protected void doInternalToJavaStatement(XExpression obj, ITreeAppendable appendable, boolean isReferenced) { if (obj instanceof XStringLiteral) { _toJavaStatement((XStringLiteral) obj, appendable, isReferenced); } else if (obj instanceof XNumberLiteral) { _toJavaStatement((XNumberLiteral) obj, appendable, isReferenced); } else if (obj instanceof XNullLiteral) { _toJavaStatement((XNullLiteral) obj, appendable, isReferenced); } else if (obj instanceof XBooleanLiteral) { _toJavaStatement((XBooleanLiteral) obj, appendable, isReferenced); } else if (obj instanceof XTypeLiteral) { _toJavaStatement((XTypeLiteral) obj, appendable, isReferenced); } else { super.doInternalToJavaStatement(obj, appendable, isReferenced); } }
Example #23
Source File: ArgDefaultValueParsingTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlParsing") public void constructor_5p_0_1_2_3_4() throws Exception { SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString( "behavior B1 {", "new(arg0 : int=4, arg1 : String=\"ghj\", arg2 : int=18, arg3 : int=98, arg4 : String=\"klm\") {", "super(null) // must be never null during runtime", "System.out.println(arg0)", "}", "}" )); assertEquals(1, mas.getXtendTypes().size()); // assertTrue(Strings.isNullOrEmpty(mas.getPackage())); // SarlBehavior behavior = (SarlBehavior) mas.getXtendTypes().get(0); assertEquals("B1", behavior.getName()); assertNull(behavior.getExtends()); assertEquals(1, behavior.getMembers().size()); // SarlConstructor constructor = (SarlConstructor) behavior.getMembers().get(0); assertParameterNames(constructor.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4"); assertParameterTypes(constructor.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String"); assertParameterDefaultValues(constructor.getParameters(), XNumberLiteral.class, "4", XStringLiteral.class, "ghj", XNumberLiteral.class, "18", XNumberLiteral.class, "98", XStringLiteral.class, "klm"); }
Example #24
Source File: ArgDefaultValueParsingTest.java From sarl with Apache License 2.0 | 5 votes |
@Test @Tag("sarlParsing") public void action_5p_0() throws Exception { SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString( "agent A1 {", "def myaction(arg0 : int=4, arg1 : String, arg2 : int, arg3 : int, arg4 : String) {", "System.out.println(arg0)", "}", "}" )); assertEquals(1, mas.getXtendTypes().size()); // assertTrue(Strings.isNullOrEmpty(mas.getPackage())); // SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0); assertEquals("A1", agent.getName()); assertNull(agent.getExtends()); assertEquals(1, agent.getMembers().size()); // SarlAction action = (SarlAction) agent.getMembers().get(0); assertEquals("myaction", action.getName()); assertTypeReferenceIdentifiers(action.getFiredEvents()); assertParameterNames(action.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4"); assertParameterTypes(action.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String"); assertParameterDefaultValues(action.getParameters(), XNumberLiteral.class, "4", null, null, null, null); assertTypeReferenceIdentifier(action.getReturnType(), "void"); }
Example #25
Source File: XbaseParserTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testReturnExpressionInBlock_1() throws Exception { XBlockExpression block = (XBlockExpression) expression( "{ return 1 2 }"); assertEquals(2, block.getExpressions().size()); assertTrue(block.getExpressions().get(0) instanceof XReturnExpression); XReturnExpression returnExpression = (XReturnExpression) block.getExpressions().get(0); assertTrue(returnExpression.getExpression() instanceof XNumberLiteral); }
Example #26
Source File: StandardFeatureCallArgumentsTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void test_08() { final IFeatureCallArguments arguments = this.toArgumentsWithReceiver("String s, int i", "\"\", 1"); Assert.assertEquals(3, arguments.getArgumentCount()); Assert.assertTrue(arguments.hasUnprocessedArguments()); final IFeatureCallArgumentSlot firstSlot = arguments.getNextUnprocessedArgumentSlot(); Assert.assertFalse(firstSlot.isVarArg()); Assert.assertFalse(firstSlot.isSuperfluous()); XExpression _argumentExpression = firstSlot.getArgumentExpression(); Assert.assertTrue((_argumentExpression instanceof XStringLiteral)); Assert.assertEquals("String", firstSlot.getDeclaredType().getSimpleName()); Assert.assertTrue(arguments.isProcessed(0)); Assert.assertFalse(arguments.isProcessed(1)); firstSlot.markProcessed(); Assert.assertTrue(arguments.isProcessed(1)); Assert.assertTrue(arguments.hasUnprocessedArguments()); final IFeatureCallArgumentSlot secondSlot = arguments.getNextUnprocessedArgumentSlot(); Assert.assertFalse(secondSlot.isVarArg()); Assert.assertFalse(secondSlot.isSuperfluous()); XExpression _argumentExpression_1 = secondSlot.getArgumentExpression(); Assert.assertTrue((_argumentExpression_1 instanceof XNumberLiteral)); Assert.assertEquals("int", secondSlot.getDeclaredType().getSimpleName()); Assert.assertFalse(arguments.isProcessed(2)); secondSlot.markProcessed(); Assert.assertTrue(arguments.isProcessed(2)); Assert.assertFalse(arguments.hasUnprocessedArguments()); }
Example #27
Source File: ArgDefaultValueParsingTest.java From sarl with Apache License 2.0 | 5 votes |
@Test @Tag("sarlParsing") public void action_5p_0_3() throws Exception { SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString( "agent A1 {", "def myaction(arg0 : int=4, arg1 : String, arg2 : int, arg3 : int=56, arg4 : String) {", "System.out.println(arg0)", "}", "}" )); assertEquals(1, mas.getXtendTypes().size()); // assertTrue(Strings.isNullOrEmpty(mas.getPackage())); // SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0); assertEquals("A1", agent.getName()); assertNull(agent.getExtends()); assertEquals(1, agent.getMembers().size()); // SarlAction action = (SarlAction) agent.getMembers().get(0); assertEquals("myaction", action.getName()); assertTypeReferenceIdentifiers(action.getFiredEvents()); assertParameterNames(action.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4"); assertParameterTypes(action.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String"); assertParameterDefaultValues(action.getParameters(), XNumberLiteral.class, "4", null, null, XNumberLiteral.class, "56", null); assertTypeReferenceIdentifier(action.getReturnType(), "void"); }
Example #28
Source File: JvmAnnotationReferencePrinter.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected String internalToString(Object obj) { if (obj instanceof XBinaryOperation) { return _internalToString((XBinaryOperation) obj); } else if (obj instanceof XFeatureCall) { return _internalToString((XFeatureCall) obj); } else if (obj instanceof XListLiteral) { return _internalToString((XListLiteral) obj); } else if (obj instanceof XMemberFeatureCall) { return _internalToString((XMemberFeatureCall) obj); } else if (obj instanceof XBooleanLiteral) { return _internalToString((XBooleanLiteral) obj); } else if (obj instanceof XNumberLiteral) { return _internalToString((XNumberLiteral) obj); } else if (obj instanceof XStringLiteral) { return _internalToString((XStringLiteral) obj); } else if (obj instanceof XTypeLiteral) { return _internalToString((XTypeLiteral) obj); } else if (obj instanceof XAnnotation) { return _internalToString((XAnnotation) obj); } else if (obj instanceof JvmAnnotationReference) { return _internalToString((JvmAnnotationReference) obj); } else if (obj instanceof JvmAnnotationValue) { return _internalToString((JvmAnnotationValue) obj); } else { return _internalToString(obj); } }
Example #29
Source File: EventParsingTest.java From sarl with Apache License 2.0 | 5 votes |
@Test @Tag("sarlParsing") public void completeFinalFieldInitialization() throws Exception { SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString( "event E1 {", "val field1 : int = 5", "val field2 : String = \"\"", "}" )); assertEquals(1, mas.getXtendTypes().size()); // assertTrue(Strings.isNullOrEmpty(mas.getPackage())); // SarlEvent event = (SarlEvent) mas.getXtendTypes().get(0); assertEquals("E1", event.getName()); assertNull(event.getExtends()); assertEquals(2, event.getMembers().size()); // SarlField attr1 = (SarlField) event.getMembers().get(0); assertEquals("field1", attr1.getName()); assertTypeReferenceIdentifier(attr1.getType(), "int"); assertXExpression(attr1.getInitialValue(), XNumberLiteral.class, "5"); // SarlField attr2 = (SarlField) event.getMembers().get(1); assertEquals("field2", attr2.getName()); assertTypeReferenceIdentifier(attr2.getType(), "java.lang.String"); assertXExpression(attr2.getInitialValue(), XStringLiteral.class, ""); }
Example #30
Source File: ArgDefaultValueParsingTest.java From sarl with Apache License 2.0 | 5 votes |
@Test @Tag("sarlParsing") public void action_5p_0_1_2_3() throws Exception { SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString( "capacity C1 {", "def myaction(arg0 : int=4, arg1 : String=\"ghj\", arg2 : int=18, arg3 : int=98, arg4 : String)", "}" )); assertEquals(1, mas.getXtendTypes().size()); // assertTrue(Strings.isNullOrEmpty(mas.getPackage())); // SarlCapacity capacity = (SarlCapacity) mas.getXtendTypes().get(0); assertEquals("C1", capacity.getName()); assertTypeReferenceIdentifiers(capacity.getExtends()); assertEquals(1, capacity.getMembers().size()); // SarlAction signature = (SarlAction) capacity.getMembers().get(0); assertParameterNames(signature.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4"); assertParameterTypes(signature.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String"); assertParameterDefaultValues(signature.getParameters(), XNumberLiteral.class, "4", XStringLiteral.class, "ghj", XNumberLiteral.class, "18", XNumberLiteral.class, "98", null); }