Only remove abstract, but not public modifier in interface method

setJikesBlockIdentifier
SimpleMap instead of SimpleDictionary
minor fixes


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@925 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 2d4264eb5b
commit b6ebe189e2
  1. 48
      jode/jode/decompiler/MethodAnalyzer.java

@ -37,18 +37,23 @@ import jode.flow.TransformExceptionHandlers;
import jode.flow.Jump; import jode.flow.Jump;
import jode.jvm.CodeVerifier; import jode.jvm.CodeVerifier;
import jode.jvm.VerifyException; import jode.jvm.VerifyException;
import jode.util.SimpleDictionary; import jode.util.SimpleMap;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.BitSet; import java.util.BitSet;
import java.util.Stack; import java.util.Stack;
import java.util.Vector; import java.util.Vector;
import java.util.Dictionary;
import java.util.Enumeration; import java.util.Enumeration;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
///#ifdef JDK12
///import java.util.Map;
///#else
import jode.util.Map;
///#endif
public class MethodAnalyzer implements Analyzer, Scope, ClassDeclarer { public class MethodAnalyzer implements Analyzer, Scope, ClassDeclarer {
ImportHandler imports; ImportHandler imports;
ClassAnalyzer classAnalyzer; ClassAnalyzer classAnalyzer;
@ -78,6 +83,7 @@ public class MethodAnalyzer implements Analyzer, Scope, ClassDeclarer {
boolean isJikesConstructor; boolean isJikesConstructor;
boolean hasJikesOuterValue; boolean hasJikesOuterValue;
boolean isImplicitAnonymousConstructor; boolean isImplicitAnonymousConstructor;
boolean isJikesBlockInitializer;
/** /**
* This dictionary maps an anonymous ClassInfo to the * This dictionary maps an anonymous ClassInfo to the
@ -194,6 +200,10 @@ public class MethodAnalyzer implements Analyzer, Scope, ClassDeclarer {
isJikesConstructor = value; isJikesConstructor = value;
} }
public final void setJikesBlockInitializer(boolean value) {
isJikesBlockInitializer = value;
}
public final void setHasOuterValue(boolean value) { public final void setHasOuterValue(boolean value) {
hasJikesOuterValue = value; hasJikesOuterValue = value;
} }
@ -463,7 +473,22 @@ public class MethodAnalyzer implements Analyzer, Scope, ClassDeclarer {
&& classAnalyzer.outerValues.length > 0 ? 1 : 0; && classAnalyzer.outerValues.length > 0 ? 1 : 0;
} }
if (isJikesBlockInitializer)
return true;
if (declareAsConstructor if (declareAsConstructor
/* The access rights of default constructor should
* be public, iff the class is public, otherwise package.
* But this rule doesn't necessarily apply for anonymous
* classes...
*/
&& ((minfo.getModifiers() & Modifier.PUBLIC)
== (getClazz().getModifiers() & Modifier.PUBLIC)
|| classAnalyzer.getName() == null)
&& (minfo.getModifiers()
& (Modifier.PRIVATE | Modifier.PROTECTED
| Modifier.SYNCHRONIZED | Modifier.STATIC
| Modifier.ABSTRACT | Modifier.NATIVE)) == 0
&& classAnalyzer.constructors.length == 1) { && classAnalyzer.constructors.length == 1) {
// If this is the only constructor and it is empty and // If this is the only constructor and it is empty and
@ -480,6 +505,11 @@ public class MethodAnalyzer implements Analyzer, Scope, ClassDeclarer {
if (isImplicitAnonymousConstructor) if (isImplicitAnonymousConstructor)
return true; return true;
} }
if (isConstructor() && isStatic()
&& getMethodHeader().getBlock() instanceof jode.flow.EmptyBlock)
return true;
return false; return false;
} }
@ -508,10 +538,6 @@ public class MethodAnalyzer implements Analyzer, Scope, ClassDeclarer {
analyzeCode(); analyzeCode();
} }
if (isConstructor() && isStatic()
&& getMethodHeader().getBlock() instanceof jode.flow.EmptyBlock)
return;
if (minfo.isDeprecated()) { if (minfo.isDeprecated()) {
writer.println("/**"); writer.println("/**");
writer.println(" * @deprecated"); writer.println(" * @deprecated");
@ -536,10 +562,12 @@ public class MethodAnalyzer implements Analyzer, Scope, ClassDeclarer {
* Every method declaration in the body of an interface is * Every method declaration in the body of an interface is
* implicitly public. It is permitted, but strongly * implicitly public. It is permitted, but strongly
* discouraged as a matter of style, to redundantly specify * discouraged as a matter of style, to redundantly specify
* the public modifier for interface methods. * the public modifier for interface methods. We don't
* follow this second rule and mark this method explicitly
* as public.
*/ */
if (classAnalyzer.getClazz().isInterface()) if (classAnalyzer.getClazz().isInterface())
modifiedModifiers &= ~(Modifier.PUBLIC | Modifier.ABSTRACT); modifiedModifiers &= ~Modifier.ABSTRACT;
String modif = Modifier.toString(modifiedModifiers); String modif = Modifier.toString(modifiedModifiers);
if (modif.length() > 0) if (modif.length() > 0)
writer.print(modif+" "); writer.print(modif+" ");
@ -738,7 +766,7 @@ public class MethodAnalyzer implements Analyzer, Scope, ClassDeclarer {
*/ */
class ShrinkOnShrink implements OuterValueListener { class ShrinkOnShrink implements OuterValueListener {
Dictionary limits = new SimpleDictionary(); Map limits = new SimpleMap();
public void setLimit(ClassAnalyzer other, public void setLimit(ClassAnalyzer other,
int newLimit) { int newLimit) {
@ -993,6 +1021,6 @@ public class MethodAnalyzer implements Analyzer, Scope, ClassDeclarer {
} }
public String toString() { public String toString() {
return "MethodAnalyzer["+getClazz()+"."+getName()+"]"; return getClass().getName()+"["+getClazz()+"."+getName()+"]";
} }
} }

Loading…
Cancel
Save