12
12
import java .util .BitSet ;
13
13
14
14
public class KVarExprent extends VarExprent implements KExprent {
15
- private boolean isExceptionType ;
15
+ public enum DeclarationType {
16
+ DEFINITION ,
17
+ USAGE ,
18
+ FOR_LOOP_VARIABLE ,
19
+ EXCEPTION_TYPE ,
20
+ }
21
+
22
+ private DeclarationType declarationType ;
16
23
17
24
public KVarExprent (int index , VarType varType , VarProcessor processor , BitSet bytecode ) {
18
25
super (index , varType , processor , bytecode );
@@ -27,6 +34,11 @@ public KVarExprent(VarExprent ex) {
27
34
// this.setLVT(ex.getLVT());
28
35
this .setEffectivelyFinal (ex .isEffectivelyFinal ());
29
36
this .setDefinition (ex .isDefinition ());
37
+ if (ex instanceof KVarExprent kVarExprent ) {
38
+ declarationType = kVarExprent .declarationType ;
39
+ } else {
40
+ declarationType = ex .isDefinition () ? DeclarationType .DEFINITION : DeclarationType .USAGE ;
41
+ }
30
42
}
31
43
32
44
@ Override
@@ -46,8 +58,7 @@ public TextBuffer toJava(int indent) {
46
58
47
59
buffer .addBytecodeMapping (bytecode );
48
60
49
- boolean definition = isDefinition ();
50
- if (definition && !isExceptionType ) {
61
+ if (declarationType == DeclarationType .DEFINITION ) {
51
62
VarProcessor processor = getProcessor ();
52
63
53
64
boolean isFinal = isEffectivelyFinal () ||
@@ -58,16 +69,16 @@ public TextBuffer toJava(int indent) {
58
69
59
70
buffer .append (getName ());
60
71
61
- if (definition || isExceptionType ) {
72
+ if (declarationType == DeclarationType . DEFINITION || declarationType == DeclarationType . EXCEPTION_TYPE ) {
62
73
buffer .append (": " );
63
74
buffer .append (KTypes .getKotlinType (getDefinitionVarType ()));
64
75
}
65
76
66
77
return buffer ;
67
78
}
68
79
69
- public void setExceptionType ( boolean isExceptionType ) {
70
- this .isExceptionType = isExceptionType ;
80
+ public void setDeclarationType ( DeclarationType declarationType ) {
81
+ this .declarationType = declarationType ;
71
82
}
72
83
73
84
@ Override
0 commit comments