Convert to Kotlin

This commit is contained in:
Nikolay Krasko
2014-10-07 23:36:29 +04:00
parent b172709008
commit a29773597e
2 changed files with 56 additions and 54 deletions
@@ -1,54 +0,0 @@
/*
* Copyright 2010-2014 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.util;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.configuration.JetModuleTypeManager;
public class ProjectRootsUtil {
private static boolean isInSource(@NotNull PsiElement element) {
return isInSource(element, true);
}
public static boolean isInSource(@NotNull final PsiElement element, final boolean includeLibrarySources) {
return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
PsiFile containingFile = element.getContainingFile();
if (containingFile == null) {
return false;
}
VirtualFile virtualFile = containingFile.getVirtualFile();
if (virtualFile == null) {
return false;
}
ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(element.getProject());
return includeLibrarySources ? index.isInSource(virtualFile) : index.isInSourceContent(virtualFile);
}
});
}
public static boolean isInSourceWithGradleCheck(@NotNull PsiElement element) {
return isInSource(element) && !JetModuleTypeManager.getInstance().isKtFileInGradleProjectInWrongFolder(element);
}
}
@@ -0,0 +1,56 @@
/*
* Copyright 2010-2014 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.util
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.roots.ProjectFileIndex
import com.intellij.openapi.util.Computable
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import org.jetbrains.jet.plugin.configuration.JetModuleTypeManager
import kotlin.platform.platformStatic
import org.jetbrains.jet.plugin.util.application.runReadAction
public object ProjectRootsUtil {
platformStatic
private fun isInSource(element: PsiElement): Boolean {
return isInSource(element, true)
}
platformStatic
public fun isInSource(element: PsiElement, includeLibrarySources: Boolean): Boolean {
return runReadAction { (): Boolean ->
val containingFile = element.getContainingFile()
if (containingFile == null) return@runReadAction false
val virtualFile = containingFile.getVirtualFile()
if (virtualFile == null) return@runReadAction false
val index = ProjectFileIndex.SERVICE.getInstance(element.getProject())
return@runReadAction if (includeLibrarySources)
index.isInSource(virtualFile)
else
index.isInSourceContent(virtualFile)
}!!
}
platformStatic
public fun isInSourceWithGradleCheck(element: PsiElement): Boolean {
return isInSource(element) && !JetModuleTypeManager.getInstance()!!.isKtFileInGradleProjectInWrongFolder(element)
}
}