package pl.jakubchmura.snmp.mib.reference.marker;

import com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;

import java.util.Collection;
import java.util.regex.Matcher;

public class GroovyMibNodeMarkerProvider extends LanguageSmiReferenceMarkerProvider {

    @Override
    protected void collectNavigationMarkers(@NotNull PsiElement element, Collection<? super RelatedItemLineMarkerInfo> result) {
        if (element instanceof GrLiteral) {
            GrLiteral literal = (GrLiteral) element;
            String value = literal.getValue() instanceof String? (String) literal.getValue(): null;
            Matcher matcher = getMatcher(value);
            if (value != null && matcher.matches()) {
                RelatedItemLineMarkerInfo<PsiElement> lineMarkerInfo = collectSmiReferences(element, matcher.group(1));
                if (lineMarkerInfo != null) {
                    result.add(lineMarkerInfo);
                }
            }
        }
    }
}

@@ -770,16 +770,53 @@
 : null;%0A
+            if (value != null) %7B%0A    
         
@@ -872,29 +872,16 @@
     
+    
 if (
-value != null && 
 matc
@@ -893,24 +893,28 @@
 atches()) %7B%0A
+    
             
@@ -1033,24 +1033,28 @@
             
+    
 if (lineMark
@@ -1063,32 +1063,36 @@
 Info != null) %7B%0A
+    
                 
@@ -1123,16 +1123,38 @@
 rInfo);%0A
+                    %7D%0A
         

Check for null to prevent NPE inside Matcher