Home » Modeling » TMF (Xtext) » Reduce available JvmTypes
| | | | | |
Re: Reduce available JvmTypes [message #1759911 is a reply to message #1759730] |
Wed, 19 April 2017 20:12 |
Marco Ullrich Messages: 14 Registered: December 2016 Location: Bayreuth |
Junior Member |
|
|
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 18:38] Report message to a moderator
|
|
| |
Re: Reduce available JvmTypes [message #1759948 is a reply to message #1759730] |
Thu, 20 April 2017 10:01 |
Marco Ullrich Messages: 14 Registered: December 2016 Location: Bayreuth |
Junior Member |
|
|
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")
}
}
}
|
|
|
Goto Forum:
Current Time: Thu Nov 07 03:38:22 GMT 2024
Powered by FUDForum. Page generated in 0.05088 seconds
|