feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,85 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file:
*
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000-2011 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package jdk.internal.org.objectweb.asm.util;
import java.util.Map;
import jdk.internal.org.objectweb.asm.Label;
/**
* An {@link jdk.internal.org.objectweb.asm.Attribute Attribute} that can print the ASM code
* to create an equivalent attribute.
*
* @author Eugene Kuleshov
*/
public interface ASMifiable {
/**
* Prints the ASM code to create an attribute equal to this attribute.
*
* @param buf
* a buffer used for printing Java code.
* @param varName
* name of the variable in a printed code used to store attribute
* instance.
* @param labelNames
* map of label instances to their names.
*/
void asmify(StringBuffer buf, String varName, Map<Label, String> labelNames);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,165 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file:
*
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000-2011 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package jdk.internal.org.objectweb.asm.util;
import jdk.internal.org.objectweb.asm.AnnotationVisitor;
import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.internal.org.objectweb.asm.Type;
/**
* An {@link AnnotationVisitor} that checks that its methods are properly used.
*
* @author Eric Bruneton
*/
public class CheckAnnotationAdapter extends AnnotationVisitor {
private final boolean named;
private boolean end;
public CheckAnnotationAdapter(final AnnotationVisitor av) {
this(av, true);
}
CheckAnnotationAdapter(final AnnotationVisitor av, final boolean named) {
super(Opcodes.ASM5, av);
this.named = named;
}
@Override
public void visit(final String name, final Object value) {
checkEnd();
checkName(name);
if (!(value instanceof Byte || value instanceof Boolean
|| value instanceof Character || value instanceof Short
|| value instanceof Integer || value instanceof Long
|| value instanceof Float || value instanceof Double
|| value instanceof String || value instanceof Type
|| value instanceof byte[] || value instanceof boolean[]
|| value instanceof char[] || value instanceof short[]
|| value instanceof int[] || value instanceof long[]
|| value instanceof float[] || value instanceof double[])) {
throw new IllegalArgumentException("Invalid annotation value");
}
if (value instanceof Type) {
int sort = ((Type) value).getSort();
if (sort == Type.METHOD) {
throw new IllegalArgumentException("Invalid annotation value");
}
}
if (av != null) {
av.visit(name, value);
}
}
@Override
public void visitEnum(final String name, final String desc,
final String value) {
checkEnd();
checkName(name);
CheckMethodAdapter.checkDesc(desc, false);
if (value == null) {
throw new IllegalArgumentException("Invalid enum value");
}
if (av != null) {
av.visitEnum(name, desc, value);
}
}
@Override
public AnnotationVisitor visitAnnotation(final String name,
final String desc) {
checkEnd();
checkName(name);
CheckMethodAdapter.checkDesc(desc, false);
return new CheckAnnotationAdapter(av == null ? null
: av.visitAnnotation(name, desc));
}
@Override
public AnnotationVisitor visitArray(final String name) {
checkEnd();
checkName(name);
return new CheckAnnotationAdapter(av == null ? null
: av.visitArray(name), false);
}
@Override
public void visitEnd() {
checkEnd();
end = true;
if (av != null) {
av.visitEnd();
}
}
private void checkEnd() {
if (end) {
throw new IllegalStateException(
"Cannot call a visit method after visitEnd has been called");
}
}
private void checkName(final String name) {
if (named && name == null) {
throw new IllegalArgumentException(
"Annotation value name must not be null");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,151 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file:
*
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000-2011 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package jdk.internal.org.objectweb.asm.util;
import jdk.internal.org.objectweb.asm.AnnotationVisitor;
import jdk.internal.org.objectweb.asm.Attribute;
import jdk.internal.org.objectweb.asm.FieldVisitor;
import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.internal.org.objectweb.asm.TypePath;
import jdk.internal.org.objectweb.asm.TypeReference;
/**
* A {@link FieldVisitor} that checks that its methods are properly used.
*/
public class CheckFieldAdapter extends FieldVisitor {
private boolean end;
/**
* Constructs a new {@link CheckFieldAdapter}. <i>Subclasses must not use
* this constructor</i>. Instead, they must use the
* {@link #CheckFieldAdapter(int, FieldVisitor)} version.
*
* @param fv
* the field visitor to which this adapter must delegate calls.
* @throws IllegalStateException
* If a subclass calls this constructor.
*/
public CheckFieldAdapter(final FieldVisitor fv) {
this(Opcodes.ASM5, fv);
if (getClass() != CheckFieldAdapter.class) {
throw new IllegalStateException();
}
}
/**
* Constructs a new {@link CheckFieldAdapter}.
*
* @param api
* the ASM API version implemented by this visitor. Must be one
* of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.
* @param fv
* the field visitor to which this adapter must delegate calls.
*/
protected CheckFieldAdapter(final int api, final FieldVisitor fv) {
super(api, fv);
}
@Override
public AnnotationVisitor visitAnnotation(final String desc,
final boolean visible) {
checkEnd();
CheckMethodAdapter.checkDesc(desc, false);
return new CheckAnnotationAdapter(super.visitAnnotation(desc, visible));
}
@Override
public AnnotationVisitor visitTypeAnnotation(final int typeRef,
final TypePath typePath, final String desc, final boolean visible) {
checkEnd();
int sort = typeRef >>> 24;
if (sort != TypeReference.FIELD) {
throw new IllegalArgumentException("Invalid type reference sort 0x"
+ Integer.toHexString(sort));
}
CheckClassAdapter.checkTypeRefAndPath(typeRef, typePath);
CheckMethodAdapter.checkDesc(desc, false);
return new CheckAnnotationAdapter(super.visitTypeAnnotation(typeRef,
typePath, desc, visible));
}
@Override
public void visitAttribute(final Attribute attr) {
checkEnd();
if (attr == null) {
throw new IllegalArgumentException(
"Invalid attribute (must not be null)");
}
super.visitAttribute(attr);
}
@Override
public void visitEnd() {
checkEnd();
end = true;
super.visitEnd();
}
private void checkEnd() {
if (end) {
throw new IllegalStateException(
"Cannot call a visit method after visitEnd has been called");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,359 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file:
*
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000-2011 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package jdk.internal.org.objectweb.asm.util;
import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.internal.org.objectweb.asm.signature.SignatureVisitor;
/**
* A {@link SignatureVisitor} that checks that its methods are properly used.
*
* @author Eric Bruneton
*/
public class CheckSignatureAdapter extends SignatureVisitor {
/**
* Type to be used to check class signatures. See
* {@link #CheckSignatureAdapter(int, SignatureVisitor)
* CheckSignatureAdapter}.
*/
public static final int CLASS_SIGNATURE = 0;
/**
* Type to be used to check method signatures. See
* {@link #CheckSignatureAdapter(int, SignatureVisitor)
* CheckSignatureAdapter}.
*/
public static final int METHOD_SIGNATURE = 1;
/**
* Type to be used to check type signatures.See
* {@link #CheckSignatureAdapter(int, SignatureVisitor)
* CheckSignatureAdapter}.
*/
public static final int TYPE_SIGNATURE = 2;
private static final int EMPTY = 1;
private static final int FORMAL = 2;
private static final int BOUND = 4;
private static final int SUPER = 8;
private static final int PARAM = 16;
private static final int RETURN = 32;
private static final int SIMPLE_TYPE = 64;
private static final int CLASS_TYPE = 128;
private static final int END = 256;
/**
* Type of the signature to be checked.
*/
private final int type;
/**
* State of the automaton used to check the order of method calls.
*/
private int state;
/**
* <tt>true</tt> if the checked type signature can be 'V'.
*/
private boolean canBeVoid;
/**
* The visitor to which this adapter must delegate calls. May be
* <tt>null</tt>.
*/
private final SignatureVisitor sv;
/**
* Creates a new {@link CheckSignatureAdapter} object. <i>Subclasses must
* not use this constructor</i>. Instead, they must use the
* {@link #CheckSignatureAdapter(int, int, SignatureVisitor)} version.
*
* @param type
* the type of signature to be checked. See
* {@link #CLASS_SIGNATURE}, {@link #METHOD_SIGNATURE} and
* {@link #TYPE_SIGNATURE}.
* @param sv
* the visitor to which this adapter must delegate calls. May be
* <tt>null</tt>.
*/
public CheckSignatureAdapter(final int type, final SignatureVisitor sv) {
this(Opcodes.ASM5, type, sv);
}
/**
* Creates a new {@link CheckSignatureAdapter} object.
*
* @param api
* the ASM API version implemented by this visitor. Must be one
* of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.
* @param type
* the type of signature to be checked. See
* {@link #CLASS_SIGNATURE}, {@link #METHOD_SIGNATURE} and
* {@link #TYPE_SIGNATURE}.
* @param sv
* the visitor to which this adapter must delegate calls. May be
* <tt>null</tt>.
*/
protected CheckSignatureAdapter(final int api, final int type,
final SignatureVisitor sv) {
super(api);
this.type = type;
this.state = EMPTY;
this.sv = sv;
}
// class and method signatures
@Override
public void visitFormalTypeParameter(final String name) {
if (type == TYPE_SIGNATURE
|| (state != EMPTY && state != FORMAL && state != BOUND)) {
throw new IllegalStateException();
}
CheckMethodAdapter.checkIdentifier(name, "formal type parameter");
state = FORMAL;
if (sv != null) {
sv.visitFormalTypeParameter(name);
}
}
@Override
public SignatureVisitor visitClassBound() {
if (state != FORMAL) {
throw new IllegalStateException();
}
state = BOUND;
SignatureVisitor v = sv == null ? null : sv.visitClassBound();
return new CheckSignatureAdapter(TYPE_SIGNATURE, v);
}
@Override
public SignatureVisitor visitInterfaceBound() {
if (state != FORMAL && state != BOUND) {
throw new IllegalArgumentException();
}
SignatureVisitor v = sv == null ? null : sv.visitInterfaceBound();
return new CheckSignatureAdapter(TYPE_SIGNATURE, v);
}
// class signatures
@Override
public SignatureVisitor visitSuperclass() {
if (type != CLASS_SIGNATURE || (state & (EMPTY | FORMAL | BOUND)) == 0) {
throw new IllegalArgumentException();
}
state = SUPER;
SignatureVisitor v = sv == null ? null : sv.visitSuperclass();
return new CheckSignatureAdapter(TYPE_SIGNATURE, v);
}
@Override
public SignatureVisitor visitInterface() {
if (state != SUPER) {
throw new IllegalStateException();
}
SignatureVisitor v = sv == null ? null : sv.visitInterface();
return new CheckSignatureAdapter(TYPE_SIGNATURE, v);
}
// method signatures
@Override
public SignatureVisitor visitParameterType() {
if (type != METHOD_SIGNATURE
|| (state & (EMPTY | FORMAL | BOUND | PARAM)) == 0) {
throw new IllegalArgumentException();
}
state = PARAM;
SignatureVisitor v = sv == null ? null : sv.visitParameterType();
return new CheckSignatureAdapter(TYPE_SIGNATURE, v);
}
@Override
public SignatureVisitor visitReturnType() {
if (type != METHOD_SIGNATURE
|| (state & (EMPTY | FORMAL | BOUND | PARAM)) == 0) {
throw new IllegalArgumentException();
}
state = RETURN;
SignatureVisitor v = sv == null ? null : sv.visitReturnType();
CheckSignatureAdapter cv = new CheckSignatureAdapter(TYPE_SIGNATURE, v);
cv.canBeVoid = true;
return cv;
}
@Override
public SignatureVisitor visitExceptionType() {
if (state != RETURN) {
throw new IllegalStateException();
}
SignatureVisitor v = sv == null ? null : sv.visitExceptionType();
return new CheckSignatureAdapter(TYPE_SIGNATURE, v);
}
// type signatures
@Override
public void visitBaseType(final char descriptor) {
if (type != TYPE_SIGNATURE || state != EMPTY) {
throw new IllegalStateException();
}
if (descriptor == 'V') {
if (!canBeVoid) {
throw new IllegalArgumentException();
}
} else {
if ("ZCBSIFJD".indexOf(descriptor) == -1) {
throw new IllegalArgumentException();
}
}
state = SIMPLE_TYPE;
if (sv != null) {
sv.visitBaseType(descriptor);
}
}
@Override
public void visitTypeVariable(final String name) {
if (type != TYPE_SIGNATURE || state != EMPTY) {
throw new IllegalStateException();
}
CheckMethodAdapter.checkIdentifier(name, "type variable");
state = SIMPLE_TYPE;
if (sv != null) {
sv.visitTypeVariable(name);
}
}
@Override
public SignatureVisitor visitArrayType() {
if (type != TYPE_SIGNATURE || state != EMPTY) {
throw new IllegalStateException();
}
state = SIMPLE_TYPE;
SignatureVisitor v = sv == null ? null : sv.visitArrayType();
return new CheckSignatureAdapter(TYPE_SIGNATURE, v);
}
@Override
public void visitClassType(final String name) {
if (type != TYPE_SIGNATURE || state != EMPTY) {
throw new IllegalStateException();
}
CheckMethodAdapter.checkInternalName(name, "class name");
state = CLASS_TYPE;
if (sv != null) {
sv.visitClassType(name);
}
}
@Override
public void visitInnerClassType(final String name) {
if (state != CLASS_TYPE) {
throw new IllegalStateException();
}
CheckMethodAdapter.checkIdentifier(name, "inner class name");
if (sv != null) {
sv.visitInnerClassType(name);
}
}
@Override
public void visitTypeArgument() {
if (state != CLASS_TYPE) {
throw new IllegalStateException();
}
if (sv != null) {
sv.visitTypeArgument();
}
}
@Override
public SignatureVisitor visitTypeArgument(final char wildcard) {
if (state != CLASS_TYPE) {
throw new IllegalStateException();
}
if ("+-=".indexOf(wildcard) == -1) {
throw new IllegalArgumentException();
}
SignatureVisitor v = sv == null ? null : sv.visitTypeArgument(wildcard);
return new CheckSignatureAdapter(TYPE_SIGNATURE, v);
}
@Override
public void visitEnd() {
if (state != CLASS_TYPE) {
throw new IllegalStateException();
}
state = END;
if (sv != null) {
sv.visitEnd();
}
}
}

View File

@@ -0,0 +1,618 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file:
*
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000-2011 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package jdk.internal.org.objectweb.asm.util;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import jdk.internal.org.objectweb.asm.Attribute;
import jdk.internal.org.objectweb.asm.Handle;
import jdk.internal.org.objectweb.asm.Label;
import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.internal.org.objectweb.asm.TypePath;
/**
* An abstract converter from visit events to text.
*
* @author Eric Bruneton
*/
public abstract class Printer {
/**
* The names of the Java Virtual Machine opcodes.
*/
public static final String[] OPCODES;
/**
* The names of the for <code>operand</code> parameter values of the
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitIntInsn} method when
* <code>opcode</code> is <code>NEWARRAY</code>.
*/
public static final String[] TYPES;
/**
* The names of the <code>tag</code> field values for
* {@link jdk.internal.org.objectweb.asm.Handle}.
*/
public static final String[] HANDLE_TAG;
static {
String s = "NOP,ACONST_NULL,ICONST_M1,ICONST_0,ICONST_1,ICONST_2,"
+ "ICONST_3,ICONST_4,ICONST_5,LCONST_0,LCONST_1,FCONST_0,"
+ "FCONST_1,FCONST_2,DCONST_0,DCONST_1,BIPUSH,SIPUSH,LDC,,,"
+ "ILOAD,LLOAD,FLOAD,DLOAD,ALOAD,,,,,,,,,,,,,,,,,,,,,IALOAD,"
+ "LALOAD,FALOAD,DALOAD,AALOAD,BALOAD,CALOAD,SALOAD,ISTORE,"
+ "LSTORE,FSTORE,DSTORE,ASTORE,,,,,,,,,,,,,,,,,,,,,IASTORE,"
+ "LASTORE,FASTORE,DASTORE,AASTORE,BASTORE,CASTORE,SASTORE,POP,"
+ "POP2,DUP,DUP_X1,DUP_X2,DUP2,DUP2_X1,DUP2_X2,SWAP,IADD,LADD,"
+ "FADD,DADD,ISUB,LSUB,FSUB,DSUB,IMUL,LMUL,FMUL,DMUL,IDIV,LDIV,"
+ "FDIV,DDIV,IREM,LREM,FREM,DREM,INEG,LNEG,FNEG,DNEG,ISHL,LSHL,"
+ "ISHR,LSHR,IUSHR,LUSHR,IAND,LAND,IOR,LOR,IXOR,LXOR,IINC,I2L,"
+ "I2F,I2D,L2I,L2F,L2D,F2I,F2L,F2D,D2I,D2L,D2F,I2B,I2C,I2S,LCMP,"
+ "FCMPL,FCMPG,DCMPL,DCMPG,IFEQ,IFNE,IFLT,IFGE,IFGT,IFLE,"
+ "IF_ICMPEQ,IF_ICMPNE,IF_ICMPLT,IF_ICMPGE,IF_ICMPGT,IF_ICMPLE,"
+ "IF_ACMPEQ,IF_ACMPNE,GOTO,JSR,RET,TABLESWITCH,LOOKUPSWITCH,"
+ "IRETURN,LRETURN,FRETURN,DRETURN,ARETURN,RETURN,GETSTATIC,"
+ "PUTSTATIC,GETFIELD,PUTFIELD,INVOKEVIRTUAL,INVOKESPECIAL,"
+ "INVOKESTATIC,INVOKEINTERFACE,INVOKEDYNAMIC,NEW,NEWARRAY,"
+ "ANEWARRAY,ARRAYLENGTH,ATHROW,CHECKCAST,INSTANCEOF,"
+ "MONITORENTER,MONITOREXIT,,MULTIANEWARRAY,IFNULL,IFNONNULL,";
OPCODES = new String[200];
int i = 0;
int j = 0;
int l;
while ((l = s.indexOf(',', j)) > 0) {
OPCODES[i++] = j + 1 == l ? null : s.substring(j, l);
j = l + 1;
}
s = "T_BOOLEAN,T_CHAR,T_FLOAT,T_DOUBLE,T_BYTE,T_SHORT,T_INT,T_LONG,";
TYPES = new String[12];
j = 0;
i = 4;
while ((l = s.indexOf(',', j)) > 0) {
TYPES[i++] = s.substring(j, l);
j = l + 1;
}
s = "H_GETFIELD,H_GETSTATIC,H_PUTFIELD,H_PUTSTATIC,"
+ "H_INVOKEVIRTUAL,H_INVOKESTATIC,H_INVOKESPECIAL,"
+ "H_NEWINVOKESPECIAL,H_INVOKEINTERFACE,";
HANDLE_TAG = new String[10];
j = 0;
i = 1;
while ((l = s.indexOf(',', j)) > 0) {
HANDLE_TAG[i++] = s.substring(j, l);
j = l + 1;
}
}
/**
* The ASM API version implemented by this class. The value of this field
* must be one of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.
*/
protected final int api;
/**
* A buffer that can be used to create strings.
*/
protected final StringBuffer buf;
/**
* The text to be printed. Since the code of methods is not necessarily
* visited in sequential order, one method after the other, but can be
* interlaced (some instructions from method one, then some instructions
* from method two, then some instructions from method one again...), it is
* not possible to print the visited instructions directly to a sequential
* stream. A class is therefore printed in a two steps process: a string
* tree is constructed during the visit, and printed to a sequential stream
* at the end of the visit. This string tree is stored in this field, as a
* string list that can contain other string lists, which can themselves
* contain other string lists, and so on.
*/
public final List<Object> text;
/**
* Constructs a new {@link Printer}.
*/
protected Printer(final int api) {
this.api = api;
this.buf = new StringBuffer();
this.text = new ArrayList<Object>();
}
/**
* Class header. See {@link jdk.internal.org.objectweb.asm.ClassVisitor#visit}.
*/
public abstract void visit(final int version, final int access,
final String name, final String signature, final String superName,
final String[] interfaces);
/**
* Class source. See {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitSource}.
*/
public abstract void visitSource(final String file, final String debug);
/**
* Class outer class. See
* {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitOuterClass}.
*/
public abstract void visitOuterClass(final String owner, final String name,
final String desc);
/**
* Class annotation. See
* {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitAnnotation}.
*/
public abstract Printer visitClassAnnotation(final String desc,
final boolean visible);
/**
* Class type annotation. See
* {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitTypeAnnotation}.
*/
public Printer visitClassTypeAnnotation(final int typeRef,
final TypePath typePath, final String desc, final boolean visible) {
throw new RuntimeException("Must be overriden");
}
/**
* Class attribute. See
* {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitAttribute}.
*/
public abstract void visitClassAttribute(final Attribute attr);
/**
* Class inner name. See
* {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitInnerClass}.
*/
public abstract void visitInnerClass(final String name,
final String outerName, final String innerName, final int access);
/**
* Class field. See {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitField}.
*/
public abstract Printer visitField(final int access, final String name,
final String desc, final String signature, final Object value);
/**
* Class method. See {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitMethod}.
*/
public abstract Printer visitMethod(final int access, final String name,
final String desc, final String signature, final String[] exceptions);
/**
* Class end. See {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitEnd}.
*/
public abstract void visitClassEnd();
// ------------------------------------------------------------------------
// Annotations
// ------------------------------------------------------------------------
/**
* Annotation value. See {@link jdk.internal.org.objectweb.asm.AnnotationVisitor#visit}.
*/
public abstract void visit(final String name, final Object value);
/**
* Annotation enum value. See
* {@link jdk.internal.org.objectweb.asm.AnnotationVisitor#visitEnum}.
*/
public abstract void visitEnum(final String name, final String desc,
final String value);
/**
* Nested annotation value. See
* {@link jdk.internal.org.objectweb.asm.AnnotationVisitor#visitAnnotation}.
*/
public abstract Printer visitAnnotation(final String name, final String desc);
/**
* Annotation array value. See
* {@link jdk.internal.org.objectweb.asm.AnnotationVisitor#visitArray}.
*/
public abstract Printer visitArray(final String name);
/**
* Annotation end. See {@link jdk.internal.org.objectweb.asm.AnnotationVisitor#visitEnd}.
*/
public abstract void visitAnnotationEnd();
// ------------------------------------------------------------------------
// Fields
// ------------------------------------------------------------------------
/**
* Field annotation. See
* {@link jdk.internal.org.objectweb.asm.FieldVisitor#visitAnnotation}.
*/
public abstract Printer visitFieldAnnotation(final String desc,
final boolean visible);
/**
* Field type annotation. See
* {@link jdk.internal.org.objectweb.asm.FieldVisitor#visitTypeAnnotation}.
*/
public Printer visitFieldTypeAnnotation(final int typeRef,
final TypePath typePath, final String desc, final boolean visible) {
throw new RuntimeException("Must be overriden");
}
/**
* Field attribute. See
* {@link jdk.internal.org.objectweb.asm.FieldVisitor#visitAttribute}.
*/
public abstract void visitFieldAttribute(final Attribute attr);
/**
* Field end. See {@link jdk.internal.org.objectweb.asm.FieldVisitor#visitEnd}.
*/
public abstract void visitFieldEnd();
// ------------------------------------------------------------------------
// Methods
// ------------------------------------------------------------------------
/**
* Method parameter. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitParameter(String, int)}.
*/
public void visitParameter(String name, int access) {
throw new RuntimeException("Must be overriden");
}
/**
* Method default annotation. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitAnnotationDefault}.
*/
public abstract Printer visitAnnotationDefault();
/**
* Method annotation. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitAnnotation}.
*/
public abstract Printer visitMethodAnnotation(final String desc,
final boolean visible);
/**
* Method type annotation. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitTypeAnnotation}.
*/
public Printer visitMethodTypeAnnotation(final int typeRef,
final TypePath typePath, final String desc, final boolean visible) {
throw new RuntimeException("Must be overriden");
}
/**
* Method parameter annotation. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitParameterAnnotation}.
*/
public abstract Printer visitParameterAnnotation(final int parameter,
final String desc, final boolean visible);
/**
* Method attribute. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitAttribute}.
*/
public abstract void visitMethodAttribute(final Attribute attr);
/**
* Method start. See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitCode}.
*/
public abstract void visitCode();
/**
* Method stack frame. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitFrame}.
*/
public abstract void visitFrame(final int type, final int nLocal,
final Object[] local, final int nStack, final Object[] stack);
/**
* Method instruction. See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitInsn}
* .
*/
public abstract void visitInsn(final int opcode);
/**
* Method instruction. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitIntInsn}.
*/
public abstract void visitIntInsn(final int opcode, final int operand);
/**
* Method instruction. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitVarInsn}.
*/
public abstract void visitVarInsn(final int opcode, final int var);
/**
* Method instruction. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitTypeInsn}.
*/
public abstract void visitTypeInsn(final int opcode, final String type);
/**
* Method instruction. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitFieldInsn}.
*/
public abstract void visitFieldInsn(final int opcode, final String owner,
final String name, final String desc);
/**
* Method instruction. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitMethodInsn}.
*/
@Deprecated
public void visitMethodInsn(final int opcode, final String owner,
final String name, final String desc) {
if (api >= Opcodes.ASM5) {
boolean itf = opcode == Opcodes.INVOKEINTERFACE;
visitMethodInsn(opcode, owner, name, desc, itf);
return;
}
throw new RuntimeException("Must be overriden");
}
/**
* Method instruction. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitMethodInsn}.
*/
public void visitMethodInsn(final int opcode, final String owner,
final String name, final String desc, final boolean itf) {
if (api < Opcodes.ASM5) {
if (itf != (opcode == Opcodes.INVOKEINTERFACE)) {
throw new IllegalArgumentException(
"INVOKESPECIAL/STATIC on interfaces require ASM 5");
}
visitMethodInsn(opcode, owner, name, desc);
return;
}
throw new RuntimeException("Must be overriden");
}
/**
* Method instruction. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitInvokeDynamicInsn}.
*/
public abstract void visitInvokeDynamicInsn(String name, String desc,
Handle bsm, Object... bsmArgs);
/**
* Method instruction. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitJumpInsn}.
*/
public abstract void visitJumpInsn(final int opcode, final Label label);
/**
* Method label. See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitLabel}.
*/
public abstract void visitLabel(final Label label);
/**
* Method instruction. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitLdcInsn}.
*/
public abstract void visitLdcInsn(final Object cst);
/**
* Method instruction. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitIincInsn}.
*/
public abstract void visitIincInsn(final int var, final int increment);
/**
* Method instruction. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitTableSwitchInsn}.
*/
public abstract void visitTableSwitchInsn(final int min, final int max,
final Label dflt, final Label... labels);
/**
* Method instruction. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitLookupSwitchInsn}.
*/
public abstract void visitLookupSwitchInsn(final Label dflt,
final int[] keys, final Label[] labels);
/**
* Method instruction. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitMultiANewArrayInsn}.
*/
public abstract void visitMultiANewArrayInsn(final String desc,
final int dims);
/**
* Instruction type annotation. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitInsnAnnotation}.
*/
public Printer visitInsnAnnotation(final int typeRef,
final TypePath typePath, final String desc, final boolean visible) {
throw new RuntimeException("Must be overriden");
}
/**
* Method exception handler. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitTryCatchBlock}.
*/
public abstract void visitTryCatchBlock(final Label start, final Label end,
final Label handler, final String type);
/**
* Try catch block type annotation. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitTryCatchAnnotation}.
*/
public Printer visitTryCatchAnnotation(final int typeRef,
final TypePath typePath, final String desc, final boolean visible) {
throw new RuntimeException("Must be overriden");
}
/**
* Method debug info. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitLocalVariable}.
*/
public abstract void visitLocalVariable(final String name,
final String desc, final String signature, final Label start,
final Label end, final int index);
/**
* Local variable type annotation. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitTryCatchAnnotation}.
*/
public Printer visitLocalVariableAnnotation(final int typeRef,
final TypePath typePath, final Label[] start, final Label[] end,
final int[] index, final String desc, final boolean visible) {
throw new RuntimeException("Must be overriden");
}
/**
* Method debug info. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitLineNumber}.
*/
public abstract void visitLineNumber(final int line, final Label start);
/**
* Method max stack and max locals. See
* {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitMaxs}.
*/
public abstract void visitMaxs(final int maxStack, final int maxLocals);
/**
* Method end. See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitEnd}.
*/
public abstract void visitMethodEnd();
/**
* Returns the text constructed by this visitor.
*
* @return the text constructed by this visitor.
*/
public List<Object> getText() {
return text;
}
/**
* Prints the text constructed by this visitor.
*
* @param pw
* the print writer to be used.
*/
public void print(final PrintWriter pw) {
printList(pw, text);
}
/**
* Appends a quoted string to a given buffer.
*
* @param buf
* the buffer where the string must be added.
* @param s
* the string to be added.
*/
public static void appendString(final StringBuffer buf, final String s) {
buf.append('\"');
for (int i = 0; i < s.length(); ++i) {
char c = s.charAt(i);
if (c == '\n') {
buf.append("\\n");
} else if (c == '\r') {
buf.append("\\r");
} else if (c == '\\') {
buf.append("\\\\");
} else if (c == '"') {
buf.append("\\\"");
} else if (c < 0x20 || c > 0x7f) {
buf.append("\\u");
if (c < 0x10) {
buf.append("000");
} else if (c < 0x100) {
buf.append("00");
} else if (c < 0x1000) {
buf.append('0');
}
buf.append(Integer.toString(c, 16));
} else {
buf.append(c);
}
}
buf.append('\"');
}
/**
* Prints the given string tree.
*
* @param pw
* the writer to be used to print the tree.
* @param l
* a string tree, i.e., a string list that can contain other
* string lists, and so on recursively.
*/
static void printList(final PrintWriter pw, final List<?> l) {
for (int i = 0; i < l.size(); ++i) {
Object o = l.get(i);
if (o instanceof List) {
printList(pw, (List<?>) o);
} else {
pw.print(o.toString());
}
}
}
}

View File

@@ -0,0 +1,85 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file:
*
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000-2011 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package jdk.internal.org.objectweb.asm.util;
import java.util.Map;
import jdk.internal.org.objectweb.asm.Label;
/**
* An {@link jdk.internal.org.objectweb.asm.Attribute Attribute} that can print a readable
* representation of itself.
*
* Implementations should construct readable output from an attribute data
* structure. Such representation could be used in unit test assertions.
*
* @author Eugene Kuleshov
*/
public interface Textifiable {
/**
* Build a human readable representation of this attribute.
*
* @param buf
* a buffer used for printing Java code.
* @param labelNames
* map of label instances to their names.
*/
void textify(StringBuffer buf, Map<Label, String> labelNames);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,118 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file:
*
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000-2011 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package jdk.internal.org.objectweb.asm.util;
import jdk.internal.org.objectweb.asm.AnnotationVisitor;
import jdk.internal.org.objectweb.asm.Opcodes;
/**
* An {@link AnnotationVisitor} that prints the annotations it visits with a
* {@link Printer}.
*
* @author Eric Bruneton
*/
public final class TraceAnnotationVisitor extends AnnotationVisitor {
private final Printer p;
public TraceAnnotationVisitor(final Printer p) {
this(null, p);
}
public TraceAnnotationVisitor(final AnnotationVisitor av, final Printer p) {
super(Opcodes.ASM5, av);
this.p = p;
}
@Override
public void visit(final String name, final Object value) {
p.visit(name, value);
super.visit(name, value);
}
@Override
public void visitEnum(final String name, final String desc,
final String value) {
p.visitEnum(name, desc, value);
super.visitEnum(name, desc, value);
}
@Override
public AnnotationVisitor visitAnnotation(final String name,
final String desc) {
Printer p = this.p.visitAnnotation(name, desc);
AnnotationVisitor av = this.av == null ? null : this.av
.visitAnnotation(name, desc);
return new TraceAnnotationVisitor(av, p);
}
@Override
public AnnotationVisitor visitArray(final String name) {
Printer p = this.p.visitArray(name);
AnnotationVisitor av = this.av == null ? null : this.av
.visitArray(name);
return new TraceAnnotationVisitor(av, p);
}
@Override
public void visitEnd() {
p.visitAnnotationEnd();
super.visitEnd();
}
}

View File

@@ -0,0 +1,249 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file:
*
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000-2011 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package jdk.internal.org.objectweb.asm.util;
import java.io.PrintWriter;
import jdk.internal.org.objectweb.asm.AnnotationVisitor;
import jdk.internal.org.objectweb.asm.Attribute;
import jdk.internal.org.objectweb.asm.ClassVisitor;
import jdk.internal.org.objectweb.asm.FieldVisitor;
import jdk.internal.org.objectweb.asm.MethodVisitor;
import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.internal.org.objectweb.asm.TypePath;
/**
* A {@link ClassVisitor} that prints the classes it visits with a
* {@link Printer}. This class visitor can be used in the middle of a class
* visitor chain to trace the class that is visited at a given point in this
* chain. This may be useful for debugging purposes.
* <p>
* The trace printed when visiting the <tt>Hello</tt> class is the following:
* <p>
* <blockquote>
*
* <pre>
* // class version 49.0 (49) // access flags 0x21 public class Hello {
*
* // compiled from: Hello.java
*
* // access flags 0x1 public &lt;init&gt; ()V ALOAD 0 INVOKESPECIAL
* java/lang/Object &lt;init&gt; ()V RETURN MAXSTACK = 1 MAXLOCALS = 1
*
* // access flags 0x9 public static main ([Ljava/lang/String;)V GETSTATIC
* java/lang/System out Ljava/io/PrintStream; LDC &quot;hello&quot;
* INVOKEVIRTUAL java/io/PrintStream println (Ljava/lang/String;)V RETURN
* MAXSTACK = 2 MAXLOCALS = 1 }
* </pre>
*
* </blockquote> where <tt>Hello</tt> is defined by:
* <p>
* <blockquote>
*
* <pre>
* public class Hello {
*
* public static void main(String[] args) {
* System.out.println(&quot;hello&quot;);
* }
* }
* </pre>
*
* </blockquote>
*
* @author Eric Bruneton
* @author Eugene Kuleshov
*/
public final class TraceClassVisitor extends ClassVisitor {
/**
* The print writer to be used to print the class. May be null.
*/
private final PrintWriter pw;
/**
* The object that actually converts visit events into text.
*/
public final Printer p;
/**
* Constructs a new {@link TraceClassVisitor}.
*
* @param pw
* the print writer to be used to print the class.
*/
public TraceClassVisitor(final PrintWriter pw) {
this(null, pw);
}
/**
* Constructs a new {@link TraceClassVisitor}.
*
* @param cv
* the {@link ClassVisitor} to which this visitor delegates
* calls. May be <tt>null</tt>.
* @param pw
* the print writer to be used to print the class.
*/
public TraceClassVisitor(final ClassVisitor cv, final PrintWriter pw) {
this(cv, new Textifier(), pw);
}
/**
* Constructs a new {@link TraceClassVisitor}.
*
* @param cv
* the {@link ClassVisitor} to which this visitor delegates
* calls. May be <tt>null</tt>.
* @param p
* the object that actually converts visit events into text.
* @param pw
* the print writer to be used to print the class. May be null if
* you simply want to use the result via
* {@link Printer#getText()}, instead of printing it.
*/
public TraceClassVisitor(final ClassVisitor cv, final Printer p,
final PrintWriter pw) {
super(Opcodes.ASM5, cv);
this.pw = pw;
this.p = p;
}
@Override
public void visit(final int version, final int access, final String name,
final String signature, final String superName,
final String[] interfaces) {
p.visit(version, access, name, signature, superName, interfaces);
super.visit(version, access, name, signature, superName, interfaces);
}
@Override
public void visitSource(final String file, final String debug) {
p.visitSource(file, debug);
super.visitSource(file, debug);
}
@Override
public void visitOuterClass(final String owner, final String name,
final String desc) {
p.visitOuterClass(owner, name, desc);
super.visitOuterClass(owner, name, desc);
}
@Override
public AnnotationVisitor visitAnnotation(final String desc,
final boolean visible) {
Printer p = this.p.visitClassAnnotation(desc, visible);
AnnotationVisitor av = cv == null ? null : cv.visitAnnotation(desc,
visible);
return new TraceAnnotationVisitor(av, p);
}
@Override
public AnnotationVisitor visitTypeAnnotation(int typeRef,
TypePath typePath, String desc, boolean visible) {
Printer p = this.p.visitClassTypeAnnotation(typeRef, typePath, desc,
visible);
AnnotationVisitor av = cv == null ? null : cv.visitTypeAnnotation(
typeRef, typePath, desc, visible);
return new TraceAnnotationVisitor(av, p);
}
@Override
public void visitAttribute(final Attribute attr) {
p.visitClassAttribute(attr);
super.visitAttribute(attr);
}
@Override
public void visitInnerClass(final String name, final String outerName,
final String innerName, final int access) {
p.visitInnerClass(name, outerName, innerName, access);
super.visitInnerClass(name, outerName, innerName, access);
}
@Override
public FieldVisitor visitField(final int access, final String name,
final String desc, final String signature, final Object value) {
Printer p = this.p.visitField(access, name, desc, signature, value);
FieldVisitor fv = cv == null ? null : cv.visitField(access, name, desc,
signature, value);
return new TraceFieldVisitor(fv, p);
}
@Override
public MethodVisitor visitMethod(final int access, final String name,
final String desc, final String signature, final String[] exceptions) {
Printer p = this.p.visitMethod(access, name, desc, signature,
exceptions);
MethodVisitor mv = cv == null ? null : cv.visitMethod(access, name,
desc, signature, exceptions);
return new TraceMethodVisitor(mv, p);
}
@Override
public void visitEnd() {
p.visitClassEnd();
if (pw != null) {
p.print(pw);
pw.flush();
}
super.visitEnd();
}
}

View File

@@ -0,0 +1,116 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file:
*
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000-2011 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package jdk.internal.org.objectweb.asm.util;
import jdk.internal.org.objectweb.asm.AnnotationVisitor;
import jdk.internal.org.objectweb.asm.Attribute;
import jdk.internal.org.objectweb.asm.FieldVisitor;
import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.internal.org.objectweb.asm.TypePath;
/**
* A {@link FieldVisitor} that prints the fields it visits with a
* {@link Printer}.
*
* @author Eric Bruneton
*/
public final class TraceFieldVisitor extends FieldVisitor {
public final Printer p;
public TraceFieldVisitor(final Printer p) {
this(null, p);
}
public TraceFieldVisitor(final FieldVisitor fv, final Printer p) {
super(Opcodes.ASM5, fv);
this.p = p;
}
@Override
public AnnotationVisitor visitAnnotation(final String desc,
final boolean visible) {
Printer p = this.p.visitFieldAnnotation(desc, visible);
AnnotationVisitor av = fv == null ? null : fv.visitAnnotation(desc,
visible);
return new TraceAnnotationVisitor(av, p);
}
@Override
public AnnotationVisitor visitTypeAnnotation(int typeRef,
TypePath typePath, String desc, boolean visible) {
Printer p = this.p.visitFieldTypeAnnotation(typeRef, typePath, desc,
visible);
AnnotationVisitor av = fv == null ? null : fv.visitTypeAnnotation(
typeRef, typePath, desc, visible);
return new TraceAnnotationVisitor(av, p);
}
@Override
public void visitAttribute(final Attribute attr) {
p.visitFieldAttribute(attr);
super.visitAttribute(attr);
}
@Override
public void visitEnd() {
p.visitFieldEnd();
super.visitEnd();
}
}

View File

@@ -0,0 +1,321 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file:
*
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000-2011 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package jdk.internal.org.objectweb.asm.util;
import jdk.internal.org.objectweb.asm.AnnotationVisitor;
import jdk.internal.org.objectweb.asm.Attribute;
import jdk.internal.org.objectweb.asm.Handle;
import jdk.internal.org.objectweb.asm.Label;
import jdk.internal.org.objectweb.asm.MethodVisitor;
import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.internal.org.objectweb.asm.TypePath;
/**
* A {@link MethodVisitor} that prints the methods it visits with a
* {@link Printer}.
*
* @author Eric Bruneton
*/
public final class TraceMethodVisitor extends MethodVisitor {
public final Printer p;
public TraceMethodVisitor(final Printer p) {
this(null, p);
}
public TraceMethodVisitor(final MethodVisitor mv, final Printer p) {
super(Opcodes.ASM5, mv);
this.p = p;
}
@Override
public void visitParameter(String name, int access) {
p.visitParameter(name, access);
super.visitParameter(name, access);
}
@Override
public AnnotationVisitor visitAnnotation(final String desc,
final boolean visible) {
Printer p = this.p.visitMethodAnnotation(desc, visible);
AnnotationVisitor av = mv == null ? null : mv.visitAnnotation(desc,
visible);
return new TraceAnnotationVisitor(av, p);
}
@Override
public AnnotationVisitor visitTypeAnnotation(int typeRef,
TypePath typePath, String desc, boolean visible) {
Printer p = this.p.visitMethodTypeAnnotation(typeRef, typePath, desc,
visible);
AnnotationVisitor av = mv == null ? null : mv.visitTypeAnnotation(
typeRef, typePath, desc, visible);
return new TraceAnnotationVisitor(av, p);
}
@Override
public void visitAttribute(final Attribute attr) {
p.visitMethodAttribute(attr);
super.visitAttribute(attr);
}
@Override
public AnnotationVisitor visitAnnotationDefault() {
Printer p = this.p.visitAnnotationDefault();
AnnotationVisitor av = mv == null ? null : mv.visitAnnotationDefault();
return new TraceAnnotationVisitor(av, p);
}
@Override
public AnnotationVisitor visitParameterAnnotation(final int parameter,
final String desc, final boolean visible) {
Printer p = this.p.visitParameterAnnotation(parameter, desc, visible);
AnnotationVisitor av = mv == null ? null : mv.visitParameterAnnotation(
parameter, desc, visible);
return new TraceAnnotationVisitor(av, p);
}
@Override
public void visitCode() {
p.visitCode();
super.visitCode();
}
@Override
public void visitFrame(final int type, final int nLocal,
final Object[] local, final int nStack, final Object[] stack) {
p.visitFrame(type, nLocal, local, nStack, stack);
super.visitFrame(type, nLocal, local, nStack, stack);
}
@Override
public void visitInsn(final int opcode) {
p.visitInsn(opcode);
super.visitInsn(opcode);
}
@Override
public void visitIntInsn(final int opcode, final int operand) {
p.visitIntInsn(opcode, operand);
super.visitIntInsn(opcode, operand);
}
@Override
public void visitVarInsn(final int opcode, final int var) {
p.visitVarInsn(opcode, var);
super.visitVarInsn(opcode, var);
}
@Override
public void visitTypeInsn(final int opcode, final String type) {
p.visitTypeInsn(opcode, type);
super.visitTypeInsn(opcode, type);
}
@Override
public void visitFieldInsn(final int opcode, final String owner,
final String name, final String desc) {
p.visitFieldInsn(opcode, owner, name, desc);
super.visitFieldInsn(opcode, owner, name, desc);
}
@Deprecated
@Override
public void visitMethodInsn(int opcode, String owner, String name,
String desc) {
if (api >= Opcodes.ASM5) {
super.visitMethodInsn(opcode, owner, name, desc);
return;
}
p.visitMethodInsn(opcode, owner, name, desc);
if (mv != null) {
mv.visitMethodInsn(opcode, owner, name, desc);
}
}
@Override
public void visitMethodInsn(int opcode, String owner, String name,
String desc, boolean itf) {
if (api < Opcodes.ASM5) {
super.visitMethodInsn(opcode, owner, name, desc, itf);
return;
}
p.visitMethodInsn(opcode, owner, name, desc, itf);
if (mv != null) {
mv.visitMethodInsn(opcode, owner, name, desc, itf);
}
}
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
Object... bsmArgs) {
p.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
super.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
}
@Override
public void visitJumpInsn(final int opcode, final Label label) {
p.visitJumpInsn(opcode, label);
super.visitJumpInsn(opcode, label);
}
@Override
public void visitLabel(final Label label) {
p.visitLabel(label);
super.visitLabel(label);
}
@Override
public void visitLdcInsn(final Object cst) {
p.visitLdcInsn(cst);
super.visitLdcInsn(cst);
}
@Override
public void visitIincInsn(final int var, final int increment) {
p.visitIincInsn(var, increment);
super.visitIincInsn(var, increment);
}
@Override
public void visitTableSwitchInsn(final int min, final int max,
final Label dflt, final Label... labels) {
p.visitTableSwitchInsn(min, max, dflt, labels);
super.visitTableSwitchInsn(min, max, dflt, labels);
}
@Override
public void visitLookupSwitchInsn(final Label dflt, final int[] keys,
final Label[] labels) {
p.visitLookupSwitchInsn(dflt, keys, labels);
super.visitLookupSwitchInsn(dflt, keys, labels);
}
@Override
public void visitMultiANewArrayInsn(final String desc, final int dims) {
p.visitMultiANewArrayInsn(desc, dims);
super.visitMultiANewArrayInsn(desc, dims);
}
@Override
public AnnotationVisitor visitInsnAnnotation(int typeRef,
TypePath typePath, String desc, boolean visible) {
Printer p = this.p
.visitInsnAnnotation(typeRef, typePath, desc, visible);
AnnotationVisitor av = mv == null ? null : mv.visitInsnAnnotation(
typeRef, typePath, desc, visible);
return new TraceAnnotationVisitor(av, p);
}
@Override
public void visitTryCatchBlock(final Label start, final Label end,
final Label handler, final String type) {
p.visitTryCatchBlock(start, end, handler, type);
super.visitTryCatchBlock(start, end, handler, type);
}
@Override
public AnnotationVisitor visitTryCatchAnnotation(int typeRef,
TypePath typePath, String desc, boolean visible) {
Printer p = this.p.visitTryCatchAnnotation(typeRef, typePath, desc,
visible);
AnnotationVisitor av = mv == null ? null : mv.visitTryCatchAnnotation(
typeRef, typePath, desc, visible);
return new TraceAnnotationVisitor(av, p);
}
@Override
public void visitLocalVariable(final String name, final String desc,
final String signature, final Label start, final Label end,
final int index) {
p.visitLocalVariable(name, desc, signature, start, end, index);
super.visitLocalVariable(name, desc, signature, start, end, index);
}
@Override
public AnnotationVisitor visitLocalVariableAnnotation(int typeRef,
TypePath typePath, Label[] start, Label[] end, int[] index,
String desc, boolean visible) {
Printer p = this.p.visitLocalVariableAnnotation(typeRef, typePath,
start, end, index, desc, visible);
AnnotationVisitor av = mv == null ? null : mv
.visitLocalVariableAnnotation(typeRef, typePath, start, end,
index, desc, visible);
return new TraceAnnotationVisitor(av, p);
}
@Override
public void visitLineNumber(final int line, final Label start) {
p.visitLineNumber(line, start);
super.visitLineNumber(line, start);
}
@Override
public void visitMaxs(final int maxStack, final int maxLocals) {
p.visitMaxs(maxStack, maxLocals);
super.visitMaxs(maxStack, maxLocals);
}
@Override
public void visitEnd() {
p.visitMethodEnd();
super.visitEnd();
}
}

View File

@@ -0,0 +1,346 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file:
*
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000-2011 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package jdk.internal.org.objectweb.asm.util;
import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.internal.org.objectweb.asm.signature.SignatureVisitor;
/**
* A {@link SignatureVisitor} that prints a disassembled view of the signature
* it visits.
*
* @author Eugene Kuleshov
* @author Eric Bruneton
*/
public final class TraceSignatureVisitor extends SignatureVisitor {
private final StringBuffer declaration;
private boolean isInterface;
private boolean seenFormalParameter;
private boolean seenInterfaceBound;
private boolean seenParameter;
private boolean seenInterface;
private StringBuffer returnType;
private StringBuffer exceptions;
/**
* Stack used to keep track of class types that have arguments. Each element
* of this stack is a boolean encoded in one bit. The top of the stack is
* the lowest order bit. Pushing false = *2, pushing true = *2+1, popping =
* /2.
*/
private int argumentStack;
/**
* Stack used to keep track of array class types. Each element of this stack
* is a boolean encoded in one bit. The top of the stack is the lowest order
* bit. Pushing false = *2, pushing true = *2+1, popping = /2.
*/
private int arrayStack;
private String separator = "";
public TraceSignatureVisitor(final int access) {
super(Opcodes.ASM5);
isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
this.declaration = new StringBuffer();
}
private TraceSignatureVisitor(final StringBuffer buf) {
super(Opcodes.ASM5);
this.declaration = buf;
}
@Override
public void visitFormalTypeParameter(final String name) {
declaration.append(seenFormalParameter ? ", " : "<").append(name);
seenFormalParameter = true;
seenInterfaceBound = false;
}
@Override
public SignatureVisitor visitClassBound() {
separator = " extends ";
startType();
return this;
}
@Override
public SignatureVisitor visitInterfaceBound() {
separator = seenInterfaceBound ? ", " : " extends ";
seenInterfaceBound = true;
startType();
return this;
}
@Override
public SignatureVisitor visitSuperclass() {
endFormals();
separator = " extends ";
startType();
return this;
}
@Override
public SignatureVisitor visitInterface() {
separator = seenInterface ? ", " : isInterface ? " extends "
: " implements ";
seenInterface = true;
startType();
return this;
}
@Override
public SignatureVisitor visitParameterType() {
endFormals();
if (seenParameter) {
declaration.append(", ");
} else {
seenParameter = true;
declaration.append('(');
}
startType();
return this;
}
@Override
public SignatureVisitor visitReturnType() {
endFormals();
if (seenParameter) {
seenParameter = false;
} else {
declaration.append('(');
}
declaration.append(')');
returnType = new StringBuffer();
return new TraceSignatureVisitor(returnType);
}
@Override
public SignatureVisitor visitExceptionType() {
if (exceptions == null) {
exceptions = new StringBuffer();
} else {
exceptions.append(", ");
}
// startType();
return new TraceSignatureVisitor(exceptions);
}
@Override
public void visitBaseType(final char descriptor) {
switch (descriptor) {
case 'V':
declaration.append("void");
break;
case 'B':
declaration.append("byte");
break;
case 'J':
declaration.append("long");
break;
case 'Z':
declaration.append("boolean");
break;
case 'I':
declaration.append("int");
break;
case 'S':
declaration.append("short");
break;
case 'C':
declaration.append("char");
break;
case 'F':
declaration.append("float");
break;
// case 'D':
default:
declaration.append("double");
break;
}
endType();
}
@Override
public void visitTypeVariable(final String name) {
declaration.append(name);
endType();
}
@Override
public SignatureVisitor visitArrayType() {
startType();
arrayStack |= 1;
return this;
}
@Override
public void visitClassType(final String name) {
if ("java/lang/Object".equals(name)) {
// Map<java.lang.Object,java.util.List>
// or
// abstract public V get(Object key); (seen in Dictionary.class)
// should have Object
// but java.lang.String extends java.lang.Object is unnecessary
boolean needObjectClass = argumentStack % 2 != 0 || seenParameter;
if (needObjectClass) {
declaration.append(separator).append(name.replace('/', '.'));
}
} else {
declaration.append(separator).append(name.replace('/', '.'));
}
separator = "";
argumentStack *= 2;
}
@Override
public void visitInnerClassType(final String name) {
if (argumentStack % 2 != 0) {
declaration.append('>');
}
argumentStack /= 2;
declaration.append('.');
declaration.append(separator).append(name.replace('/', '.'));
separator = "";
argumentStack *= 2;
}
@Override
public void visitTypeArgument() {
if (argumentStack % 2 == 0) {
++argumentStack;
declaration.append('<');
} else {
declaration.append(", ");
}
declaration.append('?');
}
@Override
public SignatureVisitor visitTypeArgument(final char tag) {
if (argumentStack % 2 == 0) {
++argumentStack;
declaration.append('<');
} else {
declaration.append(", ");
}
if (tag == EXTENDS) {
declaration.append("? extends ");
} else if (tag == SUPER) {
declaration.append("? super ");
}
startType();
return this;
}
@Override
public void visitEnd() {
if (argumentStack % 2 != 0) {
declaration.append('>');
}
argumentStack /= 2;
endType();
}
public String getDeclaration() {
return declaration.toString();
}
public String getReturnType() {
return returnType == null ? null : returnType.toString();
}
public String getExceptions() {
return exceptions == null ? null : exceptions.toString();
}
// -----------------------------------------------
private void endFormals() {
if (seenFormalParameter) {
declaration.append('>');
seenFormalParameter = false;
}
}
private void startType() {
arrayStack *= 2;
}
private void endType() {
if (arrayStack % 2 == 0) {
arrayStack /= 2;
} else {
while (arrayStack % 2 != 0) {
arrayStack /= 2;
declaration.append("[]");
}
}
}
}