Moved code from DeclarationUtils and refactored code
This commit is contained in:
@@ -16,16 +16,12 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.plugin.intentions.declarations;
|
package org.jetbrains.jet.plugin.intentions.declarations;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.intellij.psi.PsiComment;
|
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiWhiteSpace;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
|
||||||
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences;
|
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences;
|
||||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||||
@@ -44,15 +40,6 @@ public class DeclarationUtils {
|
|||||||
return property.hasInitializer() && property.isLocal();
|
return property.hasInitializer() && property.isLocal();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Predicate<PsiElement> SKIP_DELIMITERS = new Predicate<PsiElement>() {
|
|
||||||
@Override
|
|
||||||
public boolean apply(@Nullable PsiElement input) {
|
|
||||||
return input == null
|
|
||||||
|| input instanceof PsiWhiteSpace || input instanceof PsiComment
|
|
||||||
|| input.getNode().getElementType() == JetTokens.SEMICOLON;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static JetType getPropertyTypeIfNeeded(@NotNull JetProperty property) {
|
private static JetType getPropertyTypeIfNeeded(@NotNull JetProperty property) {
|
||||||
if (property.getTypeRef() != null) return null;
|
if (property.getTypeRef() != null) return null;
|
||||||
|
|||||||
+10
-2
@@ -26,11 +26,16 @@ import org.jetbrains.jet.lang.psi.JetProperty
|
|||||||
import org.jetbrains.jet.lang.psi.JetBinaryExpression
|
import org.jetbrains.jet.lang.psi.JetBinaryExpression
|
||||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||||
import org.jetbrains.jet.lexer.JetTokens
|
import org.jetbrains.jet.lexer.JetTokens
|
||||||
|
import com.intellij.psi.PsiWhiteSpace
|
||||||
|
import com.intellij.psi.PsiComment
|
||||||
|
import com.google.common.base.Predicate
|
||||||
|
|
||||||
public class JetDeclarationJoinLinesHandler : JoinRawLinesHandlerDelegate {
|
public class JetDeclarationJoinLinesHandler : JoinRawLinesHandlerDelegate {
|
||||||
|
|
||||||
override fun tryJoinRawLines(document: Document, file: PsiFile, start: Int, end: Int): Int {
|
override fun tryJoinRawLines(document: Document, file: PsiFile, start: Int, end: Int): Int {
|
||||||
val element = JetPsiUtil.skipSiblingsBackwardByPredicate(file.findElementAt(start), DeclarationUtils.SKIP_DELIMITERS) ?: return -1
|
val element = file.findElementAt(start)
|
||||||
|
?.siblings(forward = false, withItself = false)
|
||||||
|
?.firstOrNull { !isToSkip(it) } ?: return -1
|
||||||
|
|
||||||
val pair = element.parents(withItself = true)
|
val pair = element.parents(withItself = true)
|
||||||
.map { getPropertyAndAssignment(it) }
|
.map { getPropertyAndAssignment(it) }
|
||||||
@@ -49,7 +54,8 @@ public class JetDeclarationJoinLinesHandler : JoinRawLinesHandlerDelegate {
|
|||||||
val property = element as? JetProperty ?: return null
|
val property = element as? JetProperty ?: return null
|
||||||
if (property.hasInitializer()) return null
|
if (property.hasInitializer()) return null
|
||||||
|
|
||||||
val assignment = JetPsiUtil.skipSiblingsForwardByPredicate(element, DeclarationUtils.SKIP_DELIMITERS) as? JetBinaryExpression ?: return null
|
val assignment = element.siblings(forward = true, withItself = false)
|
||||||
|
.firstOrNull { !isToSkip(it) } as? JetBinaryExpression ?: return null
|
||||||
if (assignment.getOperationToken() != JetTokens.EQ) return null
|
if (assignment.getOperationToken() != JetTokens.EQ) return null
|
||||||
|
|
||||||
val left = assignment.getLeft() as? JetSimpleNameExpression ?: return null
|
val left = assignment.getLeft() as? JetSimpleNameExpression ?: return null
|
||||||
@@ -64,4 +70,6 @@ public class JetDeclarationJoinLinesHandler : JoinRawLinesHandlerDelegate {
|
|||||||
property.getParent()!!.deleteChildRange(property.getNextSibling(), assignment) //TODO: should we remove range?
|
property.getParent()!!.deleteChildRange(property.getNextSibling(), assignment) //TODO: should we remove range?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isToSkip(element: PsiElement)
|
||||||
|
= element is PsiWhiteSpace || element is PsiComment || element.getNode()!!.getElementType() == JetTokens.SEMICOLON
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user