update copyrights
[fedora-idea.git] / platform / lang-api / src / com / intellij / psi / stubs / IStubElementType.java
blobe698723506e70583195183aaa97c8678efacfe02
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author max
20 package com.intellij.psi.stubs;
22 import com.intellij.lang.ASTNode;
23 import com.intellij.lang.Language;
24 import com.intellij.psi.PsiElement;
25 import com.intellij.psi.tree.IElementType;
26 import org.jetbrains.annotations.NonNls;
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
30 public abstract class IStubElementType<StubT extends StubElement, PsiT extends PsiElement> extends IElementType implements StubSerializer<StubT> {
31 public IStubElementType(@NotNull @NonNls final String debugName, @Nullable final Language language) {
32 super(debugName, language);
35 public abstract PsiT createPsi(StubT stub);
37 public abstract StubT createStub(PsiT psi, final StubElement parentStub);
39 public boolean shouldCreateStub(ASTNode node) {
40 return true;
43 public String getId(StubT stub) {
44 assert stub.getStubType() == this;
46 final StubElement parent = stub.getParentStub();
47 int count = 0;
48 for (Object child : parent.getChildrenStubs()) {
49 if (((StubElement)child).getStubType() == this) count++;
50 if (child == stub) {
51 return '#' + String.valueOf(count);
55 throw new RuntimeException("Parent/child relations corrupted");