mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Decompile chars, bytes and shorts correctly
This commit is contained in:
committed by
Roman Shevchenko
parent
80087098e8
commit
da958ab49c
@@ -17,9 +17,7 @@ package com.intellij.psi.impl.compiled;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.CommonClassNames;
|
||||
import com.intellij.psi.PsiNameHelper;
|
||||
import com.intellij.psi.PsiReferenceList;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.cache.ModifierFlags;
|
||||
import com.intellij.psi.impl.cache.TypeInfo;
|
||||
import com.intellij.psi.impl.java.stubs.*;
|
||||
@@ -340,7 +338,7 @@ public class StubBuildingVisitor<T> extends ClassVisitor {
|
||||
|
||||
byte flags = PsiFieldStubImpl.packFlags((access & Opcodes.ACC_ENUM) != 0, (access & Opcodes.ACC_DEPRECATED) != 0, false);
|
||||
TypeInfo type = fieldType(desc, signature);
|
||||
String initializer = constToString(value, "boolean".equals(type.text.getString()), false);
|
||||
String initializer = constToString(value, type.text.getString(), false);
|
||||
PsiFieldStub stub = new PsiFieldStubImpl(myResult, name, type, initializer, flags);
|
||||
PsiModifierListStub modList = new PsiModifierListStubImpl(stub, packFieldFlags(access));
|
||||
return new AnnotationCollectingVisitor(modList);
|
||||
@@ -537,7 +535,7 @@ public class StubBuildingVisitor<T> extends ClassVisitor {
|
||||
@Override
|
||||
public void visit(final String name, final Object value) {
|
||||
valuePairPrefix(name);
|
||||
myBuilder.append(constToString(value, false, true));
|
||||
myBuilder.append(constToString(value, null, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -697,18 +695,33 @@ public class StubBuildingVisitor<T> extends ClassVisitor {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String constToString(@Nullable Object value, boolean isBoolean, boolean anno) {
|
||||
private static String constToString(@Nullable Object value, @Nullable String type, boolean anno) {
|
||||
if (value == null) return null;
|
||||
|
||||
if (value instanceof String) return "\"" + StringUtil.escapeStringCharacters((String)value) + "\"";
|
||||
if (value instanceof Boolean) return value.toString();
|
||||
if (value instanceof Long) return value.toString() + "L";
|
||||
if (value instanceof String) {
|
||||
return "\"" + StringUtil.escapeStringCharacters((String)value) + "\"";
|
||||
}
|
||||
|
||||
if (value instanceof Boolean || value instanceof Short || value instanceof Byte) {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
if (value instanceof Character) {
|
||||
return "'" + value.toString() + "'";
|
||||
}
|
||||
|
||||
if (value instanceof Long) {
|
||||
return value.toString() + "L";
|
||||
}
|
||||
|
||||
if (value instanceof Integer) {
|
||||
if (isBoolean) {
|
||||
if ("boolean".equals(type)) {
|
||||
if (value.equals(0)) return "false";
|
||||
if (value.equals(1)) return "true";
|
||||
}
|
||||
if ("char".equals(type)) {
|
||||
return "'" + ((char)((Integer)value).intValue()) + "'";
|
||||
}
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
|
||||
// IntelliJ API Decompiler stub source generated from a class file
|
||||
// Implementation of methods is not available
|
||||
|
||||
package pkg;
|
||||
|
||||
class Booleans {
|
||||
public static final boolean TRUE = true;
|
||||
public static final boolean FALSE = false;
|
||||
|
||||
Booleans() { /* compiled code */ }
|
||||
|
||||
@pkg.BooleanAnno(true)
|
||||
public static boolean TRUE() { /* compiled code */ }
|
||||
|
||||
@pkg.BooleanAnno(false)
|
||||
public static boolean FALSE() { /* compiled code */ }
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
// IntelliJ API Decompiler stub source generated from a class file
|
||||
// Implementation of methods is not available
|
||||
|
||||
package pkg;
|
||||
|
||||
class Primitives {
|
||||
public static final boolean TRUE = true;
|
||||
public static final boolean FALSE = false;
|
||||
public static final byte BYTE = 1;
|
||||
public static final char CHAR = 'c';
|
||||
public static final short SHORT = 42;
|
||||
public static final int INT = 42;
|
||||
public static final long LONG = 42L;
|
||||
|
||||
Primitives() { /* compiled code */ }
|
||||
|
||||
@pkg.BooleanAnno(true)
|
||||
public static boolean TRUE() { /* compiled code */ }
|
||||
|
||||
@pkg.BooleanAnno(false)
|
||||
public static boolean FALSE() { /* compiled code */ }
|
||||
|
||||
@pkg.ByteAnno(1)
|
||||
@pkg.CharAnno('c')
|
||||
@pkg.ShortAnno(42)
|
||||
@pkg.IntAnno(42)
|
||||
@pkg.LongAnno(42L)
|
||||
public static void m() { /* compiled code */ }
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,13 +0,0 @@
|
||||
package pkg;
|
||||
|
||||
class Booleans {
|
||||
public static final boolean TRUE = true;
|
||||
public static final boolean FALSE = false;
|
||||
|
||||
@BooleanAnno(true) public static boolean TRUE() { return TRUE; }
|
||||
@BooleanAnno(false) public static boolean FALSE() { return FALSE; }
|
||||
}
|
||||
|
||||
@interface BooleanAnno {
|
||||
boolean value();
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package pkg;
|
||||
|
||||
class Primitives {
|
||||
public static final boolean TRUE = true;
|
||||
public static final boolean FALSE = false;
|
||||
|
||||
@BooleanAnno(true) public static boolean TRUE() { return TRUE; }
|
||||
@BooleanAnno(false) public static boolean FALSE() { return FALSE; }
|
||||
|
||||
public static final byte BYTE = 1;
|
||||
public static final char CHAR = 'c';
|
||||
public static final short SHORT = 42;
|
||||
public static final int INT = 42;
|
||||
public static final long LONG = 42L;
|
||||
|
||||
@ByteAnno(1) @CharAnno('c') @ShortAnno(42) @IntAnno(42) @LongAnno(42L)
|
||||
public static void m() { }
|
||||
}
|
||||
|
||||
@interface BooleanAnno {
|
||||
boolean value();
|
||||
}
|
||||
|
||||
@interface ByteAnno {
|
||||
byte value();
|
||||
}
|
||||
|
||||
@interface CharAnno {
|
||||
char value();
|
||||
}
|
||||
|
||||
@interface ShortAnno {
|
||||
short value();
|
||||
}
|
||||
|
||||
@interface IntAnno {
|
||||
int value();
|
||||
}
|
||||
|
||||
@interface LongAnno {
|
||||
long value();
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class ClsMirrorBuildingTest extends LightIdeaTestCase {
|
||||
public void testMethodReceiver() { doTest(); }
|
||||
public void testPackageInfo() { doTest("package-info"); }
|
||||
public void testEA40568() { doTest(); }
|
||||
public void testBooleans() { doTest(); }
|
||||
public void testPrimitives() { doTest(); }
|
||||
public void testClassRefs() { doTest(); }
|
||||
public void testEA46236() { doTest("ValuedEnum"); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user