Various cleanups in the matter.idl module (#38196)

* Cleanup typos in the code

* Simplify IDL usage in scripts

* Fix matter_idl_generator_files

* Keep tests only in matter-idl GN

* Restyled by isort

* Fix Java CI

* Activate env prior to gn gen in gn_silabs_example.sh

---------

Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/.github/workflows/java-tests.yaml b/.github/workflows/java-tests.yaml
index eacc82c..bb48176 100644
--- a/.github/workflows/java-tests.yaml
+++ b/.github/workflows/java-tests.yaml
@@ -37,6 +37,7 @@
         name: Linux
 
         env:
+            PW_PROJECT_ROOT: ${{ github.workspace }}
             TSAN_OPTIONS: "halt_on_error=1 suppressions=scripts/tests/chiptest/tsan-linux-suppressions.txt"
 
         if: github.actor != 'restyled-io[bot]'
diff --git a/scripts/examples/gn_silabs_example.sh b/scripts/examples/gn_silabs_example.sh
index 32c542b..644f9c8 100755
--- a/scripts/examples/gn_silabs_example.sh
+++ b/scripts/examples/gn_silabs_example.sh
@@ -41,7 +41,6 @@
 USE_WIFI=false
 USE_DOCKER=false
 USE_GIT_SHA_FOR_VERSION=true
-USE_SLC=false
 GN_PATH="$PW_PATH/gn"
 USE_BOOTLOADER=false
 DOTFILE=".gn"
@@ -264,7 +263,6 @@
 
             --slc_generate)
                 optArgs+="slc_generate=true "
-                USE_SLC=true
                 shift
                 ;;
             --use_pw_rpc)
@@ -321,11 +319,8 @@
         } &>/dev/null
     fi
 
-    if [ "$USE_SLC" == false ]; then
-        # Activation needs to be after SLC generation which is done in gn gen.
-        # Zap generation requires activation and is done in the build phase
-        source "$CHIP_ROOT/scripts/activate.sh"
-    fi
+    # Zap generation requires activation
+    source "$CHIP_ROOT/scripts/activate.sh"
 
     if [ "$USE_WIFI" == true ]; then
         DOTFILE="$ROOT/build_for_wifi_gnfile.gn"
@@ -349,12 +344,6 @@
 
     "$GN_PATH" gen --check --script-executable="$PYTHON_PATH" --fail-on-unused-args --add-export-compile-commands=* --root="$ROOT" --dotfile="$DOTFILE" --args="silabs_board=\"$SILABS_BOARD\" $optArgs" "$BUILD_DIR"
 
-    if [ "$USE_SLC" == true ]; then
-        # Activation needs to be after SLC generation which is done in gn gen.
-        # Zap generation requires activation and is done in the build phase
-        source "$CHIP_ROOT/scripts/activate.sh"
-    fi
-
     ninja -C "$BUILD_DIR"/
     #print stats
     arm-none-eabi-size -A "$BUILD_DIR"/*.out
diff --git a/scripts/idl_lint.py b/scripts/idl_lint.py
index f21a337..99571a3 100755
--- a/scripts/idl_lint.py
+++ b/scripts/idl_lint.py
@@ -20,15 +20,8 @@
 import click
 import coloredlogs
 
-try:
-    from matter.idl import matter_idl_parser
-except ImportError:
-    sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'py_matter_idl')))
-    from matter.idl import matter_idl_parser
-
-# isort: off
 import matter.idl.lint
-
+from matter.idl import matter_idl_parser
 
 # Supported log levels, mapping string values required for argument
 # parsing into logging constants
diff --git a/scripts/py_matter_idl/BUILD.gn b/scripts/py_matter_idl/BUILD.gn
index 0267608..5973249 100644
--- a/scripts/py_matter_idl/BUILD.gn
+++ b/scripts/py_matter_idl/BUILD.gn
@@ -26,7 +26,9 @@
     "setup.cfg",
     "pyproject.toml",
   ]
-  inputs = matter_idl_generator_templates
+
+  inputs = []
+  inputs += matter_idl_generator_templates
   inputs += [
     # Dependency grammar
     "matter/idl/matter_grammar.lark",
@@ -34,6 +36,10 @@
     # Marker file to indicate to mypy that matter_idl is type-annotated
     "matter/idl/py.typed",
 
+    # IDL plugin example used by test
+    "examples/matter_idl_plugin/__init__.py",
+    "examples/matter_idl_plugin/matter_cluster_proto.jinja",
+
     # Unit test data
     "matter/idl/tests/available_tests.yaml",
     "matter/idl/tests/inputs/cluster_struct_attribute.matter",
diff --git a/scripts/py_matter_idl/examples/matter_idl_plugin/__init__.py b/scripts/py_matter_idl/examples/matter_idl_plugin/__init__.py
index b849d7e..ef8640c 100644
--- a/scripts/py_matter_idl/examples/matter_idl_plugin/__init__.py
+++ b/scripts/py_matter_idl/examples/matter_idl_plugin/__init__.py
@@ -196,7 +196,7 @@
 
     def __init__(self, storage: GeneratorStorage, idl: Idl, **kargs):
         """
-        Inintialization is specific for java generation and will add
+        Initialization is specific for java generation and will add
         filters as required by the java .jinja templates to function.
         """
         super().__init__(storage, idl, fs_loader_searchpath=os.path.dirname(__file__))
diff --git a/scripts/py_matter_idl/files.gni b/scripts/py_matter_idl/files.gni
index 4dd43d6..95be851 100644
--- a/scripts/py_matter_idl/files.gni
+++ b/scripts/py_matter_idl/files.gni
@@ -18,11 +18,16 @@
   "${chip_root}/scripts/py_matter_idl/matter/idl/generators/cpp/tlvmeta/TLVMetaData_cpp.jinja",
   "${chip_root}/scripts/py_matter_idl/matter/idl/generators/cpp/tlvmeta/TLVMetaData_h.jinja",
   "${chip_root}/scripts/py_matter_idl/matter/idl/generators/idl/MatterIdl.jinja",
-  "${chip_root}/scripts/py_matter_idl/matter/idl/generators/java/ChipEventStructs.jinja",
-  "${chip_root}/scripts/py_matter_idl/matter/idl/generators/java/ChipStructs.jinja",
-  "${chip_root}/scripts/py_matter_idl/matter/idl/generators/java/ClusterIDMapping.jinja",
   "${chip_root}/scripts/py_matter_idl/matter/idl/generators/java/ClusterReadMapping.jinja",
+  "${chip_root}/scripts/py_matter_idl/matter/idl/generators/java/ChipStructFiles_gni.jinja",
+  "${chip_root}/scripts/py_matter_idl/matter/idl/generators/java/ChipStructs.jinja",
   "${chip_root}/scripts/py_matter_idl/matter/idl/generators/java/ClusterWriteMapping.jinja",
+  "${chip_root}/scripts/py_matter_idl/matter/idl/generators/java/ClusterInfoMapping_java.jinja",
+  "${chip_root}/scripts/py_matter_idl/matter/idl/generators/java/ChipEventStructs.jinja",
+  "${chip_root}/scripts/py_matter_idl/matter/idl/generators/java/ChipStructs_java.jinja",
+  "${chip_root}/scripts/py_matter_idl/matter/idl/generators/java/ChipEventStructs_java.jinja",
+  "${chip_root}/scripts/py_matter_idl/matter/idl/generators/java/ChipClusters_java.jinja",
+  "${chip_root}/scripts/py_matter_idl/matter/idl/generators/java/ClusterIDMapping.jinja",
 ]
 
 matter_idl_generator_sources = [
@@ -46,17 +51,13 @@
   "${chip_root}/scripts/py_matter_idl/matter/idl/generators/idl/__init__.py",
   "${chip_root}/scripts/py_matter_idl/matter/idl/generators/java/__init__.py",
   "${chip_root}/scripts/py_matter_idl/matter/idl/generators/registry.py",
+  "${chip_root}/scripts/py_matter_idl/matter/idl/generators/storage.py",
   "${chip_root}/scripts/py_matter_idl/matter/idl/generators/type_definitions.py",
   "${chip_root}/scripts/py_matter_idl/matter/idl/lint/__init__.py",
   "${chip_root}/scripts/py_matter_idl/matter/idl/lint/lint_rules_parser.py",
   "${chip_root}/scripts/py_matter_idl/matter/idl/lint/type_definitions.py",
   "${chip_root}/scripts/py_matter_idl/matter/idl/matter_idl_parser.py",
   "${chip_root}/scripts/py_matter_idl/matter/idl/matter_idl_types.py",
-  "${chip_root}/scripts/py_matter_idl/matter/idl/test_backwards_compatibility.py",
-  "${chip_root}/scripts/py_matter_idl/matter/idl/test_data_model_xml.py",
-  "${chip_root}/scripts/py_matter_idl/matter/idl/test_generators.py",
-  "${chip_root}/scripts/py_matter_idl/matter/idl/test_matter_idl_parser.py",
-  "${chip_root}/scripts/py_matter_idl/matter/idl/test_zapxml.py",
   "${chip_root}/scripts/py_matter_idl/matter/idl/zapxml/__init__.py",
   "${chip_root}/scripts/py_matter_idl/matter/idl/zapxml/handlers/__init__.py",
   "${chip_root}/scripts/py_matter_idl/matter/idl/zapxml/handlers/base.py",
diff --git a/scripts/py_matter_idl/matter/idl/generators/__init__.py b/scripts/py_matter_idl/matter/idl/generators/__init__.py
index 6afea11..0168d2c 100644
--- a/scripts/py_matter_idl/matter/idl/generators/__init__.py
+++ b/scripts/py_matter_idl/matter/idl/generators/__init__.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # Copyright (c) 2022 Project CHIP Authors
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/scripts/py_matter_idl/matter/idl/generators/filters.py b/scripts/py_matter_idl/matter/idl/generators/filters.py
index 8f81c20..cb65cb9 100644
--- a/scripts/py_matter_idl/matter/idl/generators/filters.py
+++ b/scripts/py_matter_idl/matter/idl/generators/filters.py
@@ -50,7 +50,7 @@
 
 
 def to_snake_case(s: str) -> str:
-    """convert to snake case; all words are seperated by underscore and are lower case
+    """convert to snake case; all words are separated by underscore and are lower case
        examples:
         FooBarBaz --> foo_bar_baz
         foo BarBaz --> foo_bar_baz
@@ -68,7 +68,7 @@
 
 
 def to_constant_case(s: str) -> str:
-    """convert to constant case; all words are seperated by underscore and are upper case
+    """convert to constant case; all words are separated by underscore and are upper case
        similar to a snake case but with upper case
        examples:
        FooBarBaz --> FOO_BAR_BAZ
@@ -81,8 +81,8 @@
 
 
 def to_spinal_case(s: str) -> str:
-    """convert to spinal case; all words sperated by hypen and are lower case
-        similar to a snake case but with hyphen seperator instead of underscore 
+    """convert to spinal case; all words separated by hyphen and are lower case
+        similar to a snake case but with hyphen separator instead of underscore
         examples:
         FooBarBaz --> foo-bar-baz
         foo BarBaz --> foo-bar-baz
diff --git a/scripts/py_matter_idl/matter/idl/generators/idl/README.md b/scripts/py_matter_idl/matter/idl/generators/idl/README.md
index 18bdf25..5b1b30e 100644
--- a/scripts/py_matter_idl/matter/idl/generators/idl/README.md
+++ b/scripts/py_matter_idl/matter/idl/generators/idl/README.md
@@ -10,7 +10,7 @@
 
 A no-op usage can be:
 
-```
+```shell
 ./scripts/codegen.py -g idl --output-dir out/idlgen examples/all-clusters-app/all-clusters-common/all-clusters-app.matter
 ```
 
diff --git a/scripts/py_matter_idl/matter/idl/generators/java/__init__.py b/scripts/py_matter_idl/matter/idl/generators/java/__init__.py
index 2dfd7c8..1c120db 100644
--- a/scripts/py_matter_idl/matter/idl/generators/java/__init__.py
+++ b/scripts/py_matter_idl/matter/idl/generators/java/__init__.py
@@ -723,7 +723,7 @@
 
     def __init__(self, storage: GeneratorStorage, idl: Idl, **kargs):
         """
-        Inintialization is specific for java generation and will add
+        Initialization is specific for java generation and will add
         filters as required by the java .jinja templates to function.
         """
         super().__init__(storage, idl, fs_loader_searchpath=os.path.dirname(__file__))
diff --git a/scripts/py_matter_idl/matter/idl/generators/kotlin/__init__.py b/scripts/py_matter_idl/matter/idl/generators/kotlin/__init__.py
index 30e6bcf..91ff2f5 100644
--- a/scripts/py_matter_idl/matter/idl/generators/kotlin/__init__.py
+++ b/scripts/py_matter_idl/matter/idl/generators/kotlin/__init__.py
@@ -624,7 +624,7 @@
 
     def __init__(self, storage: GeneratorStorage, idl: Idl, **kargs):
         """
-        Inintialization is specific for kotlin generation and will add
+        Initialization is specific for kotlin generation and will add
         filters as required by the kotlin .jinja templates to function.
         """
         super().__init__(storage, idl, fs_loader_searchpath=os.path.dirname(__file__))
diff --git a/scripts/py_matter_idl/matter/idl/generators/markdown/__init__.py b/scripts/py_matter_idl/matter/idl/generators/markdown/__init__.py
index 3c44059..6ad508b 100644
--- a/scripts/py_matter_idl/matter/idl/generators/markdown/__init__.py
+++ b/scripts/py_matter_idl/matter/idl/generators/markdown/__init__.py
@@ -11,6 +11,7 @@
 # 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.
+
 import os
 
 from matter.idl.generators import CodeGenerator
diff --git a/scripts/py_matter_idl/matter/idl/lint/lint_rules_parser.py b/scripts/py_matter_idl/matter/idl/lint/lint_rules_parser.py
old mode 100755
new mode 100644
index f663375..c3f70ba
--- a/scripts/py_matter_idl/matter/idl/lint/lint_rules_parser.py
+++ b/scripts/py_matter_idl/matter/idl/lint/lint_rules_parser.py
@@ -1,4 +1,16 @@
-#!/usr/bin/env python
+# Copyright (c) 2022 Project CHIP Authors
+#
+# 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.
 
 import logging
 import os
@@ -10,16 +22,8 @@
 from lark import Lark
 from lark.visitors import Discard, Transformer, v_args
 
-try:
-    from matter.idl.lint.type_definitions import AttributeRequirement
-except ImportError:
-    import sys
-    sys.path.append(os.path.join(os.path.abspath(
-        os.path.dirname(__file__)), "..", ".."))
-    from matter.idl.lint.type_definitions import AttributeRequirement
-
-from matter.idl.lint.type_definitions import (ClusterAttributeDeny, ClusterCommandRequirement, ClusterRequirement,
-                                              ClusterValidationRule, RequiredAttributesRule, RequiredCommandsRule)
+from .type_definitions import (AttributeRequirement, ClusterAttributeDeny, ClusterCommandRequirement, ClusterRequirement,
+                               ClusterValidationRule, RequiredAttributesRule, RequiredCommandsRule)
 
 
 class ElementNotFoundError(Exception):
diff --git a/scripts/py_matter_idl/matter/idl/matter_idl_parser.py b/scripts/py_matter_idl/matter/idl/matter_idl_parser.py
old mode 100755
new mode 100644
index 181b82d..d8f366d
--- a/scripts/py_matter_idl/matter/idl/matter_idl_parser.py
+++ b/scripts/py_matter_idl/matter/idl/matter_idl_parser.py
@@ -1,4 +1,16 @@
-#!/usr/bin/env python
+# Copyright (c) 2022 Project CHIP Authors
+#
+# 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.
 
 import dataclasses
 import functools
@@ -40,7 +52,7 @@
             actual_pos += 1
 
         # A doc comment will apply to any supported element assuming it immediately
-        # preceeds id (skipping whitespace)
+        # precedes id (skipping whitespace)
         for item in self.supported_types(idl):
             meta = item.parse_meta
             if meta and meta.start_pos == actual_pos:
diff --git a/scripts/py_matter_idl/matter/idl/matter_idl_types.py b/scripts/py_matter_idl/matter/idl/matter_idl_types.py
index 62a8d8e..a4920fe 100644
--- a/scripts/py_matter_idl/matter/idl/matter_idl_types.py
+++ b/scripts/py_matter_idl/matter/idl/matter_idl_types.py
@@ -1,3 +1,17 @@
+# Copyright (c) 2022 Project CHIP Authors
+#
+# 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.
+
 import enum
 from dataclasses import dataclass, field
 from typing import List, Optional, Set, Union
diff --git a/scripts/py_matter_idl/matter/idl/test_case_conversion.py b/scripts/py_matter_idl/matter/idl/test_case_conversion.py
old mode 100644
new mode 100755
index 87524c8..8d9fa56
--- a/scripts/py_matter_idl/matter/idl/test_case_conversion.py
+++ b/scripts/py_matter_idl/matter/idl/test_case_conversion.py
@@ -1,3 +1,17 @@
+#!/usr/bin/env python3
+# Copyright (c) 2023 Project CHIP Authors
+#
+# 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.
 
 import unittest
 
diff --git a/scripts/py_matter_idl/setup.cfg b/scripts/py_matter_idl/setup.cfg
index cc6ce90..a06bb4b 100644
--- a/scripts/py_matter_idl/setup.cfg
+++ b/scripts/py_matter_idl/setup.cfg
@@ -16,6 +16,10 @@
 name = matter-idl
 version = 1.0.0
 description = Parse matter IDL files
+classifiers =
+    Intended Audience :: Developers
+    License :: OSI Approved :: Apache Software License
+    Programming Language :: Python :: 3
 
 [options]
 packages = find_namespace: