Evaluate expression: add ability to import class
This commit is contained in:
@@ -40,6 +40,9 @@ public abstract class JetCodeFragment(
|
|||||||
{
|
{
|
||||||
getViewProvider().forceCachedPsi(this)
|
getViewProvider().forceCachedPsi(this)
|
||||||
init(TokenType.CODE_FRAGMENT, elementType)
|
init(TokenType.CODE_FRAGMENT, elementType)
|
||||||
|
if (_context != null) {
|
||||||
|
addImportsFromString(getImportsForElement(_context))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var _resolveScope: GlobalSearchScope? = null
|
private var _resolveScope: GlobalSearchScope? = null
|
||||||
@@ -89,11 +92,15 @@ public abstract class JetCodeFragment(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun addImportsFromString(imports: String?) {
|
override fun addImportsFromString(imports: String?) {
|
||||||
if (imports == null) return
|
if (imports == null || imports.isEmpty()) return
|
||||||
|
|
||||||
_myImports.addAll(imports.split(IMPORT_SEPARATOR))
|
_myImports.addAll(imports.split(IMPORT_SEPARATOR))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun importsAsImportList(): JetImportList? {
|
||||||
|
return JetPsiFactory.createFile(_project, _myImports.makeString("\n")).getImportList()
|
||||||
|
}
|
||||||
|
|
||||||
override fun setVisibilityChecker(checker: JavaCodeFragment.VisibilityChecker?) { }
|
override fun setVisibilityChecker(checker: JavaCodeFragment.VisibilityChecker?) { }
|
||||||
|
|
||||||
override fun getVisibilityChecker() = JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE
|
override fun getVisibilityChecker() = JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE
|
||||||
@@ -110,5 +117,14 @@ public abstract class JetCodeFragment(
|
|||||||
|
|
||||||
class object {
|
class object {
|
||||||
val IMPORT_SEPARATOR = ","
|
val IMPORT_SEPARATOR = ","
|
||||||
|
|
||||||
|
fun getImportsForElement(elementAtCaret: PsiElement): String {
|
||||||
|
val containingFile = elementAtCaret.getContainingFile()
|
||||||
|
if (containingFile !is JetFile) return ""
|
||||||
|
|
||||||
|
return containingFile.getImportList()?.getImports()
|
||||||
|
?.map { it.getText() }
|
||||||
|
?.makeString(JetCodeFragment.IMPORT_SEPARATOR) ?: ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,10 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.annotations.TestOnly;
|
import org.jetbrains.annotations.TestOnly;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetCodeFragment;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetImportList;
|
||||||
import org.jetbrains.jet.lang.resolve.*;
|
import org.jetbrains.jet.lang.resolve.*;
|
||||||
import org.jetbrains.jet.lang.resolve.name.LabelName;
|
import org.jetbrains.jet.lang.resolve.name.LabelName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
@@ -158,10 +160,19 @@ public class LazyImportScope implements JetScope, LazyEntity {
|
|||||||
@NotNull BindingTrace traceForImportResolve,
|
@NotNull BindingTrace traceForImportResolve,
|
||||||
@NotNull String debugName
|
@NotNull String debugName
|
||||||
) {
|
) {
|
||||||
|
List<JetImportDirective> importDirectives;
|
||||||
|
if (jetFile instanceof JetCodeFragment) {
|
||||||
|
JetImportList importList = ((JetCodeFragment) jetFile).importsAsImportList();
|
||||||
|
importDirectives = importList != null ? importList.getImports() : Collections.<JetImportDirective>emptyList();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
importDirectives = jetFile.getImportDirectives();
|
||||||
|
}
|
||||||
|
|
||||||
return new LazyImportScope(
|
return new LazyImportScope(
|
||||||
resolveSession,
|
resolveSession,
|
||||||
packageDescriptor,
|
packageDescriptor,
|
||||||
Lists.reverse(jetFile.getImportDirectives()),
|
Lists.reverse(importDirectives),
|
||||||
traceForImportResolve,
|
traceForImportResolve,
|
||||||
debugName,
|
debugName,
|
||||||
packageDescriptor.getFqName().isRoot());
|
packageDescriptor.getFqName().isRoot());
|
||||||
|
|||||||
@@ -269,7 +269,8 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testClass(javaClass<AbstractCodeFragmentHighlightingTest>()) {
|
testClass(javaClass<AbstractCodeFragmentHighlightingTest>()) {
|
||||||
model("checker/codeFragments", extension = "kt")
|
model("checker/codeFragments", extension = "kt", recursive = false)
|
||||||
|
model("checker/codeFragments/imports", testMethod = "doTestWithImport", extension = "kt")
|
||||||
}
|
}
|
||||||
|
|
||||||
testClass(javaClass<AbstractJetJsCheckerTest>()) {
|
testClass(javaClass<AbstractJetJsCheckerTest>()) {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import org.jetbrains.jet.lang.psi.JetCodeFragment
|
|||||||
class KotlinEditorTextProvider : EditorTextProvider {
|
class KotlinEditorTextProvider : EditorTextProvider {
|
||||||
override fun getEditorText(elementAtCaret: PsiElement): TextWithImports? {
|
override fun getEditorText(elementAtCaret: PsiElement): TextWithImports? {
|
||||||
val expression = findExpressionInner(elementAtCaret)
|
val expression = findExpressionInner(elementAtCaret)
|
||||||
return TextWithImportsImpl(CodeFragmentKind.EXPRESSION, expression?.getText() ?: "", getImports(elementAtCaret), JetFileType.INSTANCE)
|
return TextWithImportsImpl(CodeFragmentKind.EXPRESSION, expression?.getText() ?: "", JetCodeFragment.getImportsForElement(elementAtCaret), JetFileType.INSTANCE)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun findExpression(elementAtCaret: PsiElement, allowMethodCalls: Boolean): Pair<PsiElement, TextRange>? {
|
override fun findExpression(elementAtCaret: PsiElement, allowMethodCalls: Boolean): Pair<PsiElement, TextRange>? {
|
||||||
@@ -50,15 +50,6 @@ class KotlinEditorTextProvider : EditorTextProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class object {
|
class object {
|
||||||
fun getImports(elementAtCaret: PsiElement): String {
|
|
||||||
val containingFile = elementAtCaret.getContainingFile()
|
|
||||||
if (containingFile !is JetFile) return ""
|
|
||||||
|
|
||||||
return containingFile.getImportList()?.getImports()
|
|
||||||
?.map { it.getText() }
|
|
||||||
?.makeString(JetCodeFragment.IMPORT_SEPARATOR) ?: ""
|
|
||||||
}
|
|
||||||
|
|
||||||
fun findExpressionInner(element: PsiElement): JetExpression? {
|
fun findExpressionInner(element: PsiElement): JetExpression? {
|
||||||
val jetElement = PsiTreeUtil.getParentOfType(element, javaClass<JetElement>())
|
val jetElement = PsiTreeUtil.getParentOfType(element, javaClass<JetElement>())
|
||||||
if (jetElement == null) return null
|
if (jetElement == null) return null
|
||||||
|
|||||||
@@ -66,6 +66,9 @@ import org.jetbrains.jet.lang.psi.JetExpressionCodeFragment
|
|||||||
import org.jetbrains.jet.lang.psi.JetExpressionCodeFragment
|
import org.jetbrains.jet.lang.psi.JetExpressionCodeFragment
|
||||||
import org.jetbrains.jet.plugin.caches.resolve.getAnalysisResults
|
import org.jetbrains.jet.plugin.caches.resolve.getAnalysisResults
|
||||||
import org.jetbrains.jet.lang.psi.JetCodeFragment
|
import org.jetbrains.jet.lang.psi.JetCodeFragment
|
||||||
|
import org.jetbrains.jet.lang.resolve.ImportPath
|
||||||
|
import org.jetbrains.jet.lang.psi.JetImportList
|
||||||
|
import org.jetbrains.jet.lang.psi.JetExpression
|
||||||
|
|
||||||
object KotlinEvaluationBuilder: EvaluatorBuilder {
|
object KotlinEvaluationBuilder: EvaluatorBuilder {
|
||||||
override fun build(codeFragment: PsiElement, position: SourcePosition?): ExpressionEvaluator {
|
override fun build(codeFragment: PsiElement, position: SourcePosition?): ExpressionEvaluator {
|
||||||
@@ -75,18 +78,16 @@ object KotlinEvaluationBuilder: EvaluatorBuilder {
|
|||||||
|
|
||||||
val elementAt = position.getElementAt()
|
val elementAt = position.getElementAt()
|
||||||
if (elementAt != null) {
|
if (elementAt != null) {
|
||||||
codeFragment.addImportsFromString(KotlinEditorTextProvider.getImports(elementAt))
|
|
||||||
|
|
||||||
val packageName = (elementAt.getContainingFile() as JetFile).getPackageDirective()?.getFqName()?.asString()
|
val packageName = (elementAt.getContainingFile() as JetFile).getPackageDirective()?.getFqName()?.asString()
|
||||||
if (packageName != null) {
|
if (packageName != null) {
|
||||||
codeFragment.addImportsFromString("import $packageName.*")
|
codeFragment.addImportsFromString("import $packageName.*")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ExpressionEvaluatorImpl(KotlinEvaluator(codeFragment, position))
|
return ExpressionEvaluatorImpl(KotlinEvaluator(codeFragment as JetExpressionCodeFragment, position))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class KotlinEvaluator(val codeFragment: PsiElement,
|
class KotlinEvaluator(val codeFragment: JetExpressionCodeFragment,
|
||||||
val sourcePosition: SourcePosition
|
val sourcePosition: SourcePosition
|
||||||
) : Evaluator {
|
) : Evaluator {
|
||||||
override fun evaluate(context: EvaluationContextImpl): Any? {
|
override fun evaluate(context: EvaluationContextImpl): Any? {
|
||||||
@@ -234,8 +235,36 @@ private fun createFileForDebugger(codeFragment: JetExpressionCodeFragment,
|
|||||||
.trySetupPsiForFile(virtualFile, JetLanguage.INSTANCE, true, false) as JetFile
|
.trySetupPsiForFile(virtualFile, JetLanguage.INSTANCE, true, false) as JetFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addImportsToFile(newImportList: JetImportList?, tmpFile: JetFile) {
|
||||||
|
if (newImportList != null) {
|
||||||
|
val tmpFileImportList = tmpFile.getImportList()
|
||||||
|
val packageDirective = tmpFile.getPackageDirective()
|
||||||
|
if (tmpFileImportList == null) {
|
||||||
|
tmpFile.addAfter(JetPsiFactory.createNewLine(tmpFile.getProject()), packageDirective)
|
||||||
|
tmpFile.addAfter(newImportList, tmpFile.getPackageDirective())
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tmpFileImportList.replace(newImportList)
|
||||||
|
}
|
||||||
|
tmpFile.addAfter(JetPsiFactory.createNewLine(tmpFile.getProject()), packageDirective)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addDebugExpressionBeforeContextElement(debugExpression: JetExpression, contextElement: PsiElement): JetExpression? {
|
||||||
|
val parent = contextElement.getParent()
|
||||||
|
if (parent == null) return null
|
||||||
|
|
||||||
|
parent.addBefore(JetPsiFactory.createNewLine(contextElement.getProject()), contextElement)
|
||||||
|
val newDebugExpression = parent.addBefore(debugExpression, contextElement)
|
||||||
|
if (newDebugExpression == null) return null
|
||||||
|
|
||||||
|
parent.addBefore(JetPsiFactory.createNewLine(contextElement.getProject()), contextElement)
|
||||||
|
|
||||||
|
return newDebugExpression as JetExpression
|
||||||
|
}
|
||||||
|
|
||||||
private fun getFunctionForExtractedFragment(
|
private fun getFunctionForExtractedFragment(
|
||||||
codeFragment: PsiElement,
|
codeFragment: JetExpressionCodeFragment,
|
||||||
breakpointFile: PsiFile,
|
breakpointFile: PsiFile,
|
||||||
breakpointLine: Int
|
breakpointLine: Int
|
||||||
): JetNamedFunction? {
|
): JetNamedFunction? {
|
||||||
@@ -252,19 +281,14 @@ private fun getFunctionForExtractedFragment(
|
|||||||
val elementAtOffset = tmpFile.findElementAt(lineStart)
|
val elementAtOffset = tmpFile.findElementAt(lineStart)
|
||||||
if (elementAtOffset == null) return null
|
if (elementAtOffset == null) return null
|
||||||
|
|
||||||
val element: PsiElement = CodeInsightUtils.getTopmostElementAtOffset(elementAtOffset, lineStart) ?: elementAtOffset
|
val contextElement: PsiElement = CodeInsightUtils.getTopmostElementAtOffset(elementAtOffset, lineStart) ?: elementAtOffset
|
||||||
|
|
||||||
|
addImportsToFile(codeFragment.importsAsImportList(), tmpFile)
|
||||||
|
|
||||||
val debugExpression = JetPsiFactory.createExpression(project, codeFragment.getText())
|
val debugExpression = JetPsiFactory.createExpression(project, codeFragment.getText())
|
||||||
|
val newDebugExpression = addDebugExpressionBeforeContextElement(debugExpression, contextElement)
|
||||||
val parent = element.getParent()
|
|
||||||
if (parent == null) return null
|
|
||||||
|
|
||||||
parent.addBefore(JetPsiFactory.createNewLine(project), element)
|
|
||||||
val newDebugExpression = parent.addBefore(debugExpression, element)
|
|
||||||
if (newDebugExpression == null) return null
|
if (newDebugExpression == null) return null
|
||||||
|
|
||||||
parent.addBefore(JetPsiFactory.createNewLine(project), element)
|
|
||||||
|
|
||||||
val nextSibling = tmpFile.getDeclarations().firstOrNull()
|
val nextSibling = tmpFile.getDeclarations().firstOrNull()
|
||||||
if (nextSibling == null) return null
|
if (nextSibling == null) return null
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import org.jetbrains.jet.lang.resolve.lazy.descriptors.LazyClassDescriptor;
|
|||||||
import org.jetbrains.jet.lang.resolve.lazy.descriptors.LazyPackageDescriptor;
|
import org.jetbrains.jet.lang.resolve.lazy.descriptors.LazyPackageDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.ChainedScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||||
@@ -228,10 +229,18 @@ public class ResolveElementCache {
|
|||||||
|
|
||||||
JetScope scopeForContextElement = contextForElement.get(BindingContext.RESOLUTION_SCOPE, contextExpression);
|
JetScope scopeForContextElement = contextForElement.get(BindingContext.RESOLUTION_SCOPE, contextExpression);
|
||||||
if (scopeForContextElement != null) {
|
if (scopeForContextElement != null) {
|
||||||
|
JetScope codeFragmentScope = resolveSession.getScopeProvider().getFileScope(codeFragment);
|
||||||
|
ChainedScope chainedScope = new ChainedScope(
|
||||||
|
scopeForContextElement.getContainingDeclaration(),
|
||||||
|
"Scope for resolve code fragment",
|
||||||
|
scopeForContextElement,
|
||||||
|
codeFragmentScope
|
||||||
|
);
|
||||||
|
|
||||||
DataFlowInfo dataFlowInfoForContextElement = contextForElement.get(BindingContext.EXPRESSION_DATA_FLOW_INFO, contextExpression);
|
DataFlowInfo dataFlowInfoForContextElement = contextForElement.get(BindingContext.EXPRESSION_DATA_FLOW_INFO, contextExpression);
|
||||||
AnalyzerPackage.computeTypeInContext(
|
AnalyzerPackage.computeTypeInContext(
|
||||||
codeFragment.getExpression(),
|
codeFragment.getExpression(),
|
||||||
scopeForContextElement,
|
chainedScope,
|
||||||
trace,
|
trace,
|
||||||
dataFlowInfoForContextElement == null ? DataFlowInfo.EMPTY : dataFlowInfoForContextElement,
|
dataFlowInfoForContextElement == null ? DataFlowInfo.EMPTY : dataFlowInfoForContextElement,
|
||||||
TypeUtils.NO_EXPECTED_TYPE,
|
TypeUtils.NO_EXPECTED_TYPE,
|
||||||
|
|||||||
@@ -309,6 +309,11 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isApplicableForCodeFragment() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,9 +97,11 @@ public class ImportInsertHelper {
|
|||||||
|
|
||||||
public static void writeImportToFile(@NotNull ImportPath importPath, @NotNull JetFile file) {
|
public static void writeImportToFile(@NotNull ImportPath importPath, @NotNull JetFile file) {
|
||||||
if (file instanceof JetCodeFragment) {
|
if (file instanceof JetCodeFragment) {
|
||||||
// TODO Insert import doesn't work for codeFragments yet
|
JetImportDirective newDirective = JetPsiFactory.createImportDirective(file.getProject(), importPath);
|
||||||
|
((JetCodeFragment) file).addImportsFromString(newDirective.getText());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JetImportList importList = file.getImportList();
|
JetImportList importList = file.getImportList();
|
||||||
if (importList != null) {
|
if (importList != null) {
|
||||||
JetImportDirective newDirective = JetPsiFactory.createImportDirective(file.getProject(), importPath);
|
JetImportDirective newDirective = JetPsiFactory.createImportDirective(file.getProject(), importPath);
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import com.intellij.psi.PsiElement;
|
|||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import com.intellij.util.IncorrectOperationException;
|
import com.intellij.util.IncorrectOperationException;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetCodeFragment;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
|
||||||
public abstract class JetIntentionAction<T extends PsiElement> implements IntentionAction {
|
public abstract class JetIntentionAction<T extends PsiElement> implements IntentionAction {
|
||||||
@@ -35,7 +36,7 @@ public abstract class JetIntentionAction<T extends PsiElement> implements Intent
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||||
return element.isValid() && file.getManager().isInProject(file) && (file instanceof JetFile);
|
return element.isValid() && (file.getManager().isInProject(file) || file instanceof JetCodeFragment) && (file instanceof JetFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Don't override this method. Use the method with JetFile instead.
|
//Don't override this method. Use the method with JetFile instead.
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public abstract class JetSingleIntentionActionFactory implements JetIntentionAct
|
|||||||
public final List<IntentionAction> createActions(Diagnostic diagnostic) {
|
public final List<IntentionAction> createActions(Diagnostic diagnostic) {
|
||||||
List<IntentionAction> intentionActionList = new LinkedList<IntentionAction>();
|
List<IntentionAction> intentionActionList = new LinkedList<IntentionAction>();
|
||||||
|
|
||||||
if (diagnostic.getPsiElement().getContainingFile() instanceof JetCodeFragment) {
|
if (diagnostic.getPsiElement().getContainingFile() instanceof JetCodeFragment && !isApplicableForCodeFragment()) {
|
||||||
return intentionActionList;
|
return intentionActionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,4 +45,8 @@ public abstract class JetSingleIntentionActionFactory implements JetIntentionAct
|
|||||||
}
|
}
|
||||||
return intentionActionList;
|
return intentionActionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isApplicableForCodeFragment() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
<caret>val a = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// IMPORT: java.util.HashMap
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
HashMap<Int, Int>()
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
LineBreakpoint created at classFromAnotherPackage.kt:7
|
||||||
|
!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !APP_PATH!\classes;!KOTLIN_RUNTIME!;!RT_JAR! classFromAnotherPackage.ClassFromAnotherPackagePackage
|
||||||
|
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
|
||||||
|
classFromAnotherPackage.kt:6
|
||||||
|
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
|
||||||
|
|
||||||
|
Process finished with exit code 0
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package classFromAnotherPackage
|
||||||
|
|
||||||
|
import stepInto.MyJavaClass
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
//Breakpoint!
|
||||||
|
args.size
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXPRESSION: MyJavaClass()
|
||||||
|
// RESULT: instance of stepInto.MyJavaClass(id=ID): LstepInto/MyJavaClass;
|
||||||
|
|
||||||
|
// EXPRESSION: stepInto.MyJavaClass()
|
||||||
|
// RESULT: instance of stepInto.MyJavaClass(id=ID): LstepInto/MyJavaClass;
|
||||||
+19
-3
@@ -24,14 +24,30 @@ import org.jetbrains.jet.lang.psi.JetExpressionCodeFragment
|
|||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||||
import org.jetbrains.jet.plugin.debugger.KotlinEditorTextProvider
|
import org.jetbrains.jet.plugin.quickfix.ImportInsertHelper
|
||||||
import com.intellij.openapi.util.text.StringUtil
|
import org.jetbrains.jet.lang.psi.JetFile
|
||||||
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||||
|
import org.jetbrains.jet.InTextDirectivesUtils
|
||||||
|
|
||||||
abstract class AbstractCodeFragmentHighlightingTest: AbstractJetPsiCheckerTest() {
|
abstract class AbstractCodeFragmentHighlightingTest : AbstractJetPsiCheckerTest() {
|
||||||
override fun doTest(filePath: String) {
|
override fun doTest(filePath: String) {
|
||||||
myFixture.configureByCodeFragment(filePath)
|
myFixture.configureByCodeFragment(filePath)
|
||||||
myFixture.checkHighlighting(true, false, false)
|
myFixture.checkHighlighting(true, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun doTestWithImport(filePath: String) {
|
||||||
|
myFixture.configureByCodeFragment(filePath)
|
||||||
|
|
||||||
|
ApplicationManager.getApplication()?.runWriteAction {
|
||||||
|
val fileText = FileUtil.loadFile(File(filePath), true)
|
||||||
|
InTextDirectivesUtils.findListWithPrefixes(fileText, "// IMPORT: ").forEach {
|
||||||
|
ImportInsertHelper.addImportDirectiveIfNeeded(FqName(it), (myFixture.getFile() as JetFile))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
myFixture.checkHighlighting(true, false, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class AbstractCodeFragmentCompletionTest : AbstractJvmBasicCompletionTest() {
|
abstract class AbstractCodeFragmentCompletionTest : AbstractJvmBasicCompletionTest() {
|
||||||
|
|||||||
+6
-1
@@ -32,6 +32,7 @@ import org.jetbrains.eval4j.jdi.asValue
|
|||||||
import org.jetbrains.eval4j.Value
|
import org.jetbrains.eval4j.Value
|
||||||
import org.jetbrains.eval4j.ObjectValue
|
import org.jetbrains.eval4j.ObjectValue
|
||||||
import com.sun.jdi.ObjectReference
|
import com.sun.jdi.ObjectReference
|
||||||
|
import org.jetbrains.jet.lang.psi.JetCodeFragment
|
||||||
|
|
||||||
public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestCase() {
|
public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestCase() {
|
||||||
fun doTest(path: String) {
|
fun doTest(path: String) {
|
||||||
@@ -85,7 +86,11 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestC
|
|||||||
KotlinCodeFragmentFactory().isContextAccepted(contextElement))
|
KotlinCodeFragmentFactory().isContextAccepted(contextElement))
|
||||||
|
|
||||||
val evaluator = DebuggerInvocationUtil.commitAndRunReadAction(getProject()) {
|
val evaluator = DebuggerInvocationUtil.commitAndRunReadAction(getProject()) {
|
||||||
EvaluatorBuilderImpl.build(TextWithImportsImpl(CodeFragmentKind.EXPRESSION, expression, KotlinEditorTextProvider.getImports(contextElement), JetFileType.INSTANCE),
|
EvaluatorBuilderImpl.build(TextWithImportsImpl(
|
||||||
|
CodeFragmentKind.EXPRESSION,
|
||||||
|
expression,
|
||||||
|
JetCodeFragment.getImportsForElement(contextElement),
|
||||||
|
JetFileType.INSTANCE),
|
||||||
contextElement,
|
contextElement,
|
||||||
sourcePosition)
|
sourcePosition)
|
||||||
}
|
}
|
||||||
|
|||||||
+48
-25
@@ -30,35 +30,58 @@ import org.jetbrains.jet.plugin.debugger.evaluate.AbstractCodeFragmentHighlighti
|
|||||||
|
|
||||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
@TestMetadata("idea/testData/checker/codeFragments")
|
@InnerTestClasses({CodeFragmentHighlightingTestGenerated.CodeFragments.class, CodeFragmentHighlightingTestGenerated.Imports.class})
|
||||||
public class CodeFragmentHighlightingTestGenerated extends AbstractCodeFragmentHighlightingTest {
|
public class CodeFragmentHighlightingTestGenerated extends AbstractCodeFragmentHighlightingTest {
|
||||||
public void testAllFilesPresentInCodeFragments() throws Exception {
|
@TestMetadata("idea/testData/checker/codeFragments")
|
||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/checker/codeFragments"), Pattern.compile("^(.+)\\.kt$"), true);
|
public static class CodeFragments extends AbstractCodeFragmentHighlightingTest {
|
||||||
|
public void testAllFilesPresentInCodeFragments() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/checker/codeFragments"), Pattern.compile("^(.+)\\.kt$"), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("binaryExpression.kt")
|
||||||
|
public void testBinaryExpression() throws Exception {
|
||||||
|
doTest("idea/testData/checker/codeFragments/binaryExpression.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("callExpression.kt")
|
||||||
|
public void testCallExpression() throws Exception {
|
||||||
|
doTest("idea/testData/checker/codeFragments/callExpression.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("contextElementAsStatement.kt")
|
||||||
|
public void testContextElementAsStatement() throws Exception {
|
||||||
|
doTest("idea/testData/checker/codeFragments/contextElementAsStatement.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("simpleNameExpression.kt")
|
||||||
|
public void testSimpleNameExpression() throws Exception {
|
||||||
|
doTest("idea/testData/checker/codeFragments/simpleNameExpression.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("smartCasts.kt")
|
||||||
|
public void testSmartCasts() throws Exception {
|
||||||
|
doTest("idea/testData/checker/codeFragments/smartCasts.kt");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("binaryExpression.kt")
|
@TestMetadata("idea/testData/checker/codeFragments/imports")
|
||||||
public void testBinaryExpression() throws Exception {
|
public static class Imports extends AbstractCodeFragmentHighlightingTest {
|
||||||
doTest("idea/testData/checker/codeFragments/binaryExpression.kt");
|
public void testAllFilesPresentInImports() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/checker/codeFragments/imports"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("hashMap.kt")
|
||||||
|
public void testHashMap() throws Exception {
|
||||||
|
doTestWithImport("idea/testData/checker/codeFragments/imports/hashMap.kt");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("callExpression.kt")
|
public static Test suite() {
|
||||||
public void testCallExpression() throws Exception {
|
TestSuite suite = new TestSuite("CodeFragmentHighlightingTestGenerated");
|
||||||
doTest("idea/testData/checker/codeFragments/callExpression.kt");
|
suite.addTestSuite(CodeFragments.class);
|
||||||
|
suite.addTestSuite(Imports.class);
|
||||||
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("contextElementAsStatement.kt")
|
|
||||||
public void testContextElementAsStatement() throws Exception {
|
|
||||||
doTest("idea/testData/checker/codeFragments/contextElementAsStatement.kt");
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("simpleNameExpression.kt")
|
|
||||||
public void testSimpleNameExpression() throws Exception {
|
|
||||||
doTest("idea/testData/checker/codeFragments/simpleNameExpression.kt");
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("smartCasts.kt")
|
|
||||||
public void testSmartCasts() throws Exception {
|
|
||||||
doTest("idea/testData/checker/codeFragments/smartCasts.kt");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -46,6 +46,11 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
|
|||||||
doTest("idea/testData/debugger/tinyApp/src/evaluate/arrays.kt");
|
doTest("idea/testData/debugger/tinyApp/src/evaluate/arrays.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("classFromAnotherPackage.kt")
|
||||||
|
public void testClassFromAnotherPackage() throws Exception {
|
||||||
|
doTest("idea/testData/debugger/tinyApp/src/evaluate/classFromAnotherPackage.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("classObjectVal.kt")
|
@TestMetadata("classObjectVal.kt")
|
||||||
public void testClassObjectVal() throws Exception {
|
public void testClassObjectVal() throws Exception {
|
||||||
doTest("idea/testData/debugger/tinyApp/src/evaluate/classObjectVal.kt");
|
doTest("idea/testData/debugger/tinyApp/src/evaluate/classObjectVal.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user