Supporting FqNames with spaces/comments inside them for deprecated
This commit is contained in:
@@ -17,12 +17,14 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.impl.CheckUtil;
|
||||
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
@@ -207,6 +209,23 @@ public class JetPsiUtil {
|
||||
return firstPart.child(name);
|
||||
}
|
||||
|
||||
/** @return <code>null</code> iff the tye has syntactic errors */
|
||||
@Nullable
|
||||
public static FqName toQualifiedName(@NotNull JetUserType userType) {
|
||||
List<String> reversedNames = Lists.newArrayList();
|
||||
|
||||
JetUserType current = userType;
|
||||
while (current != null) {
|
||||
String name = current.getReferencedName();
|
||||
if (name == null) return null;
|
||||
|
||||
reversedNames.add(name);
|
||||
current = current.getQualifier();
|
||||
}
|
||||
|
||||
return FqName.fromSegments(ContainerUtil.reverse(reversedNames));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Name getShortName(JetAnnotationEntry annotation) {
|
||||
JetTypeReference typeReference = annotation.getTypeReference();
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.lang.resolve.name;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -24,6 +25,12 @@ import java.util.List;
|
||||
|
||||
public class FqName extends FqNameBase {
|
||||
|
||||
@NotNull
|
||||
public static FqName fromSegments(@NotNull List<String> names) {
|
||||
String fqName = StringUtil.join(names, ".");
|
||||
return new FqName(fqName);
|
||||
}
|
||||
|
||||
public static final FqName ROOT = new FqName("");
|
||||
|
||||
@NotNull
|
||||
@@ -32,7 +39,6 @@ public class FqName extends FqNameBase {
|
||||
// cache
|
||||
private transient FqName parent;
|
||||
|
||||
|
||||
public FqName(@NotNull String fqName) {
|
||||
this.fqName = new FqNameUnsafe(fqName, this);
|
||||
|
||||
|
||||
+6
-8
@@ -345,15 +345,13 @@ public class KotlinLightClassForExplicitDeclaration extends AbstractLightClass i
|
||||
if (typeReference == null) continue;
|
||||
|
||||
JetTypeElement typeElement = typeReference.getTypeElement();
|
||||
if (typeElement == null) continue;
|
||||
if (!(typeElement instanceof JetUserType)) continue; // If it's not a user type, it's definitely not a ref to deprecated
|
||||
|
||||
// typeElement.getText() is either
|
||||
// simple name => we just compare it to "deprecated"
|
||||
// qualified name => we compare to FqName, there may be spaces, comments etc, we do not support these cases
|
||||
// function type, etc => comparisons below fail
|
||||
String text = typeElement.getText();
|
||||
if (deprecatedFqName.getFqName().equals(text)) return true;
|
||||
if (deprecatedName.equals(text)) return true;
|
||||
FqName fqName = JetPsiUtil.toQualifiedName((JetUserType) typeElement);
|
||||
if (fqName == null) continue;
|
||||
|
||||
if (deprecatedFqName.equals(fqName.toUnsafe())) return true;
|
||||
if (deprecatedName.equals(fqName.getFqName())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -28,8 +28,11 @@ trait Trait
|
||||
// Deprecation
|
||||
deprecated("") class Deprecated
|
||||
jet.deprecated("") class DeprecatedFQN
|
||||
jet. deprecated /**/ ("") class DeprecatedFQNSpaces
|
||||
[deprecated("")] class DeprecatedWithBrackets
|
||||
[jet.deprecated("")] class DeprecatedWithBracketsFQN
|
||||
[jet
|
||||
./**/deprecated ("")] class DeprecatedWithBracketsFQNSpaces
|
||||
|
||||
// Generic
|
||||
class Generic1<T>
|
||||
|
||||
@@ -184,7 +184,23 @@ public class KotlinLightClassCoherenceTest extends KotlinAsJavaTestBase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDeprecatedFQN() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDeprecatedFQNSpaces() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDeprecatedWithBrackets() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDeprecatedWithBracketsFQN() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDeprecatedWithBracketsFQNSpaces() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,8 +88,10 @@ public abstract class KotlinLightClassTest extends KotlinAsJavaTestBase {
|
||||
public void testDeprecation() {
|
||||
checkModifiers("test.Deprecated", PUBLIC, FINAL, DEPRECATED);
|
||||
checkModifiers("test.DeprecatedFQN", PUBLIC, FINAL, DEPRECATED);
|
||||
checkModifiers("test.DeprecatedFQNSpaces", PUBLIC, FINAL, DEPRECATED);
|
||||
checkModifiers("test.DeprecatedWithBrackets", PUBLIC, FINAL, DEPRECATED);
|
||||
checkModifiers("test.DeprecatedWithBracketsFQN", PUBLIC, FINAL, DEPRECATED);
|
||||
checkModifiers("test.DeprecatedWithBracketsFQNSpaces", PUBLIC, FINAL, DEPRECATED);
|
||||
}
|
||||
|
||||
public void testGenericity() {
|
||||
|
||||
Reference in New Issue
Block a user