summaryrefslogtreecommitdiff
path: root/tools/protologtool
diff options
context:
space:
mode:
authorAdam Pardyl <apardyl@google.com>2019-09-27 10:09:40 +0200
committerAdam Pardyl <apardyl@google.com>2019-09-27 10:24:25 +0200
commit9550999a73ba48e4fbe31530fb4bc215e291175f (patch)
treeb33e71fa8ecda3e1776eec5ba578d16eccefc912 /tools/protologtool
parentea5c362d631dcd67748b54f4a5c1dbe908cee4ef (diff)
Informative error messages, update README
ProtoLogTool error messages are hard to read, this CL addresses this issue adding more info (including file name and line number) and using verbose exception messages where available. Updated README with recent ProtoLog changes. Bug: 141672033 Test: atest protologtool-tests Change-Id: Ibfca908808526adb6c8c5f68893f093a8233728f
Diffstat (limited to 'tools/protologtool')
-rw-r--r--tools/protologtool/README.md41
-rw-r--r--tools/protologtool/src/com/android/protolog/tool/CodeUtils.kt30
-rw-r--r--tools/protologtool/src/com/android/protolog/tool/LogLevel.kt5
-rw-r--r--tools/protologtool/src/com/android/protolog/tool/ParsingContext.kt26
-rw-r--r--tools/protologtool/src/com/android/protolog/tool/ProtoLogCallProcessor.kt35
-rw-r--r--tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt24
-rw-r--r--tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt8
-rw-r--r--tools/protologtool/src/com/android/protolog/tool/ViewerConfigBuilder.kt7
-rw-r--r--tools/protologtool/src/com/android/protolog/tool/exceptions.kt19
-rw-r--r--tools/protologtool/tests/com/android/protolog/tool/CodeUtilsTest.kt32
-rw-r--r--tools/protologtool/tests/com/android/protolog/tool/ProtoLogCallProcessorTest.kt20
-rw-r--r--tools/protologtool/tests/com/android/protolog/tool/SourceTransformerTest.kt24
-rw-r--r--tools/protologtool/tests/com/android/protolog/tool/ViewerConfigBuilderTest.kt9
13 files changed, 181 insertions, 99 deletions
diff --git a/tools/protologtool/README.md b/tools/protologtool/README.md
index 3439357af598..ba639570f88c 100644
--- a/tools/protologtool/README.md
+++ b/tools/protologtool/README.md
@@ -8,8 +8,13 @@ ProtoLogTool incorporates three different modes of operation:
### Code transformation
-Command: `process <protolog class path> <protolog implementation class path>
- <protolog groups class path> <config.jar> [<input.java>] <output.srcjar>`
+Command: `protologtool transform-protolog-calls
+ --protolog-class <protolog class name>
+ --protolog-impl-class <protolog implementation class name>
+ --loggroups-class <protolog groups class name>
+ --loggroups-jar <config jar path>
+ --output-srcjar <output.srcjar>
+ [<input.java>]`
In this mode ProtoLogTool transforms every ProtoLog logging call in form of:
```java
@@ -17,16 +22,20 @@ ProtoLog.x(ProtoLogGroup.GROUP_NAME, "Format string %d %s", value1, value2);
```
into:
```java
-if (GROUP_NAME.isLogToAny()) {
- ProtoLogImpl.x(ProtoLogGroup.GROUP_NAME, 123456, "Format string %d %s or null", value1, value2);
+if (ProtoLogImpl.isEnabled(GROUP_NAME)) {
+ int protoLogParam0 = value1;
+ String protoLogParam1 = String.valueOf(value2);
+ ProtoLogImpl.x(ProtoLogGroup.GROUP_NAME, 123456, 0b0100, "Format string %d %s or null", protoLogParam0, protoLogParam1);
}
```
where `ProtoLog`, `ProtoLogImpl` and `ProtoLogGroup` are the classes provided as arguments
(can be imported, static imported or full path, wildcard imports are not allowed) and, `x` is the
logging method. The transformation is done on the source level. A hash is generated from the format
- string and log level and inserted after the `ProtoLogGroup` argument. The format string is replaced
+ string, log level and log group name and inserted after the `ProtoLogGroup` argument. After the hash
+ we insert a bitmask specifying the types of logged parameters. The format string is replaced
by `null` if `ProtoLogGroup.GROUP_NAME.isLogToLogcat()` returns false. If `ProtoLogGroup.GROUP_NAME.isEnabled()`
- returns false the log statement is removed entirely from the resultant code.
+ returns false the log statement is removed entirely from the resultant code. The real generated code is inlined
+ and a number of new line characters is added as to preserve line numbering in file.
Input is provided as a list of java source file names. Transformed source is saved to a single
source jar file. The ProtoLogGroup class with all dependencies should be provided as a compiled
@@ -34,8 +43,12 @@ jar file (config.jar).
### Viewer config generation
-Command: `viewerconf <protolog class path> <protolog implementation class path
-<protolog groups class path> <config.jar> [<input.java>] <output.json>`
+Command: `generate-viewer-config
+ --protolog-class <protolog class name>
+ --loggroups-class <protolog groups class name>
+ --loggroups-jar <config jar path>
+ --viewer-conf <viewer.json>
+ [<input.java>]`
This command is similar in it's syntax to the previous one, only instead of creating a processed source jar
it writes a viewer configuration file with following schema:
@@ -46,8 +59,9 @@ it writes a viewer configuration file with following schema:
"123456": {
"message": "Format string %d %s",
"level": "ERROR",
- "group": "GROUP_NAME"
- },
+ "group": "GROUP_NAME",
+ "at": "com\/android\/server\/example\/Class.java"
+ }
},
"groups": {
"GROUP_NAME": {
@@ -60,13 +74,13 @@ it writes a viewer configuration file with following schema:
### Binary log viewing
-Command: `read <viewer.json> <wm_log.pb>`
+Command: `read-log --viewer-conf <viewer.json> <wm_log.pb>`
Reads the binary ProtoLog log file and outputs a human-readable LogCat-like text log.
## What is ProtoLog?
-ProtoLog is a logging system created for the WindowManager project. It allows both binary and text logging
+ProtoLog is a generic logging system created for the WindowManager project. It allows both binary and text logging
and is tunable in runtime. It consists of 3 different submodules:
* logging system built-in the Android app,
* log viewer for reading binary logs,
@@ -94,8 +108,7 @@ To add a new ProtoLogGroup simple create a new enum ProtoLogGroup member with de
To add a new logging statement just add a new call to ProtoLog.x where x is a log level.
-After doing any changes to logging groups or statements you should run `make update-protolog` to update
-viewer configuration saved in the code repository.
+After doing any changes to logging groups or statements you should build the project and follow instructions printed by the tool.
## How to change settings on device in runtime?
Use the `adb shell su root cmd window logging` command. To get help just type
diff --git a/tools/protologtool/src/com/android/protolog/tool/CodeUtils.kt b/tools/protologtool/src/com/android/protolog/tool/CodeUtils.kt
index 2e48d97d6349..a52c8042582b 100644
--- a/tools/protologtool/src/com/android/protolog/tool/CodeUtils.kt
+++ b/tools/protologtool/src/com/android/protolog/tool/CodeUtils.kt
@@ -32,9 +32,14 @@ object CodeUtils {
.map { c -> c.toInt() }.reduce { h, c -> h * 31 + c }
}
- fun isWildcardStaticImported(code: CompilationUnit, className: String): Boolean {
- return code.findAll(ImportDeclaration::class.java)
- .any { im -> im.isStatic && im.isAsterisk && im.name.toString() == className }
+ fun checkWildcardStaticImported(code: CompilationUnit, className: String, fileName: String) {
+ code.findAll(ImportDeclaration::class.java)
+ .forEach { im ->
+ if (im.isStatic && im.isAsterisk && im.name.toString() == className) {
+ throw IllegalImportException("Wildcard static imports of $className " +
+ "methods are not supported.", ParsingContext(fileName, im))
+ }
+ }
}
fun isClassImportedOrSamePackage(code: CompilationUnit, className: String): Boolean {
@@ -58,24 +63,19 @@ object CodeUtils {
.map { im -> im.name.toString().substringAfterLast('.') }.toSet()
}
- fun concatMultilineString(expr: Expression): String {
+ fun concatMultilineString(expr: Expression, context: ParsingContext): String {
return when (expr) {
is StringLiteralExpr -> expr.asString()
is BinaryExpr -> when {
expr.operator == BinaryExpr.Operator.PLUS ->
- concatMultilineString(expr.left) + concatMultilineString(expr.right)
+ concatMultilineString(expr.left, context) +
+ concatMultilineString(expr.right, context)
else -> throw InvalidProtoLogCallException(
- "messageString must be a string literal " +
- "or concatenation of string literals.", expr)
+ "expected a string literal " +
+ "or concatenation of string literals, got: $expr", context)
}
- else -> throw InvalidProtoLogCallException("messageString must be a string literal " +
- "or concatenation of string literals.", expr)
- }
- }
-
- fun getPositionString(fileName: String): String {
- return when {
- else -> fileName
+ else -> throw InvalidProtoLogCallException("expected a string literal " +
+ "or concatenation of string literals, got: $expr", context)
}
}
}
diff --git a/tools/protologtool/src/com/android/protolog/tool/LogLevel.kt b/tools/protologtool/src/com/android/protolog/tool/LogLevel.kt
index 7759f35b33fe..e88f0f8231bd 100644
--- a/tools/protologtool/src/com/android/protolog/tool/LogLevel.kt
+++ b/tools/protologtool/src/com/android/protolog/tool/LogLevel.kt
@@ -22,7 +22,7 @@ enum class LogLevel {
DEBUG, VERBOSE, INFO, WARN, ERROR, WTF;
companion object {
- fun getLevelForMethodName(name: String, node: Node): LogLevel {
+ fun getLevelForMethodName(name: String, node: Node, context: ParsingContext): LogLevel {
return when (name) {
"d" -> DEBUG
"v" -> VERBOSE
@@ -30,7 +30,8 @@ enum class LogLevel {
"w" -> WARN
"e" -> ERROR
"wtf" -> WTF
- else -> throw InvalidProtoLogCallException("Unknown log level $name", node)
+ else ->
+ throw InvalidProtoLogCallException("Unknown log level $name in $node", context)
}
}
}
diff --git a/tools/protologtool/src/com/android/protolog/tool/ParsingContext.kt b/tools/protologtool/src/com/android/protolog/tool/ParsingContext.kt
new file mode 100644
index 000000000000..c6aedfc3093e
--- /dev/null
+++ b/tools/protologtool/src/com/android/protolog/tool/ParsingContext.kt
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+package com.android.protolog.tool
+
+import com.github.javaparser.ast.Node
+
+data class ParsingContext(val filePath: String, val lineNumber: Int) {
+ constructor(filePath: String, node: Node)
+ : this(filePath, if (node.range.isPresent) node.range.get().begin.line else -1)
+
+ constructor() : this("", -1)
+}
diff --git a/tools/protologtool/src/com/android/protolog/tool/ProtoLogCallProcessor.kt b/tools/protologtool/src/com/android/protolog/tool/ProtoLogCallProcessor.kt
index eae63962161c..2181cf680f6c 100644
--- a/tools/protologtool/src/com/android/protolog/tool/ProtoLogCallProcessor.kt
+++ b/tools/protologtool/src/com/android/protolog/tool/ProtoLogCallProcessor.kt
@@ -38,23 +38,27 @@ open class ProtoLogCallProcessor(
private fun getLogGroupName(
expr: Expression,
isClassImported: Boolean,
- staticImports: Set<String>
+ staticImports: Set<String>,
+ fileName: String
): String {
+ val context = ParsingContext(fileName, expr)
return when (expr) {
is NameExpr -> when {
expr.nameAsString in staticImports -> expr.nameAsString
else ->
- throw InvalidProtoLogCallException("Unknown/not imported ProtoLogGroup", expr)
+ throw InvalidProtoLogCallException("Unknown/not imported ProtoLogGroup: $expr",
+ context)
}
is FieldAccessExpr -> when {
expr.scope.toString() == protoLogGroupClassName
|| isClassImported &&
expr.scope.toString() == protoLogGroupSimpleClassName -> expr.nameAsString
else ->
- throw InvalidProtoLogCallException("Unknown/not imported ProtoLogGroup", expr)
+ throw InvalidProtoLogCallException("Unknown/not imported ProtoLogGroup: $expr",
+ context)
}
else -> throw InvalidProtoLogCallException("Invalid group argument " +
- "- must be ProtoLogGroup enum member reference", expr)
+ "- must be ProtoLogGroup enum member reference: $expr", context)
}
}
@@ -69,12 +73,10 @@ open class ProtoLogCallProcessor(
!call.scope.isPresent && staticLogImports.contains(call.name.toString())
}
- open fun process(code: CompilationUnit, callVisitor: ProtoLogCallVisitor?): CompilationUnit {
- if (CodeUtils.isWildcardStaticImported(code, protoLogClassName) ||
- CodeUtils.isWildcardStaticImported(code, protoLogGroupClassName)) {
- throw IllegalImportException("Wildcard static imports of $protoLogClassName " +
- "and $protoLogGroupClassName methods are not supported.")
- }
+ open fun process(code: CompilationUnit, callVisitor: ProtoLogCallVisitor?, fileName: String):
+ CompilationUnit {
+ CodeUtils.checkWildcardStaticImported(code, protoLogClassName, fileName)
+ CodeUtils.checkWildcardStaticImported(code, protoLogGroupClassName, fileName)
val isLogClassImported = CodeUtils.isClassImportedOrSamePackage(code, protoLogClassName)
val staticLogImports = CodeUtils.staticallyImportedMethods(code, protoLogClassName)
@@ -86,22 +88,25 @@ open class ProtoLogCallProcessor(
.filter { call ->
isProtoCall(call, isLogClassImported, staticLogImports)
}.forEach { call ->
+ val context = ParsingContext(fileName, call)
if (call.arguments.size < 2) {
throw InvalidProtoLogCallException("Method signature does not match " +
- "any ProtoLog method.", call)
+ "any ProtoLog method: $call", context)
}
- val messageString = CodeUtils.concatMultilineString(call.getArgument(1))
+ val messageString = CodeUtils.concatMultilineString(call.getArgument(1),
+ context)
val groupNameArg = call.getArgument(0)
val groupName =
- getLogGroupName(groupNameArg, isGroupClassImported, staticGroupImports)
+ getLogGroupName(groupNameArg, isGroupClassImported,
+ staticGroupImports, fileName)
if (groupName !in groupMap) {
throw InvalidProtoLogCallException("Unknown group argument " +
- "- not a ProtoLogGroup enum member", call)
+ "- not a ProtoLogGroup enum member: $call", context)
}
callVisitor?.processCall(call, messageString, LogLevel.getLevelForMethodName(
- call.name.toString(), call), groupMap.getValue(groupName))
+ call.name.toString(), call, context), groupMap.getValue(groupName))
}
return code
}
diff --git a/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt b/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt
index 53834a69ef9f..97f3de2c1221 100644
--- a/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt
+++ b/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt
@@ -17,7 +17,9 @@
package com.android.protolog.tool
import com.android.protolog.tool.CommandOptions.Companion.USAGE
+import com.github.javaparser.ParseProblemException
import com.github.javaparser.StaticJavaParser
+import com.github.javaparser.ast.CompilationUnit
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
@@ -48,7 +50,7 @@ object ProtoLogTool {
command.javaSourceArgs.forEach { path ->
val file = File(path)
val text = file.readText()
- val code = StaticJavaParser.parse(text)
+ val code = tryParse(text, path)
val pack = if (code.packageDeclaration.isPresent) code.packageDeclaration
.get().nameAsString else ""
val newPath = pack.replace('.', '/') + '/' + file.name
@@ -66,6 +68,19 @@ object ProtoLogTool {
out.close()
}
+ private fun tryParse(code: String, fileName: String): CompilationUnit {
+ try {
+ return StaticJavaParser.parse(code)
+ } catch (ex: ParseProblemException) {
+ val problem = ex.problems.first()
+ throw ParsingException("Java parsing erro" +
+ "r: ${problem.verboseMessage}",
+ ParsingContext(fileName, problem.location.orElse(null)
+ ?.begin?.range?.orElse(null)?.begin?.line
+ ?: 0))
+ }
+ }
+
private fun viewerConf(command: CommandOptions) {
val groups = ProtoLogGroupReader()
.loadFromJar(command.protoLogGroupsJarArg, command.protoLogGroupsClassNameArg)
@@ -76,7 +91,7 @@ object ProtoLogTool {
val file = File(path)
val text = file.readText()
if (containsProtoLogText(text, command.protoLogClassNameArg)) {
- val code = StaticJavaParser.parse(text)
+ val code = tryParse(text, path)
val pack = if (code.packageDeclaration.isPresent) code.packageDeclaration
.get().nameAsString else ""
val newPath = pack.replace('.', '/') + '/' + file.name
@@ -104,8 +119,11 @@ object ProtoLogTool {
CommandOptions.READ_LOG_CMD -> read(command)
}
} catch (ex: InvalidCommandException) {
- println(ex.message)
+ println("\n${ex.message}\n")
showHelpAndExit()
+ } catch (ex: CodeProcessingException) {
+ println("\n${ex.message}\n")
+ exitProcess(1)
}
}
}
diff --git a/tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt b/tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt
index c2964a3dad7e..00fd038079f9 100644
--- a/tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt
+++ b/tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt
@@ -73,8 +73,7 @@ class SourceTransformer(
}
val ifStmt: IfStmt
if (group.enabled) {
- val position = CodeUtils.getPositionString(fileName)
- val hash = CodeUtils.hash(position, messageString, level, group)
+ val hash = CodeUtils.hash(fileName, messageString, level, group)
val newCall = call.clone()
if (!group.textEnabled) {
// Remove message string if text logging is not enabled by default.
@@ -99,7 +98,8 @@ class SourceTransformer(
NodeList<Expression>(newCall.arguments[0].clone()))
if (argTypes.size != call.arguments.size - 2) {
throw InvalidProtoLogCallException(
- "Number of arguments does not mach format string", call)
+ "Number of arguments (${argTypes.size} does not mach format" +
+ " string in: $call", ParsingContext(fileName, call))
}
val blockStmt = BlockStmt()
if (argTypes.isNotEmpty()) {
@@ -225,7 +225,7 @@ class SourceTransformer(
processedCode = code.split('\n').toMutableList()
offsets = IntArray(processedCode.size)
LexicalPreservingPrinter.setup(compilationUnit)
- protoLogCallProcessor.process(compilationUnit, this)
+ protoLogCallProcessor.process(compilationUnit, this, fileName)
// return LexicalPreservingPrinter.print(compilationUnit)
return processedCode.joinToString("\n")
}
diff --git a/tools/protologtool/src/com/android/protolog/tool/ViewerConfigBuilder.kt b/tools/protologtool/src/com/android/protolog/tool/ViewerConfigBuilder.kt
index 172de0e9d4d0..941455a24ec8 100644
--- a/tools/protologtool/src/com/android/protolog/tool/ViewerConfigBuilder.kt
+++ b/tools/protologtool/src/com/android/protolog/tool/ViewerConfigBuilder.kt
@@ -32,13 +32,14 @@ class ViewerConfigBuilder(
group: LogGroup
) {
if (group.enabled) {
- val position = CodeUtils.getPositionString(fileName)
+ val position = fileName
val key = CodeUtils.hash(position, messageString, level, group)
if (statements.containsKey(key)) {
if (statements[key] != LogCall(messageString, level, group, position)) {
throw HashCollisionException(
"Please modify the log message \"$messageString\" " +
- "or \"${statements[key]}\" - their hashes are equal.")
+ "or \"${statements[key]}\" - their hashes are equal.",
+ ParsingContext(fileName, call))
}
} else {
groups.add(group)
@@ -54,7 +55,7 @@ class ViewerConfigBuilder(
fun processClass(unit: CompilationUnit, fileName: String) {
this.fileName = fileName
- protoLogCallVisitor.process(unit, this)
+ protoLogCallVisitor.process(unit, this, fileName)
}
fun build(): String {
diff --git a/tools/protologtool/src/com/android/protolog/tool/exceptions.kt b/tools/protologtool/src/com/android/protolog/tool/exceptions.kt
index 0401d8f8baa0..ae00df123353 100644
--- a/tools/protologtool/src/com/android/protolog/tool/exceptions.kt
+++ b/tools/protologtool/src/com/android/protolog/tool/exceptions.kt
@@ -16,16 +16,23 @@
package com.android.protolog.tool
-import com.github.javaparser.ast.Node
import java.lang.Exception
-import java.lang.RuntimeException
-class HashCollisionException(message: String) : RuntimeException(message)
+open class CodeProcessingException(message: String, context: ParsingContext)
+ : Exception("Code processing error in ${context.filePath}:${context.lineNumber}:\n" +
+ " $message")
-class IllegalImportException(message: String) : Exception(message)
+class HashCollisionException(message: String, context: ParsingContext) :
+ CodeProcessingException(message, context)
-class InvalidProtoLogCallException(message: String, node: Node)
- : RuntimeException("$message\nAt: $node")
+class IllegalImportException(message: String, context: ParsingContext) :
+ CodeProcessingException("Illegal import: $message", context)
+
+class InvalidProtoLogCallException(message: String, context: ParsingContext)
+ : CodeProcessingException("InvalidProtoLogCall: $message", context)
+
+class ParsingException(message: String, context: ParsingContext)
+ : CodeProcessingException(message, context)
class InvalidViewerConfigException(message: String) : Exception(message)
diff --git a/tools/protologtool/tests/com/android/protolog/tool/CodeUtilsTest.kt b/tools/protologtool/tests/com/android/protolog/tool/CodeUtilsTest.kt
index 0acbc9074857..b916f8f00a68 100644
--- a/tools/protologtool/tests/com/android/protolog/tool/CodeUtilsTest.kt
+++ b/tools/protologtool/tests/com/android/protolog/tool/CodeUtilsTest.kt
@@ -55,40 +55,40 @@ class CodeUtilsTest {
LogLevel.DEBUG, LogGroup("test2", true, true, "TAG")))
}
- @Test
- fun isWildcardStaticImported_true() {
+ @Test(expected = IllegalImportException::class)
+ fun checkWildcardStaticImported_true() {
val code = """package org.example.test;
import static org.example.Test.*;
"""
- assertTrue(CodeUtils.isWildcardStaticImported(
- StaticJavaParser.parse(code), "org.example.Test"))
+ CodeUtils.checkWildcardStaticImported(
+ StaticJavaParser.parse(code), "org.example.Test", "")
}
@Test
- fun isWildcardStaticImported_notStatic() {
+ fun checkWildcardStaticImported_notStatic() {
val code = """package org.example.test;
import org.example.Test.*;
"""
- assertFalse(CodeUtils.isWildcardStaticImported(
- StaticJavaParser.parse(code), "org.example.Test"))
+ CodeUtils.checkWildcardStaticImported(
+ StaticJavaParser.parse(code), "org.example.Test", "")
}
@Test
- fun isWildcardStaticImported_differentClass() {
+ fun checkWildcardStaticImported_differentClass() {
val code = """package org.example.test;
import static org.example.Test2.*;
"""
- assertFalse(CodeUtils.isWildcardStaticImported(
- StaticJavaParser.parse(code), "org.example.Test"))
+ CodeUtils.checkWildcardStaticImported(
+ StaticJavaParser.parse(code), "org.example.Test", "")
}
@Test
- fun isWildcardStaticImported_notWildcard() {
+ fun checkWildcardStaticImported_notWildcard() {
val code = """package org.example.test;
import org.example.Test.test;
"""
- assertFalse(CodeUtils.isWildcardStaticImported(
- StaticJavaParser.parse(code), "org.example.Test"))
+ CodeUtils.checkWildcardStaticImported(
+ StaticJavaParser.parse(code), "org.example.Test", "")
}
@Test
@@ -156,7 +156,7 @@ class CodeUtilsTest {
@Test
fun concatMultilineString_single() {
val str = StringLiteralExpr("test")
- val out = CodeUtils.concatMultilineString(str)
+ val out = CodeUtils.concatMultilineString(str, ParsingContext())
assertEquals("test", out)
}
@@ -166,7 +166,7 @@ class CodeUtilsTest {
"test" + "abc"
"""
val code = StaticJavaParser.parseExpression<BinaryExpr>(str)
- val out = CodeUtils.concatMultilineString(code)
+ val out = CodeUtils.concatMultilineString(code, ParsingContext())
assertEquals("testabc", out)
}
@@ -176,7 +176,7 @@ class CodeUtilsTest {
"test" + "abc" + "1234" + "test"
"""
val code = StaticJavaParser.parseExpression<BinaryExpr>(str)
- val out = CodeUtils.concatMultilineString(code)
+ val out = CodeUtils.concatMultilineString(code, ParsingContext())
assertEquals("testabc1234test", out)
}
}
diff --git a/tools/protologtool/tests/com/android/protolog/tool/ProtoLogCallProcessorTest.kt b/tools/protologtool/tests/com/android/protolog/tool/ProtoLogCallProcessorTest.kt
index d20ce7ec4dcb..97f67a0a3fdb 100644
--- a/tools/protologtool/tests/com/android/protolog/tool/ProtoLogCallProcessorTest.kt
+++ b/tools/protologtool/tests/com/android/protolog/tool/ProtoLogCallProcessorTest.kt
@@ -66,7 +66,7 @@ class ProtoLogCallProcessorTest {
"""
groupMap["TEST"] = LogGroup("TEST", true, false, "WindowManager")
groupMap["ERROR"] = LogGroup("ERROR", true, true, "WindowManagerERROR")
- visitor.process(StaticJavaParser.parse(code), processor)
+ visitor.process(StaticJavaParser.parse(code), processor, "")
assertEquals(2, calls.size)
var c = calls[0]
assertEquals("test %b", c.messageString)
@@ -93,7 +93,7 @@ class ProtoLogCallProcessorTest {
}
"""
groupMap["TEST"] = LogGroup("TEST", true, true, "WindowManager")
- visitor.process(StaticJavaParser.parse(code), processor)
+ visitor.process(StaticJavaParser.parse(code), processor, "")
checkCalls()
}
@@ -112,7 +112,7 @@ class ProtoLogCallProcessorTest {
}
"""
groupMap["TEST"] = LogGroup("TEST", true, true, "WindowManager")
- visitor.process(StaticJavaParser.parse(code), processor)
+ visitor.process(StaticJavaParser.parse(code), processor, "")
checkCalls()
}
@@ -130,7 +130,7 @@ class ProtoLogCallProcessorTest {
}
"""
groupMap["TEST"] = LogGroup("TEST", true, true, "WindowManager")
- visitor.process(StaticJavaParser.parse(code), processor)
+ visitor.process(StaticJavaParser.parse(code), processor, "")
}
@Test
@@ -147,7 +147,7 @@ class ProtoLogCallProcessorTest {
}
"""
groupMap["TEST"] = LogGroup("TEST", true, true, "WindowManager")
- visitor.process(StaticJavaParser.parse(code), processor)
+ visitor.process(StaticJavaParser.parse(code), processor, "")
assertEquals(0, calls.size)
}
@@ -162,7 +162,7 @@ class ProtoLogCallProcessorTest {
}
}
"""
- visitor.process(StaticJavaParser.parse(code), processor)
+ visitor.process(StaticJavaParser.parse(code), processor, "")
}
@Test(expected = InvalidProtoLogCallException::class)
@@ -176,7 +176,7 @@ class ProtoLogCallProcessorTest {
}
}
"""
- visitor.process(StaticJavaParser.parse(code), processor)
+ visitor.process(StaticJavaParser.parse(code), processor, "")
}
@Test(expected = InvalidProtoLogCallException::class)
@@ -190,7 +190,7 @@ class ProtoLogCallProcessorTest {
}
}
"""
- visitor.process(StaticJavaParser.parse(code), processor)
+ visitor.process(StaticJavaParser.parse(code), processor, "")
}
@Test(expected = InvalidProtoLogCallException::class)
@@ -204,7 +204,7 @@ class ProtoLogCallProcessorTest {
}
}
"""
- visitor.process(StaticJavaParser.parse(code), processor)
+ visitor.process(StaticJavaParser.parse(code), processor, "")
}
@Test
@@ -220,7 +220,7 @@ class ProtoLogCallProcessorTest {
}
"""
groupMap["TEST"] = LogGroup("TEST", false, true, "WindowManager")
- visitor.process(StaticJavaParser.parse(code), processor)
+ visitor.process(StaticJavaParser.parse(code), processor, "")
checkCalls()
}
}
diff --git a/tools/protologtool/tests/com/android/protolog/tool/SourceTransformerTest.kt b/tools/protologtool/tests/com/android/protolog/tool/SourceTransformerTest.kt
index 18504b684006..e746300646c8 100644
--- a/tools/protologtool/tests/com/android/protolog/tool/SourceTransformerTest.kt
+++ b/tools/protologtool/tests/com/android/protolog/tool/SourceTransformerTest.kt
@@ -175,7 +175,8 @@ class SourceTransformerTest {
var code = StaticJavaParser.parse(TEST_CODE)
Mockito.`when`(processor.process(any(CompilationUnit::class.java),
- any(ProtoLogCallVisitor::class.java))).thenAnswer { invocation ->
+ any(ProtoLogCallVisitor::class.java), any(String::class.java)))
+ .thenAnswer { invocation ->
val visitor = invocation.arguments[1] as ProtoLogCallVisitor
visitor.processCall(code.findAll(MethodCallExpr::class.java)[0], "test %d %f",
@@ -212,7 +213,8 @@ class SourceTransformerTest {
var code = StaticJavaParser.parse(TEST_CODE_MULTICALLS)
Mockito.`when`(processor.process(any(CompilationUnit::class.java),
- any(ProtoLogCallVisitor::class.java))).thenAnswer { invocation ->
+ any(ProtoLogCallVisitor::class.java), any(String::class.java)))
+ .thenAnswer { invocation ->
val visitor = invocation.arguments[1] as ProtoLogCallVisitor
val calls = code.findAll(MethodCallExpr::class.java)
@@ -254,7 +256,8 @@ class SourceTransformerTest {
var code = StaticJavaParser.parse(TEST_CODE_MULTILINE)
Mockito.`when`(processor.process(any(CompilationUnit::class.java),
- any(ProtoLogCallVisitor::class.java))).thenAnswer { invocation ->
+ any(ProtoLogCallVisitor::class.java), any(String::class.java)))
+ .thenAnswer { invocation ->
val visitor = invocation.arguments[1] as ProtoLogCallVisitor
visitor.processCall(code.findAll(MethodCallExpr::class.java)[0],
@@ -292,7 +295,8 @@ class SourceTransformerTest {
var code = StaticJavaParser.parse(TEST_CODE_NO_PARAMS)
Mockito.`when`(processor.process(any(CompilationUnit::class.java),
- any(ProtoLogCallVisitor::class.java))).thenAnswer { invocation ->
+ any(ProtoLogCallVisitor::class.java), any(String::class.java)))
+ .thenAnswer { invocation ->
val visitor = invocation.arguments[1] as ProtoLogCallVisitor
visitor.processCall(code.findAll(MethodCallExpr::class.java)[0], "test",
@@ -326,7 +330,8 @@ class SourceTransformerTest {
var code = StaticJavaParser.parse(TEST_CODE)
Mockito.`when`(processor.process(any(CompilationUnit::class.java),
- any(ProtoLogCallVisitor::class.java))).thenAnswer { invocation ->
+ any(ProtoLogCallVisitor::class.java), any(String::class.java)))
+ .thenAnswer { invocation ->
val visitor = invocation.arguments[1] as ProtoLogCallVisitor
visitor.processCall(code.findAll(MethodCallExpr::class.java)[0], "test %d %f",
@@ -363,7 +368,8 @@ class SourceTransformerTest {
var code = StaticJavaParser.parse(TEST_CODE_MULTILINE)
Mockito.`when`(processor.process(any(CompilationUnit::class.java),
- any(ProtoLogCallVisitor::class.java))).thenAnswer { invocation ->
+ any(ProtoLogCallVisitor::class.java), any(String::class.java)))
+ .thenAnswer { invocation ->
val visitor = invocation.arguments[1] as ProtoLogCallVisitor
visitor.processCall(code.findAll(MethodCallExpr::class.java)[0],
@@ -402,7 +408,8 @@ class SourceTransformerTest {
var code = StaticJavaParser.parse(TEST_CODE)
Mockito.`when`(processor.process(any(CompilationUnit::class.java),
- any(ProtoLogCallVisitor::class.java))).thenAnswer { invocation ->
+ any(ProtoLogCallVisitor::class.java), any(String::class.java)))
+ .thenAnswer { invocation ->
val visitor = invocation.arguments[1] as ProtoLogCallVisitor
visitor.processCall(code.findAll(MethodCallExpr::class.java)[0], "test %d %f",
@@ -426,7 +433,8 @@ class SourceTransformerTest {
var code = StaticJavaParser.parse(TEST_CODE_MULTILINE)
Mockito.`when`(processor.process(any(CompilationUnit::class.java),
- any(ProtoLogCallVisitor::class.java))).thenAnswer { invocation ->
+ any(ProtoLogCallVisitor::class.java), any(String::class.java)))
+ .thenAnswer { invocation ->
val visitor = invocation.arguments[1] as ProtoLogCallVisitor
visitor.processCall(code.findAll(MethodCallExpr::class.java)[0],
diff --git a/tools/protologtool/tests/com/android/protolog/tool/ViewerConfigBuilderTest.kt b/tools/protologtool/tests/com/android/protolog/tool/ViewerConfigBuilderTest.kt
index d3f8c767e8b1..2b6abcdee7ed 100644
--- a/tools/protologtool/tests/com/android/protolog/tool/ViewerConfigBuilderTest.kt
+++ b/tools/protologtool/tests/com/android/protolog/tool/ViewerConfigBuilderTest.kt
@@ -50,7 +50,8 @@ class ViewerConfigBuilderTest {
@Test
fun processClass() {
Mockito.`when`(processor.process(any(CompilationUnit::class.java),
- any(ProtoLogCallVisitor::class.java))).thenAnswer { invocation ->
+ any(ProtoLogCallVisitor::class.java), any(String::class.java)))
+ .thenAnswer { invocation ->
val visitor = invocation.arguments[1] as ProtoLogCallVisitor
visitor.processCall(MethodCallExpr(), TEST1.messageString, LogLevel.INFO,
@@ -78,7 +79,8 @@ class ViewerConfigBuilderTest {
@Test
fun processClass_nonUnique() {
Mockito.`when`(processor.process(any(CompilationUnit::class.java),
- any(ProtoLogCallVisitor::class.java))).thenAnswer { invocation ->
+ any(ProtoLogCallVisitor::class.java), any(String::class.java)))
+ .thenAnswer { invocation ->
val visitor = invocation.arguments[1] as ProtoLogCallVisitor
visitor.processCall(MethodCallExpr(), TEST1.messageString, LogLevel.INFO,
@@ -102,7 +104,8 @@ class ViewerConfigBuilderTest {
@Test
fun processClass_disabled() {
Mockito.`when`(processor.process(any(CompilationUnit::class.java),
- any(ProtoLogCallVisitor::class.java))).thenAnswer { invocation ->
+ any(ProtoLogCallVisitor::class.java), any(String::class.java)))
+ .thenAnswer { invocation ->
val visitor = invocation.arguments[1] as ProtoLogCallVisitor
visitor.processCall(MethodCallExpr(), TEST1.messageString, LogLevel.INFO,