use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class VarArgFeatureCallArgumentsTest method testBug457779_02.
@Test
public void testBug457779_02() {
final IFeatureCallArguments arguments = this.toArgumentsWithReceiver("String s, int[] i", "\"\", 1");
final XExpression first = arguments.getArgument(0);
Assert.assertNull(first);
final LightweightTypeReference firstType = arguments.getDeclaredTypeForLambda(0);
Assert.assertNull(firstType);
final XExpression second = arguments.getArgument(1);
Assert.assertTrue((second instanceof XStringLiteral));
final LightweightTypeReference secondType = arguments.getDeclaredTypeForLambda(1);
Assert.assertEquals("String", secondType.getSimpleName());
final XExpression third = arguments.getArgument(2);
Assert.assertTrue((third instanceof XNumberLiteral));
final LightweightTypeReference thirdType = arguments.getDeclaredTypeForLambda(2);
Assert.assertEquals("int", thirdType.getSimpleName());
try {
arguments.getArgument(3);
Assert.fail("Expected exception");
} catch (final Throwable _t) {
if (_t instanceof IndexOutOfBoundsException) {
} else {
throw Exceptions.sneakyThrow(_t);
}
}
try {
arguments.getDeclaredTypeForLambda(3);
Assert.fail("Expected exception");
} catch (final Throwable _t_1) {
if (_t_1 instanceof IndexOutOfBoundsException) {
} else {
throw Exceptions.sneakyThrow(_t_1);
}
}
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class AnonymousClassTypeTest method testAnonymousWithAdditionalMember.
@Test
public void testAnonymousWithAdditionalMember() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def foo() {");
_builder.newLine();
_builder.append("\t");
_builder.append("val foo = new Runnable() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("int bar");
_builder.newLine();
_builder.append("\t\t");
_builder.append("override run() {}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("foo");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFunction function = this.function(_builder.toString());
final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
final IResolvedTypes resolvedTypes = this._iBatchTypeResolver.resolveTypes(operation.eResource());
Assert.assertEquals("Runnable", resolvedTypes.getActualType(operation).toString());
XExpression _expression = function.getExpression();
final XExpression variable = IterableExtensions.<XExpression>last(((XBlockExpression) _expression).getExpressions());
final LightweightTypeReference variableType = resolvedTypes.getActualType(variable);
Assert.assertEquals("__Foo_1", variableType.toString());
Assert.assertTrue(variableType.isSubtypeOf(Runnable.class));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class AbstractExecutableBuilder method appendThrowsClause.
protected ISourceAppender appendThrowsClause(final ISourceAppender appendable) {
ISourceAppender _xblockexpression = null;
{
final Iterator<LightweightTypeReference> iterator = this.exceptions.iterator();
boolean _hasNext = iterator.hasNext();
if (_hasNext) {
appendable.append(" throws ");
do {
{
final LightweightTypeReference typeRef = iterator.next();
if ((typeRef != null)) {
this.appendType(appendable, typeRef, "Exception");
}
boolean _hasNext_1 = iterator.hasNext();
if (_hasNext_1) {
appendable.append(", ");
}
}
} while (iterator.hasNext());
}
_xblockexpression = appendable;
}
return _xblockexpression;
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class MemberFromSuperImplementor method initializeExecutableBuilder.
protected void initializeExecutableBuilder(final AbstractExecutableBuilder builder, final JvmDeclaredType overrider, final IResolvedExecutable overridden) {
final JvmExecutable executable = overridden.getDeclaration();
builder.setContext(overrider);
builder.setVisibility(overridden.getDeclaration().getVisibility());
final Procedure2<LightweightTypeReference, Integer> _function = (LightweightTypeReference it, Integer index) -> {
final JvmFormalParameter declaredParameter = executable.getParameters().get((index).intValue());
final AbstractParameterBuilder parameterBuilder = builder.newParameterBuilder();
parameterBuilder.setName(declaredParameter.getSimpleName());
parameterBuilder.setType(it);
JvmAnnotationReference _findAnnotation = this.annotationLookup.findAnnotation(declaredParameter, Extension.class);
boolean _tripleNotEquals = (_findAnnotation != null);
parameterBuilder.setExtensionFlag(_tripleNotEquals);
};
IterableExtensions.<LightweightTypeReference>forEach(overridden.getResolvedParameterTypes(), _function);
builder.setVarArgsFlag(executable.isVarArgs());
builder.setExceptions(overridden.getResolvedExceptions());
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method newMethodQuickfixes.
protected void newMethodQuickfixes(LightweightTypeReference containerType, String name, /* @Nullable */
LightweightTypeReference returnType, List<LightweightTypeReference> argumentTypes, XAbstractFeatureCall call, JvmDeclaredType callersType, final Issue issue, final IssueResolutionAcceptor issueResolutionAcceptor) {
boolean isLocal = callersType == containerType.getType();
boolean isStatic = isStaticAccess(call);
boolean isAbstract = true;
if (containerType.getType() instanceof JvmGenericType) {
isAbstract = !((JvmGenericType) containerType.getType()).isInstantiateable();
} else if (containerType.getType() instanceof JvmDeclaredType) {
isAbstract = ((JvmDeclaredType) containerType.getType()).isAbstract();
}
if (containerType.getType() instanceof JvmDeclaredType) {
JvmDeclaredType declaredType = (JvmDeclaredType) containerType.getType();
newMethodQuickfix(declaredType, name, returnType, argumentTypes, isStatic, isAbstract, false, isLocal, call, issue, issueResolutionAcceptor);
}
if (!isLocal && !isStatic) {
List<LightweightTypeReference> extensionMethodParameterTypes = newArrayList(argumentTypes);
extensionMethodParameterTypes.add(0, containerType);
newMethodQuickfix(callersType, name, returnType, extensionMethodParameterTypes, false, isAbstract, true, true, call, issue, issueResolutionAcceptor);
}
}
Aggregations