|
29 | 29 | import java.util.stream.StreamSupport; |
30 | 30 |
|
31 | 31 | import javax.lang.model.element.ElementKind; |
| 32 | +import javax.lang.model.type.PrimitiveType; |
| 33 | +import javax.lang.model.type.TypeKind; |
32 | 34 | import javax.tools.JavaFileObject; |
33 | 35 |
|
34 | 36 | import org.eclipse.core.runtime.ILog; |
@@ -192,8 +194,21 @@ public VarSymbol create(Symbol owner, CachingClassSymbolClassReader reader) { |
192 | 194 | res.setData(ElementKind.EXCEPTION_PARAMETER); |
193 | 195 | } else if (isDataResourceVariable) { |
194 | 196 | res.setData(ElementKind.RESOURCE_VARIABLE); |
195 | | - } else { |
196 | | - res.setData(this.constantValue); |
| 197 | + } else if (this.constantValue != null) { |
| 198 | + Object o = this.constantValue; |
| 199 | + // In ClassReader AttributeReader(names.ConstantValue), we see that |
| 200 | + // integer non-Long types are expected to be stored as Integers in symbol |
| 201 | + if (res.type instanceof PrimitiveType primitive) { |
| 202 | + if (TypeKind.BOOLEAN == primitive.getKind() && o instanceof Boolean b) { |
| 203 | + // as per https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.html#jvms-2.3.4 |
| 204 | + o = Integer.valueOf(b.booleanValue() ? 1 : 0); |
| 205 | + } else if (TypeKind.CHAR == primitive.getKind() && o instanceof Character c) { |
| 206 | + o = Integer.valueOf((int)c.charValue()); |
| 207 | + } else if (TypeKind.BYTE == primitive.getKind() && o instanceof Byte b) { |
| 208 | + o = Integer.valueOf((int)b.byteValue()); |
| 209 | + } |
| 210 | + } |
| 211 | + res.setData(o); |
197 | 212 | } |
198 | 213 | this.metadata.applyTo(res, reader); |
199 | 214 | reader.localAnnotate.normal(res, this.toAnnotate); |
|
0 commit comments