From efe9a4595abcd904a4ef2473432f86b637cb96ee Mon Sep 17 00:00:00 2001 From: lixiangrong Date: Mon, 7 Mar 2016 16:01:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../osc/git/eh3/annotation/PkgAnnotation.java | 19 ++++++++++++ .../git/eh3/annotation/TestPkgAnnotation.java | 18 +++++++++++ .../osc/git/eh3/annotation/package-info.java | 25 +++++++++++++++ src/main/resources/generatorConfig.xml | 31 +++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 src/main/java/osc/git/eh3/annotation/PkgAnnotation.java create mode 100644 src/main/java/osc/git/eh3/annotation/TestPkgAnnotation.java create mode 100644 src/main/java/osc/git/eh3/annotation/package-info.java create mode 100644 src/main/resources/generatorConfig.xml diff --git a/src/main/java/osc/git/eh3/annotation/PkgAnnotation.java b/src/main/java/osc/git/eh3/annotation/PkgAnnotation.java new file mode 100644 index 0000000..b1d8799 --- /dev/null +++ b/src/main/java/osc/git/eh3/annotation/PkgAnnotation.java @@ -0,0 +1,19 @@ +/** + * + */ +package osc.git.eh3.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author lixiangrong + * + */ +@Target(ElementType.PACKAGE) +@Retention(RetentionPolicy.RUNTIME) +@interface PkgAnnotation { + +} diff --git a/src/main/java/osc/git/eh3/annotation/TestPkgAnnotation.java b/src/main/java/osc/git/eh3/annotation/TestPkgAnnotation.java new file mode 100644 index 0000000..0285418 --- /dev/null +++ b/src/main/java/osc/git/eh3/annotation/TestPkgAnnotation.java @@ -0,0 +1,18 @@ +package osc.git.eh3.annotation; + +import java.lang.annotation.Annotation; + +public class TestPkgAnnotation { + + public static void main(String[] args) { + Package pkg = Package.getPackage("osc.git.eh3.annotation"); + Annotation[] annotations = pkg.getAnnotations(); + for (Annotation annotation : annotations) { + System.out.println(annotation); + } + + // ===========================友好类和包内访问常量============== + new MyPackageMethod().myPackageMethod(); + System.out.println(MyPackageConst.PACKAGE_STRING); + } +} diff --git a/src/main/java/osc/git/eh3/annotation/package-info.java b/src/main/java/osc/git/eh3/annotation/package-info.java new file mode 100644 index 0000000..8416033 --- /dev/null +++ b/src/main/java/osc/git/eh3/annotation/package-info.java @@ -0,0 +1,25 @@ +/** + * + */ +/** + * @author lixiangrong + * + */ +@PkgAnnotation +package osc.git.eh3.annotation; + +/** + * 包内方法 + */ +class MyPackageMethod { + public void myPackageMethod() { + System.out.println("MyPackageMethod..."); + } +} + +/** + * 包内常量 + */ +class MyPackageConst { + static final java.lang.String PACKAGE_STRING = "myPackageConst"; +} \ No newline at end of file diff --git a/src/main/resources/generatorConfig.xml b/src/main/resources/generatorConfig.xml new file mode 100644 index 0000000..92a4ab0 --- /dev/null +++ b/src/main/resources/generatorConfig.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
\ No newline at end of file