diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index 8f68c7ff4db9..73299fdf0ddb 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -886,11 +886,17 @@ public class HighlightUtil extends HighlightUtilBase { isAllowed = false; } - if (PsiModifier.PRIVATE.equals(modifier) || PsiModifier.PROTECTED.equals(modifier) || PsiModifier.TRANSIENT.equals(modifier) || - PsiModifier.STRICTFP.equals(modifier) || PsiModifier.SYNCHRONIZED.equals(modifier)) { + if (PsiModifier.PRIVATE.equals(modifier)) { isAllowed &= modifierOwnerParent instanceof PsiClass && (!((PsiClass)modifierOwnerParent).isInterface() || PsiUtil.isLanguageLevel9OrHigher(modifierOwner)); } + else if (PsiModifier.STRICTFP.equals(modifier)) { + isAllowed &= modifierOwnerParent instanceof PsiClass && (!((PsiClass)modifierOwnerParent).isInterface() || PsiUtil.isLanguageLevel8OrHigher(modifierOwner)); + } + else if (PsiModifier.PROTECTED.equals(modifier) || PsiModifier.TRANSIENT.equals(modifier) || + PsiModifier.SYNCHRONIZED.equals(modifier)) { + isAllowed &= modifierOwnerParent instanceof PsiClass && !((PsiClass)modifierOwnerParent).isInterface(); + } if (containingClass != null && containingClass.isAnnotationType()) { isAllowed &= !PsiModifier.STATIC.equals(modifier); diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java index 221fd6259f14..0ae52adb5325 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java @@ -238,10 +238,10 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection final ForbiddenRefsChecker checker = new ForbiddenRefsChecker(method, anonymousClass); body.accept(checker); - PsiResolveHelper helper = PsiResolveHelper.SERVICE.getInstance(body.getProject()); - final Set conflictingLocals = checker.getLocals(); - for (Iterator iterator = conflictingLocals.iterator(); iterator.hasNext(); ) { - PsiLocalVariable local = iterator.next(); + final PsiResolveHelper helper = PsiResolveHelper.SERVICE.getInstance(body.getProject()); + final Set conflictingLocals = checker.getLocals(); + for (Iterator iterator = conflictingLocals.iterator(); iterator.hasNext(); ) { + PsiVariable local = iterator.next(); final String localName = local.getName(); if (localName == null || helper.resolveReferencedVariable(localName, anonymousClass) == null) { iterator.remove(); @@ -252,7 +252,7 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project); ReplaceWithLambdaFix - .giveUniqueNames(project, lambdaContext, elementFactory, body, conflictingLocals.toArray(new PsiVariable[conflictingLocals.size()])); + .giveUniqueNames(project, anonymousClass, elementFactory, body, conflictingLocals.toArray(new PsiVariable[conflictingLocals.size()])); final String lambdaWithTypesDeclared = ReplaceWithLambdaFix.composeLambdaText(method, true); final String withoutTypesDeclared = ReplaceWithLambdaFix.composeLambdaText(method, false); @@ -350,7 +350,7 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection final Map names = new HashMap(); for (PsiVariable parameter : parameters) { String parameterName = parameter.getName(); - final String uniqueVariableName = codeStyleManager.suggestUniqueVariableName(parameterName, lambdaContext, false); + final String uniqueVariableName = codeStyleManager.suggestUniqueVariableName(parameterName, parameter.getParent(), false); if (!Comparing.equal(parameterName, uniqueVariableName)) { names.put(parameter, uniqueVariableName); } @@ -451,7 +451,7 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection private static class ForbiddenRefsChecker extends JavaRecursiveElementWalkingVisitor { private boolean myBodyContainsForbiddenRefs; - private final Set myLocals = ContainerUtilRt.newHashSet(5); + private final Set myLocals = ContainerUtilRt.newHashSet(5); private final PsiMethod myMethod; private final PsiAnonymousClass myAnonymClass; @@ -502,11 +502,13 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection } @Override - public void visitLocalVariable(PsiLocalVariable variable) { + public void visitVariable(PsiVariable variable) { if (myBodyContainsForbiddenRefs) return; - super.visitLocalVariable(variable); - myLocals.add(variable); + super.visitVariable(variable); + if (!(variable instanceof PsiField)) { + myLocals.add(variable); + } } @Override @@ -590,7 +592,7 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection return myBodyContainsForbiddenRefs; } - public Set getLocals() { + public Set getLocals() { return myLocals; } } diff --git a/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java b/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java index 954dd08703c9..9d4cf552c4fe 100644 --- a/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java @@ -340,6 +340,9 @@ public class LambdaUtil { if (gParent instanceof PsiCall) { final PsiCall contextCall = (PsiCall)gParent; final MethodCandidateInfo.CurrentCandidateProperties properties = MethodCandidateInfo.getCurrentMethod(contextCall.getArgumentList()); + if (MethodCandidateInfo.isOverloadCheck()) { + MethodCandidateInfo.ourOverloadGuard.prohibitResultCaching(MethodCandidateInfo.ourOverloadGuard.currentStack().get(0)); + } if (properties != null && properties.isApplicabilityCheck()) { //todo simplification final PsiParameter[] parameters = properties.getMethod().getParameterList().getParameters(); final int finalLambdaIdx = adjustLambdaIdx(lambdaIdx, properties.getMethod(), parameters); diff --git a/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java b/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java index 78a58fc8b70b..7a87a8c6bb49 100644 --- a/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java +++ b/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java @@ -326,9 +326,6 @@ public class MethodCandidateInfo extends CandidateInfo{ public static CurrentCandidateProperties getCurrentMethod(PsiElement context) { - if (isOverloadCheck()) { - ourOverloadGuard.prohibitResultCaching(ourOverloadGuard.currentStack().get(0)); - } final Map currentMethodCandidates = CURRENT_CANDIDATE.get(); return currentMethodCandidates != null ? currentMethodCandidates.get(context) : null; } diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocUtil.java b/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocUtil.java index 5b782423d6b2..f4376e734436 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocUtil.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocUtil.java @@ -364,14 +364,6 @@ public class JavaDocUtil { } public static boolean isInsidePackageInfo(@Nullable PsiDocComment containingComment) { - if (containingComment == null || containingComment.getOwner() != null) { - return false; - } - final PsiElement parent = containingComment.getParent(); - if (!(parent instanceof PsiJavaFile)) { - return false; - } - final PsiJavaFile file = (PsiJavaFile)parent; - return "package-info.java".equals(file.getName()); + return containingComment != null && containingComment.getOwner() == null && containingComment.getParent() instanceof PsiJavaFile; } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java index 2a03a31bb3ea..01b8d0e45786 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java @@ -34,7 +34,10 @@ import com.intellij.psi.scope.NameHint; import com.intellij.psi.scope.PsiScopeProcessor; import com.intellij.psi.scope.processor.FilterScopeProcessor; import com.intellij.psi.scope.processor.MethodResolverProcessor; -import com.intellij.psi.search.*; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.LocalSearchScope; +import com.intellij.psi.search.PackageScope; +import com.intellij.psi.search.SearchScope; import com.intellij.psi.util.*; import com.intellij.ui.IconDeferrer; import com.intellij.ui.RowIcon; @@ -711,54 +714,12 @@ public class PsiClassImplUtil { } @Nullable - public static PsiClassType correctType(PsiClassType originalType, final GlobalSearchScope resolveScope) { - if (!Registry.is("java.correct.class.type.by.place.resolve.scope")) { + public static T correctType(@Nullable final T originalType, @NotNull final GlobalSearchScope resolveScope) { + if (originalType == null || !Registry.is("java.correct.class.type.by.place.resolve.scope")) { return originalType; } - final PsiClassType.ClassResolveResult originalResolveResult = originalType.resolveGenerics(); - PsiClass superClass = originalResolveResult.getElement(); - if (superClass == null) { - return originalType; - } - - String qualifiedName = superClass.getQualifiedName(); - if (qualifiedName != null && !PsiSearchScopeUtil.isInScope(resolveScope, superClass)) { - final PsiFile file = superClass.getContainingFile(); - if (file == null || !file.getViewProvider().isPhysical()) { - return originalType; - } - PsiClass originalSuperClass = superClass; - PsiSubstitutor originalSubstitutor = originalResolveResult.getSubstitutor(); - superClass = JavaPsiFacade.getInstance(superClass.getProject()).findClass(qualifiedName, resolveScope); - if (superClass == null) { - return null; - } - - PsiTypeParameter[] typeParameters = superClass.getTypeParameters(); - PsiTypeParameter[] originalTypeParameters = originalSuperClass.getTypeParameters(); - if (typeParameters.length != originalTypeParameters.length) return null; - - PsiSubstitutor substitutor = PsiSubstitutor.EMPTY; - for (int i = 0; i < originalTypeParameters.length; i++) { - PsiType originalSubstitute = originalSubstitutor.substitute(originalTypeParameters[i]); - if (originalSubstitute != null) { - PsiType substitute = originalSubstitute.accept(new PsiTypeVisitor() { - @Nullable - @Override - public PsiType visitClassType(PsiClassType classType) { - return correctType(classType, resolveScope); - } - }); - if (substitute == null) return null; - - substitutor = substitutor.put(typeParameters[i], substitute); - } - } - return JavaPsiFacade.getElementFactory(superClass.getProject()).createType(superClass, substitutor); - } - - return originalType; + return new TypeCorrector(resolveScope).mapType(originalType); } private static boolean processSuperTypes(@NotNull PsiClass aClass, diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/TypeCorrector.java b/java/java-psi-impl/src/com/intellij/psi/impl/TypeCorrector.java new file mode 100644 index 000000000000..9f9214afaf4d --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/TypeCorrector.java @@ -0,0 +1,283 @@ +/* + * Copyright 2000-2015 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; + +import com.intellij.pom.java.LanguageLevel; +import com.intellij.psi.*; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.util.PsiUtilCore; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; + +/** + * @author peter + */ +class TypeCorrector extends PsiTypeMapper { + private final Map myResultMap = ContainerUtil.newIdentityHashMap(); + private final GlobalSearchScope myResolveScope; + + TypeCorrector(GlobalSearchScope resolveScope) { + myResolveScope = resolveScope; + } + + @Override + public PsiType visitType(PsiType type) { + if (type instanceof PsiLambdaParameterType || type instanceof PsiLambdaExpressionType || type instanceof PsiMethodReferenceType) { + return type; + } + return super.visitType(type); + } + + @Override + public PsiType visitClassType(final PsiClassType classType) { + PsiClassType alreadyComputed = myResultMap.get(classType); + if (alreadyComputed != null) { + return alreadyComputed; + } + + final PsiClassType.ClassResolveResult classResolveResult = classType.resolveGenerics(); + final PsiClass psiClass = classResolveResult.getElement(); + final PsiSubstitutor substitutor = classResolveResult.getSubstitutor(); + if (psiClass == null) return classType; + + PsiUtilCore.ensureValid(psiClass); + + final PsiClass mappedClass = mapClass(psiClass); + if (mappedClass == null) return null; + + PsiClassType mappedType = new PsiCorrectedClassType(classType.getLanguageLevel(), + classType, + new CorrectedResolveResult(psiClass, mappedClass, substitutor, classResolveResult)); + myResultMap.put(classType, mappedType); + return mappedType; + } + + private PsiClass mapClass(@NotNull PsiClass psiClass) { + String qualifiedName = psiClass.getQualifiedName(); + if (qualifiedName == null) { + return psiClass; + } + + PsiFile file = psiClass.getContainingFile(); + if (file == null || !file.getViewProvider().isPhysical()) { + return psiClass; + } + + return JavaPsiFacade.getInstance(psiClass.getProject()).findClass(qualifiedName, myResolveScope); + } + + @Nullable + private PsiSubstitutor mapSubstitutor(PsiClass originalClass, PsiClass mappedClass, PsiSubstitutor substitutor) { + PsiTypeParameter[] typeParameters = mappedClass.getTypeParameters(); + PsiTypeParameter[] originalTypeParameters = originalClass.getTypeParameters(); + if (typeParameters.length != originalTypeParameters.length) return null; + + PsiSubstitutor mappedSubstitutor = PsiSubstitutor.EMPTY; + for (int i = 0; i < originalTypeParameters.length; i++) { + PsiType originalSubstitute = substitutor.substitute(originalTypeParameters[i]); + if (originalSubstitute != null) { + PsiType substitute = mapType(originalSubstitute); + if (substitute == null) return null; + + mappedSubstitutor = mappedSubstitutor.put(typeParameters[i], substitute); + } + else { + mappedSubstitutor = mappedSubstitutor.put(typeParameters[i], null); + } + } + + if (mappedClass.hasModifierProperty(PsiModifier.STATIC)) { + return mappedSubstitutor; + } + PsiClass mappedContaining = mappedClass.getContainingClass(); + PsiClass originalContaining = originalClass.getContainingClass(); + if ((mappedContaining != null) != (originalContaining != null)) { + return null; + } + + if (mappedContaining != null) { + PsiSubstitutor outerSubstitutor = mapSubstitutor(originalContaining, mappedContaining, substitutor); + if (outerSubstitutor == null) return null; + + return mappedSubstitutor.putAll(outerSubstitutor); + } + + return mappedSubstitutor; + } + + private class PsiCorrectedClassType extends PsiClassType.Stub { + private final PsiClassType myDelegate; + private final CorrectedResolveResult myResolveResult; + + public PsiCorrectedClassType(LanguageLevel languageLevel, + PsiClassType delegate, + CorrectedResolveResult resolveResult) { + super(languageLevel, delegate.getAnnotations()); + myDelegate = delegate; + myResolveResult = resolveResult; + } + + @NotNull + @Override + public String getCanonicalText(boolean annotated) { + return myDelegate.getCanonicalText(); + } + + @NotNull + @Override + public PsiClass resolve() { + return myResolveResult.myMappedClass; + } + + @Override + public String getClassName() { + return myDelegate.getClassName(); + } + + @NotNull + @Override + public PsiType[] getParameters() { + return ContainerUtil.map2Array(myDelegate.getParameters(), PsiType.class, new Function() { + @Override + public PsiType fun(PsiType type) { + return mapType(type); + } + }); + } + + @NotNull + @Override + public ClassResolveResult resolveGenerics() { + return myResolveResult; + } + + @NotNull + @Override + public PsiClassType rawType() { + PsiClass psiClass = resolve(); + PsiElementFactory factory = JavaPsiFacade.getElementFactory(psiClass.getProject()); + return factory.createType(psiClass, factory.createRawSubstitutor(psiClass)); + } + + @NotNull + @Override + public GlobalSearchScope getResolveScope() { + return myResolveScope; + } + + @NotNull + @Override + public LanguageLevel getLanguageLevel() { + return myLanguageLevel; + } + + @NotNull + @Override + public PsiClassType setLanguageLevel(@NotNull LanguageLevel languageLevel) { + return new PsiCorrectedClassType(languageLevel, myDelegate, myResolveResult); + } + + @NotNull + @Override + public String getPresentableText() { + return myDelegate.getPresentableText(); + } + + @NotNull + @Override + public String getInternalCanonicalText() { + return myDelegate.getInternalCanonicalText(); + } + + @Override + public boolean isValid() { + return myDelegate.isValid() && resolve().isValid(); + } + + @Override + public boolean equalsToText(@NotNull @NonNls String text) { + return myDelegate.equalsToText(text); + } + } + + private class CorrectedResolveResult implements PsiClassType.ClassResolveResult { + private final PsiClass myPsiClass; + private final PsiClass myMappedClass; + private final PsiSubstitutor mySubstitutor; + private final PsiClassType.ClassResolveResult myClassResolveResult; + private volatile PsiSubstitutor myLazySubstitutor; + + public CorrectedResolveResult(PsiClass psiClass, + PsiClass mappedClass, + PsiSubstitutor substitutor, + PsiClassType.ClassResolveResult classResolveResult) { + myPsiClass = psiClass; + myMappedClass = mappedClass; + mySubstitutor = substitutor; + myClassResolveResult = classResolveResult; + } + + @NotNull + @Override + public PsiSubstitutor getSubstitutor() { + PsiSubstitutor result = myLazySubstitutor; + if (result == null) { + result = mapSubstitutor(myPsiClass, myMappedClass, mySubstitutor); + if (result == null) { + //better ideas? + result = JavaPsiFacade.getElementFactory(myMappedClass.getProject()).createRawSubstitutor(myMappedClass); + } + myLazySubstitutor = result; + } + return result; + } + + @Override + public PsiClass getElement() { + return myMappedClass; + } + + @Override + public boolean isPackagePrefixPackageReference() { + return myClassResolveResult.isPackagePrefixPackageReference(); + } + + @Override + public boolean isAccessible() { + return myClassResolveResult.isAccessible(); + } + + @Override + public boolean isStaticsScopeCorrect() { + return myClassResolveResult.isStaticsScopeCorrect(); + } + + @Override + public PsiElement getCurrentFileResolveScope() { + return myClassResolveResult.getCurrentFileResolveScope(); + } + + @Override + public boolean isValidResult() { + return myClassResolveResult.isValidResult(); + } + } +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java index f8dbb9d2c1f3..c4ee51d9030b 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java @@ -24,6 +24,7 @@ import com.intellij.openapi.util.Condition; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; import com.intellij.psi.impl.DebugUtil; +import com.intellij.psi.impl.PsiClassImplUtil; import com.intellij.psi.impl.PsiImplUtil; import com.intellij.psi.impl.source.resolve.JavaResolveCache; import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession; @@ -171,7 +172,7 @@ public class PsiMethodCallExpressionImpl extends ExpressionPsiElement implements } } - return theOnly; + return PsiClassImplUtil.correctType(theOnly, call.getResolveScope()); } @Nullable diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiReferenceExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiReferenceExpressionImpl.java index 040653e20934..aaeb06e8d795 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiReferenceExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiReferenceExpressionImpl.java @@ -27,6 +27,7 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.codeStyle.JavaCodeStyleSettingsFacade; import com.intellij.psi.filters.*; import com.intellij.psi.impl.CheckUtil; +import com.intellij.psi.impl.PsiClassImplUtil; import com.intellij.psi.impl.PsiImplUtil; import com.intellij.psi.impl.PsiManagerEx; import com.intellij.psi.impl.source.SourceJavaCodeReference; @@ -405,11 +406,11 @@ public class PsiReferenceExpressionImpl extends PsiReferenceExpressionBase imple PsiUtil.ensureValidType(substitutedType); PsiType normalized = PsiImplUtil.normalizeWildcardTypeByPosition(substitutedType, expr); PsiUtil.ensureValidType(normalized); - return normalized; + return PsiClassImplUtil.correctType(normalized, expr.getResolveScope()); } } - return TypeConversionUtil.erasure(ret); + return PsiClassImplUtil.correctType(TypeConversionUtil.erasure(ret), expr.getResolveScope()); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/advHighlighting/StrictfpInsideInterface.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/advHighlighting/StrictfpInsideInterface.java new file mode 100644 index 000000000000..580db587dd07 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/advHighlighting/StrictfpInsideInterface.java @@ -0,0 +1,5 @@ +interface A { + strictfp void m(); + strictfp default void m1(){} + strictfp static void m2() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/afterConflictsWithForeachParamAndLambdaParamNames.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/afterConflictsWithForeachParamAndLambdaParamNames.java new file mode 100644 index 000000000000..8e5eed468177 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/afterConflictsWithForeachParamAndLambdaParamNames.java @@ -0,0 +1,15 @@ +// "Replace with lambda" "true" +class Test2 { + + void foo(final List loggers) { + final PatchLogger logger = logger1 -> { + for (PatchLogger logger2 : loggers) { + logger2.logOperation(logger1); + } + }; + } + + public interface PatchLogger { + void logOperation(String logger); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/afterNameConflictsWithForeachParam.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/afterNameConflictsWithForeachParam.java new file mode 100644 index 000000000000..7892f8b835d9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/afterNameConflictsWithForeachParam.java @@ -0,0 +1,15 @@ +// "Replace with lambda" "true" +class Test2 { + + void foo(final List loggers) { + final PatchLogger logger = s -> { + for (PatchLogger logger1 : loggers) { + logger1.logOperation(s); + } + }; + } + + public interface PatchLogger { + void logOperation(String logger); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/beforeConflictsWithForeachParamAndLambdaParamNames.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/beforeConflictsWithForeachParamAndLambdaParamNames.java new file mode 100644 index 000000000000..60b8ac5e916e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/beforeConflictsWithForeachParamAndLambdaParamNames.java @@ -0,0 +1,18 @@ +// "Replace with lambda" "true" +class Test2 { + + void foo(final List loggers) { + final PatchLogger logger = new PatchLogger() { + @Override + public void logOperation(String logger1) { + for (PatchLogger logger : loggers) { + logger.logOperation(logger1); + } + } + }; + } + + public interface PatchLogger { + void logOperation(String logger); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/beforeNameConflictsWithForeachParam.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/beforeNameConflictsWithForeachParam.java new file mode 100644 index 000000000000..88d7c7e686fa --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/beforeNameConflictsWithForeachParam.java @@ -0,0 +1,18 @@ +// "Replace with lambda" "true" +class Test2 { + + void foo(final List loggers) { + final PatchLogger logger = new PatchLogger() { + @Override + public void logOperation(String s) { + for (PatchLogger logger : loggers) { + logger.logOperation(s); + } + } + }; + } + + public interface PatchLogger { + void logOperation(String logger); + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/MultipleModuleHighlightingTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/MultipleModuleHighlightingTest.groovy index b02d90b6d596..379068e37eeb 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/MultipleModuleHighlightingTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/MultipleModuleHighlightingTest.groovy @@ -15,7 +15,6 @@ */ package com.intellij.codeInsight -import com.intellij.idea.Bombed import com.intellij.openapi.module.JavaModuleType import com.intellij.openapi.roots.ModuleRootModificationUtil import com.intellij.testFramework.PsiTestUtil @@ -25,7 +24,6 @@ import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase */ class MultipleModuleHighlightingTest extends JavaCodeInsightFixtureTestCase { - @Bombed(day = 1, month = Calendar.APRIL) public void "test use original place classpath for reference type resolving"() { addTwoModules() @@ -60,7 +58,6 @@ class Class3 { myFixture.checkHighlighting() } - @Bombed(day = 1, month = Calendar.APRIL) public void "test use original place classpath for new expression type resolving"() { addTwoModules() diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LightAdvHighlightingJdk8Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LightAdvHighlightingJdk8Test.java index 4ecf0b2b434e..d6428929a0d8 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LightAdvHighlightingJdk8Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LightAdvHighlightingJdk8Test.java @@ -43,6 +43,10 @@ public class LightAdvHighlightingJdk8Test extends LightDaemonAnalyzerTestCase { doTest(); } + public void testStrictfpInsideInterface() throws Exception { + doTest(); + } + private void doTest() { IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable()); doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false); diff --git a/platform/core-api/src/com/intellij/openapi/application/ApplicationNamesInfo.java b/platform/core-api/src/com/intellij/openapi/application/ApplicationNamesInfo.java index 326dc83d5a2c..369593cab3f9 100644 --- a/platform/core-api/src/com/intellij/openapi/application/ApplicationNamesInfo.java +++ b/platform/core-api/src/com/intellij/openapi/application/ApplicationNamesInfo.java @@ -31,16 +31,11 @@ public class ApplicationNamesInfo { @NonNls private static final String ATTRIBUTE_PRODUCT = "product"; @NonNls private static final String ATTRIBUTE_FULL_NAME = "fullname"; @NonNls private static final String ATTRIBUTE_SCRIPT = "script"; - @NonNls private static final String ELEMENT_VERSION = "version"; - @NonNls private static final String ATTRIBUTE_MAJOR = "major"; - @NonNls private static final String ATTRIBUTE_MINOR = "minor"; private String myProductName; private String myFullProductName; private String myLowercaseProductName; private String myScriptName; - private String myMajorVersion; - private String myMinorVersion; private static class ApplicationNamesInfoHolder { private static final ApplicationNamesInfo ourInstance = new ApplicationNamesInfo(); @@ -69,12 +64,6 @@ public class ApplicationNamesInfo { myFullProductName = names.getAttributeValue(ATTRIBUTE_FULL_NAME); myLowercaseProductName = StringUtil.capitalize(myProductName.toLowerCase()); myScriptName = names.getAttributeValue(ATTRIBUTE_SCRIPT); - - final Element version = rootElement.getChild(ELEMENT_VERSION); - if (version != null) { - myMajorVersion = version.getAttributeValue(ATTRIBUTE_MAJOR); - myMinorVersion = version.getAttributeValue(ATTRIBUTE_MINOR); - } } /** @@ -105,14 +94,6 @@ public class ApplicationNamesInfo { return myScriptName; } - public String getMinorVersion() { - return myMinorVersion; - } - - public String getMajorVersion() { - return myMajorVersion; - } - public static String getComponentName() { final String prefix = System.getProperty(PlatformUtils.PLATFORM_PREFIX_KEY); if (prefix != null) { diff --git a/platform/diff-impl/src/com/intellij/diff/actions/CompareFilesAction.java b/platform/diff-impl/src/com/intellij/diff/actions/CompareFilesAction.java index db52dbfe83d3..eacc189696a2 100644 --- a/platform/diff-impl/src/com/intellij/diff/actions/CompareFilesAction.java +++ b/platform/diff-impl/src/com/intellij/diff/actions/CompareFilesAction.java @@ -105,6 +105,7 @@ public class CompareFilesAction extends BaseShowDiffAction { if (data.length == 1) { VirtualFile otherFile = getOtherFile(project, data[0]); if (otherFile == null) return null; + if (!data[0].isValid()) return null; return DiffRequestFactory.getInstance().createFromFiles(project, data[0], otherFile); } else { @@ -127,8 +128,7 @@ public class CompareFilesAction extends BaseShowDiffAction { key = LAST_USED_FILE_KEY; } VirtualFile selectedFile = getDefaultSelection(project, key, file); - VirtualFile[] result = FileChooser.chooseFiles(descriptor, project, selectedFile); - VirtualFile otherFile = result.length == 1 ? result[0] : null; + VirtualFile otherFile = FileChooser.chooseFile(descriptor, project, selectedFile); if (otherFile != null) updateDefaultSelection(project, key, otherFile); return otherFile; } diff --git a/platform/diff-impl/src/com/intellij/diff/actions/impl/SetEditorSettingsAction.java b/platform/diff-impl/src/com/intellij/diff/actions/impl/SetEditorSettingsAction.java index fc2a3ab2050f..c93dc22b3656 100644 --- a/platform/diff-impl/src/com/intellij/diff/actions/impl/SetEditorSettingsAction.java +++ b/platform/diff-impl/src/com/intellij/diff/actions/impl/SetEditorSettingsAction.java @@ -31,15 +31,16 @@ import java.util.List; public abstract class SetEditorSettingsAction extends ActionGroup implements DumbAware { @NotNull private final TextDiffSettingsHolder.TextDiffSettings myTextSettings; + @NotNull private final List myEditors; + @NotNull private final EditorSettingToggleAction[] myActions; - @NotNull - public abstract List getEditors(); - - public SetEditorSettingsAction(@NotNull TextDiffSettingsHolder.TextDiffSettings settings) { + public SetEditorSettingsAction(@NotNull TextDiffSettingsHolder.TextDiffSettings settings, + @NotNull List editors) { super("Editor Settings", null, AllIcons.General.SecondaryGroup); setPopup(true); myTextSettings = settings; + myEditors = editors; myActions = new EditorSettingToggleAction[]{ new EditorSettingToggleAction("EditorToggleShowWhitespaces") { @@ -121,7 +122,7 @@ public abstract class SetEditorSettingsAction extends ActionGroup implements Dum } public void applyDefaults() { - for (Editor editor : getEditors()) { + for (Editor editor : myEditors) { for (EditorSettingToggleAction action : myActions) { action.apply(editor, action.isSelected()); } @@ -146,7 +147,7 @@ public abstract class SetEditorSettingsAction extends ActionGroup implements Dum @Override public void setSelected(AnActionEvent e, boolean state) { - for (Editor editor : getEditors()) { + for (Editor editor : myEditors) { setSelected(state); apply(editor, state); } diff --git a/platform/diff-impl/src/com/intellij/diff/contents/BinaryFileContentImpl.java b/platform/diff-impl/src/com/intellij/diff/contents/BinaryFileContentImpl.java index e61040b1c67a..155e3fd27bc2 100644 --- a/platform/diff-impl/src/com/intellij/diff/contents/BinaryFileContentImpl.java +++ b/platform/diff-impl/src/com/intellij/diff/contents/BinaryFileContentImpl.java @@ -42,7 +42,7 @@ public class BinaryFileContentImpl implements DiffContent, BinaryFileContent { @Nullable @Override public OpenFileDescriptor getOpenFileDescriptor() { - if (myProject == null) return null; + if (myProject == null || myProject.isDefault()) return null; return new OpenFileDescriptor(myProject, myFile); } diff --git a/platform/diff-impl/src/com/intellij/diff/contents/DirectoryContentImpl.java b/platform/diff-impl/src/com/intellij/diff/contents/DirectoryContentImpl.java index b59154fb3956..9f615079039c 100644 --- a/platform/diff-impl/src/com/intellij/diff/contents/DirectoryContentImpl.java +++ b/platform/diff-impl/src/com/intellij/diff/contents/DirectoryContentImpl.java @@ -35,7 +35,7 @@ public class DirectoryContentImpl implements DiffContent, DirectoryContent { @Nullable @Override public OpenFileDescriptor getOpenFileDescriptor() { - if (myProject == null) return null; + if (myProject == null || myProject.isDefault()) return null; return new OpenFileDescriptor(myProject, myFile); } diff --git a/platform/diff-impl/src/com/intellij/diff/contents/FileDocumentContentImpl.java b/platform/diff-impl/src/com/intellij/diff/contents/FileDocumentContentImpl.java index cccce658ad3f..0ced9087ad7b 100644 --- a/platform/diff-impl/src/com/intellij/diff/contents/FileDocumentContentImpl.java +++ b/platform/diff-impl/src/com/intellij/diff/contents/FileDocumentContentImpl.java @@ -39,7 +39,7 @@ public class FileDocumentContentImpl extends DocumentContentImpl implements File @Nullable @Override public OpenFileDescriptor getOpenFileDescriptor(int offset) { - if (myProject == null) return null; + if (myProject == null || myProject.isDefault()) return null; return new OpenFileDescriptor(myProject, myFile, offset); } diff --git a/platform/diff-impl/src/com/intellij/diff/tools/binary/BinaryDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/binary/BinaryDiffViewer.java index 5833255d194b..51fc0d7f4da7 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/binary/BinaryDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/binary/BinaryDiffViewer.java @@ -390,10 +390,13 @@ public class BinaryDiffViewer extends ListenerDiffViewerBase { List contents = ((ContentDiffRequest)request).getContents(); if (contents.size() != 2) return false; - if (!canShowContent(contents.get(0), context)) return false; - if (!canShowContent(contents.get(1), context)) return false; - - return wantShowContent(contents.get(0), context) || wantShowContent(contents.get(1), context); + boolean canShow = true; + boolean wantShow = false; + for (DiffContent content : contents) { + canShow &= canShowContent(content, context); + wantShow |= wantShowContent(content, context); + } + return canShow && wantShow; } public static boolean canShowContent(@NotNull DiffContent content, @NotNull DiffContext context) { diff --git a/platform/diff-impl/src/com/intellij/diff/tools/fragmented/OnesideDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/fragmented/OnesideDiffViewer.java index 19240f47404f..3305b65fcb2a 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/fragmented/OnesideDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/fragmented/OnesideDiffViewer.java @@ -71,6 +71,8 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import static com.intellij.diff.util.DiffUtil.getLineCount; + public class OnesideDiffViewer extends TextDiffViewerBase { public static final Logger LOG = Logger.getInstance(OnesideDiffViewer.class); diff --git a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffViewer.java index 4ec5b18b324f..464cb0837803 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffViewer.java @@ -67,6 +67,8 @@ import java.awt.event.WindowFocusListener; import java.util.*; import java.util.List; +import static com.intellij.diff.util.DiffUtil.getLineCount; + public class SimpleDiffViewer extends TwosideTextDiffViewer { public static final Logger LOG = Logger.getInstance(SimpleDiffViewer.class); diff --git a/platform/diff-impl/src/com/intellij/diff/tools/util/base/ListenerDiffViewerBase.java b/platform/diff-impl/src/com/intellij/diff/tools/util/base/ListenerDiffViewerBase.java index daa492d87807..45cc5114a85c 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/util/base/ListenerDiffViewerBase.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/util/base/ListenerDiffViewerBase.java @@ -71,7 +71,6 @@ public abstract class ListenerDiffViewerBase extends DiffViewerBase { @Override public void documentChanged(DocumentEvent event) { onDocumentChange(event); - scheduleRediff(); } }; } @@ -92,7 +91,6 @@ public abstract class ListenerDiffViewerBase extends DiffViewerBase { public void contentsChanged(@NotNull VirtualFileEvent event) { if (files.contains(event.getFile())) { onFileChange(event); - scheduleRediff(); } } @@ -100,7 +98,6 @@ public abstract class ListenerDiffViewerBase extends DiffViewerBase { public void propertyChanged(@NotNull VirtualFilePropertyEvent event) { if (files.contains(event.getFile())) { onFileChange(event); - scheduleRediff(); } } }; @@ -112,6 +109,7 @@ public abstract class ListenerDiffViewerBase extends DiffViewerBase { @CalledInAwt protected void onDocumentChange(@NotNull DocumentEvent event) { + scheduleRediff(); } @CalledInAwt @@ -120,6 +118,7 @@ public abstract class ListenerDiffViewerBase extends DiffViewerBase { @CalledInAwt protected void onFileChange(@NotNull VirtualFileEvent event) { + scheduleRediff(); } // diff --git a/platform/diff-impl/src/com/intellij/diff/tools/util/base/TextDiffViewerBase.java b/platform/diff-impl/src/com/intellij/diff/tools/util/base/TextDiffViewerBase.java index 558eaaf6b351..50675744b962 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/util/base/TextDiffViewerBase.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/util/base/TextDiffViewerBase.java @@ -26,7 +26,6 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.actionSystem.ex.ComboBoxAction; import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.actions.EditorActionUtil; import com.intellij.openapi.editor.event.EditorMouseEvent; import com.intellij.openapi.editor.ex.EditorEx; @@ -118,6 +117,11 @@ public abstract class TextDiffViewerBase extends ListenerDiffViewerBase { ); } + @CalledInAwt + protected void onSettingsChanged() { + rediff(); + } + // // Impl // @@ -162,10 +166,6 @@ public abstract class TextDiffViewerBase extends ListenerDiffViewerBase { return result; } - protected static int getLineCount(@NotNull Document document) { - return DiffUtil.getLineCount(document); - } - private class MyFontSizeListener implements PropertyChangeListener { private boolean myDuringUpdate = false; @@ -194,13 +194,7 @@ public abstract class TextDiffViewerBase extends ListenerDiffViewerBase { protected class MySetEditorSettingsAction extends SetEditorSettingsAction { public MySetEditorSettingsAction() { - super(myTextSettings); - } - - @NotNull - @Override - public List getEditors() { - return TextDiffViewerBase.this.getEditors(); + super(myTextSettings, getEditors()); } } @@ -280,7 +274,7 @@ public abstract class TextDiffViewerBase extends ListenerDiffViewerBase { if (getCurrentSetting() == setting) return; getTextSettings().setHighlightPolicy(setting); update(e); - rediff(); + onSettingsChanged(); } @NotNull @@ -311,7 +305,7 @@ public abstract class TextDiffViewerBase extends ListenerDiffViewerBase { if (getCurrentSetting() == setting) return; getTextSettings().setIgnorePolicy(setting); update(e); - rediff(); + onSettingsChanged(); } @NotNull diff --git a/platform/diff-impl/src/com/intellij/diff/tools/util/threeside/ThreesideTextDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/util/threeside/ThreesideTextDiffViewer.java index 1f2fb6d1f63b..244f81e4a138 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/util/threeside/ThreesideTextDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/util/threeside/ThreesideTextDiffViewer.java @@ -318,11 +318,13 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { List contents = ((ContentDiffRequest)request).getContents(); if (contents.size() != 3) return false; - if (!canShowContent(contents.get(0))) return false; - if (!canShowContent(contents.get(1))) return false; - if (!canShowContent(contents.get(2))) return false; - - return true; + boolean canShow = true; + boolean wantShow = false; + for (DiffContent content : contents) { + canShow &= canShowContent(content); + wantShow |= wantShowContent(content); + } + return canShow && wantShow; } public static boolean canShowContent(@NotNull DiffContent content) { @@ -330,6 +332,11 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { return false; } + public static boolean wantShowContent(@NotNull DiffContent content) { + if (content instanceof DocumentContent) return true; + return false; + } + // // Actions // diff --git a/platform/diff-impl/src/com/intellij/diff/tools/util/twoside/TwosideTextDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/util/twoside/TwosideTextDiffViewer.java index e139f972ea72..96689115da21 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/util/twoside/TwosideTextDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/util/twoside/TwosideTextDiffViewer.java @@ -351,7 +351,7 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { EditorEx editor = getCurrentEditor(); DocumentContent content = getCurrentSide().select(myActualContent1, myActualContent2); - if (content == null) return null; + assert content != null; int offset = editor.getCaretModel().getOffset(); return content.getOpenFileDescriptor(offset); @@ -363,12 +363,13 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { List contents = ((ContentDiffRequest)request).getContents(); if (contents.size() != 2) return false; - if (!canShowContent(contents.get(0))) return false; - if (!canShowContent(contents.get(1))) return false; - - if (contents.get(0) instanceof EmptyContent && contents.get(1) instanceof EmptyContent) return false; - - return true; + boolean canShow = true; + boolean wantShow = false; + for (DiffContent content : contents) { + canShow &= canShowContent(content); + wantShow |= wantShowContent(content); + } + return canShow && wantShow; } public static boolean canShowContent(@NotNull DiffContent content) { @@ -377,6 +378,11 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { return false; } + public static boolean wantShowContent(@NotNull DiffContent content) { + if (content instanceof DocumentContent) return true; + return false; + } + // // Actions // diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleMainPanel.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleMainPanel.java index aff417c38e02..6d155c9f4ed6 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleMainPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleMainPanel.java @@ -91,7 +91,9 @@ public class CodeStyleMainPanel extends JPanel implements TabbedLanguageCodeStyl @Override public void currentSettingsChanged() { - ensureCurrentPanel().onSomethingChanged(); + if (!myIsDisposed) { + ensureCurrentPanel().onSomethingChanged(); + } } @Override diff --git a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java index 6d909a44a0a9..24d460c2658e 100644 --- a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java @@ -60,16 +60,14 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P @NonNls public static final String COMPONENT_NAME = "FacetManager"; private final Module myModule; - private final FacetTypeRegistry myFacetTypeRegistry; private final FacetManagerModel myModel = new FacetManagerModel(); private boolean myInsideCommit = false; private final MessageBus myMessageBus; private boolean myModuleAdded; - public FacetManagerImpl(final Module module, MessageBus messageBus, final FacetTypeRegistry facetTypeRegistry) { + public FacetManagerImpl(final Module module, MessageBus messageBus) { myModule = module; myMessageBus = messageBus; - myFacetTypeRegistry = facetTypeRegistry; } @Override @@ -167,6 +165,8 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P } private void addFacets(final List facetStates, final Facet underlyingFacet, ModifiableFacetModel model) { + + FacetTypeRegistry registry = FacetTypeRegistry.getInstance(); for (FacetState child : facetStates) { final String typeId = child.getFacetType(); if (typeId == null) { @@ -174,7 +174,7 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P continue; } - final FacetType type = myFacetTypeRegistry.findFacetType(typeId); + final FacetType type = registry.findFacetType(typeId); if (type == null) { addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.unknown.facet.type.0", typeId), typeId); continue; @@ -190,7 +190,7 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P FacetType expectedUnderlyingType = null; FacetTypeId underlyingTypeId = type.getUnderlyingFacetType(); if (underlyingTypeId != null) { - expectedUnderlyingType = myFacetTypeRegistry.findFacetType(underlyingTypeId); + expectedUnderlyingType = registry.findFacetType(underlyingTypeId); } FacetType actualUnderlyingType = underlyingFacet != null ? underlyingFacet.getType() : null; if (expectedUnderlyingType != null) { diff --git a/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/text/PsiAwareTextEditorProvider.java b/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/text/PsiAwareTextEditorProvider.java index 217e6051a102..c28fea82162c 100644 --- a/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/text/PsiAwareTextEditorProvider.java +++ b/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/text/PsiAwareTextEditorProvider.java @@ -56,17 +56,19 @@ public class PsiAwareTextEditorProvider extends TextEditorProvider implements As LOG.error("Cannot open text editor for " + file); } CodeFoldingState state = null; - try { - Document document = FileDocumentManager.getInstance().getDocument(file); - if (document != null) { - state = CodeFoldingManager.getInstance(project).buildInitialFoldings(document); + if (!project.isDefault()) { // There's no CodeFoldingManager for default project (which is used in diff command-line application) + try { + Document document = FileDocumentManager.getInstance().getDocument(file); + if (document != null) { + state = CodeFoldingManager.getInstance(project).buildInitialFoldings(document); + } + } + catch (ProcessCanceledException e) { + throw e; + } + catch (Exception e) { + LOG.error("Error building initial foldings", e); } - } - catch (ProcessCanceledException e) { - throw e; - } - catch (Exception e) { - LOG.error("Error building initial foldings", e); } final CodeFoldingState finalState = state; return new Builder() { diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdaterImpl.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdaterImpl.java index bc8954816b1d..9b774b5262b2 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdaterImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdaterImpl.java @@ -20,7 +20,6 @@ package com.intellij.openapi.roots.impl; import com.intellij.ProjectTopics; -import com.intellij.concurrency.JobLauncher; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.ExtensionException; @@ -48,7 +47,6 @@ import com.intellij.openapi.vfs.newvfs.events.VFileMoveEvent; import com.intellij.psi.PsiManager; import com.intellij.psi.impl.PsiManagerEx; import com.intellij.psi.impl.file.impl.FileManagerImpl; -import com.intellij.util.Processor; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.indexing.FileBasedIndexProjectHandler; @@ -63,6 +61,7 @@ import java.util.Collections; import java.util.List; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.Future; public class PushedFilePropertiesUpdaterImpl extends PushedFilePropertiesUpdater { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.impl.PushedFilePropertiesUpdater"); @@ -290,18 +289,44 @@ public class PushedFilePropertiesUpdaterImpl extends PushedFilePropertiesUpdater } if (ourConcurrentlyFlag.get() == Boolean.TRUE && Registry.is("idea.concurrent.scanning.files.to.index")) { - JobLauncher.getInstance().invokeConcurrentlyUnderProgress(tasks, null, false, new Processor() { - @Override - public boolean process(Runnable runnable) { - runnable.run(); - return true; - } - }); + invoke2xConcurrently(tasks); } else { for(Runnable r:tasks) r.run(); } } + public static void invoke2xConcurrently(final List tasks) { + final ConcurrentLinkedQueue tasksQueue = new ConcurrentLinkedQueue(tasks); + Future result = null; + if (tasks.size() > 1) { + result = ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + @Override + public void run() { + Runnable runnable; + while ((runnable = tasksQueue.poll()) != null) runnable.run(); + } + }); + } + + Runnable runnable; + while ((runnable = tasksQueue.poll()) != null) runnable.run(); + + if (result != null) { + try { + result.get(); + } catch (Exception ex) { + LOG.error(ex); + } + } + //JobLauncher.getInstance().invokeConcurrently(tasks, null, false, false, new Processor() { + // @Override + // public boolean process(Runnable runnable) { + // runnable.run(); + // return true; + // } + //}); + } + public static final ThreadLocal ourConcurrentlyFlag = new ThreadLocal(); private void applyPushersToFile(final VirtualFile fileOrDir, final FilePropertyPusher[] pushers, final Object[] moduleValues) { diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java index dd3fe289e639..4ee3bc4c0dcf 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -17,7 +17,6 @@ package com.intellij.util.indexing; import com.intellij.AppTopics; -import com.intellij.concurrency.JobLauncher; import com.intellij.history.LocalHistory; import com.intellij.ide.plugins.PluginManager; import com.intellij.ide.util.DelegatingProgressIndicator; @@ -47,6 +46,7 @@ import com.intellij.openapi.progress.Task; import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator; import com.intellij.openapi.project.*; import com.intellij.openapi.roots.*; +import com.intellij.openapi.roots.impl.PushedFilePropertiesUpdaterImpl; import com.intellij.openapi.util.*; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.registry.Registry; @@ -2658,13 +2658,7 @@ public class FileBasedIndexImpl extends FileBasedIndex { } if (ourConcurrentlyFlag.get() == Boolean.TRUE && Registry.is("idea.concurrent.scanning.files.to.index")) { - JobLauncher.getInstance().invokeConcurrentlyUnderProgress(tasks, indicator, false, false, new Processor() { - @Override - public boolean process(Runnable runnable) { - runnable.run(); - return true; - } - }); + PushedFilePropertiesUpdaterImpl.invoke2xConcurrently(tasks); } else { for(Runnable r:tasks) r.run(); } diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java index 7f220dea8c60..9ff38ff046a5 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java @@ -18,6 +18,8 @@ package com.intellij.openapi.actionSystem.ex; import com.intellij.icons.AllIcons; import com.intellij.ide.DataManager; import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.keymap.KeymapUtil; import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupFactory; @@ -218,13 +220,13 @@ public abstract class ComboBoxAction extends AnAction implements CustomComponent @Override public void run() { // give button chance to handle action listener - UIUtil.invokeLaterIfNeeded(new Runnable() { + ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { myForcePressed = false; myPopup = null; } - }); + }, ModalityState.any()); repaint(); fireStateChanged(); } diff --git a/platform/platform-api/src/com/intellij/ui/components/JBPanel.java b/platform/platform-api/src/com/intellij/ui/components/JBPanel.java index c686ee197d39..c7520bba78e5 100644 --- a/platform/platform-api/src/com/intellij/ui/components/JBPanel.java +++ b/platform/platform-api/src/com/intellij/ui/components/JBPanel.java @@ -15,23 +15,13 @@ */ package com.intellij.ui.components; -import com.intellij.openapi.actionSystem.DataKey; -import com.intellij.openapi.actionSystem.DataSink; -import com.intellij.openapi.actionSystem.TypeSafeDataProvider; -import com.intellij.util.IconUtil; -import org.jetbrains.annotations.Nullable; - import javax.swing.*; import java.awt.*; /** * @author Konstantin Bulenkov */ -public class JBPanel extends JPanel implements TypeSafeDataProvider { - @Nullable - private Icon myBackgroundImage; - @Nullable - private Icon myCenterImage; +public class JBPanel extends JPanel { public JBPanel(LayoutManager layout, boolean isDoubleBuffered) { super(layout, isDoubleBuffered); @@ -49,56 +39,4 @@ public class JBPanel extends JPanel implements TypeSafeDataProvider { super(); } - @Nullable - public Icon getBackgroundImage() { - return myBackgroundImage; - } - - public void setBackgroundImage(@Nullable Icon backgroundImage) { - myBackgroundImage = backgroundImage; - } - - @Nullable - public Icon getCenterImage() { - return myCenterImage; - } - - public void setCenterImage(@Nullable Icon centerImage) { - myCenterImage = centerImage; - } - - @Override - protected void paintComponent(Graphics g) { - Icon image = getBackgroundImage(); - if (image != null) { - final int w = image.getIconWidth(); - final int h = image.getIconHeight(); - int x = 0; - int y = 0; - while (w > 0 && x < getWidth()) { - while (h > 0 && y < getHeight()) { - image.paintIcon(this, g, x, y); - y+=h; - } - y=0; - x+=w; - } - } else { - super.paintComponent(g); - } - - paintCenterImage(g); - } - - protected void paintCenterImage(Graphics g) { - Icon centerImage = getCenterImage(); - if (centerImage != null) { - IconUtil.paintInCenterOf(this, g, centerImage); - } - } - - @Override - public void calcData(DataKey key, DataSink sink) { - // override this to provide additional context - } } diff --git a/platform/platform-api/src/com/intellij/util/io/HttpRequests.java b/platform/platform-api/src/com/intellij/util/io/HttpRequests.java index 72e2737eba25..b6f97f3d46f0 100644 --- a/platform/platform-api/src/com/intellij/util/io/HttpRequests.java +++ b/platform/platform-api/src/com/intellij/util/io/HttpRequests.java @@ -282,18 +282,12 @@ public final class HttpRequests { if (connection instanceof HttpURLConnection) { int responseCode = ((HttpURLConnection)connection).getResponseCode(); - - if (responseCode != HttpURLConnection.HTTP_OK && responseCode != HttpURLConnection.HTTP_NOT_MODIFIED) { + if (responseCode == HttpURLConnection.HTTP_MOVED_PERM || responseCode == HttpURLConnection.HTTP_MOVED_TEMP) { ((HttpURLConnection)connection).disconnect(); - - if (responseCode == HttpURLConnection.HTTP_MOVED_PERM || responseCode == HttpURLConnection.HTTP_MOVED_TEMP) { - url = connection.getHeaderField("Location"); - if (url != null) { - continue; - } + url = connection.getHeaderField("Location"); + if (url != null) { + continue; } - - throw new IOException(IdeBundle.message("error.connection.failed.with.http.code.N", responseCode)); } } diff --git a/platform/platform-impl/src/com/intellij/ide/diff/VirtualFileDiffElement.java b/platform/platform-impl/src/com/intellij/ide/diff/VirtualFileDiffElement.java index 136271b8c8c9..b697be14276f 100644 --- a/platform/platform-impl/src/com/intellij/ide/diff/VirtualFileDiffElement.java +++ b/platform/platform-impl/src/com/intellij/ide/diff/VirtualFileDiffElement.java @@ -96,7 +96,7 @@ public class VirtualFileDiffElement extends DiffElement { @Override @Nullable public OpenFileDescriptor getOpenFileDescriptor(@Nullable Project project) { - if (project == null) return null; + if (project == null || project.isDefault()) return null; return new OpenFileDescriptor(project, myFile); } diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/InstallPluginAction.java b/platform/platform-impl/src/com/intellij/ide/plugins/InstallPluginAction.java index 1c83d63642be..f0b391e5fcdd 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/InstallPluginAction.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/InstallPluginAction.java @@ -176,7 +176,8 @@ public class InstallPluginAction extends AnAction implements DumbAware { ourInstallingNodes.removeAll(list); } }; - PluginManagerMain.downloadPlugins(list, myHost.getPluginsModel().getAllPlugins(), onInstallRunnable, cleanupRunnable); + final List plugins = myHost.getPluginsModel().getAllPlugins(); + PluginManagerMain.downloadPlugins(list, PluginManagerMain.mapToPluginIds(plugins), onInstallRunnable, cleanupRunnable); } catch (final IOException e1) { ourInstallingNodes.removeAll(list); diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/PluginInstaller.java b/platform/platform-impl/src/com/intellij/ide/plugins/PluginInstaller.java index 4f235f12a85b..5f5fe69cd0f1 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/PluginInstaller.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/PluginInstaller.java @@ -56,7 +56,7 @@ public class PluginInstaller { private PluginInstaller() { } public static boolean prepareToInstall(List pluginsToInstall, - List allPlugins, + List allPlugins, @NotNull ProgressIndicator indicator) { updateUrls(pluginsToInstall, indicator); Set dependant = new THashSet(); @@ -108,7 +108,7 @@ public class PluginInstaller { } private static boolean prepareToInstall(List pluginsToInstall, - List allPlugins, + List allPlugins, Set installedDependant, @NotNull ProgressIndicator indicator) { List pluginIds = new SmartList(); @@ -134,7 +134,7 @@ public class PluginInstaller { private static boolean prepareToInstall(PluginNode pluginNode, List pluginIds, - List allPlugins, + List allPlugins, Set installedDependant, @NotNull ProgressIndicator indicator) throws IOException { installedDependant.add(pluginNode); @@ -236,13 +236,8 @@ public class PluginInstaller { return true; } - private static boolean isPluginInRepo(PluginId depPluginId, List allPlugins) { - for (IdeaPluginDescriptor plugin : allPlugins) { - if (plugin.getPluginId().equals(depPluginId)) { - return true; - } - } - return false; + private static boolean isPluginInRepo(PluginId depPluginId, List allPlugins) { + return allPlugins.contains(depPluginId); } public static void prepareToUninstall(PluginId pluginId) throws IOException { diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManagerMain.java b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManagerMain.java index e4c1a663ff0e..7e230c8c5ec5 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManagerMain.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManagerMain.java @@ -49,6 +49,7 @@ import com.intellij.ui.*; import com.intellij.ui.border.CustomLineBorder; import com.intellij.ui.components.JBLabel; import com.intellij.ui.speedSearch.SpeedSearchSupply; +import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; @@ -229,6 +230,16 @@ public abstract class PluginManagerMain implements Disposable { return pluginTable; } + @NotNull + public static List mapToPluginIds(List plugins) { + return ContainerUtil.map(plugins, new Function() { + @Override + public PluginId fun(IdeaPluginDescriptor descriptor) { + return descriptor.getPluginId(); + } + }); + } + private static String getTextPrefix() { final int fontSize = JBUI.scale(12); final int m1 = JBUI.scale(2); @@ -394,7 +405,7 @@ public abstract class PluginManagerMain implements Disposable { } public static boolean downloadPlugins(final List plugins, - final List allPlugins, + final List allPlugins, final Runnable onSuccess, @Nullable final Runnable cleanup) throws IOException { final boolean[] result = new boolean[1]; diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java index 1dcc9a8cf277..2ce1b5fcfa2f 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java @@ -164,7 +164,7 @@ public class ApplicationStatisticsPersistenceComponent extends ApplicationStatis public String fun(UsageDescriptor usageDescriptor) { final String key = usageDescriptor.getKey(); final int value = usageDescriptor.getValue(); - return value > 1 ? key + "=" + value : key; + return value != 1 ? key + "=" + value : key; } }, TOKENIZER); } diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/ex/DiffPanelOptions.java b/platform/platform-impl/src/com/intellij/openapi/diff/ex/DiffPanelOptions.java index d3911acac596..5f1baa1a8dff 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/ex/DiffPanelOptions.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/ex/DiffPanelOptions.java @@ -59,7 +59,7 @@ public class DiffPanelOptions { } public void showSource(@Nullable OpenFileDescriptor descriptor) { - if (descriptor == null || myDiffPanel.getProject() == null) return; + if (descriptor == null || myDiffPanel.getProject() == null || myDiffPanel.getProject().isDefault()) return; myShowSourcePolicy.showSource(descriptor, myDiffPanel); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorComponentImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorComponentImpl.java index c1179c5bd488..a753b8e35474 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorComponentImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorComponentImpl.java @@ -36,6 +36,7 @@ import com.intellij.openapi.ui.Queryable; import com.intellij.openapi.ui.TypingTarget; import com.intellij.openapi.util.ActionCallback; import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.wm.impl.IdeBackgroundUtil; import com.intellij.ui.Grayer; import com.intellij.ui.components.Magnificator; import com.intellij.util.ui.UIUtil; @@ -172,6 +173,8 @@ public class EditorComponentImpl extends JComponent implements Scrollable, DataP UIUtil.setupComposite((Graphics2D)g); UISettings.setupAntialiasing(g); myEditor.paint((Graphics2D)g); + + IdeBackgroundUtil.paintEditorBackground(g, this); } finally { myApplication.editorPaintFinish(); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java index 1539a8715a53..961776caac2d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java @@ -48,6 +48,7 @@ import com.intellij.openapi.ui.popup.Balloon; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.wm.impl.IdeBackgroundUtil; import com.intellij.ui.HintHint; import com.intellij.ui.JBColor; import com.intellij.ui.awt.RelativePoint; @@ -229,6 +230,8 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse } g2.setTransform(old); + + IdeBackgroundUtil.paintEditorBackground(g, this); } finally { ((ApplicationImpl)ApplicationManager.getApplication()).editorPaintFinish(); diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorsSplitters.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorsSplitters.java index 95653ec576ce..961a196287b9 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorsSplitters.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorsSplitters.java @@ -41,6 +41,7 @@ import com.intellij.openapi.wm.IdeFrame; import com.intellij.openapi.wm.ex.IdeFocusTraversalPolicy; import com.intellij.openapi.wm.ex.WindowManagerEx; import com.intellij.openapi.wm.impl.FrameTitleBuilder; +import com.intellij.openapi.wm.impl.IdeBackgroundUtil; import com.intellij.openapi.wm.impl.IdePanePanel; import com.intellij.ui.JBColor; import com.intellij.ui.OnePixelSplitter; @@ -155,14 +156,12 @@ public class EditorsSplitters extends IdePanePanel implements UISettingsListener @Override protected void paintComponent(Graphics g) { - super.paintComponent(g); - - if (myCurrentWindow == null || myCurrentWindow.getFiles().length == 0) { - g.setColor(UIUtil.isUnderDarcula()? UIUtil.getBorderColor() : new Color(0, 0, 0, 50)); - g.drawLine(0, 0, getWidth(), 0); - } - if (showEmptyText()) { + super.paintComponent(g); + g.setColor(UIUtil.isUnderDarcula() ? UIUtil.getBorderColor() : new Color(0, 0, 0, 50)); + g.drawLine(0, 0, getWidth(), 0); + + IdeBackgroundUtil.paintFrameBackground(g, this); ourPainter.paintEmptyText(this, g); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/TextEditorComponent.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/TextEditorComponent.java index a476264b8285..d24b810b3ca4 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/TextEditorComponent.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/TextEditorComponent.java @@ -133,7 +133,9 @@ class TextEditorComponent extends JBLoadingPanel implements DataProvider { */ void dispose(){ myDocument.removeDocumentListener(myDocumentListener); - EditorHistoryManager.getInstance(myProject).updateHistoryEntry(myFile, false); + if (!myProject.isDefault()) { // There's no EditorHistoryManager for default project (which is used in diff command-line application) + EditorHistoryManager.getInstance(myProject).updateHistoryEntry(myFile, false); + } disposeEditor(myEditor); myConnection.disconnect(); @@ -276,7 +278,8 @@ class TextEditorComponent extends JBLoadingPanel implements DataProvider { final Editor e = validateCurrentEditor(); if (e == null) return null; - if (!myProject.isDisposed()) { + // There's no FileEditorManager for default project (which is used in diff command-line application) + if (!myProject.isDisposed() && !myProject.isDefault()) { final Object o = FileEditorManager.getInstance(myProject).getData(dataId, e, e.getCaretModel().getCurrentCaret()); if (o != null) return o; } diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginAdvertiserEditorNotificationProvider.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginAdvertiserEditorNotificationProvider.java index 9d7d8d627b90..dd1755de7129 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginAdvertiserEditorNotificationProvider.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginAdvertiserEditorNotificationProvider.java @@ -16,8 +16,10 @@ package com.intellij.openapi.updateSettings.impl.pluginsAdvertisement; import com.intellij.ide.plugins.IdeaPluginDescriptor; +import com.intellij.ide.plugins.PluginManagerMain; import com.intellij.ide.plugins.RepositoryHelper; import com.intellij.ide.util.PropertiesComponent; +import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileTypes.FileTypeFactory; import com.intellij.openapi.fileTypes.PlainTextFileType; @@ -30,6 +32,9 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.EditorNotificationPanel; import com.intellij.ui.EditorNotifications; +import com.intellij.util.ContentsUtil; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -132,7 +137,9 @@ public class PluginAdvertiserEditorNotificationProvider extends EditorNotificati @Override public void onSuccess() { final PluginsAdvertiserDialog advertiserDialog = - new PluginsAdvertiserDialog(null, myPlugins.toArray(new PluginDownloader[myPlugins.size()]), myAllPlugins); + new PluginsAdvertiserDialog(null, + myPlugins.toArray(new PluginDownloader[myPlugins.size()]), + PluginManagerMain.mapToPluginIds(myAllPlugins)); if (advertiserDialog.showAndGet()) { myEnabledExtensions.add(extension); myNotifications.updateAllNotifications(); diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginsAdvertiser.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginsAdvertiser.java index 07208585f4cb..eaaa9437d668 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginsAdvertiser.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginsAdvertiser.java @@ -41,6 +41,7 @@ import com.intellij.reference.SoftReference; import com.intellij.ui.EditorNotifications; import com.intellij.util.Function; import com.intellij.util.PlatformUtils; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.LinkedMultiMap; import com.intellij.util.containers.MultiMap; import com.intellij.util.io.HttpRequests; @@ -322,7 +323,7 @@ public class PluginsAdvertiser implements StartupActivity { } if (message != null) { - final ConfigurePluginsListener notificationListener = new ConfigurePluginsListener(unknownFeatures, project, myAllPlugins, myPlugins, myDisabledPlugins); + final ConfigurePluginsListener notificationListener = new ConfigurePluginsListener(unknownFeatures, project, PluginManagerMain.mapToPluginIds(myAllPlugins), myPlugins, myDisabledPlugins); NOTIFICATION_GROUP.createNotification(DISPLAY_ID, message, NotificationType.INFORMATION, notificationListener).notify(project); } } @@ -449,13 +450,13 @@ public class PluginsAdvertiser implements StartupActivity { private static class ConfigurePluginsListener implements NotificationListener { private final Set myUnknownFeatures; private final Project myProject; - private final List myAllPlugins; + private final List myAllPlugins; private final Set myPlugins; private final Map myDisabledPlugins; public ConfigurePluginsListener(Set unknownFeatures, Project project, - List allPlugins, + List allPlugins, Set plugins, Map disabledPlugins) { myUnknownFeatures = unknownFeatures; diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginsAdvertiserDialog.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginsAdvertiserDialog.java index 7008ad7c0aa6..eb655d5a240f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginsAdvertiserDialog.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginsAdvertiserDialog.java @@ -17,11 +17,14 @@ package com.intellij.openapi.updateSettings.impl.pluginsAdvertisement; import com.intellij.ide.plugins.*; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.updateSettings.impl.DetectedPluginsPanel; import com.intellij.openapi.updateSettings.impl.PluginDownloader; import com.intellij.ui.TableUtil; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -36,10 +39,10 @@ public class PluginsAdvertiserDialog extends DialogWrapper { @Nullable private final Project myProject; private final PluginDownloader[] myUploadedPlugins; - private final List myAllPlugins; + private final List myAllPlugins; private final Set mySkippedPlugins = new HashSet(); - PluginsAdvertiserDialog(@Nullable Project project, PluginDownloader[] plugins, List allPlugins) { + PluginsAdvertiserDialog(@Nullable Project project, PluginDownloader[] plugins, List allPlugins) { super(project); myProject = project; Arrays.sort(plugins, new Comparator() { diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/VfsImplUtil.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/VfsImplUtil.java index a46a221bbe58..77825b188d01 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/VfsImplUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/VfsImplUtil.java @@ -23,14 +23,17 @@ import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.ZipFileCache; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.*; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VFileProperty; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.impl.ArchiveHandler; import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.openapi.vfs.newvfs.events.VFileMoveEvent; import com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent; +import com.intellij.util.Consumer; import com.intellij.util.Function; -import com.intellij.util.Processor; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -206,15 +209,14 @@ public class VfsImplUtil { ourHandlers.put(localPath, record); final String finalRootPath = localPath; - forEachDirectoryComponent(localPath, new Processor() { + forEachDirectoryComponent(localPath, new Consumer() { @Override - public boolean process(String containingDirectoryPath) { + public void consume(String containingDirectoryPath) { Set handlers = ourDominatorsMap.get(containingDirectoryPath); if (handlers == null) { ourDominatorsMap.put(containingDirectoryPath, handlers = ContainerUtil.newTroveSet()); } handlers.add(finalRootPath); - return true; } }); refresh = true; @@ -236,11 +238,11 @@ public class VfsImplUtil { return t; } - private static void forEachDirectoryComponent(String rootPath, Processor processor) { + private static void forEachDirectoryComponent(String rootPath, Consumer consumer) { int index = rootPath.lastIndexOf('/'); while (index > 0) { String containingDirectoryPath = rootPath.substring(0, index); - if (!processor.process(containingDirectoryPath)) return; + consumer.consume(containingDirectoryPath); index = rootPath.lastIndexOf('/', index - 1); } } @@ -301,14 +303,13 @@ public class VfsImplUtil { public static InvalidationState invalidate(@Nullable InvalidationState state, final String path) { Pair handlerPair = ourHandlers.remove(path); if (handlerPair != null) { - forEachDirectoryComponent(path, new Processor() { + forEachDirectoryComponent(path, new Consumer() { @Override - public boolean process(String containingDirectoryPath) { + public void consume(String containingDirectoryPath) { Set handlers = ourDominatorsMap.get(containingDirectoryPath); if (handlers != null && handlers.remove(path) && handlers.size() == 0) { ourDominatorsMap.remove(containingDirectoryPath); } - return true; } }); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeBackgroundUtil.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeBackgroundUtil.java new file mode 100644 index 000000000000..73beda12f381 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeBackgroundUtil.java @@ -0,0 +1,73 @@ +/* + * Copyright 2000-2015 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.openapi.wm.impl; + +import com.intellij.openapi.application.ex.ApplicationInfoEx; +import com.intellij.util.ImageLoader; +import com.intellij.util.ui.JBUI; +import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.awt.*; +import java.net.URL; + +/** + * @author gregsh + */ +public class IdeBackgroundUtil { + + public static void paintEditorBackground(@NotNull Graphics g, @NotNull JComponent component) { + JRootPane rootPane = component.getRootPane(); + Component glassPane = rootPane == null ? null : rootPane.getGlassPane(); + if (glassPane instanceof IdeGlassPaneImpl) { + ((IdeGlassPaneImpl)glassPane).getNamedPainters("editor").paint(g, component); + } + } + + public static void paintFrameBackground(@NotNull Graphics g, @NotNull JComponent component) { + JRootPane rootPane = component.getRootPane(); + Component glassPane = rootPane == null ? null : rootPane.getGlassPane(); + if (glassPane instanceof IdeGlassPaneImpl) { + ((IdeGlassPaneImpl)glassPane).getNamedPainters("ide").paint(g, component); + } + } + + public static void initEditorPainters(@NotNull PaintersHelper painters) { + painters.addPainter(PaintersHelper.newWallpaperPainter("idea.wallpaper.editor"), null); + } + + public static void initFramePainters(@NotNull PaintersHelper painters) { + painters.addPainter(PaintersHelper.newWallpaperPainter("idea.wallpaper.ide"), null); + + ApplicationInfoEx appInfo = ApplicationInfoEx.getInstanceEx(); + String path = UIUtil.isUnderDarcula()? appInfo.getEditorBackgroundImageUrl() : null; + URL url = path == null ? null : appInfo.getClass().getResource(path); + Image centerImage = url == null ? null : ImageLoader.loadFromUrl(url); + + if (centerImage != null) { + painters.addPainter(PaintersHelper.newImagePainter(centerImage, PaintersHelper.FillType.TOP_CENTER, 1.0f, JBUI.insets(5, 0, 0, 0)), null); + } + } + + @Nullable + public static Color getIdeBackgroundColor() { + Color result = UIUtil.getSlightlyDarkerColor(UIUtil.getPanelBackground()); + return UIUtil.isUnderDarcula() ? new Color(40, 40, 41) : UIUtil.getSlightlyDarkerColor(UIUtil.getSlightlyDarkerColor(result)); + } + +} diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneImpl.java index ab518964a4ec..0545f7d90f42 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneImpl.java @@ -28,9 +28,11 @@ import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Weighted; import com.intellij.openapi.wm.IdeGlassPane; import com.intellij.openapi.wm.IdeGlassPaneUtil; +import com.intellij.util.containers.FactoryMap; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.MenuDragMouseEvent; @@ -40,7 +42,7 @@ import java.awt.event.*; import java.util.*; import java.util.List; -public class IdeGlassPaneImpl extends JPanel implements IdeGlassPaneEx, IdeEventQueue.EventDispatcher, Painter.Listener { +public class IdeGlassPaneImpl extends JPanel implements IdeGlassPaneEx, IdeEventQueue.EventDispatcher { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.wm.impl.IdeGlassPaneImpl"); @@ -61,10 +63,14 @@ public class IdeGlassPaneImpl extends JPanel implements IdeGlassPaneEx, IdeEvent }); private final JRootPane myRootPane; - private final Set myPainters = new LinkedHashSet(); - private final Map myPainter2Component = new LinkedHashMap(); + private final Map myNamedPainters = new FactoryMap() { + @Nullable + @Override + protected PaintersHelper create(String key) { + return new PaintersHelper(IdeGlassPaneImpl.this); + } + }; - private boolean myPaintingActive; private boolean myPreprocessorActive; private final Map myListener2Cursor = new LinkedHashMap(); @@ -85,6 +91,11 @@ public class IdeGlassPaneImpl extends JPanel implements IdeGlassPaneEx, IdeEvent setVisible(false); setLayout(null); + if (myRootPane instanceof IdeRootPane) { + IdeBackgroundUtil.initFramePainters(getNamedPainters("ide")); + IdeBackgroundUtil.initEditorPainters(getNamedPainters("editor")); + } + myFocusProxy.setOpaque(false); myFocusProxy.setPreferredSize(JBUI.emptySize()); myFocusProxy.setFocusable(true); @@ -486,12 +497,6 @@ public class IdeGlassPaneImpl extends JPanel implements IdeGlassPaneEx, IdeEvent } private void deactivateIfNeeded() { - if (myPaintingActive) { - if (myPainters.isEmpty() && getComponentCount() == 0) { - myPaintingActive = false; - } - } - if (myPreprocessorActive && myMouseListeners.isEmpty()) { myPreprocessorActive = false; } @@ -500,12 +505,6 @@ public class IdeGlassPaneImpl extends JPanel implements IdeGlassPaneEx, IdeEvent } private void activateIfNeeded() { - if (!myPaintingActive) { - if (!myPainters.isEmpty() || getComponentCount() > 0) { - myPaintingActive = true; - } - } - if (!myPreprocessorActive && !myMouseListeners.isEmpty()) { myPreprocessorActive = true; } @@ -515,9 +514,10 @@ public class IdeGlassPaneImpl extends JPanel implements IdeGlassPaneEx, IdeEvent private void applyActivationState() { boolean wasVisible = isVisible(); + boolean hasWork = getPainters().hasPainters() || getComponentCount() > 0; - if (wasVisible != myPaintingActive) { - setVisible(myPaintingActive); + if (wasVisible != hasWork) { + setVisible(hasWork); } IdeEventQueue queue = IdeEventQueue.getInstance(); @@ -534,10 +534,18 @@ public class IdeGlassPaneImpl extends JPanel implements IdeGlassPaneEx, IdeEvent } } + @NotNull + PaintersHelper getNamedPainters(@NotNull String name) { + return myNamedPainters.get(name); + } + + @NotNull + private PaintersHelper getPainters() { + return getNamedPainters("glass"); + } + public void addPainter(final Component component, final Painter painter, final Disposable parent) { - myPainters.add(painter); - myPainter2Component.put(painter, component == null ? this : component); - painter.addListener(this); + getPainters().addPainter(painter, component); activateIfNeeded(); Disposer.register(parent, new Disposable() { public void dispose() { @@ -551,9 +559,7 @@ public class IdeGlassPaneImpl extends JPanel implements IdeGlassPaneEx, IdeEvent } public void removePainter(final Painter painter) { - myPainters.remove(painter); - myPainter2Component.remove(painter); - painter.removeListener(this); + getPainters().removePainter(painter); deactivateIfNeeded(); } @@ -594,28 +600,7 @@ public class IdeGlassPaneImpl extends JPanel implements IdeGlassPaneEx, IdeEvent } protected void paintComponent(final Graphics g) { - if (myPainters.isEmpty()) return; - - Graphics2D g2d = (Graphics2D)g; - for (Painter painter : myPainters) { - final Rectangle clip = g.getClipBounds(); - - final Component component = myPainter2Component.get(painter); - if (component.getParent() == null) continue; - final Rectangle componentBounds = SwingUtilities.convertRectangle(component.getParent(), component.getBounds(), this); - - if (!painter.needsRepaint()) { - continue; - } - - if (clip.contains(componentBounds) || clip.intersects(componentBounds)) { - final Point targetPoint = SwingUtilities.convertPoint(this, 0, 0, component); - final Rectangle targetRect = new Rectangle(targetPoint, component.getSize()); - g2d.translate(-targetRect.x, -targetRect.y); - painter.paint(component, g2d); - g2d.translate(targetRect.x, targetRect.y); - } - } + getPainters().paint(g); } @Override @@ -623,22 +608,6 @@ public class IdeGlassPaneImpl extends JPanel implements IdeGlassPaneEx, IdeEvent super.paintChildren(g); } - public boolean hasPainters() { - return !myPainters.isEmpty(); - } - - public void onNeedsRepaint(final Painter painter, final JComponent dirtyComponent) { - if (dirtyComponent != null && dirtyComponent.isShowing()) { - final Rectangle rec = SwingUtilities.convertRectangle(dirtyComponent, dirtyComponent.getBounds(), this); - if (rec != null) { - repaint(rec); - return; - } - } - - repaint(); - } - public Component getTargetComponentFor(MouseEvent e) { Component candidate = findComponent(e, myRootPane.getLayeredPane()); if (candidate != null) return candidate; @@ -654,7 +623,7 @@ public class IdeGlassPaneImpl extends JPanel implements IdeGlassPaneEx, IdeEvent @Override public boolean isOptimizedDrawingEnabled() { - return !hasPainters() && super.isOptimizedDrawingEnabled(); + return !getPainters().hasPainters() && super.isOptimizedDrawingEnabled(); } @Override diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdePanePanel.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdePanePanel.java index d953b4df62e2..12fdc63a104c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdePanePanel.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdePanePanel.java @@ -15,66 +15,18 @@ */ package com.intellij.openapi.wm.impl; -import com.intellij.openapi.application.ex.ApplicationInfoEx; -import com.intellij.openapi.util.IconLoader; import com.intellij.ui.components.JBPanel; -import com.intellij.util.ui.UIUtil; -import org.jetbrains.annotations.Nullable; -import javax.swing.*; import java.awt.*; public class IdePanePanel extends JBPanel { + public IdePanePanel(LayoutManager layout) { super(layout); } - @Nullable - @Override - public Icon getCenterImage() { - return getIdeBackgroundLogo(); - } - - @Nullable - @Override - public Icon getBackgroundImage() { - return getIdeBackgroundImage(); - } - @Override public Color getBackground() { - return getIdeBackgroundColor(); - } - - @Nullable - public static Icon getIdeBackgroundImage() { - return null; - } - - @Nullable - public static Icon getIdeBackgroundLogo() { - if (UIUtil.isUnderDarcula()) { - String url = ApplicationInfoEx.getInstanceEx().getEditorBackgroundImageUrl(); - if (url != null) { - return IconLoader.getIcon(url); - } - } - return null; - } - - @Override - protected void paintCenterImage(Graphics g) { - final Icon image = getCenterImage(); - if (image != null) { - final int x = (getWidth() - image.getIconWidth()) / 2; - final int y = ((getHeight() - 222) / 2 - image.getIconHeight()) / 2; - image.paintIcon(this, g, x, y); - } - } - - @Nullable - public static Color getIdeBackgroundColor() { - Color result = UIUtil.getSlightlyDarkerColor(UIUtil.getPanelBackground()); - return UIUtil.isUnderDarcula() ? new Color(40, 40, 41) : UIUtil.getSlightlyDarkerColor(UIUtil.getSlightlyDarkerColor(result)); + return IdeBackgroundUtil.getIdeBackgroundColor(); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeRootPane.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeRootPane.java index 93de35dcb37d..cc77e8faf586 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeRootPane.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeRootPane.java @@ -324,7 +324,7 @@ public class IdeRootPane extends JRootPane implements UISettingsListener { } public boolean isOptimizedDrawingEnabled() { - return !myGlassPane.hasPainters() && myGlassPane.getComponentCount() == 0; + return myGlassPane.isVisible(); } public ToolWindowsPane getToolWindowsPane() { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/PaintersHelper.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/PaintersHelper.java new file mode 100644 index 000000000000..f379b484696b --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/PaintersHelper.java @@ -0,0 +1,234 @@ +/* + * Copyright 2000-2015 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.openapi.wm.impl; + +import com.intellij.openapi.application.PathManager; +import com.intellij.openapi.ui.AbstractPainter; +import com.intellij.openapi.ui.GraphicsConfig; +import com.intellij.openapi.ui.Painter; +import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.VfsUtilCore; +import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.ui.JBUI; +import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.imageio.ImageIO; +import javax.swing.*; +import java.awt.*; +import java.net.URL; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +final class PaintersHelper implements Painter.Listener { + private final Set myPainters = ContainerUtil.newLinkedHashSet(); + private final Map myPainter2Component = ContainerUtil.newLinkedHashMap(); + + private final JComponent myRootComponent; + + public PaintersHelper(@NotNull JComponent component) { + myRootComponent = component; + } + + public boolean hasPainters() { + return !myPainters.isEmpty(); + } + + public void addPainter(@NotNull Painter painter, @Nullable Component component) { + myPainters.add(painter); + myPainter2Component.put(painter, component == null ? myRootComponent : component); + painter.addListener(this); + } + + public void removePainter(@NotNull Painter painter) { + painter.removeListener(this); + myPainters.remove(painter); + myPainter2Component.remove(painter); + } + + public void clear() { + for (Painter painter : myPainters) { + painter.removeListener(this); + } + myPainters.clear(); + myPainter2Component.clear(); + } + + public void paint(Graphics g) { + paint(g, myRootComponent); + } + + public void paint(Graphics g, JComponent current) { + if (myPainters.isEmpty()) return; + + Graphics2D g2d = (Graphics2D)g; + for (Painter painter : myPainters) { + Rectangle clip = g.getClipBounds(); + + Component component = myPainter2Component.get(painter); + if (component.getParent() == null) continue; + Rectangle componentBounds = SwingUtilities.convertRectangle(component.getParent(), component.getBounds(), current); + + if (!painter.needsRepaint()) { + continue; + } + + if (clip.contains(componentBounds) || clip.intersects(componentBounds)) { + Point targetPoint = SwingUtilities.convertPoint(current, 0, 0, component); + Rectangle targetRect = new Rectangle(targetPoint, component.getSize()); + g2d.setClip(clip.intersection(componentBounds)); + g2d.translate(-targetRect.x, -targetRect.y); + painter.paint(component, g2d); + g2d.translate(targetRect.x, targetRect.y); + } + } + + } + + @Override + public void onNeedsRepaint(Painter painter, JComponent dirtyComponent) { + if (dirtyComponent != null && dirtyComponent.isShowing()) { + Rectangle rec = SwingUtilities.convertRectangle(dirtyComponent, dirtyComponent.getBounds(), myRootComponent); + myRootComponent.repaint(rec); + } + else { + myRootComponent.repaint(); + } + } + + public enum FillType { + BG_CENTER, TILE, STRETCH, + CENTER, TOP_CENTER, BOTTOM_CENTER, + TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT + } + + public static AbstractPainter newWallpaperPainter(final String propertyName) { + return new ImagePainter() { + Image image; + float alpha; + Insets insets; + FillType fillType; + + String current; + + @Override + public void executePaint(Component component, Graphics2D g) { + String value = StringUtil.notNullize(System.getProperty(propertyName), propertyName + ".png"); + if (!Comparing.equal(value, current)) { + current = value; + image = scaled = null; + insets = JBUI.emptyInsets(); + String[] parts = value.split(","); + try { + alpha = StringUtil.parseInt(parts.length > 1 ? parts[1]: "", 10) / 100f; + try { + fillType = FillType.valueOf(parts.length > 2 ? parts[2].toUpperCase(Locale.ENGLISH) : ""); + } + catch (IllegalArgumentException e) { + fillType = FillType.STRETCH; + } + String url = parts[0].contains("://")? parts[0] : + VfsUtilCore.pathToUrl(parts[0].contains("/") ? parts[0] : PathManager.getConfigPath() + "/" + parts[0]); + + //todo ImageLoader.loadFromUrl(new URL(url)); fails with AlphaComposite for unknown reason + image = ImageIO.read(new URL(url)); + } + catch (Exception ignored) { + } + } + if (image == null) return; + executePaint(g, component, image, fillType, alpha, insets); + } + }; + } + + public static AbstractPainter newImagePainter(final Image image, final FillType fillType, final float alpha, final Insets insets) { + return new ImagePainter() { + @Override + public void executePaint(Component component, Graphics2D g) { + executePaint(g, component, image, fillType, alpha, insets); + } + }; + } + + private abstract static class ImagePainter extends AbstractPainter { + + Image scaled; + + @Override + public boolean needsRepaint() { return true; } + + public void executePaint(Graphics2D g, Component component, Image image, FillType fillType, float alpha, Insets insets) { + int cw0 = component.getWidth(); + int ch0 = component.getHeight(); + Insets i = JBUI.insets(insets.top * ch0 / 100, insets.left * cw0 / 100, insets.bottom * ch0 / 100, insets.right * cw0 / 100); + int cw = cw0 - i.left - i.right; + int ch = ch0 - i.top - i.bottom; + int w = image.getWidth(null); + int h = image.getHeight(null); + if (w <= 0 || h <= 0) return; + + if (fillType == FillType.STRETCH) { + if (scaled == null || scaled.getWidth(null) != cw || scaled.getHeight(null) != ch) { + scaled = image.getScaledInstance(cw, ch, Image.SCALE_SMOOTH); + } + } + + GraphicsConfig cfg = new GraphicsConfig(g).setAlpha(alpha); + g.setColor(g.getBackground()); + if (fillType == FillType.CENTER || fillType == FillType.BG_CENTER || + fillType == FillType.TOP_CENTER || fillType == FillType.BOTTOM_CENTER) { + int x = i.left + (cw - w) / 2; + int y = fillType == FillType.TOP_CENTER? i.top : + fillType == FillType.BOTTOM_CENTER? ch0 - i.bottom - h : + i.top + (ch - h) / 2; + UIUtil.drawImage(g, image, x, y, null); + if (fillType == FillType.BG_CENTER) { + g.setColor(component.getBackground()); + g.fillRect(0, 0, x, ch0); + g.fillRect(x, 0, w, h); + g.fillRect(x + w, 0, x, ch0); + g.fillRect(x, y + h, w, y); + } + } + else if (fillType == FillType.TOP_LEFT || fillType == FillType.TOP_RIGHT || + fillType == FillType.BOTTOM_LEFT || fillType == FillType.BOTTOM_RIGHT) { + int x = fillType == FillType.TOP_LEFT || fillType == FillType.BOTTOM_LEFT ? i.left : cw0 - i.right - w; + int y = fillType == FillType.TOP_LEFT || fillType == FillType.TOP_RIGHT ? i.top : ch0 - i.bottom - h; + UIUtil.drawImage(g, image, x, y, null); + } + else if (fillType == FillType.TILE) { + int x = i.left; + int y = i.top; + while (w > 0 && x < cw) { + while (h > 0 && y < ch) { + UIUtil.drawImage(g, image, x, y, null); + y += h; + } + y = 0; + x += w; + } + } + else if (fillType == FillType.STRETCH) { + UIUtil.drawImage(g, scaled, i.left, i.top, null); + } + cfg.restore(); + } + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowsPane.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowsPane.java index cd5612cd5ea4..d11fefbb8595 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowsPane.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowsPane.java @@ -1063,17 +1063,12 @@ public final class ToolWindowsPane extends JBLayeredPane implements Disposable { JComponent c = getComponentAt(anchor); if (c instanceof Splitter) { Splitter splitter = (Splitter)c; - if (myInfo.isSplit()) { - InternalDecorator component = (InternalDecorator)splitter.getFirstComponent(); - if (component != null) { + final InternalDecorator component = + myInfo.isSplit() ? (InternalDecorator)splitter.getFirstComponent() : (InternalDecorator)splitter.getSecondComponent(); + if (myInfo.isSplit() && component != null) { myId2SplitProportion.put(component.getWindowInfo().getId(), splitter.getProportion()); - } - setComponent(component, anchor, component != null ? component.getWindowInfo().getWeight() : 0); - } - else { - InternalDecorator component = (InternalDecorator)splitter.getSecondComponent(); - setComponent(component, anchor, component != null ? component.getWindowInfo().getWeight() : 0); } + setComponent(component, anchor, component != null ? component.getWindowInfo().getWeight() : 0); } else { setComponent(null, anchor, 0); } diff --git a/platform/platform-impl/src/com/intellij/ui/EditorTextField.java b/platform/platform-impl/src/com/intellij/ui/EditorTextField.java index daa7dcb7ae4a..4cdc5f5a1f0e 100644 --- a/platform/platform-impl/src/com/intellij/ui/EditorTextField.java +++ b/platform/platform-impl/src/com/intellij/ui/EditorTextField.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -617,7 +617,7 @@ public class EditorTextField extends NonOpaquePanel implements DocumentListener, return getParent().getBackground(); } - if (UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF()) return UIUtil.getTextFieldBackground(); + if (UIUtil.isUnderDarcula()/* || UIUtil.isUnderIntelliJLaF()*/) return UIUtil.getTextFieldBackground(); return enabled ? colorsScheme.getDefaultBackground() diff --git a/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java b/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java index 0b16dfbe0f10..4fb82713ea65 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java @@ -558,7 +558,7 @@ public class PopupFactoryImpl extends JBPopupFactory { Point p = getVisibleBestPopupLocation(editor); if (p == null) { final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); - p = new Point((visibleArea.x + visibleArea.width) / 2, (visibleArea.y + visibleArea.height) / 2); + p = new Point(visibleArea.x + visibleArea.width / 3, visibleArea.y + visibleArea.height / 2); } return new RelativePoint(editor.getContentComponent(), p); } diff --git a/platform/platform-resources/src/DefaultColorSchemesManager.xml b/platform/platform-resources/src/DefaultColorSchemesManager.xml index 9922db4edd17..0151dbbf7529 100644 --- a/platform/platform-resources/src/DefaultColorSchemesManager.xml +++ b/platform/platform-resources/src/DefaultColorSchemesManager.xml @@ -1157,7 +1157,7 @@