Limiting Proposed Java types to implementers of Interface does not work with Package [message #1739947] |
Fri, 05 August 2016 19:59 |
Sonia Ravindran Messages: 16 Registered: June 2016 |
Junior Member |
|
|
I wanted to limit the proposed Java Types to implementers of a certain interface. Thanks to the Domain Model Xbase example and Karsten's Blog "Limiting Proposed Java types to implementers of Interface" , I was able to combine these 2 examples and make the java types limited to a Interface type without package
Proposal Provider:
public class DomainmodelProposalProvider extends AbstractDomainmodelProposalProvider {
@Inject IJvmTypeProvider.Factory jvmTypeProviderFactory;
@Inject ITypesProposalProvider typeProposalProvider;
@Override
public void completeProperty_Type(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
IJvmTypeProvider jvmTypeProvider = jvmTypeProviderFactory.createTypeProvider(
model.eResource().getResourceSet());
JvmType interfaceToImplement = jvmTypeProvider.findTypeByName(IEntity.class.getName());
typeProposalProvider.createSubTypeProposals(interfaceToImplement, this, context,
DomainmodelPackage.Literals.FEATURE__TYPE, TypeMatchFilters.canInstantiate(), acceptor);
}
}
Proposal with filtered types working properly without packages :
entity Bar extends IEntity {
name : String
}
entity Foo extends IEntity{
bar : Bar //Control + Space Proposal and accept works
op doStuff(String x) : String {
return x + ' ' + bar.getName()
}
}
ISSUE After Adding packages to DSL , the Proposal completion for the type IEntity in line bar:Bar doesn't work properly.
With Package - Proposals are displayed correctly but when we select a proposal I get error Error:org.eclipse.xtext.xbase.ui.contentassist.ImportingTypesProposalProvider$FQNImporter - Could not find unique type named 'com.pkg1.Bar' in scope
package com.pkg1{
entity Bar extends IEntity {
name : String
}
}
package com.pkg1 {
entity Foo extends IEntity{
bar : Bar // Proposal is ok , but selection of proposed option results in error
op doStuff(String x) : String {
return x + ' ' + bar.getName()
}
}
}
Debugging inside XBase Code :
Class : ImportingTypesProposalProvider
public void apply(IDocument document, ConfigurableCompletionProposal proposal) throws BadLocationException {
.......
IEObjectDescription typeToImport = scope.getSingleElement(qualifiedName); //Name resolution does not happen.
|
|
|
|
|
|
|
|
|
Re: Limiting Proposed Java types to implementers of Interface does not work with Package [message #1739964 is a reply to message #1739963] |
Sat, 06 August 2016 06:28 |
|
and did i get it right you want to have split packages in the model? and what is your grammar? it indicates you dont use the domain model 1:1 that would mean having implemented
public class DomainmodelProposalProvider extends AbstractDomainmodelProposalProvider {
@Inject
IJvmTypeProvider.Factory jvmTypeProviderFactory;
@Inject
ITypesProposalProvider typeProposalProvider;
@Override // why not completeJvmParameterizedTypeReference_Type
public void completeProperty_Type(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
IJvmTypeProvider jvmTypeProvider = jvmTypeProviderFactory.createTypeProvider(
model.eResource().getResourceSet());
JvmType interfaceToImplement = jvmTypeProvider.findTypeByName("test.IEntity");
typeProposalProvider.createSubTypeProposals(interfaceToImplement, this, context,
TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, TypeMatchFilters.canInstantiate(), acceptor);
}
@Override
public void completeJvmParameterizedTypeReference_Type(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
// TODO Auto-generated method stub
//super.completeJvmParameterizedTypeReference_Type(model, assignment, context, acceptor);
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.09740 seconds