List of usage examples for org.objectweb.asm Opcodes V1_7
int V1_7
To view the source code for org.objectweb.asm Opcodes V1_7.
Click Source Link
From source file:org.elasticsearch.plan.a.Writer.java
License:Apache License
private void writeBegin() { final int compute = ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS; final int version = Opcodes.V1_7; final int access = Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC; final String base = BASE_CLASS_TYPE.getInternalName(); final String name = CLASS_TYPE.getInternalName(); writer = new ClassWriter(compute); writer.visit(version, access, name, null, base, null); writer.visitSource(source, null);/* www. jav a2 s .c o m*/ }
From source file:org.fabric3.implementation.bytecode.reflection.BytecodeConsumerInvokerFactory.java
License:Open Source License
@SuppressWarnings("unchecked") public ConsumerInvoker createInvoker(Method method) { BytecodeClassLoader classLoader = getClassLoader(method); Class<?> declaringClass = method.getDeclaringClass(); // use the toString() hashcode of the method since more than one invoker may be created per class (if it has multiple methods) int code = Math.abs(method.toString().hashCode()); String className = declaringClass.getName() + "_ConsumerInvoker" + code; try {//from www.j av a2s . c o m Class<ConsumerInvoker> invokerClass = (Class<ConsumerInvoker>) classLoader.loadClass(className); return invokerClass.newInstance(); } catch (ClassNotFoundException e) { // ignore } catch (InstantiationException e) { throw new AssertionError(e); } catch (IllegalAccessException e) { throw new AssertionError(e); } String internalTargetName = Type.getInternalName(declaringClass); String internalInvokerName = internalTargetName + "_ConsumerInvoker" + code; ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); cw.visit(Opcodes.V1_7, ACC_PUBLIC + ACC_SUPER, internalInvokerName, null, "java/lang/Object", TARGET_INVOKER_INTERFACES); cw.visitSource(className + ".java", null); // write the ctor BytecodeHelper.writeConstructor(cw, Object.class); // write the invoker method writeTargetInvoke(method, internalTargetName, cw); cw.visitEnd(); return BytecodeHelper.instantiate(ConsumerInvoker.class, className, classLoader, cw); }
From source file:org.fabric3.monitor.impl.proxy.BytecodeMonitorProxyService.java
License:Open Source License
/** * Performs the actual bytecode generation to implement the given interface * * @param type the interface to implement * @param flags the ClassWriter flags/*from w ww . ja v a2 s . co m*/ * @return the generated bytecode * @throws MonitorCreationException if there is an error generating the class */ <T> byte[] generateClass(Class<T> type, int flags) throws MonitorCreationException { String proxyClassNameInternal = Type.getInternalName(type).replace("$", "") + "_Proxy"; String proxyClassDescriptor = "L" + proxyClassNameInternal + ";"; String interfazeName = Type.getInternalName(type); ClassWriter cw = new ClassWriter(flags); cw.visit(Opcodes.V1_7, ACC_PUBLIC + ACC_SUPER, proxyClassNameInternal, null, ABSTRACT_MONITOR_HANDLER, new String[] { interfazeName }); cw.visitSource(type.getName() + "Proxy.java", null); if (type.isLocalClass()) { String enclosingName = Type.getInternalName(type.getEnclosingClass()); cw.visitInnerClass(interfazeName, enclosingName, type.getSimpleName(), ACC_PUBLIC + ACC_STATIC + ACC_ABSTRACT + ACC_INTERFACE); } writeConstructor(cw, proxyClassDescriptor); Method[] methods = type.getMethods(); int index = 0; for (Method method : methods) { String signature = calculateWriteParametersSignature(method); Class<?>[] parameterTypes = method.getParameterTypes(); generateMethod(cw, method, index, proxyClassNameInternal, signature); writeGenerateParametersMethod(cw, index, signature, parameterTypes); index++; } cw.visitEnd(); return cw.toByteArray(); }
From source file:org.gradle.initialization.DefaultLegacyTypesSupport.java
License:Apache License
@Override public byte[] generateSyntheticClass(String name) { ClassWriter visitor = new ClassWriter(0); visitor.visit(Opcodes.V1_7, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT, name.replace('.', '/'), null, OBJECT_TYPE.getInternalName(), null); visitor.visitEnd();//from w w w .j a v a 2 s.c om return visitor.toByteArray(); }
From source file:org.icesquirrel.compiler.SquirrelCompiler.java
License:Open Source License
public void compile(InputStream in, String scriptName) throws Exception { SquirrelLexer l = new SquirrelLexer(new ANTLRInputStream(in)); SquirrelParser p = new SquirrelParser(new CommonTokenStream(l)); p.addErrorListener(new BaseErrorListener() { @Override/*from ww w . j a v a 2 s . c om*/ public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { throw new IllegalStateException("failed to parse at line " + line + " due to " + msg, e); } }); ScriptContext script = p.script(); // Determine class name String className = convertClassName((namespace == null ? "" : namespace + ".") + scriptName); LOG.info(String.format("Generating class %s", className)); // Write the class definition and main() method ClassWriter cw = new ClassWriter(0); cw.visit(Opcodes.V1_7, Opcodes.ACC_PUBLIC, className, null, "java/lang/Object", new String[] { convertClassName(SquirrelMain.class.getName()) }); final MethodVisitor visitMethod = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "main", "(L[java/lang/String;)V", null, null); compileMain(cw, visitMethod, script); visitMethod.visitEnd(); // Finish writing the main class cw.visitEnd(); // Output the class file File dir = namespace == null ? output : new File(output, namespace.replace('.', File.separatorChar)); if (!dir.exists() && !dir.mkdirs()) { throw new IOException(String.format("Could not create output directory %s", dir)); } File classFile = new File(dir, scriptName + ".class"); LOG.info(String.format("Writing class to %s", classFile.getPath())); FileOutputStream fos = new FileOutputStream(classFile); try { fos.write(cw.toByteArray()); } finally { fos.close(); } }
From source file:org.jacoco.core.internal.analysis.ContentTypeDetector.java
License:Open Source License
private static int determineType(final InputStream in) throws IOException { switch (readInt(in)) { case ZIPFILE: return ZIPFILE; case CLASSFILE: // also verify version to distinguish from Mach Object files: switch (readInt(in)) { case Opcodes.V1_1: case Opcodes.V1_2: case Opcodes.V1_3: case Opcodes.V1_4: case Opcodes.V1_5: case Opcodes.V1_6: case Opcodes.V1_7: return CLASSFILE; }//from www .ja va 2 s . c om } return UNKNOWN; }
From source file:org.jacoco.core.internal.ContentTypeDetector.java
License:Open Source License
private static int determineType(final InputStream in) throws IOException { final int header = readInt(in); switch (header) { case ZIPFILE: return ZIPFILE; case PACK200FILE: return PACK200FILE; case CLASSFILE: // also verify version to distinguish from Mach Object files: switch (readInt(in)) { case Opcodes.V1_1: case Opcodes.V1_2: case Opcodes.V1_3: case Opcodes.V1_4: case Opcodes.V1_5: case Opcodes.V1_6: case Opcodes.V1_7: return CLASSFILE; }//ww w .java2 s . c om } if ((header & 0xffff0000) == GZFILE) { return GZFILE; } return UNKNOWN; }
From source file:org.jacoco.core.internal.data.CRC64Test.java
License:Open Source License
@Test public void except_java_9_checksums_should_be_different_for_different_bytecode_versions() { assertEquals(0x589E9080A572741EL, CRC64.classId(createClass(Opcodes.V10))); // should remove workaround for Java 9 // during change of exec file version assertEquals(0x1007, ExecutionDataWriter.FORMAT_VERSION); assertEquals(0xB5284860A572741CL, CRC64.classId(createClass(Opcodes.V9))); assertEquals(0xB5284860A572741CL, CRC64.classId(createClass(Opcodes.V1_8))); assertEquals(0x45284D30A572741AL, CRC64.classId(createClass(Opcodes.V1_7))); }
From source file:org.jacoco.core.internal.instr.ProbeArrayStrategyFactoryTest.java
License:Open Source License
@Test public void testClass7() { final IProbeArrayStrategy strategy = test(Opcodes.V1_7, 0, false, true, true); assertEquals(ClassFieldProbeArrayStrategy.class, strategy.getClass()); assertDataField(InstrSupport.DATAFIELD_ACC); assertInitMethod(true);/*w w w. jav a2 s. co m*/ }
From source file:org.jacoco.core.internal.instr.ProbeArrayStrategyFactoryTest.java
License:Open Source License
@Test public void testInterface7() { final IProbeArrayStrategy strategy = test(Opcodes.V1_7, Opcodes.ACC_INTERFACE, true, false, true); assertEquals(LocalProbeArrayStrategy.class, strategy.getClass()); assertNoDataField();// w w w.j a va 2 s . c o m assertNoInitMethod(); }