diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2005-11-09 06:11:13 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2005-11-09 06:11:13 +0000 |
commit | 724b9b93c33f7f9c0fb6628261f43fe960014c17 (patch) | |
tree | 43e9de9785bf0f35bc193642fcfc957382bf32bd /src | |
parent | 5ff19d5945cda4b3d554e79d726e8a19de9c5766 (diff) | |
download | javassist-724b9b93c33f7f9c0fb6628261f43fe960014c17.tar.gz javassist-724b9b93c33f7f9c0fb6628261f43fe960014c17.zip |
updated Modifier class.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@221 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src')
-rw-r--r-- | src/main/javassist/CtMember.java | 25 | ||||
-rw-r--r-- | src/main/javassist/Modifier.java | 8 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/main/javassist/CtMember.java b/src/main/javassist/CtMember.java index 4e0154f0..38846601 100644 --- a/src/main/javassist/CtMember.java +++ b/src/main/javassist/CtMember.java @@ -104,6 +104,31 @@ public abstract class CtMember { public CtClass getDeclaringClass() { return declaringClass; } /** + * Returns true if this member is accessible from the given class. + */ + public boolean visibleFrom(CtClass clazz) { + int mod = getModifiers(); + if (Modifier.isPublic(mod)) + return true; + else if (Modifier.isPrivate(mod)) + return clazz == declaringClass; + else { // package or protected + String declName = declaringClass.getPackageName(); + String fromName = clazz.getPackageName(); + boolean visible; + if (declName == null) + visible = fromName == null; + else + visible = declName.equals(fromName); + + if (!visible && Modifier.isProtected(mod)) + return clazz.subclassOf(declaringClass); + + return visible; + } + } + + /** * Obtains the modifiers of the member. * * @return modifiers encoded with diff --git a/src/main/javassist/Modifier.java b/src/main/javassist/Modifier.java index e41c7259..7b4dbdc8 100644 --- a/src/main/javassist/Modifier.java +++ b/src/main/javassist/Modifier.java @@ -66,6 +66,14 @@ public class Modifier { } /** + * Returns true if the modifiers do not include either + * <tt>public</tt>, <tt>protected</tt>, or <tt>private</tt>. + */ + public static boolean isPackage(int mod) { + return (mod & (PUBLIC | PRIVATE | PROTECTED)) == 0; + } + + /** * Returns true if the modifiers include the <tt>static</tt> * modifier. */ |