Skip to content

Commit 57dcbe0

Browse files
committed
Cleanup in libraries and tools: use property access syntax.
1 parent 19a4f65 commit 57dcbe0

File tree

22 files changed

+197
-197
lines changed

22 files changed

+197
-197
lines changed

libraries/examples/annotation-processor-example/src/main/kotlin/example/ExampleAnnotationProcessor.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import javax.tools.Diagnostic
1111
public class ExampleAnnotationProcessor : AbstractProcessor() {
1212

1313
private companion object {
14-
val ANNOTATION_FQ_NAME = ExampleAnnotation::class.java.getCanonicalName()
14+
val ANNOTATION_FQ_NAME = ExampleAnnotation::class.java.canonicalName
1515
val SUFFIX_OPTION = "suffix"
1616
val GENERATE_KOTLIN_CODE_OPTION = "generate.kotlin.code"
1717
val KAPT_KOTLIN_GENERATED_OPTION = "kapt.kotlin.generated"
@@ -20,25 +20,25 @@ public class ExampleAnnotationProcessor : AbstractProcessor() {
2020
override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment): Boolean {
2121
val elements = roundEnv.getElementsAnnotatedWith(ExampleAnnotation::class.java)
2222

23-
val elementUtils = processingEnv.getElementUtils()
24-
val filer = processingEnv.getFiler()
23+
val elementUtils = processingEnv.elementUtils
24+
val filer = processingEnv.filer
2525

26-
val options = processingEnv.getOptions()
26+
val options = processingEnv.options
2727
val generatedFileSuffix = options[SUFFIX_OPTION] ?: "Generated"
2828
val generateKotlinCode = "true" == options[GENERATE_KOTLIN_CODE_OPTION]
2929
val kotlinGenerated = options[KAPT_KOTLIN_GENERATED_OPTION]
3030

3131
for (element in elements) {
32-
val packageName = elementUtils.getPackageOf(element).getQualifiedName().toString()
33-
val simpleName = element.getSimpleName()
32+
val packageName = elementUtils.getPackageOf(element).qualifiedName.toString()
33+
val simpleName = element.simpleName
3434
val className = simpleName.toString().capitalize() + generatedFileSuffix
3535

3636
filer.createSourceFile(className).openWriter().use { with(it) {
3737
appendln("package $packageName;")
3838
appendln("public final class $className {}")
3939
}}
4040

41-
if (generateKotlinCode && kotlinGenerated != null && element.getKind() == ElementKind.CLASS) {
41+
if (generateKotlinCode && kotlinGenerated != null && element.kind == ElementKind.CLASS) {
4242
File(kotlinGenerated, "$simpleName.kt").writer().buffered().use {
4343
it.appendln("package $packageName")
4444
it.appendln("fun $simpleName.customToString() = \"$simpleName: \" + toString()")

libraries/examples/browser-example-with-library/src/test/kotlin/sample/SampleTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ open class SampleTest {
1111
open val driver: WebDriver = HtmlUnitDriver(true)
1212

1313
@test fun homePage(): Unit {
14-
driver.get("file://" + File("sample.html").getCanonicalPath())
14+
driver.get("file://" + File("sample.html").canonicalPath)
1515
Thread.sleep(1000)
1616

1717
val foo = driver.findElement(By.id("foo"))!!
18-
val text = foo.getText() ?: ""
18+
val text = foo.text ?: ""
1919
println("Found $foo with text '$text'")
2020
assertEquals("x=30 y=200 z=100 u=1000", text.trim())
2121
}

libraries/examples/browser-example/src/test/kotlin/sample/SampleTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ open class SampleTest {
1111
open val driver: WebDriver = HtmlUnitDriver(true)
1212

1313
@test fun homePage(): Unit {
14-
driver.get("file://" + File("sample.html").getCanonicalPath())
14+
driver.get("file://" + File("sample.html").canonicalPath)
1515
Thread.sleep(1000)
1616

1717
val foo = driver.findElement(By.id("foo"))!!
18-
val text = foo.getText() ?: ""
18+
val text = foo.text ?: ""
1919
println("Found $foo with text '$text'")
2020
assertEquals("Some Dynamically Created Content!!!", text.trim())
2121
}

libraries/stdlib/src/kotlin/concurrent/Locks.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public inline fun <T> ReentrantReadWriteLock.read(action: () -> T): T {
4242
public inline fun <T> ReentrantReadWriteLock.write(action: () -> T): T {
4343
val rl = readLock()
4444

45-
val readCount = if (getWriteHoldCount() == 0) getReadHoldCount() else 0
45+
val readCount = if (writeHoldCount == 0) readHoldCount else 0
4646
repeat(readCount) { rl.unlock() }
4747

4848
val wl = writeLock()

libraries/stdlib/src/kotlin/io/files/Utils.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public fun createTempFile(prefix: String = "tmp", suffix: String? = null, direct
5050
*/
5151
@Deprecated("This property has unclear semantics and will be removed soon.")
5252
public val File.directory: File
53-
get() = if (isDirectory()) this else parentFile!!
53+
get() = if (isDirectory) this else parentFile!!
5454

5555
/**
5656
* Returns parent of this abstract path name, or `null` if it has no parent.
@@ -265,20 +265,20 @@ public fun File.relativePath(descendant: File): String {
265265
public fun File.copyTo(dst: File, overwrite: Boolean = false, bufferSize: Int = DEFAULT_BUFFER_SIZE): Long {
266266
if (!exists()) {
267267
throw NoSuchFileException(file = this, reason = "The source file doesn't exist")
268-
} else if (isDirectory()) {
268+
} else if (isDirectory) {
269269
throw IllegalArgumentException("Use copyRecursively to copy a directory $this")
270270
} else if (dst.exists()) {
271271
if (!overwrite) {
272272
throw FileAlreadyExistsException(file = this,
273273
other = dst,
274274
reason = "The destination file already exists")
275-
} else if (dst.isDirectory() && dst.listFiles().any()) {
275+
} else if (dst.isDirectory && dst.listFiles().any()) {
276276
// In this case file should be copied *into* this directory,
277277
// no matter whether it is empty or not
278278
return copyTo(dst.resolve(name), overwrite, bufferSize)
279279
}
280280
}
281-
dst.getParentFile()?.mkdirs()
281+
dst.parentFile?.mkdirs()
282282
dst.delete()
283283
val input = FileInputStream(this)
284284
return input.use<FileInputStream, Long> {
@@ -340,12 +340,12 @@ public fun File.copyRecursively(dst: File,
340340
} else {
341341
val relPath = src.relativeTo(this)
342342
val dstFile = File(dst, relPath)
343-
if (dstFile.exists() && !(src.isDirectory() && dstFile.isDirectory())) {
343+
if (dstFile.exists() && !(src.isDirectory && dstFile.isDirectory)) {
344344
if (onError(dstFile, FileAlreadyExistsException(file = src,
345345
other = dstFile,
346346
reason = "The destination file already exists")) == OnErrorAction.TERMINATE)
347347
return false
348-
} else if (src.isDirectory()) {
348+
} else if (src.isDirectory) {
349349
dstFile.mkdirs()
350350
} else {
351351
if (src.copyTo(dstFile, true) != src.length()) {

libraries/stdlib/test/JavaClassTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class C()
88

99
class JavaClassTest() : TestCase() {
1010
fun testMe () {
11-
assertEquals("java.util.ArrayList", java.util.ArrayList<Any>().javaClass.getName())
12-
assertEquals("java.util.ArrayList", ArrayList::class.java.getName())
13-
assertEquals("testjc.C", C::class.java.getName())
11+
assertEquals("java.util.ArrayList", java.util.ArrayList<Any>().javaClass.name)
12+
assertEquals("java.util.ArrayList", ArrayList::class.java.name)
13+
assertEquals("testjc.C", C::class.java.name)
1414
}
1515
}

libraries/stdlib/test/io/FileTreeWalks.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class FileTreeWalkTest {
130130
val basedir = createTestFiles()
131131
try {
132132
val referenceNames = setOf("", "1", "1/2", "1/3", "6", "8")
133-
assertEquals(referenceNames, basedir.walkTopDown().filter { it.isDirectory() }.map {
133+
assertEquals(referenceNames, basedir.walkTopDown().filter { it.isDirectory }.map {
134134
it.relativeToOrSelf(basedir).invariantSeparatorsPath
135135
}.toHashSet())
136136
} finally {
@@ -145,7 +145,7 @@ class FileTreeWalkTest {
145145
val referenceNames = setOf("", "1", "1/2", "1/3", "6", "8")
146146
val namesTopDown = HashSet<String>()
147147
fun enter(file: File) {
148-
assertTrue(file.isDirectory())
148+
assertTrue(file.isDirectory)
149149
for (child in file.listFiles()) {
150150
if (child.name.endsWith("txt"))
151151
child.delete()
@@ -168,7 +168,7 @@ class FileTreeWalkTest {
168168
val referenceNames = setOf("", "1", "1/2", "1/3", "6", "8")
169169
val namesTopDown = HashSet<String>()
170170
fun enter(file: File) {
171-
assertTrue(file.isDirectory())
171+
assertTrue(file.isDirectory)
172172
for (child in file.listFiles()) {
173173
if (child.name.endsWith("txt"))
174174
child.delete()
@@ -287,7 +287,7 @@ class FileTreeWalkTest {
287287
failed.add(dir.name)
288288
}
289289
basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory).
290-
fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory()) visitFile(it) }
290+
fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory) visitFile(it) }
291291
assertTrue(stack.isEmpty())
292292
for (fileName in arrayOf("", "1", "1/2", "1/3", "6", "8")) {
293293
assertTrue(dirs.contains(File(fileName)), fileName)
@@ -313,7 +313,7 @@ class FileTreeWalkTest {
313313
files.clear()
314314
dirs.clear()
315315
basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory).
316-
fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory()) visitFile(it) }
316+
fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory) visitFile(it) }
317317
assertTrue(stack.isEmpty())
318318
assertEquals(setOf("1"), failed)
319319
assertEquals(listOf("", "1", "6", "8").map { File(it) }.toSet(), dirs)
@@ -335,7 +335,7 @@ class FileTreeWalkTest {
335335
val visited = HashSet<File>()
336336
val block: (File) -> Unit = {
337337
assertTrue(!visited.contains(it), it.toString())
338-
assertTrue(it == basedir && visited.isEmpty() || visited.contains(it.getParentFile()), it.toString())
338+
assertTrue(it == basedir && visited.isEmpty() || visited.contains(it.parentFile), it.toString())
339339
visited.add(it)
340340
}
341341
basedir.walkTopDown().forEach(block)
@@ -353,7 +353,7 @@ class FileTreeWalkTest {
353353
val visited = HashSet<File>()
354354
val block: (File) -> Unit = {
355355
assertTrue(!visited.contains(it), it.toString())
356-
assertTrue(it == basedir && visited.isEmpty() || visited.contains(it.getParentFile()), it.toString())
356+
assertTrue(it == basedir && visited.isEmpty() || visited.contains(it.parentFile), it.toString())
357357
visited.add(it)
358358
}
359359
basedir.walkTopDown().forEach(block)
@@ -376,7 +376,7 @@ class FileTreeWalkTest {
376376
val basedir1 = createTestFiles()
377377
try {
378378
basedir1.walkTopDown().forEach {
379-
if (it.isFile()) {
379+
if (it.isFile) {
380380
makeBackup(it)
381381
}
382382
}
@@ -389,7 +389,7 @@ class FileTreeWalkTest {
389389
val basedir2 = createTestFiles()
390390
try {
391391
basedir2.walkTopDown().forEach {
392-
if (it.isFile()) {
392+
if (it.isFile) {
393393
makeBackup(it)
394394
}
395395
}
@@ -424,7 +424,7 @@ class FileTreeWalkTest {
424424
val found = HashSet<File>()
425425
for (file in basedir.walkTopDown()) {
426426
if (file.name == ".git") {
427-
found.add(file.getParentFile())
427+
found.add(file.parentFile)
428428
}
429429
}
430430
assertEquals(3, found.size)

libraries/stdlib/test/io/Files.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ class FilesTest {
2020
@test fun testCreateTempDir() {
2121
val dirSuf = System.currentTimeMillis().toString()
2222
val dir1 = createTempDir("temp", dirSuf)
23-
assertTrue(dir1.exists() && dir1.isDirectory() && dir1.name.startsWith("temp") && dir1.name.endsWith(dirSuf))
23+
assertTrue(dir1.exists() && dir1.isDirectory && dir1.name.startsWith("temp") && dir1.name.endsWith(dirSuf))
2424
assertFailsWith(IllegalArgumentException::class) {
2525
createTempDir("a")
2626
}
2727

2828
val dir2 = createTempDir("temp")
29-
assertTrue(dir2.exists() && dir2.isDirectory() && dir2.name.endsWith(".tmp"))
29+
assertTrue(dir2.exists() && dir2.isDirectory && dir2.name.endsWith(".tmp"))
3030

3131
val dir3 = createTempDir()
32-
assertTrue(dir3.exists() && dir3.isDirectory())
32+
assertTrue(dir3.exists() && dir3.isDirectory)
3333

3434
dir1.delete()
3535
dir2.delete()
@@ -63,10 +63,10 @@ class FilesTest {
6363
createTempFile("temp3", ".kt", dir)
6464

6565
// This line works only with Kotlin File.listFiles(filter)
66-
val result = dir.listFiles { it -> it.getName().endsWith(".kt") } // todo ambiguity on SAM
66+
val result = dir.listFiles { it -> it.name.endsWith(".kt") } // todo ambiguity on SAM
6767
assertEquals(2, result!!.size)
6868
// This line works both with Kotlin File.listFiles(filter) and the same Java function because of SAM
69-
val result2 = dir.listFiles { it -> it.getName().endsWith(".kt") }
69+
val result2 = dir.listFiles { it -> it.name.endsWith(".kt") }
7070
assertEquals(2, result2!!.size)
7171
}
7272

@@ -410,7 +410,7 @@ class FilesTest {
410410
}
411411

412412
@test fun copyToNameWithoutParent() {
413-
val currentDir = File("").getAbsoluteFile()!!
413+
val currentDir = File("").absoluteFile!!
414414
val srcFile = createTempFile()
415415
val dstFile = createTempFile(directory = currentDir)
416416
try {
@@ -474,7 +474,7 @@ class FilesTest {
474474
for (file in src.walkTopDown()) {
475475
val dstFile = File(dst, file.relativeTo(src))
476476
assertTrue(dstFile.exists())
477-
if (dstFile.isFile()) {
477+
if (dstFile.isFile) {
478478
assertEquals(file.readText(), dstFile.readText())
479479
}
480480

libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/AnnotationProcessorWrapper.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public abstract class AnnotationProcessorWrapper(
9595
return
9696
}
9797

98-
val annotationsFilePath = processingEnv.getOptions().get(KAPT_ANNOTATION_OPTION)
98+
val annotationsFilePath = processingEnv.options[KAPT_ANNOTATION_OPTION]
9999
val annotationsFile = if (annotationsFilePath != null) File(annotationsFilePath) else null
100100
kotlinAnnotationsProvider = if (annotationsFile != null && annotationsFile.exists()) {
101101
FileKotlinAnnotationProvider(annotationsFile)
@@ -108,13 +108,13 @@ public abstract class AnnotationProcessorWrapper(
108108
}
109109

110110
override fun getSupportedAnnotationTypes(): MutableSet<String> {
111-
val supportedAnnotations = processor.getSupportedAnnotationTypes().toMutableSet()
111+
val supportedAnnotations = processor.supportedAnnotationTypes.toMutableSet()
112112
supportedAnnotations.add("__gen.KotlinAptAnnotation")
113113
return supportedAnnotations
114114
}
115115

116116
override fun getSupportedSourceVersion(): SourceVersion? {
117-
return processor.getSupportedSourceVersion()
117+
return processor.supportedSourceVersion
118118
}
119119

120120
override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment): Boolean {
@@ -127,13 +127,13 @@ public abstract class AnnotationProcessorWrapper(
127127
}
128128

129129
override fun getSupportedOptions(): MutableSet<String> {
130-
val supportedOptions = processor.getSupportedOptions().toHashSet()
130+
val supportedOptions = processor.supportedOptions.toHashSet()
131131
supportedOptions.add(KAPT_ANNOTATION_OPTION)
132132
return supportedOptions
133133
}
134134

135135
private fun ProcessingEnvironment.err(message: String) {
136-
getMessager().printMessage(Diagnostic.Kind.ERROR, message)
136+
messager.printMessage(Diagnostic.Kind.ERROR, message)
137137
}
138138

139139
}

libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/RoundEnvironmentWrapper.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ internal class RoundEnvironmentWrapper(
1717
) : RoundEnvironment {
1818

1919
override fun getRootElements(): MutableSet<out Element>? {
20-
return parent.getRootElements()
20+
return parent.rootElements
2121
}
2222

2323
override fun getElementsAnnotatedWith(a: TypeElement): MutableSet<out Element>? {
2424
val elements = parent.getElementsAnnotatedWith(a).toHashSet()
25-
elements.addAll(resolveKotlinElements(a.getQualifiedName().toString()))
25+
elements.addAll(resolveKotlinElements(a.qualifiedName.toString()))
2626
return elements
2727
}
2828

2929
override fun getElementsAnnotatedWith(a: Class<out Annotation>): MutableSet<out Element>? {
3030
val elements = parent.getElementsAnnotatedWith(a).toHashSet()
31-
elements.addAll(resolveKotlinElements(a.getName()))
31+
elements.addAll(resolveKotlinElements(a.name))
3232
return elements
3333
}
3434

@@ -37,24 +37,24 @@ internal class RoundEnvironmentWrapper(
3737
override fun errorRaised() = parent.errorRaised()
3838

3939
private fun TypeElement.filterEnclosedElements(kind: ElementKind, name: String): List<Element> {
40-
return getEnclosedElements().filter { it.getKind() == kind && it.getSimpleName().toString() == name }
40+
return enclosedElements.filter { it.kind == kind && it.simpleName.toString() == name }
4141
}
4242

4343
private fun TypeElement.filterEnclosedElements(kind: ElementKind): List<Element> {
44-
return getEnclosedElements().filter { it.getKind() == kind }
44+
return enclosedElements.filter { it.kind == kind }
4545
}
4646

4747
private fun Element.hasAnnotation(annotationFqName: String): Boolean {
48-
return getAnnotationMirrors().any { annotationFqName == it.getAnnotationType().asElement().toString() }
48+
return annotationMirrors.any { annotationFqName == it.annotationType.asElement().toString() }
4949
}
5050

5151
private fun TypeElement.hasInheritedAnnotation(annotationFqName: String): Boolean {
5252
if (hasAnnotation(annotationFqName)) return true
5353

54-
val superclassMirror = getSuperclass()
54+
val superclassMirror = superclass
5555
if (superclassMirror is NoType) return false
5656

57-
val superClass = processingEnv.getTypeUtils().asElement(superclassMirror)
57+
val superClass = processingEnv.typeUtils.asElement(superclassMirror)
5858
if (superClass !is TypeElement) return false
5959

6060
return superClass.hasInheritedAnnotation(annotationFqName)
@@ -65,7 +65,7 @@ internal class RoundEnvironmentWrapper(
6565

6666
val descriptors = kotlinAnnotationsProvider.annotatedKotlinElements.get(annotationFqName) ?: setOf()
6767
val descriptorsWithKotlin = descriptors.fold(hashSetOf<Element>()) { set, descriptor ->
68-
val clazz = processingEnv.getElementUtils().getTypeElement(descriptor.classFqName) ?: return@fold set
68+
val clazz = processingEnv.elementUtils.getTypeElement(descriptor.classFqName) ?: return@fold set
6969
when (descriptor) {
7070
is AnnotatedClassDescriptor -> set.add(clazz)
7171
is AnnotatedConstructorDescriptor -> {
@@ -85,12 +85,12 @@ internal class RoundEnvironmentWrapper(
8585
}
8686

8787
if (kotlinAnnotationsProvider.supportInheritedAnnotations) {
88-
val isInherited = processingEnv.getElementUtils().getTypeElement(annotationFqName)
89-
?.hasAnnotation(Inherited::class.java.getCanonicalName()) ?: false
88+
val isInherited = processingEnv.elementUtils.getTypeElement(annotationFqName)
89+
?.hasAnnotation(Inherited::class.java.canonicalName) ?: false
9090

9191
if (isInherited) {
9292
kotlinAnnotationsProvider.kotlinClasses.forEach { classFqName ->
93-
val clazz = processingEnv.getElementUtils().getTypeElement(classFqName) ?: return@forEach
93+
val clazz = processingEnv.elementUtils.getTypeElement(classFqName) ?: return@forEach
9494
if (clazz.hasInheritedAnnotation(annotationFqName)) {
9595
descriptorsWithKotlin.add(clazz)
9696
}

0 commit comments

Comments
 (0)