Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
8074629b
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8074629b
编写于
4月 19, 2012
作者:
N
Natalia.Ukhorskaya
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactoring in JetMacro
上级
bbc8e37d
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
195 addition
and
121 deletion
+195
-121
confluence/buildConfluenceLexer.xml
confluence/buildConfluenceLexer.xml
+1
-1
confluence/src/main/java/org/jetbrains/jet/ConfluenceUtils.java
...ence/src/main/java/org/jetbrains/jet/ConfluenceUtils.java
+47
-0
confluence/src/main/java/org/jetbrains/jet/lexer/JetMacro.java
...uence/src/main/java/org/jetbrains/jet/lexer/JetMacro.java
+47
-120
confluence/src/main/java/org/jetbrains/jet/tags/StyledDivTagType.java
...rc/main/java/org/jetbrains/jet/tags/StyledDivTagType.java
+31
-0
confluence/src/main/java/org/jetbrains/jet/tags/TagData.java
confluence/src/main/java/org/jetbrains/jet/tags/TagData.java
+44
-0
confluence/src/main/java/org/jetbrains/jet/tags/TagType.java
confluence/src/main/java/org/jetbrains/jet/tags/TagType.java
+25
-0
未找到文件。
confluence/buildConfluenceLexer.xml
浏览文件 @
8074629b
<project
name=
"ConfluenceLexer"
default=
"confluenceLexer"
>
<property
name=
"home"
value=
"${basedir}"
/>
<property
file=
"${home}/../
compiler/frontend
/idea.properties"
/>
<property
file=
"${home}/../
ideaSDK/bin
/idea.properties"
/>
<property
name=
"flex.base"
value=
"${idea.home}/tools/lexer/jflex-1.4"
/>
<property
name=
"out.dir"
value=
"${basedir}/tmpout"
/>
...
...
confluence/src/main/java/org/jetbrains/jet/ConfluenceUtils.java
0 → 100644
浏览文件 @
8074629b
package
org.jetbrains.jet
;
/**
* @author Natalia.Ukhorskaya
*/
public
class
ConfluenceUtils
{
public
static
void
escapeHTML
(
StringBuilder
builder
,
CharSequence
seq
)
{
if
(
seq
==
null
)
return
;
for
(
int
i
=
0
;
i
<
seq
.
length
();
i
++)
{
char
c
=
seq
.
charAt
(
i
);
switch
(
c
)
{
case
'<'
:
builder
.
append
(
"<"
);
break
;
case
'>'
:
builder
.
append
(
">"
);
break
;
case
'&'
:
builder
.
append
(
"&"
);
break
;
case
' '
:
builder
.
append
(
" "
);
break
;
case
'"'
:
builder
.
append
(
"""
);
break
;
default
:
builder
.
append
(
c
);
}
}
}
public
static
String
getErrorInHtml
(
Throwable
e
,
String
info
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
stringBuilder
.
append
(
"<div class=\"jet herror\">Jet highlighter error ["
).
append
(
e
.
getClass
().
getSimpleName
()).
append
(
"]: "
);
ConfluenceUtils
.
escapeHTML
(
stringBuilder
,
e
.
getMessage
());
stringBuilder
.
append
(
"<br/>"
);
stringBuilder
.
append
(
"Original text:"
);
stringBuilder
.
append
(
"<pre>"
);
ConfluenceUtils
.
escapeHTML
(
stringBuilder
,
info
);
stringBuilder
.
append
(
"</pre>"
);
stringBuilder
.
append
(
"</div>"
);
return
stringBuilder
.
toString
();
}
}
confluence/src/main/java/org/jetbrains/jet/lexer/JetMacro.java
浏览文件 @
8074629b
...
...
@@ -25,6 +25,10 @@ import com.atlassian.renderer.v2.macro.MacroException;
import
com.intellij.psi.TokenType
;
import
com.intellij.psi.tree.IElementType
;
import
org.apache.velocity.VelocityContext
;
import
org.jetbrains.jet.ConfluenceUtils
;
import
org.jetbrains.jet.tags.StyledDivTagType
;
import
org.jetbrains.jet.tags.TagData
;
import
org.jetbrains.jet.tags.TagType
;
import
java.io.StringReader
;
import
java.util.*
;
...
...
@@ -38,61 +42,6 @@ public class JetMacro extends BaseMacro {
public
static
final
StringReader
DUMMY_READER
=
new
StringReader
(
""
);
private
static
class
TagData
{
final
TagType
type
;
final
String
message
;
final
int
start
;
final
boolean
nextToken
;
int
end
;
TagData
(
TagType
type
,
String
message
,
int
start
,
boolean
nextToken
)
{
this
.
type
=
type
;
this
.
message
=
message
;
this
.
start
=
start
;
this
.
nextToken
=
nextToken
;
}
}
private
static
abstract
class
TagType
{
public
final
String
tagName
;
private
TagType
(
String
tagName
)
{
this
.
tagName
=
tagName
;
}
public
abstract
void
appendOpenTag
(
StringBuilder
builder
,
TagData
tagData
);
public
abstract
void
appendCloseTag
(
StringBuilder
builder
,
TagData
tagData
);
@Override
public
String
toString
()
{
return
tagName
;
}
}
private
static
class
StyledDivTagType
extends
TagType
{
private
StyledDivTagType
(
String
tagName
)
{
super
(
tagName
);
}
@Override
public
void
appendOpenTag
(
StringBuilder
builder
,
TagData
tagData
)
{
assert
tagData
.
type
==
this
;
builder
.
append
(
"<div class=\"jet "
).
append
(
tagName
).
append
(
"\""
);
if
(
tagData
.
message
!=
null
)
{
builder
.
append
(
" title=\""
);
escapeHTML
(
builder
,
tagData
.
message
);
builder
.
append
(
"\""
);
}
builder
.
append
(
">"
);
}
@Override
public
void
appendCloseTag
(
StringBuilder
builder
,
TagData
tagData
)
{
builder
.
append
(
"</div>"
);
}
}
private
static
final
TagType
[]
knownExtraTagTypes
=
{
new
StyledDivTagType
(
"error"
),
new
StyledDivTagType
(
"warning"
),
...
...
@@ -101,7 +50,7 @@ public class JetMacro extends BaseMacro {
@Override
public
void
appendOpenTag
(
StringBuilder
builder
,
TagData
tagData
)
{
builder
.
append
(
"<a class=\"jet ref\" href=\"#"
);
builder
.
append
(
tagData
.
message
);
builder
.
append
(
tagData
.
getMessage
()
);
builder
.
append
(
"\">"
);
}
...
...
@@ -114,7 +63,7 @@ public class JetMacro extends BaseMacro {
@Override
public
void
appendOpenTag
(
StringBuilder
builder
,
TagData
tagData
)
{
builder
.
append
(
"<a name=\""
);
builder
.
append
(
tagData
.
message
);
builder
.
append
(
tagData
.
getMessage
()
);
builder
.
append
(
"\">"
);
}
...
...
@@ -127,7 +76,7 @@ public class JetMacro extends BaseMacro {
@Override
public
void
appendOpenTag
(
StringBuilder
builder
,
TagData
tagData
)
{
builder
.
append
(
"<a class=\"jet anchor\" href=\""
);
builder
.
append
(
tagData
.
message
);
builder
.
append
(
tagData
.
getMessage
()
);
builder
.
append
(
"\">"
);
}
...
...
@@ -140,7 +89,7 @@ public class JetMacro extends BaseMacro {
@Override
public
void
appendOpenTag
(
StringBuilder
builder
,
TagData
tagData
)
{
builder
.
append
(
"<div style=\""
);
builder
.
append
(
tagData
.
message
);
builder
.
append
(
tagData
.
getMessage
()
);
builder
.
append
(
"\">"
);
}
...
...
@@ -153,7 +102,7 @@ public class JetMacro extends BaseMacro {
@Override
public
void
appendOpenTag
(
StringBuilder
builder
,
TagData
tagData
)
{
builder
.
append
(
"<div class=\""
);
builder
.
append
(
tagData
.
message
);
builder
.
append
(
tagData
.
getMessage
()
);
builder
.
append
(
"\">"
);
}
...
...
@@ -167,9 +116,10 @@ public class JetMacro extends BaseMacro {
private
static
final
Map
<
TagType
,
Pattern
>
nextTokenTags
=
new
HashMap
<
TagType
,
Pattern
>();
private
static
final
Map
<
TagType
,
Pattern
>
closedTags
=
new
HashMap
<
TagType
,
Pattern
>();
private
static
final
Map
<
TagType
,
Pattern
>
closeTags
=
new
HashMap
<
TagType
,
Pattern
>();
static
{
for
(
TagType
type
:
knownExtraTagTypes
)
{
String
tagName
=
type
.
tagName
;
String
tagName
=
type
.
getTagName
()
;
openTags
.
put
(
type
,
Pattern
.
compile
(
"<"
+
tagName
+
"\\s*((desc)?=\\\"([^\n\"]*?)\\\")?>"
,
Pattern
.
MULTILINE
));
closeTags
.
put
(
type
,
Pattern
.
compile
(
"</"
+
tagName
+
">"
));
...
...
@@ -179,6 +129,7 @@ public class JetMacro extends BaseMacro {
}
private
static
final
Map
<
IElementType
,
String
>
styleMap
=
new
HashMap
<
IElementType
,
String
>();
static
{
styleMap
.
put
(
JetTokens
.
BLOCK_COMMENT
,
"jet-comment"
);
styleMap
.
put
(
JetTokens
.
DOC_COMMENT
,
"jet-comment"
);
...
...
@@ -198,7 +149,6 @@ public class JetMacro extends BaseMacro {
styleMap
.
put
(
JetTokens
.
LABEL_IDENTIFIER
,
"label"
);
styleMap
.
put
(
JetTokens
.
ATAT
,
"label"
);
styleMap
.
put
(
JetTokens
.
FIELD_IDENTIFIER
,
"field"
);
styleMap
.
put
(
JetTokens
.
RAW_STRING_LITERAL
,
"string"
);
styleMap
.
put
(
TokenType
.
BAD_CHARACTER
,
"bad"
);
}
...
...
@@ -212,32 +162,6 @@ public class JetMacro extends BaseMacro {
return
RenderMode
.
allow
(
0
);
}
private
static
void
escapeHTML
(
StringBuilder
builder
,
CharSequence
seq
)
{
if
(
seq
==
null
)
return
;
for
(
int
i
=
0
;
i
<
seq
.
length
();
i
++)
{
char
c
=
seq
.
charAt
(
i
);
switch
(
c
)
{
case
'<'
:
builder
.
append
(
"<"
);
break
;
case
'>'
:
builder
.
append
(
">"
);
break
;
case
'&'
:
builder
.
append
(
"&"
);
break
;
case
' '
:
builder
.
append
(
" "
);
break
;
case
'"'
:
builder
.
append
(
"""
);
break
;
default
:
builder
.
append
(
c
);
}
}
}
private
String
addNewLineOpenTag
()
{
return
"<div class=\"line\">"
;
}
...
...
@@ -246,7 +170,7 @@ public class JetMacro extends BaseMacro {
return
"</div>"
;
}
private
void
add
NewLines
(
StringBuilder
result
,
String
yytext
)
{
private
void
convert
NewLines
(
StringBuilder
result
,
String
yytext
)
{
for
(
int
i
=
0
;
i
<
yytext
.
length
();
i
++)
{
if
(
yytext
.
charAt
(
i
)
==
'\n'
)
{
result
.
append
(
" "
);
...
...
@@ -259,14 +183,23 @@ public class JetMacro extends BaseMacro {
@Override
public
String
execute
(
Map
map
,
String
code
,
RenderContext
renderContext
)
throws
MacroException
{
try
{
List
<
TagData
>
tags
=
new
ArrayList
<
TagData
>();
StringBuilder
afterPreprocessing
=
preprocess
(
code
.
trim
(),
tags
);
VelocityContext
context
=
new
VelocityContext
(
MacroUtils
.
defaultVelocityContext
());
String
renderedTemplate
=
VelocityUtils
.
getRenderedTemplate
(
"template.velocity"
,
context
);
StringBuilder
result
=
new
StringBuilder
(
renderedTemplate
);
generateHtmlFromCode
(
code
,
result
);
return
result
.
toString
();
}
catch
(
Throwable
e
)
{
return
ConfluenceUtils
.
getErrorInHtml
(
e
,
code
);
}
}
public
void
generateHtmlFromCode
(
String
code
,
StringBuilder
result
)
throws
java
.
io
.
IOException
{
try
{
List
<
TagData
>
tags
=
new
ArrayList
<
TagData
>();
StringBuilder
afterPreprocessing
=
preprocess
(
code
.
trim
(),
tags
);
result
.
append
(
"<div class=\"code panel\" style=\"border-width: 1px;\">"
+
"<div class=\"codeContent panelContent\">"
+
...
...
@@ -282,24 +215,24 @@ public class JetMacro extends BaseMacro {
TagData
tag
=
iterator
.
hasNext
()
?
iterator
.
next
()
:
null
;
while
(
true
)
{
int
tokenEnd
=
jetLexer
.
getTokenEnd
();
while
(
tag
!=
null
&&
tag
.
end
<
tokenEnd
)
{
result
.
append
(
"<div class=\"jet hwarning\">Skipping a tag in the middle of a token: <"
).
append
(
tag
.
type
).
append
(
"></div>"
);
while
(
tag
!=
null
&&
tag
.
getEnd
()
<
tokenEnd
)
{
result
.
append
(
"<div class=\"jet hwarning\">Skipping a tag in the middle of a token: <"
).
append
(
tag
.
getType
()
).
append
(
"></div>"
);
tag
=
iterator
.
hasNext
()
?
iterator
.
next
()
:
null
;
}
if
(
tag
!=
null
)
{
if
(
tag
.
start
==
tokenEnd
)
{
if
(
tag
.
getStart
()
==
tokenEnd
)
{
// result.append("<div class=\"jet ").append(tag.type).append("\"");
// if (tag.message != null) {
// result.append(" title=\"").append(tag.message).append("\"");
// }
// result.append(">");
tag
.
type
.
appendOpenTag
(
result
,
tag
);
tag
.
getType
()
.
appendOpenTag
(
result
,
tag
);
}
}
if
(
tag
!=
null
)
{
if
(
tag
.
end
==
tokenEnd
||
(
tag
.
nextToken
&&
tag
.
start
<
tokenEnd
))
{
tag
.
type
.
appendCloseTag
(
result
,
tag
);
if
(
tag
.
getEnd
()
==
tokenEnd
||
(
tag
.
isNextToken
()
&&
tag
.
getStart
()
<
tokenEnd
))
{
tag
.
getType
()
.
appendCloseTag
(
result
,
tag
);
tag
=
iterator
.
hasNext
()
?
iterator
.
next
()
:
null
;
}
}
...
...
@@ -310,14 +243,15 @@ public class JetMacro extends BaseMacro {
String
yytext
=
jetLexer
.
yytext
().
toString
();
if
(
yytext
.
contains
(
"\n"
))
{
add
NewLines
(
result
,
yytext
);
convert
NewLines
(
result
,
yytext
);
yytext
=
yytext
.
replaceAll
(
"\n"
,
""
);
}
String
style
=
null
;
if
(
token
instanceof
JetKeywordToken
)
{
style
=
"keyword"
;
}
else
if
(
token
==
JetTokens
.
IDENTIFIER
)
{
}
else
if
(
token
==
JetTokens
.
IDENTIFIER
)
{
for
(
IElementType
softKeyword
:
JetTokens
.
SOFT_KEYWORDS
.
asSet
())
{
if
(((
JetKeywordToken
)
softKeyword
).
getValue
().
equals
(
yytext
.
toString
()))
{
style
=
"softkeyword"
;
...
...
@@ -325,13 +259,15 @@ public class JetMacro extends BaseMacro {
}
}
style
=
style
==
null
?
"plain"
:
style
;
}
else
if
(
styleMap
.
containsKey
(
token
))
{
}
else
if
(
styleMap
.
containsKey
(
token
))
{
style
=
styleMap
.
get
(
token
);
}
else
{
}
else
{
style
=
"plain"
;
}
result
.
append
(
"<code class=\"jet "
).
append
(
style
).
append
(
"\">"
);
escapeHTML
(
result
,
yytext
);
ConfluenceUtils
.
escapeHTML
(
result
,
yytext
);
result
.
append
(
"</code>"
);
}
...
...
@@ -339,19 +275,10 @@ public class JetMacro extends BaseMacro {
result
.
append
(
"</div>"
);
result
.
append
(
"</div>"
);
result
.
append
(
"</div>"
);
return
result
.
toString
();
}
catch
(
Throwable
e
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
stringBuilder
.
append
(
"<div class=\"jet herror\">Jet highlighter error ["
).
append
(
e
.
getClass
().
getSimpleName
()).
append
(
"]: "
);
escapeHTML
(
stringBuilder
,
e
.
getMessage
());
stringBuilder
.
append
(
"<br/>"
);
stringBuilder
.
append
(
"Original text:"
);
stringBuilder
.
append
(
"<pre>"
);
escapeHTML
(
stringBuilder
,
code
);
stringBuilder
.
append
(
"</pre>"
);
stringBuilder
.
append
(
"</div>"
);
return
stringBuilder
.
toString
();
result
=
new
StringBuilder
(
ConfluenceUtils
.
getErrorInHtml
(
e
,
code
));
}
}
private
StringBuilder
preprocess
(
CharSequence
code
,
Collection
<
TagData
>
tags
)
{
...
...
@@ -382,11 +309,11 @@ public class JetMacro extends BaseMacro {
}
else
{
TagData
tag
=
tagStack
.
pop
();
if
(
type
!=
tag
.
type
)
{
if
(
type
!=
tag
.
getType
()
)
{
throw
new
IllegalArgumentException
(
"Unmatched closing tag: "
+
closeMatcher
.
group
());
}
tag
.
end
=
position
;
tag
.
setEnd
(
position
)
;
tags
.
add
(
tag
);
i
+=
closeMatcher
.
end
()
-
1
;
continue
charLoop
;
...
...
@@ -397,7 +324,7 @@ public class JetMacro extends BaseMacro {
Matcher
closedMatcher
=
matchFrom
(
code
,
i
,
closed
);
if
(
closedMatcher
!=
null
)
{
TagData
tag
=
new
TagData
(
type
,
closedMatcher
.
group
(
3
),
position
,
false
);
tag
.
end
=
position
;
tag
.
setEnd
(
position
)
;
tags
.
add
(
tag
);
i
+=
closedMatcher
.
end
()
-
1
;
continue
charLoop
;
...
...
@@ -408,7 +335,7 @@ public class JetMacro extends BaseMacro {
if
(
nextMatcher
!=
null
)
{
TagData
tag
=
new
TagData
(
type
,
nextMatcher
.
group
(
3
),
position
,
true
);
tags
.
add
(
tag
);
tag
.
end
=
code
.
length
(
);
tag
.
setEnd
(
code
.
length
()
);
i
+=
nextMatcher
.
end
()
-
1
;
continue
charLoop
;
}
...
...
confluence/src/main/java/org/jetbrains/jet/tags/StyledDivTagType.java
0 → 100644
浏览文件 @
8074629b
package
org.jetbrains.jet.tags
;
import
org.jetbrains.jet.ConfluenceUtils
;
/**
* @author abreslav
*/
public
class
StyledDivTagType
extends
TagType
{
public
StyledDivTagType
(
String
tagName
)
{
super
(
tagName
);
}
@Override
public
void
appendOpenTag
(
StringBuilder
builder
,
TagData
tagData
)
{
assert
tagData
.
getType
()
==
this
;
builder
.
append
(
"<div class=\"jet "
).
append
(
getTagName
()).
append
(
"\""
);
if
(
tagData
.
getMessage
()
!=
null
)
{
builder
.
append
(
" title=\""
);
ConfluenceUtils
.
escapeHTML
(
builder
,
tagData
.
getMessage
());
builder
.
append
(
"\""
);
}
builder
.
append
(
">"
);
}
@Override
public
void
appendCloseTag
(
StringBuilder
builder
,
TagData
tagData
)
{
builder
.
append
(
"</div>"
);
}
}
confluence/src/main/java/org/jetbrains/jet/tags/TagData.java
0 → 100644
浏览文件 @
8074629b
package
org.jetbrains.jet.tags
;
/**
* @author abreslav
*/
public
class
TagData
{
private
final
TagType
type
;
private
final
String
message
;
private
final
int
start
;
private
final
boolean
nextToken
;
private
int
end
;
public
TagData
(
TagType
type
,
String
message
,
int
start
,
boolean
nextToken
)
{
this
.
type
=
type
;
this
.
message
=
message
;
this
.
start
=
start
;
this
.
nextToken
=
nextToken
;
}
public
TagType
getType
()
{
return
type
;
}
public
String
getMessage
()
{
return
message
;
}
public
int
getStart
()
{
return
start
;
}
public
boolean
isNextToken
()
{
return
nextToken
;
}
public
int
getEnd
()
{
return
end
;
}
public
void
setEnd
(
int
end
)
{
this
.
end
=
end
;
}
}
confluence/src/main/java/org/jetbrains/jet/tags/TagType.java
0 → 100644
浏览文件 @
8074629b
package
org.jetbrains.jet.tags
;
/**
* @author abreslav
*/
public
abstract
class
TagType
{
private
final
String
tagName
;
protected
TagType
(
String
tagName
)
{
this
.
tagName
=
tagName
;
}
public
abstract
void
appendOpenTag
(
StringBuilder
builder
,
TagData
tagData
);
public
abstract
void
appendCloseTag
(
StringBuilder
builder
,
TagData
tagData
);
@Override
public
String
toString
()
{
return
tagName
;
}
public
String
getTagName
()
{
return
tagName
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录