集册 Java实例教程 到修饰符字符串

到修饰符字符串

欢马劈雪     最近更新时间:2020-01-02 10:19:05

622
到修饰符字符串
/** from 
时代Java - N o w  J a v a . c o m**/

/*

 * Copyright 2004-2010 the Seasar Foundation and the Others.

 *

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *     http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,

 * either express or implied. See the License for the specific language

 * governing permissions and limitations under the License.

 */

//package com.nowjava;


import java.util.Set;

import javax.lang.model.element.Modifier;


public class Main {


    public static String toStringOfModifiers(final Set<Modifier> modifiers) {

        if (modifiers.isEmpty()) {

            return "";

        }


        final StringBuilder buf = new StringBuilder(32);

        if (modifiers.contains(Modifier.PUBLIC)) {

            buf.append("public ");

        }

        if (modifiers.contains(Modifier.PROTECTED)) {

            buf.append("protected ");

        }
        /*
        NowJava.com - 时代Java 提供
        */

        if (modifiers.contains(Modifier.PRIVATE)) {

            buf.append("private ");

        }

        if (modifiers.contains(Modifier.ABSTRACT)) {

            buf.append("abstract ");

        }

        if (modifiers.contains(Modifier.STATIC)) {

            buf.append("static ");

        }

        if (modifiers.contains(Modifier.FINAL)) {

            buf.append("final ");

        }

        if (modifiers.contains(Modifier.TRANSIENT)) {

            buf.append("transient ");

        }

        if (modifiers.contains(Modifier.VOLATILE)) {

            buf.append("volatile ");

        }

        if (modifiers.contains(Modifier.SYNCHRON
展开阅读全文