mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-87248 (smart type pointer manager should be more tolerant to unknown types)
This commit is contained in:
+12
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 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.
|
||||
@@ -42,6 +42,11 @@ import java.util.Set;
|
||||
public class SmartTypePointerManagerImpl extends SmartTypePointerManager {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.smartPointers.SmartTypePointerManagerImpl");
|
||||
|
||||
private static final SmartTypePointer NULL_POINTER = new SmartTypePointer() {
|
||||
@Override
|
||||
public PsiType getType() { return null; }
|
||||
};
|
||||
|
||||
private final SmartPointerManager myPsiPointerManager;
|
||||
private final Project myProject;
|
||||
|
||||
@@ -53,7 +58,8 @@ public class SmartTypePointerManagerImpl extends SmartTypePointerManager {
|
||||
@Override
|
||||
@NotNull
|
||||
public SmartTypePointer createSmartTypePointer(@NotNull PsiType type) {
|
||||
return type.accept(new SmartTypeCreatingVisitor());
|
||||
final SmartTypePointer pointer = type.accept(new SmartTypeCreatingVisitor());
|
||||
return pointer != null ? pointer : NULL_POINTER;
|
||||
}
|
||||
|
||||
private static class SimpleTypePointer implements SmartTypePointer {
|
||||
@@ -77,6 +83,7 @@ public class SmartTypePointerManagerImpl extends SmartTypePointerManager {
|
||||
myComponentTypePointer = componentTypePointer;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected PsiArrayType calcType() {
|
||||
final PsiType type = myComponentTypePointer.getType();
|
||||
@@ -164,6 +171,7 @@ public class SmartTypePointerManagerImpl extends SmartTypePointerManager {
|
||||
return myType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract T calcType();
|
||||
}
|
||||
|
||||
@@ -228,7 +236,8 @@ public class SmartTypePointerManagerImpl extends SmartTypePointerManager {
|
||||
|
||||
@Override
|
||||
public SmartTypePointer visitArrayType(PsiArrayType arrayType) {
|
||||
return new ArrayTypePointer(arrayType, arrayType.getComponentType().accept(this));
|
||||
final SmartTypePointer componentTypePointer = arrayType.getComponentType().accept(this);
|
||||
return componentTypePointer != null ? new ArrayTypePointer(arrayType, componentTypePointer) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -174,6 +174,7 @@ public abstract class PsiType implements PsiAnnotationOwner {
|
||||
* @param visitor the visitor to accept the type.
|
||||
* @return the value returned by the visitor.
|
||||
*/
|
||||
@Nullable
|
||||
public abstract <A> A accept(@NotNull PsiTypeVisitor<A> visitor);
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,44 +15,55 @@
|
||||
*/
|
||||
package com.intellij.psi;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Visitor which can be used to visit Java types.
|
||||
*
|
||||
* @author dsl
|
||||
*/
|
||||
public class PsiTypeVisitor<A> {
|
||||
@Nullable
|
||||
public A visitType(PsiType type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public A visitPrimitiveType(PsiPrimitiveType primitiveType) {
|
||||
return visitType(primitiveType);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public A visitArrayType(PsiArrayType arrayType) {
|
||||
return visitType(arrayType);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public A visitClassType(PsiClassType classType) {
|
||||
return visitType(classType);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public A visitCapturedWildcardType(PsiCapturedWildcardType capturedWildcardType) {
|
||||
return visitWildcardType(capturedWildcardType.getWildcard());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public A visitWildcardType(PsiWildcardType wildcardType) {
|
||||
return visitType(wildcardType);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public A visitEllipsisType(PsiEllipsisType ellipsisType) {
|
||||
return visitArrayType(ellipsisType);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public A visitDisjunctionType(PsiDisjunctionType disjunctionType) {
|
||||
return visitType(disjunctionType);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public A visitDiamondType(PsiDiamondType diamondType) {
|
||||
return visitType(diamondType);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 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.
|
||||
@@ -66,7 +66,9 @@ public class Bottom extends PsiType {
|
||||
if (visitor instanceof PsiTypeVisitorEx) {
|
||||
return ((PsiTypeVisitorEx<A>)visitor).visitBottom(this);
|
||||
}
|
||||
return visitor.visitType(this);
|
||||
else {
|
||||
return visitor.visitType(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 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.
|
||||
@@ -33,7 +33,8 @@ public abstract class PsiTypeVariable extends PsiType {
|
||||
if (visitor instanceof PsiTypeVisitorEx) {
|
||||
return ((PsiTypeVisitorEx<A>)visitor).visitTypeVariable(this);
|
||||
}
|
||||
|
||||
return visitor.visitType(this);
|
||||
else {
|
||||
return visitor.visitType(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 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.
|
||||
@@ -15,14 +15,18 @@
|
||||
*/
|
||||
package com.intellij.psi;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public class PsiTypeVisitorEx<A> extends PsiTypeVisitor<A> {
|
||||
@Nullable
|
||||
public A visitTypeVariable(PsiTypeVariable var) {
|
||||
return visitType(var);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public A visitBottom (Bottom bottom) {
|
||||
return visitType(bottom);
|
||||
}
|
||||
|
||||
+4
@@ -37,4 +37,8 @@ class C {
|
||||
IntParser intParser = <weak_warning descr="Lambda expressions type check is not yet implemented">(String s) -> Integer.parseInt(s)</weak_warning>;
|
||||
ListProducer<String> listProducer = <weak_warning descr="Lambda expressions type check is not yet implemented"><T>() -> new ArrayList<T>()</weak_warning>;
|
||||
}
|
||||
|
||||
Runnable foo() {
|
||||
return <weak_warning descr="Lambda expressions type check is not yet implemented">() -> { System.out.println("foo"); }</weak_warning>;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user