Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 354473

Summary: java.lang.IllegalStateException: Couldn't deresolve <Parent> with import <Parent>.*
Product: [Modeling] TMF Reporter: Christian Dietrich <christian.dietrich.opensource>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: major    
Priority: P3 CC: mail, sebastian.zarnekow
Version: unspecifiedFlags: sven.efftinge: kepler+
Target Milestone: M4   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Christian Dietrich CLA 2011-08-11 06:02:22 EDT
Build Identifier: 2.0.0

Having following simple grammar

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Ergebnisklasse
	:	'ergebnisklasse' name=ID
		('werteattribute' attribute+=ErgebnisklassenFachattribut*)?
	;
	
ErgebnisklassenFachattribut
    :   name=ID typ=[AbstraktesDatenmodellElement|TYPID]
    ;
    
TYPID
	:	ID
	;    
    
AbstraktesDatenmodellElement: Ergebnisklasse;    	

and this simple model

ergebnisklasse Test
werteattribute
lala . 

i get this nice stacktrace

0    [Worker-0] ERROR org.eclipse.xtext.linking.lazy.LazyLinkingResource  - resolution of uriFragment 'xtextLink_::0.1.0::1::/2' failed.
java.lang.IllegalStateException: Couldn't deresolve Test with import Test.*
	at org.eclipse.xtext.scoping.impl.ImportScope.getLocalElementsByName(ImportScope.java:161)
	at org.eclipse.xtext.scoping.impl.ImportScope.getSingleLocalElementByName(ImportScope.java:140)
	at org.eclipse.xtext.scoping.impl.AbstractScope.getSingleElement(AbstractScope.java:101)
	at org.eclipse.xtext.scoping.impl.AbstractScope.getSingleElement(AbstractScope.java:104)
	at org.eclipse.xtext.linking.impl.DefaultLinkingService.getLinkedObjects(DefaultLinkingService.java:121)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:169)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.resolveLazyCrossReference(LazyLinkingResource.java:138)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.resolveLazyCrossReferences(LazyLinkingResource.java:102)
	at org.eclipse.xtext.EcoreUtil2.resolveLazyCrossReferences(EcoreUtil2.java:417)
	at org.eclipse.xtext.validation.ResourceValidatorImpl.resolveProxies(ResourceValidatorImpl.java:127)
	at org.eclipse.xtext.validation.ResourceValidatorImpl.validate(ResourceValidatorImpl.java:62)
	at org.eclipse.xtext.ui.editor.validation.ValidationJob$1.exec(ValidationJob.java:79)
	at org.eclipse.xtext.ui.editor.validation.ValidationJob$1.exec(ValidationJob.java:1)
	at org.eclipse.xtext.util.concurrent.AbstractReadWriteAcces.readOnly(AbstractReadWriteAcces.java:32)
	at org.eclipse.xtext.ui.editor.model.XtextDocument.readOnly(XtextDocument.java:86)
	at org.eclipse.xtext.ui.editor.validation.ValidationJob.createIssues(ValidationJob.java:75)
	at org.eclipse.xtext.ui.editor.validation.ValidationJob.run(ValidationJob.java:64)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

The Problem is that the . (dot) in the model is recognized as qualifiedname
and then it trys to resolve this (empty) qualifiedname against its parent

since this leads to ugly "problem occured" boxes
in the ui i set this to major

a workaround might be to deactivate fragment = scoping.ImportNamespacesScopingFragment {} but this is not suitable in
may cases.

Please not: i shortend the TYPID rule in the example -> in our case we use it to allow additional kewords in the types name

Reproducible: Always
Comment 1 Christian Dietrich CLA 2011-08-11 06:10:38 EDT
Here is the workaround that may help

package org.xtext.example.mydsl;

import org.eclipse.xtext.naming.IQualifiedNameConverter;
import org.eclipse.xtext.naming.QualifiedName;

public class MydslQualifiedNameConverter extends IQualifiedNameConverter.DefaultImpl {

	@Override
	public QualifiedName toQualifiedName(String qualifiedNameAsString) {
		if (".".equals(qualifiedNameAsString)) {
			return QualifiedName.create(".");
		}
		return super.toQualifiedName(qualifiedNameAsString);
	}
	
}
Comment 2 Christian Dietrich CLA 2011-08-15 11:52:58 EDT
Here the cleaner version of the workaround/fix

public class MydslQualifiedNameConverter extends IQualifiedNameConverter.DefaultImpl {

	@Override
	public QualifiedName toQualifiedName(String qualifiedNameAsString) {
		if (getDelimiter().equals(qualifiedNameAsString)) {
			return QualifiedName.create(getDelimiter());
		}
		return super.toQualifiedName(qualifiedNameAsString);
	}

}
Comment 3 Sebastian Zarnekow CLA 2011-11-09 14:50:09 EST
Not 2.1
Comment 4 Sven Efftinge CLA 2012-11-23 02:27:49 EST
I fixed it such that an ImportNormalizer returns null when resolve() is called with an empty QualifiedName. pushed to master.
Comment 5 Eclipse Webmaster CLA 2017-10-31 10:48:19 EDT
Requested via bug 522520.

-M.
Comment 6 Eclipse Webmaster CLA 2017-10-31 10:59:22 EDT
Requested via bug 522520.

-M.