List of usage examples for org.objectweb.asm ClassReader EXPAND_FRAMES
int EXPAND_FRAMES
To view the source code for org.objectweb.asm ClassReader EXPAND_FRAMES.
Click Source Link
From source file:appeng.core.api.ApiPart.java
License:Open Source License
public ClassNode getReader(String name) { ClassReader cr;/*from ww w.j a v a2 s .c o m*/ String path = '/' + name.replace(".", "/") + ".class"; InputStream is = this.getClass().getResourceAsStream(path); try { cr = new ClassReader(is); ClassNode cn = new ClassNode(); cr.accept(cn, ClassReader.EXPAND_FRAMES); return cn; } catch (IOException e) { throw new IllegalStateException("Error loading " + name, e); } }
From source file:asmlib.UninitializedCallChecker.java
License:Open Source License
public static void verify(ClassReader cr, PrintWriter pw) { // O AnalyzerAdapter // precisa que as frames estejam delimitadas no cdigo para funcionar correctamente. // Frames parecem ser obrigatrias a partir do Java 6, mas muitas classes no as tm // por isso fazemos mais um pass com um ClassWriter, para obtermos uma classe com // as frames calculadas. ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); cr.accept(cw, 0);/*w ww . j a va 2s. c o m*/ cr = new ClassReader(cw.toByteArray()); try { cr.accept(new GenericMethodVisitorAdapter(new EmptyClassVisitor(), UninitializedCallChecker.class, cr.getClassName(), pw), ClassReader.EXPAND_FRAMES); } catch (ArrayIndexOutOfBoundsException e) { } }
From source file:br.ufpr.gres.core.classpath.Resources.java
License:Apache License
private List<ClassDetails> getClasses(final File file, String filter) throws IOException, ClassNotFoundException { final List<ClassDetails> classNames = new LinkedList<>(); if (file.exists()) { for (final File f : file.listFiles()) { if (f.isDirectory()) { classNames.addAll(getClasses(f, filter)); } else if (f.getName().endsWith(filter)) { final ClassContext context = new ClassContext(); final ClassReader first = new ClassReader(FileUtils.readFileToByteArray(f)); final NullVisitor nv = new NullVisitor(); final RegisterInformationsClassVisitor mca = new RegisterInformationsClassVisitor(context, nv); first.accept(mca, ClassReader.EXPAND_FRAMES); classNames.add(new ClassDetails(context.getClassInfo(), f, this.root)); }//w ww. j a v a 2s.c o m } } return classNames; }
From source file:br.ufpr.gres.core.MutationTest.java
License:Apache License
public Mutant getMutation(final MutationIdentifier id, byte[] classToMutate) { Collection<IMutationOperator> mutators = MUTATORS.stream().collect(Collectors.toList()); Collection<IMutationOperator> mutatorsFiltered = mutators.stream() .filter(p -> id.getMutator().equals(p.getName())).collect(Collectors.toList()); final ClassContext context = new ClassContext(); context.setTargetMutation(id);/* w w w. ja va 2 s . c o m*/ // Lembrar de usar isso aqui (ClassPathByteArraySource - pitest) // GregorMutater... carregar os bytes // final Optional<byte[]> bytes = this.byteSource.getBytes(id.getClassName() // .asJavaName()); //final PremutationClassInfo classInfo = performPreScan(classToMutate); final ClassReader reader = new ClassReader(classToMutate); final ClassWriter w = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); final MutatingClassVisitor mca = new MutatingClassVisitor(mutatorsFiltered, context, w); reader.accept(mca, ClassReader.EXPAND_FRAMES); final List<MutationDetails> details = context.getCollectedMutations(); return new Mutant(details.stream().filter(p -> p.getId().equals(id)).findFirst().get(), w.toByteArray()); }
From source file:br.ufpr.gres.core.MutationTest.java
License:Apache License
public Mutant getHigherOrderMutant(final ArrayList<MutationIdentifier> ids, byte[] classToMutate) { Collection<IMutationOperator> mutators = MUTATORS.stream().collect(Collectors.toList()); //Collection<IMutationOperator> mutatorsFiltered = mutators.stream().filter(p ->.getMutator().equals(p.getName())).collect(Collectors.toList()); final ClassContext context = new ClassContext(); context.setTargetMutation(ids);/*from w w w . j av a 2 s. co m*/ // Lembrar de usar isso aqui (ClassPathByteArraySource - pitest) // GregorMutater... carregar os bytes // final Optional<byte[]> bytes = this.byteSource.getBytes(id.getClassName() // .asJavaName()); //final PremutationClassInfo classInfo = performPreScan(classToMutate); final ClassReader reader = new ClassReader(classToMutate); final ClassWriter w = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); final MutatingClassVisitor mca = new MutatingClassVisitor(mutators, context, w); reader.accept(mca, ClassReader.EXPAND_FRAMES); List<MutationDetails> details = new ArrayList<>(); for (MutationDetails detail : context.getCollectedMutations()) { if (ids.stream().anyMatch(p -> p.equals(detail.getId()))) { details.add(detail); } } return new Mutant(details, w.toByteArray()); }
From source file:br.ufpr.gres.core.MutationTest.java
License:Apache License
@Test public void mutation() throws Exception { String directory = Paths.get(System.getProperty("user.dir")) + File.separator + "examples" + File.separator + "bub"; ClassDetails classes = new Resources(directory).getClasses().get(0); final byte[] classToMutate = classes.getBytes(); try (DataOutputStream dout = new DataOutputStream( new FileOutputStream(new File(directory + File.separator + "mutants", "Original.class")))) { dout.write(classToMutate);/*from w w w. j av a 2 s . co m*/ } catch (IOException ex) { ex.printStackTrace(); } final ClassContext context = new ClassContext(); //context.setTargetMutation(); final PremutationClassInfo classInfo = performPreScan(classToMutate); final ClassReader first = new ClassReader(classToMutate); final NullVisitor nv = new NullVisitor(); Collection<IMutationOperator> mutators = MUTATORS.stream().collect(Collectors.toList()); final MutatingClassVisitor mca = new MutatingClassVisitor(mutators, context, nv); first.accept(mca, ClassReader.EXPAND_FRAMES); if (!context.getTargetMutation().isEmpty()) { final List<MutationDetails> details = context.getMutationDetails(context.getTargetMutation().get(0)); } else { ArrayList<MutationDetails> details = new ArrayList(context.getCollectedMutations()); for (IMutationOperator operator : mutators) { int i = 0; for (MutationDetails detail : details.stream() .filter(p -> p.getMutator().equals(operator.getName())).collect(Collectors.toList())) { Mutant mutant = getMutation(detail.getId(), classToMutate); i++; System.out.println(mutant.getDetails().toString()); try (DataOutputStream dout = new DataOutputStream( new FileOutputStream(new File(directory + File.separator + "mutants", mutant.getDetails().get(0).getMutator() + "_" + i + ".class")))) { dout.write(mutant.getBytes()); } catch (IOException ex) { ex.printStackTrace(); } } } } ArrayList<MutationIdentifier> details = new ArrayList(context.getCollectedMutations().subList(0, 5).stream() .map(m -> m.getId()).collect(Collectors.toList())); System.out.println("Creating a mutant with order " + details.size()); Mutant mutant = getHigherOrderMutant(details, classToMutate); System.out.println("The new mutant"); System.out.println(mutant.toString()); try (DataOutputStream dout = new DataOutputStream( new FileOutputStream(new File(directory + File.separator + "mutants", "HOM.class")))) { dout.write(mutant.getBytes()); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:br.ufpr.gres.core.Mutator.java
License:Apache License
public static List<MutationDetails> doMutation(Collection<IMutationOperator> mutators, byte[] classToMutate) { final ClassContext context = new ClassContext(); final ClassReader first = new ClassReader(classToMutate); final NullVisitor nv = new NullVisitor(); final MutatingClassVisitor mca = new MutatingClassVisitor(mutators, context, nv); first.accept(mca, ClassReader.EXPAND_FRAMES); return context.getCollectedMutations(); }
From source file:br.ufpr.gres.core.Mutator.java
License:Apache License
public static Mutant getMutation(Collection<IMutationOperator> mutators, ArrayList<MutationIdentifier> ids, byte[] classToMutate) { final ClassContext context = new ClassContext(); context.setTargetMutation(ids);// w ww.j a v a 2s .c o m final ClassReader reader = new ClassReader(classToMutate); final ClassWriter w = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); final MutatingClassVisitor mca = new MutatingClassVisitor(mutators, context, w); reader.accept(mca, ClassReader.EXPAND_FRAMES); List<MutationDetails> details = new ArrayList<>(); for (MutationDetails detail : context.getCollectedMutations()) { if (ids.stream().anyMatch(p -> p.equals(detail.getId()))) { details.add(detail); } } return new Mutant(details, w.toByteArray()); }
From source file:br.usp.each.saeg.badua.cli.Report.java
License:Open Source License
public void run() throws IOException, ClassNotFoundException { data = read(inputFile);//from w w w .j a v a 2 s. co m final List<File> files = Files.listRecursive(classes, new FilenameFilter() { @Override public boolean accept(final File dir, final String name) { return new File(dir, name).isFile(); } }); for (final File file : files) { final InputStream input = new FileInputStream(file); final ContentTypeDetector detector = new ContentTypeDetector(input); try { if (detector.getType() == ContentTypeDetector.CLASSFILE) { final ClassReader cr = new ClassReader(detector.getInputStream()); final ClassNode cn = new ClassNode(Opcodes.ASM5); cr.accept(cn, ClassReader.EXPAND_FRAMES); classId = CRC64.checksum(cr.b); analyze(cn); } } finally { input.close(); } } }
From source file:br.usp.each.saeg.badua.core.instr.Instrumenter.java
License:Open Source License
public byte[] instrument(final ClassReader reader) { final long classId = CRC64.checksum(reader.b); final ClassWriter writer = new ClassWriter(reader, DEFAULT); final ClassVisitor ci = new ClassInstrumenter(classId, writer); reader.accept(ci, ClassReader.EXPAND_FRAMES); return writer.toByteArray(); }