org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor Java Examples

The following examples show how to use org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor. 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: JSONIdeContentProposalProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private void proposeProjectTypes(ContentAssistContext context, IIdeContentProposalAcceptor acceptor,
		List<String> namePath) {
	if (namePath.size() >= 2) {
		String n4js = namePath.get(namePath.size() - 2);
		String projectType = namePath.get(namePath.size() - 1);
		if (PackageJsonProperties.PROJECT_TYPE.name.equals(projectType)
				|| PackageJsonProperties.N4JS.name.equals(n4js)) {

			for (ProjectType type : ProjectType.values()) {
				String asString = PackageJsonUtils.getProjectTypeStringRepresentation(type);
				if (asString.equals(asString.toUpperCase())) {
					asString = asString.toLowerCase();
				}
				ContentAssistEntry entryForProjectType = getProposalCreator().createProposal(
						'"' + asString + '"', context, ContentAssistEntry.KIND_KEYWORD, null);
				if (entryForProjectType != null) {
					acceptor.accept(entryForProjectType,
							getProposalPriorities().getDefaultPriority(entryForProjectType));
				}
			}
		}
	}
}
 
Example #2
Source File: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void completeXFeatureCall(final EObject model, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  if ((model != null)) {
    boolean _hasExpressionScope = this.typeResolver.resolveTypes(model).hasExpressionScope(model, IExpressionScope.Anchor.WITHIN);
    if (_hasExpressionScope) {
      return;
    }
  }
  if ((model instanceof XMemberFeatureCall)) {
    final ICompositeNode node = NodeModelUtils.getNode(model);
    boolean _isInMemberFeatureCall = this.isInMemberFeatureCall(model, node.getEndOffset(), context);
    if (_isInMemberFeatureCall) {
      return;
    }
  }
  this.createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.AFTER, context, acceptor);
}
 
Example #3
Source File: ClasspathBasedIdeTypesProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void createTypeProposals(EReference reference, ContentAssistContext context,
		Predicate<? super ITypeDescriptor> filter, IIdeContentProposalAcceptor acceptor) {
	ITextRegion importSectionRegion = null;
	XImportSection importSection = null;
	if (!isImportDeclaration(reference, context)) {
		importSection = importsConfiguration.getImportSection(context.getResource());
		importSectionRegion = importSectionRegionUtil.computeRegion(context.getResource());
	}
	for (ITypeDescriptor typeDesc : getTypeDescriptors(context)) {
		if (!acceptor.canAcceptMoreProposals()) {
			return;
		}
		if (canPropose(typeDesc, context, filter)) {
			ContentAssistEntry entry = createProposal(reference, typeDesc, context, importSection,
					importSectionRegion);
			int priority = ((XbaseIdeContentProposalPriorities) proposalPriorities).getTypeRefPriority(typeDesc,
					entry);
			acceptor.accept(entry, priority);
		}
	}
}
 
Example #4
Source File: JSONIdeContentProposalProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private void addTemplateProposal(
		String proposal,
		String label,
		String description,
		String kind,
		ContentAssistContext context,
		IIdeContentProposalAcceptor acceptor) {
	if (getProposalCreator().isValidProposal(label, context.getPrefix(), context)) {
		ContentAssistEntry entry = new ContentAssistEntry();
		entry.setProposal(proposal);
		entry.setPrefix(context.getPrefix());
		entry.setKind(ContentAssistEntry.KIND_SNIPPET + ":" + kind);
		entry.setLabel(label);
		entry.setDescription(description);
		acceptor.accept(entry, getProposalPriorities().getDefaultPriority(entry));
	}
}
 
Example #5
Source File: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void createLocalVariableAndImplicitProposals(final EObject model, final IExpressionScope.Anchor anchor, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  String prefix = context.getPrefix();
  if (((prefix.length() > 0) && (!Character.isJavaIdentifierStart(prefix.charAt(0))))) {
    return;
  }
  IResolvedTypes _xifexpression = null;
  if ((model != null)) {
    _xifexpression = this.typeResolver.resolveTypes(model);
  } else {
    _xifexpression = this.typeResolver.resolveTypes(context.getResource());
  }
  final IResolvedTypes resolvedTypes = _xifexpression;
  final IExpressionScope expressionScope = resolvedTypes.getExpressionScope(model, anchor);
  final IScope scope = expressionScope.getFeatureScope();
  this.getCrossrefProposalProvider().lookupCrossReference(scope, this._xbaseGrammarAccess.getXFeatureCallAccess().getFeatureJvmIdentifiableElementCrossReference_2_0(), context, acceptor, this.featureDescriptionPredicate);
}
 
Example #6
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 #7
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 #8
Source File: JSONIdeContentProposalProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private void proposeLocalPackages(ContentAssistContext context, IIdeContentProposalAcceptor acceptor,
		List<String> namePath) {
	if (!namePath.isEmpty()) {
		// somewhat poor heuristic: propose all projects that are known in the current workspace
		String last = namePath.get(namePath.size() - 1);
		if (PackageJsonProperties.DEPENDENCIES.name.equals(last)
				|| PackageJsonProperties.DEV_DEPENDENCIES.name.equals(last)) {
			for (IN4JSProject project : n4jsCore.findAllProjects()) {
				N4JSProjectName projectName = project.getProjectName();
				ContentAssistEntry entryForModule = getProposalCreator().createProposal(
						'"' + projectName.getRawName() + '"', context, ContentAssistEntry.KIND_MODULE, null);
				if (entryForModule != null) {
					acceptor.accept(entryForModule, getProposalPriorities().getDefaultPriority(entryForModule));
				}
			}
		}
	}
}
 
Example #9
Source File: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void createProposals(final AbstractElement assignment, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  if (assignment instanceof Assignment) {
    _createProposals((Assignment)assignment, context, acceptor);
    return;
  } else if (assignment instanceof CrossReference) {
    _createProposals((CrossReference)assignment, context, acceptor);
    return;
  } else if (assignment instanceof Keyword) {
    _createProposals((Keyword)assignment, context, acceptor);
    return;
  } else if (assignment instanceof RuleCall) {
    _createProposals((RuleCall)assignment, context, acceptor);
    return;
  } else if (assignment != null) {
    _createProposals(assignment, context, acceptor);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(assignment, context, acceptor).toString());
  }
}
 
Example #10
Source File: ImportsAwareReferenceProposalCreator.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Retrieves possible reference targets from scope, including erroneous solutions (e.g., not visible targets). This
 * list is further filtered here. This is a general pattern: Do not change or modify scoping for special content
 * assist requirements, instead filter here.
 *
 * @param filter
 *            by default an instance of {@link N4JSCandidateFilter} will be provided here.
 */
public void lookupCrossReference(
		EObject model,
		EReference reference,
		ContentAssistContext context,
		IIdeContentProposalAcceptor acceptor,
		Predicate<IEObjectDescription> filter) {

	if (model == null) {
		return;
	}
	Resource resource = model.eResource();
	if (!(resource instanceof N4JSResource)) {
		return;
	}
	N4JSResource resourceCasted = (N4JSResource) resource;

	ReferenceDescriptor referenceDesc = new ReferenceDescriptor(context.getPrefix(), model, reference,
			context.getCurrentNode());
	Predicate<String> conflictChecker = (proposalToCheck) -> conflictHelper.existsConflict(proposalToCheck,
			context);

	referenceResolutionFinder.findResolutions(referenceDesc, false, false, conflictChecker, filter,
			new ResolutionToContentProposalAcceptor(resourceCasted, context, acceptor));
}
 
Example #11
Source File: StatemachineTemplateProposalProvider.java    From xtext-web with Eclipse Public License 2.0 6 votes vote down vote up
public void createStateProposal(ContentAssistContext context, IIdeContentProposalAcceptor acceptor) {
	StringConcatenationClient template = new StringConcatenationClient() {
		@Override
		protected void appendTo(StringConcatenationClient.TargetStringConcatenation target) {
			target.append("state ");
			target.append(variable("name"));
			target.newLineIfNotEmpty();
			target.append("\t");
			target.append(cursor(), "\t");
			target.newLineIfNotEmpty();
			target.append("end");
			target.newLine();
		}
	};
	acceptProposal("state", "Create a new state", template, context, acceptor);
}
 
Example #12
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 #13
Source File: HoverService.java    From xtext-web with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Compute a hover result for a content assist proposal at the given offset.
 */
public HoverResult getHover(XtextWebDocumentAccess document, String proposal, ITextRegion selection, int offset)
		throws InvalidRequestException {
	return document.readOnly(new CancelableUnitOfWork<HoverResult, IXtextWebDocument>() {
		@Override
		public HoverResult exec(IXtextWebDocument it, CancelIndicator cancelIndicator) throws Exception {
			ContentAssistContext[] contexts = contentAssistService.getContexts(it, selection, offset);
			Wrapper<Object> proposedElement = new Wrapper<Object>();
			Collection<ContentAssistContext> contextsList = Arrays.asList(contexts);
			contentAssistService.getProposalProvider().createProposals(contextsList,
					new IIdeContentProposalAcceptor() {
						@Override
						public void accept(ContentAssistEntry entry, int priority) {
							operationCanceledManager.checkCanceled(cancelIndicator);
							if (entry != null && entry.getSource() != null
									&& Objects.equal(entry.getProposal(), proposal)) {
								proposedElement.set(entry.getSource());
							}
						}

						@Override
						public boolean canAcceptMoreProposals() {
							return proposedElement.get() == null;
						}
					});
			return createHover(proposedElement.get(), it.getStateId(), cancelIndicator);
		}
	});
}
 
Example #14
Source File: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void _createProposals(final RuleCall ruleCall, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  AbstractRule _rule = ruleCall.getRule();
  boolean _matched = false;
  ParserRule _xExpressionRule = this._xbaseGrammarAccess.getXExpressionRule();
  if (Objects.equal(_rule, _xExpressionRule)) {
    _matched=true;
    if (((ruleCall.eContainer() instanceof Group) && Objects.equal(GrammarUtil.containingRule(ruleCall).getName(), "XParenthesizedExpression"))) {
      this.createLocalVariableAndImplicitProposals(context.getCurrentModel(), IExpressionScope.Anchor.WITHIN, context, acceptor);
    }
  }
  if (!_matched) {
    super._createProposals(ruleCall, context, acceptor);
  }
}
 
Example #15
Source File: UiToIdeContentProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void createProposals(org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	ArrayList<SimpleEntry<ContentAssistEntry, Integer>> entries = new ArrayList<>();
	IIdeContentProposalAcceptor ideAcceptor = new IIdeContentProposalAcceptor() {

		@Override
		public void accept(ContentAssistEntry entry, int priority) {
			if (entry != null) {
				entries.add(new SimpleEntry<ContentAssistEntry, Integer>(entry, priority));
			}
		}

		@Override
		public boolean canAcceptMoreProposals() {
			return entries.size() < getMaxProposals();
		}
	};

	ideProvider.createProposals(Arrays.asList(getIdeContext(context)), ideAcceptor);
	NullSafeCompletionProposalAcceptor uiAcceptor = new NullSafeCompletionProposalAcceptor(acceptor);

	entries.forEach(entry -> {
		ContentAssistEntry cae = entry.getKey();
		ConfigurableCompletionProposal proposal = doCreateProposal(cae.getProposal(), getDisplayString(cae), getImage(cae),
				entry.getValue(), context);
		uiAcceptor.accept(proposal);
	});
}
 
Example #16
Source File: TestLanguageIdeContentProposalProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void _createProposals(RuleCall ruleCall, ContentAssistContext context,
		IIdeContentProposalAcceptor acceptor) {
	if (testLanguageGrammarAccess.getTypeDeclarationRule().equals(ruleCall.getRule())) {
		StringConcatenation builder = new StringConcatenation();
		builder.append("type ${1|A,B,C|} {");
		builder.newLine();
		builder.append("\t");
		builder.newLine();
		builder.append("}");
		acceptor.accept(getProposalCreator().createSnippet(builder.toString(), "Sample Snippet", context), 0);
	}
	super._createProposals(ruleCall, context, acceptor);
}
 
Example #17
Source File: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void completeXMemberFeatureCall(final EObject model, final Assignment assignment, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  if ((model instanceof XMemberFeatureCall)) {
    AbstractElement _terminal = assignment.getTerminal();
    this.createReceiverProposals(((XMemberFeatureCall)model).getMemberCallTarget(), 
      ((CrossReference) _terminal), context, acceptor);
  } else {
    if ((model instanceof XAssignment)) {
      AbstractElement _terminal_1 = assignment.getTerminal();
      this.createReceiverProposals(((XAssignment)model).getAssignable(), 
        ((CrossReference) _terminal_1), context, acceptor);
    }
  }
}
 
Example #18
Source File: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void completeXBasicForLoopInit(final EObject model, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  final ICompositeNode node = NodeModelUtils.getNode(model);
  int _offset = node.getOffset();
  int _offset_1 = context.getOffset();
  boolean _greaterEqualsThan = (_offset >= _offset_1);
  if (_greaterEqualsThan) {
    this.createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor);
    return;
  }
  if ((model instanceof XBasicForLoopExpression)) {
    final EList<XExpression> children = ((XBasicForLoopExpression)model).getInitExpressions();
    for (int i = (children.size() - 1); (i >= 0); i--) {
      {
        final XExpression child = children.get(i);
        final ICompositeNode childNode = NodeModelUtils.getNode(child);
        int _endOffset = childNode.getEndOffset();
        int _offset_2 = context.getOffset();
        boolean _lessEqualsThan = (_endOffset <= _offset_2);
        if (_lessEqualsThan) {
          this.createLocalVariableAndImplicitProposals(child, IExpressionScope.Anchor.AFTER, context, acceptor);
          return;
        }
      }
    }
  }
  this.createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor);
}
 
Example #19
Source File: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void completeBinaryOperation(final EObject model, final Assignment assignment, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  if ((model instanceof XBinaryOperation)) {
    int _length = context.getPrefix().length();
    boolean _tripleEquals = (_length == 0);
    if (_tripleEquals) {
      final INode currentNode = context.getCurrentNode();
      final int offset = currentNode.getOffset();
      final int endOffset = currentNode.getEndOffset();
      if ((((offset < context.getOffset()) && (endOffset >= context.getOffset())) && (currentNode.getGrammarElement() instanceof CrossReference))) {
        return;
      }
    }
    int _endOffset = NodeModelUtils.findActualNodeFor(model).getEndOffset();
    int _offset = context.getOffset();
    boolean _lessEqualsThan = (_endOffset <= _offset);
    if (_lessEqualsThan) {
      AbstractElement _terminal = assignment.getTerminal();
      this.createReceiverProposals(((XExpression) model), ((CrossReference) _terminal), context, acceptor);
    } else {
      AbstractElement _terminal_1 = assignment.getTerminal();
      this.createReceiverProposals(((XBinaryOperation)model).getLeftOperand(), 
        ((CrossReference) _terminal_1), context, acceptor);
    }
  } else {
    final EObject previousModel = context.getPreviousModel();
    if ((previousModel instanceof XExpression)) {
      if (((context.getPrefix().length() == 0) && (NodeModelUtils.getNode(previousModel).getEndOffset() > context.getOffset()))) {
        return;
      }
      AbstractElement _terminal_2 = assignment.getTerminal();
      this.createReceiverProposals(((XExpression)previousModel), 
        ((CrossReference) _terminal_2), context, acceptor);
    }
  }
}
 
Example #20
Source File: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void completeXAssignment(final EObject model, final Assignment assignment, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  final String ruleName = this.getConcreteSyntaxRuleName(assignment);
  boolean _isOperatorRule = this.isOperatorRule(ruleName);
  if (_isOperatorRule) {
    this.completeBinaryOperation(model, assignment, context, acceptor);
  }
}
 
Example #21
Source File: ContentAssistService.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void createProposals(String document, TextRegion selection, int caretOffset, XtextResource resource,
		IIdeContentProposalAcceptor acceptor) {
	if (caretOffset > document.length()) {
		return;
	}
	ContentAssistContextFactory contextFactory = contextFactoryProvider.get();
	contextFactory.setPool(executorService);
	ContentAssistContext[] contexts = contextFactory.create(document, selection, caretOffset, resource);
	proposalProvider.createProposals(Arrays.asList(contexts), acceptor);
}
 
Example #22
Source File: XContentAssistService.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create a single proposal.
 */
protected void createProposals(String document, TextRegion selection, int caretOffset,
		XtextResource resource, IIdeContentProposalAcceptor acceptor) {
	if (caretOffset > document.length()) {
		return;
	}
	ContentAssistContextFactory contextFactory = contextFactoryProvider.get();
	contextFactory.setPool(executorService);
	ContentAssistContext[] contexts = contextFactory.create(document, selection, caretOffset, resource);
	proposalProvider.createProposals(Arrays.asList(contexts), acceptor);
}
 
Example #23
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);
	}
}
 
Example #24
Source File: JSONIdeContentProposalProvider.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void _createProposals(RuleCall ruleCall, ContentAssistContext context,
		IIdeContentProposalAcceptor acceptor) {
	if (grammarAccess.getNameValuePairRule() == ruleCall.getRule()) {
		createNameValueProposals(context, acceptor);
	}
}
 
Example #25
Source File: JSONIdeContentProposalProvider.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void _createProposals(Keyword keyword, ContentAssistContext context,
		IIdeContentProposalAcceptor acceptor) {
	if (keyword.getValue().length() < 4)
		return; // filter out short keywords but still propose true, false, null
	super._createProposals(keyword, context, acceptor);
}
 
Example #26
Source File: N4JSContentAssistService.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void createProposals(String document, TextRegion selection, int caretOffset, XtextResource resource,
		IIdeContentProposalAcceptor acceptor) {
	try (Measurement m = dataCollectors.dcCreateProposals().getMeasurement()) {
		super.createProposals(document, selection, caretOffset, resource, acceptor);
	}
}
 
Example #27
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 #28
Source File: N4JSIdeContentProposalProvider.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void _createProposals(Assignment assignment, ContentAssistContext context,
		IIdeContentProposalAcceptor acceptor) {

	AbstractElement terminal = assignment.getTerminal();
	if (terminal instanceof CrossReference) {
		createProposals(terminal, context, acceptor);
	}
}
 
Example #29
Source File: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void completeJavaTypes(final EReference reference, final ContentAssistContext context, final Predicate<? super ITypeDescriptor> filter, final IIdeContentProposalAcceptor acceptor) {
  this.typesProposalProvider.createTypeProposals(reference, context, filter, acceptor);
}
 
Example #30
Source File: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void completeJavaTypes(final EReference reference, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  this.completeJavaTypes(reference, context, Predicates.<ITypeDescriptor>alwaysTrue(), acceptor);
}