Stubs - Make JetClass use stub base element
This commit is contained in:
@@ -20,7 +20,6 @@ import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.StubBasedPsiElement;
|
||||
import com.intellij.psi.stubs.IStubElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -38,18 +37,16 @@ import java.util.List;
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetClass extends JetNotStubbedTypeParameterListOwner
|
||||
implements JetClassOrObject, JetModifierListOwner, StubBasedPsiElement<PsiJetClassStub> {
|
||||
|
||||
private PsiJetClassStub stub;
|
||||
public class JetClass extends JetStubTypeParameterListOwner<PsiJetClassStub>
|
||||
implements JetClassOrObject, JetModifierListOwner {
|
||||
|
||||
public JetClass(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
//public JetClass(@NotNull final PsiJetClassStub stub) {
|
||||
// this.stub = stub;
|
||||
//}
|
||||
public JetClass(@NotNull final PsiJetClassStub stub) {
|
||||
super(stub, JetStubElementTypes.CLASS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JetDeclaration> getDeclarations() {
|
||||
@@ -154,16 +151,9 @@ public class JetClass extends JetNotStubbedTypeParameterListOwner
|
||||
@NotNull
|
||||
@Override
|
||||
public IStubElementType getElementType() {
|
||||
// TODO (stubs)
|
||||
return JetStubElementTypes.CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiJetClassStub getStub() {
|
||||
// TODO (stubs)
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() throws IncorrectOperationException {
|
||||
JetPsiUtil.deleteClass(this);
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.jet.lang.psi;
|
||||
import com.intellij.extapi.psi.StubBasedPsiElementBase;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.StubBasedPsiElement;
|
||||
import com.intellij.psi.stubs.IStubElementType;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
@@ -49,6 +50,21 @@ abstract class JetStubDeclaration<T extends StubElement> extends StubBasedPsiEle
|
||||
return modifierList != null && modifierList.hasModifier(modifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getNode().getElementType().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void accept(@NotNull PsiElementVisitor visitor) {
|
||||
if (visitor instanceof JetVisitorVoid) {
|
||||
accept((JetVisitorVoid) visitor);
|
||||
}
|
||||
else {
|
||||
visitor.visitElement(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <D> void acceptChildren(@NotNull JetTreeVisitor<D> visitor, D data) {
|
||||
PsiElement child = getFirstChild();
|
||||
@@ -62,11 +78,11 @@ abstract class JetStubDeclaration<T extends StubElement> extends StubBasedPsiEle
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull JetVisitorVoid visitor) {
|
||||
visitor.visitExpression(this);
|
||||
visitor.visitJetElement(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitExpression(this, data);
|
||||
return visitor.visitJetElement(this, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.stubs.IStubElementType;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
abstract class JetStubNamedDeclaration<T extends StubElement> extends JetStubDeclaration<T> implements JetNamedDeclaration {
|
||||
public JetStubNamedDeclaration(@NotNull T stub, @NotNull IStubElementType nodeType) {
|
||||
super(stub, nodeType);
|
||||
}
|
||||
|
||||
public JetStubNamedDeclaration(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
PsiElement identifier = getNameIdentifier();
|
||||
if (identifier != null) {
|
||||
String text = identifier.getText();
|
||||
return text != null ? JetPsiUtil.unquoteIdentifier(text) : null;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Name getNameAsName() {
|
||||
String name = getName();
|
||||
return name != null ? Name.identifier(name) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Name getNameAsSafeName() {
|
||||
return JetPsiUtil.safeName(getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement getNameIdentifier() {
|
||||
return findChildByType(JetTokens.IDENTIFIER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
||||
return getNameIdentifier().replace(JetPsiFactory.createNameIdentifier(getProject(), name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTextOffset() {
|
||||
PsiElement identifier = getNameIdentifier();
|
||||
return identifier != null ? identifier.getTextRange().getStartOffset() : getTextRange().getStartOffset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isScriptDeclaration() {
|
||||
return getScript() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JetScript getScript() {
|
||||
if (getParent() != null && getParent().getParent() instanceof JetScript) {
|
||||
return (JetScript) getParent().getParent();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.stubs.IStubElementType;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
abstract class JetStubTypeParameterListOwner<T extends StubElement> extends JetStubNamedDeclaration<T> implements JetTypeParameterListOwner {
|
||||
public JetStubTypeParameterListOwner(@NotNull T stub, @NotNull IStubElementType nodeType) {
|
||||
super(stub, nodeType);
|
||||
}
|
||||
|
||||
public JetStubTypeParameterListOwner(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JetTypeParameterList getTypeParameterList() {
|
||||
return (JetTypeParameterList) findChildByType(JetNodeTypes.TYPE_PARAMETER_LIST);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JetTypeConstraintList getTypeConstraintList() {
|
||||
return (JetTypeConstraintList) findChildByType(JetNodeTypes.TYPE_CONSTRAINT_LIST);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<JetTypeConstraint> getTypeConstraints() {
|
||||
JetTypeConstraintList typeConstraintList = getTypeConstraintList();
|
||||
if (typeConstraintList == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return typeConstraintList.getConstraints();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<JetTypeParameter> getTypeParameters() {
|
||||
JetTypeParameterList list = getTypeParameterList();
|
||||
if (list == null) return Collections.emptyList();
|
||||
|
||||
return list.getParameters();
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -51,8 +51,7 @@ public class JetClassElementType extends JetStubElementType<PsiJetClassStub, Jet
|
||||
|
||||
@Override
|
||||
public JetClass createPsi(@NotNull PsiJetClassStub stub) {
|
||||
// return new JetClass(stub);
|
||||
return null;
|
||||
return new JetClass(stub);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user