diff --git a/.github/badges/branches.svg b/.github/badges/branches.svg new file mode 100644 index 00000000..9e1337fa --- /dev/null +++ b/.github/badges/branches.svg @@ -0,0 +1 @@ +branches24.2% \ No newline at end of file diff --git a/.github/badges/jacoco.svg b/.github/badges/jacoco.svg new file mode 100644 index 00000000..2a30997d --- /dev/null +++ b/.github/badges/jacoco.svg @@ -0,0 +1 @@ +coverage42% \ No newline at end of file diff --git a/.github/workflows/gradle-build.yml b/.github/workflows/gradle-build.yml index 3e53c315..9cdaa11c 100644 --- a/.github/workflows/gradle-build.yml +++ b/.github/workflows/gradle-build.yml @@ -27,9 +27,9 @@ jobs: with: arguments: build --info - - uses: gradle/gradle-build-action@v1 - with: - arguments: test --info + # - uses: gradle/gradle-build-action@v1 + # with: + # arguments: test --info gradle_ubuntu: runs-on: ubuntu-latest @@ -53,6 +53,35 @@ jobs: with: arguments: build --info - - uses: gradle/gradle-build-action@v1 + # - uses: gradle/gradle-build-action@v1 + # with: + # arguments: test --info + + - name: Generate JaCoCo Badge + uses: cicirello/jacoco-badge-generator@v2 + with: + generate-branches-badge: true + jacoco-csv-file: build/reports/jacoco/test/jacocoTestReport.csv + + - name: Log coverage percentage + run: | + echo "coverage = ${{ steps.jacoco.outputs.coverage }}" + echo "branch coverage = ${{ steps.jacoco.outputs.branches }}" + + - name: Clean Bison directory + run: | + pwd + rm -r ./bison-3.8 + + - name: Commit and push the badge (if it changed) + uses: EndBug/add-and-commit@v7 + with: + default_author: user_info + message: 'commit badge' + add: '*.svg' + + - name: Upload JaCoCo coverage report + uses: actions/upload-artifact@v2 with: - arguments: test --info + name: jacoco-report + path: target/site/jacoco/ diff --git a/.gitignore b/.gitignore index b21ee67c..b2dd2fa6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,7 @@ out .gradle .idea build +src/main/java/parser/JavaParser.java compile_and_run_tests.bat -j2eo.jar \ No newline at end of file +j2eo.jar +output.eo \ No newline at end of file diff --git a/README.md b/README.md index 011b2408..65af0f11 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@
[![Gradle Build](https://github.com/polystat/j2eo/actions/workflows/gradle-build.yml/badge.svg)](https://github.com/polystat/j2eo/actions/workflows/gradle-build.yml) +![Coverage](.github/badges/jacoco.svg) +![Branches](.github/badges/branches.svg) This is a translator of **Java** programming language to [EOLANG](https://www.eolang.org) programming language. @@ -32,7 +34,7 @@ cat <.java filepath> | docker run --rm -i polystat/j2eo java -jar j2eo.jar - 1. Make sure you have installed: - **Java 16+** (make sure command `java -version` shows 16+ version of Java in terminal if you have multiple Java version installed) - - **Maven 3.3+** (be aware of [possible conflicts](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=980467) of the latest versions of Maven and Java on some OSs) + - **Maven 3.8+** (be aware of [possible conflicts](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=980467) of the latest versions of Maven and Java on some OSs) - **Bison 3.7+** [3.7.5 recommended] (make sure the path to Bison executable is added to the `PATH` environmental variable) 2. Clone the repo into your folder: @@ -106,21 +108,21 @@ bugs in our code. It is also much easier to work with abstraction layer than wit ## NOT covered Java features list -- Type Erasure -- Subtyping -- Conversions -- Casting -- Modules -- Exceptions -- Asserts -- Throws +- Type Erasure - Zouev +- Subtyping - discuss with Yegor +- Conversions - remove +- Casting - remove +- Modules +- Exceptions - remove +- Asserts - remove +- Throws - remove - ``synchronized`` blocks -- ``try``/``catch`` blocks +- ``try``/``catch`` blocks - remove - ``yeild`` feature -- Threads and Locks -- Generics (all kinds of them) -- Native methods -- break and continue statements -- RTTI (instanceof operator) ?????? +- Threads and Locks +- Generics (all kinds of them) - remove +- Native methods +- break and continue statements - remove +- RTTI (instanceof operator) ?????? - remove In general, we cover **91 feature of 112** described in the Java language specification. \ No newline at end of file diff --git a/bin/README.md b/bin/README.md new file mode 100644 index 00000000..ef402392 --- /dev/null +++ b/bin/README.md @@ -0,0 +1,3 @@ +# ⚠️ NOTICE ⚠️ + +This directory contains binaries provided by GNU Bison project, thus, not implemented by us. We distribute it here to ease the process of setting up the development environment. Feel free to delete them/replace by files located in your local system. \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 397dd6cd..20dffa34 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,7 @@ import org.apache.tools.ant.taskdefs.condition.Os import java.security.MessageDigest import org.gradle.jvm.tasks.Jar +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { @@ -8,11 +9,21 @@ plugins { jacoco pmd checkstyle + kotlin("jvm") version "1.6.0" } group = "org.eolang" version = "0.1" +val compileKotlin: KotlinCompile by tasks +compileKotlin.kotlinOptions { + jvmTarget = "15" +} +val compileTestKotlin: KotlinCompile by tasks +compileTestKotlin.kotlinOptions { + jvmTarget = "15" +} + // The Java grammar source file for Bison val javaGrammarFilePath = "src/main/resources/Java_16_Grammar.y" @@ -31,10 +42,17 @@ repositories { } dependencies { + // Library for command-line arguments support implementation("commons-cli:commons-cli:1.4") + // Functional stuff + implementation("io.arrow-kt:arrow-core:1.0.1") + // Kotlin logger + implementation("org.slf4j:slf4j-simple:1.7.29") + implementation("io.github.microutils:kotlin-logging-jvm:2.1.0") testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1") + implementation(kotlin("stdlib-jdk8")) } @@ -48,6 +66,7 @@ val fatJar = task("fatJar", type = Jar::class) { // Include dependencies from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) with(tasks["jar"] as CopySpec) + duplicatesStrategy = org.gradle.api.file.DuplicatesStrategy.INCLUDE } tasks { @@ -143,6 +162,7 @@ tasks.withType { } })) } + reports.csv.required.set(true) } /** @@ -200,7 +220,7 @@ fun runBison() = ) } else -> - throw kotlin.UnsupportedOperationException("Your OS is not yet supported. File a GitHub or issue or " + + throw UnsupportedOperationException("Your OS is not yet supported. File a GitHub or issue or " + "provide a Pull Request with support for Bison execution for your OS.") } } catch (e: Exception) { diff --git a/src/main/java/eotree/EOAnonExpr.java b/src/main/java/eotree/EOAnonExpr.java deleted file mode 100644 index a574a177..00000000 --- a/src/main/java/eotree/EOAnonExpr.java +++ /dev/null @@ -1,12 +0,0 @@ -package eotree; - -public class EOAnonExpr extends EOBnd { - public EOAnonExpr(EOExpr expr) { - super(expr); - } - - @Override - public String generateEO(int indent) { - return expr.generateEO(indent); - } -} diff --git a/src/main/java/eotree/EOAttribute.java b/src/main/java/eotree/EOAttribute.java deleted file mode 100644 index 96f7c0b3..00000000 --- a/src/main/java/eotree/EOAttribute.java +++ /dev/null @@ -1,26 +0,0 @@ -package eotree; - -/** - * EBNF representation: - * - * '@' | name [ '...' ] - * - */ -public class EOAttribute extends EONode { - public static final EOAttribute DECORATEE = new EOAttribute("@", false); - public static final EOAttribute PARENT = new EOAttribute("^", false); - public static final EOAttribute CURRENT = new EOAttribute("$", false); - - public String name; - public boolean isVarArg; - - public EOAttribute(String name, boolean isVarArg) { - this.name = name; - this.isVarArg = isVarArg; - } - - @Override - public String generateEO(int indent) { - return name + (isVarArg ? " ..." : ""); - } -} diff --git a/src/main/java/eotree/EOAttributes.java b/src/main/java/eotree/EOAttributes.java deleted file mode 100644 index a4202104..00000000 --- a/src/main/java/eotree/EOAttributes.java +++ /dev/null @@ -1,21 +0,0 @@ -package eotree; - -import java.util.List; -import java.util.stream.Collectors; - -public class EOAttributes extends EONode { - public List attributes; - - public EOAttributes(List attributes) { - this.attributes = attributes; - } - - @Override - public String generateEO(int indent) { - return "[" + - attributes.stream() - .map(attribute -> attribute.generateEO(indent)) - .collect(Collectors.joining(" ")) - + "]"; - } -} diff --git a/src/main/java/eotree/EOBnd.java b/src/main/java/eotree/EOBnd.java deleted file mode 100644 index 56a80b31..00000000 --- a/src/main/java/eotree/EOBnd.java +++ /dev/null @@ -1,9 +0,0 @@ -package eotree; - -public abstract class EOBnd extends EONode { - public EOExpr expr; - - public EOBnd(EOExpr expr) { - this.expr = expr; - } -} diff --git a/src/main/java/eotree/EOBnd.kt b/src/main/java/eotree/EOBnd.kt new file mode 100644 index 00000000..1517cfa4 --- /dev/null +++ b/src/main/java/eotree/EOBnd.kt @@ -0,0 +1,3 @@ +package eotree + +abstract class EOBnd(var expr: EOExpr) : EONode() \ No newline at end of file diff --git a/src/main/java/eotree/EOBndExpr.java b/src/main/java/eotree/EOBndExpr.java deleted file mode 100644 index 885e2790..00000000 --- a/src/main/java/eotree/EOBndExpr.java +++ /dev/null @@ -1,28 +0,0 @@ -package eotree; - -import java.util.Arrays; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class EOBndExpr extends EOBnd { - public EOBndName bndName; - - public EOBndExpr(EOExpr expr, EOBndName bndName) { - super(expr); - this.bndName = bndName; - } - - @Override - public String generateEO(int indent) { - var lines = expr.generateEO(indent).split("\n"); - // Append attribute name to the first line - return Stream.concat( - Arrays.stream(lines) - .findFirst() - .map(line -> line + " > " + bndName.generateEO(0)) - .stream(), - Arrays.stream(lines) - .skip(1) - ).collect(Collectors.joining("\n")); - } -} diff --git a/src/main/java/eotree/EOBndExpr.kt b/src/main/java/eotree/EOBndExpr.kt new file mode 100644 index 00000000..d687d8c9 --- /dev/null +++ b/src/main/java/eotree/EOBndExpr.kt @@ -0,0 +1,19 @@ +package eotree + +import arrow.core.prependTo +import arrow.core.tail + +class EOBndExpr(expr: EOExpr, var bndName: String) : EOBnd(expr) { + override fun generateEO(indent: Int): String { + val lines = expr.generateEO(indent).split("\n") + + // Append attribute name to the first line + return lines + .first() + .let { line -> "$line > $bndName" } + .prependTo(lines.tail()) + .joinToString("\n") + } + + override fun toString(): String = "[expr] > $bndName" +} \ No newline at end of file diff --git a/src/main/java/eotree/EOBndName.java b/src/main/java/eotree/EOBndName.java deleted file mode 100644 index ec4f8a0e..00000000 --- a/src/main/java/eotree/EOBndName.java +++ /dev/null @@ -1,14 +0,0 @@ -package eotree; - -public class EOBndName extends EONode { - public String name; - - public EOBndName(String name) { - this.name = name; - } - - @Override - public String generateEO(int indent) { - return name; - } -} diff --git a/src/main/java/eotree/EOComment.java b/src/main/java/eotree/EOComment.java deleted file mode 100644 index 8877fbce..00000000 --- a/src/main/java/eotree/EOComment.java +++ /dev/null @@ -1,20 +0,0 @@ -package eotree; - -/** - * EBNF representation: - * - * '#' ANY EOL - * - */ -public class EOComment extends EONode { - public String comment; - - public EOComment(String comment) { - this.comment = comment; - } - - @Override - public String generateEO(int indent) { - return "# " + comment; - } -} diff --git a/src/main/java/eotree/EOComment.kt b/src/main/java/eotree/EOComment.kt new file mode 100644 index 00000000..ea976e19 --- /dev/null +++ b/src/main/java/eotree/EOComment.kt @@ -0,0 +1,15 @@ +package eotree + +/** + * EBNF representation: + * ` + * '#' ANY EOL +` * + */ +class EOComment(var comment: String) : EONode() { + override fun generateEO(indent: Int): String = + "# $comment" + + override fun toString(): String = + "# $comment" +} \ No newline at end of file diff --git a/src/main/java/eotree/EOCopy.java b/src/main/java/eotree/EOCopy.java deleted file mode 100644 index 6afeda4b..00000000 --- a/src/main/java/eotree/EOCopy.java +++ /dev/null @@ -1,21 +0,0 @@ -package eotree; - -import java.util.List; -import java.util.stream.Collectors; - -public class EOCopy extends EOExpr { - public EOExpr trg; - public List args; - - public EOCopy(EOExpr trg, List args) { - this.trg = trg; - this.args = args; - } - - @Override - public String generateEO(int indent) { - return trg.generateEO(indent) + args.stream() - .map(arg -> "\n" + arg.generateEO(indent + 1)) - .collect(Collectors.joining()); - } -} diff --git a/src/main/java/eotree/EOCopy.kt b/src/main/java/eotree/EOCopy.kt new file mode 100644 index 00000000..23f34d70 --- /dev/null +++ b/src/main/java/eotree/EOCopy.kt @@ -0,0 +1,29 @@ +package eotree + +class EOCopy : EOExpr { + val trg: EODot + val args: List + + constructor(trg: String, args: List) { + this.trg = trg.eoDot() + this.args = args + } + + constructor(trg: EODot, args: List) { + this.trg = trg + this.args = args + } + + constructor(trg: String, vararg args: EOExpr) : this(trg, args.toList()) + + constructor(trg: EODot, vararg args: EOExpr) : this(trg, args.toList()) + + override fun generateEO(indent: Int): String { + return trg.generateEO(indent) + args + .map { arg -> "\n${arg.generateEO(indent + 1)}" } + .joinToString("") + } + + override fun toString(): String = + "$trg(${args.joinToString()})" +} \ No newline at end of file diff --git a/src/main/java/eotree/EODot.java b/src/main/java/eotree/EODot.java deleted file mode 100644 index 8d7389ba..00000000 --- a/src/main/java/eotree/EODot.java +++ /dev/null @@ -1,22 +0,0 @@ -package eotree; - -import java.util.Optional; - -public class EODot extends EOExpr { - public Optional src; - public String name; - - public EODot(Optional src, String name) { - this.src = src; - this.name = name; - } - - @Override - public String generateEO(int indent) { - return - src - .map(eoExpr -> eoExpr.generateEO(indent) + ".") - .orElse(indent(indent)) - + name; - } -} diff --git a/src/main/java/eotree/EODot.kt b/src/main/java/eotree/EODot.kt new file mode 100644 index 00000000..8a23749f --- /dev/null +++ b/src/main/java/eotree/EODot.kt @@ -0,0 +1,51 @@ +package eotree + +import arrow.core.* +import tree.CompoundName + +class EODot : EOExpr { + var src: Option + var name: String + + constructor(name: String) : this(name.split(".")) + + constructor(names: List) { + this.name = names.last() + this.src = if (names.size > 1) + EODot(names.dropLast(1)).some() + else + None + } + + constructor(src: Option, name: String) { + this.src = src + this.name = name + } + + constructor(name: CompoundName) { + println("Mapping ${name.concatenatedJava()}") + // Recursively build a dot expression + this.src = + if (name.names.size >= 2) + Some(EODot(CompoundName(name.names.dropLast(1)))) + else None + this.name = name.names.last() + } + + override fun generateEO(indent: Int): String = + src + .map { src -> src.generateEO(indent) + "." + name } + .getOrElse { indent(indent) + name } + + override fun toString(): String = + src + .map { src -> "$src.$name" } + .getOrElse { name } +} + + +fun String.eoDot(): EODot = EODot(this) + +fun CompoundName.eoDot(): EODot = EODot(this) + +fun List.eoDot(): EODot = EODot(this) diff --git a/src/main/java/eotree/EOExpr.java b/src/main/java/eotree/EOExpr.java deleted file mode 100644 index a0380dab..00000000 --- a/src/main/java/eotree/EOExpr.java +++ /dev/null @@ -1,4 +0,0 @@ -package eotree; - -public abstract class EOExpr extends EONode { -} diff --git a/src/main/java/eotree/EOExpr.kt b/src/main/java/eotree/EOExpr.kt new file mode 100644 index 00000000..9fd593bb --- /dev/null +++ b/src/main/java/eotree/EOExpr.kt @@ -0,0 +1,3 @@ +package eotree + +abstract class EOExpr : EONode() \ No newline at end of file diff --git a/src/main/java/eotree/EOLicense.java b/src/main/java/eotree/EOLicense.java deleted file mode 100644 index e5435ddd..00000000 --- a/src/main/java/eotree/EOLicense.java +++ /dev/null @@ -1,30 +0,0 @@ -package eotree; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -/** - * EBNF representation: - * - * { comment EOL } EOL - * - */ -public class EOLicense extends EONode { - public List comments; - - public EOLicense(List comments) { - this.comments = comments; - } - - public EOLicense(EOComment... comments) { - this(Arrays.stream(comments).collect(Collectors.toList())); - } - - @Override - public String generateEO(int indent) { - return comments.stream() - .map(comment -> comment.generateEO(indent)) - .collect(Collectors.joining("\n")); - } -} diff --git a/src/main/java/eotree/EOLicense.kt b/src/main/java/eotree/EOLicense.kt new file mode 100644 index 00000000..ab9552ef --- /dev/null +++ b/src/main/java/eotree/EOLicense.kt @@ -0,0 +1,23 @@ +package eotree + +import java.util.* +import java.util.stream.Collectors + +/** + * EBNF representation: + * ` + * { comment EOL } EOL +` * + */ +class EOLicense(var comments: List) : EONode() { + constructor(vararg comments: EOComment) : this(Arrays.stream(comments) + .collect(Collectors.toList())) { + } + + override fun generateEO(indent: Int): String = + comments + .map { comment: EOComment -> comment.generateEO(indent) } + .joinToString("\n") + + override fun toString(): String = "+ [license]" +} \ No newline at end of file diff --git a/src/main/java/eotree/EOMeta.java b/src/main/java/eotree/EOMeta.java deleted file mode 100644 index c767be73..00000000 --- a/src/main/java/eotree/EOMeta.java +++ /dev/null @@ -1,22 +0,0 @@ -package eotree; - -/** - * EBNF representation: - * - * '+' name ' ' ANY EOL - * - */ -public class EOMeta extends EONode { - public String name; - public String value; - - public EOMeta(String name, String value) { - this.name = name; - this.value = value; - } - - @Override - public String generateEO(int indent) { - return "+" + name + " " + value; - } -} diff --git a/src/main/java/eotree/EOMeta.kt b/src/main/java/eotree/EOMeta.kt new file mode 100644 index 00000000..54c4408b --- /dev/null +++ b/src/main/java/eotree/EOMeta.kt @@ -0,0 +1,14 @@ +package eotree + +/** + * EBNF representation: + * ` + * '+' name ' ' ANY EOL +` * + */ +class EOMeta(var name: String, var value: String) : EONode() { + override fun generateEO(indent: Int): String = + "+$name $value" + + override fun toString(): String = "+$name $value" +} \ No newline at end of file diff --git a/src/main/java/eotree/EOMetas.java b/src/main/java/eotree/EOMetas.java deleted file mode 100644 index 7838f228..00000000 --- a/src/main/java/eotree/EOMetas.java +++ /dev/null @@ -1,31 +0,0 @@ -package eotree; - -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -/** - * EBNF representation: - * - * { meta EOL } EOL - * - */ -public class EOMetas extends EONode { - public Optional packageName; - public List metas; - - public EOMetas(Optional packageName, List metas) { - this.packageName = packageName; - this.metas = metas; - } - - @Override - public String generateEO(int indent) { - return packageName - .map(p -> "+package " + p + "\n") - .orElse("") + - metas.stream() - .map(m -> m.generateEO(indent)) - .collect(Collectors.joining("\n")); - } -} diff --git a/src/main/java/eotree/EOMetas.kt b/src/main/java/eotree/EOMetas.kt new file mode 100644 index 00000000..3dacbaa7 --- /dev/null +++ b/src/main/java/eotree/EOMetas.kt @@ -0,0 +1,23 @@ +package eotree + +import arrow.core.Option +import arrow.core.getOrElse +import arrow.core.orElse + +/** + * EBNF representation: + * ` + * { meta EOL } EOL +` * + */ +class EOMetas(var packageName: Option, var metas: List) : EONode() { + override fun generateEO(indent: Int): String = + packageName + .map { name -> "+package $name\n" } + .getOrElse { "" } + + metas + .map { m: EOMeta -> m.generateEO(indent) } + .joinToString("\n") + + override fun toString(): String = "+ [metas]" +} \ No newline at end of file diff --git a/src/main/java/eotree/EONode.java b/src/main/java/eotree/EONode.java deleted file mode 100644 index ae353e07..00000000 --- a/src/main/java/eotree/EONode.java +++ /dev/null @@ -1,11 +0,0 @@ -package eotree; - -public abstract class EONode { - public static final int INDENT_SIZE = 2; - - public static String indent(int indent) { - return " ".repeat(indent * INDENT_SIZE); - } - - public abstract String generateEO(int indent); -} diff --git a/src/main/java/eotree/EONode.kt b/src/main/java/eotree/EONode.kt new file mode 100644 index 00000000..32b154e7 --- /dev/null +++ b/src/main/java/eotree/EONode.kt @@ -0,0 +1,11 @@ +package eotree + +abstract class EONode { + private val indentSize = 2 + + abstract fun generateEO(indent: Int): String + + fun indent(indent: Int): String { + return " ".repeat(indent * indentSize) + } +} \ No newline at end of file diff --git a/src/main/java/eotree/EOObject.java b/src/main/java/eotree/EOObject.java deleted file mode 100644 index 4f16cc46..00000000 --- a/src/main/java/eotree/EOObject.java +++ /dev/null @@ -1,34 +0,0 @@ -package eotree; - -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -public class EOObject extends EOExpr { - public List freeAttrs; - public Optional varargAttr; - public List bndAttrs; - - public EOObject(List freeAttrs, - Optional varargAttr, - List bndAttrs) { - this.freeAttrs = freeAttrs; - this.varargAttr = varargAttr; - this.bndAttrs = bndAttrs; - } - - @Override - public String generateEO(int indent) { - return indent(indent) + "[" + - freeAttrs.stream() - .map(attr -> attr.generateEO(indent)) - .collect(Collectors.joining(" ")) + - (varargAttr - .map(attr -> (freeAttrs.size() > 0 ? " " : "") + attr.generateEO(indent) + "...") - .orElse("")) + - "]\n" + - bndAttrs.stream() - .map(attr -> attr.generateEO(indent + 1)) - .collect(Collectors.joining("\n")); - } -} diff --git a/src/main/java/eotree/EOObject.kt b/src/main/java/eotree/EOObject.kt new file mode 100644 index 00000000..de01dcdb --- /dev/null +++ b/src/main/java/eotree/EOObject.kt @@ -0,0 +1,36 @@ +package eotree + +import arrow.core.Option +import arrow.core.getOrElse +import java.util.* +import java.util.stream.Collectors + +class EOObject( + var freeAttrs: List, + var varargAttr: Option, + var bndAttrs: List, + var comment: String = "", +) : EOExpr() { + override fun generateEO(indent: Int): String { + return listOfNotNull( + comment.let { + if (it.isNotEmpty()) + indent(indent) + it + "\n" + else + null + }, + indent(indent), + "[", + freeAttrs.joinToString(" "), + varargAttr + .map { attr -> (if (freeAttrs.isNotEmpty()) " " else "") + attr + "..." } + .getOrElse { null }, + "]", + bndAttrs + .map { attr: EOBndExpr -> "\n" + attr.generateEO(indent + 1) } + .joinToString("") + ).joinToString("") + } + + override fun toString(): String = "[Object]" +} \ No newline at end of file diff --git a/src/main/java/eotree/EOProgram.java b/src/main/java/eotree/EOProgram.java deleted file mode 100644 index 1f874460..00000000 --- a/src/main/java/eotree/EOProgram.java +++ /dev/null @@ -1,33 +0,0 @@ -package eotree; - -import java.util.List; -import java.util.stream.Collectors; - -/** - * EBNF representation: - * - * [ license ] [ metas ] { object eol } - * - */ -public class EOProgram extends EONode { - public EOLicense license; - public EOMetas metas; - public List bnds; - - public EOProgram(EOLicense license, EOMetas metas, List bnds) { - this.license = license; - this.metas = metas; - this.bnds = bnds; - } - - @Override - public String generateEO(int indent) { - return license.generateEO(indent) + - "\n" + - metas.generateEO(indent) + - "\n" + - bnds.stream() - .map(bnd -> bnd.generateEO(indent)) - .collect(Collectors.joining("\n")) + "\n"; - } -} diff --git a/src/main/java/eotree/EOProgram.kt b/src/main/java/eotree/EOProgram.kt new file mode 100644 index 00000000..6774d715 --- /dev/null +++ b/src/main/java/eotree/EOProgram.kt @@ -0,0 +1,19 @@ +package eotree + +import java.util.stream.Collectors + +/** + * EBNF representation: + * ` + * [ license ] [ metas ] { object eol } +` * + */ +class EOProgram(var license: EOLicense, var metas: EOMetas, var bnds: List) : EONode() { + override fun generateEO(indent: Int): String = + """${license.generateEO(indent)} +${metas.generateEO(indent)} + +${bnds.joinToString("\n\n") { bnd: EOBnd -> bnd.generateEO(indent) }}""" + + override fun toString(): String = "[Program]" +} \ No newline at end of file diff --git a/src/main/java/eotree/data/EOByte.java b/src/main/java/eotree/data/EOByte.java deleted file mode 100644 index 61de9a84..00000000 --- a/src/main/java/eotree/data/EOByte.java +++ /dev/null @@ -1,22 +0,0 @@ -package eotree.data; - -import eotree.EONode; - -/** - * EBNF representation: - * - * /[\dA-F][\dA-F]/ - * - */ -public class EOByte extends EONode { - public Byte b; - - public EOByte(Byte b) { - this.b = b; - } - - @Override - public String generateEO(int indent) { - return String.format("%02x", b).toUpperCase(); - } -} diff --git a/src/main/java/eotree/data/EOByte.kt b/src/main/java/eotree/data/EOByte.kt new file mode 100644 index 00000000..16b46a33 --- /dev/null +++ b/src/main/java/eotree/data/EOByte.kt @@ -0,0 +1,16 @@ +package eotree.data + +import eotree.EONode +import java.util.* + +/** + * EBNF representation: + * ` + * /[\dA-F][\dA-F]/ +` * + */ +class EOByte(var b: Byte) : EONode() { + override fun generateEO(indent: Int): String { + return String.format("%02x", b).uppercase(Locale.getDefault()) + } +} \ No newline at end of file diff --git a/src/main/java/eotree/data/EOBytesData.java b/src/main/java/eotree/data/EOBytesData.java deleted file mode 100644 index a57759a9..00000000 --- a/src/main/java/eotree/data/EOBytesData.java +++ /dev/null @@ -1,32 +0,0 @@ -package eotree.data; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -/** - * EBNF representation: - * - * byte { '-' byte } - * - */ -public class EOBytesData extends EOData { - public EOBytesData(List bytes) { - this.bytes = bytes; - } - - public EOBytesData(EOByte... bytes) { - this(Arrays.stream(bytes).collect(Collectors.toList())); - } - - public List bytes; - - @Override - public String generateEO(int indent) { - return bytes.stream() - .map(b -> b.generateEO(indent)) - .collect(Collectors.joining("-")); - } -} diff --git a/src/main/java/eotree/data/EOBytesData.kt b/src/main/java/eotree/data/EOBytesData.kt new file mode 100644 index 00000000..72c327c3 --- /dev/null +++ b/src/main/java/eotree/data/EOBytesData.kt @@ -0,0 +1,20 @@ +package eotree.data + +import java.util.* +import java.util.stream.Collectors + +/** + * EBNF representation: + * ` + * byte { '-' byte } +` * + */ +class EOBytesData(var bytes: List) : EOData() { + constructor(vararg bytes: EOByte) : this(Arrays.stream(bytes).collect(Collectors.toList())) {} + + override fun generateEO(indent: Int): String { + return bytes.stream() + .map { b: EOByte -> b.generateEO(indent) } + .collect(Collectors.joining("-")) + } +} \ No newline at end of file diff --git a/src/main/java/eotree/data/EOCharData.java b/src/main/java/eotree/data/EOCharData.java deleted file mode 100644 index 44e9e759..00000000 --- a/src/main/java/eotree/data/EOCharData.java +++ /dev/null @@ -1,22 +0,0 @@ -package eotree.data; - -import eotree.data.EOData; - -/** - * EBNF representation: - * - * /'([^']|\\\d+)'/ - * - */ -public class EOCharData extends EOData { - public Character c; - - public EOCharData(Character c) { - this.c = c; - } - - @Override - public String generateEO(int indent) { - return "'" + c + "'"; - } -} diff --git a/src/main/java/eotree/data/EOCharData.kt b/src/main/java/eotree/data/EOCharData.kt new file mode 100644 index 00000000..9128bfc6 --- /dev/null +++ b/src/main/java/eotree/data/EOCharData.kt @@ -0,0 +1,13 @@ +package eotree.data + +/** + * EBNF representation: + * ` + * /'([^']|\\\d+)'/ +` * + */ +class EOCharData(var c: Char) : EOData() { + override fun generateEO(indent: Int): String { + return "'$c'" + } +} \ No newline at end of file diff --git a/src/main/java/eotree/data/EOData.java b/src/main/java/eotree/data/EOData.java deleted file mode 100644 index 6a5c5c54..00000000 --- a/src/main/java/eotree/data/EOData.java +++ /dev/null @@ -1,13 +0,0 @@ -package eotree.data; - -import eotree.EOExpr; - -/** - * EBNF representation: - * - * bytes | string | integer | char | float | regex - * - * - */ -public abstract class EOData extends EOExpr { -} diff --git a/src/main/java/eotree/data/EOData.kt b/src/main/java/eotree/data/EOData.kt new file mode 100644 index 00000000..819c340f --- /dev/null +++ b/src/main/java/eotree/data/EOData.kt @@ -0,0 +1,12 @@ +package eotree.data + +import eotree.EOExpr + +/** + * EBNF representation: + * ` + * bytes | string | integer | char | float | regex +` * + * + */ +abstract class EOData : EOExpr() \ No newline at end of file diff --git a/src/main/java/eotree/data/EOFloatData.java b/src/main/java/eotree/data/EOFloatData.java deleted file mode 100644 index 9228728b..00000000 --- a/src/main/java/eotree/data/EOFloatData.java +++ /dev/null @@ -1,20 +0,0 @@ -package eotree.data; - -/** - * EBNF representation: - * - * /[+-]?\d+(\.\d+)?/ - * - */ -public class EOFloatData extends EOData { - public Float f; - - public EOFloatData(Float f) { - this.f = f; - } - - @Override - public String generateEO(int indent) { - return indent(indent) + f.toString(); - } -} diff --git a/src/main/java/eotree/data/EOFloatData.kt b/src/main/java/eotree/data/EOFloatData.kt new file mode 100644 index 00000000..e0213d80 --- /dev/null +++ b/src/main/java/eotree/data/EOFloatData.kt @@ -0,0 +1,15 @@ +package eotree.data + +import eotree.EONode + +/** + * EBNF representation: + * ` + * /[+-]?\d+(\.\d+)?/ +` * + */ +class EOFloatData(var f: Float) : EOData() { + override fun generateEO(indent: Int): String { + return indent(indent) + f.toString() + } +} \ No newline at end of file diff --git a/src/main/java/eotree/data/EOIntData.java b/src/main/java/eotree/data/EOIntData.java deleted file mode 100644 index 5021f365..00000000 --- a/src/main/java/eotree/data/EOIntData.java +++ /dev/null @@ -1,20 +0,0 @@ -package eotree.data; - -/** - * EBNF representation: - * - * /[+-]?\d+|0x[a-f\d]+/ - * - */ -public class EOIntData extends EOData { - public Integer i; - - public EOIntData(Integer i) { - this.i = i; - } - - @Override - public String generateEO(int indent) { - return indent(indent) + i.toString(); - } -} diff --git a/src/main/java/eotree/data/EOIntData.kt b/src/main/java/eotree/data/EOIntData.kt new file mode 100644 index 00000000..00a92b5c --- /dev/null +++ b/src/main/java/eotree/data/EOIntData.kt @@ -0,0 +1,13 @@ +package eotree.data + +/** + * EBNF representation: + * ` + * /[+-]?\d+|0x[a-f\d]+/ +` * + */ +class EOIntData(var i: Int) : EOData() { + override fun generateEO(indent: Int): String { + return indent(indent) + i.toString() + } +} \ No newline at end of file diff --git a/src/main/java/eotree/data/EORegexData.java b/src/main/java/eotree/data/EORegexData.java deleted file mode 100644 index 6fc0b884..00000000 --- a/src/main/java/eotree/data/EORegexData.java +++ /dev/null @@ -1,20 +0,0 @@ -package eotree.data; - -/** - * EBNF representation: - * - * / /.+/[a-z]* / - * - */ -public class EORegexData extends EOData { - public String regex; - - public EORegexData(String regex) { - this.regex = regex; - } - - @Override - public String generateEO(int indent) { - return regex; - } -} diff --git a/src/main/java/eotree/data/EORegexData.kt b/src/main/java/eotree/data/EORegexData.kt new file mode 100644 index 00000000..aa17dbd0 --- /dev/null +++ b/src/main/java/eotree/data/EORegexData.kt @@ -0,0 +1,13 @@ +package eotree.data + +/** + * EBNF representation: + * ` + * / /.+/[a-z]* / +` * + */ +class EORegexData(var regex: String) : EOData() { + override fun generateEO(indent: Int): String { + return regex + } +} \ No newline at end of file diff --git a/src/main/java/eotree/data/EOStringData.java b/src/main/java/eotree/data/EOStringData.java deleted file mode 100644 index 5d8fc919..00000000 --- a/src/main/java/eotree/data/EOStringData.java +++ /dev/null @@ -1,20 +0,0 @@ -package eotree.data; - -/** - * EBNF representation: - * - * /"[^"]*"/ - * - */ -public class EOStringData extends EOData { - public String str; - - public EOStringData(String str) { - this.str = str; - } - - @Override - public String generateEO(int indent) { - return indent(indent) + "\"" + str + "\""; - } -} diff --git a/src/main/java/eotree/data/EOStringData.kt b/src/main/java/eotree/data/EOStringData.kt new file mode 100644 index 00000000..df875988 --- /dev/null +++ b/src/main/java/eotree/data/EOStringData.kt @@ -0,0 +1,15 @@ +package eotree.data + +import eotree.EONode + +/** + * EBNF representation: + * ` + * /"[^"]*"/ +` * + */ +class EOStringData(var str: String) : EOData() { + override fun generateEO(indent: Int): String { + return indent(indent) + "\"" + str + "\"" + } +} \ No newline at end of file diff --git a/src/main/java/lexer/Scanner.java b/src/main/java/lexer/Scanner.java index 74dfa128..2ee36673 100644 --- a/src/main/java/lexer/Scanner.java +++ b/src/main/java/lexer/Scanner.java @@ -1,6 +1,7 @@ package lexer; import parser.JavaParser; +import tree.Entity; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -20,6 +21,7 @@ public boolean readFile(String path) sourcePath = path; try { String text = new String(Files.readAllBytes(Paths.get(path)), StandardCharsets.UTF_8); + text = text.replace("\r\n","\n").replace("\r","n"); sourceText = text.toCharArray(); //.getChars(StandardCharsets.UTF_8); return true; } @@ -59,10 +61,15 @@ private void forgetChar() public int yylex() { - lastToken = getToken(); - - //System.out.println(lastToken.code); + lastToken = get(); + if ( Entity.debug ) + { + System.out.print(lastToken.code); + if ( lastToken.code == TokenCode.Identifier ) + System.out.print(" "+lastToken.image); + System.out.println(); + } return lastToken.code.value(); } @@ -84,8 +91,20 @@ public void yyerror(String msg) { private Token currentToken; public Token get() { - if ( currentToken == null ) currentToken = getToken(); - return currentToken; +// if ( currentToken == null ) currentToken = getToken(); + + while ( true ) + { + currentToken = getToken(); + switch ( currentToken.code ) + { + case ShortComment: + case LongComment: + continue; + default: + return currentToken; + } + } } public void forget() { @@ -99,6 +118,12 @@ private Token getToken() String image; Token token; + // if ( Entity.inBlock && Entity.unAnnotatedTypeTaken ) + // { + // Entity.unAnnotatedTypeTaken = false; + // return new Token(TokenCode.Phantom,""); + // } + while ( true ) { ch = getChar(); @@ -283,7 +308,7 @@ private Token getToken() { forgetChar(); ch = getChar(); if ( Character.isJavaIdentifierPart(ch) ) - identifier = identifier.concat(""+ch); + identifier += ch; else { // forgetChar(); break; @@ -301,7 +326,7 @@ else if ( Character.isDigit(ch) ) if ( Character.isDigit(ch) ) literal = literal.concat(""+ch); else { - forgetChar(); + // forgetChar(); break; } } @@ -336,12 +361,40 @@ else if ( Character.isDigit(ch) ) private String scanShortComment() { - return ""; + String comment = ""; + while ( true ) + { + char ch = getChar(); + forgetChar(); + if ( ch == '\n' ) break; + comment += ch; + } + return comment; } private String scanLongComment() { - return ""; + String comment = ""; + while (true ) + { + char ch = getChar(); + forgetChar(); + if ( ch == '*' ) + { + forgetChar(); + ch = getChar(); + if ( ch == '/' ) + { + forgetChar(); + break; + } + else + comment += "*" + ch; + } + else + comment += ch; + } + return comment; } private TokenCode detectKeyword(String identifier) diff --git a/src/main/java/lexer/Span.java b/src/main/java/lexer/Span.java index 90d479a3..c53807b4 100644 --- a/src/main/java/lexer/Span.java +++ b/src/main/java/lexer/Span.java @@ -36,4 +36,9 @@ public void report() end.report(); System.out.print(")"); } + + @Override + public String toString() { + return "Line " + begin.line + ", Char " + begin.pos; + } } diff --git a/src/main/java/lexer/TokenCode.java b/src/main/java/lexer/TokenCode.java index c96b3ee8..73c09708 100644 --- a/src/main/java/lexer/TokenCode.java +++ b/src/main/java/lexer/TokenCode.java @@ -9,6 +9,8 @@ public enum TokenCode ShortComment (Lexer.SHORT_COMMENT), LongComment (Lexer.LONG_COMMENT), +// Phantom (Lexer.PHANTOM), + Identifier (Lexer.IDENTIFIER), IntegerLiteral (Lexer.INTEGER_LITERAL), FloatingLiteral(Lexer.FLOATING_POINT_LITERAL), diff --git a/src/main/java/main/Main.java b/src/main/java/main/Main.java index 54ea815c..6b8d725d 100644 --- a/src/main/java/main/Main.java +++ b/src/main/java/main/Main.java @@ -1,18 +1,18 @@ package main; -import lexer.Scanner; +import lexer.*; import org.apache.commons.cli.*; -import parser.JavaParser; -import translator.Translator; +import parser.*; +import tree.Entity; import java.io.File; import java.io.FileNotFoundException; -import java.io.IOException; import java.io.PrintWriter; -import java.nio.charset.StandardCharsets; + +import static translator.TranslatorKt.translate; public class Main { - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws FileNotFoundException { // Setup command line argument parser Options options = new Options(); @@ -20,6 +20,14 @@ public static void main(String[] args) throws IOException { output.setRequired(false); options.addOption(output); + Option debug = new Option("d","debug",false,"Debug mode"); + debug.setRequired(false); + options.addOption(debug); + + Option syntaxOnly = new Option("s","syntax",false,"Syntax only"); + syntaxOnly.setRequired(false); + options.addOption(syntaxOnly); + CommandLineParser cmdLineParser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd = null; @@ -28,7 +36,7 @@ public static void main(String[] args) throws IOException { try { cmd = cmdLineParser.parse(options, args); } catch (ParseException e) { - e.printStackTrace(); + System.out.println(e.getMessage()); printUsage(formatter, options); System.exit(1); } @@ -40,31 +48,26 @@ public static void main(String[] args) throws IOException { } boolean outputToFile = cmd.hasOption("o"); + Entity.syntaxOnly = cmd.hasOption("s"); + Entity.debug = cmd.hasOption("d"); // Check if source file exists String inputFilepath = cmd.getArgList().get(0); var f = new File(inputFilepath); - if (!inputFilepath.equals("-") && !f.exists()) + if (!f.exists()) throw new FileNotFoundException("No file found at \"" + inputFilepath + "\""); - // Read, parse, map and print file Scanner scanner = new Scanner(); - if (inputFilepath.equals("-")) { - // Handle stdin case - var src = new String(System.in.readAllBytes(), StandardCharsets.UTF_8); - scanner.read(src); - } else { - // Handle file case - scanner.readFile(inputFilepath); - } - JavaParser parser = new JavaParser(scanner); + scanner.readFile(inputFilepath); + JavaParser parser = new JavaParser(scanner); try { boolean result = parser.parse(); - System.out.println(result ? "SUCCESS" : "FAIL"); + System.out.println("Parsing completed: "+(result ? "SUCCESS" : "FAIL")); if (parser.ast != null) { - //parser.ast.report(0); - var eoProgram = Translator.translate(parser.ast); + if ( Entity.debug ) parser.ast.report(0); + if ( Entity.syntaxOnly ) return; + var eoProgram = translate(parser.ast); var targetText = eoProgram.generateEO(0); // Print generated code to stdout or to file, if any specified @@ -86,6 +89,6 @@ public static void main(String[] args) throws IOException { } private static void printUsage(HelpFormatter formatter, Options options) { - formatter.printHelp("java -jar J2EO.jar [OPTIONS...] ", options); + formatter.printHelp("java -jar J2EO.jar [OPTIONS...] ", options); } } diff --git a/src/main/java/parser/JavaParser.java b/src/main/java/parser/JavaParser.java deleted file mode 100644 index a5e5d5a0..00000000 --- a/src/main/java/parser/JavaParser.java +++ /dev/null @@ -1,6023 +0,0 @@ -/* A Bison parser, made by GNU Bison 3.7.4. */ - -/* Skeleton implementation for Bison LALR(1) parsers in Java - - Copyright (C) 2007-2015, 2018-2020 Free Software Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -/* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work - under terms of your choice, so long as that work isn't itself a - parser generator using the skeleton or a modified version thereof - as a parser skeleton. Alternatively, if you modify or redistribute - the parser skeleton itself, you may (at your option) remove this - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. - - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, - especially those whose name start with YY_ or yy_. They are - private implementation details that can be changed or removed. */ - -package parser; - - - -import java.text.MessageFormat; -/* "%code imports" blocks. */ -/* "src/main/resources/Java_16_Grammar.y":138 */ - import lexer.*; -/* "src/main/resources/Java_16_Grammar.y":139 */ - import tree.*; -/* "src/main/resources/Java_16_Grammar.y":140 */ - import tree.Compilation.*; -/* "src/main/resources/Java_16_Grammar.y":141 */ - import tree.Declaration.*; -/* "src/main/resources/Java_16_Grammar.y":142 */ - import tree.Expression.*; -/* "src/main/resources/Java_16_Grammar.y":143 */ - import tree.Expression.Primary.*; -/* "src/main/resources/Java_16_Grammar.y":144 */ - import tree.Statement.*; -/* "src/main/resources/Java_16_Grammar.y":145 */ - import tree.Type.*; -/* "src/main/resources/Java_16_Grammar.y":146 */ - @SuppressWarnings("PMD") - -/* "src/main/java/parser/JavaParser.java":63 */ - -/** - * A Bison parser, automatically generated from src/main/resources/Java_16_Grammar.y. - * - * @author LALR (1) parser skeleton written by Paolo Bonzini. - */ -public class JavaParser -{ - /** Version number for the Bison executable that generated this parser. */ - public static final String bisonVersion = "3.7.4"; - - /** Name of the skeleton that generated this parser. */ - public static final String bisonSkeleton = "lalr1.java"; - - - - /** - * True if verbose error messages are enabled. - */ - private boolean yyErrorVerbose = true; - - /** - * Whether verbose error messages are enabled. - */ - public final boolean getErrorVerbose() { return yyErrorVerbose; } - - /** - * Set the verbosity of error messages. - * @param verbose True to request verbose error messages. - */ - public final void setErrorVerbose(boolean verbose) - { yyErrorVerbose = verbose; } - - - - - public enum SymbolKind - { - S_YYEOF(0), /* "end of file" */ - S_YYerror(1), /* error */ - S_YYUNDEF(2), /* "invalid token" */ - S_LPAREN(3), /* LPAREN */ - S_RPAREN(4), /* RPAREN */ - S_LBRACE(5), /* LBRACE */ - S_RBRACE(6), /* RBRACE */ - S_LBRACKET(7), /* LBRACKET */ - S_RBRACKET(8), /* RBRACKET */ - S_COMMA(9), /* COMMA */ - S_DOT(10), /* DOT */ - S_SEMICOLON(11), /* SEMICOLON */ - S_COLON(12), /* COLON */ - S_DBL_COLON(13), /* DBL_COLON */ - S_STAR(14), /* STAR */ - S_SLASH(15), /* SLASH */ - S_PERCENT(16), /* PERCENT */ - S_AMPERSAND(17), /* AMPERSAND */ - S_AT(18), /* AT */ - S_LESS(19), /* LESS */ - S_GREATER(20), /* GREATER */ - S_VERTICAL(21), /* VERTICAL */ - S_PLUS(22), /* PLUS */ - S_MINUS(23), /* MINUS */ - S_ARROW(24), /* ARROW */ - S_DIAMOND(25), /* DIAMOND */ - S_QUESTION(26), /* QUESTION */ - S_CARET(27), /* CARET */ - S_EQUAL(28), /* EQUAL */ - S_TILDE(29), /* TILDE */ - S_EXCLAMATION(30), /* EXCLAMATION */ - S_ELLIPSIS(31), /* ELLIPSIS */ - S_LESS_EQUAL(32), /* LESS_EQUAL */ - S_GREATER_EQUAL(33), /* GREATER_EQUAL */ - S_STAR_EQUAL(34), /* STAR_EQUAL */ - S_SLASH_EQUAL(35), /* SLASH_EQUAL */ - S_PERCENT_EQUAL(36), /* PERCENT_EQUAL */ - S_PLUS_EQUAL(37), /* PLUS_EQUAL */ - S_MINUS_EQUAL(38), /* MINUS_EQUAL */ - S_LESS_LESS_EQUAL(39), /* LESS_LESS_EQUAL */ - S_GR_GR_EQUAL(40), /* GR_GR_EQUAL */ - S_GR_GR_GR_EQUAL(41), /* GR_GR_GR_EQUAL */ - S_AMP_EQUAL(42), /* AMP_EQUAL */ - S_CARET_EQUAL(43), /* CARET_EQUAL */ - S_VERTICAL_EQUAL(44), /* VERTICAL_EQUAL */ - S_DBL_PLUS(45), /* DBL_PLUS */ - S_DBL_MINUS(46), /* DBL_MINUS */ - S_DBL_VERTICAL(47), /* DBL_VERTICAL */ - S_DBL_AMPERSAND(48), /* DBL_AMPERSAND */ - S_DBL_EQUAL(49), /* DBL_EQUAL */ - S_TRIPL_EQUAL(50), /* TRIPL_EQUAL */ - S_NON_EQUAL(51), /* NON_EQUAL */ - S_DBL_LESS(52), /* DBL_LESS */ - S_DBL_GREATER(53), /* DBL_GREATER */ - S_TRIPL_GREATER(54), /* TRIPL_GREATER */ - S_IDENTIFIER(55), /* IDENTIFIER */ - S_INTEGER_LITERAL(56), /* INTEGER_LITERAL */ - S_FLOATING_POINT_LITERAL(57), /* FLOATING_POINT_LITERAL */ - S_CHARACTER_LITERAL(58), /* CHARACTER_LITERAL */ - S_STRING_LITERAL(59), /* STRING_LITERAL */ - S_ABSTRACT(60), /* ABSTRACT */ - S_ASSERT(61), /* ASSERT */ - S_BOOLEAN(62), /* BOOLEAN */ - S_BREAK(63), /* BREAK */ - S_BYTE(64), /* BYTE */ - S_CASE(65), /* CASE */ - S_CATCH(66), /* CATCH */ - S_CHAR(67), /* CHAR */ - S_CLASS(68), /* CLASS */ - S_CONTINUE(69), /* CONTINUE */ - S_DEFAULT(70), /* DEFAULT */ - S_DO(71), /* DO */ - S_DOUBLE(72), /* DOUBLE */ - S_ELSE(73), /* ELSE */ - S_ENUM(74), /* ENUM */ - S_EXTENDS(75), /* EXTENDS */ - S_FALSE(76), /* FALSE */ - S_FINAL(77), /* FINAL */ - S_FINALLY(78), /* FINALLY */ - S_FLOAT(79), /* FLOAT */ - S_FOR(80), /* FOR */ - S_IF(81), /* IF */ - S_IMPLEMENTS(82), /* IMPLEMENTS */ - S_IMPORT(83), /* IMPORT */ - S_INSTANCEOF(84), /* INSTANCEOF */ - S_INT(85), /* INT */ - S_INTERFACE(86), /* INTERFACE */ - S_LONG(87), /* LONG */ - S_MODULE(88), /* MODULE */ - S_NATIVE(89), /* NATIVE */ - S_NEW(90), /* NEW */ - S_NULL(91), /* NULL */ - S_OPEN(92), /* OPEN */ - S_PACKAGE(93), /* PACKAGE */ - S_PRIVATE(94), /* PRIVATE */ - S_PROTECTED(95), /* PROTECTED */ - S_PUBLIC(96), /* PUBLIC */ - S_RECORD(97), /* RECORD */ - S_RETURN(98), /* RETURN */ - S_SHORT(99), /* SHORT */ - S_STATIC(100), /* STATIC */ - S_STRICTFP(101), /* STRICTFP */ - S_SUPER(102), /* SUPER */ - S_SWITCH(103), /* SWITCH */ - S_SYNCHRONIZED(104), /* SYNCHRONIZED */ - S_THIS(105), /* THIS */ - S_THROW(106), /* THROW */ - S_THROWS(107), /* THROWS */ - S_TRANSIENT(108), /* TRANSIENT */ - S_TRANSITIVE(109), /* TRANSITIVE */ - S_TRUE(110), /* TRUE */ - S_TRY(111), /* TRY */ - S_VAR(112), /* VAR */ - S_VOID(113), /* VOID */ - S_VOLATILE(114), /* VOLATILE */ - S_WHILE(115), /* WHILE */ - S_YIELD(116), /* YIELD */ - S_SHORT_COMMENT(117), /* SHORT_COMMENT */ - S_LONG_COMMENT(118), /* LONG_COMMENT */ - S_EOS(119), /* EOS */ - S_120_requires_(120), /* "requires" */ - S_121_exports_(121), /* "exports" */ - S_122_to_(122), /* "to" */ - S_123_opens_(123), /* "opens" */ - S_124_uses_(124), /* "uses" */ - S_125_provides_(125), /* "provides" */ - S_126_with_(126), /* "with" */ - S_YYACCEPT(127), /* $accept */ - S_Literal(128), /* Literal */ - S_CompoundName(129), /* CompoundName */ - S_ModifierSeqOpt(130), /* ModifierSeqOpt */ - S_ModifierSeq(131), /* ModifierSeq */ - S_StandardModifierSeq(132), /* StandardModifierSeq */ - S_StandardModifier(133), /* StandardModifier */ - S_CompilationUnit(134), /* CompilationUnit */ - S_Package(135), /* Package */ - S_Module(136), /* Module */ - S_ImportDeclarationSeqOpt(137), /* ImportDeclarationSeqOpt */ - S_ImportDeclarationSeq(138), /* ImportDeclarationSeq */ - S_ImportDeclaration(139), /* ImportDeclaration */ - S_TopLevelComponentSeqOpt(140), /* TopLevelComponentSeqOpt */ - S_TopLevelComponentSeq(141), /* TopLevelComponentSeq */ - S_TopLevelComponent(142), /* TopLevelComponent */ - S_ModuleDirectiveSeqOpt(143), /* ModuleDirectiveSeqOpt */ - S_ModuleDirectiveSeq(144), /* ModuleDirectiveSeq */ - S_ModuleDirective(145), /* ModuleDirective */ - S_ModuleNameList(146), /* ModuleNameList */ - S_RequiresModifierSeqOpt(147), /* RequiresModifierSeqOpt */ - S_Type(148), /* Type */ - S_UnannotatedType(149), /* UnannotatedType */ - S_PrimitiveType(150), /* PrimitiveType */ - S_ClassDeclaration(151), /* ClassDeclaration */ - S_NormalClassDeclaration(152), /* NormalClassDeclaration */ - S_TypeParametersOpt(153), /* TypeParametersOpt */ - S_TypeParameters(154), /* TypeParameters */ - S_TypeParameterList(155), /* TypeParameterList */ - S_TypeParameter(156), /* TypeParameter */ - S_TypeParameterTail(157), /* TypeParameterTail */ - S_ClassExtendsOpt(158), /* ClassExtendsOpt */ - S_ClassImplementsOpt(159), /* ClassImplementsOpt */ - S_ClassTypeList1(160), /* ClassTypeList1 */ - S_ClassTypeList2(161), /* ClassTypeList2 */ - S_ClassBodyOpt(162), /* ClassBodyOpt */ - S_ClassBody(163), /* ClassBody */ - S_ClassBodyDeclarationSeq(164), /* ClassBodyDeclarationSeq */ - S_ClassBodyDeclaration(165), /* ClassBodyDeclaration */ - S_PureBodyDeclaration(166), /* PureBodyDeclaration */ - S_ConstructorDeclaration(167), /* ConstructorDeclaration */ - S_ConstructorDeclarator(168), /* ConstructorDeclarator */ - S_ConstructorBody(169), /* ConstructorBody */ - S_ExplicitConstructorInvocation(170), /* ExplicitConstructorInvocation */ - S_EnumDeclaration(171), /* EnumDeclaration */ - S_EnumBody(172), /* EnumBody */ - S_EnumConstantListOpt(173), /* EnumConstantListOpt */ - S_EnumConstant(174), /* EnumConstant */ - S_EnumBodyDeclarationsOpt(175), /* EnumBodyDeclarationsOpt */ - S_RecordDeclaration(176), /* RecordDeclaration */ - S_RecordHeader(177), /* RecordHeader */ - S_RecordComponentListOpt(178), /* RecordComponentListOpt */ - S_RecordComponent(179), /* RecordComponent */ - S_RecordBody(180), /* RecordBody */ - S_RecordBodyDeclarationSeq(181), /* RecordBodyDeclarationSeq */ - S_RecordBodyDeclaration(182), /* RecordBodyDeclaration */ - S_FieldDeclaration(183), /* FieldDeclaration */ - S_VariableDeclaratorList(184), /* VariableDeclaratorList */ - S_VariableDeclarator(185), /* VariableDeclarator */ - S_ArrayInitializer(186), /* ArrayInitializer */ - S_VariableInitializerListOpt(187), /* VariableInitializerListOpt */ - S_VariableInitializerList(188), /* VariableInitializerList */ - S_VariableInitializer(189), /* VariableInitializer */ - S_MethodDeclaration(190), /* MethodDeclaration */ - S_MethodHeader(191), /* MethodHeader */ - S_MethodDeclarator(192), /* MethodDeclarator */ - S_FormalParameterList(193), /* FormalParameterList */ - S_FormalParameter(194), /* FormalParameter */ - S_FormalParameterTail(195), /* FormalParameterTail */ - S_ThrowsOpt(196), /* ThrowsOpt */ - S_MethodBody(197), /* MethodBody */ - S_DimsOpt(198), /* DimsOpt */ - S_Dims(199), /* Dims */ - S_Dim(200), /* Dim */ - S_InterfaceDeclaration(201), /* InterfaceDeclaration */ - S_NormalInterfaceDeclaration(202), /* NormalInterfaceDeclaration */ - S_InterfaceExtendsOpt(203), /* InterfaceExtendsOpt */ - S_InterfaceExtends(204), /* InterfaceExtends */ - S_InterfaceBody(205), /* InterfaceBody */ - S_InterfaceMemberDeclarationSeq(206), /* InterfaceMemberDeclarationSeq */ - S_InterfaceMemberDeclaration(207), /* InterfaceMemberDeclaration */ - S_ConstantDeclaration(208), /* ConstantDeclaration */ - S_InterfaceMethodDeclaration(209), /* InterfaceMethodDeclaration */ - S_AnnotationInterfaceDeclaration(210), /* AnnotationInterfaceDeclaration */ - S_AnnotationInterfaceBody(211), /* AnnotationInterfaceBody */ - S_AnnotationInterfaceMemberDeclarationSeq(212), /* AnnotationInterfaceMemberDeclarationSeq */ - S_AnnotationInterfaceMemberDeclaration(213), /* AnnotationInterfaceMemberDeclaration */ - S_AnnotationInterfaceElementDeclaration(214), /* AnnotationInterfaceElementDeclaration */ - S_DefaultValueOpt(215), /* DefaultValueOpt */ - S_Block(216), /* Block */ - S_BlockStatementSeq(217), /* BlockStatementSeq */ - S_BlockStatement(218), /* BlockStatement */ - S_BlockDeclaration(219), /* BlockDeclaration */ - S_LocalVariableDeclaration(220), /* LocalVariableDeclaration */ - S_Statement(221), /* Statement */ - S_SimpleStatement(222), /* SimpleStatement */ - S_LabeledStatement(223), /* LabeledStatement */ - S_StatementExpression(224), /* StatementExpression */ - S_IfThenElseStatement(225), /* IfThenElseStatement */ - S_ElsePartOpt(226), /* ElsePartOpt */ - S_SwitchBlock(227), /* SwitchBlock */ - S_SwitchRuleSeq(228), /* SwitchRuleSeq */ - S_SwitchRule(229), /* SwitchRule */ - S_SwitchBlockStatementGroupSeqOpt(230), /* SwitchBlockStatementGroupSeqOpt */ - S_SwitchBlockStatementGroup(231), /* SwitchBlockStatementGroup */ - S_SwitchLabelSeq(232), /* SwitchLabelSeq */ - S_SwitchLabel(233), /* SwitchLabel */ - S_CaseExpressionList(234), /* CaseExpressionList */ - S_WhileStatement(235), /* WhileStatement */ - S_ForStatement(236), /* ForStatement */ - S_BasicForStatement(237), /* BasicForStatement */ - S_ForInitOpt(238), /* ForInitOpt */ - S_ExpressionOpt(239), /* ExpressionOpt */ - S_StatementExpressionList(240), /* StatementExpressionList */ - S_StatementExpressionListOpt(241), /* StatementExpressionListOpt */ - S_EnhancedForStatement(242), /* EnhancedForStatement */ - S_CatchesOpt(243), /* CatchesOpt */ - S_Catches(244), /* Catches */ - S_CatchClause(245), /* CatchClause */ - S_CatchFormalParameter(246), /* CatchFormalParameter */ - S_CatchType(247), /* CatchType */ - S_FinallyOpt(248), /* FinallyOpt */ - S_Finally(249), /* Finally */ - S_ResourceSpecification(250), /* ResourceSpecification */ - S_ResourceSeq(251), /* ResourceSeq */ - S_Resource(252), /* Resource */ - S_Pattern(253), /* Pattern */ - S_Primary(254), /* Primary */ - S_ClassInstanceCreationExpression(255), /* ClassInstanceCreationExpression */ - S_UnqualifiedClassInstanceCreationExpression(256), /* UnqualifiedClassInstanceCreationExpression */ - S_ClassOrInterfaceTypeToInstantiate(257), /* ClassOrInterfaceTypeToInstantiate */ - S_AnnotatedCompoundName(258), /* AnnotatedCompoundName */ - S_TypeArgumentsOpt(259), /* TypeArgumentsOpt */ - S_TypeArguments(260), /* TypeArguments */ - S_TypeArgumentList(261), /* TypeArgumentList */ - S_TypeArgument(262), /* TypeArgument */ - S_FieldAccess(263), /* FieldAccess */ - S_ArrayAccess(264), /* ArrayAccess */ - S_MethodInvocation(265), /* MethodInvocation */ - S_Arguments(266), /* Arguments */ - S_ArgumentList(267), /* ArgumentList */ - S_MethodReference(268), /* MethodReference */ - S_ArrayCreationExpression(269), /* ArrayCreationExpression */ - S_DimExprs(270), /* DimExprs */ - S_DimExpr(271), /* DimExpr */ - S_Expression(272), /* Expression */ - S_LambdaExpression(273), /* LambdaExpression */ - S_LambdaParameters(274), /* LambdaParameters */ - S_LambdaParameterList1(275), /* LambdaParameterList1 */ - S_LambdaParameterList2(276), /* LambdaParameterList2 */ - S_LambdaParameter(277), /* LambdaParameter */ - S_AssignmentExpression(278), /* AssignmentExpression */ - S_Assignment(279), /* Assignment */ - S_LeftHandSide(280), /* LeftHandSide */ - S_AssignmentOperator(281), /* AssignmentOperator */ - S_ConditionalExpression(282), /* ConditionalExpression */ - S_ConditionalOrTail(283), /* ConditionalOrTail */ - S_ConditionalOrExpression(284), /* ConditionalOrExpression */ - S_ConditionalAndExpression(285), /* ConditionalAndExpression */ - S_InclusiveOrExpression(286), /* InclusiveOrExpression */ - S_ExclusiveOrExpression(287), /* ExclusiveOrExpression */ - S_AndExpression(288), /* AndExpression */ - S_EqualityExpression(289), /* EqualityExpression */ - S_RelationalExpression(290), /* RelationalExpression */ - S_InstanceofExpression(291), /* InstanceofExpression */ - S_ShiftExpression(292), /* ShiftExpression */ - S_AdditiveExpression(293), /* AdditiveExpression */ - S_MultiplicativeExpression(294), /* MultiplicativeExpression */ - S_UnaryExpression(295), /* UnaryExpression */ - S_PreIncrementExpression(296), /* PreIncrementExpression */ - S_PreDecrementExpression(297), /* PreDecrementExpression */ - S_UnaryExpressionNotPlusMinus(298), /* UnaryExpressionNotPlusMinus */ - S_PostfixExpression(299), /* PostfixExpression */ - S_PostIncrementExpression(300), /* PostIncrementExpression */ - S_PostDecrementExpression(301), /* PostDecrementExpression */ - S_CastExpression(302), /* CastExpression */ - S_TargetType(303), /* TargetType */ - S_TypeList(304), /* TypeList */ - S_SwitchExpression(305), /* SwitchExpression */ - S_AnnotationSeqOpt(306), /* AnnotationSeqOpt */ - S_AnnotationSeq(307), /* AnnotationSeq */ - S_Annotation(308), /* Annotation */ - S_AnnoParameterList(309), /* AnnoParameterList */ - S_ElementValue(310), /* ElementValue */ - S_ElementValueListOpt(311); /* ElementValueListOpt */ - - - private final int yycode_; - - SymbolKind (int n) { - this.yycode_ = n; - } - - private static final SymbolKind[] values_ = { - SymbolKind.S_YYEOF, - SymbolKind.S_YYerror, - SymbolKind.S_YYUNDEF, - SymbolKind.S_LPAREN, - SymbolKind.S_RPAREN, - SymbolKind.S_LBRACE, - SymbolKind.S_RBRACE, - SymbolKind.S_LBRACKET, - SymbolKind.S_RBRACKET, - SymbolKind.S_COMMA, - SymbolKind.S_DOT, - SymbolKind.S_SEMICOLON, - SymbolKind.S_COLON, - SymbolKind.S_DBL_COLON, - SymbolKind.S_STAR, - SymbolKind.S_SLASH, - SymbolKind.S_PERCENT, - SymbolKind.S_AMPERSAND, - SymbolKind.S_AT, - SymbolKind.S_LESS, - SymbolKind.S_GREATER, - SymbolKind.S_VERTICAL, - SymbolKind.S_PLUS, - SymbolKind.S_MINUS, - SymbolKind.S_ARROW, - SymbolKind.S_DIAMOND, - SymbolKind.S_QUESTION, - SymbolKind.S_CARET, - SymbolKind.S_EQUAL, - SymbolKind.S_TILDE, - SymbolKind.S_EXCLAMATION, - SymbolKind.S_ELLIPSIS, - SymbolKind.S_LESS_EQUAL, - SymbolKind.S_GREATER_EQUAL, - SymbolKind.S_STAR_EQUAL, - SymbolKind.S_SLASH_EQUAL, - SymbolKind.S_PERCENT_EQUAL, - SymbolKind.S_PLUS_EQUAL, - SymbolKind.S_MINUS_EQUAL, - SymbolKind.S_LESS_LESS_EQUAL, - SymbolKind.S_GR_GR_EQUAL, - SymbolKind.S_GR_GR_GR_EQUAL, - SymbolKind.S_AMP_EQUAL, - SymbolKind.S_CARET_EQUAL, - SymbolKind.S_VERTICAL_EQUAL, - SymbolKind.S_DBL_PLUS, - SymbolKind.S_DBL_MINUS, - SymbolKind.S_DBL_VERTICAL, - SymbolKind.S_DBL_AMPERSAND, - SymbolKind.S_DBL_EQUAL, - SymbolKind.S_TRIPL_EQUAL, - SymbolKind.S_NON_EQUAL, - SymbolKind.S_DBL_LESS, - SymbolKind.S_DBL_GREATER, - SymbolKind.S_TRIPL_GREATER, - SymbolKind.S_IDENTIFIER, - SymbolKind.S_INTEGER_LITERAL, - SymbolKind.S_FLOATING_POINT_LITERAL, - SymbolKind.S_CHARACTER_LITERAL, - SymbolKind.S_STRING_LITERAL, - SymbolKind.S_ABSTRACT, - SymbolKind.S_ASSERT, - SymbolKind.S_BOOLEAN, - SymbolKind.S_BREAK, - SymbolKind.S_BYTE, - SymbolKind.S_CASE, - SymbolKind.S_CATCH, - SymbolKind.S_CHAR, - SymbolKind.S_CLASS, - SymbolKind.S_CONTINUE, - SymbolKind.S_DEFAULT, - SymbolKind.S_DO, - SymbolKind.S_DOUBLE, - SymbolKind.S_ELSE, - SymbolKind.S_ENUM, - SymbolKind.S_EXTENDS, - SymbolKind.S_FALSE, - SymbolKind.S_FINAL, - SymbolKind.S_FINALLY, - SymbolKind.S_FLOAT, - SymbolKind.S_FOR, - SymbolKind.S_IF, - SymbolKind.S_IMPLEMENTS, - SymbolKind.S_IMPORT, - SymbolKind.S_INSTANCEOF, - SymbolKind.S_INT, - SymbolKind.S_INTERFACE, - SymbolKind.S_LONG, - SymbolKind.S_MODULE, - SymbolKind.S_NATIVE, - SymbolKind.S_NEW, - SymbolKind.S_NULL, - SymbolKind.S_OPEN, - SymbolKind.S_PACKAGE, - SymbolKind.S_PRIVATE, - SymbolKind.S_PROTECTED, - SymbolKind.S_PUBLIC, - SymbolKind.S_RECORD, - SymbolKind.S_RETURN, - SymbolKind.S_SHORT, - SymbolKind.S_STATIC, - SymbolKind.S_STRICTFP, - SymbolKind.S_SUPER, - SymbolKind.S_SWITCH, - SymbolKind.S_SYNCHRONIZED, - SymbolKind.S_THIS, - SymbolKind.S_THROW, - SymbolKind.S_THROWS, - SymbolKind.S_TRANSIENT, - SymbolKind.S_TRANSITIVE, - SymbolKind.S_TRUE, - SymbolKind.S_TRY, - SymbolKind.S_VAR, - SymbolKind.S_VOID, - SymbolKind.S_VOLATILE, - SymbolKind.S_WHILE, - SymbolKind.S_YIELD, - SymbolKind.S_SHORT_COMMENT, - SymbolKind.S_LONG_COMMENT, - SymbolKind.S_EOS, - SymbolKind.S_120_requires_, - SymbolKind.S_121_exports_, - SymbolKind.S_122_to_, - SymbolKind.S_123_opens_, - SymbolKind.S_124_uses_, - SymbolKind.S_125_provides_, - SymbolKind.S_126_with_, - SymbolKind.S_YYACCEPT, - SymbolKind.S_Literal, - SymbolKind.S_CompoundName, - SymbolKind.S_ModifierSeqOpt, - SymbolKind.S_ModifierSeq, - SymbolKind.S_StandardModifierSeq, - SymbolKind.S_StandardModifier, - SymbolKind.S_CompilationUnit, - SymbolKind.S_Package, - SymbolKind.S_Module, - SymbolKind.S_ImportDeclarationSeqOpt, - SymbolKind.S_ImportDeclarationSeq, - SymbolKind.S_ImportDeclaration, - SymbolKind.S_TopLevelComponentSeqOpt, - SymbolKind.S_TopLevelComponentSeq, - SymbolKind.S_TopLevelComponent, - SymbolKind.S_ModuleDirectiveSeqOpt, - SymbolKind.S_ModuleDirectiveSeq, - SymbolKind.S_ModuleDirective, - SymbolKind.S_ModuleNameList, - SymbolKind.S_RequiresModifierSeqOpt, - SymbolKind.S_Type, - SymbolKind.S_UnannotatedType, - SymbolKind.S_PrimitiveType, - SymbolKind.S_ClassDeclaration, - SymbolKind.S_NormalClassDeclaration, - SymbolKind.S_TypeParametersOpt, - SymbolKind.S_TypeParameters, - SymbolKind.S_TypeParameterList, - SymbolKind.S_TypeParameter, - SymbolKind.S_TypeParameterTail, - SymbolKind.S_ClassExtendsOpt, - SymbolKind.S_ClassImplementsOpt, - SymbolKind.S_ClassTypeList1, - SymbolKind.S_ClassTypeList2, - SymbolKind.S_ClassBodyOpt, - SymbolKind.S_ClassBody, - SymbolKind.S_ClassBodyDeclarationSeq, - SymbolKind.S_ClassBodyDeclaration, - SymbolKind.S_PureBodyDeclaration, - SymbolKind.S_ConstructorDeclaration, - SymbolKind.S_ConstructorDeclarator, - SymbolKind.S_ConstructorBody, - SymbolKind.S_ExplicitConstructorInvocation, - SymbolKind.S_EnumDeclaration, - SymbolKind.S_EnumBody, - SymbolKind.S_EnumConstantListOpt, - SymbolKind.S_EnumConstant, - SymbolKind.S_EnumBodyDeclarationsOpt, - SymbolKind.S_RecordDeclaration, - SymbolKind.S_RecordHeader, - SymbolKind.S_RecordComponentListOpt, - SymbolKind.S_RecordComponent, - SymbolKind.S_RecordBody, - SymbolKind.S_RecordBodyDeclarationSeq, - SymbolKind.S_RecordBodyDeclaration, - SymbolKind.S_FieldDeclaration, - SymbolKind.S_VariableDeclaratorList, - SymbolKind.S_VariableDeclarator, - SymbolKind.S_ArrayInitializer, - SymbolKind.S_VariableInitializerListOpt, - SymbolKind.S_VariableInitializerList, - SymbolKind.S_VariableInitializer, - SymbolKind.S_MethodDeclaration, - SymbolKind.S_MethodHeader, - SymbolKind.S_MethodDeclarator, - SymbolKind.S_FormalParameterList, - SymbolKind.S_FormalParameter, - SymbolKind.S_FormalParameterTail, - SymbolKind.S_ThrowsOpt, - SymbolKind.S_MethodBody, - SymbolKind.S_DimsOpt, - SymbolKind.S_Dims, - SymbolKind.S_Dim, - SymbolKind.S_InterfaceDeclaration, - SymbolKind.S_NormalInterfaceDeclaration, - SymbolKind.S_InterfaceExtendsOpt, - SymbolKind.S_InterfaceExtends, - SymbolKind.S_InterfaceBody, - SymbolKind.S_InterfaceMemberDeclarationSeq, - SymbolKind.S_InterfaceMemberDeclaration, - SymbolKind.S_ConstantDeclaration, - SymbolKind.S_InterfaceMethodDeclaration, - SymbolKind.S_AnnotationInterfaceDeclaration, - SymbolKind.S_AnnotationInterfaceBody, - SymbolKind.S_AnnotationInterfaceMemberDeclarationSeq, - SymbolKind.S_AnnotationInterfaceMemberDeclaration, - SymbolKind.S_AnnotationInterfaceElementDeclaration, - SymbolKind.S_DefaultValueOpt, - SymbolKind.S_Block, - SymbolKind.S_BlockStatementSeq, - SymbolKind.S_BlockStatement, - SymbolKind.S_BlockDeclaration, - SymbolKind.S_LocalVariableDeclaration, - SymbolKind.S_Statement, - SymbolKind.S_SimpleStatement, - SymbolKind.S_LabeledStatement, - SymbolKind.S_StatementExpression, - SymbolKind.S_IfThenElseStatement, - SymbolKind.S_ElsePartOpt, - SymbolKind.S_SwitchBlock, - SymbolKind.S_SwitchRuleSeq, - SymbolKind.S_SwitchRule, - SymbolKind.S_SwitchBlockStatementGroupSeqOpt, - SymbolKind.S_SwitchBlockStatementGroup, - SymbolKind.S_SwitchLabelSeq, - SymbolKind.S_SwitchLabel, - SymbolKind.S_CaseExpressionList, - SymbolKind.S_WhileStatement, - SymbolKind.S_ForStatement, - SymbolKind.S_BasicForStatement, - SymbolKind.S_ForInitOpt, - SymbolKind.S_ExpressionOpt, - SymbolKind.S_StatementExpressionList, - SymbolKind.S_StatementExpressionListOpt, - SymbolKind.S_EnhancedForStatement, - SymbolKind.S_CatchesOpt, - SymbolKind.S_Catches, - SymbolKind.S_CatchClause, - SymbolKind.S_CatchFormalParameter, - SymbolKind.S_CatchType, - SymbolKind.S_FinallyOpt, - SymbolKind.S_Finally, - SymbolKind.S_ResourceSpecification, - SymbolKind.S_ResourceSeq, - SymbolKind.S_Resource, - SymbolKind.S_Pattern, - SymbolKind.S_Primary, - SymbolKind.S_ClassInstanceCreationExpression, - SymbolKind.S_UnqualifiedClassInstanceCreationExpression, - SymbolKind.S_ClassOrInterfaceTypeToInstantiate, - SymbolKind.S_AnnotatedCompoundName, - SymbolKind.S_TypeArgumentsOpt, - SymbolKind.S_TypeArguments, - SymbolKind.S_TypeArgumentList, - SymbolKind.S_TypeArgument, - SymbolKind.S_FieldAccess, - SymbolKind.S_ArrayAccess, - SymbolKind.S_MethodInvocation, - SymbolKind.S_Arguments, - SymbolKind.S_ArgumentList, - SymbolKind.S_MethodReference, - SymbolKind.S_ArrayCreationExpression, - SymbolKind.S_DimExprs, - SymbolKind.S_DimExpr, - SymbolKind.S_Expression, - SymbolKind.S_LambdaExpression, - SymbolKind.S_LambdaParameters, - SymbolKind.S_LambdaParameterList1, - SymbolKind.S_LambdaParameterList2, - SymbolKind.S_LambdaParameter, - SymbolKind.S_AssignmentExpression, - SymbolKind.S_Assignment, - SymbolKind.S_LeftHandSide, - SymbolKind.S_AssignmentOperator, - SymbolKind.S_ConditionalExpression, - SymbolKind.S_ConditionalOrTail, - SymbolKind.S_ConditionalOrExpression, - SymbolKind.S_ConditionalAndExpression, - SymbolKind.S_InclusiveOrExpression, - SymbolKind.S_ExclusiveOrExpression, - SymbolKind.S_AndExpression, - SymbolKind.S_EqualityExpression, - SymbolKind.S_RelationalExpression, - SymbolKind.S_InstanceofExpression, - SymbolKind.S_ShiftExpression, - SymbolKind.S_AdditiveExpression, - SymbolKind.S_MultiplicativeExpression, - SymbolKind.S_UnaryExpression, - SymbolKind.S_PreIncrementExpression, - SymbolKind.S_PreDecrementExpression, - SymbolKind.S_UnaryExpressionNotPlusMinus, - SymbolKind.S_PostfixExpression, - SymbolKind.S_PostIncrementExpression, - SymbolKind.S_PostDecrementExpression, - SymbolKind.S_CastExpression, - SymbolKind.S_TargetType, - SymbolKind.S_TypeList, - SymbolKind.S_SwitchExpression, - SymbolKind.S_AnnotationSeqOpt, - SymbolKind.S_AnnotationSeq, - SymbolKind.S_Annotation, - SymbolKind.S_AnnoParameterList, - SymbolKind.S_ElementValue, - SymbolKind.S_ElementValueListOpt - }; - - static final SymbolKind get(int code) { - return values_[code]; - } - - public final int getCode() { - return this.yycode_; - } - - /* YYNAMES_[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. - First, the terminals, then, starting at \a YYNTOKENS_, nonterminals. */ - private static final String[] yynames_ = yynames_init(); - private static final String[] yynames_init() - { - return new String[] - { - "end of file", "error", "invalid token", "LPAREN", "RPAREN", "LBRACE", - "RBRACE", "LBRACKET", "RBRACKET", "COMMA", "DOT", "SEMICOLON", "COLON", - "DBL_COLON", "STAR", "SLASH", "PERCENT", "AMPERSAND", "AT", "LESS", - "GREATER", "VERTICAL", "PLUS", "MINUS", "ARROW", "DIAMOND", "QUESTION", - "CARET", "EQUAL", "TILDE", "EXCLAMATION", "ELLIPSIS", "LESS_EQUAL", - "GREATER_EQUAL", "STAR_EQUAL", "SLASH_EQUAL", "PERCENT_EQUAL", - "PLUS_EQUAL", "MINUS_EQUAL", "LESS_LESS_EQUAL", "GR_GR_EQUAL", - "GR_GR_GR_EQUAL", "AMP_EQUAL", "CARET_EQUAL", "VERTICAL_EQUAL", - "DBL_PLUS", "DBL_MINUS", "DBL_VERTICAL", "DBL_AMPERSAND", "DBL_EQUAL", - "TRIPL_EQUAL", "NON_EQUAL", "DBL_LESS", "DBL_GREATER", "TRIPL_GREATER", - "IDENTIFIER", "INTEGER_LITERAL", "FLOATING_POINT_LITERAL", - "CHARACTER_LITERAL", "STRING_LITERAL", "ABSTRACT", "ASSERT", "BOOLEAN", - "BREAK", "BYTE", "CASE", "CATCH", "CHAR", "CLASS", "CONTINUE", "DEFAULT", - "DO", "DOUBLE", "ELSE", "ENUM", "EXTENDS", "FALSE", "FINAL", "FINALLY", - "FLOAT", "FOR", "IF", "IMPLEMENTS", "IMPORT", "INSTANCEOF", "INT", - "INTERFACE", "LONG", "MODULE", "NATIVE", "NEW", "NULL", "OPEN", - "PACKAGE", "PRIVATE", "PROTECTED", "PUBLIC", "RECORD", "RETURN", "SHORT", - "STATIC", "STRICTFP", "SUPER", "SWITCH", "SYNCHRONIZED", "THIS", "THROW", - "THROWS", "TRANSIENT", "TRANSITIVE", "TRUE", "TRY", "VAR", "VOID", - "VOLATILE", "WHILE", "YIELD", "SHORT_COMMENT", "LONG_COMMENT", "EOS", - "requires", "exports", "to", "opens", "uses", "provides", "with", - "$accept", "Literal", "CompoundName", "ModifierSeqOpt", "ModifierSeq", - "StandardModifierSeq", "StandardModifier", "CompilationUnit", "Package", - "Module", "ImportDeclarationSeqOpt", "ImportDeclarationSeq", - "ImportDeclaration", "TopLevelComponentSeqOpt", "TopLevelComponentSeq", - "TopLevelComponent", "ModuleDirectiveSeqOpt", "ModuleDirectiveSeq", - "ModuleDirective", "ModuleNameList", "RequiresModifierSeqOpt", "Type", - "UnannotatedType", "PrimitiveType", "ClassDeclaration", - "NormalClassDeclaration", "TypeParametersOpt", "TypeParameters", - "TypeParameterList", "TypeParameter", "TypeParameterTail", - "ClassExtendsOpt", "ClassImplementsOpt", "ClassTypeList1", - "ClassTypeList2", "ClassBodyOpt", "ClassBody", "ClassBodyDeclarationSeq", - "ClassBodyDeclaration", "PureBodyDeclaration", "ConstructorDeclaration", - "ConstructorDeclarator", "ConstructorBody", - "ExplicitConstructorInvocation", "EnumDeclaration", "EnumBody", - "EnumConstantListOpt", "EnumConstant", "EnumBodyDeclarationsOpt", - "RecordDeclaration", "RecordHeader", "RecordComponentListOpt", - "RecordComponent", "RecordBody", "RecordBodyDeclarationSeq", - "RecordBodyDeclaration", "FieldDeclaration", "VariableDeclaratorList", - "VariableDeclarator", "ArrayInitializer", "VariableInitializerListOpt", - "VariableInitializerList", "VariableInitializer", "MethodDeclaration", - "MethodHeader", "MethodDeclarator", "FormalParameterList", - "FormalParameter", "FormalParameterTail", "ThrowsOpt", "MethodBody", - "DimsOpt", "Dims", "Dim", "InterfaceDeclaration", - "NormalInterfaceDeclaration", "InterfaceExtendsOpt", "InterfaceExtends", - "InterfaceBody", "InterfaceMemberDeclarationSeq", - "InterfaceMemberDeclaration", "ConstantDeclaration", - "InterfaceMethodDeclaration", "AnnotationInterfaceDeclaration", - "AnnotationInterfaceBody", "AnnotationInterfaceMemberDeclarationSeq", - "AnnotationInterfaceMemberDeclaration", - "AnnotationInterfaceElementDeclaration", "DefaultValueOpt", "Block", - "BlockStatementSeq", "BlockStatement", "BlockDeclaration", - "LocalVariableDeclaration", "Statement", "SimpleStatement", - "LabeledStatement", "StatementExpression", "IfThenElseStatement", - "ElsePartOpt", "SwitchBlock", "SwitchRuleSeq", "SwitchRule", - "SwitchBlockStatementGroupSeqOpt", "SwitchBlockStatementGroup", - "SwitchLabelSeq", "SwitchLabel", "CaseExpressionList", "WhileStatement", - "ForStatement", "BasicForStatement", "ForInitOpt", "ExpressionOpt", - "StatementExpressionList", "StatementExpressionListOpt", - "EnhancedForStatement", "CatchesOpt", "Catches", "CatchClause", - "CatchFormalParameter", "CatchType", "FinallyOpt", "Finally", - "ResourceSpecification", "ResourceSeq", "Resource", "Pattern", "Primary", - "ClassInstanceCreationExpression", - "UnqualifiedClassInstanceCreationExpression", - "ClassOrInterfaceTypeToInstantiate", "AnnotatedCompoundName", - "TypeArgumentsOpt", "TypeArguments", "TypeArgumentList", "TypeArgument", - "FieldAccess", "ArrayAccess", "MethodInvocation", "Arguments", - "ArgumentList", "MethodReference", "ArrayCreationExpression", "DimExprs", - "DimExpr", "Expression", "LambdaExpression", "LambdaParameters", - "LambdaParameterList1", "LambdaParameterList2", "LambdaParameter", - "AssignmentExpression", "Assignment", "LeftHandSide", - "AssignmentOperator", "ConditionalExpression", "ConditionalOrTail", - "ConditionalOrExpression", "ConditionalAndExpression", - "InclusiveOrExpression", "ExclusiveOrExpression", "AndExpression", - "EqualityExpression", "RelationalExpression", "InstanceofExpression", - "ShiftExpression", "AdditiveExpression", "MultiplicativeExpression", - "UnaryExpression", "PreIncrementExpression", "PreDecrementExpression", - "UnaryExpressionNotPlusMinus", "PostfixExpression", - "PostIncrementExpression", "PostDecrementExpression", "CastExpression", - "TargetType", "TypeList", "SwitchExpression", "AnnotationSeqOpt", - "AnnotationSeq", "Annotation", "AnnoParameterList", "ElementValue", - "ElementValueListOpt", null - }; - } - - /* The user-facing name of this symbol. */ - public final String getName() { - return yynames_[yycode_]; - } - }; - - - /** - * Communication interface between the scanner and the Bison-generated - * parser JavaParser. - */ - public interface Lexer { - /* Token kinds. */ - /** Token "end of file", to be returned by the scanner. */ - static final int YYEOF = 0; - /** Token error, to be returned by the scanner. */ - static final int YYerror = 256; - /** Token "invalid token", to be returned by the scanner. */ - static final int YYUNDEF = 257; - /** Token LPAREN, to be returned by the scanner. */ - static final int LPAREN = 258; - /** Token RPAREN, to be returned by the scanner. */ - static final int RPAREN = 259; - /** Token LBRACE, to be returned by the scanner. */ - static final int LBRACE = 260; - /** Token RBRACE, to be returned by the scanner. */ - static final int RBRACE = 261; - /** Token LBRACKET, to be returned by the scanner. */ - static final int LBRACKET = 262; - /** Token RBRACKET, to be returned by the scanner. */ - static final int RBRACKET = 263; - /** Token COMMA, to be returned by the scanner. */ - static final int COMMA = 264; - /** Token DOT, to be returned by the scanner. */ - static final int DOT = 265; - /** Token SEMICOLON, to be returned by the scanner. */ - static final int SEMICOLON = 266; - /** Token COLON, to be returned by the scanner. */ - static final int COLON = 267; - /** Token DBL_COLON, to be returned by the scanner. */ - static final int DBL_COLON = 268; - /** Token STAR, to be returned by the scanner. */ - static final int STAR = 269; - /** Token SLASH, to be returned by the scanner. */ - static final int SLASH = 270; - /** Token PERCENT, to be returned by the scanner. */ - static final int PERCENT = 271; - /** Token AMPERSAND, to be returned by the scanner. */ - static final int AMPERSAND = 272; - /** Token AT, to be returned by the scanner. */ - static final int AT = 273; - /** Token LESS, to be returned by the scanner. */ - static final int LESS = 274; - /** Token GREATER, to be returned by the scanner. */ - static final int GREATER = 275; - /** Token VERTICAL, to be returned by the scanner. */ - static final int VERTICAL = 276; - /** Token PLUS, to be returned by the scanner. */ - static final int PLUS = 277; - /** Token MINUS, to be returned by the scanner. */ - static final int MINUS = 278; - /** Token ARROW, to be returned by the scanner. */ - static final int ARROW = 279; - /** Token DIAMOND, to be returned by the scanner. */ - static final int DIAMOND = 280; - /** Token QUESTION, to be returned by the scanner. */ - static final int QUESTION = 281; - /** Token CARET, to be returned by the scanner. */ - static final int CARET = 282; - /** Token EQUAL, to be returned by the scanner. */ - static final int EQUAL = 283; - /** Token TILDE, to be returned by the scanner. */ - static final int TILDE = 284; - /** Token EXCLAMATION, to be returned by the scanner. */ - static final int EXCLAMATION = 285; - /** Token ELLIPSIS, to be returned by the scanner. */ - static final int ELLIPSIS = 286; - /** Token LESS_EQUAL, to be returned by the scanner. */ - static final int LESS_EQUAL = 287; - /** Token GREATER_EQUAL, to be returned by the scanner. */ - static final int GREATER_EQUAL = 288; - /** Token STAR_EQUAL, to be returned by the scanner. */ - static final int STAR_EQUAL = 289; - /** Token SLASH_EQUAL, to be returned by the scanner. */ - static final int SLASH_EQUAL = 290; - /** Token PERCENT_EQUAL, to be returned by the scanner. */ - static final int PERCENT_EQUAL = 291; - /** Token PLUS_EQUAL, to be returned by the scanner. */ - static final int PLUS_EQUAL = 292; - /** Token MINUS_EQUAL, to be returned by the scanner. */ - static final int MINUS_EQUAL = 293; - /** Token LESS_LESS_EQUAL, to be returned by the scanner. */ - static final int LESS_LESS_EQUAL = 294; - /** Token GR_GR_EQUAL, to be returned by the scanner. */ - static final int GR_GR_EQUAL = 295; - /** Token GR_GR_GR_EQUAL, to be returned by the scanner. */ - static final int GR_GR_GR_EQUAL = 296; - /** Token AMP_EQUAL, to be returned by the scanner. */ - static final int AMP_EQUAL = 297; - /** Token CARET_EQUAL, to be returned by the scanner. */ - static final int CARET_EQUAL = 298; - /** Token VERTICAL_EQUAL, to be returned by the scanner. */ - static final int VERTICAL_EQUAL = 299; - /** Token DBL_PLUS, to be returned by the scanner. */ - static final int DBL_PLUS = 300; - /** Token DBL_MINUS, to be returned by the scanner. */ - static final int DBL_MINUS = 301; - /** Token DBL_VERTICAL, to be returned by the scanner. */ - static final int DBL_VERTICAL = 302; - /** Token DBL_AMPERSAND, to be returned by the scanner. */ - static final int DBL_AMPERSAND = 303; - /** Token DBL_EQUAL, to be returned by the scanner. */ - static final int DBL_EQUAL = 304; - /** Token TRIPL_EQUAL, to be returned by the scanner. */ - static final int TRIPL_EQUAL = 305; - /** Token NON_EQUAL, to be returned by the scanner. */ - static final int NON_EQUAL = 306; - /** Token DBL_LESS, to be returned by the scanner. */ - static final int DBL_LESS = 307; - /** Token DBL_GREATER, to be returned by the scanner. */ - static final int DBL_GREATER = 308; - /** Token TRIPL_GREATER, to be returned by the scanner. */ - static final int TRIPL_GREATER = 309; - /** Token IDENTIFIER, to be returned by the scanner. */ - static final int IDENTIFIER = 310; - /** Token INTEGER_LITERAL, to be returned by the scanner. */ - static final int INTEGER_LITERAL = 311; - /** Token FLOATING_POINT_LITERAL, to be returned by the scanner. */ - static final int FLOATING_POINT_LITERAL = 312; - /** Token CHARACTER_LITERAL, to be returned by the scanner. */ - static final int CHARACTER_LITERAL = 313; - /** Token STRING_LITERAL, to be returned by the scanner. */ - static final int STRING_LITERAL = 314; - /** Token ABSTRACT, to be returned by the scanner. */ - static final int ABSTRACT = 315; - /** Token ASSERT, to be returned by the scanner. */ - static final int ASSERT = 316; - /** Token BOOLEAN, to be returned by the scanner. */ - static final int BOOLEAN = 317; - /** Token BREAK, to be returned by the scanner. */ - static final int BREAK = 318; - /** Token BYTE, to be returned by the scanner. */ - static final int BYTE = 319; - /** Token CASE, to be returned by the scanner. */ - static final int CASE = 320; - /** Token CATCH, to be returned by the scanner. */ - static final int CATCH = 321; - /** Token CHAR, to be returned by the scanner. */ - static final int CHAR = 322; - /** Token CLASS, to be returned by the scanner. */ - static final int CLASS = 323; - /** Token CONTINUE, to be returned by the scanner. */ - static final int CONTINUE = 324; - /** Token DEFAULT, to be returned by the scanner. */ - static final int DEFAULT = 325; - /** Token DO, to be returned by the scanner. */ - static final int DO = 326; - /** Token DOUBLE, to be returned by the scanner. */ - static final int DOUBLE = 327; - /** Token ELSE, to be returned by the scanner. */ - static final int ELSE = 328; - /** Token ENUM, to be returned by the scanner. */ - static final int ENUM = 329; - /** Token EXTENDS, to be returned by the scanner. */ - static final int EXTENDS = 330; - /** Token FALSE, to be returned by the scanner. */ - static final int FALSE = 331; - /** Token FINAL, to be returned by the scanner. */ - static final int FINAL = 332; - /** Token FINALLY, to be returned by the scanner. */ - static final int FINALLY = 333; - /** Token FLOAT, to be returned by the scanner. */ - static final int FLOAT = 334; - /** Token FOR, to be returned by the scanner. */ - static final int FOR = 335; - /** Token IF, to be returned by the scanner. */ - static final int IF = 336; - /** Token IMPLEMENTS, to be returned by the scanner. */ - static final int IMPLEMENTS = 337; - /** Token IMPORT, to be returned by the scanner. */ - static final int IMPORT = 338; - /** Token INSTANCEOF, to be returned by the scanner. */ - static final int INSTANCEOF = 339; - /** Token INT, to be returned by the scanner. */ - static final int INT = 340; - /** Token INTERFACE, to be returned by the scanner. */ - static final int INTERFACE = 341; - /** Token LONG, to be returned by the scanner. */ - static final int LONG = 342; - /** Token MODULE, to be returned by the scanner. */ - static final int MODULE = 343; - /** Token NATIVE, to be returned by the scanner. */ - static final int NATIVE = 344; - /** Token NEW, to be returned by the scanner. */ - static final int NEW = 345; - /** Token NULL, to be returned by the scanner. */ - static final int NULL = 346; - /** Token OPEN, to be returned by the scanner. */ - static final int OPEN = 347; - /** Token PACKAGE, to be returned by the scanner. */ - static final int PACKAGE = 348; - /** Token PRIVATE, to be returned by the scanner. */ - static final int PRIVATE = 349; - /** Token PROTECTED, to be returned by the scanner. */ - static final int PROTECTED = 350; - /** Token PUBLIC, to be returned by the scanner. */ - static final int PUBLIC = 351; - /** Token RECORD, to be returned by the scanner. */ - static final int RECORD = 352; - /** Token RETURN, to be returned by the scanner. */ - static final int RETURN = 353; - /** Token SHORT, to be returned by the scanner. */ - static final int SHORT = 354; - /** Token STATIC, to be returned by the scanner. */ - static final int STATIC = 355; - /** Token STRICTFP, to be returned by the scanner. */ - static final int STRICTFP = 356; - /** Token SUPER, to be returned by the scanner. */ - static final int SUPER = 357; - /** Token SWITCH, to be returned by the scanner. */ - static final int SWITCH = 358; - /** Token SYNCHRONIZED, to be returned by the scanner. */ - static final int SYNCHRONIZED = 359; - /** Token THIS, to be returned by the scanner. */ - static final int THIS = 360; - /** Token THROW, to be returned by the scanner. */ - static final int THROW = 361; - /** Token THROWS, to be returned by the scanner. */ - static final int THROWS = 362; - /** Token TRANSIENT, to be returned by the scanner. */ - static final int TRANSIENT = 363; - /** Token TRANSITIVE, to be returned by the scanner. */ - static final int TRANSITIVE = 364; - /** Token TRUE, to be returned by the scanner. */ - static final int TRUE = 365; - /** Token TRY, to be returned by the scanner. */ - static final int TRY = 366; - /** Token VAR, to be returned by the scanner. */ - static final int VAR = 367; - /** Token VOID, to be returned by the scanner. */ - static final int VOID = 368; - /** Token VOLATILE, to be returned by the scanner. */ - static final int VOLATILE = 369; - /** Token WHILE, to be returned by the scanner. */ - static final int WHILE = 370; - /** Token YIELD, to be returned by the scanner. */ - static final int YIELD = 371; - /** Token SHORT_COMMENT, to be returned by the scanner. */ - static final int SHORT_COMMENT = 372; - /** Token LONG_COMMENT, to be returned by the scanner. */ - static final int LONG_COMMENT = 373; - /** Token EOS, to be returned by the scanner. */ - static final int EOS = 374; - - /** Deprecated, use YYEOF instead. */ - public static final int EOF = YYEOF; - - - /** - * Method to retrieve the semantic value of the last scanned token. - * @return the semantic value of the last scanned token. - */ - Entity getLVal(); - - /** - * Entry point for the scanner. Returns the token identifier corresponding - * to the next token and prepares to return the semantic value - * of the token. - * @return the token identifier corresponding to the next token. - */ - int yylex() throws java.io.IOException; - - /** - * Emit an errorin a user-defined way. - * - * - * @param msg The string for the error message. - */ - void yyerror(String msg); - - - } - - - /** - * The object doing lexical analysis for us. - */ - private Lexer yylexer; - - - - - - /** - * Instantiates the Bison-generated parser. - * @param yylexer The scanner that will supply tokens to the parser. - */ - public JavaParser (Lexer yylexer) - { - - this.yylexer = yylexer; - - } - - - - private int yynerrs = 0; - - /** - * The number of syntax errors so far. - */ - public final int getNumberOfErrors () { return yynerrs; } - - /** - * Print an error message via the lexer. - * - * @param msg The error message. - */ - public final void yyerror(String msg) { - yylexer.yyerror(msg); - } - - - - private final class YYStack { - private int[] stateStack = new int[16]; - private Entity[] valueStack = new Entity[16]; - - public int size = 16; - public int height = -1; - - public final void push (int state, Entity value) { - height++; - if (size == height) - { - int[] newStateStack = new int[size * 2]; - System.arraycopy (stateStack, 0, newStateStack, 0, height); - stateStack = newStateStack; - - Entity[] newValueStack = new Entity[size * 2]; - System.arraycopy (valueStack, 0, newValueStack, 0, height); - valueStack = newValueStack; - - size *= 2; - } - - stateStack[height] = state; - valueStack[height] = value; - } - - public final void pop () { - pop (1); - } - - public final void pop (int num) { - // Avoid memory leaks... garbage collection is a white lie! - if (0 < num) { - java.util.Arrays.fill (valueStack, height - num + 1, height + 1, null); - } - height -= num; - } - - public final int stateAt (int i) { - return stateStack[height - i]; - } - - public final Entity valueAt (int i) { - return valueStack[height - i]; - } - - // Print the state stack on the debug stream. - public void print (java.io.PrintStream out) { - out.print ("Stack now"); - - for (int i = 0; i <= height; i++) - { - out.print (' '); - out.print (stateStack[i]); - } - out.println (); - } - } - - /** - * Returned by a Bison action in order to stop the parsing process and - * return success (true). - */ - public static final int YYACCEPT = 0; - - /** - * Returned by a Bison action in order to stop the parsing process and - * return failure (false). - */ - public static final int YYABORT = 1; - - - - /** - * Returned by a Bison action in order to start error recovery without - * printing an error message. - */ - public static final int YYERROR = 2; - - /** - * Internal return codes that are not supported for user semantic - * actions. - */ - private static final int YYERRLAB = 3; - private static final int YYNEWSTATE = 4; - private static final int YYDEFAULT = 5; - private static final int YYREDUCE = 6; - private static final int YYERRLAB1 = 7; - private static final int YYRETURN = 8; - - - private int yyerrstatus_ = 0; - - - /** - * Whether error recovery is being done. In this state, the parser - * reads token until it reaches a known state, and then restarts normal - * operation. - */ - public final boolean recovering () - { - return yyerrstatus_ == 0; - } - - /** Compute post-reduction state. - * @param yystate the current state - * @param yysym the nonterminal to push on the stack - */ - private int yyLRGotoState (int yystate, int yysym) - { - int yyr = yypgoto_[yysym - YYNTOKENS_] + yystate; - if (0 <= yyr && yyr <= YYLAST_ && yycheck_[yyr] == yystate) - return yytable_[yyr]; - else - return yydefgoto_[yysym - YYNTOKENS_]; - } - - private int yyaction(int yyn, YYStack yystack, int yylen) - { - /* If YYLEN is nonzero, implement the default value of the action: - '$$ = $1'. Otherwise, use the top of the stack. - - Otherwise, the following line sets YYVAL to garbage. - This behavior is undocumented and Bison - users should not rely upon it. */ - Entity yyval = (0 < yylen) ? yystack.valueAt(yylen - 1) : yystack.valueAt(0); - - switch (yyn) - { - case 2: /* Literal: INTEGER_LITERAL */ - if (yyn == 2) - /* "src/main/resources/Java_16_Grammar.y":260 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 3: /* Literal: FLOATING_POINT_LITERAL */ - if (yyn == 3) - /* "src/main/resources/Java_16_Grammar.y":261 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 4: /* Literal: TRUE */ - if (yyn == 4) - /* "src/main/resources/Java_16_Grammar.y":262 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 5: /* Literal: FALSE */ - if (yyn == 5) - /* "src/main/resources/Java_16_Grammar.y":263 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 6: /* Literal: CHARACTER_LITERAL */ - if (yyn == 6) - /* "src/main/resources/Java_16_Grammar.y":264 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 7: /* Literal: STRING_LITERAL */ - if (yyn == 7) - /* "src/main/resources/Java_16_Grammar.y":265 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 8: /* Literal: NULL */ - if (yyn == 8) - /* "src/main/resources/Java_16_Grammar.y":267 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 9: /* CompoundName: IDENTIFIER */ - if (yyn == 9) - /* "src/main/resources/Java_16_Grammar.y":273 */ - { yyval = new CompoundName(((Token)(yystack.valueAt (0))).image); }; - break; - - - case 10: /* CompoundName: CompoundName DOT IDENTIFIER */ - if (yyn == 10) - /* "src/main/resources/Java_16_Grammar.y":274 */ - { yyval = ((CompoundName)(yystack.valueAt (2))).add(((Token)(yystack.valueAt (0))).image); }; - break; - - - case 11: /* ModifierSeqOpt: %empty */ - if (yyn == 11) - /* "src/main/resources/Java_16_Grammar.y":278 */ - { yyval = null; }; - break; - - - case 12: /* ModifierSeqOpt: ModifierSeq */ - if (yyn == 12) - /* "src/main/resources/Java_16_Grammar.y":279 */ - { yyval = ((Modifiers)(yystack.valueAt (0))); }; - break; - - - case 13: /* ModifierSeq: StandardModifierSeq */ - if (yyn == 13) - /* "src/main/resources/Java_16_Grammar.y":283 */ - { yyval = new Modifiers(null,((StandardModifiers)(yystack.valueAt (0)))); }; - break; - - - case 14: /* ModifierSeq: AnnotationSeq StandardModifierSeq */ - if (yyn == 14) - /* "src/main/resources/Java_16_Grammar.y":284 */ - { yyval = new Modifiers(((Annotations)(yystack.valueAt (1))),((StandardModifiers)(yystack.valueAt (0)))); }; - break; - - - case 15: /* StandardModifierSeq: StandardModifier */ - if (yyn == 15) - /* "src/main/resources/Java_16_Grammar.y":288 */ - { yyval = new StandardModifiers(((Token)(yystack.valueAt (0)))); }; - break; - - - case 16: /* StandardModifierSeq: StandardModifierSeq StandardModifier */ - if (yyn == 16) - /* "src/main/resources/Java_16_Grammar.y":289 */ - { yyval = ((StandardModifiers)(yystack.valueAt (1))).add(((Token)(yystack.valueAt (0)))); }; - break; - - - case 17: /* StandardModifier: DEFAULT */ - if (yyn == 17) - /* "src/main/resources/Java_16_Grammar.y":294 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 18: /* StandardModifier: FINAL */ - if (yyn == 18) - /* "src/main/resources/Java_16_Grammar.y":295 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 19: /* StandardModifier: PUBLIC */ - if (yyn == 19) - /* "src/main/resources/Java_16_Grammar.y":296 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 20: /* StandardModifier: PROTECTED */ - if (yyn == 20) - /* "src/main/resources/Java_16_Grammar.y":297 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 21: /* StandardModifier: PRIVATE */ - if (yyn == 21) - /* "src/main/resources/Java_16_Grammar.y":298 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 22: /* StandardModifier: ABSTRACT */ - if (yyn == 22) - /* "src/main/resources/Java_16_Grammar.y":299 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 23: /* StandardModifier: STATIC */ - if (yyn == 23) - /* "src/main/resources/Java_16_Grammar.y":300 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 24: /* StandardModifier: STRICTFP */ - if (yyn == 24) - /* "src/main/resources/Java_16_Grammar.y":301 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 25: /* StandardModifier: SYNCHRONIZED */ - if (yyn == 25) - /* "src/main/resources/Java_16_Grammar.y":302 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 26: /* StandardModifier: TRANSIENT */ - if (yyn == 26) - /* "src/main/resources/Java_16_Grammar.y":303 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 27: /* StandardModifier: VOLATILE */ - if (yyn == 27) - /* "src/main/resources/Java_16_Grammar.y":304 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 28: /* StandardModifier: OPEN */ - if (yyn == 28) - /* "src/main/resources/Java_16_Grammar.y":305 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 29: /* CompilationUnit: %empty */ - if (yyn == 29) - /* "src/main/resources/Java_16_Grammar.y":311 */ - { yyval = null; }; - break; - - - case 30: /* CompilationUnit: Package */ - if (yyn == 30) - /* "src/main/resources/Java_16_Grammar.y":312 */ - { yyval = ((tree.Compilation.CompilationUnit)(yystack.valueAt (0))); ast = ((tree.Compilation.CompilationUnit)(yystack.valueAt (0))); }; - break; - - - case 31: /* CompilationUnit: Module */ - if (yyn == 31) - /* "src/main/resources/Java_16_Grammar.y":313 */ - { yyval = ((tree.Compilation.Module)(yystack.valueAt (0))); ast = ((tree.Compilation.Module)(yystack.valueAt (0))); }; - break; - - - case 32: /* CompilationUnit: ImportDeclarationSeqOpt TopLevelComponentSeq */ - if (yyn == 32) - /* "src/main/resources/Java_16_Grammar.y":314 */ - { ast = new SimpleCompilationUnit(((tree.Declaration.ImportDeclarations)(yystack.valueAt (1))),((tree.Compilation.TopLevelComponents)(yystack.valueAt (0)))); }; - break; - - - case 33: /* Package: PACKAGE CompoundName SEMICOLON ImportDeclarationSeqOpt TopLevelComponentSeqOpt */ - if (yyn == 33) - /* "src/main/resources/Java_16_Grammar.y":319 */ - { yyval = new tree.Compilation.Package(((CompoundName)(yystack.valueAt (3))),((tree.Declaration.ImportDeclarations)(yystack.valueAt (1))),((tree.Compilation.TopLevelComponents)(yystack.valueAt (0)))); }; - break; - - - case 34: /* Module: MODULE CompoundName LBRACE ModuleDirectiveSeqOpt RBRACE */ - if (yyn == 34) - /* "src/main/resources/Java_16_Grammar.y":325 */ - { yyval = null; }; - break; - - - case 35: /* ImportDeclarationSeqOpt: %empty */ - if (yyn == 35) - /* "src/main/resources/Java_16_Grammar.y":329 */ - { yyval = null; }; - break; - - - case 36: /* ImportDeclarationSeqOpt: ImportDeclarationSeq */ - if (yyn == 36) - /* "src/main/resources/Java_16_Grammar.y":330 */ - { yyval = ((tree.Declaration.ImportDeclarations)(yystack.valueAt (0))); }; - break; - - - case 37: /* ImportDeclarationSeq: ImportDeclaration */ - if (yyn == 37) - /* "src/main/resources/Java_16_Grammar.y":334 */ - { yyval = new ImportDeclarations(((tree.Declaration.ImportDeclaration)(yystack.valueAt (0)))); }; - break; - - - case 38: /* ImportDeclarationSeq: ImportDeclarationSeqOpt ImportDeclaration */ - if (yyn == 38) - /* "src/main/resources/Java_16_Grammar.y":335 */ - { yyval = ((tree.Declaration.ImportDeclarations)(yystack.valueAt (1))).add(((tree.Declaration.ImportDeclaration)(yystack.valueAt (0)))); }; - break; - - - case 39: /* ImportDeclaration: IMPORT CompoundName SEMICOLON */ - if (yyn == 39) - /* "src/main/resources/Java_16_Grammar.y":339 */ - { yyval = new ImportDeclaration(false,((CompoundName)(yystack.valueAt (1))),false); }; - break; - - - case 40: /* ImportDeclaration: IMPORT STATIC CompoundName SEMICOLON */ - if (yyn == 40) - /* "src/main/resources/Java_16_Grammar.y":340 */ - { yyval = new ImportDeclaration(true,((CompoundName)(yystack.valueAt (1))),false); }; - break; - - - case 41: /* ImportDeclaration: IMPORT CompoundName DOT STAR SEMICOLON */ - if (yyn == 41) - /* "src/main/resources/Java_16_Grammar.y":341 */ - { yyval = new ImportDeclaration(false,((CompoundName)(yystack.valueAt (3))),true); }; - break; - - - case 42: /* ImportDeclaration: IMPORT STATIC CompoundName DOT STAR SEMICOLON */ - if (yyn == 42) - /* "src/main/resources/Java_16_Grammar.y":342 */ - { yyval = new ImportDeclaration(true,((CompoundName)(yystack.valueAt (3))),true); }; - break; - - - case 43: /* TopLevelComponentSeqOpt: %empty */ - if (yyn == 43) - /* "src/main/resources/Java_16_Grammar.y":346 */ - { yyval = null; }; - break; - - - case 44: /* TopLevelComponentSeqOpt: TopLevelComponentSeq */ - if (yyn == 44) - /* "src/main/resources/Java_16_Grammar.y":347 */ - { yyval = ((tree.Compilation.TopLevelComponents)(yystack.valueAt (0))); }; - break; - - - case 45: /* TopLevelComponentSeq: ModifierSeqOpt TopLevelComponent */ - if (yyn == 45) - /* "src/main/resources/Java_16_Grammar.y":351 */ - { ((tree.Compilation.TopLevelComponent)(yystack.valueAt (0))).addModifiers(((Modifiers)(yystack.valueAt (1)))); yyval = new TopLevelComponents(((tree.Compilation.TopLevelComponent)(yystack.valueAt (0)))); }; - break; - - - case 46: /* TopLevelComponentSeq: TopLevelComponentSeq ModifierSeqOpt TopLevelComponent */ - if (yyn == 46) - /* "src/main/resources/Java_16_Grammar.y":352 */ - { ((tree.Compilation.TopLevelComponent)(yystack.valueAt (0))).addModifiers(((Modifiers)(yystack.valueAt (1)))); yyval = ((tree.Compilation.TopLevelComponents)(yystack.valueAt (2))).add(((tree.Compilation.TopLevelComponent)(yystack.valueAt (0)))); }; - break; - - - case 47: /* TopLevelComponent: ClassDeclaration */ - if (yyn == 47) - /* "src/main/resources/Java_16_Grammar.y":356 */ - { yyval = new TopLevelComponent(((ClassDeclaration)(yystack.valueAt (0)))); }; - break; - - - case 48: /* TopLevelComponent: InterfaceDeclaration */ - if (yyn == 48) - /* "src/main/resources/Java_16_Grammar.y":357 */ - { yyval = new TopLevelComponent(((InterfaceDeclaration)(yystack.valueAt (0)))); }; - break; - - - case 67: /* Type: UnannotatedType */ - if (yyn == 67) - /* "src/main/resources/Java_16_Grammar.y":404 */ - { yyval = ((tree.Type.UnannotatedType)(yystack.valueAt (0))); }; - break; - - - case 68: /* Type: AnnotationSeq UnannotatedType */ - if (yyn == 68) - /* "src/main/resources/Java_16_Grammar.y":405 */ - { yyval = ((tree.Type.UnannotatedType)(yystack.valueAt (0))).addAnnotations(((Annotations)(yystack.valueAt (1)))); }; - break; - - - case 69: /* UnannotatedType: PrimitiveType */ - if (yyn == 69) - /* "src/main/resources/Java_16_Grammar.y":409 */ - { yyval = new PrimitiveType(((Token)(yystack.valueAt (0)))); }; - break; - - - case 70: /* UnannotatedType: CompoundName */ - if (yyn == 70) - /* "src/main/resources/Java_16_Grammar.y":411 */ - { yyval = new TypeName(((CompoundName)(yystack.valueAt (0))),null); }; - break; - - - case 71: /* UnannotatedType: CompoundName TypeArguments */ - if (yyn == 71) - /* "src/main/resources/Java_16_Grammar.y":412 */ - { yyval = new TypeName(((CompoundName)(yystack.valueAt (1))),((tree.Type.TypeArguments)(yystack.valueAt (0)))); }; - break; - - - case 72: /* UnannotatedType: UnannotatedType Dim */ - if (yyn == 72) - /* "src/main/resources/Java_16_Grammar.y":414 */ - { yyval = ((tree.Type.UnannotatedType)(yystack.valueAt (1))).addDimension(((Dim)(yystack.valueAt (0)))); }; - break; - - - case 73: /* PrimitiveType: BYTE */ - if (yyn == 73) - /* "src/main/resources/Java_16_Grammar.y":423 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 74: /* PrimitiveType: SHORT */ - if (yyn == 74) - /* "src/main/resources/Java_16_Grammar.y":424 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 75: /* PrimitiveType: INT */ - if (yyn == 75) - /* "src/main/resources/Java_16_Grammar.y":425 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 76: /* PrimitiveType: LONG */ - if (yyn == 76) - /* "src/main/resources/Java_16_Grammar.y":426 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 77: /* PrimitiveType: CHAR */ - if (yyn == 77) - /* "src/main/resources/Java_16_Grammar.y":427 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 78: /* PrimitiveType: FLOAT */ - if (yyn == 78) - /* "src/main/resources/Java_16_Grammar.y":429 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 79: /* PrimitiveType: DOUBLE */ - if (yyn == 79) - /* "src/main/resources/Java_16_Grammar.y":430 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 80: /* PrimitiveType: BOOLEAN */ - if (yyn == 80) - /* "src/main/resources/Java_16_Grammar.y":431 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 81: /* ClassDeclaration: NormalClassDeclaration */ - if (yyn == 81) - /* "src/main/resources/Java_16_Grammar.y":452 */ - { yyval = ((ClassDeclaration)(yystack.valueAt (0))); }; - break; - - - case 82: /* ClassDeclaration: EnumDeclaration */ - if (yyn == 82) - /* "src/main/resources/Java_16_Grammar.y":453 */ - { yyval = ((tree.Declaration.Declaration)(yystack.valueAt (0))); }; - break; - - - case 83: /* ClassDeclaration: RecordDeclaration */ - if (yyn == 83) - /* "src/main/resources/Java_16_Grammar.y":454 */ - { yyval = ((tree.Declaration.Declaration)(yystack.valueAt (0))); }; - break; - - - case 84: /* NormalClassDeclaration: ModifierSeqOpt CLASS IDENTIFIER TypeParametersOpt ClassExtendsOpt ClassImplementsOpt ClassBody */ - if (yyn == 84) - /* "src/main/resources/Java_16_Grammar.y":459 */ - { yyval = new NormalClassDeclaration(((Token)(yystack.valueAt (4))),((TypeParameters)(yystack.valueAt (3))),((tree.Type.Type)(yystack.valueAt (2))),((tree.Type.TypeList)(yystack.valueAt (1))),((Declarations)(yystack.valueAt (0)))); }; - break; - - - case 85: /* TypeParametersOpt: %empty */ - if (yyn == 85) - /* "src/main/resources/Java_16_Grammar.y":463 */ - { yyval = null; }; - break; - - - case 86: /* TypeParametersOpt: TypeParameters */ - if (yyn == 86) - /* "src/main/resources/Java_16_Grammar.y":464 */ - { yyval = ((TypeParameters)(yystack.valueAt (0))); }; - break; - - - case 87: /* TypeParameters: LESS TypeParameterList GREATER */ - if (yyn == 87) - /* "src/main/resources/Java_16_Grammar.y":468 */ - { yyval = ((TypeParameters)(yystack.valueAt (1))); }; - break; - - - case 88: /* TypeParameterList: TypeParameter */ - if (yyn == 88) - /* "src/main/resources/Java_16_Grammar.y":472 */ - { yyval = new TypeParameters(((TypeParameter)(yystack.valueAt (0)))); }; - break; - - - case 89: /* TypeParameterList: TypeParameterList COMMA TypeParameter */ - if (yyn == 89) - /* "src/main/resources/Java_16_Grammar.y":473 */ - { yyval = ((TypeParameters)(yystack.valueAt (2))).add(((TypeParameter)(yystack.valueAt (0)))); }; - break; - - - case 90: /* TypeParameter: AnnotationSeq TypeParameterTail */ - if (yyn == 90) - /* "src/main/resources/Java_16_Grammar.y":483 */ - { yyval = new TypeParameter(((Annotations)(yystack.valueAt (1))),((TypeParameterTail)(yystack.valueAt (0)))); }; - break; - - - case 91: /* TypeParameter: TypeParameterTail */ - if (yyn == 91) - /* "src/main/resources/Java_16_Grammar.y":484 */ - { yyval = new TypeParameter(null,((TypeParameterTail)(yystack.valueAt (0)))); }; - break; - - - case 92: /* TypeParameterTail: IDENTIFIER */ - if (yyn == 92) - /* "src/main/resources/Java_16_Grammar.y":488 */ - { yyval = new TypeParameterTail(((Token)(yystack.valueAt (0))),null); }; - break; - - - case 93: /* TypeParameterTail: IDENTIFIER EXTENDS AnnotationSeqOpt IDENTIFIER */ - if (yyn == 93) - /* "src/main/resources/Java_16_Grammar.y":489 */ - { yyval = new TypeParameterTail(((Token)(yystack.valueAt (3))),((Annotations)(yystack.valueAt (1))),((Token)(yystack.valueAt (0)))); }; - break; - - - case 94: /* TypeParameterTail: IDENTIFIER EXTENDS ClassTypeList2 */ - if (yyn == 94) - /* "src/main/resources/Java_16_Grammar.y":490 */ - { yyval = new TypeParameterTail(((Token)(yystack.valueAt (2))),((tree.Type.TypeList)(yystack.valueAt (0)))); }; - break; - - - case 95: /* ClassExtendsOpt: %empty */ - if (yyn == 95) - /* "src/main/resources/Java_16_Grammar.y":494 */ - { yyval = null; }; - break; - - - case 96: /* ClassExtendsOpt: EXTENDS Type */ - if (yyn == 96) - /* "src/main/resources/Java_16_Grammar.y":495 */ - { yyval = ((tree.Type.Type)(yystack.valueAt (0))); }; - break; - - - case 97: /* ClassImplementsOpt: %empty */ - if (yyn == 97) - /* "src/main/resources/Java_16_Grammar.y":499 */ - { yyval = null; }; - break; - - - case 98: /* ClassImplementsOpt: IMPLEMENTS ClassTypeList1 */ - if (yyn == 98) - /* "src/main/resources/Java_16_Grammar.y":500 */ - { yyval = ((tree.Type.TypeList)(yystack.valueAt (0))); }; - break; - - - case 99: /* ClassTypeList1: Type */ - if (yyn == 99) - /* "src/main/resources/Java_16_Grammar.y":504 */ - { yyval = new TypeList(((tree.Type.Type)(yystack.valueAt (0)))); }; - break; - - - case 100: /* ClassTypeList1: ClassTypeList1 COMMA Type */ - if (yyn == 100) - /* "src/main/resources/Java_16_Grammar.y":505 */ - { yyval = ((tree.Type.TypeList)(yystack.valueAt (2))).add(((tree.Type.Type)(yystack.valueAt (0)))); }; - break; - - - case 101: /* ClassTypeList2: Type */ - if (yyn == 101) - /* "src/main/resources/Java_16_Grammar.y":509 */ - { yyval = new TypeList(((tree.Type.Type)(yystack.valueAt (0)))); }; - break; - - - case 102: /* ClassTypeList2: ClassTypeList2 AMPERSAND Type */ - if (yyn == 102) - /* "src/main/resources/Java_16_Grammar.y":510 */ - { yyval = ((tree.Type.TypeList)(yystack.valueAt (2))).add(((tree.Type.Type)(yystack.valueAt (0)))); }; - break; - - - case 103: /* ClassBodyOpt: %empty */ - if (yyn == 103) - /* "src/main/resources/Java_16_Grammar.y":514 */ - { yyval = null; }; - break; - - - case 104: /* ClassBodyOpt: ClassBody */ - if (yyn == 104) - /* "src/main/resources/Java_16_Grammar.y":515 */ - { yyval = ((Declarations)(yystack.valueAt (0))); }; - break; - - - case 105: /* ClassBody: LBRACE RBRACE */ - if (yyn == 105) - /* "src/main/resources/Java_16_Grammar.y":519 */ - { yyval = null; }; - break; - - - case 106: /* ClassBody: LBRACE ClassBodyDeclarationSeq RBRACE */ - if (yyn == 106) - /* "src/main/resources/Java_16_Grammar.y":520 */ - { yyval = ((Declarations)(yystack.valueAt (1))); }; - break; - - - case 107: /* ClassBodyDeclarationSeq: ClassBodyDeclaration */ - if (yyn == 107) - /* "src/main/resources/Java_16_Grammar.y":524 */ - { yyval = new Declarations(((tree.Declaration.Declaration)(yystack.valueAt (0)))); }; - break; - - - case 108: /* ClassBodyDeclarationSeq: ClassBodyDeclarationSeq ClassBodyDeclaration */ - if (yyn == 108) - /* "src/main/resources/Java_16_Grammar.y":525 */ - { yyval = ((Declarations)(yystack.valueAt (1))).add(((tree.Declaration.Declaration)(yystack.valueAt (0)))); }; - break; - - - case 109: /* ClassBodyDeclaration: ModifierSeqOpt PureBodyDeclaration */ - if (yyn == 109) - /* "src/main/resources/Java_16_Grammar.y":529 */ - { yyval = ((tree.Declaration.Declaration)(yystack.valueAt (0))).addModifiers(((Modifiers)(yystack.valueAt (1)))); }; - break; - - - case 110: /* ClassBodyDeclaration: Block */ - if (yyn == 110) - /* "src/main/resources/Java_16_Grammar.y":530 */ - { yyval = new ClassInitializer(((tree.Statement.Block)(yystack.valueAt (0))),false); }; - break; - - - case 111: /* ClassBodyDeclaration: STATIC Block */ - if (yyn == 111) - /* "src/main/resources/Java_16_Grammar.y":531 */ - { yyval = new ClassInitializer(((tree.Statement.Block)(yystack.valueAt (0))),true); }; - break; - - - case 112: /* ClassBodyDeclaration: SEMICOLON */ - if (yyn == 112) - /* "src/main/resources/Java_16_Grammar.y":532 */ - { yyval = null; }; - break; - - - case 113: /* PureBodyDeclaration: FieldDeclaration */ - if (yyn == 113) - /* "src/main/resources/Java_16_Grammar.y":536 */ - { yyval = ((tree.Declaration.Declaration)(yystack.valueAt (0))); }; - break; - - - case 114: /* PureBodyDeclaration: MethodDeclaration */ - if (yyn == 114) - /* "src/main/resources/Java_16_Grammar.y":537 */ - { yyval = ((tree.Declaration.Declaration)(yystack.valueAt (0))); }; - break; - - - case 115: /* PureBodyDeclaration: ClassDeclaration */ - if (yyn == 115) - /* "src/main/resources/Java_16_Grammar.y":538 */ - { yyval = ((ClassDeclaration)(yystack.valueAt (0))); }; - break; - - - case 116: /* PureBodyDeclaration: InterfaceDeclaration */ - if (yyn == 116) - /* "src/main/resources/Java_16_Grammar.y":539 */ - { yyval = ((InterfaceDeclaration)(yystack.valueAt (0))); }; - break; - - - case 117: /* PureBodyDeclaration: ConstructorDeclaration */ - if (yyn == 117) - /* "src/main/resources/Java_16_Grammar.y":540 */ - { yyval = ((ConstructorDeclaration)(yystack.valueAt (0))); }; - break; - - - case 118: /* ConstructorDeclaration: ConstructorDeclarator ThrowsOpt ConstructorBody */ - if (yyn == 118) - /* "src/main/resources/Java_16_Grammar.y":547 */ - { yyval = new ConstructorDeclaration(null,((ConstructorDeclarator)(yystack.valueAt (2))).typeParameters,((ConstructorDeclarator)(yystack.valueAt (2))).formalParameters, - ((tree.Type.TypeList)(yystack.valueAt (1))),((ConstructorBody)(yystack.valueAt (0))).invocation,((ConstructorBody)(yystack.valueAt (0))).block); }; - break; - - - case 119: /* ConstructorDeclarator: TypeParametersOpt IDENTIFIER LPAREN FormalParameterList RPAREN */ - if (yyn == 119) - /* "src/main/resources/Java_16_Grammar.y":553 */ - { yyval = new ConstructorDeclarator(((TypeParameters)(yystack.valueAt (4))),((ParameterDeclarations)(yystack.valueAt (1)))); }; - break; - - - case 120: /* ConstructorBody: LBRACE RBRACE */ - if (yyn == 120) - /* "src/main/resources/Java_16_Grammar.y":557 */ - { yyval = new ConstructorBody(null,null); }; - break; - - - case 121: /* ConstructorBody: LBRACE ExplicitConstructorInvocation RBRACE */ - if (yyn == 121) - /* "src/main/resources/Java_16_Grammar.y":558 */ - { yyval = new ConstructorBody(((ExplicitConstructorInvocation)(yystack.valueAt (1))),null); }; - break; - - - case 122: /* ConstructorBody: LBRACE BlockStatementSeq RBRACE */ - if (yyn == 122) - /* "src/main/resources/Java_16_Grammar.y":559 */ - { yyval = new ConstructorBody(null,new Block(null,((tree.Statement.BlockStatements)(yystack.valueAt (1))))); }; - break; - - - case 123: /* ConstructorBody: LBRACE ExplicitConstructorInvocation BlockStatementSeq RBRACE */ - if (yyn == 123) - /* "src/main/resources/Java_16_Grammar.y":560 */ - { yyval = new ConstructorBody(((ExplicitConstructorInvocation)(yystack.valueAt (2))),new Block(null,((tree.Statement.BlockStatements)(yystack.valueAt (1))))); }; - break; - - - case 124: /* ExplicitConstructorInvocation: TypeArgumentsOpt THIS Arguments SEMICOLON */ - if (yyn == 124) - /* "src/main/resources/Java_16_Grammar.y":564 */ - { yyval = new ExplicitConstructorInvocation(null,((tree.Type.TypeArguments)(yystack.valueAt (3))),false,((tree.Expression.ArgumentList)(yystack.valueAt (1)))); }; - break; - - - case 125: /* ExplicitConstructorInvocation: TypeArgumentsOpt SUPER Arguments SEMICOLON */ - if (yyn == 125) - /* "src/main/resources/Java_16_Grammar.y":565 */ - { yyval = new ExplicitConstructorInvocation(null,((tree.Type.TypeArguments)(yystack.valueAt (3))),true,((tree.Expression.ArgumentList)(yystack.valueAt (1)))); }; - break; - - - case 126: /* ExplicitConstructorInvocation: CompoundName DOT TypeArgumentsOpt SUPER Arguments SEMICOLON */ - if (yyn == 126) - /* "src/main/resources/Java_16_Grammar.y":566 */ - { Expression expr = new SimpleReference(((CompoundName)(yystack.valueAt (5)))); - yyval = new ExplicitConstructorInvocation(expr,((tree.Type.TypeArguments)(yystack.valueAt (3))),true,((tree.Expression.ArgumentList)(yystack.valueAt (1)))); }; - break; - - - case 127: /* ExplicitConstructorInvocation: Primary DOT TypeArgumentsOpt SUPER Arguments SEMICOLON */ - if (yyn == 127) - /* "src/main/resources/Java_16_Grammar.y":568 */ - { yyval = new ExplicitConstructorInvocation(((tree.Expression.Expression)(yystack.valueAt (5))),((tree.Type.TypeArguments)(yystack.valueAt (3))),true,((tree.Expression.ArgumentList)(yystack.valueAt (1)))); }; - break; - - - case 128: /* EnumDeclaration: ENUM IDENTIFIER ClassImplementsOpt EnumBody */ - if (yyn == 128) - /* "src/main/resources/Java_16_Grammar.y":574 */ - { yyval = null; }; - break; - - - case 139: /* RecordDeclaration: RECORD IDENTIFIER TypeParametersOpt RecordHeader ClassImplementsOpt RecordBody */ - if (yyn == 139) - /* "src/main/resources/Java_16_Grammar.y":602 */ - { yyval = null; }; - break; - - - case 152: /* FieldDeclaration: UnannotatedType VariableDeclaratorList SEMICOLON */ - if (yyn == 152) - /* "src/main/resources/Java_16_Grammar.y":638 */ - { yyval = new TypeAndDeclarators(((tree.Type.UnannotatedType)(yystack.valueAt (2))),((VariableDeclarators)(yystack.valueAt (1)))); }; - break; - - - case 153: /* VariableDeclaratorList: VariableDeclarator */ - if (yyn == 153) - /* "src/main/resources/Java_16_Grammar.y":642 */ - { yyval = new VariableDeclarators(((VariableDeclarator)(yystack.valueAt (0)))); }; - break; - - - case 154: /* VariableDeclaratorList: VariableDeclaratorList COMMA VariableDeclarator */ - if (yyn == 154) - /* "src/main/resources/Java_16_Grammar.y":643 */ - { yyval = ((VariableDeclarators)(yystack.valueAt (2))).add(((VariableDeclarator)(yystack.valueAt (0)))); }; - break; - - - case 155: /* VariableDeclarator: IDENTIFIER */ - if (yyn == 155) - /* "src/main/resources/Java_16_Grammar.y":647 */ - { yyval = new VariableDeclarator(((Token)(yystack.valueAt (0))),null,null); }; - break; - - - case 156: /* VariableDeclarator: IDENTIFIER EQUAL Expression */ - if (yyn == 156) - /* "src/main/resources/Java_16_Grammar.y":648 */ - { yyval = new VariableDeclarator(((Token)(yystack.valueAt (2))),null,new InitializerSimple(((tree.Expression.Expression)(yystack.valueAt (0))))); }; - break; - - - case 157: /* VariableDeclarator: IDENTIFIER Dims */ - if (yyn == 157) - /* "src/main/resources/Java_16_Grammar.y":649 */ - { yyval = new VariableDeclarator(((Token)(yystack.valueAt (1))),((Dims)(yystack.valueAt (0))),null); }; - break; - - - case 158: /* VariableDeclarator: IDENTIFIER Dims EQUAL ArrayInitializer */ - if (yyn == 158) - /* "src/main/resources/Java_16_Grammar.y":650 */ - { yyval = new VariableDeclarator(((Token)(yystack.valueAt (3))),((Dims)(yystack.valueAt (2))),((InitializerArray)(yystack.valueAt (0)))); }; - break; - - - case 159: /* ArrayInitializer: LBRACE VariableInitializerListOpt RBRACE */ - if (yyn == 159) - /* "src/main/resources/Java_16_Grammar.y":654 */ - { yyval = ((InitializerArray)(yystack.valueAt (1))); }; - break; - - - case 160: /* ArrayInitializer: LBRACE VariableInitializerListOpt COMMA RBRACE */ - if (yyn == 160) - /* "src/main/resources/Java_16_Grammar.y":655 */ - { yyval = ((InitializerArray)(yystack.valueAt (2))); }; - break; - - - case 161: /* VariableInitializerListOpt: %empty */ - if (yyn == 161) - /* "src/main/resources/Java_16_Grammar.y":659 */ - { yyval = null; }; - break; - - - case 162: /* VariableInitializerListOpt: VariableInitializerList */ - if (yyn == 162) - /* "src/main/resources/Java_16_Grammar.y":660 */ - { yyval = ((InitializerArray)(yystack.valueAt (0))); }; - break; - - - case 163: /* VariableInitializerList: VariableInitializer */ - if (yyn == 163) - /* "src/main/resources/Java_16_Grammar.y":664 */ - { yyval = new InitializerArray(((InitializerSimple)(yystack.valueAt (0)))); }; - break; - - - case 164: /* VariableInitializerList: VariableInitializerList COMMA VariableInitializer */ - if (yyn == 164) - /* "src/main/resources/Java_16_Grammar.y":665 */ - { yyval = ((InitializerArray)(yystack.valueAt (2))).add(((InitializerSimple)(yystack.valueAt (0)))); }; - break; - - - case 165: /* VariableInitializer: Expression */ - if (yyn == 165) - /* "src/main/resources/Java_16_Grammar.y":669 */ - { yyval = new InitializerSimple(((tree.Expression.Expression)(yystack.valueAt (0)))); }; - break; - - - case 166: /* VariableInitializer: ArrayInitializer */ - if (yyn == 166) - /* "src/main/resources/Java_16_Grammar.y":670 */ - { yyval = ((InitializerArray)(yystack.valueAt (0))); }; - break; - - - case 167: /* MethodDeclaration: MethodHeader MethodBody */ - if (yyn == 167) - /* "src/main/resources/Java_16_Grammar.y":676 */ - { yyval = new MethodDeclaration(((MethodHeader)(yystack.valueAt (1))),((tree.Statement.Block)(yystack.valueAt (0)))); }; - break; - - - case 168: /* MethodHeader: TypeParameters Type MethodDeclarator ThrowsOpt */ - if (yyn == 168) - /* "src/main/resources/Java_16_Grammar.y":686 */ - { yyval = new MethodHeader(((TypeParameters)(yystack.valueAt (3))),((tree.Type.Type)(yystack.valueAt (2))),((MethodDeclarator)(yystack.valueAt (1))),((tree.Type.TypeList)(yystack.valueAt (0)))); }; - break; - - - case 169: /* MethodHeader: TypeParameters AnnotationSeq VOID MethodDeclarator ThrowsOpt */ - if (yyn == 169) - /* "src/main/resources/Java_16_Grammar.y":687 */ - { yyval = new MethodHeader(((TypeParameters)(yystack.valueAt (4))),null,((MethodDeclarator)(yystack.valueAt (1))),((tree.Type.TypeList)(yystack.valueAt (0)))); }; - break; - - - case 170: /* MethodHeader: TypeParameters UnannotatedType MethodDeclarator ThrowsOpt */ - if (yyn == 170) - /* "src/main/resources/Java_16_Grammar.y":688 */ - { yyval = new MethodHeader(((TypeParameters)(yystack.valueAt (3))),((tree.Type.UnannotatedType)(yystack.valueAt (2))),((MethodDeclarator)(yystack.valueAt (1))),((tree.Type.TypeList)(yystack.valueAt (0)))); }; - break; - - - case 171: /* MethodHeader: TypeParameters VOID MethodDeclarator ThrowsOpt */ - if (yyn == 171) - /* "src/main/resources/Java_16_Grammar.y":689 */ - { yyval = new MethodHeader(((TypeParameters)(yystack.valueAt (3))),null,((MethodDeclarator)(yystack.valueAt (1))),((tree.Type.TypeList)(yystack.valueAt (0)))); }; - break; - - - case 172: /* MethodHeader: UnannotatedType MethodDeclarator ThrowsOpt */ - if (yyn == 172) - /* "src/main/resources/Java_16_Grammar.y":690 */ - { yyval = new MethodHeader(null,((tree.Type.UnannotatedType)(yystack.valueAt (2))),((MethodDeclarator)(yystack.valueAt (1))),((tree.Type.TypeList)(yystack.valueAt (0)))); }; - break; - - - case 173: /* MethodHeader: VOID MethodDeclarator ThrowsOpt */ - if (yyn == 173) - /* "src/main/resources/Java_16_Grammar.y":691 */ - { yyval = new MethodHeader(null,null,((MethodDeclarator)(yystack.valueAt (1))),((tree.Type.TypeList)(yystack.valueAt (0)))); }; - break; - - - case 174: /* MethodDeclarator: IDENTIFIER LPAREN RPAREN DimsOpt */ - if (yyn == 174) - /* "src/main/resources/Java_16_Grammar.y":700 */ - { yyval = new MethodDeclarator(((Token)(yystack.valueAt (3))),null,((Dims)(yystack.valueAt (0)))); }; - break; - - - case 175: /* MethodDeclarator: IDENTIFIER LPAREN FormalParameterList RPAREN DimsOpt */ - if (yyn == 175) - /* "src/main/resources/Java_16_Grammar.y":701 */ - { yyval = new MethodDeclarator(((Token)(yystack.valueAt (4))),((ParameterDeclarations)(yystack.valueAt (2))),((Dims)(yystack.valueAt (0)))); }; - break; - - - case 176: /* FormalParameterList: FormalParameter */ - if (yyn == 176) - /* "src/main/resources/Java_16_Grammar.y":715 */ - { yyval = new ParameterDeclarations(((ParameterDeclaration)(yystack.valueAt (0)))); }; - break; - - - case 177: /* FormalParameterList: FormalParameterList COMMA FormalParameter */ - if (yyn == 177) - /* "src/main/resources/Java_16_Grammar.y":716 */ - { yyval = ((ParameterDeclarations)(yystack.valueAt (2))).add(((ParameterDeclaration)(yystack.valueAt (0))));}; - break; - - - case 178: /* FormalParameter: ModifierSeq UnannotatedType FormalParameterTail */ - if (yyn == 178) - /* "src/main/resources/Java_16_Grammar.y":720 */ - { yyval = ParameterDeclaration.create(((Modifiers)(yystack.valueAt (2))),((tree.Type.UnannotatedType)(yystack.valueAt (1))),((ParameterTail)(yystack.valueAt (0)))); }; - break; - - - case 179: /* FormalParameter: UnannotatedType FormalParameterTail */ - if (yyn == 179) - /* "src/main/resources/Java_16_Grammar.y":721 */ - { yyval = ParameterDeclaration.create(null,((tree.Type.UnannotatedType)(yystack.valueAt (1))),((ParameterTail)(yystack.valueAt (0)))); }; - break; - - - case 180: /* FormalParameterTail: IDENTIFIER DimsOpt */ - if (yyn == 180) - /* "src/main/resources/Java_16_Grammar.y":725 */ - { yyval = new ParameterTail(null,((Token)(yystack.valueAt (1))),((Dims)(yystack.valueAt (0))),false,false); }; - break; - - - case 181: /* FormalParameterTail: AnnotationSeqOpt ELLIPSIS IDENTIFIER */ - if (yyn == 181) - /* "src/main/resources/Java_16_Grammar.y":726 */ - { yyval = new ParameterTail(((Annotations)(yystack.valueAt (2))),((Token)(yystack.valueAt (0))),null,true,false); }; - break; - - - case 182: /* FormalParameterTail: THIS */ - if (yyn == 182) - /* "src/main/resources/Java_16_Grammar.y":727 */ - { yyval = new ParameterTail(null,null,null,false,true); }; - break; - - - case 183: /* FormalParameterTail: IDENTIFIER DOT THIS */ - if (yyn == 183) - /* "src/main/resources/Java_16_Grammar.y":728 */ - { yyval = new ParameterTail(null,((Token)(yystack.valueAt (2))),null,false,true); }; - break; - - - case 184: /* ThrowsOpt: %empty */ - if (yyn == 184) - /* "src/main/resources/Java_16_Grammar.y":740 */ - { yyval = null; }; - break; - - - case 185: /* ThrowsOpt: THROWS ClassTypeList1 */ - if (yyn == 185) - /* "src/main/resources/Java_16_Grammar.y":741 */ - { yyval = ((tree.Type.TypeList)(yystack.valueAt (0))); }; - break; - - - case 186: /* MethodBody: Block */ - if (yyn == 186) - /* "src/main/resources/Java_16_Grammar.y":745 */ - { yyval = ((tree.Statement.Block)(yystack.valueAt (0))); }; - break; - - - case 187: /* MethodBody: SEMICOLON */ - if (yyn == 187) - /* "src/main/resources/Java_16_Grammar.y":746 */ - { yyval = null; }; - break; - - - case 188: /* DimsOpt: %empty */ - if (yyn == 188) - /* "src/main/resources/Java_16_Grammar.y":752 */ - { yyval = null; }; - break; - - - case 189: /* DimsOpt: Dims */ - if (yyn == 189) - /* "src/main/resources/Java_16_Grammar.y":753 */ - { yyval = ((Dims)(yystack.valueAt (0))); }; - break; - - - case 190: /* Dims: Dim */ - if (yyn == 190) - /* "src/main/resources/Java_16_Grammar.y":757 */ - { yyval = new Dims(((Dim)(yystack.valueAt (0)))); }; - break; - - - case 191: /* Dims: Dims Dim */ - if (yyn == 191) - /* "src/main/resources/Java_16_Grammar.y":758 */ - { yyval = ((Dims)(yystack.valueAt (1))).add(((Dim)(yystack.valueAt (0)))); }; - break; - - - case 192: /* Dim: AnnotationSeq LBRACKET RBRACKET */ - if (yyn == 192) - /* "src/main/resources/Java_16_Grammar.y":762 */ - { yyval = new Dim(((Annotations)(yystack.valueAt (2)))); }; - break; - - - case 193: /* Dim: LBRACKET RBRACKET */ - if (yyn == 193) - /* "src/main/resources/Java_16_Grammar.y":763 */ - { yyval = new Dim(null); }; - break; - - - case 194: /* InterfaceDeclaration: NormalInterfaceDeclaration */ - if (yyn == 194) - /* "src/main/resources/Java_16_Grammar.y":769 */ - { yyval = ((InterfaceDeclaration)(yystack.valueAt (0))); }; - break; - - - case 195: /* InterfaceDeclaration: AnnotationInterfaceDeclaration */ - if (yyn == 195) - /* "src/main/resources/Java_16_Grammar.y":770 */ - { yyval = null; }; - break; - - - case 196: /* NormalInterfaceDeclaration: INTERFACE IDENTIFIER TypeParametersOpt InterfaceExtendsOpt InterfaceBody */ - if (yyn == 196) - /* "src/main/resources/Java_16_Grammar.y":775 */ - { yyval = new NormalInterfaceDeclaration(((Token)(yystack.valueAt (3))),((TypeParameters)(yystack.valueAt (2))),((tree.Type.TypeList)(yystack.valueAt (1))),((Declarations)(yystack.valueAt (0)))); }; - break; - - - case 197: /* InterfaceExtendsOpt: %empty */ - if (yyn == 197) - /* "src/main/resources/Java_16_Grammar.y":779 */ - { yyval = null; }; - break; - - - case 198: /* InterfaceExtendsOpt: InterfaceExtends */ - if (yyn == 198) - /* "src/main/resources/Java_16_Grammar.y":780 */ - { yyval = ((tree.Type.TypeList)(yystack.valueAt (0))); }; - break; - - - case 199: /* InterfaceExtends: EXTENDS Type */ - if (yyn == 199) - /* "src/main/resources/Java_16_Grammar.y":784 */ - { yyval = new TypeList(((tree.Type.Type)(yystack.valueAt (0)))); }; - break; - - - case 200: /* InterfaceExtends: InterfaceExtends COMMA Type */ - if (yyn == 200) - /* "src/main/resources/Java_16_Grammar.y":785 */ - { yyval = ((tree.Type.TypeList)(yystack.valueAt (2))).add(((tree.Type.Type)(yystack.valueAt (0)))); }; - break; - - - case 201: /* InterfaceBody: LBRACE RBRACE */ - if (yyn == 201) - /* "src/main/resources/Java_16_Grammar.y":789 */ - { yyval = null; }; - break; - - - case 202: /* InterfaceBody: LBRACE InterfaceMemberDeclarationSeq RBRACE */ - if (yyn == 202) - /* "src/main/resources/Java_16_Grammar.y":790 */ - { yyval = ((Declarations)(yystack.valueAt (1))); }; - break; - - - case 203: /* InterfaceMemberDeclarationSeq: ModifierSeqOpt InterfaceMemberDeclaration */ - if (yyn == 203) - /* "src/main/resources/Java_16_Grammar.y":794 */ - { yyval = new Declarations(((tree.Declaration.Declaration)(yystack.valueAt (0))).addModifiers(((Modifiers)(yystack.valueAt (1))))); }; - break; - - - case 204: /* InterfaceMemberDeclarationSeq: InterfaceMemberDeclarationSeq ModifierSeqOpt InterfaceMemberDeclaration */ - if (yyn == 204) - /* "src/main/resources/Java_16_Grammar.y":795 */ - { yyval = ((Declarations)(yystack.valueAt (2))).add(((tree.Declaration.Declaration)(yystack.valueAt (0))).addModifiers(((Modifiers)(yystack.valueAt (1))))); }; - break; - - - case 205: /* InterfaceMemberDeclaration: ConstantDeclaration */ - if (yyn == 205) - /* "src/main/resources/Java_16_Grammar.y":799 */ - { yyval = ((tree.Declaration.Declaration)(yystack.valueAt (0))); }; - break; - - - case 206: /* InterfaceMemberDeclaration: InterfaceMethodDeclaration */ - if (yyn == 206) - /* "src/main/resources/Java_16_Grammar.y":800 */ - { yyval = ((tree.Declaration.Declaration)(yystack.valueAt (0))); }; - break; - - - case 207: /* InterfaceMemberDeclaration: ClassDeclaration */ - if (yyn == 207) - /* "src/main/resources/Java_16_Grammar.y":801 */ - { yyval = ((ClassDeclaration)(yystack.valueAt (0))); }; - break; - - - case 208: /* InterfaceMemberDeclaration: InterfaceDeclaration */ - if (yyn == 208) - /* "src/main/resources/Java_16_Grammar.y":802 */ - { yyval = ((InterfaceDeclaration)(yystack.valueAt (0))); }; - break; - - - case 209: /* ConstantDeclaration: Type VariableDeclaratorList SEMICOLON */ - if (yyn == 209) - /* "src/main/resources/Java_16_Grammar.y":806 */ - { yyval = new TypeAndDeclarators(((tree.Type.Type)(yystack.valueAt (2))),((VariableDeclarators)(yystack.valueAt (1)))); }; - break; - - - case 210: /* InterfaceMethodDeclaration: MethodHeader MethodBody */ - if (yyn == 210) - /* "src/main/resources/Java_16_Grammar.y":810 */ - { yyval = null; }; - break; - - - case 211: /* AnnotationInterfaceDeclaration: AT INTERFACE IDENTIFIER AnnotationInterfaceBody */ - if (yyn == 211) - /* "src/main/resources/Java_16_Grammar.y":814 */ - { yyval = null; }; - break; - - - case 223: /* Block: LBRACE RBRACE */ - if (yyn == 223) - /* "src/main/resources/Java_16_Grammar.y":846 */ - { yyval = null; }; - break; - - - case 224: /* Block: LBRACE BlockStatementSeq RBRACE */ - if (yyn == 224) - /* "src/main/resources/Java_16_Grammar.y":847 */ - { yyval = new Block(null,((tree.Statement.BlockStatements)(yystack.valueAt (1)))); }; - break; - - - case 225: /* BlockStatementSeq: BlockStatement */ - if (yyn == 225) - /* "src/main/resources/Java_16_Grammar.y":851 */ - { yyval = new BlockStatements(((tree.Statement.BlockStatement)(yystack.valueAt (0)))); }; - break; - - - case 226: /* BlockStatementSeq: BlockStatementSeq BlockStatement */ - if (yyn == 226) - /* "src/main/resources/Java_16_Grammar.y":852 */ - { yyval = ((tree.Statement.BlockStatements)(yystack.valueAt (1))).add(((tree.Statement.BlockStatement)(yystack.valueAt (0)))); }; - break; - - - case 227: /* BlockStatement: ModifierSeqOpt BlockDeclaration */ - if (yyn == 227) - /* "src/main/resources/Java_16_Grammar.y":856 */ - { yyval = new BlockStatement(((tree.Declaration.Declaration)(yystack.valueAt (0))).addModifiers(((Modifiers)(yystack.valueAt (1))))); }; - break; - - - case 228: /* BlockStatement: Statement */ - if (yyn == 228) - /* "src/main/resources/Java_16_Grammar.y":857 */ - { yyval = new BlockStatement(((tree.Statement.Statement)(yystack.valueAt (0)))); }; - break; - - - case 229: /* BlockDeclaration: ClassDeclaration */ - if (yyn == 229) - /* "src/main/resources/Java_16_Grammar.y":861 */ - { yyval = ((ClassDeclaration)(yystack.valueAt (0))); }; - break; - - - case 230: /* BlockDeclaration: NormalInterfaceDeclaration */ - if (yyn == 230) - /* "src/main/resources/Java_16_Grammar.y":862 */ - { yyval = ((InterfaceDeclaration)(yystack.valueAt (0))); }; - break; - - - case 231: /* BlockDeclaration: LocalVariableDeclaration SEMICOLON */ - if (yyn == 231) - /* "src/main/resources/Java_16_Grammar.y":863 */ - { yyval = ((tree.Declaration.Declaration)(yystack.valueAt (1))); }; - break; - - - case 232: /* LocalVariableDeclaration: UnannotatedType VariableDeclaratorList */ - if (yyn == 232) - /* "src/main/resources/Java_16_Grammar.y":867 */ - { yyval = new TypeAndDeclarators(((tree.Type.UnannotatedType)(yystack.valueAt (1))),((VariableDeclarators)(yystack.valueAt (0)))); }; - break; - - - case 233: /* LocalVariableDeclaration: VAR VariableDeclaratorList */ - if (yyn == 233) - /* "src/main/resources/Java_16_Grammar.y":868 */ - { yyval = new TypeAndDeclarators(null,((VariableDeclarators)(yystack.valueAt (0)))); }; - break; - - - case 239: /* SimpleStatement: Block */ - if (yyn == 239) - /* "src/main/resources/Java_16_Grammar.y":880 */ - { yyval = ((tree.Statement.Block)(yystack.valueAt (0))); }; - break; - - - case 240: /* SimpleStatement: SEMICOLON */ - if (yyn == 240) - /* "src/main/resources/Java_16_Grammar.y":881 */ - { yyval = null; }; - break; - - - case 241: /* SimpleStatement: StatementExpression SEMICOLON */ - if (yyn == 241) - /* "src/main/resources/Java_16_Grammar.y":882 */ - { yyval = ((StatementExpression)(yystack.valueAt (1))); }; - break; - - - case 242: /* SimpleStatement: ASSERT Expression SEMICOLON */ - if (yyn == 242) - /* "src/main/resources/Java_16_Grammar.y":884 */ - { yyval = new Assert(null,((tree.Expression.Expression)(yystack.valueAt (1))),null); }; - break; - - - case 243: /* SimpleStatement: ASSERT Expression COLON Expression SEMICOLON */ - if (yyn == 243) - /* "src/main/resources/Java_16_Grammar.y":885 */ - { yyval = new Assert(null,((tree.Expression.Expression)(yystack.valueAt (3))),((tree.Expression.Expression)(yystack.valueAt (1)))); }; - break; - - - case 244: /* SimpleStatement: SWITCH LPAREN Expression RPAREN SwitchBlock */ - if (yyn == 244) - /* "src/main/resources/Java_16_Grammar.y":887 */ - { yyval = null; }; - break; - - - case 245: /* SimpleStatement: DO Statement WHILE LPAREN Expression RPAREN SEMICOLON */ - if (yyn == 245) - /* "src/main/resources/Java_16_Grammar.y":888 */ - { yyval = new Do(null,((tree.Statement.Statement)(yystack.valueAt (5))),((tree.Expression.Expression)(yystack.valueAt (2)))); }; - break; - - - case 246: /* SimpleStatement: BREAK SEMICOLON */ - if (yyn == 246) - /* "src/main/resources/Java_16_Grammar.y":890 */ - { yyval = new Break(null,null); }; - break; - - - case 247: /* SimpleStatement: BREAK IDENTIFIER SEMICOLON */ - if (yyn == 247) - /* "src/main/resources/Java_16_Grammar.y":891 */ - { yyval = new Break(null,((Token)(yystack.valueAt (1)))); }; - break; - - - case 248: /* SimpleStatement: CONTINUE SEMICOLON */ - if (yyn == 248) - /* "src/main/resources/Java_16_Grammar.y":893 */ - { yyval = new Continue(null,null); }; - break; - - - case 249: /* SimpleStatement: CONTINUE IDENTIFIER SEMICOLON */ - if (yyn == 249) - /* "src/main/resources/Java_16_Grammar.y":894 */ - { yyval = new Continue(null,((Token)(yystack.valueAt (1)))); }; - break; - - - case 250: /* SimpleStatement: RETURN SEMICOLON */ - if (yyn == 250) - /* "src/main/resources/Java_16_Grammar.y":896 */ - { yyval = new Return(null,null); }; - break; - - - case 251: /* SimpleStatement: RETURN Expression SEMICOLON */ - if (yyn == 251) - /* "src/main/resources/Java_16_Grammar.y":897 */ - { yyval = new Return(null,((tree.Expression.Expression)(yystack.valueAt (1)))); }; - break; - - - case 252: /* SimpleStatement: SYNCHRONIZED LPAREN Expression RPAREN Block */ - if (yyn == 252) - /* "src/main/resources/Java_16_Grammar.y":899 */ - { yyval = new Synchronized(null,((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Statement.Block)(yystack.valueAt (0)))); }; - break; - - - case 253: /* SimpleStatement: THROW Expression SEMICOLON */ - if (yyn == 253) - /* "src/main/resources/Java_16_Grammar.y":901 */ - { yyval = new Throw(null,((tree.Expression.Expression)(yystack.valueAt (1)))); }; - break; - - - case 254: /* SimpleStatement: YIELD Expression SEMICOLON */ - if (yyn == 254) - /* "src/main/resources/Java_16_Grammar.y":902 */ - { yyval = new Yield(null,((tree.Expression.Expression)(yystack.valueAt (1)))); }; - break; - - - case 255: /* SimpleStatement: TRY Block Catches */ - if (yyn == 255) - /* "src/main/resources/Java_16_Grammar.y":905 */ - { yyval = null; }; - break; - - - case 256: /* SimpleStatement: TRY Block Catches Finally */ - if (yyn == 256) - /* "src/main/resources/Java_16_Grammar.y":906 */ - { yyval = null; }; - break; - - - case 257: /* SimpleStatement: TRY Block Finally */ - if (yyn == 257) - /* "src/main/resources/Java_16_Grammar.y":907 */ - { yyval = null; }; - break; - - - case 258: /* SimpleStatement: TRY ResourceSpecification Block CatchesOpt FinallyOpt */ - if (yyn == 258) - /* "src/main/resources/Java_16_Grammar.y":909 */ - { yyval = null; }; - break; - - - case 259: /* LabeledStatement: IDENTIFIER COLON Statement */ - if (yyn == 259) - /* "src/main/resources/Java_16_Grammar.y":913 */ - { yyval = ((tree.Statement.Statement)(yystack.valueAt (0))).addLabel(((Token)(yystack.valueAt (2)))); }; - break; - - - case 260: /* StatementExpression: Assignment */ - if (yyn == 260) - /* "src/main/resources/Java_16_Grammar.y":917 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 261: /* StatementExpression: PreIncrementExpression */ - if (yyn == 261) - /* "src/main/resources/Java_16_Grammar.y":918 */ - { yyval = ((UnaryPrefix)(yystack.valueAt (0))); }; - break; - - - case 262: /* StatementExpression: PreDecrementExpression */ - if (yyn == 262) - /* "src/main/resources/Java_16_Grammar.y":919 */ - { yyval = ((UnaryPrefix)(yystack.valueAt (0))); }; - break; - - - case 263: /* StatementExpression: PostIncrementExpression */ - if (yyn == 263) - /* "src/main/resources/Java_16_Grammar.y":920 */ - { yyval = ((UnaryPostfix)(yystack.valueAt (0))); }; - break; - - - case 264: /* StatementExpression: PostDecrementExpression */ - if (yyn == 264) - /* "src/main/resources/Java_16_Grammar.y":921 */ - { yyval = ((UnaryPostfix)(yystack.valueAt (0))); }; - break; - - - case 265: /* StatementExpression: MethodInvocation */ - if (yyn == 265) - /* "src/main/resources/Java_16_Grammar.y":922 */ - { yyval = new StatementExpression(null,((tree.Expression.Expression)(yystack.valueAt (0)))); }; - break; - - - case 266: /* StatementExpression: ClassInstanceCreationExpression */ - if (yyn == 266) - /* "src/main/resources/Java_16_Grammar.y":923 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 267: /* IfThenElseStatement: IF LPAREN Expression RPAREN Statement ElsePartOpt */ - if (yyn == 267) - /* "src/main/resources/Java_16_Grammar.y":927 */ - { yyval = null; }; - break; - - - case 268: /* ElsePartOpt: %empty */ - if (yyn == 268) - /* "src/main/resources/Java_16_Grammar.y":931 */ - { yyval = null; }; - break; - - - case 269: /* ElsePartOpt: ELSE Statement */ - if (yyn == 269) - /* "src/main/resources/Java_16_Grammar.y":932 */ - { yyval = ((tree.Statement.Statement)(yystack.valueAt (0))); }; - break; - - - case 270: /* SwitchBlock: LBRACE SwitchRuleSeq RBRACE */ - if (yyn == 270) - /* "src/main/resources/Java_16_Grammar.y":936 */ - { yyval = null; }; - break; - - - case 271: /* SwitchBlock: LBRACE SwitchBlockStatementGroupSeqOpt RBRACE */ - if (yyn == 271) - /* "src/main/resources/Java_16_Grammar.y":937 */ - { yyval = null; }; - break; - - - case 272: /* SwitchBlock: LBRACE SwitchBlockStatementGroupSeqOpt SwitchLabelSeq RBRACE */ - if (yyn == 272) - /* "src/main/resources/Java_16_Grammar.y":938 */ - { yyval = null; }; - break; - - - case 273: /* SwitchRuleSeq: SwitchRule */ - if (yyn == 273) - /* "src/main/resources/Java_16_Grammar.y":942 */ - { yyval = new SwitchRules(((SwitchRule)(yystack.valueAt (0)))); }; - break; - - - case 274: /* SwitchRuleSeq: SwitchRuleSeq SwitchRule */ - if (yyn == 274) - /* "src/main/resources/Java_16_Grammar.y":943 */ - { yyval = ((SwitchRules)(yystack.valueAt (1))).add(((SwitchRule)(yystack.valueAt (0)))); }; - break; - - - case 275: /* SwitchRule: SwitchLabel ARROW Expression SEMICOLON */ - if (yyn == 275) - /* "src/main/resources/Java_16_Grammar.y":947 */ - { yyval = new SwitchRule(((SwitchLabel)(yystack.valueAt (3))),((tree.Expression.Expression)(yystack.valueAt (1)))); }; - break; - - - case 276: /* SwitchRule: SwitchLabel ARROW Block */ - if (yyn == 276) - /* "src/main/resources/Java_16_Grammar.y":948 */ - { yyval = new SwitchRule(((SwitchLabel)(yystack.valueAt (2))),((tree.Statement.Block)(yystack.valueAt (0)))); }; - break; - - - case 277: /* SwitchRule: SwitchLabel ARROW THROW Expression SEMICOLON */ - if (yyn == 277) - /* "src/main/resources/Java_16_Grammar.y":949 */ - { yyval = new SwitchRule(((SwitchLabel)(yystack.valueAt (4))),new Throw(null,((tree.Expression.Expression)(yystack.valueAt (1))))); }; - break; - - - case 283: /* SwitchLabelSeq: SwitchLabel COLON */ - if (yyn == 283) - /* "src/main/resources/Java_16_Grammar.y":964 */ - { yyval = new SwitchLabels(((SwitchLabel)(yystack.valueAt (1)))); }; - break; - - - case 284: /* SwitchLabelSeq: SwitchLabelSeq SwitchLabel COLON */ - if (yyn == 284) - /* "src/main/resources/Java_16_Grammar.y":965 */ - { yyval = ((SwitchLabels)(yystack.valueAt (2))).add(((SwitchLabel)(yystack.valueAt (1)))); }; - break; - - - case 285: /* SwitchLabel: CASE CaseExpressionList */ - if (yyn == 285) - /* "src/main/resources/Java_16_Grammar.y":969 */ - { yyval = ((SwitchLabel)(yystack.valueAt (0))); }; - break; - - - case 286: /* SwitchLabel: DEFAULT */ - if (yyn == 286) - /* "src/main/resources/Java_16_Grammar.y":970 */ - { yyval = null; }; - break; - - - case 287: /* CaseExpressionList: AssignmentExpression */ - if (yyn == 287) - /* "src/main/resources/Java_16_Grammar.y":974 */ - { yyval = new SwitchLabel(((tree.Expression.Expression)(yystack.valueAt (0)))); }; - break; - - - case 288: /* CaseExpressionList: CaseExpressionList COMMA AssignmentExpression */ - if (yyn == 288) - /* "src/main/resources/Java_16_Grammar.y":975 */ - { yyval = ((SwitchLabel)(yystack.valueAt (2))).add(((tree.Expression.Expression)(yystack.valueAt (0)))); }; - break; - - - case 289: /* WhileStatement: WHILE LPAREN Expression RPAREN Statement */ - if (yyn == 289) - /* "src/main/resources/Java_16_Grammar.y":982 */ - { yyval = new While(null,((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Statement.Statement)(yystack.valueAt (0)))); }; - break; - - - case 290: /* ForStatement: BasicForStatement */ - if (yyn == 290) - /* "src/main/resources/Java_16_Grammar.y":986 */ - { yyval = ((tree.Statement.Statement)(yystack.valueAt (0))); }; - break; - - - case 291: /* ForStatement: EnhancedForStatement */ - if (yyn == 291) - /* "src/main/resources/Java_16_Grammar.y":987 */ - { yyval = ((tree.Statement.Statement)(yystack.valueAt (0))); }; - break; - - - case 292: /* BasicForStatement: FOR LPAREN ForInitOpt SEMICOLON ExpressionOpt SEMICOLON StatementExpressionListOpt RPAREN Statement */ - if (yyn == 292) - /* "src/main/resources/Java_16_Grammar.y":992 */ - { yyval = null; }; - break; - - - case 296: /* ExpressionOpt: %empty */ - if (yyn == 296) - /* "src/main/resources/Java_16_Grammar.y":1002 */ - { yyval = null; }; - break; - - - case 297: /* ExpressionOpt: Expression */ - if (yyn == 297) - /* "src/main/resources/Java_16_Grammar.y":1003 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 298: /* StatementExpressionList: StatementExpression */ - if (yyn == 298) - /* "src/main/resources/Java_16_Grammar.y":1010 */ - { yyval = ((StatementExpression)(yystack.valueAt (0))); }; - break; - - - case 299: /* StatementExpressionList: StatementExpressionList COMMA StatementExpression */ - if (yyn == 299) - /* "src/main/resources/Java_16_Grammar.y":1011 */ - { yyval = ((StatementExpressions)(yystack.valueAt (2))).add(((StatementExpression)(yystack.valueAt (0)))); }; - break; - - - case 300: /* StatementExpressionListOpt: %empty */ - if (yyn == 300) - /* "src/main/resources/Java_16_Grammar.y":1015 */ - { yyval = null; }; - break; - - - case 301: /* StatementExpressionListOpt: StatementExpressionList */ - if (yyn == 301) - /* "src/main/resources/Java_16_Grammar.y":1016 */ - { yyval = ((StatementExpressions)(yystack.valueAt (0))); }; - break; - - - case 302: /* EnhancedForStatement: FOR LPAREN LocalVariableDeclaration COLON Expression RPAREN Statement */ - if (yyn == 302) - /* "src/main/resources/Java_16_Grammar.y":1020 */ - { yyval = null; }; - break; - - - case 303: /* CatchesOpt: %empty */ - if (yyn == 303) - /* "src/main/resources/Java_16_Grammar.y":1024 */ - { yyval = null; }; - break; - - - case 304: /* CatchesOpt: Catches */ - if (yyn == 304) - /* "src/main/resources/Java_16_Grammar.y":1025 */ - { yyval = ((CatchClauses)(yystack.valueAt (0))); }; - break; - - - case 305: /* Catches: CatchClause */ - if (yyn == 305) - /* "src/main/resources/Java_16_Grammar.y":1029 */ - { yyval = new CatchClauses(((CatchClause)(yystack.valueAt (0)))); }; - break; - - - case 306: /* Catches: Catches CatchClause */ - if (yyn == 306) - /* "src/main/resources/Java_16_Grammar.y":1030 */ - { yyval = ((CatchClauses)(yystack.valueAt (1))).add(((CatchClause)(yystack.valueAt (0)))); }; - break; - - - case 307: /* CatchClause: CATCH LPAREN CatchFormalParameter RPAREN Block */ - if (yyn == 307) - /* "src/main/resources/Java_16_Grammar.y":1034 */ - { yyval = new CatchClause(((CatchParameter)(yystack.valueAt (2))),((tree.Statement.Block)(yystack.valueAt (0)))); }; - break; - - - case 308: /* CatchFormalParameter: ModifierSeqOpt CatchType IDENTIFIER DimsOpt */ - if (yyn == 308) - /* "src/main/resources/Java_16_Grammar.y":1038 */ - { yyval = new CatchParameter(((Modifiers)(yystack.valueAt (3))),((tree.Type.TypeList)(yystack.valueAt (2))),((Token)(yystack.valueAt (1))),((Dims)(yystack.valueAt (0)))); }; - break; - - - case 309: /* CatchType: Type */ - if (yyn == 309) - /* "src/main/resources/Java_16_Grammar.y":1042 */ - { yyval = new TypeList(((tree.Type.Type)(yystack.valueAt (0)))); }; - break; - - - case 310: /* CatchType: CatchType VERTICAL Type */ - if (yyn == 310) - /* "src/main/resources/Java_16_Grammar.y":1043 */ - { yyval = ((tree.Type.TypeList)(yystack.valueAt (2))).add(((tree.Type.Type)(yystack.valueAt (0)))); }; - break; - - - case 321: /* Primary: Literal */ - if (yyn == 321) - /* "src/main/resources/Java_16_Grammar.y":1080 */ - { yyval = new Literal(((Token)(yystack.valueAt (0)))); }; - break; - - - case 322: /* Primary: Type DimsOpt DOT CLASS */ - if (yyn == 322) - /* "src/main/resources/Java_16_Grammar.y":1081 */ - { yyval = new ClassLiteral(((tree.Type.Type)(yystack.valueAt (3))),((Dims)(yystack.valueAt (2)))); }; - break; - - - case 323: /* Primary: VOID DimsOpt DOT CLASS */ - if (yyn == 323) - /* "src/main/resources/Java_16_Grammar.y":1082 */ - { yyval = new ClassLiteral(null,((Dims)(yystack.valueAt (2)))); }; - break; - - - case 324: /* Primary: THIS */ - if (yyn == 324) - /* "src/main/resources/Java_16_Grammar.y":1083 */ - { yyval = new This(null); }; - break; - - - case 325: /* Primary: Type DOT THIS */ - if (yyn == 325) - /* "src/main/resources/Java_16_Grammar.y":1084 */ - { yyval = new This(((tree.Type.Type)(yystack.valueAt (2)))); }; - break; - - - case 326: /* Primary: LPAREN Expression RPAREN */ - if (yyn == 326) - /* "src/main/resources/Java_16_Grammar.y":1085 */ - { yyval = new Parenthesized(((tree.Expression.Expression)(yystack.valueAt (1)))); }; - break; - - - case 327: /* Primary: ClassInstanceCreationExpression */ - if (yyn == 327) - /* "src/main/resources/Java_16_Grammar.y":1086 */ - { yyval = null; }; - break; - - - case 328: /* Primary: FieldAccess */ - if (yyn == 328) - /* "src/main/resources/Java_16_Grammar.y":1087 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 329: /* Primary: ArrayAccess */ - if (yyn == 329) - /* "src/main/resources/Java_16_Grammar.y":1088 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 330: /* Primary: MethodInvocation */ - if (yyn == 330) - /* "src/main/resources/Java_16_Grammar.y":1089 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 331: /* Primary: MethodReference */ - if (yyn == 331) - /* "src/main/resources/Java_16_Grammar.y":1090 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 332: /* Primary: ArrayCreationExpression */ - if (yyn == 332) - /* "src/main/resources/Java_16_Grammar.y":1091 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 333: /* ClassInstanceCreationExpression: UnqualifiedClassInstanceCreationExpression */ - if (yyn == 333) - /* "src/main/resources/Java_16_Grammar.y":1101 */ - { yyval = null; }; - break; - - - case 334: /* ClassInstanceCreationExpression: CompoundName DOT UnqualifiedClassInstanceCreationExpression */ - if (yyn == 334) - /* "src/main/resources/Java_16_Grammar.y":1102 */ - { yyval = null; }; - break; - - - case 335: /* ClassInstanceCreationExpression: Primary DOT UnqualifiedClassInstanceCreationExpression */ - if (yyn == 335) - /* "src/main/resources/Java_16_Grammar.y":1103 */ - { yyval = null; }; - break; - - - case 341: /* TypeArgumentsOpt: %empty */ - if (yyn == 341) - /* "src/main/resources/Java_16_Grammar.y":1121 */ - { yyval = null; }; - break; - - - case 342: /* TypeArgumentsOpt: TypeArguments */ - if (yyn == 342) - /* "src/main/resources/Java_16_Grammar.y":1122 */ - { yyval = ((tree.Type.TypeArguments)(yystack.valueAt (0))); }; - break; - - - case 343: /* TypeArguments: LESS TypeArgumentList GREATER */ - if (yyn == 343) - /* "src/main/resources/Java_16_Grammar.y":1126 */ - { yyval = ((tree.Type.TypeArguments)(yystack.valueAt (1))); }; - break; - - - case 344: /* TypeArgumentList: TypeArgument */ - if (yyn == 344) - /* "src/main/resources/Java_16_Grammar.y":1130 */ - { yyval = new TypeArguments(((tree.Type.TypeArgument)(yystack.valueAt (0)))); }; - break; - - - case 345: /* TypeArgumentList: TypeArgumentList COMMA TypeArgument */ - if (yyn == 345) - /* "src/main/resources/Java_16_Grammar.y":1131 */ - { yyval = ((tree.Type.TypeArguments)(yystack.valueAt (2))).add(((tree.Type.TypeArgument)(yystack.valueAt (0)))); }; - break; - - - case 346: /* TypeArgument: Type */ - if (yyn == 346) - /* "src/main/resources/Java_16_Grammar.y":1135 */ - { yyval = new TypeArgument(((tree.Type.Type)(yystack.valueAt (0))),0,null); }; - break; - - - case 347: /* TypeArgument: QUESTION */ - if (yyn == 347) - /* "src/main/resources/Java_16_Grammar.y":1136 */ - { yyval = new TypeArgument(null,1,null); }; - break; - - - case 348: /* TypeArgument: QUESTION EXTENDS Type */ - if (yyn == 348) - /* "src/main/resources/Java_16_Grammar.y":1137 */ - { yyval = new TypeArgument(((tree.Type.Type)(yystack.valueAt (0))),1,null); }; - break; - - - case 349: /* TypeArgument: QUESTION SUPER Type */ - if (yyn == 349) - /* "src/main/resources/Java_16_Grammar.y":1138 */ - { yyval = new TypeArgument(((tree.Type.Type)(yystack.valueAt (0))),2,null); }; - break; - - - case 350: /* TypeArgument: AnnotationSeq QUESTION */ - if (yyn == 350) - /* "src/main/resources/Java_16_Grammar.y":1139 */ - { yyval = new TypeArgument(null,1,((Annotations)(yystack.valueAt (1)))); }; - break; - - - case 351: /* TypeArgument: AnnotationSeq QUESTION EXTENDS Type */ - if (yyn == 351) - /* "src/main/resources/Java_16_Grammar.y":1140 */ - { yyval = new TypeArgument(((tree.Type.Type)(yystack.valueAt (0))),2,((Annotations)(yystack.valueAt (3)))); }; - break; - - - case 352: /* TypeArgument: AnnotationSeq QUESTION SUPER Type */ - if (yyn == 352) - /* "src/main/resources/Java_16_Grammar.y":1141 */ - { yyval = new TypeArgument(((tree.Type.Type)(yystack.valueAt (0))),3,((Annotations)(yystack.valueAt (3)))); }; - break; - - - case 353: /* FieldAccess: Primary DOT IDENTIFIER */ - if (yyn == 353) - /* "src/main/resources/Java_16_Grammar.y":1151 */ - { yyval = new FieldAccess(((tree.Expression.Expression)(yystack.valueAt (2))), false,((Token)(yystack.valueAt (0)))); }; - break; - - - case 354: /* FieldAccess: SUPER DOT IDENTIFIER */ - if (yyn == 354) - /* "src/main/resources/Java_16_Grammar.y":1152 */ - { yyval = new FieldAccess(null,true, ((Token)(yystack.valueAt (0)))); }; - break; - - - case 355: /* FieldAccess: CompoundName DOT SUPER DOT IDENTIFIER */ - if (yyn == 355) - /* "src/main/resources/Java_16_Grammar.y":1153 */ - { yyval = new FieldAccess(new SimpleReference(((CompoundName)(yystack.valueAt (4)))),true,((Token)(yystack.valueAt (0)))); }; - break; - - - case 356: /* ArrayAccess: CompoundName LBRACKET Expression RBRACKET */ - if (yyn == 356) - /* "src/main/resources/Java_16_Grammar.y":1157 */ - { yyval = new ArrayAccess(new SimpleReference(((CompoundName)(yystack.valueAt (3)))),((tree.Expression.Expression)(yystack.valueAt (1)))); }; - break; - - - case 357: /* ArrayAccess: Primary LBRACKET Expression RBRACKET */ - if (yyn == 357) - /* "src/main/resources/Java_16_Grammar.y":1158 */ - { yyval = new ArrayAccess(((tree.Expression.Expression)(yystack.valueAt (3))),((tree.Expression.Expression)(yystack.valueAt (1)))); }; - break; - - - case 358: /* MethodInvocation: IDENTIFIER Arguments */ - if (yyn == 358) - /* "src/main/resources/Java_16_Grammar.y":1162 */ - { yyval = new MethodInvocation(null,false,null,((Token)(yystack.valueAt (1))),((tree.Expression.ArgumentList)(yystack.valueAt (0)))); }; - break; - - - case 359: /* MethodInvocation: IDENTIFIER DOT TypeArgumentsOpt CompoundName Arguments */ - if (yyn == 359) - /* "src/main/resources/Java_16_Grammar.y":1163 */ - { var ref = new SimpleReference(new CompoundName(((Token)(yystack.valueAt (4))).image)); - for (String s : ((CompoundName)(yystack.valueAt (1))).names) ref.compoundName.add(s); - ref.compoundName.names.remove(ref.compoundName.names.size() - 1); - yyval = new MethodInvocation(ref,false,((tree.Type.TypeArguments)(yystack.valueAt (2))), - new Token(TokenCode.Identifier, ((CompoundName)(yystack.valueAt (1))).names.get(((CompoundName)(yystack.valueAt (1))).names.size() - 1)),((tree.Expression.ArgumentList)(yystack.valueAt (0)))); }; - break; - - - case 360: /* MethodInvocation: Primary DOT TypeArgumentsOpt IDENTIFIER Arguments */ - if (yyn == 360) - /* "src/main/resources/Java_16_Grammar.y":1168 */ - { yyval = new MethodInvocation(((tree.Expression.Expression)(yystack.valueAt (4))),false,((tree.Type.TypeArguments)(yystack.valueAt (2))),((Token)(yystack.valueAt (1))),((tree.Expression.ArgumentList)(yystack.valueAt (0)))); }; - break; - - - case 361: /* MethodInvocation: SUPER DOT TypeArgumentsOpt IDENTIFIER Arguments */ - if (yyn == 361) - /* "src/main/resources/Java_16_Grammar.y":1169 */ - { yyval = new MethodInvocation(null,true,((tree.Type.TypeArguments)(yystack.valueAt (2))),((Token)(yystack.valueAt (1))),((tree.Expression.ArgumentList)(yystack.valueAt (0)))); }; - break; - - - case 362: /* MethodInvocation: CompoundName DOT SUPER DOT TypeArgumentsOpt IDENTIFIER Arguments */ - if (yyn == 362) - /* "src/main/resources/Java_16_Grammar.y":1170 */ - { var ref = new SimpleReference(((CompoundName)(yystack.valueAt (6)))); - yyval = new MethodInvocation(ref,true,((tree.Type.TypeArguments)(yystack.valueAt (2))),((Token)(yystack.valueAt (1))),((tree.Expression.ArgumentList)(yystack.valueAt (0)))); }; - break; - - - case 363: /* Arguments: LPAREN RPAREN */ - if (yyn == 363) - /* "src/main/resources/Java_16_Grammar.y":1175 */ - { yyval = null; }; - break; - - - case 364: /* Arguments: LPAREN ArgumentList RPAREN */ - if (yyn == 364) - /* "src/main/resources/Java_16_Grammar.y":1176 */ - { yyval = ((tree.Expression.ArgumentList)(yystack.valueAt (1))); }; - break; - - - case 365: /* ArgumentList: Expression */ - if (yyn == 365) - /* "src/main/resources/Java_16_Grammar.y":1185 */ - { yyval = new ArgumentList(((tree.Expression.Expression)(yystack.valueAt (0)))); }; - break; - - - case 366: /* ArgumentList: ArgumentList COMMA Expression */ - if (yyn == 366) - /* "src/main/resources/Java_16_Grammar.y":1186 */ - { yyval = ((tree.Expression.ArgumentList)(yystack.valueAt (2))).add(((tree.Expression.Expression)(yystack.valueAt (0)))); }; - break; - - - case 367: /* MethodReference: CompoundName DBL_COLON TypeArgumentsOpt IDENTIFIER */ - if (yyn == 367) - /* "src/main/resources/Java_16_Grammar.y":1190 */ - { yyval = null; }; - break; - - - case 368: /* MethodReference: Primary DBL_COLON TypeArgumentsOpt IDENTIFIER */ - if (yyn == 368) - /* "src/main/resources/Java_16_Grammar.y":1191 */ - { yyval = null; }; - break; - - - case 369: /* MethodReference: Type DBL_COLON TypeArgumentsOpt IDENTIFIER */ - if (yyn == 369) - /* "src/main/resources/Java_16_Grammar.y":1192 */ - { yyval = null; }; - break; - - - case 370: /* MethodReference: SUPER DBL_COLON TypeArgumentsOpt IDENTIFIER */ - if (yyn == 370) - /* "src/main/resources/Java_16_Grammar.y":1193 */ - { yyval = null; }; - break; - - - case 371: /* MethodReference: Type DOT SUPER DBL_COLON TypeArgumentsOpt IDENTIFIER */ - if (yyn == 371) - /* "src/main/resources/Java_16_Grammar.y":1194 */ - { yyval = null; }; - break; - - - case 372: /* MethodReference: Type DBL_COLON TypeArgumentsOpt NEW */ - if (yyn == 372) - /* "src/main/resources/Java_16_Grammar.y":1195 */ - { yyval = null; }; - break; - - - case 373: /* ArrayCreationExpression: NEW Type DimExprs DimsOpt */ - if (yyn == 373) - /* "src/main/resources/Java_16_Grammar.y":1199 */ - { yyval = null; }; - break; - - - case 374: /* ArrayCreationExpression: NEW Type Dims ArrayInitializer */ - if (yyn == 374) - /* "src/main/resources/Java_16_Grammar.y":1200 */ - { yyval = null; }; - break; - - - case 379: /* Expression: LambdaExpression */ - if (yyn == 379) - /* "src/main/resources/Java_16_Grammar.y":1216 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 380: /* Expression: AssignmentExpression */ - if (yyn == 380) - /* "src/main/resources/Java_16_Grammar.y":1217 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 381: /* LambdaExpression: IDENTIFIER ARROW Expression */ - if (yyn == 381) - /* "src/main/resources/Java_16_Grammar.y":1222 */ - { yyval = new Lambda(new ParameterDeclarations(new ParameterDeclaration(((Token)(yystack.valueAt (2))))),((tree.Expression.Expression)(yystack.valueAt (0)))); }; - break; - - - case 382: /* LambdaExpression: IDENTIFIER ARROW Block */ - if (yyn == 382) - /* "src/main/resources/Java_16_Grammar.y":1224 */ - { yyval = new Lambda(new ParameterDeclarations(new ParameterDeclaration(((Token)(yystack.valueAt (2))))),((tree.Statement.Block)(yystack.valueAt (0)))); }; - break; - - - case 383: /* LambdaExpression: LambdaParameters ARROW Expression */ - if (yyn == 383) - /* "src/main/resources/Java_16_Grammar.y":1225 */ - { yyval = new Lambda(((ParameterDeclarations)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0)))); }; - break; - - - case 384: /* LambdaExpression: LambdaParameters ARROW Block */ - if (yyn == 384) - /* "src/main/resources/Java_16_Grammar.y":1226 */ - { yyval = new Lambda(((ParameterDeclarations)(yystack.valueAt (2))),((tree.Statement.Block)(yystack.valueAt (0)))); }; - break; - - - case 385: /* LambdaParameters: LPAREN RPAREN */ - if (yyn == 385) - /* "src/main/resources/Java_16_Grammar.y":1235 */ - { yyval = null; }; - break; - - - case 386: /* LambdaParameters: LPAREN LambdaParameterList1 RPAREN */ - if (yyn == 386) - /* "src/main/resources/Java_16_Grammar.y":1236 */ - { yyval = ((ParameterDeclarations)(yystack.valueAt (1))); }; - break; - - - case 387: /* LambdaParameters: LPAREN LambdaParameterList2 RPAREN */ - if (yyn == 387) - /* "src/main/resources/Java_16_Grammar.y":1237 */ - { yyval = ((ParameterDeclarations)(yystack.valueAt (1))); }; - break; - - - case 388: /* LambdaParameterList1: IDENTIFIER */ - if (yyn == 388) - /* "src/main/resources/Java_16_Grammar.y":1242 */ - { yyval = new ParameterDeclarations(new ParameterDeclaration(((Token)(yystack.valueAt (0))))); }; - break; - - - case 389: /* LambdaParameterList1: LambdaParameterList1 COMMA IDENTIFIER */ - if (yyn == 389) - /* "src/main/resources/Java_16_Grammar.y":1243 */ - { yyval = ((ParameterDeclarations)(yystack.valueAt (2))).add(new ParameterDeclaration(((Token)(yystack.valueAt (0))))); }; - break; - - - case 390: /* LambdaParameterList2: LambdaParameter */ - if (yyn == 390) - /* "src/main/resources/Java_16_Grammar.y":1247 */ - { yyval = new ParameterDeclarations(((ParameterDeclaration)(yystack.valueAt (0)))); }; - break; - - - case 391: /* LambdaParameterList2: LambdaParameterList2 COMMA LambdaParameter */ - if (yyn == 391) - /* "src/main/resources/Java_16_Grammar.y":1248 */ - { yyval = ((ParameterDeclarations)(yystack.valueAt (2))).add(((ParameterDeclaration)(yystack.valueAt (0)))); }; - break; - - - case 392: /* LambdaParameter: ModifierSeqOpt UnannotatedType IDENTIFIER DimsOpt */ - if (yyn == 392) - /* "src/main/resources/Java_16_Grammar.y":1259 */ - { yyval = new ParameterDeclaration(((Modifiers)(yystack.valueAt (3))),((tree.Type.UnannotatedType)(yystack.valueAt (2))),((Token)(yystack.valueAt (1))).image,null,false,((Dims)(yystack.valueAt (0)))); }; - break; - - - case 393: /* LambdaParameter: ModifierSeqOpt VAR IDENTIFIER DimsOpt */ - if (yyn == 393) - /* "src/main/resources/Java_16_Grammar.y":1260 */ - { yyval = new ParameterDeclaration(((Modifiers)(yystack.valueAt (3))),null,((Token)(yystack.valueAt (1))).image,null,false,((Dims)(yystack.valueAt (0)))); }; - break; - - - case 394: /* LambdaParameter: ModifierSeqOpt UnannotatedType AnnotationSeqOpt ELLIPSIS IDENTIFIER */ - if (yyn == 394) - /* "src/main/resources/Java_16_Grammar.y":1262 */ - { yyval = new ParameterDeclaration(((Modifiers)(yystack.valueAt (4))),((tree.Type.UnannotatedType)(yystack.valueAt (3))),((Token)(yystack.valueAt (0))).image,((Annotations)(yystack.valueAt (2))),true,null); }; - break; - - - case 395: /* AssignmentExpression: ConditionalExpression */ - if (yyn == 395) - /* "src/main/resources/Java_16_Grammar.y":1272 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 396: /* AssignmentExpression: Assignment */ - if (yyn == 396) - /* "src/main/resources/Java_16_Grammar.y":1273 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 397: /* Assignment: LeftHandSide AssignmentOperator Expression */ - if (yyn == 397) - /* "src/main/resources/Java_16_Grammar.y":1277 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 398: /* LeftHandSide: CompoundName */ - if (yyn == 398) - /* "src/main/resources/Java_16_Grammar.y":1281 */ - { yyval = new SimpleReference(((CompoundName)(yystack.valueAt (0)))); }; - break; - - - case 399: /* LeftHandSide: FieldAccess */ - if (yyn == 399) - /* "src/main/resources/Java_16_Grammar.y":1282 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 400: /* LeftHandSide: ArrayAccess */ - if (yyn == 400) - /* "src/main/resources/Java_16_Grammar.y":1283 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 401: /* AssignmentOperator: EQUAL */ - if (yyn == 401) - /* "src/main/resources/Java_16_Grammar.y":1287 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 402: /* AssignmentOperator: STAR_EQUAL */ - if (yyn == 402) - /* "src/main/resources/Java_16_Grammar.y":1288 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 403: /* AssignmentOperator: SLASH_EQUAL */ - if (yyn == 403) - /* "src/main/resources/Java_16_Grammar.y":1289 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 404: /* AssignmentOperator: PERCENT_EQUAL */ - if (yyn == 404) - /* "src/main/resources/Java_16_Grammar.y":1290 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 405: /* AssignmentOperator: PLUS_EQUAL */ - if (yyn == 405) - /* "src/main/resources/Java_16_Grammar.y":1291 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 406: /* AssignmentOperator: MINUS_EQUAL */ - if (yyn == 406) - /* "src/main/resources/Java_16_Grammar.y":1292 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 407: /* AssignmentOperator: LESS_LESS_EQUAL */ - if (yyn == 407) - /* "src/main/resources/Java_16_Grammar.y":1293 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 408: /* AssignmentOperator: GR_GR_EQUAL */ - if (yyn == 408) - /* "src/main/resources/Java_16_Grammar.y":1294 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 409: /* AssignmentOperator: GR_GR_GR_EQUAL */ - if (yyn == 409) - /* "src/main/resources/Java_16_Grammar.y":1295 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 410: /* AssignmentOperator: AMP_EQUAL */ - if (yyn == 410) - /* "src/main/resources/Java_16_Grammar.y":1296 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 411: /* AssignmentOperator: CARET_EQUAL */ - if (yyn == 411) - /* "src/main/resources/Java_16_Grammar.y":1297 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 412: /* AssignmentOperator: VERTICAL_EQUAL */ - if (yyn == 412) - /* "src/main/resources/Java_16_Grammar.y":1298 */ - { yyval = ((Token)(yystack.valueAt (0))); }; - break; - - - case 413: /* ConditionalExpression: ConditionalOrExpression ConditionalOrTail */ - if (yyn == 413) - /* "src/main/resources/Java_16_Grammar.y":1302 */ - { if ( ((tree.Expression.Binary)(yystack.valueAt (0))) == null ) yyval = ((tree.Expression.Expression)(yystack.valueAt (1))); - else yyval = new Conditional(((tree.Expression.Expression)(yystack.valueAt (1))),((tree.Expression.Binary)(yystack.valueAt (0))).left,((tree.Expression.Binary)(yystack.valueAt (0))).right); }; - break; - - - case 414: /* ConditionalOrTail: %empty */ - if (yyn == 414) - /* "src/main/resources/Java_16_Grammar.y":1307 */ - { yyval = null; }; - break; - - - case 415: /* ConditionalOrTail: QUESTION Expression COLON ConditionalExpression */ - if (yyn == 415) - /* "src/main/resources/Java_16_Grammar.y":1308 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),null); }; - break; - - - case 416: /* ConditionalOrTail: QUESTION Expression COLON LambdaExpression */ - if (yyn == 416) - /* "src/main/resources/Java_16_Grammar.y":1309 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),null); }; - break; - - - case 417: /* ConditionalOrExpression: ConditionalAndExpression */ - if (yyn == 417) - /* "src/main/resources/Java_16_Grammar.y":1313 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 418: /* ConditionalOrExpression: ConditionalOrExpression DBL_VERTICAL ConditionalAndExpression */ - if (yyn == 418) - /* "src/main/resources/Java_16_Grammar.y":1314 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 419: /* ConditionalAndExpression: InclusiveOrExpression */ - if (yyn == 419) - /* "src/main/resources/Java_16_Grammar.y":1318 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 420: /* ConditionalAndExpression: ConditionalAndExpression DBL_AMPERSAND InclusiveOrExpression */ - if (yyn == 420) - /* "src/main/resources/Java_16_Grammar.y":1319 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 421: /* InclusiveOrExpression: ExclusiveOrExpression */ - if (yyn == 421) - /* "src/main/resources/Java_16_Grammar.y":1323 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 422: /* InclusiveOrExpression: InclusiveOrExpression VERTICAL ExclusiveOrExpression */ - if (yyn == 422) - /* "src/main/resources/Java_16_Grammar.y":1324 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 423: /* ExclusiveOrExpression: AndExpression */ - if (yyn == 423) - /* "src/main/resources/Java_16_Grammar.y":1328 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 424: /* ExclusiveOrExpression: ExclusiveOrExpression CARET AndExpression */ - if (yyn == 424) - /* "src/main/resources/Java_16_Grammar.y":1329 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 425: /* AndExpression: EqualityExpression */ - if (yyn == 425) - /* "src/main/resources/Java_16_Grammar.y":1333 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 426: /* AndExpression: AndExpression AMPERSAND EqualityExpression */ - if (yyn == 426) - /* "src/main/resources/Java_16_Grammar.y":1334 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 427: /* EqualityExpression: RelationalExpression */ - if (yyn == 427) - /* "src/main/resources/Java_16_Grammar.y":1338 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 428: /* EqualityExpression: EqualityExpression DBL_EQUAL RelationalExpression */ - if (yyn == 428) - /* "src/main/resources/Java_16_Grammar.y":1339 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 429: /* EqualityExpression: EqualityExpression NON_EQUAL RelationalExpression */ - if (yyn == 429) - /* "src/main/resources/Java_16_Grammar.y":1340 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 430: /* RelationalExpression: ShiftExpression */ - if (yyn == 430) - /* "src/main/resources/Java_16_Grammar.y":1344 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 431: /* RelationalExpression: RelationalExpression LESS ShiftExpression */ - if (yyn == 431) - /* "src/main/resources/Java_16_Grammar.y":1345 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 432: /* RelationalExpression: RelationalExpression GREATER ShiftExpression */ - if (yyn == 432) - /* "src/main/resources/Java_16_Grammar.y":1346 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 433: /* RelationalExpression: RelationalExpression LESS_EQUAL ShiftExpression */ - if (yyn == 433) - /* "src/main/resources/Java_16_Grammar.y":1347 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 434: /* RelationalExpression: RelationalExpression GREATER_EQUAL ShiftExpression */ - if (yyn == 434) - /* "src/main/resources/Java_16_Grammar.y":1348 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 435: /* RelationalExpression: InstanceofExpression */ - if (yyn == 435) - /* "src/main/resources/Java_16_Grammar.y":1349 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 436: /* InstanceofExpression: RelationalExpression INSTANCEOF Type */ - if (yyn == 436) - /* "src/main/resources/Java_16_Grammar.y":1353 */ - { yyval = new InstanceOf(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Type.Type)(yystack.valueAt (0)))); }; - break; - - - case 437: /* InstanceofExpression: RelationalExpression INSTANCEOF Pattern */ - if (yyn == 437) - /* "src/main/resources/Java_16_Grammar.y":1354 */ - { yyval = new InstanceOf(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Declaration.Declaration)(yystack.valueAt (0)))); }; - break; - - - case 438: /* ShiftExpression: AdditiveExpression */ - if (yyn == 438) - /* "src/main/resources/Java_16_Grammar.y":1358 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 439: /* ShiftExpression: ShiftExpression DBL_LESS AdditiveExpression */ - if (yyn == 439) - /* "src/main/resources/Java_16_Grammar.y":1359 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 440: /* ShiftExpression: ShiftExpression DBL_GREATER AdditiveExpression */ - if (yyn == 440) - /* "src/main/resources/Java_16_Grammar.y":1360 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 441: /* ShiftExpression: ShiftExpression TRIPL_GREATER AdditiveExpression */ - if (yyn == 441) - /* "src/main/resources/Java_16_Grammar.y":1361 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 442: /* AdditiveExpression: MultiplicativeExpression */ - if (yyn == 442) - /* "src/main/resources/Java_16_Grammar.y":1365 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 443: /* AdditiveExpression: AdditiveExpression PLUS MultiplicativeExpression */ - if (yyn == 443) - /* "src/main/resources/Java_16_Grammar.y":1366 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 444: /* AdditiveExpression: AdditiveExpression MINUS MultiplicativeExpression */ - if (yyn == 444) - /* "src/main/resources/Java_16_Grammar.y":1367 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 445: /* MultiplicativeExpression: UnaryExpression */ - if (yyn == 445) - /* "src/main/resources/Java_16_Grammar.y":1371 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 446: /* MultiplicativeExpression: MultiplicativeExpression STAR UnaryExpression */ - if (yyn == 446) - /* "src/main/resources/Java_16_Grammar.y":1372 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 447: /* MultiplicativeExpression: MultiplicativeExpression SLASH UnaryExpression */ - if (yyn == 447) - /* "src/main/resources/Java_16_Grammar.y":1373 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 448: /* MultiplicativeExpression: MultiplicativeExpression PERCENT UnaryExpression */ - if (yyn == 448) - /* "src/main/resources/Java_16_Grammar.y":1374 */ - { yyval = new Binary(((tree.Expression.Expression)(yystack.valueAt (2))),((tree.Expression.Expression)(yystack.valueAt (0))),((Token)(yystack.valueAt (1)))); }; - break; - - - case 449: /* UnaryExpression: PreIncrementExpression */ - if (yyn == 449) - /* "src/main/resources/Java_16_Grammar.y":1378 */ - { yyval = ((UnaryPrefix)(yystack.valueAt (0))); }; - break; - - - case 450: /* UnaryExpression: PreDecrementExpression */ - if (yyn == 450) - /* "src/main/resources/Java_16_Grammar.y":1379 */ - { yyval = ((UnaryPrefix)(yystack.valueAt (0))); }; - break; - - - case 451: /* UnaryExpression: PLUS UnaryExpression */ - if (yyn == 451) - /* "src/main/resources/Java_16_Grammar.y":1380 */ - { yyval = new UnaryPrefix(((Token)(yystack.valueAt (1))),((tree.Expression.Expression)(yystack.valueAt (0)))); }; - break; - - - case 452: /* UnaryExpression: MINUS UnaryExpression */ - if (yyn == 452) - /* "src/main/resources/Java_16_Grammar.y":1381 */ - { yyval = new UnaryPrefix(((Token)(yystack.valueAt (1))),((tree.Expression.Expression)(yystack.valueAt (0)))); }; - break; - - - case 453: /* UnaryExpression: UnaryExpressionNotPlusMinus */ - if (yyn == 453) - /* "src/main/resources/Java_16_Grammar.y":1382 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 454: /* PreIncrementExpression: DBL_PLUS UnaryExpression */ - if (yyn == 454) - /* "src/main/resources/Java_16_Grammar.y":1386 */ - { yyval = new UnaryPrefix(((Token)(yystack.valueAt (1))),((tree.Expression.Expression)(yystack.valueAt (0)))); }; - break; - - - case 455: /* PreDecrementExpression: DBL_MINUS UnaryExpression */ - if (yyn == 455) - /* "src/main/resources/Java_16_Grammar.y":1390 */ - { yyval = new UnaryPrefix(((Token)(yystack.valueAt (1))),((tree.Expression.Expression)(yystack.valueAt (0)))); }; - break; - - - case 457: /* UnaryExpressionNotPlusMinus: TILDE UnaryExpression */ - if (yyn == 457) - /* "src/main/resources/Java_16_Grammar.y":1395 */ - { yyval = new UnaryPrefix(((Token)(yystack.valueAt (1))),((tree.Expression.Expression)(yystack.valueAt (0)))); }; - break; - - - case 458: /* UnaryExpressionNotPlusMinus: EXCLAMATION UnaryExpression */ - if (yyn == 458) - /* "src/main/resources/Java_16_Grammar.y":1396 */ - { yyval = new UnaryPrefix(((Token)(yystack.valueAt (1))),((tree.Expression.Expression)(yystack.valueAt (0)))); }; - break; - - - case 459: /* UnaryExpressionNotPlusMinus: CastExpression */ - if (yyn == 459) - /* "src/main/resources/Java_16_Grammar.y":1397 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 460: /* UnaryExpressionNotPlusMinus: SwitchExpression */ - if (yyn == 460) - /* "src/main/resources/Java_16_Grammar.y":1398 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 461: /* PostfixExpression: Primary */ - if (yyn == 461) - /* "src/main/resources/Java_16_Grammar.y":1402 */ - { yyval = ((tree.Expression.Expression)(yystack.valueAt (0))); }; - break; - - - case 462: /* PostfixExpression: CompoundName */ - if (yyn == 462) - /* "src/main/resources/Java_16_Grammar.y":1403 */ - { yyval = new SimpleReference(((CompoundName)(yystack.valueAt (0)))); }; - break; - - - case 463: /* PostfixExpression: PostIncrementExpression */ - if (yyn == 463) - /* "src/main/resources/Java_16_Grammar.y":1404 */ - { yyval = ((UnaryPostfix)(yystack.valueAt (0))); }; - break; - - - case 464: /* PostfixExpression: PostDecrementExpression */ - if (yyn == 464) - /* "src/main/resources/Java_16_Grammar.y":1405 */ - { yyval = ((UnaryPostfix)(yystack.valueAt (0))); }; - break; - - - case 465: /* PostIncrementExpression: PostfixExpression DBL_PLUS */ - if (yyn == 465) - /* "src/main/resources/Java_16_Grammar.y":1409 */ - { yyval = new UnaryPostfix(((Token)(yystack.valueAt (0))),((tree.Expression.Expression)(yystack.valueAt (1)))); }; - break; - - - case 466: /* PostDecrementExpression: PostfixExpression DBL_MINUS */ - if (yyn == 466) - /* "src/main/resources/Java_16_Grammar.y":1413 */ - { yyval = new UnaryPostfix(((Token)(yystack.valueAt (0))),((tree.Expression.Expression)(yystack.valueAt (1)))); }; - break; - - - case 467: /* CastExpression: TargetType UnaryExpression */ - if (yyn == 467) - /* "src/main/resources/Java_16_Grammar.y":1417 */ - { yyval = new Cast(((tree.Type.TypeList)(yystack.valueAt (1))),((tree.Expression.Expression)(yystack.valueAt (0)))); }; - break; - - - case 468: /* CastExpression: TargetType LambdaExpression */ - if (yyn == 468) - /* "src/main/resources/Java_16_Grammar.y":1418 */ - { yyval = new Cast(((tree.Type.TypeList)(yystack.valueAt (1))),((tree.Expression.Expression)(yystack.valueAt (0)))); }; - break; - - - case 469: /* TargetType: LPAREN TypeList RPAREN */ - if (yyn == 469) - /* "src/main/resources/Java_16_Grammar.y":1422 */ - { yyval = ((tree.Type.TypeList)(yystack.valueAt (1))); }; - break; - - - case 470: /* TypeList: Type */ - if (yyn == 470) - /* "src/main/resources/Java_16_Grammar.y":1426 */ - { yyval = new TypeList(((tree.Type.Type)(yystack.valueAt (0)))); }; - break; - - - case 471: /* TypeList: TypeList AMPERSAND Type */ - if (yyn == 471) - /* "src/main/resources/Java_16_Grammar.y":1427 */ - { yyval = ((tree.Type.TypeList)(yystack.valueAt (2))).add(((tree.Type.Type)(yystack.valueAt (0)))); }; - break; - - - case 472: /* SwitchExpression: SWITCH LPAREN Expression RPAREN SwitchBlock */ - if (yyn == 472) - /* "src/main/resources/Java_16_Grammar.y":1431 */ - { yyval = new SwitchExpression(((tree.Expression.Expression)(yystack.valueAt (2))),((SwitchBlock)(yystack.valueAt (0)))); }; - break; - - - case 473: /* AnnotationSeqOpt: %empty */ - if (yyn == 473) - /* "src/main/resources/Java_16_Grammar.y":1443 */ - { yyval = null; }; - break; - - - case 474: /* AnnotationSeqOpt: AnnotationSeq */ - if (yyn == 474) - /* "src/main/resources/Java_16_Grammar.y":1444 */ - { yyval = ((Annotations)(yystack.valueAt (0))); }; - break; - - - case 475: /* AnnotationSeq: Annotation */ - if (yyn == 475) - /* "src/main/resources/Java_16_Grammar.y":1448 */ - { yyval = new Annotations(((Annotation)(yystack.valueAt (0)))); }; - break; - - - case 476: /* AnnotationSeq: AnnotationSeq Annotation */ - if (yyn == 476) - /* "src/main/resources/Java_16_Grammar.y":1449 */ - { yyval = ((Annotations)(yystack.valueAt (1))).add(((Annotation)(yystack.valueAt (0)))); }; - break; - - - case 477: /* Annotation: AT CompoundName */ - if (yyn == 477) - /* "src/main/resources/Java_16_Grammar.y":1453 */ - { yyval = new Annotation(((CompoundName)(yystack.valueAt (0))),(AnnoParameterList)null); }; - break; - - - case 478: /* Annotation: AT CompoundName LPAREN RPAREN */ - if (yyn == 478) - /* "src/main/resources/Java_16_Grammar.y":1454 */ - { yyval = new Annotation(((CompoundName)(yystack.valueAt (2))),(AnnoParameterList)null); }; - break; - - - case 479: /* Annotation: AT CompoundName LPAREN AnnoParameterList RPAREN */ - if (yyn == 479) - /* "src/main/resources/Java_16_Grammar.y":1455 */ - { yyval = new Annotation(((CompoundName)(yystack.valueAt (3))),/*$4*/ (AnnoParameterList)null); }; - break; - - - case 480: /* Annotation: AT CompoundName LPAREN ElementValue RPAREN */ - if (yyn == 480) - /* "src/main/resources/Java_16_Grammar.y":1456 */ - { yyval = new Annotation(((CompoundName)(yystack.valueAt (3))),(AnnoElementValue)null); }; - break; - - - case 481: /* AnnoParameterList: IDENTIFIER EQUAL ElementValue */ - if (yyn == 481) - /* "src/main/resources/Java_16_Grammar.y":1460 */ - { yyval = null; }; - break; - - - case 482: /* AnnoParameterList: AnnoParameterList COMMA IDENTIFIER EQUAL ElementValue */ - if (yyn == 482) - /* "src/main/resources/Java_16_Grammar.y":1461 */ - { yyval = null; }; - break; - - - case 483: /* ElementValue: ConditionalExpression */ - if (yyn == 483) - /* "src/main/resources/Java_16_Grammar.y":1465 */ - { yyval = null; }; - break; - - - case 484: /* ElementValue: LBRACE ElementValueListOpt RBRACE */ - if (yyn == 484) - /* "src/main/resources/Java_16_Grammar.y":1466 */ - { yyval = null; }; - break; - - - case 485: /* ElementValue: LBRACE COMMA RBRACE */ - if (yyn == 485) - /* "src/main/resources/Java_16_Grammar.y":1467 */ - { yyval = null; }; - break; - - - case 486: /* ElementValue: Annotation */ - if (yyn == 486) - /* "src/main/resources/Java_16_Grammar.y":1468 */ - { yyval = null; }; - break; - - - -/* "src/main/java/parser/JavaParser.java":4106 */ - - default: break; - } - - yystack.pop(yylen); - yylen = 0; - /* Shift the result of the reduction. */ - int yystate = yyLRGotoState(yystack.stateAt(0), yyr1_[yyn]); - yystack.push(yystate, yyval); - return YYNEWSTATE; - } - - - - - /** - * Parse input from the scanner that was specified at object construction - * time. Return whether the end of the input was reached successfully. - * - * @return true if the parsing succeeds. Note that this does not - * imply that there were no syntax errors. - */ - public boolean parse() throws java.io.IOException - - { - - - /* Lookahead token kind. */ - int yychar = YYEMPTY_; - /* Lookahead symbol kind. */ - SymbolKind yytoken = null; - - /* State. */ - int yyn = 0; - int yylen = 0; - int yystate = 0; - YYStack yystack = new YYStack (); - int label = YYNEWSTATE; - - - - /* Semantic value of the lookahead. */ - Entity yylval = null; - - yyerrstatus_ = 0; - yynerrs = 0; - - /* Initialize the stack. */ - yystack.push (yystate, yylval); - - - - for (;;) - switch (label) - { - /* New state. Unlike in the C/C++ skeletons, the state is already - pushed when we come here. */ - case YYNEWSTATE: - - /* Accept? */ - if (yystate == YYFINAL_) - return true; - - /* Take a decision. First try without lookahead. */ - yyn = yypact_[yystate]; - if (yyPactValueIsDefault (yyn)) - { - label = YYDEFAULT; - break; - } - - /* Read a lookahead token. */ - if (yychar == YYEMPTY_) - { - - yychar = yylexer.yylex (); - yylval = yylexer.getLVal(); - - } - - /* Convert token to internal form. */ - yytoken = yytranslate_ (yychar); - - if (yytoken == SymbolKind.S_YYerror) - { - // The scanner already issued an error message, process directly - // to error recovery. But do not keep the error token as - // lookahead, it is too special and may lead us to an endless - // loop in error recovery. */ - yychar = Lexer.YYUNDEF; - yytoken = SymbolKind.S_YYUNDEF; - label = YYERRLAB1; - } - else - { - /* If the proper action on seeing token YYTOKEN is to reduce or to - detect an error, take that action. */ - yyn += yytoken.getCode(); - if (yyn < 0 || YYLAST_ < yyn || yycheck_[yyn] != yytoken.getCode()) - label = YYDEFAULT; - - /* <= 0 means reduce or error. */ - else if ((yyn = yytable_[yyn]) <= 0) - { - if (yyTableValueIsError (yyn)) - label = YYERRLAB; - else - { - yyn = -yyn; - label = YYREDUCE; - } - } - - else - { - /* Shift the lookahead token. */ - /* Discard the token being shifted. */ - yychar = YYEMPTY_; - - /* Count tokens shifted since error; after three, turn off error - status. */ - if (yyerrstatus_ > 0) - --yyerrstatus_; - - yystate = yyn; - yystack.push (yystate, yylval); - label = YYNEWSTATE; - } - } - break; - - /*-----------------------------------------------------------. - | yydefault -- do the default action for the current state. | - `-----------------------------------------------------------*/ - case YYDEFAULT: - yyn = yydefact_[yystate]; - if (yyn == 0) - label = YYERRLAB; - else - label = YYREDUCE; - break; - - /*-----------------------------. - | yyreduce -- Do a reduction. | - `-----------------------------*/ - case YYREDUCE: - yylen = yyr2_[yyn]; - label = yyaction(yyn, yystack, yylen); - yystate = yystack.stateAt (0); - break; - - /*------------------------------------. - | yyerrlab -- here on detecting error | - `------------------------------------*/ - case YYERRLAB: - /* If not already recovering from an error, report this error. */ - if (yyerrstatus_ == 0) - { - ++yynerrs; - if (yychar == YYEMPTY_) - yytoken = null; - yyreportSyntaxError (new Context (yystack, yytoken)); - } - - if (yyerrstatus_ == 3) - { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - if (yychar <= Lexer.YYEOF) - { - /* Return failure if at end of input. */ - if (yychar == Lexer.YYEOF) - return false; - } - else - yychar = YYEMPTY_; - } - - /* Else will try to reuse lookahead token after shifting the error - token. */ - label = YYERRLAB1; - break; - - /*-------------------------------------------------. - | errorlab -- error raised explicitly by YYERROR. | - `-------------------------------------------------*/ - case YYERROR: - /* Do not reclaim the symbols of the rule which action triggered - this YYERROR. */ - yystack.pop (yylen); - yylen = 0; - yystate = yystack.stateAt (0); - label = YYERRLAB1; - break; - - /*-------------------------------------------------------------. - | yyerrlab1 -- common code for both syntax error and YYERROR. | - `-------------------------------------------------------------*/ - case YYERRLAB1: - yyerrstatus_ = 3; /* Each real token shifted decrements this. */ - - // Pop stack until we find a state that shifts the error token. - for (;;) - { - yyn = yypact_[yystate]; - if (!yyPactValueIsDefault (yyn)) - { - yyn += SymbolKind.S_YYerror.getCode(); - if (0 <= yyn && yyn <= YYLAST_ - && yycheck_[yyn] == SymbolKind.S_YYerror.getCode()) - { - yyn = yytable_[yyn]; - if (0 < yyn) - break; - } - } - - /* Pop the current state because it cannot handle the - * error token. */ - if (yystack.height == 0) - return false; - - - yystack.pop (); - yystate = yystack.stateAt (0); - } - - if (label == YYABORT) - /* Leave the switch. */ - break; - - - - /* Shift the error token. */ - - yystate = yyn; - yystack.push (yyn, yylval); - label = YYNEWSTATE; - break; - - /* Accept. */ - case YYACCEPT: - return true; - - /* Abort. */ - case YYABORT: - return false; - } -} - - - - - /** - * Information needed to get the list of expected tokens and to forge - * a syntax error diagnostic. - */ - public static final class Context - { - Context (YYStack stack, SymbolKind token) - { - yystack = stack; - yytoken = token; - } - - private YYStack yystack; - - - /** - * The symbol kind of the lookahead token. - */ - public final SymbolKind getToken () - { - return yytoken; - } - - private SymbolKind yytoken; - static final int NTOKENS = JavaParser.YYNTOKENS_; - - /** - * Put in YYARG at most YYARGN of the expected tokens given the - * current YYCTX, and return the number of tokens stored in YYARG. If - * YYARG is null, return the number of expected tokens (guaranteed to - * be less than YYNTOKENS). - */ - int getExpectedTokens (SymbolKind yyarg[], int yyargn) - { - return getExpectedTokens (yyarg, 0, yyargn); - } - - int getExpectedTokens (SymbolKind yyarg[], int yyoffset, int yyargn) - { - int yycount = yyoffset; - int yyn = yypact_[this.yystack.stateAt (0)]; - if (!yyPactValueIsDefault (yyn)) - { - /* Start YYX at -YYN if negative to avoid negative - indexes in YYCHECK. In other words, skip the first - -YYN actions for this state because they are default - actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST_ - yyn + 1; - int yyxend = yychecklim < NTOKENS ? yychecklim : NTOKENS; - for (int yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck_[yyx + yyn] == yyx && yyx != SymbolKind.S_YYerror.getCode() - && !yyTableValueIsError(yytable_[yyx + yyn])) - { - if (yyarg == null) - yycount += 1; - else if (yycount == yyargn) - return 0; // FIXME: this is incorrect. - else - yyarg[yycount++] = SymbolKind.get(yyx); - } - } - if (yyarg != null && yycount == yyoffset && yyoffset < yyargn) - yyarg[yycount] = null; - return yycount - yyoffset; - } - } - - - private int yysyntaxErrorArguments (Context yyctx, SymbolKind[] yyarg, int yyargn) - { - /* There are many possibilities here to consider: - - If this state is a consistent state with a default action, - then the only way this function was invoked is if the - default action is an error action. In that case, don't - check for expected tokens because there are none. - - The only way there can be no lookahead present (in tok) is - if this state is a consistent state with a default action. - Thus, detecting the absence of a lookahead is sufficient to - determine that there is no unexpected or expected token to - report. In that case, just report a simple "syntax error". - - Don't assume there isn't a lookahead just because this - state is a consistent state with a default action. There - might have been a previous inconsistent state, consistent - state with a non-default action, or user semantic action - that manipulated yychar. (However, yychar is currently out - of scope during semantic actions.) - - Of course, the expected token list depends on states to - have correct lookahead information, and it depends on the - parser not to perform extra reductions after fetching a - lookahead from the scanner and before detecting a syntax - error. Thus, state merging (from LALR or IELR) and default - reductions corrupt the expected token list. However, the - list is correct for canonical LR with one exception: it - will still contain any token that will not be accepted due - to an error action in a later state. - */ - int yycount = 0; - if (yyctx.getToken() != null) - { - if (yyarg != null) - yyarg[yycount] = yyctx.getToken(); - yycount += 1; - yycount += yyctx.getExpectedTokens(yyarg, 1, yyargn); - } - return yycount; - } - - - /** - * Build and emit a "syntax error" message in a user-defined way. - * - * @param ctx The context of the error. - */ - private void yyreportSyntaxError(Context yyctx) { - if (yyErrorVerbose) { - final int argmax = 5; - SymbolKind[] yyarg = new SymbolKind[argmax]; - int yycount = yysyntaxErrorArguments(yyctx, yyarg, argmax); - String[] yystr = new String[yycount]; - for (int yyi = 0; yyi < yycount; ++yyi) { - yystr[yyi] = yyarg[yyi].getName(); - } - String yyformat; - switch (yycount) { - default: - case 0: yyformat = "syntax error"; break; - case 1: yyformat = "syntax error, unexpected {0}"; break; - case 2: yyformat = "syntax error, unexpected {0}, expecting {1}"; break; - case 3: yyformat = "syntax error, unexpected {0}, expecting {1} or {2}"; break; - case 4: yyformat = "syntax error, unexpected {0}, expecting {1} or {2} or {3}"; break; - case 5: yyformat = "syntax error, unexpected {0}, expecting {1} or {2} or {3} or {4}"; break; - } - yyerror(new MessageFormat(yyformat).format(yystr)); - } else { - yyerror("syntax error"); - } - } - - /** - * Whether the given yypact_ value indicates a defaulted state. - * @param yyvalue the value to check - */ - private static boolean yyPactValueIsDefault (int yyvalue) - { - return yyvalue == yypact_ninf_; - } - - /** - * Whether the given yytable_ - * value indicates a syntax error. - * @param yyvalue the value to check - */ - private static boolean yyTableValueIsError (int yyvalue) - { - return yyvalue == yytable_ninf_; - } - - private static final short yypact_ninf_ = -680; - private static final short yytable_ninf_ = -487; - -/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ - private static final short[] yypact_ = yypact_init(); - private static final short[] yypact_init() - { - return new short[] - { - 29, 4, 127, 127, 186, -680, -680, 4451, -680, -680, - -680, 127, 99, 379, 533, -680, 127, -680, -680, -680, - -680, -680, -680, -680, -680, -680, -680, -680, -680, 2843, - -680, 4519, -680, -680, 1109, 4480, -680, 618, 80, -680, - 510, 172, 192, 346, 116, 228, 271, 285, 282, -680, - -680, -680, -680, -680, -680, -680, -680, -680, 2843, 4519, - -680, 134, -680, 370, -680, 101, 127, 127, 127, 127, - 408, 510, -680, 908, 2904, 395, 342, 454, 454, 430, - -680, 519, -680, 469, 507, 127, 27, 46, 660, 7, - -680, -680, -680, 1244, 3564, -680, 2970, 3630, 3630, 3630, - 3630, 3630, 3630, 324, -680, -680, -680, -680, -680, -680, - -680, -680, -680, -680, -680, -680, 4506, -680, -680, 218, - 581, -680, -680, 193, -680, 483, 485, 193, -680, 554, - -680, -680, -680, -680, -680, -680, -680, -680, 34, 551, - 590, 591, 605, 207, 185, -680, 252, 419, 628, -680, - -680, -680, -680, 634, -680, -680, -680, 3564, -680, 1728, - 525, 407, 632, 645, 1728, 661, 61, 582, -680, 651, - 454, -680, -680, -680, 676, -680, 127, -680, 127, -680, - 127, 2792, 329, 4618, 485, 905, 1530, 658, -680, 659, - -680, -680, 1875, -680, 270, 662, 423, -680, 500, -680, - -680, -680, -680, -680, -680, 3102, 656, 3168, -680, 2745, - 369, 433, 679, -680, 22, 656, 3564, 698, 697, 193, - -680, 447, 3564, 223, 656, -680, 493, 656, 700, -680, - 3564, 102, 656, 3564, 3630, -680, 3630, 3630, 3630, 3630, - 3630, 3630, 3630, 3630, 3630, 3630, 965, 3630, 3630, 3630, - 3630, 3630, 3630, 3630, 3630, -680, -680, -680, -680, 193, - -680, 665, -680, 1365, -680, -680, 702, 144, -680, 637, - 449, -680, -680, 61, 1728, 711, 714, 292, 342, 647, - -680, 717, 401, 544, 614, -680, 334, 1445, 550, 553, - -680, 4418, 3234, -680, 3234, -680, -680, -680, -680, -680, - -680, -680, -680, -680, -680, -680, -680, 3564, -680, 1728, - -680, -680, 3168, -680, 564, -680, 127, -680, 112, -680, - 462, -680, 2756, 3300, 463, 433, -680, 503, 721, 437, - 673, 679, -680, 675, 677, 730, -680, 668, -680, 729, - 732, 656, 728, -680, 689, 733, -680, 140, 680, 737, - -680, -680, 692, 694, 739, 551, 590, 591, 605, 207, - 185, 185, 252, 252, 252, 252, 701, -680, 56, -680, - -680, 419, 419, 419, 628, 628, -680, -680, -680, 724, - -680, 4363, 1529, 1728, 644, -680, 712, 1728, 61, -680, - -680, -680, 4144, -680, 1728, 570, -680, 1729, 748, 1728, - 342, 127, -680, -680, -680, 716, 254, -680, 720, -680, - 4480, 2118, -680, -680, -680, -680, -680, -680, -680, -680, - 3564, 484, 1728, 1728, 2745, -680, 113, 747, 3366, -680, - -680, -680, 3432, 752, 679, -680, -680, -680, 721, -680, - 761, -680, -680, -680, 32, -680, 656, -680, -680, -680, - -680, 721, -680, 3564, 387, 759, -680, 759, 3168, 701, - 261, -680, -680, -680, -680, -680, -680, 4363, -680, 296, - 1582, 763, 721, -680, 755, 723, 1728, -680, -680, 4208, - 4165, -680, -680, 679, 263, 3953, -680, -680, 752, 717, - 193, 193, 745, 447, -680, -680, 3564, -680, -680, 52, - 3564, 135, 148, 2688, 776, 777, 3498, 780, 782, 3564, - 609, 784, 3564, 4320, -680, 2232, -680, -680, -680, -680, - 778, -680, -680, -680, -680, -680, 393, 547, -680, -680, - -680, 634, 643, 646, -680, -680, -680, -680, -680, 1728, - 1728, -680, -680, 579, 781, -680, -680, 787, 3992, -680, - -680, 736, -680, 521, -680, -680, 749, 750, -680, -680, - -680, 3564, 425, 701, -680, 649, 789, -680, -680, 794, - -680, 797, 4208, 4045, -680, -680, -680, 752, 1728, -680, - 753, 264, -680, 412, 530, -680, -680, -680, -680, -680, - 4208, -680, -680, 772, -680, 4265, -680, 4084, -680, -680, - -680, -680, 754, 2688, 496, -680, 796, -680, 802, 782, - 703, 3692, 3564, -680, 804, 3564, 3564, 805, 3876, 257, - 797, 3564, 806, 56, -680, -680, -680, 809, -680, -680, - -680, -680, -680, -680, 815, 3366, -680, -680, 4105, -680, - 3630, -680, 20, -680, 128, -680, 1662, 330, 721, -680, - -680, 817, -680, -680, 819, -680, -680, 281, -680, 770, - 412, -680, -680, 719, -680, -680, 530, -680, -680, -680, - -680, 826, 719, 719, 753, 753, 264, 1349, -680, -680, - -680, -680, 779, 827, -680, -680, -680, -680, -680, 3564, - -680, -680, 830, 823, -680, 825, 829, 845, -680, 854, - 855, -680, 470, -680, 522, -680, 554, 541, 857, 797, - 257, -680, -680, 801, 858, -680, -680, -680, -680, -680, - 859, -680, -680, -680, 846, -680, -680, 1776, 863, 864, - 1890, 865, -680, 3036, -680, -680, 193, 431, 652, 868, - 1728, 827, -680, 3932, -680, -680, 719, 719, 719, 753, - -680, 2004, -680, 869, 3564, 3564, 3564, 3754, 2688, 761, - 797, -680, 3816, 4480, -680, -680, -680, 808, 801, 2688, - 3630, -680, -680, 3564, -680, 871, 813, -680, 4418, 702, - -680, 193, 1729, 21, 583, -680, -680, -680, -680, 719, - -680, 418, 2346, 2460, 556, 499, -680, 880, 884, 879, - -680, -680, 818, -680, -680, -680, -680, 1728, 888, -680, - -680, -680, -680, 885, -680, 3168, 886, 593, -680, 21, - 509, -680, -680, 867, 193, 4418, -680, 28, -680, 2574, - -680, 102, 721, 721, 889, 2688, 3754, 2688, -680, -680, - 273, 797, -680, -680, -680, -680, -680, 798, -680, 847, - -680, -680, 799, -680, -22, 893, 896, -680, -680, 829, - 906, -680, 1728, 193, -680, -680, -680, 721, 721, -680, - -680, 2688, -680, -680, 898, 900, -680, -680, -680 - }; - } - -/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. - Performed when YYTABLE does not specify something else to do. Zero - means the default is an error. */ - private static final short[] yydefact_ = yydefact_init(); - private static final short[] yydefact_init() - { - return new short[] - { - 35, 0, 0, 0, 0, 30, 31, 11, 36, 37, - 9, 0, 0, 0, 0, 1, 0, 22, 17, 18, - 28, 21, 20, 19, 23, 24, 25, 26, 27, 11, - 12, 13, 15, 38, 11, 0, 475, 0, 0, 39, - 49, 0, 35, 477, 0, 0, 0, 0, 0, 45, - 47, 81, 82, 83, 48, 194, 195, 16, 11, 14, - 476, 0, 40, 0, 10, 62, 0, 0, 0, 0, - 0, 50, 51, 11, 0, 0, 97, 85, 85, 0, - 46, 0, 41, 65, 63, 0, 0, 0, 0, 0, - 34, 52, 33, 11, 0, 478, 487, 0, 0, 0, - 0, 0, 0, 9, 2, 3, 6, 7, 80, 73, - 77, 79, 5, 78, 75, 76, 0, 8, 74, 0, - 0, 324, 4, 188, 321, 462, 0, 67, 69, 461, - 327, 333, 328, 329, 330, 331, 332, 483, 414, 417, - 419, 421, 423, 425, 427, 435, 430, 438, 442, 445, - 449, 450, 453, 456, 463, 464, 459, 0, 460, 0, - 475, 0, 0, 0, 0, 0, 0, 197, 86, 0, - 85, 42, 66, 64, 0, 54, 0, 56, 0, 58, - 0, 11, 9, 462, 470, 328, 329, 0, 379, 0, - 380, 396, 0, 395, 0, 0, 9, 488, 0, 451, - 452, 457, 458, 454, 455, 0, 341, 0, 358, 0, - 70, 0, 473, 342, 0, 341, 0, 0, 0, 189, - 190, 0, 0, 0, 341, 71, 0, 341, 0, 72, - 0, 0, 341, 0, 0, 413, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 465, 466, 468, 467, 68, - 479, 0, 480, 11, 211, 99, 98, 131, 128, 92, - 0, 88, 91, 0, 0, 0, 198, 473, 97, 95, - 53, 60, 0, 0, 0, 385, 9, 0, 0, 0, - 390, 0, 0, 326, 0, 401, 402, 403, 404, 405, - 406, 407, 408, 409, 410, 411, 412, 0, 469, 0, - 485, 484, 0, 363, 0, 365, 0, 481, 347, 346, - 0, 344, 0, 0, 0, 188, 375, 0, 0, 341, - 0, 474, 354, 0, 0, 0, 193, 0, 191, 0, - 0, 341, 0, 334, 0, 0, 325, 0, 0, 0, - 353, 335, 0, 0, 0, 418, 420, 422, 424, 426, - 428, 429, 431, 432, 433, 434, 0, 436, 67, 320, - 437, 439, 440, 441, 443, 444, 446, 447, 448, 0, - 212, 11, 11, 0, 136, 132, 0, 0, 0, 87, - 90, 199, 11, 196, 0, 0, 142, 0, 0, 0, - 97, 0, 55, 57, 59, 0, 473, 386, 0, 387, - 11, 11, 382, 381, 384, 383, 397, 471, 489, 364, - 0, 0, 0, 0, 0, 343, 350, 0, 161, 374, - 373, 376, 0, 103, 473, 338, 337, 339, 0, 370, - 0, 323, 192, 356, 0, 367, 341, 369, 372, 322, - 357, 0, 368, 0, 155, 233, 153, 232, 0, 0, - 0, 218, 219, 217, 214, 216, 213, 11, 100, 136, - 11, 0, 0, 101, 94, 0, 0, 89, 201, 11, - 11, 200, 140, 473, 473, 11, 139, 96, 0, 61, - 188, 188, 0, 474, 389, 391, 0, 223, 240, 9, - 0, 0, 0, 0, 0, 0, 0, 0, 25, 0, - 0, 0, 0, 11, 239, 11, 225, 228, 234, 235, - 0, 236, 237, 238, 290, 291, 327, 330, 260, 261, - 262, 0, 263, 264, 366, 359, 348, 349, 345, 0, - 0, 377, 166, 0, 162, 163, 165, 0, 11, 336, - 104, 0, 361, 278, 472, 355, 0, 0, 360, 416, - 415, 0, 157, 0, 482, 0, 0, 215, 133, 0, - 112, 23, 11, 11, 107, 110, 129, 134, 0, 93, - 0, 0, 207, 0, 0, 208, 203, 205, 206, 202, - 11, 143, 144, 0, 146, 11, 150, 11, 148, 84, - 393, 392, 0, 0, 0, 246, 0, 248, 0, 0, - 0, 293, 0, 250, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 229, 230, 227, 0, 224, 226, - 241, 351, 352, 159, 0, 0, 378, 105, 11, 340, - 0, 286, 0, 273, 0, 279, 11, 0, 0, 371, - 156, 0, 154, 209, 0, 130, 111, 0, 115, 0, - 0, 109, 117, 184, 113, 114, 0, 116, 108, 135, - 102, 0, 184, 184, 0, 0, 0, 0, 187, 210, - 186, 204, 0, 9, 147, 149, 394, 259, 242, 0, - 247, 249, 0, 295, 298, 0, 294, 0, 251, 0, - 0, 253, 70, 318, 0, 316, 0, 328, 0, 0, - 255, 305, 257, 303, 0, 254, 231, 160, 164, 106, - 285, 287, 270, 274, 0, 271, 280, 11, 0, 17, - 11, 0, 283, 0, 362, 158, 188, 155, 0, 0, - 0, 0, 167, 0, 173, 172, 184, 184, 184, 0, - 145, 11, 151, 0, 0, 0, 296, 0, 0, 0, - 0, 314, 0, 11, 313, 306, 256, 311, 304, 0, - 0, 272, 284, 0, 276, 0, 221, 152, 0, 185, - 118, 188, 0, 473, 0, 176, 171, 168, 170, 184, - 120, 398, 11, 11, 461, 0, 243, 0, 0, 0, - 297, 299, 268, 244, 252, 315, 317, 0, 0, 258, - 312, 289, 288, 0, 275, 0, 0, 0, 174, 473, - 188, 182, 179, 0, 188, 0, 169, 0, 121, 11, - 122, 341, 0, 0, 0, 0, 300, 0, 267, 309, - 0, 0, 277, 222, 220, 119, 178, 0, 180, 0, - 175, 177, 0, 123, 0, 0, 0, 245, 302, 301, - 0, 269, 0, 188, 307, 183, 181, 0, 0, 125, - 124, 0, 310, 308, 0, 0, 292, 126, 127 - }; - } - -/* YYPGOTO[NTERM-NUM]. */ - private static final short[] yypgoto_ = yypgoto_init(); - private static final short[] yypgoto_init() - { - return new short[] - { - -680, -680, -1, 35, -665, -27, 23, -680, -680, -680, - 874, -680, 18, -680, 840, 860, -680, -680, 850, 487, - -680, 291, 497, -680, -306, -680, -6, -421, -680, 534, - 654, -680, -255, 184, -680, -680, -448, 377, -453, -680, - -680, -680, 189, -680, -680, -680, -680, 465, 466, -680, - -680, -680, 471, -680, -680, 339, -680, -345, 374, -320, - -680, -680, 317, -680, -502, -569, 175, 132, 139, -623, - 293, -99, -197, 405, -295, 450, -680, -680, -680, -680, - 372, -459, -680, -680, -680, -680, 502, -680, -680, 505, - -405, -496, -680, -228, -349, -680, -680, -581, -680, -680, - 211, -680, 332, -680, 322, 327, -461, -680, -680, -680, - -680, -680, -680, 141, -680, -680, -680, 259, -679, -680, - -680, -680, -664, -680, -680, 217, -680, -584, 390, -218, - -680, -680, -179, -122, -680, 557, 123, 603, 520, -319, - -680, -680, -680, -680, 655, 690, -150, -680, -680, -680, - 577, -628, 539, -680, -680, -52, -680, -680, 758, 760, - 751, 756, 766, 453, -680, 396, 398, 445, 39, 657, - 713, -680, 726, 783, 877, -680, -680, -680, -680, -65, - 136, 117, -680, -80, -680 - }; - } - -/* YYDEFGOTO[NTERM-NUM]. */ - private static final short[] yydefgoto_ = yydefgoto_init(); - private static final short[] yydefgoto_init() - { - return new short[] - { - -1, 124, 183, 48, 30, 31, 32, 4, 5, 6, - 7, 8, 9, 92, 34, 49, 70, 71, 72, 282, - 85, 126, 127, 128, 50, 51, 659, 168, 270, 271, - 272, 400, 165, 266, 474, 549, 550, 573, 574, 661, - 662, 663, 752, 792, 52, 268, 384, 385, 471, 53, - 278, 395, 396, 486, 597, 598, 664, 457, 456, 542, - 543, 544, 545, 665, 584, 673, 784, 785, 822, 741, - 679, 228, 219, 220, 54, 55, 275, 276, 393, 480, - 586, 463, 588, 56, 264, 382, 464, 465, 816, 514, - 730, 516, 626, 703, 517, 518, 519, 520, 521, 838, - 554, 642, 643, 644, 645, 646, 731, 720, 522, 523, - 524, 695, 799, 696, 860, 525, 767, 710, 711, 808, - 840, 809, 712, 620, 704, 705, 370, 129, 130, 131, - 328, 329, 212, 213, 320, 321, 185, 186, 134, 208, - 314, 135, 136, 325, 326, 187, 188, 189, 288, 289, - 290, 190, 191, 192, 307, 193, 235, 138, 139, 140, - 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, - 151, 152, 153, 154, 155, 156, 157, 194, 158, 386, - 159, 36, 161, 162, 198 - }; - } - -/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule whose - number is the opposite. If YYTABLE_NINF, syntax error. */ - private static final short[] yytable_ = yytable_init(); - private static final short[] yytable_init() - { - return new short[] - { - 12, 13, 14, 225, 429, 343, 515, 257, 59, 433, - 37, 672, 721, 351, 324, 43, 197, 41, 369, 629, - 587, 455, 137, 398, 218, 33, 722, 316, 217, -29, - 694, 765, 596, 451, 706, 333, 334, 41, 175, 16, - 599, 209, 29, 43, 137, 344, 766, 209, 347, 744, - 745, 209, 352, 353, 57, 205, 41, 177, 583, 10, - 233, 225, 206, 217, 603, 86, 87, 88, 89, 58, - 666, 167, 169, 125, 16, 461, 820, 332, 782, 16, - 868, 234, 57, 64, 174, 640, 462, 555, 225, 765, - 641, 33, 647, 666, 63, 125, 125, 125, 125, 125, - 125, 125, 535, 810, 11, 746, 747, 748, 29, 38, - 39, 454, 1, 782, 565, 210, 269, 2, 341, 552, - 668, 209, 3, 786, 787, 788, 821, 317, 58, 669, - 342, 587, 558, 180, 725, 64, 199, 200, 201, 202, - 203, 204, 812, 35, 596, 488, 605, 330, 81, 176, - 436, 660, 60, 577, 610, 137, 125, 350, 210, 607, - 782, 461, 16, 210, 279, 35, 826, 794, 178, 583, - 35, 10, 462, 582, 660, 281, 801, 281, 706, 281, - 789, 724, 10, 728, 585, 668, 15, 422, 539, 64, - 606, 160, 341, 640, 35, 447, 258, 132, 641, -473, - 217, 83, 75, 608, 242, 243, 125, 624, 210, 35, - 84, 16, 397, 160, 423, 540, 287, 244, 245, 132, - 132, 132, 132, 132, 132, 132, 430, 64, 214, 35, - 448, 215, 418, 125, 629, 125, 125, 125, 125, 125, - 125, 125, 125, 125, 125, 210, 125, 125, 125, 125, - 125, 125, 125, 125, 687, 694, 240, 562, 241, 221, - 137, 217, 221, 221, 59, 556, 658, 557, 217, 246, - 217, 217, 16, 210, 308, 1, 60, 667, 64, 16, - 132, 16, 16, 76, 582, 627, 210, 309, 217, 658, - 210, 376, 377, 378, 862, 585, -141, 629, 381, 16, - 667, -141, 273, 559, 247, 248, 249, 470, 210, 491, - 16, 125, 738, 341, 16, 421, 566, 291, 592, 671, - 221, 210, 475, 708, 160, 342, 77, 205, 863, 734, - 132, 735, 205, 629, 206, 709, 737, 205, 60, 206, - 78, 492, 732, -388, 206, 322, 793, 327, 331, 74, - 79, -473, 207, 292, 733, 221, 41, 132, 292, 132, - 132, 132, 132, 132, 132, 132, 132, 132, 132, 551, - 132, 132, 132, 132, 132, 132, 132, 132, 564, 41, - 210, 82, 210, 693, 40, 184, 210, 829, 209, 41, - 60, 600, 601, 210, 217, 221, 210, -266, 210, 35, - 489, 560, -266, 331, -266, 16, 137, 211, 60, 802, - 401, 260, 402, 331, 90, 561, 261, 467, 397, 593, - 811, 210, 210, 210, 164, 222, 205, 479, 827, 160, - 16, 224, 217, 206, 743, 132, -70, 209, 217, 60, - 323, 250, 251, 16, 60, 287, 513, 434, 60, 16, - 163, 16, 125, 651, 339, 265, 209, 125, 388, 561, - 221, 327, 435, -462, -462, 16, 210, 10, 428, 389, - 217, 424, 184, 166, 108, 210, 109, 222, 210, 110, - 223, 16, 425, 224, 111, 170, 858, 205, 861, 209, - 222, 113, 217, 223, 41, 226, 224, 114, 227, 115, - 319, -70, 209, 16, 221, 572, 311, 688, 689, 312, - 432, 118, 210, 855, 856, 590, 217, 291, 35, 847, - 595, 16, 876, 476, 273, 674, 761, 16, 35, -486, - 171, -486, 229, 762, -486, 411, -486, 367, 210, 210, - 562, 678, 493, 41, 42, -319, 35, 291, 874, 875, - 513, -265, -319, 401, 407, 403, -265, 409, -265, 408, - 322, 230, 410, 230, 231, 391, 831, 232, 419, 232, - 331, 210, 795, 420, 482, 160, 132, 210, 172, 483, - 225, 132, 210, 572, 216, 633, 640, 824, 634, 210, - 221, 641, 825, 60, 210, 345, 221, 845, 346, 236, - 417, 832, 825, 291, 833, 331, 35, 173, 572, 343, - 60, 237, 618, 351, 411, 291, 35, 702, 238, 331, - 493, 35, 239, 401, 338, 404, 221, 221, 61, 62, - 65, 66, 595, 67, 68, 69, 262, 776, 362, 363, - 364, 365, 252, 253, 254, 371, 372, 373, 852, 35, - 263, 291, 854, 469, 277, 470, 259, 274, 563, 210, - 653, 563, 293, 777, 229, 283, 267, 284, 310, 225, - 41, 179, 459, 572, 468, 209, 210, 133, 473, 255, - 256, 513, 818, 294, 35, 481, 41, 280, -463, -463, - 487, -464, -464, 360, 361, 374, 375, 16, 221, 133, - 133, 133, 133, 133, 133, 133, 336, 337, 35, 35, - 348, 383, 387, 536, 537, 319, 392, 221, 823, 677, - 379, 848, 399, 394, 205, 850, 291, 41, 437, 338, - 438, 35, 439, 35, 440, 843, 441, 442, 444, 210, - 443, 707, 210, 368, 445, 450, 446, 451, 449, 452, - 791, 453, 458, 485, 823, 541, 454, 548, 459, 221, - 133, 702, 513, 137, 873, 513, 553, 472, 563, 576, - 459, 490, 578, 229, 35, 494, 602, 210, 579, 611, - 612, 210, 291, 615, 406, 616, 513, 621, 259, 630, - 635, 639, 654, 221, 60, 636, 677, 412, 807, 414, - 655, 526, 411, 682, 648, 649, 210, 690, 671, 686, - 133, 229, 221, 691, 125, 698, 701, 715, 692, 259, - 716, 717, 428, 736, 210, 739, 740, 513, 513, 743, - 631, 632, 751, 754, 750, 755, 756, 133, 757, 133, - 133, 133, 133, 133, 133, 133, 133, 133, 133, 758, - 133, 133, 133, 133, 133, 133, 133, 133, 759, 760, - 763, 210, 769, 291, 513, 229, 291, 708, 770, 670, - 733, 778, 221, 221, 675, 732, -286, 772, 460, 35, - 796, 459, 814, 815, 834, 707, 709, 291, 835, 229, - 836, 837, 841, 526, 484, 315, 842, 844, 849, 35, - 857, 867, 866, 865, 869, 526, 335, 870, -43, 877, - 871, 878, 340, 93, 35, 133, 73, 221, 80, 493, - 349, 91, 477, 354, 779, 638, 16, 390, 291, 291, - 780, 527, 160, -399, 568, 569, 685, 652, 132, -399, - -399, -399, -399, -399, -399, -399, -399, -399, -399, -399, - 528, 675, 718, 817, 591, 493, 221, 851, 846, 742, - 221, 35, 681, 625, 460, 291, 726, 338, 17, 567, - 803, 727, 768, 259, 723, 575, 581, 859, 18, 806, - 431, 538, 413, 16, 415, 19, 229, 495, 357, 0, - 575, 1, 355, 526, 358, 0, 356, 416, 0, 221, - 20, 526, 21, 22, 23, 359, 0, 0, 24, 25, - 623, 0, 26, 427, 0, 619, 27, 0, 0, 0, - 10, 0, 28, 527, 0, 0, 0, 108, 229, 109, - 0, 265, 110, 0, 0, 527, 526, 111, 0, 0, - 0, 0, 528, 0, 113, 0, 0, 0, 0, 0, - 114, 0, 115, 575, 528, 0, 133, 0, 0, 0, - 0, 133, 229, 0, 118, 0, 0, 0, 529, 657, - 0, 0, 0, 0, 0, 0, 656, 366, 575, 0, - 676, 229, 0, 0, 0, 0, 0, 581, 0, 680, - 0, 0, 657, 0, 0, 0, 0, 0, 839, 0, - 0, 0, 575, 0, 0, 0, 0, 0, 368, -32, - 534, 0, 0, 0, 0, 368, 0, 526, 546, 0, - 526, 0, 547, 527, 530, 713, 0, 16, 0, 0, - 0, 527, 0, 0, 0, 0, 0, 531, 0, 0, - 0, 526, 528, 575, 0, 0, 0, 526, 526, 0, - 528, 0, 0, 872, 0, 0, 0, 676, 0, 526, - 529, 0, 0, 0, 0, 0, 527, 0, 0, 17, - 0, 680, 529, 0, 259, 0, 0, 0, 0, 18, - 0, 0, 526, 526, 0, 528, 19, 0, 229, 0, - 604, 0, 0, 0, 532, 0, 614, 0, 0, 617, - 0, 20, 622, 21, 22, 23, 0, 0, 0, 24, - 25, 0, 0, 26, 764, 0, 530, 27, 0, 526, - 0, 133, 0, 28, 229, 526, 526, 526, 530, 531, - 0, 0, 0, 0, 0, 0, 0, 0, 774, 0, - 783, 531, 0, 0, -44, 0, 0, 527, 0, 0, - 527, 650, 0, 0, 0, 0, 0, 0, 0, 368, - 529, 526, 16, 0, 0, 804, 528, 0, 529, 528, - 0, 527, 0, 0, 0, 783, 0, 527, 527, 819, - 0, 0, 0, 0, 0, 0, 532, 0, 533, 527, - 528, 0, 0, 0, 0, 0, 528, 528, 532, 0, - 0, 0, 697, 529, 17, 699, 700, 0, 528, 0, - 0, 714, 527, 527, 18, 0, 530, 0, 0, 0, - 0, 19, 783, 0, 530, 546, 0, 0, 0, 531, - 0, 528, 528, 0, 0, 0, 20, 531, 21, 22, - 23, 0, 0, 0, 24, 25, 864, 0, 26, 527, - 0, 0, 27, 0, 0, 527, 527, 527, 28, 530, - 0, 0, 0, 0, 0, 133, 0, 16, 528, 0, - 0, 380, 531, 0, 528, 528, 528, 0, 0, 753, - 533, 0, 0, 16, 529, 0, 532, 529, 0, 0, - 0, 527, 533, 0, 532, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 10, 0, 0, 0, 529, 0, - 528, 108, 0, 109, 529, 529, 110, 0, 133, 0, - 0, 111, 0, 775, 0, 17, 529, 0, 113, 532, - 0, 0, 0, 0, 114, 18, 115, 0, 0, 0, - 530, 0, 19, 530, 797, 798, 800, 0, 118, 529, - 529, 0, 0, 531, 0, 0, 531, 20, 0, 21, - 22, 23, 749, 813, 530, 24, 25, 0, 0, 26, - 530, 530, 0, 27, 0, 0, 0, 531, 0, 28, - 533, 0, 530, 531, 531, 0, 529, 0, 533, 0, - 0, 0, 529, 529, 529, 531, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 530, 530, 108, 0, 109, - 532, 0, 110, 532, 0, 0, 0, 111, 531, 531, - 0, 0, 0, 533, 113, 0, 0, 0, 529, 0, - 114, 0, 115, 0, 532, 466, 0, 0, 0, 0, - 532, 532, 530, 0, 118, 0, 0, 16, 530, 530, - 530, 0, 532, 0, 0, 531, 0, 405, -400, 0, - 0, 531, 531, 531, -400, -400, -400, -400, -400, -400, - -400, -400, -400, -400, -400, 532, 532, 0, 0, 0, - 0, 0, 0, 0, 530, 0, 0, 411, -137, 17, - 0, 0, 0, 570, 0, 0, 0, 531, 0, 18, - 16, 0, 0, 0, 533, 0, 19, 533, 0, 0, - 0, 0, 532, 0, 0, 0, 0, 0, 532, 532, - 532, 20, 0, 21, 22, 23, 0, 0, 533, 24, - 25, 0, 0, 26, 533, 533, 0, 27, 0, 0, - 0, 0, 17, 28, 0, 0, 533, 0, 0, 0, - 0, 0, 18, 0, 532, 0, 0, 0, 0, 19, - 0, 0, 0, 0, 0, 496, 0, 411, -281, 533, - 533, 0, 0, 498, 20, 0, 21, 22, 23, 0, - 16, 0, 571, 25, 0, 0, 26, 0, 0, 0, - 27, 0, 0, 0, 0, 0, 28, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 533, 101, 102, 0, - 0, 0, 533, 533, 533, 0, 0, 499, 104, 105, - 106, 107, 17, 500, 108, 501, 109, 640, 0, 110, - 0, 502, 729, 503, 111, 0, 0, 0, 112, 19, - 0, 113, 504, 505, 0, 0, 16, 114, 533, 115, - 0, 0, 116, 117, 20, 0, 21, 22, 23, 0, - 506, 118, 24, 25, 119, 507, 508, 121, 509, 0, - 27, 0, 122, 510, 0, 123, 28, 511, 512, 496, - 0, 411, 771, 10, 10, 0, 0, 498, 0, 0, - 108, 108, 109, 109, 16, 110, 110, 0, 0, 0, - 111, 111, 0, 0, 0, 0, 0, 113, 113, 0, - 0, 0, 0, 114, 114, 115, 115, 0, 0, 0, - 0, 101, 102, 0, 0, 0, 0, 118, 118, 0, - 0, 499, 104, 105, 106, 107, 17, 500, 108, 501, - 109, 640, 0, 110, 0, 502, 729, 503, 111, 0, - 0, 0, 112, 19, 0, 113, 504, 505, 0, 0, - 0, 114, 0, 115, 0, 0, 116, 117, 20, 0, - 21, 22, 23, 0, 506, 118, 24, 25, 119, 507, - 508, 121, 509, 0, 27, 0, 122, 510, 0, 123, - 28, 511, 512, 496, 0, 411, -282, 0, 0, 0, - 0, 498, 0, 295, 0, 0, 0, 0, 16, 296, - 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 101, 102, 0, 0, 0, - 0, 0, 0, 0, 0, 499, 104, 105, 106, 107, - 17, 500, 108, 501, 109, -282, 0, 110, 0, 502, - 18, 503, 111, 0, 0, 0, 112, 19, 0, 113, - 504, 505, 0, 0, 0, 114, 0, 115, 0, 0, - 116, 117, 20, 0, 21, 22, 23, 0, 506, 118, - 24, 25, 119, 507, 508, 121, 509, 0, 27, 0, - 122, 510, 0, 123, 28, 511, 512, 496, 0, 411, - 790, 0, 0, 0, 0, 498, 0, 0, 0, 0, - 0, 0, 16, 209, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 101, - 102, 0, 0, 0, 0, 0, 0, 0, 0, 499, - 104, 105, 106, 107, 17, 500, 108, 501, 109, 0, - 0, 110, 0, 502, 18, 503, 111, 0, 0, 0, - 112, 19, 0, 113, 504, 505, 0, 0, 0, 114, - 0, 115, 0, 0, 116, 117, 20, 0, 21, 22, - 23, 0, 506, 118, 24, 25, 119, 507, 508, 121, - 509, 0, 27, 0, 122, 510, 0, 123, 28, 511, - 512, 496, 0, 411, 497, 0, 0, 0, 0, 498, - 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 101, 102, 0, 0, 0, 0, 0, - 0, 0, 0, 499, 104, 105, 106, 107, 17, 500, - 108, 501, 109, 0, 0, 110, 0, 502, 18, 503, - 111, 0, 0, 0, 112, 19, 0, 113, 504, 505, - 0, 0, 0, 114, 0, 115, 0, 0, 116, 117, - 20, 0, 21, 22, 23, 0, 506, 118, 24, 25, - 119, 507, 508, 121, 509, 0, 27, 0, 122, 510, - 0, 123, 28, 511, 512, 496, 0, 411, 628, 0, - 0, 0, 0, 498, 0, 0, 0, 0, 0, 0, - 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 101, 102, 0, - 0, 0, 0, 0, 0, 0, 0, 499, 104, 105, - 106, 107, 17, 500, 108, 501, 109, 0, 0, 110, - 0, 502, 18, 503, 111, 0, 0, 0, 112, 19, - 0, 113, 504, 505, 0, 0, 0, 114, 0, 115, - 0, 0, 116, 117, 20, 0, 21, 22, 23, 0, - 506, 118, 24, 25, 119, 507, 508, 121, 509, 0, - 27, 0, 122, 510, 0, 123, 28, 511, 512, 496, - 0, 411, 828, 0, 0, 0, 0, 498, 0, 0, - 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 101, 102, 0, 0, 0, 0, 0, 0, 0, - 0, 499, 104, 105, 106, 107, 17, 500, 108, 501, - 109, 0, 0, 110, 0, 502, 18, 503, 111, 0, - 0, 0, 112, 19, 0, 113, 504, 505, 0, 0, - 0, 114, 0, 115, 0, 0, 116, 117, 20, 0, - 21, 22, 23, 0, 506, 118, 24, 25, 119, 507, - 508, 121, 509, 0, 27, 0, 122, 510, 0, 123, - 28, 511, 512, 496, 0, 411, 830, 0, 0, 0, - 0, 498, 0, 0, 0, 0, 0, 0, 16, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 101, 102, 0, 0, 0, - 0, 0, 0, 0, 0, 499, 104, 105, 106, 107, - 17, 500, 108, 501, 109, 0, 0, 110, 0, 502, - 18, 503, 111, 0, 0, 0, 112, 19, 0, 113, - 504, 505, 0, 0, 0, 114, 0, 115, 0, 0, - 116, 117, 20, 0, 21, 22, 23, 0, 506, 118, - 24, 25, 119, 507, 508, 121, 509, 0, 27, 0, - 122, 510, 0, 123, 28, 511, 512, 496, 0, 411, - 853, 0, 0, 0, 0, 498, 0, 0, 0, 0, - 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 101, - 102, 0, 0, 0, 0, 0, 0, 0, 0, 499, - 104, 105, 106, 107, 17, 500, 108, 501, 109, 0, - 0, 110, 0, 502, 18, 503, 111, 0, 0, 0, - 112, 19, 0, 113, 504, 505, 0, 0, 0, 114, - 0, 115, 0, 0, 116, 117, 20, 0, 21, 22, - 23, 0, 506, 118, 24, 25, 119, 507, 508, 121, - 509, 0, 27, 0, 122, 510, 0, 123, 28, 511, - 512, 496, 0, 411, 0, 0, 0, 0, 0, 498, - 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 101, 102, 0, 0, 0, 0, 0, - 0, 0, 0, 499, 104, 105, 106, 107, 0, 500, - 108, 501, 109, 0, 0, 110, 0, 502, 0, 503, - 111, 0, 0, 16, 112, 0, 0, 113, 504, 505, - 0, 318, 0, 114, 16, 115, 0, 0, 116, 117, - 0, 0, 426, 0, 0, 0, 506, 118, 0, 0, - 119, 507, 609, 121, 509, 181, 285, 0, 122, 510, - 10, 123, 0, 511, 512, 0, 0, 108, 0, 109, - 16, 10, 110, 0, 97, 98, 0, 111, 108, 0, - 109, 99, 100, 110, 113, 0, 0, 0, 111, 0, - 114, 0, 115, 0, 0, 113, 0, 101, 102, 0, - 0, 114, 0, 115, 118, 0, 0, 286, 104, 105, - 106, 107, 17, 0, 108, 118, 109, 0, 0, 110, - 0, 44, 18, 0, 111, 0, 0, 0, 112, 19, - 0, 113, 0, 0, 0, 0, 0, 114, 0, 115, - 0, 0, 116, 117, 20, 0, 21, 22, 23, 0, - 0, 118, 24, 25, 119, 120, 26, 121, 0, 0, - 27, 0, 122, 17, 0, 123, 28, 94, 95, 96, - 0, 0, 0, 18, 0, 0, 0, 45, 0, 0, - 19, 0, 16, 0, 0, 0, 97, 98, 0, 46, - 0, 0, 0, 99, 100, 20, 0, 21, 22, 23, - 47, 0, 0, 24, 25, 0, 0, 26, 0, 101, - 102, 27, 0, 0, 0, 0, 0, 28, 0, 103, - 104, 105, 106, 107, 0, 0, 108, 0, 109, 0, - 0, 110, 0, 94, 0, 96, 111, 0, 0, 195, - 112, 0, 0, 113, 0, 0, 0, 0, 16, 114, - 0, 115, 97, 98, 116, 117, 0, 0, 0, 99, - 100, 0, 0, 118, 0, 0, 119, 120, 0, 121, - 0, 0, 0, 0, 122, 101, 102, 123, 0, 0, - 0, 0, 0, 0, 0, 196, 104, 105, 106, 107, - 0, 0, 108, 0, 109, 0, 0, 110, 0, 181, - 0, 411, 111, 0, 0, 0, 112, 0, 0, 113, - 0, 0, 0, 0, 16, 114, 0, 115, 97, 98, - 116, 117, 0, 0, 0, 99, 100, 0, 0, 118, - 0, 0, 119, 120, 0, 121, 0, 0, 0, 0, - 122, 101, 102, 123, 0, 0, 0, 0, 0, 0, - 0, 182, 104, 105, 106, 107, 0, 0, 108, 0, - 109, 0, 0, 110, 0, 181, 313, 0, 111, 0, - 0, 0, 112, 0, 0, 113, 0, 0, 0, 0, - 16, 114, 0, 115, 97, 98, 116, 117, 0, 0, - 0, 99, 100, 0, 0, 118, 0, 0, 119, 120, - 0, 121, 773, 0, 0, 0, 122, 101, 102, 123, - 0, 0, 0, 0, 0, 0, 0, 182, 104, 105, - 106, 107, 0, 0, 108, 0, 109, 0, 0, 110, - 0, 94, 0, 96, 111, 0, 0, 0, 112, 0, - 0, 113, 0, 0, 0, 0, 16, 114, 0, 115, - 97, 98, 116, 117, 0, 0, 0, 99, 100, 0, - 0, 118, 0, 0, 119, 120, 0, 121, 0, 0, - 0, 0, 122, 101, 102, 123, 0, 0, 0, 0, - 0, 0, 0, 196, 104, 105, 106, 107, 0, 0, - 108, 0, 109, 0, 0, 110, 0, 181, 0, 411, - 111, 0, 0, 0, 112, 0, 0, 113, 0, 0, - 0, 0, 16, 114, 0, 115, 97, 98, 116, 117, - 0, 0, 0, 99, 100, 0, 0, 118, 0, 0, - 119, 120, 0, 121, 0, 0, 0, 0, 122, 101, - 102, 123, 0, 0, 0, 0, 0, 0, 0, 182, - 104, 105, 106, 107, 0, 0, 108, 0, 109, 0, - 0, 110, 0, 181, 0, 0, 111, 0, 336, 0, - 112, 0, 0, 113, 0, 0, 0, 0, 16, 114, - 0, 115, 97, 98, 116, 117, 0, 0, 0, 99, - 100, 0, 0, 118, 0, 0, 119, 120, 0, 121, - 0, 0, 0, 0, 122, 101, 102, 123, 0, 0, - 0, 0, 0, 0, 0, 182, 104, 105, 106, 107, - 0, 0, 108, 0, 109, 0, 0, 110, 0, 181, - 0, 428, 111, 0, 0, 0, 112, 0, 0, 113, - 0, 0, 0, 0, 16, 114, 0, 115, 97, 98, - 116, 117, 0, 0, 0, 99, 100, 0, 0, 118, - 0, 0, 119, 120, 0, 121, 0, 0, 0, 0, - 122, 101, 102, 123, 0, 0, 0, 0, 0, 0, - 0, 182, 104, 105, 106, 107, 0, 0, 108, 0, - 109, 0, 0, 110, 0, 181, 0, 0, 111, 0, - 442, 0, 112, 0, 0, 113, 0, 0, 0, 0, - 16, 114, 0, 115, 97, 98, 116, 117, 0, 0, - 0, 99, 100, 0, 0, 118, 0, 0, 119, 120, - 0, 121, 0, 0, 0, 0, 122, 101, 102, 123, - 0, 0, 0, 0, 0, 0, 0, 182, 104, 105, - 106, 107, 0, 0, 108, 0, 109, 0, 0, 110, - 0, 181, 0, 0, 111, 0, 0, 0, 112, 613, - 0, 113, 0, 0, 0, 0, 16, 114, 0, 115, - 97, 98, 116, 117, 0, 0, 0, 99, 100, 0, - 0, 118, 0, 0, 119, 120, 0, 121, 0, 0, - 0, 0, 122, 101, 102, 123, 0, 0, 0, 0, - 0, 0, 0, 182, 104, 105, 106, 107, 0, 0, - 108, 0, 109, 0, 0, 110, 0, 181, 0, 0, - 111, 0, 0, 0, 112, 0, 0, 113, 0, 0, - 0, 0, 16, 114, 0, 115, 97, 98, 116, 117, - 0, 0, 0, 99, 100, 0, 0, 118, 0, 0, - 119, 120, 0, 121, 0, 0, 0, 0, 122, 101, - 102, 123, 0, 0, 0, 0, 0, 0, 0, 182, - 104, 105, 106, 107, 0, 0, 108, 0, 109, 0, - 0, 110, 0, 94, 0, 0, 111, 0, 0, 0, - 112, 0, 0, 113, 0, 0, 0, 0, 16, 114, - 0, 115, 97, 98, 116, 117, 0, 0, 0, 99, - 100, 0, 0, 118, 0, 0, 119, 120, 0, 121, - 0, 0, 0, 0, 122, 101, 102, 123, 0, 0, - 0, 0, 0, 0, 0, 196, 104, 105, 106, 107, - 0, 0, 108, 0, 109, 496, 0, 110, 0, 0, - 0, 0, 111, 0, 0, 0, 112, 0, 0, 113, - 16, 0, 0, 0, 0, 114, 0, 115, 0, 0, - 116, 117, 0, 0, 0, 0, 0, 0, 0, 118, - 0, 0, 119, 120, 0, 121, 0, 101, 102, 0, - 122, 0, 0, 123, 0, 0, 0, 196, 104, 105, - 106, 107, 0, 0, 108, 0, 109, 496, 0, 110, - 0, 0, 0, 0, 111, 0, 0, 0, 112, 0, - 0, 113, 16, 0, 0, 0, 0, 114, 0, 115, - 0, 0, 116, 117, 0, 0, 0, 0, 0, 0, - 0, 118, 0, 0, 119, 0, 0, 121, 0, 101, - 102, 0, 122, 0, 366, 123, 0, 0, 0, 196, - 104, 105, 106, 107, 0, 0, 108, 0, 109, 496, - 805, 110, 0, 0, 0, 0, 111, 0, 0, 0, - 112, 0, 0, 113, 16, 0, 0, 0, 0, 114, - 0, 115, 0, 0, 116, 117, 0, 0, 0, 0, - 0, 0, 0, 118, 0, 0, 119, 0, 0, 121, - 0, 0, 0, 0, 122, 0, 0, 123, 0, 0, - 0, 196, 104, 105, 106, 107, 0, 0, 108, 496, - 109, 0, 0, 110, 0, 0, 0, 0, 111, 0, - 0, 0, 112, 0, 16, 113, 0, 0, 0, 0, - 0, 114, 0, 115, 0, 0, 116, 117, 0, 0, - 0, 0, 0, 0, 0, 118, 0, 0, 119, 0, - 0, 121, 0, 0, 0, 0, 122, 0, 366, 123, - 0, 196, 104, 105, 106, 107, 781, 0, 108, 0, - 109, 0, 0, 110, 0, 0, 0, 0, 111, 0, - 16, 0, 112, 0, 0, 113, 0, 0, 411, 594, - 0, 114, 0, 115, 570, 0, 116, 117, 0, 0, - 0, 16, 0, 0, 0, 118, 0, 0, 119, 0, - 0, 121, 0, 0, 0, 0, 122, 10, 366, 123, - 0, 0, 17, 0, 108, 0, 109, 411, 637, 110, - 0, 0, 18, 570, 111, 0, 0, 0, 0, 19, - 16, 113, 0, 17, 0, 0, 0, 114, 0, 115, - 0, 0, 0, 18, 20, 0, 21, 22, 23, 0, - 19, 118, 24, 25, 0, 0, 26, 0, 0, 0, - 27, 0, 0, 0, 0, 20, 28, 21, 22, 23, - 411, -138, 17, 571, 25, 0, 570, 26, 0, 0, - 0, 27, 18, 16, 0, 0, 0, 28, 0, 19, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 20, 0, 21, 22, 23, 411, - 684, 0, 571, 25, 0, 570, 26, 0, 0, 0, - 27, 0, 16, 0, 0, 17, 28, 0, 0, 0, - 411, 719, 0, 0, 0, 18, 570, 0, 0, 0, - 0, 0, 19, 16, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 20, 0, 21, - 22, 23, 0, 0, 17, 571, 25, 0, 0, 26, - 478, 0, 0, 27, 18, 0, 0, 0, 0, 28, - 0, 19, 16, 0, 0, 17, 0, 0, 0, 0, - 0, 589, 0, 0, 0, 18, 20, 0, 21, 22, - 23, 0, 19, 16, 571, 25, 0, 0, 26, 0, - 0, 0, 27, 0, 0, 0, 0, 20, 28, 21, - 22, 23, 0, 0, 17, 571, 25, 0, 0, 26, - 0, 0, 0, 27, 18, 0, 0, 0, 0, 28, - 0, 19, 0, 0, 0, 17, 44, 166, 0, 0, - 0, 0, 0, 0, 0, 18, 20, 0, 21, 22, - 23, 0, 19, 0, 24, 25, 0, 0, 26, 0, - 0, 0, 27, 0, 0, 0, 0, 20, 28, 21, - 22, 23, 0, 10, 0, 24, 25, 0, 17, 26, - 108, 0, 109, 27, 0, 110, 0, 0, 18, 28, - 111, 0, 45, 44, 166, 19, 0, 113, 0, 0, - 0, 0, 0, 114, 46, 115, 0, 0, 0, 0, - 20, 0, 21, 22, 23, 47, 0, 118, 24, 25, - 0, 0, 26, 0, 0, 0, 27, 0, 0, 0, - 683, 580, 28, 0, 0, 17, 0, 108, 0, 109, - 0, 0, 110, 0, 0, 18, 0, 111, 16, 45, - 0, 0, 19, 0, 113, 0, 0, 0, 0, 0, - 114, 46, 115, 0, 0, 0, 0, 20, 0, 21, - 22, 23, 47, 0, 118, 24, 25, 0, 0, 26, - 0, 0, 0, 27, 0, 10, 0, 0, 580, 28, - 17, 44, 108, 0, 109, 0, 0, 110, 0, 0, - 18, 0, 111, 0, 45, 0, 0, 19, 0, 113, - 0, 0, 0, 0, 0, 114, 46, 115, 0, 0, - 0, 0, 20, 0, 21, 22, 23, 47, 10, 118, - 24, 25, 0, 17, 26, 108, 0, 109, 27, 0, - 110, 0, 366, 18, 28, 111, 16, 45, 0, 0, - 19, 0, 113, 0, 0, 0, 0, 0, 114, 46, - 115, 0, 0, 0, 0, 20, 0, 21, 22, 23, - 47, 0, 118, 24, 25, 0, 0, 26, 0, 16, - 0, 27, 0, 10, 0, 0, 0, 28, 17, 0, - 108, 0, 109, 0, 0, 110, 0, 0, 18, 0, - 111, 0, 0, 0, 0, 19, 0, 113, 16, 0, - 0, 0, 0, 114, 0, 115, 0, 0, 0, 0, - 20, 17, 21, 22, 23, 0, 0, 118, 24, 25, - 0, 18, 26, 0, 16, 209, 27, 0, 19, 0, - 0, 0, 28, 0, 1, 0, 0, 0, 0, 0, - 17, 0, 0, 20, 0, 21, 22, 23, 0, 0, - 18, 24, 25, 0, 0, 26, 0, 19, 0, 27, - 0, 10, 0, 0, 0, 28, 0, 0, 108, 0, - 109, 0, 20, 110, 21, 22, 23, 0, 111, 17, - 24, 25, 0, 0, 26, 113, 0, 0, 27, 18, - 0, 114, 0, 115, 28, 0, 19, 0, 0, 0, - 0, 0, 0, 0, 0, 118, 0, 0, 0, 0, - 0, 20, 0, 21, 22, 23, 0, 0, 0, 24, - 25, 0, -70, 26, 0, 222, 0, 27, 223, 0, - 0, 224, 0, 28, 0, -70, -70, 209, 0, 0, - 0, 0, 0, 0, 0, 0, -398, 0, 0, 0, - 0, 0, -398, -398, -398, -398, -398, -398, -398, -398, - -398, -398, -398, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, -70 - }; - } - -private static final short[] yycheck_ = yycheck_init(); - private static final short[] yycheck_init() - { - return new short[] - { - 1, 2, 3, 125, 324, 223, 411, 157, 35, 328, - 11, 580, 640, 231, 211, 16, 96, 10, 246, 515, - 479, 366, 74, 278, 123, 7, 6, 206, 7, 0, - 611, 710, 485, 55, 618, 214, 215, 10, 11, 18, - 488, 19, 7, 44, 96, 224, 710, 19, 227, 672, - 673, 19, 231, 232, 31, 3, 10, 11, 479, 55, - 26, 183, 10, 7, 12, 66, 67, 68, 69, 34, - 572, 77, 78, 74, 18, 381, 55, 55, 743, 18, - 102, 47, 59, 55, 85, 65, 381, 55, 210, 768, - 70, 73, 553, 595, 14, 96, 97, 98, 99, 100, - 101, 102, 421, 767, 100, 674, 675, 676, 73, 10, - 11, 55, 83, 778, 459, 116, 55, 88, 90, 438, - 573, 19, 93, 746, 747, 748, 105, 207, 93, 577, - 102, 590, 451, 126, 6, 55, 97, 98, 99, 100, - 101, 102, 770, 7, 597, 400, 11, 212, 14, 122, - 329, 572, 35, 472, 503, 207, 157, 55, 159, 11, - 825, 467, 18, 164, 170, 29, 789, 751, 122, 590, - 34, 55, 467, 479, 595, 176, 757, 178, 762, 180, - 749, 642, 55, 644, 479, 638, 0, 75, 75, 55, - 55, 74, 90, 65, 58, 55, 157, 74, 70, 55, - 7, 100, 86, 55, 19, 20, 207, 513, 209, 73, - 109, 18, 277, 96, 102, 102, 181, 32, 33, 96, - 97, 98, 99, 100, 101, 102, 325, 55, 10, 93, - 90, 13, 312, 234, 730, 236, 237, 238, 239, 240, - 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, - 251, 252, 253, 254, 603, 836, 49, 454, 51, 123, - 312, 7, 126, 127, 291, 444, 572, 446, 7, 84, - 7, 7, 18, 274, 4, 83, 159, 572, 55, 18, - 157, 18, 18, 55, 590, 513, 287, 17, 7, 595, - 291, 252, 253, 254, 21, 590, 4, 793, 263, 18, - 595, 9, 166, 453, 52, 53, 54, 11, 309, 55, - 18, 312, 657, 90, 18, 316, 55, 181, 55, 55, - 184, 322, 387, 66, 207, 102, 55, 3, 55, 648, - 207, 651, 3, 829, 10, 78, 55, 3, 221, 10, - 55, 406, 12, 9, 10, 209, 751, 211, 212, 3, - 68, 55, 28, 24, 24, 219, 10, 234, 24, 236, - 237, 238, 239, 240, 241, 242, 243, 244, 245, 434, - 247, 248, 249, 250, 251, 252, 253, 254, 458, 10, - 381, 11, 383, 611, 5, 94, 387, 792, 19, 10, - 273, 490, 491, 394, 7, 259, 397, 4, 399, 263, - 401, 453, 9, 267, 11, 18, 458, 116, 291, 758, - 9, 4, 11, 277, 6, 28, 9, 382, 483, 484, - 769, 422, 423, 424, 82, 7, 3, 392, 10, 312, - 18, 13, 7, 10, 3, 312, 18, 19, 7, 322, - 7, 22, 23, 18, 327, 410, 411, 10, 331, 18, - 55, 18, 453, 28, 7, 164, 19, 458, 9, 28, - 324, 325, 25, 45, 46, 18, 467, 55, 5, 20, - 7, 9, 181, 19, 62, 476, 64, 7, 479, 67, - 10, 18, 20, 13, 72, 55, 835, 3, 837, 19, - 7, 79, 7, 10, 10, 10, 13, 85, 13, 87, - 209, 18, 19, 18, 368, 470, 6, 11, 12, 9, - 7, 99, 513, 832, 833, 480, 7, 381, 382, 10, - 485, 18, 871, 387, 388, 113, 4, 18, 392, 4, - 11, 6, 127, 11, 9, 5, 11, 246, 539, 540, - 737, 11, 406, 10, 11, 4, 410, 411, 867, 868, - 515, 4, 11, 9, 4, 11, 9, 4, 11, 9, - 424, 7, 9, 7, 10, 274, 10, 13, 4, 13, - 434, 572, 751, 9, 4, 458, 453, 578, 109, 9, - 702, 458, 583, 548, 3, 6, 65, 4, 9, 590, - 454, 70, 9, 476, 595, 102, 460, 4, 105, 48, - 309, 102, 9, 467, 105, 469, 470, 100, 573, 827, - 493, 21, 3, 831, 5, 479, 480, 618, 27, 483, - 484, 485, 17, 9, 219, 11, 490, 491, 10, 11, - 120, 121, 597, 123, 124, 125, 4, 736, 242, 243, - 244, 245, 14, 15, 16, 247, 248, 249, 827, 513, - 5, 515, 831, 9, 3, 11, 159, 75, 9, 660, - 11, 9, 4, 11, 259, 178, 5, 180, 6, 791, - 10, 11, 381, 638, 383, 19, 677, 74, 387, 45, - 46, 646, 781, 24, 548, 394, 10, 11, 45, 46, - 399, 45, 46, 240, 241, 250, 251, 18, 562, 96, - 97, 98, 99, 100, 101, 102, 8, 10, 572, 573, - 10, 9, 75, 422, 423, 424, 5, 581, 783, 583, - 55, 820, 75, 9, 3, 824, 590, 10, 55, 324, - 55, 595, 55, 597, 4, 815, 68, 8, 10, 740, - 8, 618, 743, 246, 55, 8, 13, 55, 68, 55, - 751, 12, 28, 5, 819, 8, 55, 5, 467, 623, - 157, 762, 727, 815, 863, 730, 5, 55, 9, 6, - 479, 55, 17, 368, 638, 55, 31, 778, 55, 3, - 3, 782, 646, 3, 287, 3, 751, 3, 291, 11, - 9, 55, 3, 657, 677, 8, 660, 292, 763, 294, - 6, 411, 5, 31, 55, 55, 807, 11, 55, 55, - 207, 406, 676, 11, 815, 11, 11, 11, 115, 322, - 11, 6, 5, 4, 825, 55, 107, 792, 793, 3, - 539, 540, 5, 3, 55, 12, 11, 234, 9, 236, - 237, 238, 239, 240, 241, 242, 243, 244, 245, 4, - 247, 248, 249, 250, 251, 252, 253, 254, 4, 4, - 3, 862, 4, 727, 829, 460, 730, 66, 9, 578, - 24, 3, 736, 737, 583, 12, 12, 12, 381, 743, - 11, 590, 11, 70, 4, 762, 78, 751, 4, 484, - 11, 73, 4, 503, 397, 205, 11, 11, 31, 763, - 11, 102, 55, 105, 11, 515, 216, 11, 0, 11, - 4, 11, 222, 73, 778, 312, 42, 781, 58, 783, - 230, 71, 388, 233, 740, 548, 18, 273, 792, 793, - 741, 411, 815, 28, 469, 469, 597, 563, 815, 34, - 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, - 411, 660, 635, 778, 483, 819, 820, 825, 819, 666, - 824, 825, 590, 513, 467, 829, 644, 562, 60, 467, - 759, 644, 713, 476, 642, 470, 479, 836, 70, 762, - 325, 424, 292, 18, 294, 77, 581, 410, 237, -1, - 485, 83, 234, 603, 238, -1, 236, 307, -1, 863, - 92, 611, 94, 95, 96, 239, -1, -1, 100, 101, - 513, -1, 104, 323, -1, 510, 108, -1, -1, -1, - 55, -1, 114, 503, -1, -1, -1, 62, 623, 64, - -1, 740, 67, -1, -1, 515, 646, 72, -1, -1, - -1, -1, 503, -1, 79, -1, -1, -1, -1, -1, - 85, -1, 87, 548, 515, -1, 453, -1, -1, -1, - -1, 458, 657, -1, 99, -1, -1, -1, 411, 572, - -1, -1, -1, -1, -1, -1, 571, 112, 573, -1, - 583, 676, -1, -1, -1, -1, -1, 590, -1, 584, - -1, -1, 595, -1, -1, -1, -1, -1, 807, -1, - -1, -1, 597, -1, -1, -1, -1, -1, 611, 0, - 420, -1, -1, -1, -1, 618, -1, 727, 428, -1, - 730, -1, 432, 603, 411, 620, -1, 18, -1, -1, - -1, 611, -1, -1, -1, -1, -1, 411, -1, -1, - -1, 751, 603, 638, -1, -1, -1, 757, 758, -1, - 611, -1, -1, 862, -1, -1, -1, 660, -1, 769, - 503, -1, -1, -1, -1, -1, 646, -1, -1, 60, - -1, 666, 515, -1, 677, -1, -1, -1, -1, 70, - -1, -1, 792, 793, -1, 646, 77, -1, 783, -1, - 500, -1, -1, -1, 411, -1, 506, -1, -1, 509, - -1, 92, 512, 94, 95, 96, -1, -1, -1, 100, - 101, -1, -1, 104, 709, -1, 503, 108, -1, 829, - -1, 618, -1, 114, 819, 835, 836, 837, 515, 503, - -1, -1, -1, -1, -1, -1, -1, -1, 733, -1, - 743, 515, -1, -1, 0, -1, -1, 727, -1, -1, - 730, 561, -1, -1, -1, -1, -1, -1, -1, 762, - 603, 871, 18, -1, -1, 760, 727, -1, 611, 730, - -1, 751, -1, -1, -1, 778, -1, 757, 758, 782, - -1, -1, -1, -1, -1, -1, 503, -1, 411, 769, - 751, -1, -1, -1, -1, -1, 757, 758, 515, -1, - -1, -1, 612, 646, 60, 615, 616, -1, 769, -1, - -1, 621, 792, 793, 70, -1, 603, -1, -1, -1, - -1, 77, 825, -1, 611, 635, -1, -1, -1, 603, - -1, 792, 793, -1, -1, -1, 92, 611, 94, 95, - 96, -1, -1, -1, 100, 101, 841, -1, 104, 829, - -1, -1, 108, -1, -1, 835, 836, 837, 114, 646, - -1, -1, -1, -1, -1, 762, -1, 18, 829, -1, - -1, 6, 646, -1, 835, 836, 837, -1, -1, 689, - 503, -1, -1, 18, 727, -1, 603, 730, -1, -1, - -1, 871, 515, -1, 611, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 55, -1, -1, -1, 751, -1, - 871, 62, -1, 64, 757, 758, 67, -1, 815, -1, - -1, 72, -1, 733, -1, 60, 769, -1, 79, 646, - -1, -1, -1, -1, 85, 70, 87, -1, -1, -1, - 727, -1, 77, 730, 754, 755, 756, -1, 99, 792, - 793, -1, -1, 727, -1, -1, 730, 92, -1, 94, - 95, 96, 113, 773, 751, 100, 101, -1, -1, 104, - 757, 758, -1, 108, -1, -1, -1, 751, -1, 114, - 603, -1, 769, 757, 758, -1, 829, -1, 611, -1, - -1, -1, 835, 836, 837, 769, -1, -1, -1, -1, - 55, -1, -1, -1, -1, 792, 793, 62, -1, 64, - 727, -1, 67, 730, -1, -1, -1, 72, 792, 793, - -1, -1, -1, 646, 79, -1, -1, -1, 871, -1, - 85, -1, 87, -1, 751, 6, -1, -1, -1, -1, - 757, 758, 829, -1, 99, -1, -1, 18, 835, 836, - 837, -1, 769, -1, -1, 829, -1, 112, 28, -1, - -1, 835, 836, 837, 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 792, 793, -1, -1, -1, - -1, -1, -1, -1, 871, -1, -1, 5, 6, 60, - -1, -1, -1, 11, -1, -1, -1, 871, -1, 70, - 18, -1, -1, -1, 727, -1, 77, 730, -1, -1, - -1, -1, 829, -1, -1, -1, -1, -1, 835, 836, - 837, 92, -1, 94, 95, 96, -1, -1, 751, 100, - 101, -1, -1, 104, 757, 758, -1, 108, -1, -1, - -1, -1, 60, 114, -1, -1, 769, -1, -1, -1, - -1, -1, 70, -1, 871, -1, -1, -1, -1, 77, - -1, -1, -1, -1, -1, 3, -1, 5, 6, 792, - 793, -1, -1, 11, 92, -1, 94, 95, 96, -1, - 18, -1, 100, 101, -1, -1, 104, -1, -1, -1, - 108, -1, -1, -1, -1, -1, 114, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 829, 45, 46, -1, - -1, -1, 835, 836, 837, -1, -1, 55, 56, 57, - 58, 59, 60, 61, 62, 63, 64, 65, -1, 67, - -1, 69, 70, 71, 72, -1, -1, -1, 76, 77, - -1, 79, 80, 81, -1, -1, 18, 85, 871, 87, - -1, -1, 90, 91, 92, -1, 94, 95, 96, -1, - 98, 99, 100, 101, 102, 103, 104, 105, 106, -1, - 108, -1, 110, 111, -1, 113, 114, 115, 116, 3, - -1, 5, 6, 55, 55, -1, -1, 11, -1, -1, - 62, 62, 64, 64, 18, 67, 67, -1, -1, -1, - 72, 72, -1, -1, -1, -1, -1, 79, 79, -1, - -1, -1, -1, 85, 85, 87, 87, -1, -1, -1, - -1, 45, 46, -1, -1, -1, -1, 99, 99, -1, - -1, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, -1, 67, -1, 69, 70, 71, 72, -1, - -1, -1, 76, 77, -1, 79, 80, 81, -1, -1, - -1, 85, -1, 87, -1, -1, 90, 91, 92, -1, - 94, 95, 96, -1, 98, 99, 100, 101, 102, 103, - 104, 105, 106, -1, 108, -1, 110, 111, -1, 113, - 114, 115, 116, 3, -1, 5, 6, -1, -1, -1, - -1, 11, -1, 28, -1, -1, -1, -1, 18, 34, - 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 45, 46, -1, -1, -1, - -1, -1, -1, -1, -1, 55, 56, 57, 58, 59, - 60, 61, 62, 63, 64, 65, -1, 67, -1, 69, - 70, 71, 72, -1, -1, -1, 76, 77, -1, 79, - 80, 81, -1, -1, -1, 85, -1, 87, -1, -1, - 90, 91, 92, -1, 94, 95, 96, -1, 98, 99, - 100, 101, 102, 103, 104, 105, 106, -1, 108, -1, - 110, 111, -1, 113, 114, 115, 116, 3, -1, 5, - 6, -1, -1, -1, -1, 11, -1, -1, -1, -1, - -1, -1, 18, 19, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 45, - 46, -1, -1, -1, -1, -1, -1, -1, -1, 55, - 56, 57, 58, 59, 60, 61, 62, 63, 64, -1, - -1, 67, -1, 69, 70, 71, 72, -1, -1, -1, - 76, 77, -1, 79, 80, 81, -1, -1, -1, 85, - -1, 87, -1, -1, 90, 91, 92, -1, 94, 95, - 96, -1, 98, 99, 100, 101, 102, 103, 104, 105, - 106, -1, 108, -1, 110, 111, -1, 113, 114, 115, - 116, 3, -1, 5, 6, -1, -1, -1, -1, 11, - -1, -1, -1, -1, -1, -1, 18, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 45, 46, -1, -1, -1, -1, -1, - -1, -1, -1, 55, 56, 57, 58, 59, 60, 61, - 62, 63, 64, -1, -1, 67, -1, 69, 70, 71, - 72, -1, -1, -1, 76, 77, -1, 79, 80, 81, - -1, -1, -1, 85, -1, 87, -1, -1, 90, 91, - 92, -1, 94, 95, 96, -1, 98, 99, 100, 101, - 102, 103, 104, 105, 106, -1, 108, -1, 110, 111, - -1, 113, 114, 115, 116, 3, -1, 5, 6, -1, - -1, -1, -1, 11, -1, -1, -1, -1, -1, -1, - 18, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 45, 46, -1, - -1, -1, -1, -1, -1, -1, -1, 55, 56, 57, - 58, 59, 60, 61, 62, 63, 64, -1, -1, 67, - -1, 69, 70, 71, 72, -1, -1, -1, 76, 77, - -1, 79, 80, 81, -1, -1, -1, 85, -1, 87, - -1, -1, 90, 91, 92, -1, 94, 95, 96, -1, - 98, 99, 100, 101, 102, 103, 104, 105, 106, -1, - 108, -1, 110, 111, -1, 113, 114, 115, 116, 3, - -1, 5, 6, -1, -1, -1, -1, 11, -1, -1, - -1, -1, -1, -1, 18, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 45, 46, -1, -1, -1, -1, -1, -1, -1, - -1, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, -1, -1, 67, -1, 69, 70, 71, 72, -1, - -1, -1, 76, 77, -1, 79, 80, 81, -1, -1, - -1, 85, -1, 87, -1, -1, 90, 91, 92, -1, - 94, 95, 96, -1, 98, 99, 100, 101, 102, 103, - 104, 105, 106, -1, 108, -1, 110, 111, -1, 113, - 114, 115, 116, 3, -1, 5, 6, -1, -1, -1, - -1, 11, -1, -1, -1, -1, -1, -1, 18, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 45, 46, -1, -1, -1, - -1, -1, -1, -1, -1, 55, 56, 57, 58, 59, - 60, 61, 62, 63, 64, -1, -1, 67, -1, 69, - 70, 71, 72, -1, -1, -1, 76, 77, -1, 79, - 80, 81, -1, -1, -1, 85, -1, 87, -1, -1, - 90, 91, 92, -1, 94, 95, 96, -1, 98, 99, - 100, 101, 102, 103, 104, 105, 106, -1, 108, -1, - 110, 111, -1, 113, 114, 115, 116, 3, -1, 5, - 6, -1, -1, -1, -1, 11, -1, -1, -1, -1, - -1, -1, 18, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 45, - 46, -1, -1, -1, -1, -1, -1, -1, -1, 55, - 56, 57, 58, 59, 60, 61, 62, 63, 64, -1, - -1, 67, -1, 69, 70, 71, 72, -1, -1, -1, - 76, 77, -1, 79, 80, 81, -1, -1, -1, 85, - -1, 87, -1, -1, 90, 91, 92, -1, 94, 95, - 96, -1, 98, 99, 100, 101, 102, 103, 104, 105, - 106, -1, 108, -1, 110, 111, -1, 113, 114, 115, - 116, 3, -1, 5, -1, -1, -1, -1, -1, 11, - -1, -1, -1, -1, -1, -1, 18, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 45, 46, -1, -1, -1, -1, -1, - -1, -1, -1, 55, 56, 57, 58, 59, -1, 61, - 62, 63, 64, -1, -1, 67, -1, 69, -1, 71, - 72, -1, -1, 18, 76, -1, -1, 79, 80, 81, - -1, 26, -1, 85, 18, 87, -1, -1, 90, 91, - -1, -1, 26, -1, -1, -1, 98, 99, -1, -1, - 102, 103, 104, 105, 106, 3, 4, -1, 110, 111, - 55, 113, -1, 115, 116, -1, -1, 62, -1, 64, - 18, 55, 67, -1, 22, 23, -1, 72, 62, -1, - 64, 29, 30, 67, 79, -1, -1, -1, 72, -1, - 85, -1, 87, -1, -1, 79, -1, 45, 46, -1, - -1, 85, -1, 87, 99, -1, -1, 55, 56, 57, - 58, 59, 60, -1, 62, 99, 64, -1, -1, 67, - -1, 18, 70, -1, 72, -1, -1, -1, 76, 77, - -1, 79, -1, -1, -1, -1, -1, 85, -1, 87, - -1, -1, 90, 91, 92, -1, 94, 95, 96, -1, - -1, 99, 100, 101, 102, 103, 104, 105, -1, -1, - 108, -1, 110, 60, -1, 113, 114, 3, 4, 5, - -1, -1, -1, 70, -1, -1, -1, 74, -1, -1, - 77, -1, 18, -1, -1, -1, 22, 23, -1, 86, - -1, -1, -1, 29, 30, 92, -1, 94, 95, 96, - 97, -1, -1, 100, 101, -1, -1, 104, -1, 45, - 46, 108, -1, -1, -1, -1, -1, 114, -1, 55, - 56, 57, 58, 59, -1, -1, 62, -1, 64, -1, - -1, 67, -1, 3, -1, 5, 72, -1, -1, 9, - 76, -1, -1, 79, -1, -1, -1, -1, 18, 85, - -1, 87, 22, 23, 90, 91, -1, -1, -1, 29, - 30, -1, -1, 99, -1, -1, 102, 103, -1, 105, - -1, -1, -1, -1, 110, 45, 46, 113, -1, -1, - -1, -1, -1, -1, -1, 55, 56, 57, 58, 59, - -1, -1, 62, -1, 64, -1, -1, 67, -1, 3, - -1, 5, 72, -1, -1, -1, 76, -1, -1, 79, - -1, -1, -1, -1, 18, 85, -1, 87, 22, 23, - 90, 91, -1, -1, -1, 29, 30, -1, -1, 99, - -1, -1, 102, 103, -1, 105, -1, -1, -1, -1, - 110, 45, 46, 113, -1, -1, -1, -1, -1, -1, - -1, 55, 56, 57, 58, 59, -1, -1, 62, -1, - 64, -1, -1, 67, -1, 3, 4, -1, 72, -1, - -1, -1, 76, -1, -1, 79, -1, -1, -1, -1, - 18, 85, -1, 87, 22, 23, 90, 91, -1, -1, - -1, 29, 30, -1, -1, 99, -1, -1, 102, 103, - -1, 105, 106, -1, -1, -1, 110, 45, 46, 113, - -1, -1, -1, -1, -1, -1, -1, 55, 56, 57, - 58, 59, -1, -1, 62, -1, 64, -1, -1, 67, - -1, 3, -1, 5, 72, -1, -1, -1, 76, -1, - -1, 79, -1, -1, -1, -1, 18, 85, -1, 87, - 22, 23, 90, 91, -1, -1, -1, 29, 30, -1, - -1, 99, -1, -1, 102, 103, -1, 105, -1, -1, - -1, -1, 110, 45, 46, 113, -1, -1, -1, -1, - -1, -1, -1, 55, 56, 57, 58, 59, -1, -1, - 62, -1, 64, -1, -1, 67, -1, 3, -1, 5, - 72, -1, -1, -1, 76, -1, -1, 79, -1, -1, - -1, -1, 18, 85, -1, 87, 22, 23, 90, 91, - -1, -1, -1, 29, 30, -1, -1, 99, -1, -1, - 102, 103, -1, 105, -1, -1, -1, -1, 110, 45, - 46, 113, -1, -1, -1, -1, -1, -1, -1, 55, - 56, 57, 58, 59, -1, -1, 62, -1, 64, -1, - -1, 67, -1, 3, -1, -1, 72, -1, 8, -1, - 76, -1, -1, 79, -1, -1, -1, -1, 18, 85, - -1, 87, 22, 23, 90, 91, -1, -1, -1, 29, - 30, -1, -1, 99, -1, -1, 102, 103, -1, 105, - -1, -1, -1, -1, 110, 45, 46, 113, -1, -1, - -1, -1, -1, -1, -1, 55, 56, 57, 58, 59, - -1, -1, 62, -1, 64, -1, -1, 67, -1, 3, - -1, 5, 72, -1, -1, -1, 76, -1, -1, 79, - -1, -1, -1, -1, 18, 85, -1, 87, 22, 23, - 90, 91, -1, -1, -1, 29, 30, -1, -1, 99, - -1, -1, 102, 103, -1, 105, -1, -1, -1, -1, - 110, 45, 46, 113, -1, -1, -1, -1, -1, -1, - -1, 55, 56, 57, 58, 59, -1, -1, 62, -1, - 64, -1, -1, 67, -1, 3, -1, -1, 72, -1, - 8, -1, 76, -1, -1, 79, -1, -1, -1, -1, - 18, 85, -1, 87, 22, 23, 90, 91, -1, -1, - -1, 29, 30, -1, -1, 99, -1, -1, 102, 103, - -1, 105, -1, -1, -1, -1, 110, 45, 46, 113, - -1, -1, -1, -1, -1, -1, -1, 55, 56, 57, - 58, 59, -1, -1, 62, -1, 64, -1, -1, 67, - -1, 3, -1, -1, 72, -1, -1, -1, 76, 11, - -1, 79, -1, -1, -1, -1, 18, 85, -1, 87, - 22, 23, 90, 91, -1, -1, -1, 29, 30, -1, - -1, 99, -1, -1, 102, 103, -1, 105, -1, -1, - -1, -1, 110, 45, 46, 113, -1, -1, -1, -1, - -1, -1, -1, 55, 56, 57, 58, 59, -1, -1, - 62, -1, 64, -1, -1, 67, -1, 3, -1, -1, - 72, -1, -1, -1, 76, -1, -1, 79, -1, -1, - -1, -1, 18, 85, -1, 87, 22, 23, 90, 91, - -1, -1, -1, 29, 30, -1, -1, 99, -1, -1, - 102, 103, -1, 105, -1, -1, -1, -1, 110, 45, - 46, 113, -1, -1, -1, -1, -1, -1, -1, 55, - 56, 57, 58, 59, -1, -1, 62, -1, 64, -1, - -1, 67, -1, 3, -1, -1, 72, -1, -1, -1, - 76, -1, -1, 79, -1, -1, -1, -1, 18, 85, - -1, 87, 22, 23, 90, 91, -1, -1, -1, 29, - 30, -1, -1, 99, -1, -1, 102, 103, -1, 105, - -1, -1, -1, -1, 110, 45, 46, 113, -1, -1, - -1, -1, -1, -1, -1, 55, 56, 57, 58, 59, - -1, -1, 62, -1, 64, 3, -1, 67, -1, -1, - -1, -1, 72, -1, -1, -1, 76, -1, -1, 79, - 18, -1, -1, -1, -1, 85, -1, 87, -1, -1, - 90, 91, -1, -1, -1, -1, -1, -1, -1, 99, - -1, -1, 102, 103, -1, 105, -1, 45, 46, -1, - 110, -1, -1, 113, -1, -1, -1, 55, 56, 57, - 58, 59, -1, -1, 62, -1, 64, 3, -1, 67, - -1, -1, -1, -1, 72, -1, -1, -1, 76, -1, - -1, 79, 18, -1, -1, -1, -1, 85, -1, 87, - -1, -1, 90, 91, -1, -1, -1, -1, -1, -1, - -1, 99, -1, -1, 102, -1, -1, 105, -1, 45, - 46, -1, 110, -1, 112, 113, -1, -1, -1, 55, - 56, 57, 58, 59, -1, -1, 62, -1, 64, 3, - 4, 67, -1, -1, -1, -1, 72, -1, -1, -1, - 76, -1, -1, 79, 18, -1, -1, -1, -1, 85, - -1, 87, -1, -1, 90, 91, -1, -1, -1, -1, - -1, -1, -1, 99, -1, -1, 102, -1, -1, 105, - -1, -1, -1, -1, 110, -1, -1, 113, -1, -1, - -1, 55, 56, 57, 58, 59, -1, -1, 62, 3, - 64, -1, -1, 67, -1, -1, -1, -1, 72, -1, - -1, -1, 76, -1, 18, 79, -1, -1, -1, -1, - -1, 85, -1, 87, -1, -1, 90, 91, -1, -1, - -1, -1, -1, -1, -1, 99, -1, -1, 102, -1, - -1, 105, -1, -1, -1, -1, 110, -1, 112, 113, - -1, 55, 56, 57, 58, 59, 4, -1, 62, -1, - 64, -1, -1, 67, -1, -1, -1, -1, 72, -1, - 18, -1, 76, -1, -1, 79, -1, -1, 5, 6, - -1, 85, -1, 87, 11, -1, 90, 91, -1, -1, - -1, 18, -1, -1, -1, 99, -1, -1, 102, -1, - -1, 105, -1, -1, -1, -1, 110, 55, 112, 113, - -1, -1, 60, -1, 62, -1, 64, 5, 6, 67, - -1, -1, 70, 11, 72, -1, -1, -1, -1, 77, - 18, 79, -1, 60, -1, -1, -1, 85, -1, 87, - -1, -1, -1, 70, 92, -1, 94, 95, 96, -1, - 77, 99, 100, 101, -1, -1, 104, -1, -1, -1, - 108, -1, -1, -1, -1, 92, 114, 94, 95, 96, - 5, 6, 60, 100, 101, -1, 11, 104, -1, -1, - -1, 108, 70, 18, -1, -1, -1, 114, -1, 77, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 92, -1, 94, 95, 96, 5, - 6, -1, 100, 101, -1, 11, 104, -1, -1, -1, - 108, -1, 18, -1, -1, 60, 114, -1, -1, -1, - 5, 6, -1, -1, -1, 70, 11, -1, -1, -1, - -1, -1, 77, 18, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 92, -1, 94, - 95, 96, -1, -1, 60, 100, 101, -1, -1, 104, - 6, -1, -1, 108, 70, -1, -1, -1, -1, 114, - -1, 77, 18, -1, -1, 60, -1, -1, -1, -1, - -1, 6, -1, -1, -1, 70, 92, -1, 94, 95, - 96, -1, 77, 18, 100, 101, -1, -1, 104, -1, - -1, -1, 108, -1, -1, -1, -1, 92, 114, 94, - 95, 96, -1, -1, 60, 100, 101, -1, -1, 104, - -1, -1, -1, 108, 70, -1, -1, -1, -1, 114, - -1, 77, -1, -1, -1, 60, 18, 19, -1, -1, - -1, -1, -1, -1, -1, 70, 92, -1, 94, 95, - 96, -1, 77, -1, 100, 101, -1, -1, 104, -1, - -1, -1, 108, -1, -1, -1, -1, 92, 114, 94, - 95, 96, -1, 55, -1, 100, 101, -1, 60, 104, - 62, -1, 64, 108, -1, 67, -1, -1, 70, 114, - 72, -1, 74, 18, 19, 77, -1, 79, -1, -1, - -1, -1, -1, 85, 86, 87, -1, -1, -1, -1, - 92, -1, 94, 95, 96, 97, -1, 99, 100, 101, - -1, -1, 104, -1, -1, -1, 108, -1, -1, -1, - 55, 113, 114, -1, -1, 60, -1, 62, -1, 64, - -1, -1, 67, -1, -1, 70, -1, 72, 18, 74, - -1, -1, 77, -1, 79, -1, -1, -1, -1, -1, - 85, 86, 87, -1, -1, -1, -1, 92, -1, 94, - 95, 96, 97, -1, 99, 100, 101, -1, -1, 104, - -1, -1, -1, 108, -1, 55, -1, -1, 113, 114, - 60, 18, 62, -1, 64, -1, -1, 67, -1, -1, - 70, -1, 72, -1, 74, -1, -1, 77, -1, 79, - -1, -1, -1, -1, -1, 85, 86, 87, -1, -1, - -1, -1, 92, -1, 94, 95, 96, 97, 55, 99, - 100, 101, -1, 60, 104, 62, -1, 64, 108, -1, - 67, -1, 112, 70, 114, 72, 18, 74, -1, -1, - 77, -1, 79, -1, -1, -1, -1, -1, 85, 86, - 87, -1, -1, -1, -1, 92, -1, 94, 95, 96, - 97, -1, 99, 100, 101, -1, -1, 104, -1, 18, - -1, 108, -1, 55, -1, -1, -1, 114, 60, -1, - 62, -1, 64, -1, -1, 67, -1, -1, 70, -1, - 72, -1, -1, -1, -1, 77, -1, 79, 18, -1, - -1, -1, -1, 85, -1, 87, -1, -1, -1, -1, - 92, 60, 94, 95, 96, -1, -1, 99, 100, 101, - -1, 70, 104, -1, 18, 19, 108, -1, 77, -1, - -1, -1, 114, -1, 83, -1, -1, -1, -1, -1, - 60, -1, -1, 92, -1, 94, 95, 96, -1, -1, - 70, 100, 101, -1, -1, 104, -1, 77, -1, 108, - -1, 55, -1, -1, -1, 114, -1, -1, 62, -1, - 64, -1, 92, 67, 94, 95, 96, -1, 72, 60, - 100, 101, -1, -1, 104, 79, -1, -1, 108, 70, - -1, 85, -1, 87, 114, -1, 77, -1, -1, -1, - -1, -1, -1, -1, -1, 99, -1, -1, -1, -1, - -1, 92, -1, 94, 95, 96, -1, -1, -1, 100, - 101, -1, 4, 104, -1, 7, -1, 108, 10, -1, - -1, 13, -1, 114, -1, 17, 18, 19, -1, -1, - -1, -1, -1, -1, -1, -1, 28, -1, -1, -1, - -1, -1, 34, 35, 36, 37, 38, 39, 40, 41, - 42, 43, 44, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 55 - }; - } - -/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ - private static final short[] yystos_ = yystos_init(); - private static final short[] yystos_init() - { - return new short[] - { - 0, 83, 88, 93, 134, 135, 136, 137, 138, 139, - 55, 100, 129, 129, 129, 0, 18, 60, 70, 77, - 92, 94, 95, 96, 100, 101, 104, 108, 114, 130, - 131, 132, 133, 139, 141, 307, 308, 129, 10, 11, - 5, 10, 11, 129, 18, 74, 86, 97, 130, 142, - 151, 152, 171, 176, 201, 202, 210, 133, 130, 132, - 308, 10, 11, 14, 55, 120, 121, 123, 124, 125, - 143, 144, 145, 137, 3, 86, 55, 55, 55, 68, - 142, 14, 11, 100, 109, 147, 129, 129, 129, 129, - 6, 145, 140, 141, 3, 4, 5, 22, 23, 29, - 30, 45, 46, 55, 56, 57, 58, 59, 62, 64, - 67, 72, 76, 79, 85, 87, 90, 91, 99, 102, - 103, 105, 110, 113, 128, 129, 148, 149, 150, 254, - 255, 256, 263, 264, 265, 268, 269, 282, 284, 285, - 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, - 296, 297, 298, 299, 300, 301, 302, 303, 305, 307, - 308, 309, 310, 55, 82, 159, 19, 153, 154, 153, - 55, 11, 109, 100, 129, 11, 122, 11, 122, 11, - 126, 3, 55, 129, 148, 263, 264, 272, 273, 274, - 278, 279, 280, 282, 304, 9, 55, 310, 311, 295, - 295, 295, 295, 295, 295, 3, 10, 28, 266, 19, - 129, 148, 259, 260, 10, 13, 3, 7, 198, 199, - 200, 307, 7, 10, 13, 260, 10, 13, 198, 200, - 7, 10, 13, 26, 47, 283, 48, 21, 27, 17, - 49, 51, 19, 20, 32, 33, 84, 52, 53, 54, - 22, 23, 14, 15, 16, 45, 46, 273, 295, 149, - 4, 9, 4, 5, 211, 148, 160, 5, 172, 55, - 155, 156, 157, 307, 75, 203, 204, 3, 177, 153, - 11, 129, 146, 146, 146, 4, 55, 130, 275, 276, - 277, 307, 24, 4, 24, 28, 34, 35, 36, 37, - 38, 39, 40, 41, 42, 43, 44, 281, 4, 17, - 6, 6, 9, 4, 267, 272, 259, 310, 26, 148, - 261, 262, 307, 7, 199, 270, 271, 307, 257, 258, - 306, 307, 55, 259, 259, 272, 8, 10, 200, 7, - 272, 90, 102, 256, 259, 102, 105, 259, 10, 272, - 55, 256, 259, 259, 272, 285, 286, 287, 288, 289, - 290, 290, 292, 292, 292, 292, 112, 148, 149, 220, - 253, 293, 293, 293, 294, 294, 295, 295, 295, 55, - 6, 130, 212, 9, 173, 174, 306, 75, 9, 20, - 157, 148, 5, 205, 9, 178, 179, 306, 159, 75, - 158, 9, 11, 11, 11, 112, 149, 4, 9, 4, - 9, 5, 216, 272, 216, 272, 272, 148, 310, 4, - 9, 129, 75, 102, 9, 20, 26, 272, 5, 186, - 198, 271, 7, 266, 10, 25, 259, 55, 55, 55, - 4, 68, 8, 8, 10, 55, 13, 55, 90, 68, - 8, 55, 55, 12, 55, 184, 185, 184, 28, 148, - 149, 151, 201, 208, 213, 214, 6, 130, 148, 9, - 11, 175, 55, 148, 161, 306, 307, 156, 6, 130, - 206, 148, 4, 9, 149, 5, 180, 148, 159, 129, - 55, 55, 306, 307, 55, 277, 3, 6, 11, 55, - 61, 63, 69, 71, 80, 81, 98, 103, 104, 106, - 111, 115, 116, 130, 216, 217, 218, 221, 222, 223, - 224, 225, 235, 236, 237, 242, 255, 265, 279, 296, - 297, 299, 300, 301, 272, 266, 148, 148, 262, 75, - 102, 8, 186, 187, 188, 189, 272, 272, 5, 162, - 163, 306, 266, 5, 227, 55, 259, 259, 266, 273, - 282, 28, 199, 9, 310, 184, 55, 213, 174, 175, - 11, 100, 130, 164, 165, 216, 6, 266, 17, 55, - 113, 149, 151, 154, 191, 201, 207, 208, 209, 6, - 130, 179, 55, 306, 6, 130, 165, 181, 182, 163, - 198, 198, 31, 12, 272, 11, 55, 11, 55, 104, - 221, 3, 3, 11, 272, 3, 3, 272, 3, 216, - 250, 3, 272, 149, 151, 202, 219, 220, 6, 218, - 11, 148, 148, 6, 9, 9, 8, 6, 164, 55, - 65, 70, 228, 229, 230, 231, 232, 233, 55, 55, - 272, 28, 185, 11, 3, 6, 216, 149, 151, 153, - 154, 166, 167, 168, 183, 190, 191, 201, 165, 163, - 148, 55, 192, 192, 113, 148, 149, 307, 11, 197, - 216, 207, 31, 55, 6, 182, 55, 221, 11, 12, - 11, 11, 115, 220, 224, 238, 240, 272, 11, 272, - 272, 11, 129, 220, 251, 252, 254, 263, 66, 78, - 244, 245, 249, 216, 272, 11, 11, 6, 189, 6, - 234, 278, 6, 229, 233, 6, 231, 232, 233, 70, - 217, 233, 12, 24, 266, 186, 4, 55, 184, 55, - 107, 196, 197, 3, 196, 196, 192, 192, 192, 113, - 55, 5, 169, 272, 3, 12, 11, 9, 4, 4, - 4, 4, 11, 3, 216, 245, 249, 243, 244, 4, - 9, 6, 12, 106, 216, 272, 198, 11, 3, 160, - 169, 4, 131, 149, 193, 194, 196, 196, 196, 192, - 6, 129, 170, 217, 254, 259, 11, 272, 272, 239, - 272, 224, 221, 227, 216, 4, 252, 130, 246, 248, - 249, 221, 278, 272, 11, 70, 215, 193, 198, 149, - 55, 105, 195, 306, 4, 9, 196, 10, 6, 217, - 6, 10, 102, 105, 4, 4, 11, 73, 226, 148, - 247, 4, 11, 310, 11, 4, 195, 10, 198, 31, - 198, 194, 259, 6, 259, 266, 266, 11, 221, 240, - 241, 221, 21, 55, 216, 105, 55, 102, 102, 11, - 11, 4, 148, 198, 266, 266, 221, 11, 11 - }; - } - -/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ - private static final short[] yyr1_ = yyr1_init(); - private static final short[] yyr1_init() - { - return new short[] - { - 0, 127, 128, 128, 128, 128, 128, 128, 128, 129, - 129, 130, 130, 131, 131, 132, 132, 133, 133, 133, - 133, 133, 133, 133, 133, 133, 133, 133, 133, 134, - 134, 134, 134, 135, 136, 137, 137, 138, 138, 139, - 139, 139, 139, 140, 140, 141, 141, 142, 142, 143, - 143, 144, 144, 145, 145, 145, 145, 145, 145, 145, - 146, 146, 147, 147, 147, 147, 147, 148, 148, 149, - 149, 149, 149, 150, 150, 150, 150, 150, 150, 150, - 150, 151, 151, 151, 152, 153, 153, 154, 155, 155, - 156, 156, 157, 157, 157, 158, 158, 159, 159, 160, - 160, 161, 161, 162, 162, 163, 163, 164, 164, 165, - 165, 165, 165, 166, 166, 166, 166, 166, 167, 168, - 169, 169, 169, 169, 170, 170, 170, 170, 171, 172, - 172, 173, 173, 173, 174, 174, 175, 175, 175, 176, - 177, 178, 178, 178, 179, 179, 180, 180, 181, 181, - 182, 182, 183, 184, 184, 185, 185, 185, 185, 186, - 186, 187, 187, 188, 188, 189, 189, 190, 191, 191, - 191, 191, 191, 191, 192, 192, 193, 193, 194, 194, - 195, 195, 195, 195, 196, 196, 197, 197, 198, 198, - 199, 199, 200, 200, 201, 201, 202, 203, 203, 204, - 204, 205, 205, 206, 206, 207, 207, 207, 207, 208, - 209, 210, 211, 211, 212, 212, 213, 213, 213, 213, - 214, 215, 215, 216, 216, 217, 217, 218, 218, 219, - 219, 219, 220, 220, 221, 221, 221, 221, 221, 222, - 222, 222, 222, 222, 222, 222, 222, 222, 222, 222, - 222, 222, 222, 222, 222, 222, 222, 222, 222, 223, - 224, 224, 224, 224, 224, 224, 224, 225, 226, 226, - 227, 227, 227, 228, 228, 229, 229, 229, 230, 230, - 230, 231, 231, 232, 232, 233, 233, 234, 234, 235, - 236, 236, 237, 238, 238, 238, 239, 239, 240, 240, - 241, 241, 242, 243, 243, 244, 244, 245, 246, 247, - 247, 248, 248, 249, 250, 250, 251, 251, 252, 252, - 253, 254, 254, 254, 254, 254, 254, 254, 254, 254, - 254, 254, 254, 255, 255, 255, 256, 257, 257, 258, - 258, 259, 259, 260, 261, 261, 262, 262, 262, 262, - 262, 262, 262, 263, 263, 263, 264, 264, 265, 265, - 265, 265, 265, 266, 266, 267, 267, 268, 268, 268, - 268, 268, 268, 269, 269, 270, 270, 271, 271, 272, - 272, 273, 273, 273, 273, 274, 274, 274, 275, 275, - 276, 276, 277, 277, 277, 278, 278, 279, 280, 280, - 280, 281, 281, 281, 281, 281, 281, 281, 281, 281, - 281, 281, 281, 282, 283, 283, 283, 284, 284, 285, - 285, 286, 286, 287, 287, 288, 288, 289, 289, 289, - 290, 290, 290, 290, 290, 290, 291, 291, 292, 292, - 292, 292, 293, 293, 293, 294, 294, 294, 294, 295, - 295, 295, 295, 295, 296, 297, 298, 298, 298, 298, - 298, 299, 299, 299, 299, 300, 301, 302, 302, 303, - 304, 304, 305, 306, 306, 307, 307, 308, 308, 308, - 308, 309, 309, 310, 310, 310, 310, 311, 311, 311 - }; - } - -/* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ - private static final byte[] yyr2_ = yyr2_init(); - private static final byte[] yyr2_init() - { - return new byte[] - { - 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, - 3, 0, 1, 1, 2, 1, 2, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, - 1, 1, 2, 5, 5, 0, 1, 1, 2, 3, - 4, 5, 6, 0, 1, 2, 3, 1, 1, 0, - 1, 1, 2, 4, 3, 5, 3, 5, 3, 5, - 1, 3, 0, 1, 2, 1, 2, 1, 2, 1, - 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 7, 0, 1, 3, 1, 3, - 2, 1, 1, 4, 3, 0, 2, 0, 2, 1, - 3, 1, 3, 0, 1, 2, 3, 1, 2, 2, - 1, 2, 1, 1, 1, 1, 1, 1, 3, 5, - 2, 3, 3, 4, 4, 4, 6, 6, 4, 4, - 5, 0, 1, 3, 3, 4, 0, 1, 2, 6, - 3, 0, 1, 3, 3, 5, 2, 3, 1, 2, - 1, 3, 3, 1, 3, 1, 3, 2, 4, 3, - 4, 0, 1, 1, 3, 1, 1, 2, 4, 5, - 4, 4, 3, 3, 4, 5, 1, 3, 3, 2, - 2, 3, 1, 3, 0, 2, 1, 1, 0, 1, - 1, 2, 3, 2, 1, 1, 5, 0, 1, 2, - 3, 2, 3, 2, 3, 1, 1, 1, 1, 3, - 2, 4, 2, 3, 2, 3, 1, 1, 1, 1, - 7, 0, 2, 2, 3, 1, 2, 2, 1, 1, - 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, - 1, 2, 3, 5, 5, 7, 2, 3, 2, 3, - 2, 3, 5, 3, 3, 3, 4, 3, 5, 3, - 1, 1, 1, 1, 1, 1, 1, 6, 0, 2, - 3, 3, 4, 1, 2, 4, 3, 5, 0, 1, - 2, 1, 2, 2, 3, 2, 1, 1, 3, 5, - 1, 1, 9, 0, 1, 1, 0, 1, 1, 3, - 0, 1, 7, 0, 1, 1, 2, 5, 4, 1, - 3, 0, 1, 2, 3, 4, 1, 3, 1, 1, - 1, 1, 4, 4, 1, 3, 3, 1, 1, 1, - 1, 1, 1, 1, 3, 3, 5, 2, 2, 2, - 4, 0, 1, 3, 1, 3, 1, 1, 3, 3, - 2, 4, 4, 3, 3, 5, 4, 4, 2, 5, - 5, 5, 7, 2, 3, 1, 3, 4, 4, 4, - 4, 6, 4, 4, 4, 1, 2, 3, 4, 1, - 1, 3, 3, 3, 3, 2, 3, 3, 1, 3, - 1, 3, 4, 4, 5, 1, 1, 3, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 2, 0, 4, 4, 1, 3, 1, - 3, 1, 3, 1, 3, 1, 3, 1, 3, 3, - 1, 3, 3, 3, 3, 1, 3, 3, 1, 3, - 3, 3, 1, 3, 3, 1, 3, 3, 3, 1, - 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, - 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, - 1, 3, 5, 0, 1, 1, 2, 2, 4, 5, - 5, 3, 5, 1, 3, 3, 1, 0, 1, 3 - }; - } - - - - - /* YYTRANSLATE_(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM - as returned by yylex, with out-of-bounds checking. */ - private static final SymbolKind yytranslate_(int t) - { - // Last valid token kind. - int code_max = 381; - if (t <= 0) - return SymbolKind.S_YYEOF; - else if (t <= code_max) - return SymbolKind.get(yytranslate_table_[t]); - else - return SymbolKind.S_YYUNDEF; - } - private static final byte[] yytranslate_table_ = yytranslate_table_init(); - private static final byte[] yytranslate_table_init() - { - return new byte[] - { - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, - 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, - 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, - 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, - 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, - 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, - 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, - 125, 126 - }; - } - - - private static final int YYLAST_ = 4673; - private static final int YYEMPTY_ = -2; - private static final int YYFINAL_ = 15; - private static final int YYNTOKENS_ = 127; - -/* Unqualified %code blocks. */ -/* "src/main/resources/Java_16_Grammar.y":148 */ - - public CompilationUnit ast; - -/* "src/main/java/parser/JavaParser.java":6019 */ - -} -/* "src/main/resources/Java_16_Grammar.y":1477 */ - - diff --git a/src/main/java/translator/Blocks.java b/src/main/java/translator/Blocks.java deleted file mode 100644 index 739b6f13..00000000 --- a/src/main/java/translator/Blocks.java +++ /dev/null @@ -1,13 +0,0 @@ -package translator; - -import eotree.EOBndExpr; - -public class Blocks { - /** - * In order to map Java block into EO, all variable declarations are separated out as memory objects and then seq - * contains all the logic. - * */ - public static EOBndExpr mapBlock() { - throw new UnsupportedOperationException("Not implemented"); - } -} diff --git a/src/main/java/translator/Blocks.kt b/src/main/java/translator/Blocks.kt new file mode 100644 index 00000000..bd4a99e6 --- /dev/null +++ b/src/main/java/translator/Blocks.kt @@ -0,0 +1,11 @@ +package translator + +import eotree.EOBndExpr + +/** + * In order to map Java block into EO, all variable declarations are separated out as memory objects and then seq + * contains all the logic. + */ +fun mapBlock(): EOBndExpr { + throw UnsupportedOperationException("Not implemented") +} diff --git a/src/main/java/translator/Classes.java b/src/main/java/translator/Classes.java deleted file mode 100644 index 70f781cf..00000000 --- a/src/main/java/translator/Classes.java +++ /dev/null @@ -1,58 +0,0 @@ -package translator; - -import eotree.*; -import tree.Declaration.*; - -import java.util.*; -import java.util.stream.Collectors; - -import static util.ListUtils.concat; -import static util.ListUtils.listOf; - -public class Classes { - public static EOBnd mapClass(ClassDeclaration classDeclaration) { - if (!(classDeclaration instanceof NormalClassDeclaration)) - throw new IllegalArgumentException("Only NormalClassDeclaration is supported, but " + - classDeclaration.getClass().getSimpleName() - + " was passed"); - NormalClassDeclaration clsDec = (NormalClassDeclaration) classDeclaration; - - // TODO: implement inheritance support - if (clsDec.extendedType != null) - throw new IllegalArgumentException("Extended types are not supported yet"); - - return new EOBndExpr( - new EOObject( - new ArrayList<>(), - Optional.empty(), - concat(listOf( - /* Super class extension */ - clsDec.extendedType != null ? -// new EOBndExpr( -// new EODot(Optional.empty(), clsDec.extendedType.), -// new EOBndName("@") -// ) - null : - // Derive classes without "extends" specification from Object class. - new EOBndExpr( - new EODot(Optional.empty(), "class_Object"), - new EOBndName("@") - ) - - - ), - clsDec.body != null ? - clsDec.body.declarations.stream() - .map(Declarations::mapDeclaration) - .collect(Collectors.toList()) : - new ArrayList<>() - ) - ), - new EOBndName("class_" + clsDec.name) - ); - } - - public static EOBnd mapInterface(InterfaceDeclaration interfaceDeclaration) { - throw new IllegalArgumentException("Interface declarations are not yet implemented"); - } -} diff --git a/src/main/java/translator/Classes.kt b/src/main/java/translator/Classes.kt new file mode 100644 index 00000000..167a5428 --- /dev/null +++ b/src/main/java/translator/Classes.kt @@ -0,0 +1,57 @@ +package translator + +import arrow.core.None +import arrow.core.flattenOption +import eotree.* +import tree.Declaration.ClassDeclaration +import tree.Declaration.NormalClassDeclaration +import java.lang.IllegalArgumentException +import tree.Declaration.InterfaceDeclaration +import tree.Type.TypeName +import util.eoClassCompoundName +import util.eoClassName +import util.generateNew +import util.generateStatic +import java.util.ArrayList + +fun mapClass(clsDec: ClassDeclaration): EOBndExpr { + require(clsDec is NormalClassDeclaration) { + ("Only NormalClassDeclaration is supported, but " + + clsDec.javaClass.simpleName + + " was passed") + } + return EOBndExpr( + EOObject( + ArrayList(), + None, + /* Static variables */ + // clsDec.getStaticVariables().stream() + // .map(varDec -> Declarations.mapClassDeclaration(varDec)) + // .collect(Collectors.toList())), + + listOf( + /* Super class extension */ + (if (clsDec.extendedType is TypeName) + EOBndExpr( + (clsDec.extendedType as TypeName).compoundName.eoClassCompoundName().eoDot(), + "super" + ) + else + // Derive classes without "extends" specification from Object class. + EOBndExpr( + "class__Object".eoDot(), + "super" + )), + EOBndExpr( + "super".eoDot(), + "@" + ) + ) + (generateNew(clsDec)) + generateStatic(clsDec) + ), + clsDec.name + ) +} + +fun mapInterface(interfaceDeclaration: InterfaceDeclaration?): EOBnd { + throw IllegalArgumentException("Interface declarations are not yet implemented") +} diff --git a/src/main/java/translator/Declarations.java b/src/main/java/translator/Declarations.java deleted file mode 100644 index b06913f8..00000000 --- a/src/main/java/translator/Declarations.java +++ /dev/null @@ -1,24 +0,0 @@ -package translator; - -import eotree.EOBnd; -import eotree.EOBndExpr; -import tree.Declaration.ClassDeclaration; -import tree.Declaration.Declaration; -import tree.Declaration.MethodDeclaration; -import tree.Declaration.NormalClassDeclaration; - -public class Declarations { - - public static EOBndExpr mapDeclaration(Declaration dec) { - if (dec instanceof MethodDeclaration) { - return Methods.mapMethodDeclaration((MethodDeclaration) dec); - } - else if (dec instanceof NormalClassDeclaration) { - return (EOBndExpr) Classes.mapClass((ClassDeclaration) dec); - } else - throw new IllegalArgumentException("Declaration of type " + - dec.getClass().getSimpleName() - + " is not supported yet"); - - } -} diff --git a/src/main/java/translator/Declarations.kt b/src/main/java/translator/Declarations.kt new file mode 100644 index 00000000..174bce1c --- /dev/null +++ b/src/main/java/translator/Declarations.kt @@ -0,0 +1,44 @@ +package translator + +import arrow.core.None +import arrow.core.Option +import arrow.core.some +import eotree.EOBndExpr +import eotree.EODot +import tree.Declaration.* +import tree.Type.PrimitiveType +import tree.Type.TypeName + +fun mapClassDeclaration(dec: Declaration): Option { + // TODO: get rid of option and implement all cases + + return when (dec) { + is MethodDeclaration -> { + mapMethodDeclaration(dec).some() + } + is NormalClassDeclaration -> { + mapClass(dec as ClassDeclaration).some() + } + is VariableDeclaration -> { + mapVariableDeclaration(dec).some() + } + else -> { + None + } + } +} + +/** + * Maps a variable declaration in class object (i.e. static variable). + */ +fun mapVariableDeclaration(dec: VariableDeclaration): EOBndExpr = + when (dec.type) { + is TypeName -> + EOBndExpr(EODot("cage"), dec.name) + is PrimitiveType -> + EOBndExpr(EODot("memory"), dec.name) + null -> + throw IllegalArgumentException("\"var\" declarations are not supported yet") + else -> + throw IllegalArgumentException("Type of type " + dec.type.javaClass.name + " is not supported") + } diff --git a/src/main/java/translator/Expressions.java b/src/main/java/translator/Expressions.java deleted file mode 100644 index d0f27792..00000000 --- a/src/main/java/translator/Expressions.java +++ /dev/null @@ -1,19 +0,0 @@ -package translator; - -import eotree.EOAnonExpr; -import tree.Expression.Expression; -import tree.Expression.Primary.Literal; -import tree.Expression.Primary.MethodInvocation; - - -public class Expressions { - public static EOAnonExpr mapExpression(Expression expr) { - if (expr instanceof MethodInvocation){ - return new EOAnonExpr(MethodInvocations.mapMethodInvocation((MethodInvocation) expr)); - } else if (expr instanceof Literal){ - return new EOAnonExpr(Literals.mapLiteral((Literal) expr)); - } - - throw new IllegalArgumentException("Only MethodInvocation & Literal are supported!"); - } -} diff --git a/src/main/java/translator/Expressions.kt b/src/main/java/translator/Expressions.kt new file mode 100644 index 00000000..ff122853 --- /dev/null +++ b/src/main/java/translator/Expressions.kt @@ -0,0 +1,101 @@ +package translator + +import arrow.core.some +import eotree.* +import eotree.data.EOIntData +import lexer.TokenCode +import tree.Expression.* +import tree.Expression.Primary.Literal +import tree.Expression.Primary.MethodInvocation +import tree.Expression.Primary.Parenthesized +import tree.Expression.Primary.This + +fun mapExpression(expr: Expression): EOExpr = + when (expr) { + is MethodInvocation -> + mapMethodInvocation(expr) + is Literal -> + mapLiteral(expr) + is UnaryPrefix -> + mapUnaryPrefix(expr) + is UnaryPostfix -> + mapUnaryPostfix(expr) + is Binary -> + mapBinary(expr) + is SimpleReference -> + mapSimpleReference(expr) + is FieldAccess -> + mapFieldAccess(expr) + is This -> + mapThis(expr) + is Parenthesized -> + mapParenthesized(expr) + else -> + throw IllegalArgumentException("Expression of type ${expr.javaClass.simpleName} is not supported") + } + +fun mapParenthesized(expr: Parenthesized): EOExpr = + mapExpression(expr.expression) + +// TODO: add support for type +fun mapThis(expr: This): EOExpr = + "this".eoDot() + +fun mapFieldAccess(expr: FieldAccess): EOExpr = + "${mapExpression(expr.expression)}.${expr.identifier}".eoDot() + +fun mapUnaryPrefix(expr: UnaryPrefix): EOExpr { + val function = when (expr.operator) { + TokenCode.PlusPlus -> "add" + TokenCode.MinusMinus -> "sub" + else -> throw IllegalArgumentException("Unary prefix ${expr.operator} is not supported") + } + + // TODO: create separate state object to pass pre and post operations of the statement + // TODO: return EODot here + return EOCopy( + "${mapSimpleReference(expr.operand as SimpleReference)}.$function".eoDot(), + EOIntData(1) + ) +} + +// TODO: think about operation order +fun mapUnaryPostfix(expr: UnaryPostfix): EOExpr { + val function = when (expr.operator) { + TokenCode.PlusPlus -> "add" + TokenCode.MinusMinus -> "sub" + else -> throw IllegalArgumentException("Unary prefix ${expr.operator} is not supported") + } + + // TODO: create separate state object to pass pre and post operations of the statement + // TODO: return EODot here + return EOCopy( + "${mapSimpleReference(expr.operand as SimpleReference)}.$function".eoDot(), + EOIntData(1) + ) +} + +// TODO: add automatic casting for primitive types +// TODO: populate with all Java binary operators +fun mapBinary(expr: Binary): EOExpr { + val function = when (expr.operator) { + TokenCode.Plus -> "add" + TokenCode.Minus -> "minus" + TokenCode.Greater -> "greater" + TokenCode.GreaterEqual -> "geq" + TokenCode.Equal -> "eq" + TokenCode.Less -> "less" + TokenCode.LessEqual -> "leq" + TokenCode.Assign -> "write" + TokenCode.Star -> "mul" + else -> throw IllegalArgumentException("Binary operation ${expr.operator} is not supported") + } + + return EOCopy( + EODot(mapExpression(expr.left).some(), function), + mapExpression(expr.right) + ) +} + +fun mapSimpleReference(expr: SimpleReference): EOExpr = + expr.compoundName.eoDot() \ No newline at end of file diff --git a/src/main/java/translator/Literals.java b/src/main/java/translator/Literals.java deleted file mode 100644 index 29727c41..00000000 --- a/src/main/java/translator/Literals.java +++ /dev/null @@ -1,23 +0,0 @@ -package translator; - -import eotree.data.EOData; -import eotree.data.EOFloatData; -import eotree.data.EOIntData; -import eotree.data.EOStringData; -import lexer.TokenCode; -import tree.Expression.Primary.Literal; - - -public class Literals { - public static EOData mapLiteral(Literal literal) { - if (literal.code == TokenCode.StringLiteral){ - return new EOStringData((String) literal.value); - } else if (literal.code == TokenCode.FloatingLiteral){ - return new EOFloatData(((Number) literal.value).floatValue()); - } else if (literal.code == TokenCode.IntegerLiteral){ - return new EOIntData(((Number) literal.value).intValue()); - } - - return null; - } -} diff --git a/src/main/java/translator/Literals.kt b/src/main/java/translator/Literals.kt new file mode 100644 index 00000000..7bcbce06 --- /dev/null +++ b/src/main/java/translator/Literals.kt @@ -0,0 +1,16 @@ +package translator + +import eotree.data.EOData +import eotree.data.EOFloatData +import eotree.data.EOIntData +import eotree.data.EOStringData +import lexer.TokenCode +import tree.Expression.Primary.Literal + +fun mapLiteral(literal: Literal): EOData = + when (literal.code) { + TokenCode.StringLiteral -> EOStringData(literal.value as String) + TokenCode.FloatingLiteral -> EOFloatData((literal.value as String).toFloat()) + TokenCode.IntegerLiteral -> EOIntData((literal.value as String).toInt()) + else -> throw IllegalArgumentException("Mapping of type ${literal.javaClass.simpleName} is not supported.") + } diff --git a/src/main/java/translator/MethodInvocations.java b/src/main/java/translator/MethodInvocations.java deleted file mode 100644 index fb5a0f0f..00000000 --- a/src/main/java/translator/MethodInvocations.java +++ /dev/null @@ -1,56 +0,0 @@ -package translator; - -import eotree.*; -import tree.Expression.Expression; -import tree.Expression.Primary.MethodInvocation; -import tree.Expression.SimpleReference; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Optional; -import java.util.stream.Collectors; - - -public class MethodInvocations { - public static EOCopy mapMethodInvocation(MethodInvocation methodInvocation){ - Optional src = Optional.empty(); - if (methodInvocation.qualifier != null){ - Expression expr = methodInvocation.qualifier; - if (expr instanceof SimpleReference) { - Collections.reverse(((SimpleReference) expr).compoundName.names); - src = buildEODotObjTree(((SimpleReference) expr).compoundName.names); - } - } - if (methodInvocation.superSign){ - throw new IllegalArgumentException("Super sign isn't supported yet"); - } - if (methodInvocation.typeArguments != null){ - throw new IllegalArgumentException("Type arguments aren't supported yet"); - } - - return new EOCopy( - new EODot(src, methodInvocation.name), - methodInvocation.arguments.arguments.stream() - .map(Expressions::mapExpression) - .collect(Collectors.toList()) - ); - // Optional.empty() in EODot will be removed - } - - private static Optional buildEODotObjTree(ArrayList names) { - if (names.size() > 0) { - String name = names.remove(0); - if (name.equals("System")) { - name = "class_" + name; - } - return Optional.of( - new EODot( - buildEODotObjTree(names), - name - ) - ); - } else { - return Optional.empty(); - } - } -} diff --git a/src/main/java/translator/MethodInvocations.kt b/src/main/java/translator/MethodInvocations.kt new file mode 100644 index 00000000..25a63c39 --- /dev/null +++ b/src/main/java/translator/MethodInvocations.kt @@ -0,0 +1,43 @@ +package translator + +import arrow.core.None +import arrow.core.Option +import arrow.core.some +import eotree.* +import tree.Expression.Expression +import tree.Expression.Primary.MethodInvocation +import tree.Expression.SimpleReference +import util.isSystemOutCall +import java.util.* +import java.util.stream.Collectors +import kotlin.collections.ArrayList + + +// TODO: create state object to store binding of expression +fun mapMethodInvocation(methodInvocation: MethodInvocation): EOCopy { + require(!methodInvocation.superSign) { "Super sign isn't supported yet" } + require(methodInvocation.typeArguments == null) { "Type arguments aren't supported yet" } + + val isStaticCall = !isSystemOutCall(methodInvocation) + + val src: EODot = when (methodInvocation.qualifier) { + is SimpleReference -> + (methodInvocation.qualifier as SimpleReference).compoundName.eoDot() + else -> + throw IllegalArgumentException("Only SimpleReference is supported") + } + val callee: EODot = when (methodInvocation.qualifier) { + is SimpleReference -> + if ((methodInvocation.qualifier as SimpleReference).compoundName.names.size > 1) + (methodInvocation.qualifier as SimpleReference).compoundName.names.dropLast(1).eoDot() + else + "this".eoDot() + else -> + throw IllegalArgumentException("Only SimpleReference is supported") + } + return EOCopy( + src, + (if (!isStaticCall) listOf(callee) else ArrayList()) + + (methodInvocation.arguments?.arguments?.map { obj -> mapExpression(obj) } ?: listOf()) + ) +} diff --git a/src/main/java/translator/Methods.java b/src/main/java/translator/Methods.java deleted file mode 100644 index e7e29da9..00000000 --- a/src/main/java/translator/Methods.java +++ /dev/null @@ -1,49 +0,0 @@ -package translator; - -import eotree.*; -import tree.Declaration.MethodDeclaration; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Optional; -import java.util.stream.Collectors; - -import static util.ListUtils.listOf; - -public class Methods { - public static EOBndExpr mapMethodDeclaration(MethodDeclaration dec) { - return new EOBndExpr( - new EOObject( - // Non-vararg parameters - dec.parameters != null && !dec.name.equals("main") ? // Exclude 'String[] args' fon now - dec.parameters.parameters.stream() - .filter(param -> !param.signEllipsis) - .map(param -> new EOBndName(param.name)) - .collect(Collectors.toList()) : - new ArrayList<>(), - // Optional vararg parameter - dec.parameters != null ? - dec.parameters.parameters.stream() - .filter(param -> param.signEllipsis) - .map(param -> new EOBndName(param.name)) - .findFirst() : - Optional.empty(), - // Bound attributes - listOf( - new EOBndExpr( - new EOCopy( - new EODot(Optional.empty(), "seq"), - dec.methodBody != null ? - dec.methodBody.block.blockStatements.stream() - .map(Statements::mapBlockStatement) - .collect(Collectors.toList()) : - Collections.emptyList() - ), - new EOBndName("@") - ) - ) - ), - new EOBndName(dec.name) - ); - } -} diff --git a/src/main/java/translator/Methods.kt b/src/main/java/translator/Methods.kt new file mode 100644 index 00000000..ff3538ef --- /dev/null +++ b/src/main/java/translator/Methods.kt @@ -0,0 +1,103 @@ +package translator + +import arrow.core.None +import arrow.core.firstOrNone +import arrow.core.some +import eotree.* +import lexer.TokenCode +import tree.Declaration.Declaration +import tree.Declaration.MethodDeclaration +import tree.Declaration.ParameterDeclaration +import tree.Declaration.VariableDeclaration +import tree.Statement.BlockStatement +import tree.Statement.BlockStatements +import util.ListUtils +import java.util.* +import java.util.stream.Collectors +import kotlin.collections.ArrayList + +//fun MethodDeclaration.getLocalVariables(): List = +// // TODO: add support for nested block variables as well +// methodBody.block.blockStatements +// .filter { it.declaration != null } +// .map { } + + +fun mapMethodDeclaration(dec: MethodDeclaration): EOBndExpr { + val isStatic = dec.modifiers != null && + dec.modifiers.modifiers.modifiers.find { code: TokenCode -> code == TokenCode.Static } != null + val additionalParameters = if (!isStatic) listOf("this") else ArrayList() + + val obj = EOObject( + // Non-vararg parameters + if (dec.parameters != null) // Exclude 'String[] args' fon now + additionalParameters + + dec.parameters.parameters.stream() + .filter { param: ParameterDeclaration -> !param.signEllipsis } + .map { param: ParameterDeclaration -> param.name } + .collect(Collectors.toList()) + else + additionalParameters, + + // Optional vararg parameter + if (dec.parameters != null) + dec.parameters.parameters + .filter { param: ParameterDeclaration -> param.signEllipsis } + .map { param: ParameterDeclaration -> param.name } + .also { assert(it.size <= 1) } + .firstOrNone() + else + None, + + // Bound attributes + // TODO: implement + try { + dec.methodBody.block.findAllLocalVariables().map { mapVariableDeclaration(it) } + + listOf( + EOBndExpr( + EOCopy( + "seq", + dec.methodBody.block.blockStatements + .mapNotNull { + if (it.statement != null) + mapStatement(it.statement) + else if (it.expression != null) + mapExpression(it.expression) + else + null + } + ), + "@" + ) + ) + } catch (e: NullPointerException) { + listOf( + EOBndExpr( + EOCopy( + "0", + ArrayList() + ), + "@" + ) + ) + } + + ) + + // Contract to check parameter count + if (dec.parameters != null) + assert(dec.parameters.parameters.size + (if (isStatic) 0 else 1) == + obj.freeAttrs.size + if (obj.varargAttr.nonEmpty()) 1 else 0) { + "Parameters count of Java method and EO method do not match: ${dec.parameters.parameters.size} vs ${obj.freeAttrs.size + if (obj.varargAttr.nonEmpty()) 1 else 0}" + } + + return EOBndExpr( + obj, + dec.name + ) +} + +fun BlockStatements.findAllLocalVariables(): List = + blockStatements + .filter { it.declaration is VariableDeclaration } + .map { it.declaration as VariableDeclaration } \ No newline at end of file diff --git a/src/main/java/translator/Statements.java b/src/main/java/translator/Statements.java deleted file mode 100644 index 50c848bf..00000000 --- a/src/main/java/translator/Statements.java +++ /dev/null @@ -1,34 +0,0 @@ -package translator; - -import eotree.EOAnonExpr; -import tree.Statement.BlockStatement; -import tree.Statement.Statement; -import tree.Statement.StatementExpression; - -public class Statements { - public static EOAnonExpr mapBlockStatement(BlockStatement stmt) { - // Block statement is one of three variants - if (stmt.statement != null) { - return Statements.mapStatement(stmt.statement); - } else if (stmt.declaration != null) { - throw new UnsupportedOperationException("Not implemented"); - } else if (stmt.expression != null) { - throw new UnsupportedOperationException("Not implemented"); - } else - throw new IllegalArgumentException("BlockStatement does not have any known type"); - } - - public static EOAnonExpr mapStatement(Statement statement) { - if (statement instanceof StatementExpression) { - return mapStatementExpression((StatementExpression) statement); - } - return null; - } - - public static EOAnonExpr mapStatementExpression(StatementExpression stmtExpr) { - if (stmtExpr.expression != null) { - return Expressions.mapExpression(stmtExpr.expression); - } - return null; - } -} diff --git a/src/main/java/translator/Statements.kt b/src/main/java/translator/Statements.kt new file mode 100644 index 00000000..62234158 --- /dev/null +++ b/src/main/java/translator/Statements.kt @@ -0,0 +1,45 @@ +package translator + +import eotree.EOCopy +import eotree.EOExpr +import tree.Statement.BlockStatement +import tree.Statement.IfThenElse +import tree.Statement.Statement +import tree.Statement.StatementExpression + +fun mapBlockStatement(stmt: BlockStatement): EOExpr = + // Block statement is one of three variants + when { + stmt.statement != null -> + mapStatement(stmt.statement) + stmt.declaration != null -> + throw UnsupportedOperationException("Not implemented") + stmt.expression != null -> + mapExpression(stmt.expression) + else -> + throw IllegalArgumentException("BlockStatement does not have any known type") + } + +fun mapStatement(statement: Statement): EOExpr = + when (statement) { + is StatementExpression -> + mapStatementExpression(statement) + is IfThenElse -> + mapIfThenElse(statement) + else -> + throw IllegalArgumentException("Statement of type ${statement.javaClass.simpleName} is not supported") + } + +fun mapStatementExpression(stmtExpr: StatementExpression): EOExpr { + return mapExpression(stmtExpr.expression) +} + +fun mapIfThenElse(statement: IfThenElse): EOExpr = + EOCopy( + "if.", + listOfNotNull( + mapExpression(statement.condition), + mapStatement(statement.thenPart), + if (statement.elsePart != null) mapStatement(statement.elsePart) else null, + ) + ) \ No newline at end of file diff --git a/src/main/java/translator/Translator.java b/src/main/java/translator/Translator.java deleted file mode 100644 index 21077aef..00000000 --- a/src/main/java/translator/Translator.java +++ /dev/null @@ -1,165 +0,0 @@ -package translator; - -import eotree.*; -import tree.Compilation.CompilationUnit; -import tree.Compilation.Package; -import tree.Compilation.SimpleCompilationUnit; -import tree.Compilation.TopLevelComponent; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -import static util.ListUtils.listOf; - -public class Translator { - public static EOProgram translate(CompilationUnit unit) { - if (unit instanceof SimpleCompilationUnit) - return mapSimpleCompilationUnit((SimpleCompilationUnit) unit); - else - throw new IllegalArgumentException("CompilationUnit of type " + - unit.getClass().getSimpleName() + - " is not supported"); - } - - public static EOProgram mapPackage(Package pkg) { - return new EOProgram( - new EOLicense(), // TODO: add license? - new EOMetas( - Optional.of( - String.join(".", pkg.compoundName.names) - ), - new ArrayList<>() - ), - pkg.components.components - .stream() - .map(Translator::mapTopLevelComponent) - .collect(Collectors.toList()) - ); - } - - public static EOProgram mapSimpleCompilationUnit(SimpleCompilationUnit unit) { - ArrayList stdBnds = new ArrayList<>(); // Standard top-level bounds - stdBnds.add( - new EOBndExpr( - new EOObject( - new ArrayList<>(), - Optional.empty(), - Collections.emptyList() - ), - new EOBndName("class_Object") - ) - ); - EOObject printlnObj = new EOObject( - listOf( - new EOBndName("text") - ), - Optional.empty(), - listOf( - new EOBndExpr( - new EOCopy( - new EODot(Optional.empty(), "stdout"), - listOf( - new EOAnonExpr( - new EODot(Optional.empty(), "text") - ) - ) - ), - new EOBndName("@") - ) - ) - ); - EOObject outObj = - new EOObject( - listOf(), - Optional.empty(), - listOf( - new EOBndExpr( - printlnObj, - new EOBndName("println") - ) - ) - ); - stdBnds.add( - new EOBndExpr( - new EOObject( - listOf(), - Optional.empty(), - listOf( - new EOBndExpr( - outObj, - new EOBndName("out") - ) - ) - ), - new EOBndName("class_System") - ) - ); - List bndLst = unit.components.components - .stream() - .map(Translator::mapTopLevelComponent) - .map(bnd -> (EOBndExpr)bnd) - .collect(Collectors.toList()); - - // FIXME: assuming there is only one top-level component and it is a class - // Always calling the 'main' method - String mainClassName = bndLst.get(0).bndName.name; - bndLst.add(new EOBndExpr( - new EODot(Optional.empty(), mainClassName), - new EOBndName("mainObj") - )); - bndLst.add( - new EOBndExpr( - new EODot( - Optional.of(new EODot( - Optional.empty(), - "mainObj" - )), - "main" - ), - new EOBndName("@") - ) - ); - - List globalBnd = listOf( - new EOBndExpr( - new EOObject( - listOf(), - Optional.of(new EOBndName("args")), - bndLst - ), - new EOBndName("global") - ) - ); - - globalBnd.addAll(stdBnds); - - - return new EOProgram( - new EOLicense( - new EOComment(LocalDateTime.now().toString()), - new EOComment("j2eo team") - ), - new EOMetas( - Optional.empty(), - listOf( - new EOMeta("alias", "org.eolang.io.stdout") - ) - ), - globalBnd - ); - } - - public static EOBnd mapTopLevelComponent(TopLevelComponent component) { - if (component.classDecl != null) { - return Classes.mapClass(component.classDecl); - } else if (component.interfaceDecl != null) { - return Classes.mapInterface(component.interfaceDecl); - } else { - throw new IllegalArgumentException("Supplied TopLevelComponent does not have neither class nor interface"); - } - } -} diff --git a/src/main/java/translator/Translator.kt b/src/main/java/translator/Translator.kt new file mode 100644 index 00000000..1251e31b --- /dev/null +++ b/src/main/java/translator/Translator.kt @@ -0,0 +1,80 @@ +package translator + +import arrow.core.None +import arrow.core.Some +import eotree.* +import eotree.data.EOStringData +import tree.Compilation.CompilationUnit +import tree.Compilation.Package +import tree.Compilation.SimpleCompilationUnit +import tree.Compilation.TopLevelComponent +import util.* +import java.time.LocalDateTime + +fun translate(unit: CompilationUnit): EOProgram { + return if (unit is SimpleCompilationUnit) + mapSimpleCompilationUnit(unit) + else + throw IllegalArgumentException( + "CompilationUnit of type " + + unit.javaClass.simpleName + + " is not supported") +} + +fun mapPackage(pkg: Package): EOProgram { + return EOProgram( + EOLicense(), // TODO: add license? + EOMetas( + Some(pkg.compoundName.names.joinToString(".")), + ArrayList() + ), + pkg.components.components + .map { obj -> mapTopLevelComponent(obj) } + ) +} + +fun mapSimpleCompilationUnit(unit: SimpleCompilationUnit): EOProgram { + preprocessUnit(unit) + + val bnds = unit.components.components + .map { obj: TopLevelComponent? -> mapTopLevelComponent(obj!!) } + .map { bnd: EOBnd -> bnd as EOBndExpr } + + // FIXME: assuming there is only one top-level component and it is a class + var entrypointBnds = listOf() + try { + val mainClassName = findMainClass(unit) + entrypointBnds = generateEntryPoint(mainClassName) + } catch (e:NullPointerException){ + logger.info { "No entry point here!" } + } + + // FIXME: assuming there is only one top-level component and it is a class + // Always calling the 'main' method + + return EOProgram( + EOLicense( + EOComment(LocalDateTime.now().toString()), + EOComment("j2eo team") + ), + EOMetas( + None, + ListUtils.listOf( + //EOMeta("alias", "org.eolang.gray.cage"), + EOMeta("alias", "stdlib.class__Object"), + EOMeta("alias", "stdlib.class__System"), + ) + ), + bnds + entrypointBnds + ) +} + +fun mapTopLevelComponent(component: TopLevelComponent): EOBnd { + return if (component.classDecl != null) { + mapClass(component.classDecl) + } else if (component.interfaceDecl != null) { + mapInterface(component.interfaceDecl) + } else { + throw IllegalArgumentException("Supplied TopLevelComponent does not have neither class nor interface") + } +} diff --git a/src/main/java/translator/Types.kt b/src/main/java/translator/Types.kt new file mode 100644 index 00000000..baf95ed7 --- /dev/null +++ b/src/main/java/translator/Types.kt @@ -0,0 +1,9 @@ +package translator + +import lexer.TokenCode + + +fun TokenCode.mapPrimitiveType(): String = + when (this) { + else -> throw IllegalArgumentException("Primitive type \"$this\" is not supported") + } \ No newline at end of file diff --git a/src/main/java/tree/CompoundName.java b/src/main/java/tree/CompoundName.java index 6c4fa8da..0cd9e60e 100644 --- a/src/main/java/tree/CompoundName.java +++ b/src/main/java/tree/CompoundName.java @@ -1,6 +1,7 @@ package tree; import java.util.ArrayList; +import java.util.List; // %nterm CompoundName // @@ -20,6 +21,10 @@ public CompoundName(String first) names.add(first); } + public CompoundName(List name) { + names = new ArrayList<>(name); + } + // Adding public CompoundName add(String next) { @@ -27,14 +32,22 @@ public CompoundName add(String next) return this; } + public String concatenatedJava() { + return String.join(".", names); + } + + public String concatenatedEO() { + return String.join("__", names); + } + // Reporting public void report(int sh) { - Entity.doShift(sh); - for (int i=1; i<=names.size(); i++) + // Entity.doShift(sh); + for (int i=0; i enumerators; - public ArrayList initializers; - public ArrayList body; +// public Modifiers modifiers; -- in the base class +// public String name; -- in the base class + public TypeList implemented; + public Enumerators enumerators; + public Declarations body; // Creation - public EnumDeclaration(String n, - Modifiers mods, - ArrayList enums, - ArrayList inits, - ArrayList body) + public EnumDeclaration(Token n, TypeList impls, EnumBody body) { - super(mods,n); - this.modifiers = mods; - this.enumerators = enums; - this.initializers = inits; - this.body = body; + super(null,n.image); + this.implemented = impls; + this.enumerators = body.enumerators; + this.body = body.declarations; } // Reporting public void report(int sh) { - + title("ENUM DECLARATION "+name,sh); + if ( implemented != null ) + { + Entity.doShift(sh+Entity.shift); + System.out.println("BASES:"); + implemented.report(sh+2*Entity.shift); + } + if ( enumerators != null ) + { + Entity.doShift(sh+Entity.shift); + System.out.println("ENUMERATORS:"); + enumerators.report(sh+2*Entity.shift); + } + if ( body != null ) + { + Entity.doShift(sh+Entity.shift); + System.out.println("ENUM BODY:"); + body.report(sh+2*Entity.shift); + } } } diff --git a/src/main/java/tree/Declaration/Enumerator.java b/src/main/java/tree/Declaration/Enumerator.java new file mode 100644 index 00000000..e07dbbbf --- /dev/null +++ b/src/main/java/tree/Declaration/Enumerator.java @@ -0,0 +1,42 @@ +package tree.Declaration; + +import lexer.Token; +import tree.Annotations; +import tree.Entity; +import tree.Expression.ArgumentList; + +// EnumConstant +// : AnnotationSeqOpt IDENTIFIER Arguments +// | AnnotationSeqOpt IDENTIFIER Arguments ClassBody +// ; +public class Enumerator extends Entity +{ + // Structure + public Annotations annotations; + public String name; + public ArgumentList arguments; + public Declarations enumBody; + + // Creation + public Enumerator(Annotations anns, Token name, ArgumentList args, Declarations body) + { + this.annotations = anns; + this.name = name.image; + this.arguments = args; + this.enumBody = body; + } + + // Reporting + public void report(int sh) + { + title("ENUM CONSTANT "+name,sh); + if ( arguments != null ) + { + Entity.doShift(sh+Entity.shift); + System.out.println("ARGUMENTS:"); + arguments.report(sh+2*Entity.shift); + } + if ( enumBody != null ) + enumBody.report(sh+Entity.shift); + } +} diff --git a/src/main/java/tree/Declaration/Enumerators.java b/src/main/java/tree/Declaration/Enumerators.java new file mode 100644 index 00000000..14e00ea1 --- /dev/null +++ b/src/main/java/tree/Declaration/Enumerators.java @@ -0,0 +1,40 @@ +package tree.Declaration; + +import tree.Entity; +import java.util.ArrayList; + +// EnumConstantListOpt +// : %empty +// : EnumConstantList +// ; +// +// EnumConstantList +// : EnumConstant +// | EnumConstantListOpt COMMA EnumConstant +// ; +public class Enumerators extends Entity +{ + // Structure + public ArrayList enumerators; + + // Creation + public Enumerators(Enumerator en) + { + this.enumerators = new ArrayList<>(); + this.enumerators.add(en); + } + public Enumerators add(Enumerator en) + { + this.enumerators.add(en); + return this; + } + + // Reporting + public void report(int sh) + { + for (Enumerator e: enumerators) + { + e.report(sh); + } + } +} diff --git a/src/main/java/tree/Declaration/MethodDeclaration.java b/src/main/java/tree/Declaration/MethodDeclaration.java index 7fe0c693..ec2478c5 100644 --- a/src/main/java/tree/Declaration/MethodDeclaration.java +++ b/src/main/java/tree/Declaration/MethodDeclaration.java @@ -70,11 +70,6 @@ public MethodDeclaration(Modifiers mods, // Reporting public void report(int sh) { - // public ParameterDeclarations parameters; - // public Dims dims; - // public TypeList exceptions; - // public Block methodBody; - this.title("METHOD "+name,sh); if ( modifiers != null ) modifiers.report(sh+Entity.shift); if ( typeParameters != null ) typeParameters.report(sh+Entity.shift); @@ -86,7 +81,7 @@ public void report(int sh) if ( methodBody != null ) { title("METHOD BODY",sh+Entity.shift); - methodBody.report(sh+Entity.shift); + methodBody.report(sh+2*Entity.shift); } } diff --git a/src/main/java/tree/Declaration/NormalClassDeclaration.java b/src/main/java/tree/Declaration/NormalClassDeclaration.java index 0543b2b0..0891bfa4 100644 --- a/src/main/java/tree/Declaration/NormalClassDeclaration.java +++ b/src/main/java/tree/Declaration/NormalClassDeclaration.java @@ -4,6 +4,9 @@ import tree.Entity; import tree.Type.*; +import java.util.List; +import java.util.stream.Collectors; + // NormalClassDeclaration // : /*ModifierSeqOpt*/ CLASS IDENTIFIER TypeParametersOpt ClassExtendsOpt ClassImplementsOpt ClassBody // ; @@ -34,43 +37,71 @@ // | STATIC Block // StaticInitializer // | SEMICOLON // ; -public class NormalClassDeclaration extends ClassDeclaration -{ +public class NormalClassDeclaration extends ClassDeclaration { // Structure public TypeParameters typeParameters; - public Type extendedType; - public TypeList interfaces; - public Declarations body; + public Type extendedType; + public TypeList interfaces; + public Declarations body; // Creation public NormalClassDeclaration(Token n, TypeParameters typePars, Type extType, TypeList ints, - Declarations body) - { - super(null,n.image); + Declarations body) { + super(null, n.image); this.typeParameters = typePars; this.extendedType = extType; this.interfaces = ints; this.body = body; } + public List getStaticVariables() { + return body.declarations.stream() + .filter(dec -> dec instanceof VariableDeclaration) + .filter(dec -> dec.modifiers.modifiers.modifiers.contains(TokenCode.Static)) + .map(dec -> (VariableDeclaration) dec) + .collect(Collectors.toList()); + } + + public List getNonStaticVariables() { + return body.declarations.stream() + .filter(dec -> dec instanceof VariableDeclaration) + .filter(dec -> !dec.modifiers.modifiers.modifiers.contains(TokenCode.Static)) + .map(dec -> (VariableDeclaration) dec) + .collect(Collectors.toList()); + } + + public List getStaticMethods() { + return body.declarations.stream() + .filter(dec -> dec instanceof MethodDeclaration) + .filter(dec -> dec.modifiers.modifiers.modifiers.contains(TokenCode.Static)) + .map(dec -> (MethodDeclaration) dec) + .collect(Collectors.toList()); + } + + public List getNonStaticMethods() { + return body.declarations.stream() + .filter(dec -> dec instanceof MethodDeclaration) + .filter(dec -> !dec.modifiers.modifiers.modifiers.contains(TokenCode.Static)) + .map(dec -> (MethodDeclaration) dec) + .collect(Collectors.toList()); + } + // Reporting - public void report(int sh) - { - this.title("CLASS DECLARATION "+this.name,sh); - if ( this.typeParameters != null ) - this.typeParameters.report(sh+Entity.shift); - if ( this.extendedType != null ) - { - this.title("SUPER",sh+Entity.shift); - this.extendedType.report(sh+Entity.shift); + public void report(int sh) { + this.title("CLASS DECLARATION " + this.name, sh); + if (this.typeParameters != null) + this.typeParameters.report(sh + Entity.shift); + if (this.extendedType != null) { + this.title("SUPER", sh + Entity.shift); + this.extendedType.report(sh + Entity.shift); } - if ( this.interfaces != null ) - this.interfaces.report(sh+Entity.shift); - if ( body != null ) - body.report(sh+Entity.shift); + if (this.interfaces != null) + this.interfaces.report(sh + Entity.shift); + if (body != null) + body.report(sh + Entity.shift); } } diff --git a/src/main/java/tree/Declaration/ParameterDeclaration.java b/src/main/java/tree/Declaration/ParameterDeclaration.java index d91beaf5..87d025b7 100644 --- a/src/main/java/tree/Declaration/ParameterDeclaration.java +++ b/src/main/java/tree/Declaration/ParameterDeclaration.java @@ -1,5 +1,6 @@ package tree.Declaration; +import com.sun.source.tree.EmptyStatementTree; import lexer.Token; import tree.*; import tree.Modifiers; @@ -72,6 +73,9 @@ private static ReceiverDeclaration createReceiver(Modifiers mods,Type t,String n // Reporting public void report(int sh) { + title("PARAMETER "+name,sh); + if ( super.modifiers != null ) super.modifiers.report(sh+Entity.shift); + if ( super.type != null ) super.type.report(sh+ Entity.shift); } diff --git a/src/main/java/tree/Declaration/ParameterDeclarations.java b/src/main/java/tree/Declaration/ParameterDeclarations.java index 3c71d4b5..81a668d8 100644 --- a/src/main/java/tree/Declaration/ParameterDeclarations.java +++ b/src/main/java/tree/Declaration/ParameterDeclarations.java @@ -23,6 +23,10 @@ public ParameterDeclarations add(ParameterDeclaration par) // Reporting public void report(int sh) { + for (ParameterDeclaration p: parameters) + { + p.report(sh); + } } } diff --git a/src/main/java/tree/Declaration/TypeAndDeclarators.java b/src/main/java/tree/Declaration/TypeAndDeclarators.java index ef9936e8..f2bbc8c7 100644 --- a/src/main/java/tree/Declaration/TypeAndDeclarators.java +++ b/src/main/java/tree/Declaration/TypeAndDeclarators.java @@ -1,8 +1,9 @@ package tree.Declaration; +import tree.Entity; import tree.Type.*; -// Intermediate class - wont't appear in the AST +// Intermediate class - won't appear in the AST public class TypeAndDeclarators extends Declaration { @@ -15,6 +16,7 @@ public TypeAndDeclarators(Type t, VariableDeclarators vds) { super(null,null,t); this.declarators = vds; + if ( Entity.debug ) System.out.println("Type with declarator(s) taken"); } // Reporting diff --git a/src/main/java/tree/Declaration/VariableDeclaration.java b/src/main/java/tree/Declaration/VariableDeclaration.java index b0655600..b4121612 100644 --- a/src/main/java/tree/Declaration/VariableDeclaration.java +++ b/src/main/java/tree/Declaration/VariableDeclaration.java @@ -1,6 +1,7 @@ package tree.Declaration; import tree.Dims; +import tree.Entity; import tree.Initializer; import tree.Modifiers; import tree.Type.Type; @@ -32,7 +33,8 @@ public class VariableDeclaration extends Declaration { // Structure - public Modifiers modifiers; +// public Modifiers modifiers; -- from the base class +// public String name; -- from the base class public Dims dims; // Either a single expression, or a list of initializers @@ -53,7 +55,12 @@ public VariableDeclaration(String n, // Reporting public void report(int sh) { - + title("VARIABLE DECLARATION "+name,sh); + if ( modifiers != null ) modifiers.report(sh+ Entity.shift); + if ( type != null ) type.report(sh+ Entity.shift); + else { Entity.doShift(sh+Entity.shift); System.out.println("VAR"); } + if ( dims != null ) dims.report(sh+Entity.shift); + if ( initializer != null ) initializer.report(sh+Entity.shift); } } diff --git a/src/main/java/tree/Declaration/VariableDeclarator.java b/src/main/java/tree/Declaration/VariableDeclarator.java index ae209d04..d50768f3 100644 --- a/src/main/java/tree/Declaration/VariableDeclarator.java +++ b/src/main/java/tree/Declaration/VariableDeclarator.java @@ -24,6 +24,8 @@ public VariableDeclarator(Token id, Dims dims, Initializer init) this.name = id.image; this.dims = dims; this.initializer = init; + + System.out.println("Variable declarator with "+id.image+" accepted"); } // Reporting diff --git a/src/main/java/tree/Dims.java b/src/main/java/tree/Dims.java index da00aff2..4f6dd801 100644 --- a/src/main/java/tree/Dims.java +++ b/src/main/java/tree/Dims.java @@ -8,6 +8,10 @@ public class Dims extends Entity public ArrayList dimensions; // Creation + public Dims() + { + dimensions = new ArrayList<>(); + } public Dims(Dim dim) { this.dimensions = new ArrayList<>(); @@ -22,8 +26,11 @@ public Dims add(Dim dim) // Reporting public void report(int sh) { + title("Dimensions: ",sh); + Entity.doShift(sh+Entity.shift); for (int i=1; i<=dimensions.size(); i++) System.out.print("[]"); + System.out.println(); } } diff --git a/src/main/java/tree/Entity.java b/src/main/java/tree/Entity.java index 52f5d343..4a9b08be 100644 --- a/src/main/java/tree/Entity.java +++ b/src/main/java/tree/Entity.java @@ -32,8 +32,16 @@ public Entity(Token token) this.span = token.span; } +// // Tricks for resolving conflicts +// +// public static boolean inBlock = false; +// public static boolean unAnnotatedTypeTaken = false; + // Machinery for reporting + public static boolean debug = false; + public static boolean syntaxOnly = false; + public static final int shift = 4; public void outUnique() diff --git a/src/main/java/tree/Expression/Binary.java b/src/main/java/tree/Expression/Binary.java index f68ee7a1..2862e2dc 100644 --- a/src/main/java/tree/Expression/Binary.java +++ b/src/main/java/tree/Expression/Binary.java @@ -22,8 +22,7 @@ public Binary(Expression l, Expression r, Token token) // Reporting public void report(int sh) { - Entity.doShift(sh); - System.out.println("BINARY "+operator.toString()); + title("BINARY "+operator.toString(),sh); left.report(sh+Entity.shift); right.report(sh+Entity.shift); } diff --git a/src/main/java/tree/Expression/Cast.java b/src/main/java/tree/Expression/Cast.java index 70ebf9e3..cf3d8454 100644 --- a/src/main/java/tree/Expression/Cast.java +++ b/src/main/java/tree/Expression/Cast.java @@ -4,8 +4,8 @@ import tree.Type.TypeList; // CastExpression -// : TargetType UnaryExpression { $$ = new Cast($1,$2); } -// | TargetType LambdaExpression { $$ = new Cast($1,$2); } +// : TargetType UnaryExpression +// | TargetType LambdaExpression // ; public class Cast extends Expression { @@ -25,7 +25,8 @@ public void report(int sh) { Entity.doShift(sh); System.out.println("CAST"); - types.report(sh+Entity.shift); + types.title("Target types:",sh+Entity.shift); + types.report(sh+2*Entity.shift); expression.report(sh+Entity.shift); } diff --git a/src/main/java/tree/Expression/Primary/Literal.java b/src/main/java/tree/Expression/Primary/Literal.java index f1897558..e3458603 100644 --- a/src/main/java/tree/Expression/Primary/Literal.java +++ b/src/main/java/tree/Expression/Primary/Literal.java @@ -35,8 +35,7 @@ public Literal(Token token) // Reporting public void report(int sh) { - Entity.doShift(sh); - System.out.println(value); + title("LITERAL "+value,sh); } } diff --git a/src/main/java/tree/Expression/Primary/MethodInvocation.java b/src/main/java/tree/Expression/Primary/MethodInvocation.java index cb14def8..9b936a7e 100644 --- a/src/main/java/tree/Expression/Primary/MethodInvocation.java +++ b/src/main/java/tree/Expression/Primary/MethodInvocation.java @@ -1,14 +1,16 @@ package tree.Expression.Primary; import lexer.Token; +import tree.CompoundName; import tree.Entity; import tree.Expression.ArgumentList; import tree.Expression.Expression; +import tree.Expression.SimpleReference; import tree.Type.*; // MethodInvocation -// : IDENTIFIER Arguments -// | CompoundName DOT TypeArgumentsOpt IDENTIFIER Arguments +// : CompoundName Arguments +// | CompoundName DOT TypeArguments IDENTIFIER Arguments // | Primary DOT TypeArgumentsOpt IDENTIFIER Arguments // | SUPER DOT TypeArgumentsOpt IDENTIFIER Arguments // | CompoundName DOT SUPER DOT TypeArgumentsOpt IDENTIFIER Arguments @@ -19,16 +21,22 @@ public class MethodInvocation extends Primary public Expression qualifier; // SimpleReference or Primary public boolean superSign; public TypeArguments typeArguments; - public String name; // callee + public String name; // callee; can be null public ArgumentList arguments; + // ================================= + // NOTE! + // If qualifier != null, and name == null, then 'qualifier' actually + // contains the method name -- perhaps, the compound name. + // ================================== + // Creation public MethodInvocation(Expression q, boolean ss, TypeArguments targs, Token name, ArgumentList args) { this.qualifier = q; this.superSign = ss; this.typeArguments = targs; - this.name = name.image; + if ( name != null ) this.name = name.image; this.arguments = args; } @@ -37,8 +45,20 @@ public void report(int sh) { String t = "METHOD INVOCATION: "; if ( superSign ) t += "SUPER "; - title(t+name,sh); - if ( qualifier != null ) + if ( name != null ) + { + t += name; + title(t,sh); + } + else if ( qualifier != null && qualifier instanceof SimpleReference ) + { + CompoundName cn = ((SimpleReference)qualifier).compoundName; + Entity.doShift(sh); + System.out.print(t); + cn.report(0); + System.out.println(); + } + if ( name != null && qualifier != null ) { Entity.doShift(sh); System.out.println("Qualifier:"); @@ -48,13 +68,12 @@ public void report(int sh) { Entity.doShift(sh+Entity.shift); System.out.println("Type arguments:"); - typeArguments.report(sh+Entity.shift); + typeArguments.report(sh+2*Entity.shift); } if ( arguments != null ) { - Entity.doShift(sh+Entity.shift); - System.out.println("Arguments:"); - arguments.report(sh+Entity.shift); + arguments.title("Arguments:",sh+Entity.shift); + arguments.report(sh+2*Entity.shift); } } diff --git a/src/main/java/tree/Expression/SimpleReference.java b/src/main/java/tree/Expression/SimpleReference.java index 32ee2c85..4bf0b573 100644 --- a/src/main/java/tree/Expression/SimpleReference.java +++ b/src/main/java/tree/Expression/SimpleReference.java @@ -16,7 +16,10 @@ public SimpleReference(CompoundName cn) // Reporting public void report(int sh) { + Entity.doShift(sh); + System.out.print(this.unique+":REFERENCE TO "); compoundName.report(sh); + System.out.println(); } } diff --git a/src/main/java/tree/Expression/UnaryPostfix.java b/src/main/java/tree/Expression/UnaryPostfix.java index 01508b2a..b89f3f63 100644 --- a/src/main/java/tree/Expression/UnaryPostfix.java +++ b/src/main/java/tree/Expression/UnaryPostfix.java @@ -19,8 +19,7 @@ public UnaryPostfix(Token token, Expression op) // Reporting public void report(int sh) { - Entity.doShift(sh); - System.out.println("UNARY POSTFIX "+operator.toString()); + title("UNARY POSTFIX "+operator.toString(),sh); operand.report(sh+Entity.shift); } diff --git a/src/main/java/tree/Expression/UnaryPrefix.java b/src/main/java/tree/Expression/UnaryPrefix.java index a73e1ba7..e8d96d14 100644 --- a/src/main/java/tree/Expression/UnaryPrefix.java +++ b/src/main/java/tree/Expression/UnaryPrefix.java @@ -19,8 +19,7 @@ public UnaryPrefix(Token token, Expression op) // Reporting public void report(int sh) { - Entity.doShift(sh); - System.out.println("UNARY PREFIX "+operator.toString()); + title("UNARY PREFIX "+operator.toString(),sh); operand.report(sh+Entity.shift); } diff --git a/src/main/java/tree/InitializerSimple.java b/src/main/java/tree/InitializerSimple.java index f6fc62c7..38f2b4a3 100644 --- a/src/main/java/tree/InitializerSimple.java +++ b/src/main/java/tree/InitializerSimple.java @@ -16,7 +16,7 @@ public InitializerSimple(Expression expr) // Reporting public void report(int sh) { - + expression.report(sh); } } diff --git a/src/main/java/tree/Modifiers.java b/src/main/java/tree/Modifiers.java index 731a1041..68d31ec9 100644 --- a/src/main/java/tree/Modifiers.java +++ b/src/main/java/tree/Modifiers.java @@ -26,7 +26,7 @@ public void report(int sh) System.out.println(); } modifiers.report(sh); - System.out.println(); +// System.out.println(); } } diff --git a/src/main/java/tree/Statement/Assert.java b/src/main/java/tree/Statement/Assert.java index ca2d4db4..6f5e7c01 100644 --- a/src/main/java/tree/Statement/Assert.java +++ b/src/main/java/tree/Statement/Assert.java @@ -28,6 +28,7 @@ public Assert(ArrayList ls, Expression expr, Expression expr2) // Reporting public void report(int sh) { + super.report(sh); title("ASSERT",sh); expression.report(sh+Entity.shift); if ( expression2 != null ) diff --git a/src/main/java/tree/Statement/Block.java b/src/main/java/tree/Statement/Block.java index 4983529e..9e0239c9 100644 --- a/src/main/java/tree/Statement/Block.java +++ b/src/main/java/tree/Statement/Block.java @@ -21,7 +21,7 @@ public class Block extends Statement { // Structure -// public ArrayList labels; +// public ArrayList labels; -- from the base class public BlockStatements block; // Creation @@ -34,14 +34,7 @@ public Block(ArrayList ls, BlockStatements block) // Reporting public void report(int sh) { - if ( labels != null && labels.size() > 0 ) - { - String labs = "LABELS: "; - for (int i=0; i ls, Token label) // Reporting public void report(int sh) { + super.report(sh); Entity.doShift(sh); System.out.print("BREAK "); if ( label != null ) System.out.print(label); diff --git a/src/main/java/tree/Statement/Continue.java b/src/main/java/tree/Statement/Continue.java index 7d5c5eb0..d942956e 100644 --- a/src/main/java/tree/Statement/Continue.java +++ b/src/main/java/tree/Statement/Continue.java @@ -27,6 +27,7 @@ public Continue(ArrayList ls, Token label) // Reporting public void report(int sh) { + super.report(sh); Entity.doShift(sh); System.out.print("CONTINUE "); if ( label != null ) System.out.print(label); diff --git a/src/main/java/tree/Statement/Do.java b/src/main/java/tree/Statement/Do.java index 07cb3a92..314afbcb 100644 --- a/src/main/java/tree/Statement/Do.java +++ b/src/main/java/tree/Statement/Do.java @@ -26,6 +26,7 @@ public Do(ArrayList ls, Statement stmt, Expression cond) // Reporting public void report(int sh) { + super.report(sh); } diff --git a/src/main/java/tree/Statement/IfThenElse.java b/src/main/java/tree/Statement/IfThenElse.java index cc9e7736..3e0e6911 100644 --- a/src/main/java/tree/Statement/IfThenElse.java +++ b/src/main/java/tree/Statement/IfThenElse.java @@ -38,10 +38,11 @@ public IfThenElse(ArrayList ls, Expression c, Statement t, Statement e) // Reporting public void report(int sh) { + super.report(sh); Entity.doShift(sh); System.out.println("IF"); condition.report(sh+Entity.shift); - System.out.println(); + // System.out.println(); Entity.doShift(sh); System.out.println("THEN"); thenPart.report(sh+Entity.shift); diff --git a/src/main/java/tree/Statement/Return.java b/src/main/java/tree/Statement/Return.java index 451e08c3..4b466f03 100644 --- a/src/main/java/tree/Statement/Return.java +++ b/src/main/java/tree/Statement/Return.java @@ -26,6 +26,7 @@ public Return(ArrayList ls, Expression expr) // Reporting public void report(int sh) { + super.report(sh); Entity.doShift(sh); System.out.print("RETURN"); if ( expression != null ) diff --git a/src/main/java/tree/Statement/Statement.java b/src/main/java/tree/Statement/Statement.java index 9205b90f..4170ff9f 100644 --- a/src/main/java/tree/Statement/Statement.java +++ b/src/main/java/tree/Statement/Statement.java @@ -71,4 +71,16 @@ public Statement addLabel(Token label) labels.add(label.image); return this; } + + // Reporting + public void report(int sh) + { + if ( labels == null || labels.size() == 0 ) return; + + String labs = "LABELS: "; + for (String lab: labels) + labs += lab + " "; + Entity.doShift(sh); + System.out.println(labs); + } } diff --git a/src/main/java/tree/Statement/StatementExpression.java b/src/main/java/tree/Statement/StatementExpression.java index b569c307..438b136a 100644 --- a/src/main/java/tree/Statement/StatementExpression.java +++ b/src/main/java/tree/Statement/StatementExpression.java @@ -28,13 +28,8 @@ public StatementExpression(ArrayList ls, Expression expr) // Reporting public void report(int sh) { - int shift = sh; - if ( super.labels != null && super.labels.size() != 0 ) - { - super.report(sh); - shift += Entity.shift; - } - expression.report(shift); + super.report(sh); // printing labels, if any + expression.report(sh); } } diff --git a/src/main/java/tree/Statement/Switch.java b/src/main/java/tree/Statement/Switch.java index fb5e0b05..694775ca 100644 --- a/src/main/java/tree/Statement/Switch.java +++ b/src/main/java/tree/Statement/Switch.java @@ -81,6 +81,7 @@ public Switch(ArrayList ls,Expression expr,ArrayList bs,int // Reporting public void report(int sh) { + super.report(sh); } diff --git a/src/main/java/tree/Statement/Synchronized.java b/src/main/java/tree/Statement/Synchronized.java index 44ccd332..71057aee 100644 --- a/src/main/java/tree/Statement/Synchronized.java +++ b/src/main/java/tree/Statement/Synchronized.java @@ -26,6 +26,7 @@ public Synchronized(ArrayList ls, Expression expr, Block block) // Reporting public void report(int sh) { + super.report(sh); } } diff --git a/src/main/java/tree/Statement/Throw.java b/src/main/java/tree/Statement/Throw.java index 95a10916..ca5b52cc 100644 --- a/src/main/java/tree/Statement/Throw.java +++ b/src/main/java/tree/Statement/Throw.java @@ -25,6 +25,7 @@ public Throw(ArrayList ls, Expression expr) // Reporting public void report(int sh) { + super.report(sh); Entity.doShift(sh); System.out.println("THROW"); if ( expression != null ) diff --git a/src/main/java/tree/Statement/Try.java b/src/main/java/tree/Statement/Try.java index 796a2e10..c6c27ebe 100644 --- a/src/main/java/tree/Statement/Try.java +++ b/src/main/java/tree/Statement/Try.java @@ -40,6 +40,7 @@ public Try(ArrayList ls, // Reporting public void report(int sh) { + super.report(sh); } diff --git a/src/main/java/tree/Statement/While.java b/src/main/java/tree/Statement/While.java index 390fbb51..566b652f 100644 --- a/src/main/java/tree/Statement/While.java +++ b/src/main/java/tree/Statement/While.java @@ -25,6 +25,7 @@ public While(ArrayList ls, Expression c, Statement s) // Reporting public void report(int sh) { + super.report(sh); Entity.doShift(sh); System.out.println("WHILE"); condition.report(sh+Entity.shift); diff --git a/src/main/java/tree/Statement/Yield.java b/src/main/java/tree/Statement/Yield.java index ef3d1265..3b08e957 100644 --- a/src/main/java/tree/Statement/Yield.java +++ b/src/main/java/tree/Statement/Yield.java @@ -25,6 +25,7 @@ public Yield(ArrayList ls, Expression expr) // Reporting public void report(int sh) { + super.report(sh); Entity.doShift(sh); System.out.println("YIELD"); expression.report(sh+Entity.shift); diff --git a/src/main/java/tree/Type/PrimitiveType.java b/src/main/java/tree/Type/PrimitiveType.java index 62453856..e1745cc7 100644 --- a/src/main/java/tree/Type/PrimitiveType.java +++ b/src/main/java/tree/Type/PrimitiveType.java @@ -1,7 +1,9 @@ package tree.Type; +import lexer.Scanner; import lexer.Token; import lexer.TokenCode; +import tree.Entity; // PrimitiveType // // NumericType -- IntegralType @@ -25,12 +27,18 @@ public PrimitiveType(Token token) { super(null); this.typeCode = token.code; + +// Entity.unAnnotatedTypeTaken = true; + if ( Entity.debug ) System.out.println("Primitive type accepted"); } // Reporting public void report(int sh) { - System.out.print(typeCode.toString()); + title("TYPE "+typeCode.toString(),sh); + if ( super.annotations != null ) + super.annotations.report(sh+ Entity.shift); + if ( super.dimensions != null && super.dimensions.dimensions.size() > 0 ) + super.dimensions.report(sh+ Entity.shift); } - } \ No newline at end of file diff --git a/src/main/java/tree/Type/TypeArgument.java b/src/main/java/tree/Type/TypeArgument.java index f869978c..46c0af0b 100644 --- a/src/main/java/tree/Type/TypeArgument.java +++ b/src/main/java/tree/Type/TypeArgument.java @@ -36,7 +36,8 @@ public TypeArgument(Type t, int sign, Annotations anns) // Reporting public void report(int sh) { - + if ( type != null ) type.report(sh); + // TODO: the rest } } diff --git a/src/main/java/tree/Type/TypeArguments.java b/src/main/java/tree/Type/TypeArguments.java index b959fb14..4f5464c5 100644 --- a/src/main/java/tree/Type/TypeArguments.java +++ b/src/main/java/tree/Type/TypeArguments.java @@ -36,12 +36,10 @@ public TypeArguments add(TypeArgument arg) // Reporting public void report(int sh) { - Entity.doShift(sh); - System.out.println("TYPE ARGUMENTS"); + title("TYPE ARGUMENTS",sh); for ( TypeArgument arg: arguments) { arg.report(sh+Entity.shift); - System.out.println(); } } diff --git a/src/main/java/tree/Type/TypeList.java b/src/main/java/tree/Type/TypeList.java index 24a226ac..ade03daa 100644 --- a/src/main/java/tree/Type/TypeList.java +++ b/src/main/java/tree/Type/TypeList.java @@ -33,6 +33,10 @@ public TypeList add(Type t) // Reporting public void report(int sh) { + for (Type t: types) + { + t.report(sh); + } } diff --git a/src/main/java/tree/Type/TypeName.java b/src/main/java/tree/Type/TypeName.java index a7faa78b..56d66263 100644 --- a/src/main/java/tree/Type/TypeName.java +++ b/src/main/java/tree/Type/TypeName.java @@ -1,6 +1,8 @@ package tree.Type; +import lexer.Scanner; import tree.CompoundName; +import tree.Entity; // UnannotatedType // : ... @@ -23,14 +25,26 @@ public TypeName(CompoundName cn, TypeArguments targs) super(null); this.compoundName = cn; this.typeArguments = targs; + +// Entity.unAnnotatedTypeTaken = true; + if ( Entity.debug ) System.out.println("Type name accepted"); } // Reporting public void report(int sh) { + Entity.doShift(sh); + System.out.print("TYPE "); compoundName.report(0); - if ( typeArguments == null ) return; - typeArguments.report(0); + System.out.println(); + if ( super.annotations != null ) + super.annotations.report(sh+Entity.shift); + + if ( typeArguments != null ) + typeArguments.report(sh+ Entity.shift); + + if ( super.dimensions != null && super.dimensions.dimensions.size() > 0 ) + super.dimensions.report(sh+ Entity.shift); } } \ No newline at end of file diff --git a/src/main/java/tree/Type/UnannotatedType.java b/src/main/java/tree/Type/UnannotatedType.java index 2131ed78..4d180b81 100644 --- a/src/main/java/tree/Type/UnannotatedType.java +++ b/src/main/java/tree/Type/UnannotatedType.java @@ -2,6 +2,7 @@ import tree.Annotations; import tree.Dim; +import tree.Dims; // UnannotatedType // : PrimitiveType @@ -12,25 +13,25 @@ public class UnannotatedType extends Type { // Structure - public Dim dimension; + public Dims dimensions; // Creation public UnannotatedType(Annotations anns) { super(anns); + dimensions = new Dims(); // Empty } public UnannotatedType addDimension(Dim dim) { - this.dimension = dim; + this.dimensions.add(dim); return this; } // Reporting public void report(int sh) { - super.report(sh); - dimension.report(0); + // empty } } \ No newline at end of file diff --git a/src/main/java/util/AST.kt b/src/main/java/util/AST.kt new file mode 100644 index 00000000..2da311c4 --- /dev/null +++ b/src/main/java/util/AST.kt @@ -0,0 +1,32 @@ +package util + +import tree.Compilation.SimpleCompilationUnit +import tree.Compilation.TopLevelComponent +import tree.Declaration.ClassDeclaration +import tree.Declaration.MethodDeclaration +import tree.Declaration.NormalClassDeclaration + +fun findNameAsClass(objName: String, clsDec: NormalClassDeclaration): Boolean { + return if (objName != clsDec.name) { + try { + clsDec.body.declarations + .filterIsInstance() + .find { dec: NormalClassDeclaration -> findNameAsClass(objName, dec) } != null + } catch (e:NullPointerException) { + false; + } + } else { + true; + } +} + +fun isItClass(objName: String, components: ArrayList): Boolean{ + return if (objName != "System") { + components + .mapNotNull { component: TopLevelComponent -> component.classDecl } + .filterIsInstance() + .find { clsDec: ClassDeclaration -> findNameAsClass(objName, clsDec as NormalClassDeclaration) } != null + } else { + true; + } +} diff --git a/src/main/java/util/Comments.kt b/src/main/java/util/Comments.kt new file mode 100644 index 00000000..a2b69a68 --- /dev/null +++ b/src/main/java/util/Comments.kt @@ -0,0 +1,10 @@ +package util + +import arrow.core.prependTo +import eotree.EOBndExpr +import eotree.EOObject + +fun List.comment(comment: String): List = + first() + .apply { (expr as EOObject).comment = comment } + .prependTo(drop(1)) \ No newline at end of file diff --git a/src/main/java/util/EntryPointGenerator.kt b/src/main/java/util/EntryPointGenerator.kt new file mode 100644 index 00000000..4ba2c2bb --- /dev/null +++ b/src/main/java/util/EntryPointGenerator.kt @@ -0,0 +1,29 @@ +package util + +import arrow.core.Some +import eotree.EOBndExpr +import eotree.EOCopy +import eotree.EOObject +import eotree.data.EOStringData +import eotree.eoDot + +fun generateEntryPoint(mainClassName: String): List { + return listOf( + EOBndExpr( + EOObject( + listOf(), + Some("args"), + listOf( + EOBndExpr( + EOCopy( + "${mainClassName}.main".eoDot(), + listOf("*".eoDot()) + ), + "@" + ) + ) + ), + "main" + ) + ) +} diff --git a/src/main/java/util/ListUtils.java b/src/main/java/util/ListUtils.java index 4fa9bec8..885ab648 100644 --- a/src/main/java/util/ListUtils.java +++ b/src/main/java/util/ListUtils.java @@ -25,4 +25,11 @@ public static Optional first(List list) { else return Optional.ofNullable(list.get(0)); } + + public static Optional last(List list) { + if (list.size() == 0) + return Optional.empty(); + else + return Optional.ofNullable(list.get(list.size() - 1)); + } } diff --git a/src/main/java/util/Logging.kt b/src/main/java/util/Logging.kt new file mode 100644 index 00000000..0d37ecfc --- /dev/null +++ b/src/main/java/util/Logging.kt @@ -0,0 +1,5 @@ +package util + +import mu.KotlinLogging + +val logger = KotlinLogging.logger {} \ No newline at end of file diff --git a/src/main/java/util/MainFinder.kt b/src/main/java/util/MainFinder.kt new file mode 100644 index 00000000..13135f6a --- /dev/null +++ b/src/main/java/util/MainFinder.kt @@ -0,0 +1,25 @@ +package util + +import tree.Compilation.SimpleCompilationUnit +import tree.Compilation.TopLevelComponent +import tree.Declaration.Declaration +import tree.Declaration.MethodDeclaration +import tree.Declaration.NormalClassDeclaration + +fun containsMain(component: TopLevelComponent): Boolean { + return if (component.classDecl != null) { + (component.classDecl as NormalClassDeclaration).body.declarations + .filterIsInstance() + .find { declaration: Declaration? -> try { + (declaration as MethodDeclaration).parameters.parameters.size == 1 && + declaration.parameters.parameters[0].name == "args" && + declaration.name == "main" + } catch (e: NullPointerException) {false} } != null + } else { + false; + } +} + +fun findMainClass(unit: SimpleCompilationUnit): String { + return unit.components.components.find { component: TopLevelComponent -> containsMain(component) }!!.classDecl.name +} diff --git a/src/main/java/util/Naming.kt b/src/main/java/util/Naming.kt new file mode 100644 index 00000000..4014c528 --- /dev/null +++ b/src/main/java/util/Naming.kt @@ -0,0 +1,13 @@ +package util + +import tree.CompoundName + + +fun String.eoClassName(): String = genClassName(this) + +fun genClassName(javaName: String): String = + "class__$javaName" + +// TODO: introduce logic considering packages and classes +fun CompoundName.eoClassCompoundName(): CompoundName = + CompoundName(names.dropLast(1) + names.last().eoClassName()) \ No newline at end of file diff --git a/src/main/java/util/NewGenerator.kt b/src/main/java/util/NewGenerator.kt new file mode 100644 index 00000000..1b73aa98 --- /dev/null +++ b/src/main/java/util/NewGenerator.kt @@ -0,0 +1,74 @@ +package util + +import arrow.core.None +import arrow.core.flattenOption +import eotree.* +import lexer.TokenCode +import translator.mapClassDeclaration +import tree.Declaration.ClassDeclaration +import tree.Declaration.Declaration +import tree.Declaration.NormalClassDeclaration +import tree.Declaration.ParameterDeclaration +import tree.Type.Type +import tree.Type.TypeName +import kotlin.collections.ArrayList + +fun generateThis(clsDec: NormalClassDeclaration): EOBndExpr { + return EOBndExpr( + EOObject( + ArrayList(), + None, + listOf( + if (clsDec.extendedType is TypeName) + EOBndExpr( + ((clsDec.extendedType as TypeName).compoundName.names.last().eoClassName() + ".new").eoDot(), + "super" + ) + else + EOBndExpr( + "class__Object.new".eoDot(), + "super" + ), + EOBndExpr( + "super".eoDot(), + "@" + ) + ) + + if (clsDec.body != null) + clsDec.body.declarations + .filter { dec: Declaration -> dec.modifiers == null || + dec.modifiers.modifiers.modifiers.find { code: TokenCode -> code == TokenCode.Static } == null } + .map { mapClassDeclaration(it) } + .flattenOption() + else + listOf() + ), + "this" + ) +} + +fun generateNew(clsDec: NormalClassDeclaration): EOBndExpr { + return EOBndExpr( + EOObject( + ArrayList(), + None, + listOf( + generateThis(clsDec) + ) + ( + EOBndExpr( + EOCopy( + "seq", + listOf( + EOCopy( + "this", + listOf() + ) + ) + ), + "@" + ) + ) + ), + "new" + ) +} diff --git a/src/main/java/util/Preprocessor.kt b/src/main/java/util/Preprocessor.kt new file mode 100644 index 00000000..6488211b --- /dev/null +++ b/src/main/java/util/Preprocessor.kt @@ -0,0 +1,68 @@ +package util + +import lexer.TokenCode +import translator.mapExpression +import translator.mapStatement +import tree.Compilation.SimpleCompilationUnit +import tree.Compilation.TopLevelComponent +import tree.CompoundName +import tree.Declaration.MethodDeclaration +import tree.Declaration.NormalClassDeclaration +import tree.Expression.Expression +import tree.Expression.Primary.MethodInvocation +import tree.Expression.SimpleReference +import tree.Statement.BlockStatement +import tree.Statement.Statement +import tree.Statement.StatementExpression +import java.util.ArrayList + +fun preprocessCompoundName(compoundName: CompoundName, classNames: HashMap) { + if (compoundName.names.size == 1 && + classNames[compoundName.names.first()] == null) { + compoundName.names.add(0, "^") + } + compoundName.names + .replaceAll { if (classNames[it] != null) classNames[it] else it } +} + +fun preprocessMethodDeclaration(methodDeclaration: MethodDeclaration, classNames: HashMap) { + try { + methodDeclaration.methodBody.block.blockStatements + .mapNotNull { it.statement } + .mapNotNull { if (it is StatementExpression) it else null} + .mapNotNull { if (it.expression is MethodInvocation) it.expression as MethodInvocation else null} + .map { + if (it.qualifier != null && it.qualifier is SimpleReference) + preprocessCompoundName((it.qualifier as SimpleReference).compoundName, classNames) + else + null + } + } catch (e: NullPointerException) {/*Do nothing*/} +} + +fun preprocessClsDec(clsDec: NormalClassDeclaration, classNames: HashMap){ + if (classNames[clsDec.name] == null) { + classNames[clsDec.name] = "class__${clsDec.name}" + } + + clsDec.name = classNames[clsDec.name] + try { + clsDec.body.declarations + .filterIsInstance() + .map { innerClsDec: NormalClassDeclaration -> preprocessClsDec(innerClsDec, classNames) } + clsDec.body.declarations + .filterIsInstance() + .map { methodDeclaration: MethodDeclaration -> preprocessMethodDeclaration(methodDeclaration, classNames) } + } catch (e: NullPointerException) { /*Ignore it*/ } +} + +fun preprocessUnit(unit: SimpleCompilationUnit) { + var classNames = HashMap().also { + it["System"] = "class__System" + } + + unit.components.components + .mapNotNull { component: TopLevelComponent -> component.classDecl } + .filterIsInstance() + .map { clsDec: NormalClassDeclaration -> preprocessClsDec(clsDec, classNames)} +} diff --git a/src/main/java/util/StaticGenerator.kt b/src/main/java/util/StaticGenerator.kt new file mode 100644 index 00000000..c1c80e5f --- /dev/null +++ b/src/main/java/util/StaticGenerator.kt @@ -0,0 +1,20 @@ +package util + +import arrow.core.flattenOption +import eotree.EOBndExpr +import lexer.TokenCode +import translator.mapClassDeclaration +import tree.Declaration.Declaration +import tree.Declaration.NormalClassDeclaration + +fun generateStatic(clsDec: NormalClassDeclaration): List { + try { + return clsDec.body.declarations + .filter { dec: Declaration -> dec.modifiers != null && + dec.modifiers.modifiers.modifiers.find { code: TokenCode -> code == TokenCode.Static } != null }// TODO + .map { mapClassDeclaration(it) } + .flattenOption() + } catch (e: NullPointerException) { + return ArrayList() + } +} diff --git a/src/main/java/util/isSystemOutCall.kt b/src/main/java/util/isSystemOutCall.kt new file mode 100644 index 00000000..66d32f63 --- /dev/null +++ b/src/main/java/util/isSystemOutCall.kt @@ -0,0 +1,17 @@ +package util + +import tree.Expression.Primary.MethodInvocation +import tree.Expression.SimpleReference + +fun isSystemOutCall(methodInvocation: MethodInvocation): Boolean { + return if (methodInvocation.qualifier != null) { + if ((methodInvocation.qualifier as SimpleReference).compoundName.names.size == 3) { + (methodInvocation.qualifier as SimpleReference).compoundName.names[0] == "class__System" && + (methodInvocation.qualifier as SimpleReference).compoundName.names[1] == "out" + } else { + false + } + } else { + false + } +} diff --git a/src/main/resources/Java_16_Grammar.y b/src/main/resources/Java_16_Grammar.y index 3b7949ed..e4f4b737 100644 --- a/src/main/resources/Java_16_Grammar.y +++ b/src/main/resources/Java_16_Grammar.y @@ -1,6 +1,8 @@ //// Tokens //////////////////////// +//%token PHANTOM // =========== + %token LPAREN // ( %token RPAREN // ) %token LBRACE // { @@ -161,7 +163,7 @@ %nterm StandardModifierSeq %nterm ModifierSeq ModifierSeqOpt -%nterm CompilationUnit Package SimpleCompilationUnit +%nterm CompilationUnit Package /* SimpleCompilationUnit */ %nterm Module %nterm ImportDeclaration @@ -182,6 +184,9 @@ %nterm ClassDeclaration NormalClassDeclaration %nterm InterfaceDeclaration NormalInterfaceDeclaration AnnotationInterfaceDeclaration +%nterm EnumConstant +%nterm EnumConstantList EnumConstantListOpt +%nterm EnumBody %nterm EnumDeclaration RecordDeclaration Pattern InterfaceMemberDeclaration ClassBodyDeclaration PureBodyDeclaration FieldDeclaration MethodDeclaration @@ -189,7 +194,8 @@ LocalVariableDeclaration %nterm ConstructorDeclaration -%nterm InterfaceMemberDeclarationSeq InterfaceBody ClassBodyDeclarationSeq ClassBody ClassBodyOpt +%nterm InterfaceMemberDeclarationSeq InterfaceBody ClassBodyDeclarationSeq + ClassBody ClassBodyOpt EnumBodyDeclarationsOpt %nterm MethodDeclarator %nterm MethodHeader @@ -310,7 +316,7 @@ StandardModifier CompilationUnit : %empty { $$ = null; } | Package { $$ = $1; ast = $1; } - | Module { $$ = $1; ast = $1; } +// | Module { $$ = $1; ast = $1; } | ImportDeclarationSeqOpt TopLevelComponentSeq { ast = new SimpleCompilationUnit($1,$2); } ; @@ -322,7 +328,7 @@ Package /////// Java modules are not supported (yet) /////// Module - : /*ModifierSeqOpt*/ MODULE CompoundName LBRACE ModuleDirectiveSeqOpt RBRACE { $$ = null; } // not implemented + : ModifierSeqOpt MODULE CompoundName LBRACE ModuleDirectiveSeqOpt RBRACE { $$ = null; } // not implemented ; ImportDeclarationSeqOpt @@ -571,29 +577,34 @@ ExplicitConstructorInvocation //// EnumDeclaration //////////////////////////////////// EnumDeclaration - : /*ModifierSeqOpt*/ ENUM IDENTIFIER ClassImplementsOpt EnumBody { $$ = null; } + : /*ModifierSeqOpt*/ ENUM IDENTIFIER ClassImplementsOpt EnumBody { $$ = new EnumDeclaration($2,$3,$4); } ; EnumBody - : LBRACE EnumConstantListOpt EnumBodyDeclarationsOpt RBRACE - | LBRACE EnumConstantListOpt COMMA EnumBodyDeclarationsOpt RBRACE + : LBRACE EnumConstantListOpt EnumBodyDeclarationsOpt RBRACE { $$ = new EnumBody($2,$3); } + | LBRACE EnumConstantListOpt COMMA EnumBodyDeclarationsOpt RBRACE { $$ = new EnumBody($2,$4); } ; EnumConstantListOpt - : %empty - | EnumConstant - | EnumConstantListOpt COMMA EnumConstant + : %empty { $$ = null; } + | EnumConstantList { $$ = $1; } + ; + +EnumConstantList + : EnumConstant { $$ = new Enumerators($1); } + | EnumConstantList COMMA EnumConstant { $$ = $1.add($3); } ; EnumConstant - : AnnotationSeqOpt IDENTIFIER Arguments - | AnnotationSeqOpt IDENTIFIER Arguments ClassBody + : AnnotationSeqOpt IDENTIFIER { $$ = new Enumerator($1,$2,null,null); } + | AnnotationSeqOpt IDENTIFIER Arguments { $$ = new Enumerator($1,$2,$3,null); } + | AnnotationSeqOpt IDENTIFIER Arguments ClassBody { $$ = new Enumerator($1,$2,$3,$4); } ; EnumBodyDeclarationsOpt - : %empty - | SEMICOLON - | SEMICOLON ClassBodyDeclarationSeq + : %empty { $$ = null; } + | SEMICOLON { $$ = null; } + | SEMICOLON ClassBodyDeclarationSeq { $$ = $2; } ; //// RecordDeclaration ////////////////////////////////// @@ -635,7 +646,8 @@ RecordBodyDeclaration //// FieldDeclaration /////////////////////////////////// FieldDeclaration - : /*ModifierSeqOpt*/ UnannotatedType VariableDeclaratorList SEMICOLON { $$ = new TypeAndDeclarators($1,$2); } + : /*ModifierSeqOpt*/ UnannotatedType VariableDeclaratorList SEMICOLON + { $$ = new TypeAndDeclarators($1,$2); } ; VariableDeclaratorList @@ -840,18 +852,19 @@ DefaultValueOpt | DEFAULT ElementValue ; + //// Blocks & Statements ///////////////////////////////////// Block - : LBRACE RBRACE { $$ = null; } - | LBRACE BlockStatementSeq RBRACE { $$ = new Block(null,$2); } + : LBRACE RBRACE { $$ = null; } + | LBRACE BlockStatementSeq RBRACE { $$ = new Block(null,$2); } ; BlockStatementSeq : BlockStatement { $$ = new BlockStatements($1); } | BlockStatementSeq BlockStatement { $$ = $1.add($2); } ; - +/* BlockStatement : ModifierSeqOpt BlockDeclaration { $$ = new BlockStatement($2.addModifiers($1)); } | Statement { $$ = new BlockStatement($1); } @@ -862,6 +875,15 @@ BlockDeclaration | NormalInterfaceDeclaration { $$ = $1; } // LocalClassOrInterfaceDeclaration | LocalVariableDeclaration SEMICOLON { $$ = $1; } // LocalVariableDeclarationStatement ; +*/ + +BlockStatement + : ModifierSeqOpt ClassDeclaration { $$ = new BlockStatement($2.addModifiers($1)); } + | ModifierSeqOpt NormalInterfaceDeclaration { $$ = new BlockStatement($2.addModifiers($1)); } + | ModifierSeqOpt LocalVariableDeclaration SEMICOLON + { $$ = new BlockStatement($2.addModifiers($1)); } + | Statement { $$ = new BlockStatement($1); } + ; LocalVariableDeclaration : UnannotatedType VariableDeclaratorList { $$ = new TypeAndDeclarators($1,$2); } @@ -878,8 +900,8 @@ Statement SimpleStatement : Block { $$ = $1; } - | SEMICOLON { $$ = null; } // EmptyStatement - | StatementExpression SEMICOLON { $$ = $1; } // ExpressionStatement + | SEMICOLON { $$ = null; } // EmptyStatement + | StatementExpression SEMICOLON { $$ = $1; } // ExpressionStatement | ASSERT Expression SEMICOLON { $$ = new Assert(null,$2,null); } // AssertStatement | ASSERT Expression COLON Expression SEMICOLON { $$ = new Assert(null,$2,$4); } // AssertStatement @@ -907,6 +929,7 @@ SimpleStatement | TRY Block Finally { $$ = null; } // not implemented yet | TRY ResourceSpecification Block CatchesOpt FinallyOpt // TryWithResourcesStatement { $$ = null; } // not implemented yet + | error SEMICOLON { $$ = null; } ; LabeledStatement @@ -914,17 +937,17 @@ LabeledStatement ; StatementExpression - : Assignment { $$ = $1; } - | PreIncrementExpression { $$ = $1; } - | PreDecrementExpression { $$ = $1; } - | PostIncrementExpression { $$ = $1; } - | PostDecrementExpression { $$ = $1; } + : Assignment { $$ = new StatementExpression(null,$1); } + | PreIncrementExpression { $$ = new StatementExpression(null,$1); } + | PreDecrementExpression { $$ = new StatementExpression(null,$1); } + | PostIncrementExpression { $$ = new StatementExpression(null,$1); } + | PostDecrementExpression { $$ = new StatementExpression(null,$1); } | MethodInvocation { $$ = new StatementExpression(null,$1); } | ClassInstanceCreationExpression { $$ = $1; } ; IfThenElseStatement - : IF LPAREN Expression RPAREN Statement ElsePartOpt { $$ = null; } // not implemented yet + : IF LPAREN Expression RPAREN Statement ElsePartOpt { $$ = new IfThenElse(null,$3,$5,$6); } ; ElsePartOpt @@ -1159,12 +1182,10 @@ ArrayAccess ; MethodInvocation - : IDENTIFIER Arguments { $$ = new MethodInvocation(null,false,null,$1,$2); } - | IDENTIFIER DOT TypeArgumentsOpt CompoundName Arguments { var ref = new SimpleReference(new CompoundName($1.image)); - for (String s : $4.names) ref.compoundName.add(s); - ref.compoundName.names.remove(ref.compoundName.names.size() - 1); - $$ = new MethodInvocation(ref,false,$3, - new Token(TokenCode.Identifier, $4.names.get($4.names.size() - 1)),$5); } + : CompoundName Arguments { var ref = new SimpleReference($1); + $$ = new MethodInvocation(ref,false,null,null,$2); } + | CompoundName DOT TypeArguments IDENTIFIER Arguments { var ref = new SimpleReference($1); + $$ = new MethodInvocation(ref,false,$3,$4,$5); } | Primary DOT TypeArgumentsOpt IDENTIFIER Arguments { $$ = new MethodInvocation($1,false,$3,$4,$5); } | SUPER DOT TypeArgumentsOpt IDENTIFIER Arguments { $$ = new MethodInvocation(null,true,$3,$4,$5); } | CompoundName DOT SUPER DOT TypeArgumentsOpt IDENTIFIER Arguments { var ref = new SimpleReference($1); @@ -1187,12 +1208,12 @@ ArgumentList ; MethodReference - : CompoundName DBL_COLON TypeArgumentsOpt IDENTIFIER { $$ = null; } // not implemented yet - | Primary DBL_COLON TypeArgumentsOpt IDENTIFIER { $$ = null; } // not implemented yet - | Type DBL_COLON TypeArgumentsOpt IDENTIFIER { $$ = null; } // not implemented yet - | SUPER DBL_COLON TypeArgumentsOpt IDENTIFIER { $$ = null; } // not implemented yet - | Type DOT SUPER DBL_COLON TypeArgumentsOpt IDENTIFIER { $$ = null; } // not implemented yet - | Type DBL_COLON TypeArgumentsOpt NEW { $$ = null; } // not implemented yet +// : CompoundName DBL_COLON TypeArgumentsOpt IDENTIFIER { $$ = null; } -- covered by 'Type' case + : Primary DBL_COLON TypeArgumentsOpt IDENTIFIER { $$ = null; } // not implemented yet + | Type DBL_COLON TypeArgumentsOpt IDENTIFIER { $$ = null; } // not implemented yet + | SUPER DBL_COLON TypeArgumentsOpt IDENTIFIER { $$ = null; } // not implemented yet + | Type DOT SUPER DBL_COLON TypeArgumentsOpt IDENTIFIER { $$ = null; } // not implemented yet + | Type DBL_COLON TypeArgumentsOpt NEW { $$ = null; } // not implemented yet ; ArrayCreationExpression @@ -1258,9 +1279,8 @@ LambdaParameter // : IDENTIFIER : ModifierSeqOpt UnannotatedType IDENTIFIER DimsOpt { $$ = new ParameterDeclaration($1,$2,$3.image,null,false,$4); } | ModifierSeqOpt VAR IDENTIFIER DimsOpt { $$ = new ParameterDeclaration($1,null,$3.image,null,false,$4); } - | ModifierSeqOpt UnannotatedType AnnotationSeqOpt ELLIPSIS IDENTIFIER + | ModifierSeqOpt UnannotatedType AnnotationSeqOpt ELLIPSIS IDENTIFIER // VariableArityParameter { $$ = new ParameterDeclaration($1,$2,$5.image,$3,true,null); } - // VariableArityParameter ; //LambdaParameterType diff --git a/src/main/resources/stdlib/class__Object.eo b/src/main/resources/stdlib/class__Object.eo new file mode 100644 index 00000000..e61316ad --- /dev/null +++ b/src/main/resources/stdlib/class__Object.eo @@ -0,0 +1,17 @@ ++package stdlib + +[] > class__Object + [] > new + [] > this + [self] > init + 0 > @ + + seq > @ + this + + [] > constructor + new > self + seq > @ + self.init + self + self diff --git a/src/main/resources/stdlib/class__PrintStream.eo b/src/main/resources/stdlib/class__PrintStream.eo new file mode 100644 index 00000000..b5e8f53d --- /dev/null +++ b/src/main/resources/stdlib/class__PrintStream.eo @@ -0,0 +1,29 @@ ++package stdlib ++alias stdlib.class__Object ++alias stdout org.eolang.io.stdout + +[] > class__PrintStream + [] > new + [] > this + class__Object.new > super + super > @ + + [self] > init + 0 > @ + + [self x] > println + seq > @ + stdout + x + stdout + "\n" + + seq > @ + this + + [] > constructor + new > self + seq > @ + self.init + self + self diff --git a/src/main/resources/stdlib/class__System.eo b/src/main/resources/stdlib/class__System.eo new file mode 100644 index 00000000..74c2dc1e --- /dev/null +++ b/src/main/resources/stdlib/class__System.eo @@ -0,0 +1,24 @@ ++package stdlib ++alias stdlib.class__Object ++alias stdlib.class__PrintStream + +[] > class__System + class__PrintStream.constructor > out + + [] > new + [] > this + class__Object.new > super + super > @ + + [self] > init + 0 > @ + + seq > @ + this + + [] > constructor + new > self + seq > @ + self.init + self + self diff --git a/src/test/TEST0.java b/src/test/TEST0.java new file mode 100644 index 00000000..14789848 --- /dev/null +++ b/src/test/TEST0.java @@ -0,0 +1,30 @@ +class Example +{ + public int m1 = 5; + public T m2; + private static P1.P2.T m3; + + void message() + { + а += 1; + static int z; + var f = 1; + var aaa = ((T)x).m; + f++; + ++f; + print("Hello",world+aaa,777*f); + var ee = f1 * ( f2 - f3)/4; + } + + public static void main(String[] args) + { + message(world/3); + message(+qqq); + // message(world); + } + + public enum D + { + West, East, South, North + } +} \ No newline at end of file diff --git a/src/test/TEST1.java b/src/test/TEST1.java new file mode 100644 index 00000000..6a48b618 --- /dev/null +++ b/src/test/TEST1.java @@ -0,0 +1,32 @@ +class Example extends Object +{ + int m1; + P.T m2; + public T m3; + void message() { + int local = 1; + + print("Hello"); + print(++a); + print(a+1); + print(a++); + print(1,2); + print(a,b); + print(a-1,a+1); + print(f(1)); + print(f()); + } + + public static void main(String[] args) { + if ( x > 0) x = 1; + int x = 777; + T m = 1; + T.m = 1; + int m; + x = x + 1; + x++; + ++w; + this.m3 = a + (b*c -1); + message(); + } +} \ No newline at end of file diff --git a/src/test/java/common/TestJ2EO.java b/src/test/java/common/TestJ2EO.java deleted file mode 100644 index 35efd241..00000000 --- a/src/test/java/common/TestJ2EO.java +++ /dev/null @@ -1,407 +0,0 @@ -package common; - -import eotree.EOProgram; -import lexer.Scanner; -import org.junit.jupiter.api.*; -import org.junit.jupiter.api.parallel.Execution; -import org.junit.jupiter.api.parallel.ExecutionMode; -import parser.JavaParser; -import translator.Translator; -import tree.Compilation.CompilationUnit; - -import java.io.*; -import java.nio.file.*; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedList; -import java.util.logging.Level; -import java.util.logging.LogManager; -import java.util.logging.Logger; -import java.util.stream.Collectors; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -@Execution(ExecutionMode.CONCURRENT) -public class TestJ2EO { - - private static String testFolderRoot; - private static final char sep = File.separatorChar; - private static final Logger logger = Logger.getLogger("org.eolang.j2eo.test"); - - @BeforeAll - static void setup() { - boolean testCandidates = System.getProperty("candidates") != null && - System.getProperty("candidates").equals("true"); - - if (testCandidates) - logger.log(Level.INFO, "Executing candidate tests!"); - - String testFolderPath = "src" + sep + "test" + sep + "resources"; - if (testCandidates) { - testFolderPath += sep + "test_candidates"; - } - File file = new File(testFolderPath); - testFolderRoot = file.getAbsolutePath(); - } - - @TestFactory - Collection testChapter4() { - return testChapter(testFolderRoot + sep + "ch_4_types_values_variables"); - } - - @TestFactory - Collection testChapter5() { - return testChapter(testFolderRoot + sep + "ch_5_conversions_and_contexts"); - } - - @TestFactory - Collection testChapter6() { - return testChapter(testFolderRoot + sep + "ch_6_names"); - } - - @TestFactory - Collection testChapter7() { - return testChapter(testFolderRoot + sep + "ch_7_packages_and_modules"); - } - - @TestFactory - Collection testChapter8() { - return testChapter(testFolderRoot + sep + "ch_8_classes"); - } - - @TestFactory - Collection testChapter9() { - return testChapter(testFolderRoot + sep + "ch_9_interfaces"); - } - - @TestFactory - Collection testChapter10() { - return testChapter(testFolderRoot + sep + "ch_10_arrays"); - } - - @TestFactory - Collection testChapter11() { - return testChapter(testFolderRoot + sep + "ch_11_exceptions"); - } - - @TestFactory - Collection testChapter14() { - return testChapter(testFolderRoot + sep + "ch_14_blocks_statements_and_patterns"); - } - - @TestFactory - Collection testChapter15() { - return testChapter(testFolderRoot + sep + "ch_15_expressions"); - } - - @TestFactory - Collection testChapter16() { - return testChapter(testFolderRoot + sep + "ch_16_definite_assignment"); - } - - @TestFactory - Collection testChapter17() { - return testChapter(testFolderRoot + sep + "ch_17_threads_and_locks"); - } - - @TestFactory - Collection testChapter18() { - return testChapter(testFolderRoot + sep + "ch_18_type_inference"); - } - - @TestFactory - Collection simpleTest() { - return new ArrayList<>() { - { - add(testFile(Paths.get(testFolderRoot + sep + "SimpleTest.java"))); - } - }; - } - - private ArrayList testChapter(String chapterPath) { - ArrayList chapterTests = new ArrayList<>(); - try { - for (Path p : Files - .walk(Paths.get(chapterPath)) - .filter(Files::isRegularFile) - .filter(TestJ2EO::isReadyTest) - .filter(TestJ2EO::isNotClassFile) - .filter(TestJ2EO::isJavaFile) - .collect(Collectors.toList())) { - chapterTests.add(testFile(p)); - } - } catch (IOException e) { - e.printStackTrace(); - } - return chapterTests; - } - - private static DynamicTest testFile(Path path) { - return DynamicTest.dynamicTest( - path.getParent().getFileName().toString() + "/" + - path.getFileName().toString(), () -> { - - logger.info("-- Current test file: " + path.toString()); - - // Compile and execute Java file - String javaExecOutput = compileAndExecuteJava(path); - - // Run parser - CompilationUnit unit = parseAndBuildAST(path); - if (unit == null) { - logger.severe("Java parsing failed!!!"); - } - - // EO tree to string - String eoCode = translateToEO(unit); - if (eoCode != null) { - logger.info("-- Translation output --" + System.lineSeparator() + eoCode); - } - - // Compile and execute translated to EO Java file - String eoExecOutput = compileAndExecuteEO(eoCode, path); - - // Assert equal execution outputs - assertEquals(javaExecOutput, eoExecOutput); - } - ); - } - - private static String compileAndExecuteJava(Path path) { - StringBuilder output = new StringBuilder(); - try { - // Compile .java file - String fileName = path.getFileName().toString().split("\\.")[0]; - Path subFolder = Paths.get(path.getParent().toString(), fileName + "_java"); - if (Files.exists(subFolder)) { - deleteDirTree(subFolder); - } - Files.createDirectories(subFolder); - Files.copy(path, Paths.get(subFolder.toString(), path.getFileName().toString())); - ProcessBuilder compilePb = new ProcessBuilder( - "javac", - "-d", - subFolder.toString(), - path.toString() - ); - compilePb.directory(new File(subFolder.toString())); - compilePb.redirectErrorStream(true); - Process compileProcess = compilePb.start(); - BufferedReader stdCompInput = new BufferedReader(new - InputStreamReader(compileProcess.getInputStream())); - String sc; - StringBuilder javacSb = new StringBuilder(); - while ((sc = stdCompInput.readLine()) != null) { - javacSb.append(sc).append(System.lineSeparator()); // Java compilation output (if any) - } - compileProcess.waitFor(); - compileProcess.destroy(); - - logger.info("-- Java compilation output --" + System.lineSeparator() + javacSb.toString()); - - // Execute .class file - ProcessBuilder execPb = new ProcessBuilder( - "java", - "-cp", - subFolder.toString() + sep, - fileName - ); - execPb.directory(new File(subFolder.toString())); - execPb.redirectErrorStream(true); - Process execProcess = execPb.start(); - - // Receive output - BufferedReader stdInput = new BufferedReader(new - InputStreamReader(execProcess.getInputStream())); - String s; - while ((s = stdInput.readLine()) != null) { - output.append(s).append(System.lineSeparator()); - } - execProcess.waitFor(); - execProcess.destroy(); - - logger.info("-- Java execution output --" + System.lineSeparator() + output.toString()); - - // Remove .class files - deleteDirTree(subFolder); - - } catch (IOException | InterruptedException e) { - e.printStackTrace(); - logger.throwing(TestJ2EO.class.getName(), "compileAndExecuteJava", e); - } - return output.toString(); - } - - private static CompilationUnit parseAndBuildAST(Path path) { - Scanner scanner = new Scanner(); - scanner.readFile(path.toString()); - JavaParser parser = new JavaParser(scanner); - try { - if (!parser.parse()) { - logger.severe("Unable to parse a .java file: \"" + path.toString() + "\""); - } - } catch (IOException e) { - e.printStackTrace(); - logger.throwing(TestJ2EO.class.getName(), "parseAndBuildAST", e); - } - return parser.ast; - } - - private static String translateToEO(CompilationUnit unit) { - if (unit == null) { - logger.severe("Given AST tree root is null!!! Aborting the translation..."); - return "abort since parsing failed"; - } - EOProgram eoProgram = null; - try { - eoProgram = Translator.translate(unit); - } catch (Exception e) { - logger.throwing(TestJ2EO.class.getName(), "translateToEO", e); - } - if (eoProgram == null) { - logger.severe("Translation failed!!!"); - return null; - } else { - return eoProgram.generateEO(0); - } - } - - /*** - * The process is following:
- * 1. In the same parent folder as the ".java" test file has create subfolder.
- * 2. In that subfolder create "eo" subfolder.
- * 3. In "eo" subfolder create "main.eo" file and write previously generated EO code to it.
- * 4. Alongside "eo" subfolder make a copy of "pom.xml" file fo Maven.
- * 5. Compile "main.eo" with
mvn clean compile
- * 6. Execute with
java -cp ...
- * 7. Receive execution output
- * 8. Pass received output back
- * @param eoCode previously generated EO code - * @param testFilePath path to the ".java" test file - * @return EO execution output - */ - private static String compileAndExecuteEO(String eoCode, Path testFilePath) { - StringBuilder eoExecOut = new StringBuilder(); - String eoFileName = testFilePath.getFileName().toString().split("\\.")[0]; - Path testFolderPath = Paths.get(testFilePath.getParent().toString(), eoFileName + "_eo"); - try { - // Setup temporary folders and files - if (Files.exists(testFolderPath)) { - deleteDirTree(testFolderPath); - } - Path eoExecDir = Files.createDirectories( - Paths.get(testFolderPath.toString(), "eo")); - Path eoFilePath = Files.createFile(Paths.get(eoExecDir.toString() + sep + "class_" + eoFileName + ".eo")); - Files.copy( - Paths.get(testFolderRoot, "eo_execution_pom", "pom.xml"), - Paths.get(eoExecDir.getParent().toString() + sep + "pom.xml")); - - // Write generated code to the file - Files.writeString(eoFilePath, eoCode); - - // Execute generated EO code - try { - boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows"); // Matters a lot - - // Compile EO file - ProcessBuilder compilePb = new ProcessBuilder("mvn" + (isWindows ? ".cmd" : ""), "clean", "compile"); - compilePb.directory(new File(eoExecDir.getParent().toString())); - compilePb.redirectErrorStream(true); - Process compileProcess = compilePb.start(); - - // Receive compilation output (may be useful) - BufferedReader mvnStdInput = new BufferedReader(new - InputStreamReader(compileProcess.getInputStream())); - String m; - StringBuilder mvnSb = new StringBuilder(); - while ((m = mvnStdInput.readLine()) != null) { - mvnSb.append(m).append(System.lineSeparator()); - } - compileProcess.waitFor(); - compileProcess.destroy(); - - logger.info(" -- EO compilation output --" + System.lineSeparator() + mvnSb.toString()); - - // Execute Java ".class"es - ProcessBuilder execPb = new ProcessBuilder( - "java", - "-cp", - (isWindows ? - "\"target/classes;target/eo-runtime.jar\"" : - "target/classes:target/eo-runtime.jar"), - "org.eolang.Main", - "global", - (isWindows ? "%*" : "\"$@\"") - ); - execPb.directory(new File(eoExecDir.getParent().toString())); - execPb.redirectErrorStream(true); - Process execProcess = execPb.start(); - - // Receive EO execution output - BufferedReader stdInput = new BufferedReader(new - InputStreamReader(execProcess.getInputStream())); - String s; - while ((s = stdInput.readLine()) != null) { - eoExecOut.append(s).append(System.lineSeparator()); - } - execProcess.waitFor(); - execProcess.destroy(); - - logger.info("-- EO execution output --" + System.lineSeparator() + eoExecOut.toString()); - - } catch (InterruptedException e) { - e.printStackTrace(); - logger.throwing(TestJ2EO.class.getName(), "compileAndExecuteEO", e); - } - - // Clean everything out - deleteDirTree(eoExecDir.getParent()); - - } catch (Exception e) { - e.printStackTrace(); - logger.throwing(TestJ2EO.class.getName(), "compileAndExecuteEO", e); - } - - // Double check for delete, so that no obsolete files are created after test fail - if (Files.exists(testFolderPath)) { - try { - deleteDirTree(testFolderPath); - } catch (IOException e) { - e.printStackTrace(); - } - } - return eoExecOut.isEmpty() ? "not passed" : eoExecOut.toString(); - } - - private static void deleteDirTree(Path path) throws IOException { - Files.walkFileTree(path, new SimpleFileVisitor<>() { - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { - Files.delete(dir); - return FileVisitResult.CONTINUE; - } - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - Files.delete(file); - return FileVisitResult.CONTINUE; - } - }); - } - - private static boolean isReadyTest(Path path) { - return !path.endsWith("SampleTest.java"); - } - - private static boolean isClassFile(Path path) { - return path.toString().endsWith(".class"); - } - - private static boolean isJavaFile(Path path) { - return path.toString().endsWith(".java"); - } - - private static boolean isNotClassFile(Path path) { - return !isClassFile(path); - } -} diff --git a/src/test/java/common/TestJ2EO.kt b/src/test/java/common/TestJ2EO.kt new file mode 100644 index 00000000..0d02a7fd --- /dev/null +++ b/src/test/java/common/TestJ2EO.kt @@ -0,0 +1,361 @@ +package common + +import eotree.EOProgram +import lexer.Scanner +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.DynamicTest +import org.junit.jupiter.api.TestFactory +import org.junit.jupiter.api.parallel.Execution +import org.junit.jupiter.api.parallel.ExecutionMode +import parser.JavaParser +import translator.translate +import tree.Compilation.CompilationUnit +import util.logger +import java.io.BufferedReader +import java.io.File +import java.io.IOException +import java.io.InputStreamReader +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.Paths +import java.util.* +import kotlin.io.path.exists + +@Execution(ExecutionMode.CONCURRENT) +//@Execution(ExecutionMode.SAME_THREAD) +class TestJ2EO { + @TestFactory + fun testChapter4(): Collection { + return testChapter(testFolderRoot + sep + "ch_4_types_values_variables") + } + + @TestFactory + fun testChapter5(): Collection { + return testChapter(testFolderRoot + sep + "ch_5_conversions_and_contexts") + } + + @TestFactory + fun testChapter6(): Collection { + return testChapter(testFolderRoot + sep + "ch_6_names") + } + + @TestFactory + fun testChapter7(): Collection { + return testChapter(testFolderRoot + sep + "ch_7_packages_and_modules") + } + + @TestFactory + fun testChapter8(): Collection { + return testChapter(testFolderRoot + sep + "ch_8_classes") + } + + @TestFactory + fun testChapter9(): Collection { + return testChapter(testFolderRoot + sep + "ch_9_interfaces") + } + + @TestFactory + fun testChapter10(): Collection { + return testChapter(testFolderRoot + sep + "ch_10_arrays") + } + + @TestFactory + fun testChapter11(): Collection { + return testChapter(testFolderRoot + sep + "ch_11_exceptions") + } + + @TestFactory + fun testChapter14(): Collection { + return testChapter(testFolderRoot + sep + "ch_14_blocks_statements_and_patterns") + } + + @TestFactory + fun testChapter15(): Collection { + return testChapter(testFolderRoot + sep + "ch_15_expressions") + } + + @TestFactory + fun testChapter16(): Collection { + return testChapter(testFolderRoot + sep + "ch_16_definite_assignment") + } + + @TestFactory + fun testChapter17(): Collection { + return testChapter(testFolderRoot + sep + "ch_17_threads_and_locks") + } + + @TestFactory + fun testChapter18(): Collection { + return testChapter(testFolderRoot + sep + "ch_18_type_inference") + } + + @TestFactory + fun simpleTest(): Collection = + listOf( + testFile(Paths.get(testFolderRoot + sep + "SimpleTest.java")) + ) + + private fun testChapter(chapterPath: String): List { + return File(chapterPath).walk() + .filter { file -> file.isFile } + .filter { file -> isReadyTest(file.toPath()) } + .filter { file -> isNotClassFile(file.toPath()) } + .filter { file -> isJavaFile(file.toPath()) } + .map { file -> testFile(file.toPath()) } + .toList() + } + + companion object { + private var testFolderRoot: String? = null + private var mainFolderRoot: String? = null + private val sep = File.separatorChar.toString() + + @BeforeAll + @JvmStatic + fun setup() { + val testCandidates = + System.getProperty("candidates") != null && + System.getProperty("candidates") == "true" + if (testCandidates) + logger.info("Executing candidate tests!") + var testFolderPath = listOf("src", "test", "resources").joinToString(sep) + if (testCandidates) { + testFolderPath += sep + "test_candidates" + } + val mainFolderPath = listOf("src", "main", "resources").joinToString(sep) + val fileMain = File(mainFolderPath) + mainFolderRoot = fileMain.absolutePath + val fileTest = File(testFolderPath) + testFolderRoot = fileTest.absolutePath + } + + private fun testFile(path: Path): DynamicTest { + return DynamicTest.dynamicTest( + path.parent.fileName.toString() + "/" + + path.fileName.toString() + ) { + logger.info("-- Current test file: $path") + + // Compile and execute Java file + // FIXME: EO should generate '\r\n' symbols for Windows + val javaExecOutput = compileAndExecuteJava(path).replace("\r\n", "\n") + + // Run parser + val unit = parseAndBuildAST(path) + + // EO tree to string + val eoCode = translateToEO(unit) + logger.info("-- Translation output --" + System.lineSeparator() + eoCode) + + // Compile and execute translated to EO Java file + val eoExecOutput = compileAndExecuteEO(eoCode, path) + + // Assert equal execution outputs + Assertions.assertEquals(javaExecOutput, eoExecOutput) + } + } + + private fun compileAndExecuteJava(path: Path): String { + val fileName = path.fileName.toString().split(".").toTypedArray()[0] + val subFolder: File = Path.of(path.parent.toString(), "${fileName}_java").toFile() + if (subFolder.exists()) { + subFolder.deleteRecursively() + } + + try { + val output = StringBuilder() + // Compile .java file + Files.createDirectories(subFolder.toPath()) + Files.copy(path, Paths.get(subFolder.toString(), path.fileName.toString())) + val compilePb = ProcessBuilder( + "javac", + "-d", + subFolder.toString(), + path.toString() + ) + compilePb.directory(File(subFolder.toString())) + compilePb.redirectErrorStream(true) + val compileProcess = compilePb.start() + val stdCompInput = BufferedReader(InputStreamReader(compileProcess.inputStream)) + var sc: String? + val javacSb = StringBuilder() + while (stdCompInput.readLine().also { sc = it } != null) { + javacSb.append(sc).append(System.lineSeparator()) // Java compilation output (if any) + } + compileProcess.waitFor() + compileProcess.destroy() + logger.info("-- Java compilation output --" + System.lineSeparator() + javacSb.toString()) + + // Execute .class file + val execPb = ProcessBuilder( + "java", + "-cp", + subFolder.toString() + sep, + fileName + ) + execPb.directory(File(subFolder.toString())) + execPb.redirectErrorStream(true) + val execProcess = execPb.start() + + // Receive output + val stdInput = BufferedReader(InputStreamReader(execProcess.inputStream)) + var s: String? + while (stdInput.readLine().also { s = it } != null) { + output.append(s).append(System.lineSeparator()) + } + execProcess.waitFor() + execProcess.destroy() + logger.info("-- Java execution output --" + System.lineSeparator() + output.toString()) + + // Remove .class files + subFolder.deleteRecursively() + return output.toString() + } catch (e: Exception) { + // Cleanup output and rethrow exception + subFolder.deleteRecursively() + throw e + } + } + + private fun parseAndBuildAST(path: Path): CompilationUnit { + val scanner = Scanner() + scanner.readFile(path.toString()) + val parser = JavaParser(scanner) + if (!parser.parse()) { + logger.error("Unable to parse a .java file: \"$path\"") + throw IllegalStateException("Parsing Java file \"$path\" failed") + } + return parser.ast + } + + private fun translateToEO(unit: CompilationUnit): String { + val eoProgram: EOProgram = translate(unit) + return eoProgram.generateEO(0) + } + + /** + * The process is following:

+ * 1. In the same parent folder as the ".java" test file has create subfolder.

+ * 2. In that subfolder create "eo" subfolder.

+ * 3. In "eo" subfolder create "main.eo" file and write previously generated EO code to it.

+ * 4. Alongside "eo" subfolder make a copy of "pom.xml" file fo Maven.

+ * 5. Compile "main.eo" with
mvn clean compile
+ * 6. Execute with
java -cp ...
+ * 7. Receive execution output

+ * 8. Pass received output back

+ * @param eoCode previously generated EO code + * @param testFilePath path to the ".java" test file + * @return EO execution output + */ + private fun compileAndExecuteEO(eoCode: String?, testFilePath: Path): String { + val eoFileName = testFilePath.fileName.toString().split(".").toTypedArray()[0] + val testFolder: File = Path.of(testFilePath.parent.toString(), "${eoFileName}_eo").toFile() + // Setup temporary folders and files + if (testFolder.exists()) { + testFolder.deleteRecursively() + } + val eoExecDir = Files.createDirectories(Paths.get(testFolder.toString(), "eo")) + + try { + val eoFilePath = Files.createFile(Paths.get(eoExecDir.toString() + sep + "class_" + eoFileName + ".eo")) + Files.copy( + Paths.get(testFolderRoot, "eo_execution_pom", "pom.xml"), + Paths.get(eoExecDir.parent.toString() + sep + "pom.xml") + ) + Paths.get(mainFolderRoot, "stdlib").toFile().copyRecursively( + Paths.get(eoExecDir.toString(), "stdlib").toFile() + ) + + // Write generated code to the file + Files.writeString(eoFilePath, eoCode) + + // Execute generated EO code + val isWindows = System.getProperty("os.name").lowercase(Locale.getDefault()) + .contains("windows") // Matters a lot + + // Compile EO file + val mvnCommands = if (isWindows) listOf("mvn.cmd", "clean", "compile") + else listOf("mvn", "clean", "compile") + val compileProcess = ProcessBuilder(mvnCommands) + .directory(File(eoExecDir.parent.toString())) + .redirectErrorStream(true) + .start() + + // Receive compilation output (may be useful) + val mvnStdInput = BufferedReader(InputStreamReader(compileProcess.inputStream)) + var m: String? + val mvnSb = StringBuilder() + while (mvnStdInput.readLine().also { m = it } != null) { + mvnSb.append(m).append(System.lineSeparator()) + } + compileProcess.waitFor() + compileProcess.destroy() + logger.info(" -- EO compilation output --" + System.lineSeparator() + mvnSb.toString()) + + // Execute Java ".class"es + val execPb = ProcessBuilder( + "java", "-cp", + if (isWindows) + "\"target/classes;target/eo-runtime.jar\"" + else + "target/classes:target/eo-runtime.jar", + "org.eolang.Main", + "main", + if (isWindows) + "%*" + else + "\"$@\"1" + ) + execPb.directory(File(eoExecDir.parent.toString())) + execPb.redirectErrorStream(true) + val execProcess = execPb.start() + + // Receive EO execution output + val stdInput = BufferedReader(InputStreamReader(execProcess.inputStream)) + val eoExecOut: String = stdInput.readText() + execProcess.waitFor() + execProcess.destroy() + logger.info("-- EO execution output --\n$eoExecOut") + + // Clean everything out + eoExecDir.toAbsolutePath().parent.toFile().deleteRecursively() + + // Double check for delete, so that no obsolete files are created after test fail + if (testFolder.exists()) { + try { + testFolder.deleteRecursively() + } catch (e: IOException) { + e.printStackTrace() + } + } + + return eoExecOut + } catch (e: Exception) { + // Clean everything out + eoExecDir.toAbsolutePath().parent.toFile().deleteRecursively() + + // Double check for delete, so that no obsolete files are created after test fail + if (testFolder.exists()) + testFolder.deleteRecursively() + throw e + } + } + + private fun isReadyTest(path: Path): Boolean { + return !path.endsWith("SampleTest.java") + } + + private fun isClassFile(path: Path): Boolean { + return path.toString().endsWith(".class") + } + + private fun isJavaFile(path: Path): Boolean { + return path.toString().endsWith(".java") + } + + private fun isNotClassFile(path: Path): Boolean { + return !isClassFile(path) + } + } +} \ No newline at end of file diff --git a/src/test/java/eotree/TestEOAnonExpr.java b/src/test/java/eotree/TestEOAnonExpr.java deleted file mode 100644 index ec73c30c..00000000 --- a/src/test/java/eotree/TestEOAnonExpr.java +++ /dev/null @@ -1,25 +0,0 @@ -package eotree; - -import org.junit.jupiter.api.Test; - -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class TestEOAnonExpr { - @Test - public void TestGenerateEOZeroIndent() { - var f = new EOAnonExpr( - new EODot(Optional.empty(), "memory") - ); - assertEquals("memory", f.generateEO(0)); - } - - @Test - public void TestGenerateEONonZeroIndent() { - var f = new EOAnonExpr( - new EODot(Optional.empty(), "memory") - ); - assertEquals(" memory", f.generateEO(1)); - } -} diff --git a/src/test/java/eotree/TestEOBndExpr.java b/src/test/java/eotree/TestEOBndExpr.java index 97f19ba5..46363705 100644 --- a/src/test/java/eotree/TestEOBndExpr.java +++ b/src/test/java/eotree/TestEOBndExpr.java @@ -11,8 +11,8 @@ public class TestEOBndExpr { @Test public void TestGenerateEOZeroIndent() { var f = new EOBndExpr( - new EODot(Optional.empty(), "memory"), - new EOBndName("bnd1") + new EODot("memory"), + "bnd1" ); assertEquals("memory > bnd1", f.generateEO(0)); } @@ -20,8 +20,8 @@ public void TestGenerateEOZeroIndent() { @Test public void TestGenerateEONonZeroIndent() { var f = new EOBndExpr( - new EODot(Optional.empty(), "memory"), - new EOBndName("bnd1") + new EODot("memory"), + "bnd1" ); assertEquals(" memory > bnd1", f.generateEO(1)); } diff --git a/src/test/java/eotree/TestEOBndName.java b/src/test/java/eotree/TestEOBndName.java deleted file mode 100644 index 9d640cc2..00000000 --- a/src/test/java/eotree/TestEOBndName.java +++ /dev/null @@ -1,21 +0,0 @@ -package eotree; - -import eotree.data.EOIntData; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class TestEOBndName { - - @Test - public void TestGenerateEOZeroIndent() { - var f = new EOBndName("name"); - assertEquals(f.generateEO(0), "name"); - } - - @Test - public void TestGenerateEONonZeroIndent() { - var f = new EOBndName("name"); - assertEquals(f.generateEO(1), "name"); - } -} diff --git a/src/test/java/eotree/TestEOCopy.java b/src/test/java/eotree/TestEOCopy.java index 251ce645..3e71e4f4 100644 --- a/src/test/java/eotree/TestEOCopy.java +++ b/src/test/java/eotree/TestEOCopy.java @@ -12,22 +12,24 @@ public class TestEOCopy { @Test public void TestGenerateEOZeroIndent() { var f = new EOCopy( - new EODot(Optional.empty(), "name"), + new EODot("name"), listOf( - new EOAnonExpr( - new EODot(Optional.empty(), "arg1") - ), - new EOAnonExpr( - new EODot(Optional.empty(), "arg2") + new EODot("arg1"), + new EODot("arg2") ) - ) ); assertEquals("name\n arg1\n arg2", f.generateEO(0)); } @Test public void TestGenerateEONonZeroIndent() { - var f = new EOBndName("name"); - assertEquals(f.generateEO(1), "name"); + var f = new EOCopy( + new EODot("name"), + listOf( + new EODot("arg1"), + new EODot("arg2") + ) + ); + assertEquals(" name\n arg1\n arg2", f.generateEO(1)); } } diff --git a/src/test/java/eotree/TestEOMetas.java b/src/test/java/eotree/TestEOMetas.java index e290abaf..e8b47782 100644 --- a/src/test/java/eotree/TestEOMetas.java +++ b/src/test/java/eotree/TestEOMetas.java @@ -1,5 +1,6 @@ package eotree; +import arrow.core.Some; import org.junit.jupiter.api.Test; import java.util.Optional; @@ -12,7 +13,7 @@ public class TestEOMetas { @Test public void TestGenerateEOZeroIndent() { var f = new EOMetas( - Optional.of("org.eolang.package"), + new Some<>("org.eolang.package"), listOf( new EOMeta("key1", "value1"), new EOMeta("key2", "value2") @@ -28,7 +29,7 @@ public void TestGenerateEOZeroIndent() { @Test public void TestGenerateEONonZeroIndent() { var f = new EOMetas( - Optional.of("org.eolang.package"), + new Some<>("org.eolang.package"), listOf( new EOMeta("key1", "value1"), new EOMeta("key2", "value2") diff --git a/src/test/java/eotree/TestEOObject.java b/src/test/java/eotree/TestEOObject.java index 5e440b18..2b7c5e34 100644 --- a/src/test/java/eotree/TestEOObject.java +++ b/src/test/java/eotree/TestEOObject.java @@ -1,5 +1,6 @@ package eotree; +import arrow.core.Some; import org.junit.jupiter.api.Test; import java.util.Optional; @@ -13,22 +14,21 @@ public class TestEOObject { public void TestGenerateEOZeroIndent() { var object = new EOObject( listOf( - new EOBndName("free1"), - new EOBndName("free2") - ), - Optional.of( - new EOBndName("vararg") + "free1", + "free2" ), + new Some<>("vararg"), listOf( new EOBndExpr( - new EODot(Optional.empty(), "memory"), - new EOBndName("bnd1") + new EODot("memory"), + "bnd1" ), new EOBndExpr( - new EODot(Optional.empty(), "memory"), - new EOBndName("bnd2") + new EODot("memory"), + "bnd2" ) - ) + ), + "" ); assertEquals( """ @@ -42,23 +42,19 @@ public void TestGenerateEOZeroIndent() { @Test public void TestGenerateEONonZeroIndent() { var object = new EOObject( - listOf( - new EOBndName("free1"), - new EOBndName("free2") - ), - Optional.of( - new EOBndName("vararg") - ), + listOf("free1", "free2"), + new Some<>("vararg"), listOf( new EOBndExpr( - new EODot(Optional.empty(), "memory"), - new EOBndName("bnd1") + new EODot("memory"), + "bnd1" ), new EOBndExpr( - new EODot(Optional.empty(), "memory"), - new EOBndName("bnd2") + new EODot("memory"), + "bnd2" ) - ) + ), + "" ); //noinspection TextBlockMigration assertEquals( diff --git a/src/test/resources/codebase/View.java b/src/test/resources/codebase/View.java new file mode 100644 index 00000000..e970a110 --- /dev/null +++ b/src/test/resources/codebase/View.java @@ -0,0 +1,13975 @@ +/* + * Copyright (C) 2006 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 android.view; +import android.content.ClipData; +import android.content.Context; +import android.content.res.Configuration; +import android.content.res.Resources; +import android.content.res.TypedArray; +import android.graphics.Bitmap; +import android.graphics.Camera; +import android.graphics.Canvas; +import android.graphics.Interpolator; +import android.graphics.LinearGradient; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.graphics.PixelFormat; +import android.graphics.Point; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffXfermode; +import android.graphics.Rect; +import android.graphics.RectF; +import android.graphics.Region; +import android.graphics.Shader; +import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; +import android.os.Handler; +import android.os.IBinder; +import android.os.Message; +import android.os.Parcel; +import android.os.Parcelable; +import android.os.RemoteException; +import android.os.SystemClock; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.util.FloatProperty; +import android.util.LocaleUtil; +import android.util.Log; +import android.util.Pool; +import android.util.Poolable; +import android.util.PoolableManager; +import android.util.Pools; +import android.util.Property; +import android.util.SparseArray; +import android.util.TypedValue; +import android.view.ContextMenu.ContextMenuInfo; +import android.view.accessibility.AccessibilityEvent; +import android.view.accessibility.AccessibilityEventSource; +import android.view.accessibility.AccessibilityManager; +import android.view.accessibility.AccessibilityNodeInfo; +import android.view.accessibility.AccessibilityNodeProvider; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; +import android.view.animation.Transformation; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputConnection; +import android.view.inputmethod.InputMethodManager; +import android.widget.ScrollBarDrawable; +import static android.os.Build.VERSION_CODES.*; +import com.android.internal.R; +import com.android.internal.util.Predicate; +import com.android.internal.view.menu.MenuBuilder; +import java.lang.ref.WeakReference; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Locale; +import java.util.concurrent.CopyOnWriteArrayList; +/** + *

+ * This class represents the basic building block for user interface components. A View + * occupies a rectangular area on the screen and is responsible for drawing and + * event handling. View is the base class for widgets, which are + * used to create interactive UI components (buttons, text fields, etc.). The + * {@link android.view.ViewGroup} subclass is the base class for layouts, which + * are invisible containers that hold other Views (or other ViewGroups) and define + * their layout properties. + *

+ * + *
+ *

Developer Guides

+ *

For information about using this class to develop your application's user interface, + * read the User Interface developer guide. + *

+ * + * + *

Using Views

+ *

+ * All of the views in a window are arranged in a single tree. You can add views + * either from code or by specifying a tree of views in one or more XML layout + * files. There are many specialized subclasses of views that act as controls or + * are capable of displaying text, images, or other content. + *

+ *

+ * Once you have created a tree of views, there are typically a few types of + * common operations you may wish to perform: + *

    + *
  • Set properties: for example setting the text of a + * {@link android.widget.TextView}. The available properties and the methods + * that set them will vary among the different subclasses of views. Note that + * properties that are known at build time can be set in the XML layout + * files.
  • + *
  • Set focus: The framework will handled moving focus in + * response to user input. To force focus to a specific view, call + * {@link #requestFocus}.
  • + *
  • Set up listeners: Views allow clients to set listeners + * that will be notified when something interesting happens to the view. For + * example, all views will let you set a listener to be notified when the view + * gains or loses focus. You can register such a listener using + * {@link #setOnFocusChangeListener(android.view.View.OnFocusChangeListener)}. + * Other view subclasses offer more specialized listeners. For example, a Button + * exposes a listener to notify clients when the button is clicked.
  • + *
  • Set visibility: You can hide or show views using + * {@link #setVisibility(int)}.
  • + *
+ *

+ *

+ * Note: The Android framework is responsible for measuring, laying out and + * drawing views. You should not call methods that perform these actions on + * views yourself unless you are actually implementing a + * {@link android.view.ViewGroup}. + *

+ * + * + *

Implementing a Custom View

+ * + *

+ * To implement a custom view, you will usually begin by providing overrides for + * some of the standard methods that the framework calls on all views. You do + * not need to override all of these methods. In fact, you can start by just + * overriding {@link #onDraw(android.graphics.Canvas)}. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Category Methods Description
CreationConstructorsThere is a form of the constructor that are called when the view + * is created from code and a form that is called when the view is + * inflated from a layout file. The second form should parse and apply + * any attributes defined in the layout file. + *
{@link #onFinishInflate()}Called after a view and all of its children has been inflated + * from XML.
Layout{@link #onMeasure(int, int)}Called to determine the size requirements for this view and all + * of its children. + *
{@link #onLayout(boolean, int, int, int, int)}Called when this view should assign a size and position to all + * of its children. + *
{@link #onSizeChanged(int, int, int, int)}Called when the size of this view has changed. + *
Drawing{@link #onDraw(android.graphics.Canvas)}Called when the view should render its content. + *
Event processing{@link #onKeyDown(int, KeyEvent)}Called when a new key event occurs. + *
{@link #onKeyUp(int, KeyEvent)}Called when a key up event occurs. + *
{@link #onTrackballEvent(MotionEvent)}Called when a trackball motion event occurs. + *
{@link #onTouchEvent(MotionEvent)}Called when a touch screen motion event occurs. + *
Focus{@link #onFocusChanged(boolean, int, android.graphics.Rect)}Called when the view gains or loses focus. + *
{@link #onWindowFocusChanged(boolean)}Called when the window containing the view gains or loses focus. + *
Attaching{@link #onAttachedToWindow()}Called when the view is attached to a window. + *
{@link #onDetachedFromWindow}Called when the view is detached from its window. + *
{@link #onWindowVisibilityChanged(int)}Called when the visibility of the window containing the view + * has changed. + *
+ *

+ * + * + *

IDs

+ * Views may have an integer id associated with them. These ids are typically + * assigned in the layout XML files, and are used to find specific views within + * the view tree. A common pattern is to: + *
    + *
  • Define a Button in the layout file and assign it a unique ID. + *
    + * <Button
    + *     android:id="@+id/my_button"
    + *     android:layout_width="wrap_content"
    + *     android:layout_height="wrap_content"
    + *     android:text="@string/my_button_text"/>
    + * 
  • + *
  • From the onCreate method of an Activity, find the Button + *
    + *      Button myButton = (Button) findViewById(R.id.my_button);
    + * 
  • + *
+ *

+ * View IDs need not be unique throughout the tree, but it is good practice to + * ensure that they are at least unique within the part of the tree you are + * searching. + *

+ * + * + *

Position

+ *

+ * The geometry of a view is that of a rectangle. A view has a location, + * expressed as a pair of left and top coordinates, and + * two dimensions, expressed as a width and a height. The unit for location + * and dimensions is the pixel. + *

+ * + *

+ * It is possible to retrieve the location of a view by invoking the methods + * {@link #getLeft()} and {@link #getTop()}. The former returns the left, or X, + * coordinate of the rectangle representing the view. The latter returns the + * top, or Y, coordinate of the rectangle representing the view. These methods + * both return the location of the view relative to its parent. For instance, + * when getLeft() returns 20, that means the view is located 20 pixels to the + * right of the left edge of its direct parent. + *

+ * + *

+ * In addition, several convenience methods are offered to avoid unnecessary + * computations, namely {@link #getRight()} and {@link #getBottom()}. + * These methods return the coordinates of the right and bottom edges of the + * rectangle representing the view. For instance, calling {@link #getRight()} + * is similar to the following computation: getLeft() + getWidth() + * (see Size for more information about the width.) + *

+ * + * + *

Size, padding and margins

+ *

+ * The size of a view is expressed with a width and a height. A view actually + * possess two pairs of width and height values. + *

+ * + *

+ * The first pair is known as measured width and + * measured height. These dimensions define how big a view wants to be + * within its parent (see Layout for more details.) The + * measured dimensions can be obtained by calling {@link #getMeasuredWidth()} + * and {@link #getMeasuredHeight()}. + *

+ * + *

+ * The second pair is simply known as width and height, or + * sometimes drawing width and drawing height. These + * dimensions define the actual size of the view on screen, at drawing time and + * after layout. These values may, but do not have to, be different from the + * measured width and height. The width and height can be obtained by calling + * {@link #getWidth()} and {@link #getHeight()}. + *

+ * + *

+ * To measure its dimensions, a view takes into account its padding. The padding + * is expressed in pixels for the left, top, right and bottom parts of the view. + * Padding can be used to offset the content of the view by a specific amount of + * pixels. For instance, a left padding of 2 will push the view's content by + * 2 pixels to the right of the left edge. Padding can be set using the + * {@link #setPadding(int, int, int, int)} method and queried by calling + * {@link #getPaddingLeft()}, {@link #getPaddingTop()}, + * {@link #getPaddingRight()}, {@link #getPaddingBottom()}. + *

+ * + *

+ * Even though a view can define a padding, it does not provide any support for + * margins. However, view groups provide such a support. Refer to + * {@link android.view.ViewGroup} and + * {@link android.view.ViewGroup.MarginLayoutParams} for further information. + *

+ * + * + *

Layout

+ *

+ * Layout is a two pass process: a measure pass and a layout pass. The measuring + * pass is implemented in {@link #measure(int, int)} and is a top-down traversal + * of the view tree. Each view pushes dimension specifications down the tree + * during the recursion. At the end of the measure pass, every view has stored + * its measurements. The second pass happens in + * {@link #layout(int,int,int,int)} and is also top-down. During + * this pass each parent is responsible for positioning all of its children + * using the sizes computed in the measure pass. + *

+ * + *

+ * When a view's measure() method returns, its {@link #getMeasuredWidth()} and + * {@link #getMeasuredHeight()} values must be set, along with those for all of + * that view's descendants. A view's measured width and measured height values + * must respect the constraints imposed by the view's parents. This guarantees + * that at the end of the measure pass, all parents accept all of their + * children's measurements. A parent view may call measure() more than once on + * its children. For example, the parent may measure each child once with + * unspecified dimensions to find out how big they want to be, then call + * measure() on them again with actual numbers if the sum of all the children's + * unconstrained sizes is too big or too small. + *

+ * + *

+ * The measure pass uses two classes to communicate dimensions. The + * {@link MeasureSpec} class is used by views to tell their parents how they + * want to be measured and positioned. The base LayoutParams class just + * describes how big the view wants to be for both width and height. For each + * dimension, it can specify one of: + *

    + *
  • an exact number + *
  • MATCH_PARENT, which means the view wants to be as big as its parent + * (minus padding) + *
  • WRAP_CONTENT, which means that the view wants to be just big enough to + * enclose its content (plus padding). + *
+ * There are subclasses of LayoutParams for different subclasses of ViewGroup. + * For example, AbsoluteLayout has its own subclass of LayoutParams which adds + * an X and Y value. + *

+ * + *

+ * MeasureSpecs are used to push requirements down the tree from parent to + * child. A MeasureSpec can be in one of three modes: + *

    + *
  • UNSPECIFIED: This is used by a parent to determine the desired dimension + * of a child view. For example, a LinearLayout may call measure() on its child + * with the height set to UNSPECIFIED and a width of EXACTLY 240 to find out how + * tall the child view wants to be given a width of 240 pixels. + *
  • EXACTLY: This is used by the parent to impose an exact size on the + * child. The child must use this size, and guarantee that all of its + * descendants will fit within this size. + *
  • AT_MOST: This is used by the parent to impose a maximum size on the + * child. The child must gurantee that it and all of its descendants will fit + * within this size. + *
+ *

+ * + *

+ * To intiate a layout, call {@link #requestLayout}. This method is typically + * called by a view on itself when it believes that is can no longer fit within + * its current bounds. + *

+ * + * + *

Drawing

+ *

+ * Drawing is handled by walking the tree and rendering each view that + * intersects the invalid region. Because the tree is traversed in-order, + * this means that parents will draw before (i.e., behind) their children, with + * siblings drawn in the order they appear in the tree. + * If you set a background drawable for a View, then the View will draw it for you + * before calling back to its onDraw() method. + *

+ * + *

+ * Note that the framework will not draw views that are not in the invalid region. + *

+ * + *

+ * To force a view to draw, call {@link #invalidate()}. + *

+ * + * + *

Event Handling and Threading

+ *

+ * The basic cycle of a view is as follows: + *

    + *
  1. An event comes in and is dispatched to the appropriate view. The view + * handles the event and notifies any listeners.
  2. + *
  3. If in the course of processing the event, the view's bounds may need + * to be changed, the view will call {@link #requestLayout()}.
  4. + *
  5. Similarly, if in the course of processing the event the view's appearance + * may need to be changed, the view will call {@link #invalidate()}.
  6. + *
  7. If either {@link #requestLayout()} or {@link #invalidate()} were called, + * the framework will take care of measuring, laying out, and drawing the tree + * as appropriate.
  8. + *
+ *

+ * + *

Note: The entire view tree is single threaded. You must always be on + * the UI thread when calling any method on any view. + * If you are doing work on other threads and want to update the state of a view + * from that thread, you should use a {@link Handler}. + *

+ * + * + *

Focus Handling

+ *

+ * The framework will handle routine focus movement in response to user input. + * This includes changing the focus as views are removed or hidden, or as new + * views become available. Views indicate their willingness to take focus + * through the {@link #isFocusable} method. To change whether a view can take + * focus, call {@link #setFocusable(boolean)}. When in touch mode (see notes below) + * views indicate whether they still would like focus via {@link #isFocusableInTouchMode} + * and can change this via {@link #setFocusableInTouchMode(boolean)}. + *

+ *

+ * Focus movement is based on an algorithm which finds the nearest neighbor in a + * given direction. In rare cases, the default algorithm may not match the + * intended behavior of the developer. In these situations, you can provide + * explicit overrides by using these XML attributes in the layout file: + *

+ * nextFocusDown
+ * nextFocusLeft
+ * nextFocusRight
+ * nextFocusUp
+ * 
+ *

+ * + * + *

+ * To get a particular view to take focus, call {@link #requestFocus()}. + *

+ * + * + *

Touch Mode

+ *

+ * When a user is navigating a user interface via directional keys such as a D-pad, it is + * necessary to give focus to actionable items such as buttons so the user can see + * what will take input. If the device has touch capabilities, however, and the user + * begins interacting with the interface by touching it, it is no longer necessary to + * always highlight, or give focus to, a particular view. This motivates a mode + * for interaction named 'touch mode'. + *

+ *

+ * For a touch capable device, once the user touches the screen, the device + * will enter touch mode. From this point onward, only views for which + * {@link #isFocusableInTouchMode} is true will be focusable, such as text editing widgets. + * Other views that are touchable, like buttons, will not take focus when touched; they will + * only fire the on click listeners. + *

+ *

+ * Any time a user hits a directional key, such as a D-pad direction, the view device will + * exit touch mode, and find a view to take focus, so that the user may resume interacting + * with the user interface without touching the screen again. + *

+ *

+ * The touch mode state is maintained across {@link android.app.Activity}s. Call + * {@link #isInTouchMode} to see whether the device is currently in touch mode. + *

+ * + * + *

Scrolling

+ *

+ * The framework provides basic support for views that wish to internally + * scroll their content. This includes keeping track of the X and Y scroll + * offset as well as mechanisms for drawing scrollbars. See + * {@link #scrollBy(int, int)}, {@link #scrollTo(int, int)}, and + * {@link #awakenScrollBars()} for more details. + *

+ * + * + *

Tags

+ *

+ * Unlike IDs, tags are not used to identify views. Tags are essentially an + * extra piece of information that can be associated with a view. They are most + * often used as a convenience to store data related to views in the views + * themselves rather than by putting them in a separate structure. + *

+ * + * + *

Animation

+ *

+ * You can attach an {@link Animation} object to a view using + * {@link #setAnimation(Animation)} or + * {@link #startAnimation(Animation)}. The animation can alter the scale, + * rotation, translation and alpha of a view over time. If the animation is + * attached to a view that has children, the animation will affect the entire + * subtree rooted by that node. When an animation is started, the framework will + * take care of redrawing the appropriate views until the animation completes. + *

+ *

+ * Starting with Android 3.0, the preferred way of animating views is to use the + * {@link android.animation} package APIs. + *

+ * + * + *

Security

+ *

+ * Sometimes it is essential that an application be able to verify that an action + * is being performed with the full knowledge and consent of the user, such as + * granting a permission request, making a purchase or clicking on an advertisement. + * Unfortunately, a malicious application could try to spoof the user into + * performing these actions, unaware, by concealing the intended purpose of the view. + * As a remedy, the framework offers a touch filtering mechanism that can be used to + * improve the security of views that provide access to sensitive functionality. + *

+ * To enable touch filtering, call {@link #setFilterTouchesWhenObscured(boolean)} or set the + * android:filterTouchesWhenObscured layout attribute to true. When enabled, the framework + * will discard touches that are received whenever the view's window is obscured by + * another visible window. As a result, the view will not receive touches whenever a + * toast, dialog or other window appears above the view's window. + *

+ * For more fine-grained control over security, consider overriding the + * {@link #onFilterTouchEventForSecurity(MotionEvent)} method to implement your own + * security policy. See also {@link MotionEvent#FLAG_WINDOW_IS_OBSCURED}. + *

+ * + * @attr ref android.R.styleable#View_alpha + * @attr ref android.R.styleable#View_background + * @attr ref android.R.styleable#View_clickable + * @attr ref android.R.styleable#View_contentDescription + * @attr ref android.R.styleable#View_drawingCacheQuality + * @attr ref android.R.styleable#View_duplicateParentState + * @attr ref android.R.styleable#View_id + * @attr ref android.R.styleable#View_requiresFadingEdge + * @attr ref android.R.styleable#View_fadingEdgeLength + * @attr ref android.R.styleable#View_filterTouchesWhenObscured + * @attr ref android.R.styleable#View_fitsSystemWindows + * @attr ref android.R.styleable#View_isScrollContainer + * @attr ref android.R.styleable#View_focusable + * @attr ref android.R.styleable#View_focusableInTouchMode + * @attr ref android.R.styleable#View_hapticFeedbackEnabled + * @attr ref android.R.styleable#View_keepScreenOn + * @attr ref android.R.styleable#View_layerType + * @attr ref android.R.styleable#View_longClickable + * @attr ref android.R.styleable#View_minHeight + * @attr ref android.R.styleable#View_minWidth + * @attr ref android.R.styleable#View_nextFocusDown + * @attr ref android.R.styleable#View_nextFocusLeft + * @attr ref android.R.styleable#View_nextFocusRight + * @attr ref android.R.styleable#View_nextFocusUp + * @attr ref android.R.styleable#View_onClick + * @attr ref android.R.styleable#View_padding + * @attr ref android.R.styleable#View_paddingBottom + * @attr ref android.R.styleable#View_paddingLeft + * @attr ref android.R.styleable#View_paddingRight + * @attr ref android.R.styleable#View_paddingTop + * @attr ref android.R.styleable#View_saveEnabled + * @attr ref android.R.styleable#View_rotation + * @attr ref android.R.styleable#View_rotationX + * @attr ref android.R.styleable#View_rotationY + * @attr ref android.R.styleable#View_scaleX + * @attr ref android.R.styleable#View_scaleY + * @attr ref android.R.styleable#View_scrollX + * @attr ref android.R.styleable#View_scrollY + * @attr ref android.R.styleable#View_scrollbarSize + * @attr ref android.R.styleable#View_scrollbarStyle + * @attr ref android.R.styleable#View_scrollbars + * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade + * @attr ref android.R.styleable#View_scrollbarFadeDuration + * @attr ref android.R.styleable#View_scrollbarTrackHorizontal + * @attr ref android.R.styleable#View_scrollbarThumbHorizontal + * @attr ref android.R.styleable#View_scrollbarThumbVertical + * @attr ref android.R.styleable#View_scrollbarTrackVertical + * @attr ref android.R.styleable#View_scrollbarAlwaysDrawHorizontalTrack + * @attr ref android.R.styleable#View_scrollbarAlwaysDrawVerticalTrack + * @attr ref android.R.styleable#View_soundEffectsEnabled + * @attr ref android.R.styleable#View_tag + * @attr ref android.R.styleable#View_transformPivotX + * @attr ref android.R.styleable#View_transformPivotY + * @attr ref android.R.styleable#View_translationX + * @attr ref android.R.styleable#View_translationY + * @attr ref android.R.styleable#View_visibility + * + * @see android.view.ViewGroup + */ +public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Callback, + AccessibilityEventSource { + private static final boolean DBG = false; + /** + * The logging tag used by this class with android.util.Log. + */ + protected static final String VIEW_LOG_TAG = "View"; + /** + * Used to mark a View that has no ID. + */ + public static final int NO_ID = -1; + /** + * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when + * calling setFlags. + */ + private static final int NOT_FOCUSABLE = 0x00000000; + /** + * This view wants keystrokes. Use with TAKES_FOCUS_MASK when calling + * setFlags. + */ + private static final int FOCUSABLE = 0x00000001; + /** + * Mask for use with setFlags indicating bits used for focus. + */ + private static final int FOCUSABLE_MASK = 0x00000001; + /** + * This view will adjust its padding to fit sytem windows (e.g. status bar) + */ + private static final int FITS_SYSTEM_WINDOWS = 0x00000002; + /** + * This view is visible. + * Use with {@link #setVisibility} and {@code + * android:visibility}. + */ + public static final int VISIBLE = 0x00000000; + /** + * This view is invisible, but it still takes up space for layout purposes. + * Use with {@link #setVisibility} and {@code + * android:visibility}. + */ + public static final int INVISIBLE = 0x00000004; + /** + * This view is invisible, and it doesn't take any space for layout + * purposes. Use with {@link #setVisibility} and {@code + * android:visibility}. + */ + public static final int GONE = 0x00000008; + /** + * Mask for use with setFlags indicating bits used for visibility. + * {@hide} + */ + static final int VISIBILITY_MASK = 0x0000000C; + private static final int[] VISIBILITY_FLAGS = {VISIBLE, INVISIBLE, GONE}; + /** + * This view is enabled. Intrepretation varies by subclass. + * Use with ENABLED_MASK when calling setFlags. + * {@hide} + */ + static final int ENABLED = 0x00000000; + /** + * This view is disabled. Intrepretation varies by subclass. + * Use with ENABLED_MASK when calling setFlags. + * {@hide} + */ + static final int DISABLED = 0x00000020; + /** + * Mask for use with setFlags indicating bits used for indicating whether + * this view is enabled + * {@hide} + */ + static final int ENABLED_MASK = 0x00000020; + /** + * This view won't draw. {@link #onDraw(android.graphics.Canvas)} won't be + * called and further optimizations will be performed. It is okay to have + * this flag set and a background. Use with DRAW_MASK when calling setFlags. + * {@hide} + */ + static final int WILL_NOT_DRAW = 0x00000080; + /** + * Mask for use with setFlags indicating bits used for indicating whether + * this view is will draw + * {@hide} + */ + static final int DRAW_MASK = 0x00000080; + /** + *

This view doesn't show scrollbars.

+ * {@hide} + */ + static final int SCROLLBARS_NONE = 0x00000000; + /** + *

This view shows horizontal scrollbars.

+ * {@hide} + */ + static final int SCROLLBARS_HORIZONTAL = 0x00000100; + /** + *

This view shows vertical scrollbars.

+ * {@hide} + */ + static final int SCROLLBARS_VERTICAL = 0x00000200; + /** + *

Mask for use with setFlags indicating bits used for indicating which + * scrollbars are enabled.

+ * {@hide} + */ + static final int SCROLLBARS_MASK = 0x00000300; + /** + * Indicates that the view should filter touches when its window is obscured. + * Refer to the class comments for more information about this security feature. + * {@hide} + */ + static final int FILTER_TOUCHES_WHEN_OBSCURED = 0x00000400; + // note flag value 0x00000800 is now available for next flags... + /** + *

This view doesn't show fading edges.

+ * {@hide} + */ + static final int FADING_EDGE_NONE = 0x00000000; + /** + *

This view shows horizontal fading edges.

+ * {@hide} + */ + static final int FADING_EDGE_HORIZONTAL = 0x00001000; + /** + *

This view shows vertical fading edges.

+ * {@hide} + */ + static final int FADING_EDGE_VERTICAL = 0x00002000; + /** + *

Mask for use with setFlags indicating bits used for indicating which + * fading edges are enabled.

+ * {@hide} + */ + static final int FADING_EDGE_MASK = 0x00003000; + /** + *

Indicates this view can be clicked. When clickable, a View reacts + * to clicks by notifying the OnClickListener.

+ * {@hide} + */ + static final int CLICKABLE = 0x00004000; + /** + *

Indicates this view is caching its drawing into a bitmap.

+ * {@hide} + */ + static final int DRAWING_CACHE_ENABLED = 0x00008000; + /** + *

Indicates that no icicle should be saved for this view.

+ * {@hide} + */ + static final int SAVE_DISABLED = 0x000010000; + /** + *

Mask for use with setFlags indicating bits used for the saveEnabled + * property.

+ * {@hide} + */ + static final int SAVE_DISABLED_MASK = 0x000010000; + /** + *

Indicates that no drawing cache should ever be created for this view.

+ * {@hide} + */ + static final int WILL_NOT_CACHE_DRAWING = 0x000020000; + /** + *

Indicates this view can take / keep focus when int touch mode.

+ * {@hide} + */ + static final int FOCUSABLE_IN_TOUCH_MODE = 0x00040000; + /** + *

Enables low quality mode for the drawing cache.

+ */ + public static final int DRAWING_CACHE_QUALITY_LOW = 0x00080000; + /** + *

Enables high quality mode for the drawing cache.

+ */ + public static final int DRAWING_CACHE_QUALITY_HIGH = 0x00100000; + /** + *

Enables automatic quality mode for the drawing cache.

+ */ + public static final int DRAWING_CACHE_QUALITY_AUTO = 0x00000000; + private static final int[] DRAWING_CACHE_QUALITY_FLAGS = { + DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_LOW, DRAWING_CACHE_QUALITY_HIGH + }; + /** + *

Mask for use with setFlags indicating bits used for the cache + * quality property.

+ * {@hide} + */ + static final int DRAWING_CACHE_QUALITY_MASK = 0x00180000; + /** + *

+ * Indicates this view can be long clicked. When long clickable, a View + * reacts to long clicks by notifying the OnLongClickListener or showing a + * context menu. + *

+ * {@hide} + */ + static final int LONG_CLICKABLE = 0x00200000; + /** + *

Indicates that this view gets its drawable states from its direct parent + * and ignores its original internal states.

+ * + * @hide + */ + static final int DUPLICATE_PARENT_STATE = 0x00400000; + /** + * The scrollbar style to display the scrollbars inside the content area, + * without increasing the padding. The scrollbars will be overlaid with + * translucency on the view's content. + */ + public static final int SCROLLBARS_INSIDE_OVERLAY = 0; + /** + * The scrollbar style to display the scrollbars inside the padded area, + * increasing the padding of the view. The scrollbars will not overlap the + * content area of the view. + */ + public static final int SCROLLBARS_INSIDE_INSET = 0x01000000; + /** + * The scrollbar style to display the scrollbars at the edge of the view, + * without increasing the padding. The scrollbars will be overlaid with + * translucency. + */ + public static final int SCROLLBARS_OUTSIDE_OVERLAY = 0x02000000; + /** + * The scrollbar style to display the scrollbars at the edge of the view, + * increasing the padding of the view. The scrollbars will only overlap the + * background, if any. + */ + public static final int SCROLLBARS_OUTSIDE_INSET = 0x03000000; + /** + * Mask to check if the scrollbar style is overlay or inset. + * {@hide} + */ + static final int SCROLLBARS_INSET_MASK = 0x01000000; + /** + * Mask to check if the scrollbar style is inside or outside. + * {@hide} + */ + static final int SCROLLBARS_OUTSIDE_MASK = 0x02000000; + /** + * Mask for scrollbar style. + * {@hide} + */ + static final int SCROLLBARS_STYLE_MASK = 0x03000000; + /** + * View flag indicating that the screen should remain on while the + * window containing this view is visible to the user. This effectively + * takes care of automatically setting the WindowManager's + * {@link WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON}. + */ + public static final int KEEP_SCREEN_ON = 0x04000000; + /** + * View flag indicating whether this view should have sound effects enabled + * for events such as clicking and touching. + */ + public static final int SOUND_EFFECTS_ENABLED = 0x08000000; + /** + * View flag indicating whether this view should have haptic feedback + * enabled for events such as long presses. + */ + public static final int HAPTIC_FEEDBACK_ENABLED = 0x10000000; + /** + *

Indicates that the view hierarchy should stop saving state when + * it reaches this view. If state saving is initiated immediately at + * the view, it will be allowed. + * {@hide} + */ + static final int PARENT_SAVE_DISABLED = 0x20000000; + /** + *

Mask for use with setFlags indicating bits used for PARENT_SAVE_DISABLED.

+ * {@hide} + */ + static final int PARENT_SAVE_DISABLED_MASK = 0x20000000; + /** + * Horizontal direction of this view is from Left to Right. + * Use with {@link #setLayoutDirection}. + * {@hide} + */ + public static final int LAYOUT_DIRECTION_LTR = 0x00000000; + /** + * Horizontal direction of this view is from Right to Left. + * Use with {@link #setLayoutDirection}. + * {@hide} + */ + public static final int LAYOUT_DIRECTION_RTL = 0x40000000; + /** + * Horizontal direction of this view is inherited from its parent. + * Use with {@link #setLayoutDirection}. + * {@hide} + */ + public static final int LAYOUT_DIRECTION_INHERIT = 0x80000000; + /** + * Horizontal direction of this view is from deduced from the default language + * script for the locale. Use with {@link #setLayoutDirection}. + * {@hide} + */ + public static final int LAYOUT_DIRECTION_LOCALE = 0xC0000000; + /** + * Mask for use with setFlags indicating bits used for horizontalDirection. + * {@hide} + */ + static final int LAYOUT_DIRECTION_MASK = 0xC0000000; + /* + * Array of horizontal direction flags for mapping attribute "horizontalDirection" to correct + * flag value. + * {@hide} + */ + private static final int[] LAYOUT_DIRECTION_FLAGS = {LAYOUT_DIRECTION_LTR, + LAYOUT_DIRECTION_RTL, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE}; + /** + * Default horizontalDirection. + * {@hide} + */ + private static final int LAYOUT_DIRECTION_DEFAULT = LAYOUT_DIRECTION_INHERIT; + /** + * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} + * should add all focusable Views regardless if they are focusable in touch mode. + */ + public static final int FOCUSABLES_ALL = 0x00000000; + /** + * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} + * should add only Views focusable in touch mode. + */ + public static final int FOCUSABLES_TOUCH_MODE = 0x00000001; + /** + * Use with {@link #focusSearch(int)}. Move focus to the previous selectable + * item. + */ + public static final int FOCUS_BACKWARD = 0x00000001; + /** + * Use with {@link #focusSearch(int)}. Move focus to the next selectable + * item. + */ + public static final int FOCUS_FORWARD = 0x00000002; + /** + * Use with {@link #focusSearch(int)}. Move focus to the left. + */ + public static final int FOCUS_LEFT = 0x00000011; + /** + * Use with {@link #focusSearch(int)}. Move focus up. + */ + public static final int FOCUS_UP = 0x00000021; + /** + * Use with {@link #focusSearch(int)}. Move focus to the right. + */ + public static final int FOCUS_RIGHT = 0x00000042; + /** + * Use with {@link #focusSearch(int)}. Move focus down. + */ + public static final int FOCUS_DOWN = 0x00000082; + /** + * Bits of {@link #getMeasuredWidthAndState()} and + * {@link #getMeasuredWidthAndState()} that provide the actual measured size. + */ + public static final int MEASURED_SIZE_MASK = 0x00ffffff; + /** + * Bits of {@link #getMeasuredWidthAndState()} and + * {@link #getMeasuredWidthAndState()} that provide the additional state bits. + */ + public static final int MEASURED_STATE_MASK = 0xff000000; + /** + * Bit shift of {@link #MEASURED_STATE_MASK} to get to the height bits + * for functions that combine both width and height into a single int, + * such as {@link #getMeasuredState()} and the childState argument of + * {@link #resolveSizeAndState(int, int, int)}. + */ + public static final int MEASURED_HEIGHT_STATE_SHIFT = 16; + /** + * Bit of {@link #getMeasuredWidthAndState()} and + * {@link #getMeasuredWidthAndState()} that indicates the measured size + * is smaller that the space the view would like to have. + */ + public static final int MEASURED_STATE_TOO_SMALL = 0x01000000; + /** + * Base View state sets + */ + // Singles + /** + * Indicates the view has no states set. States are used with + * {@link android.graphics.drawable.Drawable} to change the drawing of the + * view depending on its state. + * + * @see android.graphics.drawable.Drawable + * @see #getDrawableState() + */ + protected static final int[] EMPTY_STATE_SET; + /** + * Indicates the view is enabled. States are used with + * {@link android.graphics.drawable.Drawable} to change the drawing of the + * view depending on its state. + * + * @see android.graphics.drawable.Drawable + * @see #getDrawableState() + */ + protected static final int[] ENABLED_STATE_SET; + /** + * Indicates the view is focused. States are used with + * {@link android.graphics.drawable.Drawable} to change the drawing of the + * view depending on its state. + * + * @see android.graphics.drawable.Drawable + * @see #getDrawableState() + */ + protected static final int[] FOCUSED_STATE_SET; + /** + * Indicates the view is selected. States are used with + * {@link android.graphics.drawable.Drawable} to change the drawing of the + * view depending on its state. + * + * @see android.graphics.drawable.Drawable + * @see #getDrawableState() + */ + protected static final int[] SELECTED_STATE_SET; + /** + * Indicates the view is pressed. States are used with + * {@link android.graphics.drawable.Drawable} to change the drawing of the + * view depending on its state. + * + * @see android.graphics.drawable.Drawable + * @see #getDrawableState() + * @hide + */ + protected static final int[] PRESSED_STATE_SET; + /** + * Indicates the view's window has focus. States are used with + * {@link android.graphics.drawable.Drawable} to change the drawing of the + * view depending on its state. + * + * @see android.graphics.drawable.Drawable + * @see #getDrawableState() + */ + protected static final int[] WINDOW_FOCUSED_STATE_SET; + // Doubles + /** + * Indicates the view is enabled and has the focus. + * + * @see #ENABLED_STATE_SET + * @see #FOCUSED_STATE_SET + */ + protected static final int[] ENABLED_FOCUSED_STATE_SET; + /** + * Indicates the view is enabled and selected. + * + * @see #ENABLED_STATE_SET + * @see #SELECTED_STATE_SET + */ + protected static final int[] ENABLED_SELECTED_STATE_SET; + /** + * Indicates the view is enabled and that its window has focus. + * + * @see #ENABLED_STATE_SET + * @see #WINDOW_FOCUSED_STATE_SET + */ + protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET; + /** + * Indicates the view is focused and selected. + * + * @see #FOCUSED_STATE_SET + * @see #SELECTED_STATE_SET + */ + protected static final int[] FOCUSED_SELECTED_STATE_SET; + /** + * Indicates the view has the focus and that its window has the focus. + * + * @see #FOCUSED_STATE_SET + * @see #WINDOW_FOCUSED_STATE_SET + */ + protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET; + /** + * Indicates the view is selected and that its window has the focus. + * + * @see #SELECTED_STATE_SET + * @see #WINDOW_FOCUSED_STATE_SET + */ + protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET; + // Triples + /** + * Indicates the view is enabled, focused and selected. + * + * @see #ENABLED_STATE_SET + * @see #FOCUSED_STATE_SET + * @see #SELECTED_STATE_SET + */ + protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET; + /** + * Indicates the view is enabled, focused and its window has the focus. + * + * @see #ENABLED_STATE_SET + * @see #FOCUSED_STATE_SET + * @see #WINDOW_FOCUSED_STATE_SET + */ + protected static final int[] ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET; + /** + * Indicates the view is enabled, selected and its window has the focus. + * + * @see #ENABLED_STATE_SET + * @see #SELECTED_STATE_SET + * @see #WINDOW_FOCUSED_STATE_SET + */ + protected static final int[] ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET; + /** + * Indicates the view is focused, selected and its window has the focus. + * + * @see #FOCUSED_STATE_SET + * @see #SELECTED_STATE_SET + * @see #WINDOW_FOCUSED_STATE_SET + */ + protected static final int[] FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; + /** + * Indicates the view is enabled, focused, selected and its window + * has the focus. + * + * @see #ENABLED_STATE_SET + * @see #FOCUSED_STATE_SET + * @see #SELECTED_STATE_SET + * @see #WINDOW_FOCUSED_STATE_SET + */ + protected static final int[] ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; + /** + * Indicates the view is pressed and its window has the focus. + * + * @see #PRESSED_STATE_SET + * @see #WINDOW_FOCUSED_STATE_SET + */ + protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET; + /** + * Indicates the view is pressed and selected. + * + * @see #PRESSED_STATE_SET + * @see #SELECTED_STATE_SET + */ + protected static final int[] PRESSED_SELECTED_STATE_SET; + /** + * Indicates the view is pressed, selected and its window has the focus. + * + * @see #PRESSED_STATE_SET + * @see #SELECTED_STATE_SET + * @see #WINDOW_FOCUSED_STATE_SET + */ + protected static final int[] PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET; + /** + * Indicates the view is pressed and focused. + * + * @see #PRESSED_STATE_SET + * @see #FOCUSED_STATE_SET + */ + protected static final int[] PRESSED_FOCUSED_STATE_SET; + /** + * Indicates the view is pressed, focused and its window has the focus. + * + * @see #PRESSED_STATE_SET + * @see #FOCUSED_STATE_SET + * @see #WINDOW_FOCUSED_STATE_SET + */ + protected static final int[] PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET; + /** + * Indicates the view is pressed, focused and selected. + * + * @see #PRESSED_STATE_SET + * @see #SELECTED_STATE_SET + * @see #FOCUSED_STATE_SET + */ + protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET; + /** + * Indicates the view is pressed, focused, selected and its window has the focus. + * + * @see #PRESSED_STATE_SET + * @see #FOCUSED_STATE_SET + * @see #SELECTED_STATE_SET + * @see #WINDOW_FOCUSED_STATE_SET + */ + protected static final int[] PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; + /** + * Indicates the view is pressed and enabled. + * + * @see #PRESSED_STATE_SET + * @see #ENABLED_STATE_SET + */ + protected static final int[] PRESSED_ENABLED_STATE_SET; + /** + * Indicates the view is pressed, enabled and its window has the focus. + * + * @see #PRESSED_STATE_SET + * @see #ENABLED_STATE_SET + * @see #WINDOW_FOCUSED_STATE_SET + */ + protected static final int[] PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET; + /** + * Indicates the view is pressed, enabled and selected. + * + * @see #PRESSED_STATE_SET + * @see #ENABLED_STATE_SET + * @see #SELECTED_STATE_SET + */ + protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET; + /** + * Indicates the view is pressed, enabled, selected and its window has the + * focus. + * + * @see #PRESSED_STATE_SET + * @see #ENABLED_STATE_SET + * @see #SELECTED_STATE_SET + * @see #WINDOW_FOCUSED_STATE_SET + */ + protected static final int[] PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET; + /** + * Indicates the view is pressed, enabled and focused. + * + * @see #PRESSED_STATE_SET + * @see #ENABLED_STATE_SET + * @see #FOCUSED_STATE_SET + */ + protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET; + /** + * Indicates the view is pressed, enabled, focused and its window has the + * focus. + * + * @see #PRESSED_STATE_SET + * @see #ENABLED_STATE_SET + * @see #FOCUSED_STATE_SET + * @see #WINDOW_FOCUSED_STATE_SET + */ + protected static final int[] PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET; + /** + * Indicates the view is pressed, enabled, focused and selected. + * + * @see #PRESSED_STATE_SET + * @see #ENABLED_STATE_SET + * @see #SELECTED_STATE_SET + * @see #FOCUSED_STATE_SET + */ + protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET; + /** + * Indicates the view is pressed, enabled, focused, selected and its window + * has the focus. + * + * @see #PRESSED_STATE_SET + * @see #ENABLED_STATE_SET + * @see #SELECTED_STATE_SET + * @see #FOCUSED_STATE_SET + * @see #WINDOW_FOCUSED_STATE_SET + */ + protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; + /** + * The order here is very important to {@link #getDrawableState()} + */ + private static final int[][] VIEW_STATE_SETS; + static final int VIEW_STATE_WINDOW_FOCUSED = 1; + static final int VIEW_STATE_SELECTED = 1 << 1; + static final int VIEW_STATE_FOCUSED = 1 << 2; + static final int VIEW_STATE_ENABLED = 1 << 3; + static final int VIEW_STATE_PRESSED = 1 << 4; + static final int VIEW_STATE_ACTIVATED = 1 << 5; + static final int VIEW_STATE_ACCELERATED = 1 << 6; + static final int VIEW_STATE_HOVERED = 1 << 7; + static final int VIEW_STATE_DRAG_CAN_ACCEPT = 1 << 8; + static final int VIEW_STATE_DRAG_HOVERED = 1 << 9; + static final int[] VIEW_STATE_IDS = new int[] { + R.attr.state_window_focused, VIEW_STATE_WINDOW_FOCUSED, + R.attr.state_selected, VIEW_STATE_SELECTED, + R.attr.state_focused, VIEW_STATE_FOCUSED, + R.attr.state_enabled, VIEW_STATE_ENABLED, + R.attr.state_pressed, VIEW_STATE_PRESSED, + R.attr.state_activated, VIEW_STATE_ACTIVATED, + R.attr.state_accelerated, VIEW_STATE_ACCELERATED, + R.attr.state_hovered, VIEW_STATE_HOVERED, + R.attr.state_drag_can_accept, VIEW_STATE_DRAG_CAN_ACCEPT, + R.attr.state_drag_hovered, VIEW_STATE_DRAG_HOVERED, + }; + static { + if ((VIEW_STATE_IDS.length/2) != R.styleable.ViewDrawableStates.length) { + throw new IllegalStateException( + "VIEW_STATE_IDs array length does not match ViewDrawableStates style array"); + } + int[] orderedIds = new int[VIEW_STATE_IDS.length]; + for (int i = 0; i < R.styleable.ViewDrawableStates.length; i++) { + int viewState = R.styleable.ViewDrawableStates[i]; + for (int j = 0; j sThreadLocal = new ThreadLocal(); + /** + * Map used to store views' tags. + */ + private SparseArray mKeyedTags; + /** + * The next available accessiiblity id. + */ + private static int sNextAccessibilityViewId; + /** + * The animation currently associated with this view. + * @hide + */ + protected Animation mCurrentAnimation = null; + /** + * Width as measured during measure pass. + * {@hide} + */ + @ViewDebug.ExportedProperty(category = "measurement") + int mMeasuredWidth; + /** + * Height as measured during measure pass. + * {@hide} + */ + @ViewDebug.ExportedProperty(category = "measurement") + int mMeasuredHeight; + /** + * Flag to indicate that this view was marked INVALIDATED, or had its display list + * invalidated, prior to the current drawing iteration. If true, the view must re-draw + * its display list. This flag, used only when hw accelerated, allows us to clear the + * flag while retaining this information until it's needed (at getDisplayList() time and + * in drawChild(), when we decide to draw a view's children's display lists into our own). + * + * {@hide} + */ + boolean mRecreateDisplayList = false; + /** + * The view's identifier. + * {@hide} + * + * @see #setId(int) + * @see #getId() + */ + @ViewDebug.ExportedProperty(resolveId = true) + int mID = NO_ID; + /** + * The stable ID of this view for accessibility purposes. + */ + int mAccessibilityViewId = NO_ID; + /** + * The view's tag. + * {@hide} + * + * @see #setTag(Object) + * @see #getTag() + */ + protected Object mTag; + // for mPrivateFlags: + /** {@hide} */ + static final int WANTS_FOCUS = 0x00000001; + /** {@hide} */ + static final int FOCUSED = 0x00000002; + /** {@hide} */ + static final int SELECTED = 0x00000004; + /** {@hide} */ + static final int IS_ROOT_NAMESPACE = 0x00000008; + /** {@hide} */ + static final int HAS_BOUNDS = 0x00000010; + /** {@hide} */ + static final int DRAWN = 0x00000020; + /** + * When this flag is set, this view is running an animation on behalf of its + * children and should therefore not cancel invalidate requests, even if they + * lie outside of this view's bounds. + * + * {@hide} + */ + static final int DRAW_ANIMATION = 0x00000040; + /** {@hide} */ + static final int SKIP_DRAW = 0x00000080; + /** {@hide} */ + static final int ONLY_DRAWS_BACKGROUND = 0x00000100; + /** {@hide} */ + static final int REQUEST_TRANSPARENT_REGIONS = 0x00000200; + /** {@hide} */ + static final int DRAWABLE_STATE_DIRTY = 0x00000400; + /** {@hide} */ + static final int MEASURED_DIMENSION_SET = 0x00000800; + /** {@hide} */ + static final int FORCE_LAYOUT = 0x00001000; + /** {@hide} */ + static final int LAYOUT_REQUIRED = 0x00002000; + private static final int PRESSED = 0x00004000; + /** {@hide} */ + static final int DRAWING_CACHE_VALID = 0x00008000; + /** + * Flag used to indicate that this view should be drawn once more (and only once + * more) after its animation has completed. + * {@hide} + */ + static final int ANIMATION_STARTED = 0x00010000; + private static final int SAVE_STATE_CALLED = 0x00020000; + /** + * Indicates that the View returned true when onSetAlpha() was called and that + * the alpha must be restored. + * {@hide} + */ + static final int ALPHA_SET = 0x00040000; + /** + * Set by {@link #setScrollContainer(boolean)}. + */ + static final int SCROLL_CONTAINER = 0x00080000; + /** + * Set by {@link #setScrollContainer(boolean)}. + */ + static final int SCROLL_CONTAINER_ADDED = 0x00100000; + /** + * View flag indicating whether this view was invalidated (fully or partially.) + * + * @hide + */ + static final int DIRTY = 0x00200000; + /** + * View flag indicating whether this view was invalidated by an opaque + * invalidate request. + * + * @hide + */ + static final int DIRTY_OPAQUE = 0x00400000; + /** + * Mask for {@link #DIRTY} and {@link #DIRTY_OPAQUE}. + * + * @hide + */ + static final int DIRTY_MASK = 0x00600000; + /** + * Indicates whether the background is opaque. + * + * @hide + */ + static final int OPAQUE_BACKGROUND = 0x00800000; + /** + * Indicates whether the scrollbars are opaque. + * + * @hide + */ + static final int OPAQUE_SCROLLBARS = 0x01000000; + /** + * Indicates whether the view is opaque. + * + * @hide + */ + static final int OPAQUE_MASK = 0x01800000; + /** + * Indicates a prepressed state; + * the short time between ACTION_DOWN and recognizing + * a 'real' press. Prepressed is used to recognize quick taps + * even when they are shorter than ViewConfiguration.getTapTimeout(). + * + * @hide + */ + private static final int PREPRESSED = 0x02000000; + /** + * Indicates whether the view is temporarily detached. + * + * @hide + */ + static final int CANCEL_NEXT_UP_EVENT = 0x04000000; + /** + * Indicates that we should awaken scroll bars once attached + * + * @hide + */ + private static final int AWAKEN_SCROLL_BARS_ON_ATTACH = 0x08000000; + /** + * Indicates that the view has received HOVER_ENTER. Cleared on HOVER_EXIT. + * @hide + */ + private static final int HOVERED = 0x10000000; + /** + * Indicates that pivotX or pivotY were explicitly set and we should not assume the center + * for transform operations + * + * @hide + */ + private static final int PIVOT_EXPLICITLY_SET = 0x20000000; + /** {@hide} */ + static final int ACTIVATED = 0x40000000; + /** + * Indicates that this view was specifically invalidated, not just dirtied because some + * child view was invalidated. The flag is used to determine when we need to recreate + * a view's display list (as opposed to just returning a reference to its existing + * display list). + * + * @hide + */ + static final int INVALIDATED = 0x80000000; + /* Masks for mPrivateFlags2 */ + /** + * Indicates that this view has reported that it can accept the current drag's content. + * Cleared when the drag operation concludes. + * @hide + */ + static final int DRAG_CAN_ACCEPT = 0x00000001; + /** + * Indicates that this view is currently directly under the drag location in a + * drag-and-drop operation involving content that it can accept. Cleared when + * the drag exits the view, or when the drag operation concludes. + * @hide + */ + static final int DRAG_HOVERED = 0x00000002; + /** + * Indicates whether the view layout direction has been resolved and drawn to the + * right-to-left direction. + * + * @hide + */ + static final int LAYOUT_DIRECTION_RESOLVED_RTL = 0x00000004; + /** + * Indicates whether the view layout direction has been resolved. + * + * @hide + */ + static final int LAYOUT_DIRECTION_RESOLVED = 0x00000008; + /* End of masks for mPrivateFlags2 */ + static final int DRAG_MASK = DRAG_CAN_ACCEPT | DRAG_HOVERED; + /** + * Always allow a user to over-scroll this view, provided it is a + * view that can scroll. + * + * @see #getOverScrollMode() + * @see #setOverScrollMode(int) + */ + public static final int OVER_SCROLL_ALWAYS = 0; + /** + * Allow a user to over-scroll this view only if the content is large + * enough to meaningfully scroll, provided it is a view that can scroll. + * + * @see #getOverScrollMode() + * @see #setOverScrollMode(int) + */ + public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1; + /** + * Never allow a user to over-scroll this view. + * + * @see #getOverScrollMode() + * @see #setOverScrollMode(int) + */ + public static final int OVER_SCROLL_NEVER = 2; + /** + * View has requested the system UI (status bar) to be visible (the default). + * + * @see #setSystemUiVisibility(int) + */ + public static final int SYSTEM_UI_FLAG_VISIBLE = 0; + /** + * View has requested the system UI to enter an unobtrusive "low profile" mode. + * + * This is for use in games, book readers, video players, or any other "immersive" application + * where the usual system chrome is deemed too distracting. + * + * In low profile mode, the status bar and/or navigation icons may dim. + * + * @see #setSystemUiVisibility(int) + */ + public static final int SYSTEM_UI_FLAG_LOW_PROFILE = 0x00000001; + /** + * View has requested that the system navigation be temporarily hidden. + * + * This is an even less obtrusive state than that called for by + * {@link #SYSTEM_UI_FLAG_LOW_PROFILE}; on devices that draw essential navigation controls + * (Home, Back, and the like) on screen, SYSTEM_UI_FLAG_HIDE_NAVIGATION will cause + * those to disappear. This is useful (in conjunction with the + * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN FLAG_FULLSCREEN} and + * {@link android.view.WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN FLAG_LAYOUT_IN_SCREEN} + * window flags) for displaying content using every last pixel on the display. + * + * There is a limitation: because navigation controls are so important, the least user + * interaction will cause them to reappear immediately. + * + * @see #setSystemUiVisibility(int) + */ + public static final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 0x00000002; + /** + * @deprecated Use {@link #SYSTEM_UI_FLAG_LOW_PROFILE} instead. + */ + public static final int STATUS_BAR_HIDDEN = SYSTEM_UI_FLAG_LOW_PROFILE; + /** + * @deprecated Use {@link #SYSTEM_UI_FLAG_VISIBLE} instead. + */ + public static final int STATUS_BAR_VISIBLE = SYSTEM_UI_FLAG_VISIBLE; + /** + * @hide + * + * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked + * out of the public fields to keep the undefined bits out of the developer's way. + * + * Flag to make the status bar not expandable. Unless you also + * set {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show. + */ + public static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000; + /** + * @hide + * + * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked + * out of the public fields to keep the undefined bits out of the developer's way. + * + * Flag to hide notification icons and scrolling ticker text. + */ + public static final int STATUS_BAR_DISABLE_NOTIFICATION_ICONS = 0x00020000; + /** + * @hide + * + * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked + * out of the public fields to keep the undefined bits out of the developer's way. + * + * Flag to disable incoming notification alerts. This will not block + * icons, but it will block sound, vibrating and other visual or aural notifications. + */ + public static final int STATUS_BAR_DISABLE_NOTIFICATION_ALERTS = 0x00040000; + /** + * @hide + * + * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked + * out of the public fields to keep the undefined bits out of the developer's way. + * + * Flag to hide only the scrolling ticker. Note that + * {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS} implies + * {@link #STATUS_BAR_DISABLE_NOTIFICATION_TICKER}. + */ + public static final int STATUS_BAR_DISABLE_NOTIFICATION_TICKER = 0x00080000; + /** + * @hide + * + * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked + * out of the public fields to keep the undefined bits out of the developer's way. + * + * Flag to hide the center system info area. + */ + public static final int STATUS_BAR_DISABLE_SYSTEM_INFO = 0x00100000; + /** + * @hide + * + * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked + * out of the public fields to keep the undefined bits out of the developer's way. + * + * Flag to hide only the home button. Don't use this + * unless you're a special part of the system UI (i.e., setup wizard, keyguard). + */ + public static final int STATUS_BAR_DISABLE_HOME = 0x00200000; + /** + * @hide + * + * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked + * out of the public fields to keep the undefined bits out of the developer's way. + * + * Flag to hide only the back button. Don't use this + * unless you're a special part of the system UI (i.e., setup wizard, keyguard). + */ + public static final int STATUS_BAR_DISABLE_BACK = 0x00400000; + /** + * @hide + * + * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked + * out of the public fields to keep the undefined bits out of the developer's way. + * + * Flag to hide only the clock. You might use this if your activity has + * its own clock making the status bar's clock redundant. + */ + public static final int STATUS_BAR_DISABLE_CLOCK = 0x00800000; + /** + * @hide + * + * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked + * out of the public fields to keep the undefined bits out of the developer's way. + * + * Flag to hide only the recent apps button. Don't use this + * unless you're a special part of the system UI (i.e., setup wizard, keyguard). + */ + public static final int STATUS_BAR_DISABLE_RECENT = 0x01000000; + /** + * @hide + * + * NOTE: This flag may only be used in subtreeSystemUiVisibility, etc. etc. + * + * This hides HOME and RECENT and is provided for compatibility with interim implementations. + */ + @Deprecated + public static final int STATUS_BAR_DISABLE_NAVIGATION = + STATUS_BAR_DISABLE_HOME | STATUS_BAR_DISABLE_RECENT; + /** + * @hide + */ + public static final int PUBLIC_STATUS_BAR_VISIBILITY_MASK = 0x0000FFFF; + /** + * These are the system UI flags that can be cleared by events outside + * of an application. Currently this is just the ability to tap on the + * screen while hiding the navigation bar to have it return. + * @hide + */ + public static final int SYSTEM_UI_CLEARABLE_FLAGS = + SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_HIDE_NAVIGATION; + /** + * Find views that render the specified text. + * + * @see #findViewsWithText(ArrayList, CharSequence, int) + */ + public static final int FIND_VIEWS_WITH_TEXT = 0x00000001; + /** + * Find find views that contain the specified content description. + * + * @see #findViewsWithText(ArrayList, CharSequence, int) + */ + public static final int FIND_VIEWS_WITH_CONTENT_DESCRIPTION = 0x00000002; + /** + * Find views that contain {@link AccessibilityNodeProvider}. Such + * a View is a root of virtual view hierarchy and may contain the searched + * text. If this flag is set Views with providers are automatically + * added and it is a responsibility of the client to call the APIs of + * the provider to determine whether the virtual tree rooted at this View + * contains the text, i.e. getting the list of {@link AccessibilityNodeInfo}s + * represeting the virtual views with this text. + * + * @see #findViewsWithText(ArrayList, CharSequence, int) + * + * @hide + */ + public static final int FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS = 0x00000004; + /** + * Controls the over-scroll mode for this view. + * See {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)}, + * {@link #OVER_SCROLL_ALWAYS}, {@link #OVER_SCROLL_IF_CONTENT_SCROLLS}, + * and {@link #OVER_SCROLL_NEVER}. + */ + private int mOverScrollMode; + /** + * The parent this view is attached to. + * {@hide} + * + * @see #getParent() + */ + protected ViewParent mParent; + /** + * {@hide} + */ + AttachInfo mAttachInfo; + /** + * {@hide} + */ + @ViewDebug.ExportedProperty(flagMapping = { + @ViewDebug.FlagToString(mask = FORCE_LAYOUT, equals = FORCE_LAYOUT, + name = "FORCE_LAYOUT"), + @ViewDebug.FlagToString(mask = LAYOUT_REQUIRED, equals = LAYOUT_REQUIRED, + name = "LAYOUT_REQUIRED"), + @ViewDebug.FlagToString(mask = DRAWING_CACHE_VALID, equals = DRAWING_CACHE_VALID, + name = "DRAWING_CACHE_INVALID", outputIf = false), + @ViewDebug.FlagToString(mask = DRAWN, equals = DRAWN, name = "DRAWN", outputIf = true), + @ViewDebug.FlagToString(mask = DRAWN, equals = DRAWN, name = "NOT_DRAWN", outputIf = false), + @ViewDebug.FlagToString(mask = DIRTY_MASK, equals = DIRTY_OPAQUE, name = "DIRTY_OPAQUE"), + @ViewDebug.FlagToString(mask = DIRTY_MASK, equals = DIRTY, name = "DIRTY") + }) + int mPrivateFlags; + int mPrivateFlags2; + /** + * This view's request for the visibility of the status bar. + * @hide + */ + @ViewDebug.ExportedProperty(flagMapping = { + @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_LOW_PROFILE, + equals = SYSTEM_UI_FLAG_LOW_PROFILE, + name = "SYSTEM_UI_FLAG_LOW_PROFILE", outputIf = true), + @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_HIDE_NAVIGATION, + equals = SYSTEM_UI_FLAG_HIDE_NAVIGATION, + name = "SYSTEM_UI_FLAG_HIDE_NAVIGATION", outputIf = true), + @ViewDebug.FlagToString(mask = PUBLIC_STATUS_BAR_VISIBILITY_MASK, + equals = SYSTEM_UI_FLAG_VISIBLE, + name = "SYSTEM_UI_FLAG_VISIBLE", outputIf = true) + }) + int mSystemUiVisibility; + /** + * Count of how many windows this view has been attached to. + */ + int mWindowAttachCount; + /** + * The layout parameters associated with this view and used by the parent + * {@link android.view.ViewGroup} to determine how this view should be + * laid out. + * {@hide} + */ + protected ViewGroup.LayoutParams mLayoutParams; + /** + * The view flags hold various views states. + * {@hide} + */ + @ViewDebug.ExportedProperty + int mViewFlags; + static class TransformationInfo { + /** + * The transform matrix for the View. This transform is calculated internally + * based on the rotation, scaleX, and scaleY properties. The identity matrix + * is used by default. Do *not* use this variable directly; instead call + * getMatrix(), which will automatically recalculate the matrix if necessary + * to get the correct matrix based on the latest rotation and scale properties. + */ + private final Matrix mMatrix = new Matrix(); + /** + * The transform matrix for the View. This transform is calculated internally + * based on the rotation, scaleX, and scaleY properties. The identity matrix + * is used by default. Do *not* use this variable directly; instead call + * getInverseMatrix(), which will automatically recalculate the matrix if necessary + * to get the correct matrix based on the latest rotation and scale properties. + */ + private Matrix mInverseMatrix; + /** + * An internal variable that tracks whether we need to recalculate the + * transform matrix, based on whether the rotation or scaleX/Y properties + * have changed since the matrix was last calculated. + */ + boolean mMatrixDirty = false; + /** + * An internal variable that tracks whether we need to recalculate the + * transform matrix, based on whether the rotation or scaleX/Y properties + * have changed since the matrix was last calculated. + */ + private boolean mInverseMatrixDirty = true; + /** + * A variable that tracks whether we need to recalculate the + * transform matrix, based on whether the rotation or scaleX/Y properties + * have changed since the matrix was last calculated. This variable + * is only valid after a call to updateMatrix() or to a function that + * calls it such as getMatrix(), hasIdentityMatrix() and getInverseMatrix(). + */ + private boolean mMatrixIsIdentity = true; + /** + * The Camera object is used to compute a 3D matrix when rotationX or rotationY are set. + */ + private Camera mCamera = null; + /** + * This matrix is used when computing the matrix for 3D rotations. + */ + private Matrix matrix3D = null; + /** + * These prev values are used to recalculate a centered pivot point when necessary. The + * pivot point is only used in matrix operations (when rotation, scale, or translation are + * set), so thes values are only used then as well. + */ + private int mPrevWidth = -1; + private int mPrevHeight = -1; + + /** + * The degrees rotation around the vertical axis through the pivot point. + */ + @ViewDebug.ExportedProperty + float mRotationY = 0f; + /** + * The degrees rotation around the horizontal axis through the pivot point. + */ + @ViewDebug.ExportedProperty + float mRotationX = 0f; + /** + * The degrees rotation around the pivot point. + */ + @ViewDebug.ExportedProperty + float mRotation = 0f; + /** + * The amount of translation of the object away from its left property (post-layout). + */ + @ViewDebug.ExportedProperty + float mTranslationX = 0f; + /** + * The amount of translation of the object away from its top property (post-layout). + */ + @ViewDebug.ExportedProperty + float mTranslationY = 0f; + /** + * The amount of scale in the x direction around the pivot point. A + * value of 1 means no scaling is applied. + */ + @ViewDebug.ExportedProperty + float mScaleX = 1f; + /** + * The amount of scale in the y direction around the pivot point. A + * value of 1 means no scaling is applied. + */ + @ViewDebug.ExportedProperty + float mScaleY = 1f; + /** + * The x location of the point around which the view is rotated and scaled. + */ + @ViewDebug.ExportedProperty + float mPivotX = 0f; + /** + * The y location of the point around which the view is rotated and scaled. + */ + @ViewDebug.ExportedProperty + float mPivotY = 0f; + /** + * The opacity of the View. This is a value from 0 to 1, where 0 means + * completely transparent and 1 means completely opaque. + */ + @ViewDebug.ExportedProperty + float mAlpha = 1f; + } + TransformationInfo mTransformationInfo; + private boolean mLastIsOpaque; + /** + * Convenience value to check for float values that are close enough to zero to be considered + * zero. + */ + private static final float NONZERO_EPSILON = .001f; + /** + * The distance in pixels from the left edge of this view's parent + * to the left edge of this view. + * {@hide} + */ + @ViewDebug.ExportedProperty(category = "layout") + protected int mLeft; + /** + * The distance in pixels from the left edge of this view's parent + * to the right edge of this view. + * {@hide} + */ + @ViewDebug.ExportedProperty(category = "layout") + protected int mRight; + /** + * The distance in pixels from the top edge of this view's parent + * to the top edge of this view. + * {@hide} + */ + @ViewDebug.ExportedProperty(category = "layout") + protected int mTop; + /** + * The distance in pixels from the top edge of this view's parent + * to the bottom edge of this view. + * {@hide} + */ + @ViewDebug.ExportedProperty(category = "layout") + protected int mBottom; + /** + * The offset, in pixels, by which the content of this view is scrolled + * horizontally. + * {@hide} + */ + @ViewDebug.ExportedProperty(category = "scrolling") + protected int mScrollX; + /** + * The offset, in pixels, by which the content of this view is scrolled + * vertically. + * {@hide} + */ + @ViewDebug.ExportedProperty(category = "scrolling") + protected int mScrollY; + /** + * The left padding in pixels, that is the distance in pixels between the + * left edge of this view and the left edge of its content. + * {@hide} + */ + @ViewDebug.ExportedProperty(category = "padding") + protected int mPaddingLeft; + /** + * The right padding in pixels, that is the distance in pixels between the + * right edge of this view and the right edge of its content. + * {@hide} + */ + @ViewDebug.ExportedProperty(category = "padding") + protected int mPaddingRight; + /** + * The top padding in pixels, that is the distance in pixels between the + * top edge of this view and the top edge of its content. + * {@hide} + */ + @ViewDebug.ExportedProperty(category = "padding") + protected int mPaddingTop; + /** + * The bottom padding in pixels, that is the distance in pixels between the + * bottom edge of this view and the bottom edge of its content. + * {@hide} + */ + @ViewDebug.ExportedProperty(category = "padding") + protected int mPaddingBottom; + /** + * Briefly describes the view and is primarily used for accessibility support. + */ + private CharSequence mContentDescription; + /** + * Cache the paddingRight set by the user to append to the scrollbar's size. + * + * @hide + */ + @ViewDebug.ExportedProperty(category = "padding") + protected int mUserPaddingRight; + /** + * Cache the paddingBottom set by the user to append to the scrollbar's size. + * + * @hide + */ + @ViewDebug.ExportedProperty(category = "padding") + protected int mUserPaddingBottom; + /** + * Cache the paddingLeft set by the user to append to the scrollbar's size. + * + * @hide + */ + @ViewDebug.ExportedProperty(category = "padding") + protected int mUserPaddingLeft; + /** + * Cache if the user padding is relative. + * + */ + @ViewDebug.ExportedProperty(category = "padding") + boolean mUserPaddingRelative; + /** + * Cache the paddingStart set by the user to append to the scrollbar's size. + * + */ + @ViewDebug.ExportedProperty(category = "padding") + int mUserPaddingStart; + /** + * Cache the paddingEnd set by the user to append to the scrollbar's size. + * + */ + @ViewDebug.ExportedProperty(category = "padding") + int mUserPaddingEnd; + /** + * @hide + */ + int mOldWidthMeasureSpec = Integer.MIN_VALUE; + /** + * @hide + */ + int mOldHeightMeasureSpec = Integer.MIN_VALUE; + private Drawable mBGDrawable; + private int mBackgroundResource; + private boolean mBackgroundSizeChanged; + static class ListenerInfo { + /** + * Listener used to dispatch focus change events. + * This field should be made private, so it is hidden from the SDK. + * {@hide} + */ + protected OnFocusChangeListener mOnFocusChangeListener; + /** + * Listeners for layout change events. + */ + private ArrayList mOnLayoutChangeListeners; + /** + * Listeners for attach events. + */ + private CopyOnWriteArrayList mOnAttachStateChangeListeners; + /** + * Listener used to dispatch click events. + * This field should be made private, so it is hidden from the SDK. + * {@hide} + */ + public OnClickListener mOnClickListener; + /** + * Listener used to dispatch long click events. + * This field should be made private, so it is hidden from the SDK. + * {@hide} + */ + protected OnLongClickListener mOnLongClickListener; + /** + * Listener used to build the context menu. + * This field should be made private, so it is hidden from the SDK. + * {@hide} + */ + protected OnCreateContextMenuListener mOnCreateContextMenuListener; + private OnKeyListener mOnKeyListener; + private OnTouchListener mOnTouchListener; + private OnHoverListener mOnHoverListener; + private OnGenericMotionListener mOnGenericMotionListener; + private OnDragListener mOnDragListener; + private OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener; + } + ListenerInfo mListenerInfo; + /** + * The application environment this view lives in. + * This field should be made private, so it is hidden from the SDK. + * {@hide} + */ + protected Context mContext; + private final Resources mResources; + private ScrollabilityCache mScrollCache; + private int[] mDrawableState = null; + /** + * Set to true when drawing cache is enabled and cannot be created. + * + * @hide + */ + public boolean mCachingFailed; + private Bitmap mDrawingCache; + private Bitmap mUnscaledDrawingCache; + private HardwareLayer mHardwareLayer; + DisplayList mDisplayList; + /** + * When this view has focus and the next focus is {@link #FOCUS_LEFT}, + * the user may specify which view to go to next. + */ + private int mNextFocusLeftId = View.NO_ID; + /** + * When this view has focus and the next focus is {@link #FOCUS_RIGHT}, + * the user may specify which view to go to next. + */ + private int mNextFocusRightId = View.NO_ID; + /** + * When this view has focus and the next focus is {@link #FOCUS_UP}, + * the user may specify which view to go to next. + */ + private int mNextFocusUpId = View.NO_ID; + /** + * When this view has focus and the next focus is {@link #FOCUS_DOWN}, + * the user may specify which view to go to next. + */ + private int mNextFocusDownId = View.NO_ID; + /** + * When this view has focus and the next focus is {@link #FOCUS_FORWARD}, + * the user may specify which view to go to next. + */ + int mNextFocusForwardId = View.NO_ID; + private CheckForLongPress mPendingCheckForLongPress; + private CheckForTap mPendingCheckForTap = null; + private PerformClick mPerformClick; + private SendViewScrolledAccessibilityEvent mSendViewScrolledAccessibilityEvent; + private UnsetPressedState mUnsetPressedState; + /** + * Whether the long press's action has been invoked. The tap's action is invoked on the + * up event while a long press is invoked as soon as the long press duration is reached, so + * a long press could be performed before the tap is checked, in which case the tap's action + * should not be invoked. + */ + private boolean mHasPerformedLongPress; + /** + * The minimum height of the view. We'll try our best to have the height + * of this view to at least this amount. + */ + @ViewDebug.ExportedProperty(category = "measurement") + private int mMinHeight; + /** + * The minimum width of the view. We'll try our best to have the width + * of this view to at least this amount. + */ + @ViewDebug.ExportedProperty(category = "measurement") + private int mMinWidth; + /** + * The delegate to handle touch events that are physically in this view + * but should be handled by another view. + */ + private TouchDelegate mTouchDelegate = null; + /** + * Solid color to use as a background when creating the drawing cache. Enables + * the cache to use 16 bit bitmaps instead of 32 bit. + */ + private int mDrawingCacheBackgroundColor = 0; + /** + * Special tree observer used when mAttachInfo is null. + */ + private ViewTreeObserver mFloatingTreeObserver; + /** + * Cache the touch slop from the context that created the view. + */ + private int mTouchSlop; + /** + * Object that handles automatic animation of view properties. + */ + private ViewPropertyAnimator mAnimator = null; + /** + * Flag indicating that a drag can cross window boundaries. When + * {@link #startDrag(ClipData, DragShadowBuilder, Object, int)} is called + * with this flag set, all visible applications will be able to participate + * in the drag operation and receive the dragged content. + * + * @hide + */ + public static final int DRAG_FLAG_GLOBAL = 1; + /** + * Vertical scroll factor cached by {@link #getVerticalScrollFactor}. + */ + private float mVerticalScrollFactor; + /** + * Position of the vertical scroll bar. + */ + private int mVerticalScrollbarPosition; + /** + * Position the scroll bar at the default position as determined by the system. + */ + public static final int SCROLLBAR_POSITION_DEFAULT = 0; + /** + * Position the scroll bar along the left edge. + */ + public static final int SCROLLBAR_POSITION_LEFT = 1; + /** + * Position the scroll bar along the right edge. + */ + public static final int SCROLLBAR_POSITION_RIGHT = 2; + /** + * Indicates that the view does not have a layer. + * + * @see #getLayerType() + * @see #setLayerType(int, android.graphics.Paint) + * @see #LAYER_TYPE_SOFTWARE + * @see #LAYER_TYPE_HARDWARE + */ + public static final int LAYER_TYPE_NONE = 0; + /** + *

Indicates that the view has a software layer. A software layer is backed + * by a bitmap and causes the view to be rendered using Android's software + * rendering pipeline, even if hardware acceleration is enabled.

+ * + *

Software layers have various usages:

+ *

When the application is not using hardware acceleration, a software layer + * is useful to apply a specific color filter and/or blending mode and/or + * translucency to a view and all its children.

+ *

When the application is using hardware acceleration, a software layer + * is useful to render drawing primitives not supported by the hardware + * accelerated pipeline. It can also be used to cache a complex view tree + * into a texture and reduce the complexity of drawing operations. For instance, + * when animating a complex view tree with a translation, a software layer can + * be used to render the view tree only once.

+ *

Software layers should be avoided when the affected view tree updates + * often. Every update will require to re-render the software layer, which can + * potentially be slow (particularly when hardware acceleration is turned on + * since the layer will have to be uploaded into a hardware texture after every + * update.)

+ * + * @see #getLayerType() + * @see #setLayerType(int, android.graphics.Paint) + * @see #LAYER_TYPE_NONE + * @see #LAYER_TYPE_HARDWARE + */ + public static final int LAYER_TYPE_SOFTWARE = 1; + /** + *

Indicates that the view has a hardware layer. A hardware layer is backed + * by a hardware specific texture (generally Frame Buffer Objects or FBO on + * OpenGL hardware) and causes the view to be rendered using Android's hardware + * rendering pipeline, but only if hardware acceleration is turned on for the + * view hierarchy. When hardware acceleration is turned off, hardware layers + * behave exactly as {@link #LAYER_TYPE_SOFTWARE software layers}.

+ * + *

A hardware layer is useful to apply a specific color filter and/or + * blending mode and/or translucency to a view and all its children.

+ *

A hardware layer can be used to cache a complex view tree into a + * texture and reduce the complexity of drawing operations. For instance, + * when animating a complex view tree with a translation, a hardware layer can + * be used to render the view tree only once.

+ *

A hardware layer can also be used to increase the rendering quality when + * rotation transformations are applied on a view. It can also be used to + * prevent potential clipping issues when applying 3D transforms on a view.

+ * + * @see #getLayerType() + * @see #setLayerType(int, android.graphics.Paint) + * @see #LAYER_TYPE_NONE + * @see #LAYER_TYPE_SOFTWARE + */ + public static final int LAYER_TYPE_HARDWARE = 2; + @ViewDebug.ExportedProperty(category = "drawing", mapping = { + @ViewDebug.IntToString(from = LAYER_TYPE_NONE, to = "NONE"), + @ViewDebug.IntToString(from = LAYER_TYPE_SOFTWARE, to = "SOFTWARE"), + @ViewDebug.IntToString(from = LAYER_TYPE_HARDWARE, to = "HARDWARE") + }) + int mLayerType = LAYER_TYPE_NONE; + Paint mLayerPaint; + Rect mLocalDirtyRect; + /** + * Set to true when the view is sending hover accessibility events because it + * is the innermost hovered view. + */ + private boolean mSendingHoverAccessibilityEvents; + /** + * Delegate for injecting accessiblity functionality. + */ + AccessibilityDelegate mAccessibilityDelegate; + /** + * Text direction is inherited thru {@link ViewGroup} + */ + public static final int TEXT_DIRECTION_INHERIT = 0; + /** + * Text direction is using "first strong algorithm". The first strong directional character + * determines the paragraph direction. If there is no strong directional character, the + * paragraph direction is the view's resolved layout direction. + * + */ + public static final int TEXT_DIRECTION_FIRST_STRONG = 1; + /** + * Text direction is using "any-RTL" algorithm. The paragraph direction is RTL if it contains + * any strong RTL character, otherwise it is LTR if it contains any strong LTR characters. + * If there are neither, the paragraph direction is the view's resolved layout direction. + * + */ + public static final int TEXT_DIRECTION_ANY_RTL = 2; + /** + * Text direction is forced to LTR. + * + */ + public static final int TEXT_DIRECTION_LTR = 3; + /** + * Text direction is forced to RTL. + * + */ + public static final int TEXT_DIRECTION_RTL = 4; + /** + * Text direction is coming from the system Locale. + * + */ + public static final int TEXT_DIRECTION_LOCALE = 5; + /** + * Default text direction is inherited + * + */ + protected static int DEFAULT_TEXT_DIRECTION = TEXT_DIRECTION_INHERIT; + /** + * The text direction that has been defined by {@link #setTextDirection(int)}. + * + */ + @ViewDebug.ExportedProperty(category = "text", mapping = { + @ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"), + @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), + @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), + @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), + @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL"), + @ViewDebug.IntToString(from = TEXT_DIRECTION_LOCALE, to = "LOCALE") + }) + private int mTextDirection = DEFAULT_TEXT_DIRECTION; + /** + * The resolved text direction. This needs resolution if the value is + * TEXT_DIRECTION_INHERIT. The resolution matches mTextDirection if it is + * not TEXT_DIRECTION_INHERIT, otherwise resolution proceeds up the parent + * chain of the view. + * + */ + @ViewDebug.ExportedProperty(category = "text", mapping = { + @ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"), + @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), + @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), + @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), + @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL"), + @ViewDebug.IntToString(from = TEXT_DIRECTION_LOCALE, to = "LOCALE") + }) + private int mResolvedTextDirection = TEXT_DIRECTION_INHERIT; + /** + * Consistency verifier for debugging purposes. + * @hide + */ + protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier = + InputEventConsistencyVerifier.isInstrumentationEnabled() ? + new InputEventConsistencyVerifier(this, 0) : null; + /** + * Simple constructor to use when creating a view from code. + * + * @param context The Context the view is running in, through which it can + * access the current theme, resources, etc. + */ + public View(Context context) { + mContext = context; + mResources = context != null ? context.getResources() : null; + mViewFlags = SOUND_EFFECTS_ENABLED | HAPTIC_FEEDBACK_ENABLED | LAYOUT_DIRECTION_INHERIT; + mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); + setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS); + mUserPaddingStart = -1; + mUserPaddingEnd = -1; + mUserPaddingRelative = false; + } + /** + * Constructor that is called when inflating a view from XML. This is called + * when a view is being constructed from an XML file, supplying attributes + * that were specified in the XML file. This version uses a default style of + * 0, so the only attribute values applied are those in the Context's Theme + * and the given AttributeSet. + * + *

+ * The method onFinishInflate() will be called after all children have been + * added. + * + * @param context The Context the view is running in, through which it can + * access the current theme, resources, etc. + * @param attrs The attributes of the XML tag that is inflating the view. + * @see #View(Context, AttributeSet, int) + */ + public View(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + /** + * Perform inflation from XML and apply a class-specific base style. This + * constructor of View allows subclasses to use their own base style when + * they are inflating. For example, a Button class's constructor would call + * this version of the super class constructor and supply + * R.attr.buttonStyle for defStyle; this allows + * the theme's button style to modify all of the base view attributes (in + * particular its background) as well as the Button class's attributes. + * + * @param context The Context the view is running in, through which it can + * access the current theme, resources, etc. + * @param attrs The attributes of the XML tag that is inflating the view. + * @param defStyle The default style to apply to this view. If 0, no style + * will be applied (beyond what is included in the theme). This may + * either be an attribute resource, whose value will be retrieved + * from the current theme, or an explicit style resource. + * @see #View(Context, AttributeSet) + */ + public View(Context context, AttributeSet attrs, int defStyle) { + this(context); + TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.View, + defStyle, 0); + Drawable background = null; + int leftPadding = -1; + int topPadding = -1; + int rightPadding = -1; + int bottomPadding = -1; + int startPadding = -1; + int endPadding = -1; + int padding = -1; + int viewFlagValues = 0; + int viewFlagMasks = 0; + boolean setScrollContainer = false; + int x = 0; + int y = 0; + float tx = 0; + float ty = 0; + float rotation = 0; + float rotationX = 0; + float rotationY = 0; + float sx = 1f; + float sy = 1f; + boolean transformSet = false; + int scrollbarStyle = SCROLLBARS_INSIDE_OVERLAY; + int overScrollMode = mOverScrollMode; + final int N = a.getIndexCount(); + for (int i = 0; i < N; i++) { + int attr = a.getIndex(i); + switch (attr) { + case com.android.internal.R.styleable.View_background: + background = a.getDrawable(attr); + break; + case com.android.internal.R.styleable.View_padding: + padding = a.getDimensionPixelSize(attr, -1); + break; + case com.android.internal.R.styleable.View_paddingLeft: + leftPadding = a.getDimensionPixelSize(attr, -1); + break; + case com.android.internal.R.styleable.View_paddingTop: + topPadding = a.getDimensionPixelSize(attr, -1); + break; + case com.android.internal.R.styleable.View_paddingRight: + rightPadding = a.getDimensionPixelSize(attr, -1); + break; + case com.android.internal.R.styleable.View_paddingBottom: + bottomPadding = a.getDimensionPixelSize(attr, -1); + break; + case com.android.internal.R.styleable.View_paddingStart: + startPadding = a.getDimensionPixelSize(attr, -1); + break; + case com.android.internal.R.styleable.View_paddingEnd: + endPadding = a.getDimensionPixelSize(attr, -1); + break; + case com.android.internal.R.styleable.View_scrollX: + x = a.getDimensionPixelOffset(attr, 0); + break; + case com.android.internal.R.styleable.View_scrollY: + y = a.getDimensionPixelOffset(attr, 0); + break; + case com.android.internal.R.styleable.View_alpha: + setAlpha(a.getFloat(attr, 1f)); + break; + case com.android.internal.R.styleable.View_transformPivotX: + setPivotX(a.getDimensionPixelOffset(attr, 0)); + break; + case com.android.internal.R.styleable.View_transformPivotY: + setPivotY(a.getDimensionPixelOffset(attr, 0)); + break; + case com.android.internal.R.styleable.View_translationX: + tx = a.getDimensionPixelOffset(attr, 0); + transformSet = true; + break; + case com.android.internal.R.styleable.View_translationY: + ty = a.getDimensionPixelOffset(attr, 0); + transformSet = true; + break; + case com.android.internal.R.styleable.View_rotation: + rotation = a.getFloat(attr, 0); + transformSet = true; + break; + case com.android.internal.R.styleable.View_rotationX: + rotationX = a.getFloat(attr, 0); + transformSet = true; + break; + case com.android.internal.R.styleable.View_rotationY: + rotationY = a.getFloat(attr, 0); + transformSet = true; + break; + case com.android.internal.R.styleable.View_scaleX: + sx = a.getFloat(attr, 1f); + transformSet = true; + break; + case com.android.internal.R.styleable.View_scaleY: + sy = a.getFloat(attr, 1f); + transformSet = true; + break; + case com.android.internal.R.styleable.View_id: + mID = a.getResourceId(attr, NO_ID); + break; + case com.android.internal.R.styleable.View_tag: + mTag = a.getText(attr); + break; + case com.android.internal.R.styleable.View_fitsSystemWindows: + if (a.getBoolean(attr, false)) { + viewFlagValues |= FITS_SYSTEM_WINDOWS; + viewFlagMasks |= FITS_SYSTEM_WINDOWS; + } + break; + case com.android.internal.R.styleable.View_focusable: + if (a.getBoolean(attr, false)) { + viewFlagValues |= FOCUSABLE; + viewFlagMasks |= FOCUSABLE_MASK; + } + break; + case com.android.internal.R.styleable.View_focusableInTouchMode: + if (a.getBoolean(attr, false)) { + viewFlagValues |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE; + viewFlagMasks |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE_MASK; + } + break; + case com.android.internal.R.styleable.View_clickable: + if (a.getBoolean(attr, false)) { + viewFlagValues |= CLICKABLE; + viewFlagMasks |= CLICKABLE; + } + break; + case com.android.internal.R.styleable.View_longClickable: + if (a.getBoolean(attr, false)) { + viewFlagValues |= LONG_CLICKABLE; + viewFlagMasks |= LONG_CLICKABLE; + } + break; + case com.android.internal.R.styleable.View_saveEnabled: + if (!a.getBoolean(attr, true)) { + viewFlagValues |= SAVE_DISABLED; + viewFlagMasks |= SAVE_DISABLED_MASK; + } + break; + case com.android.internal.R.styleable.View_duplicateParentState: + if (a.getBoolean(attr, false)) { + viewFlagValues |= DUPLICATE_PARENT_STATE; + viewFlagMasks |= DUPLICATE_PARENT_STATE; + } + break; + case com.android.internal.R.styleable.View_visibility: + final int visibility = a.getInt(attr, 0); + if (visibility != 0) { + viewFlagValues |= VISIBILITY_FLAGS[visibility]; + viewFlagMasks |= VISIBILITY_MASK; + } + break; + case com.android.internal.R.styleable.View_layoutDirection: + // Clear any HORIZONTAL_DIRECTION flag already set + viewFlagValues &= ~LAYOUT_DIRECTION_MASK; + // Set the HORIZONTAL_DIRECTION flags depending on the value of the attribute + final int layoutDirection = a.getInt(attr, -1); + if (layoutDirection != -1) { + viewFlagValues |= LAYOUT_DIRECTION_FLAGS[layoutDirection]; + } else { + // Set to default (LAYOUT_DIRECTION_INHERIT) + viewFlagValues |= LAYOUT_DIRECTION_DEFAULT; + } + viewFlagMasks |= LAYOUT_DIRECTION_MASK; + break; + case com.android.internal.R.styleable.View_drawingCacheQuality: + final int cacheQuality = a.getInt(attr, 0); + if (cacheQuality != 0) { + viewFlagValues |= DRAWING_CACHE_QUALITY_FLAGS[cacheQuality]; + viewFlagMasks |= DRAWING_CACHE_QUALITY_MASK; + } + break; + case com.android.internal.R.styleable.View_contentDescription: + mContentDescription = a.getString(attr); + break; + case com.android.internal.R.styleable.View_soundEffectsEnabled: + if (!a.getBoolean(attr, true)) { + viewFlagValues &= ~SOUND_EFFECTS_ENABLED; + viewFlagMasks |= SOUND_EFFECTS_ENABLED; + } + break; + case com.android.internal.R.styleable.View_hapticFeedbackEnabled: + if (!a.getBoolean(attr, true)) { + viewFlagValues &= ~HAPTIC_FEEDBACK_ENABLED; + viewFlagMasks |= HAPTIC_FEEDBACK_ENABLED; + } + break; + case R.styleable.View_scrollbars: + final int scrollbars = a.getInt(attr, SCROLLBARS_NONE); + if (scrollbars != SCROLLBARS_NONE) { + viewFlagValues |= scrollbars; + viewFlagMasks |= SCROLLBARS_MASK; + initializeScrollbars(a); + } + break; + //noinspection deprecation + case R.styleable.View_fadingEdge: + if (context.getApplicationInfo().targetSdkVersion >= ICE_CREAM_SANDWICH) { + // Ignore the attribute starting with ICS + break; + } + // With builds < ICS, fall through and apply fading edges + case R.styleable.View_requiresFadingEdge: + final int fadingEdge = a.getInt(attr, FADING_EDGE_NONE); + if (fadingEdge != FADING_EDGE_NONE) { + viewFlagValues |= fadingEdge; + viewFlagMasks |= FADING_EDGE_MASK; + initializeFadingEdge(a); + } + break; + case R.styleable.View_scrollbarStyle: + scrollbarStyle = a.getInt(attr, SCROLLBARS_INSIDE_OVERLAY); + if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { + viewFlagValues |= scrollbarStyle & SCROLLBARS_STYLE_MASK; + viewFlagMasks |= SCROLLBARS_STYLE_MASK; + } + break; + case R.styleable.View_isScrollContainer: + setScrollContainer = true; + if (a.getBoolean(attr, false)) { + setScrollContainer(true); + } + break; + case com.android.internal.R.styleable.View_keepScreenOn: + if (a.getBoolean(attr, false)) { + viewFlagValues |= KEEP_SCREEN_ON; + viewFlagMasks |= KEEP_SCREEN_ON; + } + break; + case R.styleable.View_filterTouchesWhenObscured: + if (a.getBoolean(attr, false)) { + viewFlagValues |= FILTER_TOUCHES_WHEN_OBSCURED; + viewFlagMasks |= FILTER_TOUCHES_WHEN_OBSCURED; + } + break; + case R.styleable.View_nextFocusLeft: + mNextFocusLeftId = a.getResourceId(attr, View.NO_ID); + break; + case R.styleable.View_nextFocusRight: + mNextFocusRightId = a.getResourceId(attr, View.NO_ID); + break; + case R.styleable.View_nextFocusUp: + mNextFocusUpId = a.getResourceId(attr, View.NO_ID); + break; + case R.styleable.View_nextFocusDown: + mNextFocusDownId = a.getResourceId(attr, View.NO_ID); + break; + case R.styleable.View_nextFocusForward: + mNextFocusForwardId = a.getResourceId(attr, View.NO_ID); + break; + case R.styleable.View_minWidth: + mMinWidth = a.getDimensionPixelSize(attr, 0); + break; + case R.styleable.View_minHeight: + mMinHeight = a.getDimensionPixelSize(attr, 0); + break; + case R.styleable.View_onClick: + if (context.isRestricted()) { + throw new IllegalStateException("The android:onClick attribute cannot " + + "be used within a restricted context"); + } + final String handlerName = a.getString(attr); + if (handlerName != null) { + setOnClickListener(new OnClickListener() { + private Method mHandler; + public void onClick(View v) { + if (mHandler == null) { + try { + mHandler = getContext().getClass().getMethod(handlerName, + View.class); + } catch (NoSuchMethodException e) { + int id = getId(); + String idText = id == NO_ID ? "" : " with id '" + + getContext().getResources().getResourceEntryName( + id) + "'"; + throw new IllegalStateException("Could not find a method " + + handlerName + "(View) in the activity " + + getContext().getClass() + " for onClick handler" + + " on view " + View.this.getClass() + idText, e); + } + } + try { + mHandler.invoke(getContext(), View.this); + } catch (IllegalAccessException e) { + throw new IllegalStateException("Could not execute non " + + "public method of the activity", e); + } catch (InvocationTargetException e) { + throw new IllegalStateException("Could not execute " + + "method of the activity", e); + } + } + }); + } + break; + case R.styleable.View_overScrollMode: + overScrollMode = a.getInt(attr, OVER_SCROLL_IF_CONTENT_SCROLLS); + break; + case R.styleable.View_verticalScrollbarPosition: + mVerticalScrollbarPosition = a.getInt(attr, SCROLLBAR_POSITION_DEFAULT); + break; + case R.styleable.View_layerType: + setLayerType(a.getInt(attr, LAYER_TYPE_NONE), null); + break; + case R.styleable.View_textDirection: + mTextDirection = a.getInt(attr, DEFAULT_TEXT_DIRECTION); + break; + } + } + a.recycle(); + setOverScrollMode(overScrollMode); + if (background != null) { + setBackgroundDrawable(background); + } + mUserPaddingRelative = (startPadding >= 0 || endPadding >= 0); + // Cache user padding as we cannot fully resolve padding here (we dont have yet the resolved + // layout direction). Those cached values will be used later during padding resolution. + mUserPaddingStart = startPadding; + mUserPaddingEnd = endPadding; + if (padding >= 0) { + leftPadding = padding; + topPadding = padding; + rightPadding = padding; + bottomPadding = padding; + } + // If the user specified the padding (either with android:padding or + // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise + // use the default padding or the padding from the background drawable + // (stored at this point in mPadding*) + setPadding(leftPadding >= 0 ? leftPadding : mPaddingLeft, + topPadding >= 0 ? topPadding : mPaddingTop, + rightPadding >= 0 ? rightPadding : mPaddingRight, + bottomPadding >= 0 ? bottomPadding : mPaddingBottom); + if (viewFlagMasks != 0) { + setFlags(viewFlagValues, viewFlagMasks); + } + // Needs to be called after mViewFlags is set + if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { + recomputePadding(); + } + if (x != 0 || y != 0) { + scrollTo(x, y); + } + if (transformSet) { + setTranslationX(tx); + setTranslationY(ty); + setRotation(rotation); + setRotationX(rotationX); + setRotationY(rotationY); + setScaleX(sx); + setScaleY(sy); + } + if (!setScrollContainer && (viewFlagValues&SCROLLBARS_VERTICAL) != 0) { + setScrollContainer(true); + } + computeOpaqueFlags(); + } + /** + * Non-public constructor for use in testing + */ + View() { + mResources = null; + } + /** + *

+ * Initializes the fading edges from a given set of styled attributes. This + * method should be called by subclasses that need fading edges and when an + * instance of these subclasses is created programmatically rather than + * being inflated from XML. This method is automatically called when the XML + * is inflated. + *

+ * + * @param a the styled attributes set to initialize the fading edges from + */ + protected void initializeFadingEdge(TypedArray a) { + initScrollCache(); + mScrollCache.fadingEdgeLength = a.getDimensionPixelSize( + R.styleable.View_fadingEdgeLength, + ViewConfiguration.get(mContext).getScaledFadingEdgeLength()); + } + /** + * Returns the size of the vertical faded edges used to indicate that more + * content in this view is visible. + * + * @return The size in pixels of the vertical faded edge or 0 if vertical + * faded edges are not enabled for this view. + * @attr ref android.R.styleable#View_fadingEdgeLength + */ + public int getVerticalFadingEdgeLength() { + if (isVerticalFadingEdgeEnabled()) { + ScrollabilityCache cache = mScrollCache; + if (cache != null) { + return cache.fadingEdgeLength; + } + } + return 0; + } + /** + * Set the size of the faded edge used to indicate that more content in this + * view is available. Will not change whether the fading edge is enabled; use + * {@link #setVerticalFadingEdgeEnabled(boolean)} or + * {@link #setHorizontalFadingEdgeEnabled(boolean)} to enable the fading edge + * for the vertical or horizontal fading edges. + * + * @param length The size in pixels of the faded edge used to indicate that more + * content in this view is visible. + */ + public void setFadingEdgeLength(int length) { + initScrollCache(); + mScrollCache.fadingEdgeLength = length; + } + /** + * Returns the size of the horizontal faded edges used to indicate that more + * content in this view is visible. + * + * @return The size in pixels of the horizontal faded edge or 0 if horizontal + * faded edges are not enabled for this view. + * @attr ref android.R.styleable#View_fadingEdgeLength + */ + public int getHorizontalFadingEdgeLength() { + if (isHorizontalFadingEdgeEnabled()) { + ScrollabilityCache cache = mScrollCache; + if (cache != null) { + return cache.fadingEdgeLength; + } + } + return 0; + } + /** + * Returns the width of the vertical scrollbar. + * + * @return The width in pixels of the vertical scrollbar or 0 if there + * is no vertical scrollbar. + */ + public int getVerticalScrollbarWidth() { + ScrollabilityCache cache = mScrollCache; + if (cache != null) { + ScrollBarDrawable scrollBar = cache.scrollBar; + if (scrollBar != null) { + int size = scrollBar.getSize(true); + if (size <= 0) { + size = cache.scrollBarSize; + } + return size; + } + return 0; + } + return 0; + } + /** + * Returns the height of the horizontal scrollbar. + * + * @return The height in pixels of the horizontal scrollbar or 0 if + * there is no horizontal scrollbar. + */ + protected int getHorizontalScrollbarHeight() { + ScrollabilityCache cache = mScrollCache; + if (cache != null) { + ScrollBarDrawable scrollBar = cache.scrollBar; + if (scrollBar != null) { + int size = scrollBar.getSize(false); + if (size <= 0) { + size = cache.scrollBarSize; + } + return size; + } + return 0; + } + return 0; + } + /** + *

+ * Initializes the scrollbars from a given set of styled attributes. This + * method should be called by subclasses that need scrollbars and when an + * instance of these subclasses is created programmatically rather than + * being inflated from XML. This method is automatically called when the XML + * is inflated. + *

+ * + * @param a the styled attributes set to initialize the scrollbars from + */ + protected void initializeScrollbars(TypedArray a) { + initScrollCache(); + final ScrollabilityCache scrollabilityCache = mScrollCache; + if (scrollabilityCache.scrollBar == null) { + scrollabilityCache.scrollBar = new ScrollBarDrawable(); + } + final boolean fadeScrollbars = a.getBoolean(R.styleable.View_fadeScrollbars, true); + if (!fadeScrollbars) { + scrollabilityCache.state = ScrollabilityCache.ON; + } + scrollabilityCache.fadeScrollBars = fadeScrollbars; + scrollabilityCache.scrollBarFadeDuration = a.getInt( + R.styleable.View_scrollbarFadeDuration, ViewConfiguration + .getScrollBarFadeDuration()); + scrollabilityCache.scrollBarDefaultDelayBeforeFade = a.getInt( + R.styleable.View_scrollbarDefaultDelayBeforeFade, + ViewConfiguration.getScrollDefaultDelay()); + scrollabilityCache.scrollBarSize = a.getDimensionPixelSize( + com.android.internal.R.styleable.View_scrollbarSize, + ViewConfiguration.get(mContext).getScaledScrollBarSize()); + Drawable track = a.getDrawable(R.styleable.View_scrollbarTrackHorizontal); + scrollabilityCache.scrollBar.setHorizontalTrackDrawable(track); + Drawable thumb = a.getDrawable(R.styleable.View_scrollbarThumbHorizontal); + if (thumb != null) { + scrollabilityCache.scrollBar.setHorizontalThumbDrawable(thumb); + } + boolean alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawHorizontalTrack, + false); + if (alwaysDraw) { + scrollabilityCache.scrollBar.setAlwaysDrawHorizontalTrack(true); + } + track = a.getDrawable(R.styleable.View_scrollbarTrackVertical); + scrollabilityCache.scrollBar.setVerticalTrackDrawable(track); + thumb = a.getDrawable(R.styleable.View_scrollbarThumbVertical); + if (thumb != null) { + scrollabilityCache.scrollBar.setVerticalThumbDrawable(thumb); + } + alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawVerticalTrack, + false); + if (alwaysDraw) { + scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true); + } + // Re-apply user/background padding so that scrollbar(s) get added + resolvePadding(); + } + /** + *

+ * Initalizes the scrollability cache if necessary. + *

+ */ + private void initScrollCache() { + if (mScrollCache == null) { + mScrollCache = new ScrollabilityCache(ViewConfiguration.get(mContext), this); + } + } + /** + * Set the position of the vertical scroll bar. Should be one of + * {@link #SCROLLBAR_POSITION_DEFAULT}, {@link #SCROLLBAR_POSITION_LEFT} or + * {@link #SCROLLBAR_POSITION_RIGHT}. + * + * @param position Where the vertical scroll bar should be positioned. + */ + public void setVerticalScrollbarPosition(int position) { + if (mVerticalScrollbarPosition != position) { + mVerticalScrollbarPosition = position; + computeOpaqueFlags(); + resolvePadding(); + } + } + /** + * @return The position where the vertical scroll bar will show, if applicable. + * @see #setVerticalScrollbarPosition(int) + */ + public int getVerticalScrollbarPosition() { + return mVerticalScrollbarPosition; + } + ListenerInfo getListenerInfo() { + if (mListenerInfo != null) { + return mListenerInfo; + } + mListenerInfo = new ListenerInfo(); + return mListenerInfo; + } + /** + * Register a callback to be invoked when focus of this view changed. + * + * @param l The callback that will run. + */ + public void setOnFocusChangeListener(OnFocusChangeListener l) { + getListenerInfo().mOnFocusChangeListener = l; + } + /** + * Add a listener that will be called when the bounds of the view change due to + * layout processing. + * + * @param listener The listener that will be called when layout bounds change. + */ + public void addOnLayoutChangeListener(OnLayoutChangeListener listener) { + ListenerInfo li = getListenerInfo(); + if (li.mOnLayoutChangeListeners == null) { + li.mOnLayoutChangeListeners = new ArrayList(); + } + if (!li.mOnLayoutChangeListeners.contains(listener)) { + li.mOnLayoutChangeListeners.add(listener); + } + } + /** + * Remove a listener for layout changes. + * + * @param listener The listener for layout bounds change. + */ + public void removeOnLayoutChangeListener(OnLayoutChangeListener listener) { + ListenerInfo li = mListenerInfo; + if (li == null || li.mOnLayoutChangeListeners == null) { + return; + } + li.mOnLayoutChangeListeners.remove(listener); + } + /** + * Add a listener for attach state changes. + * + * This listener will be called whenever this view is attached or detached + * from a window. Remove the listener using + * {@link #removeOnAttachStateChangeListener(OnAttachStateChangeListener)}. + * + * @param listener Listener to attach + * @see #removeOnAttachStateChangeListener(OnAttachStateChangeListener) + */ + public void addOnAttachStateChangeListener(OnAttachStateChangeListener listener) { + ListenerInfo li = getListenerInfo(); + if (li.mOnAttachStateChangeListeners == null) { + li.mOnAttachStateChangeListeners + = new CopyOnWriteArrayList(); + } + li.mOnAttachStateChangeListeners.add(listener); + } + /** + * Remove a listener for attach state changes. The listener will receive no further + * notification of window attach/detach events. + * + * @param listener Listener to remove + * @see #addOnAttachStateChangeListener(OnAttachStateChangeListener) + */ + public void removeOnAttachStateChangeListener(OnAttachStateChangeListener listener) { + ListenerInfo li = mListenerInfo; + if (li == null || li.mOnAttachStateChangeListeners == null) { + return; + } + li.mOnAttachStateChangeListeners.remove(listener); + } + /** + * Returns the focus-change callback registered for this view. + * + * @return The callback, or null if one is not registered. + */ + public OnFocusChangeListener getOnFocusChangeListener() { + ListenerInfo li = mListenerInfo; + return li != null ? li.mOnFocusChangeListener : null; + } + /** + * Register a callback to be invoked when this view is clicked. If this view is not + * clickable, it becomes clickable. + * + * @param l The callback that will run + * + * @see #setClickable(boolean) + */ + public void setOnClickListener(OnClickListener l) { + if (!isClickable()) { + setClickable(true); + } + getListenerInfo().mOnClickListener = l; + } + /** + * Return whether this view has an attached OnClickListener. Returns + * true if there is a listener, false if there is none. + */ + public boolean hasOnClickListeners() { + ListenerInfo li = mListenerInfo; + return (li != null && li.mOnClickListener != null); + } + /** + * Register a callback to be invoked when this view is clicked and held. If this view is not + * long clickable, it becomes long clickable. + * + * @param l The callback that will run + * + * @see #setLongClickable(boolean) + */ + public void setOnLongClickListener(OnLongClickListener l) { + if (!isLongClickable()) { + setLongClickable(true); + } + getListenerInfo().mOnLongClickListener = l; + } + /** + * Register a callback to be invoked when the context menu for this view is + * being built. If this view is not long clickable, it becomes long clickable. + * + * @param l The callback that will run + * + */ + public void setOnCreateContextMenuListener(OnCreateContextMenuListener l) { + if (!isLongClickable()) { + setLongClickable(true); + } + getListenerInfo().mOnCreateContextMenuListener = l; + } + /** + * Call this view's OnClickListener, if it is defined. Performs all normal + * actions associated with clicking: reporting accessibility event, playing + * a sound, etc. + * + * @return True there was an assigned OnClickListener that was called, false + * otherwise is returned. + */ + public boolean performClick() { + sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); + ListenerInfo li = mListenerInfo; + if (li != null && li.mOnClickListener != null) { + playSoundEffect(SoundEffectConstants.CLICK); + li.mOnClickListener.onClick(this); + return true; + } + return false; + } + /** + * Directly call any attached OnClickListener. Unlike {@link #performClick()}, + * this only calls the listener, and does not do any associated clicking + * actions like reporting an accessibility event. + * + * @return True there was an assigned OnClickListener that was called, false + * otherwise is returned. + */ + public boolean callOnClick() { + ListenerInfo li = mListenerInfo; + if (li != null && li.mOnClickListener != null) { + li.mOnClickListener.onClick(this); + return true; + } + return false; + } + /** + * Call this view's OnLongClickListener, if it is defined. Invokes the context menu if the + * OnLongClickListener did not consume the event. + * + * @return True if one of the above receivers consumed the event, false otherwise. + */ + public boolean performLongClick() { + sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); + boolean handled = false; + ListenerInfo li = mListenerInfo; + if (li != null && li.mOnLongClickListener != null) { + handled = li.mOnLongClickListener.onLongClick(View.this); + } + if (!handled) { + handled = showContextMenu(); + } + if (handled) { + performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); + } + return handled; + } + /** + * Performs button-related actions during a touch down event. + * + * @param event The event. + * @return True if the down was consumed. + * + * @hide + */ + protected boolean performButtonActionOnTouchDown(MotionEvent event) { + if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) { + if (showContextMenu(event.getX(), event.getY(), event.getMetaState())) { + return true; + } + } + return false; + } + /** + * Bring up the context menu for this view. + * + * @return Whether a context menu was displayed. + */ + public boolean showContextMenu() { + return getParent().showContextMenuForChild(this); + } + /** + * Bring up the context menu for this view, referring to the item under the specified point. + * + * @param x The referenced x coordinate. + * @param y The referenced y coordinate. + * @param metaState The keyboard modifiers that were pressed. + * @return Whether a context menu was displayed. + * + * @hide + */ + public boolean showContextMenu(float x, float y, int metaState) { + return showContextMenu(); + } + /** + * Start an action mode. + * + * @param callback Callback that will control the lifecycle of the action mode + * @return The new action mode if it is started, null otherwise + * + * @see ActionMode + */ + public ActionMode startActionMode(ActionMode.Callback callback) { + return getParent().startActionModeForChild(this, callback); + } + /** + * Register a callback to be invoked when a key is pressed in this view. + * @param l the key listener to attach to this view + */ + public void setOnKeyListener(OnKeyListener l) { + getListenerInfo().mOnKeyListener = l; + } + /** + * Register a callback to be invoked when a touch event is sent to this view. + * @param l the touch listener to attach to this view + */ + public void setOnTouchListener(OnTouchListener l) { + getListenerInfo().mOnTouchListener = l; + } + /** + * Register a callback to be invoked when a generic motion event is sent to this view. + * @param l the generic motion listener to attach to this view + */ + public void setOnGenericMotionListener(OnGenericMotionListener l) { + getListenerInfo().mOnGenericMotionListener = l; + } + /** + * Register a callback to be invoked when a hover event is sent to this view. + * @param l the hover listener to attach to this view + */ + public void setOnHoverListener(OnHoverListener l) { + getListenerInfo().mOnHoverListener = l; + } + /** + * Register a drag event listener callback object for this View. The parameter is + * an implementation of {@link android.view.View.OnDragListener}. To send a drag event to a + * View, the system calls the + * {@link android.view.View.OnDragListener#onDrag(View,DragEvent)} method. + * @param l An implementation of {@link android.view.View.OnDragListener}. + */ + public void setOnDragListener(OnDragListener l) { + getListenerInfo().mOnDragListener = l; + } + /** + * Give this view focus. This will cause + * {@link #onFocusChanged(boolean, int, android.graphics.Rect)} to be called. + * + * Note: this does not check whether this {@link View} should get focus, it just + * gives it focus no matter what. It should only be called internally by framework + * code that knows what it is doing, namely {@link #requestFocus(int, Rect)}. + * + * @param direction values are {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN}, + * {@link View#FOCUS_LEFT} or {@link View#FOCUS_RIGHT}. This is the direction which + * focus moved when requestFocus() is called. It may not always + * apply, in which case use the default View.FOCUS_DOWN. + * @param previouslyFocusedRect The rectangle of the view that had focus + * prior in this View's coordinate system. + */ + void handleFocusGainInternal(int direction, Rect previouslyFocusedRect) { + if (DBG) { + System.out.println(this + " requestFocus()"); + } + if ((mPrivateFlags & FOCUSED) == 0) { + mPrivateFlags |= FOCUSED; + if (mParent != null) { + mParent.requestChildFocus(this, this); + } + onFocusChanged(true, direction, previouslyFocusedRect); + refreshDrawableState(); + } + } + /** + * Request that a rectangle of this view be visible on the screen, + * scrolling if necessary just enough. + * + *

A View should call this if it maintains some notion of which part + * of its content is interesting. For example, a text editing view + * should call this when its cursor moves. + * + * @param rectangle The rectangle. + * @return Whether any parent scrolled. + */ + public boolean requestRectangleOnScreen(Rect rectangle) { + return requestRectangleOnScreen(rectangle, false); + } + /** + * Request that a rectangle of this view be visible on the screen, + * scrolling if necessary just enough. + * + *

A View should call this if it maintains some notion of which part + * of its content is interesting. For example, a text editing view + * should call this when its cursor moves. + * + *

When immediate is set to true, scrolling will not be + * animated. + * + * @param rectangle The rectangle. + * @param immediate True to forbid animated scrolling, false otherwise + * @return Whether any parent scrolled. + */ + public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) { + View child = this; + ViewParent parent = mParent; + boolean scrolled = false; + while (parent != null) { + scrolled |= parent.requestChildRectangleOnScreen(child, + rectangle, immediate); + // offset rect so next call has the rectangle in the + // coordinate system of its direct child. + rectangle.offset(child.getLeft(), child.getTop()); + rectangle.offset(-child.getScrollX(), -child.getScrollY()); + if (!(parent instanceof View)) { + break; + } + child = (View) parent; + parent = child.getParent(); + } + return scrolled; + } + /** + * Called when this view wants to give up focus. If focus is cleared + * {@link #onFocusChanged(boolean, int, android.graphics.Rect)} is called. + *

+ * Note: When a View clears focus the framework is trying + * to give focus to the first focusable View from the top. Hence, if this + * View is the first from the top that can take focus, then its focus will + * not be cleared nor will the focus change callback be invoked. + *

+ */ + public void clearFocus() { + if (DBG) { + System.out.println(this + " clearFocus()"); + } + if ((mPrivateFlags & FOCUSED) != 0) { + mPrivateFlags &= ~FOCUSED; + if (mParent != null) { + mParent.clearChildFocus(this); + } + onFocusChanged(false, 0, null); + refreshDrawableState(); + } + } + /** + * Called to clear the focus of a view that is about to be removed. + * Doesn't call clearChildFocus, which prevents this view from taking + * focus again before it has been removed from the parent + */ + void clearFocusForRemoval() { + if ((mPrivateFlags & FOCUSED) != 0) { + mPrivateFlags &= ~FOCUSED; + onFocusChanged(false, 0, null); + refreshDrawableState(); + // The view cleared focus and invoked the callbacks, so now is the + // time to give focus to the the first focusable from the top to + // ensure that the gain focus is announced after clear focus. + getRootView().requestFocus(FOCUS_FORWARD); + } + } + /** + * Called internally by the view system when a new view is getting focus. + * This is what clears the old focus. + */ + void unFocus() { + if (DBG) { + System.out.println(this + " unFocus()"); + } + if ((mPrivateFlags & FOCUSED) != 0) { + mPrivateFlags &= ~FOCUSED; + onFocusChanged(false, 0, null); + refreshDrawableState(); + } + } + /** + * Returns true if this view has focus iteself, or is the ancestor of the + * view that has focus. + * + * @return True if this view has or contains focus, false otherwise. + */ + @ViewDebug.ExportedProperty(category = "focus") + public boolean hasFocus() { + return (mPrivateFlags & FOCUSED) != 0; + } + /** + * Returns true if this view is focusable or if it contains a reachable View + * for which {@link #hasFocusable()} returns true. A "reachable hasFocusable()" + * is a View whose parents do not block descendants focus. + * + * Only {@link #VISIBLE} views are considered focusable. + * + * @return True if the view is focusable or if the view contains a focusable + * View, false otherwise. + * + * @see ViewGroup#FOCUS_BLOCK_DESCENDANTS + */ + public boolean hasFocusable() { + return (mViewFlags & VISIBILITY_MASK) == VISIBLE && isFocusable(); + } + /** + * Called by the view system when the focus state of this view changes. + * When the focus change event is caused by directional navigation, direction + * and previouslyFocusedRect provide insight into where the focus is coming from. + * When overriding, be sure to call up through to the super class so that + * the standard focus handling will occur. + * + * @param gainFocus True if the View has focus; false otherwise. + * @param direction The direction focus has moved when requestFocus() + * is called to give this view focus. Values are + * {@link #FOCUS_UP}, {@link #FOCUS_DOWN}, {@link #FOCUS_LEFT}, + * {@link #FOCUS_RIGHT}, {@link #FOCUS_FORWARD}, or {@link #FOCUS_BACKWARD}. + * It may not always apply, in which case use the default. + * @param previouslyFocusedRect The rectangle, in this view's coordinate + * system, of the previously focused view. If applicable, this will be + * passed in as finer grained information about where the focus is coming + * from (in addition to direction). Will be null otherwise. + */ + protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { + if (gainFocus) { + sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); + } + InputMethodManager imm = InputMethodManager.peekInstance(); + if (!gainFocus) { + if (isPressed()) { + setPressed(false); + } + if (imm != null && mAttachInfo != null + && mAttachInfo.mHasWindowFocus) { + imm.focusOut(this); + } + onFocusLost(); + } else if (imm != null && mAttachInfo != null + && mAttachInfo.mHasWindowFocus) { + imm.focusIn(this); + } + invalidate(true); + ListenerInfo li = mListenerInfo; + if (li != null && li.mOnFocusChangeListener != null) { + li.mOnFocusChangeListener.onFocusChange(this, gainFocus); + } + if (mAttachInfo != null) { + mAttachInfo.mKeyDispatchState.reset(this); + } + } + /** + * Sends an accessibility event of the given type. If accessiiblity is + * not enabled this method has no effect. The default implementation calls + * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)} first + * to populate information about the event source (this View), then calls + * {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} to + * populate the text content of the event source including its descendants, + * and last calls + * {@link ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)} + * on its parent to resuest sending of the event to interested parties. + *

+ * If an {@link AccessibilityDelegate} has been specified via calling + * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its + * {@link AccessibilityDelegate#sendAccessibilityEvent(View, int)} is + * responsible for handling this call. + *

+ * + * @param eventType The type of the event to send, as defined by several types from + * {@link android.view.accessibility.AccessibilityEvent}, such as + * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_CLICKED} or + * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_HOVER_ENTER}. + * + * @see #onInitializeAccessibilityEvent(AccessibilityEvent) + * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) + * @see ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent) + * @see AccessibilityDelegate + */ + public void sendAccessibilityEvent(int eventType) { + if (mAccessibilityDelegate != null) { + mAccessibilityDelegate.sendAccessibilityEvent(this, eventType); + } else { + sendAccessibilityEventInternal(eventType); + } + } + /** + * @see #sendAccessibilityEvent(int) + * + * Note: Called from the default {@link AccessibilityDelegate}. + */ + void sendAccessibilityEventInternal(int eventType) { + if (AccessibilityManager.getInstance(mContext).isEnabled()) { + sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType)); + } + } + /** + * This method behaves exactly as {@link #sendAccessibilityEvent(int)} but + * takes as an argument an empty {@link AccessibilityEvent} and does not + * perform a check whether accessibility is enabled. + *

+ * If an {@link AccessibilityDelegate} has been specified via calling + * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its + * {@link AccessibilityDelegate#sendAccessibilityEventUnchecked(View, AccessibilityEvent)} + * is responsible for handling this call. + *

+ * + * @param event The event to send. + * + * @see #sendAccessibilityEvent(int) + */ + public void sendAccessibilityEventUnchecked(AccessibilityEvent event) { + if (mAccessibilityDelegate != null) { + mAccessibilityDelegate.sendAccessibilityEventUnchecked(this, event); + } else { + sendAccessibilityEventUncheckedInternal(event); + } + } + /** + * @see #sendAccessibilityEventUnchecked(AccessibilityEvent) + * + * Note: Called from the default {@link AccessibilityDelegate}. + */ + void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) { + if (!isShown()) { + return; + } + onInitializeAccessibilityEvent(event); + // Only a subset of accessibility events populates text content. + if ((event.getEventType() & POPULATING_ACCESSIBILITY_EVENT_TYPES) != 0) { + dispatchPopulateAccessibilityEvent(event); + } + // In the beginning we called #isShown(), so we know that getParent() is not null. + getParent().requestSendAccessibilityEvent(this, event); + } + /** + * Dispatches an {@link AccessibilityEvent} to the {@link View} first and then + * to its children for adding their text content to the event. Note that the + * event text is populated in a separate dispatch path since we add to the + * event not only the text of the source but also the text of all its descendants. + * A typical implementation will call + * {@link #onPopulateAccessibilityEvent(AccessibilityEvent)} on the this view + * and then call the {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} + * on each child. Override this method if custom population of the event text + * content is required. + *

+ * If an {@link AccessibilityDelegate} has been specified via calling + * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its + * {@link AccessibilityDelegate#dispatchPopulateAccessibilityEvent(View, AccessibilityEvent)} + * is responsible for handling this call. + *

+ *

+ * Note: Accessibility events of certain types are not dispatched for + * populating the event text via this method. For details refer to {@link AccessibilityEvent}. + *

+ * + * @param event The event. + * + * @return True if the event population was completed. + */ + public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { + if (mAccessibilityDelegate != null) { + return mAccessibilityDelegate.dispatchPopulateAccessibilityEvent(this, event); + } else { + return dispatchPopulateAccessibilityEventInternal(event); + } + } + /** + * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) + * + * Note: Called from the default {@link AccessibilityDelegate}. + */ + boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) { + onPopulateAccessibilityEvent(event); + return false; + } + /** + * Called from {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} + * giving a chance to this View to populate the accessibility event with its + * text content. While this method is free to modify event + * attributes other than text content, doing so should normally be performed in + * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)}. + *

+ * Example: Adding formatted date string to an accessibility event in addition + * to the text added by the super implementation: + *

 public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
+     *     super.onPopulateAccessibilityEvent(event);
+     *     final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY;
+     *     String selectedDateUtterance = DateUtils.formatDateTime(mContext,
+     *         mCurrentDate.getTimeInMillis(), flags);
+     *     event.getText().add(selectedDateUtterance);
+     * }
+ *

+ * If an {@link AccessibilityDelegate} has been specified via calling + * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its + * {@link AccessibilityDelegate#onPopulateAccessibilityEvent(View, AccessibilityEvent)} + * is responsible for handling this call. + *

+ *

Note: Always call the super implementation before adding + * information to the event, in case the default implementation has basic information to add. + *

+ * + * @param event The accessibility event which to populate. + * + * @see #sendAccessibilityEvent(int) + * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) + */ + public void onPopulateAccessibilityEvent(AccessibilityEvent event) { + if (mAccessibilityDelegate != null) { + mAccessibilityDelegate.onPopulateAccessibilityEvent(this, event); + } else { + onPopulateAccessibilityEventInternal(event); + } + } + /** + * @see #onPopulateAccessibilityEvent(AccessibilityEvent) + * + * Note: Called from the default {@link AccessibilityDelegate}. + */ + void onPopulateAccessibilityEventInternal(AccessibilityEvent event) { + } + /** + * Initializes an {@link AccessibilityEvent} with information about + * this View which is the event source. In other words, the source of + * an accessibility event is the view whose state change triggered firing + * the event. + *

+ * Example: Setting the password property of an event in addition + * to properties set by the super implementation: + *

 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
+     *     super.onInitializeAccessibilityEvent(event);
+     *     event.setPassword(true);
+     * }
+ *

+ * If an {@link AccessibilityDelegate} has been specified via calling + * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its + * {@link AccessibilityDelegate#onInitializeAccessibilityEvent(View, AccessibilityEvent)} + * is responsible for handling this call. + *

+ *

Note: Always call the super implementation before adding + * information to the event, in case the default implementation has basic information to add. + *

+ * @param event The event to initialize. + * + * @see #sendAccessibilityEvent(int) + * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) + */ + public void onInitializeAccessibilityEvent(AccessibilityEvent event) { + if (mAccessibilityDelegate != null) { + mAccessibilityDelegate.onInitializeAccessibilityEvent(this, event); + } else { + onInitializeAccessibilityEventInternal(event); + } + } + /** + * @see #onInitializeAccessibilityEvent(AccessibilityEvent) + * + * Note: Called from the default {@link AccessibilityDelegate}. + */ + void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { + event.setSource(this); + event.setClassName(View.class.getName()); + event.setPackageName(getContext().getPackageName()); + event.setEnabled(isEnabled()); + event.setContentDescription(mContentDescription); + if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED && mAttachInfo != null) { + ArrayList focusablesTempList = mAttachInfo.mFocusablesTempList; + getRootView().addFocusables(focusablesTempList, View.FOCUS_FORWARD, + FOCUSABLES_ALL); + event.setItemCount(focusablesTempList.size()); + event.setCurrentItemIndex(focusablesTempList.indexOf(this)); + focusablesTempList.clear(); + } + } + /** + * Returns an {@link AccessibilityNodeInfo} representing this view from the + * point of view of an {@link android.accessibilityservice.AccessibilityService}. + * This method is responsible for obtaining an accessibility node info from a + * pool of reusable instances and calling + * {@link #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} on this view to + * initialize the former. + *

+ * Note: The client is responsible for recycling the obtained instance by calling + * {@link AccessibilityNodeInfo#recycle()} to minimize object creation. + *

+ * + * @return A populated {@link AccessibilityNodeInfo}. + * + * @see AccessibilityNodeInfo + */ + public AccessibilityNodeInfo createAccessibilityNodeInfo() { + AccessibilityNodeProvider provider = getAccessibilityNodeProvider(); + if (provider != null) { + return provider.createAccessibilityNodeInfo(View.NO_ID); + } else { + AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(this); + onInitializeAccessibilityNodeInfo(info); + return info; + } + } + /** + * Initializes an {@link AccessibilityNodeInfo} with information about this view. + * The base implementation sets: + *
    + *
  • {@link AccessibilityNodeInfo#setParent(View)},
  • + *
  • {@link AccessibilityNodeInfo#setBoundsInParent(Rect)},
  • + *
  • {@link AccessibilityNodeInfo#setBoundsInScreen(Rect)},
  • + *
  • {@link AccessibilityNodeInfo#setPackageName(CharSequence)},
  • + *
  • {@link AccessibilityNodeInfo#setClassName(CharSequence)},
  • + *
  • {@link AccessibilityNodeInfo#setContentDescription(CharSequence)},
  • + *
  • {@link AccessibilityNodeInfo#setEnabled(boolean)},
  • + *
  • {@link AccessibilityNodeInfo#setClickable(boolean)},
  • + *
  • {@link AccessibilityNodeInfo#setFocusable(boolean)},
  • + *
  • {@link AccessibilityNodeInfo#setFocused(boolean)},
  • + *
  • {@link AccessibilityNodeInfo#setLongClickable(boolean)},
  • + *
  • {@link AccessibilityNodeInfo#setSelected(boolean)},
  • + *
+ *

+ * Subclasses should override this method, call the super implementation, + * and set additional attributes. + *

+ *

+ * If an {@link AccessibilityDelegate} has been specified via calling + * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its + * {@link AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo)} + * is responsible for handling this call. + *

+ * + * @param info The instance to initialize. + */ + public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { + if (mAccessibilityDelegate != null) { + mAccessibilityDelegate.onInitializeAccessibilityNodeInfo(this, info); + } else { + onInitializeAccessibilityNodeInfoInternal(info); + } + } + /** + * @see #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) + * + * Note: Called from the default {@link AccessibilityDelegate}. + */ + void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { + Rect bounds = mAttachInfo.mTmpInvalRect; + getDrawingRect(bounds); + info.setBoundsInParent(bounds); + int[] locationOnScreen = mAttachInfo.mInvalidateChildLocation; + getLocationOnScreen(locationOnScreen); + bounds.offsetTo(0, 0); + bounds.offset(locationOnScreen[0], locationOnScreen[1]); + info.setBoundsInScreen(bounds); + if ((mPrivateFlags & IS_ROOT_NAMESPACE) == 0) { + ViewParent parent = getParent(); + if (parent instanceof View) { + View parentView = (View) parent; + info.setParent(parentView); + } + } + info.setPackageName(mContext.getPackageName()); + info.setClassName(View.class.getName()); + info.setContentDescription(getContentDescription()); + info.setEnabled(isEnabled()); + info.setClickable(isClickable()); + info.setFocusable(isFocusable()); + info.setFocused(isFocused()); + info.setSelected(isSelected()); + info.setLongClickable(isLongClickable()); + // TODO: These make sense only if we are in an AdapterView but all + // views can be selected. Maybe from accessiiblity perspective + // we should report as selectable view in an AdapterView. + info.addAction(AccessibilityNodeInfo.ACTION_SELECT); + info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_SELECTION); + if (isFocusable()) { + if (isFocused()) { + info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS); + } else { + info.addAction(AccessibilityNodeInfo.ACTION_FOCUS); + } + } + } + /** + * Sets a delegate for implementing accessibility support via compositon as + * opposed to inheritance. The delegate's primary use is for implementing + * backwards compatible widgets. For more details see {@link AccessibilityDelegate}. + * + * @param delegate The delegate instance. + * + * @see AccessibilityDelegate + */ + public void setAccessibilityDelegate(AccessibilityDelegate delegate) { + mAccessibilityDelegate = delegate; + } + /** + * Gets the provider for managing a virtual view hierarchy rooted at this View + * and reported to {@link android.accessibilityservice.AccessibilityService}s + * that explore the window content. + *

+ * If this method returns an instance, this instance is responsible for managing + * {@link AccessibilityNodeInfo}s describing the virtual sub-tree rooted at this + * View including the one representing the View itself. Similarly the returned + * instance is responsible for performing accessibility actions on any virtual + * view or the root view itself. + *

+ *

+ * If an {@link AccessibilityDelegate} has been specified via calling + * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its + * {@link AccessibilityDelegate#getAccessibilityNodeProvider(View)} + * is responsible for handling this call. + *

+ * + * @return The provider. + * + * @see AccessibilityNodeProvider + */ + public AccessibilityNodeProvider getAccessibilityNodeProvider() { + if (mAccessibilityDelegate != null) { + return mAccessibilityDelegate.getAccessibilityNodeProvider(this); + } else { + return null; + } + } + /** + * Gets the unique identifier of this view on the screen for accessibility purposes. + * If this {@link View} is not attached to any window, {@value #NO_ID} is returned. + * + * @return The view accessibility id. + * + * @hide + */ + public int getAccessibilityViewId() { + if (mAccessibilityViewId == NO_ID) { + mAccessibilityViewId = sNextAccessibilityViewId++; + } + return mAccessibilityViewId; + } + /** + * Gets the unique identifier of the window in which this View reseides. + * + * @return The window accessibility id. + * + * @hide + */ + public int getAccessibilityWindowId() { + return mAttachInfo != null ? mAttachInfo.mAccessibilityWindowId : NO_ID; + } + /** + * Gets the {@link View} description. It briefly describes the view and is + * primarily used for accessibility support. Set this property to enable + * better accessibility support for your application. This is especially + * true for views that do not have textual representation (For example, + * ImageButton). + * + * @return The content descriptiopn. + * + * @attr ref android.R.styleable#View_contentDescription + */ + public CharSequence getContentDescription() { + return mContentDescription; + } + /** + * Sets the {@link View} description. It briefly describes the view and is + * primarily used for accessibility support. Set this property to enable + * better accessibility support for your application. This is especially + * true for views that do not have textual representation (For example, + * ImageButton). + * + * @param contentDescription The content description. + * + * @attr ref android.R.styleable#View_contentDescription + */ + @RemotableViewMethod + public void setContentDescription(CharSequence contentDescription) { + mContentDescription = contentDescription; + } + /** + * Invoked whenever this view loses focus, either by losing window focus or by losing + * focus within its window. This method can be used to clear any state tied to the + * focus. For instance, if a button is held pressed with the trackball and the window + * loses focus, this method can be used to cancel the press. + * + * Subclasses of View overriding this method should always call super.onFocusLost(). + * + * @see #onFocusChanged(boolean, int, android.graphics.Rect) + * @see #onWindowFocusChanged(boolean) + * + * @hide pending API council approval + */ + protected void onFocusLost() { + resetPressedState(); + } + private void resetPressedState() { + if ((mViewFlags & ENABLED_MASK) == DISABLED) { + return; + } + if (isPressed()) { + setPressed(false); + if (!mHasPerformedLongPress) { + removeLongPressCallback(); + } + } + } + /** + * Returns true if this view has focus + * + * @return True if this view has focus, false otherwise. + */ + @ViewDebug.ExportedProperty(category = "focus") + public boolean isFocused() { + return (mPrivateFlags & FOCUSED) != 0; + } + /** + * Find the view in the hierarchy rooted at this view that currently has + * focus. + * + * @return The view that currently has focus, or null if no focused view can + * be found. + */ + public View findFocus() { + return (mPrivateFlags & FOCUSED) != 0 ? this : null; + } + /** + * Change whether this view is one of the set of scrollable containers in + * its window. This will be used to determine whether the window can + * resize or must pan when a soft input area is open -- scrollable + * containers allow the window to use resize mode since the container + * will appropriately shrink. + */ + public void setScrollContainer(boolean isScrollContainer) { + if (isScrollContainer) { + if (mAttachInfo != null && (mPrivateFlags&SCROLL_CONTAINER_ADDED) == 0) { + mAttachInfo.mScrollContainers.add(this); + mPrivateFlags |= SCROLL_CONTAINER_ADDED; + } + mPrivateFlags |= SCROLL_CONTAINER; + } else { + if ((mPrivateFlags&SCROLL_CONTAINER_ADDED) != 0) { + mAttachInfo.mScrollContainers.remove(this); + } + mPrivateFlags &= ~(SCROLL_CONTAINER|SCROLL_CONTAINER_ADDED); + } + } + /** + * Returns the quality of the drawing cache. + * + * @return One of {@link #DRAWING_CACHE_QUALITY_AUTO}, + * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} + * + * @see #setDrawingCacheQuality(int) + * @see #setDrawingCacheEnabled(boolean) + * @see #isDrawingCacheEnabled() + * + * @attr ref android.R.styleable#View_drawingCacheQuality + */ + public int getDrawingCacheQuality() { + return mViewFlags & DRAWING_CACHE_QUALITY_MASK; + } + /** + * Set the drawing cache quality of this view. This value is used only when the + * drawing cache is enabled + * + * @param quality One of {@link #DRAWING_CACHE_QUALITY_AUTO}, + * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} + * + * @see #getDrawingCacheQuality() + * @see #setDrawingCacheEnabled(boolean) + * @see #isDrawingCacheEnabled() + * + * @attr ref android.R.styleable#View_drawingCacheQuality + */ + public void setDrawingCacheQuality(int quality) { + setFlags(quality, DRAWING_CACHE_QUALITY_MASK); + } + /** + * Returns whether the screen should remain on, corresponding to the current + * value of {@link #KEEP_SCREEN_ON}. + * + * @return Returns true if {@link #KEEP_SCREEN_ON} is set. + * + * @see #setKeepScreenOn(boolean) + * + * @attr ref android.R.styleable#View_keepScreenOn + */ + public boolean getKeepScreenOn() { + return (mViewFlags & KEEP_SCREEN_ON) != 0; + } + /** + * Controls whether the screen should remain on, modifying the + * value of {@link #KEEP_SCREEN_ON}. + * + * @param keepScreenOn Supply true to set {@link #KEEP_SCREEN_ON}. + * + * @see #getKeepScreenOn() + * + * @attr ref android.R.styleable#View_keepScreenOn + */ + public void setKeepScreenOn(boolean keepScreenOn) { + setFlags(keepScreenOn ? KEEP_SCREEN_ON : 0, KEEP_SCREEN_ON); + } + /** + * Gets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. + * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. + * + * @attr ref android.R.styleable#View_nextFocusLeft + */ + public int getNextFocusLeftId() { + return mNextFocusLeftId; + } + /** + * Sets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. + * @param nextFocusLeftId The next focus ID, or {@link #NO_ID} if the framework should + * decide automatically. + * + * @attr ref android.R.styleable#View_nextFocusLeft + */ + public void setNextFocusLeftId(int nextFocusLeftId) { + mNextFocusLeftId = nextFocusLeftId; + } + /** + * Gets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. + * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. + * + * @attr ref android.R.styleable#View_nextFocusRight + */ + public int getNextFocusRightId() { + return mNextFocusRightId; + } + /** + * Sets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. + * @param nextFocusRightId The next focus ID, or {@link #NO_ID} if the framework should + * decide automatically. + * + * @attr ref android.R.styleable#View_nextFocusRight + */ + public void setNextFocusRightId(int nextFocusRightId) { + mNextFocusRightId = nextFocusRightId; + } + /** + * Gets the id of the view to use when the next focus is {@link #FOCUS_UP}. + * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. + * + * @attr ref android.R.styleable#View_nextFocusUp + */ + public int getNextFocusUpId() { + return mNextFocusUpId; + } + /** + * Sets the id of the view to use when the next focus is {@link #FOCUS_UP}. + * @param nextFocusUpId The next focus ID, or {@link #NO_ID} if the framework should + * decide automatically. + * + * @attr ref android.R.styleable#View_nextFocusUp + */ + public void setNextFocusUpId(int nextFocusUpId) { + mNextFocusUpId = nextFocusUpId; + } + /** + * Gets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. + * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. + * + * @attr ref android.R.styleable#View_nextFocusDown + */ + public int getNextFocusDownId() { + return mNextFocusDownId; + } + /** + * Sets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. + * @param nextFocusDownId The next focus ID, or {@link #NO_ID} if the framework should + * decide automatically. + * + * @attr ref android.R.styleable#View_nextFocusDown + */ + public void setNextFocusDownId(int nextFocusDownId) { + mNextFocusDownId = nextFocusDownId; + } + /** + * Gets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. + * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. + * + * @attr ref android.R.styleable#View_nextFocusForward + */ + public int getNextFocusForwardId() { + return mNextFocusForwardId; + } + /** + * Sets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. + * @param nextFocusForwardId The next focus ID, or {@link #NO_ID} if the framework should + * decide automatically. + * + * @attr ref android.R.styleable#View_nextFocusForward + */ + public void setNextFocusForwardId(int nextFocusForwardId) { + mNextFocusForwardId = nextFocusForwardId; + } + /** + * Returns the visibility of this view and all of its ancestors + * + * @return True if this view and all of its ancestors are {@link #VISIBLE} + */ + public boolean isShown() { + View current = this; + //noinspection ConstantConditions + do { + if ((current.mViewFlags & VISIBILITY_MASK) != VISIBLE) { + return false; + } + ViewParent parent = current.mParent; + if (parent == null) { + return false; // We are not attached to the view root + } + if (!(parent instanceof View)) { + return true; + } + current = (View) parent; + } while (current != null); + return false; + } + /** + * Apply the insets for system windows to this view, if the FITS_SYSTEM_WINDOWS flag + * is set + * + * @param insets Insets for system windows + * + * @return True if this view applied the insets, false otherwise + */ + protected boolean fitSystemWindows(Rect insets) { + if ((mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS) { + mPaddingLeft = insets.left; + mPaddingTop = insets.top; + mPaddingRight = insets.right; + mPaddingBottom = insets.bottom; + requestLayout(); + return true; + } + return false; + } + /** + * Set whether or not this view should account for system screen decorations + * such as the status bar and inset its content. This allows this view to be + * positioned in absolute screen coordinates and remain visible to the user. + * + *

This should only be used by top-level window decor views. + * + * @param fitSystemWindows true to inset content for system screen decorations, false for + * default behavior. + * + * @attr ref android.R.styleable#View_fitsSystemWindows + */ + public void setFitsSystemWindows(boolean fitSystemWindows) { + setFlags(fitSystemWindows ? FITS_SYSTEM_WINDOWS : 0, FITS_SYSTEM_WINDOWS); + } + /** + * Check for the FITS_SYSTEM_WINDOWS flag. If this method returns true, this view + * will account for system screen decorations such as the status bar and inset its + * content. This allows the view to be positioned in absolute screen coordinates + * and remain visible to the user. + * + * @return true if this view will adjust its content bounds for system screen decorations. + * + * @attr ref android.R.styleable#View_fitsSystemWindows + */ + public boolean fitsSystemWindows() { + return (mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS; + } + /** + * Returns the visibility status for this view. + * + * @return One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. + * @attr ref android.R.styleable#View_visibility + */ + @ViewDebug.ExportedProperty(mapping = { + @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"), + @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), + @ViewDebug.IntToString(from = GONE, to = "GONE") + }) + public int getVisibility() { + return mViewFlags & VISIBILITY_MASK; + } + /** + * Set the enabled state of this view. + * + * @param visibility One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. + * @attr ref android.R.styleable#View_visibility + */ + @RemotableViewMethod + public void setVisibility(int visibility) { + setFlags(visibility, VISIBILITY_MASK); + if (mBGDrawable != null) mBGDrawable.setVisible(visibility == VISIBLE, false); + } + /** + * Returns the enabled status for this view. The interpretation of the + * enabled state varies by subclass. + * + * @return True if this view is enabled, false otherwise. + */ + @ViewDebug.ExportedProperty + public boolean isEnabled() { + return (mViewFlags & ENABLED_MASK) == ENABLED; + } + /** + * Set the enabled state of this view. The interpretation of the enabled + * state varies by subclass. + * + * @param enabled True if this view is enabled, false otherwise. + */ + @RemotableViewMethod + public void setEnabled(boolean enabled) { + if (enabled == isEnabled()) return; + setFlags(enabled ? ENABLED : DISABLED, ENABLED_MASK); + /* + * The View most likely has to change its appearance, so refresh + * the drawable state. + */ + refreshDrawableState(); + // Invalidate too, since the default behavior for views is to be + // be drawn at 50% alpha rather than to change the drawable. + invalidate(true); + } + /** + * Set whether this view can receive the focus. + * + * Setting this to false will also ensure that this view is not focusable + * in touch mode. + * + * @param focusable If true, this view can receive the focus. + * + * @see #setFocusableInTouchMode(boolean) + * @attr ref android.R.styleable#View_focusable + */ + public void setFocusable(boolean focusable) { + if (!focusable) { + setFlags(0, FOCUSABLE_IN_TOUCH_MODE); + } + setFlags(focusable ? FOCUSABLE : NOT_FOCUSABLE, FOCUSABLE_MASK); + } + /** + * Set whether this view can receive focus while in touch mode. + * + * Setting this to true will also ensure that this view is focusable. + * + * @param focusableInTouchMode If true, this view can receive the focus while + * in touch mode. + * + * @see #setFocusable(boolean) + * @attr ref android.R.styleable#View_focusableInTouchMode + */ + public void setFocusableInTouchMode(boolean focusableInTouchMode) { + // Focusable in touch mode should always be set before the focusable flag + // otherwise, setting the focusable flag will trigger a focusableViewAvailable() + // which, in touch mode, will not successfully request focus on this view + // because the focusable in touch mode flag is not set + setFlags(focusableInTouchMode ? FOCUSABLE_IN_TOUCH_MODE : 0, FOCUSABLE_IN_TOUCH_MODE); + if (focusableInTouchMode) { + setFlags(FOCUSABLE, FOCUSABLE_MASK); + } + } + /** + * Set whether this view should have sound effects enabled for events such as + * clicking and touching. + * + *

You may wish to disable sound effects for a view if you already play sounds, + * for instance, a dial key that plays dtmf tones. + * + * @param soundEffectsEnabled whether sound effects are enabled for this view. + * @see #isSoundEffectsEnabled() + * @see #playSoundEffect(int) + * @attr ref android.R.styleable#View_soundEffectsEnabled + */ + public void setSoundEffectsEnabled(boolean soundEffectsEnabled) { + setFlags(soundEffectsEnabled ? SOUND_EFFECTS_ENABLED: 0, SOUND_EFFECTS_ENABLED); + } + /** + * @return whether this view should have sound effects enabled for events such as + * clicking and touching. + * + * @see #setSoundEffectsEnabled(boolean) + * @see #playSoundEffect(int) + * @attr ref android.R.styleable#View_soundEffectsEnabled + */ + @ViewDebug.ExportedProperty + public boolean isSoundEffectsEnabled() { + return SOUND_EFFECTS_ENABLED == (mViewFlags & SOUND_EFFECTS_ENABLED); + } + /** + * Set whether this view should have haptic feedback for events such as + * long presses. + * + *

You may wish to disable haptic feedback if your view already controls + * its own haptic feedback. + * + * @param hapticFeedbackEnabled whether haptic feedback enabled for this view. + * @see #isHapticFeedbackEnabled() + * @see #performHapticFeedback(int) + * @attr ref android.R.styleable#View_hapticFeedbackEnabled + */ + public void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled) { + setFlags(hapticFeedbackEnabled ? HAPTIC_FEEDBACK_ENABLED: 0, HAPTIC_FEEDBACK_ENABLED); + } + /** + * @return whether this view should have haptic feedback enabled for events + * long presses. + * + * @see #setHapticFeedbackEnabled(boolean) + * @see #performHapticFeedback(int) + * @attr ref android.R.styleable#View_hapticFeedbackEnabled + */ + @ViewDebug.ExportedProperty + public boolean isHapticFeedbackEnabled() { + return HAPTIC_FEEDBACK_ENABLED == (mViewFlags & HAPTIC_FEEDBACK_ENABLED); + } + /** + * Returns the layout direction for this view. + * + * @return One of {@link #LAYOUT_DIRECTION_LTR}, + * {@link #LAYOUT_DIRECTION_RTL}, + * {@link #LAYOUT_DIRECTION_INHERIT} or + * {@link #LAYOUT_DIRECTION_LOCALE}. + * @attr ref android.R.styleable#View_layoutDirection + * + * @hide + */ + @ViewDebug.ExportedProperty(category = "layout", mapping = { + @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "LTR"), + @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RTL"), + @ViewDebug.IntToString(from = LAYOUT_DIRECTION_INHERIT, to = "INHERIT"), + @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LOCALE, to = "LOCALE") + }) + public int getLayoutDirection() { + return mViewFlags & LAYOUT_DIRECTION_MASK; + } + /** + * Set the layout direction for this view. This will propagate a reset of layout direction + * resolution to the view's children and resolve layout direction for this view. + * + * @param layoutDirection One of {@link #LAYOUT_DIRECTION_LTR}, + * {@link #LAYOUT_DIRECTION_RTL}, + * {@link #LAYOUT_DIRECTION_INHERIT} or + * {@link #LAYOUT_DIRECTION_LOCALE}. + * + * @attr ref android.R.styleable#View_layoutDirection + * + * @hide + */ + @RemotableViewMethod + public void setLayoutDirection(int layoutDirection) { + if (getLayoutDirection() != layoutDirection) { + resetResolvedLayoutDirection(); + // Setting the flag will also request a layout. + setFlags(layoutDirection, LAYOUT_DIRECTION_MASK); + } + } + /** + * Returns the resolved layout direction for this view. + * + * @return {@link #LAYOUT_DIRECTION_RTL} if the layout direction is RTL or returns + * {@link #LAYOUT_DIRECTION_LTR} id the layout direction is not RTL. + * + * @hide + */ + @ViewDebug.ExportedProperty(category = "layout", mapping = { + @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"), + @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL") + }) + public int getResolvedLayoutDirection() { + resolveLayoutDirectionIfNeeded(); + return ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED_RTL) == LAYOUT_DIRECTION_RESOLVED_RTL) ? + LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR; + } + /** + *

Indicates whether or not this view's layout is right-to-left. This is resolved from + * layout attribute and/or the inherited value from the parent.

+ * + * @return true if the layout is right-to-left. + * + * @hide + */ + @ViewDebug.ExportedProperty(category = "layout") + public boolean isLayoutRtl() { + return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL); + } + /** + * If this view doesn't do any drawing on its own, set this flag to + * allow further optimizations. By default, this flag is not set on + * View, but could be set on some View subclasses such as ViewGroup. + * + * Typically, if you override {@link #onDraw(android.graphics.Canvas)} + * you should clear this flag. + * + * @param willNotDraw whether or not this View draw on its own + */ + public void setWillNotDraw(boolean willNotDraw) { + setFlags(willNotDraw ? WILL_NOT_DRAW : 0, DRAW_MASK); + } + /** + * Returns whether or not this View draws on its own. + * + * @return true if this view has nothing to draw, false otherwise + */ + @ViewDebug.ExportedProperty(category = "drawing") + public boolean willNotDraw() { + return (mViewFlags & DRAW_MASK) == WILL_NOT_DRAW; + } + /** + * When a View's drawing cache is enabled, drawing is redirected to an + * offscreen bitmap. Some views, like an ImageView, must be able to + * bypass this mechanism if they already draw a single bitmap, to avoid + * unnecessary usage of the memory. + * + * @param willNotCacheDrawing true if this view does not cache its + * drawing, false otherwise + */ + public void setWillNotCacheDrawing(boolean willNotCacheDrawing) { + setFlags(willNotCacheDrawing ? WILL_NOT_CACHE_DRAWING : 0, WILL_NOT_CACHE_DRAWING); + } + /** + * Returns whether or not this View can cache its drawing or not. + * + * @return true if this view does not cache its drawing, false otherwise + */ + @ViewDebug.ExportedProperty(category = "drawing") + public boolean willNotCacheDrawing() { + return (mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING; + } + /** + * Indicates whether this view reacts to click events or not. + * + * @return true if the view is clickable, false otherwise + * + * @see #setClickable(boolean) + * @attr ref android.R.styleable#View_clickable + */ + @ViewDebug.ExportedProperty + public boolean isClickable() { + return (mViewFlags & CLICKABLE) == CLICKABLE; + } + /** + * Enables or disables click events for this view. When a view + * is clickable it will change its state to "pressed" on every click. + * Subclasses should set the view clickable to visually react to + * user's clicks. + * + * @param clickable true to make the view clickable, false otherwise + * + * @see #isClickable() + * @attr ref android.R.styleable#View_clickable + */ + public void setClickable(boolean clickable) { + setFlags(clickable ? CLICKABLE : 0, CLICKABLE); + } + /** + * Indicates whether this view reacts to long click events or not. + * + * @return true if the view is long clickable, false otherwise + * + * @see #setLongClickable(boolean) + * @attr ref android.R.styleable#View_longClickable + */ + public boolean isLongClickable() { + return (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; + } + /** + * Enables or disables long click events for this view. When a view is long + * clickable it reacts to the user holding down the button for a longer + * duration than a tap. This event can either launch the listener or a + * context menu. + * + * @param longClickable true to make the view long clickable, false otherwise + * @see #isLongClickable() + * @attr ref android.R.styleable#View_longClickable + */ + public void setLongClickable(boolean longClickable) { + setFlags(longClickable ? LONG_CLICKABLE : 0, LONG_CLICKABLE); + } + /** + * Sets the pressed state for this view. + * + * @see #isClickable() + * @see #setClickable(boolean) + * + * @param pressed Pass true to set the View's internal state to "pressed", or false to reverts + * the View's internal state from a previously set "pressed" state. + */ + public void setPressed(boolean pressed) { + if (pressed) { + mPrivateFlags |= PRESSED; + } else { + mPrivateFlags &= ~PRESSED; + } + refreshDrawableState(); + dispatchSetPressed(pressed); + } + /** + * Dispatch setPressed to all of this View's children. + * + * @see #setPressed(boolean) + * + * @param pressed The new pressed state + */ + protected void dispatchSetPressed(boolean pressed) { + } + /** + * Indicates whether the view is currently in pressed state. Unless + * {@link #setPressed(boolean)} is explicitly called, only clickable views can enter + * the pressed state. + * + * @see #setPressed(boolean) + * @see #isClickable() + * @see #setClickable(boolean) + * + * @return true if the view is currently pressed, false otherwise + */ + public boolean isPressed() { + return (mPrivateFlags & PRESSED) == PRESSED; + } + /** + * Indicates whether this view will save its state (that is, + * whether its {@link #onSaveInstanceState} method will be called). + * + * @return Returns true if the view state saving is enabled, else false. + * + * @see #setSaveEnabled(boolean) + * @attr ref android.R.styleable#View_saveEnabled + */ + public boolean isSaveEnabled() { + return (mViewFlags & SAVE_DISABLED_MASK) != SAVE_DISABLED; + } + /** + * Controls whether the saving of this view's state is + * enabled (that is, whether its {@link #onSaveInstanceState} method + * will be called). Note that even if freezing is enabled, the + * view still must have an id assigned to it (via {@link #setId(int)}) + * for its state to be saved. This flag can only disable the + * saving of this view; any child views may still have their state saved. + * + * @param enabled Set to false to disable state saving, or true + * (the default) to allow it. + * + * @see #isSaveEnabled() + * @see #setId(int) + * @see #onSaveInstanceState() + * @attr ref android.R.styleable#View_saveEnabled + */ + public void setSaveEnabled(boolean enabled) { + setFlags(enabled ? 0 : SAVE_DISABLED, SAVE_DISABLED_MASK); + } + /** + * Gets whether the framework should discard touches when the view's + * window is obscured by another visible window. + * Refer to the {@link View} security documentation for more details. + * + * @return True if touch filtering is enabled. + * + * @see #setFilterTouchesWhenObscured(boolean) + * @attr ref android.R.styleable#View_filterTouchesWhenObscured + */ + @ViewDebug.ExportedProperty + public boolean getFilterTouchesWhenObscured() { + return (mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0; + } + /** + * Sets whether the framework should discard touches when the view's + * window is obscured by another visible window. + * Refer to the {@link View} security documentation for more details. + * + * @param enabled True if touch filtering should be enabled. + * + * @see #getFilterTouchesWhenObscured + * @attr ref android.R.styleable#View_filterTouchesWhenObscured + */ + public void setFilterTouchesWhenObscured(boolean enabled) { + setFlags(enabled ? 0 : FILTER_TOUCHES_WHEN_OBSCURED, + FILTER_TOUCHES_WHEN_OBSCURED); + } + /** + * Indicates whether the entire hierarchy under this view will save its + * state when a state saving traversal occurs from its parent. The default + * is true; if false, these views will not be saved unless + * {@link #saveHierarchyState(SparseArray)} is called directly on this view. + * + * @return Returns true if the view state saving from parent is enabled, else false. + * + * @see #setSaveFromParentEnabled(boolean) + */ + public boolean isSaveFromParentEnabled() { + return (mViewFlags & PARENT_SAVE_DISABLED_MASK) != PARENT_SAVE_DISABLED; + } + /** + * Controls whether the entire hierarchy under this view will save its + * state when a state saving traversal occurs from its parent. The default + * is true; if false, these views will not be saved unless + * {@link #saveHierarchyState(SparseArray)} is called directly on this view. + * + * @param enabled Set to false to disable state saving, or true + * (the default) to allow it. + * + * @see #isSaveFromParentEnabled() + * @see #setId(int) + * @see #onSaveInstanceState() + */ + public void setSaveFromParentEnabled(boolean enabled) { + setFlags(enabled ? 0 : PARENT_SAVE_DISABLED, PARENT_SAVE_DISABLED_MASK); + } + /** + * Returns whether this View is able to take focus. + * + * @return True if this view can take focus, or false otherwise. + * @attr ref android.R.styleable#View_focusable + */ + @ViewDebug.ExportedProperty(category = "focus") + public final boolean isFocusable() { + return FOCUSABLE == (mViewFlags & FOCUSABLE_MASK); + } + /** + * When a view is focusable, it may not want to take focus when in touch mode. + * For example, a button would like focus when the user is navigating via a D-pad + * so that the user can click on it, but once the user starts touching the screen, + * the button shouldn't take focus + * @return Whether the view is focusable in touch mode. + * @attr ref android.R.styleable#View_focusableInTouchMode + */ + @ViewDebug.ExportedProperty + public final boolean isFocusableInTouchMode() { + return FOCUSABLE_IN_TOUCH_MODE == (mViewFlags & FOCUSABLE_IN_TOUCH_MODE); + } + /** + * Find the nearest view in the specified direction that can take focus. + * This does not actually give focus to that view. + * + * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT + * + * @return The nearest focusable in the specified direction, or null if none + * can be found. + */ + public View focusSearch(int direction) { + if (mParent != null) { + return mParent.focusSearch(this, direction); + } else { + return null; + } + } + /** + * This method is the last chance for the focused view and its ancestors to + * respond to an arrow key. This is called when the focused view did not + * consume the key internally, nor could the view system find a new view in + * the requested direction to give focus to. + * + * @param focused The currently focused view. + * @param direction The direction focus wants to move. One of FOCUS_UP, + * FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT. + * @return True if the this view consumed this unhandled move. + */ + public boolean dispatchUnhandledMove(View focused, int direction) { + return false; + } + /** + * If a user manually specified the next view id for a particular direction, + * use the root to look up the view. + * @param root The root view of the hierarchy containing this view. + * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, + * or FOCUS_BACKWARD. + * @return The user specified next view, or null if there is none. + */ + View findUserSetNextFocus(View root, int direction) { + switch (direction) { + case FOCUS_LEFT: + if (mNextFocusLeftId == View.NO_ID) return null; + return findViewInsideOutShouldExist(root, mNextFocusLeftId); + case FOCUS_RIGHT: + if (mNextFocusRightId == View.NO_ID) return null; + return findViewInsideOutShouldExist(root, mNextFocusRightId); + case FOCUS_UP: + if (mNextFocusUpId == View.NO_ID) return null; + return findViewInsideOutShouldExist(root, mNextFocusUpId); + case FOCUS_DOWN: + if (mNextFocusDownId == View.NO_ID) return null; + return findViewInsideOutShouldExist(root, mNextFocusDownId); + case FOCUS_FORWARD: + if (mNextFocusForwardId == View.NO_ID) return null; + return findViewInsideOutShouldExist(root, mNextFocusForwardId); + case FOCUS_BACKWARD: { + final int id = mID; + return root.findViewByPredicateInsideOut(this, new Predicate() { + @Override + public boolean apply(View t) { + return t.mNextFocusForwardId == id; + } + }); + } + } + return null; + } + private View findViewInsideOutShouldExist(View root, final int childViewId) { + View result = root.findViewByPredicateInsideOut(this, new Predicate() { + @Override + public boolean apply(View t) { + return t.mID == childViewId; + } + }); + if (result == null) { + Log.w(VIEW_LOG_TAG, "couldn't find next focus view specified " + + "by user for id " + childViewId); + } + return result; + } + /** + * Find and return all focusable views that are descendants of this view, + * possibly including this view if it is focusable itself. + * + * @param direction The direction of the focus + * @return A list of focusable views + */ + public ArrayList getFocusables(int direction) { + ArrayList result = new ArrayList(24); + addFocusables(result, direction); + return result; + } + /** + * Add any focusable views that are descendants of this view (possibly + * including this view if it is focusable itself) to views. If we are in touch mode, + * only add views that are also focusable in touch mode. + * + * @param views Focusable views found so far + * @param direction The direction of the focus + */ + public void addFocusables(ArrayList views, int direction) { + addFocusables(views, direction, FOCUSABLES_TOUCH_MODE); + } + /** + * Adds any focusable views that are descendants of this view (possibly + * including this view if it is focusable itself) to views. This method + * adds all focusable views regardless if we are in touch mode or + * only views focusable in touch mode if we are in touch mode depending on + * the focusable mode paramater. + * + * @param views Focusable views found so far or null if all we are interested is + * the number of focusables. + * @param direction The direction of the focus. + * @param focusableMode The type of focusables to be added. + * + * @see #FOCUSABLES_ALL + * @see #FOCUSABLES_TOUCH_MODE + */ + public void addFocusables(ArrayList views, int direction, int focusableMode) { + if (!isFocusable()) { + return; + } + if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE && + isInTouchMode() && !isFocusableInTouchMode()) { + return; + } + if (views != null) { + views.add(this); + } + } + /** + * Finds the Views that contain given text. The containment is case insensitive. + * The search is performed by either the text that the View renders or the content + * description that describes the view for accessibility purposes and the view does + * not render or both. Clients can specify how the search is to be performed via + * passing the {@link #FIND_VIEWS_WITH_TEXT} and + * {@link #FIND_VIEWS_WITH_CONTENT_DESCRIPTION} flags. + * + * @param outViews The output list of matching Views. + * @param searched The text to match against. + * + * @see #FIND_VIEWS_WITH_TEXT + * @see #FIND_VIEWS_WITH_CONTENT_DESCRIPTION + * @see #setContentDescription(CharSequence) + */ + public void findViewsWithText(ArrayList outViews, CharSequence searched, int flags) { + if (getAccessibilityNodeProvider() != null) { + if ((flags & FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS) != 0) { + outViews.add(this); + } + } else if ((flags & FIND_VIEWS_WITH_CONTENT_DESCRIPTION) != 0 + && !TextUtils.isEmpty(searched) && !TextUtils.isEmpty(mContentDescription)) { + String searchedLowerCase = searched.toString().toLowerCase(); + String contentDescriptionLowerCase = mContentDescription.toString().toLowerCase(); + if (contentDescriptionLowerCase.contains(searchedLowerCase)) { + outViews.add(this); + } + } + } + /** + * Find and return all touchable views that are descendants of this view, + * possibly including this view if it is touchable itself. + * + * @return A list of touchable views + */ + public ArrayList getTouchables() { + ArrayList result = new ArrayList(); + addTouchables(result); + return result; + } + /** + * Add any touchable views that are descendants of this view (possibly + * including this view if it is touchable itself) to views. + * + * @param views Touchable views found so far + */ + public void addTouchables(ArrayList views) { + final int viewFlags = mViewFlags; + if (((viewFlags & CLICKABLE) == CLICKABLE || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) + && (viewFlags & ENABLED_MASK) == ENABLED) { + views.add(this); + } + } + /** + * Call this to try to give focus to a specific view or to one of its + * descendants. + * + * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns + * false), or if it is focusable and it is not focusable in touch mode + * ({@link #isFocusableInTouchMode}) while the device is in touch mode. + * + * See also {@link #focusSearch(int)}, which is what you call to say that you + * have focus, and you want your parent to look for the next one. + * + * This is equivalent to calling {@link #requestFocus(int, Rect)} with arguments + * {@link #FOCUS_DOWN} and null. + * + * @return Whether this view or one of its descendants actually took focus. + */ + public final boolean requestFocus() { + return requestFocus(View.FOCUS_DOWN); + } + /** + * Call this to try to give focus to a specific view or to one of its + * descendants and give it a hint about what direction focus is heading. + * + * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns + * false), or if it is focusable and it is not focusable in touch mode + * ({@link #isFocusableInTouchMode}) while the device is in touch mode. + * + * See also {@link #focusSearch(int)}, which is what you call to say that you + * have focus, and you want your parent to look for the next one. + * + * This is equivalent to calling {@link #requestFocus(int, Rect)} with + * null set for the previously focused rectangle. + * + * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT + * @return Whether this view or one of its descendants actually took focus. + */ + public final boolean requestFocus(int direction) { + return requestFocus(direction, null); + } + /** + * Call this to try to give focus to a specific view or to one of its descendants + * and give it hints about the direction and a specific rectangle that the focus + * is coming from. The rectangle can help give larger views a finer grained hint + * about where focus is coming from, and therefore, where to show selection, or + * forward focus change internally. + * + * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns + * false), or if it is focusable and it is not focusable in touch mode + * ({@link #isFocusableInTouchMode}) while the device is in touch mode. + * + * A View will not take focus if it is not visible. + * + * A View will not take focus if one of its parents has + * {@link android.view.ViewGroup#getDescendantFocusability()} equal to + * {@link ViewGroup#FOCUS_BLOCK_DESCENDANTS}. + * + * See also {@link #focusSearch(int)}, which is what you call to say that you + * have focus, and you want your parent to look for the next one. + * + * You may wish to override this method if your custom {@link View} has an internal + * {@link View} that it wishes to forward the request to. + * + * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT + * @param previouslyFocusedRect The rectangle (in this View's coordinate system) + * to give a finer grained hint about where focus is coming from. May be null + * if there is no hint. + * @return Whether this view or one of its descendants actually took focus. + */ + public boolean requestFocus(int direction, Rect previouslyFocusedRect) { + // need to be focusable + if ((mViewFlags & FOCUSABLE_MASK) != FOCUSABLE || + (mViewFlags & VISIBILITY_MASK) != VISIBLE) { + return false; + } + // need to be focusable in touch mode if in touch mode + if (isInTouchMode() && + (FOCUSABLE_IN_TOUCH_MODE != (mViewFlags & FOCUSABLE_IN_TOUCH_MODE))) { + return false; + } + // need to not have any parents blocking us + if (hasAncestorThatBlocksDescendantFocus()) { + return false; + } + handleFocusGainInternal(direction, previouslyFocusedRect); + return true; + } + /** + * Call this to try to give focus to a specific view or to one of its descendants. This is a + * special variant of {@link #requestFocus() } that will allow views that are not focuable in + * touch mode to request focus when they are touched. + * + * @return Whether this view or one of its descendants actually took focus. + * + * @see #isInTouchMode() + * + */ + public final boolean requestFocusFromTouch() { + // Leave touch mode if we need to + if (isInTouchMode()) { + ViewRootImpl viewRoot = getViewRootImpl(); + if (viewRoot != null) { + viewRoot.ensureTouchMode(false); + } + } + return requestFocus(View.FOCUS_DOWN); + } + /** + * @return Whether any ancestor of this view blocks descendant focus. + */ + private boolean hasAncestorThatBlocksDescendantFocus() { + ViewParent ancestor = mParent; + while (ancestor instanceof ViewGroup) { + final ViewGroup vgAncestor = (ViewGroup) ancestor; + if (vgAncestor.getDescendantFocusability() == ViewGroup.FOCUS_BLOCK_DESCENDANTS) { + return true; + } else { + ancestor = vgAncestor.getParent(); + } + } + return false; + } + /** + * @hide + */ + public void dispatchStartTemporaryDetach() { + onStartTemporaryDetach(); + } + /** + * This is called when a container is going to temporarily detach a child, with + * {@link ViewGroup#detachViewFromParent(View) ViewGroup.detachViewFromParent}. + * It will either be followed by {@link #onFinishTemporaryDetach()} or + * {@link #onDetachedFromWindow()} when the container is done. + */ + public void onStartTemporaryDetach() { + removeUnsetPressCallback(); + mPrivateFlags |= CANCEL_NEXT_UP_EVENT; + } + /** + * @hide + */ + public void dispatchFinishTemporaryDetach() { + onFinishTemporaryDetach(); + } + /** + * Called after {@link #onStartTemporaryDetach} when the container is done + * changing the view. + */ + public void onFinishTemporaryDetach() { + } + /** + * Return the global {@link KeyEvent.DispatcherState KeyEvent.DispatcherState} + * for this view's window. Returns null if the view is not currently attached + * to the window. Normally you will not need to use this directly, but + * just use the standard high-level event callbacks like + * {@link #onKeyDown(int, KeyEvent)}. + */ + public KeyEvent.DispatcherState getKeyDispatcherState() { + return mAttachInfo != null ? mAttachInfo.mKeyDispatchState : null; + } + /** + * Dispatch a key event before it is processed by any input method + * associated with the view hierarchy. This can be used to intercept + * key events in special situations before the IME consumes them; a + * typical example would be handling the BACK key to update the application's + * UI instead of allowing the IME to see it and close itself. + * + * @param event The key event to be dispatched. + * @return True if the event was handled, false otherwise. + */ + public boolean dispatchKeyEventPreIme(KeyEvent event) { + return onKeyPreIme(event.getKeyCode(), event); + } + /** + * Dispatch a key event to the next view on the focus path. This path runs + * from the top of the view tree down to the currently focused view. If this + * view has focus, it will dispatch to itself. Otherwise it will dispatch + * the next node down the focus path. This method also fires any key + * listeners. + * + * @param event The key event to be dispatched. + * @return True if the event was handled, false otherwise. + */ + public boolean dispatchKeyEvent(KeyEvent event) { + if (mInputEventConsistencyVerifier != null) { + mInputEventConsistencyVerifier.onKeyEvent(event, 0); + } + // Give any attached key listener a first crack at the event. + //noinspection SimplifiableIfStatement + ListenerInfo li = mListenerInfo; + if (li != null && li.mOnKeyListener != null && (mViewFlags & ENABLED_MASK) == ENABLED + && li.mOnKeyListener.onKey(this, event.getKeyCode(), event)) { + return true; + } + if (event.dispatch(this, mAttachInfo != null + ? mAttachInfo.mKeyDispatchState : null, this)) { + return true; + } + if (mInputEventConsistencyVerifier != null) { + mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); + } + return false; + } + /** + * Dispatches a key shortcut event. + * + * @param event The key event to be dispatched. + * @return True if the event was handled by the view, false otherwise. + */ + public boolean dispatchKeyShortcutEvent(KeyEvent event) { + return onKeyShortcut(event.getKeyCode(), event); + } + /** + * Pass the touch screen motion event down to the target view, or this + * view if it is the target. + * + * @param event The motion event to be dispatched. + * @return True if the event was handled by the view, false otherwise. + */ + public boolean dispatchTouchEvent(MotionEvent event) { + if (mInputEventConsistencyVerifier != null) { + mInputEventConsistencyVerifier.onTouchEvent(event, 0); + } + if (onFilterTouchEventForSecurity(event)) { + //noinspection SimplifiableIfStatement + ListenerInfo li = mListenerInfo; + if (li != null && li.mOnTouchListener != null && (mViewFlags & ENABLED_MASK) == ENABLED + && li.mOnTouchListener.onTouch(this, event)) { + return true; + } + if (onTouchEvent(event)) { + return true; + } + } + if (mInputEventConsistencyVerifier != null) { + mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); + } + return false; + } + /** + * Filter the touch event to apply security policies. + * + * @param event The motion event to be filtered. + * @return True if the event should be dispatched, false if the event should be dropped. + * + * @see #getFilterTouchesWhenObscured + */ + public boolean onFilterTouchEventForSecurity(MotionEvent event) { + //noinspection RedundantIfStatement + if ((mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0 + && (event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) { + // Window is obscured, drop this touch. + return false; + } + return true; + } + /** + * Pass a trackball motion event down to the focused view. + * + * @param event The motion event to be dispatched. + * @return True if the event was handled by the view, false otherwise. + */ + public boolean dispatchTrackballEvent(MotionEvent event) { + if (mInputEventConsistencyVerifier != null) { + mInputEventConsistencyVerifier.onTrackballEvent(event, 0); + } + return onTrackballEvent(event); + } + /** + * Dispatch a generic motion event. + *

+ * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} + * are delivered to the view under the pointer. All other generic motion events are + * delivered to the focused view. Hover events are handled specially and are delivered + * to {@link #onHoverEvent(MotionEvent)}. + *

+ * + * @param event The motion event to be dispatched. + * @return True if the event was handled by the view, false otherwise. + */ + public boolean dispatchGenericMotionEvent(MotionEvent event) { + if (mInputEventConsistencyVerifier != null) { + mInputEventConsistencyVerifier.onGenericMotionEvent(event, 0); + } + final int source = event.getSource(); + if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { + final int action = event.getAction(); + if (action == MotionEvent.ACTION_HOVER_ENTER + || action == MotionEvent.ACTION_HOVER_MOVE + || action == MotionEvent.ACTION_HOVER_EXIT) { + if (dispatchHoverEvent(event)) { + return true; + } + } else if (dispatchGenericPointerEvent(event)) { + return true; + } + } else if (dispatchGenericFocusedEvent(event)) { + return true; + } + if (dispatchGenericMotionEventInternal(event)) { + return true; + } + if (mInputEventConsistencyVerifier != null) { + mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); + } + return false; + } + private boolean dispatchGenericMotionEventInternal(MotionEvent event) { + //noinspection SimplifiableIfStatement + ListenerInfo li = mListenerInfo; + if (li != null && li.mOnGenericMotionListener != null + && (mViewFlags & ENABLED_MASK) == ENABLED + && li.mOnGenericMotionListener.onGenericMotion(this, event)) { + return true; + } + if (onGenericMotionEvent(event)) { + return true; + } + if (mInputEventConsistencyVerifier != null) { + mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); + } + return false; + } + /** + * Dispatch a hover event. + *

+ * Do not call this method directly. + * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. + *

+ * + * @param event The motion event to be dispatched. + * @return True if the event was handled by the view, false otherwise. + */ + protected boolean dispatchHoverEvent(MotionEvent event) { + //noinspection SimplifiableIfStatement + ListenerInfo li = mListenerInfo; + if (li != null && li.mOnHoverListener != null + && (mViewFlags & ENABLED_MASK) == ENABLED + && li.mOnHoverListener.onHover(this, event)) { + return true; + } + return onHoverEvent(event); + } + /** + * Returns true if the view has a child to which it has recently sent + * {@link MotionEvent#ACTION_HOVER_ENTER}. If this view is hovered and + * it does not have a hovered child, then it must be the innermost hovered view. + * @hide + */ + protected boolean hasHoveredChild() { + return false; + } + /** + * Dispatch a generic motion event to the view under the first pointer. + *

+ * Do not call this method directly. + * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. + *

+ * + * @param event The motion event to be dispatched. + * @return True if the event was handled by the view, false otherwise. + */ + protected boolean dispatchGenericPointerEvent(MotionEvent event) { + return false; + } + /** + * Dispatch a generic motion event to the currently focused view. + *

+ * Do not call this method directly. + * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. + *

+ * + * @param event The motion event to be dispatched. + * @return True if the event was handled by the view, false otherwise. + */ + protected boolean dispatchGenericFocusedEvent(MotionEvent event) { + return false; + } + /** + * Dispatch a pointer event. + *

+ * Dispatches touch related pointer events to {@link #onTouchEvent(MotionEvent)} and all + * other events to {@link #onGenericMotionEvent(MotionEvent)}. This separation of concerns + * reinforces the invariant that {@link #onTouchEvent(MotionEvent)} is really about touches + * and should not be expected to handle other pointing device features. + *

+ * + * @param event The motion event to be dispatched. + * @return True if the event was handled by the view, false otherwise. + * @hide + */ + public final boolean dispatchPointerEvent(MotionEvent event) { + if (event.isTouchEvent()) { + return dispatchTouchEvent(event); + } else { + return dispatchGenericMotionEvent(event); + } + } + /** + * Called when the window containing this view gains or loses window focus. + * ViewGroups should override to route to their children. + * + * @param hasFocus True if the window containing this view now has focus, + * false otherwise. + */ + public void dispatchWindowFocusChanged(boolean hasFocus) { + onWindowFocusChanged(hasFocus); + } + /** + * Called when the window containing this view gains or loses focus. Note + * that this is separate from view focus: to receive key events, both + * your view and its window must have focus. If a window is displayed + * on top of yours that takes input focus, then your own window will lose + * focus but the view focus will remain unchanged. + * + * @param hasWindowFocus True if the window containing this view now has + * focus, false otherwise. + */ + public void onWindowFocusChanged(boolean hasWindowFocus) { + InputMethodManager imm = InputMethodManager.peekInstance(); + if (!hasWindowFocus) { + if (isPressed()) { + setPressed(false); + } + if (imm != null && (mPrivateFlags & FOCUSED) != 0) { + imm.focusOut(this); + } + removeLongPressCallback(); + removeTapCallback(); + onFocusLost(); + } else if (imm != null && (mPrivateFlags & FOCUSED) != 0) { + imm.focusIn(this); + } + refreshDrawableState(); + } + /** + * Returns true if this view is in a window that currently has window focus. + * Note that this is not the same as the view itself having focus. + * + * @return True if this view is in a window that currently has window focus. + */ + public boolean hasWindowFocus() { + return mAttachInfo != null && mAttachInfo.mHasWindowFocus; + } + /** + * Dispatch a view visibility change down the view hierarchy. + * ViewGroups should override to route to their children. + * @param changedView The view whose visibility changed. Could be 'this' or + * an ancestor view. + * @param visibility The new visibility of changedView: {@link #VISIBLE}, + * {@link #INVISIBLE} or {@link #GONE}. + */ + protected void dispatchVisibilityChanged(View changedView, int visibility) { + onVisibilityChanged(changedView, visibility); + } + /** + * Called when the visibility of the view or an ancestor of the view is changed. + * @param changedView The view whose visibility changed. Could be 'this' or + * an ancestor view. + * @param visibility The new visibility of changedView: {@link #VISIBLE}, + * {@link #INVISIBLE} or {@link #GONE}. + */ + protected void onVisibilityChanged(View changedView, int visibility) { + if (visibility == VISIBLE) { + if (mAttachInfo != null) { + initialAwakenScrollBars(); + } else { + mPrivateFlags |= AWAKEN_SCROLL_BARS_ON_ATTACH; + } + } + } + /** + * Dispatch a hint about whether this view is displayed. For instance, when + * a View moves out of the screen, it might receives a display hint indicating + * the view is not displayed. Applications should not rely on this hint + * as there is no guarantee that they will receive one. + * + * @param hint A hint about whether or not this view is displayed: + * {@link #VISIBLE} or {@link #INVISIBLE}. + */ + public void dispatchDisplayHint(int hint) { + onDisplayHint(hint); + } + /** + * Gives this view a hint about whether is displayed or not. For instance, when + * a View moves out of the screen, it might receives a display hint indicating + * the view is not displayed. Applications should not rely on this hint + * as there is no guarantee that they will receive one. + * + * @param hint A hint about whether or not this view is displayed: + * {@link #VISIBLE} or {@link #INVISIBLE}. + */ + protected void onDisplayHint(int hint) { + } + /** + * Dispatch a window visibility change down the view hierarchy. + * ViewGroups should override to route to their children. + * + * @param visibility The new visibility of the window. + * + * @see #onWindowVisibilityChanged(int) + */ + public void dispatchWindowVisibilityChanged(int visibility) { + onWindowVisibilityChanged(visibility); + } + /** + * Called when the window containing has change its visibility + * (between {@link #GONE}, {@link #INVISIBLE}, and {@link #VISIBLE}). Note + * that this tells you whether or not your window is being made visible + * to the window manager; this does not tell you whether or not + * your window is obscured by other windows on the screen, even if it + * is itself visible. + * + * @param visibility The new visibility of the window. + */ + protected void onWindowVisibilityChanged(int visibility) { + if (visibility == VISIBLE) { + initialAwakenScrollBars(); + } + } + /** + * Returns the current visibility of the window this view is attached to + * (either {@link #GONE}, {@link #INVISIBLE}, or {@link #VISIBLE}). + * + * @return Returns the current visibility of the view's window. + */ + public int getWindowVisibility() { + return mAttachInfo != null ? mAttachInfo.mWindowVisibility : GONE; + } + /** + * Retrieve the overall visible display size in which the window this view is + * attached to has been positioned in. This takes into account screen + * decorations above the window, for both cases where the window itself + * is being position inside of them or the window is being placed under + * then and covered insets are used for the window to position its content + * inside. In effect, this tells you the available area where content can + * be placed and remain visible to users. + * + *

This function requires an IPC back to the window manager to retrieve + * the requested information, so should not be used in performance critical + * code like drawing. + * + * @param outRect Filled in with the visible display frame. If the view + * is not attached to a window, this is simply the raw display size. + */ + public void getWindowVisibleDisplayFrame(Rect outRect) { + if (mAttachInfo != null) { + try { + mAttachInfo.mSession.getDisplayFrame(mAttachInfo.mWindow, outRect); + } catch (RemoteException e) { + return; + } + // XXX This is really broken, and probably all needs to be done + // in the window manager, and we need to know more about whether + // we want the area behind or in front of the IME. + final Rect insets = mAttachInfo.mVisibleInsets; + outRect.left += insets.left; + outRect.top += insets.top; + outRect.right -= insets.right; + outRect.bottom -= insets.bottom; + return; + } + Display d = WindowManagerImpl.getDefault().getDefaultDisplay(); + d.getRectSize(outRect); + } + /** + * Dispatch a notification about a resource configuration change down + * the view hierarchy. + * ViewGroups should override to route to their children. + * + * @param newConfig The new resource configuration. + * + * @see #onConfigurationChanged(android.content.res.Configuration) + */ + public void dispatchConfigurationChanged(Configuration newConfig) { + onConfigurationChanged(newConfig); + } + /** + * Called when the current configuration of the resources being used + * by the application have changed. You can use this to decide when + * to reload resources that can changed based on orientation and other + * configuration characterstics. You only need to use this if you are + * not relying on the normal {@link android.app.Activity} mechanism of + * recreating the activity instance upon a configuration change. + * + * @param newConfig The new resource configuration. + */ + protected void onConfigurationChanged(Configuration newConfig) { + } + /** + * Private function to aggregate all per-view attributes in to the view + * root. + */ + void dispatchCollectViewAttributes(int visibility) { + performCollectViewAttributes(visibility); + } + void performCollectViewAttributes(int visibility) { + if ((visibility & VISIBILITY_MASK) == VISIBLE && mAttachInfo != null) { + if ((mViewFlags & KEEP_SCREEN_ON) == KEEP_SCREEN_ON) { + mAttachInfo.mKeepScreenOn = true; + } + mAttachInfo.mSystemUiVisibility |= mSystemUiVisibility; + ListenerInfo li = mListenerInfo; + if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { + mAttachInfo.mHasSystemUiListeners = true; + } + } + } + void needGlobalAttributesUpdate(boolean force) { + final AttachInfo ai = mAttachInfo; + if (ai != null) { + if (force || ai.mKeepScreenOn || (ai.mSystemUiVisibility != 0) + || ai.mHasSystemUiListeners) { + ai.mRecomputeGlobalAttributes = true; + } + } + } + /** + * Returns whether the device is currently in touch mode. Touch mode is entered + * once the user begins interacting with the device by touch, and affects various + * things like whether focus is always visible to the user. + * + * @return Whether the device is in touch mode. + */ + @ViewDebug.ExportedProperty + public boolean isInTouchMode() { + if (mAttachInfo != null) { + return mAttachInfo.mInTouchMode; + } else { + return ViewRootImpl.isInTouchMode(); + } + } + /** + * Returns the context the view is running in, through which it can + * access the current theme, resources, etc. + * + * @return The view's Context. + */ + @ViewDebug.CapturedViewProperty + public final Context getContext() { + return mContext; + } + /** + * Handle a key event before it is processed by any input method + * associated with the view hierarchy. This can be used to intercept + * key events in special situations before the IME consumes them; a + * typical example would be handling the BACK key to update the application's + * UI instead of allowing the IME to see it and close itself. + * + * @param keyCode The value in event.getKeyCode(). + * @param event Description of the key event. + * @return If you handled the event, return true. If you want to allow the + * event to be handled by the next receiver, return false. + */ + public boolean onKeyPreIme(int keyCode, KeyEvent event) { + return false; + } + /** + * Default implementation of {@link KeyEvent.Callback#onKeyDown(int, KeyEvent) + * KeyEvent.Callback.onKeyDown()}: perform press of the view + * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or {@link KeyEvent#KEYCODE_ENTER} + * is released, if the view is enabled and clickable. + * + * @param keyCode A key code that represents the button pressed, from + * {@link android.view.KeyEvent}. + * @param event The KeyEvent object that defines the button action. + */ + public boolean onKeyDown(int keyCode, KeyEvent event) { + boolean result = false; + switch (keyCode) { + case KeyEvent.KEYCODE_DPAD_CENTER: + case KeyEvent.KEYCODE_ENTER: { + if ((mViewFlags & ENABLED_MASK) == DISABLED) { + return true; + } + // Long clickable items don't necessarily have to be clickable + if (((mViewFlags & CLICKABLE) == CLICKABLE || + (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) && + (event.getRepeatCount() == 0)) { + setPressed(true); + checkForLongClick(0); + return true; + } + break; + } + } + return result; + } + /** + * Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) + * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle + * the event). + */ + public boolean onKeyLongPress(int keyCode, KeyEvent event) { + return false; + } + /** + * Default implementation of {@link KeyEvent.Callback#onKeyUp(int, KeyEvent) + * KeyEvent.Callback.onKeyUp()}: perform clicking of the view + * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or + * {@link KeyEvent#KEYCODE_ENTER} is released. + * + * @param keyCode A key code that represents the button pressed, from + * {@link android.view.KeyEvent}. + * @param event The KeyEvent object that defines the button action. + */ + public boolean onKeyUp(int keyCode, KeyEvent event) { + boolean result = false; + switch (keyCode) { + case KeyEvent.KEYCODE_DPAD_CENTER: + case KeyEvent.KEYCODE_ENTER: { + if ((mViewFlags & ENABLED_MASK) == DISABLED) { + return true; + } + if ((mViewFlags & CLICKABLE) == CLICKABLE && isPressed()) { + setPressed(false); + if (!mHasPerformedLongPress) { + // This is a tap, so remove the longpress check + removeLongPressCallback(); + result = performClick(); + } + } + break; + } + } + return result; + } + /** + * Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) + * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle + * the event). + * + * @param keyCode A key code that represents the button pressed, from + * {@link android.view.KeyEvent}. + * @param repeatCount The number of times the action was made. + * @param event The KeyEvent object that defines the button action. + */ + public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { + return false; + } + /** + * Called on the focused view when a key shortcut event is not handled. + * Override this method to implement local key shortcuts for the View. + * Key shortcuts can also be implemented by setting the + * {@link MenuItem#setShortcut(char, char) shortcut} property of menu items. + * + * @param keyCode The value in event.getKeyCode(). + * @param event Description of the key event. + * @return If you handled the event, return true. If you want to allow the + * event to be handled by the next receiver, return false. + */ + public boolean onKeyShortcut(int keyCode, KeyEvent event) { + return false; + } + /** + * Check whether the called view is a text editor, in which case it + * would make sense to automatically display a soft input window for + * it. Subclasses should override this if they implement + * {@link #onCreateInputConnection(EditorInfo)} to return true if + * a call on that method would return a non-null InputConnection, and + * they are really a first-class editor that the user would normally + * start typing on when the go into a window containing your view. + * + *

The default implementation always returns false. This does + * not mean that its {@link #onCreateInputConnection(EditorInfo)} + * will not be called or the user can not otherwise perform edits on your + * view; it is just a hint to the system that this is not the primary + * purpose of this view. + * + * @return Returns true if this view is a text editor, else false. + */ + public boolean onCheckIsTextEditor() { + return false; + } + /** + * Create a new InputConnection for an InputMethod to interact + * with the view. The default implementation returns null, since it doesn't + * support input methods. You can override this to implement such support. + * This is only needed for views that take focus and text input. + * + *

When implementing this, you probably also want to implement + * {@link #onCheckIsTextEditor()} to indicate you will return a + * non-null InputConnection. + * + * @param outAttrs Fill in with attribute information about the connection. + */ + public InputConnection onCreateInputConnection(EditorInfo outAttrs) { + return null; + } + /** + * Called by the {@link android.view.inputmethod.InputMethodManager} + * when a view who is not the current + * input connection target is trying to make a call on the manager. The + * default implementation returns false; you can override this to return + * true for certain views if you are performing InputConnection proxying + * to them. + * @param view The View that is making the InputMethodManager call. + * @return Return true to allow the call, false to reject. + */ + public boolean checkInputConnectionProxy(View view) { + return false; + } + /** + * Show the context menu for this view. It is not safe to hold on to the + * menu after returning from this method. + * + * You should normally not overload this method. Overload + * {@link #onCreateContextMenu(ContextMenu)} or define an + * {@link OnCreateContextMenuListener} to add items to the context menu. + * + * @param menu The context menu to populate + */ + public void createContextMenu(ContextMenu menu) { + ContextMenuInfo menuInfo = getContextMenuInfo(); + // Sets the current menu info so all items added to menu will have + // my extra info set. + ((MenuBuilder)menu).setCurrentMenuInfo(menuInfo); + onCreateContextMenu(menu); + ListenerInfo li = mListenerInfo; + if (li != null && li.mOnCreateContextMenuListener != null) { + li.mOnCreateContextMenuListener.onCreateContextMenu(menu, this, menuInfo); + } + // Clear the extra information so subsequent items that aren't mine don't + // have my extra info. + ((MenuBuilder)menu).setCurrentMenuInfo(null); + if (mParent != null) { + mParent.createContextMenu(menu); + } + } + /** + * Views should implement this if they have extra information to associate + * with the context menu. The return result is supplied as a parameter to + * the {@link OnCreateContextMenuListener#onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} + * callback. + * + * @return Extra information about the item for which the context menu + * should be shown. This information will vary across different + * subclasses of View. + */ + protected ContextMenuInfo getContextMenuInfo() { + return null; + } + /** + * Views should implement this if the view itself is going to add items to + * the context menu. + * + * @param menu the context menu to populate + */ + protected void onCreateContextMenu(ContextMenu menu) { + } + /** + * Implement this method to handle trackball motion events. The + * relative movement of the trackball since the last event + * can be retrieve with {@link MotionEvent#getX MotionEvent.getX()} and + * {@link MotionEvent#getY MotionEvent.getY()}. These are normalized so + * that a movement of 1 corresponds to the user pressing one DPAD key (so + * they will often be fractional values, representing the more fine-grained + * movement information available from a trackball). + * + * @param event The motion event. + * @return True if the event was handled, false otherwise. + */ + public boolean onTrackballEvent(MotionEvent event) { + return false; + } + /** + * Implement this method to handle generic motion events. + *

+ * Generic motion events describe joystick movements, mouse hovers, track pad + * touches, scroll wheel movements and other input events. The + * {@link MotionEvent#getSource() source} of the motion event specifies + * the class of input that was received. Implementations of this method + * must examine the bits in the source before processing the event. + * The following code example shows how this is done. + *

+ * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} + * are delivered to the view under the pointer. All other generic motion events are + * delivered to the focused view. + *

+ *
 public boolean onGenericMotionEvent(MotionEvent event) {
+     *     if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
+     *         if (event.getAction() == MotionEvent.ACTION_MOVE) {
+     *             // process the joystick movement...
+     *             return true;
+     *         }
+     *     }
+     *     if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
+     *         switch (event.getAction()) {
+     *             case MotionEvent.ACTION_HOVER_MOVE:
+     *                 // process the mouse hover movement...
+     *                 return true;
+     *             case MotionEvent.ACTION_SCROLL:
+     *                 // process the scroll wheel movement...
+     *                 return true;
+     *         }
+     *     }
+     *     return super.onGenericMotionEvent(event);
+     * }
+ * + * @param event The generic motion event being processed. + * @return True if the event was handled, false otherwise. + */ + public boolean onGenericMotionEvent(MotionEvent event) { + return false; + } + /** + * Implement this method to handle hover events. + *

+ * This method is called whenever a pointer is hovering into, over, or out of the + * bounds of a view and the view is not currently being touched. + * Hover events are represented as pointer events with action + * {@link MotionEvent#ACTION_HOVER_ENTER}, {@link MotionEvent#ACTION_HOVER_MOVE}, + * or {@link MotionEvent#ACTION_HOVER_EXIT}. + *

+ *
    + *
  • The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_ENTER} + * when the pointer enters the bounds of the view.
  • + *
  • The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_MOVE} + * when the pointer has already entered the bounds of the view and has moved.
  • + *
  • The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_EXIT} + * when the pointer has exited the bounds of the view or when the pointer is + * about to go down due to a button click, tap, or similar user action that + * causes the view to be touched.
  • + *
+ *

+ * The view should implement this method to return true to indicate that it is + * handling the hover event, such as by changing its drawable state. + *

+ * The default implementation calls {@link #setHovered} to update the hovered state + * of the view when a hover enter or hover exit event is received, if the view + * is enabled and is clickable. The default implementation also sends hover + * accessibility events. + *

+ * + * @param event The motion event that describes the hover. + * @return True if the view handled the hover event. + * + * @see #isHovered + * @see #setHovered + * @see #onHoverChanged + */ + public boolean onHoverEvent(MotionEvent event) { + // The root view may receive hover (or touch) events that are outside the bounds of + // the window. This code ensures that we only send accessibility events for + // hovers that are actually within the bounds of the root view. + final int action = event.getAction(); + if (!mSendingHoverAccessibilityEvents) { + if ((action == MotionEvent.ACTION_HOVER_ENTER + || action == MotionEvent.ACTION_HOVER_MOVE) + && !hasHoveredChild() + && pointInView(event.getX(), event.getY())) { + mSendingHoverAccessibilityEvents = true; + sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER); + } + } else { + if (action == MotionEvent.ACTION_HOVER_EXIT + || (action == MotionEvent.ACTION_HOVER_MOVE + && !pointInView(event.getX(), event.getY()))) { + mSendingHoverAccessibilityEvents = false; + sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT); + } + } + if (isHoverable()) { + switch (action) { + case MotionEvent.ACTION_HOVER_ENTER: + setHovered(true); + break; + case MotionEvent.ACTION_HOVER_EXIT: + setHovered(false); + break; + } + // Dispatch the event to onGenericMotionEvent before returning true. + // This is to provide compatibility with existing applications that + // handled HOVER_MOVE events in onGenericMotionEvent and that would + // break because of the new default handling for hoverable views + // in onHoverEvent. + // Note that onGenericMotionEvent will be called by default when + // onHoverEvent returns false (refer to dispatchGenericMotionEvent). + dispatchGenericMotionEventInternal(event); + return true; + } + return false; + } + /** + * Returns true if the view should handle {@link #onHoverEvent} + * by calling {@link #setHovered} to change its hovered state. + * + * @return True if the view is hoverable. + */ + private boolean isHoverable() { + final int viewFlags = mViewFlags; + //noinspection SimplifiableIfStatement + if ((viewFlags & ENABLED_MASK) == DISABLED) { + return false; + } + return (viewFlags & CLICKABLE) == CLICKABLE + || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; + } + /** + * Returns true if the view is currently hovered. + * + * @return True if the view is currently hovered. + * + * @see #setHovered + * @see #onHoverChanged + */ + @ViewDebug.ExportedProperty + public boolean isHovered() { + return (mPrivateFlags & HOVERED) != 0; + } + /** + * Sets whether the view is currently hovered. + *

+ * Calling this method also changes the drawable state of the view. This + * enables the view to react to hover by using different drawable resources + * to change its appearance. + *

+ * The {@link #onHoverChanged} method is called when the hovered state changes. + *

+ * + * @param hovered True if the view is hovered. + * + * @see #isHovered + * @see #onHoverChanged + */ + public void setHovered(boolean hovered) { + if (hovered) { + if ((mPrivateFlags & HOVERED) == 0) { + mPrivateFlags |= HOVERED; + refreshDrawableState(); + onHoverChanged(true); + } + } else { + if ((mPrivateFlags & HOVERED) != 0) { + mPrivateFlags &= ~HOVERED; + refreshDrawableState(); + onHoverChanged(false); + } + } + } + /** + * Implement this method to handle hover state changes. + *

+ * This method is called whenever the hover state changes as a result of a + * call to {@link #setHovered}. + *

+ * + * @param hovered The current hover state, as returned by {@link #isHovered}. + * + * @see #isHovered + * @see #setHovered + */ + public void onHoverChanged(boolean hovered) { + } + /** + * Implement this method to handle touch screen motion events. + * + * @param event The motion event. + * @return True if the event was handled, false otherwise. + */ + public boolean onTouchEvent(MotionEvent event) { + final int viewFlags = mViewFlags; + if ((viewFlags & ENABLED_MASK) == DISABLED) { + if (event.getAction() == MotionEvent.ACTION_UP && (mPrivateFlags & PRESSED) != 0) { + mPrivateFlags &= ~PRESSED; + refreshDrawableState(); + } + // A disabled view that is clickable still consumes the touch + // events, it just doesn't respond to them. + return (((viewFlags & CLICKABLE) == CLICKABLE || + (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)); + } + if (mTouchDelegate != null) { + if (mTouchDelegate.onTouchEvent(event)) { + return true; + } + } + if (((viewFlags & CLICKABLE) == CLICKABLE || + (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)) { + switch (event.getAction()) { + case MotionEvent.ACTION_UP: + boolean prepressed = (mPrivateFlags & PREPRESSED) != 0; + if ((mPrivateFlags & PRESSED) != 0 || prepressed) { + // take focus if we don't have it already and we should in + // touch mode. + boolean focusTaken = false; + if (isFocusable() && isFocusableInTouchMode() && !isFocused()) { + focusTaken = requestFocus(); + } + if (prepressed) { + // The button is being released before we actually + // showed it as pressed. Make it show the pressed + // state now (before scheduling the click) to ensure + // the user sees it. + mPrivateFlags |= PRESSED; + refreshDrawableState(); + } + if (!mHasPerformedLongPress) { + // This is a tap, so remove the longpress check + removeLongPressCallback(); + // Only perform take click actions if we were in the pressed state + if (!focusTaken) { + // Use a Runnable and post this rather than calling + // performClick directly. This lets other visual state + // of the view update before click actions start. + if (mPerformClick == null) { + mPerformClick = new PerformClick(); + } + if (!post(mPerformClick)) { + performClick(); + } + } + } + if (mUnsetPressedState == null) { + mUnsetPressedState = new UnsetPressedState(); + } + if (prepressed) { + postDelayed(mUnsetPressedState, + ViewConfiguration.getPressedStateDuration()); + } else if (!post(mUnsetPressedState)) { + // If the post failed, unpress right now + mUnsetPressedState.run(); + } + removeTapCallback(); + } + break; + case MotionEvent.ACTION_DOWN: + mHasPerformedLongPress = false; + if (performButtonActionOnTouchDown(event)) { + break; + } + // Walk up the hierarchy to determine if we're inside a scrolling container. + boolean isInScrollingContainer = isInScrollingContainer(); + // For views inside a scrolling container, delay the pressed feedback for + // a short period in case this is a scroll. + if (isInScrollingContainer) { + mPrivateFlags |= PREPRESSED; + if (mPendingCheckForTap == null) { + mPendingCheckForTap = new CheckForTap(); + } + postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); + } else { + // Not inside a scrolling container, so show the feedback right away + mPrivateFlags |= PRESSED; + refreshDrawableState(); + checkForLongClick(0); + } + break; + case MotionEvent.ACTION_CANCEL: + mPrivateFlags &= ~PRESSED; + refreshDrawableState(); + removeTapCallback(); + break; + case MotionEvent.ACTION_MOVE: + final int x = (int) event.getX(); + final int y = (int) event.getY(); + // Be lenient about moving outside of buttons + if (!pointInView(x, y, mTouchSlop)) { + // Outside button + removeTapCallback(); + if ((mPrivateFlags & PRESSED) != 0) { + // Remove any future long press/tap checks + removeLongPressCallback(); + // Need to switch from pressed to not pressed + mPrivateFlags &= ~PRESSED; + refreshDrawableState(); + } + } + break; + } + return true; + } + return false; + } + /** + * @hide + */ + public boolean isInScrollingContainer() { + ViewParent p = getParent(); + while (p != null && p instanceof ViewGroup) { + if (((ViewGroup) p).shouldDelayChildPressedState()) { + return true; + } + p = p.getParent(); + } + return false; + } + /** + * Remove the longpress detection timer. + */ + private void removeLongPressCallback() { + if (mPendingCheckForLongPress != null) { + removeCallbacks(mPendingCheckForLongPress); + } + } + /** + * Remove the pending click action + */ + private void removePerformClickCallback() { + if (mPerformClick != null) { + removeCallbacks(mPerformClick); + } + } + /** + * Remove the prepress detection timer. + */ + private void removeUnsetPressCallback() { + if ((mPrivateFlags & PRESSED) != 0 && mUnsetPressedState != null) { + setPressed(false); + removeCallbacks(mUnsetPressedState); + } + } + /** + * Remove the tap detection timer. + */ + private void removeTapCallback() { + if (mPendingCheckForTap != null) { + mPrivateFlags &= ~PREPRESSED; + removeCallbacks(mPendingCheckForTap); + } + } + /** + * Cancels a pending long press. Your subclass can use this if you + * want the context menu to come up if the user presses and holds + * at the same place, but you don't want it to come up if they press + * and then move around enough to cause scrolling. + */ + public void cancelLongPress() { + removeLongPressCallback(); + /* + * The prepressed state handled by the tap callback is a display + * construct, but the tap callback will post a long press callback + * less its own timeout. Remove it here. + */ + removeTapCallback(); + } + /** + * Remove the pending callback for sending a + * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. + */ + private void removeSendViewScrolledAccessibilityEventCallback() { + if (mSendViewScrolledAccessibilityEvent != null) { + removeCallbacks(mSendViewScrolledAccessibilityEvent); + } + } + /** + * Sets the TouchDelegate for this View. + */ + public void setTouchDelegate(TouchDelegate delegate) { + mTouchDelegate = delegate; + } + /** + * Gets the TouchDelegate for this View. + */ + public TouchDelegate getTouchDelegate() { + return mTouchDelegate; + } + /** + * Set flags controlling behavior of this view. + * + * @param flags Constant indicating the value which should be set + * @param mask Constant indicating the bit range that should be changed + */ + void setFlags(int flags, int mask) { + int old = mViewFlags; + mViewFlags = (mViewFlags & ~mask) | (flags & mask); + int changed = mViewFlags ^ old; + if (changed == 0) { + return; + } + int privateFlags = mPrivateFlags; + /* Check if the FOCUSABLE bit has changed */ + if (((changed & FOCUSABLE_MASK) != 0) && + ((privateFlags & HAS_BOUNDS) !=0)) { + if (((old & FOCUSABLE_MASK) == FOCUSABLE) + && ((privateFlags & FOCUSED) != 0)) { + /* Give up focus if we are no longer focusable */ + clearFocus(); + } else if (((old & FOCUSABLE_MASK) == NOT_FOCUSABLE) + && ((privateFlags & FOCUSED) == 0)) { + /* + * Tell the view system that we are now available to take focus + * if no one else already has it. + */ + if (mParent != null) mParent.focusableViewAvailable(this); + } + } + if ((flags & VISIBILITY_MASK) == VISIBLE) { + if ((changed & VISIBILITY_MASK) != 0) { + /* + * If this view is becoming visible, invalidate it in case it changed while + * it was not visible. Marking it drawn ensures that the invalidation will + * go through. + */ + mPrivateFlags |= DRAWN; + invalidate(true); + needGlobalAttributesUpdate(true); + // a view becoming visible is worth notifying the parent + // about in case nothing has focus. even if this specific view + // isn't focusable, it may contain something that is, so let + // the root view try to give this focus if nothing else does. + if ((mParent != null) && (mBottom > mTop) && (mRight > mLeft)) { + mParent.focusableViewAvailable(this); + } + } + } + /* Check if the GONE bit has changed */ + if ((changed & GONE) != 0) { + needGlobalAttributesUpdate(false); + requestLayout(); + if (((mViewFlags & VISIBILITY_MASK) == GONE)) { + if (hasFocus()) clearFocus(); + destroyDrawingCache(); + if (mParent instanceof View) { + // GONE views noop invalidation, so invalidate the parent + ((View) mParent).invalidate(true); + } + // Mark the view drawn to ensure that it gets invalidated properly the next + // time it is visible and gets invalidated + mPrivateFlags |= DRAWN; + } + if (mAttachInfo != null) { + mAttachInfo.mViewVisibilityChanged = true; + } + } + /* Check if the VISIBLE bit has changed */ + if ((changed & INVISIBLE) != 0) { + needGlobalAttributesUpdate(false); + /* + * If this view is becoming invisible, set the DRAWN flag so that + * the next invalidate() will not be skipped. + */ + mPrivateFlags |= DRAWN; + if (((mViewFlags & VISIBILITY_MASK) == INVISIBLE) && hasFocus()) { + // root view becoming invisible shouldn't clear focus + if (getRootView() != this) { + clearFocus(); + } + } + if (mAttachInfo != null) { + mAttachInfo.mViewVisibilityChanged = true; + } + } + if ((changed & VISIBILITY_MASK) != 0) { + if (mParent instanceof ViewGroup) { + ((ViewGroup) mParent).onChildVisibilityChanged(this, (changed & VISIBILITY_MASK), + (flags & VISIBILITY_MASK)); + ((View) mParent).invalidate(true); + } else if (mParent != null) { + mParent.invalidateChild(this, null); + } + dispatchVisibilityChanged(this, (flags & VISIBILITY_MASK)); + } + if ((changed & WILL_NOT_CACHE_DRAWING) != 0) { + destroyDrawingCache(); + } + if ((changed & DRAWING_CACHE_ENABLED) != 0) { + destroyDrawingCache(); + mPrivateFlags &= ~DRAWING_CACHE_VALID; + invalidateParentCaches(); + } + if ((changed & DRAWING_CACHE_QUALITY_MASK) != 0) { + destroyDrawingCache(); + mPrivateFlags &= ~DRAWING_CACHE_VALID; + } + if ((changed & DRAW_MASK) != 0) { + if ((mViewFlags & WILL_NOT_DRAW) != 0) { + if (mBGDrawable != null) { + mPrivateFlags &= ~SKIP_DRAW; + mPrivateFlags |= ONLY_DRAWS_BACKGROUND; + } else { + mPrivateFlags |= SKIP_DRAW; + } + } else { + mPrivateFlags &= ~SKIP_DRAW; + } + requestLayout(); + invalidate(true); + } + if ((changed & KEEP_SCREEN_ON) != 0) { + if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { + mParent.recomputeViewAttributes(this); + } + } + if ((changed & LAYOUT_DIRECTION_MASK) != 0) { + requestLayout(); + } + } + /** + * Change the view's z order in the tree, so it's on top of other sibling + * views + */ + public void bringToFront() { + if (mParent != null) { + mParent.bringChildToFront(this); + } + } + /** + * This is called in response to an internal scroll in this view (i.e., the + * view scrolled its own contents). This is typically as a result of + * {@link #scrollBy(int, int)} or {@link #scrollTo(int, int)} having been + * called. + * + * @param l Current horizontal scroll origin. + * @param t Current vertical scroll origin. + * @param oldl Previous horizontal scroll origin. + * @param oldt Previous vertical scroll origin. + */ + protected void onScrollChanged(int l, int t, int oldl, int oldt) { + if (AccessibilityManager.getInstance(mContext).isEnabled()) { + postSendViewScrolledAccessibilityEventCallback(); + } + mBackgroundSizeChanged = true; + final AttachInfo ai = mAttachInfo; + if (ai != null) { + ai.mViewScrollChanged = true; + } + } + /** + * Interface definition for a callback to be invoked when the layout bounds of a view + * changes due to layout processing. + */ + public interface OnLayoutChangeListener { + /** + * Called when the focus state of a view has changed. + * + * @param v The view whose state has changed. + * @param left The new value of the view's left property. + * @param top The new value of the view's top property. + * @param right The new value of the view's right property. + * @param bottom The new value of the view's bottom property. + * @param oldLeft The previous value of the view's left property. + * @param oldTop The previous value of the view's top property. + * @param oldRight The previous value of the view's right property. + * @param oldBottom The previous value of the view's bottom property. + */ + void onLayoutChange(View v, int left, int top, int right, int bottom, + int oldLeft, int oldTop, int oldRight, int oldBottom); + } + /** + * This is called during layout when the size of this view has changed. If + * you were just added to the view hierarchy, you're called with the old + * values of 0. + * + * @param w Current width of this view. + * @param h Current height of this view. + * @param oldw Old width of this view. + * @param oldh Old height of this view. + */ + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + } + /** + * Called by draw to draw the child views. This may be overridden + * by derived classes to gain control just before its children are drawn + * (but after its own view has been drawn). + * @param canvas the canvas on which to draw the view + */ + protected void dispatchDraw(Canvas canvas) { + } + /** + * Gets the parent of this view. Note that the parent is a + * ViewParent and not necessarily a View. + * + * @return Parent of this view. + */ + public final ViewParent getParent() { + return mParent; + } + /** + * Set the horizontal scrolled position of your view. This will cause a call to + * {@link #onScrollChanged(int, int, int, int)} and the view will be + * invalidated. + * @param value the x position to scroll to + */ + public void setScrollX(int value) { + scrollTo(value, mScrollY); + } + /** + * Set the vertical scrolled position of your view. This will cause a call to + * {@link #onScrollChanged(int, int, int, int)} and the view will be + * invalidated. + * @param value the y position to scroll to + */ + public void setScrollY(int value) { + scrollTo(mScrollX, value); + } + /** + * Return the scrolled left position of this view. This is the left edge of + * the displayed part of your view. You do not need to draw any pixels + * farther left, since those are outside of the frame of your view on + * screen. + * + * @return The left edge of the displayed part of your view, in pixels. + */ + public final int getScrollX() { + return mScrollX; + } + /** + * Return the scrolled top position of this view. This is the top edge of + * the displayed part of your view. You do not need to draw any pixels above + * it, since those are outside of the frame of your view on screen. + * + * @return The top edge of the displayed part of your view, in pixels. + */ + public final int getScrollY() { + return mScrollY; + } + /** + * Return the width of the your view. + * + * @return The width of your view, in pixels. + */ + @ViewDebug.ExportedProperty(category = "layout") + public final int getWidth() { + return mRight - mLeft; + } + /** + * Return the height of your view. + * + * @return The height of your view, in pixels. + */ + @ViewDebug.ExportedProperty(category = "layout") + public final int getHeight() { + return mBottom - mTop; + } + /** + * Return the visible drawing bounds of your view. Fills in the output + * rectangle with the values from getScrollX(), getScrollY(), + * getWidth(), and getHeight(). + * + * @param outRect The (scrolled) drawing bounds of the view. + */ + public void getDrawingRect(Rect outRect) { + outRect.left = mScrollX; + outRect.top = mScrollY; + outRect.right = mScrollX + (mRight - mLeft); + outRect.bottom = mScrollY + (mBottom - mTop); + } + /** + * Like {@link #getMeasuredWidthAndState()}, but only returns the + * raw width component (that is the result is masked by + * {@link #MEASURED_SIZE_MASK}). + * + * @return The raw measured width of this view. + */ + public final int getMeasuredWidth() { + return mMeasuredWidth & MEASURED_SIZE_MASK; + } + /** + * Return the full width measurement information for this view as computed + * by the most recent call to {@link #measure(int, int)}. This result is a bit mask + * as defined by {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. + * This should be used during measurement and layout calculations only. Use + * {@link #getWidth()} to see how wide a view is after layout. + * + * @return The measured width of this view as a bit mask. + */ + public final int getMeasuredWidthAndState() { + return mMeasuredWidth; + } + /** + * Like {@link #getMeasuredHeightAndState()}, but only returns the + * raw width component (that is the result is masked by + * {@link #MEASURED_SIZE_MASK}). + * + * @return The raw measured height of this view. + */ + public final int getMeasuredHeight() { + return mMeasuredHeight & MEASURED_SIZE_MASK; + } + /** + * Return the full height measurement information for this view as computed + * by the most recent call to {@link #measure(int, int)}. This result is a bit mask + * as defined by {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. + * This should be used during measurement and layout calculations only. Use + * {@link #getHeight()} to see how wide a view is after layout. + * + * @return The measured width of this view as a bit mask. + */ + public final int getMeasuredHeightAndState() { + return mMeasuredHeight; + } + /** + * Return only the state bits of {@link #getMeasuredWidthAndState()} + * and {@link #getMeasuredHeightAndState()}, combined into one integer. + * The width component is in the regular bits {@link #MEASURED_STATE_MASK} + * and the height component is at the shifted bits + * {@link #MEASURED_HEIGHT_STATE_SHIFT}>>{@link #MEASURED_STATE_MASK}. + */ + public final int getMeasuredState() { + return (mMeasuredWidth&MEASURED_STATE_MASK) + | ((mMeasuredHeight>>MEASURED_HEIGHT_STATE_SHIFT) + & (MEASURED_STATE_MASK>>MEASURED_HEIGHT_STATE_SHIFT)); + } + /** + * The transform matrix of this view, which is calculated based on the current + * roation, scale, and pivot properties. + * + * @see #getRotation() + * @see #getScaleX() + * @see #getScaleY() + * @see #getPivotX() + * @see #getPivotY() + * @return The current transform matrix for the view + */ + public Matrix getMatrix() { + if (mTransformationInfo != null) { + updateMatrix(); + return mTransformationInfo.mMatrix; + } + return Matrix.IDENTITY_MATRIX; + } + /** + * Utility function to determine if the value is far enough away from zero to be + * considered non-zero. + * @param value A floating point value to check for zero-ness + * @return whether the passed-in value is far enough away from zero to be considered non-zero + */ + private static boolean nonzero(float value) { + return (value < -NONZERO_EPSILON || value > NONZERO_EPSILON); + } + /** + * Returns true if the transform matrix is the identity matrix. + * Recomputes the matrix if necessary. + * + * @return True if the transform matrix is the identity matrix, false otherwise. + */ + final boolean hasIdentityMatrix() { + if (mTransformationInfo != null) { + updateMatrix(); + return mTransformationInfo.mMatrixIsIdentity; + } + return true; + } + void ensureTransformationInfo() { + if (mTransformationInfo == null) { + mTransformationInfo = new TransformationInfo(); + } + } + /** + * Recomputes the transform matrix if necessary. + */ + private void updateMatrix() { + final TransformationInfo info = mTransformationInfo; + if (info == null) { + return; + } + if (info.mMatrixDirty) { + // transform-related properties have changed since the last time someone + // asked for the matrix; recalculate it with the current values + // Figure out if we need to update the pivot point + if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { + if ((mRight - mLeft) != info.mPrevWidth || (mBottom - mTop) != info.mPrevHeight) { + info.mPrevWidth = mRight - mLeft; + info.mPrevHeight = mBottom - mTop; + info.mPivotX = info.mPrevWidth / 2f; + info.mPivotY = info.mPrevHeight / 2f; + } + } + info.mMatrix.reset(); + if (!nonzero(info.mRotationX) && !nonzero(info.mRotationY)) { + info.mMatrix.setTranslate(info.mTranslationX, info.mTranslationY); + info.mMatrix.preRotate(info.mRotation, info.mPivotX, info.mPivotY); + info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); + } else { + if (info.mCamera == null) { + info.mCamera = new Camera(); + info.matrix3D = new Matrix(); + } + info.mCamera.save(); + info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); + info.mCamera.rotate(info.mRotationX, info.mRotationY, -info.mRotation); + info.mCamera.getMatrix(info.matrix3D); + info.matrix3D.preTranslate(-info.mPivotX, -info.mPivotY); + info.matrix3D.postTranslate(info.mPivotX + info.mTranslationX, + info.mPivotY + info.mTranslationY); + info.mMatrix.postConcat(info.matrix3D); + info.mCamera.restore(); + } + info.mMatrixDirty = false; + info.mMatrixIsIdentity = info.mMatrix.isIdentity(); + info.mInverseMatrixDirty = true; + } + } + /** + * Utility method to retrieve the inverse of the current mMatrix property. + * We cache the matrix to avoid recalculating it when transform properties + * have not changed. + * + * @return The inverse of the current matrix of this view. + */ + final Matrix getInverseMatrix() { + final TransformationInfo info = mTransformationInfo; + if (info != null) { + updateMatrix(); + if (info.mInverseMatrixDirty) { + if (info.mInverseMatrix == null) { + info.mInverseMatrix = new Matrix(); + } + info.mMatrix.invert(info.mInverseMatrix); + info.mInverseMatrixDirty = false; + } + return info.mInverseMatrix; + } + return Matrix.IDENTITY_MATRIX; + } + /** + *

Sets the distance along the Z axis (orthogonal to the X/Y plane on which + * views are drawn) from the camera to this view. The camera's distance + * affects 3D transformations, for instance rotations around the X and Y + * axis. If the rotationX or rotationY properties are changed and this view is + * large (more than half the size of the screen), it is recommended to always + * use a camera distance that's greater than the height (X axis rotation) or + * the width (Y axis rotation) of this view.

+ * + *

The distance of the camera from the view plane can have an affect on the + * perspective distortion of the view when it is rotated around the x or y axis. + * For example, a large distance will result in a large viewing angle, and there + * will not be much perspective distortion of the view as it rotates. A short + * distance may cause much more perspective distortion upon rotation, and can + * also result in some drawing artifacts if the rotated view ends up partially + * behind the camera (which is why the recommendation is to use a distance at + * least as far as the size of the view, if the view is to be rotated.)

+ * + *

The distance is expressed in "depth pixels." The default distance depends + * on the screen density. For instance, on a medium density display, the + * default distance is 1280. On a high density display, the default distance + * is 1920.

+ * + *

If you want to specify a distance that leads to visually consistent + * results across various densities, use the following formula:

+ *
+     * float scale = context.getResources().getDisplayMetrics().density;
+     * view.setCameraDistance(distance * scale);
+     * 
+ * + *

The density scale factor of a high density display is 1.5, + * and 1920 = 1280 * 1.5.

+ * + * @param distance The distance in "depth pixels", if negative the opposite + * value is used + * + * @see #setRotationX(float) + * @see #setRotationY(float) + */ + public void setCameraDistance(float distance) { + invalidateParentCaches(); + invalidate(false); + ensureTransformationInfo(); + final float dpi = mResources.getDisplayMetrics().densityDpi; + final TransformationInfo info = mTransformationInfo; + if (info.mCamera == null) { + info.mCamera = new Camera(); + info.matrix3D = new Matrix(); + } + info.mCamera.setLocation(0.0f, 0.0f, -Math.abs(distance) / dpi); + info.mMatrixDirty = true; + invalidate(false); + } + /** + * The degrees that the view is rotated around the pivot point. + * + * @see #setRotation(float) + * @see #getPivotX() + * @see #getPivotY() + * + * @return The degrees of rotation. + */ + @ViewDebug.ExportedProperty(category = "drawing") + public float getRotation() { + return mTransformationInfo != null ? mTransformationInfo.mRotation : 0; + } + /** + * Sets the degrees that the view is rotated around the pivot point. Increasing values + * result in clockwise rotation. + * + * @param rotation The degrees of rotation. + * + * @see #getRotation() + * @see #getPivotX() + * @see #getPivotY() + * @see #setRotationX(float) + * @see #setRotationY(float) + * + * @attr ref android.R.styleable#View_rotation + */ + public void setRotation(float rotation) { + ensureTransformationInfo(); + final TransformationInfo info = mTransformationInfo; + if (info.mRotation != rotation) { + invalidateParentCaches(); + // Double-invalidation is necessary to capture view's old and new areas + invalidate(false); + info.mRotation = rotation; + info.mMatrixDirty = true; + mPrivateFlags |= DRAWN; // force another invalidation with the new orientation + invalidate(false); + } + } + /** + * The degrees that the view is rotated around the vertical axis through the pivot point. + * + * @see #getPivotX() + * @see #getPivotY() + * @see #setRotationY(float) + * + * @return The degrees of Y rotation. + */ + @ViewDebug.ExportedProperty(category = "drawing") + public float getRotationY() { + return mTransformationInfo != null ? mTransformationInfo.mRotationY : 0; + } + /** + * Sets the degrees that the view is rotated around the vertical axis through the pivot point. + * Increasing values result in counter-clockwise rotation from the viewpoint of looking + * down the y axis. + * + * When rotating large views, it is recommended to adjust the camera distance + * accordingly. Refer to {@link #setCameraDistance(float)} for more information. + * + * @param rotationY The degrees of Y rotation. + * + * @see #getRotationY() + * @see #getPivotX() + * @see #getPivotY() + * @see #setRotation(float) + * @see #setRotationX(float) + * @see #setCameraDistance(float) + * + * @attr ref android.R.styleable#View_rotationY + */ + public void setRotationY(float rotationY) { + ensureTransformationInfo(); + final TransformationInfo info = mTransformationInfo; + if (info.mRotationY != rotationY) { + invalidateParentCaches(); + // Double-invalidation is necessary to capture view's old and new areas + invalidate(false); + info.mRotationY = rotationY; + info.mMatrixDirty = true; + mPrivateFlags |= DRAWN; // force another invalidation with the new orientation + invalidate(false); + } + } + /** + * The degrees that the view is rotated around the horizontal axis through the pivot point. + * + * @see #getPivotX() + * @see #getPivotY() + * @see #setRotationX(float) + * + * @return The degrees of X rotation. + */ + @ViewDebug.ExportedProperty(category = "drawing") + public float getRotationX() { + return mTransformationInfo != null ? mTransformationInfo.mRotationX : 0; + } + /** + * Sets the degrees that the view is rotated around the horizontal axis through the pivot point. + * Increasing values result in clockwise rotation from the viewpoint of looking down the + * x axis. + * + * When rotating large views, it is recommended to adjust the camera distance + * accordingly. Refer to {@link #setCameraDistance(float)} for more information. + * + * @param rotationX The degrees of X rotation. + * + * @see #getRotationX() + * @see #getPivotX() + * @see #getPivotY() + * @see #setRotation(float) + * @see #setRotationY(float) + * @see #setCameraDistance(float) + * + * @attr ref android.R.styleable#View_rotationX + */ + public void setRotationX(float rotationX) { + ensureTransformationInfo(); + final TransformationInfo info = mTransformationInfo; + if (info.mRotationX != rotationX) { + invalidateParentCaches(); + // Double-invalidation is necessary to capture view's old and new areas + invalidate(false); + info.mRotationX = rotationX; + info.mMatrixDirty = true; + mPrivateFlags |= DRAWN; // force another invalidation with the new orientation + invalidate(false); + } + } + /** + * The amount that the view is scaled in x around the pivot point, as a proportion of + * the view's unscaled width. A value of 1, the default, means that no scaling is applied. + * + *

By default, this is 1.0f. + * + * @see #getPivotX() + * @see #getPivotY() + * @return The scaling factor. + */ + @ViewDebug.ExportedProperty(category = "drawing") + public float getScaleX() { + return mTransformationInfo != null ? mTransformationInfo.mScaleX : 1; + } + /** + * Sets the amount that the view is scaled in x around the pivot point, as a proportion of + * the view's unscaled width. A value of 1 means that no scaling is applied. + * + * @param scaleX The scaling factor. + * @see #getPivotX() + * @see #getPivotY() + * + * @attr ref android.R.styleable#View_scaleX + */ + public void setScaleX(float scaleX) { + ensureTransformationInfo(); + final TransformationInfo info = mTransformationInfo; + if (info.mScaleX != scaleX) { + invalidateParentCaches(); + // Double-invalidation is necessary to capture view's old and new areas + invalidate(false); + info.mScaleX = scaleX; + info.mMatrixDirty = true; + mPrivateFlags |= DRAWN; // force another invalidation with the new orientation + invalidate(false); + } + } + /** + * The amount that the view is scaled in y around the pivot point, as a proportion of + * the view's unscaled height. A value of 1, the default, means that no scaling is applied. + * + *

By default, this is 1.0f. + * + * @see #getPivotX() + * @see #getPivotY() + * @return The scaling factor. + */ + @ViewDebug.ExportedProperty(category = "drawing") + public float getScaleY() { + return mTransformationInfo != null ? mTransformationInfo.mScaleY : 1; + } + /** + * Sets the amount that the view is scaled in Y around the pivot point, as a proportion of + * the view's unscaled width. A value of 1 means that no scaling is applied. + * + * @param scaleY The scaling factor. + * @see #getPivotX() + * @see #getPivotY() + * + * @attr ref android.R.styleable#View_scaleY + */ + public void setScaleY(float scaleY) { + ensureTransformationInfo(); + final TransformationInfo info = mTransformationInfo; + if (info.mScaleY != scaleY) { + invalidateParentCaches(); + // Double-invalidation is necessary to capture view's old and new areas + invalidate(false); + info.mScaleY = scaleY; + info.mMatrixDirty = true; + mPrivateFlags |= DRAWN; // force another invalidation with the new orientation + invalidate(false); + } + } + /** + * The x location of the point around which the view is {@link #setRotation(float) rotated} + * and {@link #setScaleX(float) scaled}. + * + * @see #getRotation() + * @see #getScaleX() + * @see #getScaleY() + * @see #getPivotY() + * @return The x location of the pivot point. + */ + @ViewDebug.ExportedProperty(category = "drawing") + public float getPivotX() { + return mTransformationInfo != null ? mTransformationInfo.mPivotX : 0; + } + /** + * Sets the x location of the point around which the view is + * {@link #setRotation(float) rotated} and {@link #setScaleX(float) scaled}. + * By default, the pivot point is centered on the object. + * Setting this property disables this behavior and causes the view to use only the + * explicitly set pivotX and pivotY values. + * + * @param pivotX The x location of the pivot point. + * @see #getRotation() + * @see #getScaleX() + * @see #getScaleY() + * @see #getPivotY() + * + * @attr ref android.R.styleable#View_transformPivotX + */ + public void setPivotX(float pivotX) { + ensureTransformationInfo(); + mPrivateFlags |= PIVOT_EXPLICITLY_SET; + final TransformationInfo info = mTransformationInfo; + if (info.mPivotX != pivotX) { + invalidateParentCaches(); + // Double-invalidation is necessary to capture view's old and new areas + invalidate(false); + info.mPivotX = pivotX; + info.mMatrixDirty = true; + mPrivateFlags |= DRAWN; // force another invalidation with the new orientation + invalidate(false); + } + } + /** + * The y location of the point around which the view is {@link #setRotation(float) rotated} + * and {@link #setScaleY(float) scaled}. + * + * @see #getRotation() + * @see #getScaleX() + * @see #getScaleY() + * @see #getPivotY() + * @return The y location of the pivot point. + */ + @ViewDebug.ExportedProperty(category = "drawing") + public float getPivotY() { + return mTransformationInfo != null ? mTransformationInfo.mPivotY : 0; + } + /** + * Sets the y location of the point around which the view is {@link #setRotation(float) rotated} + * and {@link #setScaleY(float) scaled}. By default, the pivot point is centered on the object. + * Setting this property disables this behavior and causes the view to use only the + * explicitly set pivotX and pivotY values. + * + * @param pivotY The y location of the pivot point. + * @see #getRotation() + * @see #getScaleX() + * @see #getScaleY() + * @see #getPivotY() + * + * @attr ref android.R.styleable#View_transformPivotY + */ + public void setPivotY(float pivotY) { + ensureTransformationInfo(); + mPrivateFlags |= PIVOT_EXPLICITLY_SET; + final TransformationInfo info = mTransformationInfo; + if (info.mPivotY != pivotY) { + invalidateParentCaches(); + // Double-invalidation is necessary to capture view's old and new areas + invalidate(false); + info.mPivotY = pivotY; + info.mMatrixDirty = true; + mPrivateFlags |= DRAWN; // force another invalidation with the new orientation + invalidate(false); + } + } + /** + * The opacity of the view. This is a value from 0 to 1, where 0 means the view is + * completely transparent and 1 means the view is completely opaque. + * + *

By default this is 1.0f. + * @return The opacity of the view. + */ + @ViewDebug.ExportedProperty(category = "drawing") + public float getAlpha() { + return mTransformationInfo != null ? mTransformationInfo.mAlpha : 1; + } + /** + *

Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is + * completely transparent and 1 means the view is completely opaque.

+ * + *

If this view overrides {@link #onSetAlpha(int)} to return true, then this view is + * responsible for applying the opacity itself. Otherwise, calling this method is + * equivalent to calling {@link #setLayerType(int, android.graphics.Paint)} and + * setting a hardware layer.

+ * + *

Note that setting alpha to a translucent value (0 < alpha < 1) may have + * performance implications. It is generally best to use the alpha property sparingly and + * transiently, as in the case of fading animations.

+ * + * @param alpha The opacity of the view. + * + * @see #setLayerType(int, android.graphics.Paint) + * + * @attr ref android.R.styleable#View_alpha + */ + public void setAlpha(float alpha) { + ensureTransformationInfo(); + if (mTransformationInfo.mAlpha != alpha) { + mTransformationInfo.mAlpha = alpha; + invalidateParentCaches(); + if (onSetAlpha((int) (alpha * 255))) { + mPrivateFlags |= ALPHA_SET; + // subclass is handling alpha - don't optimize rendering cache invalidation + invalidate(true); + } else { + mPrivateFlags &= ~ALPHA_SET; + invalidate(false); + } + } + } + /** + * Faster version of setAlpha() which performs the same steps except there are + * no calls to invalidate(). The caller of this function should perform proper invalidation + * on the parent and this object. The return value indicates whether the subclass handles + * alpha (the return value for onSetAlpha()). + * + * @param alpha The new value for the alpha property + * @return true if the View subclass handles alpha (the return value for onSetAlpha()) and + * the new value for the alpha property is different from the old value + */ + boolean setAlphaNoInvalidation(float alpha) { + ensureTransformationInfo(); + if (mTransformationInfo.mAlpha != alpha) { + mTransformationInfo.mAlpha = alpha; + boolean subclassHandlesAlpha = onSetAlpha((int) (alpha * 255)); + if (subclassHandlesAlpha) { + mPrivateFlags |= ALPHA_SET; + return true; + } else { + mPrivateFlags &= ~ALPHA_SET; + } + } + return false; + } + /** + * Top position of this view relative to its parent. + * + * @return The top of this view, in pixels. + */ + @ViewDebug.CapturedViewProperty + public final int getTop() { + return mTop; + } + /** + * Sets the top position of this view relative to its parent. This method is meant to be called + * by the layout system and should not generally be called otherwise, because the property + * may be changed at any time by the layout. + * + * @param top The top of this view, in pixels. + */ + public final void setTop(int top) { + if (top != mTop) { + updateMatrix(); + final boolean matrixIsIdentity = mTransformationInfo == null + || mTransformationInfo.mMatrixIsIdentity; + if (matrixIsIdentity) { + if (mAttachInfo != null) { + int minTop; + int yLoc; + if (top < mTop) { + minTop = top; + yLoc = top - mTop; + } else { + minTop = mTop; + yLoc = 0; + } + invalidate(0, yLoc, mRight - mLeft, mBottom - minTop); + } + } else { + // Double-invalidation is necessary to capture view's old and new areas + invalidate(true); + } + int width = mRight - mLeft; + int oldHeight = mBottom - mTop; + mTop = top; + onSizeChanged(width, mBottom - mTop, width, oldHeight); + if (!matrixIsIdentity) { + if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { + // A change in dimension means an auto-centered pivot point changes, too + mTransformationInfo.mMatrixDirty = true; + } + mPrivateFlags |= DRAWN; // force another invalidation with the new orientation + invalidate(true); + } + mBackgroundSizeChanged = true; + invalidateParentIfNeeded(); + } + } + /** + * Bottom position of this view relative to its parent. + * + * @return The bottom of this view, in pixels. + */ + @ViewDebug.CapturedViewProperty + public final int getBottom() { + return mBottom; + } + /** + * True if this view has changed since the last time being drawn. + * + * @return The dirty state of this view. + */ + public boolean isDirty() { + return (mPrivateFlags & DIRTY_MASK) != 0; + } + /** + * Sets the bottom position of this view relative to its parent. This method is meant to be + * called by the layout system and should not generally be called otherwise, because the + * property may be changed at any time by the layout. + * + * @param bottom The bottom of this view, in pixels. + */ + public final void setBottom(int bottom) { + if (bottom != mBottom) { + updateMatrix(); + final boolean matrixIsIdentity = mTransformationInfo == null + || mTransformationInfo.mMatrixIsIdentity; + if (matrixIsIdentity) { + if (mAttachInfo != null) { + int maxBottom; + if (bottom < mBottom) { + maxBottom = mBottom; + } else { + maxBottom = bottom; + } + invalidate(0, 0, mRight - mLeft, maxBottom - mTop); + } + } else { + // Double-invalidation is necessary to capture view's old and new areas + invalidate(true); + } + int width = mRight - mLeft; + int oldHeight = mBottom - mTop; + mBottom = bottom; + onSizeChanged(width, mBottom - mTop, width, oldHeight); + if (!matrixIsIdentity) { + if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { + // A change in dimension means an auto-centered pivot point changes, too + mTransformationInfo.mMatrixDirty = true; + } + mPrivateFlags |= DRAWN; // force another invalidation with the new orientation + invalidate(true); + } + mBackgroundSizeChanged = true; + invalidateParentIfNeeded(); + } + } + /** + * Left position of this view relative to its parent. + * + * @return The left edge of this view, in pixels. + */ + @ViewDebug.CapturedViewProperty + public final int getLeft() { + return mLeft; + } + /** + * Sets the left position of this view relative to its parent. This method is meant to be called + * by the layout system and should not generally be called otherwise, because the property + * may be changed at any time by the layout. + * + * @param left The bottom of this view, in pixels. + */ + public final void setLeft(int left) { + if (left != mLeft) { + updateMatrix(); + final boolean matrixIsIdentity = mTransformationInfo == null + || mTransformationInfo.mMatrixIsIdentity; + if (matrixIsIdentity) { + if (mAttachInfo != null) { + int minLeft; + int xLoc; + if (left < mLeft) { + minLeft = left; + xLoc = left - mLeft; + } else { + minLeft = mLeft; + xLoc = 0; + } + invalidate(xLoc, 0, mRight - minLeft, mBottom - mTop); + } + } else { + // Double-invalidation is necessary to capture view's old and new areas + invalidate(true); + } + int oldWidth = mRight - mLeft; + int height = mBottom - mTop; + mLeft = left; + onSizeChanged(mRight - mLeft, height, oldWidth, height); + if (!matrixIsIdentity) { + if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { + // A change in dimension means an auto-centered pivot point changes, too + mTransformationInfo.mMatrixDirty = true; + } + mPrivateFlags |= DRAWN; // force another invalidation with the new orientation + invalidate(true); + } + mBackgroundSizeChanged = true; + invalidateParentIfNeeded(); + } + } + /** + * Right position of this view relative to its parent. + * + * @return The right edge of this view, in pixels. + */ + @ViewDebug.CapturedViewProperty + public final int getRight() { + return mRight; + } + /** + * Sets the right position of this view relative to its parent. This method is meant to be called + * by the layout system and should not generally be called otherwise, because the property + * may be changed at any time by the layout. + * + * @param right The bottom of this view, in pixels. + */ + public final void setRight(int right) { + if (right != mRight) { + updateMatrix(); + final boolean matrixIsIdentity = mTransformationInfo == null + || mTransformationInfo.mMatrixIsIdentity; + if (matrixIsIdentity) { + if (mAttachInfo != null) { + int maxRight; + if (right < mRight) { + maxRight = mRight; + } else { + maxRight = right; + } + invalidate(0, 0, maxRight - mLeft, mBottom - mTop); + } + } else { + // Double-invalidation is necessary to capture view's old and new areas + invalidate(true); + } + int oldWidth = mRight - mLeft; + int height = mBottom - mTop; + mRight = right; + onSizeChanged(mRight - mLeft, height, oldWidth, height); + if (!matrixIsIdentity) { + if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { + // A change in dimension means an auto-centered pivot point changes, too + mTransformationInfo.mMatrixDirty = true; + } + mPrivateFlags |= DRAWN; // force another invalidation with the new orientation + invalidate(true); + } + mBackgroundSizeChanged = true; + invalidateParentIfNeeded(); + } + } + /** + * The visual x position of this view, in pixels. This is equivalent to the + * {@link #setTranslationX(float) translationX} property plus the current + * {@link #getLeft() left} property. + * + * @return The visual x position of this view, in pixels. + */ + @ViewDebug.ExportedProperty(category = "drawing") + public float getX() { + return mLeft + (mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0); + } + /** + * Sets the visual x position of this view, in pixels. This is equivalent to setting the + * {@link #setTranslationX(float) translationX} property to be the difference between + * the x value passed in and the current {@link #getLeft() left} property. + * + * @param x The visual x position of this view, in pixels. + */ + public void setX(float x) { + setTranslationX(x - mLeft); + } + /** + * The visual y position of this view, in pixels. This is equivalent to the + * {@link #setTranslationY(float) translationY} property plus the current + * {@link #getTop() top} property. + * + * @return The visual y position of this view, in pixels. + */ + @ViewDebug.ExportedProperty(category = "drawing") + public float getY() { + return mTop + (mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0); + } + /** + * Sets the visual y position of this view, in pixels. This is equivalent to setting the + * {@link #setTranslationY(float) translationY} property to be the difference between + * the y value passed in and the current {@link #getTop() top} property. + * + * @param y The visual y position of this view, in pixels. + */ + public void setY(float y) { + setTranslationY(y - mTop); + } + /** + * The horizontal location of this view relative to its {@link #getLeft() left} position. + * This position is post-layout, in addition to wherever the object's + * layout placed it. + * + * @return The horizontal position of this view relative to its left position, in pixels. + */ + @ViewDebug.ExportedProperty(category = "drawing") + public float getTranslationX() { + return mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0; + } + /** + * Sets the horizontal location of this view relative to its {@link #getLeft() left} position. + * This effectively positions the object post-layout, in addition to wherever the object's + * layout placed it. + * + * @param translationX The horizontal position of this view relative to its left position, + * in pixels. + * + * @attr ref android.R.styleable#View_translationX + */ + public void setTranslationX(float translationX) { + ensureTransformationInfo(); + final TransformationInfo info = mTransformationInfo; + if (info.mTranslationX != translationX) { + invalidateParentCaches(); + // Double-invalidation is necessary to capture view's old and new areas + invalidate(false); + info.mTranslationX = translationX; + info.mMatrixDirty = true; + mPrivateFlags |= DRAWN; // force another invalidation with the new orientation + invalidate(false); + } + } + /** + * The horizontal location of this view relative to its {@link #getTop() top} position. + * This position is post-layout, in addition to wherever the object's + * layout placed it. + * + * @return The vertical position of this view relative to its top position, + * in pixels. + */ + @ViewDebug.ExportedProperty(category = "drawing") + public float getTranslationY() { + return mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0; + } + /** + * Sets the vertical location of this view relative to its {@link #getTop() top} position. + * This effectively positions the object post-layout, in addition to wherever the object's + * layout placed it. + * + * @param translationY The vertical position of this view relative to its top position, + * in pixels. + * + * @attr ref android.R.styleable#View_translationY + */ + public void setTranslationY(float translationY) { + ensureTransformationInfo(); + final TransformationInfo info = mTransformationInfo; + if (info.mTranslationY != translationY) { + invalidateParentCaches(); + // Double-invalidation is necessary to capture view's old and new areas + invalidate(false); + info.mTranslationY = translationY; + info.mMatrixDirty = true; + mPrivateFlags |= DRAWN; // force another invalidation with the new orientation + invalidate(false); + } + } + /** + * Hit rectangle in parent's coordinates + * + * @param outRect The hit rectangle of the view. + */ + public void getHitRect(Rect outRect) { + updateMatrix(); + final TransformationInfo info = mTransformationInfo; + if (info == null || info.mMatrixIsIdentity || mAttachInfo == null) { + outRect.set(mLeft, mTop, mRight, mBottom); + } else { + final RectF tmpRect = mAttachInfo.mTmpTransformRect; + tmpRect.set(-info.mPivotX, -info.mPivotY, + getWidth() - info.mPivotX, getHeight() - info.mPivotY); + info.mMatrix.mapRect(tmpRect); + outRect.set((int) tmpRect.left + mLeft, (int) tmpRect.top + mTop, + (int) tmpRect.right + mLeft, (int) tmpRect.bottom + mTop); + } + } + /** + * Determines whether the given point, in local coordinates is inside the view. + */ + /*package*/ final boolean pointInView(float localX, float localY) { + return localX >= 0 && localX < (mRight - mLeft) + && localY >= 0 && localY < (mBottom - mTop); + } + /** + * Utility method to determine whether the given point, in local coordinates, + * is inside the view, where the area of the view is expanded by the slop factor. + * This method is called while processing touch-move events to determine if the event + * is still within the view. + */ + private boolean pointInView(float localX, float localY, float slop) { + return localX >= -slop && localY >= -slop && localX < ((mRight - mLeft) + slop) && + localY < ((mBottom - mTop) + slop); + } + /** + * When a view has focus and the user navigates away from it, the next view is searched for + * starting from the rectangle filled in by this method. + * + * By default, the rectange is the {@link #getDrawingRect(android.graphics.Rect)}) + * of the view. However, if your view maintains some idea of internal selection, + * such as a cursor, or a selected row or column, you should override this method and + * fill in a more specific rectangle. + * + * @param r The rectangle to fill in, in this view's coordinates. + */ + public void getFocusedRect(Rect r) { + getDrawingRect(r); + } + /** + * If some part of this view is not clipped by any of its parents, then + * return that area in r in global (root) coordinates. To convert r to local + * coordinates (without taking possible View rotations into account), offset + * it by -globalOffset (e.g. r.offset(-globalOffset.x, -globalOffset.y)). + * If the view is completely clipped or translated out, return false. + * + * @param r If true is returned, r holds the global coordinates of the + * visible portion of this view. + * @param globalOffset If true is returned, globalOffset holds the dx,dy + * between this view and its root. globalOffet may be null. + * @return true if r is non-empty (i.e. part of the view is visible at the + * root level. + */ + public boolean getGlobalVisibleRect(Rect r, Point globalOffset) { + int width = mRight - mLeft; + int height = mBottom - mTop; + if (width > 0 && height > 0) { + r.set(0, 0, width, height); + if (globalOffset != null) { + globalOffset.set(-mScrollX, -mScrollY); + } + return mParent == null || mParent.getChildVisibleRect(this, r, globalOffset); + } + return false; + } + public final boolean getGlobalVisibleRect(Rect r) { + return getGlobalVisibleRect(r, null); + } + public final boolean getLocalVisibleRect(Rect r) { + Point offset = new Point(); + if (getGlobalVisibleRect(r, offset)) { + r.offset(-offset.x, -offset.y); // make r local + return true; + } + return false; + } + /** + * Offset this view's vertical location by the specified number of pixels. + * + * @param offset the number of pixels to offset the view by + */ + public void offsetTopAndBottom(int offset) { + if (offset != 0) { + updateMatrix(); + final boolean matrixIsIdentity = mTransformationInfo == null + || mTransformationInfo.mMatrixIsIdentity; + if (matrixIsIdentity) { + final ViewParent p = mParent; + if (p != null && mAttachInfo != null) { + final Rect r = mAttachInfo.mTmpInvalRect; + int minTop; + int maxBottom; + int yLoc; + if (offset < 0) { + minTop = mTop + offset; + maxBottom = mBottom; + yLoc = offset; + } else { + minTop = mTop; + maxBottom = mBottom + offset; + yLoc = 0; + } + r.set(0, yLoc, mRight - mLeft, maxBottom - minTop); + p.invalidateChild(this, r); + } + } else { + invalidate(false); + } + mTop += offset; + mBottom += offset; + if (!matrixIsIdentity) { + mPrivateFlags |= DRAWN; // force another invalidation with the new orientation + invalidate(false); + } + invalidateParentIfNeeded(); + } + } + /** + * Offset this view's horizontal location by the specified amount of pixels. + * + * @param offset the numer of pixels to offset the view by + */ + public void offsetLeftAndRight(int offset) { + if (offset != 0) { + updateMatrix(); + final boolean matrixIsIdentity = mTransformationInfo == null + || mTransformationInfo.mMatrixIsIdentity; + if (matrixIsIdentity) { + final ViewParent p = mParent; + if (p != null && mAttachInfo != null) { + final Rect r = mAttachInfo.mTmpInvalRect; + int minLeft; + int maxRight; + if (offset < 0) { + minLeft = mLeft + offset; + maxRight = mRight; + } else { + minLeft = mLeft; + maxRight = mRight + offset; + } + r.set(0, 0, maxRight - minLeft, mBottom - mTop); + p.invalidateChild(this, r); + } + } else { + invalidate(false); + } + mLeft += offset; + mRight += offset; + if (!matrixIsIdentity) { + mPrivateFlags |= DRAWN; // force another invalidation with the new orientation + invalidate(false); + } + invalidateParentIfNeeded(); + } + } + /** + * Get the LayoutParams associated with this view. All views should have + * layout parameters. These supply parameters to the parent of this + * view specifying how it should be arranged. There are many subclasses of + * ViewGroup.LayoutParams, and these correspond to the different subclasses + * of ViewGroup that are responsible for arranging their children. + * + * This method may return null if this View is not attached to a parent + * ViewGroup or {@link #setLayoutParams(android.view.ViewGroup.LayoutParams)} + * was not invoked successfully. When a View is attached to a parent + * ViewGroup, this method must not return null. + * + * @return The LayoutParams associated with this view, or null if no + * parameters have been set yet + */ + @ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") + public ViewGroup.LayoutParams getLayoutParams() { + return mLayoutParams; + } + /** + * Set the layout parameters associated with this view. These supply + * parameters to the parent of this view specifying how it should be + * arranged. There are many subclasses of ViewGroup.LayoutParams, and these + * correspond to the different subclasses of ViewGroup that are responsible + * for arranging their children. + * + * @param params The layout parameters for this view, cannot be null + */ + public void setLayoutParams(ViewGroup.LayoutParams params) { + if (params == null) { + throw new NullPointerException("Layout parameters cannot be null"); + } + mLayoutParams = params; + if (mParent instanceof ViewGroup) { + ((ViewGroup) mParent).onSetLayoutParams(this, params); + } + requestLayout(); + } + /** + * Set the scrolled position of your view. This will cause a call to + * {@link #onScrollChanged(int, int, int, int)} and the view will be + * invalidated. + * @param x the x position to scroll to + * @param y the y position to scroll to + */ + public void scrollTo(int x, int y) { + if (mScrollX != x || mScrollY != y) { + int oldX = mScrollX; + int oldY = mScrollY; + mScrollX = x; + mScrollY = y; + invalidateParentCaches(); + onScrollChanged(mScrollX, mScrollY, oldX, oldY); + if (!awakenScrollBars()) { + invalidate(true); + } + } + } + /** + * Move the scrolled position of your view. This will cause a call to + * {@link #onScrollChanged(int, int, int, int)} and the view will be + * invalidated. + * @param x the amount of pixels to scroll by horizontally + * @param y the amount of pixels to scroll by vertically + */ + public void scrollBy(int x, int y) { + scrollTo(mScrollX + x, mScrollY + y); + } + /** + *

Trigger the scrollbars to draw. When invoked this method starts an + * animation to fade the scrollbars out after a default delay. If a subclass + * provides animated scrolling, the start delay should equal the duration + * of the scrolling animation.

+ * + *

The animation starts only if at least one of the scrollbars is + * enabled, as specified by {@link #isHorizontalScrollBarEnabled()} and + * {@link #isVerticalScrollBarEnabled()}. When the animation is started, + * this method returns true, and false otherwise. If the animation is + * started, this method calls {@link #invalidate()}; in that case the + * caller should not call {@link #invalidate()}.

+ * + *

This method should be invoked every time a subclass directly updates + * the scroll parameters.

+ * + *

This method is automatically invoked by {@link #scrollBy(int, int)} + * and {@link #scrollTo(int, int)}.

+ * + * @return true if the animation is played, false otherwise + * + * @see #awakenScrollBars(int) + * @see #scrollBy(int, int) + * @see #scrollTo(int, int) + * @see #isHorizontalScrollBarEnabled() + * @see #isVerticalScrollBarEnabled() + * @see #setHorizontalScrollBarEnabled(boolean) + * @see #setVerticalScrollBarEnabled(boolean) + */ + protected boolean awakenScrollBars() { + return mScrollCache != null && + awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade, true); + } + /** + * Trigger the scrollbars to draw. + * This method differs from awakenScrollBars() only in its default duration. + * initialAwakenScrollBars() will show the scroll bars for longer than + * usual to give the user more of a chance to notice them. + * + * @return true if the animation is played, false otherwise. + */ + private boolean initialAwakenScrollBars() { + return mScrollCache != null && + awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade * 4, true); + } + /** + *

+ * Trigger the scrollbars to draw. When invoked this method starts an + * animation to fade the scrollbars out after a fixed delay. If a subclass + * provides animated scrolling, the start delay should equal the duration of + * the scrolling animation. + *

+ * + *

+ * The animation starts only if at least one of the scrollbars is enabled, + * as specified by {@link #isHorizontalScrollBarEnabled()} and + * {@link #isVerticalScrollBarEnabled()}. When the animation is started, + * this method returns true, and false otherwise. If the animation is + * started, this method calls {@link #invalidate()}; in that case the caller + * should not call {@link #invalidate()}. + *

+ * + *

+ * This method should be invoked everytime a subclass directly updates the + * scroll parameters. + *

+ * + * @param startDelay the delay, in milliseconds, after which the animation + * should start; when the delay is 0, the animation starts + * immediately + * @return true if the animation is played, false otherwise + * + * @see #scrollBy(int, int) + * @see #scrollTo(int, int) + * @see #isHorizontalScrollBarEnabled() + * @see #isVerticalScrollBarEnabled() + * @see #setHorizontalScrollBarEnabled(boolean) + * @see #setVerticalScrollBarEnabled(boolean) + */ + protected boolean awakenScrollBars(int startDelay) { + return awakenScrollBars(startDelay, true); + } + /** + *

+ * Trigger the scrollbars to draw. When invoked this method starts an + * animation to fade the scrollbars out after a fixed delay. If a subclass + * provides animated scrolling, the start delay should equal the duration of + * the scrolling animation. + *

+ * + *

+ * The animation starts only if at least one of the scrollbars is enabled, + * as specified by {@link #isHorizontalScrollBarEnabled()} and + * {@link #isVerticalScrollBarEnabled()}. When the animation is started, + * this method returns true, and false otherwise. If the animation is + * started, this method calls {@link #invalidate()} if the invalidate parameter + * is set to true; in that case the caller + * should not call {@link #invalidate()}. + *

+ * + *

+ * This method should be invoked everytime a subclass directly updates the + * scroll parameters. + *

+ * + * @param startDelay the delay, in milliseconds, after which the animation + * should start; when the delay is 0, the animation starts + * immediately + * + * @param invalidate Wheter this method should call invalidate + * + * @return true if the animation is played, false otherwise + * + * @see #scrollBy(int, int) + * @see #scrollTo(int, int) + * @see #isHorizontalScrollBarEnabled() + * @see #isVerticalScrollBarEnabled() + * @see #setHorizontalScrollBarEnabled(boolean) + * @see #setVerticalScrollBarEnabled(boolean) + */ + protected boolean awakenScrollBars(int startDelay, boolean invalidate) { + final ScrollabilityCache scrollCache = mScrollCache; + if (scrollCache == null || !scrollCache.fadeScrollBars) { + return false; + } + if (scrollCache.scrollBar == null) { + scrollCache.scrollBar = new ScrollBarDrawable(); + } + if (isHorizontalScrollBarEnabled() || isVerticalScrollBarEnabled()) { + if (invalidate) { + // Invalidate to show the scrollbars + invalidate(true); + } + if (scrollCache.state == ScrollabilityCache.OFF) { + // FIXME: this is copied from WindowManagerService. + // We should get this value from the system when it + // is possible to do so. + final int KEY_REPEAT_FIRST_DELAY = 750; + startDelay = Math.max(KEY_REPEAT_FIRST_DELAY, startDelay); + } + // Tell mScrollCache when we should start fading. This may + // extend the fade start time if one was already scheduled + long fadeStartTime = AnimationUtils.currentAnimationTimeMillis() + startDelay; + scrollCache.fadeStartTime = fadeStartTime; + scrollCache.state = ScrollabilityCache.ON; + // Schedule our fader to run, unscheduling any old ones first + if (mAttachInfo != null) { + mAttachInfo.mHandler.removeCallbacks(scrollCache); + mAttachInfo.mHandler.postAtTime(scrollCache, fadeStartTime); + } + return true; + } + return false; + } + /** + * Do not invalidate views which are not visible and which are not running an animation. They + * will not get drawn and they should not set dirty flags as if they will be drawn + */ + private boolean skipInvalidate() { + return (mViewFlags & VISIBILITY_MASK) != VISIBLE && mCurrentAnimation == null && + (!(mParent instanceof ViewGroup) || + !((ViewGroup) mParent).isViewTransitioning(this)); + } + /** + * Mark the area defined by dirty as needing to be drawn. If the view is + * visible, {@link #onDraw(android.graphics.Canvas)} will be called at some point + * in the future. This must be called from a UI thread. To call from a non-UI + * thread, call {@link #postInvalidate()}. + * + * WARNING: This method is destructive to dirty. + * @param dirty the rectangle representing the bounds of the dirty region + */ + public void invalidate(Rect dirty) { + if (ViewDebug.TRACE_HIERARCHY) { + ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); + } + if (skipInvalidate()) { + return; + } + if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || + (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || + (mPrivateFlags & INVALIDATED) != INVALIDATED) { + mPrivateFlags &= ~DRAWING_CACHE_VALID; + mPrivateFlags |= INVALIDATED; + mPrivateFlags |= DIRTY; + final ViewParent p = mParent; + final AttachInfo ai = mAttachInfo; + //noinspection PointlessBooleanExpression,ConstantConditions + if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { + if (p != null && ai != null && ai.mHardwareAccelerated) { + // fast-track for GL-enabled applications; just invalidate the whole hierarchy + // with a null dirty rect, which tells the ViewAncestor to redraw everything + p.invalidateChild(this, null); + return; + } + } + if (p != null && ai != null) { + final int scrollX = mScrollX; + final int scrollY = mScrollY; + final Rect r = ai.mTmpInvalRect; + r.set(dirty.left - scrollX, dirty.top - scrollY, + dirty.right - scrollX, dirty.bottom - scrollY); + mParent.invalidateChild(this, r); + } + } + } + /** + * Mark the area defined by the rect (l,t,r,b) as needing to be drawn. + * The coordinates of the dirty rect are relative to the view. + * If the view is visible, {@link #onDraw(android.graphics.Canvas)} + * will be called at some point in the future. This must be called from + * a UI thread. To call from a non-UI thread, call {@link #postInvalidate()}. + * @param l the left position of the dirty region + * @param t the top position of the dirty region + * @param r the right position of the dirty region + * @param b the bottom position of the dirty region + */ + public void invalidate(int l, int t, int r, int b) { + if (ViewDebug.TRACE_HIERARCHY) { + ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); + } + if (skipInvalidate()) { + return; + } + if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || + (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || + (mPrivateFlags & INVALIDATED) != INVALIDATED) { + mPrivateFlags &= ~DRAWING_CACHE_VALID; + mPrivateFlags |= INVALIDATED; + mPrivateFlags |= DIRTY; + final ViewParent p = mParent; + final AttachInfo ai = mAttachInfo; + //noinspection PointlessBooleanExpression,ConstantConditions + if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { + if (p != null && ai != null && ai.mHardwareAccelerated) { + // fast-track for GL-enabled applications; just invalidate the whole hierarchy + // with a null dirty rect, which tells the ViewAncestor to redraw everything + p.invalidateChild(this, null); + return; + } + } + if (p != null && ai != null && l < r && t < b) { + final int scrollX = mScrollX; + final int scrollY = mScrollY; + final Rect tmpr = ai.mTmpInvalRect; + tmpr.set(l - scrollX, t - scrollY, r - scrollX, b - scrollY); + p.invalidateChild(this, tmpr); + } + } + } + /** + * Invalidate the whole view. If the view is visible, + * {@link #onDraw(android.graphics.Canvas)} will be called at some point in + * the future. This must be called from a UI thread. To call from a non-UI thread, + * call {@link #postInvalidate()}. + */ + public void invalidate() { + invalidate(true); + } + /** + * This is where the invalidate() work actually happens. A full invalidate() + * causes the drawing cache to be invalidated, but this function can be called with + * invalidateCache set to false to skip that invalidation step for cases that do not + * need it (for example, a component that remains at the same dimensions with the same + * content). + * + * @param invalidateCache Whether the drawing cache for this view should be invalidated as + * well. This is usually true for a full invalidate, but may be set to false if the + * View's contents or dimensions have not changed. + */ + void invalidate(boolean invalidateCache) { + if (ViewDebug.TRACE_HIERARCHY) { + ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); + } + if (skipInvalidate()) { + return; + } + if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || + (invalidateCache && (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) || + (mPrivateFlags & INVALIDATED) != INVALIDATED || isOpaque() != mLastIsOpaque) { + mLastIsOpaque = isOpaque(); + mPrivateFlags &= ~DRAWN; + mPrivateFlags |= DIRTY; + if (invalidateCache) { + mPrivateFlags |= INVALIDATED; + mPrivateFlags &= ~DRAWING_CACHE_VALID; + } + final AttachInfo ai = mAttachInfo; + final ViewParent p = mParent; + //noinspection PointlessBooleanExpression,ConstantConditions + if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { + if (p != null && ai != null && ai.mHardwareAccelerated) { + // fast-track for GL-enabled applications; just invalidate the whole hierarchy + // with a null dirty rect, which tells the ViewAncestor to redraw everything + p.invalidateChild(this, null); + return; + } + } + if (p != null && ai != null) { + final Rect r = ai.mTmpInvalRect; + r.set(0, 0, mRight - mLeft, mBottom - mTop); + // Don't call invalidate -- we don't want to internally scroll + // our own bounds + p.invalidateChild(this, r); + } + } + } + /** + * Used to indicate that the parent of this view should clear its caches. This functionality + * is used to force the parent to rebuild its display list (when hardware-accelerated), + * which is necessary when various parent-managed properties of the view change, such as + * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method only + * clears the parent caches and does not causes an invalidate event. + * + * @hide + */ + protected void invalidateParentCaches() { + if (mParent instanceof View) { + ((View) mParent).mPrivateFlags |= INVALIDATED; + } + } + /** + * Used to indicate that the parent of this view should be invalidated. This functionality + * is used to force the parent to rebuild its display list (when hardware-accelerated), + * which is necessary when various parent-managed properties of the view change, such as + * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method will propagate + * an invalidation event to the parent. + * + * @hide + */ + protected void invalidateParentIfNeeded() { + if (isHardwareAccelerated() && mParent instanceof View) { + ((View) mParent).invalidate(true); + } + } + /** + * Indicates whether this View is opaque. An opaque View guarantees that it will + * draw all the pixels overlapping its bounds using a fully opaque color. + * + * Subclasses of View should override this method whenever possible to indicate + * whether an instance is opaque. Opaque Views are treated in a special way by + * the View hierarchy, possibly allowing it to perform optimizations during + * invalidate/draw passes. + * + * @return True if this View is guaranteed to be fully opaque, false otherwise. + */ + @ViewDebug.ExportedProperty(category = "drawing") + public boolean isOpaque() { + return (mPrivateFlags & OPAQUE_MASK) == OPAQUE_MASK && + ((mTransformationInfo != null ? mTransformationInfo.mAlpha : 1) + >= 1.0f - ViewConfiguration.ALPHA_THRESHOLD); + } + /** + * @hide + */ + protected void computeOpaqueFlags() { + // Opaque if: + // - Has a background + // - Background is opaque + // - Doesn't have scrollbars or scrollbars are inside overlay + if (mBGDrawable != null && mBGDrawable.getOpacity() == PixelFormat.OPAQUE) { + mPrivateFlags |= OPAQUE_BACKGROUND; + } else { + mPrivateFlags &= ~OPAQUE_BACKGROUND; + } + final int flags = mViewFlags; + if (((flags & SCROLLBARS_VERTICAL) == 0 && (flags & SCROLLBARS_HORIZONTAL) == 0) || + (flags & SCROLLBARS_STYLE_MASK) == SCROLLBARS_INSIDE_OVERLAY) { + mPrivateFlags |= OPAQUE_SCROLLBARS; + } else { + mPrivateFlags &= ~OPAQUE_SCROLLBARS; + } + } + /** + * @hide + */ + protected boolean hasOpaqueScrollbars() { + return (mPrivateFlags & OPAQUE_SCROLLBARS) == OPAQUE_SCROLLBARS; + } + /** + * @return A handler associated with the thread running the View. This + * handler can be used to pump events in the UI events queue. + */ + public Handler getHandler() { + if (mAttachInfo != null) { + return mAttachInfo.mHandler; + } + return null; + } + /** + * Gets the view root associated with the View. + * @return The view root, or null if none. + * @hide + */ + public ViewRootImpl getViewRootImpl() { + if (mAttachInfo != null) { + return mAttachInfo.mViewRootImpl; + } + return null; + } + /** + *

Causes the Runnable to be added to the message queue. + * The runnable will be run on the user interface thread.

+ * + *

This method can be invoked from outside of the UI thread + * only when this View is attached to a window.

+ * + * @param action The Runnable that will be executed. + * + * @return Returns true if the Runnable was successfully placed in to the + * message queue. Returns false on failure, usually because the + * looper processing the message queue is exiting. + */ + public boolean post(Runnable action) { + final AttachInfo attachInfo = mAttachInfo; + if (attachInfo != null) { + return attachInfo.mHandler.post(action); + } + // Assume that post will succeed later + ViewRootImpl.getRunQueue().post(action); + return true; + } + /** + *

Causes the Runnable to be added to the message queue, to be run + * after the specified amount of time elapses. + * The runnable will be run on the user interface thread.

+ * + *

This method can be invoked from outside of the UI thread + * only when this View is attached to a window.

+ * + * @param action The Runnable that will be executed. + * @param delayMillis The delay (in milliseconds) until the Runnable + * will be executed. + * + * @return true if the Runnable was successfully placed in to the + * message queue. Returns false on failure, usually because the + * looper processing the message queue is exiting. Note that a + * result of true does not mean the Runnable will be processed -- + * if the looper is quit before the delivery time of the message + * occurs then the message will be dropped. + */ + public boolean postDelayed(Runnable action, long delayMillis) { + final AttachInfo attachInfo = mAttachInfo; + if (attachInfo != null) { + return attachInfo.mHandler.postDelayed(action, delayMillis); + } + // Assume that post will succeed later + ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); + return true; + } + /** + *

Removes the specified Runnable from the message queue.

+ * + *

This method can be invoked from outside of the UI thread + * only when this View is attached to a window.

+ * + * @param action The Runnable to remove from the message handling queue + * + * @return true if this view could ask the Handler to remove the Runnable, + * false otherwise. When the returned value is true, the Runnable + * may or may not have been actually removed from the message queue + * (for instance, if the Runnable was not in the queue already.) + */ + public boolean removeCallbacks(Runnable action) { + final AttachInfo attachInfo = mAttachInfo; + if (attachInfo != null) { + attachInfo.mHandler.removeCallbacks(action); + } else { + // Assume that post will succeed later + ViewRootImpl.getRunQueue().removeCallbacks(action); + } + return true; + } + /** + *

Cause an invalidate to happen on a subsequent cycle through the event loop. + * Use this to invalidate the View from a non-UI thread.

+ * + *

This method can be invoked from outside of the UI thread + * only when this View is attached to a window.

+ * + * @see #invalidate() + */ + public void postInvalidate() { + postInvalidateDelayed(0); + } + /** + *

Cause an invalidate of the specified area to happen on a subsequent cycle + * through the event loop. Use this to invalidate the View from a non-UI thread.

+ * + *

This method can be invoked from outside of the UI thread + * only when this View is attached to a window.

+ * + * @param left The left coordinate of the rectangle to invalidate. + * @param top The top coordinate of the rectangle to invalidate. + * @param right The right coordinate of the rectangle to invalidate. + * @param bottom The bottom coordinate of the rectangle to invalidate. + * + * @see #invalidate(int, int, int, int) + * @see #invalidate(Rect) + */ + public void postInvalidate(int left, int top, int right, int bottom) { + postInvalidateDelayed(0, left, top, right, bottom); + } + /** + *

Cause an invalidate to happen on a subsequent cycle through the event + * loop. Waits for the specified amount of time.

+ * + *

This method can be invoked from outside of the UI thread + * only when this View is attached to a window.

+ * + * @param delayMilliseconds the duration in milliseconds to delay the + * invalidation by + */ + public void postInvalidateDelayed(long delayMilliseconds) { + // We try only with the AttachInfo because there's no point in invalidating + // if we are not attached to our window + final AttachInfo attachInfo = mAttachInfo; + if (attachInfo != null) { + attachInfo.mViewRootImpl.dispatchInvalidateDelayed(this, delayMilliseconds); + } + } + /** + *

Cause an invalidate of the specified area to happen on a subsequent cycle + * through the event loop. Waits for the specified amount of time.

+ * + *

This method can be invoked from outside of the UI thread + * only when this View is attached to a window.

+ * + * @param delayMilliseconds the duration in milliseconds to delay the + * invalidation by + * @param left The left coordinate of the rectangle to invalidate. + * @param top The top coordinate of the rectangle to invalidate. + * @param right The right coordinate of the rectangle to invalidate. + * @param bottom The bottom coordinate of the rectangle to invalidate. + */ + public void postInvalidateDelayed(long delayMilliseconds, int left, int top, + int right, int bottom) { + // We try only with the AttachInfo because there's no point in invalidating + // if we are not attached to our window + final AttachInfo attachInfo = mAttachInfo; + if (attachInfo != null) { + final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.acquire(); + info.target = this; + info.left = left; + info.top = top; + info.right = right; + info.bottom = bottom; + attachInfo.mViewRootImpl.dispatchInvalidateRectDelayed(info, delayMilliseconds); + } + } + /** + * Post a callback to send a {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} event. + * This event is sent at most once every + * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. + */ + private void postSendViewScrolledAccessibilityEventCallback() { + if (mSendViewScrolledAccessibilityEvent == null) { + mSendViewScrolledAccessibilityEvent = new SendViewScrolledAccessibilityEvent(); + } + if (!mSendViewScrolledAccessibilityEvent.mIsPending) { + mSendViewScrolledAccessibilityEvent.mIsPending = true; + postDelayed(mSendViewScrolledAccessibilityEvent, + ViewConfiguration.getSendRecurringAccessibilityEventsInterval()); + } + } + /** + * Called by a parent to request that a child update its values for mScrollX + * and mScrollY if necessary. This will typically be done if the child is + * animating a scroll using a {@link android.widget.Scroller Scroller} + * object. + */ + public void computeScroll() { + } + /** + *

Indicate whether the horizontal edges are faded when the view is + * scrolled horizontally.

+ * + * @return true if the horizontal edges should are faded on scroll, false + * otherwise + * + * @see #setHorizontalFadingEdgeEnabled(boolean) + * @attr ref android.R.styleable#View_requiresFadingEdge + */ + public boolean isHorizontalFadingEdgeEnabled() { + return (mViewFlags & FADING_EDGE_HORIZONTAL) == FADING_EDGE_HORIZONTAL; + } + /** + *

Define whether the horizontal edges should be faded when this view + * is scrolled horizontally.

+ * + * @param horizontalFadingEdgeEnabled true if the horizontal edges should + * be faded when the view is scrolled + * horizontally + * + * @see #isHorizontalFadingEdgeEnabled() + * @attr ref android.R.styleable#View_requiresFadingEdge + */ + public void setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled) { + if (isHorizontalFadingEdgeEnabled() != horizontalFadingEdgeEnabled) { + if (horizontalFadingEdgeEnabled) { + initScrollCache(); + } + mViewFlags ^= FADING_EDGE_HORIZONTAL; + } + } + /** + *

Indicate whether the vertical edges are faded when the view is + * scrolled horizontally.

+ * + * @return true if the vertical edges should are faded on scroll, false + * otherwise + * + * @see #setVerticalFadingEdgeEnabled(boolean) + * @attr ref android.R.styleable#View_requiresFadingEdge + */ + public boolean isVerticalFadingEdgeEnabled() { + return (mViewFlags & FADING_EDGE_VERTICAL) == FADING_EDGE_VERTICAL; + } + /** + *

Define whether the vertical edges should be faded when this view + * is scrolled vertically.

+ * + * @param verticalFadingEdgeEnabled true if the vertical edges should + * be faded when the view is scrolled + * vertically + * + * @see #isVerticalFadingEdgeEnabled() + * @attr ref android.R.styleable#View_requiresFadingEdge + */ + public void setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled) { + if (isVerticalFadingEdgeEnabled() != verticalFadingEdgeEnabled) { + if (verticalFadingEdgeEnabled) { + initScrollCache(); + } + mViewFlags ^= FADING_EDGE_VERTICAL; + } + } + /** + * Returns the strength, or intensity, of the top faded edge. The strength is + * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation + * returns 0.0 or 1.0 but no value in between. + * + * Subclasses should override this method to provide a smoother fade transition + * when scrolling occurs. + * + * @return the intensity of the top fade as a float between 0.0f and 1.0f + */ + protected float getTopFadingEdgeStrength() { + return computeVerticalScrollOffset() > 0 ? 1.0f : 0.0f; + } + /** + * Returns the strength, or intensity, of the bottom faded edge. The strength is + * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation + * returns 0.0 or 1.0 but no value in between. + * + * Subclasses should override this method to provide a smoother fade transition + * when scrolling occurs. + * + * @return the intensity of the bottom fade as a float between 0.0f and 1.0f + */ + protected float getBottomFadingEdgeStrength() { + return computeVerticalScrollOffset() + computeVerticalScrollExtent() < + computeVerticalScrollRange() ? 1.0f : 0.0f; + } + /** + * Returns the strength, or intensity, of the left faded edge. The strength is + * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation + * returns 0.0 or 1.0 but no value in between. + * + * Subclasses should override this method to provide a smoother fade transition + * when scrolling occurs. + * + * @return the intensity of the left fade as a float between 0.0f and 1.0f + */ + protected float getLeftFadingEdgeStrength() { + return computeHorizontalScrollOffset() > 0 ? 1.0f : 0.0f; + } + /** + * Returns the strength, or intensity, of the right faded edge. The strength is + * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation + * returns 0.0 or 1.0 but no value in between. + * + * Subclasses should override this method to provide a smoother fade transition + * when scrolling occurs. + * + * @return the intensity of the right fade as a float between 0.0f and 1.0f + */ + protected float getRightFadingEdgeStrength() { + return computeHorizontalScrollOffset() + computeHorizontalScrollExtent() < + computeHorizontalScrollRange() ? 1.0f : 0.0f; + } + /** + *

Indicate whether the horizontal scrollbar should be drawn or not. The + * scrollbar is not drawn by default.

+ * + * @return true if the horizontal scrollbar should be painted, false + * otherwise + * + * @see #setHorizontalScrollBarEnabled(boolean) + */ + public boolean isHorizontalScrollBarEnabled() { + return (mViewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; + } + /** + *

Define whether the horizontal scrollbar should be drawn or not. The + * scrollbar is not drawn by default.

+ * + * @param horizontalScrollBarEnabled true if the horizontal scrollbar should + * be painted + * + * @see #isHorizontalScrollBarEnabled() + */ + public void setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled) { + if (isHorizontalScrollBarEnabled() != horizontalScrollBarEnabled) { + mViewFlags ^= SCROLLBARS_HORIZONTAL; + computeOpaqueFlags(); + resolvePadding(); + } + } + /** + *

Indicate whether the vertical scrollbar should be drawn or not. The + * scrollbar is not drawn by default.

+ * + * @return true if the vertical scrollbar should be painted, false + * otherwise + * + * @see #setVerticalScrollBarEnabled(boolean) + */ + public boolean isVerticalScrollBarEnabled() { + return (mViewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL; + } + /** + *

Define whether the vertical scrollbar should be drawn or not. The + * scrollbar is not drawn by default.

+ * + * @param verticalScrollBarEnabled true if the vertical scrollbar should + * be painted + * + * @see #isVerticalScrollBarEnabled() + */ + public void setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled) { + if (isVerticalScrollBarEnabled() != verticalScrollBarEnabled) { + mViewFlags ^= SCROLLBARS_VERTICAL; + computeOpaqueFlags(); + resolvePadding(); + } + } + /** + * @hide + */ + protected void recomputePadding() { + setPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, mUserPaddingBottom); + } + /** + * Define whether scrollbars will fade when the view is not scrolling. + * + * @param fadeScrollbars wheter to enable fading + * + */ + public void setScrollbarFadingEnabled(boolean fadeScrollbars) { + initScrollCache(); + final ScrollabilityCache scrollabilityCache = mScrollCache; + scrollabilityCache.fadeScrollBars = fadeScrollbars; + if (fadeScrollbars) { + scrollabilityCache.state = ScrollabilityCache.OFF; + } else { + scrollabilityCache.state = ScrollabilityCache.ON; + } + } + /** + * + * Returns true if scrollbars will fade when this view is not scrolling + * + * @return true if scrollbar fading is enabled + */ + public boolean isScrollbarFadingEnabled() { + return mScrollCache != null && mScrollCache.fadeScrollBars; + } + /** + *

Specify the style of the scrollbars. The scrollbars can be overlaid or + * inset. When inset, they add to the padding of the view. And the scrollbars + * can be drawn inside the padding area or on the edge of the view. For example, + * if a view has a background drawable and you want to draw the scrollbars + * inside the padding specified by the drawable, you can use + * SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to + * appear at the edge of the view, ignoring the padding, then you can use + * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.

+ * @param style the style of the scrollbars. Should be one of + * SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET, + * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET. + * @see #SCROLLBARS_INSIDE_OVERLAY + * @see #SCROLLBARS_INSIDE_INSET + * @see #SCROLLBARS_OUTSIDE_OVERLAY + * @see #SCROLLBARS_OUTSIDE_INSET + */ + public void setScrollBarStyle(int style) { + if (style != (mViewFlags & SCROLLBARS_STYLE_MASK)) { + mViewFlags = (mViewFlags & ~SCROLLBARS_STYLE_MASK) | (style & SCROLLBARS_STYLE_MASK); + computeOpaqueFlags(); + resolvePadding(); + } + } + /** + *

Returns the current scrollbar style.

+ * @return the current scrollbar style + * @see #SCROLLBARS_INSIDE_OVERLAY + * @see #SCROLLBARS_INSIDE_INSET + * @see #SCROLLBARS_OUTSIDE_OVERLAY + * @see #SCROLLBARS_OUTSIDE_INSET + */ + @ViewDebug.ExportedProperty(mapping = { + @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_OVERLAY, to = "INSIDE_OVERLAY"), + @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_INSET, to = "INSIDE_INSET"), + @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_OVERLAY, to = "OUTSIDE_OVERLAY"), + @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_INSET, to = "OUTSIDE_INSET") + }) + public int getScrollBarStyle() { + return mViewFlags & SCROLLBARS_STYLE_MASK; + } + /** + *

Compute the horizontal range that the horizontal scrollbar + * represents.

+ * + *

The range is expressed in arbitrary units that must be the same as the + * units used by {@link #computeHorizontalScrollExtent()} and + * {@link #computeHorizontalScrollOffset()}.

+ * + *

The default range is the drawing width of this view.

+ * + * @return the total horizontal range represented by the horizontal + * scrollbar + * + * @see #computeHorizontalScrollExtent() + * @see #computeHorizontalScrollOffset() + * @see android.widget.ScrollBarDrawable + */ + protected int computeHorizontalScrollRange() { + return getWidth(); + } + /** + *

Compute the horizontal offset of the horizontal scrollbar's thumb + * within the horizontal range. This value is used to compute the position + * of the thumb within the scrollbar's track.

+ * + *

The range is expressed in arbitrary units that must be the same as the + * units used by {@link #computeHorizontalScrollRange()} and + * {@link #computeHorizontalScrollExtent()}.

+ * + *

The default offset is the scroll offset of this view.

+ * + * @return the horizontal offset of the scrollbar's thumb + * + * @see #computeHorizontalScrollRange() + * @see #computeHorizontalScrollExtent() + * @see android.widget.ScrollBarDrawable + */ + protected int computeHorizontalScrollOffset() { + return mScrollX; + } + /** + *

Compute the horizontal extent of the horizontal scrollbar's thumb + * within the horizontal range. This value is used to compute the length + * of the thumb within the scrollbar's track.

+ * + *

The range is expressed in arbitrary units that must be the same as the + * units used by {@link #computeHorizontalScrollRange()} and + * {@link #computeHorizontalScrollOffset()}.

+ * + *

The default extent is the drawing width of this view.

+ * + * @return the horizontal extent of the scrollbar's thumb + * + * @see #computeHorizontalScrollRange() + * @see #computeHorizontalScrollOffset() + * @see android.widget.ScrollBarDrawable + */ + protected int computeHorizontalScrollExtent() { + return getWidth(); + } + /** + *

Compute the vertical range that the vertical scrollbar represents.

+ * + *

The range is expressed in arbitrary units that must be the same as the + * units used by {@link #computeVerticalScrollExtent()} and + * {@link #computeVerticalScrollOffset()}.

+ * + * @return the total vertical range represented by the vertical scrollbar + * + *

The default range is the drawing height of this view.

+ * + * @see #computeVerticalScrollExtent() + * @see #computeVerticalScrollOffset() + * @see android.widget.ScrollBarDrawable + */ + protected int computeVerticalScrollRange() { + return getHeight(); + } + /** + *

Compute the vertical offset of the vertical scrollbar's thumb + * within the horizontal range. This value is used to compute the position + * of the thumb within the scrollbar's track.

+ * + *

The range is expressed in arbitrary units that must be the same as the + * units used by {@link #computeVerticalScrollRange()} and + * {@link #computeVerticalScrollExtent()}.

+ * + *

The default offset is the scroll offset of this view.

+ * + * @return the vertical offset of the scrollbar's thumb + * + * @see #computeVerticalScrollRange() + * @see #computeVerticalScrollExtent() + * @see android.widget.ScrollBarDrawable + */ + protected int computeVerticalScrollOffset() { + return mScrollY; + } + /** + *

Compute the vertical extent of the horizontal scrollbar's thumb + * within the vertical range. This value is used to compute the length + * of the thumb within the scrollbar's track.

+ * + *

The range is expressed in arbitrary units that must be the same as the + * units used by {@link #computeVerticalScrollRange()} and + * {@link #computeVerticalScrollOffset()}.

+ * + *

The default extent is the drawing height of this view.

+ * + * @return the vertical extent of the scrollbar's thumb + * + * @see #computeVerticalScrollRange() + * @see #computeVerticalScrollOffset() + * @see android.widget.ScrollBarDrawable + */ + protected int computeVerticalScrollExtent() { + return getHeight(); + } + /** + * Check if this view can be scrolled horizontally in a certain direction. + * + * @param direction Negative to check scrolling left, positive to check scrolling right. + * @return true if this view can be scrolled in the specified direction, false otherwise. + */ + public boolean canScrollHorizontally(int direction) { + final int offset = computeHorizontalScrollOffset(); + final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent(); + if (range == 0) return false; + if (direction < 0) { + return offset > 0; + } else { + return offset < range - 1; + } + } + /** + * Check if this view can be scrolled vertically in a certain direction. + * + * @param direction Negative to check scrolling up, positive to check scrolling down. + * @return true if this view can be scrolled in the specified direction, false otherwise. + */ + public boolean canScrollVertically(int direction) { + final int offset = computeVerticalScrollOffset(); + final int range = computeVerticalScrollRange() - computeVerticalScrollExtent(); + if (range == 0) return false; + if (direction < 0) { + return offset > 0; + } else { + return offset < range - 1; + } + } + /** + *

Request the drawing of the horizontal and the vertical scrollbar. The + * scrollbars are painted only if they have been awakened first.

+ * + * @param canvas the canvas on which to draw the scrollbars + * + * @see #awakenScrollBars(int) + */ + protected final void onDrawScrollBars(Canvas canvas) { + // scrollbars are drawn only when the animation is running + final ScrollabilityCache cache = mScrollCache; + if (cache != null) { + int state = cache.state; + if (state == ScrollabilityCache.OFF) { + return; + } + boolean invalidate = false; + if (state == ScrollabilityCache.FADING) { + // We're fading -- get our fade interpolation + if (cache.interpolatorValues == null) { + cache.interpolatorValues = new float[1]; + } + float[] values = cache.interpolatorValues; + // Stops the animation if we're done + if (cache.scrollBarInterpolator.timeToValues(values) == + Interpolator.Result.FREEZE_END) { + cache.state = ScrollabilityCache.OFF; + } else { + cache.scrollBar.setAlpha(Math.round(values[0])); + } + // This will make the scroll bars inval themselves after + // drawing. We only want this when we're fading so that + // we prevent excessive redraws + invalidate = true; + } else { + // We're just on -- but we may have been fading before so + // reset alpha + cache.scrollBar.setAlpha(255); + } + final int viewFlags = mViewFlags; + final boolean drawHorizontalScrollBar = + (viewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; + final boolean drawVerticalScrollBar = + (viewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL + && !isVerticalScrollBarHidden(); + if (drawVerticalScrollBar || drawHorizontalScrollBar) { + final int width = mRight - mLeft; + final int height = mBottom - mTop; + final ScrollBarDrawable scrollBar = cache.scrollBar; + final int scrollX = mScrollX; + final int scrollY = mScrollY; + final int inside = (viewFlags & SCROLLBARS_OUTSIDE_MASK) == 0 ? ~0 : 0; + int left, top, right, bottom; + if (drawHorizontalScrollBar) { + int size = scrollBar.getSize(false); + if (size <= 0) { + size = cache.scrollBarSize; + } + scrollBar.setParameters(computeHorizontalScrollRange(), + computeHorizontalScrollOffset(), + computeHorizontalScrollExtent(), false); + final int verticalScrollBarGap = drawVerticalScrollBar ? + getVerticalScrollbarWidth() : 0; + top = scrollY + height - size - (mUserPaddingBottom & inside); + left = scrollX + (mPaddingLeft & inside); + right = scrollX + width - (mUserPaddingRight & inside) - verticalScrollBarGap; + bottom = top + size; + onDrawHorizontalScrollBar(canvas, scrollBar, left, top, right, bottom); + if (invalidate) { + invalidate(left, top, right, bottom); + } + } + if (drawVerticalScrollBar) { + int size = scrollBar.getSize(true); + if (size <= 0) { + size = cache.scrollBarSize; + } + scrollBar.setParameters(computeVerticalScrollRange(), + computeVerticalScrollOffset(), + computeVerticalScrollExtent(), true); + switch (mVerticalScrollbarPosition) { + default: + case SCROLLBAR_POSITION_DEFAULT: + case SCROLLBAR_POSITION_RIGHT: + left = scrollX + width - size - (mUserPaddingRight & inside); + break; + case SCROLLBAR_POSITION_LEFT: + left = scrollX + (mUserPaddingLeft & inside); + break; + } + top = scrollY + (mPaddingTop & inside); + right = left + size; + bottom = scrollY + height - (mUserPaddingBottom & inside); + onDrawVerticalScrollBar(canvas, scrollBar, left, top, right, bottom); + if (invalidate) { + invalidate(left, top, right, bottom); + } + } + } + } + } + /** + * Override this if the vertical scrollbar needs to be hidden in a subclass, like when + * FastScroller is visible. + * @return whether to temporarily hide the vertical scrollbar + * @hide + */ + protected boolean isVerticalScrollBarHidden() { + return false; + } + /** + *

Draw the horizontal scrollbar if + * {@link #isHorizontalScrollBarEnabled()} returns true.

+ * + * @param canvas the canvas on which to draw the scrollbar + * @param scrollBar the scrollbar's drawable + * + * @see #isHorizontalScrollBarEnabled() + * @see #computeHorizontalScrollRange() + * @see #computeHorizontalScrollExtent() + * @see #computeHorizontalScrollOffset() + * @see android.widget.ScrollBarDrawable + * @hide + */ + protected void onDrawHorizontalScrollBar(Canvas canvas, Drawable scrollBar, + int l, int t, int r, int b) { + scrollBar.setBounds(l, t, r, b); + scrollBar.draw(canvas); + } + /** + *

Draw the vertical scrollbar if {@link #isVerticalScrollBarEnabled()} + * returns true.

+ * + * @param canvas the canvas on which to draw the scrollbar + * @param scrollBar the scrollbar's drawable + * + * @see #isVerticalScrollBarEnabled() + * @see #computeVerticalScrollRange() + * @see #computeVerticalScrollExtent() + * @see #computeVerticalScrollOffset() + * @see android.widget.ScrollBarDrawable + * @hide + */ + protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, + int l, int t, int r, int b) { + scrollBar.setBounds(l, t, r, b); + scrollBar.draw(canvas); + } + /** + * Implement this to do your drawing. + * + * @param canvas the canvas on which the background will be drawn + */ + protected void onDraw(Canvas canvas) { + } + /* + * Caller is responsible for calling requestLayout if necessary. + * (This allows addViewInLayout to not request a new layout.) + */ + void assignParent(ViewParent parent) { + if (mParent == null) { + mParent = parent; + } else if (parent == null) { + mParent = null; + } else { + throw new RuntimeException("view " + this + " being added, but" + + " it already has a parent"); + } + } + /** + * This is called when the view is attached to a window. At this point it + * has a Surface and will start drawing. Note that this function is + * guaranteed to be called before {@link #onDraw(android.graphics.Canvas)}, + * however it may be called any time before the first onDraw -- including + * before or after {@link #onMeasure(int, int)}. + * + * @see #onDetachedFromWindow() + */ + protected void onAttachedToWindow() { + if ((mPrivateFlags & REQUEST_TRANSPARENT_REGIONS) != 0) { + mParent.requestTransparentRegion(this); + } + if ((mPrivateFlags & AWAKEN_SCROLL_BARS_ON_ATTACH) != 0) { + initialAwakenScrollBars(); + mPrivateFlags &= ~AWAKEN_SCROLL_BARS_ON_ATTACH; + } + jumpDrawablesToCurrentState(); + // Order is important here: LayoutDirection MUST be resolved before Padding + // and TextDirection + resolveLayoutDirectionIfNeeded(); + resolvePadding(); + resolveTextDirection(); + if (isFocused()) { + InputMethodManager imm = InputMethodManager.peekInstance(); + imm.focusIn(this); + } + } + /** + * Resolve and cache the layout direction. LTR is set initially. This is implicitly supposing + * that the parent directionality can and will be resolved before its children. + */ + private void resolveLayoutDirectionIfNeeded() { + // Do not resolve if it is not needed + if ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED) == LAYOUT_DIRECTION_RESOLVED) return; + // Clear any previous layout direction resolution + mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED_RTL; + // Reset also TextDirection as a change into LayoutDirection may impact the selected + // TextDirectionHeuristic + resetResolvedTextDirection(); + // Set resolved depending on layout direction + switch (getLayoutDirection()) { + case LAYOUT_DIRECTION_INHERIT: + // We cannot do the resolution if there is no parent + if (mParent == null) return; + // If this is root view, no need to look at parent's layout dir. + if (mParent instanceof ViewGroup) { + ViewGroup viewGroup = ((ViewGroup) mParent); + // Check if the parent view group can resolve + if (! viewGroup.canResolveLayoutDirection()) { + return; + } + if (viewGroup.getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { + mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; + } + } + break; + case LAYOUT_DIRECTION_RTL: + mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; + break; + case LAYOUT_DIRECTION_LOCALE: + if(isLayoutDirectionRtl(Locale.getDefault())) { + mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; + } + break; + default: + // Nothing to do, LTR by default + } + // Set to resolved + mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED; + } + /** + * @hide + */ + protected void resolvePadding() { + // If the user specified the absolute padding (either with android:padding or + // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise + // use the default padding or the padding from the background drawable + // (stored at this point in mPadding*) + switch (getResolvedLayoutDirection()) { + case LAYOUT_DIRECTION_RTL: + // Start user padding override Right user padding. Otherwise, if Right user + // padding is not defined, use the default Right padding. If Right user padding + // is defined, just use it. + if (mUserPaddingStart >= 0) { + mUserPaddingRight = mUserPaddingStart; + } else if (mUserPaddingRight < 0) { + mUserPaddingRight = mPaddingRight; + } + if (mUserPaddingEnd >= 0) { + mUserPaddingLeft = mUserPaddingEnd; + } else if (mUserPaddingLeft < 0) { + mUserPaddingLeft = mPaddingLeft; + } + break; + case LAYOUT_DIRECTION_LTR: + default: + // Start user padding override Left user padding. Otherwise, if Left user + // padding is not defined, use the default left padding. If Left user padding + // is defined, just use it. + if (mUserPaddingStart >= 0) { + mUserPaddingLeft = mUserPaddingStart; + } else if (mUserPaddingLeft < 0) { + mUserPaddingLeft = mPaddingLeft; + } + if (mUserPaddingEnd >= 0) { + mUserPaddingRight = mUserPaddingEnd; + } else if (mUserPaddingRight < 0) { + mUserPaddingRight = mPaddingRight; + } + } + mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom; + recomputePadding(); + } + /** + * Return true if layout direction resolution can be done + * + * @hide + */ + protected boolean canResolveLayoutDirection() { + switch (getLayoutDirection()) { + case LAYOUT_DIRECTION_INHERIT: + return (mParent != null); + default: + return true; + } + } + /** + * Reset the resolved layout direction. + * + * Subclasses need to override this method to clear cached information that depends on the + * resolved layout direction, or to inform child views that inherit their layout direction. + * Overrides must also call the superclass implementation at the start of their implementation. + * + * @hide + */ + protected void resetResolvedLayoutDirection() { + // Reset the current View resolution + mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED; + } + /** + * Check if a Locale is corresponding to a RTL script. + * + * @param locale Locale to check + * @return true if a Locale is corresponding to a RTL script. + * + * @hide + */ + protected static boolean isLayoutDirectionRtl(Locale locale) { + return (LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE == + LocaleUtil.getLayoutDirectionFromLocale(locale)); + } + /** + * This is called when the view is detached from a window. At this point it + * no longer has a surface for drawing. + * + * @see #onAttachedToWindow() + */ + protected void onDetachedFromWindow() { + mPrivateFlags &= ~CANCEL_NEXT_UP_EVENT; + removeUnsetPressCallback(); + removeLongPressCallback(); + removePerformClickCallback(); + removeSendViewScrolledAccessibilityEventCallback(); + destroyDrawingCache(); + destroyLayer(); + if (mDisplayList != null) { + mDisplayList.invalidate(); + } + if (mAttachInfo != null) { + mAttachInfo.mViewRootImpl.cancelInvalidate(this); + } + mCurrentAnimation = null; + resetResolvedLayoutDirection(); + resetResolvedTextDirection(); + } + /** + * @return The number of times this view has been attached to a window + */ + protected int getWindowAttachCount() { + return mWindowAttachCount; + } + /** + * Retrieve a unique token identifying the window this view is attached to. + * @return Return the window's token for use in + * {@link WindowManager.LayoutParams#token WindowManager.LayoutParams.token}. + */ + public IBinder getWindowToken() { + return mAttachInfo != null ? mAttachInfo.mWindowToken : null; + } + /** + * Retrieve a unique token identifying the top-level "real" window of + * the window that this view is attached to. That is, this is like + * {@link #getWindowToken}, except if the window this view in is a panel + * window (attached to another containing window), then the token of + * the containing window is returned instead. + * + * @return Returns the associated window token, either + * {@link #getWindowToken()} or the containing window's token. + */ + public IBinder getApplicationWindowToken() { + AttachInfo ai = mAttachInfo; + if (ai != null) { + IBinder appWindowToken = ai.mPanelParentWindowToken; + if (appWindowToken == null) { + appWindowToken = ai.mWindowToken; + } + return appWindowToken; + } + return null; + } + /** + * Retrieve private session object this view hierarchy is using to + * communicate with the window manager. + * @return the session object to communicate with the window manager + */ + /*package*/ IWindowSession getWindowSession() { + return mAttachInfo != null ? mAttachInfo.mSession : null; + } + /** + * @param info the {@link android.view.View.AttachInfo} to associated with + * this view + */ + void dispatchAttachedToWindow(AttachInfo info, int visibility) { + //System.out.println("Attached! " + this); + mAttachInfo = info; + mWindowAttachCount++; + // We will need to evaluate the drawable state at least once. + mPrivateFlags |= DRAWABLE_STATE_DIRTY; + if (mFloatingTreeObserver != null) { + info.mTreeObserver.merge(mFloatingTreeObserver); + mFloatingTreeObserver = null; + } + if ((mPrivateFlags&SCROLL_CONTAINER) != 0) { + mAttachInfo.mScrollContainers.add(this); + mPrivateFlags |= SCROLL_CONTAINER_ADDED; + } + performCollectViewAttributes(visibility); + onAttachedToWindow(); + ListenerInfo li = mListenerInfo; + final CopyOnWriteArrayList listeners = + li != null ? li.mOnAttachStateChangeListeners : null; + if (listeners != null && listeners.size() > 0) { + // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to + // perform the dispatching. The iterator is a safe guard against listeners that + // could mutate the list by calling the various add/remove methods. This prevents + // the array from being modified while we iterate it. + for (OnAttachStateChangeListener listener : listeners) { + listener.onViewAttachedToWindow(this); + } + } + int vis = info.mWindowVisibility; + if (vis != GONE) { + onWindowVisibilityChanged(vis); + } + if ((mPrivateFlags&DRAWABLE_STATE_DIRTY) != 0) { + // If nobody has evaluated the drawable state yet, then do it now. + refreshDrawableState(); + } + } + void dispatchDetachedFromWindow() { + AttachInfo info = mAttachInfo; + if (info != null) { + int vis = info.mWindowVisibility; + if (vis != GONE) { + onWindowVisibilityChanged(GONE); + } + } + onDetachedFromWindow(); + ListenerInfo li = mListenerInfo; + final CopyOnWriteArrayList listeners = + li != null ? li.mOnAttachStateChangeListeners : null; + if (listeners != null && listeners.size() > 0) { + // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to + // perform the dispatching. The iterator is a safe guard against listeners that + // could mutate the list by calling the various add/remove methods. This prevents + // the array from being modified while we iterate it. + for (OnAttachStateChangeListener listener : listeners) { + listener.onViewDetachedFromWindow(this); + } + } + if ((mPrivateFlags & SCROLL_CONTAINER_ADDED) != 0) { + mAttachInfo.mScrollContainers.remove(this); + mPrivateFlags &= ~SCROLL_CONTAINER_ADDED; + } + mAttachInfo = null; + } + /** + * Store this view hierarchy's frozen state into the given container. + * + * @param container The SparseArray in which to save the view's state. + * + * @see #restoreHierarchyState(android.util.SparseArray) + * @see #dispatchSaveInstanceState(android.util.SparseArray) + * @see #onSaveInstanceState() + */ + public void saveHierarchyState(SparseArray container) { + dispatchSaveInstanceState(container); + } + /** + * Called by {@link #saveHierarchyState(android.util.SparseArray)} to store the state for + * this view and its children. May be overridden to modify how freezing happens to a + * view's children; for example, some views may want to not store state for their children. + * + * @param container The SparseArray in which to save the view's state. + * + * @see #dispatchRestoreInstanceState(android.util.SparseArray) + * @see #saveHierarchyState(android.util.SparseArray) + * @see #onSaveInstanceState() + */ + protected void dispatchSaveInstanceState(SparseArray container) { + if (mID != NO_ID && (mViewFlags & SAVE_DISABLED_MASK) == 0) { + mPrivateFlags &= ~SAVE_STATE_CALLED; + Parcelable state = onSaveInstanceState(); + if ((mPrivateFlags & SAVE_STATE_CALLED) == 0) { + throw new IllegalStateException( + "Derived class did not call super.onSaveInstanceState()"); + } + if (state != null) { + // Log.i("View", "Freezing #" + Integer.toHexString(mID) + // + ": " + state); + container.put(mID, state); + } + } + } + /** + * Hook allowing a view to generate a representation of its internal state + * that can later be used to create a new instance with that same state. + * This state should only contain information that is not persistent or can + * not be reconstructed later. For example, you will never store your + * current position on screen because that will be computed again when a + * new instance of the view is placed in its view hierarchy. + *

+ * Some examples of things you may store here: the current cursor position + * in a text view (but usually not the text itself since that is stored in a + * content provider or other persistent storage), the currently selected + * item in a list view. + * + * @return Returns a Parcelable object containing the view's current dynamic + * state, or null if there is nothing interesting to save. The + * default implementation returns null. + * @see #onRestoreInstanceState(android.os.Parcelable) + * @see #saveHierarchyState(android.util.SparseArray) + * @see #dispatchSaveInstanceState(android.util.SparseArray) + * @see #setSaveEnabled(boolean) + */ + protected Parcelable onSaveInstanceState() { + mPrivateFlags |= SAVE_STATE_CALLED; + return BaseSavedState.EMPTY_STATE; + } + /** + * Restore this view hierarchy's frozen state from the given container. + * + * @param container The SparseArray which holds previously frozen states. + * + * @see #saveHierarchyState(android.util.SparseArray) + * @see #dispatchRestoreInstanceState(android.util.SparseArray) + * @see #onRestoreInstanceState(android.os.Parcelable) + */ + public void restoreHierarchyState(SparseArray container) { + dispatchRestoreInstanceState(container); + } + /** + * Called by {@link #restoreHierarchyState(android.util.SparseArray)} to retrieve the + * state for this view and its children. May be overridden to modify how restoring + * happens to a view's children; for example, some views may want to not store state + * for their children. + * + * @param container The SparseArray which holds previously saved state. + * + * @see #dispatchSaveInstanceState(android.util.SparseArray) + * @see #restoreHierarchyState(android.util.SparseArray) + * @see #onRestoreInstanceState(android.os.Parcelable) + */ + protected void dispatchRestoreInstanceState(SparseArray container) { + if (mID != NO_ID) { + Parcelable state = container.get(mID); + if (state != null) { + // Log.i("View", "Restoreing #" + Integer.toHexString(mID) + // + ": " + state); + mPrivateFlags &= ~SAVE_STATE_CALLED; + onRestoreInstanceState(state); + if ((mPrivateFlags & SAVE_STATE_CALLED) == 0) { + throw new IllegalStateException( + "Derived class did not call super.onRestoreInstanceState()"); + } + } + } + } + /** + * Hook allowing a view to re-apply a representation of its internal state that had previously + * been generated by {@link #onSaveInstanceState}. This function will never be called with a + * null state. + * + * @param state The frozen state that had previously been returned by + * {@link #onSaveInstanceState}. + * + * @see #onSaveInstanceState() + * @see #restoreHierarchyState(android.util.SparseArray) + * @see #dispatchRestoreInstanceState(android.util.SparseArray) + */ + protected void onRestoreInstanceState(Parcelable state) { + mPrivateFlags |= SAVE_STATE_CALLED; + if (state != BaseSavedState.EMPTY_STATE && state != null) { + throw new IllegalArgumentException("Wrong state class, expecting View State but " + + "received " + state.getClass().toString() + " instead. This usually happens " + + "when two views of different type have the same id in the same hierarchy. " + + "This view's id is " + ViewDebug.resolveId(mContext, getId()) + ". Make sure " + + "other views do not use the same id."); + } + } + /** + *

Return the time at which the drawing of the view hierarchy started.

+ * + * @return the drawing start time in milliseconds + */ + public long getDrawingTime() { + return mAttachInfo != null ? mAttachInfo.mDrawingTime : 0; + } + /** + *

Enables or disables the duplication of the parent's state into this view. When + * duplication is enabled, this view gets its drawable state from its parent rather + * than from its own internal properties.

+ * + *

Note: in the current implementation, setting this property to true after the + * view was added to a ViewGroup might have no effect at all. This property should + * always be used from XML or set to true before adding this view to a ViewGroup.

+ * + *

Note: if this view's parent addStateFromChildren property is enabled and this + * property is enabled, an exception will be thrown.

+ * + *

Note: if the child view uses and updates additionnal states which are unknown to the + * parent, these states should not be affected by this method.

+ * + * @param enabled True to enable duplication of the parent's drawable state, false + * to disable it. + * + * @see #getDrawableState() + * @see #isDuplicateParentStateEnabled() + */ + public void setDuplicateParentStateEnabled(boolean enabled) { + setFlags(enabled ? DUPLICATE_PARENT_STATE : 0, DUPLICATE_PARENT_STATE); + } + /** + *

Indicates whether this duplicates its drawable state from its parent.

+ * + * @return True if this view's drawable state is duplicated from the parent, + * false otherwise + * + * @see #getDrawableState() + * @see #setDuplicateParentStateEnabled(boolean) + */ + public boolean isDuplicateParentStateEnabled() { + return (mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE; + } + /** + *

Specifies the type of layer backing this view. The layer can be + * {@link #LAYER_TYPE_NONE disabled}, {@link #LAYER_TYPE_SOFTWARE software} or + * {@link #LAYER_TYPE_HARDWARE hardware}.

+ * + *

A layer is associated with an optional {@link android.graphics.Paint} + * instance that controls how the layer is composed on screen. The following + * properties of the paint are taken into account when composing the layer:

+ *
    + *
  • {@link android.graphics.Paint#getAlpha() Translucency (alpha)}
  • + *
  • {@link android.graphics.Paint#getXfermode() Blending mode}
  • + *
  • {@link android.graphics.Paint#getColorFilter() Color filter}
  • + *
+ * + *

If this view has an alpha value set to < 1.0 by calling + * {@link #setAlpha(float)}, the alpha value of the layer's paint is replaced by + * this view's alpha value. Calling {@link #setAlpha(float)} is therefore + * equivalent to setting a hardware layer on this view and providing a paint with + * the desired alpha value.

+ * + *

Refer to the documentation of {@link #LAYER_TYPE_NONE disabled}, + * {@link #LAYER_TYPE_SOFTWARE software} and {@link #LAYER_TYPE_HARDWARE hardware} + * for more information on when and how to use layers.

+ * + * @param layerType The ype of layer to use with this view, must be one of + * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or + * {@link #LAYER_TYPE_HARDWARE} + * @param paint The paint used to compose the layer. This argument is optional + * and can be null. It is ignored when the layer type is + * {@link #LAYER_TYPE_NONE} + * + * @see #getLayerType() + * @see #LAYER_TYPE_NONE + * @see #LAYER_TYPE_SOFTWARE + * @see #LAYER_TYPE_HARDWARE + * @see #setAlpha(float) + * + * @attr ref android.R.styleable#View_layerType + */ + public void setLayerType(int layerType, Paint paint) { + if (layerType < LAYER_TYPE_NONE || layerType > LAYER_TYPE_HARDWARE) { + throw new IllegalArgumentException("Layer type can only be one of: LAYER_TYPE_NONE, " + + "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE"); + } + if (layerType == mLayerType) { + if (layerType != LAYER_TYPE_NONE && paint != mLayerPaint) { + mLayerPaint = paint == null ? new Paint() : paint; + invalidateParentCaches(); + invalidate(true); + } + return; + } + // Destroy any previous software drawing cache if needed + switch (mLayerType) { + case LAYER_TYPE_HARDWARE: + destroyLayer(); + // fall through - non-accelerated views may use software layer mechanism instead + case LAYER_TYPE_SOFTWARE: + destroyDrawingCache(); + break; + default: + break; + } + mLayerType = layerType; + final boolean layerDisabled = mLayerType == LAYER_TYPE_NONE; + mLayerPaint = layerDisabled ? null : (paint == null ? new Paint() : paint); + mLocalDirtyRect = layerDisabled ? null : new Rect(); + invalidateParentCaches(); + invalidate(true); + } + /** + * Indicates whether this view has a static layer. A view with layer type + * {@link #LAYER_TYPE_NONE} is a static layer. Other types of layers are + * dynamic. + */ + boolean hasStaticLayer() { + return mLayerType == LAYER_TYPE_NONE; + } + /** + * Indicates what type of layer is currently associated with this view. By default + * a view does not have a layer, and the layer type is {@link #LAYER_TYPE_NONE}. + * Refer to the documentation of {@link #setLayerType(int, android.graphics.Paint)} + * for more information on the different types of layers. + * + * @return {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or + * {@link #LAYER_TYPE_HARDWARE} + * + * @see #setLayerType(int, android.graphics.Paint) + * @see #buildLayer() + * @see #LAYER_TYPE_NONE + * @see #LAYER_TYPE_SOFTWARE + * @see #LAYER_TYPE_HARDWARE + */ + public int getLayerType() { + return mLayerType; + } + /** + * Forces this view's layer to be created and this view to be rendered + * into its layer. If this view's layer type is set to {@link #LAYER_TYPE_NONE}, + * invoking this method will have no effect. + * + * This method can for instance be used to render a view into its layer before + * starting an animation. If this view is complex, rendering into the layer + * before starting the animation will avoid skipping frames. + * + * @throws IllegalStateException If this view is not attached to a window + * + * @see #setLayerType(int, android.graphics.Paint) + */ + public void buildLayer() { + if (mLayerType == LAYER_TYPE_NONE) return; + if (mAttachInfo == null) { + throw new IllegalStateException("This view must be attached to a window first"); + } + switch (mLayerType) { + case LAYER_TYPE_HARDWARE: + if (mAttachInfo.mHardwareRenderer != null && + mAttachInfo.mHardwareRenderer.isEnabled() && + mAttachInfo.mHardwareRenderer.validate()) { + getHardwareLayer(); + } + break; + case LAYER_TYPE_SOFTWARE: + buildDrawingCache(true); + break; + } + } + + // Make sure the HardwareRenderer.validate() was invoked before calling this method + void flushLayer() { + if (mLayerType == LAYER_TYPE_HARDWARE && mHardwareLayer != null) { + mHardwareLayer.flush(); + } + } + /** + *

Returns a hardware layer that can be used to draw this view again + * without executing its draw method.

+ * + * @return A HardwareLayer ready to render, or null if an error occurred. + */ + HardwareLayer getHardwareLayer() { + if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null || + !mAttachInfo.mHardwareRenderer.isEnabled()) { + return null; + } + + if (!mAttachInfo.mHardwareRenderer.validate()) return null; + final int width = mRight - mLeft; + final int height = mBottom - mTop; + if (width == 0 || height == 0) { + return null; + } + if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || mHardwareLayer == null) { + if (mHardwareLayer == null) { + mHardwareLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer( + width, height, isOpaque()); + mLocalDirtyRect.setEmpty(); + } else if (mHardwareLayer.getWidth() != width || mHardwareLayer.getHeight() != height) { + mHardwareLayer.resize(width, height); + mLocalDirtyRect.setEmpty(); + } + // The layer is not valid if the underlying GPU resources cannot be allocated + if (!mHardwareLayer.isValid()) { + return null; + } + HardwareCanvas currentCanvas = mAttachInfo.mHardwareCanvas; + final HardwareCanvas canvas = mHardwareLayer.start(currentCanvas); + // Make sure all the GPU resources have been properly allocated + if (canvas == null) { + mHardwareLayer.end(currentCanvas); + return null; + } + mAttachInfo.mHardwareCanvas = canvas; + try { + canvas.setViewport(width, height); + canvas.onPreDraw(mLocalDirtyRect); + mLocalDirtyRect.setEmpty(); + final int restoreCount = canvas.save(); + computeScroll(); + canvas.translate(-mScrollX, -mScrollY); + mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; + // Fast path for layouts with no backgrounds + if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { + mPrivateFlags &= ~DIRTY_MASK; + dispatchDraw(canvas); + } else { + draw(canvas); + } + canvas.restoreToCount(restoreCount); + } finally { + canvas.onPostDraw(); + mHardwareLayer.end(currentCanvas); + mAttachInfo.mHardwareCanvas = currentCanvas; + } + } + return mHardwareLayer; + } + /** + * Destroys this View's hardware layer if possible. + * + * @return True if the layer was destroyed, false otherwise. + * + * @see #setLayerType(int, android.graphics.Paint) + * @see #LAYER_TYPE_HARDWARE + */ + boolean destroyLayer() { + if (mHardwareLayer != null) { + AttachInfo info = mAttachInfo; + if (info != null && info.mHardwareRenderer != null && + info.mHardwareRenderer.isEnabled() && info.mHardwareRenderer.validate()) { + mHardwareLayer.destroy(); + mHardwareLayer = null; + invalidate(true); + invalidateParentCaches(); + } + return true; + } + return false; + } + /** + * Destroys all hardware rendering resources. This method is invoked + * when the system needs to reclaim resources. Upon execution of this + * method, you should free any OpenGL resources created by the view. + * + * Note: you must call + * super.destroyHardwareResources() when overriding + * this method. + * + * @hide + */ + protected void destroyHardwareResources() { + destroyLayer(); + } + /** + *

Enables or disables the drawing cache. When the drawing cache is enabled, the next call + * to {@link #getDrawingCache()} or {@link #buildDrawingCache()} will draw the view in a + * bitmap. Calling {@link #draw(android.graphics.Canvas)} will not draw from the cache when + * the cache is enabled. To benefit from the cache, you must request the drawing cache by + * calling {@link #getDrawingCache()} and draw it on screen if the returned bitmap is not + * null.

+ * + *

Enabling the drawing cache is similar to + * {@link #setLayerType(int, android.graphics.Paint) setting a layer} when hardware + * acceleration is turned off. When hardware acceleration is turned on, enabling the + * drawing cache has no effect on rendering because the system uses a different mechanism + * for acceleration which ignores the flag. If you want to use a Bitmap for the view, even + * when hardware acceleration is enabled, see {@link #setLayerType(int, android.graphics.Paint)} + * for information on how to enable software and hardware layers.

+ * + *

This API can be used to manually generate + * a bitmap copy of this view, by setting the flag to true and calling + * {@link #getDrawingCache()}.

+ * + * @param enabled true to enable the drawing cache, false otherwise + * + * @see #isDrawingCacheEnabled() + * @see #getDrawingCache() + * @see #buildDrawingCache() + * @see #setLayerType(int, android.graphics.Paint) + */ + public void setDrawingCacheEnabled(boolean enabled) { + mCachingFailed = false; + setFlags(enabled ? DRAWING_CACHE_ENABLED : 0, DRAWING_CACHE_ENABLED); + } + /** + *

Indicates whether the drawing cache is enabled for this view.

+ * + * @return true if the drawing cache is enabled + * + * @see #setDrawingCacheEnabled(boolean) + * @see #getDrawingCache() + */ + @ViewDebug.ExportedProperty(category = "drawing") + public boolean isDrawingCacheEnabled() { + return (mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED; + } + /** + * Debugging utility which recursively outputs the dirty state of a view and its + * descendants. + * + * @hide + */ + @SuppressWarnings({"UnusedDeclaration"}) + public void outputDirtyFlags(String indent, boolean clear, int clearMask) { + Log.d("View", indent + this + " DIRTY(" + (mPrivateFlags & View.DIRTY_MASK) + + ") DRAWN(" + (mPrivateFlags & DRAWN) + ")" + " CACHE_VALID(" + + (mPrivateFlags & View.DRAWING_CACHE_VALID) + + ") INVALIDATED(" + (mPrivateFlags & INVALIDATED) + ")"); + if (clear) { + mPrivateFlags &= clearMask; + } + if (this instanceof ViewGroup) { + ViewGroup parent = (ViewGroup) this; + final int count = parent.getChildCount(); + for (int i = 0; i < count; i++) { + final View child = parent.getChildAt(i); + child.outputDirtyFlags(indent + " ", clear, clearMask); + } + } + } + /** + * This method is used by ViewGroup to cause its children to restore or recreate their + * display lists. It is called by getDisplayList() when the parent ViewGroup does not need + * to recreate its own display list, which would happen if it went through the normal + * draw/dispatchDraw mechanisms. + * + * @hide + */ + protected void dispatchGetDisplayList() {} + /** + * A view that is not attached or hardware accelerated cannot create a display list. + * This method checks these conditions and returns the appropriate result. + * + * @return true if view has the ability to create a display list, false otherwise. + * + * @hide + */ + public boolean canHaveDisplayList() { + return !(mAttachInfo == null || mAttachInfo.mHardwareRenderer == null); + } + /** + * @return The HardwareRenderer associated with that view or null if hardware rendering + * is not supported or this this has not been attached to a window. + * + * @hide + */ + public HardwareRenderer getHardwareRenderer() { + if (mAttachInfo != null) { + return mAttachInfo.mHardwareRenderer; + } + return null; + } + /** + *

Returns a display list that can be used to draw this view again + * without executing its draw method.

+ * + * @return A DisplayList ready to replay, or null if caching is not enabled. + * + * @hide + */ + public DisplayList getDisplayList() { + if (!canHaveDisplayList()) { + return null; + } + if (((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || + mDisplayList == null || !mDisplayList.isValid() || + mRecreateDisplayList)) { + // Don't need to recreate the display list, just need to tell our + // children to restore/recreate theirs + if (mDisplayList != null && mDisplayList.isValid() && + !mRecreateDisplayList) { + mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; + mPrivateFlags &= ~DIRTY_MASK; + dispatchGetDisplayList(); + return mDisplayList; + } + // If we got here, we're recreating it. Mark it as such to ensure that + // we copy in child display lists into ours in drawChild() + mRecreateDisplayList = true; + if (mDisplayList == null) { + final String name = getClass().getSimpleName(); + mDisplayList = mAttachInfo.mHardwareRenderer.createDisplayList(name); + // If we're creating a new display list, make sure our parent gets invalidated + // since they will need to recreate their display list to account for this + // new child display list. + invalidateParentCaches(); + } + final HardwareCanvas canvas = mDisplayList.start(); + int restoreCount = 0; + try { + int width = mRight - mLeft; + int height = mBottom - mTop; + canvas.setViewport(width, height); + // The dirty rect should always be null for a display list + canvas.onPreDraw(null); + computeScroll(); + restoreCount = canvas.save(); + canvas.translate(-mScrollX, -mScrollY); + mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; + mPrivateFlags &= ~DIRTY_MASK; + // Fast path for layouts with no backgrounds + if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { + dispatchDraw(canvas); + } else { + draw(canvas); + } + } finally { + canvas.restoreToCount(restoreCount); + canvas.onPostDraw(); + mDisplayList.end(); + } + } else { + mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; + mPrivateFlags &= ~DIRTY_MASK; + } + return mDisplayList; + } + /** + *

Calling this method is equivalent to calling getDrawingCache(false).

+ * + * @return A non-scaled bitmap representing this view or null if cache is disabled. + * + * @see #getDrawingCache(boolean) + */ + public Bitmap getDrawingCache() { + return getDrawingCache(false); + } + /** + *

Returns the bitmap in which this view drawing is cached. The returned bitmap + * is null when caching is disabled. If caching is enabled and the cache is not ready, + * this method will create it. Calling {@link #draw(android.graphics.Canvas)} will not + * draw from the cache when the cache is enabled. To benefit from the cache, you must + * request the drawing cache by calling this method and draw it on screen if the + * returned bitmap is not null.

+ * + *

Note about auto scaling in compatibility mode: When auto scaling is not enabled, + * this method will create a bitmap of the same size as this view. Because this bitmap + * will be drawn scaled by the parent ViewGroup, the result on screen might show + * scaling artifacts. To avoid such artifacts, you should call this method by setting + * the auto scaling to true. Doing so, however, will generate a bitmap of a different + * size than the view. This implies that your application must be able to handle this + * size.

+ * + * @param autoScale Indicates whether the generated bitmap should be scaled based on + * the current density of the screen when the application is in compatibility + * mode. + * + * @return A bitmap representing this view or null if cache is disabled. + * + * @see #setDrawingCacheEnabled(boolean) + * @see #isDrawingCacheEnabled() + * @see #buildDrawingCache(boolean) + * @see #destroyDrawingCache() + */ + public Bitmap getDrawingCache(boolean autoScale) { + if ((mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING) { + return null; + } + if ((mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED) { + buildDrawingCache(autoScale); + } + return autoScale ? mDrawingCache : mUnscaledDrawingCache; + } + /** + *

Frees the resources used by the drawing cache. If you call + * {@link #buildDrawingCache()} manually without calling + * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you + * should cleanup the cache with this method afterwards.

+ * + * @see #setDrawingCacheEnabled(boolean) + * @see #buildDrawingCache() + * @see #getDrawingCache() + */ + public void destroyDrawingCache() { + if (mDrawingCache != null) { + mDrawingCache.recycle(); + mDrawingCache = null; + } + if (mUnscaledDrawingCache != null) { + mUnscaledDrawingCache.recycle(); + mUnscaledDrawingCache = null; + } + } + /** + * Setting a solid background color for the drawing cache's bitmaps will improve + * performance and memory usage. Note, though that this should only be used if this + * view will always be drawn on top of a solid color. + * + * @param color The background color to use for the drawing cache's bitmap + * + * @see #setDrawingCacheEnabled(boolean) + * @see #buildDrawingCache() + * @see #getDrawingCache() + */ + public void setDrawingCacheBackgroundColor(int color) { + if (color != mDrawingCacheBackgroundColor) { + mDrawingCacheBackgroundColor = color; + mPrivateFlags &= ~DRAWING_CACHE_VALID; + } + } + /** + * @see #setDrawingCacheBackgroundColor(int) + * + * @return The background color to used for the drawing cache's bitmap + */ + public int getDrawingCacheBackgroundColor() { + return mDrawingCacheBackgroundColor; + } + /** + *

Calling this method is equivalent to calling buildDrawingCache(false).

+ * + * @see #buildDrawingCache(boolean) + */ + public void buildDrawingCache() { + buildDrawingCache(false); + } + /** + *

Forces the drawing cache to be built if the drawing cache is invalid.

+ * + *

If you call {@link #buildDrawingCache()} manually without calling + * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you + * should cleanup the cache by calling {@link #destroyDrawingCache()} afterwards.

+ * + *

Note about auto scaling in compatibility mode: When auto scaling is not enabled, + * this method will create a bitmap of the same size as this view. Because this bitmap + * will be drawn scaled by the parent ViewGroup, the result on screen might show + * scaling artifacts. To avoid such artifacts, you should call this method by setting + * the auto scaling to true. Doing so, however, will generate a bitmap of a different + * size than the view. This implies that your application must be able to handle this + * size.

+ * + *

You should avoid calling this method when hardware acceleration is enabled. If + * you do not need the drawing cache bitmap, calling this method will increase memory + * usage and cause the view to be rendered in software once, thus negatively impacting + * performance.

+ * + * @see #getDrawingCache() + * @see #destroyDrawingCache() + */ + public void buildDrawingCache(boolean autoScale) { + if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || (autoScale ? + mDrawingCache == null : mUnscaledDrawingCache == null)) { + mCachingFailed = false; + if (ViewDebug.TRACE_HIERARCHY) { + ViewDebug.trace(this, ViewDebug.HierarchyTraceType.BUILD_CACHE); + } + int width = mRight - mLeft; + int height = mBottom - mTop; + final AttachInfo attachInfo = mAttachInfo; + final boolean scalingRequired = attachInfo != null && attachInfo.mScalingRequired; + if (autoScale && scalingRequired) { + width = (int) ((width * attachInfo.mApplicationScale) + 0.5f); + height = (int) ((height * attachInfo.mApplicationScale) + 0.5f); + } + final int drawingCacheBackgroundColor = mDrawingCacheBackgroundColor; + final boolean opaque = drawingCacheBackgroundColor != 0 || isOpaque(); + final boolean use32BitCache = attachInfo != null && attachInfo.mUse32BitDrawingCache; + if (width <= 0 || height <= 0 || + // Projected bitmap size in bytes + (width * height * (opaque && !use32BitCache ? 2 : 4) > + ViewConfiguration.get(mContext).getScaledMaximumDrawingCacheSize())) { + destroyDrawingCache(); + mCachingFailed = true; + return; + } + boolean clear = true; + Bitmap bitmap = autoScale ? mDrawingCache : mUnscaledDrawingCache; + if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) { + Bitmap.Config quality; + if (!opaque) { + // Never pick ARGB_4444 because it looks awful + // Keep the DRAWING_CACHE_QUALITY_LOW flag just in case + switch (mViewFlags & DRAWING_CACHE_QUALITY_MASK) { + case DRAWING_CACHE_QUALITY_AUTO: + quality = Bitmap.Config.ARGB_8888; + break; + case DRAWING_CACHE_QUALITY_LOW: + quality = Bitmap.Config.ARGB_8888; + break; + case DRAWING_CACHE_QUALITY_HIGH: + quality = Bitmap.Config.ARGB_8888; + break; + default: + quality = Bitmap.Config.ARGB_8888; + break; + } + } else { + // Optimization for translucent windows + // If the window is translucent, use a 32 bits bitmap to benefit from memcpy() + quality = use32BitCache ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565; + } + // Try to cleanup memory + if (bitmap != null) bitmap.recycle(); + try { + bitmap = Bitmap.createBitmap(width, height, quality); + bitmap.setDensity(getResources().getDisplayMetrics().densityDpi); + if (autoScale) { + mDrawingCache = bitmap; + } else { + mUnscaledDrawingCache = bitmap; + } + if (opaque && use32BitCache) bitmap.setHasAlpha(false); + } catch (OutOfMemoryError e) { + // If there is not enough memory to create the bitmap cache, just + // ignore the issue as bitmap caches are not required to draw the + // view hierarchy + if (autoScale) { + mDrawingCache = null; + } else { + mUnscaledDrawingCache = null; + } + mCachingFailed = true; + return; + } + clear = drawingCacheBackgroundColor != 0; + } + Canvas canvas; + if (attachInfo != null) { + canvas = attachInfo.mCanvas; + if (canvas == null) { + canvas = new Canvas(); + } + canvas.setBitmap(bitmap); + // Temporarily clobber the cached Canvas in case one of our children + // is also using a drawing cache. Without this, the children would + // steal the canvas by attaching their own bitmap to it and bad, bad + // thing would happen (invisible views, corrupted drawings, etc.) + attachInfo.mCanvas = null; + } else { + // This case should hopefully never or seldom happen + canvas = new Canvas(bitmap); + } + if (clear) { + bitmap.eraseColor(drawingCacheBackgroundColor); + } + computeScroll(); + final int restoreCount = canvas.save(); + if (autoScale && scalingRequired) { + final float scale = attachInfo.mApplicationScale; + canvas.scale(scale, scale); + } + canvas.translate(-mScrollX, -mScrollY); + mPrivateFlags |= DRAWN; + if (mAttachInfo == null || !mAttachInfo.mHardwareAccelerated || + mLayerType != LAYER_TYPE_NONE) { + mPrivateFlags |= DRAWING_CACHE_VALID; + } + // Fast path for layouts with no backgrounds + if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { + if (ViewDebug.TRACE_HIERARCHY) { + ViewDebug.trace(this, ViewDebug.HierarchyTraceType.DRAW); + } + mPrivateFlags &= ~DIRTY_MASK; + dispatchDraw(canvas); + } else { + draw(canvas); + } + canvas.restoreToCount(restoreCount); + canvas.setBitmap(null); + if (attachInfo != null) { + // Restore the cached Canvas for our siblings + attachInfo.mCanvas = canvas; + } + } + } + /** + * Create a snapshot of the view into a bitmap. We should probably make + * some form of this public, but should think about the API. + */ + Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipChildren) { + int width = mRight - mLeft; + int height = mBottom - mTop; + final AttachInfo attachInfo = mAttachInfo; + final float scale = attachInfo != null ? attachInfo.mApplicationScale : 1.0f; + width = (int) ((width * scale) + 0.5f); + height = (int) ((height * scale) + 0.5f); + Bitmap bitmap = Bitmap.createBitmap(width > 0 ? width : 1, height > 0 ? height : 1, quality); + if (bitmap == null) { + throw new OutOfMemoryError(); + } + Resources resources = getResources(); + if (resources != null) { + bitmap.setDensity(resources.getDisplayMetrics().densityDpi); + } + Canvas canvas; + if (attachInfo != null) { + canvas = attachInfo.mCanvas; + if (canvas == null) { + canvas = new Canvas(); + } + canvas.setBitmap(bitmap); + // Temporarily clobber the cached Canvas in case one of our children + // is also using a drawing cache. Without this, the children would + // steal the canvas by attaching their own bitmap to it and bad, bad + // things would happen (invisible views, corrupted drawings, etc.) + attachInfo.mCanvas = null; + } else { + // This case should hopefully never or seldom happen + canvas = new Canvas(bitmap); + } + if ((backgroundColor & 0xff000000) != 0) { + bitmap.eraseColor(backgroundColor); + } + computeScroll(); + final int restoreCount = canvas.save(); + canvas.scale(scale, scale); + canvas.translate(-mScrollX, -mScrollY); + // Temporarily remove the dirty mask + int flags = mPrivateFlags; + mPrivateFlags &= ~DIRTY_MASK; + // Fast path for layouts with no backgrounds + if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { + dispatchDraw(canvas); + } else { + draw(canvas); + } + mPrivateFlags = flags; + canvas.restoreToCount(restoreCount); + canvas.setBitmap(null); + if (attachInfo != null) { + // Restore the cached Canvas for our siblings + attachInfo.mCanvas = canvas; + } + return bitmap; + } + /** + * Indicates whether this View is currently in edit mode. A View is usually + * in edit mode when displayed within a developer tool. For instance, if + * this View is being drawn by a visual user interface builder, this method + * should return true. + * + * Subclasses should check the return value of this method to provide + * different behaviors if their normal behavior might interfere with the + * host environment. For instance: the class spawns a thread in its + * constructor, the drawing code relies on device-specific features, etc. + * + * This method is usually checked in the drawing code of custom widgets. + * + * @return True if this View is in edit mode, false otherwise. + */ + public boolean isInEditMode() { + return false; + } + /** + * If the View draws content inside its padding and enables fading edges, + * it needs to support padding offsets. Padding offsets are added to the + * fading edges to extend the length of the fade so that it covers pixels + * drawn inside the padding. + * + * Subclasses of this class should override this method if they need + * to draw content inside the padding. + * + * @return True if padding offset must be applied, false otherwise. + * + * @see #getLeftPaddingOffset() + * @see #getRightPaddingOffset() + * @see #getTopPaddingOffset() + * @see #getBottomPaddingOffset() + * + * @since CURRENT + */ + protected boolean isPaddingOffsetRequired() { + return false; + } + /** + * Amount by which to extend the left fading region. Called only when + * {@link #isPaddingOffsetRequired()} returns true. + * + * @return The left padding offset in pixels. + * + * @see #isPaddingOffsetRequired() + * + * @since CURRENT + */ + protected int getLeftPaddingOffset() { + return 0; + } + /** + * Amount by which to extend the right fading region. Called only when + * {@link #isPaddingOffsetRequired()} returns true. + * + * @return The right padding offset in pixels. + * + * @see #isPaddingOffsetRequired() + * + * @since CURRENT + */ + protected int getRightPaddingOffset() { + return 0; + } + /** + * Amount by which to extend the top fading region. Called only when + * {@link #isPaddingOffsetRequired()} returns true. + * + * @return The top padding offset in pixels. + * + * @see #isPaddingOffsetRequired() + * + * @since CURRENT + */ + protected int getTopPaddingOffset() { + return 0; + } + /** + * Amount by which to extend the bottom fading region. Called only when + * {@link #isPaddingOffsetRequired()} returns true. + * + * @return The bottom padding offset in pixels. + * + * @see #isPaddingOffsetRequired() + * + * @since CURRENT + */ + protected int getBottomPaddingOffset() { + return 0; + } + /** + * @hide + * @param offsetRequired + */ + protected int getFadeTop(boolean offsetRequired) { + int top = mPaddingTop; + if (offsetRequired) top += getTopPaddingOffset(); + return top; + } + + /** + * @hide + * @param offsetRequired + */ + protected int getFadeHeight(boolean offsetRequired) { + int padding = mPaddingTop; + if (offsetRequired) padding += getTopPaddingOffset(); + return mBottom - mTop - mPaddingBottom - padding; + } + + /** + *

Indicates whether this view is attached to an hardware accelerated + * window or not.

+ * + *

Even if this method returns true, it does not mean that every call + * to {@link #draw(android.graphics.Canvas)} will be made with an hardware + * accelerated {@link android.graphics.Canvas}. For instance, if this view + * is drawn onto an offscren {@link android.graphics.Bitmap} and its + * window is hardware accelerated, + * {@link android.graphics.Canvas#isHardwareAccelerated()} will likely + * return false, and this method will return true.

+ * + * @return True if the view is attached to a window and the window is + * hardware accelerated; false in any other case. + */ + public boolean isHardwareAccelerated() { + return mAttachInfo != null && mAttachInfo.mHardwareAccelerated; + } + /** + * Utility function, called by draw(canvas, parent, drawingTime) to handle the less common + * case of an active Animation being run on the view. + */ + private boolean drawAnimation(ViewGroup parent, long drawingTime, + Animation a, boolean scalingRequired) { + Transformation invalidationTransform; + final int flags = parent.mGroupFlags; + final boolean initialized = a.isInitialized(); + if (!initialized) { + a.initialize(mRight - mLeft, mBottom - mTop, getWidth(), getHeight()); + a.initializeInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop); + onAnimationStart(); + } + boolean more = a.getTransformation(drawingTime, parent.mChildTransformation, 1f); + if (scalingRequired && mAttachInfo.mApplicationScale != 1f) { + if (parent.mInvalidationTransformation == null) { + parent.mInvalidationTransformation = new Transformation(); + } + invalidationTransform = parent.mInvalidationTransformation; + a.getTransformation(drawingTime, invalidationTransform, 1f); + } else { + invalidationTransform = parent.mChildTransformation; + } + if (more) { + if (!a.willChangeBounds()) { + if ((flags & (parent.FLAG_OPTIMIZE_INVALIDATE | parent.FLAG_ANIMATION_DONE)) == + parent.FLAG_OPTIMIZE_INVALIDATE) { + parent.mGroupFlags |= parent.FLAG_INVALIDATE_REQUIRED; + } else if ((flags & parent.FLAG_INVALIDATE_REQUIRED) == 0) { + // The child need to draw an animation, potentially offscreen, so + // make sure we do not cancel invalidate requests + parent.mPrivateFlags |= DRAW_ANIMATION; + parent.invalidate(mLeft, mTop, mRight, mBottom); + } + } else { + if (parent.mInvalidateRegion == null) { + parent.mInvalidateRegion = new RectF(); + } + final RectF region = parent.mInvalidateRegion; + a.getInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop, region, + invalidationTransform); + // The child need to draw an animation, potentially offscreen, so + // make sure we do not cancel invalidate requests + parent.mPrivateFlags |= DRAW_ANIMATION; + final int left = mLeft + (int) region.left; + final int top = mTop + (int) region.top; + parent.invalidate(left, top, left + (int) (region.width() + .5f), + top + (int) (region.height() + .5f)); + } + } + return more; + } + /** + * This method is called by ViewGroup.drawChild() to have each child view draw itself. + * This draw() method is an implementation detail and is not intended to be overridden or + * to be called from anywhere else other than ViewGroup.drawChild(). + */ + boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) { + boolean more = false; + final boolean childHasIdentityMatrix = hasIdentityMatrix(); + final int flags = parent.mGroupFlags; + if ((flags & parent.FLAG_CLEAR_TRANSFORMATION) == parent.FLAG_CLEAR_TRANSFORMATION) { + parent.mChildTransformation.clear(); + parent.mGroupFlags &= ~parent.FLAG_CLEAR_TRANSFORMATION; + } + Transformation transformToApply = null; + boolean concatMatrix = false; + boolean scalingRequired = false; + boolean caching; + int layerType = parent.mDrawLayers ? getLayerType() : LAYER_TYPE_NONE; + final boolean hardwareAccelerated = canvas.isHardwareAccelerated(); + if ((flags & parent.FLAG_CHILDREN_DRAWN_WITH_CACHE) == parent.FLAG_CHILDREN_DRAWN_WITH_CACHE || + (flags & parent.FLAG_ALWAYS_DRAWN_WITH_CACHE) == parent.FLAG_ALWAYS_DRAWN_WITH_CACHE) { + caching = true; + if (mAttachInfo != null) scalingRequired = mAttachInfo.mScalingRequired; + } else { + caching = (layerType != LAYER_TYPE_NONE) || hardwareAccelerated; + } + final Animation a = getAnimation(); + if (a != null) { + more = drawAnimation(parent, drawingTime, a, scalingRequired); + concatMatrix = a.willChangeTransformationMatrix(); + transformToApply = parent.mChildTransformation; + } else if ((flags & parent.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) == + parent.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) { + final boolean hasTransform = + parent.getChildStaticTransformation(this, parent.mChildTransformation); + if (hasTransform) { + final int transformType = parent.mChildTransformation.getTransformationType(); + transformToApply = transformType != Transformation.TYPE_IDENTITY ? + parent.mChildTransformation : null; + concatMatrix = (transformType & Transformation.TYPE_MATRIX) != 0; + } + } + concatMatrix |= !childHasIdentityMatrix; + // Sets the flag as early as possible to allow draw() implementations + // to call invalidate() successfully when doing animations + mPrivateFlags |= DRAWN; + if (!concatMatrix && canvas.quickReject(mLeft, mTop, mRight, mBottom, Canvas.EdgeType.BW) && + (mPrivateFlags & DRAW_ANIMATION) == 0) { + return more; + } + if (hardwareAccelerated) { + // Clear INVALIDATED flag to allow invalidation to occur during rendering, but + // retain the flag's value temporarily in the mRecreateDisplayList flag + mRecreateDisplayList = (mPrivateFlags & INVALIDATED) == INVALIDATED; + mPrivateFlags &= ~INVALIDATED; + } + computeScroll(); + final int sx = mScrollX; + final int sy = mScrollY; + DisplayList displayList = null; + Bitmap cache = null; + boolean hasDisplayList = false; + if (caching) { + if (!hardwareAccelerated) { + if (layerType != LAYER_TYPE_NONE) { + layerType = LAYER_TYPE_SOFTWARE; + buildDrawingCache(true); + } + cache = getDrawingCache(true); + } else { + switch (layerType) { + case LAYER_TYPE_SOFTWARE: + buildDrawingCache(true); + cache = getDrawingCache(true); + break; + case LAYER_TYPE_NONE: + // Delay getting the display list until animation-driven alpha values are + // set up and possibly passed on to the view + hasDisplayList = canHaveDisplayList(); + break; + } + } + } + final boolean hasNoCache = cache == null || hasDisplayList; + final boolean offsetForScroll = cache == null && !hasDisplayList && + layerType != LAYER_TYPE_HARDWARE; + final int restoreTo = canvas.save(); + if (offsetForScroll) { + canvas.translate(mLeft - sx, mTop - sy); + } else { + canvas.translate(mLeft, mTop); + if (scalingRequired) { + // mAttachInfo cannot be null, otherwise scalingRequired == false + final float scale = 1.0f / mAttachInfo.mApplicationScale; + canvas.scale(scale, scale); + } + } + float alpha = getAlpha(); + if (transformToApply != null || alpha < 1.0f || !hasIdentityMatrix()) { + if (transformToApply != null || !childHasIdentityMatrix) { + int transX = 0; + int transY = 0; + if (offsetForScroll) { + transX = -sx; + transY = -sy; + } + if (transformToApply != null) { + if (concatMatrix) { + // Undo the scroll translation, apply the transformation matrix, + // then redo the scroll translate to get the correct result. + canvas.translate(-transX, -transY); + canvas.concat(transformToApply.getMatrix()); + canvas.translate(transX, transY); + parent.mGroupFlags |= parent.FLAG_CLEAR_TRANSFORMATION; + } + float transformAlpha = transformToApply.getAlpha(); + if (transformAlpha < 1.0f) { + alpha *= transformToApply.getAlpha(); + parent.mGroupFlags |= parent.FLAG_CLEAR_TRANSFORMATION; + } + } + if (!childHasIdentityMatrix) { + canvas.translate(-transX, -transY); + canvas.concat(getMatrix()); + canvas.translate(transX, transY); + } + } + if (alpha < 1.0f) { + parent.mGroupFlags |= parent.FLAG_CLEAR_TRANSFORMATION; + if (hasNoCache) { + final int multipliedAlpha = (int) (255 * alpha); + if (!onSetAlpha(multipliedAlpha)) { + int layerFlags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; + if ((flags & parent.FLAG_CLIP_CHILDREN) == parent.FLAG_CLIP_CHILDREN || + layerType != LAYER_TYPE_NONE) { + layerFlags |= Canvas.CLIP_TO_LAYER_SAVE_FLAG; + } + if (layerType == LAYER_TYPE_NONE) { + final int scrollX = hasDisplayList ? 0 : sx; + final int scrollY = hasDisplayList ? 0 : sy; + canvas.saveLayerAlpha(scrollX, scrollY, scrollX + mRight - mLeft, + scrollY + mBottom - mTop, multipliedAlpha, layerFlags); + } + } else { + // Alpha is handled by the child directly, clobber the layer's alpha + mPrivateFlags |= ALPHA_SET; + } + } + } + } else if ((mPrivateFlags & ALPHA_SET) == ALPHA_SET) { + onSetAlpha(255); + mPrivateFlags &= ~ALPHA_SET; + } + if ((flags & parent.FLAG_CLIP_CHILDREN) == parent.FLAG_CLIP_CHILDREN) { + if (offsetForScroll) { + canvas.clipRect(sx, sy, sx + (mRight - mLeft), sy + (mBottom - mTop)); + } else { + if (!scalingRequired || cache == null) { + canvas.clipRect(0, 0, mRight - mLeft, mBottom - mTop); + } else { + canvas.clipRect(0, 0, cache.getWidth(), cache.getHeight()); + } + } + } + if (hasDisplayList) { + displayList = getDisplayList(); + if (!displayList.isValid()) { + // Uncommon, but possible. If a view is removed from the hierarchy during the call + // to getDisplayList(), the display list will be marked invalid and we should not + // try to use it again. + displayList = null; + hasDisplayList = false; + } + } + if (hasNoCache) { + boolean layerRendered = false; + if (layerType == LAYER_TYPE_HARDWARE) { + final HardwareLayer layer = getHardwareLayer(); + if (layer != null && layer.isValid()) { + mLayerPaint.setAlpha((int) (alpha * 255)); + ((HardwareCanvas) canvas).drawHardwareLayer(layer, 0, 0, mLayerPaint); + layerRendered = true; + } else { + final int scrollX = hasDisplayList ? 0 : sx; + final int scrollY = hasDisplayList ? 0 : sy; + canvas.saveLayer(scrollX, scrollY, + scrollX + mRight - mLeft, scrollY + mBottom - mTop, mLayerPaint, + Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); + } + } + if (!layerRendered) { + if (!hasDisplayList) { + // Fast path for layouts with no backgrounds + if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { + if (ViewDebug.TRACE_HIERARCHY) { + ViewDebug.trace(parent, ViewDebug.HierarchyTraceType.DRAW); + } + mPrivateFlags &= ~DIRTY_MASK; + dispatchDraw(canvas); + } else { + draw(canvas); + } + } else { + mPrivateFlags &= ~DIRTY_MASK; + ((HardwareCanvas) canvas).drawDisplayList(displayList, + mRight - mLeft, mBottom - mTop, null); + } + } + } else if (cache != null) { + mPrivateFlags &= ~DIRTY_MASK; + Paint cachePaint; + if (layerType == LAYER_TYPE_NONE) { + cachePaint = parent.mCachePaint; + if (cachePaint == null) { + cachePaint = new Paint(); + cachePaint.setDither(false); + parent.mCachePaint = cachePaint; + } + if (alpha < 1.0f) { + cachePaint.setAlpha((int) (alpha * 255)); + parent.mGroupFlags |= parent.FLAG_ALPHA_LOWER_THAN_ONE; + } else if ((flags & parent.FLAG_ALPHA_LOWER_THAN_ONE) == + parent.FLAG_ALPHA_LOWER_THAN_ONE) { + cachePaint.setAlpha(255); + parent.mGroupFlags &= ~parent.FLAG_ALPHA_LOWER_THAN_ONE; + } + } else { + cachePaint = mLayerPaint; + cachePaint.setAlpha((int) (alpha * 255)); + } + canvas.drawBitmap(cache, 0.0f, 0.0f, cachePaint); + } + canvas.restoreToCount(restoreTo); + if (a != null && !more) { + if (!hardwareAccelerated && !a.getFillAfter()) { + onSetAlpha(255); + } + parent.finishAnimatingView(this, a); + } + if (more && hardwareAccelerated) { + // invalidation is the trigger to recreate display lists, so if we're using + // display lists to render, force an invalidate to allow the animation to + // continue drawing another frame + parent.invalidate(true); + if (a.hasAlpha() && (mPrivateFlags & ALPHA_SET) == ALPHA_SET) { + // alpha animations should cause the child to recreate its display list + invalidate(true); + } + } + mRecreateDisplayList = false; + return more; + } + /** + * Manually render this view (and all of its children) to the given Canvas. + * The view must have already done a full layout before this function is + * called. When implementing a view, implement + * {@link #onDraw(android.graphics.Canvas)} instead of overriding this method. + * If you do need to override this method, call the superclass version. + * + * @param canvas The Canvas to which the View is rendered. + */ + public void draw(Canvas canvas) { + if (ViewDebug.TRACE_HIERARCHY) { + ViewDebug.trace(this, ViewDebug.HierarchyTraceType.DRAW); + } + final int privateFlags = mPrivateFlags; + final boolean dirtyOpaque = (privateFlags & DIRTY_MASK) == DIRTY_OPAQUE && + (mAttachInfo == null || !mAttachInfo.mIgnoreDirtyState); + mPrivateFlags = (privateFlags & ~DIRTY_MASK) | DRAWN; + /* + * Draw traversal performs several drawing steps which must be executed + * in the appropriate order: + * + * 1. Draw the background + * 2. If necessary, save the canvas' layers to prepare for fading + * 3. Draw view's content + * 4. Draw children + * 5. If necessary, draw the fading edges and restore layers + * 6. Draw decorations (scrollbars for instance) + */ + // Step 1, draw the background, if needed + int saveCount; + if (!dirtyOpaque) { + final Drawable background = mBGDrawable; + if (background != null) { + final int scrollX = mScrollX; + final int scrollY = mScrollY; + if (mBackgroundSizeChanged) { + background.setBounds(0, 0, mRight - mLeft, mBottom - mTop); + mBackgroundSizeChanged = false; + } + if ((scrollX | scrollY) == 0) { + background.draw(canvas); + } else { + canvas.translate(scrollX, scrollY); + background.draw(canvas); + canvas.translate(-scrollX, -scrollY); + } + } + } + // skip step 2 & 5 if possible (common case) + final int viewFlags = mViewFlags; + boolean horizontalEdges = (viewFlags & FADING_EDGE_HORIZONTAL) != 0; + boolean verticalEdges = (viewFlags & FADING_EDGE_VERTICAL) != 0; + if (!verticalEdges && !horizontalEdges) { + // Step 3, draw the content + if (!dirtyOpaque) onDraw(canvas); + // Step 4, draw the children + dispatchDraw(canvas); + // Step 6, draw decorations (scrollbars) + onDrawScrollBars(canvas); + // we're done... + return; + } + /* + * Here we do the full fledged routine... + * (this is an uncommon case where speed matters less, + * this is why we repeat some of the tests that have been + * done above) + */ + boolean drawTop = false; + boolean drawBottom = false; + boolean drawLeft = false; + boolean drawRight = false; + float topFadeStrength = 0.0f; + float bottomFadeStrength = 0.0f; + float leftFadeStrength = 0.0f; + float rightFadeStrength = 0.0f; + // Step 2, save the canvas' layers + int paddingLeft = mPaddingLeft; + final boolean offsetRequired = isPaddingOffsetRequired(); + if (offsetRequired) { + paddingLeft += getLeftPaddingOffset(); + } + int left = mScrollX + paddingLeft; + int right = left + mRight - mLeft - mPaddingRight - paddingLeft; + int top = mScrollY + getFadeTop(offsetRequired); + int bottom = top + getFadeHeight(offsetRequired); + if (offsetRequired) { + right += getRightPaddingOffset(); + bottom += getBottomPaddingOffset(); + } + final ScrollabilityCache scrollabilityCache = mScrollCache; + final float fadeHeight = scrollabilityCache.fadingEdgeLength; + int length = (int) fadeHeight; + // clip the fade length if top and bottom fades overlap + // overlapping fades produce odd-looking artifacts + if (verticalEdges && (top + length > bottom - length)) { + length = (bottom - top) / 2; + } + // also clip horizontal fades if necessary + if (horizontalEdges && (left + length > right - length)) { + length = (right - left) / 2; + } + if (verticalEdges) { + topFadeStrength = Math.max(0.0f, Math.min(1.0f, getTopFadingEdgeStrength())); + drawTop = topFadeStrength * fadeHeight > 1.0f; + bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, getBottomFadingEdgeStrength())); + drawBottom = bottomFadeStrength * fadeHeight > 1.0f; + } + if (horizontalEdges) { + leftFadeStrength = Math.max(0.0f, Math.min(1.0f, getLeftFadingEdgeStrength())); + drawLeft = leftFadeStrength * fadeHeight > 1.0f; + rightFadeStrength = Math.max(0.0f, Math.min(1.0f, getRightFadingEdgeStrength())); + drawRight = rightFadeStrength * fadeHeight > 1.0f; + } + saveCount = canvas.getSaveCount(); + int solidColor = getSolidColor(); + if (solidColor == 0) { + final int flags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; + if (drawTop) { + canvas.saveLayer(left, top, right, top + length, null, flags); + } + if (drawBottom) { + canvas.saveLayer(left, bottom - length, right, bottom, null, flags); + } + if (drawLeft) { + canvas.saveLayer(left, top, left + length, bottom, null, flags); + } + if (drawRight) { + canvas.saveLayer(right - length, top, right, bottom, null, flags); + } + } else { + scrollabilityCache.setFadeColor(solidColor); + } + // Step 3, draw the content + if (!dirtyOpaque) onDraw(canvas); + // Step 4, draw the children + dispatchDraw(canvas); + // Step 5, draw the fade effect and restore layers + final Paint p = scrollabilityCache.paint; + final Matrix matrix = scrollabilityCache.matrix; + final Shader fade = scrollabilityCache.shader; + if (drawTop) { + matrix.setScale(1, fadeHeight * topFadeStrength); + matrix.postTranslate(left, top); + fade.setLocalMatrix(matrix); + canvas.drawRect(left, top, right, top + length, p); + } + if (drawBottom) { + matrix.setScale(1, fadeHeight * bottomFadeStrength); + matrix.postRotate(180); + matrix.postTranslate(left, bottom); + fade.setLocalMatrix(matrix); + canvas.drawRect(left, bottom - length, right, bottom, p); + } + if (drawLeft) { + matrix.setScale(1, fadeHeight * leftFadeStrength); + matrix.postRotate(-90); + matrix.postTranslate(left, top); + fade.setLocalMatrix(matrix); + canvas.drawRect(left, top, left + length, bottom, p); + } + if (drawRight) { + matrix.setScale(1, fadeHeight * rightFadeStrength); + matrix.postRotate(90); + matrix.postTranslate(right, top); + fade.setLocalMatrix(matrix); + canvas.drawRect(right - length, top, right, bottom, p); + } + canvas.restoreToCount(saveCount); + // Step 6, draw decorations (scrollbars) + onDrawScrollBars(canvas); + } + /** + * Override this if your view is known to always be drawn on top of a solid color background, + * and needs to draw fading edges. Returning a non-zero color enables the view system to + * optimize the drawing of the fading edges. If you do return a non-zero color, the alpha + * should be set to 0xFF. + * + * @see #setVerticalFadingEdgeEnabled(boolean) + * @see #setHorizontalFadingEdgeEnabled(boolean) + * + * @return The known solid color background for this view, or 0 if the color may vary + */ + @ViewDebug.ExportedProperty(category = "drawing") + public int getSolidColor() { + return 0; + } + /** + * Build a human readable string representation of the specified view flags. + * + * @param flags the view flags to convert to a string + * @return a String representing the supplied flags + */ + private static String printFlags(int flags) { + String output = ""; + int numFlags = 0; + if ((flags & FOCUSABLE_MASK) == FOCUSABLE) { + output += "TAKES_FOCUS"; + numFlags++; + } + switch (flags & VISIBILITY_MASK) { + case INVISIBLE: + if (numFlags > 0) { + output += " "; + } + output += "INVISIBLE"; + // USELESS HERE numFlags++; + break; + case GONE: + if (numFlags > 0) { + output += " "; + } + output += "GONE"; + // USELESS HERE numFlags++; + break; + default: + break; + } + return output; + } + /** + * Build a human readable string representation of the specified private + * view flags. + * + * @param privateFlags the private view flags to convert to a string + * @return a String representing the supplied flags + */ + private static String printPrivateFlags(int privateFlags) { + String output = ""; + int numFlags = 0; + if ((privateFlags & WANTS_FOCUS) == WANTS_FOCUS) { + output += "WANTS_FOCUS"; + numFlags++; + } + if ((privateFlags & FOCUSED) == FOCUSED) { + if (numFlags > 0) { + output += " "; + } + output += "FOCUSED"; + numFlags++; + } + if ((privateFlags & SELECTED) == SELECTED) { + if (numFlags > 0) { + output += " "; + } + output += "SELECTED"; + numFlags++; + } + if ((privateFlags & IS_ROOT_NAMESPACE) == IS_ROOT_NAMESPACE) { + if (numFlags > 0) { + output += " "; + } + output += "IS_ROOT_NAMESPACE"; + numFlags++; + } + if ((privateFlags & HAS_BOUNDS) == HAS_BOUNDS) { + if (numFlags > 0) { + output += " "; + } + output += "HAS_BOUNDS"; + numFlags++; + } + if ((privateFlags & DRAWN) == DRAWN) { + if (numFlags > 0) { + output += " "; + } + output += "DRAWN"; + // USELESS HERE numFlags++; + } + return output; + } + /** + *

Indicates whether or not this view's layout will be requested during + * the next hierarchy layout pass.

+ * + * @return true if the layout will be forced during next layout pass + */ + public boolean isLayoutRequested() { + return (mPrivateFlags & FORCE_LAYOUT) == FORCE_LAYOUT; + } + /** + * Assign a size and position to a view and all of its + * descendants + * + *

This is the second phase of the layout mechanism. + * (The first is measuring). In this phase, each parent calls + * layout on all of its children to position them. + * This is typically done using the child measurements + * that were stored in the measure pass().

+ * + *

Derived classes should not override this method. + * Derived classes with children should override + * onLayout. In that method, they should + * call layout on each of their children.

+ * + * @param l Left position, relative to parent + * @param t Top position, relative to parent + * @param r Right position, relative to parent + * @param b Bottom position, relative to parent + */ + @SuppressWarnings({"unchecked"}) + public void layout(int l, int t, int r, int b) { + int oldL = mLeft; + int oldT = mTop; + int oldB = mBottom; + int oldR = mRight; + boolean changed = setFrame(l, t, r, b); + if (changed || (mPrivateFlags & LAYOUT_REQUIRED) == LAYOUT_REQUIRED) { + if (ViewDebug.TRACE_HIERARCHY) { + ViewDebug.trace(this, ViewDebug.HierarchyTraceType.ON_LAYOUT); + } + onLayout(changed, l, t, r, b); + mPrivateFlags &= ~LAYOUT_REQUIRED; + ListenerInfo li = mListenerInfo; + if (li != null && li.mOnLayoutChangeListeners != null) { + ArrayList listenersCopy = + (ArrayList)li.mOnLayoutChangeListeners.clone(); + int numListeners = listenersCopy.size(); + for (int i = 0; i < numListeners; ++i) { + listenersCopy.get(i).onLayoutChange(this, l, t, r, b, oldL, oldT, oldR, oldB); + } + } + } + mPrivateFlags &= ~FORCE_LAYOUT; + } + /** + * Called from layout when this view should + * assign a size and position to each of its children. + * + * Derived classes with children should override + * this method and call layout on each of + * their children. + * @param changed This is a new size or position for this view + * @param left Left position, relative to parent + * @param top Top position, relative to parent + * @param right Right position, relative to parent + * @param bottom Bottom position, relative to parent + */ + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + } + /** + * Assign a size and position to this view. + * + * This is called from layout. + * + * @param left Left position, relative to parent + * @param top Top position, relative to parent + * @param right Right position, relative to parent + * @param bottom Bottom position, relative to parent + * @return true if the new size and position are different than the + * previous ones + * {@hide} + */ + protected boolean setFrame(int left, int top, int right, int bottom) { + boolean changed = false; + if (DBG) { + Log.d("View", this + " View.setFrame(" + left + "," + top + "," + + right + "," + bottom + ")"); + } + if (mLeft != left || mRight != right || mTop != top || mBottom != bottom) { + changed = true; + // Remember our drawn bit + int drawn = mPrivateFlags & DRAWN; + int oldWidth = mRight - mLeft; + int oldHeight = mBottom - mTop; + int newWidth = right - left; + int newHeight = bottom - top; + boolean sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight); + // Invalidate our old position + invalidate(sizeChanged); + mLeft = left; + mTop = top; + mRight = right; + mBottom = bottom; + mPrivateFlags |= HAS_BOUNDS; + if (sizeChanged) { + if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { + // A change in dimension means an auto-centered pivot point changes, too + if (mTransformationInfo != null) { + mTransformationInfo.mMatrixDirty = true; + } + } + onSizeChanged(newWidth, newHeight, oldWidth, oldHeight); + } + if ((mViewFlags & VISIBILITY_MASK) == VISIBLE) { + // If we are visible, force the DRAWN bit to on so that + // this invalidate will go through (at least to our parent). + // This is because someone may have invalidated this view + // before this call to setFrame came in, thereby clearing + // the DRAWN bit. + mPrivateFlags |= DRAWN; + invalidate(sizeChanged); + // parent display list may need to be recreated based on a change in the bounds + // of any child + invalidateParentCaches(); + } + // Reset drawn bit to original value (invalidate turns it off) + mPrivateFlags |= drawn; + mBackgroundSizeChanged = true; + } + return changed; + } + /** + * Finalize inflating a view from XML. This is called as the last phase + * of inflation, after all child views have been added. + * + *

Even if the subclass overrides onFinishInflate, they should always be + * sure to call the super method, so that we get called. + */ + protected void onFinishInflate() { + } + /** + * Returns the resources associated with this view. + * + * @return Resources object. + */ + public Resources getResources() { + return mResources; + } + /** + * Invalidates the specified Drawable. + * + * @param drawable the drawable to invalidate + */ + public void invalidateDrawable(Drawable drawable) { + if (verifyDrawable(drawable)) { + final Rect dirty = drawable.getBounds(); + final int scrollX = mScrollX; + final int scrollY = mScrollY; + invalidate(dirty.left + scrollX, dirty.top + scrollY, + dirty.right + scrollX, dirty.bottom + scrollY); + } + } + /** + * Schedules an action on a drawable to occur at a specified time. + * + * @param who the recipient of the action + * @param what the action to run on the drawable + * @param when the time at which the action must occur. Uses the + * {@link SystemClock#uptimeMillis} timebase. + */ + public void scheduleDrawable(Drawable who, Runnable what, long when) { + if (verifyDrawable(who) && what != null) { + if (mAttachInfo != null) { + mAttachInfo.mHandler.postAtTime(what, who, when); + } else { + ViewRootImpl.getRunQueue().postDelayed(what, when - SystemClock.uptimeMillis()); + } + } + } + /** + * Cancels a scheduled action on a drawable. + * + * @param who the recipient of the action + * @param what the action to cancel + */ + public void unscheduleDrawable(Drawable who, Runnable what) { + if (verifyDrawable(who) && what != null) { + if (mAttachInfo != null) { + mAttachInfo.mHandler.removeCallbacks(what, who); + } else { + ViewRootImpl.getRunQueue().removeCallbacks(what); + } + } + } + /** + * Unschedule any events associated with the given Drawable. This can be + * used when selecting a new Drawable into a view, so that the previous + * one is completely unscheduled. + * + * @param who The Drawable to unschedule. + * + * @see #drawableStateChanged + */ + public void unscheduleDrawable(Drawable who) { + if (mAttachInfo != null) { + mAttachInfo.mHandler.removeCallbacksAndMessages(who); + } + } + /** + * Return the layout direction of a given Drawable. + * + * @param who the Drawable to query + * + * @hide + */ + public int getResolvedLayoutDirection(Drawable who) { + return (who == mBGDrawable) ? getResolvedLayoutDirection() : LAYOUT_DIRECTION_DEFAULT; + } + /** + * If your view subclass is displaying its own Drawable objects, it should + * override this function and return true for any Drawable it is + * displaying. This allows animations for those drawables to be + * scheduled. + * + *

Be sure to call through to the super class when overriding this + * function. + * + * @param who The Drawable to verify. Return true if it is one you are + * displaying, else return the result of calling through to the + * super class. + * + * @return boolean If true than the Drawable is being displayed in the + * view; else false and it is not allowed to animate. + * + * @see #unscheduleDrawable(android.graphics.drawable.Drawable) + * @see #drawableStateChanged() + */ + protected boolean verifyDrawable(Drawable who) { + return who == mBGDrawable; + } + /** + * This function is called whenever the state of the view changes in such + * a way that it impacts the state of drawables being shown. + * + *

Be sure to call through to the superclass when overriding this + * function. + * + * @see Drawable#setState(int[]) + */ + protected void drawableStateChanged() { + Drawable d = mBGDrawable; + if (d != null && d.isStateful()) { + d.setState(getDrawableState()); + } + } + /** + * Call this to force a view to update its drawable state. This will cause + * drawableStateChanged to be called on this view. Views that are interested + * in the new state should call getDrawableState. + * + * @see #drawableStateChanged + * @see #getDrawableState + */ + public void refreshDrawableState() { + mPrivateFlags |= DRAWABLE_STATE_DIRTY; + drawableStateChanged(); + ViewParent parent = mParent; + if (parent != null) { + parent.childDrawableStateChanged(this); + } + } + /** + * Return an array of resource IDs of the drawable states representing the + * current state of the view. + * + * @return The current drawable state + * + * @see Drawable#setState(int[]) + * @see #drawableStateChanged() + * @see #onCreateDrawableState(int) + */ + public final int[] getDrawableState() { + if ((mDrawableState != null) && ((mPrivateFlags & DRAWABLE_STATE_DIRTY) == 0)) { + return mDrawableState; + } else { + mDrawableState = onCreateDrawableState(0); + mPrivateFlags &= ~DRAWABLE_STATE_DIRTY; + return mDrawableState; + } + } + /** + * Generate the new {@link android.graphics.drawable.Drawable} state for + * this view. This is called by the view + * system when the cached Drawable state is determined to be invalid. To + * retrieve the current state, you should use {@link #getDrawableState}. + * + * @param extraSpace if non-zero, this is the number of extra entries you + * would like in the returned array in which you can place your own + * states. + * + * @return Returns an array holding the current {@link Drawable} state of + * the view. + * + * @see #mergeDrawableStates(int[], int[]) + */ + protected int[] onCreateDrawableState(int extraSpace) { + if ((mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE && + mParent instanceof View) { + return ((View) mParent).onCreateDrawableState(extraSpace); + } + int[] drawableState; + int privateFlags = mPrivateFlags; + int viewStateIndex = 0; + if ((privateFlags & PRESSED) != 0) viewStateIndex |= VIEW_STATE_PRESSED; + if ((mViewFlags & ENABLED_MASK) == ENABLED) viewStateIndex |= VIEW_STATE_ENABLED; + if (isFocused()) viewStateIndex |= VIEW_STATE_FOCUSED; + if ((privateFlags & SELECTED) != 0) viewStateIndex |= VIEW_STATE_SELECTED; + if (hasWindowFocus()) viewStateIndex |= VIEW_STATE_WINDOW_FOCUSED; + if ((privateFlags & ACTIVATED) != 0) viewStateIndex |= VIEW_STATE_ACTIVATED; + if (mAttachInfo != null && mAttachInfo.mHardwareAccelerationRequested && + HardwareRenderer.isAvailable()) { + // This is set if HW acceleration is requested, even if the current + // process doesn't allow it. This is just to allow app preview + // windows to better match their app. + viewStateIndex |= VIEW_STATE_ACCELERATED; + } + if ((privateFlags & HOVERED) != 0) viewStateIndex |= VIEW_STATE_HOVERED; + final int privateFlags2 = mPrivateFlags2; + if ((privateFlags2 & DRAG_CAN_ACCEPT) != 0) viewStateIndex |= VIEW_STATE_DRAG_CAN_ACCEPT; + if ((privateFlags2 & DRAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_DRAG_HOVERED; + drawableState = VIEW_STATE_SETS[viewStateIndex]; + //noinspection ConstantIfStatement + if (false) { + Log.i("View", "drawableStateIndex=" + viewStateIndex); + Log.i("View", toString() + + " pressed=" + ((privateFlags & PRESSED) != 0) + + " en=" + ((mViewFlags & ENABLED_MASK) == ENABLED) + + " fo=" + hasFocus() + + " sl=" + ((privateFlags & SELECTED) != 0) + + " wf=" + hasWindowFocus() + + ": " + Arrays.toString(drawableState)); + } + if (extraSpace == 0) { + return drawableState; + } + final int[] fullState; + if (drawableState != null) { + fullState = new int[drawableState.length + extraSpace]; + System.arraycopy(drawableState, 0, fullState, 0, drawableState.length); + } else { + fullState = new int[extraSpace]; + } + return fullState; + } + /** + * Merge your own state values in additionalState into the base + * state values baseState that were returned by + * {@link #onCreateDrawableState(int)}. + * + * @param baseState The base state values returned by + * {@link #onCreateDrawableState(int)}, which will be modified to also hold your + * own additional state values. + * + * @param additionalState The additional state values you would like + * added to baseState; this array is not modified. + * + * @return As a convenience, the baseState array you originally + * passed into the function is returned. + * + * @see #onCreateDrawableState(int) + */ + protected static int[] mergeDrawableStates(int[] baseState, int[] additionalState) { + final int N = baseState.length; + int i = N - 1; + while (i >= 0 && baseState[i] == 0) { + i--; + } + System.arraycopy(additionalState, 0, baseState, i + 1, additionalState.length); + return baseState; + } + /** + * Call {@link Drawable#jumpToCurrentState() Drawable.jumpToCurrentState()} + * on all Drawable objects associated with this view. + */ + public void jumpDrawablesToCurrentState() { + if (mBGDrawable != null) { + mBGDrawable.jumpToCurrentState(); + } + } + /** + * Sets the background color for this view. + * @param color the color of the background + */ + @RemotableViewMethod + public void setBackgroundColor(int color) { + if (mBGDrawable instanceof ColorDrawable) { + ((ColorDrawable) mBGDrawable).setColor(color); + } else { + setBackgroundDrawable(new ColorDrawable(color)); + } + } + /** + * Set the background to a given resource. The resource should refer to + * a Drawable object or 0 to remove the background. + * @param resid The identifier of the resource. + * @attr ref android.R.styleable#View_background + */ + @RemotableViewMethod + public void setBackgroundResource(int resid) { + if (resid != 0 && resid == mBackgroundResource) { + return; + } + Drawable d= null; + if (resid != 0) { + d = mResources.getDrawable(resid); + } + setBackgroundDrawable(d); + mBackgroundResource = resid; + } + /** + * Set the background to a given Drawable, or remove the background. If the + * background has padding, this View's padding is set to the background's + * padding. However, when a background is removed, this View's padding isn't + * touched. If setting the padding is desired, please use + * {@link #setPadding(int, int, int, int)}. + * + * @param d The Drawable to use as the background, or null to remove the + * background + */ + public void setBackgroundDrawable(Drawable d) { + if (d == mBGDrawable) { + return; + } + boolean requestLayout = false; + mBackgroundResource = 0; + /* + * Regardless of whether we're setting a new background or not, we want + * to clear the previous drawable. + */ + if (mBGDrawable != null) { + mBGDrawable.setCallback(null); + unscheduleDrawable(mBGDrawable); + } + if (d != null) { + Rect padding = sThreadLocal.get(); + if (padding == null) { + padding = new Rect(); + sThreadLocal.set(padding); + } + if (d.getPadding(padding)) { + switch (d.getResolvedLayoutDirectionSelf()) { + case LAYOUT_DIRECTION_RTL: + setPadding(padding.right, padding.top, padding.left, padding.bottom); + break; + case LAYOUT_DIRECTION_LTR: + default: + setPadding(padding.left, padding.top, padding.right, padding.bottom); + } + } + // Compare the minimum sizes of the old Drawable and the new. If there isn't an old or + // if it has a different minimum size, we should layout again + if (mBGDrawable == null || mBGDrawable.getMinimumHeight() != d.getMinimumHeight() || + mBGDrawable.getMinimumWidth() != d.getMinimumWidth()) { + requestLayout = true; + } + d.setCallback(this); + if (d.isStateful()) { + d.setState(getDrawableState()); + } + d.setVisible(getVisibility() == VISIBLE, false); + mBGDrawable = d; + if ((mPrivateFlags & SKIP_DRAW) != 0) { + mPrivateFlags &= ~SKIP_DRAW; + mPrivateFlags |= ONLY_DRAWS_BACKGROUND; + requestLayout = true; + } + } else { + /* Remove the background */ + mBGDrawable = null; + if ((mPrivateFlags & ONLY_DRAWS_BACKGROUND) != 0) { + /* + * This view ONLY drew the background before and we're removing + * the background, so now it won't draw anything + * (hence we SKIP_DRAW) + */ + mPrivateFlags &= ~ONLY_DRAWS_BACKGROUND; + mPrivateFlags |= SKIP_DRAW; + } + /* + * When the background is set, we try to apply its padding to this + * View. When the background is removed, we don't touch this View's + * padding. This is noted in the Javadocs. Hence, we don't need to + * requestLayout(), the invalidate() below is sufficient. + */ + // The old background's minimum size could have affected this + // View's layout, so let's requestLayout + requestLayout = true; + } + computeOpaqueFlags(); + if (requestLayout) { + requestLayout(); + } + mBackgroundSizeChanged = true; + invalidate(true); + } + /** + * Gets the background drawable + * @return The drawable used as the background for this view, if any. + */ + public Drawable getBackground() { + return mBGDrawable; + } + /** + * Sets the padding. The view may add on the space required to display + * the scrollbars, depending on the style and visibility of the scrollbars. + * So the values returned from {@link #getPaddingLeft}, {@link #getPaddingTop}, + * {@link #getPaddingRight} and {@link #getPaddingBottom} may be different + * from the values set in this call. + * + * @attr ref android.R.styleable#View_padding + * @attr ref android.R.styleable#View_paddingBottom + * @attr ref android.R.styleable#View_paddingLeft + * @attr ref android.R.styleable#View_paddingRight + * @attr ref android.R.styleable#View_paddingTop + * @param left the left padding in pixels + * @param top the top padding in pixels + * @param right the right padding in pixels + * @param bottom the bottom padding in pixels + */ + public void setPadding(int left, int top, int right, int bottom) { + boolean changed = false; + mUserPaddingRelative = false; + mUserPaddingLeft = left; + mUserPaddingRight = right; + mUserPaddingBottom = bottom; + final int viewFlags = mViewFlags; + // Common case is there are no scroll bars. + if ((viewFlags & (SCROLLBARS_VERTICAL|SCROLLBARS_HORIZONTAL)) != 0) { + if ((viewFlags & SCROLLBARS_VERTICAL) != 0) { + final int offset = (viewFlags & SCROLLBARS_INSET_MASK) == 0 + ? 0 : getVerticalScrollbarWidth(); + switch (mVerticalScrollbarPosition) { + case SCROLLBAR_POSITION_DEFAULT: + if (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { + left += offset; + } else { + right += offset; + } + break; + case SCROLLBAR_POSITION_RIGHT: + right += offset; + break; + case SCROLLBAR_POSITION_LEFT: + left += offset; + break; + } + } + if ((viewFlags & SCROLLBARS_HORIZONTAL) != 0) { + bottom += (viewFlags & SCROLLBARS_INSET_MASK) == 0 + ? 0 : getHorizontalScrollbarHeight(); + } + } + if (mPaddingLeft != left) { + changed = true; + mPaddingLeft = left; + } + if (mPaddingTop != top) { + changed = true; + mPaddingTop = top; + } + if (mPaddingRight != right) { + changed = true; + mPaddingRight = right; + } + if (mPaddingBottom != bottom) { + changed = true; + mPaddingBottom = bottom; + } + if (changed) { + requestLayout(); + } + } + /** + * Sets the relative padding. The view may add on the space required to display + * the scrollbars, depending on the style and visibility of the scrollbars. + * So the values returned from {@link #getPaddingStart}, {@link #getPaddingTop}, + * {@link #getPaddingEnd} and {@link #getPaddingBottom} may be different + * from the values set in this call. + * + * @attr ref android.R.styleable#View_padding + * @attr ref android.R.styleable#View_paddingBottom + * @attr ref android.R.styleable#View_paddingStart + * @attr ref android.R.styleable#View_paddingEnd + * @attr ref android.R.styleable#View_paddingTop + * @param start the start padding in pixels + * @param top the top padding in pixels + * @param end the end padding in pixels + * @param bottom the bottom padding in pixels + * + * @hide + */ + public void setPaddingRelative(int start, int top, int end, int bottom) { + mUserPaddingRelative = true; + mUserPaddingStart = start; + mUserPaddingEnd = end; + switch(getResolvedLayoutDirection()) { + case LAYOUT_DIRECTION_RTL: + setPadding(end, top, start, bottom); + break; + case LAYOUT_DIRECTION_LTR: + default: + setPadding(start, top, end, bottom); + } + } + /** + * Returns the top padding of this view. + * + * @return the top padding in pixels + */ + public int getPaddingTop() { + return mPaddingTop; + } + /** + * Returns the bottom padding of this view. If there are inset and enabled + * scrollbars, this value may include the space required to display the + * scrollbars as well. + * + * @return the bottom padding in pixels + */ + public int getPaddingBottom() { + return mPaddingBottom; + } + /** + * Returns the left padding of this view. If there are inset and enabled + * scrollbars, this value may include the space required to display the + * scrollbars as well. + * + * @return the left padding in pixels + */ + public int getPaddingLeft() { + return mPaddingLeft; + } + /** + * Returns the start padding of this view. If there are inset and enabled + * scrollbars, this value may include the space required to display the + * scrollbars as well. + * + * @return the start padding in pixels + * + * @hide + */ + public int getPaddingStart() { + return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? + mPaddingRight : mPaddingLeft; + } + /** + * Returns the right padding of this view. If there are inset and enabled + * scrollbars, this value may include the space required to display the + * scrollbars as well. + * + * @return the right padding in pixels + */ + public int getPaddingRight() { + return mPaddingRight; + } + /** + * Returns the end padding of this view. If there are inset and enabled + * scrollbars, this value may include the space required to display the + * scrollbars as well. + * + * @return the end padding in pixels + * + * @hide + */ + public int getPaddingEnd() { + return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? + mPaddingLeft : mPaddingRight; + } + /** + * Return if the padding as been set thru relative values + * {@link #setPaddingRelative(int, int, int, int)} or thru + * @attr ref android.R.styleable#View_paddingStart or + * @attr ref android.R.styleable#View_paddingEnd + * + * @return true if the padding is relative or false if it is not. + * + * @hide + */ + public boolean isPaddingRelative() { + return mUserPaddingRelative; + } + /** + * Changes the selection state of this view. A view can be selected or not. + * Note that selection is not the same as focus. Views are typically + * selected in the context of an AdapterView like ListView or GridView; + * the selected view is the view that is highlighted. + * + * @param selected true if the view must be selected, false otherwise + */ + public void setSelected(boolean selected) { + if (((mPrivateFlags & SELECTED) != 0) != selected) { + mPrivateFlags = (mPrivateFlags & ~SELECTED) | (selected ? SELECTED : 0); + if (!selected) resetPressedState(); + invalidate(true); + refreshDrawableState(); + dispatchSetSelected(selected); + } + } + /** + * Dispatch setSelected to all of this View's children. + * + * @see #setSelected(boolean) + * + * @param selected The new selected state + */ + protected void dispatchSetSelected(boolean selected) { + } + /** + * Indicates the selection state of this view. + * + * @return true if the view is selected, false otherwise + */ + @ViewDebug.ExportedProperty + public boolean isSelected() { + return (mPrivateFlags & SELECTED) != 0; + } + /** + * Changes the activated state of this view. A view can be activated or not. + * Note that activation is not the same as selection. Selection is + * a transient property, representing the view (hierarchy) the user is + * currently interacting with. Activation is a longer-term state that the + * user can move views in and out of. For example, in a list view with + * single or multiple selection enabled, the views in the current selection + * set are activated. (Um, yeah, we are deeply sorry about the terminology + * here.) The activated state is propagated down to children of the view it + * is set on. + * + * @param activated true if the view must be activated, false otherwise + */ + public void setActivated(boolean activated) { + if (((mPrivateFlags & ACTIVATED) != 0) != activated) { + mPrivateFlags = (mPrivateFlags & ~ACTIVATED) | (activated ? ACTIVATED : 0); + invalidate(true); + refreshDrawableState(); + dispatchSetActivated(activated); + } + } + /** + * Dispatch setActivated to all of this View's children. + * + * @see #setActivated(boolean) + * + * @param activated The new activated state + */ + protected void dispatchSetActivated(boolean activated) { + } + /** + * Indicates the activation state of this view. + * + * @return true if the view is activated, false otherwise + */ + @ViewDebug.ExportedProperty + public boolean isActivated() { + return (mPrivateFlags & ACTIVATED) != 0; + } + /** + * Returns the ViewTreeObserver for this view's hierarchy. The view tree + * observer can be used to get notifications when global events, like + * layout, happen. + * + * The returned ViewTreeObserver observer is not guaranteed to remain + * valid for the lifetime of this View. If the caller of this method keeps + * a long-lived reference to ViewTreeObserver, it should always check for + * the return value of {@link ViewTreeObserver#isAlive()}. + * + * @return The ViewTreeObserver for this view's hierarchy. + */ + public ViewTreeObserver getViewTreeObserver() { + if (mAttachInfo != null) { + return mAttachInfo.mTreeObserver; + } + if (mFloatingTreeObserver == null) { + mFloatingTreeObserver = new ViewTreeObserver(); + } + return mFloatingTreeObserver; + } + /** + *

Finds the topmost view in the current view hierarchy.

+ * + * @return the topmost view containing this view + */ + public View getRootView() { + if (mAttachInfo != null) { + final View v = mAttachInfo.mRootView; + if (v != null) { + return v; + } + } + View parent = this; + while (parent.mParent != null && parent.mParent instanceof View) { + parent = (View) parent.mParent; + } + return parent; + } + /** + *

Computes the coordinates of this view on the screen. The argument + * must be an array of two integers. After the method returns, the array + * contains the x and y location in that order.

+ * + * @param location an array of two integers in which to hold the coordinates + */ + public void getLocationOnScreen(int[] location) { + getLocationInWindow(location); + final AttachInfo info = mAttachInfo; + if (info != null) { + location[0] += info.mWindowLeft; + location[1] += info.mWindowTop; + } + } + /** + *

Computes the coordinates of this view in its window. The argument + * must be an array of two integers. After the method returns, the array + * contains the x and y location in that order.

+ * + * @param location an array of two integers in which to hold the coordinates + */ + public void getLocationInWindow(int[] location) { + if (location == null || location.length < 2) { + throw new IllegalArgumentException("location must be an array of two integers"); + } + if (mAttachInfo == null) { + // When the view is not attached to a window, this method does not make sense + location[0] = location[1] = 0; + return; + } + float[] position = mAttachInfo.mTmpTransformLocation; + position[0] = position[1] = 0.0f; + if (!hasIdentityMatrix()) { + getMatrix().mapPoints(position); + } + position[0] += mLeft; + position[1] += mTop; + ViewParent viewParent = mParent; + while (viewParent instanceof View) { + final View view = (View) viewParent; + position[0] -= view.mScrollX; + position[1] -= view.mScrollY; + if (!view.hasIdentityMatrix()) { + view.getMatrix().mapPoints(position); + } + position[0] += view.mLeft; + position[1] += view.mTop; + viewParent = view.mParent; + } + if (viewParent instanceof ViewRootImpl) { + // *cough* + final ViewRootImpl vr = (ViewRootImpl) viewParent; + position[1] -= vr.mCurScrollY; + } + location[0] = (int) (position[0] + 0.5f); + location[1] = (int) (position[1] + 0.5f); + } + /** + * {@hide} + * @param id the id of the view to be found + * @return the view of the specified id, null if cannot be found + */ + protected View findViewTraversal(int id) { + if (id == mID) { + return this; + } + return null; + } + /** + * {@hide} + * @param tag the tag of the view to be found + * @return the view of specified tag, null if cannot be found + */ + protected View findViewWithTagTraversal(Object tag) { + if (tag != null && tag.equals(mTag)) { + return this; + } + return null; + } + /** + * {@hide} + * @param predicate The predicate to evaluate. + * @param childToSkip If not null, ignores this child during the recursive traversal. + * @return The first view that matches the predicate or null. + */ + protected View findViewByPredicateTraversal(Predicate predicate, View childToSkip) { + if (predicate.apply(this)) { + return this; + } + return null; + } + /** + * Look for a child view with the given id. If this view has the given + * id, return this view. + * + * @param id The id to search for. + * @return The view that has the given id in the hierarchy or null + */ + public final View findViewById(int id) { + if (id < 0) { + return null; + } + return findViewTraversal(id); + } + /** + * Finds a view by its unuque and stable accessibility id. + * + * @param accessibilityId The searched accessibility id. + * @return The found view. + */ + final View findViewByAccessibilityId(int accessibilityId) { + if (accessibilityId < 0) { + return null; + } + return findViewByAccessibilityIdTraversal(accessibilityId); + } + /** + * Performs the traversal to find a view by its unuque and stable accessibility id. + * + * Note:This method does not stop at the root namespace + * boundary since the user can touch the screen at an arbitrary location + * potentially crossing the root namespace bounday which will send an + * accessibility event to accessibility services and they should be able + * to obtain the event source. Also accessibility ids are guaranteed to be + * unique in the window. + * + * @param accessibilityId The accessibility id. + * @return The found view. + */ + View findViewByAccessibilityIdTraversal(int accessibilityId) { + if (getAccessibilityViewId() == accessibilityId) { + return this; + } + return null; + } + /** + * Look for a child view with the given tag. If this view has the given + * tag, return this view. + * + * @param tag The tag to search for, using "tag.equals(getTag())". + * @return The View that has the given tag in the hierarchy or null + */ + public final View findViewWithTag(Object tag) { + if (tag == null) { + return null; + } + return findViewWithTagTraversal(tag); + } + /** + * {@hide} + * Look for a child view that matches the specified predicate. + * If this view matches the predicate, return this view. + * + * @param predicate The predicate to evaluate. + * @return The first view that matches the predicate or null. + */ + public final View findViewByPredicate(Predicate predicate) { + return findViewByPredicateTraversal(predicate, null); + } + /** + * {@hide} + * Look for a child view that matches the specified predicate, + * starting with the specified view and its descendents and then + * recusively searching the ancestors and siblings of that view + * until this view is reached. + * + * This method is useful in cases where the predicate does not match + * a single unique view (perhaps multiple views use the same id) + * and we are trying to find the view that is "closest" in scope to the + * starting view. + * + * @param start The view to start from. + * @param predicate The predicate to evaluate. + * @return The first view that matches the predicate or null. + */ + public final View findViewByPredicateInsideOut(View start, Predicate predicate) { + View childToSkip = null; + for (;;) { + View view = start.findViewByPredicateTraversal(predicate, childToSkip); + if (view != null || start == this) { + return view; + } + ViewParent parent = start.getParent(); + if (parent == null || !(parent instanceof View)) { + return null; + } + childToSkip = start; + start = (View) parent; + } + } + /** + * Sets the identifier for this view. The identifier does not have to be + * unique in this view's hierarchy. The identifier should be a positive + * number. + * + * @see #NO_ID + * @see #getId() + * @see #findViewById(int) + * + * @param id a number used to identify the view + * + * @attr ref android.R.styleable#View_id + */ + public void setId(int id) { + mID = id; + } + /** + * {@hide} + * + * @param isRoot true if the view belongs to the root namespace, false + * otherwise + */ + public void setIsRootNamespace(boolean isRoot) { + if (isRoot) { + mPrivateFlags |= IS_ROOT_NAMESPACE; + } else { + mPrivateFlags &= ~IS_ROOT_NAMESPACE; + } + } + /** + * {@hide} + * + * @return true if the view belongs to the root namespace, false otherwise + */ + public boolean isRootNamespace() { + return (mPrivateFlags&IS_ROOT_NAMESPACE) != 0; + } + /** + * Returns this view's identifier. + * + * @return a positive integer used to identify the view or {@link #NO_ID} + * if the view has no ID + * + * @see #setId(int) + * @see #findViewById(int) + * @attr ref android.R.styleable#View_id + */ + @ViewDebug.CapturedViewProperty + public int getId() { + return mID; + } + /** + * Returns this view's tag. + * + * @return the Object stored in this view as a tag + * + * @see #setTag(Object) + * @see #getTag(int) + */ + @ViewDebug.ExportedProperty + public Object getTag() { + return mTag; + } + /** + * Sets the tag associated with this view. A tag can be used to mark + * a view in its hierarchy and does not have to be unique within the + * hierarchy. Tags can also be used to store data within a view without + * resorting to another data structure. + * + * @param tag an Object to tag the view with + * + * @see #getTag() + * @see #setTag(int, Object) + */ + public void setTag(final Object tag) { + mTag = tag; + } + /** + * Returns the tag associated with this view and the specified key. + * + * @param key The key identifying the tag + * + * @return the Object stored in this view as a tag + * + * @see #setTag(int, Object) + * @see #getTag() + */ + public Object getTag(int key) { + if (mKeyedTags != null) return mKeyedTags.get(key); + return null; + } + /** + * Sets a tag associated with this view and a key. A tag can be used + * to mark a view in its hierarchy and does not have to be unique within + * the hierarchy. Tags can also be used to store data within a view + * without resorting to another data structure. + * + * The specified key should be an id declared in the resources of the + * application to ensure it is unique (see the ID resource type). + * Keys identified as belonging to + * the Android framework or not associated with any package will cause + * an {@link IllegalArgumentException} to be thrown. + * + * @param key The key identifying the tag + * @param tag An Object to tag the view with + * + * @throws IllegalArgumentException If they specified key is not valid + * + * @see #setTag(Object) + * @see #getTag(int) + */ + public void setTag(int key, final Object tag) { + // If the package id is 0x00 or 0x01, it's either an undefined package + // or a framework id + if ((key >>> 24) < 2) { + throw new IllegalArgumentException("The key must be an application-specific " + + "resource id."); + } + setKeyedTag(key, tag); + } + /** + * Variation of {@link #setTag(int, Object)} that enforces the key to be a + * framework id. + * + * @hide + */ + public void setTagInternal(int key, Object tag) { + if ((key >>> 24) != 0x1) { + throw new IllegalArgumentException("The key must be a framework-specific " + + "resource id."); + } + setKeyedTag(key, tag); + } + private void setKeyedTag(int key, Object tag) { + if (mKeyedTags == null) { + mKeyedTags = new SparseArray(); + } + mKeyedTags.put(key, tag); + } + /** + * @param consistency The type of consistency. See ViewDebug for more information. + * + * @hide + */ + protected boolean dispatchConsistencyCheck(int consistency) { + return onConsistencyCheck(consistency); + } + /** + * Method that subclasses should implement to check their consistency. The type of + * consistency check is indicated by the bit field passed as a parameter. + * + * @param consistency The type of consistency. See ViewDebug for more information. + * + * @throws IllegalStateException if the view is in an inconsistent state. + * + * @hide + */ + protected boolean onConsistencyCheck(int consistency) { + boolean result = true; + final boolean checkLayout = (consistency & ViewDebug.CONSISTENCY_LAYOUT) != 0; + final boolean checkDrawing = (consistency & ViewDebug.CONSISTENCY_DRAWING) != 0; + if (checkLayout) { + if (getParent() == null) { + result = false; + android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, + "View " + this + " does not have a parent."); + } + if (mAttachInfo == null) { + result = false; + android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, + "View " + this + " is not attached to a window."); + } + } + if (checkDrawing) { + // Do not check the DIRTY/DRAWN flags because views can call invalidate() + // from their draw() method + if ((mPrivateFlags & DRAWN) != DRAWN && + (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) { + result = false; + android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, + "View " + this + " was invalidated but its drawing cache is valid."); + } + } + return result; + } + /** + * Prints information about this view in the log output, with the tag + * {@link #VIEW_LOG_TAG}. + * + * @hide + */ + public void debug() { + debug(0); + } + /** + * Prints information about this view in the log output, with the tag + * {@link #VIEW_LOG_TAG}. Each line in the output is preceded with an + * indentation defined by the depth. + * + * @param depth the indentation level + * + * @hide + */ + protected void debug(int depth) { + String output = debugIndent(depth - 1); + output += "+ " + this; + int id = getId(); + if (id != -1) { + output += " (id=" + id + ")"; + } + Object tag = getTag(); + if (tag != null) { + output += " (tag=" + tag + ")"; + } + Log.d(VIEW_LOG_TAG, output); + if ((mPrivateFlags & FOCUSED) != 0) { + output = debugIndent(depth) + " FOCUSED"; + Log.d(VIEW_LOG_TAG, output); + } + output = debugIndent(depth); + output += "frame={" + mLeft + ", " + mTop + ", " + mRight + + ", " + mBottom + "} scroll={" + mScrollX + ", " + mScrollY + + "} "; + Log.d(VIEW_LOG_TAG, output); + if (mPaddingLeft != 0 || mPaddingTop != 0 || mPaddingRight != 0 + || mPaddingBottom != 0) { + output = debugIndent(depth); + output += "padding={" + mPaddingLeft + ", " + mPaddingTop + + ", " + mPaddingRight + ", " + mPaddingBottom + "}"; + Log.d(VIEW_LOG_TAG, output); + } + output = debugIndent(depth); + output += "mMeasureWidth=" + mMeasuredWidth + + " mMeasureHeight=" + mMeasuredHeight; + Log.d(VIEW_LOG_TAG, output); + output = debugIndent(depth); + if (mLayoutParams == null) { + output += "BAD! no layout params"; + } else { + output = mLayoutParams.debug(output); + } + Log.d(VIEW_LOG_TAG, output); + output = debugIndent(depth); + output += "flags={"; + output += View.printFlags(mViewFlags); + output += "}"; + Log.d(VIEW_LOG_TAG, output); + output = debugIndent(depth); + output += "privateFlags={"; + output += View.printPrivateFlags(mPrivateFlags); + output += "}"; + Log.d(VIEW_LOG_TAG, output); + } + /** + * Creates an string of whitespaces used for indentation. + * + * @param depth the indentation level + * @return a String containing (depth * 2 + 3) * 2 white spaces + * + * @hide + */ + protected static String debugIndent(int depth) { + StringBuilder spaces = new StringBuilder((depth * 2 + 3) * 2); + for (int i = 0; i < (depth * 2) + 3; i++) { + spaces.append(' ').append(' '); + } + return spaces.toString(); + } + /** + *

Return the offset of the widget's text baseline from the widget's top + * boundary. If this widget does not support baseline alignment, this + * method returns -1.

+ * + * @return the offset of the baseline within the widget's bounds or -1 + * if baseline alignment is not supported + */ + @ViewDebug.ExportedProperty(category = "layout") + public int getBaseline() { + return -1; + } + /** + * Call this when something has changed which has invalidated the + * layout of this view. This will schedule a layout pass of the view + * tree. + */ + public void requestLayout() { + if (ViewDebug.TRACE_HIERARCHY) { + ViewDebug.trace(this, ViewDebug.HierarchyTraceType.REQUEST_LAYOUT); + } + if (getAccessibilityNodeProvider() != null) { + throw new IllegalStateException("Views with AccessibilityNodeProvider" + + " can't have children."); + } + mPrivateFlags |= FORCE_LAYOUT; + mPrivateFlags |= INVALIDATED; + if (mParent != null) { + if (mLayoutParams != null) { + mLayoutParams.resolveWithDirection(getResolvedLayoutDirection()); + } + if (!mParent.isLayoutRequested()) { + mParent.requestLayout(); + } + } + } + /** + * Forces this view to be laid out during the next layout pass. + * This method does not call requestLayout() or forceLayout() + * on the parent. + */ + public void forceLayout() { + mPrivateFlags |= FORCE_LAYOUT; + mPrivateFlags |= INVALIDATED; + } + /** + *

+ * This is called to find out how big a view should be. The parent + * supplies constraint information in the width and height parameters. + *

+ * + *

+ * The actual measurement work of a view is performed in + * {@link #onMeasure(int, int)}, called by this method. Therefore, only + * {@link #onMeasure(int, int)} can and must be overridden by subclasses. + *

+ * + * + * @param widthMeasureSpec Horizontal space requirements as imposed by the + * parent + * @param heightMeasureSpec Vertical space requirements as imposed by the + * parent + * + * @see #onMeasure(int, int) + */ + public final void measure(int widthMeasureSpec, int heightMeasureSpec) { + if ((mPrivateFlags & FORCE_LAYOUT) == FORCE_LAYOUT || + widthMeasureSpec != mOldWidthMeasureSpec || + heightMeasureSpec != mOldHeightMeasureSpec) { + // first clears the measured dimension flag + mPrivateFlags &= ~MEASURED_DIMENSION_SET; + if (ViewDebug.TRACE_HIERARCHY) { + ViewDebug.trace(this, ViewDebug.HierarchyTraceType.ON_MEASURE); + } + // measure ourselves, this should set the measured dimension flag back + onMeasure(widthMeasureSpec, heightMeasureSpec); + // flag not set, setMeasuredDimension() was not invoked, we raise + // an exception to warn the developer + if ((mPrivateFlags & MEASURED_DIMENSION_SET) != MEASURED_DIMENSION_SET) { + throw new IllegalStateException("onMeasure() did not set the" + + " measured dimension by calling" + + " setMeasuredDimension()"); + } + mPrivateFlags |= LAYOUT_REQUIRED; + } + mOldWidthMeasureSpec = widthMeasureSpec; + mOldHeightMeasureSpec = heightMeasureSpec; + } + /** + *

+ * Measure the view and its content to determine the measured width and the + * measured height. This method is invoked by {@link #measure(int, int)} and + * should be overriden by subclasses to provide accurate and efficient + * measurement of their contents. + *

+ * + *

+ * CONTRACT: When overriding this method, you + * must call {@link #setMeasuredDimension(int, int)} to store the + * measured width and height of this view. Failure to do so will trigger an + * IllegalStateException, thrown by + * {@link #measure(int, int)}. Calling the superclass' + * {@link #onMeasure(int, int)} is a valid use. + *

+ * + *

+ * The base class implementation of measure defaults to the background size, + * unless a larger size is allowed by the MeasureSpec. Subclasses should + * override {@link #onMeasure(int, int)} to provide better measurements of + * their content. + *

+ * + *

+ * If this method is overridden, it is the subclass's responsibility to make + * sure the measured height and width are at least the view's minimum height + * and width ({@link #getSuggestedMinimumHeight()} and + * {@link #getSuggestedMinimumWidth()}). + *

+ * + * @param widthMeasureSpec horizontal space requirements as imposed by the parent. + * The requirements are encoded with + * {@link android.view.View.MeasureSpec}. + * @param heightMeasureSpec vertical space requirements as imposed by the parent. + * The requirements are encoded with + * {@link android.view.View.MeasureSpec}. + * + * @see #getMeasuredWidth() + * @see #getMeasuredHeight() + * @see #setMeasuredDimension(int, int) + * @see #getSuggestedMinimumHeight() + * @see #getSuggestedMinimumWidth() + * @see android.view.View.MeasureSpec#getMode(int) + * @see android.view.View.MeasureSpec#getSize(int) + */ + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), + getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec)); + } + /** + *

This mehod must be called by {@link #onMeasure(int, int)} to store the + * measured width and measured height. Failing to do so will trigger an + * exception at measurement time.

+ * + * @param measuredWidth The measured width of this view. May be a complex + * bit mask as defined by {@link #MEASURED_SIZE_MASK} and + * {@link #MEASURED_STATE_TOO_SMALL}. + * @param measuredHeight The measured height of this view. May be a complex + * bit mask as defined by {@link #MEASURED_SIZE_MASK} and + * {@link #MEASURED_STATE_TOO_SMALL}. + */ + protected final void setMeasuredDimension(int measuredWidth, int measuredHeight) { + mMeasuredWidth = measuredWidth; + mMeasuredHeight = measuredHeight; + mPrivateFlags |= MEASURED_DIMENSION_SET; + } + /** + * Merge two states as returned by {@link #getMeasuredState()}. + * @param curState The current state as returned from a view or the result + * of combining multiple views. + * @param newState The new view state to combine. + * @return Returns a new integer reflecting the combination of the two + * states. + */ + public static int combineMeasuredStates(int curState, int newState) { + return curState | newState; + } + /** + * Version of {@link #resolveSizeAndState(int, int, int)} + * returning only the {@link #MEASURED_SIZE_MASK} bits of the result. + */ + public static int resolveSize(int size, int measureSpec) { + return resolveSizeAndState(size, measureSpec, 0) & MEASURED_SIZE_MASK; + } + /** + * Utility to reconcile a desired size and state, with constraints imposed + * by a MeasureSpec. Will take the desired size, unless a different size + * is imposed by the constraints. The returned value is a compound integer, + * with the resolved size in the {@link #MEASURED_SIZE_MASK} bits and + * optionally the bit {@link #MEASURED_STATE_TOO_SMALL} set if the resulting + * size is smaller than the size the view wants to be. + * + * @param size How big the view wants to be + * @param measureSpec Constraints imposed by the parent + * @return Size information bit mask as defined by + * {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. + */ + public static int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) { + int result = size; + int specMode = MeasureSpec.getMode(measureSpec); + int specSize = MeasureSpec.getSize(measureSpec); + switch (specMode) { + case MeasureSpec.UNSPECIFIED: + result = size; + break; + case MeasureSpec.AT_MOST: + if (specSize < size) { + result = specSize | MEASURED_STATE_TOO_SMALL; + } else { + result = size; + } + break; + case MeasureSpec.EXACTLY: + result = specSize; + break; + } + return result | (childMeasuredState&MEASURED_STATE_MASK); + } + /** + * Utility to return a default size. Uses the supplied size if the + * MeasureSpec imposed no constraints. Will get larger if allowed + * by the MeasureSpec. + * + * @param size Default size for this view + * @param measureSpec Constraints imposed by the parent + * @return The size this view should be. + */ + public static int getDefaultSize(int size, int measureSpec) { + int result = size; + int specMode = MeasureSpec.getMode(measureSpec); + int specSize = MeasureSpec.getSize(measureSpec); + switch (specMode) { + case MeasureSpec.UNSPECIFIED: + result = size; + break; + case MeasureSpec.AT_MOST: + case MeasureSpec.EXACTLY: + result = specSize; + break; + } + return result; + } + /** + * Returns the suggested minimum height that the view should use. This + * returns the maximum of the view's minimum height + * and the background's minimum height + * ({@link android.graphics.drawable.Drawable#getMinimumHeight()}). + *

+ * When being used in {@link #onMeasure(int, int)}, the caller should still + * ensure the returned height is within the requirements of the parent. + * + * @return The suggested minimum height of the view. + */ + protected int getSuggestedMinimumHeight() { + int suggestedMinHeight = mMinHeight; + if (mBGDrawable != null) { + final int bgMinHeight = mBGDrawable.getMinimumHeight(); + if (suggestedMinHeight < bgMinHeight) { + suggestedMinHeight = bgMinHeight; + } + } + return suggestedMinHeight; + } + /** + * Returns the suggested minimum width that the view should use. This + * returns the maximum of the view's minimum width) + * and the background's minimum width + * ({@link android.graphics.drawable.Drawable#getMinimumWidth()}). + *

+ * When being used in {@link #onMeasure(int, int)}, the caller should still + * ensure the returned width is within the requirements of the parent. + * + * @return The suggested minimum width of the view. + */ + protected int getSuggestedMinimumWidth() { + int suggestedMinWidth = mMinWidth; + if (mBGDrawable != null) { + final int bgMinWidth = mBGDrawable.getMinimumWidth(); + if (suggestedMinWidth < bgMinWidth) { + suggestedMinWidth = bgMinWidth; + } + } + return suggestedMinWidth; + } + /** + * Sets the minimum height of the view. It is not guaranteed the view will + * be able to achieve this minimum height (for example, if its parent layout + * constrains it with less available height). + * + * @param minHeight The minimum height the view will try to be. + */ + public void setMinimumHeight(int minHeight) { + mMinHeight = minHeight; + } + /** + * Sets the minimum width of the view. It is not guaranteed the view will + * be able to achieve this minimum width (for example, if its parent layout + * constrains it with less available width). + * + * @param minWidth The minimum width the view will try to be. + */ + public void setMinimumWidth(int minWidth) { + mMinWidth = minWidth; + } + /** + * Get the animation currently associated with this view. + * + * @return The animation that is currently playing or + * scheduled to play for this view. + */ + public Animation getAnimation() { + return mCurrentAnimation; + } + /** + * Start the specified animation now. + * + * @param animation the animation to start now + */ + public void startAnimation(Animation animation) { + animation.setStartTime(Animation.START_ON_FIRST_FRAME); + setAnimation(animation); + invalidateParentCaches(); + invalidate(true); + } + /** + * Cancels any animations for this view. + */ + public void clearAnimation() { + if (mCurrentAnimation != null) { + mCurrentAnimation.detach(); + } + mCurrentAnimation = null; + invalidateParentIfNeeded(); + } + /** + * Sets the next animation to play for this view. + * If you want the animation to play immediately, use + * startAnimation. This method provides allows fine-grained + * control over the start time and invalidation, but you + * must make sure that 1) the animation has a start time set, and + * 2) the view will be invalidated when the animation is supposed to + * start. + * + * @param animation The next animation, or null. + */ + public void setAnimation(Animation animation) { + mCurrentAnimation = animation; + if (animation != null) { + animation.reset(); + } + } + /** + * Invoked by a parent ViewGroup to notify the start of the animation + * currently associated with this view. If you override this method, + * always call super.onAnimationStart(); + * + * @see #setAnimation(android.view.animation.Animation) + * @see #getAnimation() + */ + protected void onAnimationStart() { + mPrivateFlags |= ANIMATION_STARTED; + } + /** + * Invoked by a parent ViewGroup to notify the end of the animation + * currently associated with this view. If you override this method, + * always call super.onAnimationEnd(); + * + * @see #setAnimation(android.view.animation.Animation) + * @see #getAnimation() + */ + protected void onAnimationEnd() { + mPrivateFlags &= ~ANIMATION_STARTED; + } + /** + * Invoked if there is a Transform that involves alpha. Subclass that can + * draw themselves with the specified alpha should return true, and then + * respect that alpha when their onDraw() is called. If this returns false + * then the view may be redirected to draw into an offscreen buffer to + * fulfill the request, which will look fine, but may be slower than if the + * subclass handles it internally. The default implementation returns false. + * + * @param alpha The alpha (0..255) to apply to the view's drawing + * @return true if the view can draw with the specified alpha. + */ + protected boolean onSetAlpha(int alpha) { + return false; + } + /** + * This is used by the RootView to perform an optimization when + * the view hierarchy contains one or several SurfaceView. + * SurfaceView is always considered transparent, but its children are not, + * therefore all View objects remove themselves from the global transparent + * region (passed as a parameter to this function). + * + * @param region The transparent region for this ViewAncestor (window). + * + * @return Returns true if the effective visibility of the view at this + * point is opaque, regardless of the transparent region; returns false + * if it is possible for underlying windows to be seen behind the view. + * + * {@hide} + */ + public boolean gatherTransparentRegion(Region region) { + final AttachInfo attachInfo = mAttachInfo; + if (region != null && attachInfo != null) { + final int pflags = mPrivateFlags; + if ((pflags & SKIP_DRAW) == 0) { + // The SKIP_DRAW flag IS NOT set, so this view draws. We need to + // remove it from the transparent region. + final int[] location = attachInfo.mTransparentLocation; + getLocationInWindow(location); + region.op(location[0], location[1], location[0] + mRight - mLeft, + location[1] + mBottom - mTop, Region.Op.DIFFERENCE); + } else if ((pflags & ONLY_DRAWS_BACKGROUND) != 0 && mBGDrawable != null) { + // The ONLY_DRAWS_BACKGROUND flag IS set and the background drawable + // exists, so we remove the background drawable's non-transparent + // parts from this transparent region. + applyDrawableToTransparentRegion(mBGDrawable, region); + } + } + return true; + } + /** + * Play a sound effect for this view. + * + *

The framework will play sound effects for some built in actions, such as + * clicking, but you may wish to play these effects in your widget, + * for instance, for internal navigation. + * + *

The sound effect will only be played if sound effects are enabled by the user, and + * {@link #isSoundEffectsEnabled()} is true. + * + * @param soundConstant One of the constants defined in {@link SoundEffectConstants} + */ + public void playSoundEffect(int soundConstant) { + if (mAttachInfo == null || mAttachInfo.mRootCallbacks == null || !isSoundEffectsEnabled()) { + return; + } + mAttachInfo.mRootCallbacks.playSoundEffect(soundConstant); + } + /** + * BZZZTT!!1! + * + *

Provide haptic feedback to the user for this view. + * + *

The framework will provide haptic feedback for some built in actions, + * such as long presses, but you may wish to provide feedback for your + * own widget. + * + *

The feedback will only be performed if + * {@link #isHapticFeedbackEnabled()} is true. + * + * @param feedbackConstant One of the constants defined in + * {@link HapticFeedbackConstants} + */ + public boolean performHapticFeedback(int feedbackConstant) { + return performHapticFeedback(feedbackConstant, 0); + } + /** + * BZZZTT!!1! + * + *

Like {@link #performHapticFeedback(int)}, with additional options. + * + * @param feedbackConstant One of the constants defined in + * {@link HapticFeedbackConstants} + * @param flags Additional flags as per {@link HapticFeedbackConstants}. + */ + public boolean performHapticFeedback(int feedbackConstant, int flags) { + if (mAttachInfo == null) { + return false; + } + //noinspection SimplifiableIfStatement + if ((flags & HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING) == 0 + && !isHapticFeedbackEnabled()) { + return false; + } + return mAttachInfo.mRootCallbacks.performHapticFeedback(feedbackConstant, + (flags & HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING) != 0); + } + /** + * Request that the visibility of the status bar be changed. + * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or + * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. + */ + public void setSystemUiVisibility(int visibility) { + if (visibility != mSystemUiVisibility) { + mSystemUiVisibility = visibility; + if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { + mParent.recomputeViewAttributes(this); + } + } + } + /** + * Returns the status bar visibility that this view has requested. + * @return Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or + * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. + */ + public int getSystemUiVisibility() { + return mSystemUiVisibility; + } + /** + * Set a listener to receive callbacks when the visibility of the system bar changes. + * @param l The {@link OnSystemUiVisibilityChangeListener} to receive callbacks. + */ + public void setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener l) { + getListenerInfo().mOnSystemUiVisibilityChangeListener = l; + if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { + mParent.recomputeViewAttributes(this); + } + } + /** + * Dispatch callbacks to {@link #setOnSystemUiVisibilityChangeListener} down + * the view hierarchy. + */ + public void dispatchSystemUiVisibilityChanged(int visibility) { + ListenerInfo li = mListenerInfo; + if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { + li.mOnSystemUiVisibilityChangeListener.onSystemUiVisibilityChange( + visibility & PUBLIC_STATUS_BAR_VISIBILITY_MASK); + } + } + void updateLocalSystemUiVisibility(int localValue, int localChanges) { + int val = (mSystemUiVisibility&~localChanges) | (localValue&localChanges); + if (val != mSystemUiVisibility) { + setSystemUiVisibility(val); + } + } + /** + * Creates an image that the system displays during the drag and drop + * operation. This is called a "drag shadow". The default implementation + * for a DragShadowBuilder based on a View returns an image that has exactly the same + * appearance as the given View. The default also positions the center of the drag shadow + * directly under the touch point. If no View is provided (the constructor with no parameters + * is used), and {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} and + * {@link #onDrawShadow(Canvas) onDrawShadow()} are not overriden, then the + * default is an invisible drag shadow. + *

+ * You are not required to use the View you provide to the constructor as the basis of the + * drag shadow. The {@link #onDrawShadow(Canvas) onDrawShadow()} method allows you to draw + * anything you want as the drag shadow. + *

+ *

+ * You pass a DragShadowBuilder object to the system when you start the drag. The system + * calls {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} to get the + * size and position of the drag shadow. It uses this data to construct a + * {@link android.graphics.Canvas} object, then it calls {@link #onDrawShadow(Canvas) onDrawShadow()} + * so that your application can draw the shadow image in the Canvas. + *

+ * + *
+ *

Developer Guides

+ *

For a guide to implementing drag and drop features, read the + * Drag and Drop developer guide.

+ *
+ */ + public static class DragShadowBuilder { + private final WeakReference mView; + /** + * Constructs a shadow image builder based on a View. By default, the resulting drag + * shadow will have the same appearance and dimensions as the View, with the touch point + * over the center of the View. + * @param view A View. Any View in scope can be used. + */ + public DragShadowBuilder(View view) { + mView = new WeakReference(view); + } + /** + * Construct a shadow builder object with no associated View. This + * constructor variant is only useful when the {@link #onProvideShadowMetrics(Point, Point)} + * and {@link #onDrawShadow(Canvas)} methods are also overridden in order + * to supply the drag shadow's dimensions and appearance without + * reference to any View object. If they are not overridden, then the result is an + * invisible drag shadow. + */ + public DragShadowBuilder() { + mView = new WeakReference(null); + } + /** + * Returns the View object that had been passed to the + * {@link #View.DragShadowBuilder(View)} + * constructor. If that View parameter was {@code null} or if the + * {@link #View.DragShadowBuilder()} + * constructor was used to instantiate the builder object, this method will return + * null. + * + * @return The View object associate with this builder object. + */ + @SuppressWarnings({"JavadocReference"}) + final public View getView() { + return mView.get(); + } + /** + * Provides the metrics for the shadow image. These include the dimensions of + * the shadow image, and the point within that shadow that should + * be centered under the touch location while dragging. + *

+ * The default implementation sets the dimensions of the shadow to be the + * same as the dimensions of the View itself and centers the shadow under + * the touch point. + *

+ * + * @param shadowSize A {@link android.graphics.Point} containing the width and height + * of the shadow image. Your application must set {@link android.graphics.Point#x} to the + * desired width and must set {@link android.graphics.Point#y} to the desired height of the + * image. + * + * @param shadowTouchPoint A {@link android.graphics.Point} for the position within the + * shadow image that should be underneath the touch point during the drag and drop + * operation. Your application must set {@link android.graphics.Point#x} to the + * X coordinate and {@link android.graphics.Point#y} to the Y coordinate of this position. + */ + public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { + final View view = mView.get(); + if (view != null) { + shadowSize.set(view.getWidth(), view.getHeight()); + shadowTouchPoint.set(shadowSize.x / 2, shadowSize.y / 2); + } else { + Log.e(View.VIEW_LOG_TAG, "Asked for drag thumb metrics but no view"); + } + } + /** + * Draws the shadow image. The system creates the {@link android.graphics.Canvas} object + * based on the dimensions it received from the + * {@link #onProvideShadowMetrics(Point, Point)} callback. + * + * @param canvas A {@link android.graphics.Canvas} object in which to draw the shadow image. + */ + public void onDrawShadow(Canvas canvas) { + final View view = mView.get(); + if (view != null) { + view.draw(canvas); + } else { + Log.e(View.VIEW_LOG_TAG, "Asked to draw drag shadow but no view"); + } + } + } + /** + * Starts a drag and drop operation. When your application calls this method, it passes a + * {@link android.view.View.DragShadowBuilder} object to the system. The + * system calls this object's {@link DragShadowBuilder#onProvideShadowMetrics(Point, Point)} + * to get metrics for the drag shadow, and then calls the object's + * {@link DragShadowBuilder#onDrawShadow(Canvas)} to draw the drag shadow itself. + *

+ * Once the system has the drag shadow, it begins the drag and drop operation by sending + * drag events to all the View objects in your application that are currently visible. It does + * this either by calling the View object's drag listener (an implementation of + * {@link android.view.View.OnDragListener#onDrag(View,DragEvent) onDrag()} or by calling the + * View object's {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} method. + * Both are passed a {@link android.view.DragEvent} object that has a + * {@link android.view.DragEvent#getAction()} value of + * {@link android.view.DragEvent#ACTION_DRAG_STARTED}. + *

+ *

+ * Your application can invoke startDrag() on any attached View object. The View object does not + * need to be the one used in {@link android.view.View.DragShadowBuilder}, nor does it need to + * be related to the View the user selected for dragging. + *

+ * @param data A {@link android.content.ClipData} object pointing to the data to be + * transferred by the drag and drop operation. + * @param shadowBuilder A {@link android.view.View.DragShadowBuilder} object for building the + * drag shadow. + * @param myLocalState An {@link java.lang.Object} containing local data about the drag and + * drop operation. This Object is put into every DragEvent object sent by the system during the + * current drag. + *

+ * myLocalState is a lightweight mechanism for the sending information from the dragged View + * to the target Views. For example, it can contain flags that differentiate between a + * a copy operation and a move operation. + *

+ * @param flags Flags that control the drag and drop operation. No flags are currently defined, + * so the parameter should be set to 0. + * @return {@code true} if the method completes successfully, or + * {@code false} if it fails anywhere. Returning {@code false} means the system was unable to + * do a drag, and so no drag operation is in progress. + */ + public final boolean startDrag(ClipData data, DragShadowBuilder shadowBuilder, + Object myLocalState, int flags) { + if (ViewDebug.DEBUG_DRAG) { + Log.d(VIEW_LOG_TAG, "startDrag: data=" + data + " flags=" + flags); + } + boolean okay = false; + Point shadowSize = new Point(); + Point shadowTouchPoint = new Point(); + shadowBuilder.onProvideShadowMetrics(shadowSize, shadowTouchPoint); + if ((shadowSize.x < 0) || (shadowSize.y < 0) || + (shadowTouchPoint.x < 0) || (shadowTouchPoint.y < 0)) { + throw new IllegalStateException("Drag shadow dimensions must not be negative"); + } + if (ViewDebug.DEBUG_DRAG) { + Log.d(VIEW_LOG_TAG, "drag shadow: width=" + shadowSize.x + " height=" + shadowSize.y + + " shadowX=" + shadowTouchPoint.x + " shadowY=" + shadowTouchPoint.y); + } + Surface surface = new Surface(); + try { + IBinder token = mAttachInfo.mSession.prepareDrag(mAttachInfo.mWindow, + flags, shadowSize.x, shadowSize.y, surface); + if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "prepareDrag returned token=" + token + + " surface=" + surface); + if (token != null) { + Canvas canvas = surface.lockCanvas(null); + try { + canvas.drawColor(0, PorterDuff.Mode.CLEAR); + shadowBuilder.onDrawShadow(canvas); + } finally { + surface.unlockCanvasAndPost(canvas); + } + final ViewRootImpl root = getViewRootImpl(); + // Cache the local state object for delivery with DragEvents + root.setLocalDragState(myLocalState); + // repurpose 'shadowSize' for the last touch point + root.getLastTouchPoint(shadowSize); + okay = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, token, + shadowSize.x, shadowSize.y, + shadowTouchPoint.x, shadowTouchPoint.y, data); + if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "performDrag returned " + okay); + // Off and running! Release our local surface instance; the drag + // shadow surface is now managed by the system process. + surface.release(); + } + } catch (Exception e) { + Log.e(VIEW_LOG_TAG, "Unable to initiate drag", e); + surface.destroy(); + } + return okay; + } + /** + * Handles drag events sent by the system following a call to + * {@link android.view.View#startDrag(ClipData,DragShadowBuilder,Object,int) startDrag()}. + *

+ * When the system calls this method, it passes a + * {@link android.view.DragEvent} object. A call to + * {@link android.view.DragEvent#getAction()} returns one of the action type constants defined + * in DragEvent. The method uses these to determine what is happening in the drag and drop + * operation. + * @param event The {@link android.view.DragEvent} sent by the system. + * The {@link android.view.DragEvent#getAction()} method returns an action type constant defined + * in DragEvent, indicating the type of drag event represented by this object. + * @return {@code true} if the method was successful, otherwise {@code false}. + *

+ * The method should return {@code true} in response to an action type of + * {@link android.view.DragEvent#ACTION_DRAG_STARTED} to receive drag events for the current + * operation. + *

+ *

+ * The method should also return {@code true} in response to an action type of + * {@link android.view.DragEvent#ACTION_DROP} if it consumed the drop, or + * {@code false} if it didn't. + *

+ */ + public boolean onDragEvent(DragEvent event) { + return false; + } + /** + * Detects if this View is enabled and has a drag event listener. + * If both are true, then it calls the drag event listener with the + * {@link android.view.DragEvent} it received. If the drag event listener returns + * {@code true}, then dispatchDragEvent() returns {@code true}. + *

+ * For all other cases, the method calls the + * {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} drag event handler + * method and returns its result. + *

+ *

+ * This ensures that a drag event is always consumed, even if the View does not have a drag + * event listener. However, if the View has a listener and the listener returns true, then + * onDragEvent() is not called. + *

+ */ + public boolean dispatchDragEvent(DragEvent event) { + //noinspection SimplifiableIfStatement + ListenerInfo li = mListenerInfo; + if (li != null && li.mOnDragListener != null && (mViewFlags & ENABLED_MASK) == ENABLED + && li.mOnDragListener.onDrag(this, event)) { + return true; + } + return onDragEvent(event); + } + boolean canAcceptDrag() { + return (mPrivateFlags2 & DRAG_CAN_ACCEPT) != 0; + } + /** + * This needs to be a better API (NOT ON VIEW) before it is exposed. If + * it is ever exposed at all. + * @hide + */ + public void onCloseSystemDialogs(String reason) { + } + /** + * Given a Drawable whose bounds have been set to draw into this view, + * update a Region being computed for + * {@link #gatherTransparentRegion(android.graphics.Region)} so + * that any non-transparent parts of the Drawable are removed from the + * given transparent region. + * + * @param dr The Drawable whose transparency is to be applied to the region. + * @param region A Region holding the current transparency information, + * where any parts of the region that are set are considered to be + * transparent. On return, this region will be modified to have the + * transparency information reduced by the corresponding parts of the + * Drawable that are not transparent. + * {@hide} + */ + public void applyDrawableToTransparentRegion(Drawable dr, Region region) { + if (DBG) { + Log.i("View", "Getting transparent region for: " + this); + } + final Region r = dr.getTransparentRegion(); + final Rect db = dr.getBounds(); + final AttachInfo attachInfo = mAttachInfo; + if (r != null && attachInfo != null) { + final int w = getRight()-getLeft(); + final int h = getBottom()-getTop(); + if (db.left > 0) { + //Log.i("VIEW", "Drawable left " + db.left + " > view 0"); + r.op(0, 0, db.left, h, Region.Op.UNION); + } + if (db.right < w) { + //Log.i("VIEW", "Drawable right " + db.right + " < view " + w); + r.op(db.right, 0, w, h, Region.Op.UNION); + } + if (db.top > 0) { + //Log.i("VIEW", "Drawable top " + db.top + " > view 0"); + r.op(0, 0, w, db.top, Region.Op.UNION); + } + if (db.bottom < h) { + //Log.i("VIEW", "Drawable bottom " + db.bottom + " < view " + h); + r.op(0, db.bottom, w, h, Region.Op.UNION); + } + final int[] location = attachInfo.mTransparentLocation; + getLocationInWindow(location); + r.translate(location[0], location[1]); + region.op(r, Region.Op.INTERSECT); + } else { + region.op(db, Region.Op.DIFFERENCE); + } + } + private void checkForLongClick(int delayOffset) { + if ((mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) { + mHasPerformedLongPress = false; + if (mPendingCheckForLongPress == null) { + mPendingCheckForLongPress = new CheckForLongPress(); + } + mPendingCheckForLongPress.rememberWindowAttachCount(); + postDelayed(mPendingCheckForLongPress, + ViewConfiguration.getLongPressTimeout() - delayOffset); + } + } + /** + * Inflate a view from an XML resource. This convenience method wraps the {@link + * LayoutInflater} class, which provides a full range of options for view inflation. + * + * @param context The Context object for your activity or application. + * @param resource The resource ID to inflate + * @param root A view group that will be the parent. Used to properly inflate the + * layout_* parameters. + * @see LayoutInflater + */ + public static View inflate(Context context, int resource, ViewGroup root) { + LayoutInflater factory = LayoutInflater.from(context); + return factory.inflate(resource, root); + } + /** + * Scroll the view with standard behavior for scrolling beyond the normal + * content boundaries. Views that call this method should override + * {@link #onOverScrolled(int, int, boolean, boolean)} to respond to the + * results of an over-scroll operation. + * + * Views can use this method to handle any touch or fling-based scrolling. + * + * @param deltaX Change in X in pixels + * @param deltaY Change in Y in pixels + * @param scrollX Current X scroll value in pixels before applying deltaX + * @param scrollY Current Y scroll value in pixels before applying deltaY + * @param scrollRangeX Maximum content scroll range along the X axis + * @param scrollRangeY Maximum content scroll range along the Y axis + * @param maxOverScrollX Number of pixels to overscroll by in either direction + * along the X axis. + * @param maxOverScrollY Number of pixels to overscroll by in either direction + * along the Y axis. + * @param isTouchEvent true if this scroll operation is the result of a touch event. + * @return true if scrolling was clamped to an over-scroll boundary along either + * axis, false otherwise. + */ + @SuppressWarnings({"UnusedParameters"}) + protected boolean overScrollBy(int deltaX, int deltaY, + int scrollX, int scrollY, + int scrollRangeX, int scrollRangeY, + int maxOverScrollX, int maxOverScrollY, + boolean isTouchEvent) { + final int overScrollMode = mOverScrollMode; + final boolean canScrollHorizontal = + computeHorizontalScrollRange() > computeHorizontalScrollExtent(); + final boolean canScrollVertical = + computeVerticalScrollRange() > computeVerticalScrollExtent(); + final boolean overScrollHorizontal = overScrollMode == OVER_SCROLL_ALWAYS || + (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollHorizontal); + final boolean overScrollVertical = overScrollMode == OVER_SCROLL_ALWAYS || + (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollVertical); + int newScrollX = scrollX + deltaX; + if (!overScrollHorizontal) { + maxOverScrollX = 0; + } + int newScrollY = scrollY + deltaY; + if (!overScrollVertical) { + maxOverScrollY = 0; + } + // Clamp values if at the limits and record + final int left = -maxOverScrollX; + final int right = maxOverScrollX + scrollRangeX; + final int top = -maxOverScrollY; + final int bottom = maxOverScrollY + scrollRangeY; + boolean clampedX = false; + if (newScrollX > right) { + newScrollX = right; + clampedX = true; + } else if (newScrollX < left) { + newScrollX = left; + clampedX = true; + } + boolean clampedY = false; + if (newScrollY > bottom) { + newScrollY = bottom; + clampedY = true; + } else if (newScrollY < top) { + newScrollY = top; + clampedY = true; + } + onOverScrolled(newScrollX, newScrollY, clampedX, clampedY); + return clampedX || clampedY; + } + /** + * Called by {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)} to + * respond to the results of an over-scroll operation. + * + * @param scrollX New X scroll value in pixels + * @param scrollY New Y scroll value in pixels + * @param clampedX True if scrollX was clamped to an over-scroll boundary + * @param clampedY True if scrollY was clamped to an over-scroll boundary + */ + protected void onOverScrolled(int scrollX, int scrollY, + boolean clampedX, boolean clampedY) { + // Intentionally empty. + } + /** + * Returns the over-scroll mode for this view. The result will be + * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} + * (allow over-scrolling only if the view content is larger than the container), + * or {@link #OVER_SCROLL_NEVER}. + * + * @return This view's over-scroll mode. + */ + public int getOverScrollMode() { + return mOverScrollMode; + } + /** + * Set the over-scroll mode for this view. Valid over-scroll modes are + * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} + * (allow over-scrolling only if the view content is larger than the container), + * or {@link #OVER_SCROLL_NEVER}. + * + * Setting the over-scroll mode of a view will have an effect only if the + * view is capable of scrolling. + * + * @param overScrollMode The new over-scroll mode for this view. + */ + public void setOverScrollMode(int overScrollMode) { + if (overScrollMode != OVER_SCROLL_ALWAYS && + overScrollMode != OVER_SCROLL_IF_CONTENT_SCROLLS && + overScrollMode != OVER_SCROLL_NEVER) { + throw new IllegalArgumentException("Invalid overscroll mode " + overScrollMode); + } + mOverScrollMode = overScrollMode; + } + /** + * Gets a scale factor that determines the distance the view should scroll + * vertically in response to {@link MotionEvent#ACTION_SCROLL}. + * @return The vertical scroll scale factor. + * @hide + */ + protected float getVerticalScrollFactor() { + if (mVerticalScrollFactor == 0) { + TypedValue outValue = new TypedValue(); + if (!mContext.getTheme().resolveAttribute( + com.android.internal.R.attr.listPreferredItemHeight, outValue, true)) { + throw new IllegalStateException( + "Expected theme to define listPreferredItemHeight."); + } + mVerticalScrollFactor = outValue.getDimension( + mContext.getResources().getDisplayMetrics()); + } + return mVerticalScrollFactor; + } + /** + * Gets a scale factor that determines the distance the view should scroll + * horizontally in response to {@link MotionEvent#ACTION_SCROLL}. + * @return The horizontal scroll scale factor. + * @hide + */ + protected float getHorizontalScrollFactor() { + // TODO: Should use something else. + return getVerticalScrollFactor(); + } + /** + * Return the value specifying the text direction or policy that was set with + * {@link #setTextDirection(int)}. + * + * @return the defined text direction. It can be one of: + * + * {@link #TEXT_DIRECTION_INHERIT}, + * {@link #TEXT_DIRECTION_FIRST_STRONG} + * {@link #TEXT_DIRECTION_ANY_RTL}, + * {@link #TEXT_DIRECTION_LTR}, + * {@link #TEXT_DIRECTION_RTL}, + * {@link #TEXT_DIRECTION_LOCALE}, + * + */ + public int getTextDirection() { + return mTextDirection; + } + /** + * Set the text direction. + * + * @param textDirection the direction to set. Should be one of: + * + * {@link #TEXT_DIRECTION_INHERIT}, + * {@link #TEXT_DIRECTION_FIRST_STRONG} + * {@link #TEXT_DIRECTION_ANY_RTL}, + * {@link #TEXT_DIRECTION_LTR}, + * {@link #TEXT_DIRECTION_RTL}, + * {@link #TEXT_DIRECTION_LOCALE}, + * + */ + public void setTextDirection(int textDirection) { + if (textDirection != mTextDirection) { + mTextDirection = textDirection; + resetResolvedTextDirection(); + requestLayout(); + } + } + /** + * Return the resolved text direction. + * + * @return the resolved text direction. Return one of: + * + * {@link #TEXT_DIRECTION_FIRST_STRONG} + * {@link #TEXT_DIRECTION_ANY_RTL}, + * {@link #TEXT_DIRECTION_LTR}, + * {@link #TEXT_DIRECTION_RTL}, + * {@link #TEXT_DIRECTION_LOCALE}, + * + */ + public int getResolvedTextDirection() { + if (mResolvedTextDirection == TEXT_DIRECTION_INHERIT) { + resolveTextDirection(); + } + return mResolvedTextDirection; + } + /** + * Resolve the text direction. + * + */ + protected void resolveTextDirection() { + if (mTextDirection != TEXT_DIRECTION_INHERIT) { + mResolvedTextDirection = mTextDirection; + return; + } + if (mParent != null && mParent instanceof ViewGroup) { + mResolvedTextDirection = ((ViewGroup) mParent).getResolvedTextDirection(); + return; + } + mResolvedTextDirection = TEXT_DIRECTION_FIRST_STRONG; + } + /** + * Reset resolved text direction. Will be resolved during a call to getResolvedTextDirection(). + * + */ + protected void resetResolvedTextDirection() { + mResolvedTextDirection = TEXT_DIRECTION_INHERIT; + } + // + // Properties + // + /** + * A Property wrapper around the alpha functionality handled by the + * {@link View#setAlpha(float)} and {@link View#getAlpha()} methods. + */ + public static final Property ALPHA = new FloatProperty("alpha") { + @Override + public void setValue(View object, float value) { + object.setAlpha(value); + } + @Override + public Float get(View object) { + return object.getAlpha(); + } + }; + /** + * A Property wrapper around the translationX functionality handled by the + * {@link View#setTranslationX(float)} and {@link View#getTranslationX()} methods. + */ + public static final Property TRANSLATION_X = new FloatProperty("translationX") { + @Override + public void setValue(View object, float value) { + object.setTranslationX(value); + } + @Override + public Float get(View object) { + return object.getTranslationX(); + } + }; + /** + * A Property wrapper around the translationY functionality handled by the + * {@link View#setTranslationY(float)} and {@link View#getTranslationY()} methods. + */ + public static final Property TRANSLATION_Y = new FloatProperty("translationY") { + @Override + public void setValue(View object, float value) { + object.setTranslationY(value); + } + @Override + public Float get(View object) { + return object.getTranslationY(); + } + }; + /** + * A Property wrapper around the x functionality handled by the + * {@link View#setX(float)} and {@link View#getX()} methods. + */ + public static final Property X = new FloatProperty("x") { + @Override + public void setValue(View object, float value) { + object.setX(value); + } + @Override + public Float get(View object) { + return object.getX(); + } + }; + /** + * A Property wrapper around the y functionality handled by the + * {@link View#setY(float)} and {@link View#getY()} methods. + */ + public static final Property Y = new FloatProperty("y") { + @Override + public void setValue(View object, float value) { + object.setY(value); + } + @Override + public Float get(View object) { + return object.getY(); + } + }; + /** + * A Property wrapper around the rotation functionality handled by the + * {@link View#setRotation(float)} and {@link View#getRotation()} methods. + */ + public static final Property ROTATION = new FloatProperty("rotation") { + @Override + public void setValue(View object, float value) { + object.setRotation(value); + } + @Override + public Float get(View object) { + return object.getRotation(); + } + }; + /** + * A Property wrapper around the rotationX functionality handled by the + * {@link View#setRotationX(float)} and {@link View#getRotationX()} methods. + */ + public static final Property ROTATION_X = new FloatProperty("rotationX") { + @Override + public void setValue(View object, float value) { + object.setRotationX(value); + } + @Override + public Float get(View object) { + return object.getRotationX(); + } + }; + /** + * A Property wrapper around the rotationY functionality handled by the + * {@link View#setRotationY(float)} and {@link View#getRotationY()} methods. + */ + public static final Property ROTATION_Y = new FloatProperty("rotationY") { + @Override + public void setValue(View object, float value) { + object.setRotationY(value); + } + @Override + public Float get(View object) { + return object.getRotationY(); + } + }; + /** + * A Property wrapper around the scaleX functionality handled by the + * {@link View#setScaleX(float)} and {@link View#getScaleX()} methods. + */ + public static final Property SCALE_X = new FloatProperty("scaleX") { + @Override + public void setValue(View object, float value) { + object.setScaleX(value); + } + @Override + public Float get(View object) { + return object.getScaleX(); + } + }; + /** + * A Property wrapper around the scaleY functionality handled by the + * {@link View#setScaleY(float)} and {@link View#getScaleY()} methods. + */ + public static final Property SCALE_Y = new FloatProperty("scaleY") { + @Override + public void setValue(View object, float value) { + object.setScaleY(value); + } + @Override + public Float get(View object) { + return object.getScaleY(); + } + }; + /** + * A MeasureSpec encapsulates the layout requirements passed from parent to child. + * Each MeasureSpec represents a requirement for either the width or the height. + * A MeasureSpec is comprised of a size and a mode. There are three possible + * modes: + *
+ *
UNSPECIFIED
+ *
+ * The parent has not imposed any constraint on the child. It can be whatever size + * it wants. + *
+ * + *
EXACTLY
+ *
+ * The parent has determined an exact size for the child. The child is going to be + * given those bounds regardless of how big it wants to be. + *
+ * + *
AT_MOST
+ *
+ * The child can be as large as it wants up to the specified size. + *
+ *
+ * + * MeasureSpecs are implemented as ints to reduce object allocation. This class + * is provided to pack and unpack the <size, mode> tuple into the int. + */ + public static class MeasureSpec { + private static final int MODE_SHIFT = 30; + private static final int MODE_MASK = 0x3 << MODE_SHIFT; + /** + * Measure specification mode: The parent has not imposed any constraint + * on the child. It can be whatever size it wants. + */ + public static final int UNSPECIFIED = 0 << MODE_SHIFT; + /** + * Measure specification mode: The parent has determined an exact size + * for the child. The child is going to be given those bounds regardless + * of how big it wants to be. + */ + public static final int EXACTLY = 1 << MODE_SHIFT; + /** + * Measure specification mode: The child can be as large as it wants up + * to the specified size. + */ + public static final int AT_MOST = 2 << MODE_SHIFT; + /** + * Creates a measure specification based on the supplied size and mode. + * + * The mode must always be one of the following: + *
    + *
  • {@link android.view.View.MeasureSpec#UNSPECIFIED}
  • + *
  • {@link android.view.View.MeasureSpec#EXACTLY}
  • + *
  • {@link android.view.View.MeasureSpec#AT_MOST}
  • + *
+ * + * @param size the size of the measure specification + * @param mode the mode of the measure specification + * @return the measure specification based on size and mode + */ + public static int makeMeasureSpec(int size, int mode) { + return size + mode; + } + /** + * Extracts the mode from the supplied measure specification. + * + * @param measureSpec the measure specification to extract the mode from + * @return {@link android.view.View.MeasureSpec#UNSPECIFIED}, + * {@link android.view.View.MeasureSpec#AT_MOST} or + * {@link android.view.View.MeasureSpec#EXACTLY} + */ + public static int getMode(int measureSpec) { + return (measureSpec & MODE_MASK); + } + /** + * Extracts the size from the supplied measure specification. + * + * @param measureSpec the measure specification to extract the size from + * @return the size in pixels defined in the supplied measure specification + */ + public static int getSize(int measureSpec) { + return (measureSpec & ~MODE_MASK); + } + /** + * Returns a String representation of the specified measure + * specification. + * + * @param measureSpec the measure specification to convert to a String + * @return a String with the following format: "MeasureSpec: MODE SIZE" + */ + public static String toString(int measureSpec) { + int mode = getMode(measureSpec); + int size = getSize(measureSpec); + StringBuilder sb = new StringBuilder("MeasureSpec: "); + if (mode == UNSPECIFIED) + sb.append("UNSPECIFIED "); + else if (mode == EXACTLY) + sb.append("EXACTLY "); + else if (mode == AT_MOST) + sb.append("AT_MOST "); + else + sb.append(mode).append(" "); + sb.append(size); + return sb.toString(); + } + } + class CheckForLongPress implements Runnable { + private int mOriginalWindowAttachCount; + public void run() { + if (isPressed() && (mParent != null) + && mOriginalWindowAttachCount == mWindowAttachCount) { + if (performLongClick()) { + mHasPerformedLongPress = true; + } + } + } + public void rememberWindowAttachCount() { + mOriginalWindowAttachCount = mWindowAttachCount; + } + } + private final class CheckForTap implements Runnable { + public void run() { + mPrivateFlags &= ~PREPRESSED; + mPrivateFlags |= PRESSED; + refreshDrawableState(); + checkForLongClick(ViewConfiguration.getTapTimeout()); + } + } + private final class PerformClick implements Runnable { + public void run() { + performClick(); + } + } + /** @hide */ + public void hackTurnOffWindowResizeAnim(boolean off) { + mAttachInfo.mTurnOffWindowResizeAnim = off; + } + /** + * This method returns a ViewPropertyAnimator object, which can be used to animate + * specific properties on this View. + * + * @return ViewPropertyAnimator The ViewPropertyAnimator associated with this View. + */ + public ViewPropertyAnimator animate() { + if (mAnimator == null) { + mAnimator = new ViewPropertyAnimator(this); + } + return mAnimator; + } + /** + * Interface definition for a callback to be invoked when a key event is + * dispatched to this view. The callback will be invoked before the key + * event is given to the view. + */ + public interface OnKeyListener { + /** + * Called when a key is dispatched to a view. This allows listeners to + * get a chance to respond before the target view. + * + * @param v The view the key has been dispatched to. + * @param keyCode The code for the physical key that was pressed + * @param event The KeyEvent object containing full information about + * the event. + * @return True if the listener has consumed the event, false otherwise. + */ + boolean onKey(View v, int keyCode, KeyEvent event); + } + /** + * Interface definition for a callback to be invoked when a touch event is + * dispatched to this view. The callback will be invoked before the touch + * event is given to the view. + */ + public interface OnTouchListener { + /** + * Called when a touch event is dispatched to a view. This allows listeners to + * get a chance to respond before the target view. + * + * @param v The view the touch event has been dispatched to. + * @param event The MotionEvent object containing full information about + * the event. + * @return True if the listener has consumed the event, false otherwise. + */ + boolean onTouch(View v, MotionEvent event); + } + /** + * Interface definition for a callback to be invoked when a hover event is + * dispatched to this view. The callback will be invoked before the hover + * event is given to the view. + */ + public interface OnHoverListener { + /** + * Called when a hover event is dispatched to a view. This allows listeners to + * get a chance to respond before the target view. + * + * @param v The view the hover event has been dispatched to. + * @param event The MotionEvent object containing full information about + * the event. + * @return True if the listener has consumed the event, false otherwise. + */ + boolean onHover(View v, MotionEvent event); + } + /** + * Interface definition for a callback to be invoked when a generic motion event is + * dispatched to this view. The callback will be invoked before the generic motion + * event is given to the view. + */ + public interface OnGenericMotionListener { + /** + * Called when a generic motion event is dispatched to a view. This allows listeners to + * get a chance to respond before the target view. + * + * @param v The view the generic motion event has been dispatched to. + * @param event The MotionEvent object containing full information about + * the event. + * @return True if the listener has consumed the event, false otherwise. + */ + boolean onGenericMotion(View v, MotionEvent event); + } + /** + * Interface definition for a callback to be invoked when a view has been clicked and held. + */ + public interface OnLongClickListener { + /** + * Called when a view has been clicked and held. + * + * @param v The view that was clicked and held. + * + * @return true if the callback consumed the long click, false otherwise. + */ + boolean onLongClick(View v); + } + /** + * Interface definition for a callback to be invoked when a drag is being dispatched + * to this view. The callback will be invoked before the hosting view's own + * onDrag(event) method. If the listener wants to fall back to the hosting view's + * onDrag(event) behavior, it should return 'false' from this callback. + * + *
+ *

Developer Guides

+ *

For a guide to implementing drag and drop features, read the + * Drag and Drop developer guide.

+ *
+ */ + public interface OnDragListener { + /** + * Called when a drag event is dispatched to a view. This allows listeners + * to get a chance to override base View behavior. + * + * @param v The View that received the drag event. + * @param event The {@link android.view.DragEvent} object for the drag event. + * @return {@code true} if the drag event was handled successfully, or {@code false} + * if the drag event was not handled. Note that {@code false} will trigger the View + * to call its {@link #onDragEvent(DragEvent) onDragEvent()} handler. + */ + boolean onDrag(View v, DragEvent event); + } + /** + * Interface definition for a callback to be invoked when the focus state of + * a view changed. + */ + public interface OnFocusChangeListener { + /** + * Called when the focus state of a view has changed. + * + * @param v The view whose state has changed. + * @param hasFocus The new focus state of v. + */ + void onFocusChange(View v, boolean hasFocus); + } + /** + * Interface definition for a callback to be invoked when a view is clicked. + */ + public interface OnClickListener { + /** + * Called when a view has been clicked. + * + * @param v The view that was clicked. + */ + void onClick(View v); + } + /** + * Interface definition for a callback to be invoked when the context menu + * for this view is being built. + */ + public interface OnCreateContextMenuListener { + /** + * Called when the context menu for this view is being built. It is not + * safe to hold onto the menu after this method returns. + * + * @param menu The context menu that is being built + * @param v The view for which the context menu is being built + * @param menuInfo Extra information about the item for which the + * context menu should be shown. This information will vary + * depending on the class of v. + */ + void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo); + } + /** + * Interface definition for a callback to be invoked when the status bar changes + * visibility. This reports global changes to the system UI + * state, not just what the application is requesting. + * + * @see View#setOnSystemUiVisibilityChangeListener(android.view.View.OnSystemUiVisibilityChangeListener) + */ + public interface OnSystemUiVisibilityChangeListener { + /** + * Called when the status bar changes visibility because of a call to + * {@link View#setSystemUiVisibility(int)}. + * + * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or + * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. This tells you the + * global state of the UI visibility flags, not what your + * app is currently applying. + */ + public void onSystemUiVisibilityChange(int visibility); + } + /** + * Interface definition for a callback to be invoked when this view is attached + * or detached from its window. + */ + public interface OnAttachStateChangeListener { + /** + * Called when the view is attached to a window. + * @param v The view that was attached + */ + public void onViewAttachedToWindow(View v); + /** + * Called when the view is detached from a window. + * @param v The view that was detached + */ + public void onViewDetachedFromWindow(View v); + } + private final class UnsetPressedState implements Runnable { + public void run() { + setPressed(false); + } + } + /** + * Base class for derived classes that want to save and restore their own + * state in {@link android.view.View#onSaveInstanceState()}. + */ + public static class BaseSavedState extends AbsSavedState { + /** + * Constructor used when reading from a parcel. Reads the state of the superclass. + * + * @param source + */ + public BaseSavedState(Parcel source) { + super(source); + } + /** + * Constructor called by derived classes when creating their SavedState objects + * + * @param superState The state of the superclass of this view + */ + public BaseSavedState(Parcelable superState) { + super(superState); + } + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public BaseSavedState createFromParcel(Parcel in) { + return new BaseSavedState(in); + } + public BaseSavedState[] newArray(int size) { + return new BaseSavedState[size]; + } + }; + } + /** + * A set of information given to a view when it is attached to its parent + * window. + */ + static class AttachInfo { + interface Callbacks { + void playSoundEffect(int effectId); + boolean performHapticFeedback(int effectId, boolean always); + } + /** + * InvalidateInfo is used to post invalidate(int, int, int, int) messages + * to a Handler. This class contains the target (View) to invalidate and + * the coordinates of the dirty rectangle. + * + * For performance purposes, this class also implements a pool of up to + * POOL_LIMIT objects that get reused. This reduces memory allocations + * whenever possible. + */ + static class InvalidateInfo implements Poolable { + private static final int POOL_LIMIT = 10; + private static final Pool sPool = Pools.synchronizedPool( + Pools.finitePool(new PoolableManager() { + public InvalidateInfo newInstance() { + return new InvalidateInfo(); + } + public void onAcquired(InvalidateInfo element) { + } + public void onReleased(InvalidateInfo element) { + element.target = null; + } + }, POOL_LIMIT) + ); + private InvalidateInfo mNext; + private boolean mIsPooled; + View target; + int left; + int top; + int right; + int bottom; + public void setNextPoolable(InvalidateInfo element) { + mNext = element; + } + public InvalidateInfo getNextPoolable() { + return mNext; + } + static InvalidateInfo acquire() { + return sPool.acquire(); + } + void release() { + sPool.release(this); + } + public boolean isPooled() { + return mIsPooled; + } + public void setPooled(boolean isPooled) { + mIsPooled = isPooled; + } + } + final IWindowSession mSession; + final IWindow mWindow; + final IBinder mWindowToken; + final Callbacks mRootCallbacks; + HardwareCanvas mHardwareCanvas; + /** + * The top view of the hierarchy. + */ + View mRootView; + IBinder mPanelParentWindowToken; + Surface mSurface; + boolean mHardwareAccelerated; + boolean mHardwareAccelerationRequested; + HardwareRenderer mHardwareRenderer; + /** + * Scale factor used by the compatibility mode + */ + float mApplicationScale; + /** + * Indicates whether the application is in compatibility mode + */ + boolean mScalingRequired; + /** + * If set, ViewAncestor doesn't use its lame animation for when the window resizes. + */ + boolean mTurnOffWindowResizeAnim; + /** + * Left position of this view's window + */ + int mWindowLeft; + /** + * Top position of this view's window + */ + int mWindowTop; + /** + * Indicates whether views need to use 32-bit drawing caches + */ + boolean mUse32BitDrawingCache; + /** + * For windows that are full-screen but using insets to layout inside + * of the screen decorations, these are the current insets for the + * content of the window. + */ + final Rect mContentInsets = new Rect(); + /** + * For windows that are full-screen but using insets to layout inside + * of the screen decorations, these are the current insets for the + * actual visible parts of the window. + */ + final Rect mVisibleInsets = new Rect(); + /** + * The internal insets given by this window. This value is + * supplied by the client (through + * {@link ViewTreeObserver.OnComputeInternalInsetsListener}) and will + * be given to the window manager when changed to be used in laying + * out windows behind it. + */ + final ViewTreeObserver.InternalInsetsInfo mGivenInternalInsets + = new ViewTreeObserver.InternalInsetsInfo(); + /** + * All views in the window's hierarchy that serve as scroll containers, + * used to determine if the window can be resized or must be panned + * to adjust for a soft input area. + */ + final ArrayList mScrollContainers = new ArrayList(); + final KeyEvent.DispatcherState mKeyDispatchState + = new KeyEvent.DispatcherState(); + /** + * Indicates whether the view's window currently has the focus. + */ + boolean mHasWindowFocus; + /** + * The current visibility of the window. + */ + int mWindowVisibility; + /** + * Indicates the time at which drawing started to occur. + */ + long mDrawingTime; + /** + * Indicates whether or not ignoring the DIRTY_MASK flags. + */ + boolean mIgnoreDirtyState; + /** + * This flag tracks when the mIgnoreDirtyState flag is set during draw(), + * to avoid clearing that flag prematurely. + */ + boolean mSetIgnoreDirtyState = false; + /** + * Indicates whether the view's window is currently in touch mode. + */ + boolean mInTouchMode; + /** + * Indicates that ViewAncestor should trigger a global layout change + * the next time it performs a traversal + */ + boolean mRecomputeGlobalAttributes; + /** + * Always report new attributes at next traversal. + */ + boolean mForceReportNewAttributes; + /** + * Set during a traveral if any views want to keep the screen on. + */ + boolean mKeepScreenOn; + /** + * Bitwise-or of all of the values that views have passed to setSystemUiVisibility(). + */ + int mSystemUiVisibility; + /** + * True if a view in this hierarchy has an OnSystemUiVisibilityChangeListener + * attached. + */ + boolean mHasSystemUiListeners; + /** + * Set if the visibility of any views has changed. + */ + boolean mViewVisibilityChanged; + /** + * Set to true if a view has been scrolled. + */ + boolean mViewScrollChanged; + /** + * Global to the view hierarchy used as a temporary for dealing with + * x/y points in the transparent region computations. + */ + final int[] mTransparentLocation = new int[2]; + /** + * Global to the view hierarchy used as a temporary for dealing with + * x/y points in the ViewGroup.invalidateChild implementation. + */ + final int[] mInvalidateChildLocation = new int[2]; + /** + * Global to the view hierarchy used as a temporary for dealing with + * x/y location when view is transformed. + */ + final float[] mTmpTransformLocation = new float[2]; + /** + * The view tree observer used to dispatch global events like + * layout, pre-draw, touch mode change, etc. + */ + final ViewTreeObserver mTreeObserver = new ViewTreeObserver(); + /** + * A Canvas used by the view hierarchy to perform bitmap caching. + */ + Canvas mCanvas; + /** + * The view root impl. + */ + final ViewRootImpl mViewRootImpl; + /** + * A Handler supplied by a view's {@link android.view.ViewRootImpl}. This + * handler can be used to pump events in the UI events queue. + */ + final Handler mHandler; + /** + * Temporary for use in computing invalidate rectangles while + * calling up the hierarchy. + */ + final Rect mTmpInvalRect = new Rect(); + /** + * Temporary for use in computing hit areas with transformed views + */ + final RectF mTmpTransformRect = new RectF(); + /** + * Temporary list for use in collecting focusable descendents of a view. + */ + final ArrayList mFocusablesTempList = new ArrayList(24); + /** + * The id of the window for accessibility purposes. + */ + int mAccessibilityWindowId = View.NO_ID; + /** + * Creates a new set of attachment information with the specified + * events handler and thread. + * + * @param handler the events handler the view must use + */ + AttachInfo(IWindowSession session, IWindow window, + ViewRootImpl viewRootImpl, Handler handler, Callbacks effectPlayer) { + mSession = session; + mWindow = window; + mWindowToken = window.asBinder(); + mViewRootImpl = viewRootImpl; + mHandler = handler; + mRootCallbacks = effectPlayer; + } + } + /** + *

ScrollabilityCache holds various fields used by a View when scrolling + * is supported. This avoids keeping too many unused fields in most + * instances of View.

+ */ + private static class ScrollabilityCache implements Runnable { + /** + * Scrollbars are not visible + */ + public static final int OFF = 0; + /** + * Scrollbars are visible + */ + public static final int ON = 1; + /** + * Scrollbars are fading away + */ + public static final int FADING = 2; + public boolean fadeScrollBars; + public int fadingEdgeLength; + public int scrollBarDefaultDelayBeforeFade; + public int scrollBarFadeDuration; + public int scrollBarSize; + public ScrollBarDrawable scrollBar; + public float[] interpolatorValues; + public View host; + public final Paint paint; + public final Matrix matrix; + public Shader shader; + public final Interpolator scrollBarInterpolator = new Interpolator(1, 2); + private static final float[] OPAQUE = { 255 }; + private static final float[] TRANSPARENT = { 0.0f }; + /** + * When fading should start. This time moves into the future every time + * a new scroll happens. Measured based on SystemClock.uptimeMillis() + */ + public long fadeStartTime; + /** + * The current state of the scrollbars: ON, OFF, or FADING + */ + public int state = OFF; + private int mLastColor; + public ScrollabilityCache(ViewConfiguration configuration, View host) { + fadingEdgeLength = configuration.getScaledFadingEdgeLength(); + scrollBarSize = configuration.getScaledScrollBarSize(); + scrollBarDefaultDelayBeforeFade = ViewConfiguration.getScrollDefaultDelay(); + scrollBarFadeDuration = ViewConfiguration.getScrollBarFadeDuration(); + paint = new Paint(); + matrix = new Matrix(); + // use use a height of 1, and then wack the matrix each time we + // actually use it. + shader = new LinearGradient(0, 0, 0, 1, 0xFF000000, 0, Shader.TileMode.CLAMP); + paint.setShader(shader); + paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); + this.host = host; + } + public void setFadeColor(int color) { + if (color != 0 && color != mLastColor) { + mLastColor = color; + color |= 0xFF000000; + shader = new LinearGradient(0, 0, 0, 1, color | 0xFF000000, + color & 0x00FFFFFF, Shader.TileMode.CLAMP); + paint.setShader(shader); + // Restore the default transfer mode (src_over) + paint.setXfermode(null); + } + } + public void run() { + long now = AnimationUtils.currentAnimationTimeMillis(); + if (now >= fadeStartTime) { + // the animation fades the scrollbars out by changing + // the opacity (alpha) from fully opaque to fully + // transparent + int nextFrame = (int) now; + int framesCount = 0; + Interpolator interpolator = scrollBarInterpolator; + // Start opaque + interpolator.setKeyFrame(framesCount++, nextFrame, OPAQUE); + // End transparent + nextFrame += scrollBarFadeDuration; + interpolator.setKeyFrame(framesCount, nextFrame, TRANSPARENT); + state = FADING; + // Kick off the fade animation + host.invalidate(true); + } + } + } + /** + * Resuable callback for sending + * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. + */ + private class SendViewScrolledAccessibilityEvent implements Runnable { + public volatile boolean mIsPending; + public void run() { + sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SCROLLED); + mIsPending = false; + } + } + /** + *

+ * This class represents a delegate that can be registered in a {@link View} + * to enhance accessibility support via composition rather via inheritance. + * It is specifically targeted to widget developers that extend basic View + * classes i.e. classes in package android.view, that would like their + * applications to be backwards compatible. + *

+ *

+ * A scenario in which a developer would like to use an accessibility delegate + * is overriding a method introduced in a later API version then the minimal API + * version supported by the application. For example, the method + * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} is not available + * in API version 4 when the accessibility APIs were first introduced. If a + * developer would like his application to run on API version 4 devices (assuming + * all other APIs used by the application are version 4 or lower) and take advantage + * of this method, instead of overriding the method which would break the application's + * backwards compatibility, he can override the corresponding method in this + * delegate and register the delegate in the target View if the API version of + * the system is high enough i.e. the API version is same or higher to the API + * version that introduced + * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)}. + *

+ *

+ * Here is an example implementation: + *

+ *

+ * if (Build.VERSION.SDK_INT >= 14) { + * // If the API version is equal of higher than the version in + * // which onInitializeAccessibilityNodeInfo was introduced we + * // register a delegate with a customized implementation. + * View view = findViewById(R.id.view_id); + * view.setAccessibilityDelegate(new AccessibilityDelegate() { + * public void onInitializeAccessibilityNodeInfo(View host, + * AccessibilityNodeInfo info) { + * // Let the default implementation populate the info. + * super.onInitializeAccessibilityNodeInfo(host, info); + * // Set some other information. + * info.setEnabled(host.isEnabled()); + * } + * }); + * } + *

+ *

+ * This delegate contains methods that correspond to the accessibility methods + * in View. If a delegate has been specified the implementation in View hands + * off handling to the corresponding method in this delegate. The default + * implementation the delegate methods behaves exactly as the corresponding + * method in View for the case of no accessibility delegate been set. Hence, + * to customize the behavior of a View method, clients can override only the + * corresponding delegate method without altering the behavior of the rest + * accessibility related methods of the host view. + *

+ */ + public static class AccessibilityDelegate { + /** + * Sends an accessibility event of the given type. If accessibility is not + * enabled this method has no effect. + *

+ * The default implementation behaves as {@link View#sendAccessibilityEvent(int) + * View#sendAccessibilityEvent(int)} for the case of no accessibility delegate + * been set. + *

+ * + * @param host The View hosting the delegate. + * @param eventType The type of the event to send. + * + * @see View#sendAccessibilityEvent(int) View#sendAccessibilityEvent(int) + */ + public void sendAccessibilityEvent(View host, int eventType) { + host.sendAccessibilityEventInternal(eventType); + } + /** + * Sends an accessibility event. This method behaves exactly as + * {@link #sendAccessibilityEvent(View, int)} but takes as an argument an + * empty {@link AccessibilityEvent} and does not perform a check whether + * accessibility is enabled. + *

+ * The default implementation behaves as + * {@link View#sendAccessibilityEventUnchecked(AccessibilityEvent) + * View#sendAccessibilityEventUnchecked(AccessibilityEvent)} for + * the case of no accessibility delegate been set. + *

+ * + * @param host The View hosting the delegate. + * @param event The event to send. + * + * @see View#sendAccessibilityEventUnchecked(AccessibilityEvent) + * View#sendAccessibilityEventUnchecked(AccessibilityEvent) + */ + public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event) { + host.sendAccessibilityEventUncheckedInternal(event); + } + /** + * Dispatches an {@link AccessibilityEvent} to the host {@link View} first and then + * to its children for adding their text content to the event. + *

+ * The default implementation behaves as + * {@link View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) + * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)} for + * the case of no accessibility delegate been set. + *

+ * + * @param host The View hosting the delegate. + * @param event The event. + * @return True if the event population was completed. + * + * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) + * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) + */ + public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) { + return host.dispatchPopulateAccessibilityEventInternal(event); + } + /** + * Gives a chance to the host View to populate the accessibility event with its + * text content. + *

+ * The default implementation behaves as + * {@link View#onPopulateAccessibilityEvent(AccessibilityEvent) + * View#onPopulateAccessibilityEvent(AccessibilityEvent)} for + * the case of no accessibility delegate been set. + *

+ * + * @param host The View hosting the delegate. + * @param event The accessibility event which to populate. + * + * @see View#onPopulateAccessibilityEvent(AccessibilityEvent) + * View#onPopulateAccessibilityEvent(AccessibilityEvent) + */ + public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) { + host.onPopulateAccessibilityEventInternal(event); + } + /** + * Initializes an {@link AccessibilityEvent} with information about the + * the host View which is the event source. + *

+ * The default implementation behaves as + * {@link View#onInitializeAccessibilityEvent(AccessibilityEvent) + * View#onInitializeAccessibilityEvent(AccessibilityEvent)} for + * the case of no accessibility delegate been set. + *

+ * + * @param host The View hosting the delegate. + * @param event The event to initialize. + * + * @see View#onInitializeAccessibilityEvent(AccessibilityEvent) + * View#onInitializeAccessibilityEvent(AccessibilityEvent) + */ + public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { + host.onInitializeAccessibilityEventInternal(event); + } + /** + * Initializes an {@link AccessibilityNodeInfo} with information about the host view. + *

+ * The default implementation behaves as + * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) + * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} for + * the case of no accessibility delegate been set. + *

+ * + * @param host The View hosting the delegate. + * @param info The instance to initialize. + * + * @see View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) + * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) + */ + public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { + host.onInitializeAccessibilityNodeInfoInternal(info); + } + /** + * Called when a child of the host View has requested sending an + * {@link AccessibilityEvent} and gives an opportunity to the parent (the host) + * to augment the event. + *

+ * The default implementation behaves as + * {@link ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) + * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent)} for + * the case of no accessibility delegate been set. + *

+ * + * @param host The View hosting the delegate. + * @param child The child which requests sending the event. + * @param event The event to be sent. + * @return True if the event should be sent + * + * @see ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) + * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) + */ + public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, + AccessibilityEvent event) { + return host.onRequestSendAccessibilityEventInternal(child, event); + } + /** + * Gets the provider for managing a virtual view hierarchy rooted at this View + * and reported to {@link android.accessibilityservice.AccessibilityService}s + * that explore the window content. + *

+ * The default implementation behaves as + * {@link View#getAccessibilityNodeProvider() View#getAccessibilityNodeProvider()} for + * the case of no accessibility delegate been set. + *

+ * + * @return The provider. + * + * @see AccessibilityNodeProvider + */ + public AccessibilityNodeProvider getAccessibilityNodeProvider(View host) { + return null; + } + } +} diff --git a/src/test/resources/eo_execution_pom/pom.xml b/src/test/resources/eo_execution_pom/pom.xml index 3db6a1f2..46c7dfde 100644 --- a/src/test/resources/eo_execution_pom/pom.xml +++ b/src/test/resources/eo_execution_pom/pom.xml @@ -28,7 +28,7 @@ SOFTWARE. j2eo-testing 1.0-SNAPSHOT - 0.17.1 + 0.21.5 16 16 16 diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/CompoundReceiverVariableIsIrrelevantForStaticFieldAccess.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/CompoundReceiverVariableIsIrrelevantForStaticFieldAccess.java new file mode 100644 index 00000000..57086a69 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/CompoundReceiverVariableIsIrrelevantForStaticFieldAccess.java @@ -0,0 +1,16 @@ + +class T { + static int t = 1; +} + +class S { + static T tt = null; + static S test() { return null; } +} + +public class CompoundReceiverVariableIsIrrelevantForStaticFieldAccess { + public static void main(String[] args) { + System.out.println(S.test().tt.t); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/ReceiverVariableIsIrrelevantForStaticFieldAccess.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/ReceiverVariableIsIrrelevantForStaticFieldAccess.java new file mode 100644 index 00000000..f93666e1 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/ReceiverVariableIsIrrelevantForStaticFieldAccess.java @@ -0,0 +1,12 @@ + +class S { + static int s = 0; + static S test() { return null; } +} + +public class ReceiverVariableIsIrrelevantForStaticFieldAccess { + public static void main(String[] args) { + System.out.println(S.test().s); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/StaticBindingForFieldAccess.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/StaticBindingForFieldAccess.java new file mode 100644 index 00000000..a6223285 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/StaticBindingForFieldAccess.java @@ -0,0 +1,19 @@ + +class S { + int x = 0; +} +class T extends S { + int x = 1; +} + +public class StaticBindingForFieldAccess { + public static void main(String[] args) { + T t = new T(); + System.out.println(t.x); + S s = new S(); + System.out.println(s.x); + s = t; + System.out.println(s.x); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/StaticBindingForMembersAccessPolymorphismCase.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/StaticBindingForMembersAccessPolymorphismCase.java new file mode 100644 index 00000000..cd0563b9 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/StaticBindingForMembersAccessPolymorphismCase.java @@ -0,0 +1,19 @@ + +class S { + int x() { return 0; } +} +class T extends S { + int x() { return 1; } +} + +public class StaticBindingForMembersAccessPolymorphismCase { + public static void main(String[] args) { + T t = new T(); + System.out.println(t.x()); + S s = new S(); + System.out.println(s.x()); + s = t; + System.out.println(s.x()); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/StaticBindingForMethodAccess.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/StaticBindingForMethodAccess.java new file mode 100644 index 00000000..f02eb7d9 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/StaticBindingForMethodAccess.java @@ -0,0 +1,21 @@ + +class S { + int x = 0; + int z() { return x; } +} +class T extends S { + int x = 1; + int z() { return x; } +} + +public class StaticBindingForMethodAccess { + public static void main(String[] args) { + T t = new T(); + System.out.println(t.z()); + S s = new S(); + System.out.println(s.z()); + s = t; + System.out.println(s.z()); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/StaticBindingForMethodAccessNoX.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/StaticBindingForMethodAccessNoX.java new file mode 100644 index 00000000..d32620d3 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_1_field_access_using_a_primary/StaticBindingForMethodAccessNoX.java @@ -0,0 +1,20 @@ + +class S { + int x = 0; + int z() { return x; } +} +class T extends S { + int z() { return x; } +} + +public class StaticBindingForMethodAccessNoX { + public static void main(String[] args) { + T t = new T(); + System.out.println(t.z()); + S s = new S(); + System.out.println(s.z()); + s = t; + System.out.println(s.z()); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_2_accessing_superclass_members_using_super/SimpleSuperExpression.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_2_accessing_superclass_members_using_super/SimpleSuperExpression.java new file mode 100644 index 00000000..21991152 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_2_accessing_superclass_members_using_super/SimpleSuperExpression.java @@ -0,0 +1,21 @@ + +class T0 { int x = 0; } +class T1 extends T0 { int x = 1; } +class T2 extends T1 { int x = 2; } +class T3 extends T2 { + int x = 3; + void test() { + System.out.println(x); + System.out.println(super.x); + System.out.println(((T2)this).x); + System.out.println(((T1)this).x); + System.out.println(((T0)this).x); + } +} + +public class SimpleSuperExpression { + public static void main(String[] args) { + new T3().test(); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_2_accessing_superclass_members_using_super/SimpleSuperExpressionMethodCase.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_2_accessing_superclass_members_using_super/SimpleSuperExpressionMethodCase.java new file mode 100644 index 00000000..8f93fc1b --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_11_field_access_expressions/sec_15_11_2_accessing_superclass_members_using_super/SimpleSuperExpressionMethodCase.java @@ -0,0 +1,21 @@ + +class T0 { int x() { return 0; } } +class T1 extends T0 { int x() { return 1; } } +class T2 extends T1 { int x() { return 2; } } +class T3 extends T2 { + int x() { return 3; } + void test() { + System.out.println(x()); + System.out.println(super.x()); + System.out.println(((T2)this).x()); + System.out.println(((T1)this).x()); + System.out.println(((T0)this).x()); + } +} + +public class SimpleSuperExpressionMethodCase { + public static void main(String[] args) { + new T3().test(); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_12_method_invocation_expressions/MethodInvocationViaSuper.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_12_method_invocation_expressions/MethodInvocationViaSuper.java new file mode 100644 index 00000000..e69531dd --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_12_method_invocation_expressions/MethodInvocationViaSuper.java @@ -0,0 +1,17 @@ + +class S { + void foo() { System.out.println("Hi"); } +} +class T extends S { + void foo() {} + void run() { + T.super.foo(); + } +} + +public class MethodInvocationViaSuper { + public static void main(String[] args) { + new T().run(); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_12_method_invocation_expressions/MethodInvocationViaSuperChainCase.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_12_method_invocation_expressions/MethodInvocationViaSuperChainCase.java new file mode 100644 index 00000000..c1b729f8 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_12_method_invocation_expressions/MethodInvocationViaSuperChainCase.java @@ -0,0 +1,20 @@ + +class E { + void foo() { System.out.println("Hi"); } +} +class S extends E { + void foo() { S.super.foo(); } +} +class T extends S { + void foo() {} + void run() { + T.super.foo(); + } +} + +public class MethodInvocationViaSuperChainCase { + public static void main(String[] args) { + new T().run(); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_13_method_reference_expressions/ConstructorReference.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_13_method_reference_expressions/ConstructorReference.java new file mode 100644 index 00000000..414563b9 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_13_method_reference_expressions/ConstructorReference.java @@ -0,0 +1,19 @@ + +public class ConstructorReference { + + public static void main(String[] args) { + IEdible apple = Apple::new; + apple.setYummy(true); + System.out.println("passed"); + } +} + +class Apple { + Apple(boolean isYummy) { + System.out.println("An apple " + (isYummy ? "is" : "isn't") + " yummy."); + } +} + +interface IEdible { + Apple setYummy(boolean isYummy); +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_13_method_reference_expressions/InstanceMethodReference.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_13_method_reference_expressions/InstanceMethodReference.java new file mode 100644 index 00000000..e3469558 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_13_method_reference_expressions/InstanceMethodReference.java @@ -0,0 +1,18 @@ + +public class InstanceMethodReference { + + public void eat() { + System.out.println("yummy!!!"); + System.out.println("passed"); + } + + public static void main(String[] args) { + InstanceMethodReference methRef = new InstanceMethodReference(); + IEdible food = methRef::eat; + food.consume(); + } +} + +interface IEdible { + void consume(); +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_13_method_reference_expressions/SampleTest.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_13_method_reference_expressions/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_15_expressions/sec_15_13_method_reference_expressions/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_13_method_reference_expressions/SimpleMethodReference.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_13_method_reference_expressions/SimpleMethodReference.java new file mode 100644 index 00000000..9d2dd680 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_13_method_reference_expressions/SimpleMethodReference.java @@ -0,0 +1,17 @@ + +public class SimpleMethodReference { + + public static void eat() { + System.out.println("yummy!!!"); + System.out.println("passed"); + } + + public static void main(String[] args) { + IEdible food = SimpleMethodReference::eat; + food.consume(); + } +} + +interface IEdible { + void consume(); +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_16_cast_expressions/CastToParentViaMethod.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_16_cast_expressions/CastToParentViaMethod.java new file mode 100644 index 00000000..483130a8 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_16_cast_expressions/CastToParentViaMethod.java @@ -0,0 +1,16 @@ + +class S { + int x = 0; +} +class T extends S { + int x = 1; +} + +public class CastToParentViaMethod { + public static T getT() { return new T(); } + + public static void main(String[] args) { + System.out.println(((S)getT()).x); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_16_cast_expressions/SimpleCastToParent.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_16_cast_expressions/SimpleCastToParent.java new file mode 100644 index 00000000..18d0d791 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_16_cast_expressions/SimpleCastToParent.java @@ -0,0 +1,15 @@ + +class S { + int x = 0; +} +class T extends S { + int x = 1; +} + +public class SimpleCastToParent { + public static void main(String[] args) { + T t = new T(); + System.out.println(((S)t).x); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_1_evaluation_denotation_and_result/SampleTest.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_1_evaluation_denotation_and_result/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_15_expressions/sec_15_1_evaluation_denotation_and_result/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_1_boolean_conditional_expressions/CompoundBoolTernaryOperator.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_1_boolean_conditional_expressions/CompoundBoolTernaryOperator.java new file mode 100644 index 00000000..fcd5b2ec --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_1_boolean_conditional_expressions/CompoundBoolTernaryOperator.java @@ -0,0 +1,8 @@ + +public class CompoundBoolTernaryOperator { + public static void main(String[] args) { + int res = (true ? true : false) ? 1 : 0; + System.out.println(res); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_1_boolean_conditional_expressions/EvaluatedByFunctionTernaryOperator.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_1_boolean_conditional_expressions/EvaluatedByFunctionTernaryOperator.java new file mode 100644 index 00000000..27f5bdba --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_1_boolean_conditional_expressions/EvaluatedByFunctionTernaryOperator.java @@ -0,0 +1,13 @@ + +public class EvaluatedByFunctionTernaryOperator { + public static boolean f(int a, int b) { + return a + 1 == b; + } + public static void main(String[] args) { + int a = 1; + int b = 2; + int res = f(1, 2) ? 1 : 0; + System.out.println(res); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_1_boolean_conditional_expressions/EvaluatedTernaryOperator.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_1_boolean_conditional_expressions/EvaluatedTernaryOperator.java new file mode 100644 index 00000000..b6b7ebc0 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_1_boolean_conditional_expressions/EvaluatedTernaryOperator.java @@ -0,0 +1,10 @@ + +public class EvaluatedTernaryOperator { + public static void main(String[] args) { + int a = 1; + int b = 2; + int res = (a + 1 == b) ? 1 : 0; + System.out.println(res); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_1_boolean_conditional_expressions/SimpleBoolTernaryOperator.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_1_boolean_conditional_expressions/SimpleBoolTernaryOperator.java new file mode 100644 index 00000000..b9451128 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_1_boolean_conditional_expressions/SimpleBoolTernaryOperator.java @@ -0,0 +1,8 @@ + +public class SimpleBoolTernaryOperator { + public static void main(String[] args) { + int res = true ? 1 : 2; + System.out.println(res); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_2_numeric_conditional_expressions/NumericConditionExpressionWithDifferentTypes.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_2_numeric_conditional_expressions/NumericConditionExpressionWithDifferentTypes.java new file mode 100644 index 00000000..bfe787aa --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_2_numeric_conditional_expressions/NumericConditionExpressionWithDifferentTypes.java @@ -0,0 +1,10 @@ + +public class NumericConditionExpressionWithDifferentTypes { + public static void main(String[] args) { + byte a = 1; + short b = 1; + short c = true ? a : b; + System.out.println(c); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_2_numeric_conditional_expressions/SimpleNumericConditionExpression.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_2_numeric_conditional_expressions/SimpleNumericConditionExpression.java new file mode 100644 index 00000000..145b0e6f --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_2_numeric_conditional_expressions/SimpleNumericConditionExpression.java @@ -0,0 +1,10 @@ + +public class SimpleNumericConditionExpression { + public static void main(String[] args) { + int a = 1; + int b = 1; + int c = true ? a : b; + System.out.println(c); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_3_reference_conditional_expressions/SimpleReferencedConditionalExpression.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_3_reference_conditional_expressions/SimpleReferencedConditionalExpression.java new file mode 100644 index 00000000..3bb17df2 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_25_ternary_operator/sec_15_25_3_reference_conditional_expressions/SimpleReferencedConditionalExpression.java @@ -0,0 +1,22 @@ + +class S { + public int id; + public S(int id) { + this.id = id; + } +} +class T extends S { + public T(int id) { + super(id); + } +} + +public class SimpleReferencedConditionalExpression { + public static void main(String[] args) { + S s = new S(0); + T t = new T(1); + S res = true ? s : t; + System.out.println(res.id); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_1_lambda_parameters/ArrayLambdaParameter.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_1_lambda_parameters/ArrayLambdaParameter.java new file mode 100644 index 00000000..ce37938e --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_1_lambda_parameters/ArrayLambdaParameter.java @@ -0,0 +1,20 @@ + +public class ArrayLambdaParameter { + + public static void main(String[] args) { + IntegerFunction f = (arr) -> { + int sum = 0; + for (int i : arr) { + sum += i; + } + return sum; + }; + + System.out.println(f.process(new int[] {1, 2, 3, 4, 5})); + System.out.println("passed"); + } +} + +interface IntegerFunction { + int process(int[] arr); +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_1_lambda_parameters/SampleTest.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_1_lambda_parameters/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_1_lambda_parameters/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_1_lambda_parameters/SimpleLambda.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_1_lambda_parameters/SimpleLambda.java new file mode 100644 index 00000000..2271997c --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_1_lambda_parameters/SimpleLambda.java @@ -0,0 +1,16 @@ + +public class SimpleLambda { + + public static void main(String[] args) { + AnimalSoundFunction lionRoar = (s) -> s + "!!!"; + AnimalSoundFunction catMrrr = (s) -> s + " *uWu*"; + + System.out.println(lionRoar.say("Arrr")); + System.out.println(catMrrr.say("Mrrr")); + System.out.println("passed"); + } +} + +interface AnimalSoundFunction { + String say(String line); +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_1_lambda_parameters/VoidLambda.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_1_lambda_parameters/VoidLambda.java new file mode 100644 index 00000000..c4da0edc --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_1_lambda_parameters/VoidLambda.java @@ -0,0 +1,12 @@ + +public class VoidLambda { + + public static void main(String[] args) { + SomeFunction f = () -> { System.out.println("passed"); }; + f.process(); + } +} + +interface SomeFunction { + void process(); +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_2_lambda_body/SampleTest.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_2_lambda_body/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_2_lambda_body/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_2_lambda_body/SimpleLambdaBody.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_2_lambda_body/SimpleLambdaBody.java new file mode 100644 index 00000000..9e524028 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_27_lambda_expressions/sec_15_27_2_lambda_body/SimpleLambdaBody.java @@ -0,0 +1,18 @@ + +public class SimpleLambdaBody { + + public static void main(String[] args) { + SomeFunc strFunc = (s) -> { + int a = 666; + s = "" + a + s; + s += a; + return s; + }; + System.out.println(strFunc.stringFunc("eo_gang")); + System.out.println("passed"); + } +} + +interface SomeFunc { + String stringFunc(String input); +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_28_switch_expressions/sec_15_28_1_the_switch_block_of_a_switch_expression/CompoundSwitchExpression.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_28_switch_expressions/sec_15_28_1_the_switch_block_of_a_switch_expression/CompoundSwitchExpression.java new file mode 100644 index 00000000..13cd6187 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_28_switch_expressions/sec_15_28_1_the_switch_block_of_a_switch_expression/CompoundSwitchExpression.java @@ -0,0 +1,26 @@ + +public class CompoundSwitchExpression { + public static void main(String[] args) { + int a = 1; + switch (a) { + case 1: { + switch (a) { + case 1: { + System.out.println(a); + break; + } + default: { + System.out.println("Error"); + break; + } + } + break; + } + default: { + System.out.println("Error"); + break; + } + } + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_28_switch_expressions/sec_15_28_1_the_switch_block_of_a_switch_expression/SeveralSwitchDefaultCases.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_28_switch_expressions/sec_15_28_1_the_switch_block_of_a_switch_expression/SeveralSwitchDefaultCases.java new file mode 100644 index 00000000..9772acb7 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_28_switch_expressions/sec_15_28_1_the_switch_block_of_a_switch_expression/SeveralSwitchDefaultCases.java @@ -0,0 +1,18 @@ + +public class SeveralSwitchDefaultCases { + public static void main(String[] args) { + String s = "not string"; + switch (s) { + default: { + switch (s) { + default: { + System.out.println("Default"); + break; + } + } + break; + } + } + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_28_switch_expressions/sec_15_28_1_the_switch_block_of_a_switch_expression/SimpleStringSwitch.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_28_switch_expressions/sec_15_28_1_the_switch_block_of_a_switch_expression/SimpleStringSwitch.java new file mode 100644 index 00000000..be491818 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_28_switch_expressions/sec_15_28_1_the_switch_block_of_a_switch_expression/SimpleStringSwitch.java @@ -0,0 +1,17 @@ + +public class SimpleStringSwitch { + public static void main(String[] args) { + String s = "string"; + switch (s) { + case "string": { + System.out.println(s); + break; + } + default: { + System.out.println("Error"); + break; + } + } + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_28_switch_expressions/sec_15_28_1_the_switch_block_of_a_switch_expression/SimpleSwitchDefaultCase.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_28_switch_expressions/sec_15_28_1_the_switch_block_of_a_switch_expression/SimpleSwitchDefaultCase.java new file mode 100644 index 00000000..9e0e3b3a --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_28_switch_expressions/sec_15_28_1_the_switch_block_of_a_switch_expression/SimpleSwitchDefaultCase.java @@ -0,0 +1,17 @@ + +public class SimpleSwitchDefaultCase { + public static void main(String[] args) { + String s = "not string"; + switch (s) { + case "string": { + System.out.println(s); + break; + } + default: { + System.out.println("Default"); + break; + } + } + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_28_switch_expressions/sec_15_28_1_the_switch_block_of_a_switch_expression/SimpleSwitchExpression.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_28_switch_expressions/sec_15_28_1_the_switch_block_of_a_switch_expression/SimpleSwitchExpression.java new file mode 100644 index 00000000..784a1123 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_28_switch_expressions/sec_15_28_1_the_switch_block_of_a_switch_expression/SimpleSwitchExpression.java @@ -0,0 +1,17 @@ + +public class SimpleSwitchExpression { + public static void main(String[] args) { + int a = 1; + switch (a) { + case 1: { + System.out.println(a); + break; + } + default: { + System.out.println("Error"); + break; + } + } + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_29_constant_expressions/SimpleConstantExpressionIntExample.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_29_constant_expressions/SimpleConstantExpressionIntExample.java new file mode 100644 index 00000000..5d69f859 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_29_constant_expressions/SimpleConstantExpressionIntExample.java @@ -0,0 +1,8 @@ + +public class SimpleConstantExpressionIntExample { + public static void main(String[] args) { + int s = 0; + System.out.println(s); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_29_constant_expressions/SimpleConstantExpressionStringExample.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_29_constant_expressions/SimpleConstantExpressionStringExample.java new file mode 100644 index 00000000..57eadd63 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_29_constant_expressions/SimpleConstantExpressionStringExample.java @@ -0,0 +1,8 @@ + +public class SimpleConstantExpressionStringExample { + public static void main(String[] args) { + String s = "It is constant expression"; + System.out.println(s); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_2_forms_of_expressoins/SampleTest.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_2_forms_of_expressoins/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_15_expressions/sec_15_2_forms_of_expressoins/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_3_type_of_an_expression/SampleTest.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_3_type_of_an_expression/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_15_expressions/sec_15_3_type_of_an_expression/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_4_fp_strict_expressions/SimpleNonVoidStrictFpExpression.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_4_fp_strict_expressions/SimpleNonVoidStrictFpExpression.java new file mode 100644 index 00000000..39ccf9b5 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_4_fp_strict_expressions/SimpleNonVoidStrictFpExpression.java @@ -0,0 +1,12 @@ + +public class SimpleNonVoidStrictFpExpression { + public static strictfp float test() { + return 0f; + } + + public static void main(String[] args) { + float f = test(); + System.out.println(f); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_4_fp_strict_expressions/SimpleVoidStrictFpExpression.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_4_fp_strict_expressions/SimpleVoidStrictFpExpression.java new file mode 100644 index 00000000..db053fdd --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_4_fp_strict_expressions/SimpleVoidStrictFpExpression.java @@ -0,0 +1,9 @@ + +public class SimpleVoidStrictFpExpression { + public static strictfp void test() {} + + public static void main(String[] args) { + test(); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_6_normal_and_abrupt_completion_of_evaluation/SampleTest.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_6_normal_and_abrupt_completion_of_evaluation/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_15_expressions/sec_15_6_normal_and_abrupt_completion_of_evaluation/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_1_evaluate_left_hand_operand_first/CompoundImplicitLeftHandOperand.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_1_evaluate_left_hand_operand_first/CompoundImplicitLeftHandOperand.java new file mode 100644 index 00000000..4049e344 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_1_evaluate_left_hand_operand_first/CompoundImplicitLeftHandOperand.java @@ -0,0 +1,12 @@ + +public class CompoundImplicitLeftHandOperand { + public static void main(String[] args) { + int a = 9; + a += (a = (a = 3)); + System.out.println(a); + int b = 9; + b = b + (b = (b = 3)); + System.out.println(b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_1_evaluate_left_hand_operand_first/CompoundLeftHandOperandIsEvaluatedFirst.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_1_evaluate_left_hand_operand_first/CompoundLeftHandOperandIsEvaluatedFirst.java new file mode 100644 index 00000000..ce9c8c35 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_1_evaluate_left_hand_operand_first/CompoundLeftHandOperandIsEvaluatedFirst.java @@ -0,0 +1,9 @@ + +public class CompoundLeftHandOperandIsEvaluatedFirst { + public static void main(String[] args) { + int i = 2; + int j = (i = ((i = 3) + i)) * i; + System.out.println(j); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_1_evaluate_left_hand_operand_first/SimpleImplicitLeftHandOperand.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_1_evaluate_left_hand_operand_first/SimpleImplicitLeftHandOperand.java new file mode 100644 index 00000000..d5a8bb68 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_1_evaluate_left_hand_operand_first/SimpleImplicitLeftHandOperand.java @@ -0,0 +1,12 @@ + +public class SimpleImplicitLeftHandOperand { + public static void main(String[] args) { + int a = 9; + a += (a = 3); + System.out.println(a); + int b = 9; + b = b + (b = 3); + System.out.println(b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_1_evaluate_left_hand_operand_first/SimpleLeftHandOperandIsEvaluatedFirst.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_1_evaluate_left_hand_operand_first/SimpleLeftHandOperandIsEvaluatedFirst.java new file mode 100644 index 00000000..7fe1ffb1 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_1_evaluate_left_hand_operand_first/SimpleLeftHandOperandIsEvaluatedFirst.java @@ -0,0 +1,9 @@ + +public class SimpleLeftHandOperandIsEvaluatedFirst { + public static void main(String[] args) { + int i = 2; + int j = (i=3) * i; + System.out.println(j); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_2_evaluate_operands_before_operation/CompoundEvaluationOfOperandsBeforeOperation.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_2_evaluate_operands_before_operation/CompoundEvaluationOfOperandsBeforeOperation.java new file mode 100644 index 00000000..9190995c --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_2_evaluate_operands_before_operation/CompoundEvaluationOfOperandsBeforeOperation.java @@ -0,0 +1,19 @@ + +public class CompoundEvaluationOfOperandsBeforeOperation { + public static Integer returnInt2(Integer integer) { + System.out.println(integer); + return integer; + } + + public static Integer returnInt1(Integer integer) { + System.out.println(integer); + return integer * returnInt2(integer); + } + + public static void main(String[] args) { + Integer integer = 2; + integer = integer / returnInt1(integer); + System.out.println(integer); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_2_evaluate_operands_before_operation/SimpleEvaluationOfOperandsBeforeOperation.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_2_evaluate_operands_before_operation/SimpleEvaluationOfOperandsBeforeOperation.java new file mode 100644 index 00000000..416e3bac --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_2_evaluate_operands_before_operation/SimpleEvaluationOfOperandsBeforeOperation.java @@ -0,0 +1,14 @@ + +public class SimpleEvaluationOfOperandsBeforeOperation { + public static Integer returnInt(Integer integer) { + System.out.println(integer); + return integer; + } + + public static void main(String[] args) { + Integer integer = 2; + integer = integer / returnInt(integer); + System.out.println(integer); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_3_evaluation_respects_parentheses_and_precedence/ComplexEvaluationRespectsParenthesesAndPrecedence.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_3_evaluation_respects_parentheses_and_precedence/ComplexEvaluationRespectsParenthesesAndPrecedence.java new file mode 100644 index 00000000..60ce2ea4 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_3_evaluation_respects_parentheses_and_precedence/ComplexEvaluationRespectsParenthesesAndPrecedence.java @@ -0,0 +1,10 @@ + +public class ComplexEvaluationRespectsParenthesesAndPrecedence { + public static void main(String[] args) { + double d = 8e+10; + System.out.println(4.0 / (d * 0.5)); + System.out.println((4.0 / d) * 0.5); + System.out.println(4.0 / d * 0.5); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_3_evaluation_respects_parentheses_and_precedence/SimpleEvaluationRespectsParenthesesAndPrecedence.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_3_evaluation_respects_parentheses_and_precedence/SimpleEvaluationRespectsParenthesesAndPrecedence.java new file mode 100644 index 00000000..e4b65d7d --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_3_evaluation_respects_parentheses_and_precedence/SimpleEvaluationRespectsParenthesesAndPrecedence.java @@ -0,0 +1,9 @@ + +public class SimpleEvaluationRespectsParenthesesAndPrecedence { + public static void main(String[] args) { + double d = 8e+10; + System.out.println(4.0 * d * 0.5); + System.out.println(2.0 * d); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_4_argument_lists_are_evaluated_left_to_right/AbruptCompletionOfArgumentExpression.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_4_argument_lists_are_evaluated_left_to_right/AbruptCompletionOfArgumentExpression.java new file mode 100644 index 00000000..c6b98359 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_4_argument_lists_are_evaluated_left_to_right/AbruptCompletionOfArgumentExpression.java @@ -0,0 +1,17 @@ + +public class AbruptCompletionOfArgumentExpression { + static int test(int a, int b, int c) { + return a + b + c; + } + + static int oops(int id) { + System.out.println(id); + return 0; + } + + public static void main(String[] args) { + int id = 0; + test(id = 1, oops(id), id = 2); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_4_argument_lists_are_evaluated_left_to_right/AbruptCompletionOfArgumentExpressionWithObjects.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_4_argument_lists_are_evaluated_left_to_right/AbruptCompletionOfArgumentExpressionWithObjects.java new file mode 100644 index 00000000..38356346 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_4_argument_lists_are_evaluated_left_to_right/AbruptCompletionOfArgumentExpressionWithObjects.java @@ -0,0 +1,24 @@ + +class S { + public int id; + public S(int id) { + this.id = id; + } +} + +public class AbruptCompletionOfArgumentExpressionWithObjects { + static S test(S a, S b, S c) { + return new S(a.id + b.id + c.id); + } + + static S oops(S s) { + System.out.println(s.id); + return new S(0); + } + + public static void main(String[] args) { + S s = new S(0); + test(s = new S(1), oops(s), s = new S(2)); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_4_argument_lists_are_evaluated_left_to_right/SimpleEvaluationOrderAtMethodInvocation.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_4_argument_lists_are_evaluated_left_to_right/SimpleEvaluationOrderAtMethodInvocation.java new file mode 100644 index 00000000..e68f2db4 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_4_argument_lists_are_evaluated_left_to_right/SimpleEvaluationOrderAtMethodInvocation.java @@ -0,0 +1,12 @@ + +public class SimpleEvaluationOrderAtMethodInvocation { + static void print3(String a, String b, String c) { + System.out.println(a + b + c); + } + + public static void main(String[] args) { + String s = "A"; + print3(s, s = "B", s); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_4_argument_lists_are_evaluated_left_to_right/SimpleEvaluationOrderAtMethodInvocationValueCase.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_4_argument_lists_are_evaluated_left_to_right/SimpleEvaluationOrderAtMethodInvocationValueCase.java new file mode 100644 index 00000000..442c6369 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_4_argument_lists_are_evaluated_left_to_right/SimpleEvaluationOrderAtMethodInvocationValueCase.java @@ -0,0 +1,12 @@ + +public class SimpleEvaluationOrderAtMethodInvocationValueCase { + static void print3(int a, int b, int c) { + System.out.println(100 * a + 10 * b + c); + } + + public static void main(String[] args) { + int s = 1; + print3(s, s = 2, s); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_5_evaluation_order_for_other_expressions/ClassLeftHandOperandIsEvaluatedFirst.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_5_evaluation_order_for_other_expressions/ClassLeftHandOperandIsEvaluatedFirst.java new file mode 100644 index 00000000..2c302bf4 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_5_evaluation_order_for_other_expressions/ClassLeftHandOperandIsEvaluatedFirst.java @@ -0,0 +1,19 @@ + +class Test { + public int id; + public Test(int id, Test t) { + this.id = id; + if (t != null) { + System.out.println(t.id); + } + } +} + +public class ClassLeftHandOperandIsEvaluatedFirst { + public static void main(String[] args) { + Test t = new Test(0, null); + t = (t = new Test(1, t)); + System.out.println(t.id); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_5_evaluation_order_for_other_expressions/CompoundClassLeftHandOperandIsEvaluatedFirst.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_5_evaluation_order_for_other_expressions/CompoundClassLeftHandOperandIsEvaluatedFirst.java new file mode 100644 index 00000000..07d81df3 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_5_evaluation_order_for_other_expressions/CompoundClassLeftHandOperandIsEvaluatedFirst.java @@ -0,0 +1,19 @@ + +class Test { + public int id; + public Test(int id, Test t) { + this.id = id; + if (t != null) { + System.out.println(t.id); + } + } +} + +public class CompoundClassLeftHandOperandIsEvaluatedFirst { + public static void main(String[] args) { + Test t = new Test(0, null); + t = (t = (t = new Test(1, t))); + System.out.println(t.id); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_1_lexical_literals/SampleTest.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_1_lexical_literals/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_1_lexical_literals/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_1_lexical_literals/SimpleLexicalLiterals.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_1_lexical_literals/SimpleLexicalLiterals.java new file mode 100644 index 00000000..98b695f0 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_1_lexical_literals/SimpleLexicalLiterals.java @@ -0,0 +1,17 @@ + +public class SimpleLexicalLiterals { + + public static void main(String[] args) { + int v1 = 5; + long v2 = 5L; + long v3 = 5l; + float v4 = 5.0f; + float v5 = 5.0F; + double v6 = 5.0; + boolean v7 = v1 == v2; + char v8 = '5'; + String v9 = "5"; + Object v10 = null; + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_2_class_literals/SampleTest.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_2_class_literals/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_2_class_literals/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_2_class_literals/SimpleClassLiterals.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_2_class_literals/SimpleClassLiterals.java new file mode 100644 index 00000000..220af79f --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_2_class_literals/SimpleClassLiterals.java @@ -0,0 +1,10 @@ + +public class SimpleClassLiterals { + + public static void main(String[] args) { + Class c1 = SimpleClassLiterals.class; + Class c2 = boolean[].class; + Class c3 = void.class; + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_3_this/SampleTest.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_3_this/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_3_this/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_3_this/SimpleThis.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_3_this/SimpleThis.java new file mode 100644 index 00000000..7264cda8 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_3_this/SimpleThis.java @@ -0,0 +1,29 @@ + +public class SimpleThis { + + public static void main(String[] args) { + IntVector v1 = new IntVector(5); + IntVector v2 = new IntVector(6); + System.out.println(v1.equals(v2)); + System.out.println("passed"); + } +} + +class IntVector { + int[] v; + IntVector(int size) { + v = new int[size]; + } + boolean equals(IntVector other) { + if (this == other) { + return true; + } + if (v.length != other.v.length) { + return false; + } + for (int i = 0; i < v.length; i++) { + if (v[i] != other.v[i]) return false; + } + return true; + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_4_qualified_this/SampleTest.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_4_qualified_this/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_4_qualified_this/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_4_qualified_this/SimpleQualifiedThis.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_4_qualified_this/SimpleQualifiedThis.java new file mode 100644 index 00000000..5df49b20 --- /dev/null +++ b/src/test/resources/test_candidates/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_4_qualified_this/SimpleQualifiedThis.java @@ -0,0 +1,17 @@ + +public class SimpleQualifiedThis { + + public static void main(String[] args) { + new SomeClass().method(); + } +} +class SomeClass { + void method() { + System.out.println("passed"); + } + class SomeOtherClass { + void method() { + SomeClass.this.method(); + } + } +} diff --git a/src/test/resources/test_candidates/ch_15_expressions/sec_15_9_class_instance_creation_expressions/sec_15_9_5_anonymous_class_declarations/sec_15_9_5_1_anonymous_constructors/SampleTest.java b/src/test/resources/test_candidates/ch_15_expressions/sec_15_9_class_instance_creation_expressions/sec_15_9_5_anonymous_class_declarations/sec_15_9_5_1_anonymous_constructors/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_15_expressions/sec_15_9_class_instance_creation_expressions/sec_15_9_5_anonymous_class_declarations/sec_15_9_5_1_anonymous_constructors/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SampleTest.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SimpleByte.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SimpleByte.java new file mode 100644 index 00000000..a41617b0 --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SimpleByte.java @@ -0,0 +1,8 @@ +public class SimpleByte { + + public static void main(String[] args) { + byte a = -128; + System.out.println(a); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SimpleChar.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SimpleChar.java new file mode 100644 index 00000000..72833bde --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SimpleChar.java @@ -0,0 +1,8 @@ +public class SimpleChar { + + public static void main(String[] args) { + char a = '\u0000'; + System.out.println(a); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SimpleInteger.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SimpleInteger.java new file mode 100644 index 00000000..45bb561d --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SimpleInteger.java @@ -0,0 +1,8 @@ +public class SimpleInteger { + + public static void main(String[] args) { + int a = -2147483648; + System.out.println(a); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SimpleLong.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SimpleLong.java new file mode 100644 index 00000000..d4ddda9f --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SimpleLong.java @@ -0,0 +1,8 @@ +public class SimpleLong { + + public static void main(String[] args) { + long a = -9223372036854775808L; + System.out.println(a); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SimpleShort.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SimpleShort.java new file mode 100644 index 00000000..c3572d08 --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_1_integral_types_and_values/SimpleShort.java @@ -0,0 +1,8 @@ +public class SimpleShort { + + public static void main(String[] args) { + short a = -32768; + System.out.println(a); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_3_floating_point_types_formats_and_values/SampleTest.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_3_floating_point_types_formats_and_values/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_3_floating_point_types_formats_and_values/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_3_floating_point_types_formats_and_values/SimpleDouble.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_3_floating_point_types_formats_and_values/SimpleDouble.java new file mode 100644 index 00000000..17cf992d --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_3_floating_point_types_formats_and_values/SimpleDouble.java @@ -0,0 +1,8 @@ +public class SimpleDouble { + + public static void main(String[] args) { + double a = Double.MIN_VALUE; + System.out.println(a); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_3_floating_point_types_formats_and_values/SimpleFloat.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_3_floating_point_types_formats_and_values/SimpleFloat.java new file mode 100644 index 00000000..fd6e6934 --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_3_floating_point_types_formats_and_values/SimpleFloat.java @@ -0,0 +1,8 @@ +public class SimpleFloat { + + public static void main(String[] args) { + float a = Float.MIN_VALUE; + System.out.println(a); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_5_boolean_type_and_values/SampleTest.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_5_boolean_type_and_values/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_5_boolean_type_and_values/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_5_boolean_type_and_values/SimpleBoolean.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_5_boolean_type_and_values/SimpleBoolean.java new file mode 100644 index 00000000..9b7a47d7 --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_5_boolean_type_and_values/SimpleBoolean.java @@ -0,0 +1,8 @@ +public class SimpleBoolean { + + public static void main(String[] args) { + boolean a = false; + System.out.println(a); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/ExplicitInstancing.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/ExplicitInstancing.java new file mode 100644 index 00000000..0c178436 --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/ExplicitInstancing.java @@ -0,0 +1,19 @@ +public class ExplicitInstancing { + + public static void main(String[] args) { + Point p = null; + try { + p = (Point)Class.forName("Point").newInstance(); + } catch (Exception e) { + System.out.println(e); + } + System.out.println("passed"); + } +} + +class Point { + int x, y; + Point() { System.out.println("default"); } + Point(int x, int y) { this.x = x; this.y = y; } + static Point origin = new Point(0,0); +} \ No newline at end of file diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/ExplicitStaticInstance.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/ExplicitStaticInstance.java new file mode 100644 index 00000000..88787e7f --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/ExplicitStaticInstance.java @@ -0,0 +1,18 @@ +public class ExplicitStaticInstance { + + public static void main(String[] args) { + Point p = new Point(319, 455); + System.out.println("p.x = " + p.x); + System.out.println("p.y = " + p.y); + Point p1 = new Point(); + System.out.println("Point.origin.x = " + Point.origin.x); + System.out.println("passed"); + } +} + +class Point { + int x, y; + Point() { System.out.println("default"); } + Point(int x, int y) { this.x = x; this.y = y; } + static Point origin = new Point(0,0); +} \ No newline at end of file diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/ObjectArrayInitialization.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/ObjectArrayInitialization.java new file mode 100644 index 00000000..df0add24 --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/ObjectArrayInitialization.java @@ -0,0 +1,15 @@ +public class ObjectArrayInitialization { + + public static void main(String[] args) { + Point a[] = { new Point(0,0), new Point(1,1) }; + System.out.println("a[1].x = " + a[1].x); + System.out.println("passed"); + } +} + +class Point { + int x, y; + Point() { System.out.println("default"); } + Point(int x, int y) { this.x = x; this.y = y; } + static Point origin = new Point(0,0); +} \ No newline at end of file diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/PrimitiveAndReferenceIdentity.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/PrimitiveAndReferenceIdentity.java new file mode 100644 index 00000000..4c13c324 --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/PrimitiveAndReferenceIdentity.java @@ -0,0 +1,21 @@ +public class PrimitiveAndReferenceIdentity { + + public static void main(String[] args) { + int i1 = 3; + int i2 = i1; + i2 = 4; + System.out.print("i1==" + i1); + System.out.println(" but i2==" + i2); + Value v1 = new Value(); + v1.val = 5; + Value v2 = v1; + v2.val = 6; + System.out.print("v1.val==" + v1.val); + System.out.println(" and v2.val==" + v2.val); + System.out.println("passed"); + } +} + +class Value { + int val; +} \ No newline at end of file diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/SampleTest.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/SimpleObject.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/SimpleObject.java new file mode 100644 index 00000000..d2709aef --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_1_objects/SimpleObject.java @@ -0,0 +1,14 @@ +public class SimpleObject { + + public static void main(String[] args) { + Point p = new Point(); + System.out.println("p.x = " + p.x); + System.out.println("p.y = " + p.y); + System.out.println("passed"); + } +} + +class Point { + int x = 319; + int y = 455; +} \ No newline at end of file diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_2_class_object/SampleTest.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_2_class_object/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_2_class_object/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_2_class_object/SimpleObjectObject.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_2_class_object/SimpleObjectObject.java new file mode 100644 index 00000000..5eabb975 --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_2_class_object/SimpleObjectObject.java @@ -0,0 +1,12 @@ +public class SimpleObjectObject { + + public static void main(String[] args) { + String str = (String)method(); + System.out.println("str = " + str); + System.out.println("passed"); + } + + public static Object method() { + return "some"; + } +} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_3_class_string/SampleTest.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_3_class_string/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_3_class_string/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_3_class_string/SimpleStringObject.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_3_class_string/SimpleStringObject.java new file mode 100644 index 00000000..0b27af37 --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_3_reference_types_and_values/sec_4_3_3_class_string/SimpleStringObject.java @@ -0,0 +1,8 @@ +public class SimpleStringObject { + + public static void main(String[] args) { + String s = "some"; + System.out.println("s = " + s); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_4_type_variables/SampleTest.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_4_type_variables/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_4_type_variables/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_4_type_variables/SimpleTypeVars.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_4_type_variables/SimpleTypeVars.java new file mode 100644 index 00000000..57246dab --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_4_type_variables/SimpleTypeVars.java @@ -0,0 +1,39 @@ +public class SimpleTypeVars { + + public static void main(String[] args) { + CT ct = new CT(); + test(ct); + System.out.println("passed"); + } + + static void test(T t) { + t.mI(); // OK + t.mCPublic(); // OK + t.mCProtected(); // OK + t.mCPackage(); // OK + //t.mCPrivate(); // Compile-time error + } +} + +class C { + public void mCPublic() { + System.out.println("mCPublic()"); + } + protected void mCProtected() { + System.out.println("mCProtected()"); + } + void mCPackage() { + System.out.println("mCPackage()"); + } + private void mCPrivate() { + System.out.println("mCPrivate()"); + } +} +interface I { + void mI(); +} +class CT extends C implements I { + public void mI() { + System.out.println("mI()"); + } +} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_5_parametrized_types/sec_4_5_1_type_arguments_of_parameterized_types/SampleTest.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_5_parametrized_types/sec_4_5_1_type_arguments_of_parameterized_types/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_5_parametrized_types/sec_4_5_1_type_arguments_of_parameterized_types/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_5_parametrized_types/sec_4_5_1_type_arguments_of_parameterized_types/SimpleTypeArguments.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_5_parametrized_types/sec_4_5_1_type_arguments_of_parameterized_types/SimpleTypeArguments.java new file mode 100644 index 00000000..d4add37b --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_5_parametrized_types/sec_4_5_1_type_arguments_of_parameterized_types/SimpleTypeArguments.java @@ -0,0 +1,20 @@ +import java.util.Collection; +import java.util.ArrayList; + +public class SimpleTypeArguments { + + public static void main(String[] args) { + Collection cs = new ArrayList(); + cs.add("hello"); + cs.add("world"); + printCollection(cs); + System.out.println("passed"); + } + + static void printCollection(Collection c) { + // a wildcard collection + for (Object o : c) { + System.out.println(o); + } + } +} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_8_raw_types/SampleTest.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_8_raw_types/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_8_raw_types/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_8_raw_types/SimpleRawType.java b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_8_raw_types/SimpleRawType.java new file mode 100644 index 00000000..76c4985b --- /dev/null +++ b/src/test/resources/test_candidates/ch_4_types_values_variables/sec_4_8_raw_types/SimpleRawType.java @@ -0,0 +1,16 @@ +public class SimpleRawType { + + E value; + SimpleRawType(E v) { value = v; } + E get() { return value; } + void set(E v) { value = v; } + + public static void main(String[] args) { + SimpleRawType x = new SimpleRawType("abc"); + System.out.println(x.value); // OK, has type Object + System.out.println(x.get()); // OK, has type Object + x.set("def"); // unchecked warning + System.out.println(x.get()); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_1_identity_conversion/SampleTest.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_1_identity_conversion/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_1_identity_conversion/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_1_identity_conversion/SimpleIdentityConversion.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_1_identity_conversion/SimpleIdentityConversion.java new file mode 100644 index 00000000..5fc6c960 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_1_identity_conversion/SimpleIdentityConversion.java @@ -0,0 +1,9 @@ +public class SimpleIdentityConversion { + + public static void main(String[] args) { + int a = 319; + int b = (int) a; // Identity conversion + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/ByteWidening.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/ByteWidening.java new file mode 100644 index 00000000..f6b42897 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/ByteWidening.java @@ -0,0 +1,9 @@ +public class ByteWidening { + + public static void main(String[] args) { + byte a = 100; + short b = a; // Widening + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/CharWidening.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/CharWidening.java new file mode 100644 index 00000000..3d969878 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/CharWidening.java @@ -0,0 +1,9 @@ +public class CharWidening { + + public static void main(String[] args) { + char a = 102; + int b = a; // Widening + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/FloatWidening.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/FloatWidening.java new file mode 100644 index 00000000..0e1478d7 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/FloatWidening.java @@ -0,0 +1,9 @@ +public class FloatWidening { + + public static void main(String[] args) { + float a = 105f; + double b = a; // Widening + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/IntegerWidening.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/IntegerWidening.java new file mode 100644 index 00000000..e7ce516c --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/IntegerWidening.java @@ -0,0 +1,9 @@ +public class IntegerWidening { + + public static void main(String[] args) { + int a = 103; + float b = a; // Widening + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/LongWidening.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/LongWidening.java new file mode 100644 index 00000000..0dac2246 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/LongWidening.java @@ -0,0 +1,9 @@ +public class LongWidening { + + public static void main(String[] args) { + long a = 104L; + double b = a; // Widening + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/SampleTest.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/ShortWidening.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/ShortWidening.java new file mode 100644 index 00000000..a6fc9d51 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/ShortWidening.java @@ -0,0 +1,9 @@ +public class ShortWidening { + + public static void main(String[] args) { + short a = 101; + int b = a; // Widening + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/WideningExample.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/WideningExample.java new file mode 100644 index 00000000..6f836252 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_2_widening_primitive_conversion/WideningExample.java @@ -0,0 +1,9 @@ +public class WideningExample { + + public static void main(String[] args) { + int big = 1234567890; + float approx = big; + System.out.println("(big - (int) approx) = " + (big - (int) approx)); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/CharNarrowing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/CharNarrowing.java new file mode 100644 index 00000000..aa13617a --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/CharNarrowing.java @@ -0,0 +1,9 @@ +public class CharNarrowing { + + public static void main(String[] args) { + char a = 15001; + byte b = (byte) a; // Narrowing, possible information loss + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/DoubleNarrowing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/DoubleNarrowing.java new file mode 100644 index 00000000..cfdeaf53 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/DoubleNarrowing.java @@ -0,0 +1,9 @@ +public class DoubleNarrowing { + + public static void main(String[] args) { + double a = Double.MAX_VALUE; + float b = (float) a; // Narrowing, possible information loss + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/FloatNarrowing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/FloatNarrowing.java new file mode 100644 index 00000000..f166a7b9 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/FloatNarrowing.java @@ -0,0 +1,9 @@ +public class FloatNarrowing { + + public static void main(String[] args) { + float a = Float.MAX_VALUE; + int b = (int) a; // Narrowing, possible information loss + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/IntNarrowing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/IntNarrowing.java new file mode 100644 index 00000000..0d5a2a55 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/IntNarrowing.java @@ -0,0 +1,9 @@ +public class IntNarrowing { + + public static void main(String[] args) { + int a = 15002; + byte b = (byte) a; // Narrowing, possible information loss + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/LongNarrowing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/LongNarrowing.java new file mode 100644 index 00000000..7732bbbf --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/LongNarrowing.java @@ -0,0 +1,9 @@ +public class LongNarrowing { + + public static void main(String[] args) { + long a = 15000000000L; + int b = (int) a; // Narrowing, possible information loss + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/SampleTest.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/ShortNarrowing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/ShortNarrowing.java new file mode 100644 index 00000000..7f785e42 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_3_narrowing_primitive_conversion/ShortNarrowing.java @@ -0,0 +1,9 @@ +public class ShortNarrowing { + + public static void main(String[] args) { + short a = 15000; + byte b = (byte) a; // Narrowing, possible information loss + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/BooleanBoxing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/BooleanBoxing.java new file mode 100644 index 00000000..930afdab --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/BooleanBoxing.java @@ -0,0 +1,9 @@ +public class BooleanBoxing { + + public static void main(String[] args) { + boolean a = false; + Boolean b = a; + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/ByteBoxing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/ByteBoxing.java new file mode 100644 index 00000000..b5376c74 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/ByteBoxing.java @@ -0,0 +1,9 @@ +public class ByteBoxing { + + public static void main(String[] args) { + byte a = 42; + Byte b = a; + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/CharBoxing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/CharBoxing.java new file mode 100644 index 00000000..0ca94ccb --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/CharBoxing.java @@ -0,0 +1,9 @@ +public class CharBoxing { + + public static void main(String[] args) { + char a = '\u1234'; + Character b = a; + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/DoubleBoxing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/DoubleBoxing.java new file mode 100644 index 00000000..4ac5918a --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/DoubleBoxing.java @@ -0,0 +1,9 @@ +public class DoubleBoxing { + + public static void main(String[] args) { + double a = 1.005; + Double b = a; + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/FloatBoxing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/FloatBoxing.java new file mode 100644 index 00000000..27ab48c2 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/FloatBoxing.java @@ -0,0 +1,9 @@ +public class FloatBoxing { + + public static void main(String[] args) { + float a = 1.5f; + Float b = a; + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/IntBoxing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/IntBoxing.java new file mode 100644 index 00000000..1970c526 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/IntBoxing.java @@ -0,0 +1,9 @@ +public class IntBoxing { + + public static void main(String[] args) { + int a = 123456; + Integer b = a; + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/LongBoxing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/LongBoxing.java new file mode 100644 index 00000000..16c42054 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/LongBoxing.java @@ -0,0 +1,9 @@ +public class LongBoxing { + + public static void main(String[] args) { + long a = 15000000000L; + Long b = a; + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/SampleTest.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/ShortBoxing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/ShortBoxing.java new file mode 100644 index 00000000..ea083000 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_7_boxing_conversion/ShortBoxing.java @@ -0,0 +1,9 @@ +public class ShortBoxing { + + public static void main(String[] args) { + short a = 12345; + Short b = a; + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/BooleanUnboxing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/BooleanUnboxing.java new file mode 100644 index 00000000..fa0fbee7 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/BooleanUnboxing.java @@ -0,0 +1,9 @@ +public class BooleanUnboxing { + + public static void main(String[] args) { + Boolean a = false; + boolean b = a.booleanValue(); + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/ByteUnboxing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/ByteUnboxing.java new file mode 100644 index 00000000..23f1c563 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/ByteUnboxing.java @@ -0,0 +1,9 @@ +public class ByteUnboxing { + + public static void main(String[] args) { + Byte a = 100; + byte b = a.byteValue(); + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/CharUnboxing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/CharUnboxing.java new file mode 100644 index 00000000..5f5b7963 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/CharUnboxing.java @@ -0,0 +1,9 @@ +public class CharUnboxing { + + public static void main(String[] args) { + Character a = 100; + char b = a.charValue(); + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/DoubleUnboxing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/DoubleUnboxing.java new file mode 100644 index 00000000..79cbe657 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/DoubleUnboxing.java @@ -0,0 +1,9 @@ +public class DoubleUnboxing { + + public static void main(String[] args) { + Double a = 100.0; + double b = a.doubleValue(); + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/FloatUnboxing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/FloatUnboxing.java new file mode 100644 index 00000000..09d29331 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/FloatUnboxing.java @@ -0,0 +1,9 @@ +public class FloatUnboxing { + + public static void main(String[] args) { + Float a = 100f; + float b = a.floatValue(); + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/IntUnboxing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/IntUnboxing.java new file mode 100644 index 00000000..9d6d684a --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/IntUnboxing.java @@ -0,0 +1,9 @@ +public class IntUnboxing { + + public static void main(String[] args) { + Integer a = 100; + int b = a.intValue(); + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/LongUnboxing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/LongUnboxing.java new file mode 100644 index 00000000..ca858707 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/LongUnboxing.java @@ -0,0 +1,9 @@ +public class LongUnboxing { + + public static void main(String[] args) { + Long a = 100L; + long b = a.longValue(); + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/SampleTest.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/ShortUnboxing.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/ShortUnboxing.java new file mode 100644 index 00000000..dfe7abd3 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_1_kinds_of_conversions/sec_5_1_8_unboxing_conversion/ShortUnboxing.java @@ -0,0 +1,9 @@ +public class ShortUnboxing { + + public static void main(String[] args) { + Short a = 100; + short b = a.shortValue(); + System.out.println("b = " + b); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_2_assignment_contexts/AssignmentContextExample.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_2_assignment_contexts/AssignmentContextExample.java new file mode 100644 index 00000000..910a2419 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_2_assignment_contexts/AssignmentContextExample.java @@ -0,0 +1,15 @@ +public class AssignmentContextExample { + + public static void main(String[] args) { + short s = 12; // narrow 12 to short + float f = s; // widen short to float + System.out.println("f=" + f); + char c = '\u0123'; + long l = c; // widen char to long + System.out.println("l=0x" + Long.toString(l,16)); + f = 1.23f; + double d = f; // widen float to double + System.out.println("d=" + d); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_2_assignment_contexts/AssignmentForReferenceTypes.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_2_assignment_contexts/AssignmentForReferenceTypes.java new file mode 100644 index 00000000..deed6703 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_2_assignment_contexts/AssignmentForReferenceTypes.java @@ -0,0 +1,27 @@ +public class AssignmentForReferenceTypes { + + public static void main(String[] args) { + Point p = new Point(); + p = new Point3D(); + //Point3D p3d = p; + Object o = p; + int[] a = new int[3]; + Object o2 = a; + ColoredPoint cp = new ColoredPoint(); + Colorable c = cp; + byte[] b = new byte[4]; + //a = b; + Point3D[] p3da = new Point3D[3]; + Point[] pa = p3da; + //p3da = pa; + System.out.println("passed"); + } +} +class Point { int x, y; } +class Point3D extends Point { int z; } +interface Colorable { void setColor(int color); } +class ColoredPoint extends Point implements Colorable { + int color; + public void setColor(int color) { this.color = color; } +} + diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_2_assignment_contexts/SampleTest.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_2_assignment_contexts/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_2_assignment_contexts/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_5_casting_contexts/CastingForReferenceTypes.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_5_casting_contexts/CastingForReferenceTypes.java new file mode 100644 index 00000000..5a01c736 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_5_casting_contexts/CastingForReferenceTypes.java @@ -0,0 +1,21 @@ +public class CastingForReferenceTypes { + + public static void main(String[] args) { + Point p = new Point(); + ColoredPoint cp = new ColoredPoint(); + Colorable c; + //cp = (ColoredPoint)p; // p might not reference an + //c = (Colorable)p; // p might not be Colorable + //Long l = (Long)p; // compile-time error #1 + EndPoint e = new EndPoint(); + //c = (Colorable)e; // compile-time error #2 + System.out.println("passed"); + } +} +class Point { int x, y; } +interface Colorable { void setColor(int color); } +class ColoredPoint extends Point implements Colorable { + int color; + public void setColor(int color) { this.color = color; } +} +final class EndPoint extends Point {} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_5_casting_contexts/SampleTest.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_5_casting_contexts/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_5_casting_contexts/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_6_numeric_contexts/SampleTest.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_6_numeric_contexts/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_6_numeric_contexts/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_6_numeric_contexts/UnaryNumericPromotion.java b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_6_numeric_contexts/UnaryNumericPromotion.java new file mode 100644 index 00000000..737b8fb6 --- /dev/null +++ b/src/test/resources/test_candidates/ch_5_conversions_and_contexts/sec_5_6_numeric_contexts/UnaryNumericPromotion.java @@ -0,0 +1,19 @@ +public class UnaryNumericPromotion { + + public static void main(String[] args) { + byte b = 2; + int a[] = new int[b]; // dimension expression promotion + char c = '\u0001'; + a[c] = 1; // index expression promotion + a[0] = -c; // unary - promotion + System.out.println("a: " + a[0] + "," + a[1]); + b = -1; + int i = ~b; // bitwise complement promotion + System.out.println("~0x" + Integer.toHexString(b) + + "==0x" + Integer.toHexString(i)); + i = b << 4L; // shift promotion (left operand) + System.out.println("0x" + Integer.toHexString(b) + + "<<4L==0x" + Integer.toHexString(i)); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_1_declarations/SimpleDeclaration.java b/src/test/resources/test_candidates/ch_6_names/sec_6_1_declarations/SimpleDeclaration.java new file mode 100644 index 00000000..f7af5014 --- /dev/null +++ b/src/test/resources/test_candidates/ch_6_names/sec_6_1_declarations/SimpleDeclaration.java @@ -0,0 +1,7 @@ + +public class SimpleDeclaration { + int i; + public static void main(String[] args) { + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_1_declarations/SimpleDeclarationWithInstantiation.java b/src/test/resources/test_candidates/ch_6_names/sec_6_1_declarations/SimpleDeclarationWithInstantiation.java new file mode 100644 index 00000000..9c3a57f8 --- /dev/null +++ b/src/test/resources/test_candidates/ch_6_names/sec_6_1_declarations/SimpleDeclarationWithInstantiation.java @@ -0,0 +1,7 @@ + +public class SimpleDeclarationWithInstantiation { + int i = 1; + public static void main(String[] args) { + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_2_names_and_identifiers/SampleTest.java b/src/test/resources/test_candidates/ch_6_names/sec_6_2_names_and_identifiers/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_6_names/sec_6_2_names_and_identifiers/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_2_names_and_identifiers/SimplePrivate.java b/src/test/resources/test_candidates/ch_6_names/sec_6_2_names_and_identifiers/SimplePrivate.java new file mode 100644 index 00000000..f1f48151 --- /dev/null +++ b/src/test/resources/test_candidates/ch_6_names/sec_6_2_names_and_identifiers/SimplePrivate.java @@ -0,0 +1,7 @@ + +public class SimplePrivate { + private int i; + public static void main(String[] args) { + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_2_names_and_identifiers/SimplePublic.java b/src/test/resources/test_candidates/ch_6_names/sec_6_2_names_and_identifiers/SimplePublic.java new file mode 100644 index 00000000..9dddffd3 --- /dev/null +++ b/src/test/resources/test_candidates/ch_6_names/sec_6_2_names_and_identifiers/SimplePublic.java @@ -0,0 +1,7 @@ + +public class SimplePublic { + public int i; + public static void main(String[] args) { + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_2_names_and_identifiers/SimpleStatic.java b/src/test/resources/test_candidates/ch_6_names/sec_6_2_names_and_identifiers/SimpleStatic.java new file mode 100644 index 00000000..1f2caf93 --- /dev/null +++ b/src/test/resources/test_candidates/ch_6_names/sec_6_2_names_and_identifiers/SimpleStatic.java @@ -0,0 +1,7 @@ + +public class SimpleStatic { + static int i; + public static void main(String[] args) { + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/ScopeOfVarDeclr1.java b/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/ScopeOfVarDeclr1.java new file mode 100644 index 00000000..eaabfa3b --- /dev/null +++ b/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/ScopeOfVarDeclr1.java @@ -0,0 +1,8 @@ +public class ScopeOfLocalVarDeclr1 { + static int x; + public static void main(String[] args) { + int x = (x = 2) * 2; + System.out.println("x = " + x); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/ScopeOfVarDeclr2.java b/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/ScopeOfVarDeclr2.java new file mode 100644 index 00000000..bf9719b2 --- /dev/null +++ b/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/ScopeOfVarDeclr2.java @@ -0,0 +1,9 @@ +public class ScopeOfLocalVarDeclr1 { + static int x; + public static void main(String[] args) { + System.out.print("2+1="); + int two = 2, three = two + 1; + System.out.println(three); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_2_if_statements/IfVarScopeFalseBlock.java b/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_2_if_statements/IfVarScopeFalseBlock.java new file mode 100644 index 00000000..aa547c29 --- /dev/null +++ b/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_2_if_statements/IfVarScopeFalseBlock.java @@ -0,0 +1,14 @@ +public class IfVarScopeTrueBlock { + + public static void main(String[] args) { + Object str = "some2"; + if (!(str instanceof String s)) { + //str = "some3"; // ERROR + System.out.println("failed"); + } else { + s = s + "_mod"; + System.out.println("s = " + s); + } + System.out.println("passed"); + } +} \ No newline at end of file diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_2_if_statements/IfVarScopeTrueBlock.java b/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_2_if_statements/IfVarScopeTrueBlock.java new file mode 100644 index 00000000..5aeb714b --- /dev/null +++ b/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_2_if_statements/IfVarScopeTrueBlock.java @@ -0,0 +1,13 @@ +public class IfVarScopeTrueBlock { + + public static void main(String[] args) { + Object str = "some"; + if (str instanceof String s) { + s = s + "_mod"; + System.out.println("s = " + s); + } else { + System.out.println("failed"); + } + System.out.println("passed"); + } +} \ No newline at end of file diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_2_if_statements/SampleTest.java b/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_2_if_statements/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_2_if_statements/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_2_if_statements/SimpleIfStatement.java b/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_2_if_statements/SimpleIfStatement.java new file mode 100644 index 00000000..0fd02a78 --- /dev/null +++ b/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_2_if_statements/SimpleIfStatement.java @@ -0,0 +1,11 @@ + +public class SimpleIfStatement { + public static void main(String[] args) { + if (true) { + System.out.println("pass"); + } else { + System.out.println("error"); + } + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_3_while_statements/SampleTest.java b/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_3_while_statements/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_3_while_statements/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_3_while_statements/SimpleWhileStatetment.java b/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_3_while_statements/SimpleWhileStatetment.java new file mode 100644 index 00000000..680cba5c --- /dev/null +++ b/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_3_while_statements/SimpleWhileStatetment.java @@ -0,0 +1,11 @@ + +public class SimpleWhileStatetment { + public static void main(String[] args) { + int i = 0; + while (i < 5) { + System.out.println("while"); + i++; + } + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_5_for_statements/SampleTest.java b/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_5_for_statements/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_5_for_statements/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_5_for_statements/SimpleForStatement.java b/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_5_for_statements/SimpleForStatement.java new file mode 100644 index 00000000..fdfc9c37 --- /dev/null +++ b/src/test/resources/test_candidates/ch_6_names/sec_6_3_scope_of_a_declaration/sec_6_3_2_scope_for_pattern_vars_in_statements/sec_6_3_2_5_for_statements/SimpleForStatement.java @@ -0,0 +1,9 @@ + +public class SimpleForStatement { + public static void main(String[] args) { + for (int i = 0; i < 5; i++) { + System.out.println("for"); + } + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_4_shadowing_and_obscuring/sec_6_4_1_shadowing/SampleTest.java b/src/test/resources/test_candidates/ch_6_names/sec_6_4_shadowing_and_obscuring/sec_6_4_1_shadowing/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_6_names/sec_6_4_shadowing_and_obscuring/sec_6_4_1_shadowing/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_4_shadowing_and_obscuring/sec_6_4_1_shadowing/ShadowingOfFieldDeclrByLocalVarDeclr.java b/src/test/resources/test_candidates/ch_6_names/sec_6_4_shadowing_and_obscuring/sec_6_4_1_shadowing/ShadowingOfFieldDeclrByLocalVarDeclr.java new file mode 100644 index 00000000..4717af9b --- /dev/null +++ b/src/test/resources/test_candidates/ch_6_names/sec_6_4_shadowing_and_obscuring/sec_6_4_1_shadowing/ShadowingOfFieldDeclrByLocalVarDeclr.java @@ -0,0 +1,10 @@ +public class ShadowingOfFieldDecrlByLocalVarDeclr { + + static int x = 1; + public static void main(String[] args) { + int x = 0; + System.out.print("x=" + x); + System.out.println(", ShadowingOfFieldDecrlByLocalVarDeclr.x=" + ShadowingOfFieldDecrlByLocalVarDeclr.x); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_4_shadowing_and_obscuring/sec_6_4_1_shadowing/ShadowingOfLocalVar.java b/src/test/resources/test_candidates/ch_6_names/sec_6_4_shadowing_and_obscuring/sec_6_4_1_shadowing/ShadowingOfLocalVar.java new file mode 100644 index 00000000..40eaefcd --- /dev/null +++ b/src/test/resources/test_candidates/ch_6_names/sec_6_4_shadowing_and_obscuring/sec_6_4_1_shadowing/ShadowingOfLocalVar.java @@ -0,0 +1,14 @@ +public class ShadowingOfLocalVar { + + public static void main(String[] args) { + int i; + class Local { + { + for (int i = 0; i < 10; i++) + System.out.println(i); + } + } + new Local(); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_4_shadowing_and_obscuring/sec_6_4_1_shadowing/ShadowingOfTypeDeclrByAnotherTypeDeclr.java b/src/test/resources/test_candidates/ch_6_names/sec_6_4_shadowing_and_obscuring/sec_6_4_1_shadowing/ShadowingOfTypeDeclrByAnotherTypeDeclr.java new file mode 100644 index 00000000..33c1acdb --- /dev/null +++ b/src/test/resources/test_candidates/ch_6_names/sec_6_4_shadowing_and_obscuring/sec_6_4_1_shadowing/ShadowingOfTypeDeclrByAnotherTypeDeclr.java @@ -0,0 +1,13 @@ +import java.util.*; + +public class ShadowingOfTypeDeclrByAnotherTypeDeclr { + + public static void main(String[] args) { + Vector v = new Vector(); + System.out.println(v.val[0]); + System.out.println("passed"); + } +} +class Vector { + int val[] = { 1 , 2 }; +} \ No newline at end of file diff --git a/src/test/resources/test_candidates/ch_6_names/sec_6_4_shadowing_and_obscuring/sec_6_4_1_shadowing/ShadowingPatternMatching.java b/src/test/resources/test_candidates/ch_6_names/sec_6_4_shadowing_and_obscuring/sec_6_4_1_shadowing/ShadowingPatternMatching.java new file mode 100644 index 00000000..32d038d8 --- /dev/null +++ b/src/test/resources/test_candidates/ch_6_names/sec_6_4_shadowing_and_obscuring/sec_6_4_1_shadowing/ShadowingPatternMatching.java @@ -0,0 +1,26 @@ +public class ShadowingPatternMatching { + + static void test(Object a, Object b, Object c) { + if (a instanceof Point p) { + System.out.println("a is a point ("+p.x+","+p.y+")"); + } + if (b instanceof Point p){ + System.out.println("b is a point ("+p.x+","+p.y+")"); + } + if (c instanceof Point p) { + System.out.println("c is a point ("+p.x+","+p.y+")"); + } + } + + public static void main(String[] args) { + Point p = new Point(2,3); + Point q = new Point(4,5); + Point r = new Point(6,7); + test(p, q, r); + System.out.println("passed"); + } +} +class Point { + int x, y; + Point(int x, int y) { this.x = x; this.y = y; } +} \ No newline at end of file diff --git a/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_2_generic_classes_and_type_params/SampleTest.java b/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_2_generic_classes_and_type_params/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_2_generic_classes_and_type_params/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_2_generic_classes_and_type_params/SimpleGenericClass.java b/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_2_generic_classes_and_type_params/SimpleGenericClass.java new file mode 100644 index 00000000..bd87bc78 --- /dev/null +++ b/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_2_generic_classes_and_type_params/SimpleGenericClass.java @@ -0,0 +1,14 @@ + +public class SimpleGenericClass { + + public static void main(String[] args) { + Generic g = new Generic(); + g.method("passed"); + } +} + +class Generic { + void method(T arg) { + System.out.println((String)arg); + } +} diff --git a/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_3_inner_classes_and_enclosing_instances/SampleTest.java b/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_3_inner_classes_and_enclosing_instances/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_3_inner_classes_and_enclosing_instances/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_3_inner_classes_and_enclosing_instances/SimpleInnerClass.java b/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_3_inner_classes_and_enclosing_instances/SimpleInnerClass.java new file mode 100644 index 00000000..f4d9d7d2 --- /dev/null +++ b/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_3_inner_classes_and_enclosing_instances/SimpleInnerClass.java @@ -0,0 +1,30 @@ + +public class SimpleInnerClass { + + public static void main(String[] args) { + Outer o = new Outer(); + //Inner i = new Inner(); + Outer.Inner.hello(); + System.out.println("passed"); + } +} +class HasStatic { + static int j = 100; +} +class Outer { + class Inner extends HasStatic { + static { + System.out.println("Hello from Outer.Inner"); + } + static int x = 3; + static final int y = 4; + static void hello() { + System.out.println("Hello from Outer.Inner.hello"); + } + static class VeryNestedButNotInner extends NestedButNotInner {} + } + static class NestedButNotInner { + int z = Inner.x; + } + interface NeverInner {} // Implicitly static, so never inner +} diff --git a/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_4_superclasses_and_subclasses/SampleTest.java b/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_4_superclasses_and_subclasses/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_4_superclasses_and_subclasses/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_4_superclasses_and_subclasses/SimpleClassExtend.java b/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_4_superclasses_and_subclasses/SimpleClassExtend.java new file mode 100644 index 00000000..ef0658ae --- /dev/null +++ b/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_4_superclasses_and_subclasses/SimpleClassExtend.java @@ -0,0 +1,16 @@ + +public class SimpleClassExtend { + + public static void main(String[] args) { + Sub s = new Sub(); + s.method(); + } +} + +class Base { + void method() { System.out.println("passed"); } +} + +class Sub extends Base { + void otherMethod() {} +} diff --git a/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_5_superinterfaces/SampleTest.java b/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_5_superinterfaces/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_5_superinterfaces/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_5_superinterfaces/SimpleSuperinterface.java b/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_5_superinterfaces/SimpleSuperinterface.java new file mode 100644 index 00000000..3e254e63 --- /dev/null +++ b/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_5_superinterfaces/SimpleSuperinterface.java @@ -0,0 +1,18 @@ + +public class SimpleSuperinterface { + + public static void main(String[] args) { + Lion l = new Lion(); + l.say(); + } +} + +interface IAnimal { + void say(); +} + +class Lion implements IAnimal { + public void say() { + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_6_class_body_and_member_declrs/SampleTest.java b/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_6_class_body_and_member_declrs/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_8_classes/sec_8_1_class_declarations/sec_8_1_6_class_body_and_member_declrs/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_8_classes/sec_8_2_class_members/SampleTest.java b/src/test/resources/test_candidates/ch_8_classes/sec_8_2_class_members/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_8_classes/sec_8_2_class_members/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_8_classes/sec_8_2_class_members/SimpleClassMembers.java b/src/test/resources/test_candidates/ch_8_classes/sec_8_2_class_members/SimpleClassMembers.java new file mode 100644 index 00000000..572ad286 --- /dev/null +++ b/src/test/resources/test_candidates/ch_8_classes/sec_8_2_class_members/SimpleClassMembers.java @@ -0,0 +1,20 @@ +public class SimpleClassMembers { + public static void main(String[] args) { + ColoredPoint c = new ColoredPoint(0, 0); + c.reset(); + System.out.println("passed"); + } +} + +class Point { + int x, y; + private Point() { reset(); } + Point(int x, int y) { this.x = x; this.y = y; } + void reset() { this.x = 0; this.y = 0; } +} + +class ColoredPoint extends Point { + int color; + ColoredPoint(int x, int y) { super(x, y); color = 0; } +} + diff --git a/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_8_inheritance_overrideing_and_hiding/sec_8_4_8_1_overriding_by_instance_methods/SampleTest.java b/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_8_inheritance_overrideing_and_hiding/sec_8_4_8_1_overriding_by_instance_methods/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_8_inheritance_overrideing_and_hiding/sec_8_4_8_1_overriding_by_instance_methods/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_8_inheritance_overrideing_and_hiding/sec_8_4_8_1_overriding_by_instance_methods/SimpleOverriding.java b/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_8_inheritance_overrideing_and_hiding/sec_8_4_8_1_overriding_by_instance_methods/SimpleOverriding.java new file mode 100644 index 00000000..bb34fa77 --- /dev/null +++ b/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_8_inheritance_overrideing_and_hiding/sec_8_4_8_1_overriding_by_instance_methods/SimpleOverriding.java @@ -0,0 +1,26 @@ + +public class SimpleOverriding { + + public static void main(String[] args) { + SlowPoint p = new SlowPoint(); + p.xLimit = 10; + p.yLimit = 15; + p.move(100, -100); + + System.out.println("x: " + p.x + ", y: " + p.y); + System.out.println("passed"); + } +} +class Point { + int x = 0, y = 0; + void move(int dx, int dy) { x += dx; y += dy; } +} +class SlowPoint extends Point { + int xLimit, yLimit; + void move(int dx, int dy) { + super.move(limit(dx, xLimit), limit(dy, yLimit)); + } + static int limit(int d, int limit) { + return d > limit ? limit : d < -limit ? -limit : d; + } +} diff --git a/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_8_inheritance_overrideing_and_hiding/sec_8_4_8_2_hiding_by_class_methods/SampleTest.java b/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_8_inheritance_overrideing_and_hiding/sec_8_4_8_2_hiding_by_class_methods/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_8_inheritance_overrideing_and_hiding/sec_8_4_8_2_hiding_by_class_methods/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_8_inheritance_overrideing_and_hiding/sec_8_4_8_2_hiding_by_class_methods/SimpleHiding.java b/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_8_inheritance_overrideing_and_hiding/sec_8_4_8_2_hiding_by_class_methods/SimpleHiding.java new file mode 100644 index 00000000..37906342 --- /dev/null +++ b/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_8_inheritance_overrideing_and_hiding/sec_8_4_8_2_hiding_by_class_methods/SimpleHiding.java @@ -0,0 +1,18 @@ + +class Super { + static String greeting() { return "Goodnight"; } + String name() { return "Richard"; } +} + +class Sub extends Super { + static String greeting() { return "Hello"; } + String name() { return "Dick"; } +} + +class SimpleHiding { + public static void main(String[] args) { + Super s = new Sub(); + System.out.println(s.greeting() + ", " + s.name()); + System.out.println("passed"); + } +} diff --git a/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_9_overloading/SampleTest.java b/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_9_overloading/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_9_overloading/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_9_overloading/SimpleOverloading.java b/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_9_overloading/SimpleOverloading.java new file mode 100644 index 00000000..5e12b989 --- /dev/null +++ b/src/test/resources/test_candidates/ch_8_classes/sec_8_4_method_declarations/sec_8_4_9_overloading/SimpleOverloading.java @@ -0,0 +1,19 @@ + +public class SimpleOverloading { + + public static void main(String[] args) { + Point p = new Point(); + p.x = 0; + p.y = 0; + p.move(10, -10); + System.out.println(p); + System.out.println("passed"); + } +} + +class Point { + float x, y; + void move(int dx, int dy) { x += dx; y += dy; } + void move(float dx, float dy) { x += dx; y += dy; } + public String toString() { return "("+x+","+y+")"; } +} diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_1_interface_modifiers/sec_9_1_1_1_abstract_interfaces/SampleTest.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_1_interface_modifiers/sec_9_1_1_1_abstract_interfaces/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_1_interface_modifiers/sec_9_1_1_1_abstract_interfaces/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_1_interface_modifiers/sec_9_1_1_2_strictfp_interfaces/SampleTest.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_1_interface_modifiers/sec_9_1_1_2_strictfp_interfaces/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_1_interface_modifiers/sec_9_1_1_2_strictfp_interfaces/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_1_interface_modifiers/sec_9_1_1_2_strictfp_interfaces/SimpleStrictfpInterface.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_1_interface_modifiers/sec_9_1_1_2_strictfp_interfaces/SimpleStrictfpInterface.java new file mode 100644 index 00000000..0843e41b --- /dev/null +++ b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_1_interface_modifiers/sec_9_1_1_2_strictfp_interfaces/SimpleStrictfpInterface.java @@ -0,0 +1,19 @@ +public class SimpleStrictfpInterface { + + public static void main(String[] args) { + new Work().doSomething(); + System.out.println("passed"); + } +} + +strictfp interface IDoable { + void doSomething(); +} + +class Work implements IDoable { + @Override + public void doSomething() { + double some_val = 2.8 * 3.9; + System.out.println("working... " + some_val); + } +} diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_1_interface_modifiers/sec_9_1_1_3_static_interfaces/SampleTest.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_1_interface_modifiers/sec_9_1_1_3_static_interfaces/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_1_interface_modifiers/sec_9_1_1_3_static_interfaces/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_1_interface_modifiers/sec_9_1_1_3_static_interfaces/SimpleStaticInterface.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_1_interface_modifiers/sec_9_1_1_3_static_interfaces/SimpleStaticInterface.java new file mode 100644 index 00000000..0b6f5ab9 --- /dev/null +++ b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_1_interface_modifiers/sec_9_1_1_3_static_interfaces/SimpleStaticInterface.java @@ -0,0 +1,21 @@ +public class SimpleStaticInterface { + + public static void main(String[] args) { + new Work().doNestedSomething(); + System.out.println("passed"); + } +} + +interface IDoable { + void doSomething(); + public static interface INestedDoable { + void doNestedSomething(); + } +} + +class Work implements IDoable.INestedDoable { + @Override + public void doNestedSomething() { + System.out.println("doing nested work..."); + } +} diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_2_generic_interfaces_and_type_parameters/SampleTest.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_2_generic_interfaces_and_type_parameters/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_2_generic_interfaces_and_type_parameters/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_2_generic_interfaces_and_type_parameters/SimpleGenericInterface.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_2_generic_interfaces_and_type_parameters/SimpleGenericInterface.java new file mode 100644 index 00000000..60bdc56c --- /dev/null +++ b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_2_generic_interfaces_and_type_parameters/SimpleGenericInterface.java @@ -0,0 +1,18 @@ +public class SimpleGenericInterface { + + public static void main(String[] args) { + System.out.println(new Work().perform()); + System.out.println("passed"); + } +} + +interface IDoable { + T perform(); +} + +class Work implements IDoable { + @Override + public String perform() { + return "working on it..."; + } +} \ No newline at end of file diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_3_superinterfaces_and_subinterfaces/SampleTest.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_3_superinterfaces_and_subinterfaces/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_3_superinterfaces_and_subinterfaces/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_3_superinterfaces_and_subinterfaces/SimpleSupAndSubInterfaces.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_3_superinterfaces_and_subinterfaces/SimpleSupAndSubInterfaces.java new file mode 100644 index 00000000..a46c0388 --- /dev/null +++ b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_1_interface_declarations/sec_9_1_3_superinterfaces_and_subinterfaces/SimpleSupAndSubInterfaces.java @@ -0,0 +1,28 @@ +public class SimpleSupAndSubInterfaces { + + public static void main(String[] args) { + new Work().perform(); + System.out.println("passed"); + } +} + +interface IExisting { + void toBe(); +} + +interface IDoable extends IExisting { + void perform(); +} + +class Work implements IDoable { + @Override + public void toBe() { + System.out.println("exising in da world..."); + } + + @Override + public void perform() { + toBe(); + System.out.println("performing a job..."); + } +} \ No newline at end of file diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_3_field_constant_declarations/sec_9_3_1_init_of_fields_in_interfaces/SampleTest.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_3_field_constant_declarations/sec_9_3_1_init_of_fields_in_interfaces/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_3_field_constant_declarations/sec_9_3_1_init_of_fields_in_interfaces/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_3_field_constant_declarations/sec_9_3_1_init_of_fields_in_interfaces/SimpleInterfaceConstants.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_3_field_constant_declarations/sec_9_3_1_init_of_fields_in_interfaces/SimpleInterfaceConstants.java new file mode 100644 index 00000000..0d105cf7 --- /dev/null +++ b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_3_field_constant_declarations/sec_9_3_1_init_of_fields_in_interfaces/SimpleInterfaceConstants.java @@ -0,0 +1,13 @@ +public class SimpleInterfaceConstants { + + public static void main(String[] args) { + System.out.println(ITest.k); + System.out.println("passed"); + } +} + +interface ITest { + int j = 1; + float f = j; + int k = (int)f + 1; +} \ No newline at end of file diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_1_inheritance_and_overriding/SimpleInterfaceInheritanceNOverride.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_1_inheritance_and_overriding/SimpleInterfaceInheritanceNOverride.java new file mode 100644 index 00000000..3eb1f787 --- /dev/null +++ b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_1_inheritance_and_overriding/SimpleInterfaceInheritanceNOverride.java @@ -0,0 +1,16 @@ +public class SimpleInterfaceInheritanceNOverride { + + public static void main(String[] args) { + System.out.println(new Test().name()); + System.out.println("passed"); + } +} +interface Top { + default String name() { return "unnamed"; } +} +interface Left extends Top { + default String name() { return getClass().getName(); } +} +interface Right extends Top {} +interface Bottom extends Left, Right {} +class Test implements Bottom {} \ No newline at end of file diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_1_inheritance_and_overriding/sec_9_4_1_1_overriding_by_instance_methods/SampleTest.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_1_inheritance_and_overriding/sec_9_4_1_1_overriding_by_instance_methods/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_1_inheritance_and_overriding/sec_9_4_1_1_overriding_by_instance_methods/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_1_inheritance_and_overriding/sec_9_4_1_2_requirements_in_overriding/SampleTest.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_1_inheritance_and_overriding/sec_9_4_1_2_requirements_in_overriding/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_1_inheritance_and_overriding/sec_9_4_1_2_requirements_in_overriding/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_1_inheritance_and_overriding/sec_9_4_1_3_inheriting_methods_with_override_equivalent_signatures/SampleTest.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_1_inheritance_and_overriding/sec_9_4_1_3_inheriting_methods_with_override_equivalent_signatures/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_1_inheritance_and_overriding/sec_9_4_1_3_inheriting_methods_with_override_equivalent_signatures/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_2_overloading/SampleTest.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_2_overloading/SampleTest.java deleted file mode 100644 index 2c897dfb..00000000 --- a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_2_overloading/SampleTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eolang.j2eo; - -public class SampleTest { - - public static void Main (String[] args) { - - } - -} diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_2_overloading/SimpleInterfaceOverloading.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_2_overloading/SimpleInterfaceOverloading.java new file mode 100644 index 00000000..b2e0a35b --- /dev/null +++ b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_4_method_declarations/sec_9_4_2_overloading/SimpleInterfaceOverloading.java @@ -0,0 +1,32 @@ +public class SimpleInterfaceOverloading { + + public static void main(String[] args) { + new Point().move(5, 6); + new Point().move(4.0, 4.0); + new Point().move(4f, 4f); + System.out.println("passed"); + } +} +interface PointInterface { + void move(int dx, int dy); +} +interface RealPointInterface extends PointInterface { + void move(float dx, float dy); + void move(double dx, double dy); +} +class Point implements RealPointInterface { + @Override + public void move(int dx, int dy) { + System.out.println("int move"); + } + + @Override + public void move(float dx, float dy) { + System.out.println("float move"); + } + + @Override + public void move(double dx, double dy) { + System.out.println("double move"); + } +} \ No newline at end of file diff --git a/src/test/resources/test_candidates/ch_9_interfaces/sec_9_6_annotation_interfaces/SimpleAnnotationInterface.java b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_6_annotation_interfaces/SimpleAnnotationInterface.java new file mode 100644 index 00000000..72582a01 --- /dev/null +++ b/src/test/resources/test_candidates/ch_9_interfaces/sec_9_6_annotation_interfaces/SimpleAnnotationInterface.java @@ -0,0 +1,17 @@ +public class SimpleAnnotationInterface { + + public static void main(String[] args) { + method(); + System.out.println("passed"); + } + + @interface SimpleTest { + int someVal(); + } + + @SimpleTest(someVal = 5) + static void method() { + System.out.println("working my work..."); + } + +} \ No newline at end of file diff --git a/src/test/resources/test_candidates/eo_execution_pom/pom.xml b/src/test/resources/test_candidates/eo_execution_pom/pom.xml index 3db6a1f2..46c7dfde 100644 --- a/src/test/resources/test_candidates/eo_execution_pom/pom.xml +++ b/src/test/resources/test_candidates/eo_execution_pom/pom.xml @@ -28,7 +28,7 @@ SOFTWARE. j2eo-testing 1.0-SNAPSHOT - 0.17.1 + 0.21.5 16 16 16