use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-xtend by eclipse.
the class ErrorTest method testErrorModel_019.
@Test
public void testErrorModel_019() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package x");
_builder.newLine();
_builder.append("import bug396879.*");
_builder.newLine();
_builder.append("class Z {");
_builder.newLine();
_builder.append(" \t");
_builder.append("def addListeners(BooleanProperty prop) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val ChangeListenerBoolean> listener = [ p, oldValue, newValue | ]\t\tprop.addListener(listener)");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.processWithoutException(_builder);
final XtendTypeDeclaration z = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
XtendMember _get = z.getMembers().get(1);
final XtendField field = ((XtendField) _get);
XExpression _initialValue = field.getInitialValue();
final XClosure closure = ((XClosure) _initialValue);
final JvmFormalParameter param = IterableExtensions.<JvmFormalParameter>head(closure.getDeclaredFormalParameters());
final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(param);
Assert.assertNotNull(resolvedTypes.getActualType(param));
}
use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-xtend by eclipse.
the class Oven method fireproof.
public void fireproof(final String input) throws Exception {
try {
final EObject file = this._parseHelper.parse(input);
final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(file);
Assert.assertNotNull(resolvedTypes);
if ((file != null)) {
Iterable<EObject> _iterable = IteratorExtensions.<EObject>toIterable(file.eAllContents());
for (final EObject content : _iterable) {
boolean _matched = false;
if (content instanceof XAbstractFeatureCall) {
_matched = true;
this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
XExpression _implicitReceiver = ((XAbstractFeatureCall) content).getImplicitReceiver();
boolean _tripleNotEquals = (_implicitReceiver != null);
if (_tripleNotEquals) {
this.assertExpressionTypeIsResolved(((XAbstractFeatureCall) content).getImplicitReceiver(), resolvedTypes);
}
XExpression _implicitFirstArgument = ((XAbstractFeatureCall) content).getImplicitFirstArgument();
boolean _tripleNotEquals_1 = (_implicitFirstArgument != null);
if (_tripleNotEquals_1) {
this.assertExpressionTypeIsResolved(((XAbstractFeatureCall) content).getImplicitFirstArgument(), resolvedTypes);
}
}
if (!_matched) {
if (content instanceof XClosure) {
_matched = true;
this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
final Consumer<JvmFormalParameter> _function = (JvmFormalParameter it) -> {
this.assertIdentifiableTypeIsResolved(it, resolvedTypes);
};
((XClosure) content).getImplicitFormalParameters().forEach(_function);
}
}
if (!_matched) {
if (content instanceof XExpression) {
_matched = true;
this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
}
}
if (!_matched) {
if (content instanceof JvmIdentifiableElement) {
_matched = true;
this.assertIdentifiableTypeIsResolved(((JvmIdentifiableElement) content), resolvedTypes);
}
}
}
}
} catch (final Throwable _t) {
if (_t instanceof Throwable) {
final Throwable e = (Throwable) _t;
String _message = e.getMessage();
final ComparisonFailure error = new ComparisonFailure(_message, input, "");
error.setStackTrace(e.getStackTrace());
throw error;
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}
use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-xtend by eclipse.
the class CompilationUnitImpl method toParameterDeclaration.
public ParameterDeclaration toParameterDeclaration(final JvmFormalParameter delegate) {
final Function1<JvmFormalParameter, JvmParameterDeclarationImpl> _function = (JvmFormalParameter it) -> {
JvmParameterDeclarationImpl _xifexpression = null;
boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
if (_isBelongedToCompilationUnit) {
MutableJvmParameterDeclarationImpl _mutableJvmParameterDeclarationImpl = new MutableJvmParameterDeclarationImpl();
final Procedure1<MutableJvmParameterDeclarationImpl> _function_1 = (MutableJvmParameterDeclarationImpl it_1) -> {
it_1.setDelegate(delegate);
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<MutableJvmParameterDeclarationImpl>operator_doubleArrow(_mutableJvmParameterDeclarationImpl, _function_1);
} else {
JvmParameterDeclarationImpl _jvmParameterDeclarationImpl = new JvmParameterDeclarationImpl();
final Procedure1<JvmParameterDeclarationImpl> _function_2 = (JvmParameterDeclarationImpl it_1) -> {
it_1.setDelegate(delegate);
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<JvmParameterDeclarationImpl>operator_doubleArrow(_jvmParameterDeclarationImpl, _function_2);
}
return _xifexpression;
};
return this.<JvmFormalParameter, JvmParameterDeclarationImpl>getOrCreate(delegate, _function);
}
use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-xtend by eclipse.
the class LinkingTest method testBug345433_02.
@Test
public void testBug345433_02() throws Exception {
String classAsString = "import static extension org.eclipse.xtext.GrammarUtil.*\n" + "class Foo {" + " org.eclipse.xtext.Grammar grammar\n" + " def function1() {\n" + " grammar.containedRuleCalls.filter(e0 | " + " !e0.isAssigned() && !e0.isEObjectRuleCall()" + " ).map(e1 | e1.rule)\n" + " }\n" + "}";
XtendClass clazz = clazz(classAsString);
IResourceValidator validator = ((XtextResource) clazz.eResource()).getResourceServiceProvider().getResourceValidator();
List<Issue> issues = validator.validate(clazz.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
XtendFunction function = (XtendFunction) clazz.getMembers().get(1);
XExpression body = function.getExpression();
LightweightTypeReference bodyType = getType(body);
assertEquals("java.lang.Iterable<org.eclipse.xtext.AbstractRule>", bodyType.getIdentifier());
XBlockExpression block = (XBlockExpression) body;
XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(0);
XClosure closure = (XClosure) featureCall.getMemberCallArguments().get(0);
JvmFormalParameter e1 = closure.getFormalParameters().get(0);
assertEquals("e1", e1.getSimpleName());
assertEquals("org.eclipse.xtext.RuleCall", getType(e1).getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-xtend by eclipse.
the class LinkingTest method testDeclaredConstructor_01.
@Test
public void testDeclaredConstructor_01() throws Exception {
XtendClass clazz = clazz("class Foo { " + " int i" + " new(int i) { this.i = i }" + "}");
assertEquals(2, clazz.getMembers().size());
XtendConstructor constructor = (XtendConstructor) clazz.getMembers().get(1);
XAssignment assignment = (XAssignment) ((XBlockExpression) constructor.getExpression()).getExpressions().get(0);
JvmField field = (JvmField) assignment.getFeature();
assertEquals("i", field.getSimpleName());
XFeatureCall target = (XFeatureCall) assignment.getAssignable();
JvmDeclaredType identifiableElement = (JvmDeclaredType) target.getFeature();
assertEquals("Foo", identifiableElement.getSimpleName());
XFeatureCall value = (XFeatureCall) assignment.getValue();
JvmFormalParameter parameter = (JvmFormalParameter) value.getFeature();
assertEquals("i", parameter.getSimpleName());
}
Aggregations