001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020package org.apache.isis.core.metamodel.methodutils; 021 022import java.lang.reflect.Method; 023import java.lang.reflect.Modifier; 024 025/** 026 * As used in the <tt>findAndRemove...</tt> methods. 027 */ 028public enum MethodScope { 029 CLASS, OBJECT; 030 031 public boolean isClass() { 032 return this == CLASS; 033 } 034 035 public boolean isObject() { 036 return this == OBJECT; 037 } 038 039 public boolean doesNotMatchScope(final Method method) { 040 return !matchesScopeOf(method); 041 } 042 043 public boolean matchesScopeOf(final Method method) { 044 return isStatic(method) == this.isClass(); 045 } 046 047 public static MethodScope scopeFor(final Method method) { 048 return isStatic(method) ? CLASS : OBJECT; 049 } 050 051 private static boolean isStatic(final Method method) { 052 final int modifiers = method.getModifiers(); 053 final boolean isStatic = Modifier.isStatic(modifiers); 054 return isStatic; 055 } 056 057}