use of org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner 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.StandardTypeReferenceOwner in project xtext-xtend by eclipse.
the class ExtractMethodRefactoring method calculateReturnType.
protected LightweightTypeReference calculateReturnType(IResolvedTypes resolvedTypes) {
List<LightweightTypeReference> returnTypes = newArrayList();
for (XExpression expression : expressions) {
LightweightTypeReference expressionReturnType = resolvedTypes.getReturnType(expression, expression != lastExpression);
if (expressionReturnType != null)
returnTypes.add(expressionReturnType);
}
StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(typeComputationServices, xtendClass);
return typeComputationServices.getTypeConformanceComputer().getCommonSuperType(returnTypes, owner);
}
use of org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner 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.StandardTypeReferenceOwner in project xtext-xtend by eclipse.
the class ReplacingAppendableTest method insertListField.
protected XtextDocument insertListField(final String model, final String fieldName) throws Exception {
final int cursorPosition = model.indexOf('|');
String actualModel = model.replace("|", " ");
final XtendFile file = testHelper.xtendFile("Foo", actualModel);
final XtextDocument document = documentProvider.get();
document.set(actualModel);
XtextResource xtextResource = (XtextResource) file.eResource();
document.setInput(xtextResource);
final EObject context = eObjectAtOffsetHelper.resolveElementAt(xtextResource, cursorPosition);
document.modify(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
ReplacingAppendable a = appendableFactory.create(document, state, cursorPosition, 1);
ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, context);
LightweightTypeReference typeRef = owner.toLightweightTypeReference(services.getTypeReferences().getTypeForName(List.class, context, typesFactory.createJvmWildcardTypeReference()));
a.append(typeRef);
a.append(" ").append(fieldName);
a.commitChanges();
}
});
return document;
}
use of org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner 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);
}
}
Aggregations