/*
 * Copyright 2015 Marek Kaput
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.rustidea.psi.impl;

import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.rustidea.psi.RustElementVisitor;
import org.rustidea.psi.RustIdentifier;
import org.rustidea.psi.RustLifetime;
import org.rustidea.psi.types.RustStubElementTypes;
import org.rustidea.psi.types.RustTypes;
import org.rustidea.stubs.RustLifetimeStub;
import org.rustidea.stubs.impl.IRustStubPsiElement;

public class RustLifetimeImpl extends IRustStubPsiElement<RustLifetimeStub> implements RustLifetime {
    public RustLifetimeImpl(@NotNull RustLifetimeStub stub) {
        super(stub, RustStubElementTypes.LIFETIME);
    }

    public RustLifetimeImpl(@NotNull ASTNode node) {
        super(node);
    }

    @Nullable
    @Override
    public RustIdentifier getNameIdentifier() {
        return findChildByType(RustTypes.LIFETIME_TOKEN);
    }

    @Nullable
    @Override
    public String getName() {
        final RustLifetimeStub stub = getStub();
        if (stub != null) {
            return stub.getName();
        }

        final RustIdentifier node = getNameIdentifier();
        if (node != null) {
            return node.getText().substring(1); // Trim initial '
        }

        return null;
    }

    @NotNull
    @Override
    public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
        // TODO Implement this.
        throw new IncorrectOperationException("not implemented yet");
    }

    @Override
    public void accept(@NotNull PsiElementVisitor visitor) {
        if (visitor instanceof RustElementVisitor) {
            ((RustElementVisitor) visitor).visitLifetime(this);
        } else {
            visitor.visitElement(this);
        }
    }

    @Override
    public String toString() {
        return "RustLifetime:" + getName();
    }
}

@@ -728,24 +728,66 @@
 entVisitor;%0A
+import com.intellij.psi.util.PsiTreeUtil;%0A
 import com.i
@@ -828,16 +828,16 @@
 eption;%0A
-
 import o
@@ -1091,49 +1091,8 @@
 es;%0A
-import org.rustidea.psi.types.RustTypes;%0A
 impo
@@ -1486,39 +1486,38 @@
 );%0A    %7D%0A%0A    @N
+otN
 ull
-able
 %0A    @Override%0A 
@@ -1582,48 +1582,69 @@
 urn 
-fin
+PsiTreeUtil.getRequire
 dChild
-By
+Of
 Type(
-RustTypes.LIFETIME_TOKEN
+this, RustIdentifier.class
 );%0A 
@@ -1842,108 +1842,34 @@
     
-final RustIdentifier node = getNameIdentifier();%0A        if (node != null) %7B%0A            return node
+return getNameIdentifier()
 .get
@@ -1911,40 +1911,8 @@
 l '%0A
-        %7D%0A%0A        return null;%0A
     

Make RustLifetimeImpl.getNameIdentifier non-nullable