Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Interfaces and classes / types are proposed where only interfaces should be proposed
Interfaces and classes / types are proposed where only interfaces should be proposed [message #1764813] Fri, 02 June 2017 11:47 Go to next message
Marco Ullrich is currently offline Marco UllrichFriend
Messages: 14
Registered: December 2016
Location: Bayreuth
Junior Member
Hello everyone,

i have a problem with the proposal provider proposing too much.
I have the following grammar:

Program:	SubPrograms+=NamedElement*;
NamedElement:	Type |  Interface;
Type:	'type' name=ID;
Interface:'interface' name=ID ('offers' interfaces=JvmTypeReference)?;

The semantic is, that interfaces could only offer other interfaces (like in java a interface can only extend other interfaces).
Hence the proposal provider should only provide interfaces for the feature 'interfaces'

This is my inferrer.
Types are generated as nested static classes, interfaces are also nested in the main class:
def dispatch void infer(Program program, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {								
	acceptor.accept(program.toClass("Main"))[
		packageName = "main" 
		program.subPrograms.forEach[ namedElement |
								
			if(namedElement instanceof Interface){
				members+= namedElement.toInterface(namedElement.name,[
								interface = true
								if(namedElement.interfaces!= null){
									superTypes += namedElement.interfaces.cloneWithProxies																		
								}
							])
			}						
			
			// Types are nested static classes						
			if(namedElement instanceof Type){
				members+=namedElement.toClass(namedElement.name,[		
					static = true
				])			
			}					
		]
	]	  
}										


To achieve the desired proposal behaviour, i customized the ProposalProvider:
class MyDsl2ProposalProvider extends AbstractMyDsl2ProposalProvider {	
	override completeInterface_Interfaces(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		val filter = createVisibilityFilter(context, IJavaSearchConstants.INTERFACE)		
		completeJavaTypes(context, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, filter, acceptor)
	}
}


The proposalprovider now proposes all jvm-interfaces and every interface AND type that is defined by the user.
E.g. in the following program:
type myType

interface i1 

interface i2 offers Main$<ctrl+space>


<ctrl+space> displays the proposals:
Main.i1
Main.i2,
Main.myType

i1 and i2 are ok, because they are interfaces but i dont want myType to be displayed, because it is a typ (aka. a class).

Am i doing something wrong in my proposal provider?
I thought filtering for IJavaSearchConstants.INTERFACE would reduce the searchscope to interfaces?

Tanks in advance for your help! (:

Marco
Re: Interfaces and classes / types are proposed where only interfaces should be proposed [message #1764818 is a reply to message #1764813] Fri, 02 June 2017 12:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
hmmm

this is cause the tyes come from

if (acceptor.canAcceptMoreProposals()) {
Iterable<IEObjectDescription> allDirtyTypes = dirtyStateManager.getExportedObjectsByType(TypesPackage.Literals.JVM_TYPE);
for(IEObjectDescription description: allDirtyTypes) {
QualifiedName qualifiedName = description.getQualifiedName();
final int modifiers = getDirtyStateModifiers(context, description);
if (filter.accept(modifiers, qualifiedName.skipLast(1).toString().toCharArray(), qualifiedName.getLastSegment().toCharArray(), new char[0][0], description.getEObjectURI().toPlatformString(true))) {
String fqName = description.getQualifiedName().toString();
createTypeProposal(fqName, modifiers, fqName.indexOf('$') > 0, proposalFactory, myContext, scopeAware, jvmTypeProvider, valueConverter);
}
}
}

and this place does not seem to care about interface/noninterface (for local defined types)

i assume the modiers should be looked as well (e.g.)

import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.xtext.common.types.xtext.ui.ITypesProposalProvider.Filter;
import org.eclipse.xtext.common.types.xtext.ui.TypeMatchFilters;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;

public class VisibilityFilter2 extends TypeMatchFilters.AbstractFilter {
	
	private Filter delegate;
	private int searchFor;

	public VisibilityFilter2(ContentAssistContext context, int searchFor) {
		this.searchFor = searchFor;
		delegate = TypeMatchFilters.and(TypeMatchFilters.isNotInternal(searchFor), TypeMatchFilters.isAcceptableByPreference());
	}

	@Override
	public boolean accept(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames,
			String path) {
		if (delegate.accept(modifiers, packageName, simpleTypeName, enclosingTypeNames, path)) {
			if (searchFor == IJavaSearchConstants.INTERFACE) {
				return Flags.isInterface(modifiers);
			}
			return true;
		}
		return false;
	}
		
	}


can you please file a bug at xtext-eclipse on github


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Interfaces and classes / types are proposed where only interfaces should be proposed [message #1764824 is a reply to message #1764818] Fri, 02 June 2017 13:01 Go to previous message
Marco Ullrich is currently offline Marco UllrichFriend
Messages: 14
Registered: December 2016
Location: Bayreuth
Junior Member
Hi Christian,
thank you for your feedback and clarifying this!
I'll file a bugreport.

Edit: Issue

[Updated on: Fri, 02 June 2017 14:30]

Report message to a moderator

Previous Topic:name may not be null xtext 2.12
Next Topic:mismatched input 'JaFirHug' expecting RULE_NAME
Goto Forum:
  


Current Time: Sat Sep 18 08:47:25 GMT 2021

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

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

Back to the top