Search in sources :

Example 1 with IProposalConflictHelper

use of org.eclipse.xtext.ui.editor.contentassist.IProposalConflictHelper 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

NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 URI (org.eclipse.emf.common.util.URI)1 EClass (org.eclipse.emf.ecore.EClass)1 EObject (org.eclipse.emf.ecore.EObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 Region (org.eclipse.jface.text.Region)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)1 EObjectDescription (org.eclipse.xtext.resource.EObjectDescription)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)1 ConfigurableCompletionProposal (org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal)1 ContentAssistContext (org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext)1 IProposalConflictHelper (org.eclipse.xtext.ui.editor.contentassist.IProposalConflictHelper)1 PrefixMatcher (org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher)1 Class (org.eclipse.xtext.ui.tests.editor.contentassist.crossReferenceProposalTest.Class)1 Model (org.eclipse.xtext.ui.tests.editor.contentassist.crossReferenceProposalTest.Model)1 ClassImpl (org.eclipse.xtext.ui.tests.editor.contentassist.crossReferenceProposalTest.impl.ClassImpl)1