Java Code Examples for org.apache.bcel.classfile.FieldOrMethod#isProtected()

The following examples show how to use org.apache.bcel.classfile.FieldOrMethod#isProtected() . 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 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 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 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 5
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;
}