本文整理了Java中com.google.common.reflect.Element
类的一些代码示例,展示了Element
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element
类的具体详情如下:
包路径:com.google.common.reflect.Element
类名称:Element
[英]Represents either a Field, a Method or a Constructor. Provides convenience methods such as #isPublic and #isPackagePrivate.
[中]表示字段、方法或构造函数。提供方便的方法,如“isPublic”和“isPackagePrivate”。
代码示例来源:origin: google/guava
@SuppressWarnings("unchecked") // The declaring class is T's raw class, or one of its supertypes.
@Override
public final Class<? super T> getDeclaringClass() {
return (Class<? super T>) super.getDeclaringClass();
}
代码示例来源:origin: google/guava
/** Returns true if the element is package-private. */
public final boolean isPackagePrivate() {
return !isPrivate() && !isPublic() && !isProtected();
}
代码示例来源:origin: google/guava
/**
* Returns {@code true} if this method is final, per {@code Modifier.isFinal(getModifiers())}.
*
* <p>Note that a method may still be effectively "final", or non-overridable when it has no
* {@code final} keyword. For example, it could be private, or it could be declared by a final
* class. To tell whether a method is overridable, use {@link Invokable#isOverridable}.
*/
public final boolean isFinal() {
return Modifier.isFinal(getModifiers());
}
代码示例来源:origin: google/guava
static Element method(String name, Class<?>... parameterTypes) throws Exception {
Element element = new Element(A.class.getDeclaredMethod(name, parameterTypes));
assertEquals(name, element.getName());
assertEquals(A.class, element.getDeclaringClass());
return element;
}
代码示例来源:origin: google/guava
public void testPublicField() throws Exception {
Element element = A.field("publicField");
assertFalse(element.isPrivate());
assertFalse(element.isPackagePrivate());
assertFalse(element.isProtected());
assertTrue(element.isPublic());
assertFalse(element.isFinal());
assertFalse(element.isStatic());
assertTrue(element.isAnnotationPresent(Tested.class));
}
代码示例来源:origin: google/guava
public void testFinalMethod() throws Exception {
Element element = A.method("publicFinalMethod");
assertFalse(element.isAbstract());
assertFalse(element.isPrivate());
assertTrue(element.isFinal());
assertTrue(element.isPublic());
assertTrue(element.isAnnotationPresent(Tested.class));
}
代码示例来源:origin: google/guava
public void testConstructor() throws Exception {
Element element = A.constructor();
assertTrue(element.isPublic());
assertFalse(element.isPackagePrivate());
assertFalse(element.isAbstract());
assertFalse(element.isStatic());
assertTrue(element.isAnnotationPresent(Tested.class));
}
代码示例来源:origin: google/guava
@Override
public boolean equals(@Nullable Object obj) {
if (obj instanceof Element) {
Element that = (Element) obj;
return getOwnerType().equals(that.getOwnerType()) && member.equals(that.member);
}
return false;
}
代码示例来源:origin: google/guava
public void testPrivateMethod() throws Exception {
Element element = A.method("privateMethod");
assertFalse(element.isAbstract());
assertTrue(element.isPrivate());
assertFalse(element.isPackagePrivate());
assertFalse(element.isPublic());
assertFalse(element.isProtected());
assertTrue(element.isAnnotationPresent(Tested.class));
}
代码示例来源:origin: com.google.guava/guava-tests
public void testFinalMethod() throws Exception {
Element element = A.method("publicFinalMethod");
assertFalse(element.isAbstract());
assertFalse(element.isPrivate());
assertTrue(element.isFinal());
assertTrue(element.isPublic());
assertTrue(element.isAnnotationPresent(Tested.class));
}
代码示例来源:origin: google/guava
static Element field(String name) throws Exception {
Element element = new Element(A.class.getDeclaredField(name));
assertEquals(name, element.getName());
assertEquals(A.class, element.getDeclaringClass());
return element;
}
代码示例来源:origin: com.google.guava/guava-tests
public void testConstructor() throws Exception {
Element element = A.constructor();
assertTrue(element.isPublic());
assertFalse(element.isPackagePrivate());
assertFalse(element.isAbstract());
assertFalse(element.isStatic());
assertTrue(element.isAnnotationPresent(Tested.class));
}
代码示例来源:origin: google/j2objc
@Override
public boolean equals(@NullableDecl Object obj) {
if (obj instanceof Element) {
Element that = (Element) obj;
return getOwnerType().equals(that.getOwnerType()) && member.equals(that.member);
}
return false;
}
代码示例来源:origin: google/guava
public void testProtectedMethod() throws Exception {
Element element = A.method("protectedMethod");
assertFalse(element.isAbstract());
assertFalse(element.isPrivate());
assertFalse(element.isPackagePrivate());
assertFalse(element.isFinal());
assertFalse(element.isPublic());
assertTrue(element.isProtected());
assertTrue(element.isAnnotationPresent(Tested.class));
}
代码示例来源:origin: google/j2objc
/** Returns true if the element is package-private. */
public final boolean isPackagePrivate() {
return !isPrivate() && !isPublic() && !isProtected();
}
代码示例来源:origin: google/guava
/** Returns true if the field is transient. */
final boolean isTransient() {
return Modifier.isTransient(getModifiers());
}
代码示例来源:origin: google/j2objc
@SuppressWarnings("unchecked") // The declaring class is T's raw class, or one of its supertypes.
@Override
public final Class<? super T> getDeclaringClass() {
return (Class<? super T>) super.getDeclaringClass();
}
代码示例来源:origin: google/guava
static Element constructor() throws Exception {
Constructor<?> constructor = A.class.getDeclaredConstructor(Object.class);
Element element = new Element(constructor);
assertEquals(constructor.getName(), element.getName());
assertEquals(A.class, element.getDeclaringClass());
return element;
}
代码示例来源:origin: wildfly/wildfly
@Override
public boolean equals(@NullableDecl Object obj) {
if (obj instanceof Element) {
Element that = (Element) obj;
return getOwnerType().equals(that.getOwnerType()) && member.equals(that.member);
}
return false;
}
代码示例来源:origin: google/guava
public void testProtectedField() throws Exception {
Element element = A.field("protectedField");
assertFalse(element.isPrivate());
assertFalse(element.isPackagePrivate());
assertTrue(element.isProtected());
assertFalse(element.isPublic());
assertFalse(element.isFinal());
assertFalse(element.isStatic());
assertTrue(element.isAnnotationPresent(Tested.class));
}
内容来源于网络,如有侵权,请联系作者删除!