Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
a0d8ab6d
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,发现更多精彩内容 >>
提交
a0d8ab6d
编写于
4月 04, 2012
作者:
N
Nikolay Krasko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
KT-1712 Formatting for getters and setters
#KT-1712 fixed
上级
549c4649
变更
13
显示空白变更内容
内联
并排
Showing
13 changed file
with
231 addition
and
49 deletion
+231
-49
idea/src/org/jetbrains/jet/plugin/formatter/ASTIndentStrategy.java
...org/jetbrains/jet/plugin/formatter/ASTIndentStrategy.java
+158
-0
idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java
idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java
+37
-30
idea/testData/formatter/GetterAndSetter.kt
idea/testData/formatter/GetterAndSetter.kt
+9
-0
idea/testData/formatter/GetterAndSetter_after.kt
idea/testData/formatter/GetterAndSetter_after.kt
+9
-0
idea/testData/quickfix/typeAddition/afterWrongGetterParameterType.kt
...ta/quickfix/typeAddition/afterWrongGetterParameterType.kt
+1
-1
idea/testData/quickfix/typeAddition/afterWrongSetterParameterType.kt
...ta/quickfix/typeAddition/afterWrongSetterParameterType.kt
+1
-1
idea/testData/quickfix/typeAddition/beforeWrongGetterParameterType.kt
...a/quickfix/typeAddition/beforeWrongGetterParameterType.kt
+1
-1
idea/testData/quickfix/typeAddition/beforeWrongSetterParameterType.kt
...a/quickfix/typeAddition/beforeWrongSetterParameterType.kt
+1
-1
idea/testData/quickfix/variables/changeMutability/afterValWithSetter.kt
...quickfix/variables/changeMutability/afterValWithSetter.kt
+2
-2
idea/testData/templates/exval.exp.kt
idea/testData/templates/exval.exp.kt
+3
-3
idea/testData/templates/exvar.exp.kt
idea/testData/templates/exvar.exp.kt
+5
-5
idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java
idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java
+4
-0
idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTest.java
...org/jetbrains/jet/formatter/JetTypingIndentationTest.java
+0
-5
未找到文件。
idea/src/org/jetbrains/jet/plugin/formatter/ASTIndentStrategy.java
0 → 100644
浏览文件 @
a0d8ab6d
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* 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.jetbrains.jet.plugin.formatter
;
import
com.intellij.formatting.Indent
;
import
com.intellij.lang.ASTNode
;
import
com.intellij.psi.tree.IElementType
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
/**
* @author Nikolay Krasko
*/
public
abstract
class
ASTIndentStrategy
{
public
static
ASTIndentStrategy
constIndent
(
Indent
indent
)
{
return
new
ConstIndentStrategy
(
indent
);
}
public
static
PositionStrategy
forNode
(
@Nullable
String
debugInfo
)
{
return
new
PositionStrategy
(
debugInfo
);
}
@Nullable
public
abstract
Indent
getIndent
(
@NotNull
ASTNode
node
);
public
static
class
ConstIndentStrategy
extends
ASTIndentStrategy
{
private
final
Indent
indent
;
public
ConstIndentStrategy
(
Indent
indent
)
{
this
.
indent
=
indent
;
}
@Nullable
@Override
public
Indent
getIndent
(
@NotNull
ASTNode
node
)
{
return
indent
;
}
}
public
static
class
PositionStrategy
extends
ASTIndentStrategy
{
private
Indent
defaultIndent
=
Indent
.
getNoneIndent
();
private
List
<
IElementType
>
in
=
new
ArrayList
<
IElementType
>();
private
List
<
IElementType
>
notIn
=
new
ArrayList
<
IElementType
>();
private
List
<
IElementType
>
forElement
=
new
ArrayList
<
IElementType
>();
private
List
<
IElementType
>
notForElement
=
new
ArrayList
<
IElementType
>();
private
String
debugInfo
;
public
PositionStrategy
(
@Nullable
String
debugInfo
)
{
this
.
debugInfo
=
debugInfo
;
}
@Override
public
String
toString
()
{
return
"PositionStrategy "
+
(
debugInfo
!=
null
?
debugInfo
:
"No debug info"
);
}
public
PositionStrategy
set
(
Indent
indent
)
{
defaultIndent
=
indent
;
return
this
;
}
public
PositionStrategy
in
(
@NotNull
IElementType
parentType
,
@NotNull
IElementType
...
orParentTypes
)
{
in
.
clear
();
in
.
add
(
parentType
);
Collections
.
addAll
(
in
,
orParentTypes
);
return
this
;
}
public
PositionStrategy
notIn
(
@NotNull
IElementType
parentType
,
@NotNull
IElementType
...
orParentTypes
)
{
notIn
.
clear
();
notIn
.
add
(
parentType
);
Collections
.
addAll
(
notIn
,
orParentTypes
);
return
this
;
}
public
PositionStrategy
inAny
()
{
in
.
clear
();
notIn
.
clear
();
return
this
;
}
public
PositionStrategy
forType
(
@NotNull
IElementType
elementType
,
@NotNull
IElementType
...
otherTypes
)
{
forElement
.
clear
();
forElement
.
add
(
elementType
);
Collections
.
addAll
(
forElement
,
otherTypes
);
return
this
;
}
public
PositionStrategy
notForType
(
@NotNull
IElementType
elementType
,
@NotNull
IElementType
...
otherTypes
)
{
notForElement
.
clear
();
notForElement
.
add
(
elementType
);
Collections
.
addAll
(
notForElement
,
otherTypes
);
return
this
;
}
public
PositionStrategy
forAny
()
{
forElement
.
clear
();
notForElement
.
clear
();
return
this
;
}
@Nullable
@Override
public
Indent
getIndent
(
@NotNull
ASTNode
node
)
{
if
(!
forElement
.
isEmpty
())
{
if
(!
forElement
.
contains
(
node
.
getElementType
()))
{
return
null
;
}
}
if
(
notForElement
.
contains
(
node
.
getElementType
()))
{
return
null
;
}
ASTNode
parent
=
node
.
getTreeParent
();
if
(
parent
!=
null
)
{
if
(!
in
.
isEmpty
())
{
if
(!
in
.
contains
(
parent
.
getElementType
()))
{
return
null
;
}
}
if
(
notIn
.
contains
(
parent
.
getElementType
()))
{
return
null
;
}
}
else
{
if
(!
in
.
isEmpty
())
{
return
null
;
}
}
return
defaultIndent
;
}
}
}
idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java
浏览文件 @
a0d8ab6d
...
...
@@ -48,10 +48,6 @@ public class JetBlock extends AbstractBlock {
JetNodeTypes
.
CLASS_BODY
,
JetNodeTypes
.
FUNCTION_LITERAL_EXPRESSION
);
private
static
final
TokenSet
STATEMENT_PARTS
=
TokenSet
.
create
(
JetNodeTypes
.
THEN
,
JetNodeTypes
.
ELSE
);
// private static final List<IndentWhitespaceRule>
public
JetBlock
(
@NotNull
ASTNode
node
,
...
...
@@ -241,35 +237,50 @@ public class JetBlock extends AbstractBlock {
};
}
@Override
protected
Indent
getChildIndent
()
{
return
super
.
getChildIndent
();
//To change body of overridden methods use File | Settings | File Templates.
}
static
ASTIndentStrategy
[]
INDENT_RULES
=
new
ASTIndentStrategy
[]
{
ASTIndentStrategy
.
forNode
(
"No indent for braces in blocks"
)
.
in
(
JetNodeTypes
.
BLOCK
,
JetNodeTypes
.
CLASS_BODY
,
JetNodeTypes
.
FUNCTION_LITERAL_EXPRESSION
)
.
forType
(
JetTokens
.
RBRACE
,
JetTokens
.
LBRACE
)
.
set
(
Indent
.
getNoneIndent
()),
@Nullable
protected
Indent
createChildIndent
(
@NotNull
ASTNode
child
)
{
CommonCodeStyleSettings
commonSettings
=
mySettings
.
getCommonSettings
(
JetLanguage
.
INSTANCE
);
ASTIndentStrategy
.
forNode
(
"Indent for block content"
)
.
in
(
JetNodeTypes
.
BLOCK
,
JetNodeTypes
.
CLASS_BODY
,
JetNodeTypes
.
FUNCTION_LITERAL_EXPRESSION
)
.
notForType
(
JetTokens
.
RBRACE
,
JetTokens
.
LBRACE
)
.
set
(
Indent
.
getNormalIndent
()),
ASTIndentStrategy
.
forNode
(
"Indent for property accessors"
)
.
in
(
JetNodeTypes
.
PROPERTY
)
.
forType
(
JetNodeTypes
.
PROPERTY_ACCESSOR
)
.
set
(
Indent
.
getNormalIndent
()),
ASTIndentStrategy
.
forNode
(
"For a single statement if 'for'"
)
.
in
(
JetNodeTypes
.
BODY
)
.
notForType
(
JetNodeTypes
.
BLOCK
)
.
set
(
Indent
.
getNormalIndent
()),
ASTIndentStrategy
.
forNode
(
"For the entry in when"
)
.
forType
(
JetNodeTypes
.
WHEN_ENTRY
)
.
set
(
Indent
.
getNormalIndent
()),
ASTIndentStrategy
.
forNode
(
"For single statement in THEN and ELSE"
)
.
in
(
JetNodeTypes
.
THEN
,
JetNodeTypes
.
ELSE
)
.
notForType
(
JetNodeTypes
.
BLOCK
)
.
set
(
Indent
.
getNormalIndent
())
};
@Nullable
protected
static
Indent
createChildIndent
(
@NotNull
ASTNode
child
)
{
ASTNode
childParent
=
child
.
getTreeParent
();
IElementType
childType
=
child
.
getElementType
();
if
(
CODE_BLOCKS
.
contains
(
myNode
.
getElementType
()))
{
return
indentIfNotBrace
(
child
);
for
(
ASTIndentStrategy
strategy
:
INDENT_RULES
)
{
Indent
indent
=
strategy
.
getIndent
(
child
);
if
(
indent
!=
null
)
{
return
indent
;
}
if
(
childParent
!=
null
&&
childParent
.
getElementType
()
==
JetNodeTypes
.
BODY
&&
childType
!=
JetNodeTypes
.
BLOCK
)
{
// For a single statement if 'for'
return
Indent
.
getNormalIndent
();
}
if
(
childType
==
JetNodeTypes
.
WHEN_ENTRY
)
{
// For the entry in when
// TODO: Add an option for configuration?
return
Indent
.
getNormalIndent
();
}
// TODO: Try to rewrite other rules to declarative style
if
(
childParent
!=
null
&&
childParent
.
getElementType
()
==
JetNodeTypes
.
WHEN_ENTRY
)
{
ASTNode
prev
=
getPrevWithoutWhitespace
(
child
);
...
...
@@ -278,10 +289,6 @@ public class JetBlock extends AbstractBlock {
}
}
if
(
STATEMENT_PARTS
.
contains
(
myNode
.
getElementType
())
&&
childType
!=
JetNodeTypes
.
BLOCK
)
{
return
Indent
.
getNormalIndent
();
}
if
(
childParent
!=
null
&&
childParent
.
getElementType
()
==
JetNodeTypes
.
DOT_QUALIFIED_EXPRESSION
)
{
if
(
childParent
.
getFirstChildNode
()
!=
child
&&
childParent
.
getLastChildNode
()
!=
child
)
{
return
Indent
.
getContinuationWithoutFirstIndent
(
false
);
...
...
idea/testData/formatter/GetterAndSetter.kt
0 → 100644
浏览文件 @
a0d8ab6d
class
Test
{
var
test
:
Int
get
()
{
return
0
}
set
(
value
)
{
throw
NotSupportedException
()
}
}
\ No newline at end of file
idea/testData/formatter/GetterAndSetter_after.kt
0 → 100644
浏览文件 @
a0d8ab6d
class
Test
{
var
test
:
Int
get
()
{
return
0
}
set
(
value
)
{
throw
NotSupportedException
()
}
}
\ No newline at end of file
idea/testData/quickfix/typeAddition/afterWrongGetterParameterType.kt
浏览文件 @
a0d8ab6d
idea/testData/quickfix/typeAddition/afterWrongSetterParameterType.kt
浏览文件 @
a0d8ab6d
idea/testData/quickfix/typeAddition/beforeWrongGetterParameterType.kt
浏览文件 @
a0d8ab6d
idea/testData/quickfix/typeAddition/beforeWrongSetterParameterType.kt
浏览文件 @
a0d8ab6d
idea/testData/quickfix/variables/changeMutability/afterValWithSetter.kt
浏览文件 @
a0d8ab6d
idea/testData/templates/exval.exp.kt
浏览文件 @
a0d8ab6d
val
Int
.
v
:
Int
get
()
{
get
()
{
<
caret
>
}
\ No newline at end of file
}
\ No newline at end of file
idea/testData/templates/exvar.exp.kt
浏览文件 @
a0d8ab6d
var
Int
.
v
:
Int
get
()
{
get
()
{
<
caret
>
}
set
(
value
)
{
}
set
(
value
)
{
}
\ No newline at end of file
}
\ No newline at end of file
idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java
浏览文件 @
a0d8ab6d
...
...
@@ -67,6 +67,10 @@ public class JetFormatterTest extends AbstractJetFormatterTest {
doTest
();
}
public
void
testGetterAndSetter
()
throws
Exception
{
doTest
();
}
public
void
testIf
()
throws
Exception
{
doTest
();
}
...
...
idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTest.java
浏览文件 @
a0d8ab6d
...
...
@@ -21,7 +21,6 @@ import com.intellij.psi.codeStyle.CodeStyleSettings;
import
com.intellij.psi.codeStyle.CodeStyleSettingsManager
;
import
com.intellij.testFramework.LightCodeInsightTestCase
;
import
org.jetbrains.jet.plugin.PluginTestCaseBase
;
import
org.jetbrains.jet.plugin.formatter.JetCodeStyleSettings
;
import
java.io.File
;
...
...
@@ -106,10 +105,6 @@ public class JetTypingIndentationTest extends LightCodeInsightTestCase {
checkResultByFile
(
afterFileName
);
}
public
static
JetCodeStyleSettings
getJetSettings
()
{
return
getSettings
().
getCustomSettings
(
JetCodeStyleSettings
.
class
);
}
public
static
CodeStyleSettings
getSettings
()
{
return
CodeStyleSettingsManager
.
getSettings
(
getProject
());
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录