update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / impl / java / stubs / JavaImportStatementElementType.java
blobcfc03d7ee9f4256e1ff64a8a0f74bfebdbc8a33a
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.impl.java.stubs;
22 import com.intellij.lang.ASTNode;
23 import com.intellij.psi.PsiImportStatementBase;
24 import com.intellij.psi.PsiImportStaticStatement;
25 import com.intellij.psi.PsiJavaCodeReferenceElement;
26 import com.intellij.psi.impl.java.stubs.impl.PsiImportStatementStubImpl;
27 import com.intellij.psi.impl.source.PsiImportStatementImpl;
28 import com.intellij.psi.impl.source.PsiImportStaticStatementImpl;
29 import com.intellij.psi.impl.source.tree.java.ImportStaticStatementElement;
30 import com.intellij.psi.stubs.IndexSink;
31 import com.intellij.psi.stubs.StubElement;
32 import com.intellij.psi.stubs.StubOutputStream;
33 import com.intellij.psi.stubs.StubInputStream;
34 import com.intellij.util.io.DataInputOutputUtil;
35 import com.intellij.util.io.PersistentStringEnumerator;
36 import com.intellij.util.io.StringRef;
37 import org.jetbrains.annotations.NonNls;
38 import org.jetbrains.annotations.NotNull;
40 import java.io.IOException;
42 public class JavaImportStatementElementType extends JavaStubElementType<PsiImportStatementStub, PsiImportStatementBase> {
43 public JavaImportStatementElementType(@NonNls @NotNull final String id) {
44 super(id);
47 public PsiImportStatementBase createPsi(final PsiImportStatementStub stub) {
48 assert !isCompiled(stub);
49 if (stub.isStatic()) {
50 return new PsiImportStaticStatementImpl(stub);
52 else {
53 return new PsiImportStatementImpl(stub);
57 public PsiImportStatementBase createPsi(final ASTNode node) {
58 if (node instanceof ImportStaticStatementElement) {
59 return new PsiImportStaticStatementImpl(node);
61 else {
62 return new PsiImportStatementImpl(node);
66 public PsiImportStatementStub createStub(final PsiImportStatementBase psi, final StubElement parentStub) {
67 final byte flags = PsiImportStatementStubImpl.packFlags(psi.isOnDemand(), psi instanceof PsiImportStaticStatement);
68 final PsiJavaCodeReferenceElement ref = psi.getImportReference();
69 return new PsiImportStatementStubImpl(parentStub, ref != null ? ref.getCanonicalText() : null, flags);
72 public void serialize(final PsiImportStatementStub stub, final StubOutputStream dataStream)
73 throws IOException {
74 dataStream.writeByte(((PsiImportStatementStubImpl)stub).getFlags());
75 dataStream.writeName(stub.getImportReferenceText());
78 public PsiImportStatementStub deserialize(final StubInputStream dataStream, final StubElement parentStub) throws IOException {
79 byte flags = dataStream.readByte();
80 StringRef reftext = dataStream.readName();
81 return new PsiImportStatementStubImpl(parentStub, reftext, flags);
84 public void indexStub(final PsiImportStatementStub stub, final IndexSink sink) {