• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pmd / pmd / 492

07 May 2026 06:15AM UTC coverage: 79.021% (+0.003%) from 79.018%
492

push

github

adangel
[java] Shrink reported locations for some rules (#6084)

18721 of 24613 branches covered (76.06%)

Branch coverage included in aggregate %.

29 of 29 new or added lines in 9 files covered. (100.0%)

1 existing line in 1 file now uncovered.

40816 of 50730 relevant lines covered (80.46%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.05
/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractTypeDeclaration.java
1
/*
2
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3
 */
4

5
package net.sourceforge.pmd.lang.java.ast;
6

7
import org.checkerframework.checker.nullness.qual.NonNull;
8
import org.checkerframework.checker.nullness.qual.Nullable;
9

10
import net.sourceforge.pmd.lang.ast.Node;
11
import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken;
12
import net.sourceforge.pmd.lang.document.FileLocation;
13
import net.sourceforge.pmd.lang.java.symbols.JClassSymbol;
14
import net.sourceforge.pmd.lang.java.types.JClassType;
15

16

17
/**
18
 * Abstract class for type declarations nodes.
19
 * This is a {@linkplain Node#isFindBoundary() find boundary} for tree traversal methods.
20
 */
21
abstract class AbstractTypeDeclaration extends AbstractTypedSymbolDeclarator<JClassSymbol> implements ASTTypeDeclaration, LeftRecursiveNode {
1✔
22

23
    private String binaryName;
24
    private @Nullable String canonicalName;
25
    private JavaccToken simpleName;
26

27
    AbstractTypeDeclaration(int i) {
28
        super(i);
1✔
29
    }
1✔
30

31
    @Override
32
    public FileLocation getReportLocation() {
33
        if (isAnonymous()) {
1✔
34
            ASTConstructorCall constructorCall = ancestors(ASTConstructorCall.class).first();
1✔
35
            if (constructorCall != null) {
1✔
36
                return constructorCall.getTypeNode().getReportLocation();
1✔
37
            }
38
            ASTEnumConstant enumConstant = ancestors(ASTEnumConstant.class).first();
1✔
39
            if (enumConstant != null) {
1!
40
                return enumConstant.getReportLocation();
1✔
41
            }
UNCOV
42
            return super.getReportLocation();
×
43
        } else {
44
            // report on the identifier, not the entire class.
45
            return simpleName.getReportLocation();
1✔
46
        }
47
    }
48

49
    @NonNull
50
    @Override
51
    public String getSimpleName() {
52
        assert simpleName != null : "Null simple name";
1!
53
        return simpleName.getImage();
1✔
54
    }
55

56
    final void setSimpleName(JavaccToken simpleName) {
57
        this.simpleName = simpleName;
1✔
58
    }
1✔
59

60
    @Override
61
    public @NonNull String getBinaryName() {
62
        assert binaryName != null : "Null binary name";
1!
63
        return binaryName;
1✔
64
    }
65

66
    @Override
67
    public @Nullable String getCanonicalName() {
68
        assert binaryName != null : "binary name and canonical name weren't set";
1!
69
        return canonicalName;
1✔
70
    }
71

72
    @Override
73
    public Visibility getVisibility() {
74
        return isLocal() ? Visibility.V_LOCAL : ASTTypeDeclaration.super.getVisibility();
1✔
75
    }
76

77
    void setBinaryName(String binaryName, @Nullable String canon) {
78
        assert binaryName != null : "Null binary name";
1!
79
        this.binaryName = binaryName;
1✔
80
        this.canonicalName = canon;
1✔
81
    }
1✔
82

83
    @Override
84
    public @NonNull JClassType getTypeMirror() {
85
        return (JClassType) super.getTypeMirror();
1✔
86
    }
87

88
    @Override
89
    public boolean isFindBoundary() {
90
        return isNested();
1✔
91
    }
92
}
93

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc