text:
.class public Lmf/org/apache/xml/resolver/apps/resolver;
.super Ljava/lang/Object;
.source "resolver.java"

# static fields
.field private static debug:Lmf/org/apache/xml/resolver/helpers/Debug;

# direct methods
.method static constructor <clinit>()V
    .locals 1

    invoke-static {}, Lmf/org/apache/xml/resolver/CatalogManager;->getStaticManager()Lmf/org/apache/xml/resolver/CatalogManager;

    move-result-object v0

    iget-object v0, v0, Lmf/org/apache/xml/resolver/CatalogManager;->debug:Lmf/org/apache/xml/resolver/helpers/Debug;

    sput-object v0, Lmf/org/apache/xml/resolver/apps/resolver;->debug:Lmf/org/apache/xml/resolver/helpers/Debug;

    return-void
.end method

.method public constructor <init>()V
    .locals 0

    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method

.method public static main([Ljava/lang/String;)V
    .locals 30
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/FileNotFoundException;,
            Ljava/io/IOException;
        }
    .end annotation

    const/4 v10, 0x0

    new-instance v7, Ljava/util/Vector;

    invoke-direct {v7}, Ljava/util/Vector;-><init>()V

    const/16 v18, 0x0

    const/16 v19, 0x0

    const/16 v16, 0x0

    const/16 v17, 0x0

    const/16 v24, 0x0

    const/16 v25, 0x0

    const/4 v5, 0x0

    const/4 v15, 0x0

    :goto_0
    move-object/from16 v0, p0

    array-length v0, v0

    move/from16 v27, v0

    move/from16 v0, v27

    if-ge v15, v0, :cond_8

    aget-object v27, p0, v15

    const-string/jumbo v28, "-c"

    invoke-virtual/range {v27 .. v28}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v27

    if-nez v27, :cond_1

    aget-object v27, p0, v15

    const-string/jumbo v28, "-p"

    invoke-virtual/range {v27 .. v28}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v27

    if-nez v27, :cond_2

    aget-object v27, p0, v15

    const-string/jumbo v28, "-s"

    invoke-virtual/range {v27 .. v28}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v27

    if-nez v27, :cond_3

    aget-object v27, p0, v15

    const-string/jumbo v28, "-n"

    invoke-virtual/range {v27 .. v28}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v27

    if-nez v27, :cond_4

    aget-object v27, p0, v15

    const-string/jumbo v28, "-u"

    invoke-virtual/range {v27 .. v28}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v27

    if-nez v27, :cond_5

    aget-object v27, p0, v15

    const-string/jumbo v28, "-a"

    invoke-virtual/range {v27 .. v28}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v27

    if-nez v27, :cond_6

    aget-object v27, p0, v15

    const-string/jumbo v28, "-d"

    invoke-virtual/range {v27 .. v28}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v27

    if-nez v27, :cond_7

    aget-object v19, p0, v15

    :cond_0
    :goto_1
    add-int/lit8 v15, v15, 0x1

    goto :goto_0

    :cond_1
    add-int/lit8 v15, v15, 0x1

    aget-object v27, p0, v15

    move-object/from16 v0, v27

    invoke-virtual {v7, v0}, Ljava/util/Vector;->add(Ljava/lang/Object;)Z

    goto :goto_1

    :cond_2
    add-int/lit8 v15, v15, 0x1

    aget-object v17, p0, v15

    goto :goto_1

    :cond_3
    add-int/lit8 v15, v15, 0x1

    aget-object v24, p0, v15

    goto :goto_1

    :cond_4
    add-int/lit8 v15, v15, 0x1

    aget-object v16, p0, v15

    goto :goto_1

    :cond_5
    add-int/lit8 v15, v15, 0x1

    aget-object v25, p0, v15

    goto :goto_1

    :cond_6
    const/4 v5, 0x1

    goto :goto_1

    :cond_7
    add-int/lit8 v15, v15, 0x1

    aget-object v11, p0, v15

    :try_start_0
    invoke-static {v11}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

    move-result v10

    if-lez v10, :cond_0

    sget-object v27, Lmf/org/apache/xml/resolver/apps/resolver;->debug:Lmf/org/apache/xml/resolver/helpers/Debug;

    move-object/from16 v0, v27

    invoke-virtual {v0, v10}, Lmf/org/apache/xml/resolver/helpers/Debug;->setDebug(I)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_1

    :catch_0
    move-exception v4

    goto :goto_1

    :cond_8
    if-eqz v19, :cond_a

    :goto_2
    const-string/jumbo v27, "doctype"

    move-object/from16 v0, v19

    move-object/from16 v1, v27

    invoke-virtual {v0, v1}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v27

    if-nez v27, :cond_b

    const-string/jumbo v27, "document"

    move-object/from16 v0, v19

    move-object/from16 v1, v27

    invoke-virtual {v0, v1}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v27

    if-nez v27, :cond_c

    const-string/jumbo v27, "entity"

    move-object/from16 v0, v19

    move-object/from16 v1, v27

    invoke-virtual {v0, v1}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v27

    if-nez v27, :cond_d

    const-string/jumbo v27, "notation"

    move-object/from16 v0, v19

    move-object/from16 v1, v27

    invoke-virtual {v0, v1}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v27

    if-nez v27, :cond_e

    const-string/jumbo v27, "public"

    move-object/from16 v0, v19

    move-object/from16 v1, v27

    invoke-virtual {v0, v1}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v27

    if-nez v27, :cond_f

    const-string/jumbo v27, "system"

    move-object/from16 v0, v19

    move-object/from16 v1, v27

    invoke-virtual {v0, v1}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v27

    if-nez v27, :cond_10

    const-string/jumbo v27, "uri"

    move-object/from16 v0, v19

    move-object/from16 v1, v27

    invoke-virtual {v0, v1}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v27

    if-nez v27, :cond_11

    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    new-instance v28, Ljava/lang/StringBuilder;

    invoke-static/range {v19 .. v19}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v29

    invoke-direct/range {v28 .. v29}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string/jumbo v29, " is not a recognized keyword."

    invoke-virtual/range {v28 .. v29}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v28

    invoke-virtual/range {v28 .. v28}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v28

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    invoke-static {}, Lmf/org/apache/xml/resolver/apps/resolver;->usage()V

    :cond_9
    :goto_3
    if-nez v5, :cond_12

    :goto_4
    new-instance v8, Lmf/org/apache/xml/resolver/tools/CatalogResolver;

    invoke-direct {v8}, Lmf/org/apache/xml/resolver/tools/CatalogResolver;-><init>()V

    invoke-virtual {v8}, Lmf/org/apache/xml/resolver/tools/CatalogResolver;->getCatalog()Lmf/org/apache/xml/resolver/Catalog;

    move-result-object v20

    const/4 v9, 0x0

    :goto_5
    invoke-virtual {v7}, Ljava/util/Vector;->size()I

    move-result v27

    move/from16 v0, v27

    if-ge v9, v0, :cond_13

    invoke-virtual {v7, v9}, Ljava/util/Vector;->elementAt(I)Ljava/lang/Object;

    move-result-object v14

    check-cast v14, Ljava/lang/String;

    move-object/from16 v0, v20

    invoke-virtual {v0, v14}, Lmf/org/apache/xml/resolver/Catalog;->parseCatalog(Ljava/lang/String;)V

    add-int/lit8 v9, v9, 0x1

    goto :goto_5

    :cond_a
    invoke-static {}, Lmf/org/apache/xml/resolver/apps/resolver;->usage()V

    goto/16 :goto_2

    :cond_b
    sget v18, Lmf/org/apache/xml/resolver/Catalog;->DOCTYPE:I

    if-nez v17, :cond_9

    if-nez v24, :cond_9

    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v28, "DOCTYPE requires public or system identifier."

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    invoke-static {}, Lmf/org/apache/xml/resolver/apps/resolver;->usage()V

    goto :goto_3

    :cond_c
    sget v18, Lmf/org/apache/xml/resolver/Catalog;->DOCUMENT:I

    goto :goto_3

    :cond_d
    sget v18, Lmf/org/apache/xml/resolver/Catalog;->ENTITY:I

    if-nez v17, :cond_9

    if-nez v24, :cond_9

    if-nez v16, :cond_9

    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v28, "ENTITY requires name or public or system identifier."

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    invoke-static {}, Lmf/org/apache/xml/resolver/apps/resolver;->usage()V

    goto :goto_3

    :cond_e
    sget v18, Lmf/org/apache/xml/resolver/Catalog;->NOTATION:I

    if-nez v17, :cond_9

    if-nez v24, :cond_9

    if-nez v16, :cond_9

    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v28, "NOTATION requires name or public or system identifier."

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    invoke-static {}, Lmf/org/apache/xml/resolver/apps/resolver;->usage()V

    goto :goto_3

    :cond_f
    sget v18, Lmf/org/apache/xml/resolver/Catalog;->PUBLIC:I

    if-nez v17, :cond_9

    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v28, "PUBLIC requires public identifier."

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    invoke-static {}, Lmf/org/apache/xml/resolver/apps/resolver;->usage()V

    goto :goto_3

    :cond_10
    sget v18, Lmf/org/apache/xml/resolver/Catalog;->SYSTEM:I

    if-nez v24, :cond_9

    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v28, "SYSTEM requires system identifier."

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    invoke-static {}, Lmf/org/apache/xml/resolver/apps/resolver;->usage()V

    goto/16 :goto_3

    :cond_11
    sget v18, Lmf/org/apache/xml/resolver/Catalog;->URI:I

    if-nez v25, :cond_9

    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v28, "URI requires a uri."

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    invoke-static {}, Lmf/org/apache/xml/resolver/apps/resolver;->usage()V

    goto/16 :goto_3

    :cond_12
    const/4 v6, 0x0

    const/16 v22, 0x0

    :try_start_1
    const-string/jumbo v27, "basename"

    invoke-static/range {v27 .. v27}, Lmf/org/apache/xml/resolver/helpers/FileURL;->makeURL(Ljava/lang/String;)Ljava/net/URL;
    :try_end_1
    .catch Ljava/net/MalformedURLException; {:try_start_1 .. :try_end_1} :catch_1

    move-result-object v6

    :goto_6
    :try_start_2
    new-instance v23, Ljava/net/URL;

    move-object/from16 v0, v23

    move-object/from16 v1, v24

    invoke-direct {v0, v6, v1}, Ljava/net/URL;-><init>(Ljava/net/URL;Ljava/lang/String;)V
    :try_end_2
    .catch Ljava/net/MalformedURLException; {:try_start_2 .. :try_end_2} :catch_2

    :try_start_3
    invoke-virtual/range {v23 .. v23}, Ljava/net/URL;->toString()Ljava/lang/String;
    :try_end_3
    .catch Ljava/net/MalformedURLException; {:try_start_3 .. :try_end_3} :catch_4

    move-result-object v24

    goto/16 :goto_4

    :catch_1
    move-exception v12

    const-string/jumbo v27, "user.dir"

    invoke-static/range {v27 .. v27}, Ljava/lang/System;->getProperty(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v26

    const/16 v27, 0x5c

    const/16 v28, 0x2f

    invoke-virtual/range {v26 .. v28}, Ljava/lang/String;->replace(CC)Ljava/lang/String;

    move-result-object v26

    sget-object v27, Lmf/org/apache/xml/resolver/apps/resolver;->debug:Lmf/org/apache/xml/resolver/helpers/Debug;

    const-string/jumbo v28, "Malformed URL on cwd"

    const/16 v29, 0x1

    move-object/from16 v0, v27

    move/from16 v1, v29

    move-object/from16 v2, v28

    move-object/from16 v3, v26

    invoke-virtual {v0, v1, v2, v3}, Lmf/org/apache/xml/resolver/helpers/Debug;->message(ILjava/lang/String;Ljava/lang/String;)V

    const/4 v6, 0x0

    goto :goto_6

    :catch_2
    move-exception v12

    :goto_7
    :try_start_4
    new-instance v22, Ljava/net/URL;

    new-instance v27, Ljava/lang/StringBuilder;

    const-string/jumbo v28, "file:///"

    invoke-direct/range {v27 .. v28}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, v27

    move-object/from16 v1, v24

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v27

    invoke-virtual/range {v27 .. v27}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v27

    move-object/from16 v0, v22

    move-object/from16 v1, v27

    invoke-direct {v0, v1}, Ljava/net/URL;-><init>(Ljava/lang/String;)V
    :try_end_4
    .catch Ljava/net/MalformedURLException; {:try_start_4 .. :try_end_4} :catch_3

    goto/16 :goto_4

    :catch_3
    move-exception v13

    sget-object v27, Lmf/org/apache/xml/resolver/apps/resolver;->debug:Lmf/org/apache/xml/resolver/helpers/Debug;

    const-string/jumbo v28, "Malformed URL on system id"

    const/16 v29, 0x1

    move-object/from16 v0, v27

    move/from16 v1, v29

    move-object/from16 v2, v28

    move-object/from16 v3, v24

    invoke-virtual {v0, v1, v2, v3}, Lmf/org/apache/xml/resolver/helpers/Debug;->message(ILjava/lang/String;Ljava/lang/String;)V

    goto/16 :goto_4

    :cond_13
    const/16 v21, 0x0

    sget v27, Lmf/org/apache/xml/resolver/Catalog;->DOCTYPE:I

    move/from16 v0, v18

    move/from16 v1, v27

    if-eq v0, v1, :cond_14

    sget v27, Lmf/org/apache/xml/resolver/Catalog;->DOCUMENT:I

    move/from16 v0, v18

    move/from16 v1, v27

    if-eq v0, v1, :cond_19

    sget v27, Lmf/org/apache/xml/resolver/Catalog;->ENTITY:I

    move/from16 v0, v18

    move/from16 v1, v27

    if-eq v0, v1, :cond_1a

    sget v27, Lmf/org/apache/xml/resolver/Catalog;->NOTATION:I

    move/from16 v0, v18

    move/from16 v1, v27

    if-eq v0, v1, :cond_1e

    sget v27, Lmf/org/apache/xml/resolver/Catalog;->PUBLIC:I

    move/from16 v0, v18

    move/from16 v1, v27

    if-eq v0, v1, :cond_22

    sget v27, Lmf/org/apache/xml/resolver/Catalog;->SYSTEM:I

    move/from16 v0, v18

    move/from16 v1, v27

    if-eq v0, v1, :cond_25

    sget v27, Lmf/org/apache/xml/resolver/Catalog;->URI:I

    move/from16 v0, v18

    move/from16 v1, v27

    if-eq v0, v1, :cond_27

    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v28, "resType is wrong!? This can\'t happen!"

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    invoke-static {}, Lmf/org/apache/xml/resolver/apps/resolver;->usage()V

    :goto_8
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    new-instance v28, Ljava/lang/StringBuilder;

    const-string/jumbo v29, "Result: "

    invoke-direct/range {v28 .. v29}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, v28

    move-object/from16 v1, v21

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v28

    invoke-virtual/range {v28 .. v28}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v28

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    return-void

    :cond_14
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v28, "Resolve DOCTYPE (name, publicid, systemid):"

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    if-nez v16, :cond_15

    :goto_9
    if-nez v17, :cond_16

    :goto_a
    if-nez v24, :cond_17

    :goto_b
    if-nez v25, :cond_18

    :goto_c
    move-object/from16 v0, v20

    move-object/from16 v1, v16

    move-object/from16 v2, v17

    move-object/from16 v3, v24

    invoke-virtual {v0, v1, v2, v3}, Lmf/org/apache/xml/resolver/Catalog;->resolveDoctype(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v21

    goto :goto_8

    :cond_15
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    new-instance v28, Ljava/lang/StringBuilder;

    const-string/jumbo v29, "       name: "

    invoke-direct/range {v28 .. v29}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, v28

    move-object/from16 v1, v16

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v28

    invoke-virtual/range {v28 .. v28}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v28

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    goto :goto_9

    :cond_16
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    new-instance v28, Ljava/lang/StringBuilder;

    const-string/jumbo v29, "  public id: "

    invoke-direct/range {v28 .. v29}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, v28

    move-object/from16 v1, v17

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v28

    invoke-virtual/range {v28 .. v28}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v28

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    goto :goto_a

    :cond_17
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    new-instance v28, Ljava/lang/StringBuilder;

    const-string/jumbo v29, "  system id: "

    invoke-direct/range {v28 .. v29}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, v28

    move-object/from16 v1, v24

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v28

    invoke-virtual/range {v28 .. v28}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v28

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    goto :goto_b

    :cond_18
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    new-instance v28, Ljava/lang/StringBuilder;

    const-string/jumbo v29, "        uri: "

    invoke-direct/range {v28 .. v29}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, v28

    move-object/from16 v1, v25

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v28

    invoke-virtual/range {v28 .. v28}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v28

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    goto :goto_c

    :cond_19
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v28, "Resolve DOCUMENT ():"

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    invoke-virtual/range {v20 .. v20}, Lmf/org/apache/xml/resolver/Catalog;->resolveDocument()Ljava/lang/String;

    move-result-object v21

    goto/16 :goto_8

    :cond_1a
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v28, "Resolve ENTITY (name, publicid, systemid):"

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    if-nez v16, :cond_1b

    :goto_d
    if-nez v17, :cond_1c

    :goto_e
    if-nez v24, :cond_1d

    :goto_f
    move-object/from16 v0, v20

    move-object/from16 v1, v16

    move-object/from16 v2, v17

    move-object/from16 v3, v24

    invoke-virtual {v0, v1, v2, v3}, Lmf/org/apache/xml/resolver/Catalog;->resolveEntity(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v21

    goto/16 :goto_8

    :cond_1b
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    new-instance v28, Ljava/lang/StringBuilder;

    const-string/jumbo v29, "       name: "

    invoke-direct/range {v28 .. v29}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, v28

    move-object/from16 v1, v16

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v28

    invoke-virtual/range {v28 .. v28}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v28

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    goto :goto_d

    :cond_1c
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    new-instance v28, Ljava/lang/StringBuilder;

    const-string/jumbo v29, "  public id: "

    invoke-direct/range {v28 .. v29}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, v28

    move-object/from16 v1, v17

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v28

    invoke-virtual/range {v28 .. v28}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v28

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    goto :goto_e

    :cond_1d
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    new-instance v28, Ljava/lang/StringBuilder;

    const-string/jumbo v29, "  system id: "

    invoke-direct/range {v28 .. v29}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, v28

    move-object/from16 v1, v24

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v28

    invoke-virtual/range {v28 .. v28}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v28

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    goto :goto_f

    :cond_1e
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v28, "Resolve NOTATION (name, publicid, systemid):"

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    if-nez v16, :cond_1f

    :goto_10
    if-nez v17, :cond_20

    :goto_11
    if-nez v24, :cond_21

    :goto_12
    move-object/from16 v0, v20

    move-object/from16 v1, v16

    move-object/from16 v2, v17

    move-object/from16 v3, v24

    invoke-virtual {v0, v1, v2, v3}, Lmf/org/apache/xml/resolver/Catalog;->resolveNotation(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v21

    goto/16 :goto_8

    :cond_1f
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    new-instance v28, Ljava/lang/StringBuilder;

    const-string/jumbo v29, "       name: "

    invoke-direct/range {v28 .. v29}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, v28

    move-object/from16 v1, v16

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v28

    invoke-virtual/range {v28 .. v28}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v28

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    goto :goto_10

    :cond_20
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    new-instance v28, Ljava/lang/StringBuilder;

    const-string/jumbo v29, "  public id: "

    invoke-direct/range {v28 .. v29}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, v28

    move-object/from16 v1, v17

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v28

    invoke-virtual/range {v28 .. v28}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v28

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    goto :goto_11

    :cond_21
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    new-instance v28, Ljava/lang/StringBuilder;

    const-string/jumbo v29, "  system id: "

    invoke-direct/range {v28 .. v29}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, v28

    move-object/from16 v1, v24

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v28

    invoke-virtual/range {v28 .. v28}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v28

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    goto :goto_12

    :cond_22
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v28, "Resolve PUBLIC (publicid, systemid):"

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    if-nez v17, :cond_23

    :goto_13
    if-nez v24, :cond_24

    :goto_14
    move-object/from16 v0, v20

    move-object/from16 v1, v17

    move-object/from16 v2, v24

    invoke-virtual {v0, v1, v2}, Lmf/org/apache/xml/resolver/Catalog;->resolvePublic(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v21

    goto/16 :goto_8

    :cond_23
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    new-instance v28, Ljava/lang/StringBuilder;

    const-string/jumbo v29, "  public id: "

    invoke-direct/range {v28 .. v29}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, v28

    move-object/from16 v1, v17

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v28

    invoke-virtual/range {v28 .. v28}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v28

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    goto :goto_13

    :cond_24
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    new-instance v28, Ljava/lang/StringBuilder;

    const-string/jumbo v29, "  system id: "

    invoke-direct/range {v28 .. v29}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, v28

    move-object/from16 v1, v24

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v28

    invoke-virtual/range {v28 .. v28}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v28

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    goto :goto_14

    :cond_25
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v28, "Resolve SYSTEM (systemid):"

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    if-nez v24, :cond_26

    :goto_15
    move-object/from16 v0, v20

    move-object/from16 v1, v24

    invoke-virtual {v0, v1}, Lmf/org/apache/xml/resolver/Catalog;->resolveSystem(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v21

    goto/16 :goto_8

    :cond_26
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    new-instance v28, Ljava/lang/StringBuilder;

    const-string/jumbo v29, "  system id: "

    invoke-direct/range {v28 .. v29}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, v28

    move-object/from16 v1, v24

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v28

    invoke-virtual/range {v28 .. v28}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v28

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    goto :goto_15

    :cond_27
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v28, "Resolve URI (uri):"

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    if-nez v25, :cond_28

    :goto_16
    move-object/from16 v0, v20

    move-object/from16 v1, v25

    invoke-virtual {v0, v1}, Lmf/org/apache/xml/resolver/Catalog;->resolveURI(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v21

    goto/16 :goto_8

    :cond_28
    sget-object v27, Ljava/lang/System;->out:Ljava/io/PrintStream;

    new-instance v28, Ljava/lang/StringBuilder;

    const-string/jumbo v29, "        uri: "

    invoke-direct/range {v28 .. v29}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    move-object/from16 v0, v28

    move-object/from16 v1, v25

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v28

    invoke-virtual/range {v28 .. v28}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v28

    invoke-virtual/range {v27 .. v28}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    goto :goto_16

    :catch_4
    move-exception v12

    move-object/from16 v22, v23

    goto/16 :goto_7
.end method

.method public static usage()V
    .locals 2

    sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v1, "Usage: resolver [options] keyword"

    invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v1, ""

    invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v1, "Where:"

    invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v1, ""

    invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v1, "-c catalogfile  Loads a particular catalog file."

    invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v1, "-n name         Sets the name."

    invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v1, "-p publicId     Sets the public identifier."

    invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v1, "-s systemId     Sets the system identifier."

    invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v1, "-a              Makes the system URI absolute before resolution"

    invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v1, "-u uri          Sets the URI."

    invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v1, "-d integer      Set the debug level."

    invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v1, "keyword         Identifies the type of resolution to perform:"

    invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v1, "                doctype, document, entity, notation, public, system,"

    invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string/jumbo v1, "                or uri."

    invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    const/4 v0, 0x1

    invoke-static {v0}, Ljava/lang/System;->exit(I)V

    return-void
.end method


text:
#include <stdio.h>

#include "printtoken.h"
#include "tokenbuffer.h"
#include "token.h"

/*
 * printTokenTable  prints the Lexeme Table to std output.
 * printTokenList prints the Lexeme List to std output and to the file lexlist.txt.
 *
 * TODO Does print out nulsym. Should this be printed? When will this token be generated
 * in the first place?
 *
 */

void printTokenTable(TokenBuffer* b, FILE* fout){
	int numTokens = b->length;

	fprintf(fout, "Lexeme Table:");
	fprintf(fout, "\nlexeme        token type");
	int i = 0;
	for ( i = 0; i < numTokens; i++){
		fprintf(fout, "\n%-14s%d", b->buf[i].lexeme, b->buf[i].type);
	}
}
//end printTokenTable

void printTokenList(TokenBuffer* b, FILE* fout){
	int numTokens = b->length;

	fprintf(fout, "Lexeme List:\n");
	int i = 0;
	for ( i = 0; i < numTokens; i++){
		if ((b->buf[i].type == 2) || (b->buf[i].type == 3)){
			fprintf(fout, "%d %s ", b->buf[i].type, b->buf[i].lexeme);
		}
		else{
			fprintf(fout, "%d ", b->buf[i].type);
		}
	}
}
//end printTokenList

void printSymbolicTokenList(TokenBuffer* b, FILE* fout){
	int numTokens = b->length;

	fprintf(fout, "Lexeme List:\n");
	int i = 0;
	for ( i = 0; i < numTokens; i++){
        switch (b->buf[i].type)
        {
            case nulsym: fputs("nulsym ", fout); break;
            case identsym: fprintf(fout, "identsym %s ", b->buf[i].lexeme); break;
            case numbersym: fprintf(fout, "numbersym %s ", b->buf[i].lexeme); break;
            case plussym: fputs("plussym ", fout); break;
            case minussym: fputs("minussym ", fout); break;
            case multsym: fputs("multsym ", fout); break;
            case slashsym: fputs("slashsym ", fout); break;
            case oddsym: fputs("oddsym ", fout); break;
            case eqsym: fputs("eqsym ", fout); break;
            case neqsym: fputs("neqsym ", fout); break;
            case lessym: fputs("lessym ", fout); break;
            case leqsym: fputs("leqsym ", fout); break;
            case gtrsym: fputs("gtrsym ", fout); break;
            case geqsym: fputs("geqsym ", fout); break;
            case lparentsym: fputs("lparentsym ", fout); break;
            case rparentsym: fputs("rparentsym ", fout); break;
            case commasym: fputs("commasym ", fout); break;
            case semicolonsym: fputs("semicolonsym ", fout); break;
            case periodsym: fputs("periodsym ", fout); break;
            case becomessym: fputs("becomessym ", fout); break;
            case beginsym: fputs("beginsym ", fout); break;
            case endsym: fputs("endsym ", fout); break;
            case ifsym: fputs("ifsym ", fout); break;
            case thensym: fputs("thensym ", fout); break;
            case whilesym: fputs("whilesym ", fout); break;
            case dosym: fputs("dosym ", fout); break;
            case callsym: fputs("callsym ", fout); break;
            case constsym: fputs("constsym ", fout); break;
            case intsym: fputs("intsym ", fout); break;
            case procsym: fputs("procsym ", fout); break;
            case outsym: fputs("outsym ", fout); break;
            case insym: fputs("insym ", fout); break;
            case elsesym: fputs("elsesym ", fout); break;
        }
	}
}
//end printTokenList

redpajama_set_name: RedPajamaGithub


text:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#33ff0000"
    android:text="从上到下为2个CheckBox,1个ToggleButton,1个Switch.看好默认效果"/>
    <TextView
        android:id="@+id/text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <CheckBox
        android:id="@+id/cb1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="北京"
        android:textColor="#0000FF"
        android:textSize="30sp"
        android:textStyle="normal" />

    <CheckBox
        android:id="@+id/cb2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="上海"
        android:textColor="#0000FF"
        android:textSize="30sp" />

    <ToggleButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textOff="不喜欢"
        android:textOn="喜欢" />

    <Switch
        android:id="@+id/switch1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textOff="不不喜欢"
        android:textOn="喜欢" />

</LinearLayout>


text:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Controller extends CI_Hooks
{
	/**
	 * Hook: post_controller
	 */
	// add extra information to mViewData
	function add_viewdata()
	{
		$CI =& get_instance();
		$ctrler = $CI->router->fetch_class();

		// fallback when mTitle is not set / empty
		if ( empty($CI->mTitle) )
		{
			// take controller or action name as title
			if ($CI->mAction=='index')
				$CI->mTitle = ucfirst($CI->mCtrler);
			else
				$CI->mTitle = ucfirst($CI->mAction);
		}

		if ($ctrler!='home')
		{
			// add an "active" entry at the end of breadcrumb (based on mTitle)
			$CI->mBreadcrumb[] = array('name' => $CI->mTitle);
		}

		// push to mViewData before rendering
		$CI->mViewData['breadcrumb'] = $CI->mBreadcrumb;

		// render output
		$view_data = empty($CI->mViewData) ? NULL : $CI->mViewData;
		$CI->load->view($CI->mViewFile, $CI->mViewData);
	}
}


text:
html {
    padding: 10px;
    font-family: Verdana, sans-serif;
}

.login-buttons-dropdown-align-right {
    float: right;
}

.loadingclock {
  position: relative;
  width: 24px;
  height: 24px;
  border: 2px solid #ccc;
  border-radius: 100%;
}
.loadingclock:before {
  display: block;
  position: absolute;
  left: 11px;
  top: 2px;
  width: 2px;
  height: 10px;
  background-color: #ccc;
  -webkit-animation: spin 3s linear infinite;
  animation: spin 3s linear infinite;
  content: "";
  -webkit-transform-origin: 1px 10px;
  -ms-transform-origin: 1px 10px;
  transform-origin: 1px 10px;
}
.loadingclock:after {
  display: block;
  position: absolute;
  left: 11px;
  top: 3px;
  width: 2px;
  height: 9px;
  background-color: #ccc;
  -webkit-animation: spin 18s linear infinite;
  animation: spin 18s linear infinite;
  content: "";
  -webkit-transform-origin: 1px 9px;
  -ms-transform-origin: 1px 9px;
  transform-origin: 1px 9px;
}
@-webkit-keyframes spin {
  to {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@keyframes spin {
  to {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}


text:
/**
 * @author André König <andre.koenig@posteo.de>
 *
 */

'use strict';

/**
 * Module dependencies
 *
 */
var fs = require('fs');
var path = require('path');

var file = path.join(process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'], '.npmawesomebotrc');

function Configuration () {
    this.path = file;
}

Configuration.prototype.exists = function exists () {
    return fs.existsSync(this.path);
};

Configuration.prototype.touch = function touch () {
    var template = path.join(__dirname, '..', 'etc', 'template');

    fs.createReadStream(template).pipe(fs.createWriteStream(this.path));
};

Configuration.prototype.consume = function consume () {
    return JSON.parse(fs.readFileSync(this.path, 'utf-8'));
};

module.exports = new Configuration();


text:
package org.kie.workbench.common.dmn.client.editors.expressions;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;

import com.ait.lienzo.client.core.event.INodeXYEvent;
import com.ait.lienzo.client.core.types.Point2D;
import com.ait.lienzo.test.LienzoMockitoTestRunner;
import org.jboss.errai.ui.client.local.spi.TranslationService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.workbench.common.dmn.api.definition.HasExpression;
import org.kie.workbench.common.dmn.api.definition.HasName;
import org.kie.workbench.common.dmn.api.definition.HasVariable;
import org.kie.workbench.common.dmn.api.definition.NOPDomainObject;
import org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase;
import org.kie.workbench.common.dmn.api.definition.model.Expression;
import org.kie.workbench.common.dmn.api.definition.model.IsInformationItem;
import org.kie.workbench.common.dmn.api.definition.model.LiteralExpression;
import org.kie.workbench.common.dmn.api.property.dmn.Name;
import org.kie.workbench.common.dmn.client.commands.factory.DefaultCanvasCommandFactory;
import org.kie.workbench.common.dmn.client.commands.general.ClearExpressionTypeCommand;
import org.kie.workbench.common.dmn.client.commands.general.SetHasValueCommand;
import org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition;
import org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions;
import org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue;
import org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionEditorColumn;
import org.kie.workbench.common.dmn.client.editors.expressions.types.literal.LiteralExpressionColumn;
import org.kie.workbench.common.dmn.client.editors.expressions.types.literal.LiteralExpressionGrid;
import org.kie.workbench.common.dmn.client.editors.expressions.types.undefined.UndefinedExpressionColumn;
import org.kie.workbench.common.dmn.client.editors.expressions.types.undefined.UndefinedExpressionEditorDefinition;
import org.kie.workbench.common.dmn.client.editors.expressions.types.undefined.UndefinedExpressionGrid;
import org.kie.workbench.common.dmn.client.resources.i18n.DMNEditorConstants;
import org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid;
import org.kie.workbench.common.dmn.client.widgets.grid.ExpressionGridCache;
import org.kie.workbench.common.dmn.client.widgets.grid.ExpressionGridCacheImpl;
import org.kie.workbench.common.dmn.client.widgets.grid.columns.factory.AutocompleteTextAreaDOMElementFactory;
import org.kie.workbench.common.dmn.client.widgets.grid.columns.factory.TextAreaSingletonDOMElementFactory;
import org.kie.workbench.common.dmn.client.widgets.grid.controls.container.CellEditorControlsView;
import org.kie.workbench.common.dmn.client.widgets.grid.controls.list.HasListSelectorControl;
import org.kie.workbench.common.dmn.client.widgets.grid.controls.list.ListSelectorView;
import org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper;
import org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridColumn;
import org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData;
import org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple;
import org.kie.workbench.common.dmn.client.widgets.layer.DMNGridLayer;
import org.kie.workbench.common.stunner.core.client.api.SessionManager;
import org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler;
import org.kie.workbench.common.stunner.core.client.canvas.event.selection.DomainObjectSelectionEvent;
import org.kie.workbench.common.stunner.core.client.command.SessionCommandManager;
import org.kie.workbench.common.stunner.core.client.session.ClientSession;
import org.kie.workbench.common.stunner.core.diagram.Diagram;
import org.kie.workbench.common.stunner.core.graph.Graph;
import org.kie.workbench.common.stunner.core.graph.Node;
import org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext;
import org.kie.workbench.common.stunner.core.graph.content.definition.Definition;
import org.kie.workbench.common.stunner.forms.client.event.RefreshFormPropertiesEvent;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.uberfire.ext.wires.core.grids.client.model.Bounds;
import org.uberfire.ext.wires.core.grids.client.model.GridCell;
import org.uberfire.ext.wires.core.grids.client.model.GridCellValue;
import org.uberfire.ext.wires.core.grids.client.model.GridData;
import org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCell;
import org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData;
import org.uberfire.ext.wires.core.grids.client.widget.grid.selections.CellSelectionManager;
import org.uberfire.mocks.EventSourceMock;
import org.uberfire.mvp.Command;
import org.uberfire.mvp.ParameterizedCommand;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(LienzoMockitoTestRunner.class)
public class ExpressionContainerGridTest {

    private static final String NODE_UUID = "uuid";

    private static final String NAME = "name";

    private static final double COLUMN_NEW_WIDTH = 300.0;

    private static final double LITERAL_EXPRESSION_EDITOR_PADDING = 10.0;

    @Mock
    private CellEditorControlsView.Presenter cellEditorControls;

    @Mock
    private TranslationService translationService;

    @Mock
    private ListSelectorView.Presenter listSelector;

    @Mock
    private SessionManager sessionManager;

    @Mock
    private SessionCommandManager<AbstractCanvasHandler> sessionCommandManager;

    @Mock
    private DefaultCanvasCommandFactory canvasCommandFactory;

    @Mock
    private Supplier<ExpressionEditorDefinitions> expressionEditorDefinitionsSupplier;

    @Mock
    private ClientSession session;

    @Mock
    private ExpressionEditorDefinition literalExpressionEditorDefinition;

    @Mock
    private LiteralExpressionGrid literalExpressionEditor;

    @Mock
    private UndefinedExpressionEditorDefinition undefinedExpressionEditorDefinition;

    @Mock
    private UndefinedExpressionGrid undefinedExpressionEditor;

    @Mock
    private AbstractCanvasHandler canvasHandler;

    @Mock
    private Diagram diagram;

    @Mock
    private Graph graph;

    @Mock
    private Node node;

    @Mock
    private GraphCommandExecutionContext graphExecutionContext;

    @Mock
    private GridCellTuple parent;

    @Mock
    private HasExpression hasExpression;

    @Mock
    private IsInformationItem isInformationItem;

    @Mock
    private ParameterizedCommand<Optional<Expression>> onHasExpressionChanged;

    @Mock
    private ParameterizedCommand<Optional<HasName>> onHasNameChanged;

    @Mock
    private EventSourceMock<RefreshFormPropertiesEvent> refreshFormPropertiesEvent;

    @Mock
    private EventSourceMock<DomainObjectSelectionEvent> domainObjectSelectionEvent;

    @Mock
    private CellSelectionManager cellSelectionManager;

    @Mock
    private TextAreaSingletonDOMElementFactory textAreaSingletonDOMElementFactory;

    @Mock
    private AutocompleteTextAreaDOMElementFactory autocompleteTextareaDOMElementFactory;

    @Captor
    private ArgumentCaptor<Optional<HasName>> hasNameCaptor;

    @Captor
    private ArgumentCaptor<ClearExpressionTypeCommand> clearExpressionTypeCommandCaptor;

    @Captor
    private ArgumentCaptor<DomainObjectSelectionEvent> domainObjectSelectionEventCaptor;

    @Captor
    private ArgumentCaptor<RefreshFormPropertiesEvent> refreshFormPropertiesEventCaptor;

    private interface MockHasNameHasVariable extends HasName,
                                                     HasVariable {

    }

    private MockHasNameHasVariable hasName = new MockHasNameHasVariable() {

        private Name name = new Name(NAME);

        @Override
        public Name getName() {
            return name;
        }

        @Override
        public void setName(final Name name) {
            this.name = name;
        }

        @Override
        public IsInformationItem getVariable() {
            return isInformationItem;
        }

        @Override
        public void setVariable(final IsInformationItem informationItem) {
            throw new UnsupportedOperationException("Not supported in this Unit Test");
        }

        @Override
        public DMNModelInstrumentedBase asDMNModelInstrumentedBase() {
            throw new UnsupportedOperationException("Not supported in this Unit Test");
        }
    };

    private LiteralExpression literalExpression = new LiteralExpression();

    private ExpressionGridCache expressionGridCache;

    private DMNGridLayer gridLayer;

    private ExpressionContainerGrid grid;

    @Before
    @SuppressWarnings("unchecked")
    public void setup() {
        this.expressionGridCache = new ExpressionGridCacheImpl();
        this.gridLayer = spy(new DMNGridLayer());
        this.grid = new ExpressionContainerGrid(gridLayer,
                                                cellEditorControls,
                                                translationService,
                                                listSelector,
                                                sessionManager,
                                                sessionCommandManager,
                                                canvasCommandFactory,
                                                expressionEditorDefinitionsSupplier,
                                                () -> expressionGridCache,
                                                onHasExpressionChanged,
                                                onHasNameChanged,
                                                refreshFormPropertiesEvent,
                                                domainObjectSelectionEvent) {
            @Override
            public CellSelectionManager getCellSelectionManager() {
                return cellSelectionManager;
            }
        };

        this.gridLayer.add(grid);

        final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
        expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
        expressionEditorDefinitions.add(literalExpressionEditorDefinition);

        when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
        when(literalExpressionEditor.isCacheable()).thenReturn(true);
        when(literalExpressionEditor.getParentInformation()).thenReturn(parent);
        when(literalExpressionEditor.getModel()).thenReturn(new BaseGridData());
        when(literalExpressionEditorDefinition.getModelClass()).thenReturn(Optional.of(literalExpression));
        when(literalExpressionEditorDefinition.getEditor(any(GridCellTuple.class),
                                                         any(Optional.class),
                                                         any(HasExpression.class),
                                                         any(Optional.class),
                                                         anyBoolean(),
                                                         anyInt())).thenReturn(Optional.of(literalExpressionEditor));

        when(undefinedExpressionEditor.getParentInformation()).thenReturn(parent);
        when(undefinedExpressionEditor.getModel()).thenReturn(new BaseGridData());
        when(undefinedExpressionEditorDefinition.getModelClass()).thenReturn(Optional.empty());
        when(undefinedExpressionEditorDefinition.getEditor(any(GridCellTuple.class),
                                                           any(Optional.class),
                                                           any(HasExpression.class),
                                                           any(Optional.class),
                                                           anyBoolean(),
                                                           anyInt())).thenReturn(Optional.of(undefinedExpressionEditor));

        when(sessionManager.getCurrentSession()).thenReturn(session);
        when(session.getCanvasHandler()).thenReturn(canvasHandler);
        when(canvasHandler.getGraphExecutionContext()).thenReturn(graphExecutionContext);
        doReturn(mock(Bounds.class)).when(gridLayer).getVisibleBounds();

        when(canvasHandler.getDiagram()).thenReturn(diagram);
        when(diagram.getGraph()).thenReturn(graph);
        when(graph.nodes()).thenReturn(Collections.singletonList(node));

        when(parent.getGridWidget()).thenReturn(grid);
        when(parent.getRowIndex()).thenReturn(0);
        when(parent.getColumnIndex()).thenReturn(0);

        doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).format(Mockito.<String>any());
    }

    @Test
    public void testInitialSetup() {
        final GridData uiModel = grid.getModel();
        assertThat(uiModel).isInstanceOf(DMNGridData.class);

        assertThat(uiModel.getColumnCount()).isEqualTo(1);
        assertThat(uiModel.getColumns().get(0)).isInstanceOf(ExpressionEditorColumn.class);

        assertThat(uiModel.getRowCount()).isEqualTo(1);
    }

    @Test
    public void testGridDraggingIsDisabled() {
        assertThat(grid.onDragHandle(mock(INodeXYEvent.class))).isFalse();
    }

    @Test
    public void testDeselect() {
        grid.getModel().selectCell(0, 0);
        assertFalse(grid.getModel().getSelectedCells().isEmpty());

        grid.deselect();

        assertTrue(grid.getModel().getSelectedCells().isEmpty());
    }

    @Test
    public void testSetUndefinedExpression() {
        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);

        final GridCellValue<?> gridCellValue = grid.getModel().getCell(0, 0).getValue();
        assertThat(gridCellValue).isInstanceOf(ExpressionCellValue.class);
        final ExpressionCellValue expressionCellValue = (ExpressionCellValue) gridCellValue;
        assertThat(expressionCellValue.getValue().isPresent()).isTrue();
        assertThat(expressionCellValue.getValue().get()).isSameAs(undefinedExpressionEditor);
        assertThat(grid.isOnlyVisualChangeAllowed()).isFalse();

        verify(undefinedExpressionEditor).selectFirstCell();
        verify(gridLayer).batch();
    }

    @Test
    public void testSetDefinedExpression() {
        when(hasExpression.getExpression()).thenReturn(literalExpression);

        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);

        final GridCellValue<?> gridCellValue = grid.getModel().getCell(0, 0).getValue();
        assertThat(gridCellValue).isInstanceOf(ExpressionCellValue.class);
        final ExpressionCellValue expressionCellValue = (ExpressionCellValue) gridCellValue;
        assertThat(expressionCellValue.getValue().isPresent()).isTrue();
        assertThat(expressionCellValue.getValue().get()).isSameAs(literalExpressionEditor);
        assertThat(grid.isOnlyVisualChangeAllowed()).isFalse();

        verify(literalExpressionEditor).selectFirstCell();
        verify(gridLayer).batch();
    }

    @Test
    public void testSetExpressionWhenOnlyVisualChangeAllowed() {
        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           true);

        assertThat(grid.isOnlyVisualChangeAllowed()).isTrue();
    }

    @Test
    public void testResizeContainerCorrectlyResizesExpressionComponentWidth() {
        final BaseGridData literalExpressionModel = new BaseGridData();
        final DMNGridColumn literalExpressionEditorColumn = new LiteralExpressionColumn(Collections.emptyList(),
                                                                                autocompleteTextareaDOMElementFactory,
                                                                                DMNGridColumn.DEFAULT_WIDTH,
                                                                                literalExpressionEditor);
        literalExpressionModel.appendColumn(literalExpressionEditorColumn);

        when(literalExpressionEditor.getExpression()).thenReturn(() -> Optional.of(literalExpression));
        when(literalExpressionEditor.getModel()).thenReturn(literalExpressionModel);
        when(literalExpressionEditor.getPadding()).thenReturn(LITERAL_EXPRESSION_EDITOR_PADDING);
        when(hasExpression.getExpression()).thenReturn(literalExpression);

        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);
        grid.getModel().getColumns().get(0).setWidth(COLUMN_NEW_WIDTH);

        assertThat(literalExpression.getComponentWidths().get(0)).isEqualTo(COLUMN_NEW_WIDTH - LITERAL_EXPRESSION_EDITOR_PADDING * 2);
    }

    @Test
    public void testSetDefinedExpressionWhenReopeningWithResizedColumn() {
        //Emulate User setting expression and resizing column
        when(hasExpression.getExpression()).thenReturn(literalExpression);

        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);
        when(literalExpressionEditor.getWidth()).thenReturn(COLUMN_NEW_WIDTH);

        //Emulate re-opening editor
        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);

        //Verify width is preserved
        assertThat(grid.getModel().getColumns().get(0).getWidth()).isEqualTo(COLUMN_NEW_WIDTH);
    }

    @Test
    public void testSetDefinedExpressionWhenReopeningWhenWorkbenchRestarted() {
        //Emulate User setting expression and resizing column
        when(hasExpression.getExpression()).thenReturn(literalExpression);

        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);

        //Emulate re-starting the Workbench and re-opening the editor
        when(literalExpressionEditor.getWidth()).thenReturn(DMNGridColumn.DEFAULT_WIDTH);
        when(literalExpressionEditor.getMinimumWidth()).thenReturn(UndefinedExpressionColumn.DEFAULT_WIDTH);
        expressionGridCache.removeExpressionGrid(NODE_UUID);
        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);

        //Verify width is equal to the minimum required
        assertThat(grid.getModel().getColumns().get(0).getWidth()).isEqualTo(UndefinedExpressionColumn.DEFAULT_WIDTH);
    }

    @Test
    public void testGetItemsWithClearEnabled() {
        when(hasExpression.isClearSupported()).thenReturn(true);

        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);
        final List<HasListSelectorControl.ListSelectorItem> items = grid.getItems(0, 0);

        assertThat(items.size()).isEqualTo(1);

        final HasListSelectorControl.ListSelectorItem item = items.get(0);

        assertThat(item).isInstanceOf(HasListSelectorControl.ListSelectorTextItem.class);
        final HasListSelectorControl.ListSelectorTextItem ti = (HasListSelectorControl.ListSelectorTextItem) item;
        assertThat(ti.getText()).isEqualTo(DMNEditorConstants.ExpressionEditor_Clear);
        ti.getCommand().execute();
        verify(cellEditorControls).hide();
        verify(sessionCommandManager).execute(eq(canvasHandler),
                                              any(ClearExpressionTypeCommand.class));
    }

    @Test
    public void testGetItemsWithClearDisabled() {
        when(hasExpression.isClearSupported()).thenReturn(false);

        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);
        final List<HasListSelectorControl.ListSelectorItem> items = grid.getItems(0, 0);

        assertThat(items).isEmpty();
    }

    @Test
    public void testOnItemSelected() {
        final Command command = mock(Command.class);
        final HasListSelectorControl.ListSelectorTextItem listSelectorItem = mock(HasListSelectorControl.ListSelectorTextItem.class);
        when(listSelectorItem.getCommand()).thenReturn(command);

        grid.onItemSelected(listSelectorItem);

        verify(command).execute();
    }

    @Test
    public void testOnClearExpressionItemSelected() {
        //Emulate User setting expression and resizing column
        when(literalExpressionEditor.getWidth()).thenReturn(COLUMN_NEW_WIDTH);
        when(hasExpression.getExpression()).thenReturn(literalExpression);
        when(hasExpression.isClearSupported()).thenReturn(true);

        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);
        verify(gridLayer).select(literalExpressionEditor);
        verify(literalExpressionEditor).selectFirstCell();
        verify(gridLayer).batch();

        //Get and select ClearExpression item
        final List<HasListSelectorControl.ListSelectorItem> items = grid.getItems(0, 0);
        final HasListSelectorControl.ListSelectorItem item = items.get(0);
        final HasListSelectorControl.ListSelectorTextItem ti = (HasListSelectorControl.ListSelectorTextItem) item;

        ti.getCommand().execute();

        assertThat(grid.getModel().getColumns().get(0).getWidth()).isEqualTo(COLUMN_NEW_WIDTH);
        verify(sessionCommandManager).execute(eq(canvasHandler),
                                              clearExpressionTypeCommandCaptor.capture());

        final ClearExpressionTypeCommand clearExpressionTypeCommand = clearExpressionTypeCommandCaptor.getValue();
        //We're using a mock HasExpression therefore the ClearExpressionCommand does not change mocked behaviour. Reset mock.
        reset(hasExpression, gridLayer);

        clearExpressionTypeCommand.execute(canvasHandler);

        //Verify Expression has been cleared and UndefinedExpressionEditor resized
        assertThat(grid.getModel().getColumns().get(0).getWidth()).isEqualTo(DMNGridColumn.DEFAULT_WIDTH);
        verify(gridLayer).select(undefinedExpressionEditor);
        verify(undefinedExpressionEditor).selectFirstCell();
        verify(gridLayer).batch();

        //Check undo operation
        clearExpressionTypeCommand.undo(canvasHandler);

        //Verify Expression has been restored and UndefinedExpressionEditor resized
        assertThat(grid.getModel().getColumns().get(0).getWidth()).isEqualTo(COLUMN_NEW_WIDTH);
        verify(gridLayer).select(literalExpressionEditor);
        verify(literalExpressionEditor, times(2)).selectFirstCell();
        verify(gridLayer, times(2)).batch();
    }

    @Test
    public void testSpyHasNameWithHasNameGet() {
        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);

        final Optional<HasName> spy = grid.spyHasName(Optional.of(hasName));

        assertThat(spy.isPresent()).isTrue();
        assertThat(spy.get().getName().getValue()).isEqualTo(NAME);
    }

    @Test
    public void testSpyHasNameWithHasNameSetNameObject() {
        final String NEW_NAME = "new-name";

        final Name newName = new Name(NEW_NAME);

        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);

        final Optional<HasName> spy = grid.spyHasName(Optional.of(hasName));

        assertThat(spy.isPresent()).isTrue();
        spy.get().setName(newName);

        assertThat(hasName.getName().getValue()).isEqualTo(NEW_NAME);
        verify(isInformationItem).setName(eq(newName));
        verify(onHasNameChanged).execute(hasNameCaptor.capture());
        assertThat(hasNameCaptor.getValue().get().getName().getValue()).isEqualTo(NEW_NAME);
    }

    @Test
    public void testSpyHasNameWithoutHasNameGet() {
        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.empty(),
                           false);

        final Optional<HasName> spy = grid.spyHasName(Optional.empty());

        assertThat(spy.isPresent()).isTrue();
        assertThat(spy.get().getName().getValue()).isEqualTo(HasName.NOP.getName().getValue());
    }

    @Test
    @SuppressWarnings("unchecked")
    public void testSpyHasNameWithoutHasNameSetNameObject() {
        final String NEW_NAME = "new-name";

        final Name newName = new Name(NEW_NAME);

        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.empty(),
                           false);

        final Optional<HasName> spy = grid.spyHasName(Optional.empty());

        assertThat(spy.isPresent()).isTrue();
        spy.get().setName(newName);

        assertThat(hasName.getName().getValue()).isEqualTo(NAME);
        verify(onHasNameChanged, never()).execute(any(Optional.class));
    }

    @Test
    public void testSpyHasNameUpdateUndoWithSetHasNameCommand() {
        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);

        final Optional<HasName> spy = grid.spyHasName(Optional.of(hasName));

        final Name newName = new Name("new-name");
        final Name oldName = spy.get().getName();
        final org.uberfire.mvp.Command canvasOperation = mock(org.uberfire.mvp.Command.class);

        final SetHasValueCommand command = new SetHasValueCommand<>(spy.get(),
                                                                    newName,
                                                                    canvasOperation);

        command.execute(canvasHandler);
        spy.ifPresent(name -> assertThat(name.getName().getValue()).isEqualTo(newName.getValue()));

        command.undo(canvasHandler);
        spy.ifPresent(name -> assertThat(name.getName().getValue()).isEqualTo(oldName.getValue()));
    }

    @Test
    public void testSpyHasExpressionWithExpressionGet() {
        when(hasExpression.getExpression()).thenReturn(literalExpression);

        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);

        final HasExpression spy = grid.spyHasExpression(hasExpression);

        assertThat(spy.getExpression()).isEqualTo(literalExpression);
    }

    @Test
    public void testSpyHasExpressionWithoutExpressionGet() {
        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);

        final HasExpression spy = grid.spyHasExpression(hasExpression);

        assertThat(spy.getExpression()).isNull();
    }

    @Test
    public void testSpyHasExpressionWithExpressionSet() {
        final HasExpression hasExpression = new HasExpression() {

            private Expression expression = new LiteralExpression();

            @Override
            public Expression getExpression() {
                return expression;
            }

            @Override
            public void setExpression(final Expression expression) {
                this.expression = expression;
            }

            @Override
            public DMNModelInstrumentedBase asDMNModelInstrumentedBase() {
                return null;
            }
        };

        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);

        final HasExpression spy = grid.spyHasExpression(hasExpression);

        spy.setExpression(null);

        assertThat(hasExpression.getExpression()).isNull();
    }

    @Test
    public void testSpyHasExpressionWithExpressionAsDMNModelInstrumentedBase() {
        when(hasExpression.asDMNModelInstrumentedBase()).thenReturn(literalExpression);

        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);

        final HasExpression spy = grid.spyHasExpression(hasExpression);

        assertThat(spy.asDMNModelInstrumentedBase()).isEqualTo(literalExpression);
    }

    @Test
    public void testSelectCellWithPoint() {
        final Point2D point = mock(Point2D.class);
        final LiteralExpression domainObject = mock(LiteralExpression.class);
        when(hasExpression.asDMNModelInstrumentedBase()).thenReturn(domainObject);

        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);

        grid.selectCell(point, false, true);

        verify(gridLayer).select(eq(grid));
        verify(domainObjectSelectionEvent).fire(domainObjectSelectionEventCaptor.capture());

        final DomainObjectSelectionEvent domainObjectSelectionEvent = domainObjectSelectionEventCaptor.getValue();
        assertThat(domainObjectSelectionEvent.getCanvasHandler()).isEqualTo(canvasHandler);
        assertThat(domainObjectSelectionEvent.getDomainObject()).isEqualTo(domainObject);

        verify(cellSelectionManager).selectCell(eq(point), eq(false), eq(true));
    }

    @Test
    public void testSelectCellWithCoordinates() {
        final int uiRowIndex = 0;
        final int uiColumnIndex = 1;
        final LiteralExpression domainObject = mock(LiteralExpression.class);
        when(hasExpression.asDMNModelInstrumentedBase()).thenReturn(domainObject);

        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);

        grid.selectCell(uiRowIndex, uiColumnIndex, false, true);

        verify(gridLayer).select(eq(grid));
        verify(domainObjectSelectionEvent).fire(domainObjectSelectionEventCaptor.capture());

        final DomainObjectSelectionEvent domainObjectSelectionEvent = domainObjectSelectionEventCaptor.getValue();
        assertThat(domainObjectSelectionEvent.getCanvasHandler()).isEqualTo(canvasHandler);
        assertThat(domainObjectSelectionEvent.getDomainObject()).isEqualTo(domainObject);

        verify(cellSelectionManager).selectCell(eq(uiRowIndex), eq(uiColumnIndex), eq(false), eq(true));
    }

    @Test
    public void testSelectCellWithCoordinatesNonDomainObject() {
        final int uiRowIndex = 0;
        final int uiColumnIndex = 1;

        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);

        grid.selectCell(uiRowIndex, uiColumnIndex, false, true);

        verify(gridLayer).select(eq(grid));
        verify(domainObjectSelectionEvent).fire(domainObjectSelectionEventCaptor.capture());

        final DomainObjectSelectionEvent domainObjectSelectionEvent = domainObjectSelectionEventCaptor.getValue();
        assertThat(domainObjectSelectionEvent.getCanvasHandler()).isEqualTo(canvasHandler);
        assertThat(domainObjectSelectionEvent.getDomainObject()).isInstanceOf(NOPDomainObject.class);

        verify(cellSelectionManager).selectCell(eq(uiRowIndex), eq(uiColumnIndex), eq(false), eq(true));
    }

    @Test
    public void testSelectCellWithDomainObjectInStunnerGraph() {
        final int uiRowIndex = 0;
        final int uiColumnIndex = 1;
        final LiteralExpression domainObject = mock(LiteralExpression.class);
        when(hasExpression.asDMNModelInstrumentedBase()).thenReturn(domainObject);
        when(graph.nodes()).thenReturn(Collections.singletonList(node));

        final Definition definition = mock(Definition.class);
        when(node.getUUID()).thenReturn(NODE_UUID);
        when(node.getContent()).thenReturn(definition);
        when(definition.getDefinition()).thenReturn(domainObject);

        grid.setExpression(NODE_UUID,
                           hasExpression,
                           Optional.of(hasName),
                           false);

        grid.selectCell(uiRowIndex, uiColumnIndex, false, true);

        verify(gridLayer).select(eq(grid));
        verify(refreshFormPropertiesEvent).fire(refreshFormPropertiesEventCaptor.capture());

        final RefreshFormPropertiesEvent refreshFormPropertiesEvent = refreshFormPropertiesEventCaptor.getValue();
        assertThat(refreshFormPropertiesEvent.getUuid()).isEqualTo(NODE_UUID);
        assertThat(refreshFormPropertiesEvent.getSession()).isEqualTo(session);

        verify(cellSelectionManager).selectCell(eq(uiRowIndex), eq(uiColumnIndex), eq(false), eq(true));
    }

    @Test
    public void testGetBaseExpressionGrid() {

        final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> expectedBaseExpressionGrid = Optional.of(mock(LiteralExpressionGrid.class));
        final ExpressionCellValue value = mock(ExpressionCellValue.class);
        final GridCell<?> cell = new BaseGridCell<>(value);
        final Supplier<GridCell<?>> cellSupplier = () -> cell;

        when(value.getValue()).thenReturn(expectedBaseExpressionGrid);
        grid.getModel().setCell(0, 0, cellSupplier);

        assertEquals(expectedBaseExpressionGrid, grid.getBaseExpressionGrid());
    }
}


text:
package io.github.zwieback.relef.analyzers;

public abstract class Analyzer {

    public abstract void analyze();
}


text:
local peripheral = {}

function peripheral.wrap(channel,timeout)
	local pos = dronetest.active_systems[dronetest.current_id].pos
	-- use a unique message-id so we are able to identify the response to our request easily.
	local msg_id = sys:getUniqueId()
	-- this should be wrapped in sys:sendDigilineMessage
	digiline:receptor_send(pos, digiline.rules.default,channel, {action="GET_CAPABILITIES",msg_id=msg_id})

	-- wait for answer, this should be in a sys:function, with a timeout!
	--[[
	local e = nil
	while e == nil do
		sleep(0.05)
		e = sys:receiveDigilineMessage(channel,msg_id)
	end
	--]]
	e = sys:waitForDigilineMessage(channel,msg_id,timeout)
	if e == nil then
		print("could not reach peripheral on channel '"..channel.."'.")
		return nil
	end
	-- create functions to execute actions the peripheral offered
	local newp = {}
	for name,desc in pairs(e.msg) do
		print("wrap peripheral's method "..name..": "..dump(desc))
		newp[name] = function(a,b,c,d,e)
			local pos = dronetest.active_systems[dronetest.current_id].pos
			local msg_id = sys:getUniqueId()
		--	dronetest.log("action: "..name.." @ "..channel)
			-- send action -- we attach a print() function, so the peripheral, when called from a computer, can print to its screen
			digiline:receptor_send(pos, digiline.rules.default,channel, {action=name,argv={a,b,c,d,e},msg_id=msg_id,print=function(msg) print(msg) end})

			-- receive answer, see above
			e = sys:waitForDigilineMessage(channel,msg_id,timeout)
			if e == nil then
				print("system "..dronetest.current_id.." could not reach peripheral on channel '"..channel.."' for action '"..name.."'.")
				return nil
			end

			return unpack(e.msg)
		end

	end

	return newp
end

function peripheral.wrap_digilines(channel)
	local newp = {
		channel = channel,
		sendAndReceive = function(msg,timeout)
			local pos = dronetest.active_systems[dronetest.current_id].pos
			local msg_id = sys:getUniqueId()
			digiline:receptor_send(pos, digiline.rules.default,channel, {action=msg,msg_id=msg_id})
			e = sys:waitForDigilineMessage(channel,msg_id,timeout)
			if e == nil then
				print("could not reach peripheral on channel '"..channel.."'.")
				return nil
			end
			return unpack(e.msg)
		end,
		send = function(msg)
			local pos = dronetest.active_systems[dronetest.current_id].pos
			digiline:receptor_send(pos, digiline.rules.default,channel, {action=msg,msg_id=msg_id})
		end,
		receive = function(timeout)
			return sys:waitForDigilineMessage(channel,"",timeout)
		end
	}
	return newp

end
return peripheral


text:
<?php

namespace Vespolina\Sync\Handler;

/**
 * Interface to determine and handle dependencies for a generic entity
 *
 * @author Daniel Kucharski <daniel@vespolina.org>
 */
class DefaultEntityHandler implements EntityHandlerInterface
{
    public function hasDependencies($entity)
    {
        return false;
    }

    public function emit($entity)
    {
    }

    public function merge(array $resolvedDependencies)
    {
    }
}


text:
module Resolvers
  class BoardListIssuesResolver < BaseResolver
    type Types::IssueType, null: true

    alias_method :list, :object

    def resolve(**args)
      service = Boards::Issues::ListService.new(list.board.resource_parent, context[:current_user], { board_id: list.board.id, id: list.id })
      Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection.new(service.execute)
    end

    # https://gitlab.com/gitlab-org/gitlab/-/issues/235681
    def self.complexity_multiplier(args)
      0.005
    end
  end
end


text:
<?php

namespace Abds\MaincoreBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Abds\MaincoreBundle\Entity\Game_User
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Abds\MaincoreBundle\Entity\Game_UserRepository")
 */
class Game_User
{
	/**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="Abds\MaincoreBundle\Entity\Game")
     */
    private $game;

	/**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="Abds\MaincoreBundle\Entity\User")
     */
    private $user;

	/**
     *
     * @ORM\ManyToOne(targetEntity="Abds\MaincoreBundle\Entity\Enjoy")
     */
	private $enjoy;

	public function getGame()
	{
		return $this->game;
	}

	public function setGame(Abds\MaincoreBundle\Entity\Game $game)
	{
		$this->game = $game;
	}

	public function getUser()
	{
		return $this->user;
	}

	public function setUser(Abds\MaincoreBundle\Entity\User $user)
	{
		$this->user = $user;
	}

	public function getEnjoy()
	{
		return $this->enjoy;
	}

	public function setEnjoy(Abds\MaincoreBundle\Entity\Enjoy $enjoy)
	{
		$this->enjoy = $enjoy;
	}
}


text:
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/phpcr/doctrine-mapping"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <document
        name="Symfony\Cmf\Bundle\MenuBundle\Document\MultilangMenu"
        translator="attribute"
        >
    </document>

</doctrine-mapping>


text:
var Meteor = require('meteor/meteor')
it("environment - server basics", function (done) {
  test.isFalse(Meteor.isClient);
  test.isTrue(Meteor.isServer);
  done()
});


text:
<?php

namespace Fnash\ApiKeyBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
    /**
     * {@inheritdoc}
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('Fnash_api_key');

        $rootNode
            ->children()
                ->scalarNode('delivery')
                    ->defaultValue('query')
                    ->validate()
                        ->ifNotInArray(array('query', 'header'))
                        ->thenInvalid('Unknown authentication delivery type "%s".')
                     ->end()
                 ->end()
                ->scalarNode('parameter_name')
                    ->defaultValue('api_key')
                 ->end()
            ->end()
        ;

        return $treeBuilder;
    }
}


text:
<?php
/**
 * @var modX $modx
 * @var sTask $task
 * @var sTaskRun $run
 * @var array $scriptProperties
 */

// Repeat in a hour
$task->schedule('+59 minutes');

// Grab modxStats for the model
$path = $modx->getOption('modxstats.core_path', null, $modx->getOption('core_path') . 'components/modxstats/');
$modxstats = $modx->getService('modxstats', 'modxStats', $path . 'model/modxstats/');

// Load the recent posts page from the forum; this contains all the info we need
$html = file_get_contents('http://forums.modx.com/thread/recent');

// We'll extract these in a moment using some regex.
$recentPosts = 0;
$posts = 0;
$threads = 0;
$members = 0;

// Extract the recent posts
$found = preg_match('/
Recent Posts \(([\d,]+)?\)<\/h1>/', $html, $matches);
if ($found && isset($matches[1])) {
    $recentPosts = (int)str_replace(',', '', $matches[1]);
}

// Extract number of posts
$found = preg_match('/
Posts: ([\d,]+)<\/span><\/li>/', $html, $matches);
if ($found && isset($matches[1])) {
    $posts = (int)str_replace(',', '', $matches[1]);
}

// Extract number of threads
$found = preg_match('/
Threads: ([\d,]+)<\/span><\/li>/', $html, $matches);
if ($found && isset($matches[1])) {
    $threads = (int)str_replace(',', '', $matches[1]);
}

// Extract number of members
$found = preg_match('/
Members: ([\d,]+)<\/span><\/li>/', $html, $matches);
if ($found && isset($matches[1])) {
    $members = (int)str_replace(',', '', $matches[1]);
}

// Collect stuff
$data = array(
    'collected_on' => time(),
    'recent_posts' => $recentPosts,
    'posts' => $posts,
    'threads' => $threads,
    'members' => $members,
);

// Store it in the database
$forumTotals = $modx->newObject('msForumTotals', $data);
$forumTotals->fromArray($data);

if (!$forumTotals->save()) {
    $run->addError('error_save_object');
}

// Return the data to Scheduler
return 'Collected data! ' . $modx->toJSON($data);


text:
import unittest
from time import sleep

MICROBIT1_BD_ADDR='0xf5:0x3a:0xc9:0xb0:0x15:0xf6'

SCANTIME = 5            # seconds

from .le_scan_test import BluetoothLEScanTest

class TestLEScan(unittest.TestCase):

    def test_lescan_find_microbit1(self):
        ble_scan_test = BluetoothLEScanTest()

        ble_scan_test.set_scan_enable(False)
        ble_scan_test.set_filter()
        ble_scan_test.set_scan_parameters()
        ble_scan_test.set_scan_enable(True, True)

        sleep(SCANTIME)

        ble_scan_test.set_scan_enable(False)

        self.assertTrue(MICROBIT1_BD_ADDR in ble_scan_test.found_bd_addrs)