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


Java Scope类代码示例

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


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


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