org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry Java Examples
The following examples show how to use
org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry.
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: XbaseIdeContentProposalPriorities.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public int getCrossRefPriority(IEObjectDescription objectDesc, ContentAssistEntry entry) { if (entry != null) { if (objectDesc instanceof SimpleIdentifiableElementDescription) { if (!"this".equals(entry.getProposal()) && !"super".equals(entry.getProposal())) { return adjustPriority(entry, getCrossRefPriority() + 70); } } else if (objectDesc instanceof StaticFeatureDescriptionWithTypeLiteralReceiver) { return adjustPriority(entry, getCrossRefPriority() + 60); } else if (objectDesc instanceof IIdentifiableElementDescription) { JvmIdentifiableElement element = ((IIdentifiableElementDescription) objectDesc).getElementOrProxy(); if (element instanceof JvmField) { return adjustPriority(entry, getCrossRefPriority() + 50); } else if (element instanceof JvmExecutable) { return adjustPriority(entry, getCrossRefPriority() + 20); } } } return super.getCrossRefPriority(objectDesc, entry); }
Example #2
Source File: ImportsAwareReferenceProposalCreator.java From n4js with Eclipse Public License 1.0 | 6 votes |
private ContentAssistEntry convertResolutionToContentAssistEntry(ReferenceResolution resolution, N4JSResource resource, ContentAssistContext context) { ContentAssistEntry cae = new ContentAssistEntry(); cae.setPrefix(context.getPrefix()); cae.setProposal(resolution.proposal); cae.setLabel(resolution.label); cae.setDescription(resolution.description); if (resolution.importToBeAdded != null) { ReplaceRegion textReplacement = importHelper.getReplacementForImport(resource.getScript(), resolution.importToBeAdded); cae.getTextReplacements().add(textReplacement); } cae.setSource(resolution.referencedElement); cae.setKind(getKind(resolution)); return cae; }
Example #3
Source File: ClasspathBasedIdeTypesProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected ContentAssistEntry createProposal(EReference reference, ITypeDescriptor typeDesc, ContentAssistContext context, XImportSection importSection, ITextRegion importSectionRegion) { boolean importDecl = isImportDeclaration(reference, context); String qualifiedName = qualifiedNameConverter.toString(typeDesc.getQualifiedName()); String proposal; if (importDecl) { proposal = qualifiedName; } else { proposal = typeDesc.getSimpleName(); } return proposalCreator.createProposal(proposal, context, (ContentAssistEntry it) -> { it.setKind(ContentAssistEntry.KIND_REFERENCE); if (importDecl) { it.setLabel(typeDesc.getSimpleName()); it.setDescription(proposal); } else { it.setDescription(qualifiedName); if (importSectionRegion != null && isImportDeclarationRequired(typeDesc, qualifiedName, context, importSection)) { addImportDeclaration(it, importSectionRegion, typeDesc, qualifiedName, context); } } }); }
Example #4
Source File: JSONIdeContentProposalProvider.java From n4js with Eclipse Public License 1.0 | 6 votes |
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 #5
Source File: JSONIdeContentProposalProvider.java From n4js with Eclipse Public License 1.0 | 6 votes |
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 #6
Source File: JSONIdeContentProposalProvider.java From n4js with Eclipse Public License 1.0 | 6 votes |
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 #7
Source File: ClasspathBasedIdeTypesProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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 #8
Source File: JSONIdeContentProposalProvider.java From n4js with Eclipse Public License 1.0 | 6 votes |
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 #9
Source File: XIdeContentProposalAcceptor.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override public void accept(ContentAssistEntry entry, int priority) { if (entry != null) { if (entry.getProposal() == null) { throw new IllegalArgumentException("proposal must not be null."); } String entryString = entry.toString(); if (entries.containsKey(entryString)) { Pair<Integer, ContentAssistEntry> existingProposal = entries.get(entryString); priority = existingProposal.getKey(); } entries.put(entryString, Pair.of(priority, entry)); } }
Example #10
Source File: HoverService.java From xtext-web with Eclipse Public License 2.0 | 5 votes |
/** * 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 #11
Source File: XbaseIdeCrossrefProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void addNameAndDescription(ContentAssistEntry entry, EObject element, String qualifiedNameAsString, String shortName) { QualifiedName qualifiedName = getQualifiedNameConverter().toQualifiedName(qualifiedNameAsString); if (qualifiedName.getSegmentCount() > 1) { entry.setLabel(qualifiedName.getLastSegment()); entry.setDescription(qualifiedNameAsString); } else { entry.setLabel(qualifiedNameAsString); } }
Example #12
Source File: UiToIdeContentProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@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 #13
Source File: UiToIdeContentProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected StyledString getDisplayString(ContentAssistEntry entry) { StyledString result = new StyledString(entry.getLabel() != null ? entry.getLabel() : entry.getProposal()); if (!Strings.isNullOrEmpty(entry.getDescription())) { result.append(new StyledString(" \u2013 " + entry.getDescription(), StyledString.QUALIFIER_STYLER)); } return result; }
Example #14
Source File: UiToIdeContentProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected Image getImage(ContentAssistEntry entry) { Object source = entry.getSource(); if (source instanceof IEObjectDescription) { return getImage((IEObjectDescription) source); } else if (source instanceof EObject) { return getImage((EObject) source); } return null; }
Example #15
Source File: CustomContentAssistService.java From solidity-ide with Eclipse Public License 1.0 | 5 votes |
@Override protected CompletionItem toCompletionItem(ContentAssistEntry entry, int caretOffset, Position caretPosition, Document document) { CompletionItem completionItem = super.toCompletionItem(entry, caretOffset, caretPosition, document); Either<String, MarkupContent> documentation = completionItem.getDocumentation(); if (documentation != null && documentation.getLeft() == null && documentation.getRight()==null) { completionItem.setDocumentation((Either<String,MarkupContent>)null); } return completionItem; }
Example #16
Source File: JSONIdeContentProposalProvider.java From n4js with Eclipse Public License 1.0 | 5 votes |
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 #17
Source File: PatchedContentAssistService.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override protected CompletionItem toCompletionItem(ContentAssistEntry entry, int caretOffset, Position caretPosition, Document document) { CompletionItem result = super.toCompletionItem(entry, caretOffset, caretPosition, document); if (entry.getKind().startsWith(ContentAssistEntry.KIND_SNIPPET + ":")) { result.setInsertTextFormat(InsertTextFormat.Snippet); entry.setKind(entry.getKind().substring(ContentAssistEntry.KIND_SNIPPET.length() + 1)); } else if (Objects.equal(entry.getKind(), ContentAssistEntry.KIND_SNIPPET)) { result.setInsertTextFormat(InsertTextFormat.Snippet); } result.setKind(translateKind(entry)); return result; }
Example #18
Source File: ImportsAwareReferenceProposalCreator.java From n4js with Eclipse Public License 1.0 | 5 votes |
private static String getKind(ReferenceResolution resolution) { EClass eClass = resolution.referencedElement.getEClass(); if (TypesPackage.eINSTANCE.getTClass() == eClass) { return ContentAssistEntry.KIND_CLASS; } if (TypesPackage.eINSTANCE.getTInterface() == eClass) { return ContentAssistEntry.KIND_INTERFACE; } if (TypesPackage.eINSTANCE.getTField() == eClass) { return ContentAssistEntry.KIND_FIELD; } if (TypesPackage.eINSTANCE.getTEnum() == eClass) { return ContentAssistEntry.KIND_ENUM; } if (TypesPackage.eINSTANCE.getTFunction() == eClass) { return ContentAssistEntry.KIND_FUNCTION; } if (TypesPackage.eINSTANCE.getTVariable() == eClass) { return ContentAssistEntry.KIND_VARIABLE; } if (N4JSPackage.eINSTANCE.getVariableDeclaration() == eClass) { return ContentAssistEntry.KIND_VARIABLE; } if (TypesPackage.eINSTANCE.getModuleNamespaceVirtualType() == eClass) { return ContentAssistEntry.KIND_COLOR; } return ContentAssistEntry.KIND_TEXT; }
Example #19
Source File: TestLanguageProposalCreator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public ContentAssistEntry createProposal(String proposal, String prefix, ContentAssistContext context, String kind, Procedure1<? super ContentAssistEntry> init) { ContentAssistEntry entry = super.createProposal(proposal, prefix, context, kind, init); if (entry != null && kind == ContentAssistEntry.KIND_KEYWORD && "{".equals(proposal)) { // just for testing purposes entry.getTextReplacements().add(new ReplaceRegion(context.getOffset() + 1, 0, "}")); } return entry; }
Example #20
Source File: ContentAssistService.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public CompletionList createCompletionList(Document document, XtextResource resource, CompletionParams params, CancelIndicator cancelIndicator) { try { CompletionList result = new CompletionList(); result.setIsIncomplete(true); IdeContentProposalAcceptor acceptor = proposalAcceptorProvider.get(); int caretOffset = document.getOffSet(params.getPosition()); Position caretPosition = params.getPosition(); TextRegion position = new TextRegion(caretOffset, 0); try { createProposals(document.getContents(), position, caretOffset, resource, acceptor); } catch (Throwable t) { if (!operationCanceledManager.isOperationCanceledException(t)) { throw t; } } int idx = 0; for (ContentAssistEntry it : acceptor.getEntries()) { CompletionItem item = toCompletionItem(it, caretOffset, caretPosition, document); item.setSortText(Strings.padStart(Integer.toString(idx), 5, '0')); result.getItems().add(item); idx++; } return result; } catch (Throwable e) { throw Exceptions.sneakyThrow(e); } }
Example #21
Source File: ContentAssistService.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected CompletionItem toCompletionItem(ContentAssistEntry entry, int caretOffset, Position caretPosition, Document document) { CompletionItem completionItem = new CompletionItem(); String label = entry.getLabel(); if (label == null) { label = entry.getProposal(); } completionItem.setLabel(label); completionItem.setDetail(entry.getDescription()); completionItem.setDocumentation(entry.getDocumentation()); String prefix = entry.getPrefix(); if (prefix == null) { prefix = ""; } int prefixOffset = caretOffset - prefix.length(); Position prefixPosition = document.getPosition(prefixOffset); completionItem.setTextEdit(new TextEdit(new Range(prefixPosition, caretPosition), entry.getProposal())); completionItem.setKind(translateKind(entry)); if (!entry.getTextReplacements().isEmpty()) { if (completionItem.getAdditionalTextEdits() == null) { completionItem.setAdditionalTextEdits(new ArrayList<>(entry.getTextReplacements().size())); } entry.getTextReplacements().forEach( (ReplaceRegion it) -> completionItem.getAdditionalTextEdits().add(toTextEdit(it, document))); } if (ContentAssistEntry.KIND_SNIPPET.equals(entry.getKind())) { completionItem.setInsertTextFormat(InsertTextFormat.Snippet); } return completionItem; }
Example #22
Source File: XContentAssistService.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Convert to a completion item. */ protected CompletionItem toCompletionItem(ContentAssistEntry entry, int caretOffset, Position caretPosition, Document document) { CompletionItem result = new CompletionItem(); String label = null; if (entry.getLabel() != null) { label = entry.getLabel(); } else { label = entry.getProposal(); } result.setLabel(label); result.setDetail(entry.getDescription()); result.setDocumentation(entry.getDocumentation()); String prefix = null; if (entry.getPrefix() != null) { prefix = entry.getPrefix(); } else { prefix = ""; } Position prefixPosition = document.getPosition(caretOffset - prefix.length()); result.setTextEdit(new TextEdit(new Range(prefixPosition, caretPosition), entry.getProposal())); if (!entry.getTextReplacements().isEmpty()) { if (result.getAdditionalTextEdits() == null) { result.setAdditionalTextEdits(new ArrayList<>(entry.getTextReplacements().size())); } entry.getTextReplacements().forEach(it -> { result.getAdditionalTextEdits().add(toTextEdit(it, document)); }); } if (entry.getKind().startsWith(ContentAssistEntry.KIND_SNIPPET + ":")) { result.setInsertTextFormat(InsertTextFormat.Snippet); entry.setKind(entry.getKind().substring(ContentAssistEntry.KIND_SNIPPET.length() + 1)); } else if (Objects.equal(entry.getKind(), ContentAssistEntry.KIND_SNIPPET)) { result.setInsertTextFormat(InsertTextFormat.Snippet); } result.setKind(translateKind(entry)); return result; }
Example #23
Source File: ContentAssistService.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected CompletionItemKind translateKind(ContentAssistEntry entry) { if (entry.getKind() != null) { switch (entry.getKind()) { case ContentAssistEntry.KIND_CLASS: return CompletionItemKind.Class; case ContentAssistEntry.KIND_COLOR: return CompletionItemKind.Color; case ContentAssistEntry.KIND_CONSTRUCTOR: return CompletionItemKind.Constructor; case ContentAssistEntry.KIND_ENUM: return CompletionItemKind.Enum; case ContentAssistEntry.KIND_FIELD: return CompletionItemKind.Field; case ContentAssistEntry.KIND_FILE: return CompletionItemKind.File; case ContentAssistEntry.KIND_FUNCTION: return CompletionItemKind.Function; case ContentAssistEntry.KIND_INTERFACE: return CompletionItemKind.Interface; case ContentAssistEntry.KIND_KEYWORD: return CompletionItemKind.Keyword; case ContentAssistEntry.KIND_METHOD: return CompletionItemKind.Method; case ContentAssistEntry.KIND_MODULE: return CompletionItemKind.Module; case ContentAssistEntry.KIND_PROPERTY: return CompletionItemKind.Property; case ContentAssistEntry.KIND_REFERENCE: return CompletionItemKind.Reference; case ContentAssistEntry.KIND_SNIPPET: return CompletionItemKind.Snippet; case ContentAssistEntry.KIND_TEXT: return CompletionItemKind.Text; case ContentAssistEntry.KIND_UNIT: return CompletionItemKind.Unit; case ContentAssistEntry.KIND_VALUE: return CompletionItemKind.Value; case ContentAssistEntry.KIND_VARIABLE: return CompletionItemKind.Variable; default: return CompletionItemKind.Value; } } else { return CompletionItemKind.Value; } }
Example #24
Source File: ContentAssistResult.java From xtext-web with Eclipse Public License 2.0 | 4 votes |
public List<ContentAssistEntry> getEntries() { return entries; }
Example #25
Source File: ContentAssistService.java From xtext-web with Eclipse Public License 2.0 | 4 votes |
/** * Invoke the proposal provider and put the results into a * {@link ContentAssistResult} object. */ protected ContentAssistResult createProposals(List<ContentAssistContext> contexts, String stateId, int proposalsLimit) { ContentAssistResult result = new ContentAssistResult(stateId); if (!contexts.isEmpty()) { Set<Pair<Integer, ContentAssistEntry>> proposals = new HashSet<Pair<Integer, ContentAssistEntry>>(); IIdeContentProposalAcceptor acceptor = new IIdeContentProposalAcceptor() { @Override public void accept(ContentAssistEntry entry, int priority) { if (entry != null) { if (entry.getProposal() == null) { throw new IllegalArgumentException("proposal must not be null."); } proposals.add(Pair.of(priority, entry)); } } @Override public boolean canAcceptMoreProposals() { return proposals.size() < proposalsLimit; } }; proposalProvider.createProposals(contexts, acceptor); List<Pair<Integer, ContentAssistEntry>> sorted = IterableExtensions.sortWith(proposals, (Pair<Integer, ContentAssistEntry> p1, Pair<Integer, ContentAssistEntry> p2) -> { int prioResult = p2.getKey().compareTo(p1.getKey()); if (prioResult != 0) { return prioResult; } String s1 = p1.getValue().getLabel(); if (s1 == null) { s1 = p1.getValue().getProposal(); } String s2 = p2.getValue().getLabel(); if (s2 == null) { s2 = p2.getValue().getProposal(); } return s1.compareTo(s2); }); result.getEntries() .addAll(Lists.transform(sorted, (Pair<Integer, ContentAssistEntry> it) -> it.getValue())); } return result; }
Example #26
Source File: XbaseIdeContentProposalPriorities.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
public int getTypeRefPriority(ITypeDescriptor typeDesc, ContentAssistEntry entry) { return adjustPriority(entry, getCrossRefPriority()); }
Example #27
Source File: XbaseIdeCrossrefProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected void addNameAndDescription(ContentAssistEntry entry, JvmFeature feature, boolean withParents, int insignificantParameters, String shortName, LightweightTypeReferenceFactory converter) { StringBuilder labelBuilder = new StringBuilder(shortName); StringBuilder descriptionBuilder = new StringBuilder(); if (feature instanceof JvmOperation) { if (withParents) { labelBuilder.append("("); appendParameters(labelBuilder, (JvmExecutable) feature, insignificantParameters, converter); labelBuilder.append(")"); } JvmOperation jvmOperation = (JvmOperation) feature; JvmTypeReference returnType = jvmOperation.getReturnType(); if (returnType != null && returnType.getSimpleName() != null) { labelBuilder.append(" : "); labelBuilder.append(converter.toLightweightReference(returnType).getHumanReadableName()); } descriptionBuilder.append( converter.toPlainTypeReference(jvmOperation.getDeclaringType()).getHumanReadableName()); if (!withParents) { descriptionBuilder.append("."); descriptionBuilder.append(jvmOperation.getSimpleName()); descriptionBuilder.append("()"); } } else { if (feature instanceof JvmField) { labelBuilder.append(" : "); JvmField jvmField = (JvmField) feature; if (jvmField.getType() != null) { String fieldType = converter.toLightweightReference(jvmField.getType()) .getHumanReadableName(); if (fieldType != null) { labelBuilder.append(fieldType); } } descriptionBuilder.append( converter.toPlainTypeReference(jvmField.getDeclaringType()).getHumanReadableName()); } else if (feature instanceof JvmConstructor) { if (withParents) { labelBuilder.append("("); appendParameters(labelBuilder, ((JvmExecutable) feature), insignificantParameters, converter); labelBuilder.append(")"); } } } entry.setLabel(labelBuilder.toString()); entry.setDescription(descriptionBuilder.toString()); }
Example #28
Source File: XbaseIdeCrossrefProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override public ContentAssistEntry createProposal(IEObjectDescription candidate, CrossReference crossRef, ContentAssistContext context) { if (hasIdRule(crossRef)) { ProposalBracketInfo bracketInfo = getProposalBracketInfo(candidate, context); String proposalString = getQualifiedNameConverter().toString(candidate.getName()) + bracketInfo.brackets; final int insignificantParameters; if (candidate instanceof IIdentifiableElementDescription) { insignificantParameters = ((IIdentifiableElementDescription) candidate) .getNumberOfIrrelevantParameters(); } else { insignificantParameters = 0; } LightweightTypeReferenceFactory converter = getTypeConverter(context.getResource()); EObject objectOrProxy = candidate.getEObjectOrProxy(); return getProposalCreator().createProposal(proposalString, context, (ContentAssistEntry result) -> { result.setKind(ContentAssistEntry.KIND_REFERENCE); if (objectOrProxy instanceof JvmFeature) { if (bracketInfo.brackets.startsWith(" =")) { addNameAndDescription(result, (JvmFeature) objectOrProxy, false, insignificantParameters, getQualifiedNameConverter().toString(candidate.getName()) + bracketInfo.brackets, converter); } else { addNameAndDescription(result, (JvmFeature) objectOrProxy, !Strings.isNullOrEmpty(bracketInfo.brackets), insignificantParameters, getQualifiedNameConverter().toString(candidate.getName()), converter); } } else { addNameAndDescription(result, objectOrProxy, getQualifiedNameConverter().toString(candidate.getQualifiedName()), getQualifiedNameConverter().toString(candidate.getName())); } int offset = context.getOffset() - context.getPrefix().length() + proposalString.length(); result.setEscapePosition(offset + bracketInfo.caretOffset); if (bracketInfo.selectionOffset != 0) { offset = offset + bracketInfo.selectionOffset; result.getEditPositions().add(new TextRegion(offset, bracketInfo.selectionLength)); } if (objectOrProxy instanceof JvmExecutable) { StringBuilder parameterList = new StringBuilder(); appendParameters(parameterList, (JvmExecutable) objectOrProxy, insignificantParameters, converter); } }); } return super.createProposal(candidate, crossRef, context); }
Example #29
Source File: ClasspathBasedIdeTypesProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected boolean addImportDeclaration(ContentAssistEntry entry, ITextRegion importSectionRegion, ITypeDescriptor typeDesc, String qualifiedName, ContentAssistContext context) { int insertionOffset = importSectionRegion.getOffset() + importSectionRegion.getLength(); String declaration = "\nimport " + qualifiedName; return entry.getTextReplacements().add(new ReplaceRegion(insertionOffset, 0, declaration)); }
Example #30
Source File: ImportsAwareReferenceProposalCreator.java From n4js with Eclipse Public License 1.0 | 4 votes |
@Override public void accept(ReferenceResolution resolution) { ContentAssistEntry entry = convertResolutionToContentAssistEntry(resolution, resource, context); int priority = proposalPriorities.getCrossRefPriority(resolution.referencedElement, entry); contentProposalAcceptor.accept(entry, priority); }