当前位置: 首页>>代码示例>>Java>>正文


Java Modifier.getAccessSpecifier方法代码示例

本文整理汇总了Java中com.github.javaparser.ast.Modifier.getAccessSpecifier方法的典型用法代码示例。如果您正苦于以下问题:Java Modifier.getAccessSpecifier方法的具体用法?Java Modifier.getAccessSpecifier怎么用?Java Modifier.getAccessSpecifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.github.javaparser.ast.Modifier的用法示例。


在下文中一共展示了Modifier.getAccessSpecifier方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDeclarationAsString

import com.github.javaparser.ast.Modifier; //导入方法依赖的package包/类
/**
 * The declaration returned has this schema:
 *
 * [accessSpecifier] className ([paramType [paramName]])
 * [throws exceptionsList]
 */
@Override
public String getDeclarationAsString(boolean includingModifiers, boolean includingThrows,
                                     boolean includingParameterName) {
    StringBuilder sb = new StringBuilder();
    if (includingModifiers) {
        AccessSpecifier accessSpecifier = Modifier.getAccessSpecifier(getModifiers());
        sb.append(accessSpecifier.getCodeRepresenation());
        sb.append(accessSpecifier == AccessSpecifier.DEFAULT ? "" : " ");
    }
    sb.append(getName());
    sb.append("(");
    boolean firstParam = true;
    for (Parameter param : getParameters()) {
        if (firstParam) {
            firstParam = false;
        } else {
            sb.append(", ");
        }
        if (includingParameterName) {
            sb.append(param.toStringWithoutComments());
        } else {
            sb.append(param.getElementType().toStringWithoutComments());
        }
    }
    sb.append(")");
    if (includingThrows) {
        boolean firstThrow = true;
        for (ReferenceType thr : getThrows()) {
            if (firstThrow) {
                firstThrow = false;
                sb.append(" throws ");
            } else {
                sb.append(", ");
            }
            sb.append(thr.toStringWithoutComments());
        }
    }
    return sb.toString();
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:46,代码来源:ConstructorDeclaration.java

示例2: getDeclarationAsString

import com.github.javaparser.ast.Modifier; //导入方法依赖的package包/类
/**
 * The declaration returned has this schema:
 *
 * [accessSpecifier] [static] [abstract] [final] [native]
 * [synchronized] returnType methodName ([paramType [paramName]])
 * [throws exceptionsList]
 * 
 * @return method declaration as String
 */
@Override
public String getDeclarationAsString(boolean includingModifiers, boolean includingThrows,
                                     boolean includingParameterName) {
    StringBuilder sb = new StringBuilder();
    if (includingModifiers) {
        AccessSpecifier accessSpecifier = Modifier.getAccessSpecifier(getModifiers());
        sb.append(accessSpecifier.getCodeRepresenation());
        sb.append(accessSpecifier == AccessSpecifier.DEFAULT ? "" : " ");
        if (getModifiers().contains(Modifier.STATIC)) {
            sb.append("static ");
        }
        if (getModifiers().contains(Modifier.ABSTRACT)) {
            sb.append("abstract ");
        }
        if (getModifiers().contains(Modifier.FINAL)) {
            sb.append("final ");
        }
        if (getModifiers().contains(Modifier.NATIVE)) {
            sb.append("native ");
        }
        if (getModifiers().contains(Modifier.SYNCHRONIZED)) {
            sb.append("synchronized ");
        }
    }
    // TODO verify it does not print comments connected to the type
    sb.append(getElementType().toStringWithoutComments());
    sb.append(" ");
    sb.append(getName());
    sb.append("(");
    boolean firstParam = true;
    for (Parameter param : getParameters()) {
        if (firstParam) {
            firstParam = false;
        } else {
            sb.append(", ");
        }
        if (includingParameterName) {
            sb.append(param.toStringWithoutComments());
        } else {
            sb.append(param.getElementType().toStringWithoutComments());
            if (param.isVarArgs()) {
                sb.append("...");
            }
        }
    }
    sb.append(")");
    if (includingThrows) {
        boolean firstThrow = true;
        for (ReferenceType thr : getThrows()) {
            if (firstThrow) {
                firstThrow = false;
                sb.append(" throws ");
            } else {
                sb.append(", ");
            }
            sb.append(thr.toStringWithoutComments());
        }
    }
    return sb.toString();
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:70,代码来源:MethodDeclaration.java


注:本文中的com.github.javaparser.ast.Modifier.getAccessSpecifier方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。