groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] 01/05: get source context from GroovyRuntimeException and SyntaxException
Date Sat, 11 Jan 2020 02:05:05 GMT
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 8fe37ab77f42fda80137a09819b888363412016a
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Fri Jan 10 14:56:19 2020 -0600

    get source context from GroovyRuntimeException and SyntaxException
---
 .../codehaus/groovy/control/CompilationUnit.java   | 25 ++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/control/CompilationUnit.java b/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
index eb915ef..bd21641 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
@@ -19,6 +19,7 @@
 package org.codehaus.groovy.control;
 
 import groovy.lang.GroovyClassLoader;
+import groovy.lang.GroovyRuntimeException;
 import groovy.transform.CompilationUnitAware;
 import org.codehaus.groovy.GroovyBugError;
 import org.codehaus.groovy.ast.ClassCodeExpressionTransformer;
@@ -942,10 +943,22 @@ public class CompilationUnit extends ProcessingUnit {
 
                     if (errorCollector != null) {
                         unit.getErrorCollector().addCollectorContents(errorCollector);
-                    } else if (context != null) {
-                        unit.getErrorCollector().addException(e instanceof Exception ? (Exception)
e : new RuntimeException(e), context);
                     } else {
-                        unit.getErrorCollector().addError(new ExceptionMessage(e instanceof
Exception ? (Exception) e : new RuntimeException(e), unit.debug, unit));
+                        if (e instanceof GroovyRuntimeException) {
+                            GroovyRuntimeException gre = (GroovyRuntimeException) e;
+                            context = Optional.ofNullable(gre.getModule()).map(ModuleNode::getContext).orElse(context);
+                        }
+                        if (context != null) {
+                            if (e instanceof SyntaxException) {
+                                unit.getErrorCollector().addError((SyntaxException) e, context);
+                            } else if (e.getCause() instanceof SyntaxException) {
+                                unit.getErrorCollector().addError((SyntaxException) e.getCause(),
context);
+                            } else {
+                                unit.getErrorCollector().addException(e instanceof Exception
? (Exception) e : new RuntimeException(e), context);
+                            }
+                        } else {
+                            unit.getErrorCollector().addError(new ExceptionMessage(e instanceof
Exception ? (Exception) e : new RuntimeException(e), unit.debug, unit));
+                        }
                     }
                 }
             }
@@ -1079,13 +1092,13 @@ public class CompilationUnit extends ProcessingUnit {
         addNewPhaseOperation((ISourceUnitOperation) op, phase);
     }
 
-    @Deprecated // IntelliJ IDEA depends on the API
-    public void applyToPrimaryClassNodes(final PrimaryClassNodeOperation op) throws CompilationFailedException
{
+    @Deprecated
+    public void applyToSourceUnits(final SourceUnitOperation op) throws CompilationFailedException
{
         op.doPhaseOperation(this);
     }
 
     @Deprecated
-    public void applyToSourceUnits(final SourceUnitOperation op) throws CompilationFailedException
{
+    public void applyToPrimaryClassNodes(final PrimaryClassNodeOperation op) throws CompilationFailedException
{
         op.doPhaseOperation(this);
     }
 


Mime
View raw message