Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » quick fix for add import using JvmType ?
quick fix for add import using JvmType ? [message #955430] Tue, 23 October 2012 19:51 Go to next message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
Hi,

I'm studying the org.xtext.httprouting demo.

I liked the way that this demo is handling the imports using:

Import :
	'import' importedType=[ types::JvmType | QualifiedName];



Running the example, when I added this sentence into editor:
import com.acme.GuessTheNumber

inject GuessTheNumber controller
inject MagicNumber someObj

I receive this error:
Couldn't resolve reference to JvmType 'MagicNumber'.


So, I would like to experiment with a quick fix for adding an import statement for resolve this kind of error. It is that possible?

Could someone point me which validation class are being used to throw this error and how to know the issue code used?

I would appreciate if someone point me to some example of this kind of quickfix too.

regards

[Updated on: Wed, 24 October 2012 17:24]

Report message to a moderator

Re: quick fix for add import using JvmType ? [message #956605 is a reply to message #955430] Wed, 24 October 2012 16:55 Go to previous messageGo to next message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
Ok, I found how to do that.

I've created one class extending from DefaultQuickfixProvider, changed the method:

public void createLinkingIssueResolutions(final Issue issue,
			final IssueResolutionAcceptor issueResolutionAcceptor)


and created this new resolution method:

public void createImportResolution(String issueString,
		IEObjectDescription solution, String ruleName,
		Keyword keyword, boolean caseInsensitive) {
final String replacement = qualifiedNameConverter
					.toString(solution.getName());

	// add a import statement
	issueResolutionAcceptor.accept(issue, "Add import for "
						+ replacement, "Will add 'import " + replacement + "'",
						// providing null for the icon name makes Eclipse use the
						// standard quick fix icon
						null, new ISemanticModification() {

		public void apply(EObject element,
				IModificationContext context)	throws Exception {
						// we know that the warning applies to cities
		ComponentTemplateLibrary c = (ComponentTemplateLibrary) element
							.eContainer().eContainer();

		// // programmatic modification of the model
		Import importobj = ComponentTemplateLibraryDslFactory.eINSTANCE
								.createImport();

		IJvmTypeProvider typeProvider = typeProviderFactory.findOrCreateTypeProvider(c.eResource().getResourceSet());
		JvmType jvmType = typeProvider.findTypeByName(replacement);

		importobj.setImportedType(jvmType);
		c.getImports().add(importobj);
		// Xtext automatically inserts text for the
						// above
					}
				});
			}
		});
	}


But I've found a problem. The quickfix is showing right and I can select it properly, but the import statement is being serialized with the jvmType in its single name form and not in its qualified name as expected.

I've checked the grammar:
Import:
	('import' importedType=[jvmTypes::JvmType|QualifiedName]) 
;


And checked the DSLQualifiedNameProvider is extending from Xbase one.

Could someone please give any tip where should I check?

thanks

[Updated on: Wed, 24 October 2012 17:25]

Report message to a moderator

Re: quick fix for add import using JvmType ? [message #956706 is a reply to message #956605] Wed, 24 October 2012 18:48 Go to previous message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
Found the problem... It seem that exists a bug in the class CrossReferenceSerializer, especifically in this method:

	protected String getCrossReferenceNameFromScope(EObject semanticObject, CrossReference crossref, EObject target,
			final IScope scope, Acceptor errors) {
		String ruleName = linkingHelper.getRuleNameFrom(crossref);
		boolean foundOne = false;
		List<ISerializationDiagnostic> recordedErrros = null;
		for (IEObjectDescription desc : scope.getElements(target)) {
			foundOne = true;
			String unconverted = qualifiedNameConverter.toString(desc.getName()); <----- here is the problem
			try {
				return valueConverter.toString(unconverted, ruleName);
			} catch (ValueConverterException e) {
				if (errors != null) {
					if (recordedErrros == null)
						recordedErrros = Lists.newArrayList();
					recordedErrros.add(diagnostics.getValueConversionExceptionDiagnostic(semanticObject, crossref,
							unconverted, e));
				}
			}
		}
		if (errors != null) {
			if (recordedErrros != null)
				for (ISerializationDiagnostic diag : recordedErrros)
					errors.accept(diag);
			if (!foundOne)
				errors.accept(diagnostics.getNoEObjectDescriptionFoundDiagnostic(semanticObject, crossref, target,
						scope));
		}
		return null;
	}


After I have created my own CrossReferenceSerializer class and changed the indicated sentence for:
String unconverted = qualifiedNameConverter.toString(desc.getQualifiedName());

Everything works as expected.
Previous Topic:Partial Grammar Testing
Next Topic:JvmGenericType does not contain @Property operations
Goto Forum:
  


Current Time: Fri Apr 26 05:32:24 GMT 2024

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

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

Back to the top