getFullName/getFullAlias have no trailing dot anymore

allow preservation of packages


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@812 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent c6010dfefe
commit fb10437749
  1. 55
      jode/jode/obfuscator/PackageIdentifier.java

@ -49,6 +49,14 @@ public class PackageIdentifier extends Identifier {
setLoadOnDemand(); setLoadOnDemand();
} }
/**
* Marks the parent package as preserved, too.
*/
protected void setSinglePreserved() {
if (parent != null)
parent.setPreserved();
}
public void setLoadOnDemand() { public void setLoadOnDemand() {
if (loadOnDemand) if (loadOnDemand)
return; return;
@ -286,12 +294,11 @@ public class PackageIdentifier extends Identifier {
public void preserveMatchingIdentifier(WildCard wildcard) { public void preserveMatchingIdentifier(WildCard wildcard) {
String component = wildcard.getNextComponent(getFullName()); String component = wildcard.getNextComponent(getFullName());
if (component != null) { if (component != null) {
String fullname = getFullName();
fullname = (fullname.length() > 0)
? fullname + "."+ component : component;
Identifier ident = (Identifier) loadedClasses.get(component); Identifier ident = (Identifier) loadedClasses.get(component);
if (ident == null && loadOnDemand) { if (ident == null && loadOnDemand) {
String fullname = getFullName();
fullname = (fullname.length() > 0)
? fullname + "."+ component
: component;
if (ClassInfo.isPackage(fullname)) { if (ClassInfo.isPackage(fullname)) {
ident = new PackageIdentifier(bundle, this, ident = new PackageIdentifier(bundle, this,
component, loadOnDemand); component, loadOnDemand);
@ -308,7 +315,12 @@ public class PackageIdentifier extends Identifier {
ident.applyPreserveRule(bundle.preserveRule); ident.applyPreserveRule(bundle.preserveRule);
} }
} }
if (wildcard.startsWith(ident.getFullName()+".")) { if (wildcard.matches(fullname)) {
if (GlobalOptions.verboseLevel > 1)
GlobalOptions.err.println("preserving "+ident);
ident.setPreserved();
}
if (wildcard.startsWith(fullname+".")) {
if (ident instanceof PackageIdentifier) if (ident instanceof PackageIdentifier)
((PackageIdentifier) ident) ((PackageIdentifier) ident)
.preserveMatchingIdentifier(wildcard); .preserveMatchingIdentifier(wildcard);
@ -330,7 +342,7 @@ public class PackageIdentifier extends Identifier {
continue; continue;
String subFull = fullname + subclazz; String subFull = fullname + subclazz;
if (wildcard.startsWith(subFull + ".")) { if (wildcard.startsWith(subFull)) {
if (ClassInfo.isPackage(subFull)) { if (ClassInfo.isPackage(subFull)) {
Identifier ident = new PackageIdentifier Identifier ident = new PackageIdentifier
(bundle, this, subclazz, true); (bundle, this, subclazz, true);
@ -350,6 +362,11 @@ public class PackageIdentifier extends Identifier {
Enumeration enum = loadedClasses.elements(); Enumeration enum = loadedClasses.elements();
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
Identifier ident = (Identifier) enum.nextElement(); Identifier ident = (Identifier) enum.nextElement();
if (wildcard.matches(ident.getFullName())) {
if (GlobalOptions.verboseLevel > 1)
GlobalOptions.err.println("Preserving "+ident);
ident.setPreserved();
}
if (wildcard.startsWith(ident.getFullName()+".")) { if (wildcard.startsWith(ident.getFullName()+".")) {
if (ident instanceof PackageIdentifier) if (ident instanceof PackageIdentifier)
((PackageIdentifier) ident) ((PackageIdentifier) ident)
@ -376,13 +393,16 @@ public class PackageIdentifier extends Identifier {
} }
/** /**
* @return the full qualified alias, including trailing dot. * @return the full qualified alias.
*/ */
public String getFullAlias() { public String getFullAlias() {
if (parent != null) if (parent != null) {
return parent.getFullAlias() + getAlias() + "."; if (parent.getFullAlias().length() > 0)
else return parent.getFullAlias() + "." + getAlias();
return ""; else
return getAlias();
}
return "";
} }
public String findAlias(String className) { public String findAlias(String className) {
@ -405,9 +425,9 @@ public class PackageIdentifier extends Identifier {
Enumeration enum = loadedClasses.elements(); Enumeration enum = loadedClasses.elements();
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
Identifier ident = (Identifier) enum.nextElement(); Identifier ident = (Identifier) enum.nextElement();
if (ident instanceof ClassIdentifier) { if (ident instanceof ClassIdentifier)
((ClassIdentifier) ident).buildTable(renameRule); ((ClassIdentifier) ident).buildTable(renameRule);
} else else
((PackageIdentifier) ident).buildTable(renameRule); ((PackageIdentifier) ident).buildTable(renameRule);
} }
} }
@ -425,7 +445,7 @@ public class PackageIdentifier extends Identifier {
public void readTable(Hashtable table) { public void readTable(Hashtable table) {
if (parent != null) if (parent != null)
setAlias((String) table.get(parent.getFullName() + getName())); setAlias((String) table.get(getFullName()));
Enumeration enum = loadedClasses.elements(); Enumeration enum = loadedClasses.elements();
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
Identifier ident = (Identifier) enum.nextElement(); Identifier ident = (Identifier) enum.nextElement();
@ -436,7 +456,7 @@ public class PackageIdentifier extends Identifier {
public void writeTable(Hashtable table) { public void writeTable(Hashtable table) {
if (parent != null) if (parent != null)
table.put(parent.getFullAlias() + getAlias(), getName()); table.put(getFullAlias(), getName());
Enumeration enum = loadedClasses.elements(); Enumeration enum = loadedClasses.elements();
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
Identifier ident = (Identifier) enum.nextElement(); Identifier ident = (Identifier) enum.nextElement();
@ -481,7 +501,7 @@ public class PackageIdentifier extends Identifier {
zip.closeEntry(); zip.closeEntry();
} catch (java.io.IOException ex) { } catch (java.io.IOException ex) {
GlobalOptions.err.println("Can't write Class " GlobalOptions.err.println("Can't write Class "
+ ident.getName()); + ident.getName());
ex.printStackTrace(GlobalOptions.err); ex.printStackTrace(GlobalOptions.err);
} }
} }
@ -531,8 +551,7 @@ public class PackageIdentifier extends Identifier {
} }
public String toString() { public String toString() {
return (parent == null) ? "base package" return (parent == null) ? "base package" : getFullName();
: parent.getFullName()+getName();
} }
public boolean contains(String newAlias) { public boolean contains(String newAlias) {

Loading…
Cancel
Save