code cleanup: eval4j, ide-common, idea-analysis

This commit is contained in:
Dmitry Jemerov
2015-07-20 18:50:27 +02:00
parent 9e7a67fabf
commit 9142d48e81
21 changed files with 54 additions and 71 deletions
+5 -12
View File
@@ -16,23 +16,16 @@
package org.jetbrains.eval4j
import org.jetbrains.org.objectweb.asm.tree.analysis.*
import org.jetbrains.org.objectweb.asm.Handle
import org.jetbrains.org.objectweb.asm.Opcodes.*
import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
import org.jetbrains.org.objectweb.asm.tree.FieldInsnNode
import org.jetbrains.org.objectweb.asm.tree.IntInsnNode
import org.jetbrains.org.objectweb.asm.tree.LdcInsnNode
import org.jetbrains.org.objectweb.asm.tree.MethodInsnNode
import org.jetbrains.org.objectweb.asm.tree.MultiANewArrayInsnNode
import org.jetbrains.org.objectweb.asm.tree.TypeInsnNode
import org.jetbrains.org.objectweb.asm.tree.JumpInsnNode
import org.jetbrains.org.objectweb.asm.tree.IincInsnNode
import org.jetbrains.org.objectweb.asm.tree.*
import org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException
import org.jetbrains.org.objectweb.asm.tree.analysis.Interpreter
class UnsupportedByteCodeException(message: String) : RuntimeException(message)
public trait Eval {
public interface Eval {
public fun loadClass(classType: Type): Value
public fun loadString(str: String): Value
public fun newInstance(classType: Type): Value
@@ -97,7 +90,7 @@ class SingleInstructionInterpreter(private val eval: Eval) : Interpreter<Value>(
is Double -> double(cst)
is String -> eval.loadString(cst)
is Type -> {
val sort = (cst as Type).getSort()
val sort = cst.getSort()
when (sort) {
Type.OBJECT, Type.ARRAY -> eval.loadClass(cst)
Type.METHOD -> throw UnsupportedByteCodeException("Mothod handles are not supported")
@@ -24,7 +24,7 @@ import org.jetbrains.org.objectweb.asm.tree.analysis.Frame
import org.jetbrains.org.objectweb.asm.util.Printer
import java.util.ArrayList
public trait InterpreterResult {
public interface InterpreterResult {
override fun toString(): String
}
@@ -46,7 +46,7 @@ public class AbnormalTermination(public val message: String): InterpreterResult
override fun toString(): String = "Terminated abnormally: $message"
}
public trait InterpretationEventHandler {
public interface InterpretationEventHandler {
object NONE : InterpretationEventHandler {
override fun instructionProcessed(insn: AbstractInsnNode): InterpreterResult? = null
override fun exceptionThrown(currentState: Frame<Value>, currentInsn: AbstractInsnNode, exception: Value): InterpreterResult? = null
@@ -80,7 +80,7 @@ public fun interpreterLoop(
val firstInsn = m.instructions.getFirst()
if (firstInsn == null) throw IllegalArgumentException("Empty method")
var currentInsn = firstInsn!!
var currentInsn = firstInsn
fun goto(nextInsn: AbstractInsnNode?) {
if (nextInsn == null) throw IllegalArgumentException("Instruction flow ended with no RETURN")
+1 -1
View File
@@ -19,7 +19,7 @@ package org.jetbrains.eval4j
import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.tree.LabelNode
public trait Value : org.jetbrains.org.objectweb.asm.tree.analysis.Value {
public interface Value : org.jetbrains.org.objectweb.asm.tree.analysis.Value {
public val asmType: Type
public val valid: Boolean
override fun getSize(): Int = asmType.getSize()