diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties b/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties index 574dd0e07a6f..dd5964be48be 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties @@ -363,3 +363,4 @@ expected.0.to.be.inline.constant=Expected ''{0}'' to be an inline constant cannot.assign.a.value.to.final.field.0=Cannot assign a value to final field ''{0}'' variable.0.might.not.have.been.initialized=Variable ''{0}'' might not have been initialized unexpected.symbol=Unexpected symbol +statement.expected=Statement expected diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GrHighlightUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GrHighlightUtil.java index 71d144e7e2f1..0cc8d4cda637 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GrHighlightUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GrHighlightUtil.java @@ -34,6 +34,7 @@ import org.jetbrains.plugins.groovy.lang.lexer.TokenSets; import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrClassInitializer; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrLabeledStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression; @@ -181,6 +182,9 @@ public class GrHighlightUtil { boolean reassigned = isReassigned((GrVariable)resolved); return reassigned ? REASSIGNED_LOCAL_VARIABLE : LOCAL_VARIABLE; } + else if (resolved instanceof GrLabeledStatement) { + return LABEL; + } return null; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GrKeywordAndDeclarationHighlighter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GrKeywordAndDeclarationHighlighter.java index a5041beaa7b9..bc3cd76177ab 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GrKeywordAndDeclarationHighlighter.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GrKeywordAndDeclarationHighlighter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -34,7 +34,6 @@ import org.jetbrains.plugins.groovy.lang.lexer.TokenSets; import org.jetbrains.plugins.groovy.lang.psi.GrNamedElement; import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrLabel; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationNameValuePair; import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel; @@ -47,7 +46,8 @@ import java.util.ArrayList; import java.util.List; import static com.intellij.codeInsight.daemon.impl.HighlightInfoType.INFORMATION; -import static org.jetbrains.plugins.groovy.highlighter.DefaultHighlighter.*; +import static org.jetbrains.plugins.groovy.highlighter.DefaultHighlighter.ANNOTATION; +import static org.jetbrains.plugins.groovy.highlighter.DefaultHighlighter.KEYWORD; /** * @author Max Medvedev @@ -81,9 +81,6 @@ public class GrKeywordAndDeclarationHighlighter extends TextEditorHighlightingPa } } else { - if (element instanceof GrLabel) { - addInfo(element, LABEL); - } super.visitElement(element); } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/bugs/GroovyLabeledStatementInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/bugs/GroovyLabeledStatementInspection.java index faaf3cddd8f7..8037ca7d1b1a 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/bugs/GroovyLabeledStatementInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/bugs/GroovyLabeledStatementInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -63,7 +63,7 @@ public class GroovyLabeledStatementInspection extends BaseInspection { public void visitLabeledStatement(GrLabeledStatement labeledStatement) { super.visitLabeledStatement(labeledStatement); - final String name = labeledStatement.getLabelName(); + final String name = labeledStatement.getName(); GrLabeledStatement existing = ResolveUtil.resolveLabeledStatement(name, labeledStatement, true); if (existing != null && PsiTreeUtil.isAncestor(existing, labeledStatement, true)) { registerError(labeledStatement.getLabel(), name); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java index 3281ec903b75..9850efa2ceeb 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -127,8 +127,8 @@ public class GroovyPostHighlightingPass extends TextEditorHighlightingPass { } if (deadCodeEnabled && - element instanceof GrNamedElement && - !PostHighlightingPass.isImplicitUsage((GrNamedElement)element, progress) && + element instanceof GrNamedElement && element instanceof PsiModifierListOwner && + !PostHighlightingPass.isImplicitUsage((PsiModifierListOwner)element, progress) && !GroovySuppressableInspectionTool.isElementToolSuppressedIn(element, GroovyUnusedDeclarationInspection.SHORT_NAME)) { PsiElement nameId = ((GrNamedElement)element).getNameIdentifierGroovy(); if (nameId.getNode().getElementType() == GroovyTokenTypes.mIDENT) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GroovyFindUsagesProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GroovyFindUsagesProvider.java index e89a6024ac1a..9ddb4debd422 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GroovyFindUsagesProvider.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GroovyFindUsagesProvider.java @@ -90,7 +90,7 @@ public class GroovyFindUsagesProvider implements FindUsagesProvider { return name; } } else if (element instanceof GrLabeledStatement) { - return ((GrLabeledStatement)element).getLabelName(); + return ((GrLabeledStatement)element).getName(); } else if (element instanceof PropertyForRename) { return ((PropertyForRename)element).getPropertyName(); } else if (element instanceof GrClosableBlock) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java index 3e692885ff00..0cf6955456b7 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java @@ -145,7 +145,7 @@ public class GroovyIndentProcessor extends GroovyElementVisitor { @Override public void visitLabeledStatement(GrLabeledStatement labeledStatement) { - if (myChildType == LABEL) { + if (myChildType == mIDENT) { CommonCodeStyleSettings.IndentOptions indentOptions = myBlock.getContext().getSettings().getIndentOptions(); if (indentOptions != null && indentOptions.LABEL_INDENT_ABSOLUTE) { myResult = Indent.getAbsoluteLabelIndent(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/declaration/GrChangeMemberVisibilityModifierBase.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/declaration/GrChangeMemberVisibilityModifierBase.java index a38bcd4eeb0e..89efd4e49d9b 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/declaration/GrChangeMemberVisibilityModifierBase.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/declaration/GrChangeMemberVisibilityModifierBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -52,7 +52,7 @@ public abstract class GrChangeMemberVisibilityModifierBase extends Intention { final PsiElement parent = element.getParent(); return parent instanceof GrMember && parent instanceof GrNamedElement && - (((GrNamedElement)parent).getNameIdentifierGroovy() == element || ((GrNamedElement)parent).getModifierList() == element) && + (((GrNamedElement)parent).getNameIdentifierGroovy() == element || ((GrMember)parent).getModifierList() == element) && ((GrMember)parent).getModifierList() != null && !((GrMember)parent).getModifierList().hasExplicitModifier(myModifier); } }; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/GroovyElementTypes.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/GroovyElementTypes.java index 171807dee85d..6cb0df6a87cc 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/GroovyElementTypes.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/GroovyElementTypes.java @@ -226,8 +226,6 @@ public interface GroovyElementTypes extends GroovyTokenTypes, GroovyDocElementTy GroovyElementType PATH_INDEX_PROPERTY = new GroovyElementType("Index property"); GroovyElementType PARENTHESIZED_EXPRESSION = new GroovyElementType("Parenthesized expression"); - // Plain label - GroovyElementType LABEL = new GroovyElementType("Label"); // Arguments GroovyElementType ARGUMENTS = new GroovyElementType("Arguments"); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/GroovyParser.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/GroovyParser.java index 1ebee6ff7a16..d12550a57d0f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/GroovyParser.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/GroovyParser.java @@ -247,7 +247,8 @@ public class GroovyParser implements PsiParser { if (parseSeparatorsWithoutLastNls(builder, plainStatement, until)) { return false; } - } else { + } + else { builder.error(GroovyBundle.message("wrong.statement")); assert builder.getTokenType() != mLCURLY && builder.getTokenType() != mRCURLY; builder.advanceLexer(); @@ -272,7 +273,8 @@ public class GroovyParser implements PsiParser { return true; } beforeNls.drop(); - } else { + } + else { break; } } @@ -334,7 +336,8 @@ public class GroovyParser implements PsiParser { if (SynchronizedStatement.parse(builder, this)) { synMarker.drop(); return true; - } else { + } + else { synMarker.rollbackTo(); } } @@ -373,24 +376,25 @@ public class GroovyParser implements PsiParser { if (BranchStatement.BRANCH_KEYWORDS.contains(builder.getTokenType())) { return BranchStatement.parse(builder, this); } - if (ParserUtils.lookAhead(builder, GroovyTokenTypes.mIDENT, GroovyTokenTypes.mCOLON)) { - return parseLabeledStatement(builder); + if (parseLabeledStatement(builder)) { + return true; } if (parseDeclaration(builder, false, false, null)) return true; return AssignmentExpression.parse(builder, this, true); - } /** * parses imports (marks them as not allowed), type definitions, methods, variables or fields (if isInClass), initializers (if isInClass), constructors * with corresponding typeDefinitionName - * + *
* If non of preceding elements was found rolls back and return false - * */ - public boolean parseDeclaration(@NotNull PsiBuilder builder, boolean isInClass, boolean isInAnnotation, @Nullable String typeDefinitionName) { + public boolean parseDeclaration(@NotNull PsiBuilder builder, + boolean isInClass, + boolean isInAnnotation, + @Nullable String typeDefinitionName) { PsiBuilder.Marker declMarker = builder.mark(); boolean modifiersParsed = Modifiers.parse(builder, this); @@ -419,7 +423,8 @@ public class GroovyParser implements PsiParser { return true; } - final IElementType declType = Declaration.parseAfterModifiers(builder, isInClass, isInAnnotation, typeDefinitionName, this, modifiersParsed); + final IElementType declType = + Declaration.parseAfterModifiers(builder, isInClass, isInAnnotation, typeDefinitionName, this, modifiersParsed); if (declType != WRONGWAY) { if (declType != null) { declMarker.done(declType); @@ -455,7 +460,8 @@ public class GroovyParser implements PsiParser { public boolean parseStatementWithImports(PsiBuilder builder) { if (ImportStatement.parse(builder, this)) { return true; - } else { + } + else { return parseStatement(builder, false); } } @@ -463,12 +469,22 @@ public class GroovyParser implements PsiParser { private boolean parseLabeledStatement(PsiBuilder builder) { PsiBuilder.Marker marker = builder.mark(); - ParserUtils.eatElement(builder, LABEL); - ParserUtils.getToken(builder, GroovyTokenTypes.mCOLON); + + if (!ParserUtils.getToken(builder, mIDENT) || !ParserUtils.getToken(builder, GroovyTokenTypes.mCOLON)) { + marker.rollbackTo(); + return false; + } + + final PsiBuilder.Marker nlsMarker = builder.mark(); ParserUtils.getToken(builder, GroovyTokenTypes.mNLS); - - parseStatement(builder, true); + if (parseStatement(builder, true)) { + nlsMarker.drop(); + } + else { + nlsMarker.rollbackTo(); + builder.error(GroovyBundle.message("statement.expected")); + } marker.done(LABELED_STATEMENT); return true; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/GroovyPsiCreator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/GroovyPsiCreator.java index 87059549a342..d8a16b70d684 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/GroovyPsiCreator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/GroovyPsiCreator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -25,7 +25,6 @@ import org.jetbrains.plugins.groovy.lang.groovydoc.psi.GroovyDocPsiCreator; import org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType; import org.jetbrains.plugins.groovy.lang.lexer.TokenSets; import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyASTPsiElementImpl; -import org.jetbrains.plugins.groovy.lang.psi.impl.auxiliary.GrLabelImpl; import org.jetbrains.plugins.groovy.lang.psi.impl.auxiliary.GrListOrMapImpl; import org.jetbrains.plugins.groovy.lang.psi.impl.auxiliary.GrThrowsClauseImpl; import org.jetbrains.plugins.groovy.lang.psi.impl.auxiliary.annotation.GrAnnotationArgumentListImpl; @@ -98,7 +97,6 @@ public class GroovyPsiCreator implements GroovyElementTypes { //Identifiers & literal if (elem == LITERAL) return new GrLiteralImpl(node); - if (elem == LABEL) return new GrLabelImpl(node); // if (elem.equals(IDENTIFIER)) return new GrIdentifierImpl(node); //Lists, maps etc... if (elem == LIST_OR_MAP) return new GrListOrMapImpl(node); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GrNamedElement.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GrNamedElement.java index 70275dca1303..e4901369e5e1 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GrNamedElement.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GrNamedElement.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -16,15 +16,14 @@ package org.jetbrains.plugins.groovy.lang.psi; -import com.intellij.psi.PsiModifierListOwner; -import com.intellij.psi.PsiNamedElement; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiNamedElement; import org.jetbrains.annotations.NotNull; /** * @author ven */ -public interface GrNamedElement extends PsiNamedElement, GroovyPsiElement, PsiModifierListOwner { +public interface GrNamedElement extends PsiNamedElement, GroovyPsiElement { @NotNull PsiElement getNameIdentifierGroovy(); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GroovyElementVisitor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GroovyElementVisitor.java index 08854d70c0f3..e362cba389ec 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GroovyElementVisitor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GroovyElementVisitor.java @@ -16,7 +16,6 @@ package org.jetbrains.plugins.groovy.lang.psi; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.*; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrLabel; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrThrowsClause; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList; @@ -212,10 +211,6 @@ public abstract class GroovyElementVisitor { visitExpression(expression); } - public void visitLabel(GrLabel label) { - visitElement(label); - } - public void visitArgumentList(GrArgumentList list) { visitElement(list); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GroovyPsiElementFactory.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GroovyPsiElementFactory.java index 33114bf2b7c5..9f370e032d95 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GroovyPsiElementFactory.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GroovyPsiElementFactory.java @@ -27,7 +27,6 @@ import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMemberReference; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocReferenceElement; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocTag; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrLabel; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation; import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature; @@ -228,8 +227,6 @@ public abstract class GroovyPsiElementFactory implements JVMElementFactory { public abstract GrMethod createConstructorFromText(String constructorName, CharSequence constructorText, @Nullable PsiElement context); - public abstract GrLabel createLabel(@NotNull String name); - public abstract GrDocComment createDocCommentFromText(String text) ; public abstract GrDocTag createDocTagFromText(String text) ; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/auxiliary/GrLabel.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/auxiliary/GrLabel.java deleted file mode 100644 index 4cac3e2c1fb9..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/auxiliary/GrLabel.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2000-2009 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.plugins.groovy.lang.psi.api.auxiliary; - -import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; - -/** - * @author ilyas - */ -public interface GrLabel extends GroovyPsiElement { - String getName(); -} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/GrLabeledStatement.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/GrLabeledStatement.java index 46c7ffbe7bd1..09977132e1bd 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/GrLabeledStatement.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/GrLabeledStatement.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -16,21 +16,22 @@ package org.jetbrains.plugins.groovy.lang.psi.api.statements; -import com.intellij.psi.PsiNamedElement; +import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrLabel; +import org.jetbrains.plugins.groovy.lang.psi.GrNamedElement; /** * @author ilyas */ -public interface GrLabeledStatement extends GrStatement, PsiNamedElement{ - @NotNull - String getLabelName(); - +public interface GrLabeledStatement extends GrStatement, GrNamedElement { @Nullable GrStatement getStatement(); @NotNull - GrLabel getLabel(); + PsiElement getLabel(); + + @NotNull + @Override + String getName(); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java index 71624fe26a78..f0528e88d0dd 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java @@ -41,7 +41,6 @@ import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMemberReference; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocReferenceElement; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocTag; import org.jetbrains.plugins.groovy.lang.psi.*; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrLabel; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation; import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature; @@ -501,14 +500,6 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory { return methods[0]; } - @Override - public GrLabel createLabel(@NotNull String name) { - GroovyFileBase file = createGroovyFileChecked(name + ": println()"); - GrTopStatement definition = file.getTopStatements()[0]; - assert definition instanceof GrLabeledStatement; - return ((GrLabeledStatement)definition).getLabel(); - } - @NotNull public GrMethod createMethodFromText(@NotNull String methodText, @Nullable PsiElement context) { GroovyFile file = createGroovyFile(methodText, false, context); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/GrLabelImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/GrLabelImpl.java deleted file mode 100644 index 72346b50c1ce..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/GrLabelImpl.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2000-2009 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.plugins.groovy.lang.psi.impl.auxiliary; - -import com.intellij.lang.ASTNode; -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes; -import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrLabel; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; -import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiElementImpl; - -/** - * @author ilyas - */ -public class GrLabelImpl extends GroovyPsiElementImpl implements GrLabel { - - public GrLabelImpl(@NotNull ASTNode node) { - super(node); - } - - public void accept(GroovyElementVisitor visitor) { - visitor.visitLabel(this); - } - - public String toString() { - return "Label"; - } - - public String getName() { - final PsiElement id = findChildByType(GroovyElementTypes.mIDENT); - assert id != null; - return id.getText(); - } -} \ No newline at end of file diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/GrLabelReference.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/GrLabelReference.java index 8bea5cd7cbff..4c1d287691f3 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/GrLabelReference.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/GrLabelReference.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -43,7 +43,7 @@ public class GrLabelReference implements PsiReference { public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException { if (element instanceof GrLabeledStatement) { - myStatement = handleElementRename(((GrLabeledStatement)element).getLabelName()); + myStatement = handleElementRename(((GrLabeledStatement)element).getName()); } throw new IncorrectOperationException("Can't bind not to labeled statement"); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrLabeledStatementImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrLabeledStatementImpl.java index 9b6721818b38..ceb4b228472f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrLabeledStatementImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrLabeledStatementImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -26,9 +26,9 @@ import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrLabel; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrLabeledStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiElementImpl; @@ -51,13 +51,12 @@ public class GrLabeledStatementImpl extends GroovyPsiElementImpl implements GrLa @NotNull public String getLabelName() { - final GrLabel label = getLabel(); - return label.getName(); + return getName(); } @NotNull - public GrLabel getLabel() { - final GrLabel label = findChildByClass(GrLabel.class); + public PsiElement getLabel() { + final PsiElement label = findChildByType(GroovyTokenTypes.mIDENT); assert label != null; return label; } @@ -69,7 +68,7 @@ public class GrLabeledStatementImpl extends GroovyPsiElementImpl implements GrLa public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, - PsiElement lastParent, + @Nullable PsiElement lastParent, @NotNull PsiElement place) { GrStatement statement = getStatement(); return statement == null || statement == lastParent || statement.processDeclarations(processor, state, lastParent, place); @@ -82,14 +81,22 @@ public class GrLabeledStatementImpl extends GroovyPsiElementImpl implements GrLa } public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException { - final GrLabel labelElement = getLabel(); - final GrLabel newLabel = GroovyPsiElementFactory.getInstance(getProject()).createLabel(name); + final PsiElement labelElement = getLabel(); + final PsiElement newLabel = GroovyPsiElementFactory.getInstance(getProject()).createReferenceNameFromText(name); labelElement.replace(newLabel); return this; } + @NotNull @Override public String getName() { - return getLabelName(); + final PsiElement label = getLabel(); + return label.getText(); + } + + @NotNull + @Override + public PsiElement getNameIdentifierGroovy() { + return getLabel(); } } \ No newline at end of file diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java index 64ddcf4d4879..d8ef7e40bec9 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java @@ -448,7 +448,7 @@ public class ResolveUtil { } private static boolean isApplicableLabelStatement(PsiElement element, String labelName) { - return ((element instanceof GrLabeledStatement && labelName.equals(((GrLabeledStatement)element).getLabelName()))); + return ((element instanceof GrLabeledStatement && labelName.equals(((GrLabeledStatement)element).getName()))); } @Nullable diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java index a2640eaa6376..0b5785a699ea 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -305,7 +305,7 @@ public class CodeBlockGenerator extends Generator { GenerationUtil.writeStatement(builder, context, labeledStatement, new StatementWriter() { @Override public void writeStatement(StringBuilder builder, ExpressionContext context) { - final String label = labeledStatement.getLabelName(); + final String label = labeledStatement.getName(); final GrStatement statement = labeledStatement.getStatement(); builder.append(label).append(": "); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/spock/SpockUtils.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/spock/SpockUtils.java index d68175b1de8d..6c46532b3606 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/spock/SpockUtils.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/spock/SpockUtils.java @@ -93,7 +93,7 @@ public class SpockUtils { while (true) { GrStatement statement = l.getStatement(); - if ("where".equals(l.getLabelName())) { + if ("where".equals(l.getName())) { elementUnderLabel = statement; break main; } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/StatementsParsingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/StatementsParsingTest.groovy index e21d0e154a5a..f4086fe387e7 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/StatementsParsingTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/StatementsParsingTest.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -100,6 +100,7 @@ public class StatementsParsingTest extends GroovyParsingTestCase { public void testKing_regex$king4() throws Throwable { doTest(); } public void testLabeled$label1() throws Throwable { doTest(); } public void testLabeled$label2() throws Throwable { doTest(); } + public void testLabeled$label3() throws Throwable { doTest(); } public void testLoop$while1() throws Throwable { doTest(); } public void testLoop$while2() throws Throwable { doTest(); } public void testLoop$while3() throws Throwable { doTest(); } diff --git a/plugins/groovy/testdata/parsing/groovy/statements/blocks/labeledClosure.test b/plugins/groovy/testdata/parsing/groovy/statements/blocks/labeledClosure.test index 56d996ab614b..f8e9e5c35e8f 100644 --- a/plugins/groovy/testdata/parsing/groovy/statements/blocks/labeledClosure.test +++ b/plugins/groovy/testdata/parsing/groovy/statements/blocks/labeledClosure.test @@ -2,8 +2,7 @@ L:{ x + y }.getClass() ----- Groovy script Labeled statement - Label - PsiElement(identifier)('L') + PsiElement(identifier)('L') PsiElement(:)(':') Block statement Open block diff --git a/plugins/groovy/testdata/parsing/groovy/statements/labeled/label1.test b/plugins/groovy/testdata/parsing/groovy/statements/labeled/label1.test index db6b6f12b705..d1c775d027aa 100644 --- a/plugins/groovy/testdata/parsing/groovy/statements/labeled/label1.test +++ b/plugins/groovy/testdata/parsing/groovy/statements/labeled/label1.test @@ -6,8 +6,7 @@ Groovy script PsiElement(Integer)('1') PsiElement(new line)('\n') Labeled statement - Label - PsiElement(identifier)('l') + PsiElement(identifier)('l') PsiElement(:)(':') PsiWhiteSpace(' ') Block statement diff --git a/plugins/groovy/testdata/parsing/groovy/statements/labeled/label2.test b/plugins/groovy/testdata/parsing/groovy/statements/labeled/label2.test index 6e1b5feaa64f..e47598936d9c 100644 --- a/plugins/groovy/testdata/parsing/groovy/statements/labeled/label2.test +++ b/plugins/groovy/testdata/parsing/groovy/statements/labeled/label2.test @@ -3,8 +3,7 @@ myLabel: ----- Groovy script Labeled statement - Label - PsiElement(identifier)('myLabel') + PsiElement(identifier)('myLabel') PsiElement(:)(':') PsiElement(new line)('\n') Additive expression diff --git a/plugins/groovy/testdata/parsing/groovy/statements/labeled/label3.test b/plugins/groovy/testdata/parsing/groovy/statements/labeled/label3.test new file mode 100644 index 000000000000..8744f1ced414 --- /dev/null +++ b/plugins/groovy/testdata/parsing/groovy/statements/labeled/label3.test @@ -0,0 +1,8 @@ +myLabel: +----- +Groovy script + Labeled statement + PsiElement(identifier)('myLabel') + PsiElement(:)(':') + PsiErrorElement:Statement expected +