Add getSignificantElement method in JetCodeFragment

This commit is contained in:
Natalia Ukhorskaya
2014-05-15 13:29:16 +04:00
parent 8c0f99001b
commit fd8d292c02
6 changed files with 17 additions and 18 deletions
@@ -27,5 +27,6 @@ public class JetBlockCodeFragment(
context: PsiElement?
) : 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 _exceptionHandler: JavaCodeFragment.ExceptionHandler? = null
public abstract fun getSignificantElement(): JetElement?
override fun forceResolveScope(scope: GlobalSearchScope?) {
_resolveScope = scope
}
@@ -30,5 +30,5 @@ public class JetExpressionCodeFragment(
context: PsiElement?
) : 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
public JetType getType() {
JetTypeReference typeReference = findChildByClass(JetTypeReference.class);
if (typeReference != null) {
JetElement typeReference = getSignificantElement();
if (typeReference instanceof JetTypeReference) {
//TODO return the actual type
return KotlinBuiltIns.getInstance().getAnyType();
}
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)
val debugExpression = when(codeFragment) {
is JetExpressionCodeFragment -> codeFragment.getExpression()
is JetBlockCodeFragment -> codeFragment.getBlock()
else -> null
}
val debugExpression = codeFragment.getSignificantElement()
if (debugExpression == null) return null
val newDebugExpression = parent.addBefore(debugExpression, contextElement)
@@ -218,14 +218,8 @@ public class ResolveElementCache {
JetCodeFragment codeFragment,
BindingTrace trace
) {
JetExpression codeFragmentExpression = null;
if (codeFragment instanceof JetExpressionCodeFragment) {
codeFragmentExpression = ((JetExpressionCodeFragment) codeFragment).getExpression();
}
else if (codeFragment instanceof JetBlockCodeFragment) {
codeFragmentExpression = ((JetBlockCodeFragment) codeFragment).getBlock();
}
if (codeFragmentExpression == null) return;
JetElement codeFragmentExpression = codeFragment.getSignificantElement();
if (!(codeFragmentExpression instanceof JetExpression)) return;
PsiElement contextElement = codeFragment.getContext();
if (!(contextElement instanceof JetExpression)) return;
@@ -245,7 +239,7 @@ public class ResolveElementCache {
DataFlowInfo dataFlowInfoForContextElement = contextForElement.get(BindingContext.EXPRESSION_DATA_FLOW_INFO, contextExpression);
AnalyzerPackage.computeTypeInContext(
codeFragmentExpression,
(JetExpression) codeFragmentExpression,
chainedScope,
trace,
dataFlowInfoForContextElement == null ? DataFlowInfo.EMPTY : dataFlowInfoForContextElement,