diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclaration.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclaration.java index a4df289944c..3e2caee7ba2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclaration.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclaration.java @@ -16,17 +16,8 @@ package org.jetbrains.jet.lang.psi; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lexer.JetToken; - /** * @author Nikolay Krasko */ public interface JetDeclaration extends JetExpression, JetModifierListOwner { - @Override - @Nullable - JetModifierList getModifierList(); - - @Override - boolean hasModifier(JetToken modifier); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetElement.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetElement.java index 02d88c7bbe1..fb14efe3578 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetElement.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetElement.java @@ -1,3 +1,19 @@ +/* + * 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.psi.NavigatablePsiElement; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetElementImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetElementImpl.java index 69505a2e3f8..03a016f97d3 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetElementImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetElementImpl.java @@ -69,7 +69,7 @@ public class JetElementImpl extends ASTWrapperPsiElement implements JetElement { public void acceptChildren(@NotNull JetTreeVisitor visitor, D data) { PsiElement child = getFirstChild(); while (child != null) { - if (child instanceof JetElementImpl) { + if (child instanceof JetElement) { ((JetElement) child).accept(visitor, data); } child = child.getNextSibling(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclaration.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclaration.java index b620b77a769..f9fd37bd073 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclaration.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclaration.java @@ -1,89 +1,19 @@ -/* - * 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.PsiNameIdentifierOwner; -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 max + * @author Nikolay Krasko */ -public abstract class JetNamedDeclaration extends JetDeclarationImpl implements PsiNameIdentifierOwner, JetStatementExpression, JetNamed { - public JetNamedDeclaration(@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; - } - +public interface JetNamedDeclaration extends JetDeclaration, PsiNameIdentifierOwner, JetStatementExpression, JetNamed { @NotNull - public Name getNameAsSafeName() { - return JetPsiUtil.safeName(getName()); - } + Name getNameAsSafeName(); - @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(); - } - - public boolean isScriptDeclaration() { - return getScript() != null; - } + boolean isScriptDeclaration(); @Nullable - public JetScript getScript() { - if (getParent() != null && getParent().getParent() instanceof JetScript) { - return (JetScript) getParent().getParent(); - } - else { - return null; - } - } + JetScript getScript(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNotStubbedNamedDeclaration.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNotStubbedNamedDeclaration.java new file mode 100644 index 00000000000..943b9f45b91 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNotStubbedNamedDeclaration.java @@ -0,0 +1,92 @@ +/* + * 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.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 max + */ +@Deprecated +abstract class JetNotStubbedNamedDeclaration extends JetDeclarationImpl implements JetNamedDeclaration { + public JetNotStubbedNamedDeclaration(@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; + } + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetObjectDeclaration.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetObjectDeclaration.java index 7c93e85125b..3d5d53dd805 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetObjectDeclaration.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetObjectDeclaration.java @@ -31,7 +31,7 @@ import java.util.List; /** * @author abreslav */ -public class JetObjectDeclaration extends JetNamedDeclaration implements JetClassOrObject { +public class JetObjectDeclaration extends JetNotStubbedNamedDeclaration implements JetClassOrObject { public JetObjectDeclaration(@NotNull ASTNode node) { super(node); } @@ -123,4 +123,9 @@ public class JetObjectDeclaration extends JetNamedDeclaration implements JetClas public void delete() throws IncorrectOperationException { JetPsiUtil.deleteClass(this); } + + //@Override + //public ItemPresentation getPresentation() { + // return ItemPresentationProviders.getItemPresentation(this); + //} } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetObjectDeclarationName.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetObjectDeclarationName.java index ea60153b3f6..7de233bcd86 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetObjectDeclarationName.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetObjectDeclarationName.java @@ -22,7 +22,7 @@ import org.jetbrains.annotations.NotNull; /** * @author abreslav */ -public class JetObjectDeclarationName extends JetNamedDeclaration { +public class JetObjectDeclarationName extends JetNotStubbedNamedDeclaration { public JetObjectDeclarationName(@NotNull ASTNode node) { super(node); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameter.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameter.java index b9f3d8fb16b..0b7efc45bf0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameter.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameter.java @@ -25,7 +25,7 @@ import org.jetbrains.jet.lexer.JetTokens; /** * @author max */ -public class JetParameter extends JetNamedDeclaration { +public class JetParameter extends JetNotStubbedNamedDeclaration { public JetParameter(@NotNull ASTNode node) { super(node); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java index cf249e15c53..21e1fe639b1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java @@ -180,7 +180,7 @@ public class JetPsiUtil { if (parent instanceof JetFile) { firstPart = getFQName((JetFile) parent); } - else if (parent instanceof JetNamedDeclaration) { + else if (parent instanceof JetNotStubbedNamedDeclaration) { firstPart = getFQName((JetNamedDeclaration) parent); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetStubDeclaration.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetStubDeclaration.java new file mode 100644 index 00000000000..328507a2407 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetStubDeclaration.java @@ -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.extapi.psi.StubBasedPsiElementBase; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.stubs.IStubElementType; +import com.intellij.psi.stubs.StubElement; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.JetNodeTypes; +import org.jetbrains.jet.lexer.JetToken; + +/** + * @author Nikolay Krasko + */ +abstract class JetStubDeclaration extends StubBasedPsiElementBase implements JetDeclaration { + public JetStubDeclaration(@NotNull T stub, @NotNull IStubElementType nodeType) { + super(stub, nodeType); + } + + public JetStubDeclaration(@NotNull ASTNode node) { + super(node); + } + + @Override + public JetModifierList getModifierList() { + return (JetModifierList) findChildByType(JetNodeTypes.MODIFIER_LIST); + } + + @Override + public boolean hasModifier(JetToken modifier) { + JetModifierList modifierList = getModifierList(); + return modifierList != null && modifierList.hasModifier(modifier); + } + + @Override + public void acceptChildren(@NotNull JetTreeVisitor visitor, D data) { + PsiElement child = getFirstChild(); + while (child != null) { + if (child instanceof JetElement) { + ((JetElement) child).accept(visitor, data); + } + child = child.getNextSibling(); + } + } + + @Override + public void accept(@NotNull JetVisitorVoid visitor) { + visitor.visitExpression(this); + } + + @Override + public R accept(@NotNull JetVisitor visitor, D data) { + return visitor.visitExpression(this, data); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeParameter.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeParameter.java index 8bf602556e9..93b1f351c01 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeParameter.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeParameter.java @@ -26,7 +26,7 @@ import org.jetbrains.jet.lexer.JetTokens; /** * @author max */ -public class JetTypeParameter extends JetNamedDeclaration { +public class JetTypeParameter extends JetNotStubbedNamedDeclaration { public JetTypeParameter(@NotNull ASTNode node) { super(node); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeParameterListOwner.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeParameterListOwner.java index 96058c30ede..3e32b92e6f1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeParameterListOwner.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeParameterListOwner.java @@ -27,7 +27,7 @@ import java.util.List; /** * @author max */ -public class JetTypeParameterListOwner extends JetNamedDeclaration { +public class JetTypeParameterListOwner extends JetNotStubbedNamedDeclaration { public JetTypeParameterListOwner(@NotNull ASTNode node) { super(node); }