@@ -0,0 +1,2469 @@
+// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.%0Apackage com.intellij.model;%0A%0Aimport com.intellij.openapi.application.Application;%0Aimport org.jetbrains.annotations.ApiStatus.Experimental;%0Aimport org.jetbrains.annotations.Contract;%0Aimport org.jetbrains.annotations.NotNull;%0Aimport org.jetbrains.annotations.Nullable;%0A%0Aimport java.util.Objects;%0A%0A/**%0A * %3Ch3%3EExample 1%3C/h3%3E%0A * %7B@linkplain com.intellij.psi.SmartPsiElementPointer Smart pointers%7D might be used to restore the element across different read actions.%0A * %3Cp%3E%0A * Elements are expected to stay valid within a single %7B@link Application#runReadAction read action%7D.%0A * It's highly advised to split long read actions into several short ones, but this also means%0A * that some %7B@link Application#runWriteAction write action%7D might be run in between these short read actions,%0A * which could potentially change the model of the element (reference model, PSI model, framework model or whatever model).%0A * %3C/p%3E%0A *%0A * %3Ch3%3EExample 2%3C/h3%3E%0A * Pointers might be used to avoid hard references to the element to save the memory.%0A * In this case the pointer stores minimal needed information to be able to restore the element when requested.%0A *%0A * @param %3CT%3E type of underlying element%0A */%0A@Experimental%0Apublic interface Pointer%3CT%3E %7B%0A%0A  /**%0A   * @return value or %7B@code null%7D if the value was invalidated or cannot be restored%0A   */%0A  @Nullable%0A  T dereference();%0A%0A  boolean equals(Object o);%0A%0A  int hashCode();%0A%0A  /**%0A   * Creates a pointer which holds strong reference to the %7B@code value%7D.%0A   * The pointer always dereferences into the passed %7B@code value%7D.%0A   * Hard pointers should be used only for values that cannot be invalidated.%0A   */%0A  @Contract(value = %22_ -%3E new%22, pure = true)%0A  @NotNull%0A  static %3CT%3E Pointer%3CT%3E hardPointer(@NotNull T value) %7B%0A    return new HardPointer%3C%3E(value);%0A  %7D%0A%7D%0A%0Afinal class HardPointer%3CT%3E implements Pointer%3CT%3E %7B%0A%0A  private final T myValue;%0A%0A  HardPointer(@NotNull T value) %7B%0A    myValue = value;%0A  %7D%0A%0A  @NotNull%0A  @Override%0A  public T dereference() %7B%0A    return myValue;%0A  %7D%0A%0A  @Override%0A  public boolean equals(Object o) %7B%0A    if (this == o) return true;%0A    if (o == null %7C%7C getClass() != o.getClass()) return false;%0A    HardPointer%3C?%3E pointer = (HardPointer%3C?%3E)o;%0A    return Objects.equals(myValue, pointer.myValue);%0A  %7D%0A%0A  @Override%0A  public int hashCode() %7B%0A    return myValue.hashCode();%0A  %7D%0A%7D%0A

add Pointer