From 0a0f60ea44276b034b239464d09b614c7d6ac0ca Mon Sep 17 00:00:00 2001 From: Peter Gromov Date: Tue, 10 Feb 2009 01:13:17 +0300 Subject: [PATCH] jam for nested annotations --- .../src/com/intellij/psi/ref/InstanceofLink.java | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 openapi/src/com/intellij/psi/ref/InstanceofLink.java diff --git a/openapi/src/com/intellij/psi/ref/InstanceofLink.java b/openapi/src/com/intellij/psi/ref/InstanceofLink.java new file mode 100644 index 0000000000..724533eeda --- /dev/null +++ b/openapi/src/com/intellij/psi/ref/InstanceofLink.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved. + * Use is subject to license terms. + */ +package com.intellij.psi.ref; + +import com.intellij.psi.PsiChildLink; +import com.intellij.psi.PsiElement; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; + +/** + * @author peter + */ +public class InstanceofLink extends PsiChildLink { + private final PsiChildLink myDelegate; + private final Class myCastTo; + + private InstanceofLink(PsiChildLink delegate, Class castTo) { + myDelegate = delegate; + myCastTo = castTo; + } + + public CastTo findLinkedChild(@Nullable Parent parent) { + final Child existing = myDelegate.findLinkedChild(parent); + return myCastTo.isInstance(existing) ? (CastTo) existing : null; + } + + @NotNull + public CastTo createChild(@NotNull Parent parent) throws IncorrectOperationException { + return (CastTo) myDelegate.createChild(parent); + } + + public static InstanceofLink create( + PsiChildLink delegate, Class castTo) { + return new InstanceofLink(delegate, castTo); + } +} -- 2.11.4.GIT