Permalink
Browse files

Kotlin 1.1.4

  • Loading branch information...
ingokegel committed Aug 18, 2017
1 parent f04d4b2 commit 503b630394b50e2364cabf7db9e58ce2dc57194f
Showing with 79 additions and 82 deletions.
  1. +4 −5 .idea/inspectionProfiles/Project_Default.xml
  2. +2 −2 build.gradle
  3. +4 −6 modules/browser/src/main/kotlin/org/gjt/jclasslib/browser/BrowserFrame.kt
  4. +3 −3 modules/browser/src/main/kotlin/org/gjt/jclasslib/browser/DetailPane.kt
  5. +1 −1 modules/browser/src/main/kotlin/org/gjt/jclasslib/browser/Main.kt
  6. +4 −6 modules/browser/src/main/kotlin/org/gjt/jclasslib/browser/config/BrowserConfig.kt
  7. +1 −1 modules/browser/src/main/kotlin/org/gjt/jclasslib/browser/config/classpath/ClasspathEntry.kt
  8. +3 −3 modules/browser/src/main/kotlin/org/gjt/jclasslib/browser/config/classpath/ClasspathJrtEntry.kt
  9. +1 −1 modules/browser/src/main/kotlin/org/gjt/jclasslib/browser/detail/TableDetailPane.kt
  10. +3 −3 modules/browser/src/main/kotlin/org/gjt/jclasslib/browser/detail/TypeAnnotationDetailPane.kt
  11. +3 −3 modules/browser/src/main/kotlin/org/gjt/jclasslib/browser/detail/attributes/Columns.kt
  12. +1 −1 ...r/src/main/kotlin/org/gjt/jclasslib/browser/detail/attributes/ModuleHashesAttributeDetailPanel.kt
  13. +1 −2 modules/browser/src/main/kotlin/org/gjt/jclasslib/browser/detail/attributes/code/ByteCodeDocument.kt
  14. +1 −1 ...browser/src/main/kotlin/org/gjt/jclasslib/browser/detail/attributes/document/AttributeDocument.kt
  15. +3 −3 modules/browser/src/main/kotlin/org/gjt/jclasslib/util/ClosableTabComponent.kt
  16. +17 −13 modules/browser/src/main/kotlin/org/gjt/jclasslib/util/DnDTabbedPane.kt
  17. +3 −3 modules/data/src/main/kotlin/org/gjt/jclasslib/bytecode/IncrementInstruction.kt
  18. +1 −1 modules/data/src/main/kotlin/org/gjt/jclasslib/bytecode/PaddedInstruction.kt
  19. +3 −3 modules/data/src/main/kotlin/org/gjt/jclasslib/structures/ClassFile.kt
  20. +4 −4 modules/data/src/main/kotlin/org/gjt/jclasslib/structures/attributes/VerificationType.kt
  21. +3 −3 ...es/data/src/main/kotlin/org/gjt/jclasslib/structures/attributes/targettype/SupertypeTargetInfo.kt
  22. +1 −2 modules/data/src/test/kotlin/org/gjt/jclasslib/test/ClassFileConsistencyTest.kt
  23. +11 −11 modules/idea/src/main/kotlin/org/gjt/jclasslib/idea/Action.kt
  24. +1 −1 modules/idea/src/main/kotlin/org/gjt/jclasslib/idea/ToolWindow.kt
@@ -1,7 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0" is_locked="false">
<option name="myName" value="Project Default" />
<option name="myLocal" value="false" />
<inspection_tool class="BooleanConstructor" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="CanBeFinal" enabled="false" level="WARNING" enabled_by_default="false">
<option name="REPORT_CLASSES" value="true" />
@@ -36,12 +35,9 @@
<inspection_tool class="InfiniteLoopStatement" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="InstantiatingObjectToGetClassObject" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="LeakingThis" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
<option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
<option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />
</inspection_tool>
<inspection_tool class="LoopStatementsThatDontLoop" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="ManualArrayCopy" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="MemberVisibilityCanPrivate" enabled="false" level="INFO" enabled_by_default="false" />
<inspection_tool class="NoExplicitFinalizeCalls" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="OctalLiteral" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="PointlessArithmeticExpression" enabled="false" level="WARNING" enabled_by_default="false">
@@ -53,6 +49,9 @@
<inspection_tool class="PointlessBooleanExpression" enabled="false" level="WARNING" enabled_by_default="false">
<option name="m_ignoreExpressionsContainingConstants" value="false" />
</inspection_tool>
<inspection_tool class="RefusedBequest" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoreEmptySuperMethods" value="false" />
</inspection_tool>
<inspection_tool class="ReturnFromFinallyBlock" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="SameParameterValue" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="SameReturnValue" enabled="false" level="WARNING" enabled_by_default="false" />
View
@@ -7,10 +7,10 @@ buildDir = file('build/gradle')
ext.externalLibsDir = file("$buildDir/externalLibs")
buildscript {scriptHandler ->
ext.kotlinVersion = '1.1.3-2'
ext.kotlinVersion = '1.1.4'
String[] kotlinVersionParts = kotlinVersion.split('-')
ext.kotlinVersionMain = kotlinVersionParts[0]
ext.kotlinVersionHotfix = kotlinVersionParts.length > 1 ? "-${kotlinVersionParts[1]}" : ''
ext.kotlinVersionHotfix = kotlinVersionParts.length > 1 ? "-${kotlinVersionParts[1]}" : '-1'
repositories {
flatDir {
@@ -49,12 +49,10 @@ class BrowserFrame : JFrame() {
classesChooserPath = classesFileChooser.currentDirectory.absolutePath
val file = classesFileChooser.selectedFile
val lowerCasePath = file.path.toLowerCase()
if (lowerCasePath.endsWith(".class")) {
openClassFromFile(file)
} else if (lowerCasePath.endsWith(".jar")) {
openClassFromJar(file)
} else {
GUIHelper.showMessage(this, "Please select a class file or a JAR file", JOptionPane.WARNING_MESSAGE)
when {
lowerCasePath.endsWith(".class") -> openClassFromFile(file)
lowerCasePath.endsWith(".jar") -> openClassFromJar(file)
else -> GUIHelper.showMessage(this, "Please select a class file or a JAR file", JOptionPane.WARNING_MESSAGE)
}
}
}
@@ -78,10 +78,10 @@ abstract class DetailPane<out T : Any>(private val elementClass: Class<T>, val s
protected open fun isChildShown(node: BrowserTreeNode) = true
protected fun getConstantPoolEntryName(constantPoolIndex: Int): String {
try {
return services.classFile.getConstantPoolEntryName(constantPoolIndex)
return try {
services.classFile.getConstantPoolEntryName(constantPoolIndex)
} catch (ex: InvalidByteCodeException) {
return "invalid constant pool reference"
"invalid constant pool reference"
}
}
@@ -57,7 +57,7 @@ fun main(args: Array<String>) {
fun getBrowserFrames(): List<BrowserFrame> = Frame.getFrames()
.mapNotNull { if (it is BrowserFrame) it else null }
.filterIsInstance<BrowserFrame>()
.filter { it.isVisible }
fun getNextBrowserFrame(browserFrame: BrowserFrame) : BrowserFrame = getBrowserFrames().run {
@@ -92,12 +92,10 @@ class BrowserConfig : ClasspathComponent {
}
private fun createJreEntry(): ClasspathEntry? {
return if (File(jreHome, "lib/modules").exists()) {
ClasspathJrtEntry(jreHome)
} else if (File(jreHome, "lib/rt.jar").exists()) {
ClasspathArchiveEntry(File(jreHome, "lib/rt.jar").path)
} else {
return null
return when {
File(jreHome, "lib/modules").exists() -> ClasspathJrtEntry(jreHome)
File(jreHome, "lib/rt.jar").exists() -> ClasspathArchiveEntry(File(jreHome, "lib/rt.jar").path)
else -> return null
}
}
@@ -51,7 +51,7 @@ abstract class ClasspathEntry(fileName : String) : ClasspathComponent {
val childCount = parentNode.childCount
val newNode = ClassTreeNode(newNodeName, packageNode)
for (i in 0..childCount - 1) {
for (i in 0 until childCount) {
val childNode = parentNode.getChildAt(i) as ClassTreeNode
val childNodeName = childNode.toString()
if (childNode.childCount > 0 && !packageNode) {
@@ -15,10 +15,10 @@ import javax.swing.tree.DefaultTreeModel
class ClasspathJrtEntry(jreHome: String) : ClasspathEntry(jreHome) {
override fun findClass(className: String, modulePathSelection: Boolean): FindResult? {
if (modulePathSelection) {
return findClassWithModuleNameInJrt(className, file)?.let { FindResult("$JRT_PREFIX$it", it.getName(1).toString()) }
return if (modulePathSelection) {
findClassWithModuleNameInJrt(className, file)?.let { FindResult("$JRT_PREFIX$it", it.getName(1).toString()) }
} else {
return findClassInJrt(className, file)?.let { FindResult("$JRT_PREFIX$it") }
findClassInJrt(className, file)?.let { FindResult("$JRT_PREFIX$it") }
}
}
@@ -139,7 +139,7 @@ abstract class TableDetailPane<T : AttributeInfo>(elementClass: Class<T>, servic
}
private fun updateRowHeights() {
for (row in 0..table.rowCount - 1) {
for (row in 0 until table.rowCount) {
val rowHeight = (0..table.columnCount - 1).map { column ->
val c = table.prepareRenderer(table.getCellRenderer(row, column), row, column) as JComponent
c.size = c.preferredSize.apply {
@@ -122,10 +122,10 @@ class TypeAnnotationDetailPane(services: BrowserServices) : KeyValueDetailPane<T
throw RuntimeException("No parent node with element class $elementClass found")
}
val node = path.lastPathComponent as BrowserTreeNode
if (node.element?.let { it::class.java } == elementClass) {
return path
return if (node.element?.let { it::class.java } == elementClass) {
path
} else {
return findParentNode(elementClass, path.parentPath)
findParentNode(elementClass, path.parentPath)
}
}
@@ -68,10 +68,10 @@ abstract class NamedConstantPoolLinkColumn<in T : Any>(name: String, services: B
open protected fun getComment(constantPoolIndex: Int) = getConstantPoolEntryName(constantPoolIndex)
private fun getConstantPoolEntryName(constantPoolIndex: Int): String {
try {
return services.classFile.getConstantPoolEntryName(constantPoolIndex)
return try {
services.classFile.getConstantPoolEntryName(constantPoolIndex)
} catch (ex: InvalidByteCodeException) {
return "invalid constant pool reference"
"invalid constant pool reference"
}
}
}
@@ -31,7 +31,7 @@ class ModuleHashesAttributeDetailPane(services: BrowserServices) : TableDetailPa
})
add(object : StringColumn<HashEntry>("Hash", 700) {
override fun createValue(row: HashEntry) =
row.hashValues.map { it.toString(16).padStart(2, '0') }.joinToString(separator = "")
row.hashValues.joinToString(separator = "") { it.toString(16).padStart(2, '0') }
})
}
}
@@ -35,10 +35,9 @@ class ByteCodeDocument(styles: StyleContext, private val attribute: CodeAttribut
val instructions = ByteCodeReader.readByteCode(attribute.code)
verifyOffsets(instructions)
calculateOffsetWidth(instructions)
val instructionLineCounts = instructions.map {
return instructions.map {
addInstructionToDocument(it)
}
return instructionLineCounts
}
private fun verifyOffsets(instructions: ArrayList<Instruction>) {
@@ -82,7 +82,7 @@ abstract class AttributeDocument(protected val styles: StyleContext, protected v
for (i in 1..numberOfLines) {
lineNumberDocument.appendBatchString(getPaddedValue(i, lineNumberWidth), STYLE_LINE_NUMBER)
val lineNumberCount = lineNumberCounts?.get(i - 1) ?: 1
for (j in 0..lineNumberCount - 1) {
for (j in 0 until lineNumberCount) {
lineNumberDocument.appendBatchLineFeed(STYLE_NORMAL)
}
}
@@ -15,10 +15,10 @@ class ClosableTabComponent(private val tabbedPane: JTabbedPane) : JPanel(FlowLay
}
override fun getText(): String? {
val index = tabbedPane.indexOfTabComponent(this@ClosableTabComponent)
if (index != -1) {
return tabbedPane.getTitleAt(index)
return if (index != -1) {
tabbedPane.getTitleAt(index)
} else {
return null
null
}
}
})
@@ -118,7 +118,7 @@ open class DnDTabbedPane : JTabbedPane() {
return 0
}
for (i in 0..tabCount - 1) {
for (i in 0 until tabCount) {
val r = getBoundsAt(i) ?: continue
if (isTopOrBottom) {
r.setRect(r.x - r.width / 2, r.y, r.width, height)
@@ -197,18 +197,22 @@ open class DnDTabbedPane : JTabbedPane() {
return
}
if (targetIndex == tabCount) {
source.remove(sourceIndex)
addTab(str, cmp)
selectedIndex = tabCount - 1
} else if (sourceIndex > targetIndex) {
source.remove(sourceIndex)
insertTab(str, null, cmp, null, targetIndex)
selectedIndex = targetIndex
} else {
source.remove(sourceIndex)
insertTab(str, null, cmp, null, targetIndex - 1)
selectedIndex = targetIndex - 1
selectedIndex = when {
targetIndex == tabCount -> {
source.remove(sourceIndex)
addTab(str, cmp)
tabCount - 1
}
sourceIndex > targetIndex -> {
source.remove(sourceIndex)
insertTab(str, null, cmp, null, targetIndex)
targetIndex
}
else -> {
source.remove(sourceIndex)
insertTab(str, null, cmp, null, targetIndex - 1)
targetIndex - 1
}
}
}
@@ -25,10 +25,10 @@ constructor(opcode: Opcode, wide: Boolean, immediateByte: Int = 0, var increment
override fun read(input: ByteCodeInput) {
super.read(input)
if (isWide) {
incrementConst = input.readShort().toInt()
incrementConst = if (isWide) {
input.readShort().toInt()
} else {
incrementConst = input.readByte().toInt()
input.readByte().toInt()
}
}
@@ -30,7 +30,7 @@ open class PaddedInstruction(opcode: Opcode) : Instruction(opcode) {
super.read(input)
val bytesToRead = paddingBytes(input.bytesRead)
for (i in 0..bytesToRead - 1) {
for (i in 0 until bytesToRead) {
input.readByte()
}
}
@@ -106,7 +106,7 @@ class ClassFile : Structure(), AttributeContainer {
* @param enlargedConstantPool the enlarged constant pool
*/
fun enlargeConstantPool(enlargedConstantPool: Array<Constant>) {
for (i in constantPool.size..enlargedConstantPool.size - 1) {
for (i in constantPool.size until enlargedConstantPool.size) {
constantPoolEntryToIndex.put(enlargedConstantPool[i], i)
}
this.constantPool = enlargedConstantPool
@@ -183,8 +183,8 @@ class ClassFile : Structure(), AttributeContainer {
checkValidConstantPoolIndex(index)
val cpInfo = constantPool[index]
if (entryClass.isAssignableFrom(cpInfo::class.java)) {
return entryClass.cast(cpInfo)
return if (entryClass.isAssignableFrom(cpInfo::class.java)) {
entryClass.cast(cpInfo)
} else {
throw InvalidByteCodeException("constant pool entry at $index of class ${cpInfo::class.java.name} is not assignable to ${entryClass.name}")
}
@@ -31,10 +31,10 @@ enum class VerificationType(override val tag: Int) : ClassFileEnum {
* Create an associated [VerificationTypeInfoEntry] instance.
*/
fun createEntry(classFile: ClassFile): VerificationTypeInfoEntry {
when (this) {
OBJECT -> return ObjectVerificationTypeInfoEntry(classFile)
UNINITIALIZED -> return UninitializedVerificationTypeInfoEntry()
else -> return VerificationTypeInfoEntry(this)
return when (this) {
OBJECT -> ObjectVerificationTypeInfoEntry(classFile)
UNINITIALIZED -> UninitializedVerificationTypeInfoEntry()
else -> VerificationTypeInfoEntry(this)
}
}
@@ -34,10 +34,10 @@ class SupertypeTargetInfo : TargetInfo() {
override val verbose: String
get() {
if (supertypeIndex == 65535) {
return "Super class ($supertypeIndex)"
return if (supertypeIndex == 65535) {
"Super class ($supertypeIndex)"
} else {
return "<a href=\"I$supertypeIndex\">interface index $supertypeIndex</a>"
"<a href=\"I$supertypeIndex\">interface index $supertypeIndex</a>"
}
}
@@ -11,7 +11,6 @@ import org.gjt.jclasslib.io.ClassFileReader
import org.gjt.jclasslib.io.ClassFileWriter
import org.gjt.jclasslib.io.forEachClassInJrt
import org.gjt.jclasslib.structures.isDebug
import org.testng.annotations.Test
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.File
@@ -157,7 +156,7 @@ class ClassFileConsistencyTest {
System.err.println("ERROR in " + className)
System.err.println("Different length " + before.size + " != " + after.size)
}
for (i in 0..minOf(before.size, after.size) - 1) {
for (i in 0 until minOf(before.size, after.size)) {
if (before[i] != after[i]) {
System.err.println("Different byte at index " + i)
return false
@@ -24,7 +24,7 @@ class ShowBytecodeAction : AnAction() {
override fun update(e: AnActionEvent) {
e.presentation.apply {
isEnabled = getPsiElement(e)?.run { containingFile is PsiClassOwner && getContainingClassName(this) != null } ?: false
isEnabled = getPsiElement(e)?.run { containingFile is PsiClassOwner && getContainingClassName(this) != null } == true
icon = ICON
}
}
@@ -41,16 +41,16 @@ class ShowBytecodeAction : AnAction() {
}
private fun getPsiElement(dataContext: DataContext, project: Project?, editor: Editor?): PsiElement? {
if (project == null) {
return null
} else if (editor == null) {
return dataContext.getData(CommonDataKeys.PSI_ELEMENT)
} else {
val psiFile = PsiUtilBase.getPsiFileInEditor(editor, project)
val injectedEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, psiFile)
return injectedEditor?.let {
findElementInFile(PsiUtilBase.getPsiFileInEditor(it, project), it)
} ?: findElementInFile(psiFile, editor)
return when {
project == null -> null
editor == null -> dataContext.getData(CommonDataKeys.PSI_ELEMENT)
else -> {
val psiFile = PsiUtilBase.getPsiFileInEditor(editor, project)
val injectedEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, psiFile)
injectedEditor?.let {
findElementInFile(PsiUtilBase.getPsiFileInEditor(it, project), it)
} ?: findElementInFile(psiFile, editor)
}
}
}
@@ -228,7 +228,7 @@ class BytecodeToolWindowPanel(override var classFile: ClassFile, val virtualFile
}
private fun findClass(parent: PsiClass?, names: Array<String>, index: Int): PsiClass? {
for (i in index..names.size - 1) {
for (i in index until names.size) {
val psiClass = findClass(parent, names.slice(index..i).joinToString("$"))
if (psiClass != null) {
if (i < names.size - 1) {

0 comments on commit 503b630

Please sign in to comment.