update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / impl / java / stubs / JavaMethodElementType.java
blobbbfe191ba192f82075592ff6fc72f30f3dde67da
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.PsiAnnotationMemberValue;
24 import com.intellij.psi.PsiAnnotationMethod;
25 import com.intellij.psi.PsiMethod;
26 import com.intellij.psi.impl.cache.RecordUtil;
27 import com.intellij.psi.impl.cache.TypeInfo;
28 import com.intellij.psi.impl.compiled.ClsMethodImpl;
29 import com.intellij.psi.impl.java.stubs.impl.PsiMethodStubImpl;
30 import com.intellij.psi.impl.java.stubs.index.JavaMethodNameIndex;
31 import com.intellij.psi.impl.source.PsiAnnotationMethodImpl;
32 import com.intellij.psi.impl.source.PsiMethodImpl;
33 import com.intellij.psi.impl.source.tree.java.AnnotationMethodElement;
34 import com.intellij.psi.stubs.IndexSink;
35 import com.intellij.psi.stubs.StubElement;
36 import com.intellij.psi.stubs.StubOutputStream;
37 import com.intellij.psi.stubs.StubInputStream;
38 import com.intellij.util.io.StringRef;
39 import org.jetbrains.annotations.NonNls;
41 import java.io.IOException;
43 public class JavaMethodElementType extends JavaStubElementType<PsiMethodStub, PsiMethod> {
44 public JavaMethodElementType(@NonNls final String name) {
45 super(name);
48 public PsiMethod createPsi(final PsiMethodStub stub) {
49 if (isCompiled(stub)) {
50 return new ClsMethodImpl(stub);
52 else {
53 return stub.isAnnotationMethod() ? new PsiAnnotationMethodImpl(stub) : new PsiMethodImpl(stub);
57 public PsiMethod createPsi(final ASTNode node) {
58 if (node instanceof AnnotationMethodElement) {
59 return new PsiAnnotationMethodImpl(node);
61 else {
62 return new PsiMethodImpl(node);
66 public PsiMethodStub createStub(final PsiMethod psi, final StubElement parentStub) {
67 final byte flags = PsiMethodStubImpl.packFlags(psi.isConstructor(),
68 psi instanceof PsiAnnotationMethod,
69 psi.isVarArgs(),
70 RecordUtil.isDeprecatedByDocComment(psi),
71 RecordUtil.isDeprecatedByAnnotation(psi));
73 String defValueText = null;
74 if (psi instanceof PsiAnnotationMethod) {
75 PsiAnnotationMemberValue defaultValue = ((PsiAnnotationMethod)psi).getDefaultValue();
76 if (defaultValue != null) {
77 defValueText = defaultValue.getText();
81 return new PsiMethodStubImpl(parentStub, StringRef.fromString(psi.getName()),
82 TypeInfo.create(psi.getReturnTypeNoResolve(), psi.getReturnTypeElement()),
83 flags,
84 StringRef.fromString(defValueText));
87 public void serialize(final PsiMethodStub stub, final StubOutputStream dataStream) throws IOException {
88 dataStream.writeName(stub.getName());
89 TypeInfo.writeTYPE(dataStream, stub.getReturnTypeText(false));
90 dataStream.writeByte(((PsiMethodStubImpl)stub).getFlags());
91 if (stub.isAnnotationMethod()) {
92 dataStream.writeName(stub.getDefaultValueText());
96 public PsiMethodStub deserialize(final StubInputStream dataStream, final StubElement parentStub) throws IOException {
97 StringRef name = dataStream.readName();
98 final TypeInfo type = TypeInfo.readTYPE(dataStream, parentStub);
99 byte flags = dataStream.readByte();
100 final StringRef defaultMethodValue = PsiMethodStubImpl.isAnnotationMethod(flags) ? dataStream.readName() : null;
101 return new PsiMethodStubImpl(parentStub, name, type, flags, defaultMethodValue);
104 public void indexStub(final PsiMethodStub stub, final IndexSink sink) {
105 final String name = stub.getName();
106 if (name != null) {
107 sink.occurrence(JavaMethodNameIndex.KEY, name);
112 public String getId(final PsiMethodStub stub) {
113 final String name = stub.getName();
114 if (name != null) return name;
115 return super.getId(stub);