• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Scope类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.Scope的典型用法代码示例。如果您正苦于以下问题:Java Scope类的具体用法?Java Scope怎么用?Java Scope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Scope类属于com.puppycrawl.tools.checkstyle.api包,在下文中一共展示了Scope类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: equalScope

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:24,代码来源:AbstractReferenceCheck.java


示例2: inScope

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
/**
 * 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));
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:23,代码来源:Utils.java


示例3: isInStatic

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
/**
 * Determines whether an AST node is in a static method or static
 * initializer.
 * @param ast the node to check.
 * @return true if ast is in a static method or a static block;
 */
private static boolean isInStatic(DetailAST ast) {
    DetailAST parent = ast.getParent();
    boolean inStatic = false;

    while (parent != null && !inStatic) {
        if (parent.getType() == TokenTypes.STATIC_INIT) {
            inStatic = true;
        }
        else if (parent.getType() == TokenTypes.METHOD_DEF
                    && !ScopeUtils.isInScope(parent, Scope.ANONINNER)
                    || parent.getType() == TokenTypes.VARIABLE_DEF) {
            final DetailAST mods =
                parent.findFirstToken(TokenTypes.MODIFIERS);
            inStatic = mods.findFirstToken(TokenTypes.LITERAL_STATIC) != null;
            break;
        }
        else {
            parent = parent.getParent();
        }
    }
    return inStatic;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:29,代码来源:HiddenFieldCheck.java


示例4: shouldCheck

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
/**
 * Whether we should check this node.
 * @param ast a given node.
 * @return whether we should check a given node.
 */
private boolean shouldCheck(final DetailAST ast) {
    final Scope customScope;

    if (ScopeUtils.isInInterfaceOrAnnotationBlock(ast)) {
        customScope = Scope.PUBLIC;
    }
    else {
        final DetailAST mods = ast.findFirstToken(TokenTypes.MODIFIERS);
        customScope = ScopeUtils.getScopeFromMods(mods);
    }
    final Scope surroundingScope = ScopeUtils.getSurroundingScope(ast);

    return customScope.isIn(scope)
        && (surroundingScope == null || surroundingScope.isIn(scope))
        && (excludeScope == null
            || !customScope.isIn(excludeScope)
            || surroundingScope != null
            && !surroundingScope.isIn(excludeScope));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:25,代码来源:JavadocTypeCheck.java


示例5: shouldCheck

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
/**
 * Whether we should check this node.
 * @param ast a given node.
 * @return whether we should check a given node.
 */
private boolean shouldCheck(final DetailAST ast) {
    boolean result = false;
    if (!ScopeUtils.isInCodeBlock(ast) && !isIgnored(ast)) {
        Scope customScope = Scope.PUBLIC;
        if (ast.getType() != TokenTypes.ENUM_CONSTANT_DEF
                && !ScopeUtils.isInInterfaceOrAnnotationBlock(ast)) {
            final DetailAST mods = ast.findFirstToken(TokenTypes.MODIFIERS);
            customScope = ScopeUtils.getScopeFromMods(mods);
        }

        final Scope surroundingScope = ScopeUtils.getSurroundingScope(ast);
        result = customScope.isIn(scope) && surroundingScope.isIn(scope)
            && (excludeScope == null
                || !customScope.isIn(excludeScope)
                || !surroundingScope.isIn(excludeScope));
    }
    return result;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:JavadocVariableCheck.java


示例6: processAST

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
@Override
protected final void processAST(DetailAST ast) {
    final Scope theScope = calculateScope(ast);
    if (shouldCheck(ast, theScope)) {
        final FileContents contents = getFileContents();
        final TextBlock textBlock = contents.getJavadocBefore(ast.getLineNo());

        if (textBlock == null) {
            if (!isMissingJavadocAllowed(ast)) {
                log(ast, MSG_JAVADOC_MISSING);
            }
        }
        else {
            checkComment(ast, textBlock);
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:JavadocMethodCheck.java


示例7: getScopeFromMods

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
/**
 * Returns the Scope specified by the modifier set.
 *
 * @param aMods root node of a modifier set
 * @return a {@code Scope} value
 */
public static Scope getScopeFromMods(DetailAST aMods) {
    // default scope
    Scope returnValue = Scope.PACKAGE;
    for (AST token = aMods.getFirstChild(); token != null
            && returnValue == Scope.PACKAGE;
            token = token.getNextSibling()) {
        if ("public".equals(token.getText())) {
            returnValue = Scope.PUBLIC;
        }
        else if ("protected".equals(token.getText())) {
            returnValue = Scope.PROTECTED;
        }
        else if ("private".equals(token.getText())) {
            returnValue = Scope.PRIVATE;
        }
    }
    return returnValue;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:25,代码来源:ScopeUtils.java


示例8: testExcludeScope

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
@Test
public void testExcludeScope() throws Exception {
    final DefaultConfiguration checkConfig =
        createModuleConfig(JavadocTypeCheck.class);
    checkConfig.addAttribute("scope", Scope.PRIVATE.getName());
    checkConfig.addAttribute("excludeScope", Scope.PROTECTED.getName());
    final String[] expected = {
        "27: " + getCheckMessage(MSG_JAVADOC_MISSING),
        "39: " + getCheckMessage(MSG_JAVADOC_MISSING),
        "52: " + getCheckMessage(MSG_JAVADOC_MISSING),
        "63: " + getCheckMessage(MSG_JAVADOC_MISSING),
        "75: " + getCheckMessage(MSG_JAVADOC_MISSING),
        "87: " + getCheckMessage(MSG_JAVADOC_MISSING),
        "99: " + getCheckMessage(MSG_JAVADOC_MISSING),
        "111: " + getCheckMessage(MSG_JAVADOC_MISSING),
    };
    verify(checkConfig,
           getPath("InputJavadocTypeNoJavadoc.java"),
           expected);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:21,代码来源:JavadocTypeCheckTest.java


示例9: testSurroundingScope

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
@Test
public void testSurroundingScope() {
    assertEquals("Invalid surrounding scope",
            Scope.PUBLIC, ScopeUtils.getSurroundingScope(getNodeWithParentScope(
        TokenTypes.LITERAL_PUBLIC, "public", TokenTypes.ANNOTATION_DEF)));
    assertEquals("Invalid surrounding scope",
            Scope.PROTECTED, ScopeUtils.getSurroundingScope(
        getNodeWithParentScope(TokenTypes.LITERAL_PROTECTED, "protected",
        TokenTypes.INTERFACE_DEF)));
    assertEquals("Invalid surrounding scope",
            Scope.PRIVATE, ScopeUtils.getSurroundingScope(
        getNodeWithParentScope(TokenTypes.LITERAL_PRIVATE, "private", TokenTypes.ENUM_DEF)));
    assertEquals("Invalid surrounding scope",
            Scope.PACKAGE, ScopeUtils.getSurroundingScope(
        getNodeWithParentScope(TokenTypes.LITERAL_STATIC, "static", TokenTypes.CLASS_DEF)));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:ScopeUtilsTest.java


示例10: shouldCheck

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
/**
 * Whether we should check this node.
 * 
 * @param aAST
 *            a given node.
 * @return whether we should check a given node.
 */
private boolean shouldCheck(final DetailAST aAST) {
    if (ScopeUtils.inCodeBlock(aAST)) {
        return false;
    }

    final Scope scope;
    if (aAST.getType() == TokenTypes.ENUM_CONSTANT_DEF) {
        scope = Scope.PUBLIC;
    } else {
        final DetailAST mods = aAST.findFirstToken(TokenTypes.MODIFIERS);
        final Scope declaredScope = ScopeUtils.getScopeFromMods(mods);
        scope = ScopeUtils.inInterfaceOrAnnotationBlock(aAST) ? Scope.PUBLIC : declaredScope;
    }

    final Scope surroundingScope = ScopeUtils.getSurroundingScope(aAST);

    return Utilities.isExportedPackage(aAST) && scope.isIn(mScope) && surroundingScope.isIn(mScope)
            && ((mExcludeScope == null) || !scope.isIn(mExcludeScope) || !surroundingScope.isIn(mExcludeScope));
}
 
开发者ID:Adobe-Consulting-Services,项目名称:checkstyle-osgi-checks,代码行数:27,代码来源:ExportedJavadocVariableCheck.java


示例11: setScope

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
/** @see AbstractReferenceCheck */
public void setScope(String aFrom)
{
    super.setScope(aFrom);
    ((ReferenceVisitor) getVisitor()).addFieldScope(
        Scope.getInstance(aFrom));
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:8,代码来源:HiddenInheritedFieldCheck.java


示例12: setScope

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
/** @see AbstractReferenceCheck */
public void setScope(String aScopeName)
{
    super.setScope(aScopeName);
    ((ReferenceVisitor) getVisitor()).addMethodScope(
        Scope.getInstance(aScopeName));
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:8,代码来源:UnusedMethodCheck.java


示例13: mustCheckReferenceCount

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
/** @see com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck */
public boolean mustCheckReferenceCount(DetailAST aAST)
{
    final DetailAST mods = aAST.findFirstToken(TokenTypes.MODIFIERS);
    return ((mods != null)
        && (ScopeUtils.getScopeFromMods(mods) == Scope.PRIVATE));
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:8,代码来源:OneMethodPrivateFieldCheck.java


示例14: mustCheckReferenceCount

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
/** @see com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck */
public boolean mustCheckReferenceCount(DetailAST aAST)
{
    final DetailAST mods = aAST.findFirstToken(TokenTypes.MODIFIERS);
    if ((mods == null)
        || (ScopeUtils.getScopeFromMods(mods) != Scope.PRIVATE))
    {
        return false;
    }

    return !mAllowSerializationMethods
           || !(isWriteObject(aAST) || isReadObject(aAST)
                || isWriteReplaceOrReadResolve(aAST));
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:15,代码来源:UnusedPrivateMethodCheck.java


示例15: raiseCounter

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
/**
 * Determine the visibility modifier and raise the corresponding counter.
 * @param method
 *            The method-subtree from the AbstractSyntaxTree.
 */
private void raiseCounter(DetailAST method) {
    final MethodCounter actualCounter = counters.peek();
    final DetailAST temp = method.findFirstToken(TokenTypes.MODIFIERS);
    final Scope scope = ScopeUtils.getScopeFromMods(temp);
    actualCounter.increment(scope);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:12,代码来源:MethodCountCheck.java


示例16: checkCounters

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
/**
 * Check the counters and report violations.
 * @param counter the method counters to check
 * @param ast to report errors against.
 */
private void checkCounters(MethodCounter counter, DetailAST ast) {
    checkMax(maxPrivate, counter.value(Scope.PRIVATE),
             MSG_PRIVATE_METHODS, ast);
    checkMax(maxPackage, counter.value(Scope.PACKAGE),
             MSG_PACKAGE_METHODS, ast);
    checkMax(maxProtected, counter.value(Scope.PROTECTED),
             MSG_PROTECTED_METHODS, ast);
    checkMax(maxPublic, counter.value(Scope.PUBLIC),
             MSG_PUBLIC_METHODS, ast);
    checkMax(maxTotal, counter.getTotal(), MSG_MANY_METHODS, ast);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:MethodCountCheck.java


示例17: increment

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
/**
 * Increments to counter by one for the supplied scope.
 * @param scope the scope counter to increment.
 */
private void increment(Scope scope) {
    total++;
    if (inInterface) {
        counts.put(Scope.PUBLIC, 1 + value(Scope.PUBLIC));
    }
    else {
        counts.put(scope, 1 + value(scope));
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:14,代码来源:MethodCountCheck.java


示例18: processModifiersState

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
/**
 * Process if given modifiers are appropriate in given state
 * ({@code STATE_STATIC_VARIABLE_DEF}, {@code STATE_INSTANCE_VARIABLE_DEF},
 * ({@code STATE_CTOR_DEF}, {@code STATE_METHOD_DEF}), if it is
 * it updates states where appropriate or logs violation.
 * @param modifierAst modifiers to process
 * @param state current state
 * @return true if modifierAst is valid in given state, false otherwise
 */
private boolean processModifiersState(DetailAST modifierAst, ScopeState state) {
    boolean isStateValid = true;
    if (modifierAst.findFirstToken(TokenTypes.LITERAL_STATIC) == null) {
        if (state.currentScopeState > STATE_INSTANCE_VARIABLE_DEF) {
            isStateValid = false;
            log(modifierAst, MSG_INSTANCE);
        }
        else if (state.currentScopeState == STATE_STATIC_VARIABLE_DEF) {
            state.declarationAccess = Scope.PUBLIC;
            state.currentScopeState = STATE_INSTANCE_VARIABLE_DEF;
        }
    }
    else {
        if (state.currentScopeState > STATE_STATIC_VARIABLE_DEF) {
            if (!ignoreModifiers
                    || state.currentScopeState > STATE_INSTANCE_VARIABLE_DEF) {
                isStateValid = false;
                log(modifierAst, MSG_STATIC);
            }
        }
        else {
            state.currentScopeState = STATE_STATIC_VARIABLE_DEF;
        }
    }
    return isStateValid;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:36,代码来源:DeclarationOrderCheck.java


示例19: processModifiersSubState

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
/**
 * Checks if given modifiers are valid in substate of given
 * state({@code Scope}), if it is it updates substate or else it
 * logs violation.
 * @param modifiersAst modifiers to process
 * @param state current state
 * @param isStateValid is main state for given modifiers is valid
 */
private void processModifiersSubState(DetailAST modifiersAst, ScopeState state,
                                      boolean isStateValid) {
    final Scope access = ScopeUtils.getScopeFromMods(modifiersAst);
    if (state.declarationAccess.compareTo(access) > 0) {
        if (isStateValid
                && !ignoreModifiers
                && !isForwardReference(modifiersAst.getParent())) {
            log(modifiersAst, MSG_ACCESS);
        }
    }
    else {
        state.declarationAccess = access;
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:23,代码来源:DeclarationOrderCheck.java


示例20: shouldCheck

import com.puppycrawl.tools.checkstyle.api.Scope; //导入依赖的package包/类
/**
 * Whether we should check this node.
 * @param ast a given node.
 * @return whether we should check a given node.
 */
private boolean shouldCheck(final DetailAST ast) {
    boolean check = false;

    if (ast.getType() == TokenTypes.PACKAGE_DEF) {
        check = getFileContents().inPackageInfo();
    }
    else if (!ScopeUtils.isInCodeBlock(ast)) {
        final Scope customScope;

        if (ScopeUtils.isInInterfaceOrAnnotationBlock(ast)
                || ast.getType() == TokenTypes.ENUM_CONSTANT_DEF) {
            customScope = Scope.PUBLIC;
        }
        else {
            customScope = ScopeUtils.getScopeFromMods(ast.findFirstToken(TokenTypes.MODIFIERS));
        }
        final Scope surroundingScope = ScopeUtils.getSurroundingScope(ast);

        check = customScope.isIn(scope)
                && (surroundingScope == null || surroundingScope.isIn(scope))
                && (excludeScope == null
                    || !customScope.isIn(excludeScope)
                    || surroundingScope != null
                        && !surroundingScope.isIn(excludeScope));
    }
    return check;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:33,代码来源:JavadocStyleCheck.java



注:本文中的com.puppycrawl.tools.checkstyle.api.Scope类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java INodeReferenceSection类代码示例发布时间:2022-05-22
下一篇:
Java FMLEvent类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap