Java Code Examples for org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext#getCurrentModel()

The following examples show how to use org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext#getCurrentModel() . 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: N4JSIdeContentProposalProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void _createProposals(Keyword keyword, ContentAssistContext context,
		IIdeContentProposalAcceptor acceptor) {

	EObject currentModel = context.getCurrentModel();
	EObject previousModel = context.getPreviousModel();
	if (currentModel instanceof ParameterizedPropertyAccessExpression ||
			previousModel instanceof ParameterizedPropertyAccessExpression)
		return; // filter out all keywords if we are in the context of a property access
	if (currentModel instanceof JSXElement || previousModel instanceof JSXElement)
		return; // filter out all keywords if we are in the context of a JSX element
	if (!Character.isAlphabetic(keyword.getValue().charAt(0)))
		return; // filter out operators
	if (keyword.getValue().length() < 5)
		return; // filter out short keywords
	super._createProposals(keyword, context, acceptor);
}
 
Example 2
Source File: JSONIdeContentProposalProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private void proposeVersions(ContentAssistContext context, IIdeContentProposalAcceptor acceptor,
		List<String> namePath) {
	if (namePath.size() >= 2) {
		// somewhat poor heuristic: propose all projects that are known in the current workspace
		String devOrDep = namePath.get(namePath.size() - 2);
		if (PackageJsonProperties.DEPENDENCIES.name.equals(devOrDep)
				|| PackageJsonProperties.DEV_DEPENDENCIES.name.equals(devOrDep)) {

			NameValuePair pair = (NameValuePair) context.getCurrentModel();
			IN4JSProject project = n4jsCore.findProject(new N4JSProjectName(pair.getName())).orNull();
			if (project != null) {
				VersionNumber version = project.getVersion();
				ContentAssistEntry versionEntry = getProposalCreator().createProposal(
						'"' + version.toString() + '"', context, ContentAssistEntry.KIND_VALUE, null);
				acceptor.accept(versionEntry, getProposalPriorities().getDefaultPriority(versionEntry));
			}
			ContentAssistEntry wildcard = getProposalCreator().createProposal(
					"\"*\"", context, ContentAssistEntry.KIND_VALUE, null);
			acceptor.accept(wildcard, getProposalPriorities().getDefaultPriority(wildcard));
		}
	}
}
 
Example 3
Source File: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void createReceiverProposals(final XExpression receiver, final CrossReference crossReference, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(receiver);
  final LightweightTypeReference receiverType = resolvedTypes.getActualType(receiver);
  if (((receiverType == null) || receiverType.isPrimitiveVoid())) {
    return;
  }
  final IExpressionScope expressionScope = resolvedTypes.getExpressionScope(receiver, IExpressionScope.Anchor.RECEIVER);
  IScope scope = null;
  final EObject currentModel = context.getCurrentModel();
  if ((currentModel != receiver)) {
    if (((currentModel instanceof XMemberFeatureCall) && 
      (((XMemberFeatureCall) currentModel).getMemberCallTarget() == receiver))) {
      scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(((XAbstractFeatureCall) currentModel)), crossReference);
    } else {
      scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(), crossReference);
    }
  } else {
    scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(), crossReference);
  }
  this.getCrossrefProposalProvider().lookupCrossReference(scope, crossReference, context, acceptor, this.featureDescriptionPredicate);
}
 
Example 4
Source File: N4JSIdeContentProposalProvider.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * For type proposals, use a dedicated proposal creator that will query the scope, filter it and apply the proposal
 * factory to all applicable {@link IEObjectDescription descriptions}.
 */
protected void lookupCrossReference(EReference reference, ContentAssistContext context,
		IIdeContentProposalAcceptor acceptor, Predicate<IEObjectDescription> filter) {

	if (reference.getEReferenceType().isSuperTypeOf(TypesPackage.Literals.TYPE)
			|| TypesPackage.Literals.TYPE.isSuperTypeOf(reference.getEReferenceType())) {

		EObject model = context.getCurrentModel();
		importsAwareReferenceProposalCreator.lookupCrossReference(model, reference, context, acceptor, filter);
	}
}
 
Example 5
Source File: JSONIdeContentProposalProvider.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private void createNameValueProposals(ContentAssistContext context, IIdeContentProposalAcceptor acceptor) {
	EObject model = context.getCurrentModel();
	List<String> namePath = CompletionUtils.getJsonPathNames(model);
	Set<String> alreadyUsedNames = CompletionUtils.getAlreadyUsedNames(model);
	List<PackageJsonProperties> pathProps = PackageJsonProperties.valuesOfPath(namePath);
	for (PackageJsonProperties pathProp : pathProps) {
		String name = pathProp.name;
		String label = name;
		if (!alreadyUsedNames.contains(name) && this.isMatchingPairPrefix(context, name)) {
			if (context.getPrefix().startsWith("\"")) {
				label = '"' + name + '"';
			}
			String proposal = null;
			String kind = null;
			if (pathProp.valueType == JSONStringLiteral.class) {
				proposal = String.format("\"%s\": \"$1\"$0", name);
				kind = ContentAssistEntry.KIND_PROPERTY;
			} else if (pathProp.valueType == JSONArray.class) {
				proposal = String.format("\"%s\": [\n\t$1\n]$0", name);
				kind = ContentAssistEntry.KIND_VALUE;
			} else if (pathProp.valueType == JSONObject.class) {
				proposal = String.format("\"%s\": {\n\t$1\n}$0", name);
				kind = ContentAssistEntry.KIND_CLASS;
			}
			if (proposal != null) {
				addTemplateProposal(proposal, label, pathProp.description, kind, context, acceptor);
			}
		}
	}
	if (pathProps.isEmpty()) {
		addTemplateProposal("\"${1:name}\": \"$2\"$0", "<value>", "Generic name value pair",
				ContentAssistEntry.KIND_PROPERTY, context, acceptor);
		addTemplateProposal("\"${1:name}\": [\n\t$2\n]$0", "<array>", "Generic name array pair",
				ContentAssistEntry.KIND_VALUE, context, acceptor);
		addTemplateProposal("\"${1:name}\": {\n\t$2\n}$0", "<object>", "Generic name object pair",
				ContentAssistEntry.KIND_CLASS, context, acceptor);
	}
}