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);
}
Aggregations