eclipse / epsilon

Epsilon is a family of Java-based scripting languages for automating common model-based software engineering tasks, such as code generation, model-to-model transformation and model validation, that work out of the box with EMF (including Xtext and Sirius), UML (including Cameo/MagicDraw), Simulink, XML and other types of models.
https://eclipse.org/epsilon
Eclipse Public License 2.0
53 stars 11 forks source link

EGL: Outdented TemplateOperation causes StringIndexOutOfBoundsException #90

Closed Arkaedan closed 2 months ago

Arkaedan commented 2 months ago

Outdented TemplateOperation causes StringIndexOutOfBoundsException when used in a file that has other outdented sections.

Example:

[%for (f in Sequence{1}) {-%]
    [%=f%]
[%}%]
[%=t()%]
[%
@template
operation t(){-%]
    [%=1%]
[%}%]

Which causes this error:

begin 4, end 8, length 4
    at (C:\Users\harr01\AppData\Local\Temp\epsilon\TemplateOperation.egl@4:3-4:6)
    at (C:\Users\harr01\AppData\Local\Temp\epsilon\TemplateOperation.egl@4:3-4:8)
    at (C:\Users\harr01\AppData\Local\Temp\epsilon\TemplateOperation.egl@4:3-4:8)
    at (C:\Users\harr01\AppData\Local\Temp\epsilon\TemplateOperation.egl@1:2-4:18)
    at (C:\Users\harr01\AppData\Local\Temp\epsilon\TemplateOperation.egl@1:0-14:1)

    Cause: begin 4, end 8, length 4
    at (C:\Users\harr01\AppData\Local\Temp\epsilon\TemplateOperation.egl@4:3-4:6)
    at (C:\Users\harr01\AppData\Local\Temp\epsilon\TemplateOperation.egl@4:3-4:8)
    at (C:\Users\harr01\AppData\Local\Temp\epsilon\TemplateOperation.egl@4:3-4:8)
    at (C:\Users\harr01\AppData\Local\Temp\epsilon\TemplateOperation.egl@1:2-4:18)
    at (C:\Users\harr01\AppData\Local\Temp\epsilon\TemplateOperation.egl@1:0-14:1)

    at org.eclipse.epsilon.egl.internal.EglModule.execute(EglModule.java:181)
    at org.eclipse.epsilon.egl.EglTemplate.process(EglTemplate.java:94)
    at org.eclipse.epsilon.egl.test.acceptance.AcceptanceTestUtil.run(AcceptanceTestUtil.java:77)
    at org.eclipse.epsilon.egl.test.acceptance.AcceptanceTestUtil.run(AcceptanceTestUtil.java:64)
    at org.eclipse.epsilon.egl.test.acceptance.AcceptanceTestUtil.run(AcceptanceTestUtil.java:50)
    at org.eclipse.epsilon.egl.test.acceptance.AcceptanceTestUtil.test(AcceptanceTestUtil.java:45)
    at org.eclipse.epsilon.egl.test.acceptance.AcceptanceTestUtil.test(AcceptanceTestUtil.java:37)
    at org.eclipse.epsilon.egl.test.acceptance.outdentation.OutdentationTests.test(OutdentationTests.java:66)
    at org.eclipse.epsilon.egl.test.acceptance.outdentation.OutdentationTests.testTemplateOperation(OutdentationTests.java:47)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:757)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: begin 4, end 8, length 4
    at (C:\Users\harr01\AppData\Local\Temp\epsilon\TemplateOperation.egl@4:3-4:6)
    at (C:\Users\harr01\AppData\Local\Temp\epsilon\TemplateOperation.egl@4:3-4:8)
    at (C:\Users\harr01\AppData\Local\Temp\epsilon\TemplateOperation.egl@4:3-4:8)
    at (C:\Users\harr01\AppData\Local\Temp\epsilon\TemplateOperation.egl@1:2-4:18)
    at (C:\Users\harr01\AppData\Local\Temp\epsilon\TemplateOperation.egl@1:0-14:1)

    at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4606)
    at java.base/java.lang.String.substring(String.java:2709)
    at org.eclipse.epsilon.egl.output.OutdentationFormatter.format(OutdentationFormatter.java:61)
    at org.eclipse.epsilon.egl.dom.TemplateOperation.executeBody(TemplateOperation.java:67)
    at org.eclipse.epsilon.egl.dom.TemplateOperation.executeBody(TemplateOperation.java:1)
    at org.eclipse.epsilon.eol.dom.Operation.execute(Operation.java:173)
    at org.eclipse.epsilon.eol.dom.Operation.execute(Operation.java:148)
    at org.eclipse.epsilon.eol.dom.OperationCallExpression.execute(OperationCallExpression.java:157)
    at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeImpl(ExecutorFactory.java:204)
    at org.eclipse.epsilon.eol.execute.ExecutorFactory.execute(ExecutorFactory.java:233)
    at org.eclipse.epsilon.eol.dom.OperationCallExpression.execute(OperationCallExpression.java:148)
    at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeImpl(ExecutorFactory.java:204)
    at org.eclipse.epsilon.eol.execute.ExecutorFactory.execute(ExecutorFactory.java:233)
    at org.eclipse.epsilon.eol.dom.ExpressionStatement.execute(ExpressionStatement.java:31)
    at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeImpl(ExecutorFactory.java:204)
    at org.eclipse.epsilon.eol.execute.ExecutorFactory.execute(ExecutorFactory.java:233)
    at org.eclipse.epsilon.eol.dom.StatementBlock.execute(StatementBlock.java:68)
    at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeImpl(ExecutorFactory.java:204)
    at org.eclipse.epsilon.eol.execute.ExecutorFactory.execute(ExecutorFactory.java:233)
    at org.eclipse.epsilon.eol.EolModule.executeImpl(EolModule.java:480)
    at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeImpl(ExecutorFactory.java:207)
    at org.eclipse.epsilon.eol.execute.ExecutorFactory.execute(ExecutorFactory.java:233)
    at org.eclipse.epsilon.eol.EolModule.execute(EolModule.java:475)
    at org.eclipse.epsilon.egl.internal.EglModule.execute(EglModule.java:170)
    ... 34 more
Caused by: java.lang.StringIndexOutOfBoundsException: begin 4, end 8, length 4