Refactoring: rename methods

This commit is contained in:
Nikolay Krasko
2014-10-08 18:15:00 +04:00
parent 6c9538b040
commit 3ea2d420b2
15 changed files with 22 additions and 18 deletions
@@ -41,7 +41,7 @@ public class DebugInfoAnnotator implements Annotator {
@Override @Override
public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) { public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) {
if (!isDebugInfoEnabled() || !ProjectRootsUtil.isInSource(element)) { if (!isDebugInfoEnabled() || !ProjectRootsUtil.isInProjectOrLibSource(element)) {
return; return;
} }
@@ -39,7 +39,7 @@ public class DuplicateJvmSignatureAnnotator implements Annotator {
@Override @Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) { public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
if (!(element instanceof JetFile) && !(element instanceof JetDeclaration)) return; if (!(element instanceof JetFile) && !(element instanceof JetDeclaration)) return;
if (!ProjectRootsUtil.isInSource(element, false)) return; if (!ProjectRootsUtil.isInProjectSource(element)) return;
PsiFile file = element.getContainingFile(); PsiFile file = element.getContainingFile();
if (!(file instanceof JetFile) || TargetPlatformDetector.getPlatform((JetFile) file) != TargetPlatform.JVM) return; if (!(file instanceof JetFile) || TargetPlatformDetector.getPlatform((JetFile) file) != TargetPlatform.JVM) return;
@@ -93,7 +93,7 @@ public class JetPsiChecker implements Annotator, HighlightRangeExtension {
@Override @Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) { public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
if (!(ProjectRootsUtil.isInSource(element) || element.getContainingFile() instanceof JetCodeFragment)) return; if (!(ProjectRootsUtil.isInProjectOrLibSource(element) || element.getContainingFile() instanceof JetCodeFragment)) return;
for (HighlightingVisitor visitor : getBeforeAnalysisVisitors(holder)) { for (HighlightingVisitor visitor : getBeforeAnalysisVisitors(holder)) {
element.accept(visitor); element.accept(visitor);
@@ -116,7 +116,7 @@ public class JetPsiChecker implements Annotator, HighlightRangeExtension {
} }
public static void annotateElement(PsiElement element, AnnotationHolder holder, Diagnostics diagnostics) { public static void annotateElement(PsiElement element, AnnotationHolder holder, Diagnostics diagnostics) {
if (ProjectRootsUtil.isInSource(element, /* includeLibrarySources = */ false) || element.getContainingFile() instanceof JetCodeFragment) { if (ProjectRootsUtil.isInProjectSource(element) || element.getContainingFile() instanceof JetCodeFragment) {
ElementAnnotator elementAnnotator = new ElementAnnotator(element, holder); ElementAnnotator elementAnnotator = new ElementAnnotator(element, holder);
for (Diagnostic diagnostic : diagnostics.forElement(element)) { for (Diagnostic diagnostic : diagnostics.forElement(element)) {
elementAnnotator.registerDiagnosticAnnotations(diagnostic); elementAnnotator.registerDiagnosticAnnotations(diagnostic);
@@ -23,8 +23,7 @@ import org.jetbrains.jet.plugin.util.application.runReadAction
import org.jetbrains.jet.plugin.stubindex.JetSourceFilterScope import org.jetbrains.jet.plugin.stubindex.JetSourceFilterScope
public object ProjectRootsUtil { public object ProjectRootsUtil {
platformStatic private fun isInSource(element: PsiElement, includeLibrarySources: Boolean): Boolean {
public fun isInSource(element: PsiElement, includeLibrarySources: Boolean): Boolean {
return runReadAction { (): Boolean -> return runReadAction { (): Boolean ->
val containingFile = element.getContainingFile() val containingFile = element.getContainingFile()
if (containingFile == null) return@runReadAction false if (containingFile == null) return@runReadAction false
@@ -39,7 +38,12 @@ public object ProjectRootsUtil {
} }
platformStatic platformStatic
public fun isInSource(element: PsiElement): Boolean { public fun isInProjectSource(element: PsiElement): Boolean {
return isInSource(element, false)
}
platformStatic
public fun isInProjectOrLibSource(element: PsiElement): Boolean {
return isInSource(element, true) return isInSource(element, true)
} }
} }
@@ -60,7 +60,7 @@ public class HierarchyUtils {
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file == null) return null; if (file == null) return null;
if (!ProjectRootsUtil.isInSource(file)) return null; if (!ProjectRootsUtil.isInProjectOrLibSource(file)) return null;
return TargetElementUtilBase.findTargetElement(editor, TargetElementUtilBase.getInstance().getAllAccepted()); return TargetElementUtilBase.findTargetElement(editor, TargetElementUtilBase.getInstance().getAllAccepted());
} }
@@ -54,7 +54,7 @@ public class KotlinTypeHierarchyProvider extends JavaTypeHierarchyProvider {
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file == null) return null; if (file == null) return null;
if (!ProjectRootsUtil.isInSource(file)) return null; if (!ProjectRootsUtil.isInProjectOrLibSource(file)) return null;
PsiElement target = TargetElementUtilBase.findTargetElement(editor, TargetElementUtilBase.getInstance().getAllAccepted()); PsiElement target = TargetElementUtilBase.findTargetElement(editor, TargetElementUtilBase.getInstance().getAllAccepted());
@@ -46,7 +46,7 @@ public class KotlinCallHierarchyProvider implements HierarchyProvider {
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file == null) return null; if (file == null) return null;
if (!ProjectRootsUtil.isInSource(file)) return null; if (!ProjectRootsUtil.isInProjectOrLibSource(file)) return null;
return TargetElementUtilBase.findTargetElement(editor, TargetElementUtilBase.getInstance().getAllAccepted()); return TargetElementUtilBase.findTargetElement(editor, TargetElementUtilBase.getInstance().getAllAccepted());
} }
@@ -88,7 +88,7 @@ public class DeclarationHintSupport extends AbstractProjectComponent {
Editor editor = e.getEditor(); Editor editor = e.getEditor();
PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument()); PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument());
if (psiFile == null || psiFile.getLanguage() != JetLanguage.INSTANCE || !ProjectRootsUtil.isInSource(psiFile)) { if (psiFile == null || psiFile.getLanguage() != JetLanguage.INSTANCE || !ProjectRootsUtil.isInProjectOrLibSource(psiFile)) {
return; return;
} }
@@ -151,7 +151,7 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
PsiElement first = KotlinPackage.first(elements); PsiElement first = KotlinPackage.first(elements);
if (DumbService.getInstance(first.getProject()).isDumb() || if (DumbService.getInstance(first.getProject()).isDumb() ||
!ProjectRootsUtil.isInSource(elements.get(0))) { !ProjectRootsUtil.isInProjectOrLibSource(elements.get(0))) {
return; return;
} }
@@ -79,7 +79,7 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
} }
JetFile file = location.getJetFile(); JetFile file = location.getJetFile();
if (file == null || !ProjectRootsUtil.isInSource(file, false)) { if (file == null || !ProjectRootsUtil.isInProjectSource(file)) {
return null; return null;
} }
@@ -174,7 +174,7 @@ public class AutoImportFix(element: JetSimpleNameExpression) : JetHintAction<Jet
val priority = when { val priority = when {
declaration == null -> Priority.OTHER declaration == null -> Priority.OTHER
ModuleUtilCore.findModuleForPsiElement(declaration) == module -> Priority.MODULE ModuleUtilCore.findModuleForPsiElement(declaration) == module -> Priority.MODULE
ProjectRootsUtil.isInSource(declaration, false) -> Priority.PROJECT ProjectRootsUtil.isInProjectSource(declaration) -> Priority.PROJECT
else -> Priority.OTHER else -> Priority.OTHER
} }
@@ -51,7 +51,7 @@ public class JetJUnitConfigurationProducer extends RuntimeConfigurationProducer
protected RunnerAndConfigurationSettings createConfigurationByElement(Location location, ConfigurationContext context) { protected RunnerAndConfigurationSettings createConfigurationByElement(Location location, ConfigurationContext context) {
PsiElement leaf = location.getPsiElement(); PsiElement leaf = location.getPsiElement();
if (!ProjectRootsUtil.isInSource(leaf)) { if (!ProjectRootsUtil.isInProjectOrLibSource(leaf)) {
return null; return null;
} }
@@ -78,7 +78,7 @@ public class JetRunConfigurationProducer extends RuntimeConfigurationProducer im
if (ProjectStructureUtil.isJsKotlinModule(module)) return null; if (ProjectStructureUtil.isJsKotlinModule(module)) return null;
PsiFile psiFile = location.getPsiElement().getContainingFile(); PsiFile psiFile = location.getPsiElement().getContainingFile();
if (!(psiFile instanceof JetFile && ProjectRootsUtil.isInSource(psiFile))) return null; if (!(psiFile instanceof JetFile && ProjectRootsUtil.isInProjectOrLibSource(psiFile))) return null;
JetFile jetFile = (JetFile) psiFile; JetFile jetFile = (JetFile) psiFile;
final ResolveSessionForBodies session = ResolvePackage.getLazyResolveSession(jetFile); final ResolveSessionForBodies session = ResolvePackage.getLazyResolveSession(jetFile);
@@ -52,7 +52,7 @@ public class JetTestNgConfigurationProducer extends TestNGConfigurationProducer
Project project = context.getProject(); Project project = context.getProject();
PsiElement leaf = location.getPsiElement(); PsiElement leaf = location.getPsiElement();
if (!ProjectRootsUtil.isInSource(leaf)) { if (!ProjectRootsUtil.isInProjectOrLibSource(leaf)) {
return false; return false;
} }
@@ -58,7 +58,7 @@ public class KotlinReferencesSearcher extends QueryExecutorBase<PsiReference, Re
PsiElement element = queryParameters.getElementToSearch(); PsiElement element = queryParameters.getElementToSearch();
final PsiNamedElement unwrappedElement = AsJavaPackage.getNamedUnwrappedElement(element); final PsiNamedElement unwrappedElement = AsJavaPackage.getNamedUnwrappedElement(element);
if (unwrappedElement == null || !ProjectRootsUtil.isInSource(unwrappedElement)) return; if (unwrappedElement == null || !ProjectRootsUtil.isInProjectOrLibSource(unwrappedElement)) return;
ApplicationManager.getApplication().runReadAction( ApplicationManager.getApplication().runReadAction(
new Runnable() { new Runnable() {