Move ExceptionWithContext to Util module

This commit is contained in:
Ben Gruver
2012-10-15 20:23:01 -07:00
parent 70aa787967
commit bf95959ae4
18 changed files with 21 additions and 12 deletions

View File

@ -30,7 +30,7 @@ package org.jf.dexlib;
import com.google.common.base.Preconditions;
import org.jf.dexlib.Util.AnnotatedOutput;
import org.jf.dexlib.Util.ExceptionWithContext;
import org.jf.util.ExceptionWithContext;
import org.jf.dexlib.Util.Input;
import org.jf.dexlib.Util.ReadOnlyArrayList;

View File

@ -30,6 +30,7 @@ package org.jf.dexlib;
import com.google.common.base.Preconditions;
import org.jf.dexlib.Util.*;
import org.jf.util.ExceptionWithContext;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

View File

@ -32,7 +32,7 @@ import org.jf.dexlib.Code.*;
import org.jf.dexlib.Item;
import org.jf.dexlib.ItemType;
import org.jf.dexlib.MethodIdItem;
import org.jf.dexlib.Util.ExceptionWithContext;
import org.jf.util.ExceptionWithContext;
import java.util.*;

View File

@ -30,7 +30,7 @@ package org.jf.dexlib.Code.Analysis;
import org.jf.dexlib.*;
import org.jf.dexlib.Util.AccessFlags;
import org.jf.dexlib.Util.ExceptionWithContext;
import org.jf.util.ExceptionWithContext;
import org.jf.dexlib.Util.SparseArray;
import javax.annotation.Nonnull;

View File

@ -32,7 +32,7 @@ import org.jf.dexlib.*;
import org.jf.dexlib.Code.*;
import org.jf.dexlib.Code.Format.*;
import org.jf.dexlib.Util.AccessFlags;
import org.jf.dexlib.Util.ExceptionWithContext;
import org.jf.util.ExceptionWithContext;
import org.jf.dexlib.Util.SparseArray;
import java.util.BitSet;

View File

@ -28,7 +28,7 @@
package org.jf.dexlib.Code.Analysis;
import org.jf.dexlib.Util.ExceptionWithContext;
import org.jf.util.ExceptionWithContext;
public class ValidationException extends ExceptionWithContext {
private int codeAddress;

View File

@ -30,8 +30,7 @@ package org.jf.dexlib.Code;
import org.jf.dexlib.Code.Format.*;
import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.ExceptionWithContext;
import org.jf.dexlib.Util.Hex;
import org.jf.util.ExceptionWithContext;
public class InstructionIterator {
public static void IterateInstructions(DexFile dexFile, byte[] insns, ProcessInstructionDelegate delegate) {

View File

@ -33,6 +33,7 @@ import org.jf.dexlib.Code.*;
import org.jf.dexlib.Debug.DebugInstructionIterator;
import org.jf.dexlib.Debug.DebugOpcode;
import org.jf.dexlib.Util.*;
import org.jf.util.ExceptionWithContext;
import java.util.ArrayList;
import java.util.List;

View File

@ -29,6 +29,7 @@
package org.jf.dexlib;
import org.jf.dexlib.Util.*;
import org.jf.util.ExceptionWithContext;
import java.io.*;
import java.security.DigestException;

View File

@ -28,7 +28,7 @@
package org.jf.dexlib;
import org.jf.dexlib.Util.ExceptionWithContext;
import org.jf.util.ExceptionWithContext;
import org.jf.dexlib.Util.Input;
public class IndexedSection<T extends Item> extends Section<T> {

View File

@ -31,7 +31,7 @@ package org.jf.dexlib;
import com.google.common.base.Preconditions;
import org.jf.dexlib.Util.AlignmentUtils;
import org.jf.dexlib.Util.AnnotatedOutput;
import org.jf.dexlib.Util.ExceptionWithContext;
import org.jf.util.ExceptionWithContext;
import org.jf.dexlib.Util.Input;
public abstract class Item<T extends Item> implements Comparable<T> {

View File

@ -28,7 +28,7 @@
package org.jf.dexlib;
import org.jf.dexlib.Util.ExceptionWithContext;
import org.jf.util.ExceptionWithContext;
import org.jf.dexlib.Util.SparseArray;
import java.util.List;

View File

@ -24,6 +24,8 @@
package org.jf.dexlib.Util;
import org.jf.util.ExceptionWithContext;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;

View File

@ -24,6 +24,8 @@
package org.jf.dexlib.Util;
import org.jf.util.ExceptionWithContext;
/**
* Implementation of {@link Input} which reads the data from a
* <code>byte[]</code> instance.

View File

@ -24,6 +24,8 @@
package org.jf.dexlib.Util;
import org.jf.util.ExceptionWithContext;
import java.util.ArrayList;
/**

View File

@ -1,157 +0,0 @@
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* As per the Apache license requirements, this file has been modified
* from its original state.
*
* Such modifications are Copyright (C) 2010 Ben Gruver, and are released
* under the original license
*/
package org.jf.dexlib.Util;
import java.io.PrintStream;
import java.io.PrintWriter;
/**
* Exception which carries around structured context.
*/
public class ExceptionWithContext
extends RuntimeException {
/** non-null; human-oriented context of the exception */
private StringBuffer context;
/**
* Augments the given exception with the given context, and return the
* result. The result is either the given exception if it was an
* {@link ExceptionWithContext}, or a newly-constructed exception if it
* was not.
*
* @param ex non-null; the exception to augment
* @param str non-null; context to add
* @return non-null; an appropriate instance
*/
public static ExceptionWithContext withContext(Throwable ex, String str) {
ExceptionWithContext ewc;
if (ex instanceof ExceptionWithContext) {
ewc = (ExceptionWithContext) ex;
} else {
ewc = new ExceptionWithContext(ex);
}
ewc.addContext(str);
return ewc;
}
/**
* Constructs an instance.
*
* @param message human-oriented message
*/
public ExceptionWithContext(String message) {
this(message, null);
}
/**
* Constructs an instance.
*
* @param cause null-ok; exception that caused this one
*/
public ExceptionWithContext(Throwable cause) {
this(null, cause);
}
/**
* Constructs an instance.
*
* @param message human-oriented message
* @param cause null-ok; exception that caused this one
*/
public ExceptionWithContext(String message, Throwable cause) {
super((message != null) ? message :
(cause != null) ? cause.getMessage() : null,
cause);
if (cause instanceof ExceptionWithContext) {
String ctx = ((ExceptionWithContext) cause).context.toString();
context = new StringBuffer(ctx.length() + 200);
context.append(ctx);
} else {
context = new StringBuffer(200);
}
}
/** {@inheritDoc} */
@Override
public void printStackTrace(PrintStream out) {
super.printStackTrace(out);
out.println(context);
}
/** {@inheritDoc} */
@Override
public void printStackTrace(PrintWriter out) {
super.printStackTrace(out);
out.println(context);
}
/**
* Adds a line of context to this instance.
*
* @param str non-null; new context
*/
public void addContext(String str) {
if (str == null) {
throw new NullPointerException("str == null");
}
context.append(str);
if (!str.endsWith("\n")) {
context.append('\n');
}
}
/**
* Gets the context.
*
* @return non-null; the context
*/
public String getContext() {
return context.toString();
}
/**
* Prints the message and context.
*
* @param out non-null; where to print to
*/
public void printContext(PrintStream out) {
out.println(getMessage());
out.print(context);
}
/**
* Prints the message and context.
*
* @param out non-null; where to print to
*/
public void printContext(PrintWriter out) {
out.println(getMessage());
out.print(context);
}
}