From b0295419fa9cff18035ea02519c07d0af9ad6003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Galland?= Date: Fri, 8 Sep 2017 16:02:44 +0200 Subject: [PATCH] [ui] Copy the type parameter constrains into the auto-generated functions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #742 Signed-off-by: Stéphane Galland --- .../ui/quickfix/SARLQuickfixProvider.java | 28 ++++++++++++- .../MissedMethodAddModification.java | 39 +++++++++---------- 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/main/coreplugins/io.sarl.lang.ui/src/io/sarl/lang/ui/quickfix/SARLQuickfixProvider.java b/main/coreplugins/io.sarl.lang.ui/src/io/sarl/lang/ui/quickfix/SARLQuickfixProvider.java index 9c75e29348..44823e1ef8 100644 --- a/main/coreplugins/io.sarl.lang.ui/src/io/sarl/lang/ui/quickfix/SARLQuickfixProvider.java +++ b/main/coreplugins/io.sarl.lang.ui/src/io/sarl/lang/ui/quickfix/SARLQuickfixProvider.java @@ -62,6 +62,8 @@ import org.eclipse.xtext.util.Strings; import org.eclipse.xtext.validation.ConfigurableIssueCodesProvider; import org.eclipse.xtext.validation.Issue; +import org.eclipse.xtext.xbase.jvmmodel.JvmTypeReferenceBuilder; +import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices; import org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable; @@ -140,6 +142,12 @@ public class SARLQuickfixProvider extends XtendQuickfixProvider { @Inject private AnnotationLookup annotationFinder; + @Inject + private JvmTypeReferenceBuilder typeParameterBuilder; + + @Inject + private JvmTypesBuilder typeBuilder; + /** Replies if the given code is for a ignorable warning. * * @param code the code of the warning. @@ -256,12 +264,30 @@ public IResourceSetProvider getResourceSetProvider() { /** Replies the type services. * - * @return the type serices. + * @return the type services. */ public CommonTypeComputationServices getTypeServices() { return this.services; } + /** Replies the type parameter builder. + * + * @return the builder. + * @since 0.6 + */ + public JvmTypeReferenceBuilder getJvmTypeParameterBuilder() { + return this.typeParameterBuilder; + } + + /** Replies the type builder. + * + * @return the builder. + * @since 0.6 + */ + public JvmTypesBuilder getJvmTypeBuilder() { + return this.typeBuilder; + } + /** Replies the JVM associations. * * @return the JVM associations. diff --git a/main/coreplugins/io.sarl.lang.ui/src/io/sarl/lang/ui/quickfix/acceptors/MissedMethodAddModification.java b/main/coreplugins/io.sarl.lang.ui/src/io/sarl/lang/ui/quickfix/acceptors/MissedMethodAddModification.java index cf9a256e32..dd5a2142cf 100644 --- a/main/coreplugins/io.sarl.lang.ui/src/io/sarl/lang/ui/quickfix/acceptors/MissedMethodAddModification.java +++ b/main/coreplugins/io.sarl.lang.ui/src/io/sarl/lang/ui/quickfix/acceptors/MissedMethodAddModification.java @@ -37,6 +37,7 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.jdt.internal.ui.JavaPluginImages; import org.eclipse.jdt.internal.ui.text.correction.IProposalRelevance; +import org.eclipse.xtend.core.validation.IssueCodes; import org.eclipse.xtend.core.xtend.XtendTypeDeclaration; import org.eclipse.xtend.ide.codebuilder.XtendMethodBuilder; import org.eclipse.xtext.EcoreUtil2; @@ -50,11 +51,15 @@ import org.eclipse.xtext.common.types.JvmType; import org.eclipse.xtext.common.types.JvmTypeParameter; import org.eclipse.xtext.common.types.JvmTypeReference; +import org.eclipse.xtext.common.types.TypesFactory; +import org.eclipse.xtext.common.types.util.TypeReferences; import org.eclipse.xtext.resource.XtextResource; import org.eclipse.xtext.ui.editor.model.IXtextDocument; import org.eclipse.xtext.ui.editor.model.edit.IModificationContext; import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor; import org.eclipse.xtext.validation.Issue; +import org.eclipse.xtext.xbase.jvmmodel.JvmTypeReferenceBuilder; +import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder; import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference; import org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices; import org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable; @@ -165,13 +170,13 @@ public void apply(EObject element, IModificationContext context) throws Exceptio builder.setMethodName(operation.getSimpleName()); builder.setStaticFlag(false); - builder.setOverrideFlag(true); + builder.setOverrideFlag(!getTools().isIgnorable(IssueCodes.MISSING_OVERRIDE)); builder.setAbstractFlag(false); builder.setBodyGenerator(null); builder.setVisibility(operation.getVisibility()); - builder.setTypeParameters(cloneTypeParameters(operation.getTypeParameters())); + builder.setTypeParameters(cloneTypeParameters(operation)); final QualifiedActionName qualifiedActionName = this.actionPrototypeProvider.createQualifiedActionName( declaringType, @@ -321,30 +326,24 @@ private List cloneTypeReferences(List typeParameterMap) { final JvmTypeReference mappedReference = mapToTypeParameter(type, typeParameterMap); return Utils.toLightweightTypeReference(mappedReference, this.services); } - /** Clone the given type parameters. - * - * @param typeParameters the types to clone. - * @param typeParameterMap the type parameter mapping. - * @return the types. - */ - private static List cloneTypeParameters(List typeParameters) { - final List newList = new ArrayList<>(typeParameters.size()); - for (final JvmTypeParameter type : typeParameters) { - newList.add(EcoreUtil2.cloneWithProxies(type)); - } - return newList; + private List cloneTypeParameters(JvmOperation fromOperation) { + final SARLQuickfixProvider tools = getTools(); + final JvmTypeReferenceBuilder builder1 = tools.getJvmTypeParameterBuilder(); + final JvmTypesBuilder builder2 = tools.getJvmTypeBuilder(); + final TypeReferences builder3 = tools.getTypeServices().getTypeReferences(); + final TypesFactory builder4 = tools.getTypeServices().getTypesFactory(); + final List outParameters = new ArrayList<>(); + Utils.copyTypeParametersFromJvmOperation( + fromOperation.getTypeParameters(), + outParameters, + builder1, builder2, builder3, builder4, null); + return outParameters; } }