-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NPE with TypeDefinition #771
Conversation
...pse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/contentmodel/CMXSDDocument.java
Outdated
Show resolved
Hide resolved
...pse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/contentmodel/CMXSDDocument.java
Show resolved
Hide resolved
5f44942
to
7bfb0d9
Compare
Please not this PR is not perfect. When a xs:element is not included inside a xs:complexType I search the first xs:element (xs:element/@name) which matches the origin element local name which can be wrong. |
332da84
to
c4d03c7
Compare
d1b9120
to
038f5ac
Compare
The PR is ready and tests are written. The PR should work now correctly and jump every time to the proper xs:element declaration. The main idea of find type location is to find the location of the Xerces XSElementDeclaration. It works (in master) for global xs:element or local xs:element which are declared inside a xs:complexType but not when xs:element is declared inside a xs:choice, xs:sequence, etc it doesn't work. This PR fixes the problem. To test this PR you can
|
038f5ac
to
7e00698
Compare
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLPositionUtility.java
Outdated
Show resolved
Hide resolved
...pse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/contentmodel/CMXSDDocument.java
Outdated
Show resolved
Hide resolved
// - fParticle array of XSParticleDecl where fValue is an instance of | ||
// XSElementDeclaration | ||
// - fLocalElementDecl array of Xerces Element which stores the element offset. | ||
|
||
// Get the XMLSchemaLoader instance from the XSLoader instance | ||
Field f = XSLoaderImpl.class.getDeclaredField("fSchemaLoader"); | ||
f.setAccessible(true); | ||
XMLSchemaLoader schemaLoader = (XMLSchemaLoader) f.get(xsLoader); | ||
|
||
// Get the XSDHandler instance from the XMLSchemaLoader instance | ||
Field f2 = XMLSchemaLoader.class.getDeclaredField("fSchemaHandler"); | ||
f2.setAccessible(true); | ||
XSDHandler handler = (XSDHandler) f2.get(schemaLoader); | ||
|
||
// Get the XSParticleDecl array from the XSDHandler instance | ||
Field f3 = XSDHandler.class.getDeclaredField("fParticle"); | ||
f3.setAccessible(true); | ||
XSParticleDecl[] fParticle = (XSParticleDecl[]) f3.get(handler); | ||
|
||
// Get the index where elementDeclaration is associated with a XSParticleDecl | ||
int i = getXSElementDeclIndex(elementDeclaration, fParticle); | ||
if (i >= 0) { | ||
// Get the Xerces Element array from the XSDHandler instance | ||
Field f4 = XSDHandler.class.getDeclaredField("fLocalElementDecl"); | ||
f4.setAccessible(true); | ||
Element[] fLocalElementDecl = (Element[]) f4.get(handler); | ||
return (ElementImpl) fLocalElementDecl[i]; | ||
} | ||
} catch (Exception e) { | ||
LOGGER.log(Level.SEVERE, | ||
"Error while retrieving mapped Xerces xs:element of '" + elementDeclaration.getName() + "'.", e); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My eyes burn from all that reflection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know -( But it's the only mean that I have found to get those Xerces information. The master code uses already reflection for the xs:complexType case.
398c82a
to
d01ea4e
Compare
Fixes eclipse-lemminx#629 Signed-off-by: azerr <[email protected]>
I'm good with merging this PR |
Fixes #629
Signed-off-by: azerr [email protected]