A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/commit/303b9628e45339e356f871c0a53de7895e209601 below:

Remove name node in import & package decl · pmd/pmd@303b962 · GitHub

File tree Expand file treeCollapse file tree 6 files changed

+32

-66

lines changed

Filter options

Expand file treeCollapse file tree 6 files changed

+32

-66

lines changed Original file line number Diff line number Diff line change

@@ -1709,15 +1709,17 @@ private void ModuleDeclLahead() #void:

1709 1709 1710 1710 1711 1711

void PackageDeclaration() :

1712 -

{}

1712 +

{String image;}

1713 1713

{

1714 -

( Annotation() )* "package" Name() ";"

1714 +

( Annotation() )* "package" image=VoidName() { jjtThis.setImage(image); } ";"

1715 1715

}

1716 1716 1717 1717

void ImportDeclaration() :

1718 -

{}

1718 +

{String image;}

1719 1719

{

1720 -

"import" [ "static" {checkForBadStaticImportUsage();jjtThis.setStatic();} ] Name() [ "." "*" {jjtThis.setImportOnDemand();} ] ";"

1720 +

"import" [ "static" {checkForBadStaticImportUsage();jjtThis.setStatic();} ]

1721 +

image=ImportName() { jjtThis.setImage(image); }

1722 +

[ "." "*" {jjtThis.setImportOnDemand();} ] ";"

1721 1723

}

1722 1724 1723 1725

/*

@@ -3148,10 +3150,10 @@ void Annotation() #void:

3148 3150

{}

3149 3151

{

3150 3152

(

3151 -

LOOKAHEAD( "@" Name() "(" ( <IDENTIFIER> "=" | ")" ))

3153 +

LOOKAHEAD( "@" VoidName() "(" ( <IDENTIFIER> "=" | ")" ))

3152 3154

NormalAnnotation()

3153 3155

|

3154 -

LOOKAHEAD( "@" Name() "(" )

3156 +

LOOKAHEAD( "@" VoidName() "(" )

3155 3157

SingleMemberAnnotation()

3156 3158

|

3157 3159

MarkerAnnotation()

@@ -3339,6 +3341,23 @@ void AmbiguousName():

3339 3341 3340 3342 3341 3343

String VoidName() #void:

3344 +

/* This is identical to ImportName except we only need 1 token lookahead. */

3345 +

{

3346 +

StringBuilder s = new StringBuilder();

3347 +

Token t;

3348 +

}

3349 +

{

3350 +

t=<IDENTIFIER>

3351 +

{

3352 +

s.append(t.image);

3353 +

}

3354 +

( "." t=<IDENTIFIER>

3355 +

{s.append('.').append(t.image);}

3356 +

)*

3357 +

{return s.toString();}

3358 +

}

3359 + 3360 +

String ImportName() #void:

3342 3361

/*

3343 3362

* A lookahead of 2 is required below since "Name" can be followed

3344 3363

* by a ".*" when used in the context of an "ImportDeclaration".

Original file line number Diff line number Diff line change

@@ -4,31 +4,21 @@

4 4 5 5

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

6 6 7 -

import net.sourceforge.pmd.annotation.InternalApi;

8 - 9 7

/**

10 8

* Represents an import declaration in a Java file.

11 9

*

12 10

* <pre class="grammar">

13 11

*

14 -

* ImportDeclaration ::= "import" "static"? {@linkplain ASTName Name} ( "." "*" )? ";"

12 +

* ImportDeclaration ::= "import" "static"? Name ( "." "*" )? ";"

15 13

*

16 14

* </pre>

17 15

*

18 16

* @see <a href="https://docs.oracle.com/javase/specs/jls/se9/html/jls-7.html#jls-7.5">JLS 7.5</a>

19 17

*/

20 -

// TODO should this really be a type node?

21 -

// E.g. for on-demand imports, what's the type of this node? There's no type name, just a package name

22 -

// for on-demand static imports?

23 -

// for static imports of a field? the type of the field or the type of the enclosing type?

24 -

// for static imports of a method?

25 -

// I don't think we can work out a spec without surprising corner cases, and #1207 will abstract

26 -

// things away anyway, so I think we should make it a regular node

27 -

public final class ASTImportDeclaration extends AbstractJavaTypeNode {

18 +

public final class ASTImportDeclaration extends AbstractJavaNode {

28 19 29 20

private boolean isImportOnDemand;

30 21

private boolean isStatic;

31 -

private Package pkg;

32 22 33 23

ASTImportDeclaration(int id) {

34 24

super(id);

@@ -75,19 +65,13 @@ public boolean isStatic() {

75 65

return isStatic;

76 66

}

77 67 78 -

// TODO - this should go away, but the DuplicateImports rule still uses it

79 -

// (in a clunky way)

80 -

public ASTName getImportedNameNode() {

81 -

return (ASTName) jjtGetChild(0);

82 -

}

83 - 84 68 85 69

/**

86 70

* Returns the full name of the import. For on-demand imports, this is the name without

87 71

* the final dot and asterisk.

88 72

*/

89 73

public String getImportedName() {

90 -

return jjtGetChild(0).getImage();

74 +

return getImage();

91 75

}

92 76 93 77

@@ -132,22 +116,5 @@ public <T> void jjtAccept(SideEffectingVisitor<T> visitor, T data) {

132 116

visitor.visit(this, data);

133 117

}

134 118 135 -

@InternalApi

136 -

@Deprecated

137 -

public void setPackage(Package packge) {

138 -

this.pkg = packge;

139 -

}

140 - 141 119 142 -

/**

143 -

* Returns the {@link Package} instance representing the package of the

144 -

* type or method imported by this declaration. This may be null if the

145 -

* auxclasspath is not correctly set, as this method depends on correct

146 -

* type resolution.

147 -

*/

148 -

// TODO deprecate? This is only used in a test. I don't think it's really

149 -

// useful and it gives work to ClassTypeResolver.

150 -

public Package getPackage() {

151 -

return this.pkg;

152 -

}

153 120

}

Original file line number Diff line number Diff line change

@@ -56,8 +56,7 @@ public Object visit(ASTCompilationUnit node, Object data) {

56 56 57 57

@Override

58 58

public Object visit(ASTImportDeclaration node, Object data) {

59 -

ASTName name = node.getFirstChildOfType(ASTName.class);

60 -

if (!lombokImported && name != null && name.getImage() != null & name.getImage().startsWith(LOMBOK_PACKAGE)) {

59 +

if (!lombokImported && node.getImage() != null & node.getImage().startsWith(LOMBOK_PACKAGE)) {

61 60

lombokImported = true;

62 61

}

63 62

return super.visit(node, data);

Original file line number Diff line number Diff line change

@@ -87,19 +87,19 @@ private boolean isDisambiguationImport(ASTCompilationUnit node, String singleTyp

87 87

@Override

88 88

public Object visit(ASTImportDeclaration node, Object data) {

89 89

ImportWrapper wrapper = new ImportWrapper(node.getImportedName(), node.getImportedName(),

90 -

node.getImportedNameNode(), node.isStatic() && node.isImportOnDemand());

90 +

node, node.isStatic() && node.isImportOnDemand());

91 91 92 92

// blahhhh... this really wants to be ASTImportDeclaration to be

93 93

// polymorphic...

94 94

if (node.isImportOnDemand()) {

95 95

if (importOnDemandImports.contains(wrapper)) {

96 -

addViolation(data, node.getImportedNameNode(), node.getImportedNameNode().getImage());

96 +

addViolation(data, node, node.getImportedName());

97 97

} else {

98 98

importOnDemandImports.add(wrapper);

99 99

}

100 100

} else {

101 101

if (singleTypeImports.contains(wrapper)) {

102 -

addViolation(data, node.getImportedNameNode(), node.getImportedNameNode().getImage());

102 +

addViolation(data, node, node.getImportedName());

103 103

} else {

104 104

singleTypeImports.add(wrapper);

105 105

}

Original file line number Diff line number Diff line change

@@ -220,23 +220,6 @@ public Object visit(ASTPackageDeclaration node, Object data) {

220 220

return data;

221 221

}

222 222 223 -

@Override

224 -

public Object visit(ASTImportDeclaration node, Object data) {

225 -

ASTName importedType = (ASTName) node.jjtGetChild(0);

226 - 227 -

if (importedType.getType() != null) {

228 -

setTypeDefinition(node, JavaTypeDefinition.forClass(importedType.getType()));

229 -

} else {

230 -

populateType(node, importedType.getImage());

231 -

}

232 - 233 -

if (node.getType() != null) {

234 -

node.setPackage(node.getType().getPackage());

235 -

}

236 - 237 -

// no need to visit children, the only child, ASTName, will have no type

238 -

return data;

239 -

}

240 223 241 224

@Override

242 225

public Object visit(ASTTypeDeclaration node, Object data) {

Original file line number Diff line number Diff line change

@@ -158,8 +158,6 @@ public void acceptanceTest() {

158 158

assertEquals(ArrayListFound.class,

159 159

acu.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class).getType());

160 160

ASTImportDeclaration id = acu.getFirstDescendantOfType(ASTImportDeclaration.class);

161 -

assertEquals("java.util", id.getPackage().getName());

162 -

assertEquals(ArrayList.class, id.getType());

163 161

assertEquals(ArrayList.class, acu.getFirstDescendantOfType(ASTClassOrInterfaceType.class).getType());

164 162

assertEquals(ArrayList.class, acu.getFirstDescendantOfType(ASTReferenceType.class).getType());

165 163

assertEquals(ArrayList.class, acu.getFirstDescendantOfType(ASTType.class).getType());

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4