Java Code Examples for org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext#getCurrentModel()
The following examples show how to use
org.eclipse.xtext.ui.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: CrossReferenceProposalTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testBug276742_08b() throws Exception { String modelAsString = "Foo {}"; ContentAssistProcessorTestBuilder builder = newBuilder(); XtextContentAssistProcessor processor = get(XtextContentAssistProcessor.class); XtextResource resource = getResourceFromString(modelAsString); ITextViewer viewer = builder.getSourceViewer(modelAsString, builder.getDocument(resource, modelAsString)); ContentAssistContext[] contexts = processor.getContextFactory() .create(viewer, modelAsString.length(), resource); assertEquals(2, contexts.length); Set<EClass> contextTypes = Sets.newHashSet(CrossReferenceProposalTestPackage.Literals.MODEL, CrossReferenceProposalTestPackage.Literals.CLASS); CrossReferenceProposalTestLanguageGrammarAccess grammarAccess = get(CrossReferenceProposalTestLanguageGrammarAccess.class); for (ContentAssistContext context : contexts) { EObject model = context.getCurrentModel(); assertTrue(contextTypes.remove(model.eClass())); if (context.getFirstSetGrammarElements().contains( grammarAccess.getClassAccess().getRightCurlyBracketKeyword_3())) { assertEquals(CrossReferenceProposalTestPackage.Literals.CLASS, model.eClass()); } else { assertEquals(CrossReferenceProposalTestPackage.Literals.MODEL, model.eClass()); } } }
Example 2
Source File: XbaseProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected void createReceiverProposals(XExpression receiver, CrossReference crossReference, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) { // long time = System.currentTimeMillis(); String ruleName = getConcreteSyntaxRuleName(crossReference); Function<IEObjectDescription, ICompletionProposal> proposalFactory = getProposalFactory(ruleName, contentAssistContext); IResolvedTypes resolvedTypes = typeResolver.resolveTypes(receiver); LightweightTypeReference receiverType = resolvedTypes.getActualType(receiver); if (receiverType == null || receiverType.isPrimitiveVoid()) { return; } IExpressionScope expressionScope = resolvedTypes.getExpressionScope(receiver, IExpressionScope.Anchor.RECEIVER); // TODO exploit the type name information IScope scope; if (contentAssistContext.getCurrentModel() != receiver) { EObject currentModel = contentAssistContext.getCurrentModel(); if (currentModel instanceof XMemberFeatureCall && ((XMemberFeatureCall) currentModel).getMemberCallTarget() == receiver) { scope = filterByConcreteSyntax(expressionScope.getFeatureScope((XAbstractFeatureCall) currentModel), crossReference); } else { scope = filterByConcreteSyntax(expressionScope.getFeatureScope(), crossReference); } } else { scope = filterByConcreteSyntax(expressionScope.getFeatureScope(), crossReference); } getCrossReferenceProposalCreator().lookupCrossReference(scope, receiver, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor, getFeatureDescriptionPredicate(contentAssistContext), proposalFactory); // System.out.printf("XbaseProposalProvider.createReceiverProposals = %d\n", System.currentTimeMillis() - time); }
Example 3
Source File: CurrentModelBugTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public void verify(ContentAssistContext contentAssistContext) { EObject currentModel = contentAssistContext.getCurrentModel(); assertEquals(currentModel.toString(), expectedClass, currentModel.eClass()); if (expectedClassName != null) { assertTrue(contentAssistContext.getCurrentModel() instanceof org.eclipse.xtext.ui.tests.editor.contentassist.domainModelTest.Class); assertEquals(expectedClassName, ((org.eclipse.xtext.ui.tests.editor.contentassist.domainModelTest.Class) contentAssistContext.getCurrentModel()).getName()); } }
Example 4
Source File: JdtTypesProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public void createTypeProposals(ICompletionProposalFactory proposalFactory, ContentAssistContext context, EReference typeReference, Filter filter, IValueConverter<String> valueConverter, ICompletionProposalAcceptor acceptor) { EObject model = context.getCurrentModel(); if (model == null || model.eResource() == null || model.eResource().getResourceSet() == null) return; IJavaProject javaProject = projectProvider.getJavaProject(model.eResource().getResourceSet()); createTypeProposals(javaProject, proposalFactory, context, typeReference, filter, valueConverter, acceptor); }
Example 5
Source File: DotTemplateProposalProvider.java From gef with Eclipse Public License 2.0 | 5 votes |
protected TemplateProposal doCreateProposal(Template template, TemplateContext templateContext, ContentAssistContext context, Image image, int relevance) { EObject currentModel = context.getCurrentModel(); if (isEdgeTemplate(template)) { template = replaceOpVariable(currentModel, template); } if (isHtmlLabelTemplate(template)) { if (currentModel instanceof Attribute) { ID attributeNameID = ((Attribute) currentModel).getName(); if (attributeNameID != null) { String attributeName = attributeNameID.toValue(); switch (attributeName) { case DotAttributes.HEADLABEL__E: case DotAttributes.LABEL__GCNE: case DotAttributes.TAILLABEL__E: case DotAttributes.XLABEL__NE: return super.doCreateProposal(template, templateContext, context, image, relevance); default: return null; } } } else { return null; } } return super.doCreateProposal(template, templateContext, context, image, relevance); }
Example 6
Source File: DotHtmlLabelProposalProvider.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override protected boolean isValidProposal(String proposal, String prefix, ContentAssistContext context) { if (prefix == null) { return false; } // consider a single quote / double quote as a valid prefix for the // attribute values if (context.getCurrentModel() instanceof HtmlAttr && (prefix.startsWith("\"") || prefix.startsWith("'"))) { //$NON-NLS-1$ //$NON-NLS-2$ prefix = prefix.substring(1); if (!context.getMatcher().isCandidateMatchingPrefix(proposal, prefix)) { return false; } else { /** * Skip the proposal validation check through the * conflictHelper, otherwise it will report a conflict. The * conflictHelper cannot differentiate between the different * states of the custom lexer (tagMode is on or off). */ return true; } } return super.isValidProposal(proposal, prefix, context); }
Example 7
Source File: DotArrowTypeProposalProvider.java From gef with Eclipse Public License 2.0 | 4 votes |
@Override protected ICompletionProposal createCompletionProposal(String proposal, StyledString displayString, Image image, int priority, String prefix, ContentAssistContext context) { for (DeprecatedShape deprecatedShape : DeprecatedShape.VALUES) { if (deprecatedShape.toString().equals(proposal)) { // don't propose the deprecated shapes return null; } } // don't propose primitive shapes invalid for the already parsed // modifier(s) if (context.getCurrentModel() instanceof ArrowShape && PrimitiveShape.get(proposal) != null) { ArrowShape arrowShape = (ArrowShape) context.getCurrentModel(); // The open modifier is not allowed for the primitive shapes // 'crow', 'curve', 'icurve', 'none', 'tee' and 'vee', so do not // propose them if the open modifier already has been parsed. if (arrowShape.isOpen()) { switch (PrimitiveShape.get(proposal)) { case CROW: case CURVE: case ICURVE: case NONE: case TEE: case VEE: return null; } } // The side modifier is not allowed for the primitive shapes // 'dot' and 'none', so do not propose them if the side modifier // already has been parsed. if (arrowShape.getSide() != null) { switch (PrimitiveShape.get(proposal)) { case DOT: case NONE: return null; } } } return super.createCompletionProposal(proposal, displayString, image, priority, prefix, context); }