diff --git a/CHANGELOG.md b/CHANGELOG.md index 40737b577..ea51d7b0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,9 @@ All notable changes to this project will be documented in this file. ### Removed - #1631 ActiveX Flash component download in windows installer +### Changed +- Spaces around ternar operators, parenthesis on ternar inside ternat + ## [14.0.1] - 2021-02-26 ### Added - AS3 goto definition on imports diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/TernarOpItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/TernarOpItem.java index e45abc7e3..9ff28ef1a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/TernarOpItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/TernarOpItem.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.graph.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; @@ -51,11 +52,31 @@ public class TernarOpItem extends GraphTargetItem { @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { + if (expression.getPrecedence() >= precedence){ + writer.append("("); + } expression.toString(writer, localData); - writer.append("?"); + if (expression.getPrecedence() >= precedence){ + writer.append(")"); + } + writer.append(" ? "); + + if (onTrue instanceof TernarOpItem){ //ternar in ternar better in parenthesis + writer.append("("); + } onTrue.toString(writer, localData); - writer.append(":"); + if (onTrue instanceof TernarOpItem){ + writer.append(")"); + } + writer.append(" : "); + if (onFalse instanceof TernarOpItem){ + writer.append("("); + } onFalse.toString(writer, localData); + if (onFalse instanceof TernarOpItem){ + writer.append(")"); + } + return writer; }