User Tools

Site Tools


zh_cn:tutorial:accesswideners

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
zh_cn:tutorial:accesswideners [2021/10/03 12:39] – 初次添加,待完成 hendrix-shenzh_cn:tutorial:accesswideners [2021/10/25 10:11] – [Access Changes] solidblock
Line 1: Line 1:
 ====== Access Wideners ====== ====== Access Wideners ======
  
-Access wideners 提供了一种放宽类、方法、字段访问权限的方式。Access wideners 类似于著名的 Access Transformers.+Access wideners(访问加宽)提供了一种放宽类、方法、字段访问权限的方式。Access wideners 类似于著名的 Access Transformers.
  
-Access wideners 应该**仅在**使用 Mixin 无法实现时使用+Access wideners 应该**仅在**使用 Mixin 无法实现时使用目前只有以下两种情景 Mixin 无法做到:
-目前只有以下两种情景 Mixin 无法做到:+
   * 需要访问一个(包内)的私有类,尤其是为了 @Shadow 修饰或在 Mixin 类内访问一个字段或方法。   * 需要访问一个(包内)的私有类,尤其是为了 @Shadow 修饰或在 Mixin 类内访问一个字段或方法。
   * 需要重写使用 final 修饰的子类。   * 需要重写使用 final 修饰的子类。
     * 在你考虑重写使用 final 修饰的方法之前,使用注入器等方法修改。     * 在你考虑重写使用 final 修饰的方法之前,使用注入器等方法修改。
     * 如果你想为一个包含私有构造方法的类创建子类,wideners 是个不错的选择     * 如果你想为一个包含私有构造方法的类创建子类,wideners 是个不错的选择
-    * +
 为了让 access widener 造成的的变化显示在反编译的源代码中,请运行 ''genSources'' gradle任务。 为了让 access widener 造成的的变化显示在反编译的源代码中,请运行 ''genSources'' gradle任务。
  
Line 17: Line 16:
 ===== 文件格式 ===== ===== 文件格式 =====
  
-一个特定的文件格式被用来定义你的mod中包含的访问变化。为了帮助IDE,你应该使用".accesswidener "的文件扩展名。 
  
-需要在你的模组里包含一个声明修改访问权限的特殊文件,为了方便,你应该在IDE中使用 ''.accesswidener'' 文件扩展+需要在你的模组里包含一个声明修改访问权限的特殊文件,为了帮助,你应该在IDE中使用 ''.accesswidener'' 文件扩展名。
  
 该文件首行应该遵循下述格式,''命名空间'' 应该与你模组源码使用混淆命名空间匹配,通常是 ''named''。 Loom 将会为你重新映射 access widener 文件,使其更改为 ''intermediary''。如果你使用自定义的 ''RemapJarTask'',设置 ''remapAccessWidener'' 为 ''true'' 来确保上述行为发生。 该文件首行应该遵循下述格式,''命名空间'' 应该与你模组源码使用混淆命名空间匹配,通常是 ''named''。 Loom 将会为你重新映射 access widener 文件,使其更改为 ''intermediary''。如果你使用自定义的 ''RemapJarTask'',设置 ''remapAccessWidener'' 为 ''true'' 来确保上述行为发生。
Line 27: Line 25:
 </code> </code>
  
-**再次提醒,命名空间应该在你使用 yarn 命名时设置为 ''named'', 使用 中间名 命名时设置为 ''intermediary''。**+**再次提醒,命名空间应该在你使用 yarn 命名时设置为 ''named'', 使用中间名命名时设置为 ''intermediary''。**
  
 Access widener 文件允许使用空行和和以 # 开头的注释。 Access widener 文件允许使用空行和和以 # 开头的注释。
Line 51: Line 49:
   - 访问权可以是 //accessible// 或 //extendable//   - 访问权可以是 //accessible// 或 //extendable//
  
-== Methods ==+== 方法 ==
  
-Method access can be changed by specifying the access, class name, method name and method descriptor as named the mappings namespace defined in the header.+可以通过指定访问权限、类名称、方法名称和方法描述符来改变方法访问权,就像上面定义的映射命名空间一样。
  
 <code [enable_line_numbers="true"]> <code [enable_line_numbers="true"]>
Line 59: Line 57:
 </code> </code>
  
-  - access can be //accessible// or //extendable// +  - access 可以是 //accessible// 或 //extendable// 
-  - classname is the owner class +  - classname 是拥有者类 
-  - methodName is the method name +  - methodName 是方法名称 
-  - methodDesc is the method descriptior+  - methodDesc 是方法描述符
  
-== Fields ==+== 字段 ==
  
-Field access can be changed by specifying the access, class name, field name and field descriptor as named the mappings namespace defined in the header.+字段的访问权可以通过指定访问权、类名称、字段名称和字段描述符来修改,就像上面定义的映射命名空间一样。
  
 <code [enable_line_numbers="true"]> <code [enable_line_numbers="true"]>
Line 72: Line 70:
 </code> </code>
  
-  - access can be //accessible// or //mutable// +  - access 可以是 //accessible// 或 //mutable// 
-  - className is the owner class +  - className 是拥有者类 
-  - fieldName is the field name +  - fieldName 是字段名称 
-  - fieldDesc is the field descriptor+  - fieldDesc 是字段描述符
  
-===== Access Changes =====+===== 访问权变更 =====
  
-=== Extendable ===+=== Extendable(可继承) ===
  
-Extendable should be used where you want to extend a class or override a method.+需要继承最终类或者覆盖最终方法时,用 extendable。
  
-  * Classes are made public and final is removed +  * 类将会改成 public 并移除 final 修饰符 
-  * Methods are made protected and final is removed+  * 方法会改成 protected 并移除 final 修饰符
  
-Making a method extendable also makes the class extendable.+将方法改为 extendable 的同时也会使类变为 extendable
  
-=== Accessible ===+=== Accessible(可访问) ===
  
-Accessible should be used when you want to access a class, field or method from another class.+需要访问另一个类的类、字段或方法时,用 accessible。
  
-  * Classes are made public +  * 类将变为 public 
-  * Methods are made public and final if private +  * 方法将变为 public,并且若为 private,还会变为 final 
-  * Fields are made public+  * 字段将会变为 public
  
-Making a method or field accessible also makes the class accessible.+将方法或者字段改为 accessible 将会使得类也 accessible
  
-=== Mutable ===+=== Mutable(可修改) ===
  
-Mutable should be used when you want to mutate a final field+需要修改常量字段时,用 mutable。
  
-  * Fields have final removed+  * 字段将会移除 final 修饰符
  
 ===== Specifying file location ===== ===== Specifying file location =====
zh_cn/tutorial/accesswideners.txt · Last modified: 2021/10/25 10:14 by solidblock