Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
2173a498
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2173a498
编写于
8月 14, 2008
作者:
A
Andy Clement
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reworked int/hex/long handling - more consistent and reliable now
上级
a06b5aaa
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
96 addition
and
27 deletion
+96
-27
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/IntLiteral.java
...a/org/springframework/expression/spel/ast/IntLiteral.java
+8
-23
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Literal.java
...java/org/springframework/expression/spel/ast/Literal.java
+46
-1
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/LongLiteral.java
.../org/springframework/expression/spel/ast/LongLiteral.java
+39
-0
org.springframework.expression/src/main/java/org/springframework/expression/spel/internal/SpelTreeAdaptor.java
...ngframework/expression/spel/internal/SpelTreeAdaptor.java
+3
-3
未找到文件。
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/IntLiteral.java
浏览文件 @
2173a498
...
...
@@ -17,33 +17,18 @@ package org.springframework.expression.spel.ast;
import
org.antlr.runtime.Token
;
/**
* Expression language AST node that represents an integer literal.
*
* @author Andy Clement
*/
public
class
IntLiteral
extends
Literal
{
private
static
String
[]
suffixes
=
{
"UL"
,
"LU"
,
"ul"
,
"lu"
,
"uL"
,
"lU"
,
"U"
,
"L"
,
"u"
,
"l"
};
private
Integer
value
;
public
IntLiteral
(
Token
payload
)
{
super
(
payload
);
// TODO properly support longs and unsigned numbers
String
toParse
=
payload
.
getText
();
try
{
value
=
Integer
.
parseInt
(
toParse
);
}
catch
(
NumberFormatException
nfe
)
{
for
(
int
i
=
0
;
i
<
suffixes
.
length
;
i
++)
{
if
(
toParse
.
endsWith
(
suffixes
[
i
]))
{
value
=
Integer
.
parseInt
(
toParse
.
substring
(
0
,
toParse
.
length
()-
suffixes
[
i
].
length
()));
return
;
}
}
throw
nfe
;
}
}
private
final
Integer
value
;
public
IntLiteral
(
Token
payload
,
int
radix
)
{
IntLiteral
(
Token
payload
,
int
value
)
{
super
(
payload
);
value
=
Integer
.
parseInt
(
payload
.
getText
().
substring
(
2
),
radix
)
;
this
.
value
=
value
;
}
@Override
...
...
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Literal.java
浏览文件 @
2173a498
...
...
@@ -16,8 +16,10 @@
package
org.springframework.expression.spel.ast
;
import
org.antlr.runtime.Token
;
import
org.springframework.expression.spel.SpelException
;
import
org.springframework.expression.spel.ExpressionState
;
import
org.springframework.expression.spel.SpelException
;
import
org.springframework.expression.spel.SpelMessages
;
import
org.springframework.expression.spel.internal.InternalELException
;
/**
* Common superclass for nodes representing literals (boolean, string, number, etc).
...
...
@@ -53,4 +55,47 @@ public abstract class Literal extends SpelNode {
return
false
;
}
/**
* Process the string form of a number, using the specified base if supplied and return an appropriate literal to
* hold it. Any suffix to indicate a long will be taken into account (either 'l' or 'L' is supported).
*
* @param numberToken the token holding the number as its payload (eg. 1234 or 0xCAFE)
* @param radix the base of number
* @return a subtype of Literal that can represent it
*/
public
static
Literal
getIntLiteral
(
Token
numberToken
,
int
radix
)
{
String
numberString
=
numberToken
.
getText
();
boolean
isLong
=
false
;
boolean
isHex
=
(
radix
==
16
);
if
(
numberString
.
length
()
>
0
)
{
isLong
=
numberString
.
endsWith
(
"L"
)
||
numberString
.
endsWith
(
"l"
);
}
if
(
isLong
||
isHex
)
{
// needs to be chopped up a little
int
len
=
numberString
.
length
();
// assert: if hex then startsWith 0x or 0X
numberString
=
numberString
.
substring
((
isHex
?
2
:
0
),
isLong
?
len
-
1
:
len
);
}
if
(
isLong
)
{
try
{
long
value
=
Long
.
parseLong
(
numberString
,
radix
);
return
new
LongLiteral
(
numberToken
,
value
);
}
catch
(
NumberFormatException
nfe
)
{
throw
new
InternalELException
(
new
SpelException
(
numberToken
.
getCharPositionInLine
(),
nfe
,
SpelMessages
.
NOT_A_LONG
,
numberToken
.
getText
()));
}
}
else
{
try
{
int
value
=
Integer
.
parseInt
(
numberString
,
radix
);
return
new
IntLiteral
(
numberToken
,
value
);
}
catch
(
NumberFormatException
nfe
)
{
throw
new
InternalELException
(
new
SpelException
(
numberToken
.
getCharPositionInLine
(),
nfe
,
SpelMessages
.
NOT_AN_INTEGER
,
numberToken
.
getText
()));
}
}
}
}
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/LongLiteral.java
0 → 100644
浏览文件 @
2173a498
/*
* Copyright 2004-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.expression.spel.ast
;
import
org.antlr.runtime.Token
;
/**
* Expression language AST node that represents a long integer literal.
*
* @author Andy Clement
*/
public
class
LongLiteral
extends
Literal
{
private
final
Long
value
;
LongLiteral
(
Token
payload
,
long
value
)
{
super
(
payload
);
this
.
value
=
value
;
}
@Override
public
Long
getLiteralValue
()
{
return
value
;
}
}
org.springframework.expression/src/main/java/org/springframework/expression/spel/internal/SpelTreeAdaptor.java
浏览文件 @
2173a498
...
...
@@ -28,9 +28,9 @@ import org.springframework.expression.spel.ast.ExpressionListNode;
import
org.springframework.expression.spel.ast.FunctionReference
;
import
org.springframework.expression.spel.ast.Identifier
;
import
org.springframework.expression.spel.ast.Indexer
;
import
org.springframework.expression.spel.ast.IntLiteral
;
import
org.springframework.expression.spel.ast.Lambda
;
import
org.springframework.expression.spel.ast.ListInitializer
;
import
org.springframework.expression.spel.ast.Literal
;
import
org.springframework.expression.spel.ast.LocalFunctionReference
;
import
org.springframework.expression.spel.ast.LocalVariableReference
;
import
org.springframework.expression.spel.ast.MapEntry
;
...
...
@@ -94,9 +94,9 @@ public class SpelTreeAdaptor extends CommonTreeAdaptor {
case
SpringExpressionsLexer
.
REAL_LITERAL
:
return
new
RealLiteral
(
payload
);
case
SpringExpressionsLexer
.
INTEGER_LITERAL
:
return
new
IntLiteral
(
payload
);
return
Literal
.
getIntLiteral
(
payload
,
10
);
case
SpringExpressionsLexer
.
HEXADECIMAL_INTEGER_LITERAL
:
return
new
IntLiteral
(
payload
,
16
/* HEX */
);
return
Literal
.
getIntLiteral
(
payload
,
16
);
case
SpringExpressionsLexer
.
NOT_EQUAL
:
return
new
OperatorInequality
(
payload
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录