Move getExpressionType method to utils
This commit is contained in:
@@ -2,7 +2,15 @@ package org.jetbrains.jet.plugin.codeInsight.surroundWith;
|
|||||||
|
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.psi.JetBlockExpression;
|
import org.jetbrains.jet.lang.psi.JetBlockExpression;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
||||||
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
||||||
|
|
||||||
public class KotlinSurrounderUtils {
|
public class KotlinSurrounderUtils {
|
||||||
|
|
||||||
@@ -13,4 +21,11 @@ public class KotlinSurrounderUtils {
|
|||||||
PsiElement lBrace = block.getFirstChild();
|
PsiElement lBrace = block.getFirstChild();
|
||||||
block.addRangeAfter(statements[0], statements[statements.length - 1], lBrace);
|
block.addRangeAfter(statements[0], statements[statements.length - 1], lBrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static JetType getExpressionType(JetExpression expression) {
|
||||||
|
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) expression.getContainingFile());
|
||||||
|
BindingContext expressionBindingContext = ResolveSessionUtils.resolveToExpression(resolveSession, expression);
|
||||||
|
return expressionBindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-12
@@ -2,22 +2,18 @@ package org.jetbrains.jet.plugin.codeInsight.surroundWith.expression;
|
|||||||
|
|
||||||
import com.intellij.codeInsight.CodeInsightBundle;
|
import com.intellij.codeInsight.CodeInsightBundle;
|
||||||
import com.intellij.codeInsight.CodeInsightUtilBase;
|
import com.intellij.codeInsight.CodeInsightUtilBase;
|
||||||
import com.intellij.lang.surroundWith.Surrounder;
|
|
||||||
import com.intellij.openapi.editor.Editor;
|
import com.intellij.openapi.editor.Editor;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.util.TextRange;
|
import com.intellij.openapi.util.TextRange;
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
|
||||||
import com.intellij.util.IncorrectOperationException;
|
|
||||||
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.JetExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.psi.JetParenthesizedExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
import org.jetbrains.jet.lang.psi.JetPrefixExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
import org.jetbrains.jet.plugin.codeInsight.surroundWith.KotlinSurrounderUtils;
|
||||||
|
|
||||||
public class KotlinNotSurrounder extends KotlinExpressionSurrounder {
|
public class KotlinNotSurrounder extends KotlinExpressionSurrounder {
|
||||||
@Override
|
@Override
|
||||||
@@ -27,9 +23,7 @@ public class KotlinNotSurrounder extends KotlinExpressionSurrounder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isApplicable(@NotNull JetExpression expression) {
|
public boolean isApplicable(@NotNull JetExpression expression) {
|
||||||
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) expression.getContainingFile());
|
JetType type = KotlinSurrounderUtils.getExpressionType(expression);
|
||||||
BindingContext expressionBindingContext = ResolveSessionUtils.resolveToExpression(resolveSession, expression);
|
|
||||||
JetType type = expressionBindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
|
||||||
return KotlinBuiltIns.getInstance().getBooleanType().equals(type);
|
return KotlinBuiltIns.getInstance().getBooleanType().equals(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user