use of org.eclipse.xtext.xbase.typesystem.override.ResolvedConstructor in project xtext-eclipse by eclipse.
the class XbaseDeclarativeHoverSignatureProvider method _signature.
protected String _signature(XConstructorCall constructorCall, boolean typeAtEnd) {
if (typeAtEnd) {
throw new UnsupportedOperationException();
}
IResolvedTypes resolvedTypes = typeResolver.resolveTypes(constructorCall);
LightweightTypeReference createdType = resolvedTypes.getActualType(constructorCall);
final List<LightweightTypeReference> typeArguments = resolvedTypes.getActualTypeArguments(constructorCall);
final int typeArgumentCount = createdType.getTypeArguments().size();
final int constructorTypeArgumentCount = typeArguments.size();
final JvmConstructor constructor = constructorCall.getConstructor();
ResolvedConstructor resolvedConstructor = new ResolvedConstructor(constructor, createdType) {
@Override
protected Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> computeContextTypeParameterMapping() {
Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> result = super.computeContextTypeParameterMapping();
if (typeArgumentCount == constructorTypeArgumentCount)
return result;
List<JvmTypeParameter> constructorTypeParameters = getDeclaration().getTypeParameters();
for (int i = 0; i < constructorTypeParameters.size(); i++) {
result.put(constructorTypeParameters.get(i), new LightweightMergedBoundTypeArgument(typeArguments.get(i), VarianceInfo.INVARIANT));
}
return result;
}
};
StringBuilder result = new StringBuilder(250);
if (typeArgumentCount != constructorTypeArgumentCount) {
result.append("<");
for (int i = 0; i < constructorTypeArgumentCount - typeArgumentCount; i++) {
if (i != 0) {
result.append(", ");
}
result.append(typeArguments.get(i).getHumanReadableName());
}
result.append("> ");
}
result.append(constructor.getDeclaringType().getSimpleName());
if (typeArgumentCount != 0) {
result.append("<");
for (int i = constructorTypeArgumentCount - typeArgumentCount; i < constructorTypeArgumentCount; i++) {
if (i != constructorTypeArgumentCount - typeArgumentCount) {
result.append(", ");
}
result.append(typeArguments.get(i).getHumanReadableName());
}
result.append(">");
}
result.append('(');
List<LightweightTypeReference> parameterTypes = resolvedConstructor.getResolvedParameterTypes();
for (int i = 0; i < parameterTypes.size(); i++) {
if (i != 0) {
result.append(", ");
}
result.append(parameterTypes.get(i).getHumanReadableName());
result.append(' ').append(constructor.getParameters().get(i).getSimpleName());
}
result.append(')');
List<LightweightTypeReference> exceptions = resolvedConstructor.getResolvedExceptions();
if (!exceptions.isEmpty()) {
result.append(" throws ");
for (int i = 0; i < exceptions.size(); i++) {
if (i != 0) {
result.append(", ");
}
result.append(exceptions.get(i).getHumanReadableName());
}
}
return result.toString();
}
use of org.eclipse.xtext.xbase.typesystem.override.ResolvedConstructor in project xtext-xtend by eclipse.
the class SuperMemberImplementorTest method checkImplementConstructor.
protected void checkImplementConstructor(final String firstParamType, String implementCode) {
StringBuilderBasedAppendable appendable = new StringBuilderBasedAppendable();
JvmConstructor constructor = Iterables.find(superClass.getDeclaredConstructors(), new Predicate<JvmConstructor>() {
@Override
public boolean apply(JvmConstructor c) {
if (firstParamType == null)
return c.getParameters().isEmpty();
if (c.getParameters().size() >= 1) {
return firstParamType.equals(c.getParameters().get(0).getParameterType().getSimpleName());
}
return false;
}
});
LightweightTypeReference contextType = getContextType();
ResolvedConstructor resolvedConstructor = new ResolvedConstructor(constructor, contextType);
implementor.appendConstructorFromSuper(xtendClass, resolvedConstructor, appendable);
String code = appendable.toString();
if (!equalsIgnoreWhitespace(implementCode, code))
assertEquals(implementCode, code);
}
use of org.eclipse.xtext.xbase.typesystem.override.ResolvedConstructor in project xtext-xtend by eclipse.
the class XtendQuickfixProvider method addConstuctorFromSuper.
@Fix(IssueCodes.MISSING_CONSTRUCTOR)
public void addConstuctorFromSuper(final Issue issue, IssueResolutionAcceptor acceptor) {
if (issue.getData() != null) {
for (int i = 0; i < issue.getData().length; i += 2) {
final URI constructorURI = URI.createURI(issue.getData()[i]);
String javaSignature = issue.getData()[i + 1];
String xtendSignature = "new" + javaSignature.substring(javaSignature.indexOf('('));
acceptor.accept(issue, "Add constructor " + xtendSignature, "Add constructor " + xtendSignature, "fix_indent.gif", new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context) throws Exception {
XtendClass clazz = (XtendClass) element;
JvmGenericType inferredType = associations.getInferredType(clazz);
ResolvedFeatures features = overrideHelper.getResolvedFeatures(inferredType);
ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) clazz.eResource(), insertionOffsets.getNewConstructorInsertOffset(null, clazz), 0, new OptionalParameters() {
{
ensureEmptyLinesAround = true;
baseIndentationLevel = 1;
}
});
EObject constructor = clazz.eResource().getResourceSet().getEObject(constructorURI, true);
if (constructor instanceof JvmConstructor) {
superMemberImplementor.appendConstructorFromSuper(clazz, new ResolvedConstructor((JvmConstructor) constructor, features.getType()), appendable);
}
appendable.commitChanges();
}
});
}
}
}
Aggregations