org.apache.bcel.classfile.FieldOrMethod Java Examples

The following examples show how to use org.apache.bcel.classfile.FieldOrMethod. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractReferenceCheck.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Tests whether the scope of a field or method is compatible
 * with the scope of this check. References for compatible
 * fields or methods should be checked.
 * @param aFieldOrMethod the field or method to check.
 * @return true if the scope of aFieldOrMethod is compatible
 * with the scope of this check.
 */
private boolean equalScope(FieldOrMethod aFieldOrMethod)
{
    if (aFieldOrMethod.isPrivate()) {
        return (mScope == Scope.PRIVATE);
    }
    else if (aFieldOrMethod.isProtected()) {
        return (mScope == Scope.PROTECTED);
    }
    else if (aFieldOrMethod.isPublic()) {
        return (mScope == Scope.PUBLIC);
    }
    else {
        return (mScope == Scope.PACKAGE);
    }
}
 
Example #2
Source File: Utils.java    From contribution with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Determines whether the declared scope of a field or method is in
 * a set of scopes.
 * @param aFieldOrMethod the field or method to test.
 * @param aScopes the set of scopes to test against.
 * @return true if the declared scope of aFieldOrMethod is in aScopes.
 */
public static boolean inScope(FieldOrMethod aFieldOrMethod, Set aScopes)
{
    if (aFieldOrMethod.isPrivate()) {
        return (aScopes.contains(Scope.PRIVATE));
    }
    else if (aFieldOrMethod.isProtected()) {
        return (aScopes.contains(Scope.PROTECTED));
    }
    else if (aFieldOrMethod.isPublic()) {
        return (aScopes.contains(Scope.PUBLIC));
    }
    else {
        return (aScopes.contains(Scope.PACKAGE));
    }
}
 
Example #3
Source File: AbstractReferenceCheck.java    From contribution with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Tests whether the scope of a field or method is compatible
 * with the scope of this check. References for compatible
 * fields or methods should be checked.
 * @param aFieldOrMethod the field or method to check.
 * @return true if the scope of aFieldOrMethod is compatible
 * with the scope of this check.
 */
private boolean equalScope(FieldOrMethod aFieldOrMethod)
{
    if (aFieldOrMethod.isPrivate()) {
        return (mScope == Scope.PRIVATE);
    }
    else if (aFieldOrMethod.isProtected()) {
        return (mScope == Scope.PROTECTED);
    }
    else if (aFieldOrMethod.isPublic()) {
        return (mScope == Scope.PUBLIC);
    }
    else {
        return (mScope == Scope.PACKAGE);
    }
}
 
Example #4
Source File: Utils.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Determines whether the declared scope of a field or method is in
 * a set of scopes.
 * @param aFieldOrMethod the field or method to test.
 * @param aScopes the set of scopes to test against.
 * @return true if the declared scope of aFieldOrMethod is in aScopes.
 */
public static boolean inScope(FieldOrMethod aFieldOrMethod, Set aScopes)
{
    if (aFieldOrMethod.isPrivate()) {
        return (aScopes.contains(Scope.PRIVATE));
    }
    else if (aFieldOrMethod.isProtected()) {
        return (aScopes.contains(Scope.PROTECTED));
    }
    else if (aFieldOrMethod.isPublic()) {
        return (aScopes.contains(Scope.PUBLIC));
    }
    else {
        return (aScopes.contains(Scope.PACKAGE));
    }
}
 
Example #5
Source File: BCELUtil.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Checks if the given member is synthetic
 *
 * @param m The member to be checked
 * @return True if the member is synthetic, false otherwise
 * @deprecated You probably don't care for synthetic members, but want to
 *             know if the developer added it (think of lambdas), use
 *             {@link MemberUtils#isUserGenerated(FieldOrMethod)} instead
 */
@Deprecated
public static boolean isSynthetic(FieldOrMethod m) {
    if (m.isSynthetic()) {
        return true;
    }

    for (Attribute a : m.getAttributes()) {
        if (a instanceof Synthetic) {
            return true;
        }
    }
    return false;
}
 
Example #6
Source File: MemberUtils.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static boolean internalIsSynthetic(final FieldOrMethod m) {
    if (m.isSynthetic()) {
        return true;
    }

    for (final Attribute a : m.getAttributes()) {
        if (a instanceof Synthetic) {
            return true;
        }
    }

    return false;
}
 
Example #7
Source File: AbstractReferenceCheck.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Determines whether a class name, and field or method should be ignored.
 * @param aClassName the class name to consider.
 * @param aFieldOrMethod  the field or method to consider.
 * @return true if aClassName, and field or method should be ignored.
 */
protected boolean ignore(String aClassName, FieldOrMethod aFieldOrMethod)
{
    final String fieldOrMethodName = aFieldOrMethod.getName();
    return (!equalScope(aFieldOrMethod)
            || mIgnoreClassNameRegexp.matcher(aClassName).matches()
        || mIgnoreNameRegexp.matcher(fieldOrMethodName).matches());
}
 
Example #8
Source File: LinkageChecker.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the field or method of a class is accessible from {@code sourceClassName}.
 *
 * @see <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#jls-6.6.1">JLS 6.6.1
 *     Determining Accessibility</a>
 */
private boolean isMemberAccessibleFrom(
    JavaClass targetClass, FieldOrMethod member, String sourceClassName) {
  // The order of these if statements for public, protected, and private are in the same order
  // they
  // appear in JLS 6.6.1
  if (member.isPublic()) {
    return true;
  }
  if (member.isProtected()) {
    if (ClassDumper.classesInSamePackage(targetClass.getClassName(), sourceClassName)) {
      return true;
    }
    try {
      JavaClass sourceClass = classDumper.loadJavaClass(sourceClassName);
      if (ClassDumper.isClassSubClassOf(sourceClass, targetClass)) {
        return true;
      }
    } catch (ClassNotFoundException ex) {
      logger.warning(
          "The source class "
              + sourceClassName
              + " of a reference was not found in the class path when checking accessibility");
      return false;
    }
  }
  if (member.isPrivate()) {
    // Access from within same top-level class is allowed to read private class. However, such
    // cases are already filtered at errorsFromSymbolReferences.
    return false;
  }
  // Default: package private
  if (ClassDumper.classesInSamePackage(targetClass.getClassName(), sourceClassName)) {
    return true;
  }
  return false;
}
 
Example #9
Source File: ClassFeatureSet.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Figure out if a class member (field or method) is synthetic.
 *
 * @param member
 *            a field or method
 * @return true if the member is synthetic
 */
private boolean isSynthetic(FieldOrMethod member) {
    if (BCELUtil.isSynthetic(member)) {
        return true;
    }

    String name = member.getName();

    return name.startsWith("class$") || name.startsWith("access$");
}
 
Example #10
Source File: AbstractReferenceCheck.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Determines whether a class name, and field or method should be ignored.
 * @param aClassName the class name to consider.
 * @param aFieldOrMethod  the field or method to consider.
 * @return true if aClassName, and field or method should be ignored.
 */
protected boolean ignore(String aClassName, FieldOrMethod aFieldOrMethod)
{
    final String fieldOrMethodName = aFieldOrMethod.getName();
    return (!equalScope(aFieldOrMethod)
            || mIgnoreClassNameRegexp.matcher(aClassName).matches()
        || mIgnoreNameRegexp.matcher(fieldOrMethodName).matches());
}
 
Example #11
Source File: SerializableIdiom.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
boolean isSynthetic(FieldOrMethod obj) {
    Attribute[] a = obj.getAttributes();
    for (Attribute aA : a) {
        if (aA instanceof Synthetic) {
            return true;
        }
    }
    return false;
}
 
Example #12
Source File: FieldOrMethodDefinition.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Returns the FieldOrMethod.
 * @return the FieldOrMethod.
 */
protected FieldOrMethod getFieldOrMethod()
{
    return mFieldOrMethod;
}
 
Example #13
Source File: DontUseEnum.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean isVisible(FieldOrMethod obj) {
    return (obj.getAccessFlags() & Const.ACC_PUBLIC) != 0 || (obj.getAccessFlags() & Const.ACC_PROTECTED) != 0;
}
 
Example #14
Source File: FieldOrMethodDefinition.java    From contribution with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Returns the FieldOrMethod.
 * @return the FieldOrMethod.
 */
protected FieldOrMethod getFieldOrMethod()
{
    return mFieldOrMethod;
}
 
Example #15
Source File: MemberUtils.java    From spotbugs with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Checks if the the given method was user-generated. This takes into
 * account for instance lambda methods, that even though they are marked as
 * "synthetic", they are user-generated, and therefore interesting to
 * analysis.
 *
 * @param m The field or method to check.
 * @return True if the given member is user generated, false otherwise.
 */
public static boolean isUserGenerated(final FieldOrMethod m) {
    return !internalIsSynthetic(m) || (m instanceof Method && couldBeLambda((Method) m));
}
 
Example #16
Source File: FieldOrMethodDefinition.java    From cacheonix-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Constructs a <code>FieldOrMethodDefinition</code> for a Field
 * or a Method.
 * @param aFieldOrMethod the Field or Method
 */
protected FieldOrMethodDefinition(FieldOrMethod aFieldOrMethod)
{
    mFieldOrMethod = aFieldOrMethod;
}
 
Example #17
Source File: FieldOrMethodDefinition.java    From contribution with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Constructs a <code>FieldOrMethodDefinition</code> for a Field
 * or a Method.
 * @param aFieldOrMethod the Field or Method
 */
protected FieldOrMethodDefinition(FieldOrMethod aFieldOrMethod)
{
    mFieldOrMethod = aFieldOrMethod;
}