Reduce available JvmTypes [message #1759730] |
Mon, 17 April 2017 14:54  |
Eclipse User |
|
|
|
Hello everyone,
i am currently writing a beginner friendly OO-Language based on Xbase.
I decided to use Xbase for this purpose, hence most of my DSL concepts can easily be mapped to Java and it ships with a lot of nice features (like debugging).
My problem is, that Xbase provides too many types (e.g. StringBuilder etc...), which can be quiet overwhelming for beginners.
I only want to provide some primitive types (like int, String, boolean and double) and some datastructures like arrays and lists (and user-defined classes of course).
I tried to override the different Xbase grammarrules to achieve this, e.g:
JvmParameterizedTypeReference:
type=[JvmPrimitiveType] ;
But with no luck. : /
So my question is: How can i reduce the amount of available JvmTypes?
Where should i start / what is the best approach for that?
Thanks in advance and kind regards,
Marco
|
|
|
|
|
|
|
|
Re: Reduce available JvmTypes [message #1759911 is a reply to message #1759730] |
Wed, 19 April 2017 16:12   |
Eclipse User |
|
|
|
Thank you both for your support, now I am back on track. 
I decided to extend and customize the JdtTypeProvider, hence it should only provide some types.
Now I have one question left:
The scope provider now uses my implementation of the type provider but all types are still proposed.
I thought the proposals were build depending on the content of of the scope, aren't they?
As a workaround, i could customize the proposals as mentioned in Karstens blog, but I wonder why it still proposes all types....
Here my solution so far ,just in case someone else has the same problem / requirement:
In the UI-Plugin add a factory...
@Singleton
class MyFilteredJdtTypeProviderFactory extends JdtTypeProviderFactory {
@Inject
IWorkingCopyOwnerProvider copyOwnerProvider;
@Inject
TypeResourceServices typeResourceServices;
override protected IJdtTypeProvider createJdtTypeProvider(IJavaProject javaProject, ResourceSet resourceSet) {
if (javaProject == null){
return new NullJdtTypeProvider(resourceSet)
}
var WorkingCopyOwner wco= null
if(copyOwnerProvider==null)
wco = DefaultWorkingCopyOwner.PRIMARY
else
wco = copyOwnerProvider.getWorkingCopyOwner(javaProject, resourceSet)
return new MyFilteredJdtTypeProvider(javaProject, resourceSet, getIndexedJvmTypeAccess(), wco, typeResourceServices);
}
}
...and the provider...
class MyFilteredJdtTypeProvider extends JdtTypeProvider {
public new(IJavaProject javaProject, ResourceSet resourceSet, IndexedJvmTypeAccess indexedJvmTypeAccess, WorkingCopyOwner workingCopyOwner, TypeResourceServices services) {
super(javaProject, resourceSet, indexedJvmTypeAccess, workingCopyOwner, services)
}
private val HashSet<String> supportedJdtTypes ={
val hs = new HashSet()
hs.add("int")
hs.add("double")
hs.add("boolean")
hs.add("java.lang.String")
// Required by the compiler to process method bodys right
hs.add("void")
// Required, otherwise operators do not work
hs.add("org.eclipse.xtext.xbase.lib.StringExtensions")
hs.add("org.eclipse.xtext.xbase.lib.IntegerExtensions")
hs.add("org.eclipse.xtext.xbase.lib.DoubleExtensions")
hs.add("org.eclipse.xtext.xbase.lib.BooleanExtensions")
return hs
}
public override JvmType findTypeByName(String name) {
if(name.isTypeSupported){
return doFindTypeByName(name, false)
}else{
return null
}
}
public override JvmType findTypeByName(String name, boolean binaryNestedTypeDelimiter) {
if(name.isTypeSupported){
return super.findTypeByName(name,binaryNestedTypeDelimiter)
}else{
return null
}
}
def isTypeSupported(String name){
supportedJdtTypes.contains(name)
}
}
... and tell the framework (in UiModule.xtend) to use our factory instead of its default impl:
override Class<? extends IJvmTypeProvider.Factory> bindIJvmTypeProvider$Factory() {
return MyFilteredJdtTypeProviderFactory;
}
[Updated on: Thu, 20 April 2017 14:38] by Moderator
|
|
|
|
Re: Reduce available JvmTypes [message #1759948 is a reply to message #1759730] |
Thu, 20 April 2017 06:01  |
Eclipse User |
|
|
|
Okay, I See, thanks again. 
In case someone should be interested, this is my approach (iam filtering the types of the ITypesProposalProvider / JdtTypesProposalProvider):
class MyDslProposalProvider extends AbstractExpressionsProposalProvider {
override protected completeJavaTypes(ContentAssistContext context, EReference reference, boolean forced,IValueConverter<String> valueConverter, ITypesProposalProvider.Filter filter,ICompletionProposalAcceptor acceptor) {
val extendedFilter = TypeMatchFilters.and(filter,new SupportedTypesFilter())
super.completeJavaTypes(context, reference, forced, valueConverter, extendedFilter, acceptor)
}
private static class SupportedTypesFilter extends AbstractFilter {
override boolean accept(int modifiers, char[] packageName, char[] simpleTypeName,char[][] enclosingTypeNames, String path) {
// Add further predicates to filter for java types here
packageName.join.equals("java.lang")&& simpleTypeName.join.equals("String")
}
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.07697 seconds