use of org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference in project xtext-xtend by eclipse.
the class AbstractOverloadedInstanceMethodTest method linksTo.
protected void linksTo(final String invocation, final String method) {
try {
final XtendFile file = this.file(this.inMethodBody(invocation), false);
XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
final XtendClass c = ((XtendClass) _head);
XtendMember _head_1 = IterableExtensions.<XtendMember>head(c.getMembers());
final XtendFunction m = ((XtendFunction) _head_1);
XExpression _expression = m.getExpression();
final XBlockExpression body = ((XBlockExpression) _expression);
XExpression _last = IterableExtensions.<XExpression>last(body.getExpressions());
final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
JvmIdentifiableElement _feature = featureCall.getFeature();
final JvmOperation operation = ((JvmOperation) _feature);
final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, file);
final ParameterizedTypeReference declaration = owner.newParameterizedTypeReference(operation.getDeclaringType());
final BottomResolvedOperation resolved = new BottomResolvedOperation(operation, declaration, this.overrideTester);
Assert.assertEquals(method, resolved.getSimpleSignature());
Assert.assertTrue(IterableExtensions.join(file.eResource().getErrors(), "\n"), file.eResource().getErrors().isEmpty());
Assert.assertNotNull(featureCall.getImplicitReceiver());
Assert.assertNull(featureCall.getImplicitFirstArgument());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference in project xtext-xtend by eclipse.
the class AbstractOverloadedStaticMethodTest method linksTo.
protected void linksTo(final String invocation, final String method) {
try {
final XtendFile file = this.file(this.inMethodBody(invocation), false);
XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
final XtendClass c = ((XtendClass) _head);
XtendMember _head_1 = IterableExtensions.<XtendMember>head(c.getMembers());
final XtendFunction m = ((XtendFunction) _head_1);
XExpression _expression = m.getExpression();
final XBlockExpression body = ((XBlockExpression) _expression);
XExpression _last = IterableExtensions.<XExpression>last(body.getExpressions());
final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
JvmIdentifiableElement _feature = featureCall.getFeature();
final JvmOperation operation = ((JvmOperation) _feature);
final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, file);
final ParameterizedTypeReference declaration = owner.newParameterizedTypeReference(operation.getDeclaringType());
final BottomResolvedOperation resolved = new BottomResolvedOperation(operation, declaration, this.overrideTester);
Assert.assertEquals(method, resolved.getSimpleSignature());
Assert.assertTrue(IterableExtensions.join(file.eResource().getErrors(), "\n"), file.eResource().getErrors().isEmpty());
Assert.assertNull(featureCall.getImplicitReceiver());
Assert.assertNull(featureCall.getImplicitFirstArgument());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method getReceiverType.
/* @Nullable */
protected LightweightTypeReference getReceiverType(XAbstractFeatureCall featureCall) {
XExpression actualReceiver = featureCall.getActualReceiver();
ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, featureCall);
if (actualReceiver == null) {
JvmDeclaredType callersType = getCallersType(featureCall);
if (callersType != null)
return owner.newParameterizedTypeReference(callersType);
} else if (actualReceiver instanceof XAbstractFeatureCall && ((XAbstractFeatureCall) actualReceiver).isTypeLiteral()) {
JvmType type = (JvmType) ((XAbstractFeatureCall) actualReceiver).getFeature();
ParameterizedTypeReference reference = owner.newParameterizedTypeReference(type);
return reference;
} else {
LightweightTypeReference typeRef = typeResolver.resolveTypes(featureCall).getActualType(actualReceiver);
if (typeRef != null && typeRef.getType() instanceof JvmDeclaredType)
return typeRef;
}
return null;
}
use of org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference in project xtext-xtend by eclipse.
the class SuperMemberImplementorTest method getContextType.
protected LightweightTypeReference getContextType() {
JvmGenericType inferredType = associations.getInferredType(xtendClass);
ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, inferredType);
ParameterizedTypeReference contextType = owner.newParameterizedTypeReference(inferredType);
for (JvmTypeParameter typeParamter : inferredType.getTypeParameters()) {
contextType.addTypeArgument(owner.newParameterizedTypeReference(typeParamter));
}
return contextType;
}
use of org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference in project xtext-xtend by eclipse.
the class CacheMethodCompileStrategy method apply.
@Override
public void apply(ITreeAppendable appendable) {
JvmOperation cacheMethod = (JvmOperation) logicalContainerProvider.getLogicalContainer(createExtensionInfo.getCreateExpression());
JvmDeclaredType containerType = cacheMethod.getDeclaringType();
IResolvedTypes resolvedTypes = typeResolver.resolveTypes(containerType);
final ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, containerType);
LightweightTypeReference listType = owner.newReferenceTo(ArrayList.class, new TypeReferenceInitializer<ParameterizedTypeReference>() {
@Override
public LightweightTypeReference enhance(ParameterizedTypeReference reference) {
reference.addTypeArgument(owner.newWildcardTypeReference());
return reference;
}
});
String cacheVarName = cacheField.getSimpleName();
String cacheKeyVarName = appendable.declareSyntheticVariable("CacheKey", "_cacheKey");
appendable.append("final ").append(listType).append(" ").append(cacheKeyVarName).append(" = ").append(CollectionLiterals.class).append(".newArrayList(");
List<JvmFormalParameter> list = cacheMethod.getParameters();
for (Iterator<JvmFormalParameter> iterator = list.iterator(); iterator.hasNext(); ) {
JvmFormalParameter jvmFormalParameter = iterator.next();
appendable.append(getVarName(jvmFormalParameter));
if (iterator.hasNext()) {
appendable.append(", ");
}
}
appendable.append(");");
// declare result variable
LightweightTypeReference returnType = resolvedTypes.getActualType(initializerMethod.getParameters().get(0));
if (returnType != null) {
appendable.newLine().append("final ").append(returnType);
} else {
appendable.newLine().append("final Object");
}
String resultVarName = "_result";
appendable.append(" ").append(resultVarName).append(";");
// open synchronize block
appendable.newLine().append("synchronized (").append(cacheVarName).append(") {");
appendable.increaseIndentation();
// if the cache contains the key return the previously created object.
appendable.newLine().append("if (").append(cacheVarName).append(".containsKey(").append(cacheKeyVarName).append(")) {");
appendable.increaseIndentation();
appendable.newLine().append("return ").append(cacheVarName).append(".get(").append(cacheKeyVarName).append(");");
appendable.decreaseIndentation().newLine().append("}");
// execute the creation
compiler.toJavaStatement(createExtensionInfo.getCreateExpression(), appendable, true);
appendable.newLine();
appendable.append(resultVarName).append(" = ");
compiler.toJavaExpression(createExtensionInfo.getCreateExpression(), appendable);
appendable.append(";");
// store the newly created object in the cache
appendable.newLine().append(cacheVarName).append(".put(").append(cacheKeyVarName).append(", ");
LightweightTypeReference fieldType = resolvedTypes.getActualType(cacheField);
LightweightTypeReference declaredResultType = fieldType.getTypeArguments().get(1);
boolean castRequired = false;
if (!declaredResultType.isAssignableFrom(returnType)) {
castRequired = true;
appendable.append("(").append(declaredResultType).append(")");
}
appendable.append(resultVarName).append(");");
// close synchronize block
appendable.decreaseIndentation();
appendable.newLine().append("}");
appendable.newLine().append(initializerMethod.getSimpleName()).append("(").append(resultVarName);
for (JvmFormalParameter parameter : cacheMethod.getParameters()) {
appendable.append(", ").append(parameter.getName());
}
appendable.append(");");
// return the result
appendable.newLine().append("return ");
if (castRequired) {
appendable.append("(").append(declaredResultType).append(")");
}
appendable.append(resultVarName).append(";");
}
Aggregations