Path: blob/master/src/java.base/share/classes/jdk/internal/module/ModuleResolution.java
41159 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package jdk.internal.module;2627import java.lang.module.ModuleReference;28import static jdk.internal.module.ClassFileConstants.*;2930/**31* Represents the Module Resolution flags.32*/33public final class ModuleResolution {3435final int value;3637ModuleResolution(int value) {38this.value = value;39}4041public int value() {42return value;43}4445public static ModuleResolution empty() {46return new ModuleResolution(0);47}4849public boolean doNotResolveByDefault() {50return (value & DO_NOT_RESOLVE_BY_DEFAULT) != 0;51}5253public boolean hasDeprecatedWarning() {54return (value & WARN_DEPRECATED) != 0;55}5657public boolean hasDeprecatedForRemovalWarning() {58return (value & WARN_DEPRECATED_FOR_REMOVAL) != 0;59}6061public boolean hasIncubatingWarning() {62return (value & WARN_INCUBATING) != 0;63}6465public ModuleResolution withDoNotResolveByDefault() {66return new ModuleResolution(value | DO_NOT_RESOLVE_BY_DEFAULT);67}6869public ModuleResolution withDeprecated() {70if ((value & (WARN_DEPRECATED_FOR_REMOVAL | WARN_INCUBATING)) != 0)71throw new InternalError("cannot add deprecated to " + value);72return new ModuleResolution(value | WARN_DEPRECATED);73}7475public ModuleResolution withDeprecatedForRemoval() {76if ((value & (WARN_DEPRECATED | WARN_INCUBATING)) != 0)77throw new InternalError("cannot add deprecated for removal to " + value);78return new ModuleResolution(value | WARN_DEPRECATED_FOR_REMOVAL);79}8081public ModuleResolution withIncubating() {82if ((value & (WARN_DEPRECATED | WARN_DEPRECATED_FOR_REMOVAL)) != 0)83throw new InternalError("cannot add incubating to " + value);84return new ModuleResolution(value | WARN_INCUBATING);85}8687public static boolean doNotResolveByDefault(ModuleReference mref) {88// get the DO_NOT_RESOLVE_BY_DEFAULT flag, if any89if (mref instanceof ModuleReferenceImpl) {90ModuleResolution mres = ((ModuleReferenceImpl) mref).moduleResolution();91if (mres != null)92return mres.doNotResolveByDefault();93}9495return false;96}9798public static boolean hasIncubatingWarning(ModuleReference mref) {99if (mref instanceof ModuleReferenceImpl) {100ModuleResolution mres = ((ModuleReferenceImpl) mref).moduleResolution();101if (mres != null)102return mres.hasIncubatingWarning();103}104105return false;106}107108@Override109public String toString() {110return super.toString() + "[value=" + value + "]";111}112}113114115