Skip to content

Commit

Permalink
Added Wollok Proposal for Constructor Calls with Named Parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Dec 14, 2017
1 parent 48eeddf commit 3b8b34c
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 8 deletions.
Binary file added org.uqbar.project.wollok.ui/icons/assignment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ public class Messages extends NLS {

public static String WollokTemplateProposalProvider_WConstructorCall_name;
public static String WollokTemplateProposalProvider_WConstructorCall_description;


public static String WollokTemplateProposalProvider_WConstructorCallWithNamedParameter_name;
public static String WollokTemplateProposalProvider_WConstructorCallWithNamedParameter_description;

public static String WollokTemplateProposalProvider_WConstructor_name;
public static String WollokTemplateProposalProvider_WConstructor_description;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package org.uqbar.project.wollok.ui.contentassist

import org.eclipse.emf.ecore.EObject
import org.eclipse.xtext.Assignment
import org.eclipse.xtext.RuleCall
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor
import org.uqbar.project.wollok.ui.Messages
import org.uqbar.project.wollok.ui.WollokActivator
import org.uqbar.project.wollok.wollokDsl.WConstructorCall
import org.uqbar.project.wollok.wollokDsl.WExpression
import org.uqbar.project.wollok.wollokDsl.WLibraryElement
import org.uqbar.project.wollok.wollokDsl.WMember
Expand All @@ -26,6 +30,14 @@ class WollokDslProposalProvider extends AbstractWollokDslProposalProvider {
var extension BasicTypeResolver typeResolver = new BasicTypeResolver
WollokProposalBuilder builder

override complete_WConstructorCall(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
if (model instanceof WConstructorCall) {
val initializations = (model as WConstructorCall).createInitializersForNamedParametersInConstructor
acceptor.accept(createCompletionProposal(initializations, Messages.WollokTemplateProposalProvider_WConstructorCallWithNamedParameter_name, WollokActivator.getInstance.getImageDescriptor('icons/assignment.png').createImage, context))
}
super.complete_WConstructorCall(model, ruleCall, context, acceptor)
}

// This whole implementation is just an heuristic until we have a type system
override completeWMemberFeatureCall_Feature(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
val call = model as WMemberFeatureCall
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class WollokTemplateProposalProvider extends DefaultTemplateProposalProvider {
static Properties properties
ContextTypeIdHelper helper
@Inject
extension WollokDslGrammarAccess ga;
extension WollokDslGrammarAccess ga

@Inject
new(TemplateStore templateStore, ContextTypeRegistry registry, ContextTypeIdHelper helper) {
Expand All @@ -54,7 +54,7 @@ class WollokTemplateProposalProvider extends DefaultTemplateProposalProvider {

val extension builder = new TemplateBuilder(grammar, "org.uqbar.project.wollok", "WollokTemplateProposalProvider", getProperties, [rule, name, description, id, content |
addTemplate(rule, templateContext, acceptor, name, description, id, context, content)
]);
])

builder

Expand Down Expand Up @@ -141,12 +141,12 @@ try {
}

def addTemplate(AbstractRule rule, TemplateContext templateContext, ITemplateAcceptor acceptor, String name, String description, String tid, ContentAssistContext context, String c) {
val id = helper.getId(rule);
val id = helper.getId(rule)
template(templateContext, id, name, description, tid, c, acceptor, context)
}

def addTemplate(AbstractElement rule, TemplateContext templateContext, ITemplateAcceptor acceptor, String name, String description, String tid, ContentAssistContext context, String c) {
val id = helper.getId(rule);
val id = helper.getId(rule)
template(templateContext, id, name, description, tid, c, acceptor, context)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ WollokTemplateProposalProvider_WVariableDeclaration_description = Add new refere

WollokTemplateProposalProvider_WConstructorCall_name = Constructor call
WollokTemplateProposalProvider_WConstructorCall_description = Add a Constructor call

WollokTemplateProposalProvider_WConstructorCallWithNamedParameter_name = Initialize attributes
WollokTemplateProposalProvider_WConstructorCallWithNamedParameter_description = Add named parameters to constructor call

WollokTemplateProposalProvider_WConstructor_name = Add constructor
WollokTemplateProposalProvider_WConstructor_description = Add a new Constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ WollokTemplateProposalProvider_WVariableDeclaration_description = Agregar una nu
WollokTemplateProposalProvider_WConstructorCall_name = Llamada a constructor
WollokTemplateProposalProvider_WConstructorCall_description = Agregar llamada a constructor

WollokTemplateProposalProvider_WConstructorCallWithNamedParameter_name = Inicializar atributos
WollokTemplateProposalProvider_WConstructorCallWithNamedParameter_description = Agregar parámetros nombrados en el constructor

WollokTemplateProposalProvider_WConstructor_name = Agregar constructor
WollokTemplateProposalProvider_WConstructor_description = Agregar un nuevo constructor

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ class WollokDslQuickfixProvider extends DefaultQuickfixProvider {
def addMissingAttributesInConstructorCall(Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, Messages.WollokDslQuickFixProvider_add_missing_initializations_name,
Messages.WollokDslQuickFixProvider_add_missing_initializations_description, null) [ e, it |
val initializations = (e as WConstructorCall)
.uninitializedNamedParameters.map
[ ", " + variable.name + " = value" ].join
val call = e as WConstructorCall
val preffix = if (call.hasNamedParameters) ", " else ""
val initializations = preffix + call.createInitializersForNamedParametersInConstructor
xtextDocument.replace(e.node.endOffset - 1, 0, initializations)
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,4 +680,8 @@ class WollokModelExtensions {
uninitializedAttributes.filter [ arg | !namedArguments.contains(arg.variable.name) ]
}

def static createInitializersForNamedParametersInConstructor(WConstructorCall it) {
uninitializedNamedParameters.map
[ variable.name + " = value" ].join(", ")
}
}

0 comments on commit 3b8b34c

Please sign in to comment.