use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method getResolvedArgumentTypes.
protected List<LightweightTypeReference> getResolvedArgumentTypes(EObject context, JvmIdentifiableElement logicalContainer, List<XExpression> arguments) {
List<LightweightTypeReference> argumentTypes = newArrayList();
IResolvedTypes resolvedTypes = typeResolver.resolveTypes(context);
for (XExpression argument : arguments) {
LightweightTypeReference resolved = resolvedTypes.getActualType(argument);
if (resolved == null) {
StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, context);
argumentTypes.add(owner.newReferenceToObject());
} else {
LocalTypeSubstitutor substitutor = new LocalTypeSubstitutor(resolved.getOwner(), logicalContainer);
argumentTypes.add(substitutor.withoutLocalTypes(resolved));
}
}
return argumentTypes;
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference 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.LightweightTypeReference in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method newMethodQuickfix.
protected void newMethodQuickfix(JvmDeclaredType containerType, String name, /* @Nullable */
LightweightTypeReference returnType, List<LightweightTypeReference> parameterTypes, boolean isStatic, boolean isAbstract, boolean isExtension, boolean isLocal, XAbstractFeatureCall call, final Issue issue, final IssueResolutionAcceptor issueResolutionAcceptor) {
AbstractMethodBuilder methodBuilder = codeBuilderFactory.createMethodBuilder(containerType);
methodBuilder.setMethodName(name);
methodBuilder.setReturnType(returnType);
for (LightweightTypeReference parameterType : parameterTypes) methodBuilder.newParameterBuilder().setType(parameterType);
methodBuilder.setContext(call);
methodBuilder.setVisibility(JvmVisibility.PUBLIC);
methodBuilder.setStaticFlag(isStatic);
methodBuilder.setAbstractFlag(isAbstract);
StringBuffer label = new StringBuffer("Create ");
if (isStatic)
label.append("static ");
if (isExtension)
label.append("extension ");
label.append("method '").append(name).append("(");
boolean isFirst = true;
for (LightweightTypeReference parameterType : parameterTypes) {
if (!isFirst)
label.append(", ");
isFirst = false;
label.append(parameterType.getSimpleName());
}
label.append(")'");
if (!isLocal)
label.append(" in '" + containerType.getSimpleName() + "'");
quickfixFactory.addQuickfix(methodBuilder, label.toString(), issue, issueResolutionAcceptor);
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method newFieldQuickfix.
protected void newFieldQuickfix(String name, XAbstractFeatureCall call, final Issue issue, final IssueResolutionAcceptor issueResolutionAcceptor) {
JvmDeclaredType callersType = getCallersType(call);
LightweightTypeReference receiverType = getReceiverType(call);
LightweightTypeReference fieldType = getNewMemberType(call);
if (callersType != null && receiverType != null && callersType == receiverType.getType())
newFieldQuickfix(callersType, name, fieldType, isStaticAccess(call), call, issue, issueResolutionAcceptor);
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method newConstructorQuickfix.
protected void newConstructorQuickfix(Issue issue, IssueResolutionAcceptor issueResolutionAcceptor, JvmDeclaredType ownerType, XExpression call, List<XExpression> arguments) {
if (ownerType != null) {
List<LightweightTypeReference> parameterTypes = getResolvedArgumentTypes(call, logicalContainerProvider.getNearestLogicalContainer(call), arguments);
AbstractConstructorBuilder constructorBuilder = codeBuilderFactory.createConstructorBuilder(ownerType);
constructorBuilder.setContext(call);
for (LightweightTypeReference parameterType : parameterTypes) constructorBuilder.newParameterBuilder().setType(parameterType);
constructorBuilder.setVisibility(JvmVisibility.PUBLIC);
StringBuffer label = new StringBuffer("Create constructor '");
if (constructorBuilder.getOwnerSource() instanceof XtendClass)
label.append("new");
else
label.append(ownerType.getSimpleName());
label.append("(");
boolean isFirst = true;
for (LightweightTypeReference parameterType : parameterTypes) {
if (!isFirst)
label.append(", ");
isFirst = false;
label.append(parameterType.getSimpleName());
}
label.append(")'");
if (getCallersType(call) != ownerType)
label.append(" in '").append(ownerType.getSimpleName()).append("'");
quickfixFactory.addQuickfix(constructorBuilder, label.toString(), issue, issueResolutionAcceptor);
}
}
Aggregations