Search in sources :

Example 1 with Model

use of org.eclipse.xtext.ui.tests.editor.contentassist.crossReferenceProposalTest.Model in project xtext-eclipse by eclipse.

the class CrossReferenceProposalTestLanguageSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == CrossReferenceProposalTestPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case CrossReferenceProposalTestPackage.CLASS:
                sequence_Class(context, (org.eclipse.xtext.ui.tests.editor.contentassist.crossReferenceProposalTest.Class) semanticObject);
                return;
            case CrossReferenceProposalTestPackage.MODEL:
                sequence_Model(context, (Model) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Model(org.eclipse.xtext.ui.tests.editor.contentassist.crossReferenceProposalTest.Model) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Example 2 with Model

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

Model (org.eclipse.xtext.ui.tests.editor.contentassist.crossReferenceProposalTest.Model)2 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 EPackage (org.eclipse.emf.ecore.EPackage)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 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)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