Stub for annotations

This commit is contained in:
Natalia.Ukhorskaya
2012-10-03 12:21:59 +04:00
parent 3cdc2363fa
commit ae6aa1b160
12 changed files with 244 additions and 10 deletions
@@ -57,7 +57,7 @@ public interface JetNodeTypes {
JetNodeType MODIFIER_LIST = new JetNodeType("MODIFIER_LIST", JetModifierList.class);
JetNodeType PRIMARY_CONSTRUCTOR_MODIFIER_LIST = new JetNodeType("PRIMARY_CONSTRUCTOR_MODIFIER_LIST", JetModifierList.class);
JetNodeType ANNOTATION = new JetNodeType("ANNOTATION", JetAnnotation.class);
JetNodeType ANNOTATION_ENTRY = new JetNodeType("ANNOTATION_ENTRY", JetAnnotationEntry.class);
IElementType ANNOTATION_ENTRY = JetStubElementTypes.ANNOTATION_ENTRY;
JetNodeType TYPE_ARGUMENT_LIST = new JetNodeType("TYPE_ARGUMENT_LIST", JetTypeArgumentList.class);
JetNodeType VALUE_ARGUMENT_LIST = new JetNodeType("VALUE_ARGUMENT_LIST", JetValueArgumentList.class);
@@ -17,9 +17,12 @@
package org.jetbrains.jet.lang.psi;
import com.intellij.lang.ASTNode;
import com.intellij.psi.stubs.IStubElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetNodeTypes;
import org.jetbrains.jet.lang.psi.stubs.PsiJetAnnotationStub;
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
import java.util.Collections;
import java.util.List;
@@ -27,11 +30,21 @@ import java.util.List;
/**
* @author max
*/
public class JetAnnotationEntry extends JetElementImpl implements JetCallElement {
public class JetAnnotationEntry extends JetElementImplStub<PsiJetAnnotationStub> implements JetCallElement {
public JetAnnotationEntry(@NotNull ASTNode node) {
super(node);
}
@NotNull
@Override
public IStubElementType getElementType() {
return JetStubElementTypes.ANNOTATION_ENTRY;
}
public JetAnnotationEntry(@NotNull PsiJetAnnotationStub stub) {
super(stub, JetStubElementTypes.ANNOTATION_ENTRY);
}
@Override
public void accept(@NotNull JetVisitorVoid visitor) {
visitor.visitAnnotationEntry(this);
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.psi.stubs;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.jet.lang.psi.JetAnnotationEntry;
public interface PsiJetAnnotationStub extends StubElement<JetAnnotationEntry> {
String getText();
}
@@ -0,0 +1,69 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.psi.stubs.elements;
import com.intellij.lang.ASTNode;
import com.intellij.psi.stubs.IndexSink;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.stubs.StubInputStream;
import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetAnnotationEntry;
import org.jetbrains.jet.lang.psi.stubs.PsiJetAnnotationStub;
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetAnnotationStubImpl;
import java.io.IOException;
public class JetAnnotationElementType extends JetStubElementType<PsiJetAnnotationStub, JetAnnotationEntry> {
public JetAnnotationElementType(@NotNull @NonNls String debugName) {
super(debugName);
}
@Override
public JetAnnotationEntry createPsiFromAst(@NotNull ASTNode node) {
return new JetAnnotationEntry(node);
}
@Override
public JetAnnotationEntry createPsi(@NotNull PsiJetAnnotationStub stub) {
return new JetAnnotationEntry(stub);
}
@Override
public PsiJetAnnotationStub createStub(@NotNull JetAnnotationEntry psi, StubElement parentStub) {
return new PsiJetAnnotationStubImpl(parentStub, JetStubElementTypes.ANNOTATION_ENTRY, psi.getText());
}
@Override
public void serialize(PsiJetAnnotationStub stub, StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getText());
}
@Override
public PsiJetAnnotationStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
StringRef text = dataStream.readName();
return new PsiJetAnnotationStubImpl(parentStub, JetStubElementTypes.ANNOTATION_ENTRY, text);
}
@Override
public void indexStub(PsiJetAnnotationStub stub, IndexSink sink) {
StubIndexServiceFactory.getInstance().indexAnnotation(stub, sink);
}
}
@@ -33,4 +33,5 @@ public interface JetStubElementTypes {
JetTypeParameterElementType TYPE_PARAMETER = new JetTypeParameterElementType("TYPE_PARAMETER");
JetTypeParameterListElementType TYPE_PARAMETER_LIST = new JetTypeParameterListElementType("TYPE_PARAMETER_LIST");
JetAnnotationElementType ANNOTATION_ENTRY = new JetAnnotationElementType("ANNOTATION_ENTRY");
}
@@ -17,10 +17,7 @@
package org.jetbrains.jet.lang.psi.stubs.elements;
import com.intellij.psi.stubs.IndexSink;
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
import org.jetbrains.jet.lang.psi.stubs.PsiJetObjectStub;
import org.jetbrains.jet.lang.psi.stubs.PsiJetPropertyStub;
import org.jetbrains.jet.lang.psi.stubs.*;
/**
* @author Nikolay Krasko
@@ -46,10 +43,15 @@ public interface StubIndexService {
@Override
public void indexProperty(PsiJetPropertyStub stub, IndexSink sink) {
}
@Override
public void indexAnnotation(PsiJetAnnotationStub stub, IndexSink sink) {
}
};
void indexClass(PsiJetClassStub stub, IndexSink sink);
void indexFunction(PsiJetFunctionStub stub, IndexSink sink);
void indexObject(PsiJetObjectStub stub, IndexSink sink);
void indexProperty(PsiJetPropertyStub stub, IndexSink sink);
void indexAnnotation(PsiJetAnnotationStub stub, IndexSink sink);
}
@@ -0,0 +1,51 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.psi.stubs.impl;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.stubs.StubBase;
import com.intellij.psi.stubs.StubElement;
import com.intellij.util.io.StringRef;
import org.jetbrains.jet.lang.psi.JetAnnotationEntry;
import org.jetbrains.jet.lang.psi.stubs.PsiJetAnnotationStub;
public class PsiJetAnnotationStubImpl extends StubBase<JetAnnotationEntry> implements PsiJetAnnotationStub {
private final StringRef text;
public PsiJetAnnotationStubImpl(StubElement parent, IStubElementType elementType, String text) {
this(parent, elementType, StringRef.fromString(text));
}
public PsiJetAnnotationStubImpl(StubElement parent, IStubElementType elementType, StringRef text) {
super(parent, elementType);
this.text = text;
}
@Override
public String getText() {
return text.getString();
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("PsiJetAnnotationStubImpl[");
builder.append("text=").append(getText());
builder.append("]");
return builder.toString();
}
}