Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

GRAILS-6583 added Andrew's code for GSP debugging

  • Loading branch information...
commit 584dc9b6e7aa6daaa66fb96bed368ea905ac03aa 1 parent 804d6ef
@burtbeckwith burtbeckwith authored
View
3  maven/grails-web.mf
@@ -22,6 +22,9 @@ Import-Template:
org.codehaus.groovy.ant.*;version="${groovy.version:[=.=.=, =.+1.0)}",
org.codehaus.groovy.tools.*;version="${groovy.version:[=.=.=, =.+1.0)}",
org.codehaus.groovy.syntax.*;version="${groovy.version:[=.=.=, =.+1.0)}",
+ org.codehaus.groovy.ast.*;version="${groovy.version:[=.=.=, =.+1.0)}",
+ org.codehaus.groovy.ast.expr.*;version="${groovy.version:[=.=.=, =.+1.0)}",
+ org.codehaus.groovy.ast.stmt.*;version="${groovy.version:[=.=.=, =.+1.0)}",
org.codehaus.groovy.grails.*;version="${grails.version:[=.=.=, =.+1.0)}",
org.hibernate.*;version="${hibernate.version:[=.=.=, =.+1.0)}",
com.opensymphony.module.sitemesh.*;version="${sitemesh.version:[=.=.=, =.+1.0)}",
View
80 src/java/org/codehaus/groovy/grails/web/pages/GroovyPageParser.java
@@ -91,6 +91,7 @@
private GSPWriter out;
private String className;
private String packageName;
+ private String sourceName; // last segment of the file name (eg- index.gsp)
private boolean finalPass = false;
private int tagIndex;
private Map<Object, Object> tagContext;
@@ -227,6 +228,7 @@ public GroovyPageParser(String name, String uri, String filename, InputStream in
pageName = uri;
environment = Environment.getCurrent();
makeName(name);
+ makeSourceName(filename);
}
private Map<String, String> parseDirectives(String gspSource) {
@@ -683,6 +685,22 @@ else if (ix == 0 && c >= '0' && c <= '9') {
className = buf.toString();
}
+ /**
+ * find the simple name of this gsp
+ * @param filename the fully qualified file name
+ */
+ private void makeSourceName(String filename) {
+ if (filename != null) {
+ int lastSegmentStart = filename.lastIndexOf('/');
+ if (lastSegmentStart == -1) {
+ lastSegmentStart = filename.lastIndexOf('\\');
+ }
+ sourceName = filename.substring(lastSegmentStart + 1);
+ } else {
+ sourceName = className;
+ }
+ }
+
private static boolean match(CharSequence pat, CharSequence text, int start) {
int ix = start, ixz = text.length(), ixy = start + pat.length();
if (ixz > ixy) {
@@ -831,6 +849,10 @@ private void page() {
out.println("null");
}
out.println("}");
+
+ if (shouldAddLineNumbers()) {
+ addLineNumbers();
+ }
}
else {
for (int i = 0; i < DEFAULT_IMPORTS.length; i++) {
@@ -839,6 +861,64 @@ private void page() {
}
}
}
+
+ /**
+ * Determines if the line numbers array should be added to the generated Groovy class.
+ * @return true if they should
+ */
+ private boolean shouldAddLineNumbers() {
+ try {
+ // for now, we support this through a system property.
+ String prop = System.getenv("GROOVY_PAGE_ADD_LINE_NUMBERS");
+ return Boolean.valueOf(prop).booleanValue();
+ } catch (Exception e) {
+ // something wild happened
+ return false;
+ }
+ }
+
+ /**
+ * Adds the line numbers array to the end of the generated Groovy ModuleNode
+ * in a way suitable for the LineNumberTransform AST transform to operate on it
+ */
+ private void addLineNumbers() {
+ out.println();
+ out.println("@org.codehaus.groovy.grails.web.transform.LineNumber(");
+ out.print("\tlines = [");
+ // get the line numbers here. this will mean that the last 2 lines will not be captured in the
+ // line number information, but that's OK since a user cannot set a breakpoint there anyway.
+ int[] lineNumbers = filterTrailing0s(out.getLineNumbers());
+
+ for (int i = 0; i < lineNumbers.length; i++) {
+ out.print(lineNumbers[i]);
+ if (i < lineNumbers.length - 1) {
+ out.print(", ");
+ }
+ }
+ out.println("],");
+ out.println("\tsourceName = \"" + sourceName + "\"");
+ out.println(")");
+ out.println("class ___LineNumberPlaceholder { }");
+ }
+
+ /**
+ * Filters trailing 0s from the line number array
+ * @param lineNumbers the line number array
+ * @return a new array that removes all 0s from the end of it
+ */
+ private int[] filterTrailing0s(int[] lineNumbers) {
+ int startLocation = lineNumbers.length - 1;
+ for (int i = lineNumbers.length -1; i >= 0; i--) {
+ if (lineNumbers[i] > 0) {
+ startLocation = i + 1;
+ break;
+ }
+ }
+
+ int[] newLineNumbers = new int[startLocation];
+ System.arraycopy(lineNumbers, 0, newLineNumbers, 0, startLocation);
+ return newLineNumbers;
+ }
private void endTag() {
if (!finalPass) return;
View
35 src/java/org/codehaus/groovy/grails/web/transform/LineNumber.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2003-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.codehaus.groovy.grails.web.transform;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.codehaus.groovy.transform.GroovyASTTransformationClass;
+
+/**
+ * @author Andrew Eisenberg
+ * @created Jul 22, 2010
+ */
+@Retention(RetentionPolicy.SOURCE)
+@Target({ ElementType.TYPE })
+@GroovyASTTransformationClass({"org.codehaus.groovy.grails.web.transform.LineNumberTransform"})
+public @interface LineNumber {
+ int[] lines();
+ String sourceName();
+}
View
717 src/java/org/codehaus/groovy/grails/web/transform/LineNumberTransform.java
@@ -0,0 +1,717 @@
+/*
+ * Copyright 2003-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.codehaus.groovy.grails.web.transform;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.codehaus.groovy.ast.expr.ConstantExpression;
+
+import org.codehaus.groovy.ast.ASTNode;
+import org.codehaus.groovy.ast.AnnotationNode;
+import org.codehaus.groovy.ast.ClassCodeVisitorSupport;
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.expr.ArgumentListExpression;
+import org.codehaus.groovy.ast.expr.ArrayExpression;
+import org.codehaus.groovy.ast.expr.AttributeExpression;
+import org.codehaus.groovy.ast.expr.BinaryExpression;
+import org.codehaus.groovy.ast.expr.BitwiseNegationExpression;
+import org.codehaus.groovy.ast.expr.BooleanExpression;
+import org.codehaus.groovy.ast.expr.CastExpression;
+import org.codehaus.groovy.ast.expr.ClassExpression;
+import org.codehaus.groovy.ast.expr.ClosureExpression;
+import org.codehaus.groovy.ast.expr.ClosureListExpression;
+import org.codehaus.groovy.ast.expr.ConstructorCallExpression;
+import org.codehaus.groovy.ast.expr.DeclarationExpression;
+import org.codehaus.groovy.ast.expr.ElvisOperatorExpression;
+import org.codehaus.groovy.ast.expr.Expression;
+import org.codehaus.groovy.ast.expr.FieldExpression;
+import org.codehaus.groovy.ast.expr.GStringExpression;
+import org.codehaus.groovy.ast.expr.ListExpression;
+import org.codehaus.groovy.ast.expr.MapEntryExpression;
+import org.codehaus.groovy.ast.expr.MapExpression;
+import org.codehaus.groovy.ast.expr.MethodCallExpression;
+import org.codehaus.groovy.ast.expr.MethodPointerExpression;
+import org.codehaus.groovy.ast.expr.NotExpression;
+import org.codehaus.groovy.ast.expr.PostfixExpression;
+import org.codehaus.groovy.ast.expr.PrefixExpression;
+import org.codehaus.groovy.ast.expr.PropertyExpression;
+import org.codehaus.groovy.ast.expr.RangeExpression;
+import org.codehaus.groovy.ast.expr.RegexExpression;
+import org.codehaus.groovy.ast.expr.SpreadExpression;
+import org.codehaus.groovy.ast.expr.SpreadMapExpression;
+import org.codehaus.groovy.ast.expr.StaticMethodCallExpression;
+import org.codehaus.groovy.ast.expr.TernaryExpression;
+import org.codehaus.groovy.ast.expr.TupleExpression;
+import org.codehaus.groovy.ast.expr.UnaryMinusExpression;
+import org.codehaus.groovy.ast.expr.UnaryPlusExpression;
+import org.codehaus.groovy.ast.stmt.Statement;
+import org.codehaus.groovy.classgen.BytecodeExpression;
+import org.codehaus.groovy.control.CompilePhase;
+import org.codehaus.groovy.control.SourceUnit;
+import org.codehaus.groovy.transform.ASTTransformation;
+import org.codehaus.groovy.transform.GroovyASTTransformation;
+import org.springframework.util.ReflectionUtils;
+
+/**
+ * Convert line number information to that based on the line number array passed
+ * into the line number array in the {@link LineNumber} annotation.
+ *
+ * @author Andrew Eisenberg
+ * @created Jul 22, 2010
+ */
+@GroovyASTTransformation(phase=CompilePhase.SEMANTIC_ANALYSIS)
+public class LineNumberTransform implements ASTTransformation {
+
+ // LOG statements commented out because they were causing
+ // compilation problems when used outside of grails
+// static final Log LOG = LogFactory.getLog(LineNumberTransform)
+
+ public void visit(ASTNode[] nodes, SourceUnit source) {
+ List<ClassNode> classes = source.getAST().getClasses();
+
+ AnnotationNode annotation = null;
+ for (ClassNode clazz : classes) {
+ annotation = findAnnotation(clazz);
+ if (annotation != null) {
+ break;
+ }
+ }
+
+ if (annotation == null) {
+ return;
+ }
+
+ int[] array = extractLineNumberArray(annotation);
+ if (array != null) {
+ LineNumberVisitor visitor = new LineNumberVisitor(array);
+ for (ClassNode clazz : classes) {
+ visitor.visitClass(clazz);
+ }
+ }
+
+ String sourceName = extractSourceName(annotation);
+ if (sourceName != null) {
+ source.getAST().setDescription(sourceName);
+ // source.name = sourceName
+ Field field = ReflectionUtils.findField(SourceUnit.class, "name");
+ field.setAccessible(true);
+ ReflectionUtils.setField(field, source, sourceName);
+ }
+ }
+
+ String extractSourceName(AnnotationNode node) {
+ ConstantExpression newName = (ConstantExpression)node.getMember("sourceName");
+ return (String)newName.getValue();
+ }
+
+ AnnotationNode findAnnotation(ClassNode clazz) {
+ if (clazz != null) {
+ for (AnnotationNode node : clazz.getAnnotations()) {
+ if (node.getClassNode().getName().equals(LineNumber.class.getName())) {
+ // LOG.debug "Transforming in ${clazz.name}"
+ return node;
+ }
+ }
+ }
+ return null;
+ }
+
+ int[] extractLineNumberArray(AnnotationNode node) {
+ ListExpression lineNumberArray = (ListExpression)node.getMember("lines");
+ // make assumption that this is a simple array of constants
+ List<Integer> numbers = new ArrayList<Integer>();
+ for (Expression e : lineNumberArray.getExpressions()) {
+ if (e instanceof ConstantExpression) {
+ numbers.add((Integer)((ConstantExpression)e).getValue());
+ }
+ else {
+ numbers.add(-1);
+ }
+ }
+ // LOG.debug "We have transformed: ${numbers}"
+ if (numbers.isEmpty()) {
+ return null;
+ }
+ int[] array = new int[numbers.size()];
+ for (int i = 0, count = numbers.size(); i < count; i++) {
+ array[i] = numbers.get(i);
+ }
+ return array;
+ }
+
+ class LineNumberVisitor extends ClassCodeVisitorSupport {
+ int[] lineNumbers;
+
+ LineNumberVisitor(int[] lineNumbers) {
+ this.lineNumbers = lineNumbers;
+// if (LOG.isDebugEnabled()) {
+// String numbers = "Line numbers: ";
+// for (int number : lineNumbers) {
+// numbers += number + ", ";
+// }
+// LOG.debug numbers
+// }
+ }
+
+ @Override
+ protected void visitStatement(Statement statement) {
+ // LOG.debug "Transforming statement '${statement}':"
+
+ if (statement.getLineNumber() >= 0 && statement.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${statement.lineNumber} to ${lineNumbers[statement.lineNumber]}"
+ statement.setLineNumber(lineNumbers[statement.getLineNumber() - 1]);
+ }
+
+ if (statement.getLastLineNumber() > 0 && statement.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${statement.lastLineNumber} to ${lineNumbers[statement.lastLineNumber]}"
+ statement.setLastLineNumber(lineNumbers[statement.getLastLineNumber() - 1]);
+ }
+ }
+
+ @Override
+ public void visitMethodCallExpression(MethodCallExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitMethodCallExpression(expression);
+ }
+ @Override
+ public void visitStaticMethodCallExpression(StaticMethodCallExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitStaticMethodCallExpression(expression);
+ }
+ @Override
+ public void visitConstructorCallExpression(ConstructorCallExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitConstructorCallExpression(expression);
+ }
+ @Override
+ public void visitBinaryExpression(BinaryExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitBinaryExpression(expression);
+ }
+ @Override
+ public void visitTernaryExpression(TernaryExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitTernaryExpression(expression);
+ }
+ @Override
+ public void visitShortTernaryExpression(ElvisOperatorExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitShortTernaryExpression(expression);
+ }
+ @Override
+ public void visitPostfixExpression(PostfixExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitPostfixExpression(expression);
+ }
+ @Override
+ public void visitPrefixExpression(PrefixExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitPrefixExpression(expression);
+ }
+ @Override
+ public void visitBooleanExpression(BooleanExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitBooleanExpression(expression);
+ }
+ @Override
+ public void visitNotExpression(NotExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitNotExpression(expression);
+ }
+ @Override
+ public void visitClosureExpression(ClosureExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitClosureExpression(expression);
+ }
+ @Override
+ public void visitTupleExpression(TupleExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitTupleExpression(expression);
+ }
+ @Override
+ public void visitListExpression(ListExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitListExpression(expression);
+ }
+ @Override
+ public void visitArrayExpression(ArrayExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitArrayExpression(expression);
+ }
+ @Override
+ public void visitMapExpression(MapExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitMapExpression(expression);
+ }
+ @Override
+ public void visitMapEntryExpression(MapEntryExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitMapEntryExpression(expression);
+ }
+ @Override
+ public void visitRangeExpression(RangeExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitRangeExpression(expression);
+ }
+ @Override
+ public void visitSpreadExpression(SpreadExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitSpreadExpression(expression);
+ }
+ @Override
+ public void visitSpreadMapExpression(SpreadMapExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitSpreadMapExpression(expression);
+ }
+ @Override
+ public void visitMethodPointerExpression(
+ MethodPointerExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitMethodPointerExpression(expression);
+ }
+ @Override
+ public void visitUnaryMinusExpression(UnaryMinusExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitUnaryMinusExpression(expression);
+ }
+ @Override
+ public void visitUnaryPlusExpression(UnaryPlusExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitUnaryPlusExpression(expression);
+ }
+ @Override
+ public void visitBitwiseNegationExpression(BitwiseNegationExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitBitwiseNegationExpression(expression);
+ }
+ @Override
+ public void visitCastExpression(CastExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitCastExpression(expression);
+ }
+ @Override
+ public void visitConstantExpression(ConstantExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitConstantExpression(expression);
+ }
+ @Override
+ public void visitClassExpression(ClassExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitClassExpression(expression);
+ }
+ @Override
+ public void visitDeclarationExpression(DeclarationExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitDeclarationExpression(expression);
+ }
+ @Override
+ public void visitPropertyExpression(PropertyExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitPropertyExpression(expression);
+ }
+ @Override
+ public void visitAttributeExpression(AttributeExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitAttributeExpression(expression);
+ }
+ @Override
+ public void visitFieldExpression(FieldExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitFieldExpression(expression);
+ }
+ @Override
+ public void visitRegexExpression(RegexExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitRegexExpression(expression);
+ }
+ @Override
+ public void visitGStringExpression(GStringExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitGStringExpression(expression);
+ }
+ @Override
+ public void visitArgumentlistExpression(ArgumentListExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitArgumentlistExpression(expression);
+ }
+ @Override
+ public void visitClosureListExpression(ClosureListExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitClosureListExpression(expression);
+ }
+ @Override
+ public void visitBytecodeExpression(BytecodeExpression expression) {
+ // LOG.debug "Transforming expression '${expression}':"
+
+ if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
+ // LOG.debug " start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber - 1]}"
+ expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
+ }
+
+ if (expression.getLastLineNumber() > 0 && expression.getLastLineNumber() < lineNumbers.length) {
+ // LOG.debug " end from ${expression.lastLineNumber} to ${lineNumbers[expression.lastLineNumber - 1]}"
+ expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
+ }
+ super.visitBytecodeExpression(expression);
+ }
+ @Override
+ protected SourceUnit getSourceUnit() {
+ return null;
+ }
+ }
+}

2 comments on commit 584dc9b

@graemerocher

Line 872 could probably be written as

private boolean shouldAddLineNumbers() {

return Boolean.getBoolean("GROOVY_PAGE_ADD_LINE_NUMBERS")
}

@pledbrook
Collaborator

That works for system properties but not environment variables. Of course, it may make sense to make it a system property!

Please sign in to comment.
Something went wrong with that request. Please try again.