RE: Missing type information (not seen in visitor)

2017-09-25 Thread Showalter, Jim
org.apache.bcel

-Original Message-
From: Gary Gregory [mailto:garydgreg...@gmail.com] 
Sent: Monday, September 25, 2017 6:15 PM
To: Commons Users List <user@commons.apache.org>
Subject: Re: Missing type information (not seen in visitor)

Which Commons component are you using?

Gary

On Sep 25, 2017 17:05, "Showalter, Jim" <jim_showal...@intuit.com> wrote:

> We have two classes like this:
>
> package com.intuit.foo;
>
> public class Foo {
> }
>
> public class FooHolder {
>private List foos = new ArrayList<>(); }
>
> After visiting both classes and dumping out the info, I see this:
>
> com/intuit/foo/Foo:
>   class, lines 0 to ~2, deletable, public
>
> com/intuit/foo/Foos:
>   class, lines 0 to ~2, not-deletable, public
>   type references
> 
>   field declarations
> com/intuit/obill/v1/quote/response/Quote:chargeDetails:
> Ljava/util/List;
>
> Note that the type Foo is not seen in when visiting the Foos. Because 
> there are no other references to Foo anywhere, this results in a 
> false-positive delete of Foo.java.
>
> I collect all of the referred-to types in the visitor like this:
>
>@Override
>public void visitConstantClass(final ConstantClass obj) {
>   String className = 
> JavaUtils.dotsToSlashes( 
> javaClass().getConstantPool().getConstant(obj.getNameIndex()).toString
> ().replace("\")",
> "").replaceAll("^.*\"", ""));
>   if (ignore(className)) {
>  return;
>   }
>   type().addTypeReference(className);
>}
>
> What am I doing wrong?
>
> Jim Showalter
> Programmer
> Intuit, 2003H-265Z
> Garcia Avenue
> Mountain View, CA 94043
> (408) 353-4954 [home]
> (408) 204-1661 [personal cell]
> (669) 271-2257 [work cell]
>
>


Missing type information (not seen in visitor)

2017-09-25 Thread Showalter, Jim
We have two classes like this:

package com.intuit.foo;

public class Foo {
}

public class FooHolder {
   private List foos = new ArrayList<>();
}

After visiting both classes and dumping out the info, I see this:

com/intuit/foo/Foo:
  class, lines 0 to ~2, deletable, public

com/intuit/foo/Foos:
  class, lines 0 to ~2, not-deletable, public
  type references

  field declarations
com/intuit/obill/v1/quote/response/Quote:chargeDetails:Ljava/util/List;

Note that the type Foo is not seen in when visiting the Foos. Because there are 
no other references to Foo anywhere, this results in a false-positive delete of 
Foo.java.

I collect all of the referred-to types in the visitor like this:

   @Override
   public void visitConstantClass(final ConstantClass obj) {
  String className = 
JavaUtils.dotsToSlashes(javaClass().getConstantPool().getConstant(obj.getNameIndex()).toString().replace("\")",
 "").replaceAll("^.*\"", ""));
  if (ignore(className)) {
 return;
  }
  type().addTypeReference(className);
   }

What am I doing wrong?

Jim Showalter
Programmer
Intuit, 2003H-265Z
Garcia Avenue
Mountain View, CA 94043
(408) 353-4954 [home]
(408) 204-1661 [personal cell]
(669) 271-2257 [work cell]



isNested returns false for aspects

2017-09-14 Thread Showalter, Jim
We have a class com/intuit/foo/Bar$AjcClosure1 that returns false from isNested.

Jim Showalter
Programmer
Intuit, 2003H-265Z
Garcia Avenue
Mountain View, CA 94043
(408) 353-4954
(408) 204-1661



RE: [BCEL] Re: How can I recover .class references separate from other references to classes using BCEL?

2017-09-10 Thread Showalter, Jim
This works:

public void visitCode(final Code obj) {
ConstantPoolGen cpg = new 
ConstantPoolGen(javaClass.getConstantPool());
InstructionList list = new InstructionList(obj.getCode());
Iterator iter = list.iterator();
while (iter.hasNext()) {
Instruction instruction = 
((InstructionHandle)iter.next()).getInstruction();
if (instruction instanceof LDC) {
LDC load = (LDC)instruction;
if 
(javaClass().getConstantPool().getConstant(load.getIndex()).getTag() == 
Const.CONSTANT_Class) {
Object val = load.getValue(cpg);
System.out.println(type.classFileName() 
+ ": " + val);
}
}
}
}

-Original Message-
From: Stephan Herrmann [mailto:stephan.herrm...@berlin.de] 
Sent: Sunday, September 10, 2017 1:12 PM
To: user@commons.apache.org
Subject: [BCEL] Re: How can I recover .class references separate from other 
references to classes using BCEL?

quick guess: check if the previous instruction is ldc.

HTH,
Stephan

On 10.09.2017 21:50, Showalter, Jim wrote:
> The use case is, suppose you want to recover the source from a .class file.
> 
> In the original source, it said:
> 
> public class SomeExperiment {
>   public static void main(String[] args) {
>   System.out.println(SomeOtherClass.class); <<< WANT TO RECOVER THE 
> ".class" FROM HERE
>   }
> }
> 
> In the visitor I wrote, there's an override:
> 
>   public void visitConstantClass(final ConstantClass obj) {
> String className = 
> JavaUtils.dotsToSlashes(javaClass().getConstantPool().getConstant(obj.getNameIndex()).toString());
>System.out.println(class file name + ": " + className);
>   }
> 
> Dumping out the data on a .class from a .java file that contains no 
> occurrences of the string ".class", I get:
> 
> com/intuit/qbo/Misc.class: com/intuit/qbo/Misc$Reader
> com/intuit/qbo/Misc.class: com/intuit/qbo/util/SomeException
> com/intuit/qbo/Misc.class: com/intuit/qbo/Misc
> com/intuit/qbo/Misc.class: com/intuit/qbo/api/MiscIf
> 
> This means ClassConstant isn't just for .class references. It's for all 
> references to classes.
> 
> How can I use BCEL to recover the original ".class" reference in 
> SomeExperiment?
> 
> Jim Showalter
> Programmer
> Intuit, 2003H-265Z
> Garcia Avenue
> Mountain View, CA 94043
> (408) 353-4954
> (408) 204-1661
> 
> 


-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org


-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



How can I recover .class references separate from other references to classes using BCEL?

2017-09-10 Thread Showalter, Jim
The use case is, suppose you want to recover the source from a .class file.

In the original source, it said:

public class SomeExperiment {
 public static void main(String[] args) {
 System.out.println(SomeOtherClass.class); <<< WANT TO RECOVER THE ".class" 
FROM HERE
 }
}

In the visitor I wrote, there's an override:

 public void visitConstantClass(final ConstantClass obj) {
   String className = 
JavaUtils.dotsToSlashes(javaClass().getConstantPool().getConstant(obj.getNameIndex()).toString());
  System.out.println(class file name + ": " + className);
 }

Dumping out the data on a .class from a .java file that contains no occurrences 
of the string ".class", I get:

com/intuit/qbo/Misc.class: com/intuit/qbo/Misc$Reader
com/intuit/qbo/Misc.class: com/intuit/qbo/util/SomeException
com/intuit/qbo/Misc.class: com/intuit/qbo/Misc
com/intuit/qbo/Misc.class: com/intuit/qbo/api/MiscIf

This means ClassConstant isn't just for .class references. It's for all 
references to classes.

How can I use BCEL to recover the original ".class" reference in SomeExperiment?

Jim Showalter
Programmer
Intuit, 2003H-265Z
Garcia Avenue
Mountain View, CA 94043
(408) 353-4954
(408) 204-1661