1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.core.type.classreading;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.EmptyVisitor;
import org.springframework.core.type.ClassMetadata;
import org.springframework.util.ClassUtils;
/**
* ASM class visitor which looks only for the class name and implemented types,
* exposing them through the {@link org.springframework.core.type.ClassMetadata}
* interface.
*
* @author Rod Johnson
* @author Costin Leau
* @author Mark Fisher
* @author Ramnivas Laddad
* @since 2.5
*/
class ClassMetadataReadingVisitor implements ClassVisitor, ClassMetadata {
private String className;
private boolean isInterface;
private boolean isAbstract;
private boolean isFinal;
private String enclosingClassName;
private boolean independentInnerClass;
private String superClassName;
private String[] interfaces;
public void visit(int version, int access, String name, String signature, String supername, String[] interfaces) {
this.className = ClassUtils.convertResourcePathToClassName(name);
this.isInterface = ((access & Opcodes.ACC_INTERFACE) != 0);
this.isAbstract = ((access & Opcodes.ACC_ABSTRACT) != 0);
this.isFinal = ((access & Opcodes.ACC_FINAL) != 0);
if (supername != null) {
this.superClassName = ClassUtils.convertResourcePathToClassName(supername);
}
this.interfaces = new String[interfaces.length];
for (int i = 0; i < interfaces.length; i++) {
this.interfaces[i] = ClassUtils.convertResourcePathToClassName(interfaces[i]);
}
}
public void visitOuterClass(String owner, String name, String desc) {
this.enclosingClassName = ClassUtils.convertResourcePathToClassName(owner);
}
public void visitInnerClass(String name, String outerName, String innerName, int access) {
if (outerName != null && this.className.equals(ClassUtils.convertResourcePathToClassName(name))) {
this.enclosingClassName = ClassUtils.convertResourcePathToClassName(outerName);
this.independentInnerClass = ((access & Opcodes.ACC_STATIC) != 0);
}
}
public void visitSource(String source, String debug) {
// no-op
}
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
// no-op
return new EmptyVisitor();
}
public void visitAttribute(Attribute attr) {
// no-op
}
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
// no-op
return new EmptyVisitor();
}
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
// no-op
return new EmptyVisitor();
}
public void visitEnd() {
// no-op
}
public String getClassName() {
return this.className;
}
public boolean isInterface() {
return this.isInterface;
}
public boolean isAbstract() {
return this.isAbstract;
}
public boolean isConcrete() {
return !(this.isInterface || this.isAbstract);
}
public boolean isFinal() {
return this.isFinal;
}
public boolean isIndependent() {
return (this.enclosingClassName == null || this.independentInnerClass);
}
public boolean hasEnclosingClass() {
return (this.enclosingClassName != null);
}
public String getEnclosingClassName() {
return this.enclosingClassName;
}
public boolean hasSuperClass() {
return (this.superClassName != null);
}
public String getSuperClassName() {
return this.superClassName;
}
public String[] getInterfaceNames() {
return this.interfaces;
}
}
|