-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
AbstractLiteral.java
55 lines (45 loc) · 1.48 KB
/
AbstractLiteral.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java.ast;
import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken;
import net.sourceforge.pmd.lang.document.Chars;
import net.sourceforge.pmd.lang.rule.xpath.NoAttribute;
/**
* @author Clément Fournier
*/
abstract class AbstractLiteral extends AbstractJavaExpr implements ASTLiteral {
private JavaccToken literalToken;
AbstractLiteral(int i) {
super(i);
}
@Override
public void jjtClose() {
super.jjtClose();
// Note that in this method, if the literal is parenthesized,
// its parentheses have not yet been set yet so the text is
// just the literal.
assert getParenthesisDepth() == 0;
assert getFirstToken() == getLastToken(); // NOPMD
literalToken = getFirstToken();
}
@Override
@NoAttribute
public final Chars getText() {
JavaccToken firstToken = getFirstToken();
// this literal has parentheses, the text includes them
if (firstToken.kind == JavaTokenKinds.LPAREN) {
return super.getText();
}
return firstToken.getImageCs();
}
@Override
public final Chars getLiteralText() {
assert literalToken.getImageCs() != null;
return literalToken.getImageCs();
}
@Override
public boolean isCompileTimeConstant() {
return true; // note: NullLiteral overrides this to false
}
}