Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Limiting Proposed Java types to implementers of Interface does not work with Package(Limiting Proposed Java types to implementers of Interface does not work with Package)
Limiting Proposed Java types to implementers of Interface does not work with Package [message #1739947] Fri, 05 August 2016 19:59 Go to next message
Sonia Ravindran is currently offline Sonia RavindranFriend
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 #1739948 is a reply to message #1739947] Fri, 05 August 2016 20:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Can you give your current grammar as well and the current adaptions of scope providers

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Limiting Proposed Java types to implementers of Interface does not work with Package [message #1739950 is a reply to message #1739948] Fri, 05 August 2016 20:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
ps if you did remove XImportSection:

@Override
public Class<? extends ITypesProposalProvider> bindITypesProposalProvider() {
return JdtTypesProposalProvider.class;
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Limiting Proposed Java types to implementers of Interface does not work with Package [message #1739954 is a reply to message #1739950] Fri, 05 August 2016 22:19 Go to previous messageGo to next message
Sonia Ravindran is currently offline Sonia RavindranFriend
Messages: 16
Registered: June 2016
Junior Member
Thanks Christian . Overriding JdtTypesProposalProvider works Smile
However I get the complete fully qualified name with the package for the JvmTypeReference ( com.pkg1.Bar instead of Bar)
import org.eclipse.xtext.example.domainmodel.interfaces.IEntity

package com.pkg1 { 

entity Foo extends IEntity{
	bar : com.pkg1.Bar
	op doStuff(String x) : String {
		return x + ' ' + bar.getName()
	}
}
} 


Is there a way, I get only the simple Class Name without the package for my references so that the DSL will look cleaner.
Re: Limiting Proposed Java types to implementers of Interface does not work with Package [message #1739958 is a reply to message #1739954] Sat, 06 August 2016 04:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
How do your imports work ?????

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Limiting Proposed Java types to implementers of Interface does not work with Package [message #1739962 is a reply to message #1739958] Sat, 06 August 2016 06:00 Go to previous messageGo to next message
Sonia Ravindran is currently offline Sonia RavindranFriend
Messages: 16
Registered: June 2016
Junior Member
My imports work using XImportSelection. I still use it to access java libraries from XExpression.

case 1(Using Proposal):
In the above example , the JdtTypesProposalProvider provides the fully qualified type name as com.pkg1.Bar. After selecting the proposal, even if i remove the package part com.pkg1 and just have Bar, it still works the same.
XBase is still able to recognize the type correctly and generates the java files correctly.

case 2 (without implementing proposal):
If i don't use use Type Proposal provider explicitly, all the java reference types are listed. When i select Bar from this very long list. Then i get only Bar with simple class name as type.

Based on the above 2 cases, I wanted to confirm whether I will be able to implement cross reference only with the simple type name. So that i get the cleaner code reference as case 2 and better usability as in case 1 .
Re: Limiting Proposed Java types to implementers of Interface does not work with Package [message #1739963 is a reply to message #1739962] Sat, 06 August 2016 06:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
do you have a import section or dont you?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
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 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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
Re: Limiting Proposed Java types to implementers of Interface does not work with Package [message #1739965 is a reply to message #1739964] Sat, 06 August 2016 06:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
(using ImportingTypesProposalProvider)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Limiting Proposed Java types to implementers of Interface does not work with Package [message #1739971 is a reply to message #1739965] Sat, 06 August 2016 08:15 Go to previous messageGo to next message
Sonia Ravindran is currently offline Sonia RavindranFriend
Messages: 16
Registered: June 2016
Junior Member
Hi Christian,
Yes I use Import section.

ImportingTypesProposalProvider doesn't work . If i Use ImportingTypesProposalProvider, I still get the old error message
org.eclipse.xtext.xbase.ui.contentassist.ImportingTypesProposalProvider$FQNImporter  - Could not find unique type named 'com.pkg1.Bar' in scope



Grammar:
grammar org.eclipse.xtext.example.domainmodel.Domainmodel with org.eclipse.xtext.xbase.Xbase

generate domainmodel "http://www.xtext.org/example/Domainmodel"

DomainModel:
	importSection=XImportSection?
	elements+=AbstractElement*;
	
AbstractElement:
	PackageDeclaration | Entity;

PackageDeclaration:
	'package' name=QualifiedName '{'
		elements+=AbstractElement*
	'}';

Entity:
	'entity' name=ValidID ('extends' superType=JvmParameterizedTypeReference)? '{'
		features+=Feature*
	'}';

Feature:
	Property | Operation;

Property:
	name=ValidID ':' type=JvmTypeReference;

Operation:
	'op' name=ValidID '(' (params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)*)? ')' (':' type=JvmTypeReference)? 
		body=XBlockExpression;



Also Attached the complete sample source here which has the Proposal implementation.
  • Attachment: Sample.zip
    (Size: 1.21MB, Downloaded 85 times)
Re: Limiting Proposed Java types to implementers of Interface does not work with Package [message #1739973 is a reply to message #1739971] Sat, 06 August 2016 10:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Property:
name=ValidID ':' type=JvmTypeReference;

is not a cross ref.
thus your prosalprovider regarding DomainmodelPackage.Literals.FEATURE__TYPE is wromng bcause the actuall cross ref you are creating porposals for is TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE

(see the code i posted)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Limiting Proposed Java types to implementers of Interface does not work with Package [message #1739987 is a reply to message #1739973] Sun, 07 August 2016 02:42 Go to previous message
Sonia Ravindran is currently offline Sonia RavindranFriend
Messages: 16
Registered: June 2016
Junior Member
Thank you so much Christian. Now i got the mistake i was doing . The code you proposed perfectly solved my problems. Sorry I didn't note the "TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE" line carefully last time.
Thanks again for your timely help.
Previous Topic:Referencing an element increase its internal indentation
Next Topic:Loading Xtext based model from Eclipse EASE
Goto Forum:
  


Current Time: Fri Apr 26 02:37:03 GMT 2024

Powered by FUDForum. Page generated in 0.04585 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top