2 * Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved.
3 * Use is subject to license terms.
5 package com
.intellij
.psi
;
7 import org
.jetbrains
.annotations
.NotNull
;
8 import org
.jetbrains
.annotations
.Nullable
;
13 public abstract class PsiChildLink
<Parent
extends PsiElement
, Child
extends PsiElement
> implements PsiRefElementCreator
<Parent
, Child
> {
15 @Nullable public abstract Child
findLinkedChild(@Nullable Parent parent
);
18 public final PsiRef
<Child
> createChildRef(@NotNull Parent parent
) {
19 final Child existing
= findLinkedChild(parent
);
20 if (existing
!= null) {
21 return PsiRef
.real(existing
);
23 return PsiRef
.imaginary(PsiRef
.real(parent
), this);
27 public final PsiRef
<Child
> createChildRef(@NotNull PsiRef
<?
extends Parent
> parentRef
) {
28 final Parent parent
= parentRef
.getPsiElement();
30 final Child existing
= findLinkedChild(parent
);
31 if (existing
!= null) {
32 return PsiRef
.real(existing
);
35 return PsiRef
.imaginary(parentRef
, this);