Skip to content

Commit 5e15a5d

Browse files
committed
Exposes predefined code styles as extension point
1 parent 552ad94 commit 5e15a5d

File tree

3 files changed

+121
-1
lines changed

3 files changed

+121
-1
lines changed

kotlin-eclipse-core/plugin.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<plugin>
44
<extension-point id="org.jetbrains.kotlin.core.scriptTemplateProvider" name="Kotlin Script Template Provider" schema="schema/org.jetbrains.kotlin.core.scriptTemplateProvider.exsd"/>
55
<extension-point id="org.jetbrains.kotlin.core.scriptTemplateProviderEx" name="Kotlin Script Template Provider" schema="schema/org.jetbrains.kotlin.core.scriptTemplateProviderEx.exsd"/>
6+
<extension-point id="org.jetbrains.kotlin.core.predefinedKotlinCodeStyle" name="Predefined Kotlin Code Style" schema="schema/org.jetbrains.kotlin.core.predefinedKotlinCodeStyle.exsd"/>
67
<extension
78
id="org.jetbrains.kotlin.core.kotlinNature"
89
name="KotlinNature"
@@ -52,4 +53,13 @@
5253
id="org.jetbrains.kotlin.core.kotlinClasspathProvider">
5354
</classpathProvider>
5455
</extension>
56+
<extension
57+
point="org.jetbrains.kotlin.core.predefinedKotlinCodeStyle">
58+
<codeStyle
59+
class="org.jetbrains.kotlin.idea.formatter.KotlinObsoleteCodeStyle">
60+
</codeStyle>
61+
<codeStyle
62+
class="org.jetbrains.kotlin.idea.formatter.KotlinStyleGuideCodeStyle">
63+
</codeStyle>
64+
</extension>
5565
</plugin>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<!-- Schema file written by PDE -->
3+
<schema targetNamespace="org.jetbrains.kotlin.core" xmlns="http://www.w3.org/2001/XMLSchema">
4+
<annotation>
5+
<appinfo>
6+
<meta.schema plugin="org.jetbrains.kotlin.core" id="org.jetbrains.kotlin.core.predefinedKotlinCodeStyle" name="Predefined Kotlin Code Style"/>
7+
</appinfo>
8+
<documentation>
9+
[Enter description of this extension point.]
10+
</documentation>
11+
</annotation>
12+
13+
<element name="extension">
14+
<annotation>
15+
<appinfo>
16+
<meta.element />
17+
</appinfo>
18+
</annotation>
19+
<complexType>
20+
<choice minOccurs="1" maxOccurs="unbounded">
21+
<element ref="codeStyle"/>
22+
</choice>
23+
<attribute name="point" type="string" use="required">
24+
<annotation>
25+
<documentation>
26+
27+
</documentation>
28+
</annotation>
29+
</attribute>
30+
<attribute name="id" type="string">
31+
<annotation>
32+
<documentation>
33+
34+
</documentation>
35+
</annotation>
36+
</attribute>
37+
<attribute name="name" type="string">
38+
<annotation>
39+
<documentation>
40+
41+
</documentation>
42+
<appinfo>
43+
<meta.attribute translatable="true"/>
44+
</appinfo>
45+
</annotation>
46+
</attribute>
47+
</complexType>
48+
</element>
49+
50+
<element name="codeStyle">
51+
<complexType>
52+
<attribute name="class" type="string">
53+
<annotation>
54+
<documentation>
55+
56+
</documentation>
57+
<appinfo>
58+
<meta.attribute kind="java" basedOn="org.jetbrains.kotlin.idea.formatter.KotlinPredefinedCodeStyle:"/>
59+
</appinfo>
60+
</annotation>
61+
</attribute>
62+
</complexType>
63+
</element>
64+
65+
<annotation>
66+
<appinfo>
67+
<meta.section type="since"/>
68+
</appinfo>
69+
<documentation>
70+
[Enter the first release in which this extension point appears.]
71+
</documentation>
72+
</annotation>
73+
74+
<annotation>
75+
<appinfo>
76+
<meta.section type="examples"/>
77+
</appinfo>
78+
<documentation>
79+
[Enter extension point usage example here.]
80+
</documentation>
81+
</annotation>
82+
83+
<annotation>
84+
<appinfo>
85+
<meta.section type="apiinfo"/>
86+
</appinfo>
87+
<documentation>
88+
[Enter API information here.]
89+
</documentation>
90+
</annotation>
91+
92+
<annotation>
93+
<appinfo>
94+
<meta.section type="implementation"/>
95+
</appinfo>
96+
<documentation>
97+
[Enter information about supplied implementation of this extension point.]
98+
</documentation>
99+
</annotation>
100+
101+
102+
</schema>

kotlin-eclipse-core/src/org/jetbrains/kotlin/core/formatting/KotlinCodeStyleManager.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
package org.jetbrains.kotlin.core.formatting
22

33
import com.intellij.psi.codeStyle.CodeStyleSettings
4+
import org.eclipse.core.internal.registry.ExtensionRegistry
45
import org.eclipse.core.resources.IProject
56
import org.eclipse.core.resources.ProjectScope
7+
import org.jetbrains.kotlin.core.model.loadExecutableEP
68
import org.jetbrains.kotlin.core.preferences.KotlinCodeStyleProperties
79
import org.jetbrains.kotlin.idea.formatter.KotlinObsoleteCodeStyle
810
import org.jetbrains.kotlin.idea.formatter.KotlinPredefinedCodeStyle
911
import org.jetbrains.kotlin.idea.formatter.KotlinStyleGuideCodeStyle
1012
import java.util.concurrent.ConcurrentHashMap
1113

14+
private const val CODESTYLE_EXTENSION_POINT = "org.jetbrains.kotlin.core.predefinedKotlinCodeStyle"
15+
1216
object KotlinCodeStyleManager {
1317
private val stylesCache = ConcurrentHashMap<String, CodeStyleSettings>()
1418

1519
private val predefinedStyles: Map<String, KotlinPredefinedCodeStyle> by lazy {
16-
listOf(KotlinStyleGuideCodeStyle.INSTANCE, KotlinObsoleteCodeStyle.INSTANCE)
20+
loadPredefinedCodeStyles()
1721
.map { it.codeStyleId to it }
1822
.toMap()
1923
}
@@ -50,3 +54,7 @@ val IProject.codeStyle: CodeStyleSettings
5054
.codeStyleId
5155
?.let { KotlinCodeStyleManager.get(it) }
5256
?: CodeStyleSettings()
57+
58+
private fun loadPredefinedCodeStyles() =
59+
loadExecutableEP<KotlinPredefinedCodeStyle>(CODESTYLE_EXTENSION_POINT)
60+
.mapNotNull { it.createProvider() }

0 commit comments

Comments
 (0)