Dear all,
I'm writing an agent-oriented programming language based on Xbase.
In my grammar, I defined an Event type as:
Event: 'event' name=ValidID ('extends' superTypes+=JvmParameterizedTypeReference)?
I written a validator that is checking if the "supertypes" are subtypes of io.sarl.lang.core.Event (a class defined in my API). It is working fine.
I defined a proposal provider on the "supertypes" that aims to propose only the types that are subtypes of io.sarl.lang.core.Event. The code is below. It is based on the version 2.7 of Xtext (which is fixing a bug in createSubTypeProposals).
The proposal provider permits to obtain the correct list of types.
BUT, then I validate/select of the types, I obtain the following error:
org.eclipse.xtext.xbase.ui.contentassist.ImportingTypesProposalProvider$FQNImporter - Could not find unique type named 'io.sarl.core.Initialize' in scope
How to deal with this error? Have I missed to code something (a scope...)?
Note that the class "io.sarl.core.Initialize" is a Java class that is not defined inside the current Java project, but into one of the Java dependencies (jar file).
class SARLProposalProvider extends AbstractSARLProposalProvider {
// extends ImportingTypesProposalProvider extends JdtTypesProposalProvider
@Inject extension IQualifiedNameProvider
@Inject private var IJvmTypeProvider.Factory jvmTypeProviderFactory
@Inject private var ITypesProposalProvider typeProposalProvider
@Inject private ILogicalContainerProvider logicalContainerProvider
override completeEvent_SuperTypes(
EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
if (model instanceof Event) {
model.buildProposalsWithout(
model.fullyQualifiedName.toString,
"io.sarl.lang.core.Event", context,
acceptor, SarlPackage.Literals::INHERITING_ELEMENT__SUPER_TYPES,
IJavaSearchConstants::CLASS
)
}
}
private def buildProposalsWithout(EObject event, String containerFullyQualifiedName, String superTypeName, ContentAssistContext context, ICompletionProposalAcceptor acceptor, EReference reference, int expectedType) {
val jvmTypeProvider = jvmTypeProviderFactory.createTypeProvider(event.eResource.resourceSet)
val interfaceToImplement = jvmTypeProvider.findTypeByName(superTypeName)
typeProposalProvider.createSubTypeProposals(
interfaceToImplement,
this,
context,
reference,
new SARLProposalProvider.TypeFilter(
expectedType,
superTypeName,
containerFullyQualifiedName),
acceptor
);
}
private static class TypeFilter implements ITypesProposalProvider.Filter {
private val int searchFor
private val String[] typeNames
new (int searchFor, String... typeNames) {
this.searchFor = searchFor
this.typeNames = typeNames
}
override accept(int modifiers,
char[] packageName, char[] simpleTypeName,
char[][] enclosingTypeNames, String path) {
if (Flags::isFinal(modifiers)
|| !Flags::isPublic(modifiers)
|| (searchFor==IJavaSearchConstants::INTERFACE && !Flags::isInterface(modifiers))
|| (searchFor==IJavaSearchConstants::CLASS &&
(Flags::isInterface(modifiers) || Flags::isEnum(modifiers))
|| Flags::isAnnotation(modifiers))) {
return false
}
var fqName = new StringBuilder(packageName.length + simpleTypeName.length + 1)
if (packageName.length != 0) {
fqName.append(packageName)
fqName.append('.')
}
for(char[] enclosingType: enclosingTypeNames) {
fqName.append(enclosingType);
fqName.append('.')
}
fqName.append(simpleTypeName)
var str = fqName.toString
for(exception : this.typeNames) {
if (str == exception) return false
}
return true
}
override getSearchFor() {
this.searchFor
}
}
}
[Updated on: Sat, 05 July 2014 13:27]
Report message to a moderator