Skip to content

Commit

Permalink
Experimenting with psi validation for "psi is outdated" issues #829 #840
Browse files Browse the repository at this point in the history


GitOrigin-RevId: 4b71f55579f7c21986df01574a22b3fa39551b17
  • Loading branch information
mplushnikov authored and intellij-monorepo-bot committed Aug 13, 2020
1 parent cd39da2 commit efdddde
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 47 deletions.
4 changes: 2 additions & 2 deletions plugins/lombok/gradle.properties
Expand Up @@ -3,8 +3,8 @@
# https://www.jetbrains.com/intellij-repository/snapshots
#
#ideaVersion=2020.1.4
#ideaVersion=2020.2
ideaVersion=LATEST-EAP-SNAPSHOT
ideaVersion=2020.2
#ideaVersion=LATEST-EAP-SNAPSHOT
#
pluginGroup=de.plushnikov.intellij.plugin
pluginName=lombok-plugin
Expand Down
Expand Up @@ -14,12 +14,12 @@
import java.util.*;
import java.util.stream.Stream;

public class LombokLightClassBuilder extends LightPsiClassBuilder implements PsiExtensibleClass {
public class LombokLightClassBuilder extends LightPsiClassBuilder implements PsiExtensibleClass, SyntheticElement {
private boolean myIsEnum;
private final String myQualifiedName;
private final Icon myBaseIcon;
private final LombokLightModifierList myModifierList;
private Collection<PsiField> myFields = new ArrayList<>();
private final Collection<PsiField> myFields = new ArrayList<>();

public LombokLightClassBuilder(@NotNull PsiElement context, @NotNull String simpleName, @NotNull String qualifiedName) {
super(context, simpleName);
Expand Down Expand Up @@ -187,15 +187,21 @@ public boolean equals(Object o) {

LombokLightClassBuilder that = (LombokLightClassBuilder) o;

if(getNavigationElement() != this && !getNavigationElement().equals(that.getNavigationElement())) {
return false;
}

return myQualifiedName.equals(that.myQualifiedName);
return isValid() == that.isValid() && myQualifiedName.equals(that.myQualifiedName);
}

@Override
public int hashCode() {
return myQualifiedName.hashCode();
}

@Override
public boolean isValid() {
return super.isValid() && areAllFieldsAndMethodsValid();
}

private boolean areAllFieldsAndMethodsValid() {
return Arrays.stream(getFields()).allMatch(PsiElement::isValid)
&& Arrays.stream(getMethods()).allMatch(PsiElement::isValid);
}
}
Expand Up @@ -12,12 +12,13 @@
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.Objects;
import java.util.stream.Stream;

/**
* @author Plushnikov Michail
*/
public class LombokLightFieldBuilder extends LightFieldBuilder {
public class LombokLightFieldBuilder extends LightFieldBuilder implements SyntheticElement {
private String myName;
private final LombokLightIdentifier myNameIdentifier;
private final LombokLightModifierList myModifierList;
Expand Down Expand Up @@ -138,13 +139,25 @@ public boolean isEquivalentTo(PsiElement another) {
(null != containingClass && containingClass.isEquivalentTo(anotherContainingClass));
}

if(getNavigationElement() != this && !getNavigationElement().equals(anotherLightField.getNavigationElement())) {
stillEquivalent = false;
}

return stillEquivalent;
} else {
return super.isEquivalentTo(another);
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LombokLightFieldBuilder that = (LombokLightFieldBuilder) o;
return isValid() == that.isValid() &&
Objects.equals(myName, that.myName) &&
Objects.equals(myNameIdentifier, that.myNameIdentifier) &&
Objects.equals(myModifierList, that.myModifierList);
}

@Override
public int hashCode() {
return Objects.hash(myName, myNameIdentifier, myModifierList);
}
}
Expand Up @@ -3,14 +3,15 @@
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiManager;
import com.intellij.psi.SyntheticElement;
import com.intellij.psi.impl.light.LightIdentifier;

import java.util.Objects;

/**
* Date: 12.10.13 Time: 23:27
*/
public class LombokLightIdentifier extends LightIdentifier {
public class LombokLightIdentifier extends LightIdentifier implements SyntheticElement {
private String myText;

public LombokLightIdentifier(PsiManager manager, String text) {
Expand Down Expand Up @@ -49,16 +50,11 @@ public boolean equals(Object o) {

LombokLightIdentifier that = (LombokLightIdentifier) o;

if(getNavigationElement() != this && !getNavigationElement().equals(that.getNavigationElement())) {
return false;
}

return Objects.equals(myText, that.myText);

}

@Override
public int hashCode() {
return myText != null ? myText.hashCode() : 0;
return Objects.hash(myText);
}
}
Expand Up @@ -22,7 +22,7 @@
/**
* @author Plushnikov Michail
*/
public class LombokLightMethodBuilder extends LightMethodBuilder {
public class LombokLightMethodBuilder extends LightMethodBuilder implements SyntheticElement {
private PsiMethod myMethod;
private ASTNode myASTNode;
private PsiCodeBlock myBodyCodeBlock;
Expand Down Expand Up @@ -288,11 +288,7 @@ public boolean equals(Object o) {
return false;
}

if(getNavigationElement() != this && !getNavigationElement().equals(that.getNavigationElement())) {
return false;
}

return Objects.equals(myReturnTypeAsText, that.myReturnTypeAsText);
return isValid() == that.isValid() && Objects.equals(myReturnTypeAsText, that.myReturnTypeAsText);
}

@Override
Expand Down
Expand Up @@ -13,7 +13,7 @@
/**
* @author Plushnikov Michail
*/
public class LombokLightModifierList extends LightModifierList {
public class LombokLightModifierList extends LightModifierList implements SyntheticElement {
private static final Set<String> ALL_MODIFIERS = new HashSet<>(Arrays.asList(PsiModifier.MODIFIERS));

private final Map<String, PsiAnnotation> myAnnotations;
Expand Down Expand Up @@ -115,10 +115,6 @@ public boolean equals(Object o) {

LombokLightModifierList that = (LombokLightModifierList) o;

if (getNavigationElement() != this && !getNavigationElement().equals(that.getNavigationElement())) {
return false;
}

return myAnnotations.equals(that.myAnnotations);
}

Expand Down
Expand Up @@ -2,10 +2,7 @@

import com.intellij.lang.Language;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiIdentifier;
import com.intellij.psi.PsiManager;
import com.intellij.psi.PsiType;
import com.intellij.psi.*;
import com.intellij.psi.impl.light.LightModifierList;
import com.intellij.psi.impl.light.LightParameter;
import com.intellij.psi.impl.light.LightVariableBuilder;
Expand All @@ -17,7 +14,7 @@
/**
* @author Plushnikov Michail
*/
public class LombokLightParameter extends LightParameter {
public class LombokLightParameter extends LightParameter implements SyntheticElement {
private String myName;
private final LombokLightIdentifier myNameIdentifier;

Expand Down Expand Up @@ -77,10 +74,6 @@ public boolean equals(Object o) {
return false;
}

if(getNavigationElement() != this && !getNavigationElement().equals(that.getNavigationElement())) {
return false;
}

return thisType.getCanonicalText().equals(thatType.getCanonicalText());
}

Expand Down
Expand Up @@ -2,11 +2,12 @@

import com.intellij.lang.Language;
import com.intellij.psi.PsiManager;
import com.intellij.psi.SyntheticElement;
import com.intellij.psi.impl.light.LightParameterListBuilder;

import java.util.Arrays;

public class LombokLightParameterListBuilder extends LightParameterListBuilder {
public class LombokLightParameterListBuilder extends LightParameterListBuilder implements SyntheticElement {

public LombokLightParameterListBuilder(PsiManager manager, Language language) {
super(manager, language);
Expand All @@ -27,10 +28,6 @@ public boolean equals(Object o) {
return false;
}

if(getNavigationElement() != this && !getNavigationElement().equals(that.getNavigationElement())) {
return false;
}

return Arrays.equals(getParameters(), that.getParameters());
}

Expand Down
Expand Up @@ -3,9 +3,10 @@
import com.intellij.lang.Language;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiManager;
import com.intellij.psi.SyntheticElement;
import com.intellij.psi.impl.light.LightReferenceListBuilder;

public class LombokLightReferenceListBuilder extends LightReferenceListBuilder {
public class LombokLightReferenceListBuilder extends LightReferenceListBuilder implements SyntheticElement {

public LombokLightReferenceListBuilder(PsiManager manager, Language language, Role role) {
super(manager, language, role);
Expand Down

0 comments on commit efdddde

Please sign in to comment.