diff options
Diffstat (limited to 'plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.stereotypeproperty.xtext.ui/src/org/eclipse/papyrus/uml/textedit/stereotypeproperty/xtext/ui/contentassist/AppliedStereotypePropertyProposalProvider.java')
1 files changed, 54 insertions, 61 deletions
diff --git a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.stereotypeproperty.xtext.ui/src/org/eclipse/papyrus/uml/textedit/stereotypeproperty/xtext/ui/contentassist/AppliedStereotypePropertyProposalProvider.java b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.stereotypeproperty.xtext.ui/src/org/eclipse/papyrus/uml/textedit/stereotypeproperty/xtext/ui/contentassist/AppliedStereotypePropertyProposalProvider.java index d7b09a67473..eb1d28394c1 100644 --- a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.stereotypeproperty.xtext.ui/src/org/eclipse/papyrus/uml/textedit/stereotypeproperty/xtext/ui/contentassist/AppliedStereotypePropertyProposalProvider.java +++ b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.stereotypeproperty.xtext.ui/src/org/eclipse/papyrus/uml/textedit/stereotypeproperty/xtext/ui/contentassist/AppliedStereotypePropertyProposalProvider.java @@ -40,6 +40,7 @@ import org.eclipse.xtext.gmf.glue.contentassist.CompletionProposalUtils; import org.eclipse.xtext.gmf.glue.edit.part.PopupXtextEditorHelper; 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 */ @@ -52,110 +53,102 @@ public class AppliedStereotypePropertyProposalProvider extends AbstractAppliedSt public void completeNameExpression_Path(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { - EditPart contextEObject=((EditPart)PopupXtextEditorHelper.getHostEditPart()); - if( contextEObject instanceof IAdaptable){ + EditPart contextEObject = ((EditPart)PopupXtextEditorHelper.getHostEditPart()); + if(contextEObject instanceof IAdaptable) { - AppliedStereotypeProperty appliedStereotypeProperty =(AppliedStereotypeProperty)contextEObject.getAdapter(AppliedStereotypeProperty.class); - if((model instanceof ExpressionValueRule)&&((appliedStereotypeProperty.getStereotypeProperty().getUpper()==1))||(!(model instanceof ExpressionValueRule))){ - EClass stereotypeApplication =appliedStereotypeProperty.getStereotypeApplication().eClass(); + AppliedStereotypeProperty appliedStereotypeProperty = (AppliedStereotypeProperty)contextEObject.getAdapter(AppliedStereotypeProperty.class); + if((model instanceof ExpressionValueRule) && ((appliedStereotypeProperty.getStereotypeProperty().getUpper() == 1)) || (!(model instanceof ExpressionValueRule))) { + EClass stereotypeApplication = appliedStereotypeProperty.getStereotypeApplication().eClass(); - EStructuralFeature foundStructuralFeature=null; - Iterator<EStructuralFeature> iterator= stereotypeApplication.getEAllStructuralFeatures().iterator(); + EStructuralFeature foundStructuralFeature = null; + Iterator<EStructuralFeature> iterator = stereotypeApplication.getEAllStructuralFeatures().iterator(); while(iterator.hasNext()) { EStructuralFeature eStructuralFeature = (EStructuralFeature)iterator.next(); - if(eStructuralFeature.getName().equals(appliedStereotypeProperty.getStereotypeProperty().getName())){ - foundStructuralFeature=eStructuralFeature; + if(eStructuralFeature.getName().equals(appliedStereotypeProperty.getStereotypeProperty().getName())) { + foundStructuralFeature = eStructuralFeature; } } - if( foundStructuralFeature!=null){ - UMLContentProvider umlContentProvider = new UMLContentProvider(appliedStereotypeProperty.getStereotypeApplication(),foundStructuralFeature, appliedStereotypeProperty.getStereotype()); - HierarchicToFlatContentProvider treeToFlatContentProvider = new HierarchicToFlatContentProvider(umlContentProvider); - Object[] result=treeToFlatContentProvider.getElements(); - UMLLabelProvider umlLabelProvider= new UMLLabelProvider(); - for (int i=0; i<result.length;i++){ - if( result[i]instanceof EObject &&UMLUtil.getBaseElement((EObject)result[i])!=null){ - acceptor.accept(CompletionProposalUtils.createCompletionProposal(((NamedElement)UMLUtil.getBaseElement((EObject)result[i])), ((NamedElement)UMLUtil.getBaseElement((EObject)result[i])).getQualifiedName(),((NamedElement)UMLUtil.getBaseElement((EObject)result[i])).getQualifiedName(), context)) ; - } - else if(result[i] instanceof EEnumLiteral){ - EEnumLiteral enumerationLiteral= (EEnumLiteral)result[i]; - acceptor.accept(CompletionProposalUtils.createCompletionProposal(enumerationLiteral.getName(),enumerationLiteral.getName(), context)) ; - } - else if(result[i] instanceof Enumerator){ - Enumerator enumerationLiteral= (Enumerator)result[i]; - acceptor.accept(CompletionProposalUtils.createCompletionProposal(enumerationLiteral.getName(),enumerationLiteral.getName(), context)) ; + if(foundStructuralFeature != null) { + UMLContentProvider umlContentProvider = new UMLContentProvider(appliedStereotypeProperty.getStereotypeApplication(), foundStructuralFeature, appliedStereotypeProperty.getStereotype()); + HierarchicToFlatContentProvider treeToFlatContentProvider = new HierarchicToFlatContentProvider(umlContentProvider); + Object[] result = treeToFlatContentProvider.getElements(); + UMLLabelProvider umlLabelProvider = new UMLLabelProvider(); + for(int i = 0; i < result.length; i++) { + if(result[i] instanceof EObject && UMLUtil.getBaseElement((EObject)result[i]) != null) { + acceptor.accept(CompletionProposalUtils.createCompletionProposal(((NamedElement)UMLUtil.getBaseElement((EObject)result[i])), ((NamedElement)UMLUtil.getBaseElement((EObject)result[i])).getQualifiedName(), ((NamedElement)UMLUtil.getBaseElement((EObject)result[i])).getQualifiedName(), context)); + } else if(result[i] instanceof EEnumLiteral) { + EEnumLiteral enumerationLiteral = (EEnumLiteral)result[i]; + acceptor.accept(CompletionProposalUtils.createCompletionProposal(enumerationLiteral.getName(), enumerationLiteral.getName(), context)); + } else if(result[i] instanceof Enumerator) { + Enumerator enumerationLiteral = (Enumerator)result[i]; + acceptor.accept(CompletionProposalUtils.createCompletionProposal(enumerationLiteral.getName(), enumerationLiteral.getName(), context)); + } else { + if(result[i] instanceof NamedElement) { + NamedElement namedElement = (NamedElement)result[i]; + acceptor.accept(CompletionProposalUtils.createCompletionProposal(namedElement, namedElement.getQualifiedName(), namedElement.getQualifiedName(), context)); + } } - else{ - if(result[i] instanceof NamedElement){ - NamedElement namedElement= (NamedElement)result[i]; - acceptor.accept(CompletionProposalUtils.createCompletionProposal(namedElement, namedElement.getQualifiedName(),namedElement.getQualifiedName(), context)) ; - }} } completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor); } } } } + public void completeNameExpression_Id(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { //acceptor.accept(CompletionProposalUtils.createCompletionProposal("NameExpression_Id", "NameExpression_Id", context)) ; super.completeNameExpression_Id(model, assignment, context, acceptor); //completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor); } - public void completeBooleanKeyWord(Keyword keyword, - ContentAssistContext contentAssistContext, - ICompletionProposalAcceptor acceptor, AppliedStereotypeProperty appliedStereotypeProperty){ - - if( appliedStereotypeProperty.getStereotypeProperty().getType().getName().equals("Boolean")){ - String TRUE="true"; - String FALSE="false"; - if(keyword.getValue().startsWith(TRUE)||(keyword.getValue().startsWith(FALSE))){ + + public void completeBooleanKeyWord(Keyword keyword, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor, AppliedStereotypeProperty appliedStereotypeProperty) { + + if(appliedStereotypeProperty.getStereotypeProperty().getType().getName().equals("Boolean")) { + String TRUE = "true"; + String FALSE = "false"; + if(keyword.getValue().startsWith(TRUE) || (keyword.getValue().startsWith(FALSE))) { addKeyWord(keyword, contentAssistContext, acceptor); } } - + } - public void addKeyWord(Keyword keyword, - ContentAssistContext contentAssistContext, - ICompletionProposalAcceptor acceptor){ + public void addKeyWord(Keyword keyword, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) { - ICompletionProposal proposal = createCompletionProposal(keyword.getValue(), getKeywordDisplayString(keyword), - getImage(keyword), contentAssistContext); + ICompletionProposal proposal = createCompletionProposal(keyword.getValue(), getKeywordDisplayString(keyword), getImage(keyword), contentAssistContext); getPriorityHelper().adjustKeywordPriority(proposal, contentAssistContext.getPrefix()); acceptor.accept(proposal); } @Override - public void completeKeyword(Keyword keyword, - ContentAssistContext contentAssistContext, - ICompletionProposalAcceptor acceptor) { + public void completeKeyword(Keyword keyword, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) { - if (!contentAssistContext.getPrefix().equals("")&&!contentAssistContext.getPrefix().equals("=")) { - if (keyword.getValue().startsWith(contentAssistContext.getPrefix())) + if(!contentAssistContext.getPrefix().equals("") && !contentAssistContext.getPrefix().equals("=")) { + if(keyword.getValue().startsWith(contentAssistContext.getPrefix())) super.completeKeyword(keyword, contentAssistContext, acceptor); - } - else{ + } else { //take in account cardinalities and type of the properties - EditPart contextEObject=((EditPart)PopupXtextEditorHelper.getHostEditPart()); - if( contextEObject instanceof IAdaptable){ - AppliedStereotypeProperty appliedStereotypeProperty =(AppliedStereotypeProperty)contextEObject.getAdapter(AppliedStereotypeProperty.class); + EditPart contextEObject = ((EditPart)PopupXtextEditorHelper.getHostEditPart()); + if(contextEObject instanceof IAdaptable) { + AppliedStereotypeProperty appliedStereotypeProperty = (AppliedStereotypeProperty)contextEObject.getAdapter(AppliedStereotypeProperty.class); completeBooleanKeyWord(keyword, contentAssistContext, acceptor, appliedStereotypeProperty); //collection - if(appliedStereotypeProperty.getStereotypeProperty().getUpper()==-1||appliedStereotypeProperty.getStereotypeProperty().getUpper()>1){ - if(keyword.getValue().startsWith("}")||keyword.getValue().startsWith("{")||keyword.getValue().startsWith(",")||keyword.getValue().startsWith("null")||keyword.getValue().startsWith(",")){ + if(appliedStereotypeProperty.getStereotypeProperty().getUpper() == -1 || appliedStereotypeProperty.getStereotypeProperty().getUpper() > 1) { + if(keyword.getValue().startsWith("}") || keyword.getValue().startsWith("{") || keyword.getValue().startsWith(",") || keyword.getValue().startsWith("null") || keyword.getValue().startsWith(",")) { addKeyWord(keyword, contentAssistContext, acceptor); } } - if(appliedStereotypeProperty.getStereotypeProperty().getUpper()==1){ - if(keyword.getValue().startsWith("null")){ + if(appliedStereotypeProperty.getStereotypeProperty().getUpper() == 1) { + if(keyword.getValue().startsWith("null")) { addKeyWord(keyword, contentAssistContext, acceptor); } } - - if(appliedStereotypeProperty.getStereotypeProperty().getType().eClass().getName().equals("PrimitiveType")){ - if(keyword.getValue().startsWith("\"")){ + + if(appliedStereotypeProperty.getStereotypeProperty().getType().eClass().getName().equals("PrimitiveType")) { + if(keyword.getValue().startsWith("\"")) { addKeyWord(keyword, contentAssistContext, acceptor); } } |