Changed: Spaces around ternar operators, parenthesis on ternar inside ternat

This commit is contained in:
Jindra Petřík
2021-03-04 19:14:09 +01:00
parent 7f57039f18
commit 07f72acd06
2 changed files with 27 additions and 3 deletions

View File

@@ -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);
expression.toString(writer, localData);
if (expression.getPrecedence() >= precedence){
writer.append(")");
}
writer.append(" ? ");
if (onTrue instanceof TernarOpItem){ //ternar in ternar better in parenthesis
writer.append("(");
}
onTrue.toString(writer, localData);
onTrue.toString(writer, localData);
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;
}