Commit 2948eeca authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ improvements for code completion in TO, #230

parent 156f6789
Loading
Loading
Loading
Loading
Loading
+30 −7
Original line number Diff line number Diff line
@@ -371,6 +371,13 @@ public class TDLtxProposalProvider extends AbstractTDLtxProposalProvider {
	}

	private void completeAssignment(EObject model, ContentAssistContext context, ICompletionProposalAcceptor acceptor, DataType type) {
		String prefix = "";
		String suffix = "( )";
		String collectionSuffix = "[ ]";
		completeAssignment(model, context, acceptor, type, prefix, suffix, collectionSuffix);
	}
	
	private void completeAssignment(EObject model, ContentAssistContext context, ICompletionProposalAcceptor acceptor, DataType type, String prefix, String suffix, String collectionSuffix) {
		List<NamedElement> namedElements = getAllElementsOfType(model, NamedElement.class);

		for (NamedElement ne : namedElements) {
@@ -383,13 +390,12 @@ public class TDLtxProposalProvider extends AbstractTDLtxProposalProvider {
				if (ne instanceof SimpleDataType) {
					
				} else {
					String prefix = "";
					String suffix = "( )";
					String usedSuffix = suffix;
					if (ne instanceof CollectionDataType) {
						suffix = "[ ]";
						usedSuffix = collectionSuffix;
					}
					acceptor.accept(createCompletionProposal(suffix, new StyledString(suffix).append(" : new anonymous instance of type "+ne.getName(), StyledString.DECORATIONS_STYLER), getImage(ne), 1200, "", context));
					acceptor.accept(createCompletionProposal(prefix+ne.getName()+suffix, new StyledString(prefix+ne.getName()+suffix).append(" : new instance of type", StyledString.DECORATIONS_STYLER), getImage(ne), 1100, "", context));
					acceptor.accept(createCompletionProposal(usedSuffix, new StyledString(usedSuffix).append(" : new anonymous instance of type "+ne.getName(), StyledString.DECORATIONS_STYLER), getImage(ne), 1200, "", context));
					acceptor.accept(createCompletionProposal(prefix+ne.getName()+usedSuffix, new StyledString(prefix+ne.getName()+usedSuffix).append(" : new instance of type", StyledString.DECORATIONS_STYLER), getImage(ne), 1100, "", context));
				}
			} else if (ne instanceof Function && ((Function) ne).getReturnType().conformsTo(type)) {
				accept = true;
@@ -917,7 +923,24 @@ public class TDLtxProposalProvider extends AbstractTDLtxProposalProvider {
	@Override
	public void completeTOCollectionItemFragment_Item(EObject model, Assignment assignment, ContentAssistContext context,
			ICompletionProposalAcceptor acceptor) {
		completeCollectionDataInstance_Item(model, assignment, context, acceptor);
		//TODO: copied from collectionItemFragment_Item
		
		if (model instanceof DataElementUse) {
			NamedElement dataElement = ((DataElementUse) model).getDataElement();
			if (dataElement == null) {
				dataElement = ((DataElementUse) model).resolveDataType();
			}
			if (dataElement instanceof CollectionDataType) {
				DataType itemType = ((CollectionDataType) dataElement).getItemType();
				//TODO: spacing issue / empty data element
				completeAssignment(model, context, acceptor, itemType, "", " containing { }", " including { }");
				return; //?
			}
		}
		//super completeRuleCall
		if (superContainment)
			super.completeCollectionItemFragment_Item(model, assignment, context, acceptor);

	}

	//TODO: anything specific?