Add getSignificantElement method in JetCodeFragment
This commit is contained in:
@@ -27,5 +27,6 @@ public class JetBlockCodeFragment(
|
|||||||
context: PsiElement?
|
context: PsiElement?
|
||||||
) : JetCodeFragment(project, name, text, JetNodeTypes.BLOCK_CODE_FRAGMENT, context) {
|
) : JetCodeFragment(project, name, text, JetNodeTypes.BLOCK_CODE_FRAGMENT, context) {
|
||||||
|
|
||||||
fun getBlock() = findChildByClass(javaClass<JetBlockExpression>()) ?: throw IllegalStateException("Block expression should be parsed for BlockCodeFragment")
|
override fun getSignificantElement() = findChildByClass(javaClass<JetBlockExpression>())
|
||||||
|
?: throw IllegalStateException("Block expression should be parsed for BlockCodeFragment")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ public abstract class JetCodeFragment(
|
|||||||
private var _superType: PsiType? = null
|
private var _superType: PsiType? = null
|
||||||
private var _exceptionHandler: JavaCodeFragment.ExceptionHandler? = null
|
private var _exceptionHandler: JavaCodeFragment.ExceptionHandler? = null
|
||||||
|
|
||||||
|
public abstract fun getSignificantElement(): JetElement?
|
||||||
|
|
||||||
override fun forceResolveScope(scope: GlobalSearchScope?) {
|
override fun forceResolveScope(scope: GlobalSearchScope?) {
|
||||||
_resolveScope = scope
|
_resolveScope = scope
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,5 +30,5 @@ public class JetExpressionCodeFragment(
|
|||||||
context: PsiElement?
|
context: PsiElement?
|
||||||
) : JetCodeFragment(project, name, text, JetNodeTypes.EXPRESSION_CODE_FRAGMENT, context) {
|
) : JetCodeFragment(project, name, text, JetNodeTypes.EXPRESSION_CODE_FRAGMENT, context) {
|
||||||
|
|
||||||
fun getExpression() = findChildByClass(javaClass<JetExpression>())
|
override fun getSignificantElement() = findChildByClass(javaClass<JetExpression>())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,11 +30,17 @@ public class JetTypeCodeFragment extends JetCodeFragment {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public JetType getType() {
|
public JetType getType() {
|
||||||
JetTypeReference typeReference = findChildByClass(JetTypeReference.class);
|
JetElement typeReference = getSignificantElement();
|
||||||
if (typeReference != null) {
|
if (typeReference instanceof JetTypeReference) {
|
||||||
//TODO return the actual type
|
//TODO return the actual type
|
||||||
return KotlinBuiltIns.getInstance().getAnyType();
|
return KotlinBuiltIns.getInstance().getAnyType();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public JetElement getSignificantElement() {
|
||||||
|
return findChildByClass(JetTypeReference.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -254,11 +254,7 @@ fun addDebugExpressionBeforeContextElement(codeFragment: JetCodeFragment, contex
|
|||||||
|
|
||||||
parent.addBefore(JetPsiFactory.createNewLine(contextElement.getProject()), contextElement)
|
parent.addBefore(JetPsiFactory.createNewLine(contextElement.getProject()), contextElement)
|
||||||
|
|
||||||
val debugExpression = when(codeFragment) {
|
val debugExpression = codeFragment.getSignificantElement()
|
||||||
is JetExpressionCodeFragment -> codeFragment.getExpression()
|
|
||||||
is JetBlockCodeFragment -> codeFragment.getBlock()
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
if (debugExpression == null) return null
|
if (debugExpression == null) return null
|
||||||
|
|
||||||
val newDebugExpression = parent.addBefore(debugExpression, contextElement)
|
val newDebugExpression = parent.addBefore(debugExpression, contextElement)
|
||||||
|
|||||||
@@ -218,14 +218,8 @@ public class ResolveElementCache {
|
|||||||
JetCodeFragment codeFragment,
|
JetCodeFragment codeFragment,
|
||||||
BindingTrace trace
|
BindingTrace trace
|
||||||
) {
|
) {
|
||||||
JetExpression codeFragmentExpression = null;
|
JetElement codeFragmentExpression = codeFragment.getSignificantElement();
|
||||||
if (codeFragment instanceof JetExpressionCodeFragment) {
|
if (!(codeFragmentExpression instanceof JetExpression)) return;
|
||||||
codeFragmentExpression = ((JetExpressionCodeFragment) codeFragment).getExpression();
|
|
||||||
}
|
|
||||||
else if (codeFragment instanceof JetBlockCodeFragment) {
|
|
||||||
codeFragmentExpression = ((JetBlockCodeFragment) codeFragment).getBlock();
|
|
||||||
}
|
|
||||||
if (codeFragmentExpression == null) return;
|
|
||||||
|
|
||||||
PsiElement contextElement = codeFragment.getContext();
|
PsiElement contextElement = codeFragment.getContext();
|
||||||
if (!(contextElement instanceof JetExpression)) return;
|
if (!(contextElement instanceof JetExpression)) return;
|
||||||
@@ -245,7 +239,7 @@ public class ResolveElementCache {
|
|||||||
|
|
||||||
DataFlowInfo dataFlowInfoForContextElement = contextForElement.get(BindingContext.EXPRESSION_DATA_FLOW_INFO, contextExpression);
|
DataFlowInfo dataFlowInfoForContextElement = contextForElement.get(BindingContext.EXPRESSION_DATA_FLOW_INFO, contextExpression);
|
||||||
AnalyzerPackage.computeTypeInContext(
|
AnalyzerPackage.computeTypeInContext(
|
||||||
codeFragmentExpression,
|
(JetExpression) codeFragmentExpression,
|
||||||
chainedScope,
|
chainedScope,
|
||||||
trace,
|
trace,
|
||||||
dataFlowInfoForContextElement == null ? DataFlowInfo.EMPTY : dataFlowInfoForContextElement,
|
dataFlowInfoForContextElement == null ? DataFlowInfo.EMPTY : dataFlowInfoForContextElement,
|
||||||
|
|||||||
Reference in New Issue
Block a user