diff options
Diffstat (limited to 'extraplugins/alf')
-rw-r--r-- | extraplugins/alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/contentassist/AlfProposalProvider.java | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/extraplugins/alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/contentassist/AlfProposalProvider.java b/extraplugins/alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/contentassist/AlfProposalProvider.java index 38e24e1e7fb..940d1247a2d 100644 --- a/extraplugins/alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/contentassist/AlfProposalProvider.java +++ b/extraplugins/alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/contentassist/AlfProposalProvider.java @@ -13,10 +13,168 @@ *****************************************************************************/ package org.eclipse.papyrus.alf.ui.contentassist; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.text.contentassist.ICompletionProposal; +import org.eclipse.papyrus.alf.alf.NameExpression; +import org.eclipse.papyrus.alf.alf.PropertyCallExpression; +import org.eclipse.papyrus.alf.alf.SuffixExpression; +import org.eclipse.papyrus.alf.scoping.AlfScopingTool; +import org.eclipse.papyrus.alf.scoping.AlfPartialScope; +import org.eclipse.papyrus.alf.scoping.AlfScopeProvider; import org.eclipse.papyrus.alf.ui.contentassist.AbstractAlfProposalProvider; +import org.eclipse.papyrus.alf.validation.AlfJavaValidator; +import org.eclipse.papyrus.alf.validation.typing.ErrorTypeFacade; +import org.eclipse.papyrus.alf.validation.typing.SignatureFacadeFactory; +import org.eclipse.papyrus.alf.validation.typing.TypeExpression; +import org.eclipse.papyrus.alf.validation.typing.TypeFacade; +import org.eclipse.papyrus.alf.validation.typing.TypeUtils; +import org.eclipse.uml2.uml.Classifier; +import org.eclipse.uml2.uml.Operation; +import org.eclipse.uml2.uml.Property; +import org.eclipse.xtext.Assignment; +import org.eclipse.xtext.RuleCall; +import org.eclipse.xtext.gmf.glue.contentassist.CompletionProposalUtils; +import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext; +import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor; /** * see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#contentAssist on how to customize content assistant */ public class AlfProposalProvider extends AbstractAlfProposalProvider { + + + @Override + public void completeLocalNameDeclarationStatement_Type(EObject model, + Assignment assignment, ContentAssistContext context, + ICompletionProposalAcceptor acceptor) { + // TODO Auto-generated method stub + AlfPartialScope scope = AlfScopeProvider.scopingTool.getVisibleClassifiers(model) ; + new AlfCompletionProposalUtils().classifierProposals(scope, context, acceptor) ; + super.completeLocalNameDeclarationStatement_Type(model, assignment, context, + acceptor); + } + + @Override + public void completeOperationCallExpression_OperationName(EObject model, + Assignment assignment, ContentAssistContext context, + ICompletionProposalAcceptor acceptor) { + TypeExpression typeOfModel = null ; + if (model instanceof SuffixExpression) { + if (context.getPrefix().equals("")) + typeOfModel = new TypeUtils().getTypeOfCandidateExpression(model) ; + else + typeOfModel = new TypeUtils((SuffixExpression)model).getTypeOfCandidateExpression(model.eContainer()) ; + } + else { + typeOfModel = new TypeUtils().getTypeOfCandidateExpression(model) ; + } + if (typeOfModel == null || typeOfModel.getTypeFacade() instanceof ErrorTypeFacade) + super.completeOperationCallExpression_OperationName(model, assignment, context, + acceptor); + else { + new AlfCompletionProposalUtils().operationProposals(typeOfModel.getTypeFacade(), context, acceptor) ; + super.completeOperationCallExpression_OperationName(model, assignment, context, acceptor); + } + } + + + @Override + public void completePropertyCallExpression_PropertyName(EObject model, + Assignment assignment, ContentAssistContext context, + ICompletionProposalAcceptor acceptor) { + TypeExpression typeOfModel = null ; + if (model instanceof SuffixExpression) { + if (context.getPrefix().equals("")) + typeOfModel = new TypeUtils().getTypeOfCandidateExpression(model) ; + else + typeOfModel = new TypeUtils((SuffixExpression)model).getTypeOfCandidateExpression(model.eContainer()) ; + } + else { + typeOfModel = new TypeUtils().getTypeOfCandidateExpression(model) ; + } + if (typeOfModel == null || typeOfModel.getTypeFacade() instanceof ErrorTypeFacade) + super.completePropertyCallExpression_PropertyName(model, assignment, context, + acceptor); + else { + new AlfCompletionProposalUtils().propertyProposals(typeOfModel.getTypeFacade(), context, acceptor) ; + super.completePropertyCallExpression_PropertyName(model, assignment, context, acceptor); + } + } + + /************************** + * + * Completion proposal utils + * + */ + private class AlfCompletionProposalUtils { + + public void classifierProposals(AlfPartialScope scope, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { + for (List<EObject> scopingLevel : scope.getScopeDetails()) { + String completionString = "" ; + String displayString = "" ; + Map<String, ICompletionProposal> completionProposals = new HashMap<String, ICompletionProposal>() ; + ICompletionProposal proposal = null ; + for (EObject visibleClassifier : scopingLevel) { + completionString = scope.getElementName(visibleClassifier) ; + displayString = "" + completionString ; + if (completionString.startsWith(context.getPrefix())) { + completionString = completionString.substring(context.getPrefix().length()) ; + if (completionProposals.get(displayString)==null) { + completionProposals.put(displayString, proposal) ; + proposal = CompletionProposalUtils.createCompletionProposal(completionString, displayString, context) ; + acceptor.accept(proposal) ; + } + } + } + } + } + + public void operationProposals(TypeFacade f, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { + Classifier c = f.extractActualType() ; + String completionString = "" ; + String displayString = "" ; + Map<String, ICompletionProposal> completionProposals = new HashMap<String, ICompletionProposal>() ; + ICompletionProposal proposal = null ; + for (Operation o : c.getAllOperations()) { + completionString = SignatureFacadeFactory.eInstance.createSignatureFacade(o).getLabel() ; + displayString = "" + completionString ; + if (completionString.startsWith(context.getPrefix())) { + completionString = completionString.substring(context.getPrefix().length()) ; + if (completionProposals.get(displayString)==null) { + completionProposals.put(displayString, proposal) ; + proposal = CompletionProposalUtils.createCompletionProposal(completionString, displayString, context) ; + acceptor.accept(proposal) ; + } + } + } + } + + public void propertyProposals(TypeFacade f, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { + Classifier c = f.extractActualType() ; + String completionString = "" ; + String displayString = "" ; + Map<String, ICompletionProposal> completionProposals = new HashMap<String, ICompletionProposal>() ; + ICompletionProposal proposal = null ; + for (Property p : c.getAllAttributes()) { + displayString = p.getName() + " : " + (p.getType() == null ? "any" : p.getType().getName()) ; + completionString = p.getName() ; + if (completionString.startsWith(context.getPrefix())) { + completionString = completionString.substring(context.getPrefix().length()) ; + if (completionProposals.get(displayString)==null) { + completionProposals.put(displayString, proposal) ; + proposal = CompletionProposalUtils.createCompletionProposal(completionString, displayString, context) ; + acceptor.accept(proposal) ; + } + } + } + } + } + } |