Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
1001b4ae
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,发现更多精彩内容 >>
提交
1001b4ae
编写于
6月 15, 2011
作者:
D
Dmitry Jemerov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
initial, really basic implementation of formatter
上级
41bb4ce4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
215 addition
and
0 deletion
+215
-0
idea/src/META-INF/plugin.xml
idea/src/META-INF/plugin.xml
+2
-0
idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java
idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java
+146
-0
idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java
...rains/jet/plugin/formatter/JetFormattingModelBuilder.java
+29
-0
idea/src/org/jetbrains/jet/plugin/formatter/JetIndentOptionsProvider.java
...brains/jet/plugin/formatter/JetIndentOptionsProvider.java
+38
-0
未找到文件。
idea/src/META-INF/plugin.xml
浏览文件 @
1001b4ae
...
...
@@ -28,6 +28,7 @@
<lang.commenter
language=
"jet"
implementationClass=
"org.jetbrains.jet.plugin.JetCommenter"
/>
<lang.psiStructureViewFactory
language=
"jet"
implementationClass=
"org.jetbrains.jet.plugin.structureView.JetStructureViewFactory"
/>
<lang.foldingBuilder
language=
"jet"
implementationClass=
"org.jetbrains.jet.plugin.JetFoldingBuilder"
/>
<lang.formatter
language=
"jet"
implementationClass=
"org.jetbrains.jet.plugin.formatter.JetFormattingModelBuilder"
/>
<annotator
language=
"jet"
implementationClass=
"org.jetbrains.jet.plugin.annotations.SoftKeywordsAnnotator"
/>
<annotator
language=
"jet"
implementationClass=
"org.jetbrains.jet.plugin.annotations.LabelsAnnotator"
/>
<annotator
language=
"jet"
implementationClass=
"org.jetbrains.jet.plugin.annotations.JetPsiChecker"
/>
...
...
@@ -35,5 +36,6 @@
<configurationType
implementation=
"org.jetbrains.jet.plugin.run.JetRunConfigurationType"
/>
<codeInsight.lineMarkerProvider
language=
"jet"
implementationClass=
"org.jetbrains.jet.plugin.annotations.JetLineMarkerProvider"
/>
<iconProvider
implementation=
"org.jetbrains.jet.plugin.JetIconProvider"
/>
<fileTypeIndentOptionsProvider
implementation=
"org.jetbrains.jet.plugin.formatter.JetIndentOptionsProvider"
/>
</extensions>
</idea-plugin>
idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java
0 → 100644
浏览文件 @
1001b4ae
package
org.jetbrains.jet.plugin.formatter
;
import
com.intellij.formatting.*
;
import
com.intellij.lang.ASTNode
;
import
com.intellij.openapi.util.TextRange
;
import
com.intellij.psi.TokenType
;
import
com.intellij.psi.codeStyle.CodeStyleSettings
;
import
com.intellij.psi.tree.IElementType
;
import
com.intellij.psi.tree.TokenSet
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.JetNodeTypes
;
import
org.jetbrains.jet.lexer.JetTokens
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
/**
* @author yole
*/
public
class
JetBlock
implements
ASTBlock
{
private
ASTNode
myNode
;
private
Alignment
myAlignment
;
private
Indent
myIndent
;
private
Wrap
myWrap
;
private
CodeStyleSettings
mySettings
;
private
List
<
Block
>
mySubBlocks
;
private
static
final
TokenSet
CODE_BLOCKS
=
TokenSet
.
create
(
JetNodeTypes
.
BLOCK
,
JetNodeTypes
.
CLASS_BODY
,
JetNodeTypes
.
FUNCTION_LITERAL
);
private
static
final
TokenSet
STATEMENT_PARTS
=
TokenSet
.
create
(
JetNodeTypes
.
THEN
,
JetNodeTypes
.
ELSE
);
public
JetBlock
(
ASTNode
node
,
Alignment
alignment
,
Indent
indent
,
Wrap
wrap
,
CodeStyleSettings
settings
)
{
myNode
=
node
;
myAlignment
=
alignment
;
myIndent
=
indent
;
myWrap
=
wrap
;
mySettings
=
settings
;
}
@Override
public
ASTNode
getNode
()
{
return
myNode
;
}
@NotNull
@Override
public
TextRange
getTextRange
()
{
return
myNode
.
getTextRange
();
}
@Override
public
Wrap
getWrap
()
{
return
myWrap
;
}
@Override
public
Indent
getIndent
()
{
return
myIndent
;
}
@Override
public
Alignment
getAlignment
()
{
return
myAlignment
;
}
@NotNull
@Override
public
List
<
Block
>
getSubBlocks
()
{
if
(
mySubBlocks
==
null
)
{
mySubBlocks
=
buildSubBlocks
();
}
return
new
ArrayList
<
Block
>(
mySubBlocks
);
}
private
List
<
Block
>
buildSubBlocks
()
{
List
<
Block
>
blocks
=
new
ArrayList
<
Block
>();
for
(
ASTNode
child
=
myNode
.
getFirstChildNode
();
child
!=
null
;
child
=
child
.
getTreeNext
())
{
IElementType
childType
=
child
.
getElementType
();
if
(
child
.
getTextRange
().
getLength
()
==
0
)
continue
;
if
(
childType
==
TokenType
.
WHITE_SPACE
)
{
continue
;
}
blocks
.
add
(
buildSubBlock
(
child
));
}
return
Collections
.
unmodifiableList
(
blocks
);
}
private
Block
buildSubBlock
(
ASTNode
child
)
{
Wrap
wrap
=
null
;
Indent
childIndent
=
Indent
.
getNoneIndent
();
Alignment
childAlignment
=
null
;
if
(
CODE_BLOCKS
.
contains
(
myNode
.
getElementType
()))
{
childIndent
=
indentIfNotBrace
(
child
);
}
else
if
(
myNode
.
getElementType
()
==
JetNodeTypes
.
WHEN
)
{
childIndent
=
indentIfNotBrace
(
child
);
}
else
if
(
STATEMENT_PARTS
.
contains
(
myNode
.
getElementType
())
&&
child
.
getElementType
()
!=
JetNodeTypes
.
BLOCK
)
{
childIndent
=
Indent
.
getNormalIndent
();
}
return
new
JetBlock
(
child
,
childAlignment
,
childIndent
,
wrap
,
mySettings
);
}
private
static
Indent
indentIfNotBrace
(
ASTNode
child
)
{
return
child
.
getElementType
()
==
JetTokens
.
RBRACE
||
child
.
getElementType
()
==
JetTokens
.
LBRACE
?
Indent
.
getNoneIndent
()
:
Indent
.
getNormalIndent
();
}
@Override
public
Spacing
getSpacing
(
Block
block
,
Block
block1
)
{
return
null
;
}
@NotNull
@Override
public
ChildAttributes
getChildAttributes
(
int
newChildIndex
)
{
Indent
childIndent
=
Indent
.
getNoneIndent
();
if
(
CODE_BLOCKS
.
contains
(
myNode
.
getElementType
())
||
myNode
.
getElementType
()
==
JetNodeTypes
.
WHEN
)
{
childIndent
=
Indent
.
getNormalIndent
();
}
return
new
ChildAttributes
(
childIndent
,
null
);
}
@Override
public
boolean
isIncomplete
()
{
return
false
;
}
@Override
public
boolean
isLeaf
()
{
return
myNode
.
getFirstChildNode
()
==
null
;
}
}
idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java
0 → 100644
浏览文件 @
1001b4ae
package
org.jetbrains.jet.plugin.formatter
;
import
com.intellij.formatting.FormattingModel
;
import
com.intellij.formatting.FormattingModelBuilder
;
import
com.intellij.formatting.FormattingModelProvider
;
import
com.intellij.formatting.Indent
;
import
com.intellij.lang.ASTNode
;
import
com.intellij.openapi.util.TextRange
;
import
com.intellij.psi.PsiElement
;
import
com.intellij.psi.PsiFile
;
import
com.intellij.psi.codeStyle.CodeStyleSettings
;
import
org.jetbrains.annotations.NotNull
;
/**
* @author yole
*/
public
class
JetFormattingModelBuilder
implements
FormattingModelBuilder
{
@NotNull
@Override
public
FormattingModel
createModel
(
PsiElement
element
,
CodeStyleSettings
settings
)
{
final
JetBlock
block
=
new
JetBlock
(
element
.
getNode
(),
null
,
Indent
.
getNoneIndent
(),
null
,
settings
);
return
FormattingModelProvider
.
createFormattingModelForPsiFile
(
element
.
getContainingFile
(),
block
,
settings
);
}
@Override
public
TextRange
getRangeAffectingIndent
(
PsiFile
psiFile
,
int
i
,
ASTNode
astNode
)
{
return
null
;
}
}
idea/src/org/jetbrains/jet/plugin/formatter/JetIndentOptionsProvider.java
0 → 100644
浏览文件 @
1001b4ae
package
org.jetbrains.jet.plugin.formatter
;
import
com.intellij.application.options.IndentOptionsEditor
;
import
com.intellij.application.options.SmartIndentOptionsEditor
;
import
com.intellij.openapi.fileTypes.FileType
;
import
com.intellij.psi.PsiFile
;
import
com.intellij.psi.codeStyle.CodeStyleSettings
;
import
com.intellij.psi.codeStyle.FileTypeIndentOptionsProvider
;
import
org.jetbrains.jet.plugin.JetFileType
;
/**
* @author yole
*/
public
class
JetIndentOptionsProvider
implements
FileTypeIndentOptionsProvider
{
@Override
public
CodeStyleSettings
.
IndentOptions
createIndentOptions
()
{
return
new
CodeStyleSettings
.
IndentOptions
();
}
@Override
public
FileType
getFileType
()
{
return
JetFileType
.
INSTANCE
;
}
@Override
public
IndentOptionsEditor
createOptionsEditor
()
{
return
new
SmartIndentOptionsEditor
();
}
@Override
public
String
getPreviewText
()
{
return
""
;
}
@Override
public
void
prepareForReformat
(
PsiFile
psiFile
)
{
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录