mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
calc expected types for the entire live template range
This commit is contained in:
@@ -76,19 +76,13 @@ public class ExpectedTypeMacro extends Macro {
|
||||
final Project project = context.getProject();
|
||||
PsiType[] types = null;
|
||||
|
||||
final int offset = context.getTemplateStartOffset();
|
||||
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
|
||||
assert file != null;
|
||||
final PsiFile fileCopy = (PsiFile)file.copy();
|
||||
BlockSupport.getInstance(project).reparseRange(fileCopy, context.getTemplateStartOffset(), context.getTemplateEndOffset(),
|
||||
CompletionUtil.DUMMY_IDENTIFIER);
|
||||
|
||||
new WriteCommandAction(project) {
|
||||
@Override
|
||||
protected void run(com.intellij.openapi.application.Result result) throws Throwable {
|
||||
final BlockSupport blockSupport = ServiceManager.getService(project, BlockSupport.class);
|
||||
blockSupport.reparseRange(fileCopy, offset, offset, CompletionUtil.DUMMY_IDENTIFIER);
|
||||
}
|
||||
}.execute();
|
||||
PsiElement element = fileCopy.findElementAt(offset);
|
||||
PsiElement element = fileCopy.findElementAt(context.getTemplateStartOffset());
|
||||
|
||||
if (element instanceof PsiIdentifier && element.getParent() instanceof PsiExpression) {
|
||||
ExpectedTypeInfo[] infos = ExpectedTypesProvider.getExpectedTypes((PsiExpression)element.getParent(), true);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
class Foo {
|
||||
|
||||
static void foo(List<String> ls) {
|
||||
List<String> ls2 = Arrays.asList(ls.toArray(new String[ls.size()])<caret>);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
class Foo {
|
||||
|
||||
static void foo(List<String> ls) {
|
||||
List<String> ls2 = Arrays.asList(<caret>);
|
||||
}
|
||||
}
|
||||
@@ -237,6 +237,13 @@ public class LiveTemplateTest extends LightCodeInsightFixtureTestCase {
|
||||
checkResult();
|
||||
}
|
||||
|
||||
public void testAsListToar() {
|
||||
configure();
|
||||
startTemplate("toar", "other")
|
||||
myFixture.type('\n\t')
|
||||
checkResult();
|
||||
}
|
||||
|
||||
public void testVarargToar() {
|
||||
configure();
|
||||
startTemplate("toar", "other")
|
||||
|
||||
Reference in New Issue
Block a user