diff --git a/bin/nix/idea.sh b/bin/nix/idea.sh index 486bfd094e2a..07d8e1f03b15 100644 --- a/bin/nix/idea.sh +++ b/bin/nix/idea.sh @@ -30,6 +30,30 @@ if [ -z "$IDEA_JDK" ]; then fi fi +VERSION_LOG='/tmp/java.version.log' +$IDEA_JDK/bin/java -version 2> $VERSION_LOG +grep 'OpenJDK' $VERSION_LOG +OPEN_JDK=$? +grep '64-Bit' $VERSION_LOG +BITS=$? +rm /tmp/java.version.log +if [ $OPEN_JDK -eq 0 ]; then + echo WARNING: You are launching IDE using OpenJDK Java runtime + echo + echo THIS IS STRICTLY UNSUPPORTED DUE TO KNOWN PERFORMANCE AND GRAPHICS PROBLEMS + echo + echo NOTE: If you have both Sun JDK and OpenJDK installed + echo please validate either IDEA_JDK or JDK_HOME points to valid Sun JDK installation + echo + echo Press Enter to continue. + read IGNORE +fi +if [ $BITS -eq 0 ]; then + BITS="64" +else + BITS="" +fi + #-------------------------------------------------------------------------- # Ensure the IDEA_HOME var for this script points to the # home directory where IntelliJ IDEA is installed on your system. diff --git a/build/lib/gant/jps-sources.zip b/build/lib/gant/jps-sources.zip index ec76cf49df46..156b692f32b0 100644 Binary files a/build/lib/gant/jps-sources.zip and b/build/lib/gant/jps-sources.zip differ diff --git a/build/lib/gant/lib/jps.jar b/build/lib/gant/lib/jps.jar index 495f788f98b7..258ade38632c 100644 Binary files a/build/lib/gant/lib/jps.jar and b/build/lib/gant/lib/jps.jar differ diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacCompiler.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacCompiler.java index 774035bf7b29..3c97e1e793cc 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacCompiler.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacCompiler.java @@ -317,6 +317,14 @@ public class JavacCompiler extends ExternalCompiler { } } } + else { + if (versionIndex > 5) { + // Unless explicitly specified by user, disable annotation processing by default for 'java compilation' mode + // This is needed to suppress unwanted side-effects from auto-discovered processors from compilation classpath + additionalOptions.add("-proc:none"); + } + } + while (tokenizer.hasMoreTokens()) { @NonNls String token = tokenizer.nextToken(); if (versionIndex == 0) { @@ -329,10 +337,10 @@ public class JavacCompiler extends ExternalCompiler { continue; // not supported in these versions } } + if (token.startsWith("-proc:")) { + continue; + } if (isAnnotationProcessing) { - if (token.startsWith("-proc:")) { - continue; - } if (token.startsWith("-implicit:")) { continue; } @@ -344,6 +352,7 @@ public class JavacCompiler extends ExternalCompiler { additionalOptions.add(token); } } + return additionalOptions; } diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/ViewAsGroup.java b/java/debugger/impl/src/com/intellij/debugger/actions/ViewAsGroup.java index 6dfe16463e06..088ec13e8fad 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/ViewAsGroup.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/ViewAsGroup.java @@ -24,6 +24,7 @@ import com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl; import com.intellij.debugger.ui.tree.render.NodeRenderer; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.project.DumbAware; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -34,7 +35,7 @@ import java.util.List; * Date: Sep 26, 2003 * Time: 11:05:57 PM */ -public class ViewAsGroup extends ActionGroup{ +public class ViewAsGroup extends ActionGroup implements DumbAware { private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.actions.ViewAsGroup"); private AnAction[] myChildren = AnAction.EMPTY_ARRAY; diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java b/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java index 4a71d7f56ebd..9476c8f92562 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java @@ -338,6 +338,11 @@ public class DebuggerSessionTab extends DebuggerSessionTabBase implements Dispos e.getPresentation().setText(ActionsBundle.message("group.XDebugger.settings.text")); e.getPresentation().setIcon(layoutGroup.getTemplatePresentation().getIcon()); } + + @Override + public boolean isDumbAware() { + return true; + } }; for (AnAction each : layout) { settings.add(each); diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/actions/AddFacetActionGroup.java b/java/idea-ui/src/com/intellij/facet/impl/ui/actions/AddFacetActionGroup.java index beb3b85073e5..0624e929c045 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/actions/AddFacetActionGroup.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/actions/AddFacetActionGroup.java @@ -22,6 +22,7 @@ import com.intellij.facet.FacetTypeRegistry; import com.intellij.openapi.actionSystem.ActionGroup; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.DumbAware; import org.jetbrains.annotations.Nullable; import java.util.Arrays; @@ -30,7 +31,7 @@ import java.util.Comparator; /** * @author nik */ -public class AddFacetActionGroup extends ActionGroup { +public class AddFacetActionGroup extends ActionGroup implements DumbAware { private final boolean myFromPopup; private final FacetEditorFacade myEditor; private AnAction[] myCachedChildren; diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportNode.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportNode.java index f66d36a9849c..351b992ec178 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportNode.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportNode.java @@ -52,7 +52,7 @@ public class FrameworkSupportNode extends CheckedTreeNode { private final Computable myBaseDirForLibrariesGetter; private LibraryCompositionOptionsPanel myLibraryCompositionOptionsPanel; - FrameworkSupportNode(final FrameworkSupportProvider provider, final FrameworkSupportNode parentNode, final FrameworkSupportModelImpl model, + public FrameworkSupportNode(final FrameworkSupportProvider provider, final FrameworkSupportNode parentNode, final FrameworkSupportModelImpl model, Computable baseDirForLibrariesGetter, Disposable parentDisposable) { super(provider); myBaseDirForLibrariesGetter = baseDirForLibrariesGetter; diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index 08cac928c5b7..aa9d0312b1a5 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -462,8 +462,8 @@ public class HighlightUtil { if (rType != null && expression != null && isCastIntentionApplicable(expression, lType)) { QuickFixAction.registerQuickFixAction(highlightInfo, new AddTypeCastFix(lType, expression)); } - if (lType instanceof PsiClassType && expression != null) { - QuickFixAction.registerQuickFixAction(highlightInfo, new WrapExpressionFix((PsiClassType)lType, expression)); + if (expression != null && lType != null) { + QuickFixAction.registerQuickFixAction(highlightInfo, new WrapExpressionFix(lType, expression)); } ChangeNewOperatorTypeFix.register(highlightInfo, expression, lType); return highlightInfo; diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/WrapExpressionFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/WrapExpressionFix.java index cf4aae9002e5..d4c85df105fb 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/WrapExpressionFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/WrapExpressionFix.java @@ -22,6 +22,7 @@ import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; +import com.intellij.psi.search.GlobalSearchScope; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -34,29 +35,47 @@ public class WrapExpressionFix implements IntentionAction { private final PsiExpression myExpression; private final PsiClassType myExpectedType; + private final boolean myPrimitiveExpected; - public WrapExpressionFix(PsiClassType expectedType, PsiExpression expression) { + public WrapExpressionFix(PsiType expectedType, PsiExpression expression) { myExpression = expression; - myExpectedType = expectedType; + myExpectedType = getClassType(expectedType, expression); + myPrimitiveExpected = expectedType instanceof PsiPrimitiveType; + } + + @Nullable + private static PsiClassType getClassType(PsiType type, PsiElement place) { + if (type instanceof PsiClassType) { + return (PsiClassType)type; + } + else if (type instanceof PsiPrimitiveType){ + return ((PsiPrimitiveType)type).getBoxedType(place.getManager(), GlobalSearchScope.allScope(place.getProject())); + } + return null; } @NotNull public String getText() { - final PsiMethod wrapper = myExpression.isValid() ? findWrapper(myExpression.getType(), myExpectedType) : null; + final PsiMethod wrapper = myExpression.isValid() ? findWrapper(myExpression.getType(), myExpectedType, myPrimitiveExpected) : null; final String methodPresentation = wrapper != null ? (wrapper.getContainingClass().getName() + "." + wrapper.getName()) : ""; return QuickFixBundle.message("wrap.expression.using.static.accessor.text", methodPresentation); } @Nullable - private static PsiMethod findWrapper(PsiType type, PsiClassType expectedType) { + private static PsiMethod findWrapper(PsiType type, PsiClassType expectedType, boolean primitiveExpected) { PsiClass aClass = expectedType.resolve(); if (aClass != null) { + PsiType expectedReturnType = expectedType; + if (primitiveExpected) { + expectedReturnType = PsiPrimitiveType.getUnboxedType(expectedType); + } + if (expectedReturnType == null) return null; PsiMethod[] methods = aClass.getMethods(); for (PsiMethod method : methods) { if (method.hasModifierProperty(PsiModifier.STATIC) && method.getParameterList().getParametersCount() == 1 && method.getParameterList().getParameters()[0].getType().equals(type) && method.getReturnType() != null && - expectedType.equals(method.getReturnType())) { + expectedReturnType.equals(method.getReturnType())) { return method; } } @@ -73,14 +92,15 @@ public class WrapExpressionFix implements IntentionAction { public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { return myExpression.isValid() && myExpression.getManager().isInProject(myExpression) + && myExpectedType != null && myExpectedType.isValid() && myExpression.getType() != null - && findWrapper(myExpression.getType(), myExpectedType) != null; + && findWrapper(myExpression.getType(), myExpectedType, myPrimitiveExpected) != null; } public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { if (!CodeInsightUtilBase.prepareFileForWrite(file)) return; - PsiMethod wrapper = findWrapper(myExpression.getType(), myExpectedType); + PsiMethod wrapper = findWrapper(myExpression.getType(), myExpectedType, myPrimitiveExpected); assert wrapper != null; PsiElementFactory factory = JavaPsiFacade.getInstance(file.getProject()).getElementFactory(); @NonNls String methodCallText = "Foo." + wrapper.getName() + "()"; @@ -97,39 +117,43 @@ public class WrapExpressionFix implements IntentionAction { } public static void registerWrapAction (JavaResolveResult[] candidates, PsiExpression[] expressions, HighlightInfo highlightInfo) { - PsiClassType expectedType = null; + PsiType expectedType = null; PsiExpression expr = null; nextMethod: for (int i = 0; i < candidates.length && expectedType == null; i++) { - JavaResolveResult candidate = candidates[i]; - PsiSubstitutor substitutor = candidate.getSubstitutor(); + final JavaResolveResult candidate = candidates[i]; + final PsiSubstitutor substitutor = candidate.getSubstitutor(); final PsiElement element = candidate.getElement(); assert element != null; - PsiParameter[] parameters = ((PsiMethod)element).getParameterList().getParameters(); - if (parameters.length != expressions.length) continue; + final PsiMethod method = (PsiMethod)element; + final PsiParameter[] parameters = method.getParameterList().getParameters(); + if (!method.isVarArgs() && parameters.length != expressions.length) continue; for (int j = 0; j < expressions.length; j++) { PsiExpression expression = expressions[j]; - if (expression.getType() != null) { - PsiType paramType = parameters[j].getType(); + final PsiType exprType = expression.getType(); + if (exprType != null) { + PsiType paramType = parameters[Math.min(j, parameters.length -1)].getType(); + if (paramType instanceof PsiEllipsisType) { + paramType = ((PsiEllipsisType)paramType).getComponentType(); + } paramType = substitutor != null ? substitutor.substitute(paramType) : paramType; - if (paramType.isAssignableFrom(expression.getType())) continue; - if (paramType instanceof PsiClassType) { - if (expectedType == null && findWrapper(expression.getType(), (PsiClassType) paramType) != null) { - expectedType = (PsiClassType) paramType; - expr = expression; - } else { - expectedType = null; - expr = null; - continue nextMethod; - } + if (paramType.isAssignableFrom(exprType)) continue; + final PsiClassType classType = getClassType(paramType, expression); + if (expectedType == null && classType != null && findWrapper(exprType, classType, paramType instanceof PsiPrimitiveType) != null) { + expectedType = paramType; + expr = expression; + } else { + expectedType = null; + expr = null; + continue nextMethod; } } } } if (expectedType != null) { - QuickFixAction.registerQuickFixAction(highlightInfo, expr.getTextRange(), new WrapExpressionFix(expectedType, expr), null); + QuickFixAction.registerQuickFixAction(highlightInfo, expr.getTextRange(), new WrapExpressionFix(expectedType, expr), null); } } diff --git a/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocExternalFilter.java b/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocExternalFilter.java index 960ab8abec61..3d26640288e7 100644 --- a/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocExternalFilter.java +++ b/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocExternalFilter.java @@ -24,8 +24,10 @@ import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.util.ProgressIndicatorBase; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; @@ -121,6 +123,12 @@ public class JavaDocExternalFilter { return DOC_ELEMENT_PROTOCOL + root + href; } + if (Comparing.strEqual(VirtualFileManager.extractProtocol(root), LocalFileSystem.PROTOCOL)) { + final String path = VirtualFileManager.extractPath(root); + if (!path.startsWith("/")) {//skip host for local file system files (format - file://host_name/path) + root = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, "/" + path); + } + } return ourHTMLFilesuffix.matcher(root).replaceAll("/") + href; } }; diff --git a/java/java-impl/src/com/intellij/codeInsight/lookup/PsiTypeLookupItem.java b/java/java-impl/src/com/intellij/codeInsight/lookup/PsiTypeLookupItem.java index 5ad8b86fddc1..545172114b67 100644 --- a/java/java-impl/src/com/intellij/codeInsight/lookup/PsiTypeLookupItem.java +++ b/java/java-impl/src/com/intellij/codeInsight/lookup/PsiTypeLookupItem.java @@ -15,6 +15,8 @@ */ package com.intellij.codeInsight.lookup; +import com.intellij.codeInsight.completion.DefaultInsertHandler; +import com.intellij.codeInsight.completion.InsertionContext; import com.intellij.psi.*; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -33,6 +35,12 @@ public class PsiTypeLookupItem extends LookupItem { return super.equals(o) && o instanceof PsiTypeLookupItem && getBracketsCount() == ((PsiTypeLookupItem) o).getBracketsCount(); } + @Override + public void handleInsert(InsertionContext context) { + DefaultInsertHandler.addImportForItem(context.getFile(), context.getStartOffset(), this); + super.handleInsert(context); + } + @Override public int hashCode() { final int fromSuper = super.hashCode(); diff --git a/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodProcessor.java b/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodProcessor.java index 1ec3ceb5e20d..1dddf700b55b 100644 --- a/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodProcessor.java @@ -726,6 +726,10 @@ public class ExtractMethodProcessor implements MatchProvider { myExtractedMethod = (PsiMethod)myTargetClass.addAfter(newMethod, myAnchor); if (myNeedChangeContext) { ChangeContextUtil.decodeContextInfo(myExtractedMethod, myTargetClass, RefactoringUtil.createThisExpression(myManager, null)); + if (myMethodCall.resolveMethod() != myExtractedMethod) { + final PsiReferenceExpression methodExpression = myMethodCall.getMethodExpression(); + methodExpression.setQualifierExpression(RefactoringUtil.createThisExpression(myManager, myTargetClass)); + } } } diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java index 3773594dc847..69f3b958cc47 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java @@ -33,6 +33,7 @@ import com.intellij.psi.controlFlow.*; import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; import com.intellij.psi.infos.MethodCandidateInfo; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.InheritanceUtil; import com.intellij.psi.util.PsiTreeUtil; @@ -592,7 +593,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor { if (!name.equals(parmName)) { name = myJavaCodeStyle.suggestUniqueVariableName(name, block.getFirstChild(), true); } - RefactoringUtil.renameVariableReferences(parm, name, GlobalSearchScope.projectScope(myProject)); + RefactoringUtil.renameVariableReferences(parm, name, new LocalSearchScope(myMethodCopy.getBody()), true); PsiType paramType = parm.getType(); @NonNls String defaultValue; if (paramType instanceof PsiEllipsisType) { @@ -687,7 +688,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor { name = newName; } if (!name.equals(oldName)) { - RefactoringUtil.renameVariableReferences(var, name, GlobalSearchScope.projectScope(myProject)); + RefactoringUtil.renameVariableReferences(var, name, new LocalSearchScope(myMethodCopy.getBody()), true); var.getNameIdentifier().replace(myFactory.createIdentifier(name)); } } @@ -1313,4 +1314,4 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor { return myReference == null ? Collections.singletonList(myMethod) : Arrays.asList(myReference, myMethod); } } -} \ No newline at end of file +} diff --git a/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java b/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java index 2d9a51938ce4..dfb93e683027 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java +++ b/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java @@ -402,7 +402,14 @@ public class RefactoringUtil { } public static void renameVariableReferences(PsiVariable variable, String newName, SearchScope scope) throws IncorrectOperationException { - for (PsiReference reference : ReferencesSearch.search(variable, scope)) { + renameVariableReferences(variable, newName, scope, false); + } + + public static void renameVariableReferences(PsiVariable variable, + String newName, + SearchScope scope, + final boolean ignoreAccessScope) throws IncorrectOperationException { + for (PsiReference reference : ReferencesSearch.search(variable, scope, ignoreAccessScope)) { reference.handleElementRename(newName); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterParseAssignment.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterParseAssignment.java new file mode 100644 index 000000000000..ea20b8721e18 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterParseAssignment.java @@ -0,0 +1,4 @@ +// "Wrap using 'Long.parseLong'" "true" +public class Test { + private long lo = Long.parseLong("42"); +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterParseInCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterParseInCall.java new file mode 100644 index 000000000000..5ce32b3862cb --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterParseInCall.java @@ -0,0 +1,8 @@ +// "Wrap using 'Long.parseLong'" "true" +public class Test { + void ba() { + fa(Long.parseLong("42")); + } + + void fa(long l){} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterParseInVarargsCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterParseInVarargsCall.java new file mode 100644 index 000000000000..31706139c373 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterParseInVarargsCall.java @@ -0,0 +1,8 @@ +// "Wrap using 'Long.parseLong'" "true" +public class Test { + void ba(long l) { + fa(l, Long.parseLong("42")); + } + + void fa(long... l){} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterValueofAssignment.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterValueofAssignment.java new file mode 100644 index 000000000000..1ac02ad800e2 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterValueofAssignment.java @@ -0,0 +1,4 @@ +// "Wrap using 'Long.valueOf'" "true" +public class Test { + private Long lo = Long.valueOf("42"); +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterValueofCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterValueofCall.java new file mode 100644 index 000000000000..19333acdf670 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterValueofCall.java @@ -0,0 +1,8 @@ +// "Wrap using 'Long.valueOf'" "true" +public class Test { + void ba() { + fa(Long.valueOf("42")); + } + + void fa(Long l){} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterValueofInVarargsCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterValueofInVarargsCall.java new file mode 100644 index 000000000000..11e61b1c5d59 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterValueofInVarargsCall.java @@ -0,0 +1,8 @@ +// "Wrap using 'Long.valueOf'" "true" +public class Test { + void ba(Long l) { + fa(l, Long.valueOf("42")); + } + + void fa(Long... l){} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterValueofVarargsCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterValueofVarargsCall.java new file mode 100644 index 000000000000..4291e43fe0a1 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/afterValueofVarargsCall.java @@ -0,0 +1,8 @@ +// "Wrap using 'Long.valueOf'" "true" +public class Test { + void ba() { + fa(Long.valueOf("42")); + } + + void fa(Long l, int... ii){} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeParseAssignment.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeParseAssignment.java new file mode 100644 index 000000000000..0700d003d994 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeParseAssignment.java @@ -0,0 +1,4 @@ +// "Wrap using 'Long.parseLong'" "true" +public class Test { + private long lo = "42"; +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeParseInCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeParseInCall.java new file mode 100644 index 000000000000..d4d0283e1f6c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeParseInCall.java @@ -0,0 +1,8 @@ +// "Wrap using 'Long.parseLong'" "true" +public class Test { + void ba() { + fa("42"); + } + + void fa(long l){} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeParseInVarargsCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeParseInVarargsCall.java new file mode 100644 index 000000000000..62ca613e69d9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeParseInVarargsCall.java @@ -0,0 +1,8 @@ +// "Wrap using 'Long.parseLong'" "true" +public class Test { + void ba(long l) { + fa(l, "42"); + } + + void fa(long... l){} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeValueofAssignment.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeValueofAssignment.java new file mode 100644 index 000000000000..8b812118de12 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeValueofAssignment.java @@ -0,0 +1,4 @@ +// "Wrap using 'Long.valueOf'" "true" +public class Test { + private Long lo = "42"; +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeValueofCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeValueofCall.java new file mode 100644 index 000000000000..17604b21f05c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeValueofCall.java @@ -0,0 +1,8 @@ +// "Wrap using 'Long.valueOf'" "true" +public class Test { + void ba() { + fa("42"); + } + + void fa(Long l){} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeValueofInVarargsCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeValueofInVarargsCall.java new file mode 100644 index 000000000000..a49a329bbf79 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeValueofInVarargsCall.java @@ -0,0 +1,8 @@ +// "Wrap using 'Long.valueOf'" "true" +public class Test { + void ba(Long l) { + fa(l, "42"); + } + + void fa(Long... l){} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeValueofVarargsCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeValueofVarargsCall.java new file mode 100644 index 000000000000..7dd6f914ff0a --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression/beforeValueofVarargsCall.java @@ -0,0 +1,8 @@ +// "Wrap using 'Long.valueOf'" "true" +public class Test { + void ba() { + fa("42"); + } + + void fa(Long l, int... ii){} +} diff --git a/java/java-tests/testData/refactoring/extractMethod/ConflictingAnonymous.java b/java/java-tests/testData/refactoring/extractMethod/ConflictingAnonymous.java new file mode 100644 index 000000000000..9b9f4e280df1 --- /dev/null +++ b/java/java-tests/testData/refactoring/extractMethod/ConflictingAnonymous.java @@ -0,0 +1,10 @@ +public class Test { + void foo() { + new A() { + void fe() {System.out.println("");} + } + } +} +class A { + void newMethod(){} +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/extractMethod/ConflictingAnonymous_after.java b/java/java-tests/testData/refactoring/extractMethod/ConflictingAnonymous_after.java new file mode 100644 index 000000000000..4b206009a893 --- /dev/null +++ b/java/java-tests/testData/refactoring/extractMethod/ConflictingAnonymous_after.java @@ -0,0 +1,16 @@ +public class Test { + void foo() { + new A() { + void fe() { + Test.this.newMethod(); + } + } + } + + private void newMethod() { + System.out.println(""); + } +} +class A { + void newMethod(){} +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/inlineMethod/ParamNameConflictsWithLocalVar.java b/java/java-tests/testData/refactoring/inlineMethod/ParamNameConflictsWithLocalVar.java new file mode 100644 index 000000000000..7f3adbdc2ad6 --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineMethod/ParamNameConflictsWithLocalVar.java @@ -0,0 +1,14 @@ +public class ABl { + void foo(int fe) { + System.out.println(fe); + } + + void bar(boolean br) { + int fe = 0; + if (br) { + foo(fe); + } else { + foo(11); + } + } +} diff --git a/java/java-tests/testData/refactoring/inlineMethod/ParamNameConflictsWithLocalVar.java.after b/java/java-tests/testData/refactoring/inlineMethod/ParamNameConflictsWithLocalVar.java.after new file mode 100644 index 000000000000..008bc752ec9e --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineMethod/ParamNameConflictsWithLocalVar.java.after @@ -0,0 +1,11 @@ +public class ABl { + + void bar(boolean br) { + int fe = 0; + if (br) { + System.out.println(fe); + } else { + System.out.println(11); + } + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/WrapExpressionFixTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/WrapExpressionFixTest.java new file mode 100644 index 000000000000..2e45a824a8d4 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/WrapExpressionFixTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2000-2010 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 com.intellij.codeInsight.daemon.quickFix; + +import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.pom.java.LanguageLevel; + +public class WrapExpressionFixTest extends LightQuickFixTestCase { + protected void setUp() throws Exception { + super.setUp(); + LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_6); + } + + public void test() throws Exception { + doAllTests(); + } + + protected String getBasePath() { + return "/codeInsight/daemonCodeAnalyzer/quickFix/wrapExpression"; + } +} + diff --git a/java/java-tests/testSrc/com/intellij/ide/util/frameworkSupport/FrameworkSupportProviderTestCase.java b/java/java-tests/testSrc/com/intellij/ide/util/frameworkSupport/FrameworkSupportProviderTestCase.java new file mode 100644 index 000000000000..eb63696cd21a --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/ide/util/frameworkSupport/FrameworkSupportProviderTestCase.java @@ -0,0 +1,106 @@ +package com.intellij.ide.util.frameworkSupport; + +import com.intellij.facet.Facet; +import com.intellij.facet.FacetManager; +import com.intellij.facet.FacetTypeId; +import com.intellij.facet.ui.FacetBasedFrameworkSupportProvider; +import com.intellij.ide.util.newProjectWizard.FrameworkSupportNode; +import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportCommunicator; +import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportModelImpl; +import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.openapi.roots.ModuleRootManager; +import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.testFramework.IdeaTestCase; +import com.intellij.testFramework.PsiTestUtil; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.util.*; + +/** + * @author nik + */ +public abstract class FrameworkSupportProviderTestCase extends IdeaTestCase { + private FrameworkSupportModelImpl myFrameworkSupportModel; + private Map myConfigurables; + private Map myNodes; + + @Override + protected void setUp() throws Exception { + super.setUp(); + myFrameworkSupportModel = new FrameworkSupportModelImpl(getProject(), null); + myNodes = new HashMap(); + for (FrameworkSupportProvider provider : FrameworkSupportProvider.EXTENSION_POINT.getExtensions()) { + final FrameworkSupportNode node = new FrameworkSupportNode(provider, null, myFrameworkSupportModel, null, getTestRootDisposable()); + myNodes.put(provider, node); + myFrameworkSupportModel.registerComponent(provider, node); + } + myConfigurables = new HashMap(); + } + + protected void addSupport() throws IOException { + final VirtualFile root = getVirtualFile(createTempDir("contentRoot")); + PsiTestUtil.addContentRoot(myModule, root); + final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel(); + try { + List selectedConfigurables = new ArrayList(); + for (FrameworkSupportNode node : myNodes.values()) { + if (node.isChecked()) { + final FrameworkSupportConfigurable configurable = getOrCreateConfigurable(node.getProvider()); + configurable.addSupport(myModule, model, null); + selectedConfigurables.add(configurable); + } + } + for (FrameworkSupportCommunicator communicator : FrameworkSupportCommunicator.EP_NAME.getExtensions()) { + communicator.onFrameworkSupportAdded(myModule, model, selectedConfigurables, myFrameworkSupportModel); + } + } + finally { + model.commit(); + } + for (FrameworkSupportConfigurable configurable : myConfigurables.values()) { + Disposer.dispose(configurable); + } + } + + protected FrameworkSupportConfigurable selectFramework(@NotNull FacetTypeId id) { + return selectFramework(FacetBasedFrameworkSupportProvider.getProviderId(id)); + } + + protected FrameworkSupportConfigurable selectFramework(@NotNull String id) { + for (FrameworkSupportProvider provider : FrameworkSupportProvider.EXTENSION_POINT.getExtensions()) { + if (provider.getId().equals(id)) { + return selectFramework(provider); + } + } + fail("Framework provider with id='" + id + "' not found"); + return null; + } + + protected FrameworkSupportConfigurable selectFramework(@NotNull FrameworkSupportProvider provider) { + final FrameworkSupportConfigurable configurable = getOrCreateConfigurable(provider); + myNodes.get(provider).setChecked(true); + configurable.onFrameworkSelectionChanged(true); + return configurable; + } + + private FrameworkSupportConfigurable getOrCreateConfigurable(FrameworkSupportProvider provider) { + FrameworkSupportConfigurable configurable = myConfigurables.get(provider); + if (configurable == null) { + configurable = provider.createConfigurable(myFrameworkSupportModel); + myConfigurables.put(provider, configurable); + } + return configurable; + } + + protected F getFacet(FacetTypeId id) { + final F facet = FacetManager.getInstance(myModule).getFacetByType(id); + assertNotNull(id + " facet not found", facet); + return facet; + } + + protected VirtualFile getContentRoot() { + return ModuleRootManager.getInstance(myModule).getContentRoots()[0]; + } +} diff --git a/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java b/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java index ef41e85586f9..a3ce352ff46d 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java @@ -168,6 +168,12 @@ public class ExtractMethodTest extends LightCodeInsightTestCase { doTest(); } + + public void testConflictingAnonymous() throws Exception { + doTest(); + } + + public void testFinalParamUsedInsideAnon() throws Exception { CodeStyleSettingsManager.getSettings(getProject()).GENERATE_FINAL_PARAMETERS = false; doTest(); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java index ddbcbc3c359e..08cb36ca145a 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java @@ -157,6 +157,10 @@ public class InlineMethodTest extends LightCodeInsightTestCase { doTest(); } + public void testParamNameConflictsWithLocalVar() throws Exception { + doTest(); + } + @Override protected Sdk getProjectJDK() { return JavaSdkImpl.getMockJdk17("java 1.5"); diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionService.java b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionService.java index 97ecbbc3ab5f..94c607d7f167 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionService.java +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionService.java @@ -80,7 +80,7 @@ public abstract class CompletionService { for (int i = contributors.indexOf(from) + 1; i < contributors.size(); i++) { final CompletionContributor contributor = contributors.get(i); - if (dumb && !(contributor instanceof DumbAware)) continue; + if (dumb && !DumbService.isDumbAware(contributor)) continue; final CompletionResultSet result = createResultSet(parameters, consumer, contributor); contributor.fillCompletionVariants(parameters, result); diff --git a/platform/lang-api/src/com/intellij/execution/filters/CompositeFilter.java b/platform/lang-api/src/com/intellij/execution/filters/CompositeFilter.java index 9e80cb261a73..7258b6837515 100644 --- a/platform/lang-api/src/com/intellij/execution/filters/CompositeFilter.java +++ b/platform/lang-api/src/com/intellij/execution/filters/CompositeFilter.java @@ -33,7 +33,7 @@ public class CompositeFilter implements Filter { public Result applyFilter(final String line, final int entireLength) { final boolean dumb = DumbService.getInstance(myProject).isDumb(); for (final Filter filter : myFilters) { - if (!dumb || filter instanceof DumbAware) { + if (!dumb || DumbService.isDumbAware(filter)) { final Result info = filter.applyFilter(line, entireLength); if (info != null) { return info; diff --git a/platform/lang-api/src/com/intellij/execution/runners/ExecutionUtil.java b/platform/lang-api/src/com/intellij/execution/runners/ExecutionUtil.java index 5d61ef91a0b8..428ee23b2e46 100644 --- a/platform/lang-api/src/com/intellij/execution/runners/ExecutionUtil.java +++ b/platform/lang-api/src/com/intellij/execution/runners/ExecutionUtil.java @@ -55,6 +55,8 @@ public class ExecutionUtil { String error = e.getMessage(); HyperlinkListener listener = null; + LOG.debug(error); + if (error.contains("87") && e instanceof ProcessNotCreatedException) { final String commandLineString = ((ProcessNotCreatedException)e).getCommandLine().getCommandLineString(); if (commandLineString.length() > 1024 * 32) { diff --git a/platform/lang-api/src/com/intellij/ide/actions/CreateElementActionBase.java b/platform/lang-api/src/com/intellij/ide/actions/CreateElementActionBase.java index 0a61b591a903..95a3d6111d28 100644 --- a/platform/lang-api/src/com/intellij/ide/actions/CreateElementActionBase.java +++ b/platform/lang-api/src/com/intellij/ide/actions/CreateElementActionBase.java @@ -88,7 +88,7 @@ public abstract class CreateElementActionBase extends AnAction { presentation.setEnabled(enabled); } - protected boolean isDumbAware() { + public boolean isDumbAware() { return false; } diff --git a/platform/lang-api/src/com/intellij/lang/PsiBuilder.java b/platform/lang-api/src/com/intellij/lang/PsiBuilder.java index 2f2052f1f31a..e730513dad5d 100644 --- a/platform/lang-api/src/com/intellij/lang/PsiBuilder.java +++ b/platform/lang-api/src/com/intellij/lang/PsiBuilder.java @@ -53,7 +53,7 @@ public interface PsiBuilder extends UserDataHolder { IElementType getTokenType(); /** - * Sets optional remapper that can changs the type of freshly lexed tokens. + * Sets optional remapper that can change the type of freshly lexed tokens. * Output of getTokenType() is affected by it. * @param remapper the remapper object, or null. */ @@ -110,17 +110,25 @@ public interface PsiBuilder extends UserDataHolder { */ void done(IElementType type); + /** + * Like done(), but collapses all tokens between start and end markers into single leaf node of given type. + * + * @param type the type of the node in the AST tree. + */ + void collapse(IElementType type); + /** * TODO doc - * @param type - * @param before + * @param type the type of the node in the AST tree. + * @param before marker to complete this one before. */ void doneBefore(IElementType type, Marker before); /** * TODO doc - * @param type - * @param before + * @param type the type of the node in the AST tree. + * @param before marker to complete this one before. + * @param errorMessage for error element. */ void doneBefore(IElementType type, Marker before, String errorMessage); @@ -128,7 +136,7 @@ public interface PsiBuilder extends UserDataHolder { * Completes this marker and labels it as error element with specified message. Before calling this method, * all markers added after the beginning of this marker must be either dropped or completed. * - * @param message for error element + * @param message for error element. */ void error(String message); } @@ -162,7 +170,7 @@ public interface PsiBuilder extends UserDataHolder { ASTNode getTreeBuilt(); /** - * Same as {@link #getTreeBuilt()} but returns a light tree, which is build faster, produces less garbage but is uncapable of creating a PSI over. + * Same as {@link #getTreeBuilt()} but returns a light tree, which is build faster, produces less garbage but is incapable of creating a PSI over. * @return the light tree built. */ FlyweightCapableTreeStructure getLightTree(); diff --git a/platform/lang-api/src/com/intellij/lang/folding/FoldingDescriptor.java b/platform/lang-api/src/com/intellij/lang/folding/FoldingDescriptor.java index 5b17f826924f..47593ec2449f 100644 --- a/platform/lang-api/src/com/intellij/lang/folding/FoldingDescriptor.java +++ b/platform/lang-api/src/com/intellij/lang/folding/FoldingDescriptor.java @@ -33,7 +33,7 @@ import java.util.Set; * * @author max * @see FoldingBuilder - */ + */ public class FoldingDescriptor { public static final FoldingDescriptor[] EMPTY = new FoldingDescriptor[0]; @@ -86,7 +86,7 @@ public class FoldingDescriptor { /** * @return the node to which the folding region is related. */ - @NotNull + @NotNull public ASTNode getElement() { return myElement; } @@ -117,7 +117,7 @@ public class FoldingDescriptor { } return null; } - + @NotNull public Set getDependencies() { return myDependencies; diff --git a/platform/lang-api/src/com/intellij/lang/folding/LanguageFolding.java b/platform/lang-api/src/com/intellij/lang/folding/LanguageFolding.java index 95dfbdfe9458..b3c1d77c6b7d 100644 --- a/platform/lang-api/src/com/intellij/lang/folding/LanguageFolding.java +++ b/platform/lang-api/src/com/intellij/lang/folding/LanguageFolding.java @@ -63,7 +63,7 @@ public class LanguageFolding extends LanguageExtension { } public static FoldingDescriptor[] buildFoldingDescriptors(FoldingBuilder builder, PsiElement root, Document document, boolean quick) { - if (!(builder instanceof DumbAware) && DumbService.getInstance(root.getProject()).isDumb()) { + if (!DumbService.isDumbAware(builder) && DumbService.getInstance(root.getProject()).isDumb()) { return FoldingDescriptor.EMPTY; } diff --git a/platform/lang-api/src/com/intellij/psi/search/PsiElementProcessor.java b/platform/lang-api/src/com/intellij/psi/search/PsiElementProcessor.java index 00b3048140de..d87d4eff9d07 100644 --- a/platform/lang-api/src/com/intellij/psi/search/PsiElementProcessor.java +++ b/platform/lang-api/src/com/intellij/psi/search/PsiElementProcessor.java @@ -118,10 +118,14 @@ public interface PsiElementProcessor { return myFoundElement; } - public boolean execute(T element) { + public boolean setFound(T element) { myFoundElement = element; return false; } + + public boolean execute(T element) { + return setFound(element); + } } class FindFilteredElement extends FindElement { diff --git a/platform/lang-api/src/com/intellij/util/PsiIconUtil.java b/platform/lang-api/src/com/intellij/util/PsiIconUtil.java index 30537756771b..874a1fdeffce 100644 --- a/platform/lang-api/src/com/intellij/util/PsiIconUtil.java +++ b/platform/lang-api/src/com/intellij/util/PsiIconUtil.java @@ -36,7 +36,7 @@ public class PsiIconUtil { public static Icon getProvidersIcon(PsiElement element, int flags) { final boolean dumb = DumbService.getInstance(element.getProject()).isDumb(); for (final IconProvider iconProvider : getIconProviders()) { - if (dumb && !(iconProvider instanceof DumbAware)) { + if (dumb && !DumbService.isDumbAware(iconProvider)) { continue; } diff --git a/platform/lang-impl/src/com/intellij/codeHighlighting/TextEditorHighlightingPass.java b/platform/lang-impl/src/com/intellij/codeHighlighting/TextEditorHighlightingPass.java index 4e6069ddecd5..456cfa04787e 100644 --- a/platform/lang-impl/src/com/intellij/codeHighlighting/TextEditorHighlightingPass.java +++ b/platform/lang-impl/src/com/intellij/codeHighlighting/TextEditorHighlightingPass.java @@ -59,7 +59,7 @@ public abstract class TextEditorHighlightingPass implements HighlightingPass { } private boolean isValid() { - if (isDumbMode() && !(this instanceof DumbAware)) { + if (isDumbMode() && !DumbService.isDumbAware(this)) { return false; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java index b0158dc1b026..2dd65f91df3d 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -148,7 +148,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { result.setResult(initializationContext); for (final CompletionContributor contributor : CompletionContributor.forLanguage(PsiUtilBase.getLanguageInEditor(editor, project))) { - if (DumbService.getInstance(project).isDumb() && !(contributor instanceof DumbAware)) { + if (DumbService.getInstance(project).isDumb() && !DumbService.isDumbAware(contributor)) { continue; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/actions/CodeCompletionGroup.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/actions/CodeCompletionGroup.java index dfdf98c073c9..b4be2de99a73 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/actions/CodeCompletionGroup.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/actions/CodeCompletionGroup.java @@ -18,11 +18,12 @@ package com.intellij.codeInsight.completion.actions; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; -public class CodeCompletionGroup extends DefaultActionGroup { +public class CodeCompletionGroup extends DefaultActionGroup implements DumbAware { public void update(AnActionEvent event){ Presentation presentation = event.getPresentation(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java index 3544c091d703..538aa6208ad9 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java @@ -111,7 +111,7 @@ public abstract class PassExecutorService implements Disposable { for (int i = 0; i < passes.length; i++) { final HighlightingPass pass = passes[i]; - if (dumb && !(pass instanceof DumbAware)) { + if (dumb && !DumbService.isDumbAware(pass)) { continue; } @@ -319,7 +319,7 @@ public abstract class PassExecutorService implements Disposable { boolean success = ApplicationManagerEx.getApplicationEx().tryRunReadAction(new Runnable() { public void run() { try { - if (DumbService.getInstance(myProject).isDumb() && !(myPass instanceof DumbAware)) { + if (DumbService.getInstance(myProject).isDumb() && !DumbService.isDumbAware(myPass)) { return; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/analysis/DefaultHighlightVisitor.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/analysis/DefaultHighlightVisitor.java index cd7b4f720c96..5318b3f2cb7e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/analysis/DefaultHighlightVisitor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/analysis/DefaultHighlightVisitor.java @@ -127,7 +127,7 @@ public class DefaultHighlightVisitor implements HighlightVisitor, DumbAware { JobUtil.invokeConcurrentlyUnderMyProgress(annotators, new Processor() { public boolean process(Annotator annotator) { - if (dumb && !(annotator instanceof DumbAware)) { + if (dumb && !DumbService.isDumbAware(annotator)) { return true; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/BackspaceHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/BackspaceHandler.java index 3625fdee6ce7..c88309abe221 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/BackspaceHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/BackspaceHandler.java @@ -162,8 +162,11 @@ public class BackspaceHandler extends EditorWriteActionHandler { final CharSequence charSeq = editor.getDocument().getCharsSequence(); // smart backspace is activated only if all characters in the check range are whitespace characters - for(int pos=startCheckRange; pos referenceClass = ref.getClass(); for (UnresolvedReferenceQuickFixProvider each : fixProviders) { - if (dumb && !(each instanceof DumbAware)) { + if (dumb && !DumbService.isDumbAware(each)) { continue; } if (ReflectionCache.isAssignable(each.getReferenceClass(), referenceClass)) { diff --git a/platform/lang-impl/src/com/intellij/execution/actions/BaseRunConfigurationAction.java b/platform/lang-impl/src/com/intellij/execution/actions/BaseRunConfigurationAction.java index 62afe1947d0b..564fa8d0a01d 100644 --- a/platform/lang-impl/src/com/intellij/execution/actions/BaseRunConfigurationAction.java +++ b/platform/lang-impl/src/com/intellij/execution/actions/BaseRunConfigurationAction.java @@ -178,12 +178,7 @@ public abstract class BaseRunConfigurationAction extends ActionGroup { final RunnerAndConfigurationSettings existing = context.findExisting(); RunnerAndConfigurationSettings configuration = existing; if (configuration == null) { - try { - configuration = context.getConfiguration(); - } - catch (IndexNotReadyException e) { - configuration = null; - } + configuration = context.getConfiguration(); } if (configuration == null){ presentation.setEnabled(false); diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java index efefb4a811ad..640621cae453 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java @@ -197,7 +197,7 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { myHistoryViewer.getContentComponent().addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent event) { - if (UIUtil.isReallyTypedEvent(event)) { + if (myFullEditor == null && UIUtil.isReallyTypedEvent(event)) { myConsoleEditor.getContentComponent().requestFocus(); myConsoleEditor.processKeyTyped(event); } diff --git a/platform/lang-impl/src/com/intellij/ide/actions/CreateFileAction.java b/platform/lang-impl/src/com/intellij/ide/actions/CreateFileAction.java index 1937fc015756..6ed9e2758a34 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/CreateFileAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/CreateFileAction.java @@ -42,7 +42,7 @@ public class CreateFileAction extends CreateElementActionBase implements DumbAwa } @Override - protected boolean isDumbAware() { + public boolean isDumbAware() { return CreateFileAction.class.equals(getClass()); } diff --git a/platform/lang-impl/src/com/intellij/ide/actions/ExcludingActionGroup.java b/platform/lang-impl/src/com/intellij/ide/actions/ExcludingActionGroup.java index 5d3738a00dd2..27e74a2200ff 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/ExcludingActionGroup.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/ExcludingActionGroup.java @@ -43,6 +43,11 @@ public class ExcludingActionGroup extends ActionGroup { myDelegate.update(e); } + @Override + public boolean isDumbAware() { + return myDelegate.isDumbAware(); + } + @NotNull public AnAction[] getChildren(@Nullable AnActionEvent e) { List result = new ArrayList(); diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/actions/CreateFromTemplateGroup.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/actions/CreateFromTemplateGroup.java index 0611e9e2f5a7..f86adaef8821 100644 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/actions/CreateFromTemplateGroup.java +++ b/platform/lang-impl/src/com/intellij/ide/fileTemplates/actions/CreateFromTemplateGroup.java @@ -27,13 +27,14 @@ import com.intellij.ide.fileTemplates.ui.SelectTemplateDialog; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; import org.jetbrains.annotations.Nullable; import java.util.*; -public class CreateFromTemplateGroup extends ActionGroup{ +public class CreateFromTemplateGroup extends ActionGroup implements DumbAware { private static final Logger LOG = Logger.getInstance("#com.intellij.ide.fileTemplates.actions.CreateFromTemplateGroup"); public void update(AnActionEvent event){ diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ContributorsBasedGotoByModel.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ContributorsBasedGotoByModel.java index 22a438d5c6e9..83f5480b033d 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ContributorsBasedGotoByModel.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ContributorsBasedGotoByModel.java @@ -87,7 +87,7 @@ public abstract class ContributorsBasedGotoByModel implements ChooseByNameModel for (ChooseByNameContributor contributor : myContributors) { try { - if (dumb && !(contributor instanceof DumbAware)) { + if (dumb && !DumbService.isDumbAware(contributor)) { continue; } diff --git a/platform/lang-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java b/platform/lang-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java index 69cdbc54521d..64bcae71ece0 100644 --- a/platform/lang-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java +++ b/platform/lang-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java @@ -277,6 +277,11 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder { myBuilder.done(this); } + public void collapse(IElementType type) { + myType = type; + myBuilder.collapse(this); + } + public void doneBefore(IElementType type, Marker before) { myType = type; myBuilder.doneBefore(this, before); @@ -373,6 +378,7 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder { private static class DoneMarker extends ProductionMarker { public StartMarker myStart; + public boolean myCollapse = false; public DoneMarker() {} @@ -470,6 +476,8 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder { } public void advanceLexer() { + if (eof()) return; + if (!myTokenTypeChecked) { LOG.assertTrue(eof(), "Probably a bug: eating token without its type checking"); } @@ -593,10 +601,9 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder { myProduction.add(doneMarker); } - public void done(Marker marker) { + public void done(final Marker marker) { doValidityChecks(marker); - DoneMarker doneMarker = DONE_MARKERS.alloc(); doneMarker.myStart = (StartMarker)marker; doneMarker.myLexemeIndex = myCurrentLexeme; @@ -605,6 +612,11 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder { myProduction.add(doneMarker); } + public void collapse(final Marker marker) { + done(marker); + ((StartMarker)marker).myDoneMarker.myCollapse = true; + } + @SuppressWarnings({"UseOfSystemOutOrSystemErr", "SuspiciousMethodCalls"}) private void doValidityChecks(final Marker marker) { if (myDebugMode) { @@ -828,9 +840,14 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder { lexIndex = insertLeafs(lexIndex, childMarker.myLexemeIndex, ast); - CompositeElement childNode = createComposite(childMarker); - ast.rawAddChildren(childNode); - lexIndex = bind(childNode, childMarker, lexIndex); + if (!childMarker.myDoneMarker.myCollapse) { + CompositeElement childNode = createComposite(childMarker); + ast.rawAddChildren(childNode); + lexIndex = bind(childNode, childMarker, lexIndex); + } + else { + lexIndex = collapseLeafs(ast, childMarker); + } lexIndex = insertLeafs(lexIndex, childMarker.myDoneMarker.myLexemeIndex, ast); } @@ -863,6 +880,14 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder { return curToken; } + private int collapseLeafs(CompositeElement ast, StartMarker startMarker) { + final int start = myLexStarts[startMarker.myLexemeIndex]; + final int end = myLexStarts[startMarker.myDoneMarker.myLexemeIndex]; + final TreeElement leaf = createLeaf(startMarker.myType, start, end); + ast.rawAddChildren(leaf); + return startMarker.myDoneMarker.myLexemeIndex; + } + private static CompositeElement createComposite(final StartMarker marker) { final IElementType type = marker.myType; if (type == TokenType.ERROR_ELEMENT) { diff --git a/platform/lang-impl/src/com/intellij/psi/ResolvingHint.java b/platform/lang-impl/src/com/intellij/psi/ResolvingHint.java index c8448f4466f3..e2550c6acbf1 100644 --- a/platform/lang-impl/src/com/intellij/psi/ResolvingHint.java +++ b/platform/lang-impl/src/com/intellij/psi/ResolvingHint.java @@ -17,6 +17,7 @@ package com.intellij.psi; /** + * Can be implemented by {@link com.intellij.psi.PsiReference} * @author Dmitry Avdeev */ public interface ResolvingHint { diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedLanguageManagerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedLanguageManagerImpl.java index 905e58565a63..f0405b22740d 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedLanguageManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedLanguageManagerImpl.java @@ -307,7 +307,7 @@ public class InjectedLanguageManagerImpl extends InjectedLanguageManager { MultiHostInjector[] infos = cachedInjectors.get(element.getClass()); if (infos != null) { for (MultiHostInjector injector : infos) { - if (dumb && !(injector instanceof DumbAware)) { + if (dumb && !DumbService.isDumbAware(injector)) { continue; } diff --git a/platform/lang-impl/src/com/intellij/refactoring/copy/CopyFilesOrDirectoriesHandler.java b/platform/lang-impl/src/com/intellij/refactoring/copy/CopyFilesOrDirectoriesHandler.java index 287f49d36341..e0feed07276e 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/copy/CopyFilesOrDirectoriesHandler.java +++ b/platform/lang-impl/src/com/intellij/refactoring/copy/CopyFilesOrDirectoriesHandler.java @@ -80,20 +80,12 @@ public class CopyFilesOrDirectoriesHandler implements CopyHandlerDelegate { dialog.show(); if (dialog.isOK()) { final String newName = elements.length == 1 ? dialog.getNewName() : null; - final PsiManager psiManager = PsiManager.getInstance(project); final PsiDirectory targetDirectory = dialog.getTargetDirectory(); try { for (PsiElement element : elements) { PsiFileSystemItem psiElement = (PsiFileSystemItem)element; - if (newName != null) { - if (!psiElement.isDirectory()) { - psiElement = (PsiFileSystemItem)psiElement.copy(); - psiElement.setName(newName); - psiManager.checkMove(psiElement, targetDirectory); - } else { - targetDirectory.checkCreateSubdirectory(newName); - MoveFilesOrDirectoriesUtil.checkIfMoveIntoSelf(psiElement, targetDirectory); - } + if (psiElement.isDirectory()) { + MoveFilesOrDirectoriesUtil.checkIfMoveIntoSelf(psiElement, targetDirectory); } } } diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenameHandler.java b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenameHandler.java index aa9655238917..d6bcf26fc118 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenameHandler.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenameHandler.java @@ -67,7 +67,9 @@ public class VariableInplaceRenameHandler implements RenameHandler { public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, final DataContext dataContext) { PsiElement element = PsiElementRenameHandler.getElement(dataContext); editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); - doRename(element, editor, dataContext); + if (checkAvailable(element, editor, dataContext)) { + doRename(element, editor, dataContext); + } } public void invoke(@NotNull final Project project, @NotNull final PsiElement[] elements, final DataContext dataContext) { @@ -75,10 +77,12 @@ public class VariableInplaceRenameHandler implements RenameHandler { if (element == null) element = PsiElementRenameHandler.getElement(dataContext); LOG.assertTrue(element != null); Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); - doRename(element, editor, dataContext); + if (checkAvailable(element, editor, dataContext)) { + doRename(element, editor, dataContext); + } } - private void doRename(final PsiElement elementToRename, final Editor editor, final DataContext dataContext) { + boolean checkAvailable(final PsiElement elementToRename, final Editor editor, final DataContext dataContext) { if (!isAvailableOnDataContext(dataContext)) { LOG.error("Recursive invocation"); RenameHandlerRegistry.getInstance().getRenameHandler(dataContext).invoke( @@ -86,8 +90,13 @@ public class VariableInplaceRenameHandler implements RenameHandler { editor, elementToRename.getContainingFile(), dataContext ); - return; + return false; } + return true; + } + + @Nullable + public VariableInplaceRenamer doRename(final PsiElement elementToRename, final Editor editor, final DataContext dataContext) { VariableInplaceRenamer renamer = createRenamer(elementToRename, editor); boolean startedRename = renamer == null ? false : renamer.performInplaceRename(); @@ -107,6 +116,7 @@ public class VariableInplaceRenameHandler implements RenameHandler { ourPreventInlineRenameFlag.set(null); } } + return renamer; } @Nullable diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java index 9b64ad92dc41..a33385160045 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java @@ -162,12 +162,13 @@ public class VariableInplaceRenamer { final TemplateBuilderImpl builder = new TemplateBuilderImpl(scope); PsiElement nameIdentifier = myElementToRename instanceof PsiNameIdentifierOwner ? ((PsiNameIdentifierOwner)myElementToRename).getNameIdentifier() : null; - PsiElement selectedElement = getSelectedInEditorElement(nameIdentifier, refs, myEditor.getCaretModel().getOffset()); + int offset = myEditor.getCaretModel().getOffset(); + PsiElement selectedElement = getSelectedInEditorElement(nameIdentifier, refs, offset); if (!CommonRefactoringUtil.checkReadOnlyStatus(myProject, myElementToRename)) return true; if (nameIdentifier != null) addVariable(nameIdentifier, selectedElement, builder); for (PsiReference ref : refs) { - addVariable(ref, selectedElement, builder); + addVariable(ref, selectedElement, builder, offset); } final PsiElement scope1 = scope; @@ -379,8 +380,9 @@ public class VariableInplaceRenamer { return range.getStartOffset() <= offset && offset <= range.getEndOffset(); } - private void addVariable(final PsiReference reference, final PsiElement selectedElement, final TemplateBuilderImpl builder) { - if (reference.getElement() == selectedElement) { + private void addVariable(final PsiReference reference, final PsiElement selectedElement, final TemplateBuilderImpl builder, int offset) { + if (reference.getElement() == selectedElement && + contains(reference.getRangeInElement().shiftRight(selectedElement.getTextRange().getStartOffset()), offset)) { Expression expression = new MyExpression(myElementToRename.getName()); builder.replaceElement(reference, PRIMARY_VARIABLE_NAME, expression, true); } diff --git a/platform/lang-impl/src/com/intellij/refactoring/ui/RefactoringDialog.java b/platform/lang-impl/src/com/intellij/refactoring/ui/RefactoringDialog.java index a8dd723fc14d..19c804a593db 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/ui/RefactoringDialog.java +++ b/platform/lang-impl/src/com/intellij/refactoring/ui/RefactoringDialog.java @@ -24,6 +24,8 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.List; /** * Author: msk @@ -107,11 +109,19 @@ public abstract class RefactoringDialog extends DialogWrapper { return true; } + protected boolean hasPreviewButton() { + return true; + } + protected Action[] createActions() { + List actions = new ArrayList(); + actions.add(getRefactorAction()); + if(hasPreviewButton()) actions.add(getPreviewAction()); + actions.add(getCancelAction()); + if (hasHelpAction ()) - return new Action[]{getRefactorAction(), getPreviewAction(), getCancelAction(), getHelpAction()}; - else - return new Action[]{getRefactorAction(), getPreviewAction(), getCancelAction()}; + actions.add(getHelpAction()); + return actions.toArray(new Action[actions.size()]); } protected Project getProject() { diff --git a/platform/lang-impl/src/com/intellij/tools/ExternalToolsGroup.java b/platform/lang-impl/src/com/intellij/tools/ExternalToolsGroup.java index ca06b28a74d0..791c46fcc6fc 100644 --- a/platform/lang-impl/src/com/intellij/tools/ExternalToolsGroup.java +++ b/platform/lang-impl/src/com/intellij/tools/ExternalToolsGroup.java @@ -17,12 +17,13 @@ package com.intellij.tools; import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; /** * @author Eugene Belyaev */ -public class ExternalToolsGroup extends SimpleActionGroup { +public class ExternalToolsGroup extends SimpleActionGroup implements DumbAware { public void update(AnActionEvent event){ Presentation presentation = event.getPresentation(); removeAll(); diff --git a/platform/lang-impl/testSrc/com/intellij/lang/LightPsiBuilderTest.java b/platform/lang-impl/testSrc/com/intellij/lang/LightPsiBuilderTest.java new file mode 100644 index 000000000000..243aca81a128 --- /dev/null +++ b/platform/lang-impl/testSrc/com/intellij/lang/LightPsiBuilderTest.java @@ -0,0 +1,127 @@ +/* + * Copyright 2000-2010 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 com.intellij.lang; + +import com.intellij.lang.impl.PsiBuilderImpl; +import com.intellij.lexer.LexerBase; +import com.intellij.psi.impl.DebugUtil; +import com.intellij.psi.tree.IElementType; +import com.intellij.psi.tree.TokenSet; +import org.jetbrains.annotations.NotNull; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + + +public class LightPsiBuilderTest { + + @Test + public void testPlain() { + doTest( + "a< stdOutReadingFuture = executeOnPooledThread(stdoutThread); + final Future stdErrReadingFuture = executeOnPooledThread(stderrThread); myWaitFor.setTerminationCallback(new Consumer() { @Override @@ -149,8 +145,13 @@ public class OSProcessHandler extends ProcessHandler { stderrThread.setProcessTerminated(true); stdoutThread.setProcessTerminated(true); - outSemaphore.waitFor(); - errSemaphore.waitFor(); + stdErrReadingFuture.get(); + stdOutReadingFuture.get(); + } + catch (InterruptedException e) { + } + catch (ExecutionException e) { + LOG.error(e); } finally { onOSProcessTerminated(exitCode); @@ -228,56 +229,38 @@ public class OSProcessHandler extends ProcessHandler { return EncodingManager.getInstance().getDefaultCharset(); } - private abstract class ReadProcessRequest { + private abstract static class ReadProcessThread implements Runnable { private final Reader myReader; private boolean skipLF = false; - private boolean myIsClosed = false; - private volatile boolean myIsProcessTerminated = false; - private final Semaphore mySemaphore = new Semaphore(); - private final BlockingQueue myNotificationQueue = new LinkedBlockingQueue(); + private boolean myIsProcessTerminated = false; + private final char[] myBuffer = new char[8192]; - public ReadProcessRequest(final Reader reader) { + public ReadProcessThread(final Reader reader) { myReader = reader; } - public boolean isProcessTerminated() { - return myIsProcessTerminated; - } - - public void setProcessTerminated(boolean isProcessTerminated) { + public synchronized void setProcessTerminated(boolean isProcessTerminated) { myIsProcessTerminated = isProcessTerminated; } - public Semaphore schedule() { - ourReaderThread.addRequest(this); - - executeOnPooledThread(new Runnable() { - @Override - public void run() { + public void run() { + try { + while (readAvailable()) { try { - while (true) { - final String token = myNotificationQueue.take(); - if (token.isEmpty()) break; - textAvailable(token); - } + Thread.sleep(50L); } - catch (InterruptedException e) { - // Ignore - } - finally { - mySemaphore.up(); + catch (InterruptedException ignore) { } } - }); - - mySemaphore.down(); - return mySemaphore; + } + catch (Exception e) { + LOG.error(e); + } } - public void readAvailable(char[] buffer) throws IOException { - int fairCount = 0; - boolean checkForTermination = true; + private synchronized boolean readAvailable() throws IOException { + char[] buffer = myBuffer; StringBuilder token = new StringBuilder(); while (myReader.ready()) { int n = myReader.read(buffer); @@ -298,98 +281,31 @@ public class OSProcessHandler extends ProcessHandler { } if (c == '\n') { - myNotificationQueue.offer(token.toString()); + textAvailable(token.toString()); token.setLength(0); } } - - if (++fairCount > 10) { - checkForTermination = false; - break; - } } if (token.length() != 0) { - myNotificationQueue.offer(token.toString()); + textAvailable(token.toString()); token.setLength(0); } - if (checkForTermination && isProcessTerminated()) { - close(); - } - } + if (myIsProcessTerminated) { + try { + myReader.close(); + } + catch (IOException e1) { + // supressed + } - private void close() { - LOG.assertTrue(!myIsClosed); - myIsClosed = true; + return false; + } - try { - myReader.close(); - } - catch (IOException e1) { - // supressed - } - finally { - myNotificationQueue.offer(""); - } + return true; } protected abstract void textAvailable(final String s); - - private boolean isClosed() { - return myIsClosed; - } - } - - private static class ReaderThread extends Thread { - private final BlockingQueue queue = new LinkedBlockingQueue(); - private final char[] myBuffer = new char[8192]; - - - @Override - public void run() { - while (true) { - ReadProcessRequest request = takeRequest(); - if (request == null) return; - - processRequest(request); - if (!request.isClosed()) addRequest(request); - - //noinspection UnusedAssignment - request = null; //leak? - - try { - Thread.sleep(1L); - } - catch (InterruptedException e) { - // ignore - } - } - } - - - private void processRequest(ReadProcessRequest request) { - try { - request.readAvailable(myBuffer); - } - catch (IOException e) { - LOG.error(e); - } - } - - @Nullable - private ReadProcessRequest takeRequest() { - try { - return queue.take(); - } - catch (InterruptedException e) { - return null; - } - } - - public void addRequest(ReadProcessRequest request) { - queue.offer(request); - } - } } diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/ActionGroup.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/ActionGroup.java index 930e75f04e10..b2946b38272c 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/ActionGroup.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/ActionGroup.java @@ -23,13 +23,14 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; +import java.lang.reflect.Method; import java.util.Set; import java.util.HashSet; /** * Represents a group of actions. */ -public abstract class ActionGroup extends AnAction implements DumbAware { +public abstract class ActionGroup extends AnAction { private boolean myPopup; private final PropertyChangeSupport myChangeSupport = new PropertyChangeSupport(this); public static final ActionGroup EMPTY_GROUP = new ActionGroup() { @@ -47,6 +48,8 @@ public abstract class ActionGroup extends AnAction implements DumbAware { */ @NonNls public static final String PROP_POPUP = "popup"; + private Boolean myDumbAware; + /** * Creates a new ActionGroup with shortName set to null and * popup set to false. @@ -79,6 +82,11 @@ public abstract class ActionGroup extends AnAction implements DumbAware { public void actionPerformed(AnActionEvent e){ } + @Override + public void update(AnActionEvent e) { + super.update(e); + } + /** * @return true if {@link #actionPerformed(AnActionEvent)} should be called */ @@ -152,4 +160,28 @@ public abstract class ActionGroup extends AnAction implements DumbAware { } } } + + @Override + public boolean isDumbAware() { + if (myDumbAware != null) { + return myDumbAware; + } + + boolean dumbAware = super.isDumbAware(); + if (dumbAware) { + myDumbAware = Boolean.valueOf(dumbAware); + } else { + if (myDumbAware == null) { + try { + Method updateMethod = getClass().getMethod("update", AnActionEvent.class); + myDumbAware = updateMethod.getDeclaringClass().equals(AnAction.class); + } + catch (NoSuchMethodException e) { + myDumbAware = Boolean.FALSE; + } + } + } + + return myDumbAware; + } } diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/AnAction.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/AnAction.java index 737598ea17a7..ca16b19308b2 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/AnAction.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/AnAction.java @@ -17,6 +17,7 @@ package com.intellij.openapi.actionSystem; import com.intellij.openapi.Disposable; import com.intellij.openapi.keymap.KeymapUtil; +import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.annotations.NonNls; @@ -298,4 +299,8 @@ public abstract class AnAction { public void setTransparentUpdate(boolean transparentUpdate) { myTransparentUpdate = transparentUpdate; } + + public boolean isDumbAware() { + return this instanceof DumbAware; + } } diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/AsyncUpdateAction.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/AsyncUpdateAction.java index 87524635ee69..4b28cc17bed4 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/AsyncUpdateAction.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/AsyncUpdateAction.java @@ -37,7 +37,7 @@ public abstract class AsyncUpdateAction extends AnAction { public final void update(AnActionEvent e) { final T data = prepareDataFromContext(e); final Presentation originalPresentation = e.getPresentation(); - if (!forceSyncUpdate(e) && this instanceof DumbAware) { + if (!forceSyncUpdate(e) && isDumbAware()) { final Presentation realPresentation = (Presentation)originalPresentation.clone(); ourUpdaterService.submit(new Runnable() { public void run() { diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ActionUtil.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ActionUtil.java index 1872d5dbd358..fd5d315298cb 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ActionUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ActionUtil.java @@ -88,7 +88,7 @@ public class ActionUtil { } final boolean enabledBeforeUpdate = presentation.isEnabled(); - final boolean notAllowed = dumbMode && !(action instanceof DumbAware) && !(action instanceof ActionGroup); + final boolean notAllowed = dumbMode && !action.isDumbAware(); try { if (beforeActionPerformed) { @@ -122,7 +122,7 @@ public class ActionUtil { performDumbAwareUpdate(action, e, true); final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); - if (project != null && DumbService.getInstance(project).isDumb() && !(action instanceof DumbAware)) { + if (project != null && DumbService.getInstance(project).isDumb() && !action.isDumbAware()) { if (Boolean.FALSE.equals(e.getPresentation().getClientProperty(WOULD_BE_ENABLED_IF_NOT_DUMB_MODE))) { return false; } diff --git a/platform/platform-api/src/com/intellij/openapi/project/DumbService.java b/platform/platform-api/src/com/intellij/openapi/project/DumbService.java index a7eee8dda576..e9f1a4c8e80b 100644 --- a/platform/platform-api/src/com/intellij/openapi/project/DumbService.java +++ b/platform/platform-api/src/com/intellij/openapi/project/DumbService.java @@ -16,6 +16,7 @@ package com.intellij.openapi.project; import com.intellij.openapi.Disposable; +import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.components.ServiceManager; @@ -91,7 +92,7 @@ public abstract class DumbService { if (isDumb()) { final ArrayList result = new ArrayList(collection); for (Iterator iterator = result.iterator(); iterator.hasNext();) { - if (!(iterator.next() instanceof DumbAware)) { + if (!isDumbAware(iterator.next())) { iterator.remove(); } } @@ -139,6 +140,14 @@ public abstract class DumbService { public abstract Project getProject(); + public static boolean isDumbAware(Object o) { + if (o instanceof AnAction) { + return ((AnAction)o).isDumbAware(); + } else { + return o instanceof DumbAware; + } + } + /** * @see #DUMB_MODE */ diff --git a/platform/platform-api/src/com/intellij/openapi/ui/Messages.java b/platform/platform-api/src/com/intellij/openapi/ui/Messages.java index 71c391d97f9d..249abf64d253 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/Messages.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/Messages.java @@ -581,7 +581,14 @@ public class Messages { if (messageComponent.getCaret() != null) { messageComponent.setCaretPosition(0); } - messageComponent.setBackground(UIUtil.getOptionPaneBackground()); + + if (UIUtil.isUnderNimbusLookAndFeel()) { + messageComponent.setOpaque(false); + messageComponent.setBackground(new Color(0, 0, 0, 0)); + } else { + messageComponent.setBackground(UIUtil.getOptionPaneBackground()); + } + messageComponent.setForeground(label.getForeground()); final Dimension screenSize = messageComponent.getToolkit().getScreenSize(); diff --git a/platform/platform-api/src/com/intellij/ui/switcher/QuickActionManager.java b/platform/platform-api/src/com/intellij/ui/switcher/QuickActionManager.java index ee57aa1a846e..d61036cca139 100644 --- a/platform/platform-api/src/com/intellij/ui/switcher/QuickActionManager.java +++ b/platform/platform-api/src/com/intellij/ui/switcher/QuickActionManager.java @@ -21,6 +21,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.components.ProjectComponent; +import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.util.AsyncResult; @@ -105,7 +106,7 @@ public class QuickActionManager implements ProjectComponent { } - private class Group extends DefaultActionGroup { + private class Group extends DefaultActionGroup implements DumbAware { private String myTitle; private Group(List actions, String title) { diff --git a/platform/platform-api/src/com/intellij/util/IconUtil.java b/platform/platform-api/src/com/intellij/util/IconUtil.java index 5d54d330f969..e6167ef10296 100644 --- a/platform/platform-api/src/com/intellij/util/IconUtil.java +++ b/platform/platform-api/src/com/intellij/util/IconUtil.java @@ -117,7 +117,7 @@ public class IconUtil { final boolean dumb = project != null && DumbService.getInstance(project).isDumb(); for (FileIconPatcher patcher : getPatchers()) { - if (dumb && !(patcher instanceof DumbAware)) { + if (dumb && !DumbService.isDumbAware(patcher)) { continue; } diff --git a/platform/platform-impl/src/com/intellij/ide/actions/CodeEditorActionGroup.java b/platform/platform-impl/src/com/intellij/ide/actions/CodeEditorActionGroup.java index 55cd49780758..43597f77ac24 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/CodeEditorActionGroup.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/CodeEditorActionGroup.java @@ -19,10 +19,11 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.wm.ToolWindowManager; -public class CodeEditorActionGroup extends DefaultActionGroup { +public class CodeEditorActionGroup extends DefaultActionGroup implements DumbAware { public CodeEditorActionGroup() { super(); } diff --git a/platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java b/platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java index 5e17424e73fc..60cdc3f185c3 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java @@ -28,7 +28,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; public class OpenProjectFileChooserDescriptor extends FileChooserDescriptor { - private final Icon myProjectIcon = IconLoader.getIcon(ApplicationInfoImpl.getInstanceEx().getSmallIconUrl()); + private static final Icon ourProjectIcon = IconLoader.getIcon(ApplicationInfoImpl.getInstanceEx().getSmallIconUrl()); public OpenProjectFileChooserDescriptor(final boolean chooseFiles) { super(chooseFiles, true, false, false, false, false); @@ -39,7 +39,7 @@ public class OpenProjectFileChooserDescriptor extends FileChooserDescriptor { } public Icon getOpenIcon(final VirtualFile virtualFile) { - if (isProjectDirectory(virtualFile)) return myProjectIcon; + if (isProjectDirectory(virtualFile)) return ourProjectIcon; final Icon icon = getImporterIcon(virtualFile, true); if(icon!=null){ return icon; @@ -48,7 +48,7 @@ public class OpenProjectFileChooserDescriptor extends FileChooserDescriptor { } public Icon getClosedIcon(final VirtualFile virtualFile) { - if (isProjectDirectory(virtualFile)) return myProjectIcon; + if (isProjectDirectory(virtualFile)) return ourProjectIcon; final Icon icon = getImporterIcon(virtualFile, false); if(icon!=null){ return icon; @@ -60,7 +60,7 @@ public class OpenProjectFileChooserDescriptor extends FileChooserDescriptor { public static Icon getImporterIcon(final VirtualFile virtualFile, final boolean open) { final ProjectOpenProcessor provider = ProjectOpenProcessor.getImportProvider(virtualFile); if(provider!=null) { - return provider.getIcon(); + return virtualFile.isDirectory() ? ourProjectIcon : provider.getIcon(); } return null; } @@ -94,10 +94,6 @@ public class OpenProjectFileChooserDescriptor extends FileChooserDescriptor { if (isIprFile(file)) { return true; } - final ProjectOpenProcessor importProvider = ProjectOpenProcessor.getImportProvider(file); - if (importProvider != null && importProvider.lookForProjectsInDirectory()) { - return true; - } } } return false; diff --git a/platform/platform-impl/src/com/intellij/ide/actions/OtherGroup.java b/platform/platform-impl/src/com/intellij/ide/actions/OtherGroup.java index c5cd0b328429..79307c73fadd 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/OtherGroup.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/OtherGroup.java @@ -18,8 +18,9 @@ package com.intellij.ide.actions; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.project.DumbAware; -public class OtherGroup extends DefaultActionGroup { +public class OtherGroup extends DefaultActionGroup implements DumbAware { public OtherGroup() { super(); } diff --git a/platform/platform-impl/src/com/intellij/ide/actions/RecentProjectsGroup.java b/platform/platform-impl/src/com/intellij/ide/actions/RecentProjectsGroup.java index 1ed87056ec14..3d1a8c14574d 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/RecentProjectsGroup.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/RecentProjectsGroup.java @@ -21,11 +21,12 @@ import com.intellij.openapi.actionSystem.ActionGroup; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.util.SystemInfo; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class RecentProjectsGroup extends ActionGroup { +public class RecentProjectsGroup extends ActionGroup implements DumbAware { public RecentProjectsGroup() { super(); diff --git a/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java b/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java index c89a680b176a..9544ca3b911b 100644 --- a/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java @@ -128,7 +128,7 @@ public class StartupManagerImpl extends StartupManagerEx { final List nonDumbAware = CollectionFactory.arrayList(); for (Runnable each : myPostStartupActivities) { - if (each instanceof DumbAware) { + if (DumbService.isDumbAware(each)) { dumbAware.add(each); } else { @@ -186,7 +186,7 @@ public class StartupManagerImpl extends StartupManagerEx { final Runnable runnable; final Application application = ApplicationManager.getApplication(); - if (action instanceof DumbAware) { + if (DumbService.isDumbAware(action)) { runnable = new DumbAwareRunnable() { public void run() { application.runWriteAction(action); diff --git a/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizationUtil.java b/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizationUtil.java index 775faa3907d5..9f9df41e6641 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizationUtil.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizationUtil.java @@ -138,6 +138,11 @@ public class CustomizationUtil { public void update(AnActionEvent e) { myGroup.update(e); } + + @Override + public boolean isDumbAware() { + return myGroup.isDumbAware(); + } } public static void optimizeSchema(final JTree tree, final CustomActionsSchema schema) { diff --git a/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java b/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java index 15506dab5db8..e5812ef1e1de 100644 --- a/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java @@ -22,6 +22,7 @@ import com.intellij.openapi.components.ApplicationComponent; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.*; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.wm.WindowManager; import com.intellij.openapi.wm.impl.IdeFrameImpl; import com.intellij.ui.BalloonLayout; @@ -163,7 +164,13 @@ public class NotificationsManagerImpl extends NotificationsManager implements No final JLabel label = new JLabel(text.getText()); final Dimension size = label.getPreferredSize(); text.setEditable(false); + text.setOpaque(false); + + if (UIUtil.isUnderNimbusLookAndFeel()) { + text.setBackground(new Color(0, 0, 0, 0)); + } + text.setBorder(null); text.setPreferredSize(size); diff --git a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/Utils.java b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/Utils.java index ae711f12b18c..c7103a37ebd3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/Utils.java +++ b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/Utils.java @@ -182,7 +182,7 @@ public class Utils{ continue; } final Project project = PlatformDataKeys.PROJECT.getData(context); - if (project != null && DumbService.getInstance(project).isDumb() && !(anAction instanceof DumbAware) && !(anAction instanceof ActionGroup)) { + if (project != null && DumbService.getInstance(project).isDumb() && !anAction.isDumbAware()) { continue; } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java index fd3bf3336372..67e395eef768 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java @@ -254,6 +254,7 @@ public class FileBasedStorage extends XmlElementStorage { private Document processReadException(final Exception e) { myBlockSavingTheContent = isProjectOrModuleFile(); + LOG.warn(e); if (!ApplicationManager.getApplication().isUnitTestMode() && !ApplicationManager.getApplication().isHeadlessEnvironment()) { SwingUtilities.invokeLater(new Runnable(){ public void run() { diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.java index 6b07780bd455..16811705de04 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.java @@ -495,7 +495,7 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec if (DumbService.getInstance(myProject).isDumb()) { final List dumbAware = ContainerUtil.findAll(providers, new Condition() { public boolean value(FileEditorProvider fileEditorProvider) { - return fileEditorProvider instanceof DumbAware; + return DumbService.isDumbAware(fileEditorProvider); } }); providers = dumbAware.toArray(new FileEditorProvider[dumbAware.size()]); @@ -520,7 +520,7 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec editors[i] = editor; // Register PropertyChangeListener into editor editor.addPropertyChangeListener(myEditorPropertyChangeListener); - editor.putUserData(DUMB_AWARE, provider instanceof DumbAware); + editor.putUserData(DUMB_AWARE, DumbService.isDumbAware(provider)); if (current && editor instanceof TextEditorImpl) { ((TextEditorImpl)editor).initFolding(); diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorProviderManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorProviderManagerImpl.java index 1f852ad740b6..da5c27a83384 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorProviderManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorProviderManagerImpl.java @@ -71,7 +71,7 @@ public final class FileEditorProviderManagerImpl extends FileEditorProviderManag final boolean dumb = DumbService.getInstance(project).isDumb(); for(int i = myProviders.size() -1 ; i >= 0; i--){ FileEditorProvider provider=myProviders.get(i); - if((!dumb || provider instanceof DumbAware) && provider.accept(project, file)){ + if((!dumb || DumbService.isDumbAware(provider)) && provider.accept(project, file)){ mySharedProviderList.add(provider); doNotShowTextEditor |= provider.getPolicy() == FileEditorPolicy.HIDE_DEFAULT_EDITOR; } diff --git a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeKeyEventDispatcher.java b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeKeyEventDispatcher.java index db85cb8683be..f6d76829f0ee 100644 --- a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeKeyEventDispatcher.java +++ b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeKeyEventDispatcher.java @@ -505,7 +505,7 @@ public final class IdeKeyEventDispatcher implements Disposable { ActionUtil.performDumbAwareUpdate(action, actionEvent, true); - if (dumb && !(action instanceof DumbAware)) { + if (dumb && !action.isDumbAware()) { if (Boolean.FALSE.equals(presentation.getClientProperty(ActionUtil.WOULD_BE_ENABLED_IF_NOT_DUMB_MODE))) { continue; } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java index deb4fcdd0121..476cc5e70233 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java @@ -375,7 +375,7 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements final Color treeFg = UIManager.getColor("Tree.foreground"); label.setForeground(new Color(treeFg.getRed(), treeFg.getGreen(), treeFg.getBlue(), 180)); final ToolWindowFactory factory = bean.getToolWindowFactory(); - final ToolWindowImpl toolWindow = (ToolWindowImpl)registerToolWindow(bean.id, label, toolWindowAnchor, myProject, factory instanceof DumbAware); + final ToolWindowImpl toolWindow = (ToolWindowImpl)registerToolWindow(bean.id, label, toolWindowAnchor, myProject, DumbService.isDumbAware(factory)); toolWindow.setContentFactory(factory); if (bean.icon != null) { Icon icon = IconLoader.findIcon(bean.icon, factory.getClass()); diff --git a/platform/platform-impl/src/com/intellij/ui/AbstractExpandableItemsHandler.java b/platform/platform-impl/src/com/intellij/ui/AbstractExpandableItemsHandler.java index 615edd73283c..b361b5be89cf 100644 --- a/platform/platform-impl/src/com/intellij/ui/AbstractExpandableItemsHandler.java +++ b/platform/platform-impl/src/com/intellij/ui/AbstractExpandableItemsHandler.java @@ -99,8 +99,26 @@ abstract public class AbstractExpandableItemsHandler + + diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java index e01f4bb79efc..22af2f110ecd 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java @@ -307,8 +307,14 @@ public class GroovyDslFileIndex extends ScalarIndexExtension { } } + private static boolean stopGdsl = false; + @Nullable private static GroovyDslExecutor createExecutor(String text, VirtualFile vfile, final Project project) { + if (stopGdsl) { + return null; + } + try { return new GroovyDslExecutor(text, vfile.getName()); } @@ -323,6 +329,16 @@ public class GroovyDslFileIndex extends ScalarIndexExtension { return null; } invokeDslErrorPopup(e, project, vfile); + + if (e instanceof OutOfMemoryError) { + stopGdsl = true; + throw (Error)e; + } + if (e instanceof NoClassDefFoundError) { + stopGdsl = true; + throw (NoClassDefFoundError) e; + } + return null; } } @@ -330,6 +346,7 @@ public class GroovyDslFileIndex extends ScalarIndexExtension { if (!isActivated(vfile)) { return; } + disableFile(vfile); final StringWriter writer = new StringWriter(); //noinspection IOResourceOpenedButNotSafelyClosed @@ -349,8 +366,6 @@ public class GroovyDslFileIndex extends ScalarIndexExtension { notification.expire(); } })); - - disableFile(vfile); } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/types/GrClosureSignatureUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/types/GrClosureSignatureUtil.java index d07fffb2af5a..55a5b122a538 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/types/GrClosureSignatureUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/types/GrClosureSignatureUtil.java @@ -125,7 +125,7 @@ public class GrClosureSignatureUtil { } public static boolean isSignatureApplicable(GrClosureSignature signature, PsiType[] args, GroovyPsiElement context) { - if (mapArgTypesToParameters(signature, args, context) != null) return true; + if (mapArgTypesToParameters(signature, args, context, false) != null) return true; if (args.length == 1) { final GrClosureParameter[] parameters = signature.getParameters(); @@ -133,27 +133,30 @@ public class GrClosureSignatureUtil { PsiType arg = args[0]; if (arg instanceof GrTupleType) { args = ((GrTupleType)arg).getComponentTypes(); - if (mapArgTypesToParameters(signature, args, context) != null) return true; + if (mapArgTypesToParameters(signature, args, context, false) != null) return true; } } return false; } - public static ArgInfo[] mapArgTypesToParameters(GrClosureSignature signature, PsiType[] args, GroovyPsiElement context) { - return mapParametersToArguments(signature, args, (Function)Function.ID, context); + public static ArgInfo[] mapArgTypesToParameters(GrClosureSignature signature, + PsiType[] args, + GroovyPsiElement context, + boolean partial) { + return mapParametersToArguments(signature, args, (Function)Function.ID, context, partial); } @Nullable private static ArgInfo[] mapParametersToArguments(GrClosureSignature signature, Arg[] args, Function typeComputer, - GroovyPsiElement context) { + GroovyPsiElement context, boolean partial) { GrClosureParameter[] params = signature.getParameters(); if (args.length > params.length && !signature.isVarargs()) return null; int optional = getOptionalParamCount(signature, false); int notOptional = params.length - optional; if (signature.isVarargs()) notOptional--; - if (notOptional > args.length) return null; + if (notOptional > args.length && !partial) return null; final ArgInfo[] map = mapSimple(params, args, typeComputer, context); if (map != null) return map; @@ -374,7 +377,7 @@ public class GrClosureSignatureUtil { public PsiType fun(InnerArg o) { return o.type; } - }, list); + }, list, false); if (innerMap == null) return null; ArgInfo[] map = new ArgInfo[innerMap.length]; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java index 71266e933832..0e374ce62084 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java @@ -904,4 +904,32 @@ public class PsiUtil { } return false; } + + public static GrReferenceExpression qualifyMemberReference(GrReferenceExpression refExpr, PsiMember member, String name) { + assert refExpr.getQualifierExpression() == null; + + final PsiClass clazz = member.getContainingClass(); + assert clazz != null; + + final PsiElement replaced; + if (member.hasModifierProperty(GrModifier.STATIC)) { + final GrReferenceExpression newRefExpr = GroovyPsiElementFactory.getInstance(member.getProject()) + .createReferenceExpressionFromText(clazz.getQualifiedName() + "." + name); + replaced = refExpr.replace(newRefExpr); + } + else { + final PsiClass containingClass = PsiTreeUtil.getParentOfType(refExpr, PsiClass.class); + if (member.getManager().areElementsEquivalent(containingClass, clazz)) { + final GrReferenceExpression newRefExpr = GroovyPsiElementFactory.getInstance(member.getProject()) + .createReferenceExpressionFromText("this." + name); + replaced = refExpr.replace(newRefExpr); + } + else { + final GrReferenceExpression newRefExpr = GroovyPsiElementFactory.getInstance(member.getProject()) + .createReferenceExpressionFromText(clazz.getName() + ".this." + name); + replaced = refExpr.replace(newRefExpr); + } + } + return (GrReferenceExpression)replaced; + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/processors/MethodResolverProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/processors/MethodResolverProcessor.java index c2eef6a9aeaf..302737d3fc76 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/processors/MethodResolverProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/processors/MethodResolverProcessor.java @@ -138,7 +138,7 @@ public class MethodResolverProcessor extends ResolverProcessor { final GrClosureParameter[] params = signature.getParameters(); final GrClosureSignatureUtil.ArgInfo[] argInfos = - GrClosureSignatureUtil.mapArgTypesToParameters(erasedSignature, argTypes, (GroovyPsiElement)myPlace); + GrClosureSignatureUtil.mapArgTypesToParameters(erasedSignature, argTypes, (GroovyPsiElement)myPlace, myAllVariants); if (argInfos == null) return partialSubstitutor; int max = Math.max(params.length, argTypes.length); @@ -147,15 +147,21 @@ public class MethodResolverProcessor extends ResolverProcessor { PsiType[] argumentTypes = new PsiType[max]; int i = 0; for (int paramIndex = 0; paramIndex < argInfos.length; paramIndex++) { - GrClosureSignatureUtil.ArgInfo argInfo = argInfos[paramIndex]; - final List psiTypes = argInfo.args; PsiType paramType = params[paramIndex].getType(); - if (argInfo.isMultiArg) { - if (paramType instanceof PsiArrayType) paramType = ((PsiArrayType)paramType).getComponentType(); - } - for (PsiType type : psiTypes) { + + GrClosureSignatureUtil.ArgInfo argInfo = argInfos[paramIndex]; + if (argInfo != null) { + if (argInfo.isMultiArg) { + if (paramType instanceof PsiArrayType) paramType = ((PsiArrayType)paramType).getComponentType(); + } + for (PsiType type : argInfo.args) { + argumentTypes[i] = handleConversion(paramType, type); + parameterTypes[i] = paramType; + i++; + } + } else { parameterTypes[i] = paramType; - argumentTypes[i] = handleConversion(paramType, type); + argumentTypes[i] = PsiType.NULL; i++; } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringSupportProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringSupportProvider.java index 61e08638e865..f29b4a04ef2d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringSupportProvider.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringSupportProvider.java @@ -18,9 +18,13 @@ package org.jetbrains.plugins.groovy.refactoring; import com.intellij.lang.refactoring.DefaultRefactoringSupportProvider; import com.intellij.psi.PsiElement; +import com.intellij.psi.search.LocalSearchScope; +import com.intellij.psi.search.SearchScope; import com.intellij.refactoring.RefactoringActionHandler; import com.intellij.refactoring.changeSignature.ChangeSignatureHandler; import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition; import org.jetbrains.plugins.groovy.refactoring.changeSignature.GrChangeSignatureHandler; import org.jetbrains.plugins.groovy.refactoring.extractMethod.GroovyExtractMethodHandler; @@ -54,4 +58,17 @@ public class GroovyRefactoringSupportProvider extends DefaultRefactoringSupportP public ChangeSignatureHandler getChangeSignatureHandler() { return new GrChangeSignatureHandler(); } + + @Override + public boolean doInplaceRenameFor(PsiElement element, PsiElement context) { + if (!(element instanceof GrVariable)) return false; + if (element instanceof GrField) return false; + + final SearchScope scope = element.getUseScope(); + if (!(scope instanceof LocalSearchScope)) return false; + + final PsiElement[] scopeElements = ((LocalSearchScope)scope).getScope(); + if (scopeElements.length != 1) return false; + return true; + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/inplace/GroovyResolveSnapshot.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/inplace/GroovyResolveSnapshot.java new file mode 100644 index 000000000000..4501063da4bf --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/inplace/GroovyResolveSnapshot.java @@ -0,0 +1,86 @@ +/* + * Copyright 2000-2010 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.refactoring.rename.inplace; + +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDocumentManager; +import com.intellij.psi.PsiElement; +import com.intellij.psi.SmartPointerManager; +import com.intellij.psi.SmartPsiElementPointer; +import com.intellij.refactoring.rename.inplace.ResolveSnapshotProvider; +import com.intellij.util.containers.HashMap; +import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementVisitor; +import org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember; +import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; + +import java.util.Map; + +/** + * @author Maxim.Medvedev + */ +public class GroovyResolveSnapshot extends ResolveSnapshotProvider.ResolveSnapshot { + private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.refactoring.rename.inplace.GroovyResolveSnapshot"); + + private final Map myReferencesMap = + new HashMap(); + private final Project myProject; + private final Document myDocument; + + public GroovyResolveSnapshot(final PsiElement scope) { + myProject = scope.getProject(); + myDocument = PsiDocumentManager.getInstance(myProject).getDocument(scope.getContainingFile()); + final SmartPointerManager pointerManager = SmartPointerManager.getInstance(myProject); + final Map pointers = new HashMap(); + scope.accept(new GroovyPsiElementVisitor(new GroovyRecursiveElementVisitor() { + @Override + public void visitReferenceExpression(GrReferenceExpression refExpr) { + if (!refExpr.isQualified()) { + PsiElement resolved = refExpr.resolve(); + if (resolved instanceof GrMember) { + SmartPsiElementPointer key = pointerManager.createSmartPsiElementPointer(refExpr); + SmartPsiElementPointer value = pointers.get(resolved); + if (value == null) { + value = pointerManager.createSmartPsiElementPointer(resolved); + pointers.put(resolved, value); + } + myReferencesMap.put(key, value); + } + } + super.visitReferenceExpression(refExpr); + } + })); + } + + public void apply(String hidingLocalName) { + PsiDocumentManager.getInstance(myProject).commitDocument(myDocument); + for (Map.Entry entry : myReferencesMap.entrySet()) { + qualify(entry.getKey().getElement(), entry.getValue().getElement(), hidingLocalName); + } + } + + private static void qualify(PsiElement referent, PsiElement referee, String hidingLocalName) { + if (referent instanceof GrReferenceExpression && referee instanceof GrMember) { + GrReferenceExpression ref = ((GrReferenceExpression)referent); + if (!ref.isQualified() && hidingLocalName.equals(ref.getReferenceName())) { + PsiUtil.qualifyMemberReference(ref, (GrMember)referee, hidingLocalName); + } + } + } +} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/inplace/GroovyResolveSnapshotProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/inplace/GroovyResolveSnapshotProvider.java new file mode 100644 index 000000000000..f836181cdc47 --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/inplace/GroovyResolveSnapshotProvider.java @@ -0,0 +1,29 @@ +/* + * Copyright 2000-2010 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.refactoring.rename.inplace; + +import com.intellij.psi.PsiElement; +import com.intellij.refactoring.rename.inplace.ResolveSnapshotProvider; + +/** + * @author Maxim.Medvedev + */ +public class GroovyResolveSnapshotProvider extends ResolveSnapshotProvider{ + @Override + public ResolveSnapshot createSnapshot(PsiElement scope) { + return new GroovyResolveSnapshot(scope); + } +} diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy index eb1d15defb15..0617136a193b 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy @@ -297,8 +297,8 @@ public class ResolveMethodTest extends GroovyResolveTestCase { assertNull(ref.resolve()); } - public void testGrvy723() throws Exception { - PsiReference ref = configureByFile("grvy723/A.groovy"); + public void testPrivateScriptMethod() throws Exception { + PsiReference ref = configureByFile("A.groovy"); assertNotNull(ref.resolve()); } @@ -418,8 +418,8 @@ public class ResolveMethodTest extends GroovyResolveTestCase { assertTrue(resolved instanceof PsiMethod); } - public void testMethodPointer() throws Exception { - PsiReference ref = configureByFile("methodPointer/A.groovy"); + public void testMethodPointer1() throws Exception { + PsiReference ref = configureByFile("A.groovy"); PsiElement resolved = ref.resolve(); assertTrue(resolved instanceof PsiMethod); } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/rename/RenameTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/rename/RenameTest.groovy index df931960716c..5b0b352d735a 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/rename/RenameTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/rename/RenameTest.groovy @@ -9,6 +9,8 @@ import com.intellij.psi.impl.source.PostprocessReformattingAspect import com.intellij.psi.util.PsiTreeUtil import com.intellij.refactoring.rename.RenameProcessor import com.intellij.refactoring.rename.RenameUtil +import com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler +import com.intellij.testFramework.fixtures.CodeInsightTestUtil import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import org.jetbrains.plugins.groovy.GroovyFileType import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField @@ -313,4 +315,23 @@ print foo foo = 4""" } + public void testInplaceRename() { + doInplaceRenameTest(); + } + + public void testInplaceRenameWithGetter() { + doInplaceRenameTest(); + } + + public void testInplaceRenameWithStaticField() { + doInplaceRenameTest(); + } + + private def doInplaceRenameTest() { + String prefix = TestUtils.getTestDataPath() + "groovy/refactoring/rename/" + getTestName(false) + myFixture.configureByFile prefix + ".groovy"; + CodeInsightTestUtil.doInlineRename(new VariableInplaceRenameHandler(), "foo", myFixture); + myFixture.checkResultByFile prefix + "_after.groovy" + } + } diff --git a/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRename.groovy b/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRename.groovy new file mode 100644 index 000000000000..eeef5dacceb4 --- /dev/null +++ b/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRename.groovy @@ -0,0 +1,12 @@ +class X { + def foo = 2 + + def a() { + def fo = 3; + + fo = 5 + print fo + + print foo + } +} \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameWithGetter.groovy b/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameWithGetter.groovy new file mode 100644 index 000000000000..2ed55fdbcf34 --- /dev/null +++ b/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameWithGetter.groovy @@ -0,0 +1,12 @@ +class X { + def getFoo(){} + + def a() { + def fo = 3; + + fo = 5 + print fo + + print foo + } +} \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameWithGetter_after.groovy b/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameWithGetter_after.groovy new file mode 100644 index 000000000000..1117fe87ad2e --- /dev/null +++ b/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameWithGetter_after.groovy @@ -0,0 +1,12 @@ +class X { + def getFoo(){} + + def a() { + def foo = 3; + + foo = 5 + print foo + + print this.foo + } +} \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameWithStaticField.groovy b/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameWithStaticField.groovy new file mode 100644 index 000000000000..fb7cb6653ce3 --- /dev/null +++ b/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameWithStaticField.groovy @@ -0,0 +1,12 @@ +class X { + static def foo = 2 + + static def a() { + def fo = 3; + + fo = 5 + print fo + + print foo + } +} \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameWithStaticField_after.groovy b/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameWithStaticField_after.groovy new file mode 100644 index 000000000000..7897a4ab7685 --- /dev/null +++ b/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameWithStaticField_after.groovy @@ -0,0 +1,12 @@ +class X { + static def foo = 2 + + static def a() { + def foo = 3; + + foo = 5 + print foo + + print X.foo + } +} \ No newline at end of file diff --git a/plugins/groovy/testdata/resolve/method/methodpointer/A.groovy b/plugins/groovy/testdata/resolve/method/methodPointer1/A.groovy similarity index 100% rename from plugins/groovy/testdata/resolve/method/methodpointer/A.groovy rename to plugins/groovy/testdata/resolve/method/methodPointer1/A.groovy diff --git a/plugins/groovy/testdata/resolve/method/GRVY723/A.groovy b/plugins/groovy/testdata/resolve/method/privateScriptMethod/A.groovy similarity index 100% rename from plugins/groovy/testdata/resolve/method/GRVY723/A.groovy rename to plugins/groovy/testdata/resolve/method/privateScriptMethod/A.groovy diff --git a/plugins/hg4idea/resources/org/zmlx/hg4idea/HgVcsMessages.properties b/plugins/hg4idea/resources/org/zmlx/hg4idea/HgVcsMessages.properties index 46fcc80e8e06..675d06aac6e7 100644 --- a/plugins/hg4idea/resources/org/zmlx/hg4idea/HgVcsMessages.properties +++ b/plugins/hg4idea/resources/org/zmlx/hg4idea/HgVcsMessages.properties @@ -69,6 +69,8 @@ hg4idea.init.already.under.hg.option.use.parent=Use parent repository, but keep hg4idea.init.already.under.hg.option.create.repo.here=Create new repository here. hg4idea.init.created.notification.title=Mercurial repository created hg4idea.init.created.notification.description=Repository was created in {0} +hg4idea.init.error.title=Error creating Mercurial repository +hg4idea.init.error.description=Couldn''t create a Mercurial repository in {0} hg4idea.move.progress=Moving files in the VCS... diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgInit.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgInit.java index f9b1b02702c4..dfc698a7a7c9 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgInit.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgInit.java @@ -6,11 +6,11 @@ import com.intellij.notification.Notifications; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.actionSystem.Presentation; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsDirectoryMapping; +import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import org.zmlx.hg4idea.HgUtil; import org.zmlx.hg4idea.HgVcs; @@ -23,24 +23,17 @@ import java.util.ArrayList; import java.util.List; /** - * Action for initializing Mercurial repository. Command "hg init". + * Action for initializing a Mercurial repository. + * Command "hg init". * @author Kirill Likhodedov */ public class HgInit extends DumbAwareAction { - private static final Logger LOG = Logger.getInstance(HgInit.class.getName()); private Project myProject; - public HgInit() { - } - @Override public void actionPerformed(AnActionEvent e) { myProject = e.getData(PlatformDataKeys.PROJECT); - if (myProject == null) { - LOG.warn("[actionPerformed] project is null"); - return; - } // provide window to select the root directory final HgInitDialog hgInitDialog = new HgInitDialog(myProject); @@ -53,7 +46,7 @@ public class HgInit extends DumbAwareAction { return; } - // check if it the project is not yet under mercurial and provide some options in that case + // check if the selected folder is not yet under mercurial and provide some options in that case final VirtualFile vcsRoot = HgUtil.getNearestHgRoot(selectedRoot); VirtualFile mapRoot = selectedRoot; if (vcsRoot != null) { @@ -67,37 +60,43 @@ public class HgInit extends DumbAwareAction { if (dialog.getAnswer() == HgInitAlreadyUnderHgDialog.Answer.USE_PARENT_REPO) { mapRoot = vcsRoot; } else if (dialog.getAnswer() == HgInitAlreadyUnderHgDialog.Answer.CREATE_REPO_HERE) { - createRepository(selectedRoot); + if (!createRepository(selectedRoot)) { + return; + } } } else { // no parent repository => creating the repository here. - createRepository(selectedRoot); + if (!createRepository(selectedRoot)){ + return; + } } - // update vcs directory mappings - mapRoot.refresh(false, false); - final String path = mapRoot.equals(myProject.getBaseDir()) ? "" : mapRoot.getPath(); - final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject); - final List vcsDirectoryMappings = new ArrayList(vcsManager.getDirectoryMappings()); - VcsDirectoryMapping mapping = new VcsDirectoryMapping(path, HgVcs.VCS_NAME); - for (int i = 0; i < vcsDirectoryMappings.size(); i++) { - final VcsDirectoryMapping m = vcsDirectoryMappings.get(i); - if (m.getDirectory().equals(path)) { - if (m.getVcs().length() == 0) { - vcsDirectoryMappings.set(i, mapping); - mapping = null; - break; - } - else if (m.getVcs().equals(mapping.getVcs())) { - mapping = null; - break; + // update vcs directory mappings if new repository was created inside the current project directory + if (myProject != null && myProject.getBaseDir() != null && VfsUtil.isAncestor(myProject.getBaseDir(), mapRoot, false)) { + mapRoot.refresh(false, false); + final String path = mapRoot.equals(myProject.getBaseDir()) ? "" : mapRoot.getPath(); + final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject); + final List vcsDirectoryMappings = new ArrayList(vcsManager.getDirectoryMappings()); + VcsDirectoryMapping mapping = new VcsDirectoryMapping(path, HgVcs.VCS_NAME); + for (int i = 0; i < vcsDirectoryMappings.size(); i++) { + final VcsDirectoryMapping m = vcsDirectoryMappings.get(i); + if (m.getDirectory().equals(path)) { + if (m.getVcs().length() == 0) { + vcsDirectoryMappings.set(i, mapping); + mapping = null; + break; + } + else if (m.getVcs().equals(mapping.getVcs())) { + mapping = null; + break; + } } } + if (mapping != null) { + vcsDirectoryMappings.add(mapping); + } + vcsManager.setDirectoryMappings(vcsDirectoryMappings); + vcsManager.updateActiveVcss(); } - if (mapping != null) { - vcsDirectoryMappings.add(mapping); - } - vcsManager.setDirectoryMappings(vcsDirectoryMappings); - vcsManager.updateActiveVcss(); } @Override @@ -108,13 +107,14 @@ public class HgInit extends DumbAwareAction { presentation.setVisible(project != null); } - private void createRepository(VirtualFile selectedRoot) { - if ((new HgInitCommand(myProject)).execute(selectedRoot)) { - Notifications.Bus.notify(new Notification(HgVcs.NOTIFICATION_GROUP_ID, - HgVcsMessages.message("hg4idea.init.created.notification.title"), - HgVcsMessages.message("hg4idea.init.created.notification.description", selectedRoot.getPresentableUrl()), - NotificationType.INFORMATION), myProject); - } + private boolean createRepository(VirtualFile selectedRoot) { + final boolean succeeded = (new HgInitCommand(myProject)).execute(selectedRoot); + Notifications.Bus.notify(new Notification(HgVcs.NOTIFICATION_GROUP_ID, + HgVcsMessages.message(succeeded ? "hg4idea.init.created.notification.title" : "hg4idea.init.error.title"), + HgVcsMessages.message(succeeded ? "hg4idea.init.created.notification.description" : "hg4idea.init.error.description", + selectedRoot.getPresentableUrl()), + succeeded ? NotificationType.INFORMATION : NotificationType.ERROR), myProject); + return succeeded; } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgInitCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgInitCommand.java index 96f738793349..670ba67983c1 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgInitCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgInitCommand.java @@ -4,6 +4,9 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; +import java.util.List; + /** * Representation of the "hg init" */ @@ -16,7 +19,10 @@ public class HgInitCommand { } public boolean execute(@NotNull VirtualFile repositoryRoot) { - return HgCommandService.getInstance(myProject).execute(repositoryRoot, "init", null) != null; + final List args = new ArrayList(1); + args.add(repositoryRoot.getPath()); + final HgCommandResult result = HgCommandService.getInstance(myProject).execute(null, "init", args); + return result != null && !HgErrorUtil.isAbort(result); } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgInitDialog.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgInitDialog.java index 1c7d515dff94..f3750cbd84fa 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgInitDialog.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgInitDialog.java @@ -48,15 +48,28 @@ public class HgInitDialog extends DialogWrapper { private JRadioButton myCreateRepositoryForTheRadioButton; private JRadioButton mySelectWhereToCreateRadioButton; private TextFieldWithBrowseButton myTextFieldBrowser; - private final Project myProject; - private VirtualFile mySelectedDir; - private FileChooserDescriptor myFileDescriptor; - private boolean myIsProjectBaseDirHgRoot; // basing on this field, show options or invoke file chooser at once - public HgInitDialog(Project project) { + @Nullable private final Project myProject; + private final boolean myShowDialog; // basing on this field, show options or invoke file chooser at once + private final FileChooserDescriptor myFileDescriptor; + private VirtualFile mySelectedDir; + + public HgInitDialog(@Nullable Project project) { super(project); myProject = project; - myIsProjectBaseDirHgRoot = HgUtil.isHgRoot(myProject.getBaseDir()); + // a file chooser instead of dialog will be shown immediately if there is no current project or if current project is already an hg root + myShowDialog = (myProject != null && !HgUtil.isHgRoot(myProject.getBaseDir())); + + myFileDescriptor = new FileChooserDescriptor(false, true, false, false, false, false) { + public void validateSelectedFiles(VirtualFile[] files) throws Exception { + if (HgUtil.isHgRoot(files[0])) { + throw new ConfigurationException(HgVcsMessages.message("hg4idea.init.this.is.hg.root", files[0].getPresentableUrl())); + } + updateEverything(); + } + }; + myFileDescriptor.setHideIgnored(false); + init(); } @@ -64,7 +77,9 @@ public class HgInitDialog extends DialogWrapper { protected void init() { super.init(); setTitle(HgVcsMessages.message("hg4idea.init.dialog.title")); - mySelectedDir = myProject.getBaseDir(); + if (myProject != null) { + mySelectedDir = myProject.getBaseDir(); + } mySelectWhereToCreateRadioButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -84,15 +99,6 @@ public class HgInitDialog extends DialogWrapper { } }); - myFileDescriptor = new FileChooserDescriptor(false, true, false, false, false, false) { - public void validateSelectedFiles(VirtualFile[] files) throws Exception { - if (HgUtil.isHgRoot(files[0])) { - throw new ConfigurationException(HgVcsMessages.message("hg4idea.init.this.is.hg.root", files[0].getPresentableUrl())); - } - updateEverything(); - } - }; - myFileDescriptor.setHideIgnored(false); myTextFieldBrowser.addBrowseFolderListener(HgVcsMessages.message("hg4idea.init.destination.directory.title"), HgVcsMessages.message("hg4idea.init.destination.directory.description"), myProject, myFileDescriptor); @@ -103,20 +109,17 @@ public class HgInitDialog extends DialogWrapper { */ @Override public void show() { - if (myIsProjectBaseDirHgRoot) { - final VirtualFile[] files = FileChooser.chooseFiles(myProject, myFileDescriptor, myProject.getBaseDir()); - mySelectedDir = (files.length == 0 ? null : files[0]); - } else { + if (myShowDialog) { super.show(); + } else { + final VirtualFile[] files = FileChooser.chooseFiles(myProject, myFileDescriptor); + mySelectedDir = (files.length == 0 ? null : files[0]); } } @Override public boolean isOK() { - if (myIsProjectBaseDirHgRoot) { - return mySelectedDir != null; - } - return super.isOK(); + return myShowDialog ? super.isOK() : mySelectedDir != null; } @Nullable @@ -134,7 +137,7 @@ public class HgInitDialog extends DialogWrapper { * enable/disable the 'OK' button, show error text and update mySelectedDir. */ private void updateEverything() { - if (myCreateRepositoryForTheRadioButton.isSelected()) { + if (myShowDialog && myCreateRepositoryForTheRadioButton.isSelected()) { enableOKAction(); mySelectedDir = myProject.getBaseDir(); } else { diff --git a/plugins/junit_rt/src/com/intellij/junit3/TestAllInPackage2.java b/plugins/junit_rt/src/com/intellij/junit3/TestAllInPackage2.java index 8c83eb729a28..f044db433c58 100644 --- a/plugins/junit_rt/src/com/intellij/junit3/TestAllInPackage2.java +++ b/plugins/junit_rt/src/com/intellij/junit3/TestAllInPackage2.java @@ -46,10 +46,12 @@ public class TestAllInPackage2 extends TestSuite { private static boolean skipSuite(Set allNames, Test suite) { if (suite instanceof TestRunnerUtil.SuiteMethodWrapper) { final Test test = ((TestRunnerUtil.SuiteMethodWrapper)suite).getSuite(); + final String currentSuiteName = ((TestRunnerUtil.SuiteMethodWrapper)suite).getClassName(); if (test instanceof TestSuite) { boolean hasAllComponents = true; for (int idx = 0; idx < ((TestSuite)test).testCount(); idx++) { - if (!allNames.contains(((TestSuite)test).testAt(idx).toString())) { + final String testName = ((TestSuite)test).testAt(idx).toString(); + if (!allNames.contains(testName) || currentSuiteName.equals(testName)) { hasAllComponents = false; break; } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/facade/MavenFacadeManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/facade/MavenFacadeManager.java index 809062d28ad6..48591c8face0 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/facade/MavenFacadeManager.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/facade/MavenFacadeManager.java @@ -130,6 +130,7 @@ public class MavenFacadeManager { myFacade.set(myLogger, myDownloadListener); } catch (Exception e) { + if (e instanceof RuntimeException) throw (RuntimeException)e; throw new RuntimeException(e); } } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/DownloadActionGroup.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/DownloadActionGroup.java index 2c206cb37b03..bb9d0b2a0447 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/DownloadActionGroup.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/DownloadActionGroup.java @@ -18,9 +18,10 @@ package org.jetbrains.idea.maven.project.actions; import com.intellij.openapi.actionSystem.ActionGroup; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DefaultActionGroup; +import com.intellij.openapi.project.DumbAware; import org.jetbrains.idea.maven.utils.actions.MavenActionUtil; -public class DownloadActionGroup extends DefaultActionGroup { +public class DownloadActionGroup extends DefaultActionGroup implements DumbAware { @Override public void update(AnActionEvent e) { super.update(e); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenUtil.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenUtil.java index 758d73160732..edf0ce0bea84 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenUtil.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenUtil.java @@ -129,7 +129,7 @@ public class MavenUtil { } public static void runDumbAware(final Project project, final Runnable r) { - if (r instanceof DumbAware) { + if (DumbService.isDumbAware(r)) { r.run(); } else { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/actions/MavenActionGroup.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/actions/MavenActionGroup.java index c5e96bfc0203..2d3c60fd0b6f 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/actions/MavenActionGroup.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/actions/MavenActionGroup.java @@ -18,8 +18,9 @@ package org.jetbrains.idea.maven.utils.actions; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.DefaultActionGroup; +import com.intellij.openapi.project.DumbAware; -public class MavenActionGroup extends DefaultActionGroup { +public class MavenActionGroup extends DefaultActionGroup implements DumbAware { @Override public void update(AnActionEvent e) { super.update(e); diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/TextSplitter.java b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/TextSplitter.java index 5602b49ec507..e68defbe000a 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/TextSplitter.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/TextSplitter.java @@ -33,8 +33,13 @@ public class TextSplitter extends BaseSplitter { if (text == null || StringUtil.isEmpty(text)) { return null; } - Matcher matcher; List results = new ArrayList(); + doSplit(text, range, results); + return (results.size() == 0) ? null : results; + } + + protected void doSplit(@NotNull String text, @NotNull TextRange range, List results) { + Matcher matcher; final WordSplitter ws = SplitterFactory.getInstance().getWordSplitter(); matcher = EXTENDED_WORD_AND_SPECIAL.matcher(text.substring(range.getStartOffset(), range.getEndOffset())); while (matcher.find()) { @@ -45,7 +50,5 @@ public class TextSplitter extends BaseSplitter { results.addAll(res); } } - return (results.size() == 0) ? null : results; } - } \ No newline at end of file diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/tokenizer/XmlTextTokenizer.java b/plugins/spellchecker/src/com/intellij/spellchecker/tokenizer/XmlTextTokenizer.java index 0c09d78b3420..484acf8e1ea4 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/tokenizer/XmlTextTokenizer.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/tokenizer/XmlTextTokenizer.java @@ -32,6 +32,7 @@ public class XmlTextTokenizer extends Tokenizer { @Nullable @Override public Token[] tokenize(@NotNull XmlText element) { + if(element.getContainingFile().getContext() != null) return null; // outer element should care of spell checking List> list = ((PsiLanguageInjectionHost)element).getInjectedPsi(); if (list != null && list.size() > 0) return null; return new Token[]{new Token(element, element.getText(),false, SplitterFactory.getInstance().getPlainTextSplitter())}; diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/IgnoreActionGroup.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/IgnoreActionGroup.java index e449c075dc42..b3d672cc648d 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/IgnoreActionGroup.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/IgnoreActionGroup.java @@ -19,6 +19,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Ref; import com.intellij.openapi.vfs.VirtualFile; @@ -32,7 +33,7 @@ import org.jetbrains.idea.svn.ignore.SvnPropertyService; import java.util.Map; import java.util.Set; -public class IgnoreActionGroup extends DefaultActionGroup { +public class IgnoreActionGroup extends DefaultActionGroup implements DumbAware { private final IgnoreGroupHelperAction myHelperAction; private final IgnoreInfoGetterStub myGetterStub; diff --git a/xml/dom-openapi/src/com/intellij/util/xml/ElementPresentationManager.java b/xml/dom-openapi/src/com/intellij/util/xml/ElementPresentationManager.java index e6351d6f540b..91f296a624d8 100644 --- a/xml/dom-openapi/src/com/intellij/util/xml/ElementPresentationManager.java +++ b/xml/dom-openapi/src/com/intellij/util/xml/ElementPresentationManager.java @@ -190,7 +190,7 @@ public abstract class ElementPresentationManager { for (final IconProvider provider : IconProvider.EXTENSION_POINT_NAME.getExtensions()) { if (provider instanceof DomIconProvider) { - if (dumb && !(provider instanceof DumbAware)) { + if (dumb && !DumbService.isDumbAware(provider)) { continue; } diff --git a/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/SchemaReferencesProvider.java b/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/SchemaReferencesProvider.java index 7bd1dd97968f..566c77b37450 100644 --- a/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/SchemaReferencesProvider.java +++ b/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/SchemaReferencesProvider.java @@ -674,7 +674,7 @@ public class SchemaReferencesProvider extends PsiReferenceProvider { } @Nullable - public static PsiReference createSchemaPrefixReference(final PsiElement element) { + private static PsiReference createSchemaPrefixReference(final PsiElement element) { if (element instanceof XmlAttributeValue) { final XmlAttributeValue attributeValue = (XmlAttributeValue)element; final String prefix = XmlUtil.findPrefixByQualifiedName(attributeValue.getValue()); diff --git a/xml/impl/src/com/intellij/psi/impl/source/xml/PossiblePrefixReference.java b/xml/impl/src/com/intellij/psi/impl/source/xml/PossiblePrefixReference.java new file mode 100644 index 000000000000..07e568a37fe0 --- /dev/null +++ b/xml/impl/src/com/intellij/psi/impl/source/xml/PossiblePrefixReference.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2010 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 com.intellij.psi.impl.source.xml; + +import com.intellij.psi.PsiReference; + +/** + * @author Dmitry Avdeev + */ +public interface PossiblePrefixReference extends PsiReference { + + boolean isPrefixReference(); +} diff --git a/xml/impl/src/com/intellij/psi/impl/source/xml/SchemaPrefix.java b/xml/impl/src/com/intellij/psi/impl/source/xml/SchemaPrefix.java index d0905e2ca6cc..9669f8445ca4 100644 --- a/xml/impl/src/com/intellij/psi/impl/source/xml/SchemaPrefix.java +++ b/xml/impl/src/com/intellij/psi/impl/source/xml/SchemaPrefix.java @@ -16,13 +16,16 @@ package com.intellij.psi.impl.source.xml; import com.intellij.openapi.util.TextRange; +import com.intellij.psi.ElementManipulators; import com.intellij.psi.PsiElement; import com.intellij.psi.impl.RenameableFakePsiElement; import com.intellij.psi.search.SearchScope; import com.intellij.psi.xml.XmlAttribute; +import com.intellij.psi.xml.XmlAttributeValue; import com.intellij.util.Icons; import com.intellij.xml.XmlExtension; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -39,6 +42,16 @@ public class SchemaPrefix extends RenameableFakePsiElement { myName = name; } + public static SchemaPrefix createJspPrefix(XmlAttributeValue element, String prefix) { + TextRange range = ElementManipulators.getValueTextRange(element).shiftRight(element.getStartOffsetInParent()); + return new SchemaPrefix((XmlAttribute)element.getParent(), range, prefix) { + @Override + protected String getNamespace() { + return ((XmlAttribute)getParent()).getParent().getAttributeValue("uri"); + } + }; + } + public String getTypeName() { return "XML Namespace Prefix"; } @@ -81,4 +94,19 @@ public class SchemaPrefix extends RenameableFakePsiElement { public boolean isEquivalentTo(PsiElement another) { return another instanceof SchemaPrefix && ((SchemaPrefix)another).getDeclaration() == getDeclaration(); } + + public String getQuickNavigateInfo() { + String ns = getNamespace(); + StringBuilder builder = new StringBuilder().append(getTypeName()).append(" \"").append(getName()).append("\""); + if (ns != null) { + builder.append(" (").append(ns).append(")"); + } + return builder.toString(); + } + + @Nullable + protected String getNamespace() { + XmlAttribute parent = (XmlAttribute)getParent(); + return parent.getValue(); + } } diff --git a/xml/impl/src/com/intellij/psi/impl/source/xml/SchemaPrefixReference.java b/xml/impl/src/com/intellij/psi/impl/source/xml/SchemaPrefixReference.java index 9e21a3be9232..8ef432759162 100644 --- a/xml/impl/src/com/intellij/psi/impl/source/xml/SchemaPrefixReference.java +++ b/xml/impl/src/com/intellij/psi/impl/source/xml/SchemaPrefixReference.java @@ -34,7 +34,7 @@ import org.jetbrains.annotations.Nullable; /** * @author Konstantin Bulenkov */ -public class SchemaPrefixReference extends PsiReferenceBase { +public class SchemaPrefixReference extends PsiReferenceBase implements PossiblePrefixReference { private final NullableLazyValue myPrefix = new NullableLazyValue() { @Override @@ -44,7 +44,7 @@ public class SchemaPrefixReference extends PsiReferenceBase { } else if (myElement instanceof XmlAttributeValue && ((XmlAttribute)((XmlAttributeValue)myElement).getParent()).getLocalName().equals("prefix")) { - return new SchemaPrefix((XmlAttribute)myElement.getParent(), getRangeInElement().shiftRight(myElement.getStartOffsetInParent()), myName); + return SchemaPrefix.createJspPrefix((XmlAttributeValue)SchemaPrefixReference.this.myElement, myName); } else { return resolvePrefix(myElement, myName); @@ -56,6 +56,13 @@ public class SchemaPrefixReference extends PsiReferenceBase { @Nullable private final TagNameReference myTagNameReference; + /** + * + * @param element XmlAttribute || XmlAttributeValue + * @param range + * @param name + * @param tagNameReference + */ public SchemaPrefixReference(XmlElement element, TextRange range, String name, @Nullable TagNameReference tagNameReference) { super(element, range, true); myName = name; @@ -102,12 +109,11 @@ public class SchemaPrefixReference extends PsiReferenceBase { @Nullable public static SchemaPrefix resolvePrefix(PsiElement element, String name) { XmlExtension extension = XmlExtension.getExtension(element.getContainingFile()); - final XmlAttribute declaration = extension.getPrefixDeclaration(PsiTreeUtil.getParentOfType(element, XmlTag.class, false), name); - if (declaration != null) { - final String prefix = declaration.getNamespacePrefix(); - final TextRange textRange = TextRange.from(prefix.length() + 1, name.length()); - return new SchemaPrefix(declaration, textRange, name); - } - return null; + return extension.getPrefixDeclaration(PsiTreeUtil.getParentOfType(element, XmlTag.class, false), name); + } + + @Override + public boolean isPrefixReference() { + return true; } } diff --git a/xml/impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java b/xml/impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java index 00f397913480..da672c0a6d1c 100644 --- a/xml/impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java +++ b/xml/impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java @@ -437,7 +437,7 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag { XmlElementDescriptor elementDescriptor = null; final XmlNSDescriptor nsDescriptor = getNSDescriptor(namespace, false); if (nsDescriptor != null) { - if (!DumbService.getInstance(getProject()).isDumb() || nsDescriptor instanceof DumbAware) { + if (!DumbService.getInstance(getProject()).isDumb() || DumbService.isDumbAware(nsDescriptor)) { elementDescriptor = nsDescriptor.getElementDescriptor(this); } } diff --git a/xml/impl/src/com/intellij/xml/DefaultXmlExtension.java b/xml/impl/src/com/intellij/xml/DefaultXmlExtension.java index 678ecb4599a8..561afd3e4c4d 100644 --- a/xml/impl/src/com/intellij/xml/DefaultXmlExtension.java +++ b/xml/impl/src/com/intellij/xml/DefaultXmlExtension.java @@ -20,12 +20,14 @@ import com.intellij.openapi.editor.ScrollType; import com.intellij.openapi.module.ModuleUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.XmlElementFactory; import com.intellij.psi.codeStyle.CodeStyleManager; +import com.intellij.psi.impl.source.xml.SchemaPrefix; import com.intellij.psi.impl.source.xml.TagNameReference; import com.intellij.psi.xml.*; import com.intellij.util.IncorrectOperationException; @@ -242,13 +244,17 @@ public class DefaultXmlExtension extends XmlExtension { } } - public XmlAttribute getPrefixDeclaration(final XmlTag context, String namespacePrefix) { + public SchemaPrefix getPrefixDeclaration(final XmlTag context, String namespacePrefix) { @NonNls String nsDeclarationAttrName = null; for(XmlTag t = context; t != null; t = t.getParentTag()) { if (t.hasNamespaceDeclarations()) { if (nsDeclarationAttrName == null) nsDeclarationAttrName = namespacePrefix.length() > 0 ? "xmlns:"+namespacePrefix:"xmlns"; XmlAttribute attribute = t.getAttribute(nsDeclarationAttrName); - if (attribute != null) return attribute; + if (attribute != null) { + final String attrPrefix = attribute.getNamespacePrefix(); + final TextRange textRange = TextRange.from(attrPrefix.length() + 1, namespacePrefix.length()); + return new SchemaPrefix(attribute, textRange, namespacePrefix); + } } } return null; diff --git a/xml/impl/src/com/intellij/xml/XmlExtension.java b/xml/impl/src/com/intellij/xml/XmlExtension.java index 43ab08f8de94..761c649d37a1 100644 --- a/xml/impl/src/com/intellij/xml/XmlExtension.java +++ b/xml/impl/src/com/intellij/xml/XmlExtension.java @@ -28,6 +28,7 @@ import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.psi.impl.source.xml.SchemaPrefix; import com.intellij.psi.impl.source.xml.TagNameReference; import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.SearchScope; @@ -156,7 +157,7 @@ public abstract class XmlExtension { } @Nullable - public abstract XmlAttribute getPrefixDeclaration(final XmlTag context, String namespacePrefix); + public abstract SchemaPrefix getPrefixDeclaration(final XmlTag context, String namespacePrefix); public SearchScope getNsPrefixScope(XmlAttribute declaration) { return new LocalSearchScope(declaration.getParent()); diff --git a/xml/impl/src/com/intellij/xml/refactoring/SchemaPrefixRenameHandler.java b/xml/impl/src/com/intellij/xml/refactoring/SchemaPrefixRenameHandler.java index 838fbee82313..655c42040aff 100644 --- a/xml/impl/src/com/intellij/xml/refactoring/SchemaPrefixRenameHandler.java +++ b/xml/impl/src/com/intellij/xml/refactoring/SchemaPrefixRenameHandler.java @@ -18,10 +18,10 @@ package com.intellij.xml.refactoring; import com.intellij.openapi.editor.Editor; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiNamedElement; import com.intellij.psi.PsiReference; -import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; +import com.intellij.psi.impl.source.xml.PossiblePrefixReference; import com.intellij.psi.impl.source.xml.SchemaPrefix; -import com.intellij.psi.impl.source.xml.SchemaPrefixReference; import com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler; import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer; import org.jetbrains.annotations.Nullable; @@ -35,25 +35,17 @@ public class SchemaPrefixRenameHandler extends VariableInplaceRenameHandler { @Override protected boolean isAvailable(PsiElement element, Editor editor, PsiFile file) { - SchemaPrefixReference ref = getReference(file, editor); - return ref != null && ref.resolve() != null; + PossiblePrefixReference ref = getReference(file, editor); + return ref != null && ref.resolve() instanceof SchemaPrefix; } @Nullable - private static SchemaPrefixReference getReference(PsiFile file, Editor editor) { + private static PossiblePrefixReference getReference(PsiFile file, Editor editor) { if (file != null && editor != null) { int offset = editor.getCaretModel().getOffset(); PsiReference reference = file.findReferenceAt(offset); - if (reference instanceof PsiMultiReference) { - PsiReference[] references = ((PsiMultiReference)reference).getReferences(); - for (PsiReference psiReference : references) { - if (psiReference instanceof SchemaPrefixReference) { - return (SchemaPrefixReference)psiReference; - } - } - } - if (reference instanceof SchemaPrefixReference) { - return (SchemaPrefixReference)reference; + if (reference instanceof PossiblePrefixReference) { + return (PossiblePrefixReference)reference; } } return null; @@ -62,11 +54,11 @@ public class SchemaPrefixRenameHandler extends VariableInplaceRenameHandler { @Override protected VariableInplaceRenamer createRenamer(PsiElement elementToRename, Editor editor) { - SchemaPrefixReference reference = getReference(elementToRename.getContainingFile(), editor); + PossiblePrefixReference reference = getReference(elementToRename.getContainingFile(), editor); if (reference != null) { - SchemaPrefix prefix = reference.resolve(); - if (prefix != null) { - return new VariableInplaceRenamer(prefix, editor) { + PsiElement prefix = reference.resolve(); + if (prefix instanceof SchemaPrefix) { + return new VariableInplaceRenamer((PsiNamedElement)prefix, editor) { @Override protected void addReferenceAtCaret(Collection refs) {} diff --git a/xml/impl/src/com/intellij/xml/util/documentation/HtmlDocumentationProvider.java b/xml/impl/src/com/intellij/xml/util/documentation/HtmlDocumentationProvider.java index 6282a4d8c79a..13a78ae40786 100644 --- a/xml/impl/src/com/intellij/xml/util/documentation/HtmlDocumentationProvider.java +++ b/xml/impl/src/com/intellij/xml/util/documentation/HtmlDocumentationProvider.java @@ -21,6 +21,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiManager; import com.intellij.psi.PsiWhiteSpace; import com.intellij.psi.XmlElementFactory; +import com.intellij.psi.impl.source.xml.SchemaPrefix; import com.intellij.psi.meta.PsiMetaData; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.*; @@ -54,7 +55,10 @@ public class HtmlDocumentationProvider implements DocumentationProvider { @Nullable public String getQuickNavigateInfo(PsiElement element) { - return null; + if (element instanceof SchemaPrefix) { + return ((SchemaPrefix)element).getQuickNavigateInfo(); + } + return null; } public List getUrlFor(PsiElement element, PsiElement originalElement) { diff --git a/xml/impl/src/com/intellij/xml/util/documentation/XmlDocumentationProvider.java b/xml/impl/src/com/intellij/xml/util/documentation/XmlDocumentationProvider.java index 48e0d93f4056..d049c94edd06 100644 --- a/xml/impl/src/com/intellij/xml/util/documentation/XmlDocumentationProvider.java +++ b/xml/impl/src/com/intellij/xml/util/documentation/XmlDocumentationProvider.java @@ -26,6 +26,7 @@ import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.html.HtmlTag; +import com.intellij.psi.impl.source.xml.SchemaPrefix; import com.intellij.psi.search.PsiElementProcessor; import com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider; import com.intellij.psi.tree.IElementType; @@ -62,6 +63,9 @@ public class XmlDocumentationProvider implements DocumentationProvider { @Nullable public String getQuickNavigateInfo(PsiElement element) { + if (element instanceof SchemaPrefix) { + return ((SchemaPrefix)element).getQuickNavigateInfo(); + } final String name = ElementDescriptionUtil.getElementDescription(element, UsageViewShortNameLocation.INSTANCE); if (StringUtil.isEmpty(name)) return null; final String typeName = ElementDescriptionUtil.getElementDescription(element, UsageViewTypeLocation.INSTANCE); diff --git a/xml/openapi/src/com/intellij/xml/XmlSchemaProvider.java b/xml/openapi/src/com/intellij/xml/XmlSchemaProvider.java index c6b6322f5913..7fa5b7b3e19e 100644 --- a/xml/openapi/src/com/intellij/xml/XmlSchemaProvider.java +++ b/xml/openapi/src/com/intellij/xml/XmlSchemaProvider.java @@ -47,7 +47,7 @@ public abstract class XmlSchemaProvider { final boolean dumb = DumbService.getInstance(file.getProject()).isDumb(); for (XmlSchemaProvider provider: Extensions.getExtensions(EP_NAME)) { - if (dumb && !(provider instanceof DumbAware)) { + if (dumb && !DumbService.isDumbAware(provider)) { continue; }