public static CtClass listType(String className) { try { return ClassPool.getDefault().get(className+"[]"); } catch (NotFoundException e) { e.printStackTrace(); return voidType; } } }
public static CtClass type(Class<?> clazz) { try { return ClassPool.getDefault().get(clazz.getName()); } catch (NotFoundException e) { e.printStackTrace(); return voidType; } }
public void defineStructSetCAS(FSTClazzInfo.FSTFieldInfo casAcc, FSTClazzInfo clInfo, CtMethod method) { int off = casAcc.getStructOffset(); try { if ( method.getParameterTypes().length != 2 ) { throw new RuntimeException("CAS setter requires expected and newValue args"); } } catch (NotFoundException e) { e.printStackTrace(); } try { if ( casAcc.getType() == int.class ) { method.setBody("return ___bytes.compareAndSwapInt("+off+"+___offset,$1,$2);"); } else if ( casAcc.getType() == int.class ) { method.setBody("return ___bytes.compareAndSwapLong("+off+"+___offset,$1,$2);"); } else { throw new RuntimeException("CAS access only applicable to int and long."); } } catch (CannotCompileException e) { throw new RuntimeException(e); } }
@Override public DynamicBean removeField(String fieldName) { try { clazz.removeField(clazz.getField(fieldName)); clazz.removeMethod(clazz.getDeclaredMethod("get" + StringUtils.capitalize(fieldName))); clazz.removeMethod(clazz.getDeclaredMethod("set" + StringUtils.capitalize(fieldName))); } catch (NotFoundException e) { e.printStackTrace(); log.error("can't remove field : " + fieldName); } return this; }
public void defineStructSetCAS(FSTClazzInfo.FSTFieldInfo casAcc, FSTClazzInfo clInfo, CtMethod method) { int off = casAcc.getStructOffset(); try { if ( method.getParameterTypes().length != 2 ) { throw new RuntimeException("CAS setter requires expected and newValue args"); } } catch (NotFoundException e) { e.printStackTrace(); } try { if ( casAcc.getType() == int.class ) { method.setBody("return ___bytes.compareAndSwapInt("+off+"+___offset,$1,$2);"); } else if ( casAcc.getType() == int.class ) { method.setBody("return ___bytes.compareAndSwapLong("+off+"+___offset,$1,$2);"); } else { throw new RuntimeException("CAS access only applicable to int and long."); } } catch (CannotCompileException e) { throw new RuntimeException(e); } }
@Override public void defineArrayPointer(FSTClazzInfo.FSTFieldInfo indexfi, FSTClazzInfo clInfo, CtMethod method) { int index = indexfi.getStructOffset(); CtClass[] parameterTypes = new CtClass[0]; try { parameterTypes = method.getParameterTypes(); } catch (NotFoundException e) { e.printStackTrace(); } if ( parameterTypes != null && parameterTypes.length ==1 ) { try { if (indexfi.isIntegral()) { method.setBody("{ ___fac.fillPrimitiveArrayBasePointer($1,___bytes, ___offset, "+index+"); }"); } else { method.setBody("{ ___fac.fillTypedArrayBasePointer($1,___bytes, ___offset, "+index+"); }"); } } catch (CannotCompileException e) { throw new RuntimeException(e); } } else { try { if (indexfi.isIntegral()) { method.setBody("{ return (org.nustaq.offheap.structs.FSTStruct)___fac.createPrimitiveArrayBasePointer(___bytes, ___offset, "+index+"); }"); } else method.setBody("{ return ("+indexfi.getArrayType().getName()+")___fac.createTypedArrayBasePointer(___bytes, ___offset, "+index+"); }"); } catch (CannotCompileException e) { throw new RuntimeException(e); } } }
@Override public void defineArrayPointer(FSTClazzInfo.FSTFieldInfo indexfi, FSTClazzInfo clInfo, CtMethod method) { int index = indexfi.getStructOffset(); CtClass[] parameterTypes = new CtClass[0]; try { parameterTypes = method.getParameterTypes(); } catch (NotFoundException e) { e.printStackTrace(); } if ( parameterTypes != null && parameterTypes.length ==1 ) { try { if (indexfi.isIntegral()) { method.setBody("{ ___fac.fillPrimitiveArrayBasePointer($1,___bytes, ___offset, "+index+"); }"); } else { method.setBody("{ ___fac.fillTypedArrayBasePointer($1,___bytes, ___offset, "+index+"); }"); } } catch (CannotCompileException e) { throw new RuntimeException(e); } } else { try { if (indexfi.isIntegral()) { method.setBody("{ return (org.nustaq.offheap.structs.FSTStruct)___fac.createPrimitiveArrayBasePointer(___bytes, ___offset, "+index+"); }"); } else method.setBody("{ return ("+indexfi.getArrayType().getName()+")___fac.createTypedArrayBasePointer(___bytes, ___offset, "+index+"); }"); } catch (CannotCompileException e) { throw new RuntimeException(e); } } }
e.printStackTrace(); return new String[0];
try { drawable = Resources.getSystem().getDrawable(R.drawable.icon); } catch (NotFoundException e) { e.printStackTrace(); }
try { m.addLocalVariable(mse, ClassPool.getDefault().get("org.javadynamicanalyzer.MethodStackEntry")); } catch (NotFoundException e) { e.printStackTrace(); } int mseCSindex=m.getMethodInfo().getCodeAttribute().getMaxLocals()-1;
/** * Determines the ImageJ 1.x version without loading the ImageJ 1.x classes. * * @param hacker the {@link CodeHacker} instance to use * @return the ImageJ 1.x version */ public static String getImageJ1Version(final CodeHacker hacker) { try { return hacker.getConstant("ij.ImageJ", "VERSION"); } catch (final NotFoundException e) { e.printStackTrace(); return null; } }
/** * Verify that CtField is exactly the java.util.Collection, java.util.List or java.util.Set, otherwise cannot instrument the class' field */ private boolean isCtFieldACollection(CtField ctField) { try { return ctField.getType().equals(cp.get(Collection.class.getName())) || ctField.getType().equals(cp.get(List.class.getName())) || ctField.getType().equals(cp.get(Set.class.getName())) ; } catch (NotFoundException e) { e.printStackTrace(); return false; } } }
/** * Verify that CtField is exactly the java.util.Collection, java.util.List or java.util.Set, otherwise cannot instrument the class' field */ private boolean isCtFieldACollection(CtField ctField) { try { return ctField.getType().equals(cp.get(Collection.class.getName())) || ctField.getType().equals(cp.get(List.class.getName())) || ctField.getType().equals(cp.get(Set.class.getName())) ; } catch (NotFoundException e) { e.printStackTrace(); return false; } } }
public boolean acceptConstr(CtConstructor constr) { try { CtClass[] paramTypes = constr.getParameterTypes(); String[] params = new String[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) { params[i] = paramTypes[i].getName(); } return acceptConstr(params); } catch (NotFoundException nfe) { nfe.printStackTrace(); return false; } }
public void updateLoaderWithLienzoTranslator(final Loader loader, final Translator translator) { try { final LienzoMockitoClassTranslator lienzoTranslator = new LienzoMockitoClassTranslator(settings, translator); loader.addTranslator(ClassPool.getDefault(), lienzoTranslator); } catch (final NotFoundException e) { e.printStackTrace(); } catch (final CannotCompileException e) { e.printStackTrace(); } } }
public void updateLoaderWithLienzoTranslator(final Loader loader, final Translator translator) { try { final LienzoMockitoClassTranslator lienzoTranslator = new LienzoMockitoClassTranslator(settings, translator); loader.addTranslator(ClassPool.getDefault(), lienzoTranslator); } catch (final NotFoundException e) { e.printStackTrace(); } catch (final CannotCompileException e) { e.printStackTrace(); } } }
new ExprEditor() { @Override public void edit(MethodCall m) throws CannotCompileException { try { if (m.where().getName().equals(sourceMethod)) { if (m.getMethod().getName().equals(methodcalltoReplace)) { if(lineNumberOfMethodcalltoReplace == m.getLineNumber()){ // The content of the hardcoded string can be replaced with runtime data m.replace("$_ = ($r)"+"new com.nuwaza.aqua.sample.SampleForMethodInvocationFieldAccess().helloworld();"); } } } } catch (NotFoundException e) { e.printStackTrace(); } super.edit(m); }
@Override public void write(DiagramBean bean) throws IOException { CalledMethod r = DiagramRecorder.currentDiagramBean.getRoot(); assertEquals(1, r.getChildren().size()); try { assertEquals( pool.get( sk.anivit.stacktracegen.recording.Test.class .getName()).getDeclaredMethod( "testik"), r.getMethod()); } catch (NotFoundException e) { fail(e.getMessage()); e.printStackTrace(); } bean.setStopTime(-10); } });