mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 16:58:56 +00:00
[xbase][compiler] Fix: NPE in compiler
This commit is contained in:
parent
421085e6e3
commit
65d9c1413d
3 changed files with 18 additions and 8 deletions
|
@ -14,6 +14,8 @@ import java.util.List;
|
|||
import org.eclipse.emf.common.notify.Adapter;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.EStructuralFeature;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.eclipse.xtext.AbstractRule;
|
||||
import org.eclipse.xtext.Action;
|
||||
import org.eclipse.xtext.Assignment;
|
||||
|
@ -60,7 +62,8 @@ public class NodeModelUtils {
|
|||
* @param leafNodeOffset the offset that is covered by the searched node.
|
||||
* @return the leaf node at the given offset or <code>null</code>.
|
||||
*/
|
||||
public static ILeafNode findLeafNodeAtOffset(INode node, int leafNodeOffset) {
|
||||
@Nullable
|
||||
public static ILeafNode findLeafNodeAtOffset(@NonNull INode node, int leafNodeOffset) {
|
||||
INode localNode = node;
|
||||
while(!(localNode instanceof AbstractNode)) {
|
||||
localNode = localNode.getParent();
|
||||
|
@ -115,7 +118,8 @@ public class NodeModelUtils {
|
|||
* @return the node that is directly associated with the given object.
|
||||
* @see NodeModelUtils#findActualNodeFor(EObject)
|
||||
*/
|
||||
public static ICompositeNode getNode(EObject object) {
|
||||
@Nullable
|
||||
public static ICompositeNode getNode(@Nullable EObject object) {
|
||||
if (object == null)
|
||||
return null;
|
||||
List<Adapter> adapters = object.eAdapters();
|
||||
|
@ -132,6 +136,7 @@ public class NodeModelUtils {
|
|||
*
|
||||
* @return the list of nodes that were used to assign values to the given feature for the given object.
|
||||
*/
|
||||
@NonNull
|
||||
public static List<INode> findNodesForFeature(EObject semanticObject, EStructuralFeature structuralFeature) {
|
||||
ICompositeNode node = findActualNodeFor(semanticObject);
|
||||
if (node != null) {
|
||||
|
@ -205,7 +210,8 @@ public class NodeModelUtils {
|
|||
* @param semanticObject the semantic object whose node should be provided.
|
||||
* @return the node that covers all assigned values of the given object.
|
||||
*/
|
||||
public static ICompositeNode findActualNodeFor(EObject semanticObject) {
|
||||
@Nullable
|
||||
public static ICompositeNode findActualNodeFor(@Nullable EObject semanticObject) {
|
||||
ICompositeNode node = getNode(semanticObject);
|
||||
if (node != null) {
|
||||
while (GrammarUtil.containingAssignment(node.getGrammarElement()) == null && node.getParent() != null && !node.getParent().hasDirectSemanticElement()) {
|
||||
|
@ -222,7 +228,8 @@ public class NodeModelUtils {
|
|||
*
|
||||
* @return the semantic object that is really associated with the actual container node of the given node.
|
||||
*/
|
||||
public static EObject findActualSemanticObjectFor(INode node) {
|
||||
@Nullable
|
||||
public static EObject findActualSemanticObjectFor(@Nullable INode node) {
|
||||
if (node == null)
|
||||
return null;
|
||||
if (node.hasDirectSemanticElement())
|
||||
|
@ -251,7 +258,8 @@ public class NodeModelUtils {
|
|||
return findActualSemanticObjectFor(node.getParent());
|
||||
}
|
||||
|
||||
private static EObject findActualSemanticObjectInChildren(INode node, EObject grammarElement) {
|
||||
@Nullable
|
||||
private static EObject findActualSemanticObjectInChildren(@NonNull INode node, @Nullable EObject grammarElement) {
|
||||
if (node.hasDirectSemanticElement())
|
||||
return node.getSemanticElement();
|
||||
AbstractRule rule = null;
|
||||
|
|
|
@ -33,8 +33,10 @@ public class XtextDiagnosticConverter extends DiagnosticConverterImpl{
|
|||
ITextRegion location = locationInFileProvider.getSignificantTextRegion(obj);
|
||||
if (location != null) {
|
||||
ICompositeNode rootNode = NodeModelUtils.getNode(EcoreUtil.getRootContainer(obj));
|
||||
ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(rootNode, location.getOffset());
|
||||
return getLocationForNode(leafNode);
|
||||
if (rootNode != null) {
|
||||
ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(rootNode, location.getOffset());
|
||||
return getLocationForNode(leafNode);
|
||||
}
|
||||
} else {
|
||||
return super.getLocationData(obj.eContainer(), null, index);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonN
|
|||
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
|
||||
org.eclipse.jdt.core.compiler.annotation.nonnullisdefault=disabled
|
||||
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
|
||||
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
|
||||
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
|
|
Loading…
Reference in a new issue