org.powermock.modules.agent.DefinalizingClassTransformer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powermock-module-javaagent Show documentation
Show all versions of powermock-module-javaagent Show documentation
PowerMock Java agent support.
/*
* Copyright 2011 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.powermock.modules.agent;
import net.bytebuddy.jar.asm.ClassReader;
import net.bytebuddy.jar.asm.ClassWriter;
import java.lang.instrument.ClassFileTransformer;
import java.security.ProtectionDomain;
public class DefinalizingClassTransformer extends AbstractClassTransformer implements ClassFileTransformer {
private static final int NO_FLAGS_OR_OPTIONS = 0;
public byte[] transform(ClassLoader loader, String className, Class> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
if (loader == null || shouldIgnore(className)) {
return null;
}
final ClassReader reader = new ClassReader(classfileBuffer);
final ClassWriter writer = new ClassWriter(NO_FLAGS_OR_OPTIONS);
reader.accept(new DefinalizingClassVisitor(writer), NO_FLAGS_OR_OPTIONS);
return writer.toByteArray();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy