Search in sources :

Example 6 with PrefixMatcher

use of org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher in project xtext-eclipse by eclipse.

the class CrossReferenceProposalTest method testBug356185.

@Test
public void testBug356185() throws Exception {
    final String content = "Foo {}";
    XtextResourceSet rs = new XtextResourceSet() {

        @Override
        protected void demandLoad(Resource resource) throws IOException {
            resource.load(new StringInputStream(content), null);
        }
    };
    rs.setClasspathURIContext(getClass());
    XtextResource resource1 = (XtextResource) rs.createResource(URI.createURI("test1." + getCurrentFileExtension()));
    resource1.load(new StringInputStream(content), null);
    Model model = (Model) resource1.getContents().get(0);
    URI classToShowURI = EcoreUtil.getURI(model.getElements().get(0));
    resource1.unload();
    ClassImpl classToShow = (ClassImpl) CrossReferenceProposalTestFactory.eINSTANCE.createClass();
    classToShow.eSetProxyURI(classToShowURI);
    ResourceSet resourceSet = resource1.getResourceSet();
    XtextResource resource2 = (XtextResource) resourceSet.createResource(URI.createURI("test." + getCurrentFileExtension()));
    resource2.load(new StringInputStream("Foo <- Bar {}"), null);
    ContentAssistContext.Builder builder = get(ContentAssistContext.Builder.class);
    builder.setResource(resource2);
    builder.setReplaceRegion(new Region(0, 0));
    model = (Model) resource2.getContents().get(0);
    Class contextClass = model.getElements().get(0);
    ICompositeNode node = NodeModelUtils.getNode(contextClass);
    builder.setCurrentNode(node);
    builder.setMatcher(new PrefixMatcher() {

        @Override
        public boolean isCandidateMatchingPrefix(String name, String prefix) {
            return true;
        }
    });
    ContentAssistContext context = builder.toContext();
    ContentProposalProvider proposalProvider = get(ContentProposalProvider.class);
    proposalProvider.setConflictHelper(new IProposalConflictHelper() {

        @Override
        public boolean existsConflict(String proposal, ContentAssistContext context) {
            return false;
        }
    });
    Function<IEObjectDescription, ICompletionProposal> proposalFactory = proposalProvider.getProposalFactory(context);
    ConfigurableCompletionProposal proposal = (ConfigurableCompletionProposal) proposalFactory.apply(new EObjectDescription(QualifiedName.create("Foo"), classToShow, null));
    assertTrue(classToShow.eIsProxy());
    Object additionalProposalInfo = proposal.getAdditionalProposalInfo(new NullProgressMonitor());
    assertNotNull(additionalProposalInfo);
}
Also used : EObjectDescription(org.eclipse.xtext.resource.EObjectDescription) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) ClassImpl(org.eclipse.xtext.ui.tests.editor.contentassist.crossReferenceProposalTest.impl.ClassImpl) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) XtextResource(org.eclipse.xtext.resource.XtextResource) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IProposalConflictHelper(org.eclipse.xtext.ui.editor.contentassist.IProposalConflictHelper) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) PrefixMatcher(org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) StringInputStream(org.eclipse.xtext.util.StringInputStream) ContentAssistContext(org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext) Model(org.eclipse.xtext.ui.tests.editor.contentassist.crossReferenceProposalTest.Model) Region(org.eclipse.jface.text.Region) EClass(org.eclipse.emf.ecore.EClass) Class(org.eclipse.xtext.ui.tests.editor.contentassist.crossReferenceProposalTest.Class) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test)

Aggregations

PrefixMatcher (org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher)6 ConfigurableCompletionProposal (org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal)5 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)4 StyledString (org.eclipse.jface.viewers.StyledString)4 ContentAssistContext (org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 Builder (org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext.Builder)2 CharMatcher (com.google.common.base.CharMatcher)1 Matcher (java.util.regex.Matcher)1 URI (org.eclipse.emf.common.util.URI)1 EClass (org.eclipse.emf.ecore.EClass)1 EObject (org.eclipse.emf.ecore.EObject)1 EPackage (org.eclipse.emf.ecore.EPackage)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 AccessRestriction (org.eclipse.jdt.internal.compiler.env.AccessRestriction)1 BasicSearchEngine (org.eclipse.jdt.internal.core.search.BasicSearchEngine)1