java: .class stub builder migrated to ASM 5

This commit is contained in:
Roman Shevchenko
2014-03-24 17:35:02 +01:00
parent 0240a3efcb
commit f39ed60813
6 changed files with 414 additions and 15 deletions
@@ -40,7 +40,7 @@ import static com.intellij.psi.compiled.ClassFileDecompilers.Full;
public class ClassFileStubBuilder implements BinaryFileStubBuilder {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClassFileStubBuilder");
public static final int STUB_VERSION = 9;
public static final int STUB_VERSION = 10;
@Override
public boolean acceptsFile(@NotNull VirtualFile file) {
@@ -537,9 +537,10 @@ public class ClsFileImpl extends ClsRepositoryPsiElement<PsiClassHolderFileStub>
try {
PsiJavaFileStubImpl stub = new PsiJavaFileStubImpl("do.not.know.yet", true);
StubBuildingVisitor<VirtualFile> visitor = new StubBuildingVisitor<VirtualFile>(file, STRATEGY, stub, 0, file.getNameWithoutExtension());
String className = file.getNameWithoutExtension();
StubBuildingVisitor<VirtualFile> visitor = new StubBuildingVisitor<VirtualFile>(file, STRATEGY, stub, 0, className);
try {
new ClassReader(bytes).accept(visitor, ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES);
new ClassReader(bytes).accept(visitor, ClassReader.SKIP_FRAMES);
}
catch (OutOfOrderInnerClassException e) {
return null;
@@ -56,6 +56,8 @@ public class StubBuildingVisitor<T> extends ClassVisitor {
public static final String FLOAT_NEGATIVE_INF = "-1.0f / 0.0";
public static final String FLOAT_NAN = "0.0f / 0.0";
public static final int ASM_API = Opcodes.ASM5;
@NonNls private static final String SYNTHETIC_CLASS_INIT_METHOD = "<clinit>";
@NonNls private static final String SYNTHETIC_INIT_METHOD = "<init>";
@@ -68,7 +70,7 @@ public class StubBuildingVisitor<T> extends ClassVisitor {
private PsiModifierListStub myModList;
public StubBuildingVisitor(T classSource, InnerClassSourceStrategy<T> innersStrategy, StubElement parent, int access, String shortName) {
super(Opcodes.ASM4);
super(ASM_API);
mySource = classSource;
myInnersStrategy = innersStrategy;
myParent = parent;
@@ -325,7 +327,7 @@ public class StubBuildingVisitor<T> extends ClassVisitor {
if (reader == null) return;
final StubBuildingVisitor<T> classVisitor = new StubBuildingVisitor<T>(innerSource, myInnersStrategy, myResult, access, innerName);
reader.accept(classVisitor, ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES);
reader.accept(classVisitor, ClassReader.SKIP_FRAMES);
}
private static boolean isCorrectName(String name) {
@@ -543,7 +545,7 @@ public class StubBuildingVisitor<T> extends ClassVisitor {
private final String myDesc;
public AnnotationTextCollector(@Nullable String desc, AnnotationResultCallback callback) {
super(Opcodes.ASM4);
super(ASM_API);
myCallback = callback;
myDesc = desc;
@@ -615,7 +617,7 @@ public class StubBuildingVisitor<T> extends ClassVisitor {
private final PsiModifierListStub myModList;
private AnnotationCollectingVisitor(final PsiModifierListStub modList) {
super(Opcodes.ASM4);
super(ASM_API);
myModList = modList;
}
@@ -646,7 +648,7 @@ public class StubBuildingVisitor<T> extends ClassVisitor {
final int paramIgnoreCount,
final int paramCount,
final PsiParameterStubImpl[] paramStubs) {
super(Opcodes.ASM4);
super(ASM_API);
myOwner = owner;
myModList = modList;
myIgnoreCount = ignoreCount;
@@ -0,0 +1,385 @@
// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available
package java.lang;
public final class Class <T> implements java.io.Serializable, java.lang.reflect.GenericDeclaration, java.lang.reflect.Type, java.lang.reflect.AnnotatedElement {
private static final int ANNOTATION = 8192;
private static final int ENUM = 16384;
private static final int SYNTHETIC = 4096;
private transient volatile java.lang.reflect.Constructor<T> cachedConstructor;
private transient volatile java.lang.Class<?> newInstanceCallerCache;
private transient java.lang.String name;
private static java.security.ProtectionDomain allPermDomain;
private static boolean useCaches;
private transient volatile java.lang.ref.SoftReference<java.lang.Class.ReflectionData<T>> reflectionData;
private transient volatile int classRedefinedCount;
private transient volatile sun.reflect.generics.repository.ClassRepository genericInfo;
private static final long serialVersionUID = 3206093459760846163L;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private static sun.reflect.ReflectionFactory reflectionFactory;
private static boolean initted;
private transient volatile T[] enumConstants;
private transient volatile java.util.Map<java.lang.String,T> enumConstantDirectory;
private transient volatile java.lang.Class.AnnotationData annotationData;
private transient volatile sun.reflect.annotation.AnnotationType annotationType;
transient java.lang.ClassValue.ClassValueMap classValueMap;
private static native void registerNatives();
private Class() { /* compiled code */ }
public java.lang.String toString() { /* compiled code */ }
public java.lang.String toGenericString() { /* compiled code */ }
@sun.reflect.CallerSensitive
public static java.lang.Class<?> forName(java.lang.String s) throws java.lang.ClassNotFoundException { /* compiled code */ }
@sun.reflect.CallerSensitive
public static java.lang.Class<?> forName(java.lang.String s, boolean b, java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundException { /* compiled code */ }
private static native java.lang.Class<?> forName0(java.lang.String s, boolean b, java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundException;
@sun.reflect.CallerSensitive
public T newInstance() throws java.lang.InstantiationException, java.lang.IllegalAccessException { /* compiled code */ }
public native boolean isInstance(java.lang.Object o);
public native boolean isAssignableFrom(java.lang.Class<?> aClass);
public native boolean isInterface();
public native boolean isArray();
public native boolean isPrimitive();
public boolean isAnnotation() { /* compiled code */ }
public boolean isSynthetic() { /* compiled code */ }
public java.lang.String getName() { /* compiled code */ }
private native java.lang.String getName0();
@sun.reflect.CallerSensitive
public java.lang.ClassLoader getClassLoader() { /* compiled code */ }
native java.lang.ClassLoader getClassLoader0();
public java.lang.reflect.TypeVariable<java.lang.Class<T>>[] getTypeParameters() { /* compiled code */ }
public native java.lang.Class<? super T> getSuperclass();
public java.lang.reflect.Type getGenericSuperclass() { /* compiled code */ }
public java.lang.Package getPackage() { /* compiled code */ }
public java.lang.Class<?>[] getInterfaces() { /* compiled code */ }
private native java.lang.Class<?>[] getInterfaces0();
public java.lang.reflect.Type[] getGenericInterfaces() { /* compiled code */ }
public native java.lang.Class<?> getComponentType();
public native int getModifiers();
public native java.lang.Object[] getSigners();
native void setSigners(java.lang.Object[] objects);
@sun.reflect.CallerSensitive
public java.lang.reflect.Method getEnclosingMethod() throws java.lang.SecurityException { /* compiled code */ }
private native java.lang.Object[] getEnclosingMethod0();
private java.lang.Class.EnclosingMethodInfo getEnclosingMethodInfo() { /* compiled code */ }
private static java.lang.Class<?> toClass(java.lang.reflect.Type type) { /* compiled code */ }
@sun.reflect.CallerSensitive
public java.lang.reflect.Constructor<?> getEnclosingConstructor() throws java.lang.SecurityException { /* compiled code */ }
@sun.reflect.CallerSensitive
public java.lang.Class<?> getDeclaringClass() throws java.lang.SecurityException { /* compiled code */ }
private native java.lang.Class<?> getDeclaringClass0();
@sun.reflect.CallerSensitive
public java.lang.Class<?> getEnclosingClass() throws java.lang.SecurityException { /* compiled code */ }
public java.lang.String getSimpleName() { /* compiled code */ }
public java.lang.String getTypeName() { /* compiled code */ }
private static boolean isAsciiDigit(char c) { /* compiled code */ }
public java.lang.String getCanonicalName() { /* compiled code */ }
public boolean isAnonymousClass() { /* compiled code */ }
public boolean isLocalClass() { /* compiled code */ }
public boolean isMemberClass() { /* compiled code */ }
private java.lang.String getSimpleBinaryName() { /* compiled code */ }
private boolean isLocalOrAnonymousClass() { /* compiled code */ }
@sun.reflect.CallerSensitive
public java.lang.Class<?>[] getClasses() { /* compiled code */ }
@sun.reflect.CallerSensitive
public java.lang.reflect.Field[] getFields() throws java.lang.SecurityException { /* compiled code */ }
@sun.reflect.CallerSensitive
public java.lang.reflect.Method[] getMethods() throws java.lang.SecurityException { /* compiled code */ }
@sun.reflect.CallerSensitive
public java.lang.reflect.Constructor<?>[] getConstructors() throws java.lang.SecurityException { /* compiled code */ }
@sun.reflect.CallerSensitive
public java.lang.reflect.Field getField(java.lang.String s) throws java.lang.NoSuchFieldException, java.lang.SecurityException { /* compiled code */ }
@sun.reflect.CallerSensitive
public java.lang.reflect.Method getMethod(java.lang.String s, java.lang.Class<?>... classes) throws java.lang.NoSuchMethodException, java.lang.SecurityException { /* compiled code */ }
@sun.reflect.CallerSensitive
public java.lang.reflect.Constructor<T> getConstructor(java.lang.Class<?>... classes) throws java.lang.NoSuchMethodException, java.lang.SecurityException { /* compiled code */ }
@sun.reflect.CallerSensitive
public java.lang.Class<?>[] getDeclaredClasses() throws java.lang.SecurityException { /* compiled code */ }
@sun.reflect.CallerSensitive
public java.lang.reflect.Field[] getDeclaredFields() throws java.lang.SecurityException { /* compiled code */ }
@sun.reflect.CallerSensitive
public java.lang.reflect.Method[] getDeclaredMethods() throws java.lang.SecurityException { /* compiled code */ }
@sun.reflect.CallerSensitive
public java.lang.reflect.Constructor<?>[] getDeclaredConstructors() throws java.lang.SecurityException { /* compiled code */ }
@sun.reflect.CallerSensitive
public java.lang.reflect.Field getDeclaredField(java.lang.String s) throws java.lang.NoSuchFieldException, java.lang.SecurityException { /* compiled code */ }
@sun.reflect.CallerSensitive
public java.lang.reflect.Method getDeclaredMethod(java.lang.String s, java.lang.Class<?>... classes) throws java.lang.NoSuchMethodException, java.lang.SecurityException { /* compiled code */ }
@sun.reflect.CallerSensitive
public java.lang.reflect.Constructor<T> getDeclaredConstructor(java.lang.Class<?>... classes) throws java.lang.NoSuchMethodException, java.lang.SecurityException { /* compiled code */ }
public java.io.InputStream getResourceAsStream(java.lang.String s) { /* compiled code */ }
public java.net.URL getResource(java.lang.String s) { /* compiled code */ }
public java.security.ProtectionDomain getProtectionDomain() { /* compiled code */ }
private native java.security.ProtectionDomain getProtectionDomain0();
static native java.lang.Class<?> getPrimitiveClass(java.lang.String s);
private void checkMemberAccess(int i, java.lang.Class<?> aClass, boolean b) { /* compiled code */ }
private void checkPackageAccess(java.lang.ClassLoader classLoader, boolean b) { /* compiled code */ }
private java.lang.String resolveName(java.lang.String s) { /* compiled code */ }
private java.lang.Class.ReflectionData<T> reflectionData() { /* compiled code */ }
private java.lang.Class.ReflectionData<T> newReflectionData(java.lang.ref.SoftReference<java.lang.Class.ReflectionData<T>> softReference, int i) { /* compiled code */ }
private native java.lang.String getGenericSignature0();
private sun.reflect.generics.factory.GenericsFactory getFactory() { /* compiled code */ }
private sun.reflect.generics.repository.ClassRepository getGenericInfo() { /* compiled code */ }
native byte[] getRawAnnotations();
native byte[] getRawTypeAnnotations();
static byte[] getExecutableTypeAnnotationBytes(java.lang.reflect.Executable executable) { /* compiled code */ }
native sun.reflect.ConstantPool getConstantPool();
private java.lang.reflect.Field[] privateGetDeclaredFields(boolean b) { /* compiled code */ }
private java.lang.reflect.Field[] privateGetPublicFields(java.util.Set<java.lang.Class<?>> set) { /* compiled code */ }
private static void addAll(java.util.Collection<java.lang.reflect.Field> collection, java.lang.reflect.Field[] fields) { /* compiled code */ }
private java.lang.reflect.Constructor<T>[] privateGetDeclaredConstructors(boolean b) { /* compiled code */ }
private java.lang.reflect.Method[] privateGetDeclaredMethods(boolean b) { /* compiled code */ }
private java.lang.reflect.Method[] privateGetPublicMethods() { /* compiled code */ }
private static java.lang.reflect.Field searchFields(java.lang.reflect.Field[] fields, java.lang.String s) { /* compiled code */ }
private java.lang.reflect.Field getField0(java.lang.String s) throws java.lang.NoSuchFieldException { /* compiled code */ }
private static java.lang.reflect.Method searchMethods(java.lang.reflect.Method[] methods, java.lang.String s, java.lang.Class<?>[] classes) { /* compiled code */ }
private java.lang.reflect.Method getMethod0(java.lang.String s, java.lang.Class<?>[] classes, boolean b) { /* compiled code */ }
private java.lang.reflect.Constructor<T> getConstructor0(java.lang.Class<?>[] classes, int i) throws java.lang.NoSuchMethodException { /* compiled code */ }
private static boolean arrayContentsEq(java.lang.Object[] objects, java.lang.Object[] objects1) { /* compiled code */ }
private static java.lang.reflect.Field[] copyFields(java.lang.reflect.Field[] fields) { /* compiled code */ }
private static java.lang.reflect.Method[] copyMethods(java.lang.reflect.Method[] methods) { /* compiled code */ }
private static <U> java.lang.reflect.Constructor<U>[] copyConstructors(java.lang.reflect.Constructor<U>[] constructors) { /* compiled code */ }
private native java.lang.reflect.Field[] getDeclaredFields0(boolean b);
private native java.lang.reflect.Method[] getDeclaredMethods0(boolean b);
private native java.lang.reflect.Constructor<T>[] getDeclaredConstructors0(boolean b);
private native java.lang.Class<?>[] getDeclaredClasses0();
private static java.lang.String argumentTypesToString(java.lang.Class<?>[] classes) { /* compiled code */ }
public boolean desiredAssertionStatus() { /* compiled code */ }
private static native boolean desiredAssertionStatus0(java.lang.Class<?> aClass);
public boolean isEnum() { /* compiled code */ }
private static sun.reflect.ReflectionFactory getReflectionFactory() { /* compiled code */ }
private static void checkInitted() { /* compiled code */ }
public T[] getEnumConstants() { /* compiled code */ }
T[] getEnumConstantsShared() { /* compiled code */ }
java.util.Map<java.lang.String,T> enumConstantDirectory() { /* compiled code */ }
public T cast(java.lang.Object o) { /* compiled code */ }
private java.lang.String cannotCastMsg(java.lang.Object o) { /* compiled code */ }
public <U> java.lang.Class<? extends U> asSubclass(java.lang.Class<U> aClass) { /* compiled code */ }
public <A extends java.lang.annotation.Annotation> A getAnnotation(java.lang.Class<A> aClass) { /* compiled code */ }
public boolean isAnnotationPresent(java.lang.Class<? extends java.lang.annotation.Annotation> aClass) { /* compiled code */ }
public <A extends java.lang.annotation.Annotation> A[] getAnnotationsByType(java.lang.Class<A> aClass) { /* compiled code */ }
public java.lang.annotation.Annotation[] getAnnotations() { /* compiled code */ }
public <A extends java.lang.annotation.Annotation> A getDeclaredAnnotation(java.lang.Class<A> aClass) { /* compiled code */ }
public <A extends java.lang.annotation.Annotation> A[] getDeclaredAnnotationsByType(java.lang.Class<A> aClass) { /* compiled code */ }
public java.lang.annotation.Annotation[] getDeclaredAnnotations() { /* compiled code */ }
private java.lang.Class.AnnotationData annotationData() { /* compiled code */ }
private java.lang.Class.AnnotationData createAnnotationData(int i) { /* compiled code */ }
boolean casAnnotationType(sun.reflect.annotation.AnnotationType annotationType, sun.reflect.annotation.AnnotationType annotationType1) { /* compiled code */ }
sun.reflect.annotation.AnnotationType getAnnotationType() { /* compiled code */ }
java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.lang.annotation.Annotation> getDeclaredAnnotationMap() { /* compiled code */ }
public java.lang.reflect.AnnotatedType getAnnotatedSuperclass() { /* compiled code */ }
public java.lang.reflect.AnnotatedType[] getAnnotatedInterfaces() { /* compiled code */ }
private static class AnnotationData {
final java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.lang.annotation.Annotation> annotations;
final java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.lang.annotation.Annotation> declaredAnnotations;
final int redefinedCount;
AnnotationData(java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.lang.annotation.Annotation> map, java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.lang.annotation.Annotation> map1, int i) { /* compiled code */ }
}
private static class Atomic {
private static final sun.misc.Unsafe unsafe;
private static final long reflectionDataOffset;
private static final long annotationTypeOffset;
private static final long annotationDataOffset;
private Atomic() { /* compiled code */ }
private static long objectFieldOffset(java.lang.reflect.Field[] fields, java.lang.String s) { /* compiled code */ }
static <T> boolean casReflectionData(java.lang.Class<?> aClass, java.lang.ref.SoftReference<java.lang.Class.ReflectionData<T>> softReference, java.lang.ref.SoftReference<java.lang.Class.ReflectionData<T>> softReference1) { /* compiled code */ }
static <T> boolean casAnnotationType(java.lang.Class<?> aClass, sun.reflect.annotation.AnnotationType annotationType, sun.reflect.annotation.AnnotationType annotationType1) { /* compiled code */ }
static <T> boolean casAnnotationData(java.lang.Class<?> aClass, java.lang.Class.AnnotationData annotationData, java.lang.Class.AnnotationData annotationData1) { /* compiled code */ }
}
private static final class EnclosingMethodInfo {
private java.lang.Class<?> enclosingClass;
private java.lang.String name;
private java.lang.String descriptor;
private EnclosingMethodInfo(java.lang.Object[] objects) { /* compiled code */ }
boolean isPartial() { /* compiled code */ }
boolean isConstructor() { /* compiled code */ }
boolean isMethod() { /* compiled code */ }
java.lang.Class<?> getEnclosingClass() { /* compiled code */ }
java.lang.String getName() { /* compiled code */ }
java.lang.String getDescriptor() { /* compiled code */ }
}
static class MethodArray {
private java.lang.reflect.Method[] methods;
private int length;
MethodArray() { /* compiled code */ }
void add(java.lang.reflect.Method method) { /* compiled code */ }
void addAll(java.lang.reflect.Method[] methods) { /* compiled code */ }
void addAll(java.lang.Class.MethodArray methodArray) { /* compiled code */ }
void addIfNotPresent(java.lang.reflect.Method method) { /* compiled code */ }
void addAllIfNotPresent(java.lang.Class.MethodArray methodArray) { /* compiled code */ }
void addAllNonStatic(java.lang.reflect.Method[] methods) { /* compiled code */ }
int length() { /* compiled code */ }
java.lang.reflect.Method get(int i) { /* compiled code */ }
void removeByNameAndSignature(java.lang.reflect.Method method) { /* compiled code */ }
void compactAndTrim() { /* compiled code */ }
java.lang.reflect.Method[] getArray() { /* compiled code */ }
}
private static class ReflectionData <T> {
volatile java.lang.reflect.Field[] declaredFields;
volatile java.lang.reflect.Field[] publicFields;
volatile java.lang.reflect.Method[] declaredMethods;
volatile java.lang.reflect.Method[] publicMethods;
volatile java.lang.reflect.Constructor<T>[] declaredConstructors;
volatile java.lang.reflect.Constructor<T>[] publicConstructors;
volatile java.lang.reflect.Field[] declaredPublicFields;
volatile java.lang.reflect.Method[] declaredPublicMethods;
volatile java.lang.Class<?>[] interfaces;
final int redefinedCount;
ReflectionData(int i) { /* compiled code */ }
}
}
@@ -7,13 +7,13 @@ package org.apache.commons.lang.enum;
public abstract class ValuedEnum extends org.apache.commons.lang.enum.Enum {
private final int iValue;
protected ValuedEnum(java.lang.String s, int i) { /* compiled code */ }
protected ValuedEnum(java.lang.String name, int value) { /* compiled code */ }
protected static org.apache.commons.lang.enum.Enum getEnum(java.lang.Class aClass, int i) { /* compiled code */ }
protected static org.apache.commons.lang.enum.Enum getEnum(java.lang.Class enumClass, int value) { /* compiled code */ }
public final int getValue() { /* compiled code */ }
public int compareTo(java.lang.Object o) { /* compiled code */ }
public int compareTo(java.lang.Object other) { /* compiled code */ }
public java.lang.String toString() { /* compiled code */ }
}
@@ -18,8 +18,10 @@ package com.intellij.psi;
import com.intellij.JavaTestUtil;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileSystem;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.impl.compiled.ClsFileImpl;
@@ -52,7 +54,7 @@ public class ClsMirrorBuildingTest extends LightIdeaTestCase {
public void testLocalClass() { doTest(); }
public void testBounds() { doTest(); }
public void testTextPsiMismatch() throws Exception {
public void testTextPsiMismatch() {
CommonCodeStyleSettings.IndentOptions options =
CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().getIndentOptions(JavaFileType.INSTANCE);
int indent = options.INDENT_SIZE;
@@ -65,22 +67,31 @@ public class ClsMirrorBuildingTest extends LightIdeaTestCase {
}
}
public void testJdk8Class() {
String testDir = JavaTestUtil.getJavaTestDataPath();
String clsPath = testDir + "/../../mockJDK-1.8/jre/lib/rt.jar!/java/lang/Class.class";
String txtPath = testDir + "/psi/cls/mirror/" + "Class.txt";
doTest(clsPath, txtPath);
}
private void doTest() {
doTest(getTestName(false));
}
private static void doTest(String name) {
String testDir = JavaTestUtil.getJavaTestDataPath() + "/psi/cls/mirror/";
doTest(testDir + "pkg/" + name + ".class", testDir + name + ".txt");
}
String clsPath = testDir + "pkg/" + name + ".class";
VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(clsPath);
private static void doTest(String clsPath, String txtPath) {
VirtualFileSystem fs = clsPath.contains("!/") ? JarFileSystem.getInstance() : LocalFileSystem.getInstance();
VirtualFile vFile = fs.findFileByPath(clsPath);
assertNotNull(clsPath, vFile);
PsiFile clsFile = getPsiManager().findFile(vFile);
assertNotNull(vFile.getPath(), clsFile);
String expected;
try {
String txtPath = testDir + name + ".txt";
expected = StringUtil.trimTrailing(PlatformTestUtil.loadFileText(txtPath));
}
catch (IOException e) {