2 * Copyright 2000-2015 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.
17 package com.intellij.psi.impl.source.tree;
19 import com.intellij.lang.*;
20 import com.intellij.openapi.util.Getter;
21 import com.intellij.psi.PsiElement;
22 import com.intellij.psi.impl.PsiManagerEx;
23 import com.intellij.psi.impl.source.CharTableImpl;
24 import com.intellij.psi.impl.source.PsiFileImpl;
25 import com.intellij.psi.tree.IElementType;
26 import com.intellij.psi.tree.IFileElementType;
27 import com.intellij.psi.tree.ILightStubFileElementType;
28 import com.intellij.util.CharTable;
29 import org.jetbrains.annotations.NotNull;
31 public class FileElement extends LazyParseableElement implements FileASTNode, Getter<FileElement> {
32 public static final FileElement[] EMPTY_ARRAY = new FileElement[0];
33 private volatile CharTable myCharTable = new CharTableImpl();
34 private volatile boolean myDetached;
37 protected PsiElement createPsiNoLock() {
38 return myDetached ? null : super.createPsiNoLock();
41 public void detachFromFile() {
48 public CharTable getCharTable() {
54 public LighterAST getLighterAST() {
55 final IFileElementType contentType = (IFileElementType)getElementType();
56 assert contentType instanceof ILightStubFileElementType:contentType; // method should not be called for such element types
59 return new FCTSBackedLighterAST(getCharTable(), ((ILightStubFileElementType<?>)contentType).parseContentsLight(this));
61 return new TreeBackedLighterAST(this);
64 public FileElement(@NotNull IElementType type, CharSequence text) {
68 @Deprecated // for 8.1 API compatibility
69 public FileElement(IElementType type) {
74 public PsiManagerEx getManager() {
75 CompositeElement treeParent = getTreeParent();
76 if (treeParent != null) return treeParent.getManager();
77 return (PsiManagerEx)getPsi().getManager(); //TODO: cache?
81 public ASTNode copyElement() {
82 PsiFileImpl psiElement = (PsiFileImpl)getPsi();
83 PsiFileImpl psiElementCopy = (PsiFileImpl)psiElement.copy();
84 return psiElementCopy.getTreeElement();
87 public void setCharTable(@NotNull CharTable table) {
92 public FileElement get() {