From da1aab6e432f743420f71a16006c9dea8e02b695 Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 9 Mar 2011 11:00:29 +0100 Subject: [PATCH 1/7] introduce parameter: correct introduce parameter and remove unused from the enclosing method --- .../OldReferenceResolver.java | 7 ++--- .../afterEnclosingWithParamDeletion.java | 28 +++++++++++++++++++ .../beforeEnclosingWithParamDeletion.java | 28 +++++++++++++++++++ .../refactoring/IntroduceParameterTest.java | 24 ++++++++++++++++ 4 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 java/java-tests/testData/refactoring/introduceParameter/afterEnclosingWithParamDeletion.java create mode 100644 java/java-tests/testData/refactoring/introduceParameter/beforeEnclosingWithParamDeletion.java diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/OldReferenceResolver.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/OldReferenceResolver.java index efd4672e9f5e..1ca50aad8094 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/OldReferenceResolver.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/OldReferenceResolver.java @@ -110,7 +110,7 @@ public class OldReferenceResolver { final JavaResolveResult adv = oldRef.advancedResolve(false); final PsiElement scope = getClassContainingResolve(adv); final PsiClass clss = PsiTreeUtil.getParentOfType(oldExpr, PsiClass.class); - if (clss != null && scope != null && PsiTreeUtil.isAncestor(clss, scope, false)) { + if (clss != null && scope != null ) { final PsiElement subj = adv.getElement(); @@ -118,7 +118,6 @@ public class OldReferenceResolver { // Parameters if (subj instanceof PsiParameter) { PsiParameterList parameterList = myMethodToReplaceIn.getParameterList(); - PsiParameter[] parameters = parameterList.getParameters(); if (subj.getParent() != parameterList) return; int index = parameterList.getParameterIndex((PsiParameter)subj); @@ -133,7 +132,7 @@ public class OldReferenceResolver { } } // "naked" field and methods (should become qualified) - else if ((subj instanceof PsiField || subj instanceof PsiMethod) && oldRef.getQualifierExpression() == null) { + else if ((subj instanceof PsiField || subj instanceof PsiMethod) && oldRef.getQualifierExpression() == null && PsiTreeUtil.isAncestor(clss, scope, false)) { boolean isStatic = subj instanceof PsiField && ((PsiField)subj).hasModifierProperty(PsiModifier.STATIC) || subj instanceof PsiMethod && ((PsiMethod)subj).hasModifierProperty(PsiModifier.STATIC); @@ -151,7 +150,7 @@ public class OldReferenceResolver { } } - if (subj instanceof PsiField) { + if (subj instanceof PsiField && PsiTreeUtil.isAncestor(clss, scope, false)) { // probably replacing field with a getter if (myReplaceFieldsWithGetters != IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE) { if (myReplaceFieldsWithGetters == IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL || diff --git a/java/java-tests/testData/refactoring/introduceParameter/afterEnclosingWithParamDeletion.java b/java/java-tests/testData/refactoring/introduceParameter/afterEnclosingWithParamDeletion.java new file mode 100644 index 000000000000..1216026ab11f --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameter/afterEnclosingWithParamDeletion.java @@ -0,0 +1,28 @@ +/* + * Copyright 2000-2011 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. + */ +class AAAA { + void foo() { + sampleEnclosing("A" + ""); + } + + private void sampleEnclosing(final String anObject) { + new AAAA() { + void bar() { + System.out.println(anObject); + } + }.bar(); + } +} diff --git a/java/java-tests/testData/refactoring/introduceParameter/beforeEnclosingWithParamDeletion.java b/java/java-tests/testData/refactoring/introduceParameter/beforeEnclosingWithParamDeletion.java new file mode 100644 index 000000000000..231920153098 --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameter/beforeEnclosingWithParamDeletion.java @@ -0,0 +1,28 @@ +/* + * Copyright 2000-2011 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. + */ +class AAAA { + void foo() { + sampleEnclosing("A"); + } + + private void sampleEnclosing(final String s) { + new AAAA() { + void bar() { + System.out.println(s + ""); + } + }.bar(); + } +} diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java index c193eeae4d9e..30481aacf6ca 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java @@ -28,6 +28,8 @@ import gnu.trove.TIntArrayList; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; +import java.util.List; + @TestDataPath("$CONTENT_ROOT/testData") public class IntroduceParameterTest extends LightCodeInsightTestCase { @Override @@ -270,6 +272,12 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase { checkResultByFile("/refactoring/introduceParameter/after" + getTestName(false) + ".java"); } + public void testEnclosingWithParamDeletion() throws Exception { + configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java"); + perform(true, 0, "anObject", false, true, true, false, 1); + checkResultByFile("/refactoring/introduceParameter/after" + getTestName(false) + ".java"); + } + private static boolean perform(boolean replaceAllOccurences, int replaceFieldsWithGetters, @NonNls String parameterName, @@ -277,6 +285,18 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase { boolean declareFinal, final boolean removeUnusedParameters, final boolean generateDelegate) { + return perform(replaceAllOccurences, replaceFieldsWithGetters, parameterName, searchForSuper, declareFinal, removeUnusedParameters, + generateDelegate, 0); + } + + private static boolean perform(boolean replaceAllOccurences, + int replaceFieldsWithGetters, + @NonNls String parameterName, + boolean searchForSuper, + boolean declareFinal, + final boolean removeUnusedParameters, + final boolean generateDelegate, + int enclosingLevel) { int startOffset = myEditor.getSelectionModel().getSelectionStart(); int endOffset = myEditor.getSelectionModel().getSelectionEnd(); @@ -294,6 +314,10 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase { PsiMethod method = Util.getContainingMethod(context); if (method == null) return false; + final List methods = IntroduceParameterHandler.getEnclosingMethods(method); + assertTrue(methods.size() > enclosingLevel); + method = methods.get(enclosingLevel); + final PsiMethod methodToSearchFor; if (searchForSuper) { methodToSearchFor = method.findDeepestSuperMethod(); From 2a951607158e8a229260f85de4545c3d680e1aba Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 9 Mar 2011 12:04:49 +0100 Subject: [PATCH 2/7] ui cleanup --- .../InplaceIntroduceParameterPopup.java | 26 ++++++++++++------- .../IntroduceParameterHandler.java | 5 ++-- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java index b94db818fdaf..32494482c0b3 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java @@ -45,6 +45,7 @@ import com.intellij.refactoring.introduceVariable.VariableInplaceIntroducer; import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer; import com.intellij.refactoring.ui.TypeSelectorManager; import com.intellij.refactoring.ui.TypeSelectorManagerImpl; +import com.intellij.ui.TitlePanel; import com.intellij.ui.awt.RelativePoint; import com.intellij.usageView.UsageInfo; import gnu.trove.TIntArrayList; @@ -107,10 +108,16 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { myExprText = myExpr != null ? myExpr.getText() : null; myWholePanel = new JPanel(new GridBagLayout()); - myWholePanel.setBorder(BorderFactory.createTitledBorder(IntroduceParameterHandler.REFACTORING_NAME)); + myWholePanel.setBorder(null); final GridBagConstraints gc = - new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0); + new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0); + final TitlePanel titlePanel = new TitlePanel(); + titlePanel.setBorder(null); + titlePanel.setText(IntroduceParameterHandler.REFACTORING_NAME); + myWholePanel.add(titlePanel, gc); + + gc.insets = new Insets(5, 5, 5, 0); if (myOccurrences.length > 1 && !myIsInvokedOnDeclaration) { gc.gridy++; createOccurrencesCb(gc, myWholePanel, myOccurrences.length); @@ -395,13 +402,14 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { private void showBalloon() { final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createBalloonBuilder(myWholePanel); - balloonBuilder.setFadeoutTime(0); - balloonBuilder.setFillColor(IdeTooltipManager.GRAPHITE_COLOR); - balloonBuilder.setAnimationCycle(0); - balloonBuilder.setHideOnClickOutside(false); - balloonBuilder.setHideOnKeyOutside(false); - balloonBuilder.setHideOnAction(false); - balloonBuilder.setCloseButtonEnabled(true); + balloonBuilder.setFadeoutTime(0) + .setFillColor(IdeTooltipManager.GRAPHITE_COLOR) + .setAnimationCycle(0) + .setHideOnClickOutside(false) + .setHideOnKeyOutside(false) + .setHideOnAction(false) + .setCloseButtonEnabled(true); + final RelativePoint target = JBPopupFactory.getInstance().guessBestPopupLocation(myEditor); final Point screenPoint = target.getScreenPoint(); myBalloon = balloonBuilder.createBalloon(); diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java index 463b38926bd7..ab68e187b33f 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java @@ -171,7 +171,6 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R final List validEnclosingMethods, final Introducer introducer) { final JPanel panel = new JPanel(new BorderLayout()); - panel.setBorder(IdeBorderFactory.createRoundedBorder()); final JCheckBox superMethod = new JCheckBox("Choose base method", true); superMethod.setMnemonic('b'); panel.add(superMethod, BorderLayout.SOUTH); @@ -191,7 +190,9 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R } }); updateView(validEnclosingMethods.get(0), editor, attributes, highlighters, superMethod); - panel.add(ScrollPaneFactory.createScrollPane(list), BorderLayout.CENTER); + final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(list); + scrollPane.setBorder(null); + panel.add(scrollPane, BorderLayout.CENTER); final List> keyboardActions = Collections.singletonList(Pair.create(new ActionListener() { From 06133feca80745d7a8cdcd06d89cb0dd2ad55c3e Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Wed, 9 Mar 2011 14:12:17 +0300 Subject: [PATCH 3/7] Fix: IDEA-66363 (Plugin Dialog: speed search works incorrect if search key contains '-') --- .../ide/ui/search/PorterStemmerUtil.java | 12 ++++---- .../intellij/ide/ui/search/SearchUtil.java | 2 +- .../SearchableOptionsRegistrarImpl.java | 28 ++++++++----------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/search/PorterStemmerUtil.java b/platform/platform-impl/src/com/intellij/ide/ui/search/PorterStemmerUtil.java index c1dc0df8495d..7bf8e2ee5fa7 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/search/PorterStemmerUtil.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/search/PorterStemmerUtil.java @@ -28,19 +28,19 @@ public class PorterStemmerUtil { // check for zero length final int strLen = str.length(); if (strLen > 0) { - int lastDigit = -1; + int lastNonLetter = -1; for (int i = 0; i < strLen; ++i) { char c = str.charAt(i); - if (Character.isDigit(c)) { - lastDigit = i; + if (Character.isDigit(c) || c == '-' || c == '_') { + lastNonLetter = i; } else if (!Character.isLetter(c)) { return null; } } - ++lastDigit; - if (lastDigit > 0 && lastDigit < strLen) { - return str.substring(0, lastDigit) + stemString(str.substring(lastDigit)); + ++lastNonLetter; + if (lastNonLetter > 0 && lastNonLetter < strLen) { + return str.substring(0, lastNonLetter) + stemString(str.substring(lastNonLetter)); } return stemString(str); } diff --git a/platform/platform-impl/src/com/intellij/ide/ui/search/SearchUtil.java b/platform/platform-impl/src/com/intellij/ide/ui/search/SearchUtil.java index 4bcb43406275..e69d72a19c8c 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/search/SearchUtil.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/search/SearchUtil.java @@ -447,7 +447,7 @@ public class SearchUtil { final String filter) { if (pos < end) { final Set filters = SearchableOptionsRegistrar.getInstance().getProcessedWords(filter); - final String[] words = text.substring(pos, end).split("[\\W&&[^_-]]"); + final String[] words = text.substring(pos, end).split("[\\W&&[^-]]+"); for (String word : words) { if (filters.contains(PorterStemmerUtil.stem(word.toLowerCase()))) { selectedWords.add(word); diff --git a/platform/platform-impl/src/com/intellij/ide/ui/search/SearchableOptionsRegistrarImpl.java b/platform/platform-impl/src/com/intellij/ide/ui/search/SearchableOptionsRegistrarImpl.java index 5f2b23b5132b..8e069a96fdf9 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/search/SearchableOptionsRegistrarImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/search/SearchableOptionsRegistrarImpl.java @@ -67,7 +67,7 @@ public class SearchableOptionsRegistrarImpl extends SearchableOptionsRegistrar { private static final Logger LOG = Logger.getInstance("#com.intellij.ide.ui.search.SearchableOptionsRegistrarImpl"); public static final int LOAD_FACTOR = 20; @NonNls - private static final Pattern REG_EXP = Pattern.compile("[\\W&&[^_-]]"); + private static final Pattern REG_EXP = Pattern.compile("[\\W&&[^-]]+"); @SuppressWarnings({"HardCodedStringLiteral"}) public SearchableOptionsRegistrarImpl() { @@ -360,14 +360,12 @@ public class SearchableOptionsRegistrarImpl extends SearchableOptionsRegistrar { Set result = new HashSet(); @NonNls final String toLowerCase = text.toLowerCase(); final String[] options = REG_EXP.split(toLowerCase); - if (options != null) { - for (String opt : options) { - if (opt == null) continue; - if (isStopWord(opt)) continue; - final String processed = PorterStemmerUtil.stem(opt); - if (isStopWord(processed)) continue; - result.add(opt); - } + for (String opt : options) { + if (isStopWord(opt)) continue; + final String processed = PorterStemmerUtil.stem(opt); + assert processed != null; + if (isStopWord(processed)) continue; + result.add(opt); } return result; } @@ -376,13 +374,11 @@ public class SearchableOptionsRegistrarImpl extends SearchableOptionsRegistrar { Set result = new HashSet(); @NonNls final String toLowerCase = text.toLowerCase(); final String[] options = REG_EXP.split(toLowerCase); - if (options != null) { - for (String opt : options) { - if (isStopWord(opt)) continue; - opt = PorterStemmerUtil.stem(opt); - if (opt == null) continue; - result.add(opt); - } + for (String opt : options) { + if (isStopWord(opt)) continue; + opt = PorterStemmerUtil.stem(opt); + assert opt != null; + result.add(opt); } return result; } From 5a064c1a41dde5f6f2444ac21d302d581b25b41a Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 9 Mar 2011 12:20:28 +0100 Subject: [PATCH 4/7] fix groovy reparse failing when typing 'def' or 'if' before 'return' inside switch case block --- .../groovy/lang/parser/GroovyParser.java | 89 +++++++++------ .../statements/declaration/Declaration.java | 80 ++++++++------ .../statements/imports/ImportStatement.java | 11 +- .../typeDefinitions/TypeDefinition.java | 28 +++-- .../groovy/lang/GroovyHighlightingTest.java | 17 --- .../lang/parser/GroovyReparseTest.groovy | 102 ++++++++++++++++++ .../groovy/expressions/errors/err_final.test | 14 +-- .../parsing/groovy/generics/err3.test | 2 - .../parsing/groovy/statements/ifstmt/if2.test | 7 +- .../statements/tuples/doubleParens.test | 8 +- .../statements/tuples/nestedTupleUnsupp.test | 8 +- .../CodeBlockReparse_after.txt} | 0 .../CodeBlockReparse_before.txt} | 0 .../testdata/reparse/SwitchCaseDef_after.txt | 50 +++++++++ .../testdata/reparse/SwitchCaseDef_before.txt | 44 ++++++++ .../testdata/reparse/SwitchCaseDo_after.txt | 47 ++++++++ .../testdata/reparse/SwitchCaseDo_before.txt | 44 ++++++++ .../testdata/reparse/SwitchCaseFor_after.txt | 49 +++++++++ .../testdata/reparse/SwitchCaseFor_before.txt | 44 ++++++++ .../testdata/reparse/SwitchCaseIf_after.txt | 49 +++++++++ .../testdata/reparse/SwitchCaseIf_before.txt | 44 ++++++++ .../reparse/SwitchCaseSwitch_after.txt | 49 +++++++++ .../reparse/SwitchCaseSwitch_before.txt | 44 ++++++++ .../reparse/SwitchCaseWhile_after.txt | 49 +++++++++ .../reparse/SwitchCaseWhile_before.txt | 44 ++++++++ 25 files changed, 810 insertions(+), 113 deletions(-) create mode 100644 plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/GroovyReparseTest.groovy rename plugins/groovy/testdata/{highlighting/CodeBlockReparse2.txt => reparse/CodeBlockReparse_after.txt} (100%) rename plugins/groovy/testdata/{highlighting/CodeBlockReparse1.txt => reparse/CodeBlockReparse_before.txt} (100%) create mode 100644 plugins/groovy/testdata/reparse/SwitchCaseDef_after.txt create mode 100644 plugins/groovy/testdata/reparse/SwitchCaseDef_before.txt create mode 100644 plugins/groovy/testdata/reparse/SwitchCaseDo_after.txt create mode 100644 plugins/groovy/testdata/reparse/SwitchCaseDo_before.txt create mode 100644 plugins/groovy/testdata/reparse/SwitchCaseFor_after.txt create mode 100644 plugins/groovy/testdata/reparse/SwitchCaseFor_before.txt create mode 100644 plugins/groovy/testdata/reparse/SwitchCaseIf_after.txt create mode 100644 plugins/groovy/testdata/reparse/SwitchCaseIf_before.txt create mode 100644 plugins/groovy/testdata/reparse/SwitchCaseSwitch_after.txt create mode 100644 plugins/groovy/testdata/reparse/SwitchCaseSwitch_before.txt create mode 100644 plugins/groovy/testdata/reparse/SwitchCaseWhile_after.txt create mode 100644 plugins/groovy/testdata/reparse/SwitchCaseWhile_before.txt 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 df1ee5cccb10..2d51bced73e7 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 @@ -24,6 +24,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.GroovyBundle; import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; import org.jetbrains.plugins.groovy.lang.parser.parsing.auxiliary.Separators; +import org.jetbrains.plugins.groovy.lang.parser.parsing.auxiliary.modifiers.Modifiers; import org.jetbrains.plugins.groovy.lang.parser.parsing.statements.*; import org.jetbrains.plugins.groovy.lang.parser.parsing.statements.blocks.OpenOrClosableBlock; import org.jetbrains.plugins.groovy.lang.parser.parsing.statements.constructor.ConstructorBody; @@ -36,6 +37,8 @@ import org.jetbrains.plugins.groovy.lang.parser.parsing.statements.typeDefinitio import org.jetbrains.plugins.groovy.lang.parser.parsing.toplevel.CompilationUnit; import org.jetbrains.plugins.groovy.lang.parser.parsing.util.ParserUtils; +import static org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes.*; + /** * Parser for Groovy script files * @@ -50,13 +53,13 @@ public class GroovyParser implements PsiParser { @NotNull public ASTNode parse(IElementType root, PsiBuilder builder) { //builder.setDebugMode(true); - if (root == GroovyElementTypes.OPEN_BLOCK) { + if (root == OPEN_BLOCK) { OpenOrClosableBlock.parseOpenBlockDeep(builder, this); } - else if (root == GroovyElementTypes.CLOSABLE_BLOCK) { + else if (root == CLOSABLE_BLOCK) { OpenOrClosableBlock.parseClosableBlockDeep(builder, this); } - else if (root == GroovyElementTypes.CONSTRUCTOR_BODY) { + else if (root == CONSTRUCTOR_BODY) { ConstructorBody.parseConstructorBodyDeep(builder, this); } else { @@ -73,12 +76,12 @@ public class GroovyParser implements PsiParser { ParserUtils.getToken(builder, GroovyTokenTypes.kFOR); if (!ParserUtils.getToken(builder, GroovyTokenTypes.mLPAREN, GroovyBundle.message("lparen.expected"))) { - marker.done(GroovyElementTypes.FOR_STATEMENT); + marker.done(FOR_STATEMENT); return true; } if (!ForStatement.forClauseParse(builder, this)) { builder.error(GroovyBundle.message("for.clause.expected")); - marker.done(GroovyElementTypes.FOR_STATEMENT); + marker.done(FOR_STATEMENT); return true; } @@ -88,7 +91,7 @@ public class GroovyParser implements PsiParser { while (!builder.eof() && GroovyTokenTypes.mNLS == builder.getTokenType()){ builder.advanceLexer(); } - marker.done(GroovyElementTypes.FOR_STATEMENT); + marker.done(FOR_STATEMENT); return true; } @@ -99,18 +102,18 @@ public class GroovyParser implements PsiParser { if (parseExtendedStatement(builder)) { warn.rollbackTo(); - marker.done(GroovyElementTypes.FOR_STATEMENT); + marker.done(FOR_STATEMENT); return true; } if (!parseStatement(builder, true)) { warn.rollbackTo(); builder.error(GroovyBundle.message("expression.expected")); - marker.done(GroovyElementTypes.FOR_STATEMENT); + marker.done(FOR_STATEMENT); return true; } else { warn.drop(); - marker.done(GroovyElementTypes.FOR_STATEMENT); + marker.done(FOR_STATEMENT); return true; } } @@ -126,10 +129,8 @@ public class GroovyParser implements PsiParser { } if (!ParserUtils.getToken(builder, GroovyTokenTypes.mLPAREN, GroovyBundle.message("lparen.expected"))) { -// ifStmtMarker.done(IF_STATEMENT); -// return IF_STATEMENT; - ifStmtMarker.drop(); - return false; + ifStmtMarker.done(IF_STATEMENT); + return true; } if (!ConditionalExpression.parse(builder, this)) { @@ -150,7 +151,7 @@ public class GroovyParser implements PsiParser { builder.error(GroovyBundle.message("rparen.expected")); } if (!ParserUtils.getToken(builder, GroovyTokenTypes.mRPAREN)) { - ifStmtMarker.done(GroovyElementTypes.IF_STATEMENT); + ifStmtMarker.done(IF_STATEMENT); return true; } } @@ -163,7 +164,7 @@ public class GroovyParser implements PsiParser { if (!parseStatement(builder, true) && !parseExtendedStatement(builder)) { warn.rollbackTo(); builder.error(GroovyBundle.message("expression.expected")); - ifStmtMarker.done(GroovyElementTypes.IF_STATEMENT); + ifStmtMarker.done(IF_STATEMENT); return true; } else { warn.drop(); @@ -184,18 +185,18 @@ public class GroovyParser implements PsiParser { if (!parseStatement(builder, true) && !parseExtendedStatement(builder)) { warn.rollbackTo(); builder.error(GroovyBundle.message("expression.expected")); - ifStmtMarker.done(GroovyElementTypes.IF_STATEMENT); + ifStmtMarker.done(IF_STATEMENT); return true; } else { warn.drop(); } - ifStmtMarker.done(GroovyElementTypes.IF_STATEMENT); + ifStmtMarker.done(IF_STATEMENT); return true; } else { rb.rollbackTo(); - ifStmtMarker.done(GroovyElementTypes.IF_STATEMENT); + ifStmtMarker.done(IF_STATEMENT); return true; } } @@ -279,7 +280,7 @@ public class GroovyParser implements PsiParser { ParserUtils.getToken(builder, GroovyTokenTypes.kWHILE); if (!ParserUtils.getToken(builder, GroovyTokenTypes.mLPAREN, GroovyBundle.message("lparen.expected"))) { - marker.done(GroovyElementTypes.WHILE_STATEMENT); + marker.done(WHILE_STATEMENT); return true; } @@ -295,7 +296,7 @@ public class GroovyParser implements PsiParser { builder.error(GroovyBundle.message("rparen.expected")); } if (!ParserUtils.getToken(builder, GroovyTokenTypes.mRPAREN)) { - marker.done(GroovyElementTypes.WHILE_STATEMENT); + marker.done(WHILE_STATEMENT); return true; } } @@ -306,11 +307,11 @@ public class GroovyParser implements PsiParser { if (!parseStatement(builder, true) && !parseExtendedStatement(builder)) { warn.rollbackTo(); builder.error(GroovyBundle.message("expression.expected")); - marker.done(GroovyElementTypes.WHILE_STATEMENT); + marker.done(WHILE_STATEMENT); return true; } else { warn.drop(); - marker.done(GroovyElementTypes.WHILE_STATEMENT); + marker.done(WHILE_STATEMENT); return true; } } @@ -391,7 +392,7 @@ public class GroovyParser implements PsiParser { if (isBlockStatementNeeded && GroovyTokenTypes.mLCURLY.equals(builder.getTokenType())) { final PsiBuilder.Marker marker = builder.mark(); OpenOrClosableBlock.parseOpenBlockDeep(builder, this); - marker.done(GroovyElementTypes.BLOCK_STATEMENT); + marker.done(BLOCK_STATEMENT); return true; } @@ -467,21 +468,39 @@ public class GroovyParser implements PsiParser { //declaration PsiBuilder.Marker declMarker = builder.mark(); - if (!Declaration.parse(builder, false, this)) { - declMarker.rollbackTo(); - } else { - declMarker.drop(); + boolean modifiersParsed = Modifiers.parse(builder, this); + + if (kIMPORT == builder.getTokenType()) { + final PsiBuilder.Marker impMarker = declMarker.precede(); + ImportStatement.parseAfterModifiers(builder); + declMarker.done(IMPORT_STATEMENT); + impMarker.error(GroovyBundle.message("import.not.allowed")); return true; } - PsiBuilder.Marker marker = builder.mark(); - if (ImportStatement.parse(builder, this)) { - marker.error(GroovyBundle.message("import.not.allowed")); + if (kCLASS == builder.getTokenType() || kINTERFACE == builder.getTokenType() || kENUM == builder.getTokenType() || mAT == builder.getTokenType()) { + final IElementType tdType = TypeDefinition.parseAfterModifiers(builder, this); + if (tdType != WRONGWAY) { + declMarker.done(tdType); + return true; + } } - else { - marker.drop(); + + final IElementType declType = Declaration.parseAfterModifiers(builder, false, false, this, declMarker, modifiersParsed); + if (declType != WRONGWAY) { + if (declType != null) { + declMarker.done(declType); + } else { + declMarker.drop(); + } + return true; } - if (TypeDefinition.parse(builder, this)) return true; + + if (modifiersParsed) { + declMarker.done(VARIABLE_DEFINITION_ERROR); + return true; + } + declMarker.rollbackTo(); return AssignmentExpression.parse(builder, this, true); @@ -498,14 +517,14 @@ public class GroovyParser implements PsiParser { private boolean parseLabeledStatement(PsiBuilder builder) { PsiBuilder.Marker marker = builder.mark(); - ParserUtils.eatElement(builder, GroovyElementTypes.LABEL); + ParserUtils.eatElement(builder, LABEL); ParserUtils.getToken(builder, GroovyTokenTypes.mCOLON); ParserUtils.getToken(builder, GroovyTokenTypes.mNLS); parseStatement(builder, false); - marker.done(GroovyElementTypes.LABELED_STATEMENT); + marker.done(LABELED_STATEMENT); return true; } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/declaration/Declaration.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/declaration/Declaration.java index 6e014467c0ea..4612dfff1f73 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/declaration/Declaration.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/declaration/Declaration.java @@ -18,12 +18,12 @@ package org.jetbrains.plugins.groovy.lang.parser.parsing.statements.declaration; import com.intellij.lang.PsiBuilder; import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.GroovyBundle; import org.jetbrains.plugins.groovy.lang.lexer.TokenSets; import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes; import org.jetbrains.plugins.groovy.lang.parser.GroovyParser; import org.jetbrains.plugins.groovy.lang.parser.parsing.auxiliary.modifiers.Modifiers; -import org.jetbrains.plugins.groovy.lang.parser.parsing.statements.typeDefinitions.ReferenceElement; import org.jetbrains.plugins.groovy.lang.parser.parsing.types.TypeParameters; import org.jetbrains.plugins.groovy.lang.parser.parsing.types.TypeSpec; import org.jetbrains.plugins.groovy.lang.parser.parsing.util.ParserUtils; @@ -50,11 +50,41 @@ public class Declaration implements GroovyElementTypes { //allows error messages boolean modifiersParsed = Modifiers.parse(builder, parser); + final boolean methodStart = mLT == builder.getTokenType(); + final IElementType type = parseAfterModifiers(builder, isInClass, isInAnnotation, parser, declMarker, modifiersParsed); + if (type == WRONGWAY) { + if (modifiersParsed && methodStart) { + declMarker.error(GroovyBundle.message("method.definitions.expected")); + return false; + } + + declMarker.rollbackTo(); + if (modifiersParsed) { + builder.error(GroovyBundle.message("variable.definitions.expected")); + } + + return false; + } + + if (type != null) { + declMarker.done(type); + } else { + declMarker.drop(); + } + return true; + } + + @Nullable + public static IElementType parseAfterModifiers(PsiBuilder builder, + boolean isInClass, + boolean isInAnnotation, + GroovyParser parser, + PsiBuilder.Marker declMarker, boolean modifiersParsed) { if (modifiersParsed && mLT == builder.getTokenType()) { TypeParameters.parse(builder); PsiBuilder.Marker checkMarker = builder.mark(); //point to begin of type or variable - if (TypeSpec.parse(builder, true) == fail) { //if type wasn't recognized trying parse VaribleDeclaration + if (TypeSpec.parse(builder, true) == fail) { //if type wasn't recognized trying parse VariableDeclaration checkMarker.rollbackTo(); } else { checkMarker.drop(); @@ -62,17 +92,17 @@ public class Declaration implements GroovyElementTypes { IElementType decl = VariableDefinitions.parseDefinitions(builder, isInClass, false, false, true, modifiersParsed, false, parser); if (WRONGWAY.equals(decl)) { - declMarker.error(GroovyBundle.message("method.definitions.expected")); - } else { - declMarker.done(METHOD_DEFINITION); + return WRONGWAY; } - return true; - } else if (modifiersParsed) { + return METHOD_DEFINITION; + } + + if (modifiersParsed) { PsiBuilder.Marker checkMarker = builder.mark(); //point to begin of type or variable - if (TypeSpec.parse(builder, false) == fail) { //if type wasn't recognized trying parse VaribleDeclaration + if (TypeSpec.parse(builder, false) == fail) { //if type wasn't recognized trying parse VariableDeclaration checkMarker.rollbackTo(); if (isInAnnotation) { @@ -83,14 +113,9 @@ public class Declaration implements GroovyElementTypes { IElementType varDecl = VariableDefinitions.parse(builder, isInClass, modifiersParsed, parser); if (WRONGWAY.equals(varDecl)) { - declMarker.rollbackTo(); - builder.error(GroovyBundle.message("variable.definitions.expected")); - return false; - } else { - declMarker.done(varDecl); - return true; + return WRONGWAY; } - + return varDecl; } else { //type was recognized, identifier here //starts after type IElementType varDeclarationTop = VariableDefinitions.parse(builder, isInClass, modifiersParsed, false, parser); @@ -106,17 +131,13 @@ public class Declaration implements GroovyElementTypes { IElementType varDecl = VariableDefinitions.parse(builder, isInClass, modifiersParsed, false, parser); if (WRONGWAY.equals(varDecl)) { - builder.error(GroovyBundle.message("variable.definitions.expected")); - declMarker.rollbackTo(); - return false; + return WRONGWAY; } else { - declMarker.done(varDecl); - return true; + return varDecl; } } else { checkMarker.drop(); - declMarker.done(varDeclarationTop); - return true; + return varDeclarationTop; } } } else { @@ -130,8 +151,7 @@ public class Declaration implements GroovyElementTypes { && (Character.isLowerCase((text.charAt(0))) || !Character.isLetter(text.charAt(0))) && (ParserUtils.lookAhead(builder, mIDENT, mIDENT) || ParserUtils.lookAhead(builder, mIDENT, mLPAREN))) { //call expression - declMarker.rollbackTo(); - return false; + return WRONGWAY; } boolean typeParsed = false; @@ -140,22 +160,18 @@ public class Declaration implements GroovyElementTypes { //type specification starts with upper case letter if (!typeParsed) { builder.error(GroovyBundle.message("type.specification.expected")); - declMarker.rollbackTo(); - return false; + return WRONGWAY; } } IElementType varDef = VariableDefinitions.parseDefinitions(builder, isInClass, false, false, false, typeParsed, false, parser); if (varDef != WRONGWAY) { - declMarker.done(varDef); - return true; + return varDef; } else if (isInClass && typeParsed) { - declMarker.drop(); - return typeParsed; + return typeParsed ? null : WRONGWAY; } - declMarker.rollbackTo(); - return false; + return WRONGWAY; } } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/imports/ImportStatement.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/imports/ImportStatement.java index df52b6191bc2..09c08f0d5455 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/imports/ImportStatement.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/imports/ImportStatement.java @@ -40,15 +40,18 @@ public class ImportStatement implements GroovyElementTypes { impMarker.rollbackTo(); return false; } + + parseAfterModifiers(builder); + impMarker.done(IMPORT_STATEMENT); + return true; + } + + public static void parseAfterModifiers(PsiBuilder builder) { ParserUtils.getToken(builder, kIMPORT, GroovyBundle.message("import.keyword.expected")); ParserUtils.getToken(builder, kSTATIC); if (!ImportReference.parse(builder)) { builder.error(GroovyBundle.message("import.identifier.expected")); } - impMarker.done(IMPORT_STATEMENT); - - return true; } - } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/typeDefinitions/TypeDefinition.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/typeDefinitions/TypeDefinition.java index b3f1e8201465..4009eca64528 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/typeDefinitions/TypeDefinition.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/typeDefinitions/TypeDefinition.java @@ -17,6 +17,7 @@ package org.jetbrains.plugins.groovy.lang.parser.parsing.statements.typeDefinitions; import com.intellij.lang.PsiBuilder; +import com.intellij.psi.tree.IElementType; import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes; import org.jetbrains.plugins.groovy.lang.parser.GroovyParser; import org.jetbrains.plugins.groovy.lang.parser.parsing.statements.typeDefinitions.typeDef.AnnotationDefinition; @@ -41,27 +42,34 @@ public class TypeDefinition implements GroovyElementTypes { public static boolean parse(PsiBuilder builder, GroovyParser parser) { PsiBuilder.Marker tdMarker = builder.mark(); Modifiers.parse(builder, parser); + + final IElementType tdType = parseAfterModifiers(builder, parser); + if (tdType == WRONGWAY) { + tdMarker.rollbackTo(); + return false; + } + + tdMarker.done(tdType); + return true; + } + + public static IElementType parseAfterModifiers(PsiBuilder builder, GroovyParser parser) { if (builder.getTokenType() == kCLASS && ClassDefinition.parse(builder, parser)) { - tdMarker.done(CLASS_DEFINITION); - return true; + return CLASS_DEFINITION; } if (builder.getTokenType() == kINTERFACE && InterfaceDefinition.parse(builder, parser)) { - tdMarker.done(INTERFACE_DEFINITION); - return true; + return INTERFACE_DEFINITION; } if (builder.getTokenType() == kENUM && EnumDefinition.parse(builder, parser)) { - tdMarker.done(ENUM_DEFINITION); - return true; + return ENUM_DEFINITION; } if (builder.getTokenType() == mAT && AnnotationDefinition.parse(builder, parser)) { - tdMarker.done(ANNOTATION_DEFINITION); - return true; + return ANNOTATION_DEFINITION; } - tdMarker.rollbackTo(); - return false; + return WRONGWAY; } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java index ecbc59ae27d0..7ae68e87a667 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java @@ -12,7 +12,6 @@ import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.impl.DebugUtil; import com.intellij.testFramework.IdeaTestUtil; import com.intellij.testFramework.LightProjectDescriptor; import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor; @@ -348,21 +347,5 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase { doTest(new GroovyAssignabilityCheckInspection()); } - public void testCodeBlockReparse() throws IOException { - myFixture.configureByText("a.groovy", "foo 'a', {}"); - myFixture.checkHighlighting(true, false, false); - final String psiBefore = DebugUtil.psiToString(myFixture.getFile(), false); - - myFixture.type('\n'); - myFixture.checkHighlighting(true, false, false); - final String psiAfter = DebugUtil.psiToString(myFixture.getFile(), false); - - myFixture.configureByText("a.txt", psiBefore); - myFixture.checkResultByFile(getTestName(false) + "1.txt"); - - myFixture.configureByText("a.txt", psiAfter); - myFixture.checkResultByFile(getTestName(false) + "2.txt"); - } - public void testDuplicatedNamedArgs() {doTest();} } \ No newline at end of file diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/GroovyReparseTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/GroovyReparseTest.groovy new file mode 100644 index 000000000000..4c03321128ea --- /dev/null +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/GroovyReparseTest.groovy @@ -0,0 +1,102 @@ +package org.jetbrains.plugins.groovy.lang.parser + +import com.intellij.psi.impl.DebugUtil +import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase +import org.jetbrains.plugins.groovy.util.TestUtils +import com.intellij.psi.PsiDocumentManager + +/** + * @author peter + */ +class GroovyReparseTest extends LightCodeInsightFixtureTestCase { + + @Override + protected String getBasePath() { + return TestUtils.getTestDataPath() + "reparse/"; + } + + void checkReparse(String text, String type) { + myFixture.configureByText("a.groovy", text); + PsiDocumentManager.getInstance(project).commitAllDocuments() + final String psiBefore = DebugUtil.psiToString(myFixture.getFile(), false); + + myFixture.type(type); + PsiDocumentManager.getInstance(project).commitAllDocuments() + final String psiAfter = DebugUtil.psiToString(myFixture.getFile(), false); + + myFixture.configureByText("a.txt", psiBefore); + myFixture.checkResultByFile(getTestName(false) + "_before.txt"); + + myFixture.configureByText("a.txt", psiAfter); + myFixture.checkResultByFile(getTestName(false) + "_after.txt"); + } + + public void testCodeBlockReparse() throws IOException { + checkReparse("foo 'a', {}", '\n') + } + + public void testSwitchCaseIf() throws Exception { + checkReparse """ + def foo() { + switch(x) { + case 2: + return 2 + } + } +""", "if " + } + + public void testSwitchCaseDef() throws Exception { + checkReparse """ + def foo() { + switch(x) { + case 2: + return 2 + } + } +""", "def " + } + + public void testSwitchCaseFor() throws Exception { + checkReparse """ + def foo() { + switch(x) { + case 2: + return 2 + } + } +""", "for " + } + public void testSwitchCaseWhile() throws Exception { + checkReparse """ + def foo() { + switch(x) { + case 2: + return 2 + } + } +""", "while " + } + public void testSwitchCaseDo() throws Exception { + checkReparse """ + def foo() { + switch(x) { + case 2: + return 2 + } + } +""", "do " + } + public void testSwitchCaseSwitch() throws Exception { + checkReparse """ + def foo() { + switch(x) { + case 2: + return 2 + } + } +""", "switch " + } + + +} diff --git a/plugins/groovy/testdata/parsing/groovy/expressions/errors/err_final.test b/plugins/groovy/testdata/parsing/groovy/expressions/errors/err_final.test index 1478ab26e1b0..bc1f1fa474c1 100644 --- a/plugins/groovy/testdata/parsing/groovy/expressions/errors/err_final.test +++ b/plugins/groovy/testdata/parsing/groovy/expressions/errors/err_final.test @@ -1,8 +1,10 @@ -def final +def final ----- Groovy script - PsiErrorElement:';' or new line expected - PsiElement(def)('def') - PsiWhiteSpace(' ') - PsiElement(final)('final') - PsiWhiteSpace(' ') \ No newline at end of file + Variable definitions + Modifiers + PsiElement(def)('def') + PsiWhiteSpace(' ') + PsiElement(final)('final') + PsiErrorElement:Identifier, string literal or '(' expected + \ No newline at end of file diff --git a/plugins/groovy/testdata/parsing/groovy/generics/err3.test b/plugins/groovy/testdata/parsing/groovy/generics/err3.test index 50a95b57e37e..4ae43d53514a 100644 --- a/plugins/groovy/testdata/parsing/groovy/generics/err3.test +++ b/plugins/groovy/testdata/parsing/groovy/generics/err3.test @@ -27,8 +27,6 @@ Groovy script PsiElement(>)('>') PsiWhiteSpace(' ') PsiElement(identifier)('t') - PsiErrorElement:';', '}' or new line expected - PsiWhiteSpace(' ') PsiElement(=)('=') PsiErrorElement:';', '}' or new line expected diff --git a/plugins/groovy/testdata/parsing/groovy/statements/ifstmt/if2.test b/plugins/groovy/testdata/parsing/groovy/statements/ifstmt/if2.test index 56db031dc728..47616764e63c 100644 --- a/plugins/groovy/testdata/parsing/groovy/statements/ifstmt/if2.test +++ b/plugins/groovy/testdata/parsing/groovy/statements/ifstmt/if2.test @@ -1,9 +1,10 @@ if expr1 expr2 else expr3 ----- Groovy script - PsiElement(if)('if') - PsiErrorElement:'(' expected - + IF statement + PsiElement(if)('if') + PsiErrorElement:'(' expected + PsiWhiteSpace(' ') PsiErrorElement:';' or new line expected PsiElement(identifier)('expr1') diff --git a/plugins/groovy/testdata/parsing/groovy/statements/tuples/doubleParens.test b/plugins/groovy/testdata/parsing/groovy/statements/tuples/doubleParens.test index 052b5049870f..e58137601344 100644 --- a/plugins/groovy/testdata/parsing/groovy/statements/tuples/doubleParens.test +++ b/plugins/groovy/testdata/parsing/groovy/statements/tuples/doubleParens.test @@ -1,9 +1,13 @@ def ((a)) ----- Groovy script + Variable definitions + Modifiers + PsiElement(def)('def') + PsiErrorElement:Identifier expected + + PsiWhiteSpace(' ') PsiErrorElement:';' or new line expected - PsiElement(def)('def') - PsiWhiteSpace(' ') PsiElement(()('(') PsiElement(()('(') PsiElement(identifier)('a') diff --git a/plugins/groovy/testdata/parsing/groovy/statements/tuples/nestedTupleUnsupp.test b/plugins/groovy/testdata/parsing/groovy/statements/tuples/nestedTupleUnsupp.test index 09f1753eefc9..e247f12c97bc 100644 --- a/plugins/groovy/testdata/parsing/groovy/statements/tuples/nestedTupleUnsupp.test +++ b/plugins/groovy/testdata/parsing/groovy/statements/tuples/nestedTupleUnsupp.test @@ -1,9 +1,13 @@ def ((a,b),c)=[[1,2],3] ----- Groovy script + Variable definitions + Modifiers + PsiElement(def)('def') + PsiErrorElement:Identifier expected + + PsiWhiteSpace(' ') PsiErrorElement:';' or new line expected - PsiElement(def)('def') - PsiWhiteSpace(' ') PsiElement(()('(') PsiElement(()('(') PsiElement(identifier)('a') diff --git a/plugins/groovy/testdata/highlighting/CodeBlockReparse2.txt b/plugins/groovy/testdata/reparse/CodeBlockReparse_after.txt similarity index 100% rename from plugins/groovy/testdata/highlighting/CodeBlockReparse2.txt rename to plugins/groovy/testdata/reparse/CodeBlockReparse_after.txt diff --git a/plugins/groovy/testdata/highlighting/CodeBlockReparse1.txt b/plugins/groovy/testdata/reparse/CodeBlockReparse_before.txt similarity index 100% rename from plugins/groovy/testdata/highlighting/CodeBlockReparse1.txt rename to plugins/groovy/testdata/reparse/CodeBlockReparse_before.txt diff --git a/plugins/groovy/testdata/reparse/SwitchCaseDef_after.txt b/plugins/groovy/testdata/reparse/SwitchCaseDef_after.txt new file mode 100644 index 000000000000..4ed3979693ce --- /dev/null +++ b/plugins/groovy/testdata/reparse/SwitchCaseDef_after.txt @@ -0,0 +1,50 @@ +Groovy script + PsiElement(new line)('\n ') + Method + Modifiers + PsiElement(def)('def') + PsiWhiteSpace(' ') + PsiElement(identifier)('foo') + PsiElement(()('(') + Parameter list + + PsiElement())(')') + PsiWhiteSpace(' ') + Throw clause + + Open block + PsiElement({)('{') + PsiWhiteSpace('\n ') + Switch statement + PsiElement(switch)('switch') + PsiElement(()('(') + Reference expression + PsiElement(identifier)('x') + PsiElement())(')') + PsiWhiteSpace(' ') + PsiElement({)('{') + PsiWhiteSpace('\n ') + Case section + Case label + PsiElement(case)('case') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(:)(':') + PsiElement(new line)('\n ') + Variable definitions + Modifiers + PsiElement(def)('def') + PsiErrorElement:Identifier, string literal or '(' expected + + PsiWhiteSpace(' ') + RETURN statement + PsiElement(return)('return') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n') diff --git a/plugins/groovy/testdata/reparse/SwitchCaseDef_before.txt b/plugins/groovy/testdata/reparse/SwitchCaseDef_before.txt new file mode 100644 index 000000000000..3f84b8c5350c --- /dev/null +++ b/plugins/groovy/testdata/reparse/SwitchCaseDef_before.txt @@ -0,0 +1,44 @@ +Groovy script + PsiElement(new line)('\n ') + Method + Modifiers + PsiElement(def)('def') + PsiWhiteSpace(' ') + PsiElement(identifier)('foo') + PsiElement(()('(') + Parameter list + + PsiElement())(')') + PsiWhiteSpace(' ') + Throw clause + + Open block + PsiElement({)('{') + PsiWhiteSpace('\n ') + Switch statement + PsiElement(switch)('switch') + PsiElement(()('(') + Reference expression + PsiElement(identifier)('x') + PsiElement())(')') + PsiWhiteSpace(' ') + PsiElement({)('{') + PsiWhiteSpace('\n ') + Case section + Case label + PsiElement(case)('case') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(:)(':') + PsiElement(new line)('\n ') + RETURN statement + PsiElement(return)('return') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n') diff --git a/plugins/groovy/testdata/reparse/SwitchCaseDo_after.txt b/plugins/groovy/testdata/reparse/SwitchCaseDo_after.txt new file mode 100644 index 000000000000..93c95749b4d8 --- /dev/null +++ b/plugins/groovy/testdata/reparse/SwitchCaseDo_after.txt @@ -0,0 +1,47 @@ +Groovy script + PsiElement(new line)('\n ') + Method + Modifiers + PsiElement(def)('def') + PsiWhiteSpace(' ') + PsiElement(identifier)('foo') + PsiElement(()('(') + Parameter list + + PsiElement())(')') + PsiWhiteSpace(' ') + Throw clause + + Open block + PsiElement({)('{') + PsiWhiteSpace('\n ') + Switch statement + PsiElement(switch)('switch') + PsiElement(()('(') + Reference expression + PsiElement(identifier)('x') + PsiElement())(')') + PsiWhiteSpace(' ') + PsiElement({)('{') + PsiWhiteSpace('\n ') + Case section + Case label + PsiElement(case)('case') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(:)(':') + PsiElement(new line)('\n ') + Reference expression + PsiElement(identifier)('do') + PsiWhiteSpace(' ') + RETURN statement + PsiElement(return)('return') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n') diff --git a/plugins/groovy/testdata/reparse/SwitchCaseDo_before.txt b/plugins/groovy/testdata/reparse/SwitchCaseDo_before.txt new file mode 100644 index 000000000000..3f84b8c5350c --- /dev/null +++ b/plugins/groovy/testdata/reparse/SwitchCaseDo_before.txt @@ -0,0 +1,44 @@ +Groovy script + PsiElement(new line)('\n ') + Method + Modifiers + PsiElement(def)('def') + PsiWhiteSpace(' ') + PsiElement(identifier)('foo') + PsiElement(()('(') + Parameter list + + PsiElement())(')') + PsiWhiteSpace(' ') + Throw clause + + Open block + PsiElement({)('{') + PsiWhiteSpace('\n ') + Switch statement + PsiElement(switch)('switch') + PsiElement(()('(') + Reference expression + PsiElement(identifier)('x') + PsiElement())(')') + PsiWhiteSpace(' ') + PsiElement({)('{') + PsiWhiteSpace('\n ') + Case section + Case label + PsiElement(case)('case') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(:)(':') + PsiElement(new line)('\n ') + RETURN statement + PsiElement(return)('return') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n') diff --git a/plugins/groovy/testdata/reparse/SwitchCaseFor_after.txt b/plugins/groovy/testdata/reparse/SwitchCaseFor_after.txt new file mode 100644 index 000000000000..a6945af333a6 --- /dev/null +++ b/plugins/groovy/testdata/reparse/SwitchCaseFor_after.txt @@ -0,0 +1,49 @@ +Groovy script + PsiElement(new line)('\n ') + Method + Modifiers + PsiElement(def)('def') + PsiWhiteSpace(' ') + PsiElement(identifier)('foo') + PsiElement(()('(') + Parameter list + + PsiElement())(')') + PsiWhiteSpace(' ') + Throw clause + + Open block + PsiElement({)('{') + PsiWhiteSpace('\n ') + Switch statement + PsiElement(switch)('switch') + PsiElement(()('(') + Reference expression + PsiElement(identifier)('x') + PsiElement())(')') + PsiWhiteSpace(' ') + PsiElement({)('{') + PsiWhiteSpace('\n ') + Case section + Case label + PsiElement(case)('case') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(:)(':') + PsiElement(new line)('\n ') + For statement + PsiElement(for)('for') + PsiErrorElement:'(' expected + + PsiWhiteSpace(' ') + RETURN statement + PsiElement(return)('return') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n') diff --git a/plugins/groovy/testdata/reparse/SwitchCaseFor_before.txt b/plugins/groovy/testdata/reparse/SwitchCaseFor_before.txt new file mode 100644 index 000000000000..3f84b8c5350c --- /dev/null +++ b/plugins/groovy/testdata/reparse/SwitchCaseFor_before.txt @@ -0,0 +1,44 @@ +Groovy script + PsiElement(new line)('\n ') + Method + Modifiers + PsiElement(def)('def') + PsiWhiteSpace(' ') + PsiElement(identifier)('foo') + PsiElement(()('(') + Parameter list + + PsiElement())(')') + PsiWhiteSpace(' ') + Throw clause + + Open block + PsiElement({)('{') + PsiWhiteSpace('\n ') + Switch statement + PsiElement(switch)('switch') + PsiElement(()('(') + Reference expression + PsiElement(identifier)('x') + PsiElement())(')') + PsiWhiteSpace(' ') + PsiElement({)('{') + PsiWhiteSpace('\n ') + Case section + Case label + PsiElement(case)('case') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(:)(':') + PsiElement(new line)('\n ') + RETURN statement + PsiElement(return)('return') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n') diff --git a/plugins/groovy/testdata/reparse/SwitchCaseIf_after.txt b/plugins/groovy/testdata/reparse/SwitchCaseIf_after.txt new file mode 100644 index 000000000000..c9ad5905add8 --- /dev/null +++ b/plugins/groovy/testdata/reparse/SwitchCaseIf_after.txt @@ -0,0 +1,49 @@ +Groovy script + PsiElement(new line)('\n ') + Method + Modifiers + PsiElement(def)('def') + PsiWhiteSpace(' ') + PsiElement(identifier)('foo') + PsiElement(()('(') + Parameter list + + PsiElement())(')') + PsiWhiteSpace(' ') + Throw clause + + Open block + PsiElement({)('{') + PsiWhiteSpace('\n ') + Switch statement + PsiElement(switch)('switch') + PsiElement(()('(') + Reference expression + PsiElement(identifier)('x') + PsiElement())(')') + PsiWhiteSpace(' ') + PsiElement({)('{') + PsiWhiteSpace('\n ') + Case section + Case label + PsiElement(case)('case') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(:)(':') + PsiElement(new line)('\n ') + IF statement + PsiElement(if)('if') + PsiErrorElement:'(' expected + + PsiWhiteSpace(' ') + RETURN statement + PsiElement(return)('return') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n') diff --git a/plugins/groovy/testdata/reparse/SwitchCaseIf_before.txt b/plugins/groovy/testdata/reparse/SwitchCaseIf_before.txt new file mode 100644 index 000000000000..3f84b8c5350c --- /dev/null +++ b/plugins/groovy/testdata/reparse/SwitchCaseIf_before.txt @@ -0,0 +1,44 @@ +Groovy script + PsiElement(new line)('\n ') + Method + Modifiers + PsiElement(def)('def') + PsiWhiteSpace(' ') + PsiElement(identifier)('foo') + PsiElement(()('(') + Parameter list + + PsiElement())(')') + PsiWhiteSpace(' ') + Throw clause + + Open block + PsiElement({)('{') + PsiWhiteSpace('\n ') + Switch statement + PsiElement(switch)('switch') + PsiElement(()('(') + Reference expression + PsiElement(identifier)('x') + PsiElement())(')') + PsiWhiteSpace(' ') + PsiElement({)('{') + PsiWhiteSpace('\n ') + Case section + Case label + PsiElement(case)('case') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(:)(':') + PsiElement(new line)('\n ') + RETURN statement + PsiElement(return)('return') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n') diff --git a/plugins/groovy/testdata/reparse/SwitchCaseSwitch_after.txt b/plugins/groovy/testdata/reparse/SwitchCaseSwitch_after.txt new file mode 100644 index 000000000000..6c231a7f6eba --- /dev/null +++ b/plugins/groovy/testdata/reparse/SwitchCaseSwitch_after.txt @@ -0,0 +1,49 @@ +Groovy script + PsiElement(new line)('\n ') + Method + Modifiers + PsiElement(def)('def') + PsiWhiteSpace(' ') + PsiElement(identifier)('foo') + PsiElement(()('(') + Parameter list + + PsiElement())(')') + PsiWhiteSpace(' ') + Throw clause + + Open block + PsiElement({)('{') + PsiWhiteSpace('\n ') + Switch statement + PsiElement(switch)('switch') + PsiElement(()('(') + Reference expression + PsiElement(identifier)('x') + PsiElement())(')') + PsiWhiteSpace(' ') + PsiElement({)('{') + PsiWhiteSpace('\n ') + Case section + Case label + PsiElement(case)('case') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(:)(':') + PsiElement(new line)('\n ') + Switch statement + PsiElement(switch)('switch') + PsiErrorElement:'(' expected + + PsiWhiteSpace(' ') + RETURN statement + PsiElement(return)('return') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n') diff --git a/plugins/groovy/testdata/reparse/SwitchCaseSwitch_before.txt b/plugins/groovy/testdata/reparse/SwitchCaseSwitch_before.txt new file mode 100644 index 000000000000..3f84b8c5350c --- /dev/null +++ b/plugins/groovy/testdata/reparse/SwitchCaseSwitch_before.txt @@ -0,0 +1,44 @@ +Groovy script + PsiElement(new line)('\n ') + Method + Modifiers + PsiElement(def)('def') + PsiWhiteSpace(' ') + PsiElement(identifier)('foo') + PsiElement(()('(') + Parameter list + + PsiElement())(')') + PsiWhiteSpace(' ') + Throw clause + + Open block + PsiElement({)('{') + PsiWhiteSpace('\n ') + Switch statement + PsiElement(switch)('switch') + PsiElement(()('(') + Reference expression + PsiElement(identifier)('x') + PsiElement())(')') + PsiWhiteSpace(' ') + PsiElement({)('{') + PsiWhiteSpace('\n ') + Case section + Case label + PsiElement(case)('case') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(:)(':') + PsiElement(new line)('\n ') + RETURN statement + PsiElement(return)('return') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n') diff --git a/plugins/groovy/testdata/reparse/SwitchCaseWhile_after.txt b/plugins/groovy/testdata/reparse/SwitchCaseWhile_after.txt new file mode 100644 index 000000000000..d9ebb5af09c9 --- /dev/null +++ b/plugins/groovy/testdata/reparse/SwitchCaseWhile_after.txt @@ -0,0 +1,49 @@ +Groovy script + PsiElement(new line)('\n ') + Method + Modifiers + PsiElement(def)('def') + PsiWhiteSpace(' ') + PsiElement(identifier)('foo') + PsiElement(()('(') + Parameter list + + PsiElement())(')') + PsiWhiteSpace(' ') + Throw clause + + Open block + PsiElement({)('{') + PsiWhiteSpace('\n ') + Switch statement + PsiElement(switch)('switch') + PsiElement(()('(') + Reference expression + PsiElement(identifier)('x') + PsiElement())(')') + PsiWhiteSpace(' ') + PsiElement({)('{') + PsiWhiteSpace('\n ') + Case section + Case label + PsiElement(case)('case') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(:)(':') + PsiElement(new line)('\n ') + WHILE statement + PsiElement(while)('while') + PsiErrorElement:'(' expected + + PsiWhiteSpace(' ') + RETURN statement + PsiElement(return)('return') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n') diff --git a/plugins/groovy/testdata/reparse/SwitchCaseWhile_before.txt b/plugins/groovy/testdata/reparse/SwitchCaseWhile_before.txt new file mode 100644 index 000000000000..3f84b8c5350c --- /dev/null +++ b/plugins/groovy/testdata/reparse/SwitchCaseWhile_before.txt @@ -0,0 +1,44 @@ +Groovy script + PsiElement(new line)('\n ') + Method + Modifiers + PsiElement(def)('def') + PsiWhiteSpace(' ') + PsiElement(identifier)('foo') + PsiElement(()('(') + Parameter list + + PsiElement())(')') + PsiWhiteSpace(' ') + Throw clause + + Open block + PsiElement({)('{') + PsiWhiteSpace('\n ') + Switch statement + PsiElement(switch)('switch') + PsiElement(()('(') + Reference expression + PsiElement(identifier)('x') + PsiElement())(')') + PsiWhiteSpace(' ') + PsiElement({)('{') + PsiWhiteSpace('\n ') + Case section + Case label + PsiElement(case)('case') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(:)(':') + PsiElement(new line)('\n ') + RETURN statement + PsiElement(return)('return') + PsiWhiteSpace(' ') + Literal + PsiElement(Integer)('2') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n ') + PsiElement(})('}') + PsiElement(new line)('\n') From 1d0730c970a27e607e7107beb56108481033e04e Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 9 Mar 2011 12:22:00 +0100 Subject: [PATCH 5/7] one class less --- .../parsing/auxiliary/modifiers/Modifier.java | 51 ------------------- .../auxiliary/modifiers/Modifiers.java | 13 ++++- .../members/ConstructorDefinition.java | 4 +- 3 files changed, 13 insertions(+), 55 deletions(-) delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/auxiliary/modifiers/Modifier.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/auxiliary/modifiers/Modifier.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/auxiliary/modifiers/Modifier.java deleted file mode 100644 index 03942f8d3499..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/auxiliary/modifiers/Modifier.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.parser.parsing.auxiliary.modifiers; - -import com.intellij.lang.PsiBuilder; -import org.jetbrains.plugins.groovy.lang.lexer.TokenSets; -import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes; - -/** - * @autor: Dmitry.Krasilschikov - * @date: 14.03.2007 - */ - -/* - * Modifier ::= private - * | public - * | protected - * | static - * | transient - * | final - * | abstract - * | native - * | synchronized - * | volatile - * | srtictfp - * | def - */ - -public class Modifier implements GroovyElementTypes { - public static boolean parse(PsiBuilder builder) { - if (TokenSets.MODIFIERS.contains(builder.getTokenType())) { - builder.advanceLexer(); - return true; - } - return false; - } -} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/auxiliary/modifiers/Modifiers.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/auxiliary/modifiers/Modifiers.java index ae3de880f0d9..1ccee9924c45 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/auxiliary/modifiers/Modifiers.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/auxiliary/modifiers/Modifiers.java @@ -17,6 +17,7 @@ package org.jetbrains.plugins.groovy.lang.parser.parsing.auxiliary.modifiers; import com.intellij.lang.PsiBuilder; +import org.jetbrains.plugins.groovy.lang.lexer.TokenSets; import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes; import org.jetbrains.plugins.groovy.lang.parser.GroovyParser; import org.jetbrains.plugins.groovy.lang.parser.parsing.auxiliary.annotations.Annotation; @@ -38,7 +39,7 @@ public class Modifiers implements GroovyElementTypes { boolean endsWithNewLine; PsiBuilder.Marker modifiersMarker = builder.mark(); - if (!Annotation.parse(builder, parser) && !Modifier.parse(builder)) { + if (!Annotation.parse(builder, parser) && !parseModifier(builder)) { modifiersMarker.done(MODIFIERS); return false; } @@ -49,7 +50,7 @@ public class Modifiers implements GroovyElementTypes { newLineMarker = builder.mark(); endsWithNewLine = ParserUtils.getToken(builder, mNLS); - if (!Annotation.parse(builder, parser) && !Modifier.parse(builder)) break; + if (!Annotation.parse(builder, parser) && !parseModifier(builder)) break; } // Do not include last newline @@ -63,4 +64,12 @@ public class Modifiers implements GroovyElementTypes { return true; } + + public static boolean parseModifier(PsiBuilder builder) { + if (TokenSets.MODIFIERS.contains(builder.getTokenType())) { + builder.advanceLexer(); + return true; + } + return false; + } } \ No newline at end of file diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/typeDefinitions/members/ConstructorDefinition.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/typeDefinitions/members/ConstructorDefinition.java index 1e4b1d45464a..2bc6090c8f46 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/typeDefinitions/members/ConstructorDefinition.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/typeDefinitions/members/ConstructorDefinition.java @@ -22,7 +22,7 @@ import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes; import org.jetbrains.plugins.groovy.lang.parser.GroovyParser; import org.jetbrains.plugins.groovy.lang.parser.parsing.auxiliary.ThrowClause; import org.jetbrains.plugins.groovy.lang.parser.parsing.auxiliary.annotations.Annotation; -import org.jetbrains.plugins.groovy.lang.parser.parsing.auxiliary.modifiers.Modifier; +import org.jetbrains.plugins.groovy.lang.parser.parsing.auxiliary.modifiers.Modifiers; import org.jetbrains.plugins.groovy.lang.parser.parsing.auxiliary.parameters.ParameterList; import org.jetbrains.plugins.groovy.lang.parser.parsing.statements.constructor.ConstructorBody; import org.jetbrains.plugins.groovy.lang.parser.parsing.util.ParserUtils; @@ -87,7 +87,7 @@ public class ConstructorDefinition implements GroovyElementTypes { return false; } ParserUtils.getToken(builder, mNLS); - } while(Annotation.parse(builder, parser) || Modifier.parse(builder)); + } while(Annotation.parse(builder, parser) || Modifiers.parseModifier(builder)); modifiersMarker.done(MODIFIERS); return true; From 85eafcaa5072d9cc0d3cc512e78847471a2ce605 Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Wed, 9 Mar 2011 14:38:17 +0300 Subject: [PATCH 6/7] Revert "IDEA-60449 running junit tests in a module with an Android facet should not perform a full Android build" This reverts commit 412ec6ef3ed5e3482b5b5125c8d3476ea20c9671. --- .../jetbrains/android/compiler/AndroidCompileUtil.java | 8 -------- .../jetbrains/android/compiler/AndroidDexCompiler.java | 4 ---- .../android/compiler/AndroidPackagingCompiler.java | 4 ---- .../compiler/AndroidResourcesPackagingCompiler.java | 4 ---- 4 files changed, 20 deletions(-) diff --git a/plugins/android/src/org/jetbrains/android/compiler/AndroidCompileUtil.java b/plugins/android/src/org/jetbrains/android/compiler/AndroidCompileUtil.java index fd3e4cecca9f..9ec2f05e98a8 100644 --- a/plugins/android/src/org/jetbrains/android/compiler/AndroidCompileUtil.java +++ b/plugins/android/src/org/jetbrains/android/compiler/AndroidCompileUtil.java @@ -18,10 +18,7 @@ package org.jetbrains.android.compiler; import com.intellij.CommonBundle; import com.intellij.compiler.impl.CompileContextImpl; import com.intellij.compiler.impl.ModuleCompileScope; -import com.intellij.compiler.options.CompileStepBeforeRun; import com.intellij.compiler.progress.CompilerTask; -import com.intellij.execution.configurations.RunConfiguration; -import com.intellij.execution.junit.JUnitConfiguration; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.compiler.CompileContext; @@ -359,9 +356,4 @@ public class AndroidCompileUtil { } return ArrayUtil.toStringArray(result); } - - public static boolean isFullBuild(@NotNull CompileContext context) { - RunConfiguration runConfiguration = CompileStepBeforeRun.getRunConfiguration(context); - return !(runConfiguration instanceof JUnitConfiguration); - } } diff --git a/plugins/android/src/org/jetbrains/android/compiler/AndroidDexCompiler.java b/plugins/android/src/org/jetbrains/android/compiler/AndroidDexCompiler.java index 088e8665fde3..c081254f5ad1 100644 --- a/plugins/android/src/org/jetbrains/android/compiler/AndroidDexCompiler.java +++ b/plugins/android/src/org/jetbrains/android/compiler/AndroidDexCompiler.java @@ -75,10 +75,6 @@ public class AndroidDexCompiler implements ClassPostProcessingCompiler { @NotNull public ProcessingItem[] getProcessingItems(CompileContext context) { - if (!AndroidCompileUtil.isFullBuild(context)) { - return ProcessingItem.EMPTY_ARRAY; - } - return ApplicationManager.getApplication().runReadAction(new PrepareAction(context)); } diff --git a/plugins/android/src/org/jetbrains/android/compiler/AndroidPackagingCompiler.java b/plugins/android/src/org/jetbrains/android/compiler/AndroidPackagingCompiler.java index 5b494d95aa62..f47570f16b0c 100644 --- a/plugins/android/src/org/jetbrains/android/compiler/AndroidPackagingCompiler.java +++ b/plugins/android/src/org/jetbrains/android/compiler/AndroidPackagingCompiler.java @@ -94,10 +94,6 @@ public class AndroidPackagingCompiler implements PackagingCompiler { @NotNull public ProcessingItem[] getProcessingItems(CompileContext context) { - if (!AndroidCompileUtil.isFullBuild(context)) { - return ProcessingItem.EMPTY_ARRAY; - } - final List items = new ArrayList(); for (Module module : ModuleManager.getInstance(context.getProject()).getModules()) { AndroidFacet facet = AndroidFacet.getInstance(module); diff --git a/plugins/android/src/org/jetbrains/android/compiler/AndroidResourcesPackagingCompiler.java b/plugins/android/src/org/jetbrains/android/compiler/AndroidResourcesPackagingCompiler.java index 9a0acf3e5054..3bf30f9ad5cf 100644 --- a/plugins/android/src/org/jetbrains/android/compiler/AndroidResourcesPackagingCompiler.java +++ b/plugins/android/src/org/jetbrains/android/compiler/AndroidResourcesPackagingCompiler.java @@ -42,10 +42,6 @@ public class AndroidResourcesPackagingCompiler implements ClassPostProcessingCom @NotNull @Override public ProcessingItem[] getProcessingItems(CompileContext context) { - if (!AndroidCompileUtil.isFullBuild(context)) { - return ProcessingItem.EMPTY_ARRAY; - } - final List items = new ArrayList(); for (Module module : ModuleManager.getInstance(context.getProject()).getModules()) { AndroidFacet facet = AndroidFacet.getInstance(module); From c992b9c21662bedf5d1611fb82520ad9e8b35a1b Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 9 Mar 2011 13:02:38 +0100 Subject: [PATCH 7/7] Resolve in javadoc fixed --- .../javadoc/PsiDocMethodOrFieldRef.java | 2 +- .../javaDoc/resolve/pkg/See3.java | 28 +++++++++++++++++++ .../daemon/JavadocResolveTest.java | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/resolve/pkg/See3.java diff --git a/java/java-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocMethodOrFieldRef.java b/java/java-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocMethodOrFieldRef.java index e4416a428200..2e184b08c3b0 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocMethodOrFieldRef.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocMethodOrFieldRef.java @@ -101,7 +101,7 @@ public class PsiDocMethodOrFieldRef extends CompositePsiElement implements PsiDo final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(element.getProject()).getElementFactory(); for (String s : signature) { try { - types.add(elementFactory.createTypeFromText(s, scope)); + types.add(elementFactory.createTypeFromText(s, element)); } catch (IncorrectOperationException e) { types.add(PsiType.NULL); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/resolve/pkg/See3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/resolve/pkg/See3.java new file mode 100644 index 000000000000..dd7bf93b51a2 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/resolve/pkg/See3.java @@ -0,0 +1,28 @@ +package pkg; + +/** + * @see #equals(Object) + + * @see A3#equals(Object) + * @see pkg.A3#equals(Object) + + * @see Object#equals(Object) + * @see java.lang.Object#equals(Object) + */ +class A3 { + public boolean equals(Object obj) { + return super.equals(obj); + } +} + +/** + * @see #equals(Object) + + * @see B3#equals(Object) + * @see pkg.B3#equals(Object) + + * @see Object#equals(Object) + * @see java.lang.Object#equals(Object) + */ +class B3 { +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/JavadocResolveTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/JavadocResolveTest.java index 6b2be0270645..7b776d725ae7 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/JavadocResolveTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/JavadocResolveTest.java @@ -30,6 +30,7 @@ public class JavadocResolveTest extends DaemonAnalyzerTestCase { public void testSee0() throws Exception { doTest(); } public void testSee1() throws Exception { doTest(); } public void testSee2() throws Exception { doTest(); } + public void testSee3() throws Exception { doTest(); } private void doTest() throws Exception { doTest(BASE_PATH + "/pkg/" + getTestName(false) + ".java", BASE_PATH, false, false);