提交 9bf7270b 编写于 作者: S Skylot

reformat code, resolve compiler warnings

上级 a99e0e96
......@@ -10,8 +10,10 @@ subprojects {
version = jadxVersion
compileJava {
options.compilerArgs << '-Xlint'
gradle.projectsEvaluated {
tasks.withType(Compile) {
options.compilerArgs << "-Xlint" << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
jar {
......
#Tue Sep 24 21:49:47 MSK 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
......
package jadx.api;
public interface IJadxArgs {
int getThreadsCount();
int getThreadsCount();
boolean isCFGOutput();
boolean isCFGOutput();
boolean isRawCFGOutput();
boolean isRawCFGOutput();
boolean isFallbackMode();
boolean isFallbackMode();
boolean isVerbose();
boolean isVerbose();
}
......@@ -20,12 +20,26 @@ public final class JavaPackage implements Comparable<JavaPackage> {
}
@Override
public String toString() {
return name;
public int compareTo(JavaPackage o) {
return name.compareTo(o.name);
}
@Override
public int compareTo(JavaPackage o) {
return name.compareTo(o.name);
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
JavaPackage that = (JavaPackage) o;
if (!name.equals(that.name)) return false;
return true;
}
@Override
public int hashCode() {
return name.hashCode();
}
@Override
public String toString() {
return name;
}
}
......@@ -69,7 +69,7 @@ public class ClspGraph {
}
Set<String> anc = getAncestors(clsName);
NClass cls = nameMap.get(implClsName);
if(cls != null) {
if (cls != null) {
return searchCommonParent(anc, cls);
} else {
LOG.debug("Missing class: {}", implClsName);
......@@ -97,7 +97,7 @@ public class ClspGraph {
result = new HashSet<String>();
ancestorCache.put(clsName, result);
NClass cls = nameMap.get(clsName);
if(cls != null) {
if (cls != null) {
addAncestorsNames(cls, result);
} else {
LOG.debug("Missing class: {}", clsName);
......
......@@ -81,7 +81,7 @@ public class AnnotationGen {
if (vl.size() == 1 && vl.containsKey("value")) {
code.add(encValueToString(vl.get("value")));
} else {
for (Iterator<Entry<String, Object>> it = vl.entrySet().iterator(); it.hasNext();) {
for (Iterator<Entry<String, Object>> it = vl.entrySet().iterator(); it.hasNext(); ) {
Entry<String, Object> e = it.next();
code.add(e.getKey());
code.add(" = ");
......@@ -101,7 +101,7 @@ public class AnnotationGen {
if (an != null) {
Object exs = an.getDefaultValue();
code.add(" throws ");
for (Iterator<ArgType> it = ((List<ArgType>) exs).iterator(); it.hasNext();) {
for (Iterator<ArgType> it = ((List<ArgType>) exs).iterator(); it.hasNext(); ) {
ArgType ex = it.next();
code.add(TypeGen.translate(classGen, ex));
if (it.hasNext())
......@@ -163,7 +163,7 @@ public class AnnotationGen {
StringBuilder str = new StringBuilder();
str.append('{');
List<Object> list = (List<Object>) val;
for (Iterator<Object> it = list.iterator(); it.hasNext();) {
for (Iterator<Object> it = list.iterator(); it.hasNext(); ) {
Object obj = it.next();
str.append(encValueToString(obj));
if (it.hasNext())
......
......@@ -356,7 +356,7 @@ public class ClassGen {
return shortName;
// don't add import if this class from same package
if(classInfo.getPackage().equals(cls.getPackage()))
if (classInfo.getPackage().equals(cls.getPackage()))
return shortName;
for (ClassInfo cls : imports) {
......@@ -380,9 +380,9 @@ public class ClassGen {
private void insertSourceFileInfo(CodeWriter code, AttrNode node) {
IAttribute sourceFileAttr = node.getAttributes().get(AttributeType.SOURCE_FILE);
if(sourceFileAttr != null) {
if (sourceFileAttr != null) {
code.startLine(1, "// compiled from: ");
code.add(((SourceFileAttr)sourceFileAttr).getFileName());
code.add(((SourceFileAttr) sourceFileAttr).getFileName());
}
}
......
......@@ -167,7 +167,7 @@ public class CodeWriter {
buf.trimToSize();
for (Map.Entry<Object, Integer> entry : annotations.entrySet()) {
Object v = entry.getKey();
if(v instanceof LineAttrNode) {
if (v instanceof LineAttrNode) {
LineAttrNode l = (LineAttrNode) v;
l.setDecompiledLine(entry.getValue());
}
......
......@@ -36,8 +36,7 @@ public class TypeGen {
/**
* Convert literal value to string according to value type
*
* @throws JadxRuntimeException
* for incorrect type or literal value
* @throws JadxRuntimeException for incorrect type or literal value
*/
public static String literalToString(long lit, ArgType type) {
if (type == null || !type.isTypeKnown()) {
......
......@@ -7,7 +7,7 @@ import java.util.Set;
public class NameMapper {
private static final Set<String> reservedNames = new HashSet<String>(
Arrays.asList(new String[] {
Arrays.asList(new String[]{
"abstract",
"assert",
"boolean",
......
......@@ -129,7 +129,7 @@ public final class AttributesList {
if (type.isUniq()) {
uniqAttr.remove(type);
} else {
for (Iterator<IAttribute> it = attributes.iterator(); it.hasNext();) {
for (Iterator<IAttribute> it = attributes.iterator(); it.hasNext(); ) {
IAttribute attr = it.next();
if (attr.getType() == type)
it.remove();
......@@ -148,7 +148,7 @@ public final class AttributesList {
if (getMultiCountInternal(type) == 0)
return;
for (Iterator<IAttribute> it = attributes.iterator(); it.hasNext();) {
for (Iterator<IAttribute> it = attributes.iterator(); it.hasNext(); ) {
IAttribute a = it.next();
if (a == attr) {
it.remove();
......
......@@ -81,7 +81,7 @@ public final class ClassInfo {
char firstChar = name.charAt(0);
if (Character.isDigit(firstChar)) {
name = "InnerClass_" + name;
} else if(firstChar == '$') {
} else if (firstChar == '$') {
name = "_" + name;
}
if (NameMapper.isReserved(name)) {
......
......@@ -49,10 +49,10 @@ public final class MethodInfo {
return declClass.getFullName() + "." + name;
}
public String getFullId() {
return declClass.getFullName() + "." + shortId;
}
/**
* Method name and signature
*/
......
......@@ -74,7 +74,7 @@ public class InsnDecoder {
case Opcodes.FILL_ARRAY_DATA_PAYLOAD:
return null;
// move-result will be process in invoke and filled-new-array instructions
// move-result will be process in invoke and filled-new-array instructions
case Opcodes.MOVE_RESULT:
case Opcodes.MOVE_RESULT_WIDE:
case Opcodes.MOVE_RESULT_OBJECT:
......@@ -676,7 +676,7 @@ public class InsnDecoder {
return node;
}
private InsnNode insn(InsnType type, RegisterArg res, InsnArg arg) {
private InsnNode insn(InsnType type, RegisterArg res, InsnArg arg) {
InsnNode node = new InsnNode(type, 1);
node.setResult(res);
node.addArg(arg);
......
......@@ -75,7 +75,7 @@ public abstract class InsnArg extends Typed {
arg = insn.getArg(0);
String name = insn.getResult().getTypedVar().getName();
if (name != null) {
arg.getTypedVar().setName(name);
arg.getTypedVar().setName(name);
}
break;
case CONST_STR:
......
......@@ -83,7 +83,7 @@ public class TypedVar {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if(name != null)
if (name != null)
sb.append('\'').append(name).append("' ");
sb.append(type);
return sb.toString();
......
......@@ -4,7 +4,6 @@ import jadx.core.dex.info.ClassInfo;
import jadx.core.dex.info.MethodInfo;
import jadx.core.dex.instructions.InsnType;
import jadx.core.dex.instructions.InvokeNode;
import jadx.core.dex.instructions.args.InsnArg;
import jadx.core.dex.instructions.args.RegisterArg;
import jadx.core.dex.nodes.InsnNode;
import jadx.core.dex.nodes.MethodNode;
......
......@@ -71,7 +71,7 @@ public class InsnNode extends LineAttrNode {
public boolean containsArg(RegisterArg arg) {
for (InsnArg a : arguments) {
if (a == arg || (a.isRegister() && ((RegisterArg)a).getRegNum() == arg.getRegNum()))
if (a == arg || (a.isRegister() && ((RegisterArg) a).getRegNum() == arg.getRegNum()))
return true;
}
return false;
......
......@@ -73,7 +73,7 @@ public class AnnotationsParser {
return new AnnotationsList(list);
}
private static final Annotation.Visibility[] visibilities = new Annotation.Visibility[] {
private static final Annotation.Visibility[] visibilities = new Annotation.Visibility[]{
Annotation.Visibility.BUILD,
Annotation.Visibility.RUNTIME,
Annotation.Visibility.SYSTEM
......
......@@ -276,7 +276,7 @@ public class BlockMakerVisitor extends AbstractVisitor {
idom.getDominatesOn().add(block);
} else {
throw new JadxRuntimeException("Can't find immediate dominator for block " + block
+ " in " + bs + " preds:" + preds);
+ " in " + bs + " preds:" + preds);
}
}
}
......@@ -313,7 +313,7 @@ public class BlockMakerVisitor extends AbstractVisitor {
for (BlockNode block : mth.getBasicBlocks()) {
AttributesList attributes = block.getAttributes();
IAttribute loop = attributes.get(AttributeType.LOOP);
if(loop != null && attributes.contains(AttributeFlag.LOOP_START)) {
if (loop != null && attributes.contains(AttributeFlag.LOOP_START)) {
mth.registerLoop((LoopAttr) loop);
}
}
......
......@@ -237,7 +237,7 @@ public class CodeShrinker extends AbstractVisitor {
case CHECK_CAST:
InsnArg castArg = insn.getArg(0);
ArgType castType = (ArgType) ((IndexInsnNode)insn).getIndex();
ArgType castType = (ArgType) ((IndexInsnNode) insn).getIndex();
if (!ArgType.isCastNeeded(castArg.getType(), castType)) {
InsnNode insnNode = new InsnNode(InsnType.MOVE, 1);
insnNode.setResult(insn.getResult());
......
......@@ -66,8 +66,8 @@ public class DotGraphVisitor extends AbstractVisitor {
dot.startLine("MethodNode[shape=record,label=\"{"
+ escape(mth.getAccessFlags().makeString())
+ escape(mth.getReturnType() + " "
+ mth.getParentClass().getFullName() + "." + mth.getName()
+ "(" + Utils.listToString(mth.getArguments(true)) + ") ")
+ mth.getParentClass().getFullName() + "." + mth.getName()
+ "(" + Utils.listToString(mth.getArguments(true)) + ") ")
+ (attrs.length() == 0 ? "" : " | " + attrs)
+ (mth.getSuperCall() != null ? "| Super call: " + escape(mth.getSuperCall().toString()) : "")
+ "}\"];");
......
......@@ -63,7 +63,7 @@ public class InstructionRemover {
for (InsnNode rem : toRemove) {
unbindInsn(rem);
for (Iterator<InsnNode> it = insns.iterator(); it.hasNext();) {
for (Iterator<InsnNode> it = insns.iterator(); it.hasNext(); ) {
InsnNode insn = it.next();
if (insn == rem) {
it.remove();
......@@ -76,7 +76,7 @@ public class InstructionRemover {
public static void remove(BlockNode block, InsnNode insn) {
unbindInsn(insn);
// remove by pointer (don't use equals)
for (Iterator<InsnNode> it = block.getInstructions().iterator(); it.hasNext();) {
for (Iterator<InsnNode> it = block.getInstructions().iterator(); it.hasNext(); ) {
InsnNode ir = it.next();
if (ir == insn) {
it.remove();
......
......@@ -27,7 +27,7 @@ public class CleanRegions extends AbstractVisitor {
if (!(region instanceof Region))
return;
for (Iterator<IContainer> it = region.getSubBlocks().iterator(); it.hasNext();) {
for (Iterator<IContainer> it = region.getSubBlocks().iterator(); it.hasNext(); ) {
IContainer container = it.next();
if (container instanceof BlockNode) {
BlockNode block = (BlockNode) container;
......
......@@ -111,7 +111,7 @@ public class ProcessVariables extends AbstractVisitor {
usageMap.remove(arg);
}
for (Iterator<Entry<RegisterArg, Usage>> it = usageMap.entrySet().iterator(); it.hasNext();) {
for (Iterator<Entry<RegisterArg, Usage>> it = usageMap.entrySet().iterator(); it.hasNext(); ) {
Entry<RegisterArg, Usage> entry = it.next();
Usage u = entry.getValue();
......@@ -138,7 +138,7 @@ public class ProcessVariables extends AbstractVisitor {
// find region which contain all usage regions
Set<IRegion> set = u.getUseRegions();
for (Iterator<IRegion> it = set.iterator(); it.hasNext();) {
for (Iterator<IRegion> it = set.iterator(); it.hasNext(); ) {
IRegion r = it.next();
IRegion parent = r.getParent();
if (parent != null && set.contains(parent))
......
......@@ -73,8 +73,7 @@ final class RegionStack {
/**
* Add boundary(exit) node for current stack frame
*
* @param exit
* boundary node, null will be ignored
* @param exit boundary node, null will be ignored
*/
public void addExit(BlockNode exit) {
if (exit != null)
......
......@@ -69,7 +69,7 @@ public class Utils {
return "";
StringBuilder str = new StringBuilder();
for (Iterator<?> it = list.iterator(); it.hasNext();) {
for (Iterator<?> it = list.iterator(); it.hasNext(); ) {
Object o = it.next();
str.append(o);
if (it.hasNext())
......
......@@ -34,7 +34,7 @@ public class JavaToDex {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
System.setOut(new PrintStream(baos));
DxArgs args = new DxArgs("-", new String[] { javaFile });
DxArgs args = new DxArgs("-", new String[]{javaFile});
Main.run(args);
baos.close();
} catch (Throwable e) {
......
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss} %-5level - %msg%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss} %-5level - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
\ No newline at end of file
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
......@@ -21,7 +21,7 @@ import static junit.framework.Assert.fail;
public abstract class InternalJadxTest {
public ClassNode getClassNode(Class clazz) {
public ClassNode getClassNode(Class<?> clazz) {
try {
File temp = getJarForClass(clazz);
......
......@@ -12,6 +12,8 @@ import static org.junit.Assert.assertThat;
public class TestStringBuilderElimination extends InternalJadxTest {
public static class MyException extends Exception {
private static final long serialVersionUID = 4245254480662372757L;
public MyException(String str, Exception e) {
// super("msg:" + str, e);
}
......
......@@ -47,6 +47,7 @@ import org.fife.ui.rtextarea.RTextScrollPane;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings("serial")
public class MainWindow extends JFrame {
private static final Logger LOG = LoggerFactory.getLogger(MainWindow.class);
......
......@@ -8,9 +8,9 @@ import jadx.gui.utils.Utils;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.tree.DefaultMutableTreeNode;
public class JClass extends DefaultMutableTreeNode implements JNode {
public class JClass extends JNode {
private static final long serialVersionUID = -1239986875244097177L;
private static final ImageIcon ICON_CLASS = Utils.openIcon("class_obj");
private static final ImageIcon ICON_CLASS_DEFAULT = Utils.openIcon("class_default_obj");
......@@ -49,7 +49,7 @@ public class JClass extends DefaultMutableTreeNode implements JNode {
}
}
public String getCode(){
public String getCode() {
return cls.getCode();
}
......
......@@ -7,9 +7,10 @@ import jadx.gui.utils.Utils;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.tree.DefaultMutableTreeNode;
public class JField extends DefaultMutableTreeNode implements JNode {
public class JField extends JNode {
private static final long serialVersionUID = 1712572192106793359L;
private static final ImageIcon ICON_FLD_DEF = Utils.openIcon("field_default_obj");
private static final ImageIcon ICON_FLD_PRI = Utils.openIcon("field_private_obj");
private static final ImageIcon ICON_FLD_PRO = Utils.openIcon("field_protected_obj");
......
......@@ -8,10 +8,11 @@ import jadx.gui.utils.Utils;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.tree.DefaultMutableTreeNode;
import java.util.Iterator;
public class JMethod extends DefaultMutableTreeNode implements JNode {
public class JMethod extends JNode {
private static final long serialVersionUID = 3834526867464663751L;
private static final ImageIcon ICON_MTH_DEF = Utils.openIcon("methdef_obj");
private static final ImageIcon ICON_MTH_PRI = Utils.openIcon("methpri_obj");
private static final ImageIcon ICON_MTH_PRO = Utils.openIcon("methpro_obj");
......@@ -46,7 +47,7 @@ public class JMethod extends DefaultMutableTreeNode implements JNode {
public Icon getIcon() {
AccessInfo accessFlags = mth.getAccessFlags();
OverlayIcon icon = Utils.makeIcon(accessFlags, ICON_MTH_PUB, ICON_MTH_PRI, ICON_MTH_PRO, ICON_MTH_DEF);
if(accessFlags.isConstructor()) icon.add(ICON_CONSTRUCTOR);
if (accessFlags.isConstructor()) icon.add(ICON_CONSTRUCTOR);
if (accessFlags.isSynchronized()) icon.add(ICON_SYNC);
return icon;
}
......@@ -62,7 +63,7 @@ public class JMethod extends DefaultMutableTreeNode implements JNode {
base.append('(');
for (Iterator<ArgType> it = mth.getArguments().iterator(); it.hasNext(); ) {
base.append(Utils.typeStr(it.next()));
if(it.hasNext())
if (it.hasNext())
base.append(", ");
}
base.append(')');
......
package jadx.gui.treemodel;
import javax.swing.Icon;
import javax.swing.tree.DefaultMutableTreeNode;
public interface JNode {
public abstract class JNode extends DefaultMutableTreeNode {
JClass getJParent();
public abstract JClass getJParent();
int getLine();
public abstract int getLine();
void updateChilds();
public abstract void updateChilds();
Icon getIcon();
public abstract Icon getIcon();
}
......@@ -6,11 +6,12 @@ import jadx.gui.utils.Utils;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.tree.DefaultMutableTreeNode;
import java.util.ArrayList;
import java.util.List;
public class JPackage extends DefaultMutableTreeNode implements JNode, Comparable<JPackage> {
public class JPackage extends JNode implements Comparable<JPackage> {
private static final long serialVersionUID = -4120718634156839804L;
private static final ImageIcon PACKAGE_ICON = Utils.openIcon("package_obj");
private String name;
......@@ -81,6 +82,20 @@ public class JPackage extends DefaultMutableTreeNode implements JNode, Comparabl
return name.compareTo(o.name);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
JPackage jPackage = (JPackage) o;
if (!name.equals(jPackage.name)) return false;
return true;
}
@Override
public int hashCode() {
return name.hashCode();
}
@Override
public String toString() {
return name;
......
......@@ -6,7 +6,6 @@ import jadx.gui.utils.Utils;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.tree.DefaultMutableTreeNode;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
......@@ -17,7 +16,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
public class JRoot extends DefaultMutableTreeNode implements JNode {
public class JRoot extends JNode {
private static final long serialVersionUID = 8888495789773527342L;
private static final ImageIcon ROOT_ICON = Utils.openIcon("java_model_obj");
......
......@@ -14,7 +14,7 @@ import java.util.List;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
public class JRootTest {
......
......@@ -51,6 +51,7 @@ public class TestInner extends AbstractTest {
}.run();
}
@SuppressWarnings("serial")
public static class MyException extends Exception {
public MyException(String str, Exception e) {
super("msg:" + str, e);
......
......@@ -2,7 +2,7 @@ package jadx.samples;
public class TestSwitch extends AbstractTest {
public static final int test1(int i) {
public static int test1(int i) {
int k = i * 4;
switch (k) {
......@@ -19,7 +19,7 @@ public class TestSwitch extends AbstractTest {
return i;
}
public static final int test2(int i) {
public static int test2(int i) {
int k = i;
switch (k) {
case 1:
......@@ -39,7 +39,7 @@ public class TestSwitch extends AbstractTest {
return -i;
}
public static final int test3(int i, int j) {
public static int test3(int i, int j) {
int k = i;
switch (k) {
case 1:
......@@ -53,7 +53,7 @@ public class TestSwitch extends AbstractTest {
return -1;
}
public static final int test4(int i) {
public static int test4(int i) {
int k = i;
switch (k) {
case 1:
......@@ -64,7 +64,8 @@ public class TestSwitch extends AbstractTest {
return -1;
}
public static final int test5(int i, int b) {
@SuppressWarnings("fallthrough")
public static int test5(int i, int b) {
int k = i;
switch (k) {
case 1:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册