equals of PropertyGroup node shouldn't depend on PsiType (EA-99891 - INRE: FileBasedIndexImpl.handleDumbMode)

plus cleanup, remove test-only code
This commit is contained in:
peter
2017-04-25 09:45:55 +02:00
parent 577c743943
commit b756f221ba
2 changed files with 8 additions and 30 deletions

View File

@@ -508,6 +508,7 @@ public class PropertyUtil {
return suggestPropertyName(field, field.getName()); return suggestPropertyName(field, field.getName());
} }
@NotNull
public static String suggestPropertyName(@NotNull PsiField field, @NotNull String fieldName) { public static String suggestPropertyName(@NotNull PsiField field, @NotNull String fieldName) {
JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(field.getProject()); JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(field.getProject());
VariableKind kind = codeStyleManager.getVariableKind(field); VariableKind kind = codeStyleManager.getVariableKind(field);

View File

@@ -26,7 +26,6 @@ import com.intellij.openapi.editor.colors.CodeInsightColors;
import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.IconLoader;
import com.intellij.psi.*; import com.intellij.psi.*;
import com.intellij.psi.util.PropertyUtil; import com.intellij.psi.util.PropertyUtil;
@@ -40,8 +39,8 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
public class PropertyGroup implements Group, ColoredItemPresentation, AccessLevelProvider, WeighedItem { public class PropertyGroup implements Group, ColoredItemPresentation, AccessLevelProvider, WeighedItem {
private final String myPropertyName; @NotNull private final String myPropertyName;
private final SmartTypePointer myPropertyType; @NotNull private final String myTypeText;
private SmartPsiElementPointer myFieldPointer; private SmartPsiElementPointer myFieldPointer;
private SmartPsiElementPointer myGetterPointer; private SmartPsiElementPointer myGetterPointer;
@@ -56,9 +55,9 @@ public class PropertyGroup implements Group, ColoredItemPresentation, AccessLeve
private final Project myProject; private final Project myProject;
private final Collection<TreeElement> myChildren = new ArrayList<>(); private final Collection<TreeElement> myChildren = new ArrayList<>();
private PropertyGroup(String propertyName, PsiType propertyType, boolean isStatic, @NotNull Project project) { private PropertyGroup(@NotNull String propertyName, @NotNull PsiType propertyType, boolean isStatic, @NotNull Project project) {
myPropertyName = propertyName; myPropertyName = propertyName;
myPropertyType = SmartTypePointerManager.getInstance(project).createSmartTypePointer(propertyType); myTypeText = propertyType.getPresentableText();
myIsStatic = isStatic; myIsStatic = isStatic;
myProject = project; myProject = project;
} }
@@ -143,8 +142,7 @@ public class PropertyGroup implements Group, ColoredItemPresentation, AccessLeve
@Override @Override
public String getPresentableText() { public String getPresentableText() {
final PsiType type = getPropertyType(); return myPropertyName + ": " + myTypeText;
return myPropertyName + (type != null ? ": " + type.getPresentableText() : "");
} }
public String toString() { public String toString() {
@@ -156,32 +154,11 @@ public class PropertyGroup implements Group, ColoredItemPresentation, AccessLeve
if (this == o) return true; if (this == o) return true;
if (!(o instanceof PropertyGroup)) return false; if (!(o instanceof PropertyGroup)) return false;
final PropertyGroup propertyGroup = (PropertyGroup)o; return myPropertyName.equals(((PropertyGroup)o).myPropertyName) && myTypeText.equals(((PropertyGroup)o).myTypeText);
if (myPropertyName != null ? !myPropertyName.equals(propertyGroup.myPropertyName) : propertyGroup.myPropertyName != null) return false;
final PsiType propertyType = getPropertyType();
final PsiType otherPropertyType = propertyGroup.getPropertyType();
if (!Comparing.equal(propertyType, otherPropertyType)) {
return false;
}
return true;
} }
public int hashCode() { public int hashCode() {
return myPropertyName != null ? myPropertyName.hashCode() : 0; return myPropertyName.hashCode() * 31 + myTypeText.hashCode();
}
public String getGetterName() {
return PropertyUtil.suggestGetterName(myPropertyName, getPropertyType());
}
private PsiType getPropertyType() {
if (myPropertyType == null) {
return null;
}
return myPropertyType.getType();
} }
@Override @Override