From c362124ffd1bdc4ec45d06c26203dd08b8ba7c1b Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 17 Apr 2013 19:35:03 +0200 Subject: [PATCH] IDEA-105455 (encode type information in type element copy) --- .../impl/source/tree/JavaTreeGenerator.java | 11 +++---- .../refactoring/IntroduceVariableTest.java | 30 +++++++++++++------ 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaTreeGenerator.java b/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaTreeGenerator.java index 30e55c110153..6e34ca2e1e19 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaTreeGenerator.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaTreeGenerator.java @@ -133,13 +133,11 @@ public class JavaTreeGenerator implements TreeGenerator { String text = type.getPresentableText(); PsiJavaParserFacade parserFacade = JavaPsiFacade.getInstance(original.getProject()).getParserFacade(); - TreeElement element = (TreeElement)parserFacade.createTypeElementFromText(text, original).getNode(); + PsiTypeElement element = parserFacade.createTypeElementFromText(text, original); - PsiTypeElementImpl result = (PsiTypeElementImpl)element.getPsi(); + TreeElement result = (TreeElement)element.getNode(); markGeneratedIfNeeded(original, result); - if (type instanceof PsiClassType) { - encodeInfoInTypeElement(result, type); - } + encodeInfoInTypeElement(result, type); return result; } @@ -195,8 +193,7 @@ public class JavaTreeGenerator implements TreeGenerator { else if (type instanceof PsiIntersectionType) { encodeInfoInTypeElement(typeElement, ((PsiIntersectionType)type).getRepresentative()); } - else { - LOG.assertTrue(type instanceof PsiClassType); + else if (type instanceof PsiClassType) { final PsiClassType classType = (PsiClassType)type; final PsiClassType.ClassResolveResult resolveResult = classType.resolveGenerics(); PsiClass referencedClass = resolveResult.getElement(); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableTest.java index 0ac07353cb60..4d9e581ad94b 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableTest.java @@ -1,7 +1,21 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.refactoring; import com.intellij.JavaTestUtil; -import com.intellij.idea.Bombed; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.CommonClassNames; @@ -19,7 +33,6 @@ import junit.framework.Assert; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -import java.util.Calendar; import java.util.Collection; /** @@ -210,11 +223,11 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase { public void testArrayFromVarargs() throws Exception { doTest(new MockIntroduceVariableHandler("strs", false, false, false, "java.lang.String[]")); } - + public void testArrayFromVarargs1() throws Exception { doTest(new MockIntroduceVariableHandler("strs", false, false, false, "java.lang.String[]")); } - + public void testEnumArrayFromVarargs() throws Exception { doTest(new MockIntroduceVariableHandler("strs", false, false, false, "E[]")); } @@ -261,7 +274,7 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase { public void testAndAndSubexpression() throws Exception { doTest(new MockIntroduceVariableHandler("ab", true, true, false, "boolean")); } - + public void testSubexpressionWithSpacesInSelection() throws Exception { doTest(new MockIntroduceVariableHandler("ab", true, true, false, "boolean")); } @@ -289,11 +302,11 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase { public void testInvalidPostfixExpr() throws Exception { doTest(new MockIntroduceVariableHandler("a1", true, false, true, "int[]")); } - + public void testPolyadic() throws Exception { doTest(new MockIntroduceVariableHandler("b1", true, true, true, "boolean")); } - + public void testAssignmentToUnresolvedReference() throws Exception { doTest(new MockIntroduceVariableHandler("collection", true, true, true, "java.util.List>")); } @@ -358,7 +371,7 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase { } fail("Should not be able to perform refactoring"); } - + public void testMultiCatchSimple() throws Exception { doTest(new MockIntroduceVariableHandler("e", true, true, false, "java.lang.Exception", true)); } @@ -398,7 +411,6 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase { doTest(new MockIntroduceVariableHandler("m", false, false, false, "Foo.I")); } - @Bombed(month = Calendar.APRIL, day = 22, user = "Roman") public void testReturnNonExportedArray() throws Exception { doTest(new MockIntroduceVariableHandler("i", false, false, false, "java.io.File[]") { @Override