Java Code Examples for org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext#getPrefix()

The following examples show how to use org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext#getPrefix() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TwoContextsContentAssistTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void completeKeyword(Keyword keyword, final ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
	super.completeKeyword(keyword, context, new FilteringCompletionProposalAcceptor(acceptor, new Predicate<ICompletionProposal>() {
		@Override
		public boolean apply(ICompletionProposal input) {
			if (!input.getDisplayString().startsWith(context.getPrefix()))
				throw new IllegalStateException("proposed element '"+input.getDisplayString()+"' does not start with '"+ context.getPrefix()+"'");
			return true;
		}
	}));
}
 
Example 2
Source File: XbaseProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void completeJavaTypes(ContentAssistContext context, EReference reference, boolean forced,
		IValueConverter<String> valueConverter, ITypesProposalProvider.Filter filter,
		ICompletionProposalAcceptor acceptor) {
	String prefix = context.getPrefix();
	if (prefix.length() > 0) {
		if (Character.isJavaIdentifierStart(context.getPrefix().charAt(0))) {
			if (!forced && getXbaseCrossReferenceProposalCreator().isShowSmartProposals()) {
				if (!prefix.contains(".") && !prefix.contains("::") && !Character.isUpperCase(prefix.charAt(0)))
					return;
			}
			typeProposalProvider.createTypeProposals(this, context, reference, filter, valueConverter, acceptor);
		}
	} else {
		if (forced || !getXbaseCrossReferenceProposalCreator().isShowSmartProposals()) {
			INode lastCompleteNode = context.getLastCompleteNode();
			if (lastCompleteNode instanceof ILeafNode && !((ILeafNode) lastCompleteNode).isHidden()) {
				if (lastCompleteNode.getLength() > 0 && lastCompleteNode.getTotalEndOffset() == context.getOffset()) {
					String text = lastCompleteNode.getText();
					char lastChar = text.charAt(text.length() - 1);
					if (Character.isJavaIdentifierPart(lastChar)) {
						return;
					}
				}
			}
			typeProposalProvider.createTypeProposals(this, context, reference, filter, valueConverter, acceptor);
		}
	}
}
 
Example 3
Source File: XbaseProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected void createLocalVariableAndImplicitProposals(
			EObject context,
			IExpressionScope.Anchor anchor,
			ContentAssistContext contentAssistContext,
			ICompletionProposalAcceptor acceptor) {
		String prefix = contentAssistContext.getPrefix();
		if (prefix.length() > 0) {
			if (!Character.isJavaIdentifierStart(prefix.charAt(0))) {
				if (prefix.length() > 1) {
					if (prefix.charAt(0) == '^' && !Character.isJavaIdentifierStart(prefix.charAt(1))) {
						return;
					}
				}
			}
		}
		
//		long time = System.currentTimeMillis();
		Function<IEObjectDescription, ICompletionProposal> proposalFactory = getProposalFactory(getFeatureCallRuleName(), contentAssistContext);
		IResolvedTypes resolvedTypes = context != null ? typeResolver.resolveTypes(context) : typeResolver.resolveTypes(contentAssistContext.getResource());
		IExpressionScope expressionScope = resolvedTypes.getExpressionScope(context, anchor);
		// TODO use the type name information
		IScope scope = expressionScope.getFeatureScope();
		getCrossReferenceProposalCreator().lookupCrossReference(scope, context, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor, getFeatureDescriptionPredicate(contentAssistContext), proposalFactory);
//		System.out.printf("XbaseProposalProvider.createLocalVariableAndImplicitProposals = %d\n", System.currentTimeMillis() - time);
//		time = System.currentTimeMillis();
		
		// TODO use the type name information
		proposeDeclaringTypeForStaticInvocation(context, null /* ignore */, contentAssistContext, acceptor);
//		System.out.printf("XbaseProposalProvider.proposeDeclaringTypeForStaticInvocation = %d\n", System.currentTimeMillis() - time);
		if(context != null && !(context instanceof XMemberFeatureCall)) {
			Iterable<JvmFeature> featuresToImport = getFavoriteStaticFeatures(context, input->true);
			// Create StaticFeatureDescription instead of SimpleIdentifiableElementDescription since we want the Proposal to show parameters
			Iterable<IEObjectDescription> scopedFeatures = Iterables.transform(featuresToImport, feature -> {
				QualifiedName qualifiedName = QualifiedName.create(feature.getSimpleName());
				return new StaticFeatureDescription(qualifiedName, feature, 0, true);	
			});
			// Scope for all static features
			IScope staticMemberScope = new SimpleScope(IScope.NULLSCOPE, scopedFeatures);
			proposeFavoriteStaticFeatures(context, contentAssistContext, acceptor, staticMemberScope);
		}
	}
 
Example 4
Source File: DotProposalProvider.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
private void proposeAttributeValues(String subgrammarName,
		ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	INode currentNode = context.getCurrentNode();
	String nodeText = currentNode.getText();
	String prefix = context.getPrefix();

	int offset = currentNode.getOffset();
	String text = nodeText.trim();

	if (!nodeText.contains(prefix)) {
		text = prefix;
		offset = context.getOffset() - prefix.length();
	} else {
		boolean quoted = text.startsWith("\"") //$NON-NLS-1$
				&& text.endsWith("\""); //$NON-NLS-1$
		boolean html = text.startsWith("<") && text.endsWith(">"); //$NON-NLS-1$ //$NON-NLS-2$

		if (quoted || html) {
			if (quoted) {
				text = ID.fromString(text, Type.QUOTED_STRING).toValue();
			} else {
				text = text.substring(1, text.length() - 1);
			}
			offset++;
		}
	}

	List<ConfigurableCompletionProposal> configurableCompletionProposals = new DotProposalProviderDelegator(
			subgrammarName).computeConfigurableCompletionProposals(text,
					context.getOffset() - offset);

	for (ConfigurableCompletionProposal configurableCompletionProposal : configurableCompletionProposals) {
		// adapt the replacement offset determined within the
		// sub-grammar context to be valid within the context of the
		// original text
		configurableCompletionProposal.setReplacementOffset(offset
				+ configurableCompletionProposal.getReplacementOffset());

		acceptor.accept(configurableCompletionProposal);
	}
}