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.
20 package com
.intellij
.psi
.impl
.source
;
22 import com
.intellij
.lang
.ASTNode
;
23 import com
.intellij
.lang
.StdLanguages
;
24 import com
.intellij
.lexer
.JavaLexer
;
25 import com
.intellij
.openapi
.vfs
.VirtualFile
;
26 import com
.intellij
.pom
.java
.LanguageLevel
;
27 import com
.intellij
.psi
.PsiManager
;
28 import com
.intellij
.psi
.StubBuilder
;
29 import com
.intellij
.psi
.impl
.java
.stubs
.PsiJavaFileStub
;
30 import com
.intellij
.psi
.impl
.java
.stubs
.impl
.PsiJavaFileStubImpl
;
31 import com
.intellij
.psi
.impl
.source
.parsing
.FileTextParsing
;
32 import com
.intellij
.psi
.impl
.source
.tree
.FileElement
;
33 import com
.intellij
.psi
.stubs
.IndexSink
;
34 import com
.intellij
.psi
.stubs
.StubElement
;
35 import com
.intellij
.psi
.stubs
.StubInputStream
;
36 import com
.intellij
.psi
.stubs
.StubOutputStream
;
37 import com
.intellij
.psi
.tree
.IStubFileElementType
;
38 import com
.intellij
.psi
.util
.PsiUtil
;
39 import com
.intellij
.util
.io
.StringRef
;
41 import java
.io
.IOException
;
43 public class JavaFileElementType
extends IStubFileElementType
<PsiJavaFileStub
> {
44 public static final int STUB_VERSION
= 3;
46 public JavaFileElementType() {
47 super("java.FILE", StdLanguages
.JAVA
);
50 public StubBuilder
getBuilder() {
51 return new JavaFileStubBuilder();
54 public int getStubVersion() {
59 public boolean shouldBuildStubFor(final VirtualFile file
) {
60 final VirtualFile dir
= file
.getParent();
61 return dir
== null || dir
.getUserData(LanguageLevel
.KEY
) != null;
64 public ASTNode
parseContents(ASTNode chameleon
) {
65 FileElement node
= (FileElement
)chameleon
;
66 final CharSequence seq
= node
.getChars();
68 final PsiManager manager
= node
.getManager();
69 final JavaLexer lexer
= new JavaLexer(PsiUtil
.getLanguageLevel(node
.getPsi()));
70 return FileTextParsing
.parseFileText(manager
, lexer
, seq
, 0, seq
.length(), node
.getCharTable());
73 public String
getExternalId() {
77 public void serialize(final PsiJavaFileStub stub
, final StubOutputStream dataStream
)
79 dataStream
.writeBoolean(stub
.isCompiled());
80 dataStream
.writeName(stub
.getPackageName());
83 public PsiJavaFileStub
deserialize(final StubInputStream dataStream
, final StubElement parentStub
) throws IOException
{
84 boolean compiled
= dataStream
.readBoolean();
85 StringRef packName
= dataStream
.readName();
86 return new PsiJavaFileStubImpl(packName
, compiled
);
89 public void indexStub(final PsiJavaFileStub stub
, final IndexSink sink
) {