diff --git a/kotlin-bundled-compiler/META-INF/MANIFEST.MF b/kotlin-bundled-compiler/META-INF/MANIFEST.MF
index ef0e69108..d5c401fed 100644
--- a/kotlin-bundled-compiler/META-INF/MANIFEST.MF
+++ b/kotlin-bundled-compiler/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Bundled Kotlin Compiler
Bundle-SymbolicName: org.jetbrains.kotlin.bundled-compiler;singleton:=true
-Bundle-Version: 0.8.7.qualifier
+Bundle-Version: 0.8.8.qualifier
Bundle-Vendor: JetBrains
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ClassPath: .,
diff --git a/kotlin-bundled-compiler/build.properties b/kotlin-bundled-compiler/build.properties
index ee8fdd479..516ab323b 100644
--- a/kotlin-bundled-compiler/build.properties
+++ b/kotlin-bundled-compiler/build.properties
@@ -31,7 +31,8 @@ bin.includes = META-INF/,\
lib/kotlin-script-runtime.jar,\
lib/allopen-compiler-plugin.jar,\
lib/sam-with-receiver-compiler-plugin.jar,\
- lib/noarg-compiler-plugin.jar
+ lib/noarg-compiler-plugin.jar,\
+ lib/annotations-13.0.jar
src.includes = lib/
bin.excludes = lib/kotlin-compiler-sources.jar,\
lib/downloads/
diff --git a/kotlin-bundled-compiler/get_bundled.xml b/kotlin-bundled-compiler/get_bundled.xml
index d34bbae12..170c309e7 100644
--- a/kotlin-bundled-compiler/get_bundled.xml
+++ b/kotlin-bundled-compiler/get_bundled.xml
@@ -1,16 +1,16 @@
-
+
-
+
-
+
+ value="${teamcity-base}/guestAuth/app/rest/builds/buildType:Kotlin_130_CompilerAllPlugins,status:success,count:1/artifacts/content"/>
@@ -86,7 +86,7 @@
@@ -192,6 +192,7 @@
+
@@ -218,16 +219,16 @@
-
+
-
+
RANGE_COMPARATOR = new Comparator() {
+ @Override
+ public int compare(TextRange range1, TextRange range2) {
+ int startOffsetDiff = range1.getStartOffset() - range2.getStartOffset();
+ return startOffsetDiff != 0 ? startOffsetDiff : range1.getEndOffset() - range2.getEndOffset();
+ }
+ };
+
+ private TextRangeUtil() {
+ }
+
+ /**
+ * Excludes ranges from the original range. For example, if the original range is [30..100] and ranges to exclude are
+ * [20..50] and [60..90], resulting ranges will be [50..60] and [90..100]. The ranges may overlap and follow in any order. In the latter
+ * case the original list of excluded ranges is sorted by start/end offset.
+ *
+ * @param original The original range to exclude the ranges from.
+ * @param excludedRanges The list of ranges to exclude.
+ * @return A list of ranges after excluded ranges have been applied.
+ */
+ public static Iterable excludeRanges(@NotNull TextRange original, @NotNull List excludedRanges) {
+ if (!excludedRanges.isEmpty()) {
+ if (excludedRanges.size() > 1) {
+ Collections.sort(excludedRanges, RANGE_COMPARATOR);
+ }
+ int enabledRangeStart = original.getStartOffset();
+ List enabledRanges = new ArrayList();
+ for (TextRange excludedRange : excludedRanges) {
+ if (excludedRange.getEndOffset() < enabledRangeStart) continue;
+ int excludedRangeStart = excludedRange.getStartOffset();
+ if (excludedRangeStart > original.getEndOffset()) break;
+ if (excludedRangeStart > enabledRangeStart) {
+ enabledRanges.add(new TextRange(enabledRangeStart, excludedRangeStart));
+ }
+ enabledRangeStart = excludedRange.getEndOffset();
+ }
+ if (enabledRangeStart < original.getEndOffset()) {
+ enabledRanges.add(new TextRange(enabledRangeStart, original.getEndOffset()));
+ }
+ return enabledRanges;
+ }
+ return Collections.singletonList(original);
+ }
+
+ /**
+ * Return least text range that contains all of passed text ranges.
+ * For example for {[0, 3],[3, 7],[10, 17]} this method will return [0, 17]
+ * @param textRanges The list of ranges to process
+ * @return least text range that contains all of passed text ranges
+ */
+ @NotNull
+ public static TextRange getEnclosingTextRange(@NotNull List textRanges) {
+ if(textRanges.isEmpty())
+ return TextRange.EMPTY_RANGE;
+ int lowerBound = textRanges.get(0).getStartOffset();
+ int upperBound = textRanges.get(0).getEndOffset();
+ for(int i = 1; i < textRanges.size(); ++i) {
+ TextRange textRange = textRanges.get(i);
+ lowerBound = Math.min(lowerBound, textRange.getStartOffset());
+ upperBound = Math.max(upperBound, textRange.getEndOffset());
+ }
+ return new TextRange(lowerBound, upperBound);
+ }
+
+ public static int getDistance(@NotNull Segment r2, @NotNull Segment r1) {
+ int s1 = r1.getStartOffset();
+ int e1 = r1.getEndOffset();
+ int s2 = r2.getStartOffset();
+ int e2 = r2.getEndOffset();
+ return Math.max(s1, s2) <= Math.min(e1, e2) ? 0 : Math.min(Math.abs(s1 - e2), Math.abs(s2 - e1));
+ }
+}
diff --git a/kotlin-eclipse-aspects/.classpath b/kotlin-eclipse-aspects/.classpath
index 1ee93acd9..9fcfb446e 100644
--- a/kotlin-eclipse-aspects/.classpath
+++ b/kotlin-eclipse-aspects/.classpath
@@ -3,6 +3,8 @@
+
+
diff --git a/kotlin-eclipse-aspects/.project b/kotlin-eclipse-aspects/.project
index 3da7649e3..2ff8cf783 100644
--- a/kotlin-eclipse-aspects/.project
+++ b/kotlin-eclipse-aspects/.project
@@ -5,6 +5,11 @@
+
+ org.jetbrains.kotlin.ui.kotlinBuilder
+
+
+
org.eclipse.ajdt.core.ajbuilder
@@ -25,6 +30,7 @@
org.eclipse.ajdt.ui.ajnature
org.eclipse.pde.PluginNature
org.eclipse.jdt.core.javanature
+ org.jetbrains.kotlin.core.kotlinNature
diff --git a/kotlin-eclipse-aspects/META-INF/MANIFEST.MF b/kotlin-eclipse-aspects/META-INF/MANIFEST.MF
index 1334ee20f..e4d10767a 100644
--- a/kotlin-eclipse-aspects/META-INF/MANIFEST.MF
+++ b/kotlin-eclipse-aspects/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: kotlin-eclipse-aspects
Bundle-SymbolicName: org.jetbrains.kotlin.aspects
-Bundle-Version: 0.8.7.qualifier
+Bundle-Version: 0.8.8.qualifier
Bundle-Activator: org.jetbrains.kotlin.aspects.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
@@ -33,7 +33,9 @@ Import-Package: org.eclipse.core.resources,
org.eclipse.jdt.launching.sourcelookup.containers,
org.eclipse.jface.text,
org.eclipse.ui.ide,
- org.eclipse.jdt.internal.ui.viewsupport
+ org.eclipse.jdt.internal.ui.packageview,
+ org.eclipse.jdt.internal.ui.viewsupport,
+ org.eclipse.swt.graphics
Eclipse-SupplementBundle:
org.eclipse.jdt.debug.ui,
org.eclipse.jdt.debug,
diff --git a/kotlin-eclipse-aspects/pom.xml b/kotlin-eclipse-aspects/pom.xml
index 0fcc5d3b1..661b502fc 100644
--- a/kotlin-eclipse-aspects/pom.xml
+++ b/kotlin-eclipse-aspects/pom.xml
@@ -8,7 +8,7 @@
../pom.xml
kotlin.eclipse
kotlin.eclipse.plugin
- 0.8.7-SNAPSHOT
+ 0.8.8-SNAPSHOT
org.jetbrains.kotlin.aspects
diff --git a/kotlin-eclipse-core/META-INF/MANIFEST.MF b/kotlin-eclipse-core/META-INF/MANIFEST.MF
index 73f866837..4a76e5885 100644
--- a/kotlin-eclipse-core/META-INF/MANIFEST.MF
+++ b/kotlin-eclipse-core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: kotlin-eclipse-core
Bundle-SymbolicName: org.jetbrains.kotlin.core;singleton:=true
-Bundle-Version: 0.8.7.qualifier
+Bundle-Version: 0.8.8.qualifier
Bundle-Activator: org.jetbrains.kotlin.core.Activator
Bundle-Vendor: JetBrains
Require-Bundle: org.jetbrains.kotlin.bundled-compiler,
@@ -32,6 +32,7 @@ Export-Package: org.jetbrains.kotlin.core,
org.jetbrains.kotlin.core.compiler,
org.jetbrains.kotlin.core.debug,
org.jetbrains.kotlin.core.filesystem,
+ org.jetbrains.kotlin.core.formatting,
org.jetbrains.kotlin.core.launch,
org.jetbrains.kotlin.core.log,
org.jetbrains.kotlin.core.model,
diff --git a/kotlin-eclipse-core/plugin.xml b/kotlin-eclipse-core/plugin.xml
index 5fa81bcd6..9505b515b 100644
--- a/kotlin-eclipse-core/plugin.xml
+++ b/kotlin-eclipse-core/plugin.xml
@@ -3,6 +3,7 @@
+
+
+
+
+
+
+
diff --git a/kotlin-eclipse-core/pom.xml b/kotlin-eclipse-core/pom.xml
index fc208faf3..76881d210 100644
--- a/kotlin-eclipse-core/pom.xml
+++ b/kotlin-eclipse-core/pom.xml
@@ -8,7 +8,7 @@
../pom.xml
kotlin.eclipse
kotlin.eclipse.plugin
- 0.8.7-SNAPSHOT
+ 0.8.8-SNAPSHOT
org.jetbrains.kotlin.core
diff --git a/kotlin-eclipse-core/preferences.ini b/kotlin-eclipse-core/preferences.ini
index ec9e681f4..c71553e45 100644
--- a/kotlin-eclipse-core/preferences.ini
+++ b/kotlin-eclipse-core/preferences.ini
@@ -11,3 +11,4 @@ compilerPlugins/jpa/jarPath=$KOTLIN_HOME/lib/noarg-compiler-plugin.jar
compilerPlugins/jpa/args=org.jetbrains.kotlin.noarg:preset=jpa
compilerPlugins/sam-with-receiver/active=false
compilerPlugins/sam-with-receiver/jarPath=$KOTLIN_HOME/lib/sam-with-receiver-compiler-plugin.jar
+codeStyle/codeStyleId=KOTLIN_OLD_DEFAULTS
diff --git a/kotlin-eclipse-core/schema/org.jetbrains.kotlin.core.predefinedKotlinCodeStyle.exsd b/kotlin-eclipse-core/schema/org.jetbrains.kotlin.core.predefinedKotlinCodeStyle.exsd
new file mode 100644
index 000000000..e9dc42bba
--- /dev/null
+++ b/kotlin-eclipse-core/schema/org.jetbrains.kotlin.core.predefinedKotlinCodeStyle.exsd
@@ -0,0 +1,102 @@
+
+
+
+
+
+
+
+
+ [Enter description of this extension point.]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ [Enter the first release in which this extension point appears.]
+
+
+
+
+
+
+
+
+ [Enter extension point usage example here.]
+
+
+
+
+
+
+
+
+ [Enter API information here.]
+
+
+
+
+
+
+
+
+ [Enter information about supplied implementation of this extension point.]
+
+
+
+
+
diff --git a/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/KotlinClasspathContainer.kt b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/KotlinClasspathContainer.kt
index fcc71451f..c5f849ed6 100644
--- a/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/KotlinClasspathContainer.kt
+++ b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/KotlinClasspathContainer.kt
@@ -24,34 +24,34 @@ import org.eclipse.jdt.core.IJavaProject
import org.eclipse.jdt.core.JavaCore
import org.jetbrains.kotlin.core.model.KotlinJavaManager
import org.jetbrains.kotlin.core.utils.ProjectUtils
-import java.util.ArrayList
-import kotlin.jvm.JvmStatic
+import java.util.*
val runtimeContainerId: IPath = Path("org.jetbrains.kotlin.core.KOTLIN_CONTAINER")
fun newExportedLibraryEntry(path: IPath): IClasspathEntry = JavaCore.newLibraryEntry(path, null, null, true)
-public class KotlinClasspathContainer(val javaProject: IJavaProject) : IClasspathContainer {
+class KotlinClasspathContainer(val javaProject: IJavaProject) : IClasspathContainer {
companion object {
val CONTAINER_ENTRY: IClasspathEntry = JavaCore.newContainerEntry(runtimeContainerId)
val LIB_RUNTIME_NAME = "kotlin-stdlib"
val LIB_RUNTIME_SRC_NAME = "kotlin-stdlib-sources"
val LIB_REFLECT_NAME = "kotlin-reflect"
val LIB_SCRIPT_RUNTIME_NAME = "kotlin-script-runtime"
-
+ val LIB_ANNOTATIONS_1_3 = "annotations-13.0"
+
@JvmStatic
- public fun getPathToLightClassesFolder(javaProject: IJavaProject): IPath {
- return Path(javaProject.getProject().getName()).append(KotlinJavaManager.KOTLIN_BIN_FOLDER).makeAbsolute()
+ fun getPathToLightClassesFolder(javaProject: IJavaProject): IPath {
+ return Path(javaProject.project.name).append(KotlinJavaManager.KOTLIN_BIN_FOLDER).makeAbsolute()
}
}
-
- override public fun getClasspathEntries() : Array {
+
+ override fun getClasspathEntries(): Array {
val entries = ArrayList()
val kotlinBinFolderEntry = newExportedLibraryEntry(getPathToLightClassesFolder(javaProject))
entries.add(kotlinBinFolderEntry)
-
- val project = javaProject.getProject()
+
+ val project = javaProject.project
if (!ProjectUtils.isMavenProject(project) && !ProjectUtils.isGradleProject(project)) {
val kotlinRuntimeEntry = JavaCore.newLibraryEntry(
LIB_RUNTIME_NAME.buildLibPath(),
@@ -60,20 +60,22 @@ public class KotlinClasspathContainer(val javaProject: IJavaProject) : IClasspat
true)
val kotlinReflectEntry = newExportedLibraryEntry(LIB_REFLECT_NAME.buildLibPath())
val kotlinScriptRuntime = newExportedLibraryEntry(LIB_SCRIPT_RUNTIME_NAME.buildLibPath())
+ val annotations13 = newExportedLibraryEntry(LIB_ANNOTATIONS_1_3.buildLibPath())
entries.add(kotlinRuntimeEntry)
entries.add(kotlinReflectEntry)
entries.add(kotlinScriptRuntime)
+ entries.add(annotations13)
}
return entries.toTypedArray()
}
-
- override public fun getDescription() : String = "Kotlin Runtime Library"
-
- override public fun getKind() : Int = IClasspathContainer.K_APPLICATION
-
- override public fun getPath() : IPath = runtimeContainerId
+
+ override fun getDescription(): String = "Kotlin Runtime Library"
+
+ override fun getKind(): Int = IClasspathContainer.K_APPLICATION
+
+ override fun getPath(): IPath = runtimeContainerId
}
fun String.buildLibPath(): Path = Path(ProjectUtils.buildLibPath(this))
\ No newline at end of file
diff --git a/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/builder/KotlinPsiManager.kt b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/builder/KotlinPsiManager.kt
index 70c3dfa0c..ea2ebd001 100644
--- a/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/builder/KotlinPsiManager.kt
+++ b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/builder/KotlinPsiManager.kt
@@ -59,13 +59,22 @@ interface PsiFilesStorage {
fun removeFile(file: IFile)
}
+private fun parseFile(file: IFile): KtFile =
+ KotlinPsiManager.parseFile(file) ?: throw IllegalStateException("Can't parse file $file")
+
+private fun parseIfNotSame(file: IFile, ktFile: KtFile?, expectedSourceCode: String): KtFile =
+ if (ktFile != null && ktFile.getText().equals(StringUtilRt.convertLineSeparators(expectedSourceCode))) {
+ ktFile
+ }
+ else parseFile(file)
+
private class ScriptsFilesStorage : PsiFilesStorage {
private val cachedKtFiles = ConcurrentHashMap()
override fun getPsiFile(eclipseFile: IFile): KtFile {
assert(isApplicable(eclipseFile)) { "$eclipseFile is not applicable for Kotlin scripts storage" }
- return cachedKtFiles.getOrPut(eclipseFile) { KotlinPsiManager.parseFile(eclipseFile)!! }
+ return cachedKtFiles.getOrPut(eclipseFile) { parseFile(eclipseFile) }
}
@Synchronized
@@ -94,109 +103,113 @@ private class ProjectSourceFiles : PsiFilesStorage {
fun isKotlinFile(file: IFile): Boolean = KotlinFileType.INSTANCE.getDefaultExtension() == file.fileExtension
}
- private val projectFiles = hashMapOf>()
- private val cachedKtFiles = hashMapOf()
- private val mapOperationLock = Any()
+ private val projectFiles = ConcurrentHashMap>()
+ private val cachedKtFiles = ConcurrentHashMap()
override fun getPsiFile(eclipseFile: IFile): KtFile {
- synchronized (mapOperationLock) {
- updateProjectPsiSourcesIfNeeded(eclipseFile.getProject())
+ updateProjectPsiSourcesIfNeeded(eclipseFile.getProject())
- assert(existsInProjectSources(eclipseFile), { "File(" + eclipseFile.getName() + ") does not contain in the psiFiles" })
+ assert(existsInProjectSources(eclipseFile), { "File(" + eclipseFile.getName() + ") does not contain in the psiFiles" })
- return cachedKtFiles.getOrPut(eclipseFile) {
- KotlinPsiManager.parseFile(eclipseFile) ?: throw IllegalStateException("Can't parse file $eclipseFile")
- }
- }
+ return cachedKtFiles.getOrPut(eclipseFile) { parseFile(eclipseFile) }
}
override fun getPsiFile(file: IFile, expectedSourceCode: String): KtFile {
- synchronized (mapOperationLock) {
- updatePsiFile(file, expectedSourceCode)
- return getPsiFile(file)
- }
+ updateProjectPsiSourcesIfNeeded(file.getProject())
+
+ assert(existsInProjectSources(file), { "File(" + file.getName() + ") does not contain in the psiFiles" })
+
+ return cachedKtFiles.compute(file) { _,cachedKtFile ->
+ parseIfNotSame(file, cachedKtFile, expectedSourceCode)
+ }!!
}
override fun isApplicable(file: IFile): Boolean = existsInProjectSources(file)
fun existsInProjectSources(file: IFile): Boolean {
- synchronized (mapOperationLock) {
- val project = file.getProject() ?: return false
-
- updateProjectPsiSourcesIfNeeded(project)
-
- val files = projectFiles[project]
- return if (files != null) files.contains(file) else false
+ val project = file.getProject() ?: return false
+
+ val exists = projectFiles.compute(project) { _,origFiles ->
+ origFiles ?: computeProjectPsiSources(project, origFiles)
}
+ ?.contains(file) ?: false
+
+ return exists
}
fun containsProject(project: IProject): Boolean {
- return synchronized (mapOperationLock) {
- projectFiles.containsKey(project)
- }
+ return projectFiles.containsKey(project)
}
fun getFilesByProject(project: IProject): Set {
- synchronized (mapOperationLock) {
- updateProjectPsiSourcesIfNeeded(project)
-
- if (projectFiles.containsKey(project)) {
- return Collections.unmodifiableSet(projectFiles[project])
- }
-
- return emptySet()
+ val files = projectFiles.compute(project) { _,origFiles ->
+ origFiles ?: computeProjectPsiSources(project, origFiles)
}
+
+ return if (files != null)
+ Collections.unmodifiableSet(files)
+ else
+ emptySet()
}
fun addFile(file: IFile) {
- synchronized (mapOperationLock) {
- assert(KotlinNature.hasKotlinNature(file.getProject()),
- { "Project (" + file.getProject().getName() + ") does not have Kotlin nature" })
-
- assert(!existsInProjectSources(file), { "File(" + file.getName() + ") is already added" })
-
- projectFiles
- .getOrPut(file.project) { hashSetOf() }
- .add(file)
+ assert(KotlinNature.hasKotlinNature(file.getProject()),
+ { "Project (" + file.getProject().getName() + ") does not have Kotlin nature" })
+
+ assert(!existsInProjectSources(file), { "File(" + file.getName() + ") is already added" })
+
+ projectFiles.compute(file.project) { _,origFiles ->
+ val files = origFiles ?: hashSetOf()
+ files.add(file)
+ files
}
}
override fun removeFile(file: IFile) {
- synchronized (mapOperationLock) {
- assert(existsInProjectSources(file), { "File(" + file.getName() + ") does not contain in the psiFiles" })
-
+ assert(existsInProjectSources(file), { "File(" + file.getName() + ") does not contain in the psiFiles" })
+
+ projectFiles.compute(file.project) { _,origFiles ->
cachedKtFiles.remove(file)
- projectFiles.get(file.project)?.remove(file)
- }
+ origFiles?.remove(file)
+ origFiles
+ }
}
fun addProject(project: IProject) {
- synchronized (mapOperationLock) {
- if (ProjectUtils.isAccessibleKotlinProject(project)) {
- addFilesToParse(JavaCore.create(project))
- }
+ projectFiles.compute(project) { _,origFiles ->
+ computeProjectPsiSources(project, origFiles)
}
}
+ fun computeProjectPsiSources(project: IProject, origFiles: HashSet? = null) =
+ if (ProjectUtils.isAccessibleKotlinProject(project)) {
+ getFilesToParse(JavaCore.create(project))
+ }
+ else origFiles
+
fun removeProject(project: IProject) {
- synchronized (mapOperationLock) {
- val files = getFilesByProject(project)
-
- projectFiles.remove(project)
- for (file in files) {
+ projectFiles.computeIfPresent(project) { _,origFiles ->
+ for (file in origFiles) {
cachedKtFiles.remove(file)
}
+ null
}
}
fun addFilesToParse(javaProject: IJavaProject) {
+ projectFiles.compute(javaProject.getProject()) { _,_ ->
+ getFilesToParse(javaProject)
+ }
+ }
+
+ fun getFilesToParse(javaProject: IJavaProject): HashSet {
+ val files = hashSetOf()
+
try {
- projectFiles.put(javaProject.getProject(), HashSet())
-
for (sourceFolder in javaProject.sourceFolders) {
sourceFolder.getResource().accept { resource ->
if (resource is IFile && isKotlinFile(resource)) {
- addFile(resource)
+ files.add(resource)
}
true
@@ -205,15 +218,13 @@ private class ProjectSourceFiles : PsiFilesStorage {
} catch (e: CoreException) {
KotlinLogger.logError(e)
}
+
+ return files;
}
fun updateProjectPsiSourcesIfNeeded(project: IProject) {
- if (projectFiles.containsKey(project)) {
- return
- }
-
- if (ProjectUtils.isAccessibleKotlinProject(project)) {
- updateProjectPsiSources(project, IResourceDelta.ADDED)
+ projectFiles.computeIfAbsent(project) { _ ->
+ computeProjectPsiSources(project)!!
}
}
@@ -227,20 +238,6 @@ private class ProjectSourceFiles : PsiFilesStorage {
fun invalidateProjectSourceFiles() {
cachedKtFiles.clear()
}
-
- private fun updatePsiFile(file: IFile, sourceCode: String) {
- val sourceCodeWithouCR = StringUtilRt.convertLineSeparators(sourceCode)
-
- synchronized (mapOperationLock) {
- assert(existsInProjectSources(file), { "File(" + file.getName() + ") does not contain in the psiFiles" })
-
- val currentParsedFile = getPsiFile(file)
- if (!currentParsedFile.getText().equals(sourceCodeWithouCR)) {
- val jetFile = KotlinPsiManager.parseText(sourceCodeWithouCR, file)!!
- cachedKtFiles.put(file, jetFile)
- }
- }
- }
}
object KotlinPsiManager {
diff --git a/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/formatting/KotlinCodeStyleManager.kt b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/formatting/KotlinCodeStyleManager.kt
new file mode 100644
index 000000000..71201a6ed
--- /dev/null
+++ b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/formatting/KotlinCodeStyleManager.kt
@@ -0,0 +1,60 @@
+package org.jetbrains.kotlin.core.formatting
+
+import com.intellij.psi.codeStyle.CodeStyleSettings
+import org.eclipse.core.internal.registry.ExtensionRegistry
+import org.eclipse.core.resources.IProject
+import org.eclipse.core.resources.ProjectScope
+import org.jetbrains.kotlin.core.model.loadExecutableEP
+import org.jetbrains.kotlin.core.preferences.KotlinCodeStyleProperties
+import org.jetbrains.kotlin.idea.formatter.KotlinObsoleteCodeStyle
+import org.jetbrains.kotlin.idea.formatter.KotlinPredefinedCodeStyle
+import org.jetbrains.kotlin.idea.formatter.KotlinStyleGuideCodeStyle
+import java.util.concurrent.ConcurrentHashMap
+
+private const val CODESTYLE_EXTENSION_POINT = "org.jetbrains.kotlin.core.predefinedKotlinCodeStyle"
+
+object KotlinCodeStyleManager {
+ private val stylesCache = ConcurrentHashMap()
+
+ private val predefinedStyles: Map by lazy {
+ loadPredefinedCodeStyles()
+ .map { it.codeStyleId to it }
+ .toMap()
+ }
+
+ val styles: List
+ get() = (predefinedStyles.keys + stylesCache.keys).sorted()
+
+ // Can be used in the future to provide user defined code styles
+ fun getOrCreate(id: String, settingsApplier: CodeStyleSettings.() -> Unit): CodeStyleSettings =
+ stylesCache.getOrPut(id) { CodeStyleSettings().also { it.settingsApplier() } }
+
+ fun get(id: String): CodeStyleSettings? = stylesCache[id] ?: createStyleFromPredef(id)
+
+ // Uses the same logic as ConcurrentHashMap.getOrPut() but due to possible nullability cannot be expressed by that method.
+ private fun createStyleFromPredef(id: String): CodeStyleSettings? = predefinedStyles[id]
+ ?.let { CodeStyleSettings().also(it::apply) }
+ ?.let { stylesCache.putIfAbsent(id, it) ?: it }
+
+ fun invalidate(id: String) {
+ stylesCache -= id
+ }
+
+ fun getStyleLabel(id: String?) =
+ id?.let { predefinedStyles[it]?.name ?: it } ?: "unknown"
+}
+
+private val IProject.codeStyleSettings
+ get() = KotlinCodeStyleProperties(ProjectScope(this))
+ .takeIf { it.globalsOverridden }
+ ?: KotlinCodeStyleProperties.workspaceInstance
+
+val IProject.codeStyle: CodeStyleSettings
+ get() = codeStyleSettings
+ .codeStyleId
+ ?.let { KotlinCodeStyleManager.get(it) }
+ ?: CodeStyleSettings()
+
+private fun loadPredefinedCodeStyles() =
+ loadExecutableEP(CODESTYLE_EXTENSION_POINT)
+ .mapNotNull { it.createProvider() }
\ No newline at end of file
diff --git a/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/model/KotlinEnvironment.kt b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/model/KotlinEnvironment.kt
index 7bfea76cb..a2e80b480 100644
--- a/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/model/KotlinEnvironment.kt
+++ b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/model/KotlinEnvironment.kt
@@ -29,7 +29,9 @@ import org.eclipse.core.resources.IFile
import org.eclipse.core.resources.IProject
import org.eclipse.core.resources.IResource
import org.eclipse.core.resources.ProjectScope
+import org.eclipse.core.runtime.IProgressMonitor
import org.eclipse.core.runtime.Status
+import org.eclipse.core.runtime.jobs.IJobChangeEvent
import org.eclipse.core.runtime.jobs.Job
import org.eclipse.jdt.core.IClasspathContainer
import org.eclipse.jdt.core.IClasspathEntry
@@ -242,7 +244,7 @@ class KotlinScriptEnvironment private constructor(
val definitions = arrayListOf()
val classpath = arrayListOf()
- runJob("Initialize Script Definitions", Job.DECORATE, constructFamilyForInitialization(eclipseFile), { monitor ->
+ runJob("Initialize Script Definitions", Job.DECORATE, 0, constructFamilyForInitialization(eclipseFile), { monitor ->
val definitionsAndClasspath = loadAndCreateDefinitionsByTemplateProviders(eclipseFile, monitor)
KotlinLogger.logInfo("Found definitions: ${definitionsAndClasspath.first.joinToString()}")
definitions.addAll(definitionsAndClasspath.first)
@@ -251,7 +253,7 @@ class KotlinScriptEnvironment private constructor(
monitor.done()
Status.OK_STATUS
- }, { _ ->
+ }, {
isScriptDefinitionsInitialized = true
isInitializingScriptDefinitions = false
postTask(definitions, classpath)
diff --git a/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/model/KotlinNature.kt b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/model/KotlinNature.kt
index 87954d892..2821a0bb7 100644
--- a/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/model/KotlinNature.kt
+++ b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/model/KotlinNature.kt
@@ -16,14 +16,11 @@
*******************************************************************************/
package org.jetbrains.kotlin.core.model
-import org.eclipse.core.resources.ICommand
import org.eclipse.core.resources.IProject
-import org.eclipse.core.resources.IProjectDescription
import org.eclipse.core.resources.IProjectNature
-import org.eclipse.core.runtime.CoreException
+import org.eclipse.core.resources.ProjectScope
import kotlin.properties.Delegates
import org.jetbrains.kotlin.core.builder.KotlinPsiManager
-import org.eclipse.core.resources.IResourceDelta
import java.util.LinkedList
import org.eclipse.core.runtime.jobs.Job
import org.eclipse.core.runtime.IProgressMonitor
@@ -32,8 +29,9 @@ import org.eclipse.jdt.core.JavaCore
import java.util.Collections
import org.eclipse.core.runtime.Status
import org.eclipse.core.resources.ResourcesPlugin
+import org.jetbrains.kotlin.core.preferences.KotlinCodeStyleProperties
-public class KotlinNature: IProjectNature {
+class KotlinNature: IProjectNature {
companion object {
val KOTLIN_NATURE: String = "org.jetbrains.kotlin.core.kotlinNature"
@JvmField val KOTLIN_BUILDER: String = "org.jetbrains.kotlin.ui.kotlinBuilder"
@@ -47,64 +45,70 @@ public class KotlinNature: IProjectNature {
fun hasKotlinBuilder(project: IProject) : Boolean {
if (!project.isAccessible) return false
- return project.getDescription().getBuildSpec().any {
- KOTLIN_BUILDER == it.getBuilderName()
+ return project.description.buildSpec.any {
+ KOTLIN_BUILDER == it.builderName
}
}
@JvmStatic
fun addNature(project:IProject) {
if (!hasKotlinNature(project)) {
- val description = project.getDescription()
-
- val newNatureIds = description.getNatureIds().toMutableList()
- newNatureIds.add(KotlinNature.KOTLIN_NATURE)
-
- description.setNatureIds(newNatureIds.toTypedArray())
+ val description = project.description
+ description.natureIds += KOTLIN_NATURE
project.setDescription(description, null)
}
}
}
-
- public var eclipseProject: IProject by Delegates.notNull()
-
- override public fun configure() {
+
+ var eclipseProject: IProject by Delegates.notNull()
+
+ override fun configure() {
addKotlinBuilder(eclipseProject)
+ setPreferredCodeStyle(eclipseProject)
}
-
- override public fun deconfigure() {
+
+ override fun deconfigure() {
removeKotlinBuilder(eclipseProject)
KotlinPsiManager.removeProjectFromManager(eclipseProject)
KotlinAnalysisFileCache.resetCache()
KotlinAnalysisProjectCache.resetCache(eclipseProject)
}
-
- override public fun setProject(project: IProject) {
+
+ override fun setProject(project: IProject) {
eclipseProject = project
}
-
- override public fun getProject(): IProject = eclipseProject
+
+ override fun getProject(): IProject = eclipseProject
private fun addKotlinBuilder(project: IProject) {
if (!hasKotlinBuilder(project)) {
- val description = project.getDescription()
+ val description = project.description
- val kotlinBuilderCommand = description.newCommand().apply { setBuilderName(KOTLIN_BUILDER) }
+ val kotlinBuilderCommand = description.newCommand().apply { builderName = KOTLIN_BUILDER }
- val newBuildCommands = description.getBuildSpec().toCollection(LinkedList())
+ val newBuildCommands = description.buildSpec.toCollection(LinkedList())
newBuildCommands.addFirst(kotlinBuilderCommand)
-
- description.setBuildSpec(newBuildCommands.toTypedArray())
+
+ description.buildSpec = newBuildCommands.toTypedArray()
project.setDescription(description, null)
}
}
+
+ private fun setPreferredCodeStyle(eclipseProject: IProject) {
+ KotlinCodeStyleProperties(ProjectScope(eclipseProject)).apply {
+ codeStyleId = "KOTLIN_OFFICIAL"
+ globalsOverridden = true
+ saveChanges()
+ }
+
+ }
private fun removeKotlinBuilder(project: IProject) {
if (hasKotlinBuilder(project)) {
- val description = project.getDescription()
- val newBuildCommands = description.getBuildSpec().filter { it.getBuilderName() != KotlinNature.KOTLIN_BUILDER }
-
- description.setBuildSpec(newBuildCommands.toTypedArray())
+ val description = project.description
+ val newBuildCommands = description.buildSpec.filter { it.builderName != KotlinNature.KOTLIN_BUILDER }
+
+ description.buildSpec = newBuildCommands.toTypedArray()
project.setDescription(description, null)
}
}
@@ -114,23 +118,23 @@ public class KotlinNature: IProjectNature {
fun setKotlinBuilderBeforeJavaBuilder(project: IProject) {
val job = object : Job("Swap Kotlin builder with Java Builder") {
override fun run(monitor: IProgressMonitor?): IStatus? {
- val description = project.getDescription()
+ val description = project.description
- val builders = description.getBuildSpec().toCollection(LinkedList())
- val kotlinBuilderIndex = builders.indexOfFirst { it.getBuilderName() == KotlinNature.KOTLIN_BUILDER }
- val javaBuilderIndex = builders.indexOfFirst { it.getBuilderName() == JavaCore.BUILDER_ID }
+ val builders = description.buildSpec.toCollection(LinkedList())
+ val kotlinBuilderIndex = builders.indexOfFirst { it.builderName == KotlinNature.KOTLIN_BUILDER }
+ val javaBuilderIndex = builders.indexOfFirst { it.builderName == JavaCore.BUILDER_ID }
if (kotlinBuilderIndex >= 0 && javaBuilderIndex >= 0 && javaBuilderIndex < kotlinBuilderIndex) {
Collections.swap(builders, kotlinBuilderIndex, javaBuilderIndex)
-
- description.setBuildSpec(builders.toTypedArray())
+
+ description.buildSpec = builders.toTypedArray()
project.setDescription(description, monitor)
}
return Status.OK_STATUS
}
}
-
- job.setRule(ResourcesPlugin.getWorkspace().getRoot())
+
+ job.rule = ResourcesPlugin.getWorkspace().root
job.schedule()
}
\ No newline at end of file
diff --git a/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/model/kotlinModelUtils.kt b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/model/kotlinModelUtils.kt
index 44dacd5b0..d917e86b0 100644
--- a/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/model/kotlinModelUtils.kt
+++ b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/model/kotlinModelUtils.kt
@@ -73,13 +73,14 @@ fun isConfigurationMissing(project: IProject): Boolean {
}
}
-fun runJob(name: String, priority: Int = Job.LONG, action: (IProgressMonitor) -> IStatus) {
- runJob(name, priority, null, action, {})
-}
+fun runJob(name: String, priority: Int = Job.LONG, delay: Long = 0, action: (IProgressMonitor) -> IStatus) =
+ runJob(name, priority, delay, null, action, {})
+
fun runJob(
name: String,
priority: Int = Job.LONG,
+ delay: Long = 0,
jobFamily: Any? = null,
action: (IProgressMonitor) -> IStatus,
postTask: (IJobChangeEvent) -> Unit
@@ -102,7 +103,7 @@ fun runJob(
}
})
- job.schedule()
+ job.schedule(delay)
return job
}
\ No newline at end of file
diff --git a/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/preferences/KotlinCodeStyleProperties.kt b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/preferences/KotlinCodeStyleProperties.kt
new file mode 100644
index 000000000..6091c099d
--- /dev/null
+++ b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/preferences/KotlinCodeStyleProperties.kt
@@ -0,0 +1,23 @@
+package org.jetbrains.kotlin.core.preferences
+
+import org.eclipse.core.resources.ProjectScope
+import org.eclipse.core.runtime.preferences.IScopeContext
+import org.eclipse.core.runtime.preferences.InstanceScope
+import org.jetbrains.kotlin.core.Activator
+import org.jetbrains.kotlin.core.builder.KotlinPsiManager
+import org.jetbrains.kotlin.core.formatting.KotlinCodeStyleManager
+import org.jetbrains.kotlin.idea.formatter.KotlinPredefinedCodeStyle
+import org.jetbrains.kotlin.idea.formatter.KotlinStyleGuideCodeStyle
+import org.jetbrains.kotlin.psi.KtFile
+
+class KotlinCodeStyleProperties(scope: IScopeContext = InstanceScope.INSTANCE)
+ : Preferences(scope, "${Activator.PLUGIN_ID}/codeStyle"
+) {
+ var globalsOverridden by BooleanPreference()
+
+ var codeStyleId by StringPreference()
+
+ companion object {
+ val workspaceInstance by lazy { KotlinCodeStyleProperties() }
+ }
+}
\ No newline at end of file
diff --git a/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/preferences/KotlinProperties.kt b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/preferences/KotlinProperties.kt
index 058c6bf14..ce19be98a 100644
--- a/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/preferences/KotlinProperties.kt
+++ b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/preferences/KotlinProperties.kt
@@ -1,13 +1,11 @@
package org.jetbrains.kotlin.core.preferences
-import org.jetbrains.kotlin.core.Activator
-import org.jetbrains.kotlin.config.JvmTarget
-import org.eclipse.core.runtime.preferences.IScopeContext
import org.eclipse.core.runtime.preferences.DefaultScope
-import org.osgi.service.prefs.Preferences as InternalPreferences
+import org.eclipse.core.runtime.preferences.IScopeContext
import org.eclipse.core.runtime.preferences.InstanceScope
-import org.jetbrains.kotlin.config.ApiVersion
-import org.jetbrains.kotlin.config.LanguageVersion
+import org.jetbrains.kotlin.config.*
+import org.jetbrains.kotlin.core.Activator
+import org.osgi.service.prefs.Preferences as InternalPreferences
class KotlinProperties(scope: IScopeContext = InstanceScope.INSTANCE) : Preferences(scope, Activator.PLUGIN_ID) {
var globalsOverridden by BooleanPreference()
@@ -57,3 +55,6 @@ class CompilerPlugin(scope: IScopeContext, path: String) : Preferences(scope, pa
var active by BooleanPreference()
}
+
+val KotlinProperties.languageVersionSettings: LanguageVersionSettings
+ get() = LanguageVersionSettingsImpl(languageVersion, apiVersion)
\ No newline at end of file
diff --git a/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/resolve/EclipseAnalyzerFacadeForJVM.kt b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/resolve/EclipseAnalyzerFacadeForJVM.kt
index 09187148e..2b4646750 100644
--- a/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/resolve/EclipseAnalyzerFacadeForJVM.kt
+++ b/kotlin-eclipse-core/src/org/jetbrains/kotlin/core/resolve/EclipseAnalyzerFacadeForJVM.kt
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM
import org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.SourceOrBinaryModuleClassResolver
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
-import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
import org.jetbrains.kotlin.container.ComponentProvider
import org.jetbrains.kotlin.context.ContextForNewModule
import org.jetbrains.kotlin.context.MutableModuleContext
@@ -34,6 +33,7 @@ import org.jetbrains.kotlin.context.ProjectContext
import org.jetbrains.kotlin.core.log.KotlinLogger
import org.jetbrains.kotlin.core.model.KotlinEnvironment
import org.jetbrains.kotlin.core.model.KotlinScriptEnvironment
+import org.jetbrains.kotlin.core.preferences.languageVersionSettings
import org.jetbrains.kotlin.core.utils.ProjectUtils
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
@@ -51,8 +51,7 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.util.KotlinFrontEndException
-import java.util.ArrayList
-import java.util.LinkedHashSet
+import java.util.*
import org.jetbrains.kotlin.frontend.java.di.createContainerForTopDownAnalyzerForJvm as createContainerForScript
data class AnalysisResultWithProvider(val analysisResult: AnalysisResult, val componentProvider: ComponentProvider?) {
@@ -61,8 +60,8 @@ data class AnalysisResultWithProvider(val analysisResult: AnalysisResult, val co
}
}
-public object EclipseAnalyzerFacadeForJVM {
- public fun analyzeFilesWithJavaIntegration(
+object EclipseAnalyzerFacadeForJVM {
+ fun analyzeFilesWithJavaIntegration(
environment: KotlinEnvironment,
filesToAnalyze: Collection): AnalysisResultWithProvider {
val filesSet = filesToAnalyze.toSet()
@@ -90,9 +89,7 @@ public object EclipseAnalyzerFacadeForJVM {
val sourceScope = TopDownAnalyzerFacadeForJVM.newModuleSearchScope(project, filesToAnalyze)
val moduleClassResolver = SourceOrBinaryModuleClassResolver(sourceScope)
- val languageVersionSettings = LanguageVersionSettingsImpl(
- environment.compilerProperties.languageVersion,
- environment.compilerProperties.apiVersion)
+ val languageVersionSettings = environment.compilerProperties.languageVersionSettings
val optionalBuiltInsModule = JvmBuiltIns(storageManager).apply { initialize(module, true) }.builtInsModule
@@ -167,11 +164,11 @@ public object EclipseAnalyzerFacadeForJVM {
}
return AnalysisResultWithProvider(
- AnalysisResult.success(trace.getBindingContext(), module),
+ AnalysisResult.success(trace.bindingContext, module),
container)
}
-
- public fun analyzeScript(
+
+ fun analyzeScript(
environment: KotlinScriptEnvironment,
scriptFile: KtFile): AnalysisResultWithProvider {
@@ -201,11 +198,11 @@ public object EclipseAnalyzerFacadeForJVM {
}
return AnalysisResultWithProvider(
- AnalysisResult.success(trace.getBindingContext(), container.get()),
+ AnalysisResult.success(trace.bindingContext, container.get()),
container)
}
-
- private fun getPath(jetFile: KtFile): String? = jetFile.getVirtualFile()?.getPath()
+
+ private fun getPath(jetFile: KtFile): String? = jetFile.virtualFile?.path
private fun createModuleContext(
project: Project,
diff --git a/kotlin-eclipse-feature/feature.xml b/kotlin-eclipse-feature/feature.xml
index c24381f9c..d5fbcd4d9 100644
--- a/kotlin-eclipse-feature/feature.xml
+++ b/kotlin-eclipse-feature/feature.xml
@@ -2,7 +2,7 @@
diff --git a/kotlin-eclipse-feature/pom.xml b/kotlin-eclipse-feature/pom.xml
index 311b86bb5..115079480 100644
--- a/kotlin-eclipse-feature/pom.xml
+++ b/kotlin-eclipse-feature/pom.xml
@@ -8,12 +8,12 @@
../pom.xml
kotlin.eclipse
kotlin.eclipse.plugin
- 0.8.7-SNAPSHOT
+ 0.8.8-SNAPSHOT
org.jetbrains.kotlin.feature
kotlin.eclipse
- 0.8.7-SNAPSHOT
+ 0.8.8-SNAPSHOT
eclipse-feature
\ No newline at end of file
diff --git a/kotlin-eclipse-maven/META-INF/MANIFEST.MF b/kotlin-eclipse-maven/META-INF/MANIFEST.MF
index e8b582ef1..c92df7f7b 100644
--- a/kotlin-eclipse-maven/META-INF/MANIFEST.MF
+++ b/kotlin-eclipse-maven/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: kotlin-eclipse-maven
Bundle-SymbolicName: org.jetbrains.kotlin.maven;singleton:=true
-Bundle-Version: 0.8.7.qualifier
+Bundle-Version: 0.8.8.qualifier
Bundle-Activator: org.jetbrains.kotlin.maven.Activator
Bundle-Vendor: JetBrains
Require-Bundle: org.eclipse.core.runtime,
diff --git a/kotlin-eclipse-maven/pom.xml b/kotlin-eclipse-maven/pom.xml
index f21fe3af3..a9f70e760 100644
--- a/kotlin-eclipse-maven/pom.xml
+++ b/kotlin-eclipse-maven/pom.xml
@@ -8,7 +8,7 @@
../pom.xml
kotlin.eclipse
kotlin.eclipse.plugin
- 0.8.7-SNAPSHOT
+ 0.8.8-SNAPSHOT
org.jetbrains.kotlin.maven
diff --git a/kotlin-eclipse-p2updatesite/category.xml b/kotlin-eclipse-p2updatesite/category.xml
index c0e979315..bdc959099 100644
--- a/kotlin-eclipse-p2updatesite/category.xml
+++ b/kotlin-eclipse-p2updatesite/category.xml
@@ -1,6 +1,6 @@
-
+
diff --git a/kotlin-eclipse-p2updatesite/pom.xml b/kotlin-eclipse-p2updatesite/pom.xml
index d6bf15a87..a9c067320 100644
--- a/kotlin-eclipse-p2updatesite/pom.xml
+++ b/kotlin-eclipse-p2updatesite/pom.xml
@@ -8,12 +8,12 @@
../pom.xml
kotlin.eclipse
kotlin.eclipse.plugin
- 0.8.7-SNAPSHOT
+ 0.8.8-SNAPSHOT
org.jetbrains.kotlin.p2updatesite
kotlin.eclipse
- 0.8.7-SNAPSHOT
+ 0.8.8-SNAPSHOT
eclipse-repository
\ No newline at end of file
diff --git a/kotlin-eclipse-policy/feature.xml b/kotlin-eclipse-policy/feature.xml
index 1c921a581..083ae685f 100644
--- a/kotlin-eclipse-policy/feature.xml
+++ b/kotlin-eclipse-policy/feature.xml
@@ -2,7 +2,7 @@
diff --git a/kotlin-eclipse-policy/pom.xml b/kotlin-eclipse-policy/pom.xml
index fbab69e55..7e8d73ab1 100644
--- a/kotlin-eclipse-policy/pom.xml
+++ b/kotlin-eclipse-policy/pom.xml
@@ -8,12 +8,12 @@
../pom.xml
kotlin.eclipse
kotlin.eclipse.plugin
- 0.8.7-SNAPSHOT
+ 0.8.8-SNAPSHOT
org.jetbrains.kotlin.policy
kotlin.eclipse
- 0.8.7-SNAPSHOT
+ 0.8.8-SNAPSHOT
eclipse-feature
\ No newline at end of file
diff --git a/kotlin-eclipse-test-framework/.classpath b/kotlin-eclipse-test-framework/.classpath
index 1fa3e6803..f98be78ce 100644
--- a/kotlin-eclipse-test-framework/.classpath
+++ b/kotlin-eclipse-test-framework/.classpath
@@ -3,5 +3,6 @@
+
diff --git a/kotlin-eclipse-test-framework/.project b/kotlin-eclipse-test-framework/.project
index ff755ca20..f507c9f5e 100644
--- a/kotlin-eclipse-test-framework/.project
+++ b/kotlin-eclipse-test-framework/.project
@@ -5,6 +5,11 @@
+
+ org.jetbrains.kotlin.ui.kotlinBuilder
+
+
+
org.eclipse.jdt.core.javabuilder
@@ -24,5 +29,13 @@
org.eclipse.pde.PluginNature
org.eclipse.jdt.core.javanature
+ org.jetbrains.kotlin.core.kotlinNature
+
+
+ kotlin_bin
+ 2
+ org.jetbrains.kotlin.core.filesystem:/kotlin-eclipse-test-framework/kotlin_bin
+
+
diff --git a/kotlin-eclipse-test-framework/META-INF/MANIFEST.MF b/kotlin-eclipse-test-framework/META-INF/MANIFEST.MF
index 583b3a360..1c0e0efb0 100644
--- a/kotlin-eclipse-test-framework/META-INF/MANIFEST.MF
+++ b/kotlin-eclipse-test-framework/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: kotlin-eclipse-testframework
Bundle-SymbolicName: org.jetbrains.kotlin.testframework
-Bundle-Version: 0.8.7.qualifier
+Bundle-Version: 0.8.8.qualifier
Bundle-Activator: org.jetbrains.kotlin.testframework.Activator
Require-Bundle: org.jetbrains.kotlin.core,
org.jetbrains.kotlin.ui,
diff --git a/kotlin-eclipse-test-framework/pom.xml b/kotlin-eclipse-test-framework/pom.xml
index dd6a595c3..b3b9c33af 100644
--- a/kotlin-eclipse-test-framework/pom.xml
+++ b/kotlin-eclipse-test-framework/pom.xml
@@ -8,9 +8,31 @@
../pom.xml
kotlin.eclipse
kotlin.eclipse.plugin
- 0.8.7-SNAPSHOT
+ 0.8.8-SNAPSHOT
org.jetbrains.kotlin.testframework
eclipse-plugin
+
+
+ src
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ ${kotlin.version}
+
+
+
+ compile
+ process-sources
+
+ compile
+
+
+
+
+
+
\ No newline at end of file
diff --git a/kotlin-eclipse-test-framework/src/org/jetbrains/kotlin/testframework/utils/CodeStyleConfigurator.kt b/kotlin-eclipse-test-framework/src/org/jetbrains/kotlin/testframework/utils/CodeStyleConfigurator.kt
new file mode 100644
index 000000000..133aa1c64
--- /dev/null
+++ b/kotlin-eclipse-test-framework/src/org/jetbrains/kotlin/testframework/utils/CodeStyleConfigurator.kt
@@ -0,0 +1,67 @@
+package org.jetbrains.kotlin.testframework.utils
+
+import org.eclipse.core.resources.IProject
+import org.eclipse.core.resources.ProjectScope
+import org.jetbrains.kotlin.core.formatting.KotlinCodeStyleManager
+import org.jetbrains.kotlin.core.preferences.KotlinCodeStyleProperties
+import org.jetbrains.kotlin.idea.KotlinLanguage
+import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings
+import java.util.*
+import kotlin.reflect.KFunction
+import kotlin.reflect.KMutableProperty
+
+object CodeStyleConfigurator {
+ fun configure(project: IProject, fileText: String) {
+ val generatedId = UUID.randomUUID().toString()
+
+ KotlinCodeStyleProperties(ProjectScope(project)).apply {
+ codeStyleId = generatedId
+ globalsOverridden = true
+ saveChanges()
+ }
+
+ KotlinCodeStyleManager.getOrCreate(generatedId) {
+ val kotlinSettings = getCustomSettings(KotlinCodeStyleSettings::class.java)
+ val commonSettings = getCommonSettings(KotlinLanguage.INSTANCE)
+
+ fun setDynamic(prop: String, value: Any) {
+ kotlinSettings.setDynamic(prop, value) or commonSettings.setDynamic(prop, value)
+ }
+
+ InTextDirectivesUtils.findListWithPrefixes(fileText, "SET_TRUE:")
+ .forEach { setDynamic(it, true) }
+
+ InTextDirectivesUtils.findListWithPrefixes(fileText, "SET_FALSE:")
+ .forEach { setDynamic(it, false) }
+
+ InTextDirectivesUtils.findListWithPrefixes(fileText, "SET_INT:")
+ .map { it.split("=", limit = 2) }
+ .forEach { (prop, value) -> setDynamic(prop, value.trim().toInt()) }
+
+ InTextDirectivesUtils.findStringWithPrefixes(fileText, "RIGHT_MARGIN: ")
+ ?.also { commonSettings.RIGHT_MARGIN = it.trim().toInt() }
+ }
+ }
+
+ fun deconfigure(project: IProject) {
+ KotlinCodeStyleProperties(ProjectScope(project)).apply {
+ globalsOverridden = false
+ codeStyleId?.also { KotlinCodeStyleManager.invalidate(it) }
+ saveChanges()
+ }
+ }
+
+ private fun Any.setDynamic(name: String, value: Any): Boolean =
+ this::class.members.singleOrNull { it.name in setOf(name) }
+ ?.let {
+ when (it) {
+ is KMutableProperty -> it.setter
+ is KFunction -> it
+ else -> null
+ }
+ }
+ ?.call(this, value)
+ ?.let { true }
+ ?: false
+
+}
\ No newline at end of file
diff --git a/kotlin-eclipse-test-framework/src/org/jetbrains/kotlin/testframework/utils/TestJavaProject.java b/kotlin-eclipse-test-framework/src/org/jetbrains/kotlin/testframework/utils/TestJavaProject.java
index 95b13ec89..c7677f48f 100644
--- a/kotlin-eclipse-test-framework/src/org/jetbrains/kotlin/testframework/utils/TestJavaProject.java
+++ b/kotlin-eclipse-test-framework/src/org/jetbrains/kotlin/testframework/utils/TestJavaProject.java
@@ -213,6 +213,10 @@ public IJavaProject getJavaProject() {
return javaProject;
}
+ public IProject getProject() {
+ return project;
+ }
+
public void addKotlinRuntime() throws CoreException {
ProjectUtils.addKotlinRuntime(javaProject);
}
diff --git a/kotlin-eclipse-ui-test/META-INF/MANIFEST.MF b/kotlin-eclipse-ui-test/META-INF/MANIFEST.MF
index 8cff744bd..a8865d599 100644
--- a/kotlin-eclipse-ui-test/META-INF/MANIFEST.MF
+++ b/kotlin-eclipse-ui-test/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: kotlin-eclipse-ui-test
Bundle-SymbolicName: org.jetbrains.kotlin.ui.tests;singleton:=true
-Bundle-Version: 0.8.7.qualifier
+Bundle-Version: 0.8.8.qualifier
Bundle-Vendor: JetBrains
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ClassPath: .,
diff --git a/kotlin-eclipse-ui-test/pom.xml b/kotlin-eclipse-ui-test/pom.xml
index dee1d7e2c..fc207d858 100644
--- a/kotlin-eclipse-ui-test/pom.xml
+++ b/kotlin-eclipse-ui-test/pom.xml
@@ -8,7 +8,7 @@
../pom.xml
kotlin.eclipse
kotlin.eclipse.plugin
- 0.8.7-SNAPSHOT
+ 0.8.8-SNAPSHOT
org.jetbrains.kotlin.ui.tests
diff --git a/kotlin-eclipse-ui-test/src/org/jetbrains/kotlin/core/tests/launch/KotlinLaunchTestCase.kt b/kotlin-eclipse-ui-test/src/org/jetbrains/kotlin/core/tests/launch/KotlinLaunchTestCase.kt
index 2157faca0..c17bfea25 100644
--- a/kotlin-eclipse-ui-test/src/org/jetbrains/kotlin/core/tests/launch/KotlinLaunchTestCase.kt
+++ b/kotlin-eclipse-ui-test/src/org/jetbrains/kotlin/core/tests/launch/KotlinLaunchTestCase.kt
@@ -23,6 +23,7 @@ import org.eclipse.debug.core.ILaunchListener
import org.eclipse.debug.internal.ui.DebugUIPlugin
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants
import org.eclipse.jface.dialogs.MessageDialogWithToggle
+import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
import org.jetbrains.kotlin.testframework.editor.KotlinEditorTestCase
import org.jetbrains.kotlin.testframework.utils.KotlinTestUtils
import org.jetbrains.kotlin.ui.launch.KotlinLaunchShortcut
@@ -32,26 +33,26 @@ import org.junit.Assert
import org.junit.Before
abstract class KotlinLaunchTestCase : KotlinEditorTestCase() {
- val compileWithErrorPreference = DebugUIPlugin.getDefault().getPreferenceStore()
+ val compileWithErrorPreference = DebugUIPlugin.getDefault().preferenceStore
.getString(IInternalDebugUIConstants.PREF_CONTINUE_WITH_COMPILE_ERROR)
@Before
fun before() {
- DebugUIPlugin.getDefault().getPreferenceStore().setValue(
+ DebugUIPlugin.getDefault().preferenceStore.setValue(
IInternalDebugUIConstants.PREF_CONTINUE_WITH_COMPILE_ERROR, MessageDialogWithToggle.ALWAYS)
}
@After
fun after() {
- DebugUIPlugin.getDefault().getPreferenceStore().setValue(
+ DebugUIPlugin.getDefault().preferenceStore.setValue(
IInternalDebugUIConstants.PREF_CONTINUE_WITH_COMPILE_ERROR, compileWithErrorPreference)
}
fun doTest(input: String, projectName: String, packageName: String, additionalSrcFolderName: String?) {
testEditor = configureEditor("Test.kt", input, projectName, packageName)
- testEditor.getTestJavaProject().addKotlinRuntime()
+ testEditor.testJavaProject.addKotlinRuntime()
if (additionalSrcFolderName != null) {
- testEditor.getTestJavaProject().createSourceFolder(additionalSrcFolderName)
+ testEditor.testJavaProject.createSourceFolder(additionalSrcFolderName)
}
KotlinTestUtils.joinBuildThread()
@@ -76,13 +77,13 @@ abstract class KotlinLaunchTestCase : KotlinEditorTestCase() {
override fun launchAdded(launch: ILaunch) {
}
}
-
- DebugPlugin.getDefault().getLaunchManager().addLaunchListener(launchListener)
+
+ DebugPlugin.getDefault().launchManager.addLaunchListener(launchListener)
var launch: ILaunch? = null
try {
- val entryPoint = getEntryPoint(getEditor().parsedFile!!)
- val launchConfiguration = KotlinLaunchShortcut.createConfiguration(entryPoint!!, testEditor.getEclipseProject())
+ val entryPoint = getEntryPoint(editor.parsedFile!!, LanguageVersionSettingsImpl.DEFAULT)
+ val launchConfiguration = KotlinLaunchShortcut.createConfiguration(entryPoint!!, testEditor.eclipseProject)
launch = DebugUIPlugin.buildAndLaunch(launchConfiguration, "run", NullProgressMonitor())
synchronized (launch) {
@@ -95,7 +96,7 @@ abstract class KotlinLaunchTestCase : KotlinEditorTestCase() {
if (!launch.isTerminated) stdout.append("Launch not terminated")
} finally {
launch?.terminate()
- DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(launchListener)
+ DebugPlugin.getDefault().launchManager.removeLaunchListener(launchListener)
}
return stdout.toString()
diff --git a/kotlin-eclipse-ui-test/src/org/jetbrains/kotlin/ui/tests/editors/KotlinAutoIndentTestCase.kt b/kotlin-eclipse-ui-test/src/org/jetbrains/kotlin/ui/tests/editors/KotlinAutoIndentTestCase.kt
index 150ab4c0f..cd7ba9683 100644
--- a/kotlin-eclipse-ui-test/src/org/jetbrains/kotlin/ui/tests/editors/KotlinAutoIndentTestCase.kt
+++ b/kotlin-eclipse-ui-test/src/org/jetbrains/kotlin/ui/tests/editors/KotlinAutoIndentTestCase.kt
@@ -7,8 +7,8 @@ import org.eclipse.ui.editors.text.EditorsUI
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants
import org.jetbrains.kotlin.testframework.utils.EditorTestUtils
import org.jetbrains.kotlin.ui.tests.editors.formatter.KotlinFormatActionTestCase
-import org.jetbrains.kotlin.ui.formatter.settings
import com.intellij.psi.codeStyle.CodeStyleSettings
+import org.jetbrains.kotlin.testframework.utils.CodeStyleConfigurator
import org.junit.After
abstract class KotlinAutoIndentTestCase : KotlinEditorWithAfterFileTestCase() {
@@ -19,11 +19,11 @@ abstract class KotlinAutoIndentTestCase : KotlinEditorWithAfterFileTestCase() {
@After
fun setDefaultSettings() {
- settings = CodeStyleSettings()
+ CodeStyleConfigurator.deconfigure(testProject.project)
}
override fun performTest(fileText: String, expectedFileText: String) {
- KotlinFormatActionTestCase.configureSettings(fileText)
+ CodeStyleConfigurator.configure(testProject.project, fileText)
EditorsUI.getPreferenceStore().setValue(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS, true)
EditorsUI.getPreferenceStore().setValue(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH, 4)
diff --git a/kotlin-eclipse-ui-test/src/org/jetbrains/kotlin/ui/tests/editors/formatter/KotlinFormatActionTestCase.java b/kotlin-eclipse-ui-test/src/org/jetbrains/kotlin/ui/tests/editors/formatter/KotlinFormatActionTestCase.java
index e4545c0fc..cd544c701 100644
--- a/kotlin-eclipse-ui-test/src/org/jetbrains/kotlin/ui/tests/editors/formatter/KotlinFormatActionTestCase.java
+++ b/kotlin-eclipse-ui-test/src/org/jetbrains/kotlin/ui/tests/editors/formatter/KotlinFormatActionTestCase.java
@@ -16,34 +16,18 @@
*******************************************************************************/
package org.jetbrains.kotlin.ui.tests.editors.formatter;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextUtilities;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
-import org.jetbrains.kotlin.idea.KotlinLanguage;
-import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings;
import org.jetbrains.kotlin.testframework.editor.KotlinEditorWithAfterFileTestCase;
+import org.jetbrains.kotlin.testframework.utils.CodeStyleConfigurator;
import org.jetbrains.kotlin.testframework.utils.EditorTestUtils;
-import org.jetbrains.kotlin.testframework.utils.InTextDirectivesUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
-import com.intellij.psi.codeStyle.CodeStyleSettings;
-import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
-
-import kotlin.Pair;
-import kotlin.collections.CollectionsKt;
-import kotlin.jvm.functions.Function1;
-import org.jetbrains.kotlin.ui.formatter.KotlinFormatterKt;
-
public abstract class KotlinFormatActionTestCase extends KotlinEditorWithAfterFileTestCase {
@Before
public void before() {
@@ -52,7 +36,7 @@ public void before() {
@After
public void setDefaultSettings() {
- KotlinFormatterKt.setSettings(new CodeStyleSettings());
+ CodeStyleConfigurator.INSTANCE.deconfigure(getTestProject().getProject());
}
@Override
@@ -61,8 +45,8 @@ protected void performTest(String fileText, String content) {
EditorsUI.getPreferenceStore().setValue(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS, true);
EditorsUI.getPreferenceStore().setValue(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH, 4);
-
- configureSettings(fileText);
+
+ CodeStyleConfigurator.INSTANCE.configure(getTestProject().getProject(), fileText);
getTestEditor().runFormatAction();
@@ -79,94 +63,4 @@ private void assertLineDelimiters(String expectedLineDelimiter, IDocument docume
throw new RuntimeException(e);
}
}
-
- public static void configureSettings(String fileText) {
- List settingsToTrue = InTextDirectivesUtils.findListWithPrefixes(fileText, "SET_TRUE:");
- List settingsToFalse = InTextDirectivesUtils.findListWithPrefixes(fileText, "SET_FALSE:");
- List settingsToIntValue = CollectionsKt.map(InTextDirectivesUtils.findListWithPrefixes(fileText, "SET_INT:"), new Function1() {
- @Override
- public Pair invoke(String s) {
- String[] tokens = s.split("=");
- return new Pair(tokens[0].trim(), Integer.valueOf(tokens[1].trim()));
- }
- });
-
- KotlinCodeStyleSettings kotlinSettings = KotlinFormatterKt.getSettings().getCustomSettings(KotlinCodeStyleSettings.class);
- CommonCodeStyleSettings commonSettings = KotlinFormatterKt.getSettings().getCommonSettings(KotlinLanguage.INSTANCE);
-
- List