diff --git a/java/compiler/impl/src/com/intellij/openapi/projectRoots/impl/MockJdkWrapper.java b/java/compiler/impl/src/com/intellij/openapi/projectRoots/impl/MockJdkWrapper.java index 5cf32bef72a9..e10139310ba2 100644 --- a/java/compiler/impl/src/com/intellij/openapi/projectRoots/impl/MockJdkWrapper.java +++ b/java/compiler/impl/src/com/intellij/openapi/projectRoots/impl/MockJdkWrapper.java @@ -90,4 +90,8 @@ public final class MockJdkWrapper implements Sdk { public SdkModificator getSdkModificator() { return null; } + + public Sdk getDelegate() { + return myDelegate; + } } \ No newline at end of file diff --git a/java/compiler/notNull/src/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenter.java b/java/compiler/notNull/src/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenter.java index a53ae7b17b2e..d6bcc68bbe76 100644 --- a/java/compiler/notNull/src/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenter.java +++ b/java/compiler/notNull/src/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenter.java @@ -78,6 +78,7 @@ public class NotNullVerifyingInstrumenter extends ClassAdapter implements Opcode return new MethodAdapter(v) { private final ArrayList myNotNullParams = new ArrayList(); + private int mySyntheticCount = 0; private boolean myIsNotNull = false; //private boolean myIsUnmodifiable = false; public Label myThrowLabel; @@ -92,9 +93,15 @@ public class NotNullVerifyingInstrumenter extends ClassAdapter implements Opcode av = mv.visitParameterAnnotation(parameter, anno, visible); - if (isReferenceType(args[parameter]) && - anno.equals(NOT_NULL_ANNO)) { - myNotNullParams.add(new Integer(parameter)); + if (isReferenceType(args[parameter])) { + if (anno.equals(NOT_NULL_ANNO)) { + myNotNullParams.add(new Integer(parameter)); + } + else if (anno.equals("Ljava/lang/Synthetic;")) { + // See asm r1278 for what we do this, + // http://forge.objectweb.org/tracker/index.php?func=detail&aid=307392&group_id=23&atid=100023 + mySyntheticCount++; + } } return av; } @@ -117,7 +124,7 @@ public class NotNullVerifyingInstrumenter extends ClassAdapter implements Opcode } for (int p = 0; p < myNotNullParams.size(); ++p) { int var = ((access & ACC_STATIC) == 0) ? 1 : 0; - int param = ((Integer)myNotNullParams.get(p)).intValue(); + int param = ((Integer)myNotNullParams.get(p)).intValue() - mySyntheticCount; for (int i = 0; i < param + startParameter; ++i) { var += args[i].getSize(); } diff --git a/java/java-impl/src/com/intellij/codeInspection/internal/InternalInspectionToolsProvider.java b/java/java-impl/src/com/intellij/codeInspection/internal/InternalInspectionToolsProvider.java index ca418c30c5b4..998ef4cdd340 100644 --- a/java/java-impl/src/com/intellij/codeInspection/internal/InternalInspectionToolsProvider.java +++ b/java/java-impl/src/com/intellij/codeInspection/internal/InternalInspectionToolsProvider.java @@ -21,14 +21,20 @@ import com.intellij.util.ArrayUtil; public class InternalInspectionToolsProvider implements InspectionToolProvider { public static final String GROUP_NAME = "IDEA Platform Inspections"; + private static final Class[] CLASSES = new Class[] { UndesirableClassUsageInspection.class }; @Override public Class[] getInspectionClasses() { - if (!ApplicationManagerEx.getApplicationEx().isInternal()) return ArrayUtil.EMPTY_CLASS_ARRAY; - return getPublicClasses(); + if (!isActive()) return ArrayUtil.EMPTY_CLASS_ARRAY; + return CLASSES; } public static Class[] getPublicClasses() { - return new Class[] { UndesirableClassUsageInspection.class }; + if (isActive()) return ArrayUtil.EMPTY_CLASS_ARRAY; + return CLASSES; + } + + private static boolean isActive() { + return ApplicationManagerEx.getApplicationEx().isInternal(); } } diff --git a/java/java-impl/src/com/intellij/codeInspection/internal/UndesirableClassUsageInspection.java b/java/java-impl/src/com/intellij/codeInspection/internal/UndesirableClassUsageInspection.java index ebcd126bca21..e06b26509aae 100644 --- a/java/java-impl/src/com/intellij/codeInspection/internal/UndesirableClassUsageInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/internal/UndesirableClassUsageInspection.java @@ -18,11 +18,13 @@ package com.intellij.codeInspection.internal; import com.intellij.codeInspection.BaseJavaLocalInspectionTool; import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.codeInspection.ProblemsHolder; +import com.intellij.openapi.application.QueryExecutorBase; import com.intellij.psi.*; import com.intellij.ui.components.JBList; import com.intellij.ui.components.JBScrollPane; import com.intellij.ui.table.JBTable; import com.intellij.ui.treeStructure.Tree; +import com.intellij.util.QueryExecutor; import gnu.trove.THashMap; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; @@ -33,11 +35,12 @@ import java.util.Map; public class UndesirableClassUsageInspection extends BaseJavaLocalInspectionTool { private static final Map CLASSES = new THashMap(); - { + static { CLASSES.put(JList.class.getName(), JBList.class.getName()); CLASSES.put(JTable.class.getName(), JBTable.class.getName()); CLASSES.put(JTree.class.getName(), Tree.class.getName()); CLASSES.put(JScrollPane.class.getName(), JBScrollPane.class.getName()); + CLASSES.put(QueryExecutor.class.getName(), QueryExecutorBase.class.getName()); } @Nls diff --git a/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java b/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java index a87eda3415e0..e043ac150d5f 100644 --- a/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java @@ -209,19 +209,19 @@ public class RefJavaManagerImpl extends RefJavaManager { @Nullable public String getType(final RefEntity ref) { if (ref instanceof RefMethod) { - return RefJavaManager.METHOD; + return METHOD; } else if (ref instanceof RefClass) { - return RefJavaManager.CLASS; + return CLASS; } else if (ref instanceof RefField) { - return RefJavaManager.FIELD; + return FIELD; } else if (ref instanceof RefParameter) { - return RefJavaManager.PARAMETER; + return PARAMETER; } else if (ref instanceof RefPackage) { - return RefJavaManager.PACKAGE; + return PACKAGE; } return null; } @@ -247,8 +247,7 @@ public class RefJavaManagerImpl extends RefJavaManager { } public boolean belongsToScope(final PsiElement psiElement) { - if (psiElement instanceof PsiTypeParameter) return false; - return true; + return !(psiElement instanceof PsiTypeParameter); } public void export(final RefEntity refEntity, final Element element) { @@ -265,8 +264,7 @@ public class RefJavaManagerImpl extends RefJavaManager { private static void appendPackageElement(final Element element, final String packageName) { final Element packageElement = new Element("package"); - packageElement - .addContent(packageName.length() > 0 ? packageName : InspectionsBundle.message("inspection.export.results.default")); + packageElement.addContent(packageName.length() > 0 ? packageName : InspectionsBundle.message("inspection.export.results.default")); element.addContent(packageElement); } @@ -320,7 +318,7 @@ public class RefJavaManagerImpl extends RefJavaManager { public void visitMethod(final PsiMethod method) { super.visitMethod(method); final RefElement refElement = myRefManager.getReference(method); - if (refElement instanceof RefMethod) { + if (refElement instanceof RefMethodImpl) { ((RefMethodImpl)refElement).buildReferences(); } } @@ -328,7 +326,7 @@ public class RefJavaManagerImpl extends RefJavaManager { public void visitField(final PsiField field) { super.visitField(field); final RefElement refElement = myRefManager.getReference(field); - if (refElement instanceof RefField) { + if (refElement instanceof RefFieldImpl) { ((RefFieldImpl)refElement).buildReferences(); } } @@ -409,4 +407,4 @@ public class RefJavaManagerImpl extends RefJavaManager { } } } -} \ No newline at end of file +} diff --git a/java/java-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java b/java/java-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java index d50ad25c5690..188c0ef7e06a 100644 --- a/java/java-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java @@ -250,43 +250,42 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod { public void buildReferences() { // Work on code block to find what we're referencing... PsiMethod method = (PsiMethod) getElement(); - if (method != null) { - PsiCodeBlock body = method.getBody(); - final RefJavaUtil refUtil = RefJavaUtil.getInstance(); - refUtil.addReferences(method, this, body); - refUtil.addReferences(method, this, method.getModifierList()); - checkForSuperCall(method); - setOnlyCallsSuper(refUtil.isMethodOnlyCallsSuper(method)); + if (method == null) return; + PsiCodeBlock body = method.getBody(); + final RefJavaUtil refUtil = RefJavaUtil.getInstance(); + refUtil.addReferences(method, this, body); + refUtil.addReferences(method, this, method.getModifierList()); + checkForSuperCall(method); + setOnlyCallsSuper(refUtil.isMethodOnlyCallsSuper(method)); - setBodyEmpty(isOnlyCallsSuper() || !isExternalOverride() && (body == null || body.getStatements().length == 0)); + setBodyEmpty(isOnlyCallsSuper() || !isExternalOverride() && (body == null || body.getStatements().length == 0)); - PsiType retType = method.getReturnType(); - if (retType != null) { - PsiType psiType = retType; - RefClass ownerClass = refUtil.getOwnerClass(getRefManager(), method); + PsiType retType = method.getReturnType(); + if (retType != null) { + PsiType psiType = retType; + RefClass ownerClass = refUtil.getOwnerClass(getRefManager(), method); - if (ownerClass != null) { - psiType = psiType.getDeepComponentType(); + if (ownerClass != null) { + psiType = psiType.getDeepComponentType(); - if (psiType instanceof PsiClassType) { - PsiClass psiClass = PsiUtil.resolveClassInType(psiType); - if (psiClass != null && getRefManager().belongsToScope(psiClass)) { - RefClassImpl refClass = (RefClassImpl) getRefManager().getReference(psiClass); - if (refClass != null) { - refClass.addTypeReference(ownerClass); - refClass.addClassExporter(this); - } + if (psiType instanceof PsiClassType) { + PsiClass psiClass = PsiUtil.resolveClassInType(psiType); + if (psiClass != null && getRefManager().belongsToScope(psiClass)) { + RefClassImpl refClass = (RefClassImpl) getRefManager().getReference(psiClass); + if (refClass != null) { + refClass.addTypeReference(ownerClass); + refClass.addClassExporter(this); } } } } - - for (RefParameter parameter : getParameters()) { - refUtil.setIsFinal(parameter, parameter.getElement().hasModifierProperty(PsiModifier.FINAL)); - } - - getRefManager().fireBuildReferences(this); } + + for (RefParameter parameter : getParameters()) { + refUtil.setIsFinal(parameter, parameter.getElement().hasModifierProperty(PsiModifier.FINAL)); + } + + getRefManager().fireBuildReferences(this); } private void collectUncaughtExceptions(PsiMethod method) { diff --git a/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java b/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java index a1051cfbdb03..90ee10cf58a3 100644 --- a/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java +++ b/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java @@ -584,13 +584,14 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{ final SearchScope searchScope = options.searchScope; if (element instanceof PsiMethod && ((PsiMethod)element).isConstructor()){ PsiMethod method = (PsiMethod)element; - if (options.isIncludeOverloadUsages) { - for (PsiMethod constructor : method.getContainingClass().getConstructors()) { - addConstructorUsages(constructor, searchScope, result, options); - } - } - else { - addConstructorUsages(method, searchScope, result, options); + final PsiClass parentClass = method.getContainingClass(); + + if (parentClass != null) { + MethodReferencesSearch.search(new MethodReferencesSearch.SearchParameters(method, searchScope, !options.isIncludeOverloadUsages, options.fastTrack)).forEach(new ReadActionProcessor() { + public boolean processInReadAction(final PsiReference ref) { + return addResult(result, ref, options, parentClass); + } + }); } return; } @@ -609,17 +610,6 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{ } } - private static void addConstructorUsages(PsiMethod method, SearchScope searchScope, final Processor result, final FindUsagesOptions options) { - final PsiClass parentClass = method.getContainingClass(); - if (parentClass == null) return; - - ReferencesSearch.search(new ReferencesSearch.SearchParameters(method, searchScope, false, options.fastTrack)).forEach(new ReadActionProcessor() { - public boolean processInReadAction(final PsiReference ref) { - return addResult(result, ref, options, parentClass); - } - }); - } - public static void addResult(Processor total, PsiElement element, FindUsagesOptions options, PsiElement refElement) { if (filterUsage(element, options, refElement)){ total.process(new UsageInfo(element)); diff --git a/java/java-impl/src/com/intellij/openapi/projectRoots/impl/JavaSdkImpl.java b/java/java-impl/src/com/intellij/openapi/projectRoots/impl/JavaSdkImpl.java index 1c957a79cfaf..dcbacb752c4d 100644 --- a/java/java-impl/src/com/intellij/openapi/projectRoots/impl/JavaSdkImpl.java +++ b/java/java-impl/src/com/intellij/openapi/projectRoots/impl/JavaSdkImpl.java @@ -163,7 +163,7 @@ public class JavaSdkImpl extends JavaSdk { int minorDot = versionString.indexOf('.', dotIdx + 1); if (minorDot > 0) { int minor = Integer.parseInt(versionString.substring(dotIdx + 1, minorDot)); - versionString = String.valueOf(major) + "." + String.valueOf(minor); + versionString = major + "." + minor; } } catch (NumberFormatException e) { @@ -220,13 +220,10 @@ public class JavaSdkImpl extends JavaSdk { private final Map myCachedVersionStrings = new HashMap(); public final String getVersionString(final String sdkHome) { - String versionString; - - if(myCachedVersionStrings.containsKey(sdkHome)) { + if (myCachedVersionStrings.containsKey(sdkHome)) { return myCachedVersionStrings.get(sdkHome); - } else { - versionString = getJdkVersion(sdkHome); } + String versionString = getJdkVersion(sdkHome); if (versionString != null && versionString.length() == 0) { versionString = null; } @@ -268,47 +265,44 @@ public class JavaSdkImpl extends JavaSdk { return jdk; } - public static Sdk getMockJdkCE() { - File mockJdkCEPath = new File(PathManager.getHomePath(), "java/mockJDK"); + private static File getPathForJdkNamed(String name) { + File mockJdkCEPath = new File(PathManager.getHomePath(), "java/" + name); if (mockJdkCEPath.exists()) { - return createMockJdk(mockJdkCEPath.getPath(), "java 1.5", getInstance()); + return mockJdkCEPath; } - - mockJdkCEPath = new File(PathManager.getHomePath(), "community/java/mockJDK"); - if (mockJdkCEPath.exists()) { - return createMockJdk(mockJdkCEPath.getPath(), "java 1.5", getInstance()); - } - - return getMockJdk("java 1.5"); - + return new File(PathManager.getHomePath(), "community/java/" + name); } - - public static Sdk getMockJdk(@NonNls String versionName) { - File mockJdkCEPath = new File(PathManager.getHomePath(), "java/mockJDK"); - if (mockJdkCEPath.exists()) { - return createMockJdk(mockJdkCEPath.getPath(), versionName, getInstance()); - } - final String forcedPath = System.getProperty("idea.testingFramework.mockJDK"); - String jdkHome = forcedPath != null ? forcedPath : PathManager.getHomePath() + File.separator + "mockJDK"; - return createMockJdk(jdkHome, versionName, getInstance()); - } - - public static Sdk getMockJdk15(@NonNls String versionName) { - File mockJdkCEPath = new File(PathManager.getHomePath(), "java/mockJDK"); - if (mockJdkCEPath.exists()) { - return createMockJdk(mockJdkCEPath.getPath(), versionName, getInstance()); - } - String jdkHome = PathManager.getHomePath() + File.separator + "mockJDK-1.5"; - return createMockJdk(jdkHome, versionName, getInstance()); - } - public static Sdk getMockJdk17() { - File mockJdkCEPath = new File(PathManager.getHomePath(), "java/mockJDK-1.7"); - if (mockJdkCEPath.exists()) { - return createMockJdk(mockJdkCEPath.getPath(), "java 1.7", getInstance()); - } - mockJdkCEPath = new File(PathManager.getHomePath(), "community/java/mockJDK-1.7"); - return createMockJdk(mockJdkCEPath.getPath(), "java 1.7", getInstance()); + return getMockJdk17("java 1.7"); + } + public static Sdk getMockJdk17(String name) { + File mockJdkCEPath = getPathForJdkNamed("mockJDK-1.7"); + return createMockJdk(mockJdkCEPath.getPath(), name, getInstance()); + } + public static Sdk getMockJdk14() { + File mockJdkCEPath = getMockJdk14Path(); + return createMockJdk(mockJdkCEPath.getPath(), "java 1.4", getInstance()); + } + + public static File getMockJdk14Path() { + return getPathForJdkNamed("mockJDK-1.4"); + } + + public static Sdk getWebMockJdk17() { + Sdk jdk = getMockJdk17(); + addWebJarsTo(jdk); + return jdk; + } + + public static void addWebJarsTo(Sdk jdk) { + SdkModificator sdkModificator = jdk.getSdkModificator(); + File jar = new File(PathManager.getHomePath(), "lib/jsp-api.jar"); + VirtualFile root = JarFileSystem.getInstance().getJarRootForLocalFile(LocalFileSystem.getInstance().findFileByIoFile(jar)); + sdkModificator.addRoot(root, OrderRootType.CLASSES); + File jar2 = new File(PathManager.getHomePath(), "lib/servlet-api.jar"); + VirtualFile root2 = JarFileSystem.getInstance().getJarRootForLocalFile(LocalFileSystem.getInstance().findFileByIoFile(jar2)); + sdkModificator.addRoot(root2, OrderRootType.CLASSES); + sdkModificator.commitChanges(); } private static Sdk createMockJdk(String jdkHome, final String versionName, JavaSdk javaSdk) { @@ -341,9 +335,7 @@ public class JavaSdkImpl extends JavaSdk { FileFilter jarFileFilter = new FileFilter(){ @SuppressWarnings({"HardCodedStringLiteral"}) public boolean accept(File f){ - if (f.isDirectory()) return false; - if (f.getName().endsWith(".jar")) return true; - return false; + return !f.isDirectory() && f.getName().endsWith(".jar"); } }; diff --git a/java/java-impl/src/com/intellij/psi/NonClasspathClassFinder.java b/java/java-impl/src/com/intellij/psi/NonClasspathClassFinder.java index 58fa776ad97e..bde3a3650563 100644 --- a/java/java-impl/src/com/intellij/psi/NonClasspathClassFinder.java +++ b/java/java-impl/src/com/intellij/psi/NonClasspathClassFinder.java @@ -27,9 +27,7 @@ import com.intellij.psi.search.NonClasspathDirectoryScope; import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.*; /** * @author peter @@ -95,6 +93,31 @@ public abstract class NonClasspathClassFinder extends PsiElementFinder { return result.toArray(new PsiClass[result.size()]); } + + @Override + public Set getClassNames(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) { + final List classRoots = getClassRoots(); + if (classRoots.isEmpty()) { + return Collections.emptySet(); + } + + Set result = new HashSet(); + for (final VirtualFile classRoot : classRoots) { + if (scope.contains(classRoot)) { + final String pkgName = psiPackage.getQualifiedName(); + final VirtualFile dir = classRoot.findFileByRelativePath(pkgName.replace('.', '/')); + if (dir != null && dir.isDirectory()) { + for (final VirtualFile file : dir.getChildren()) { + if (!file.isDirectory() && "class".equals(file.getExtension())) { + result.add(file.getNameWithoutExtension()); + } + } + } + } + } + return result; + } + @Override public PsiPackage findPackage(@NotNull String qualifiedName) { final List classRoots = getClassRoots(); diff --git a/java/java-impl/src/com/intellij/psi/impl/JavaPsiFacadeImpl.java b/java/java-impl/src/com/intellij/psi/impl/JavaPsiFacadeImpl.java index 64791e667335..b08d11e023e5 100644 --- a/java/java-impl/src/com/intellij/psi/impl/JavaPsiFacadeImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/JavaPsiFacadeImpl.java @@ -309,6 +309,13 @@ public class JavaPsiFacadeImpl extends JavaPsiFacadeEx implements Disposable { return myNameHelper; } + public Set getClassNames(PsiPackageImpl psiPackage, GlobalSearchScope scope) { + Set result = new HashSet(); + for (PsiElementFinder finder : myElementFinders) { + result.addAll(finder.getClassNames(psiPackage, scope)); + } + return result; + } public PsiClass[] getClasses(PsiPackageImpl psiPackage, GlobalSearchScope scope) { List result = null; for (PsiElementFinder finder : myElementFinders) { @@ -428,9 +435,8 @@ public class JavaPsiFacadeImpl extends JavaPsiFacadeEx implements Disposable { @NotNull public PsiClass[] getClasses(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) { List list = null; - final PsiDirectory[] dirs = psiPackage.getDirectories(scope); String packageName = psiPackage.getQualifiedName(); - for (PsiDirectory dir : dirs) { + for (PsiDirectory dir : psiPackage.getDirectories(scope)) { PsiClass[] classes = JavaDirectoryService.getInstance().getClasses(dir); if (classes.length == 0) continue; if (list == null) list = new ArrayList(); @@ -446,6 +452,30 @@ public class JavaPsiFacadeImpl extends JavaPsiFacadeEx implements Disposable { return list == null ? PsiClass.EMPTY_ARRAY : list.toArray(new PsiClass[list.size()]); } + + @Override + public Set getClassNames(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) { + Set names = null; + for (PsiDirectory dir : psiPackage.getDirectories(scope)) { + for (PsiFile file : dir.getFiles()) { + if (file instanceof PsiClassOwner) { + final Set inFile; + if (file instanceof PsiClassOwnerEx) { + inFile = ((PsiClassOwnerEx)file).getClassNames(); + } else { + inFile = getClassNames(((PsiClassOwner)file).getClasses()); + } + + if (inFile.isEmpty()) continue; + if (names == null) names = new HashSet(); + names.addAll(inFile); + } + } + + } + return names == null ? Collections.emptySet() : names; + } + @Override public boolean processPackageDirectories(@NotNull PsiPackage psiPackage, @NotNull final GlobalSearchScope scope, final Processor consumer) { final PsiManager psiManager = PsiManager.getInstance(getProject()); diff --git a/java/java-impl/src/com/intellij/psi/impl/compiled/ClsFileImpl.java b/java/java-impl/src/com/intellij/psi/impl/compiled/ClsFileImpl.java index 7e2bbef95a5d..9334cdd0e9aa 100644 --- a/java/java-impl/src/com/intellij/psi/impl/compiled/ClsFileImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/compiled/ClsFileImpl.java @@ -53,11 +53,13 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.lang.ref.SoftReference; +import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; public class ClsFileImpl extends ClsRepositoryPsiElement implements PsiJavaFile, PsiFileWithStubSupport, PsiFileEx, - Queryable { + Queryable, PsiClassOwnerEx { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsFileImpl"); static final Object MIRROR_LOCK = new String("Mirror Lock"); @@ -174,6 +176,11 @@ public class ClsFileImpl extends ClsRepositoryPsiElement return ArrayUtil.EMPTY_STRING_ARRAY; } + @Override + public Set getClassNames() { + return Collections.singleton(getVirtualFile().getNameWithoutExtension()); + } + @NotNull public PsiJavaCodeReferenceElement[] getImplicitlyImportedPackageReferences() { return PsiJavaCodeReferenceElement.EMPTY_ARRAY; diff --git a/java/java-impl/src/com/intellij/psi/impl/file/PsiPackageImpl.java b/java/java-impl/src/com/intellij/psi/impl/file/PsiPackageImpl.java index 26205cc3f949..3ad84d11db68 100644 --- a/java/java-impl/src/com/intellij/psi/impl/file/PsiPackageImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/file/PsiPackageImpl.java @@ -58,7 +58,6 @@ import com.intellij.util.CommonProcessors; import com.intellij.util.Icons; import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.ContainerUtil; -import gnu.trove.THashSet; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -424,20 +423,11 @@ public class PsiPackageImpl extends PsiElementBase implements PsiPackage, Querya return (JavaPsiFacadeImpl)JavaPsiFacade.getInstance(myManager.getProject()); } - private Set buildClassnamesCache() { - Set classNames = new THashSet(); - for (PsiClass aClass: getClasses()) { - classNames.add(aClass.getName()); - } - return classNames; - } - private Set getClassNamesCache() { if (myPublicClassNamesCache == null) { + Set classNames = getFacade().getClassNames(this, allScope()); synchronized (myPublicClassNamesCacheLock) { - if (myPublicClassNamesCache == null) { - myPublicClassNamesCache = buildClassnamesCache(); - } + myPublicClassNamesCache = classNames; } } diff --git a/java/java-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java b/java/java-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java index 5fafccb55777..9530748b317b 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java @@ -96,7 +96,10 @@ public class PsiImmediateClassType extends PsiClassType { List lst = new ArrayList(); final PsiTypeParameter[] parameters = myClass.getTypeParameters(); for (PsiTypeParameter parameter : parameters) { - lst.add(mySubstitutor.substitute(parameter)); + PsiType substituted = mySubstitutor.substitute(parameter); + if (substituted != null) { + lst.add(substituted); + } } return lst.toArray(new PsiType[lst.size()]); } diff --git a/java/java-tests/testData/inspection/deadCode/enumInstantiation/ext_src/Test1.java b/java/java-tests/testData/inspection/deadCode/enumInstantiation/ext_src/Test1.java index d0490b228bfe..1d1ee58d6909 100644 --- a/java/java-tests/testData/inspection/deadCode/enumInstantiation/ext_src/Test1.java +++ b/java/java-tests/testData/inspection/deadCode/enumInstantiation/ext_src/Test1.java @@ -1,7 +1,7 @@ -public void Test1 { +public class Test1 { void foo() { if (Test.FIRST.invert() != Test.SECOND) { //assert } } -} \ No newline at end of file +} diff --git a/java/java-tests/testData/refactoring/turnRefsToSuper/fieldTest/after/ComponentCaller.java b/java/java-tests/testData/refactoring/turnRefsToSuper/fieldTest/after/ComponentCaller.java index 88a10050e402..c70a8f9bd713 100644 --- a/java/java-tests/testData/refactoring/turnRefsToSuper/fieldTest/after/ComponentCaller.java +++ b/java/java-tests/testData/refactoring/turnRefsToSuper/fieldTest/after/ComponentCaller.java @@ -1,5 +1,6 @@ import javax.swing.*; import java.awt.*; +import javax.swing.*; public class ComponentCaller extends JComponent{ Component1 component1; diff --git a/java/java-tests/testData/refactoring/turnRefsToSuper/fieldTest/before/ComponentCaller.java b/java/java-tests/testData/refactoring/turnRefsToSuper/fieldTest/before/ComponentCaller.java index 88a10050e402..c70a8f9bd713 100644 --- a/java/java-tests/testData/refactoring/turnRefsToSuper/fieldTest/before/ComponentCaller.java +++ b/java/java-tests/testData/refactoring/turnRefsToSuper/fieldTest/before/ComponentCaller.java @@ -1,5 +1,6 @@ import javax.swing.*; import java.awt.*; +import javax.swing.*; public class ComponentCaller extends JComponent{ Component1 component1; diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/ClassNameCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/ClassNameCompletionTest.java index 89dac789b5e9..585b55849dd3 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/ClassNameCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/ClassNameCompletionTest.java @@ -33,7 +33,7 @@ public class ClassNameCompletionTest extends CompletionTestCase { } protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } protected void tearDown() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionSortingTestCase.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionSortingTestCase.java index 18fe48c5e674..3240ba305ad4 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionSortingTestCase.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionSortingTestCase.java @@ -41,7 +41,7 @@ public abstract class CompletionSortingTestCase extends LightCompletionTestCase @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } protected abstract String getBasePath(); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/HeavySmartTypeCompletion15Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/HeavySmartTypeCompletion15Test.java index 95acb8999c9e..e5ad185ef108 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/HeavySmartTypeCompletion15Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/HeavySmartTypeCompletion15Test.java @@ -90,6 +90,6 @@ public class HeavySmartTypeCompletion15Test extends CompletionTestCase { } protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java index 1cd9f5cff3a8..a6778c702fc5 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java @@ -190,6 +190,6 @@ public class SecondSmartTypeCompletionTest extends LightCompletionTestCase { @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java index 9932fd937875..b90900f6fd95 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java @@ -1077,7 +1077,7 @@ public class SmartTypeCompletionTest extends LightCompletionTestCase { @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } private void select() { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingTest.java index ba39b86c07fb..1f6af1504839 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingTest.java @@ -10,19 +10,21 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.editor.markup.EffectType; import com.intellij.openapi.editor.markup.TextAttributes; -import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.projectRoots.SdkModificator; import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; -import com.intellij.openapi.roots.*; +import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.packageDependencies.DependencyValidationManager; import com.intellij.pom.java.LanguageLevel; -import com.intellij.psi.*; -import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiClassType; +import com.intellij.psi.PsiField; +import com.intellij.psi.PsiJavaFile; import com.intellij.psi.search.scope.packageSet.NamedScope; import com.intellij.psi.search.scope.packageSet.NamedScopeManager; import com.intellij.psi.search.scope.packageSet.NamedScopesHolder; @@ -64,7 +66,7 @@ public class AdvHighlightingTest extends DaemonAnalyzerTestCase { protected Sdk getTestProjectJdk() { @NonNls boolean is50 = "StaticImportConflict".equals(getTestName(false)); LanguageLevelProjectExtension.getInstance(myProject).setLanguageLevel(is50 ? LanguageLevel.JDK_1_5 : LanguageLevel.JDK_1_4); - return is50 ? JavaSdkImpl.getMockJdk15("java 1.5") : JavaSdkImpl.getMockJdk("java 1.4"); + return is50 ? JavaSdkImpl.getMockJdk17("java 1.5") : JavaSdkImpl.getMockJdk14(); } public void testStaticImportConflict() throws Exception { doTest(BASE_PATH+"/staticImportConflict/Usage.java", BASE_PATH+"/staticImportConflict", false, false); } @@ -147,10 +149,10 @@ public class AdvHighlightingTest extends DaemonAnalyzerTestCase { ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { final ModifiableRootModel rootModel4 = rootManager4.getModifiableModel(); - rootModel4.setSdk(JavaSdkImpl.getMockJdk("java 1.4")); + rootModel4.setSdk(JavaSdkImpl.getMockJdk17("java 1.4")); rootModel4.commit(); final ModifiableRootModel rootModel5 = rootManager5.getModifiableModel(); - rootModel5.setSdk(JavaSdkImpl.getMockJdk15("java 1.5")); + rootModel5.setSdk(JavaSdkImpl.getMockJdk17("java 1.5")); rootModel5.addModuleOrderEntry(java4); rootModel5.commit(); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java index 947fbdf48892..8a1eb48987eb 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -38,7 +38,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { } @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } protected void tearDown() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ImportHelperTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ImportHelperTest.java index 98fd729c0174..adb1fdd49dbf 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ImportHelperTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ImportHelperTest.java @@ -135,7 +135,7 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase { } protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdk15("mock 1.5"); + return JavaSdkImpl.getMockJdk17("mock 1.5"); } private void checkAddImport(PsiJavaFile file, String fqn, String... expectedOrder) { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/JavadocHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/JavadocHighlightingTest.java index 7f9dd579eca2..28023f3788f0 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/JavadocHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/JavadocHighlightingTest.java @@ -115,6 +115,6 @@ public class JavadocHighlightingTest extends LightDaemonAnalyzerTestCase { } protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingPerformanceTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingPerformanceTest.java index 00c036b886db..5f44831ec83d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingPerformanceTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingPerformanceTest.java @@ -8,15 +8,21 @@ import com.intellij.lang.LanguageAnnotators; import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.lang.injection.MultiHostInjector; import com.intellij.openapi.Disposable; +import com.intellij.openapi.application.ex.PathManagerEx; import com.intellij.openapi.extensions.ExtensionPoint; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.impl.source.tree.injected.JavaConcatenationInjectorManager; import com.intellij.testFramework.PlatformTestUtil; +import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl; +import com.intellij.util.Function; import org.jetbrains.annotations.NonNls; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; public class LightAdvHighlightingPerformanceTest extends LightDaemonAnalyzerTestCase { @@ -31,6 +37,7 @@ public class LightAdvHighlightingPerformanceTest extends LightDaemonAnalyzerTest Disposer.register(my, BlockExtensions.create(Extensions.getArea(getProject()).getExtensionPoint(MultiHostInjector.MULTIHOST_INJECTOR_EP_NAME))); IntentionManager.getInstance().getAvailableIntentionActions(); // hack to avoid slowdowns in PyExtensionFactory + PathManagerEx.getTestDataPath(); // to cache stuff } @Override @@ -73,6 +80,7 @@ public class LightAdvHighlightingPerformanceTest extends LightDaemonAnalyzerTest PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); getFile().getText(); //to load text + CodeInsightTestFixtureImpl.ensureIndexesUpToDate(getProject()); final List infos = new ArrayList(); PlatformTestUtil.assertTiming("Performance failed", maxMillis, new Runnable() { @@ -88,10 +96,32 @@ public class LightAdvHighlightingPerformanceTest extends LightDaemonAnalyzerTest public void testaThinlet() throws Exception { List errors = doTest(24000 - JobSchedulerImpl.CORES_COUNT * 1000); + dump("thinlet", errors); assertEquals(1157, errors.size()); } + + private static void dump(String msg, List errors) { + if (true) return; + Collections.sort(errors, new Comparator() { + @Override + public int compare(HighlightInfo o1, HighlightInfo o2) { + return o1.toString().compareTo(o2.toString()); + } + }); + String s = StringUtil.join(errors, new Function() { + @Override + public String fun(HighlightInfo info) { + return info.toString(); + } + }, "\n"); + System.out.println(msg+":\n-----------------------------------------"); + System.out.println(s); + System.out.println("\n--------------------------------------------"); + } + public void testaClassLoader() throws Exception { List errors = doTest(10000 - JobSchedulerImpl.CORES_COUNT * 1000); + dump("classloader", errors); assertEquals(176, errors.size()); } } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/SuppressWarningsTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/SuppressWarningsTest.java index 0514199a8923..204066140e46 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/SuppressWarningsTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/SuppressWarningsTest.java @@ -32,7 +32,7 @@ public class SuppressWarningsTest extends LightDaemonAnalyzerTestCase { } @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } protected LocalInspectionTool[] configureLocalInspectionTools() { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/ChangeParameterClassTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/ChangeParameterClassTest.java index 5e05e9e19228..ecc48a5f0196 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/ChangeParameterClassTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/ChangeParameterClassTest.java @@ -3,7 +3,7 @@ package com.intellij.codeInsight.daemon.quickFix; -public class ChangeParameterClassTest extends LightQuickFixTestCase { +public class ChangeParameterClassTest extends LightQuickFix15TestCase { public void test() throws Exception {doAllTests();} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateFieldFromParameterTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateFieldFromParameterTest.java index c32f690d8e3a..f7da450e71c4 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateFieldFromParameterTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateFieldFromParameterTest.java @@ -29,6 +29,6 @@ public class CreateFieldFromParameterTest extends LightIntentionActionTestCase { } @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/LightQuickFix15TestCase.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/LightQuickFix15TestCase.java index 296106eb1593..f3bf91546b20 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/LightQuickFix15TestCase.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/LightQuickFix15TestCase.java @@ -18,7 +18,7 @@ public abstract class LightQuickFix15TestCase extends LightQuickFixTestCase { } protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } protected void tearDown() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/MethodReturnTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/MethodReturnTest.java index ab9a554dde1f..da43ad02b469 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/MethodReturnTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/MethodReturnTest.java @@ -3,7 +3,7 @@ package com.intellij.codeInsight.daemon.quickFix; -public class MethodReturnTest extends LightQuickFixTestCase { +public class MethodReturnTest extends LightQuickFix15TestCase { public void test() throws Exception { doAllTests(); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/ReplaceAddAllArrayToCollectionsFixTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/ReplaceAddAllArrayToCollectionsFixTest.java index 2de4a80c9604..a13e77071236 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/ReplaceAddAllArrayToCollectionsFixTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/ReplaceAddAllArrayToCollectionsFixTest.java @@ -18,6 +18,6 @@ public class ReplaceAddAllArrayToCollectionsFixTest extends LightQuickFixTestCas @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/SurroundWithArrayFixTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/SurroundWithArrayFixTest.java index 7db939ba7c6f..cb47751c0aab 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/SurroundWithArrayFixTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/SurroundWithArrayFixTest.java @@ -7,7 +7,7 @@ package com.intellij.codeInsight.daemon.quickFix; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; -public class SurroundWithArrayFixTest extends LightQuickFixTestCase { +public class SurroundWithArrayFixTest extends LightQuickFix15TestCase { public void test() throws Exception { doAllTests(); } @@ -18,6 +18,6 @@ public class SurroundWithArrayFixTest extends LightQuickFixTestCase { @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } -} \ No newline at end of file +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/SurroundWithIfFixTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/SurroundWithIfFixTest.java index 4b4c21cc77f1..15010f1c7aae 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/SurroundWithIfFixTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/SurroundWithIfFixTest.java @@ -25,6 +25,6 @@ public class SurroundWithIfFixTest extends LightQuickFixTestCase { @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/VariableTypeFromCallTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/VariableTypeFromCallTest.java index 2bb0d56a0f09..3b9c7e7fe90c 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/VariableTypeFromCallTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/VariableTypeFromCallTest.java @@ -16,7 +16,7 @@ package com.intellij.codeInsight.daemon.quickFix; -public class VariableTypeFromCallTest extends LightQuickFixTestCase { +public class VariableTypeFromCallTest extends LightQuickFix15TestCase { public void test() throws Exception { doAllTests(); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceBackwardTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceBackwardTest.java index d17326380aa8..2b6cabcd6864 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceBackwardTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceBackwardTest.java @@ -34,7 +34,7 @@ public class SliceBackwardTest extends DaemonAnalyzerTestCase { @Override protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } private void dotest() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceForwardTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceForwardTest.java index f5f42c93f46f..5eeb74e1a597 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceForwardTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceForwardTest.java @@ -26,7 +26,7 @@ public class SliceForwardTest extends DaemonAnalyzerTestCase { @Override protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } private void dotest() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceTreeTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceTreeTest.java index 93574ecb5274..480883a76d1e 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceTreeTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceTreeTest.java @@ -35,7 +35,7 @@ public class SliceTreeTest extends LightDaemonAnalyzerTestCase { } @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } protected void tearDown() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/UnusedDeclarationTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/UnusedDeclarationTest.java index 2523b8e5fed8..a12c16397f57 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/UnusedDeclarationTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/UnusedDeclarationTest.java @@ -21,7 +21,6 @@ public class UnusedDeclarationTest extends InspectionTestCase { protected void setUp() throws Exception { super.setUp(); myTool = new UnusedDeclarationInspection(); - LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_3); } private void doTest() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/dependencies/CyclicDependenciesTest.java b/java/java-tests/testSrc/com/intellij/dependencies/CyclicDependenciesTest.java index 17b27fabe46a..1f25868bdfaa 100644 --- a/java/java-tests/testSrc/com/intellij/dependencies/CyclicDependenciesTest.java +++ b/java/java-tests/testSrc/com/intellij/dependencies/CyclicDependenciesTest.java @@ -25,7 +25,7 @@ public class CyclicDependenciesTest extends PsiTestCase { public void run() { try { String root = JavaTestUtil.getJavaTestDataPath() + "/dependencies/cycle/" + getTestName(true); - PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk("java 1.4")); + PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17()); PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete); } catch (Exception e) { diff --git a/java/java-tests/testSrc/com/intellij/dependencies/UsagesInAnalyzingDependenciesTest.java b/java/java-tests/testSrc/com/intellij/dependencies/UsagesInAnalyzingDependenciesTest.java index c10a04563731..8c42f1029bd6 100644 --- a/java/java-tests/testSrc/com/intellij/dependencies/UsagesInAnalyzingDependenciesTest.java +++ b/java/java-tests/testSrc/com/intellij/dependencies/UsagesInAnalyzingDependenciesTest.java @@ -37,7 +37,7 @@ public class UsagesInAnalyzingDependenciesTest extends PsiTestCase{ public void run() { try{ String root = JavaTestUtil.getJavaTestDataPath() + "/dependencies/search/" + getTestName(true); - PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk("java 1.4")); + PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17()); PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete); } catch(Exception e){ diff --git a/java/java-tests/testSrc/com/intellij/projectView/BaseProjectViewTestCase.java b/java/java-tests/testSrc/com/intellij/projectView/BaseProjectViewTestCase.java index eb79e4972970..892251b1d665 100644 --- a/java/java-tests/testSrc/com/intellij/projectView/BaseProjectViewTestCase.java +++ b/java/java-tests/testSrc/com/intellij/projectView/BaseProjectViewTestCase.java @@ -84,11 +84,11 @@ public abstract class BaseProjectViewTestCase extends TestSourceBasedTestCase { return pane; } - protected void assertStructureEqual(PsiDirectory packageDirectory, String expected) { + protected void assertStructureEqual(PsiDirectory packageDirectory, @NonNls String expected) { assertStructureEqual(packageDirectory, expected, 17, myStructure); } - protected void assertStructureEqual(PsiDirectory packageDirectory, String expected, int maxRowCount) { + protected void assertStructureEqual(PsiDirectory packageDirectory, @NonNls String expected, int maxRowCount) { assertStructureEqual(packageDirectory, expected, maxRowCount, myStructure); } @@ -100,7 +100,7 @@ public abstract class BaseProjectViewTestCase extends TestSourceBasedTestCase { return (AbstractProjectTreeStructure)myStructure; } - protected void assertStructureEqual(String expected) { + protected void assertStructureEqual(@NonNls String expected) { assertStructureEqual(myStructure.getRootElement(), expected); } @@ -289,7 +289,7 @@ public abstract class BaseProjectViewTestCase extends TestSourceBasedTestCase { @Override protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdkCE(); + return JavaSdkImpl.getMockJdk17(); } protected static void sortClasses(final PsiClass[] classes) { diff --git a/java/java-tests/testSrc/com/intellij/projectView/JavaTreeStructureTest.java b/java/java-tests/testSrc/com/intellij/projectView/JavaTreeStructureTest.java index 63e696a320a2..5dc496a27cdb 100644 --- a/java/java-tests/testSrc/com/intellij/projectView/JavaTreeStructureTest.java +++ b/java/java-tests/testSrc/com/intellij/projectView/JavaTreeStructureTest.java @@ -212,7 +212,7 @@ public class JavaTreeStructureTest extends TestSourceBasedTestCase { @Override protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdkCE(); + return JavaSdkImpl.getMockJdk17(); } } diff --git a/java/java-tests/testSrc/com/intellij/projectView/ProjectTreeStructureTest.java b/java/java-tests/testSrc/com/intellij/projectView/ProjectTreeStructureTest.java index 67f1e0a34eed..af734635fbcf 100644 --- a/java/java-tests/testSrc/com/intellij/projectView/ProjectTreeStructureTest.java +++ b/java/java-tests/testSrc/com/intellij/projectView/ProjectTreeStructureTest.java @@ -35,7 +35,7 @@ public class ProjectTreeStructureTest extends BaseProjectViewTestCase { " Class4.java\n"); assertStructureEqual("Project\n" + " External Libraries\n" + - " Library: < java 1.5 >\n" + + " Library: < java 1.7 >\n" + " annotations.jar\n" + " classpath.index\n" + " META-INF\n" + @@ -65,7 +65,7 @@ public class ProjectTreeStructureTest extends BaseProjectViewTestCase { assertStructureEqual("Project\n" + " External Libraries\n" + - " Library: < java 1.5 >\n" + + " Library: < java 1.7 >\n" + " annotations.jar\n" + " classpath.index\n" + " META-INF\n" + diff --git a/java/java-tests/testSrc/com/intellij/projectView/ProjectViewSwitchingTest.java b/java/java-tests/testSrc/com/intellij/projectView/ProjectViewSwitchingTest.java index 02e14bd7565f..68941178b93c 100644 --- a/java/java-tests/testSrc/com/intellij/projectView/ProjectViewSwitchingTest.java +++ b/java/java-tests/testSrc/com/intellij/projectView/ProjectViewSwitchingTest.java @@ -64,7 +64,7 @@ public class ProjectViewSwitchingTest extends TestSourceBasedTestCase { @Override protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdkCE(); + return JavaSdkImpl.getMockJdk17(); } } diff --git a/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java b/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java index 53309e3f43d6..d3373e276197 100644 --- a/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java +++ b/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java @@ -245,7 +245,7 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase { @Override protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdkCE(); + return JavaSdkImpl.getMockJdk17(); } } diff --git a/java/java-tests/testSrc/com/intellij/psi/ArrayIndexOutOfBoundsTest.java b/java/java-tests/testSrc/com/intellij/psi/ArrayIndexOutOfBoundsTest.java index 6129c18e0008..1de2f7a3c630 100644 --- a/java/java-tests/testSrc/com/intellij/psi/ArrayIndexOutOfBoundsTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/ArrayIndexOutOfBoundsTest.java @@ -36,7 +36,7 @@ public class ArrayIndexOutOfBoundsTest extends PsiTestCase { public void run() { try{ String root = JavaTestUtil.getJavaTestDataPath() + "/psi/arrayIndexOutOfBounds/src"; - PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk("java 1.4")); + PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17()); myProjectRoot = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete); } catch(Exception e){ diff --git a/java/java-tests/testSrc/com/intellij/psi/ClsBuilderTest.java b/java/java-tests/testSrc/com/intellij/psi/ClsBuilderTest.java index 6856d04ecd3b..63078d13c71b 100644 --- a/java/java-tests/testSrc/com/intellij/psi/ClsBuilderTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/ClsBuilderTest.java @@ -24,7 +24,7 @@ import java.io.IOException; public class ClsBuilderTest extends LightIdeaTestCase { protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("1.5"); + return JavaSdkImpl.getMockJdk17(); } public void testUtilList() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/psi/ModifyAnnotationsTest.java b/java/java-tests/testSrc/com/intellij/psi/ModifyAnnotationsTest.java index 7becce1c59e1..12d7fa72fc05 100644 --- a/java/java-tests/testSrc/com/intellij/psi/ModifyAnnotationsTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/ModifyAnnotationsTest.java @@ -24,7 +24,7 @@ public class ModifyAnnotationsTest extends PsiTestCase { public void run() { try { String root = JavaTestUtil.getJavaTestDataPath() + "/psi/repositoryUse/modifyAnnotations"; - PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk15("mock 1.5")); + PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17("mock 1.5")); PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete); } catch(Exception e){ @@ -36,7 +36,7 @@ public class ModifyAnnotationsTest extends PsiTestCase { } protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdk15("mock 1.5"); + return JavaSdkImpl.getMockJdk17("mock 1.5"); } public void testReplaceAnnotation() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/AnonymousToInnerTest.java b/java/java-tests/testSrc/com/intellij/refactoring/AnonymousToInnerTest.java index 6782516c8291..609b41c5b308 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/AnonymousToInnerTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/AnonymousToInnerTest.java @@ -19,7 +19,7 @@ public class AnonymousToInnerTest extends LightCodeInsightTestCase { @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } public void testGenericTypeParameters() throws Exception { // IDEADEV-29446 diff --git a/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureTargetTest.java b/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureTargetTest.java index e27c45a45726..546d947a8acc 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureTargetTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureTargetTest.java @@ -37,7 +37,7 @@ public class ChangeSignatureTargetTest extends LightCodeInsightTestCase { @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } private void doTest(String expectedMemberName) throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/CopyClassTest.java b/java/java-tests/testSrc/com/intellij/refactoring/CopyClassTest.java index 4dd274034fdf..e812fb1e4483 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/CopyClassTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/CopyClassTest.java @@ -38,7 +38,7 @@ public class CopyClassTest extends CodeInsightTestCase { private void doTest(final String oldName, final String copyName) throws Exception { String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/copyClass/" + getTestName(true); - PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk15("java 1.5")); + PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17("java 1.5")); myRootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete); performAction(oldName, copyName); @@ -70,7 +70,7 @@ public class CopyClassTest extends CodeInsightTestCase { private void doMultifileTest() throws Exception { String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/copyClass/multifile/" + getTestName(true); String rootBefore = root + "/before"; - PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk("java 1.4")); + PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17()); VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete); final HashMap map = new HashMap(); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethod15Test.java b/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethod15Test.java index 5a700c773650..31a250a06b54 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethod15Test.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethod15Test.java @@ -27,6 +27,6 @@ public class ExtractMethod15Test extends LightCodeInsightTestCase { @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java b/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java index 55813fb2b502..873f5b27ffd3 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java @@ -31,7 +31,7 @@ public class ExtractMethodTest extends LightCodeInsightTestCase { @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } public void testExitPoints1() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/ExtractSuperClassTest.java b/java/java-tests/testSrc/com/intellij/refactoring/ExtractSuperClassTest.java index d33ac6575b80..dca6ce459b3b 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/ExtractSuperClassTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/ExtractSuperClassTest.java @@ -63,7 +63,7 @@ public class ExtractSuperClassTest extends CodeInsightTestCase { @Override protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdk15("mock 1.5"); + return JavaSdkImpl.getMockJdk17(); } @Override @@ -80,7 +80,7 @@ public class ExtractSuperClassTest extends CodeInsightTestCase { private void doTest(@NonNls final String className, @NonNls final String newClassName, RefactoringTestUtil.MemberDescriptor... membersToFind) throws Exception { String rootBefore = getRoot() + "/before"; - PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk("java 1.5")); + PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk14()); final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete); PsiClass psiClass = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject)); assertNotNull(psiClass); @@ -100,4 +100,4 @@ public class ExtractSuperClassTest extends CodeInsightTestCase { myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting(); IdeaTestUtil.assertDirectoriesEqual(rootDir2, rootDir, IdeaTestUtil.CVS_FILE_FILTER); } -} \ No newline at end of file +} diff --git a/java/java-tests/testSrc/com/intellij/refactoring/FindMethodDuplicatesBaseTest.java b/java/java-tests/testSrc/com/intellij/refactoring/FindMethodDuplicatesBaseTest.java index 0cd1c520e604..bb057fe9817b 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/FindMethodDuplicatesBaseTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/FindMethodDuplicatesBaseTest.java @@ -21,7 +21,7 @@ public abstract class FindMethodDuplicatesBaseTest extends LightCodeInsightTestC } protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } protected void doTest() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/InheritanceToDelegationTest.java b/java/java-tests/testSrc/com/intellij/refactoring/InheritanceToDelegationTest.java index e3b45d35ca2f..9d93d39a8288 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/InheritanceToDelegationTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/InheritanceToDelegationTest.java @@ -24,7 +24,7 @@ public class InheritanceToDelegationTest extends MultiFileTestCase { } protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } protected String getTestRoot() { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/InlineSuperClassTest.java b/java/java-tests/testSrc/com/intellij/refactoring/InlineSuperClassTest.java index ef07ab92a47d..81df809876c2 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/InlineSuperClassTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/InlineSuperClassTest.java @@ -23,7 +23,7 @@ public class InlineSuperClassTest extends MultiFileTestCase { } protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } private void doTest() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceConstantTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceConstantTest.java index 5f017f4591b7..de321991b063 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceConstantTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceConstantTest.java @@ -88,6 +88,6 @@ public class IntroduceConstantTest extends LightCodeInsightTestCase { } protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceFieldInSameClassTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceFieldInSameClassTest.java index 56fefe62646f..de6dd6214841 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceFieldInSameClassTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceFieldInSameClassTest.java @@ -19,7 +19,7 @@ public class IntroduceFieldInSameClassTest extends LightCodeInsightTestCase { @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } public void testInClassInitializer () throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java index 02ca2417184e..983646c48293 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java @@ -328,6 +328,6 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase { @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } } diff --git a/java/java-tests/testSrc/com/intellij/refactoring/MoveClassTest.java b/java/java-tests/testSrc/com/intellij/refactoring/MoveClassTest.java index e9cc0d4660ef..abe24cded051 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/MoveClassTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/MoveClassTest.java @@ -75,7 +75,7 @@ public class MoveClassTest extends CodeInsightTestCase { String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/moveClass/" + testName; String rootBefore = root + "/before"; - PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk("java 1.4")); + PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17()); VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete); performAction(classNames, newPackageName); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/MoveClassToInnerTest.java b/java/java-tests/testSrc/com/intellij/refactoring/MoveClassToInnerTest.java index 635ec1e43ab3..a9a38fb0812e 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/MoveClassToInnerTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/MoveClassToInnerTest.java @@ -120,7 +120,7 @@ public class MoveClassToInnerTest extends CodeInsightTestCase { private VirtualFile prepareTest() throws Exception { String rootBefore = getRoot() + "/before"; - PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk("java 1.4")); + PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17()); return PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete); } @@ -153,4 +153,4 @@ public class MoveClassToInnerTest extends CodeInsightTestCase { PsiDocumentManager.getInstance(myProject).commitAllDocuments(); FileDocumentManager.getInstance().saveAllDocuments(); } -} \ No newline at end of file +} diff --git a/java/java-tests/testSrc/com/intellij/refactoring/PullUpTest.java b/java/java-tests/testSrc/com/intellij/refactoring/PullUpTest.java index d5fe5eedc979..3a53f431baf2 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/PullUpTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/PullUpTest.java @@ -129,7 +129,7 @@ public class PullUpTest extends LightCodeInsightTestCase { } protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("50"); + return JavaSdkImpl.getMockJdk17("50"); } @Override diff --git a/java/java-tests/testSrc/com/intellij/refactoring/PushDownMultifileTest.java b/java/java-tests/testSrc/com/intellij/refactoring/PushDownMultifileTest.java index 50b381ea2885..cd7727bfec76 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/PushDownMultifileTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/PushDownMultifileTest.java @@ -28,7 +28,7 @@ public class PushDownMultifileTest extends MultiFileTestCase { } protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } private void doTest() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/RenameClassTest.java b/java/java-tests/testSrc/com/intellij/refactoring/RenameClassTest.java index c82d15571fae..25ede307809d 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/RenameClassTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/RenameClassTest.java @@ -105,6 +105,6 @@ public class RenameClassTest extends MultiFileTestCase { @Override protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } } diff --git a/java/java-tests/testSrc/com/intellij/refactoring/RenameCollisionsTest.java b/java/java-tests/testSrc/com/intellij/refactoring/RenameCollisionsTest.java index 720983a9c68c..b3024ee49b8a 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/RenameCollisionsTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/RenameCollisionsTest.java @@ -180,7 +180,7 @@ public class RenameCollisionsTest extends LightCodeInsightTestCase { @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } public void testAllUsagesInCode() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/SuggestedParamTypesTest.java b/java/java-tests/testSrc/com/intellij/refactoring/SuggestedParamTypesTest.java index bf0e39c3baab..881ca1b180e3 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/SuggestedParamTypesTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/SuggestedParamTypesTest.java @@ -48,7 +48,7 @@ public class SuggestedParamTypesTest extends LightCodeInsightTestCase { @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } public void testPostfixExprUsedAsOutput() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/TurnRefsToSuperTest.java b/java/java-tests/testSrc/com/intellij/refactoring/TurnRefsToSuperTest.java index 5f0b5160e7c1..2bdd98fd9553 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/TurnRefsToSuperTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/TurnRefsToSuperTest.java @@ -160,6 +160,6 @@ public class TurnRefsToSuperTest extends MultiFileTestCase { @Override protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } } diff --git a/java/java-tests/testSrc/com/intellij/refactoring/TypeCookTest.java b/java/java-tests/testSrc/com/intellij/refactoring/TypeCookTest.java index 968375b7afa2..e13859ab45b9 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/TypeCookTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/TypeCookTest.java @@ -30,7 +30,7 @@ import java.io.PrintWriter; public class TypeCookTest extends MultiFileTestCase { protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } @Override diff --git a/java/java-tests/testSrc/com/intellij/refactoring/WrapReturnValueTest.java b/java/java-tests/testSrc/com/intellij/refactoring/WrapReturnValueTest.java index 6a327a8503dd..4a921b146d09 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/WrapReturnValueTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/WrapReturnValueTest.java @@ -26,7 +26,7 @@ public class WrapReturnValueTest extends MultiFileTestCase{ } protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } private void doTest(final boolean existing) throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/changeClassSignature/ChangeClassSignatureTest.java b/java/java-tests/testSrc/com/intellij/refactoring/changeClassSignature/ChangeClassSignatureTest.java index 7e4a8a677e43..a3712f47e33b 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/changeClassSignature/ChangeClassSignatureTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/changeClassSignature/ChangeClassSignatureTest.java @@ -22,7 +22,7 @@ public class ChangeClassSignatureTest extends LightCodeInsightTestCase { } protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } public void testNoParams() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineConstantFieldTest.java b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineConstantFieldTest.java index 1c06fd5184a9..9257fd73d8b4 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineConstantFieldTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineConstantFieldTest.java @@ -27,7 +27,7 @@ public class InlineConstantFieldTest extends LightCodeInsightTestCase { @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } private void doTest() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineLocalTest.java b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineLocalTest.java index 54e15ee65e52..69adf382f930 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineLocalTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineLocalTest.java @@ -23,7 +23,7 @@ public class InlineLocalTest extends LightCodeInsightTestCase { } protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } public void testInference () throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java index 6712233eab3a..ddbcbc3c359e 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java @@ -159,7 +159,7 @@ public class InlineMethodTest extends LightCodeInsightTestCase { @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } private void doTest() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineParameterTest.java b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineParameterTest.java index 65a9b5189039..673361a21540 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineParameterTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineParameterTest.java @@ -21,7 +21,7 @@ public class InlineParameterTest extends LightCodeInsightTestCase { } protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } public void testSameValue() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineToAnonymousClassMultifileTest.java b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineToAnonymousClassMultifileTest.java index 0ac1c8c4bfd9..ddda0445876c 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineToAnonymousClassMultifileTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineToAnonymousClassMultifileTest.java @@ -38,7 +38,7 @@ public class InlineToAnonymousClassMultifileTest extends CodeInsightTestCase { private void doTest(String className) throws Exception { String rootBefore = getRoot() + "/before"; - PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk("java 1.4")); + PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17()); final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete); PsiClass classToInline = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject)); assertEquals(null, InlineToAnonymousClassHandler.getCannotInlineMessage(classToInline)); @@ -55,4 +55,4 @@ public class InlineToAnonymousClassMultifileTest extends CodeInsightTestCase { myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting(); IdeaTestUtil.assertDirectoriesEqual(rootDir2, rootDir, IdeaTestUtil.CVS_FILE_FILTER); } -} \ No newline at end of file +} diff --git a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineToAnonymousClassTest.java b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineToAnonymousClassTest.java index 01f0a50c5baf..a6958aa8e7f2 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineToAnonymousClassTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineToAnonymousClassTest.java @@ -25,7 +25,7 @@ public class InlineToAnonymousClassTest extends LightCodeInsightTestCase { } protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } public void testSimple() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/roots/InheritedJdkTest.java b/java/java-tests/testSrc/com/intellij/roots/InheritedJdkTest.java index e5eeba378dba..71d08e11a0e2 100644 --- a/java/java-tests/testSrc/com/intellij/roots/InheritedJdkTest.java +++ b/java/java-tests/testSrc/com/intellij/roots/InheritedJdkTest.java @@ -20,7 +20,7 @@ public class InheritedJdkTest extends ModuleTestCase { } public void test1() throws Exception { - final Sdk jdk = JavaSdkImpl.getMockJdk("java 1.4"); + final Sdk jdk = JavaSdkImpl.getMockJdk17("java 1.4"); ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { ProjectJdkTable.getInstance().addJdk(jdk); @@ -39,7 +39,7 @@ public class InheritedJdkTest extends ModuleTestCase { }); assertTrue("JDK is inherited after explicit inheritSdk()", rootManager.isSdkInherited()); - assertTrue("Correct jdk inherited", jdk.equals(rootManager.getSdk())); + assertEquals("Correct jdk inherited", jdk, rootManager.getSdk()); ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { @@ -50,9 +50,9 @@ public class InheritedJdkTest extends ModuleTestCase { }); assertFalse("JDK is not inherited after setJdk(null)", rootManager.isSdkInherited()); - assertTrue("No JDK assigned", null == rootManager.getSdk()); + assertNull("No JDK assigned", rootManager.getSdk()); - final Sdk jdk1 = JavaSdkImpl.getMockJdk("jjj"); + final Sdk jdk1 = JavaSdkImpl.getMockJdk17("jjj"); ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { ProjectJdkTable.getInstance().addJdk(jdk1); @@ -67,7 +67,7 @@ public class InheritedJdkTest extends ModuleTestCase { }); assertFalse("JDK is not inherited after setJdk(jdk1)", rootManager.isSdkInherited()); - assertTrue("jdk1 is assigned", jdk1.equals(rootManager.getSdk())); + assertEquals("jdk1 is assigned", jdk1, rootManager.getSdk()); } public void test2() throws Exception { @@ -81,9 +81,9 @@ public class InheritedJdkTest extends ModuleTestCase { }); assertTrue("JDK is inherited after inheritSdk()", rootManager.isSdkInherited()); - assertTrue("No JDK assigned", null == rootManager.getSdk()); + assertNull("No JDK assigned", rootManager.getSdk()); - final Sdk mockJdk = JavaSdkImpl.getMockJdk("mock 1.4"); + final Sdk mockJdk = JavaSdkImpl.getMockJdk17("mock 1.4"); ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { ProjectJdkTable.getInstance().addJdk(mockJdk); @@ -98,7 +98,7 @@ public class InheritedJdkTest extends ModuleTestCase { }); assertTrue(rootManager.isSdkInherited()); - assertTrue("mockJdk inherited", mockJdk.equals(rootManager.getSdk())); + assertEquals("mockJdk inherited", mockJdk, rootManager.getSdk()); ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { @@ -115,7 +115,7 @@ public class InheritedJdkTest extends ModuleTestCase { }, null)); assertNull("Non-existing JDK", rootManager.getSdk()); - final Sdk jdk1 = JavaSdkImpl.getMockJdk("jdk1"); + final Sdk jdk1 = JavaSdkImpl.getMockJdk17("jdk1"); ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { ProjectJdkTable.getInstance().addJdk(jdk1); @@ -124,6 +124,6 @@ public class InheritedJdkTest extends ModuleTestCase { assertTrue(rootManager.isSdkInherited()); assertNotNull("JDK appeared", rootManager.getSdk()); - assertTrue("jdk1 found", jdk1.equals(rootManager.getSdk())); + assertEquals("jdk1 found", jdk1, rootManager.getSdk()); } } diff --git a/java/java-tests/testSrc/com/intellij/roots/ModuleRootsExternalizationTest.java b/java/java-tests/testSrc/com/intellij/roots/ModuleRootsExternalizationTest.java index e223048db447..b52b91b3b495 100644 --- a/java/java-tests/testSrc/com/intellij/roots/ModuleRootsExternalizationTest.java +++ b/java/java-tests/testSrc/com/intellij/roots/ModuleRootsExternalizationTest.java @@ -58,20 +58,20 @@ public class ModuleRootsExternalizationTest extends ModuleTestCase { File classes = new File(content, "classes"); File testClasses = new File(content, "testClasses"); final VirtualFile contentFile = LocalFileSystem.getInstance().findFileByIoFile(content); - assertTrue(contentFile != null); + assertNotNull(contentFile); final VirtualFile sourceFile = LocalFileSystem.getInstance().findFileByIoFile(source); - assertTrue(sourceFile != null); + assertNotNull(sourceFile); final VirtualFile testSourceFile = LocalFileSystem.getInstance().findFileByIoFile(testSource); - assertTrue(testSourceFile != null); + assertNotNull(testSourceFile); final VirtualFile excludeFile = LocalFileSystem.getInstance().findFileByIoFile(exclude); - assertTrue(excludeFile != null); + assertNotNull(excludeFile); final VirtualFile classesFile = LocalFileSystem.getInstance().findFileByIoFile(classes); - assertTrue(classesFile != null); + assertNotNull(classesFile); final VirtualFile testClassesFile = LocalFileSystem.getInstance().findFileByIoFile(testClasses); - assertTrue(testClassesFile != null); + assertNotNull(testClassesFile); final File moduleFile = new File(content, "test.iml"); final Module module = createModule(moduleFile); @@ -85,7 +85,7 @@ public class ModuleRootsExternalizationTest extends ModuleTestCase { compilerModuleExtension.setCompilerOutputPath(classesFile); compilerModuleExtension.setCompilerOutputPathForTests(testClassesFile); compilerModuleExtension.inheritCompilerOutputPath(false); - rootModel.setSdk(JavaSdkImpl.getMockJdk("java 1.4")); + rootModel.setSdk(JavaSdkImpl.getMockJdk17()); contentEntry.addSourceFolder(sourceFile, false); contentEntry.addSourceFolder(testSourceFile, true); contentEntry.addExcludeFolder(excludeFile); @@ -108,7 +108,7 @@ public class ModuleRootsExternalizationTest extends ModuleTestCase { "" + "" + "" + - "" + + "" + "" + "", module); @@ -142,8 +142,8 @@ public class ModuleRootsExternalizationTest extends ModuleTestCase { }); final Iterator libraryIterator = moduleLibraryTable.getLibraryIterator(); - assertTrue(libraryIterator.next().equals(unnamedLibrary)); - assertTrue(libraryIterator.next().equals(namedLibrary)); + assertEquals(libraryIterator.next(), unnamedLibrary); + assertEquals(libraryIterator.next(), namedLibrary); ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { diff --git a/java/java-tests/testSrc/com/intellij/roots/RootsChangedTest.java b/java/java-tests/testSrc/com/intellij/roots/RootsChangedTest.java index 74f791a9d5b4..5827c4bbaf76 100644 --- a/java/java-tests/testSrc/com/intellij/roots/RootsChangedTest.java +++ b/java/java-tests/testSrc/com/intellij/roots/RootsChangedTest.java @@ -24,7 +24,7 @@ import java.io.IOException; */ public class RootsChangedTest extends ModuleTestCase { private MessageBusConnection myConnection; - private RootsChangedTest.MyModuleRootListener myModuleRootListener; + private MyModuleRootListener myModuleRootListener; protected void setUp() throws Exception { super.setUp(); @@ -64,7 +64,7 @@ public class RootsChangedTest extends ModuleTestCase { final Module moduleB = createModule("b.iml"); assertEventsCount(2); - final Sdk jdk = JavaSdkImpl.getMockJdk("AAA"); + final Sdk jdk = JavaSdkImpl.getMockJdk17(); ProjectJdkTable.getInstance().addJdk(jdk); assertEventsCount(0); @@ -89,11 +89,11 @@ public class RootsChangedTest extends ModuleTestCase { final Module moduleB = createModule("b.iml"); assertEventsCount(2); - final Sdk jdk = JavaSdkImpl.getMockJdk("AAA"); + final Sdk jdk = JavaSdkImpl.getMockJdk17("AAA"); ProjectJdkTable.getInstance().addJdk(jdk); assertEventsCount(0); - final Sdk jdkBBB = JavaSdkImpl.getMockJdk("BBB"); + final Sdk jdkBBB = JavaSdkImpl.getMockJdk17("BBB"); ProjectJdkTable.getInstance().addJdk(jdk); assertEventsCount(0); diff --git a/java/mockJDK-1.4/jre/lib/rt.jar b/java/mockJDK-1.4/jre/lib/rt.jar new file mode 100644 index 000000000000..023209857448 Binary files /dev/null and b/java/mockJDK-1.4/jre/lib/rt.jar differ diff --git a/java/mockJDK-1.4/src.zip b/java/mockJDK-1.4/src.zip new file mode 100644 index 000000000000..12c6173f93ba Binary files /dev/null and b/java/mockJDK-1.4/src.zip differ diff --git a/java/mockJDK-1.7/jre/lib/rt.jar b/java/mockJDK-1.7/jre/lib/rt.jar index fdbd1eb22b7a..78062deef86e 100644 Binary files a/java/mockJDK-1.7/jre/lib/rt.jar and b/java/mockJDK-1.7/jre/lib/rt.jar differ diff --git a/java/mockJDK-1.7/lib/jsp-api.jar b/java/mockJDK-1.7/lib/jsp-api.jar deleted file mode 100644 index 95832ba0a217..000000000000 Binary files a/java/mockJDK-1.7/lib/jsp-api.jar and /dev/null differ diff --git a/java/mockJDK-1.7/lib/servlet-api.jar b/java/mockJDK-1.7/lib/servlet-api.jar deleted file mode 100644 index bc0dea064501..000000000000 Binary files a/java/mockJDK-1.7/lib/servlet-api.jar and /dev/null differ diff --git a/java/mockJDK/jre/lib/annotations.jar b/java/mockJDK/jre/lib/annotations.jar deleted file mode 100644 index 5de67805f7b7..000000000000 Binary files a/java/mockJDK/jre/lib/annotations.jar and /dev/null differ diff --git a/java/mockJDK/jre/lib/rt.jar b/java/mockJDK/jre/lib/rt.jar deleted file mode 100644 index ae8e6b0b6381..000000000000 Binary files a/java/mockJDK/jre/lib/rt.jar and /dev/null differ diff --git a/java/mockJDK/src.zip b/java/mockJDK/src.zip deleted file mode 100644 index 4ac79dc0a0bd..000000000000 Binary files a/java/mockJDK/src.zip and /dev/null differ diff --git a/java/openapi/src/com/intellij/psi/PsiClassOwnerEx.java b/java/openapi/src/com/intellij/psi/PsiClassOwnerEx.java new file mode 100644 index 000000000000..42806536b8d1 --- /dev/null +++ b/java/openapi/src/com/intellij/psi/PsiClassOwnerEx.java @@ -0,0 +1,15 @@ +package com.intellij.psi; + +import java.util.Set; + +/** + * @author peter + */ +public interface PsiClassOwnerEx extends PsiClassOwner { + + /** + * @return a set of the short names of the top-level classes defined in this file, as this may be faster than getName() for each of getClasses() + */ + Set getClassNames(); + +} diff --git a/java/openapi/src/com/intellij/psi/PsiElementFinder.java b/java/openapi/src/com/intellij/psi/PsiElementFinder.java index e26c8956f4d9..650cfead6b44 100644 --- a/java/openapi/src/com/intellij/psi/PsiElementFinder.java +++ b/java/openapi/src/com/intellij/psi/PsiElementFinder.java @@ -18,9 +18,14 @@ package com.intellij.psi; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.util.Processor; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + /** * Allows to extend the mechanism of locating classes and packages by full-qualified name. * Implementations of this interface need to be registered as extensions in order @@ -92,6 +97,22 @@ public abstract class PsiElementFinder { return PsiClass.EMPTY_ARRAY; } + public Set getClassNames(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) { + return getClassNames(getClasses(psiPackage, scope)); + } + + protected static Set getClassNames(PsiClass[] classes) { + if (classes.length == 0) { + return Collections.emptySet(); + } + + final HashSet names = new HashSet(); + for (PsiClass aClass : classes) { + ContainerUtil.addIfNotNull(aClass.getName(), names); + } + return names; + } + public boolean processPackageDirectories(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope, Processor consumer) { return true; } diff --git a/java/testFramework/src/com/intellij/testFramework/IdeaTestCase.java b/java/testFramework/src/com/intellij/testFramework/IdeaTestCase.java index 16b8655eaf1f..57de90c29be5 100644 --- a/java/testFramework/src/com/intellij/testFramework/IdeaTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/IdeaTestCase.java @@ -36,7 +36,7 @@ import org.jetbrains.annotations.NonNls; @Override protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdk("java 1.4"); + return JavaSdkImpl.getMockJdk17(); } @Override diff --git a/java/testFramework/src/com/intellij/testFramework/InspectionTestCase.java b/java/testFramework/src/com/intellij/testFramework/InspectionTestCase.java index c8a758ca7d24..a70d766acb1c 100644 --- a/java/testFramework/src/com/intellij/testFramework/InspectionTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/InspectionTestCase.java @@ -24,15 +24,20 @@ */ package com.intellij.testFramework; +import com.intellij.ExtensionPoints; import com.intellij.analysis.AnalysisScope; import com.intellij.codeInspection.GlobalInspectionTool; import com.intellij.codeInspection.InspectionManager; import com.intellij.codeInspection.LocalInspectionTool; +import com.intellij.codeInspection.deadCode.UnusedCodeExtension; import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.codeInspection.ex.*; +import com.intellij.codeInspection.reference.RefElement; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ex.PathManagerEx; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.extensions.ExtensionPoint; +import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; import com.intellij.openapi.roots.ContentEntry; @@ -40,16 +45,23 @@ import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.openapi.roots.ModifiableRootModel; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.pom.java.LanguageLevel; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiManager; +import com.intellij.psi.util.PsiUtil; +import org.jdom.Element; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import java.io.File; @SuppressWarnings({"HardCodedStringLiteral"}) public abstract class InspectionTestCase extends PsiTestCase { private static final Logger LOG = Logger.getInstance("#com.intellij.testFramework.InspectionTestCase"); + private UnusedCodeExtension myUnusedCodeExtension; + private VirtualFile ext_src; public InspectionManagerEx getManager() { return (InspectionManagerEx) InspectionManager.getInstance(myProject); @@ -107,7 +119,7 @@ public abstract class InspectionTestCase extends PsiTestCase { } } }); - AnalysisScope scope = createAnalysisScope(sourceDir[0]); + AnalysisScope scope = createAnalysisScope(sourceDir[0].getParent()); InspectionManagerEx inspectionManager = (InspectionManagerEx) InspectionManager.getInstance(myProject); final GlobalInspectionContextImpl globalContext = inspectionManager.createNewGlobalContext(true); @@ -146,13 +158,13 @@ public abstract class InspectionTestCase extends PsiTestCase { if (sourceDir[0] == null) { sourceDir[0] = projectDir; } - VirtualFile ext_src = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(testDir + "/ext_src")); final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule); final ModifiableRootModel rootModel = rootManager.getModifiableModel(); rootModel.clear(); // configure source and output path final ContentEntry contentEntry = rootModel.addContentEntry(projectDir); contentEntry.addSourceFolder(sourceDir[0], false); + ext_src = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(testDir + "/ext_src")); if (ext_src != null) { contentEntry.addSourceFolder(ext_src, false); } @@ -160,20 +172,67 @@ public abstract class InspectionTestCase extends PsiTestCase { // IMPORTANT! The jdk must be obtained in a way it is obtained in the normal program! //ProjectJdkEx jdk = ProjectJdkTable.getInstance().getInternalJdk(); - rootModel.setSdk(getTestProjectSdk(sdkName)); + rootModel.setSdk(getTestProjectSdk()); rootModel.commit(); } - protected Sdk getTestProjectSdk(String sdkName) { - Sdk sdk; - if ("java 1.5".equals(sdkName)) { - sdk = JavaSdkImpl.getMockJdk15(sdkName); - LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_5); - } - else { - sdk = JavaSdkImpl.getMockJdk(sdkName); - } + @Override + protected void setUp() throws Exception { + super.setUp(); + ExtensionPoint point = Extensions.getRootArea().getExtensionPoint(ExtensionPoints.DEAD_CODE_TOOL); + myUnusedCodeExtension = new UnusedCodeExtension() { + @NotNull + @Override + public String getDisplayName() { + return "duh"; + } + + @Override + public boolean isEntryPoint(RefElement refElement) { + return isEntryPoint(refElement.getElement()); + } + + @Override + public boolean isEntryPoint(PsiElement psiElement) { + return ext_src != null && VfsUtil.isAncestor(ext_src, PsiUtil.getVirtualFile(psiElement), false); + } + + @Override + public boolean isSelected() { + return false; + } + + @Override + public void setSelected(boolean selected) { + + } + + public void readExternal(Element element) { + + } + + public void writeExternal(Element element) { + + } + }; + + point.registerExtension(myUnusedCodeExtension); + } + + @Override + protected void tearDown() throws Exception { + ExtensionPoint point = Extensions.getRootArea().getExtensionPoint(ExtensionPoints.DEAD_CODE_TOOL); + point.unregisterExtension(myUnusedCodeExtension); + myUnusedCodeExtension = null; + ext_src = null; + super.tearDown(); + } + + protected Sdk getTestProjectSdk() { + Sdk sdk = JavaSdkImpl.getMockJdk17(); + LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_5); + //sdk = JavaSdkImpl.getMockJdk(""); return sdk; } diff --git a/java/testFramework/src/com/intellij/testFramework/LightCodeInsightTestCase.java b/java/testFramework/src/com/intellij/testFramework/LightCodeInsightTestCase.java index fc8b9c8d99f6..fcbd332cec6d 100644 --- a/java/testFramework/src/com/intellij/testFramework/LightCodeInsightTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/LightCodeInsightTestCase.java @@ -36,7 +36,7 @@ public abstract class LightCodeInsightTestCase extends LightPlatformCodeInsightT @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk("java 1.4"); + return JavaSdkImpl.getMockJdk17(); } protected ModuleType getModuleType() { diff --git a/java/testFramework/src/com/intellij/testFramework/LightIdeaTestCase.java b/java/testFramework/src/com/intellij/testFramework/LightIdeaTestCase.java index 44b290ce142a..216414e4a845 100644 --- a/java/testFramework/src/com/intellij/testFramework/LightIdeaTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/LightIdeaTestCase.java @@ -44,7 +44,7 @@ import org.jetbrains.annotations.NonNls; @Override protected Sdk getProjectJDK() { - return JavaSdkImpl.getMockJdk("java 1.4"); + return JavaSdkImpl.getMockJdk17(); } protected ModuleType getModuleType() { diff --git a/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java b/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java index dd799580d467..6cc61e89b41b 100644 --- a/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java @@ -120,7 +120,7 @@ public abstract class PsiTestCase extends ModuleTestCase { myTestDataBefore = loadData(dataName); - PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk("java 1.4")); + PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17()); VirtualFile vDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, myDataRoot, myFilesToDelete); final VirtualFile vFile = vDir.findChild(myTestDataBefore.getTextFile()); diff --git a/java/testFramework/src/com/intellij/testFramework/fixtures/DefaultLightProjectDescriptor.java b/java/testFramework/src/com/intellij/testFramework/fixtures/DefaultLightProjectDescriptor.java index 03670d6658ea..d927fb9bc6b3 100644 --- a/java/testFramework/src/com/intellij/testFramework/fixtures/DefaultLightProjectDescriptor.java +++ b/java/testFramework/src/com/intellij/testFramework/fixtures/DefaultLightProjectDescriptor.java @@ -33,7 +33,7 @@ public class DefaultLightProjectDescriptor implements LightProjectDescriptor { } public Sdk getSdk() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) { diff --git a/java/testFramework/src/com/intellij/testFramework/fixtures/LightCodeInsightFixtureTestCase.java b/java/testFramework/src/com/intellij/testFramework/fixtures/LightCodeInsightFixtureTestCase.java index 981caa91c1fc..9970ad55f61a 100644 --- a/java/testFramework/src/com/intellij/testFramework/fixtures/LightCodeInsightFixtureTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/fixtures/LightCodeInsightFixtureTestCase.java @@ -48,7 +48,7 @@ public abstract class LightCodeInsightFixtureTestCase extends UsefulTestCase{ } public Sdk getSdk() { - return JavaSdkImpl.getMockJdk("java 1.4"); + return JavaSdkImpl.getMockJdk17(); } public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) { @@ -140,4 +140,4 @@ public abstract class LightCodeInsightFixtureTestCase extends UsefulTestCase{ return PsiFileFactory.getInstance(getProject()).createFileFromText(fileName, language, text, false, true); } -} \ No newline at end of file +} diff --git a/java/testFramework/src/com/intellij/testFramework/fixtures/impl/JavaModuleFixtureBuilderImpl.java b/java/testFramework/src/com/intellij/testFramework/fixtures/impl/JavaModuleFixtureBuilderImpl.java index 763072b93c0c..d5dc44d49f8d 100644 --- a/java/testFramework/src/com/intellij/testFramework/fixtures/impl/JavaModuleFixtureBuilderImpl.java +++ b/java/testFramework/src/com/intellij/testFramework/fixtures/impl/JavaModuleFixtureBuilderImpl.java @@ -23,6 +23,7 @@ import com.intellij.openapi.module.StdModuleTypes; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; import com.intellij.openapi.projectRoots.impl.MockJdkWrapper; +import com.intellij.openapi.projectRoots.impl.ProjectJdkImpl; import com.intellij.openapi.roots.*; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryTable; @@ -127,15 +128,10 @@ abstract class JavaModuleFixtureBuilderImpl extends Mod final Sdk jdk; if (myJdk != null) { jdk = JavaSdkImpl.getInstance().createJdk(module.getName() + "_jdk", myJdk, false); - } else { - switch (myMockJdkLevel) { - default: - jdk = JavaSdkImpl.getMockJdk("java 1.4"); - break; - case jdk15: - jdk = JavaSdkImpl.getMockJdk15("java 1.5"); - break; - } + ((ProjectJdkImpl)jdk).setVersionString("java 1.5"); + } + else { + jdk = JavaSdkImpl.getMockJdk17(); } if (jdk != null) { model.setSdk(new MockJdkWrapper(CompilerConfigurationImpl.getTestsExternalCompilerHome(), jdk)); diff --git a/lib/asm-commons.jar b/lib/asm-commons.jar index 5bea0d61b4c6..6f9d40fba58c 100644 Binary files a/lib/asm-commons.jar and b/lib/asm-commons.jar differ diff --git a/lib/asm.jar b/lib/asm.jar index af1d08516fb6..7638ae05807d 100644 Binary files a/lib/asm.jar and b/lib/asm.jar differ diff --git a/lib/src/asm-src.zip b/lib/src/asm-src.zip index 4e5d094e17f9..68995ddf62eb 100644 Binary files a/lib/src/asm-src.zip and b/lib/src/asm-src.zip differ diff --git a/platform/lang-impl/src/com/intellij/application/options/editor/EditorAppearanceConfigurable.form b/platform/lang-impl/src/com/intellij/application/options/editor/EditorAppearanceConfigurable.form index 3ec5a7f5550a..0836f2c101b0 100644 --- a/platform/lang-impl/src/com/intellij/application/options/editor/EditorAppearanceConfigurable.form +++ b/platform/lang-impl/src/com/intellij/application/options/editor/EditorAppearanceConfigurable.form @@ -1,6 +1,6 @@
- + @@ -10,7 +10,7 @@ - + @@ -57,7 +57,7 @@ - + @@ -76,7 +76,7 @@ - + @@ -100,12 +100,20 @@ - + + + + + + + + + diff --git a/platform/lang-impl/src/com/intellij/application/options/editor/EditorAppearanceConfigurable.java b/platform/lang-impl/src/com/intellij/application/options/editor/EditorAppearanceConfigurable.java index 19c3aee9c104..bb3fffe711db 100644 --- a/platform/lang-impl/src/com/intellij/application/options/editor/EditorAppearanceConfigurable.java +++ b/platform/lang-impl/src/com/intellij/application/options/editor/EditorAppearanceConfigurable.java @@ -48,6 +48,7 @@ public class EditorAppearanceConfigurable extends CompositeConfigurableemptyList()); } protected String getChooserTitle(PsiElement sourceElement, String name, int length) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoTargetHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoTargetHandler.java index 7a17601f8c4b..5dea7421057b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoTargetHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoTargetHandler.java @@ -56,7 +56,7 @@ public abstract class GotoTargetHandler implements CodeInsightActionHandler { try { GotoData gotoData = getSourceAndTargetElements(editor, file); - if (gotoData != null) { + if (gotoData != null && gotoData.source != null) { show(project, editor, file, gotoData.source, gotoData.targets, gotoData.additionalActions); } } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/reference/RefElementImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/reference/RefElementImpl.java index 343ea8fe2736..c90fdfcf13a6 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/reference/RefElementImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/reference/RefElementImpl.java @@ -139,7 +139,7 @@ public abstract class RefElementImpl extends RefEntityImpl implements RefElement } public boolean isReferenced() { - return getInReferences().size() > 0; + return !getInReferences().isEmpty(); } public boolean hasSuspiciousCallers() { @@ -257,6 +257,6 @@ public abstract class RefElementImpl extends RefEntityImpl implements RefElement } } final RefEntity entity = getOwner(); - return entity instanceof RefElement && ((RefElementImpl)entity).isSuppressed(toolId); + return entity instanceof RefElementImpl && ((RefElementImpl)entity).isSuppressed(toolId); } } diff --git a/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java b/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java index 09fce5ad0ff3..a924b846a51e 100644 --- a/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java +++ b/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java @@ -355,21 +355,26 @@ public class FindUsagesManager implements JDOMExternalizable { options.fastTrack = new SearchRequestCollector(); - for (final PsiElement element : elements) { - ApplicationManager.getApplication().runReadAction(new Runnable() { - public void run() { - LOG.assertTrue(element.isValid()); + try { + for (final PsiElement element : elements) { + ApplicationManager.getApplication().runReadAction(new Runnable() { + public void run() { + LOG.assertTrue(element.isValid()); + } + }); + handler.processElementUsages(element, usageInfoProcessor, options); + } + + PsiManager.getInstance(handler.getProject()).getSearchHelper().processRequests(options.fastTrack, new ReadActionProcessor() { + public boolean processInReadAction(final PsiReference ref) { + TextRange rangeInElement = ref.getRangeInElement(); + return usageInfoProcessor.process(new UsageInfo(ref.getElement(), rangeInElement.getStartOffset(), rangeInElement.getEndOffset(), false)); } }); - handler.processElementUsages(element, usageInfoProcessor, options); } - - PsiManager.getInstance(handler.getProject()).getSearchHelper().processRequests(options.fastTrack, new ReadActionProcessor() { - public boolean processInReadAction(final PsiReference ref) { - TextRange rangeInElement = ref.getRangeInElement(); - return usageInfoProcessor.process(new UsageInfo(ref.getElement(), rangeInElement.getStartOffset(), rangeInElement.getEndOffset(), false)); - } - }); + finally { + options.fastTrack = null; + } } }; } diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java index 0543a0771e95..97d436f972f8 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java @@ -62,6 +62,7 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import javax.swing.border.EmptyBorder; import javax.swing.event.DocumentEvent; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @@ -464,6 +465,7 @@ public abstract class ChooseByNameBase{ }); myListScrollPane = ScrollPaneFactory.createScrollPane(myList); + myListScrollPane.setViewportBorder(new EmptyBorder(0, 0, 0, 0)); if (!UIUtil.isMotifLookAndFeel()) { UIUtil.installPopupMenuBorder(myTextFieldPanel); diff --git a/platform/lang-impl/src/com/intellij/injected/editor/EditorWindow.java b/platform/lang-impl/src/com/intellij/injected/editor/EditorWindow.java index 8fc447cb4c66..e9b8e83d92db 100644 --- a/platform/lang-impl/src/com/intellij/injected/editor/EditorWindow.java +++ b/platform/lang-impl/src/com/intellij/injected/editor/EditorWindow.java @@ -33,6 +33,7 @@ import com.intellij.openapi.editor.ex.*; import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.editor.highlighter.EditorHighlighter; import com.intellij.openapi.editor.impl.EditorImpl; +import com.intellij.openapi.editor.impl.TextDrawingCallback; import com.intellij.openapi.editor.markup.MarkupModel; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; @@ -183,6 +184,11 @@ public class EditorWindow implements EditorEx, UserDataHolderEx { return null; } + @Override + public TextDrawingCallback getTextDrawingCallback() { + return myDelegate.getTextDrawingCallback(); + } + @NotNull public SelectionModel getSelectionModel() { return mySelectionModelDelegate; diff --git a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/CompositeProjectRoot.java b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/CompositeProjectRoot.java index 0d08f0701195..65ebc7db7e56 100644 --- a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/CompositeProjectRoot.java +++ b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/CompositeProjectRoot.java @@ -23,6 +23,7 @@ import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ArrayUtil; import org.jdom.Element; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Arrays; @@ -35,6 +36,7 @@ import java.util.List; class CompositeProjectRoot implements ProjectRoot { private final List myRoots = new ArrayList(); + @NotNull ProjectRoot[] getProjectRoots() { return myRoots.toArray(new ProjectRoot[myRoots.size()]); } @@ -68,6 +70,7 @@ class CompositeProjectRoot implements ProjectRoot { myRoots.remove(root); } + @NotNull ProjectRoot add(VirtualFile virtualFile) { final SimpleProjectRoot root = new SimpleProjectRoot(virtualFile); myRoots.add(root); diff --git a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java index 93bb832970ba..b58d7672ca56 100644 --- a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java @@ -83,7 +83,7 @@ public class ProjectJdkImpl extends UserDataHolderBase implements JDOMExternaliz } public final void setVersionString(String versionString) { - myVersionString = (versionString == null || "".equals(versionString)) ? null : versionString; + myVersionString = versionString == null || "".equals(versionString) ? null : versionString; myVersionDefined = true; } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSchemesImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSchemesImpl.java index 68b75208fd49..e7830eaa3179 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSchemesImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSchemesImpl.java @@ -78,9 +78,7 @@ public class CodeStyleSchemesImpl extends CodeStyleSchemes implements Exportable init(); addScheme(new CodeStyleSchemeImpl(DEFAULT_SCHEME_NAME, true, null)); - CodeStyleScheme current = findSchemeByName(CURRENT_SCHEME_NAME); - if (current == null) current = getDefaultScheme(); - setCurrentScheme(current); + setCurrentScheme(getDefaultScheme()); } public CodeStyleScheme[] getSchemes() { @@ -155,6 +153,10 @@ public class CodeStyleSchemesImpl extends CodeStyleSchemes implements Exportable public void readExternal(Element element) throws InvalidDataException { init(); DefaultJDOMExternalizer.readExternal(this, element); + + CodeStyleScheme current = findSchemeByName(CURRENT_SCHEME_NAME); + if (current == null) current = getDefaultScheme(); + setCurrentScheme(current); } private void init() { diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/TreeUtil.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/TreeUtil.java index 3deeb25a69a2..864edb0baca9 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/TreeUtil.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/TreeUtil.java @@ -73,7 +73,8 @@ public class TreeUtil { } @Nullable - public static ASTNode skipElementsBack(ASTNode element, TokenSet types) { + public static ASTNode skipElementsBack(@Nullable ASTNode element, TokenSet types) { + if (element == null) return null; if (!types.contains(element.getElementType())) return element; ASTNode parent = element.getTreeParent(); diff --git a/platform/lang-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperBaseDialog.java b/platform/lang-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperBaseDialog.java index 5a00463d818c..aca732f738ac 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperBaseDialog.java +++ b/platform/lang-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperBaseDialog.java @@ -250,11 +250,15 @@ public abstract class ExtractSuperBaseDialog 0) { + Arrays.sort(strings); + defaultName = strings[0]; + } else { + defaultName = "undefined"; // need to avoid show dialog in test + } + } if (defaultName != null) { dialog.performRename(defaultName); } diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameDialog.java b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameDialog.java index ea45458ba4b4..f4bcfa9269d7 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameDialog.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameDialog.java @@ -134,7 +134,7 @@ public class RenameDialog extends RefactoringDialog { }, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.CTRL_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); } - private String[] getSuggestedNames() { + public String[] getSuggestedNames() { List result = new ArrayList(); final NameSuggestionProvider[] providers = Extensions.getExtensions(NameSuggestionProvider.EP_NAME); for(NameSuggestionProvider provider: providers) { diff --git a/platform/lang-impl/src/com/intellij/semantic/SemServiceImpl.java b/platform/lang-impl/src/com/intellij/semantic/SemServiceImpl.java index 7049f1e729fb..547401aeb10d 100644 --- a/platform/lang-impl/src/com/intellij/semantic/SemServiceImpl.java +++ b/platform/lang-impl/src/com/intellij/semantic/SemServiceImpl.java @@ -215,7 +215,7 @@ public class SemServiceImpl extends SemService{ return null; } - if (cached != null && cached != Collections.EMPTY_LIST) { + if (cached != null && cached != Collections.emptyList()) { if (singleList == null) { singleList = cached; continue; diff --git a/platform/lang-impl/src/com/intellij/util/indexing/AdditionalIndexableFileSet.java b/platform/lang-impl/src/com/intellij/util/indexing/AdditionalIndexableFileSet.java index d1afeda79323..8d0a5766ba16 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/AdditionalIndexableFileSet.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/AdditionalIndexableFileSet.java @@ -19,8 +19,6 @@ import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.roots.ContentIterator; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileManager; -import com.intellij.util.containers.ContainerUtil; import gnu.trove.THashSet; import java.util.Set; @@ -37,9 +35,7 @@ public class AdditionalIndexableFileSet implements IndexableFileSet { public AdditionalIndexableFileSet(IndexedRootsProvider... extensions) { for (IndexedRootsProvider provider : extensions) { - for (String url : provider.getRootsToIndex()) { - ContainerUtil.addIfNotNull(VirtualFileManager.getInstance().findFileByUrl(url), myRoots); - } + myRoots.addAll(IndexableSetContributor.getRootsToIndex(provider)); } } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java index aac358d4351c..50e59becfa26 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -1906,9 +1906,7 @@ public class FileBasedIndex implements ApplicationComponent { if (project.isDisposed()) { return; } - final Set rootsToIndex = provider.getRootsToIndex(); - for (String url : rootsToIndex) { - final VirtualFile root = VirtualFileManager.getInstance().findFileByUrl(url); + for (VirtualFile root : IndexableSetContributor.getRootsToIndex(provider)) { if (visitedRoots.add(root)) { iterateRecursively(root, processor, indicator); } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/IndexableSetContributor.java b/platform/lang-impl/src/com/intellij/util/indexing/IndexableSetContributor.java new file mode 100644 index 000000000000..a20db92b0b48 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/indexing/IndexableSetContributor.java @@ -0,0 +1,43 @@ +package com.intellij.util.indexing; + +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileManager; +import com.intellij.util.NotNullFunction; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.HashSet; +import java.util.Set; + +/** + * @author peter + */ +public abstract class IndexableSetContributor implements IndexedRootsProvider { + @Override + public final Set getRootsToIndex() { + return ContainerUtil.map2Set(getAdditionalRootsToIndex(), new NotNullFunction() { + @NotNull + @Override + public String fun(VirtualFile virtualFile) { + return virtualFile.getUrl(); + } + }); + } + + public static Set getRootsToIndex(IndexedRootsProvider provider) { + /* + if (provider instanceof IndexableSetContributor) { + return ((IndexableSetContributor)provider).getAdditionalRootsToIndex(); + } + */ + + final HashSet result = new HashSet(); + for (String url : provider.getRootsToIndex()) { + ContainerUtil.addIfNotNull(VirtualFileManager.getInstance().findFileByUrl(url), result); + } + return result; + } + + + public abstract Set getAdditionalRootsToIndex(); +} diff --git a/platform/lang-impl/src/com/intellij/util/indexing/IndexedRootsProvider.java b/platform/lang-impl/src/com/intellij/util/indexing/IndexedRootsProvider.java index 5e683479b1a8..bca1b6d4aede 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/IndexedRootsProvider.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/IndexedRootsProvider.java @@ -21,6 +21,7 @@ import com.intellij.openapi.extensions.ExtensionPointName; import java.util.Set; /** + * @deprecated extend {@link com.intellij.util.indexing.IndexableSetContributor} instead * @author Dmitry Avdeev */ public interface IndexedRootsProvider { @@ -28,6 +29,7 @@ public interface IndexedRootsProvider { ExtensionPointName EP_NAME = new ExtensionPointName("com.intellij.indexedRootsProvider"); /** + * @deprecated * @return each string is VFS url {@link com.intellij.openapi.vfs.VirtualFile#getUrl()} of the root to index. Cannot depend on project. */ Set getRootsToIndex(); diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/FormatUtil.java b/platform/lvcs-impl/src/com/intellij/history/integration/FormatUtil.java index 38194b0d5e48..57a93026c042 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/FormatUtil.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/FormatUtil.java @@ -16,6 +16,8 @@ package com.intellij.history.integration; +import com.intellij.openapi.util.text.StringUtil; + import java.text.DateFormat; import java.util.Date; @@ -23,7 +25,10 @@ public class FormatUtil { public static final DateFormat FORMAT = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); public static String formatTimestamp(long t) { - DateFormat f = FORMAT; - return f.format(new Date(t)); + return FORMAT.format(new Date(t)); + } + + public static String formatRelativeTimestamp(long t) { + return StringUtil.formatDate(t, FORMAT); } } diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/ui/models/FileDifferenceModel.java b/platform/lvcs-impl/src/com/intellij/history/integration/ui/models/FileDifferenceModel.java index 5b2e04913a55..30587ea347f0 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/ui/models/FileDifferenceModel.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/ui/models/FileDifferenceModel.java @@ -58,7 +58,7 @@ public abstract class FileDifferenceModel { } private String formatTitle(Entry e, boolean isAvailable) { - String result = FormatUtil.formatTimestamp(e.getTimestamp()) + " - " + e.getName(); + String result = FormatUtil.formatRelativeTimestamp(e.getTimestamp()) + " - " + e.getName(); if (!isAvailable) { result += " - " + LocalHistoryBundle.message("content.not.available"); } diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/RecentChangesPopup.java b/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/RecentChangesPopup.java index fecb79954f33..865e611c6727 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/RecentChangesPopup.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/RecentChangesPopup.java @@ -108,7 +108,7 @@ public class RecentChangesPopup { public Component getListCellRendererComponent(JList l, Object val, int i, boolean isSelected, boolean cellHasFocus) { RecentChange c = (RecentChange)val; myActionLabel.setText(c.getChangeName()); - myDateLabel.setText(FormatUtil.formatTimestamp(c.getTimestamp())); + myDateLabel.setText(FormatUtil.formatRelativeTimestamp(c.getTimestamp())); updateColors(isSelected); return myPanel; diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/RevisionsList.java b/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/RevisionsList.java index c5aa247bfcbc..8ca329b1d3d2 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/RevisionsList.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/RevisionsList.java @@ -50,7 +50,7 @@ public class RevisionsList { public RevisionsList(SelectionListener l) { table = new JBTable(); - table.setModel(new MyModel(Collections.EMPTY_LIST, Collections.EMPTY_MAP)); + table.setModel(new MyModel(Collections.emptyList(), Collections.emptyMap())); table.setTableHeader(null); table.setShowGrid(false); @@ -309,7 +309,7 @@ public class RevisionsList { myBorder.set(row == table.getModel().getRowCount() - 1); - myDateLabel.setText(ensureString(StringUtil.formatDate(r.revision.getTimestamp(), FormatUtil.FORMAT))); + myDateLabel.setText(ensureString(FormatUtil.formatRelativeTimestamp(r.revision.getTimestamp()))); myFilesCountLabel.setText(ensureString(labelsAndColor.filesCount)); myTitleLabel.setFont(myTitleLabel.getFont().deriveFont(labelsAndColor.isNamed ? Font.BOLD : Font.PLAIN)); diff --git a/platform/platform-api/src/com/intellij/openapi/application/ex/PathManagerEx.java b/platform/platform-api/src/com/intellij/openapi/application/ex/PathManagerEx.java index 7573e3194c96..50865410af49 100644 --- a/platform/platform-api/src/com/intellij/openapi/application/ex/PathManagerEx.java +++ b/platform/platform-api/src/com/intellij/openapi/application/ex/PathManagerEx.java @@ -56,8 +56,8 @@ public class PathManagerEx { } /** Caches test data lookup strategy by class. */ - private static final ConcurrentMap CLASS_STRATEGY_CACHE - = new ConcurrentHashMap(); + private static final ConcurrentMap CLASS_STRATEGY_CACHE = new ConcurrentHashMap(); + private static final ConcurrentMap CLASS_CACHE = new ConcurrentHashMap(); /** * Holds names of the files that contain community test classes. @@ -245,21 +245,26 @@ public class PathManagerEx { @Nullable private static Class loadClass(String className) { - Class clazz = null; ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + + Class clazz = CLASS_CACHE.get(className); + if (clazz != null) { + return clazz; + } + ClassLoader definingClassLoader = PathManagerEx.class.getClassLoader(); ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); - List classLoaders - = asList(contextClassLoader, definingClassLoader, systemClassLoader); - for (ClassLoader classLoader : classLoaders) { + for (ClassLoader classLoader : asList(contextClassLoader, definingClassLoader, systemClassLoader)) { clazz = loadClass(className, classLoader); if (clazz != null) { - break; + CLASS_CACHE.put(className, clazz); + return clazz; } } - return clazz; + CLASS_CACHE.put(className, TestCase.class); //dummy + return null; } @Nullable diff --git a/platform/platform-api/src/com/intellij/openapi/editor/CaretModel.java b/platform/platform-api/src/com/intellij/openapi/editor/CaretModel.java index ab9d0f8b5fce..0b56a2bad9ff 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/CaretModel.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/CaretModel.java @@ -102,7 +102,7 @@ public interface CaretModel { int getVisualLineStart(); /** - * @return document offset for the end of the logical line where caret is located + * @return document offset that points to the first symbol shown at the next visual line after the one with caret on it */ int getVisualLineEnd(); diff --git a/platform/platform-api/src/com/intellij/openapi/editor/EditorSettings.java b/platform/platform-api/src/com/intellij/openapi/editor/EditorSettings.java index b3403b120c61..e1d7b1d099e0 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/EditorSettings.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/EditorSettings.java @@ -100,4 +100,7 @@ public interface EditorSettings { boolean isUseSoftWraps(); void setUseSoftWraps(boolean use); + + boolean isSoftWrapsShown(); + void setShowSoftWraps(boolean show); } diff --git a/platform/platform-api/src/com/intellij/ui/components/JBScrollBar.java b/platform/platform-api/src/com/intellij/ui/components/JBScrollBar.java new file mode 100644 index 000000000000..0c5a5506e843 --- /dev/null +++ b/platform/platform-api/src/com/intellij/ui/components/JBScrollBar.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.ui.components; + +import com.intellij.util.ui.ButtonlessScrollBarUI; + +import javax.swing.*; + +public class JBScrollBar extends JScrollBar{ + public JBScrollBar() { + init(); + } + + public JBScrollBar(int orientation) { + super(orientation); + init(); + } + + public JBScrollBar(int orientation, int value, int extent, int min, int max) { + super(orientation, value, extent, min, max); + init(); + } + + private void init() { + putClientProperty("JScrollBar.fastWheelScrolling", Boolean.TRUE); // fast scrolling for JDK 6 + setFocusable(false); + } + + @Override + public void updateUI() { + setUI(ButtonlessScrollBarUI.createNormal()); + } +} diff --git a/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java b/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java index 13a91ca6d0ad..edbdfd712b22 100644 --- a/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java +++ b/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java @@ -15,6 +15,7 @@ */ package com.intellij.ui.components; +import com.intellij.ui.IdeBorderFactory; import com.intellij.util.ui.ButtonlessScrollBarUI; import javax.swing.*; @@ -22,49 +23,91 @@ import javax.swing.border.EmptyBorder; import javax.swing.plaf.ScrollPaneUI; import java.awt.*; -/** - * @author Vladimir Kondratyev - */ public class JBScrollPane extends JScrollPane { - public JBScrollPane(Component view) { - super(view); + public JBScrollPane() { + init(); } - public JBScrollPane() { + public JBScrollPane(Component view) { + super(view); + init(); } public JBScrollPane(int vsbPolicy, int hsbPolicy) { super(vsbPolicy, hsbPolicy); + init(); } - public JBScrollPane(Component view, int vsbPolicy, int hsbPolicy) { super(view, vsbPolicy, hsbPolicy); + init(); + } + + private void init() { + setBorder(IdeBorderFactory.createSimpleBorder()); + setCorner(UPPER_RIGHT_CORNER, new Corner(UPPER_RIGHT_CORNER)); + setCorner(UPPER_LEFT_CORNER, new Corner(UPPER_LEFT_CORNER)); + setCorner(LOWER_RIGHT_CORNER, new Corner(LOWER_RIGHT_CORNER)); + setCorner(LOWER_LEFT_CORNER, new Corner(LOWER_LEFT_CORNER)); } - /** - * Scrollpane's background should be always in sync with view's background - */ public void setUI(ScrollPaneUI ui) { super.setUI(ui); - setViewportBorder(new EmptyBorder(1, 1, 1, 1)); - - // We need to set color of viewport later because UIManager - // updates UI of scroll pane and only after that updates UI - // of its children. To be the last in this sequence we need - // set background later. - SwingUtilities.invokeLater(new Runnable() { - public void run() { - Component component = getViewport().getView(); - if (component != null) { - getViewport().setBackground(component.getBackground()); - } - } - }); - - getVerticalScrollBar().setUI(ButtonlessScrollBarUI.createNormal()); - getHorizontalScrollBar().setUI(ButtonlessScrollBarUI.createNormal()); } + @Override + public JScrollBar createVerticalScrollBar() { + return new MyScrollBar(JScrollBar.VERTICAL); + } + + @Override + public JScrollBar createHorizontalScrollBar() { + return new MyScrollBar(JScrollBar.HORIZONTAL); + } + + private class MyScrollBar extends ScrollBar { + public MyScrollBar(int orientation) { + super(orientation); + } + + @Override + public void updateUI() { + setUI(ButtonlessScrollBarUI.createNormal()); + } + } + + private static class Corner extends JPanel { + private final String myPos; + + public Corner(String pos) { + myPos = pos; + } + + @Override + protected void paintComponent(Graphics g) { + g.setColor(ButtonlessScrollBarUI.TRACK_BACKGROUND); + g.fillRect(0, 0, getWidth(), getHeight()); + + g.setColor(ButtonlessScrollBarUI.TRACK_BORDER); + + int x2 = getWidth() - 1; + int y2 = getHeight() - 1; + + if (myPos == UPPER_LEFT_CORNER || myPos == UPPER_RIGHT_CORNER) { + g.drawLine(0, y2, x2, y2); + } + if (myPos == LOWER_LEFT_CORNER || myPos == LOWER_RIGHT_CORNER) { + g.drawLine(0, 0, x2, 0); + } + + if (myPos == UPPER_LEFT_CORNER || myPos == LOWER_LEFT_CORNER) { + g.drawLine(x2, 0, x2, y2); + } + + if (myPos == UPPER_RIGHT_CORNER || myPos == LOWER_RIGHT_CORNER) { + g.drawLine(0, 0, 0, y2); + } + } + } } diff --git a/platform/platform-api/src/com/intellij/ui/switcher/ApplySwitchAction.java b/platform/platform-api/src/com/intellij/ui/switcher/ApplySwitchAction.java index b9b36ea13b82..fac19fe2bf2f 100644 --- a/platform/platform-api/src/com/intellij/ui/switcher/ApplySwitchAction.java +++ b/platform/platform-api/src/com/intellij/ui/switcher/ApplySwitchAction.java @@ -60,7 +60,7 @@ public class ApplySwitchAction extends AnAction { if (switchManager.canApplySwitch()) { switchManager.applySwitch(); } else { - switchManager.resetSession(); + switchManager.disposeCurrentSession(false); QuickActionManager.getInstance(project).showQuickActions(); } diff --git a/platform/platform-api/src/com/intellij/ui/switcher/SwitchManager.java b/platform/platform-api/src/com/intellij/ui/switcher/SwitchManager.java index b1d9df22ae4e..4df13d60182c 100644 --- a/platform/platform-api/src/com/intellij/ui/switcher/SwitchManager.java +++ b/platform/platform-api/src/com/intellij/ui/switcher/SwitchManager.java @@ -49,6 +49,8 @@ public class SwitchManager implements ProjectComponent, KeyEventDispatcher, AnAc private Set mySwitchActions = new HashSet(); + private Set myFadingWay = new HashSet(); + public SwitchManager(Project project, QuickAccessSettings quickAccess, ActionManager actionManager) { myProject = project; myQa = quickAccess; @@ -64,7 +66,7 @@ public class SwitchManager implements ProjectComponent, KeyEventDispatcher, AnAc public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) { if (!mySwitchActions.contains(action)) { - disposeSession(mySession); + disposeCurrentSession(false); } } @@ -96,7 +98,7 @@ public class SwitchManager implements ProjectComponent, KeyEventDispatcher, AnAc if (areAllModifiersPressed(e.getModifiers(), myQa.getModiferCodes())) { myWaitingForAutoInitSession = true; myAutoInitSessionEvent = e; - myInitSessionAlarm.addRequest(new Runnable() { + Runnable initRunnable = new Runnable() { public void run() { IdeFocusManager.getInstance(myProject).doWhenFocusSettlesDown(new Runnable() { public void run() { @@ -106,7 +108,12 @@ public class SwitchManager implements ProjectComponent, KeyEventDispatcher, AnAc } }); } - }, Registry.intValue("actionSystem.keyGestureHoldTime")); + }; + if (myFadingWay.size() == 0) { + myInitSessionAlarm.addRequest(initRunnable, Registry.intValue("actionSystem.keyGestureHoldTime")); + } else { + initRunnable.run(); + } } } else { if (myWaitingForAutoInitSession) { @@ -181,14 +188,15 @@ public class SwitchManager implements ProjectComponent, KeyEventDispatcher, AnAc public ActionCallback initSession(SwitchingSession session) { cancelWaitingForAutoInit(); - disposeSession(mySession); + disposeCurrentSession(false); mySession = session; return new ActionCallback.Done(); } - private void disposeSession(SwitchingSession session) { + public void disposeCurrentSession(boolean fadeAway) { if (mySession != null) { - Disposer.dispose(session); + mySession.setFadeaway(fadeAway); + Disposer.dispose(mySession); mySession = null; } } @@ -212,7 +220,7 @@ public class SwitchManager implements ProjectComponent, KeyEventDispatcher, AnAc final ActionCallback result = new ActionCallback(); if (isSessionActive()) { final boolean showSpots = mySession.isShowspots(); - mySession.finish().doWhenDone(new AsyncResult.Handler() { + mySession.finish(false).doWhenDone(new AsyncResult.Handler() { public void run(final SwitchTarget switchTarget) { mySession = null; IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(new Runnable() { @@ -237,12 +245,16 @@ public class SwitchManager implements ProjectComponent, KeyEventDispatcher, AnAc return isSessionActive() && mySession.isSelectionWasMoved(); } - public void resetSession() { - disposeSession(mySession); - } - public boolean isSelectionWasMoved() { if (!isSessionActive()) return false; return mySession.isSelectionWasMoved(); } + + public void addFadingAway(SwitchingSession session) { + myFadingWay.add(session); + } + + public void removeFadingAway(SwitchingSession session) { + myFadingWay.remove(session); + } } diff --git a/platform/platform-api/src/com/intellij/ui/switcher/SwitchingSession.java b/platform/platform-api/src/com/intellij/ui/switcher/SwitchingSession.java index 1e770b9ba86e..8e02fd6a0cd2 100644 --- a/platform/platform-api/src/com/intellij/ui/switcher/SwitchingSession.java +++ b/platform/platform-api/src/com/intellij/ui/switcher/SwitchingSession.java @@ -17,20 +17,16 @@ package com.intellij.ui.switcher; import com.intellij.openapi.Disposable; import com.intellij.openapi.ui.AbstractPainter; -import com.intellij.openapi.ui.Painter; -import com.intellij.openapi.util.ActionCallback; import com.intellij.openapi.util.AsyncResult; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.wm.IdeGlassPane; import com.intellij.openapi.wm.IdeGlassPaneUtil; import com.intellij.openapi.wm.impl.content.GraphicsConfig; -import com.intellij.ui.awt.RelativePoint; import com.intellij.ui.awt.RelativeRectangle; import com.intellij.util.Alarm; import org.jetbrains.annotations.Nullable; -import javax.swing.*; import java.awt.*; import java.awt.event.KeyEvent; import java.awt.geom.Area; @@ -57,7 +53,7 @@ public class SwitchingSession implements KeyEventDispatcher, Disposable { private boolean mySelectionWasMoved; - private Alarm myAutoApply = new Alarm(); + private Alarm myAlarm = new Alarm(); private Runnable myAutoApplyRunnable = new Runnable() { public void run() { if (myManager.canApplySwitch()) { @@ -78,6 +74,13 @@ public class SwitchingSession implements KeyEventDispatcher, Disposable { } }; + private boolean myFadingAway; + private Disposable myPainterDisposable = new Disposable() { + @Override + public void dispose() { + } + }; + public SwitchingSession(SwitchManager mgr, SwitchProvider provider, KeyEvent e, @Nullable SwitchTarget preselected, boolean showSpots) { myManager = mgr; myProvider = provider; @@ -120,7 +123,7 @@ public class SwitchingSession implements KeyEventDispatcher, Disposable { myGlassPane = IdeGlassPaneUtil.find(myProvider.getComponent()); myRootComponent = myProvider.getComponent().getRootPane(); mySpotlight = new Spotlight(myRootComponent); - myGlassPane.addPainter(myRootComponent, mySpotlight, this); + myGlassPane.addPainter(myRootComponent, mySpotlight, myPainterDisposable); myShowspotsAlarm = new Alarm(this); restartShowspotsAlarm(); @@ -129,6 +132,10 @@ public class SwitchingSession implements KeyEventDispatcher, Disposable { mySpotlight.setNeedsRepaint(true); } + public void setFadeaway(boolean fadeAway) { + myFadingAway = fadeAway; + } + private class Spotlight extends AbstractPainter { @@ -233,10 +240,14 @@ public class SwitchingSession implements KeyEventDispatcher, Disposable { } public boolean dispatchKeyEvent(KeyEvent e) { - KeyEvent event = myInitialEvent; - if (event == null || ((e.getModifiers() & event.getModifiers()) == 0)) { - finish(); - return false; + if (myFadingAway) { + _dispose(); + } else { + KeyEvent event = myInitialEvent; + if (event == null || ((e.getModifiers() & event.getModifiers()) == 0)) { + finish(!isSelectionWasMoved()); + return false; + } } return false; @@ -275,12 +286,12 @@ public class SwitchingSession implements KeyEventDispatcher, Disposable { mySelection = target; - mySelectionWasMoved = !mySelection.equals(myStartSelection); + mySelectionWasMoved |= !mySelection.equals(myStartSelection); mySpotlight.setNeedsRepaint(true); - myAutoApply.cancelAllRequests(); - myAutoApply.addRequest(myAutoApplyRunnable, Registry.intValue("actionSystem.autoSelectTimeout")); + myAlarm.cancelAllRequests(); + myAlarm.addRequest(myAutoApplyRunnable, Registry.intValue("actionSystem.autoSelectTimeout")); restartShowspotsAlarm(); } @@ -413,19 +424,37 @@ public class SwitchingSession implements KeyEventDispatcher, Disposable { } public void dispose() { - KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(this); myFinished = true; + + if (myFadingAway) { + myManager.addFadingAway(this); + myAlarm.addRequest(new Runnable() { + @Override + public void run() { + _dispose(); + } + }, Registry.intValue("actionSystem.keyGestureDblClickTime")); + } else { + _dispose(); + } } - public AsyncResult finish() { - myAutoApply.cancelAllRequests(); + private void _dispose() { + myFadingAway = false; + myManager.removeFadingAway(this); + Disposer.dispose(myPainterDisposable); + KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(this); + } + + public AsyncResult finish(final boolean fadeAway) { + myAlarm.cancelAllRequests(); final AsyncResult result = new AsyncResult(); final SwitchTarget selection = getSelection(); if (selection != null) { selection.switchTo(true).doWhenDone(new Runnable() { public void run() { - Disposer.dispose(SwitchingSession.this); + myManager.disposeCurrentSession(fadeAway); result.setDone(selection); } }).notifyWhenRejected(result); diff --git a/platform/platform-api/src/com/intellij/util/ui/ButtonlessScrollBarUI.java b/platform/platform-api/src/com/intellij/util/ui/ButtonlessScrollBarUI.java index c28b346b0090..556cbbaf494b 100644 --- a/platform/platform-api/src/com/intellij/util/ui/ButtonlessScrollBarUI.java +++ b/platform/platform-api/src/com/intellij/util/ui/ButtonlessScrollBarUI.java @@ -29,23 +29,18 @@ import java.awt.event.AdjustmentEvent; import java.awt.event.AdjustmentListener; public class ButtonlessScrollBarUI extends BasicScrollBarUI { - public static final Color GRADIENT_LIGHT = new SameColor(0xfb); public static final Color GRADIENT_DARK = new SameColor(0xd7); public static final Color GRADIENT_THUMB_BORDER = new SameColor(0xc9); - public static final Color PLAIN_THUMB_FILL = new SameColor(0xe5); - public static final Color PLAIN_THUMB_BORDER = new SameColor(0xd0); public static final Color TRACK_BACKGROUND = LightColors.SLIGHTLY_GRAY; public static final Color TRACK_BORDER = new SameColor(230); - private final boolean myIsMini; private final AdjustmentListener myAdjustmentListener; private final Animator myAnimator; private int myAnimationColorShift = 0; - protected ButtonlessScrollBarUI(boolean isMini) { - myIsMini = isMini; + protected ButtonlessScrollBarUI() { myAdjustmentListener = new AdjustmentListener() { @Override public void adjustmentValueChanged(AdjustmentEvent e) { @@ -54,10 +49,16 @@ public class ButtonlessScrollBarUI extends BasicScrollBarUI { } }; - myAnimator = new Animator("Adjustment fadeout", myIsMini ? 5 : 10, myIsMini ? 300 : 500, false, 1, 0) { + final int delayFrames = 4; + final int framesCount = 10 + delayFrames; + myAnimator = new Animator("Adjustment fadeout", framesCount, framesCount * 50, false, 1, 0) { @Override public void paintNow(float frame, float totalFrames, float cycle) { - myAnimationColorShift = (int)((totalFrames - frame) * 3); + myAnimationColorShift = 40; + if (frame > delayFrames) { + myAnimationColorShift *= 1 - ((frame - delayFrames) / (totalFrames - delayFrames)); + } + if (scrollbar != null) { scrollbar.repaint(); } @@ -66,20 +67,7 @@ public class ButtonlessScrollBarUI extends BasicScrollBarUI { } public static BasicScrollBarUI createNormal() { - return new ButtonlessScrollBarUI(false); - } - - public static BasicScrollBarUI createMini() { - return new ButtonlessScrollBarUI(true); - } - - @Override - public void installUI(JComponent c) { - if (myIsMini) { - c.putClientProperty("JComponent.sizeVariant", "mini"); - } - - super.installUI(c); + return new ButtonlessScrollBarUI(); } @Override @@ -116,7 +104,7 @@ public class ButtonlessScrollBarUI extends BasicScrollBarUI { } protected int getThickness() { - return myIsMini ? 10 : 13; + return 13; } @Override @@ -142,14 +130,7 @@ public class ButtonlessScrollBarUI extends BasicScrollBarUI { } g.translate(thumbBounds.x, thumbBounds.y); - - if (myIsMini) { - paintMiniThumb(g, thumbBounds); - } - else { - paintMaxiThumb(g, thumbBounds); - } - + paintMaxiThumb(g, thumbBounds); g.translate(-thumbBounds.x, -thumbBounds.y); } @@ -158,16 +139,18 @@ public class ButtonlessScrollBarUI extends BasicScrollBarUI { int hgap = vertical ? 2 : 1; int vgap = vertical ? 1 : 2; + + int w = adjustThumbWidth(thumbBounds.width - hgap * 2); int h = thumbBounds.height - vgap * 2; + // leave one pixel between thumb and right or bottom edge if (vertical) { h -= 1; } else { w -= 1; } - final GradientPaint paint; final Color start = adjustColor(GRADIENT_LIGHT); final Color end = adjustColor(GRADIENT_DARK); @@ -180,10 +163,10 @@ public class ButtonlessScrollBarUI extends BasicScrollBarUI { } ((Graphics2D)g).setPaint(paint); - g.fillRoundRect(hgap, vgap, w + 1, h + 1, 4, 4); + g.fillRect(hgap + 1, vgap + 1, w - 1, h - 1); g.setColor(GRADIENT_THUMB_BORDER); - g.drawRoundRect(hgap, vgap, w, h, 4, 4); + g.drawRoundRect(hgap, vgap, w, h, 3, 3); } protected int adjustThumbWidth(int width) { @@ -195,22 +178,6 @@ public class ButtonlessScrollBarUI extends BasicScrollBarUI { return new SameColor(c.getRed() - myAnimationColorShift); } - private void paintMiniThumb(Graphics g, Rectangle thumbBounds) { - final boolean vertical = isVertical(); - final int hgap = vertical ? 2 : 1; - final int vgap = vertical ? 1 : 2; - - int w = thumbBounds.width - hgap * 2; - int h = thumbBounds.height - vgap * 2; - - g.setColor(adjustColor(PLAIN_THUMB_FILL)); - g.fillRect(hgap, vgap, w, h); - - g.setColor(PLAIN_THUMB_BORDER); - g.drawRect(hgap, vgap, w, h); - } - - private boolean isVertical() { return scrollbar.getOrientation() == JScrollBar.VERTICAL; } @@ -226,6 +193,10 @@ public class ButtonlessScrollBarUI extends BasicScrollBarUI { } private static class EmptyButton extends JButton { + private EmptyButton() { + setFocusable(false); + } + @Override public Dimension getMaximumSize() { return new Dimension(0, 0); diff --git a/platform/platform-impl/src/com/intellij/diagnostic/PerformanceWatcher.java b/platform/platform-impl/src/com/intellij/diagnostic/PerformanceWatcher.java index 9db084401813..bf42e2d8cf19 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/PerformanceWatcher.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/PerformanceWatcher.java @@ -121,7 +121,7 @@ public class PerformanceWatcher implements ApplicationComponent { } private static void deleteOldThreadDumps() { - File allLogsDir = new File(PathManager.getSystemPath(), "log"); + File allLogsDir = new File(PathManager.getLogPath()); if (allLogsDir.isDirectory()) { final String[] dirs = allLogsDir.list(new FilenameFilter() { public boolean accept(final File dir, final String name) { diff --git a/platform/platform-impl/src/com/intellij/ide/util/ExportToFileUtil.java b/platform/platform-impl/src/com/intellij/ide/util/ExportToFileUtil.java index 576023d8c3b1..7f11e4e16900 100644 --- a/platform/platform-impl/src/com/intellij/ide/util/ExportToFileUtil.java +++ b/platform/platform-impl/src/com/intellij/ide/util/ExportToFileUtil.java @@ -20,6 +20,14 @@ import com.intellij.ide.ExporterToTextFile; import com.intellij.ide.IdeBundle; import com.intellij.openapi.components.PathMacroManager; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.EditorFactory; +import com.intellij.openapi.editor.EditorSettings; +import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.openapi.editor.impl.DocumentImpl; +import com.intellij.openapi.editor.impl.EditorFactoryImpl; +import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; @@ -27,8 +35,8 @@ import com.intellij.openapi.ui.FixedSizeButton; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.WindowManager; -import com.intellij.ui.ScrollPaneFactory; import com.intellij.util.SystemProperties; +import com.intellij.util.ui.UIUtil; import javax.swing.*; import javax.swing.event.ChangeEvent; @@ -105,8 +113,7 @@ public class ExportToFileUtil { public static class ExportDialogBase extends DialogWrapper { private final Project myProject; private final ExporterToTextFile myExporter; - protected JTextArea myTextArea; - protected JScrollPane myTextScrollPane; + protected Editor myTextArea; protected JTextField myTfFile; protected JButton myFileButton; private ChangeListener myListener; @@ -140,20 +147,29 @@ public class ExportToFileUtil { public void dispose() { myExporter.removeSettingsChangedListener(myListener); + EditorFactory.getInstance().releaseEditor(myTextArea); super.dispose(); } private void initText() { - myTextArea.setText(myExporter.getReportText()); - myTextArea.getCaret().setDot(0); + myTextArea.getDocument().setText(myExporter.getReportText()); } protected JComponent createCenterPanel() { - myTextArea = new JTextArea(); - myTextArea.setEditable(false); - myTextScrollPane = ScrollPaneFactory.createScrollPane(myTextArea); - myTextScrollPane.setPreferredSize(new Dimension(400, 300)); - return myTextScrollPane; + final Document document = ((EditorFactoryImpl)EditorFactory.getInstance()).createDocument(true); + ((DocumentImpl)document).setAcceptSlashR(true); + + myTextArea = EditorFactory.getInstance().createEditor(document, myProject, StdFileTypes.PLAIN_TEXT, true); + final EditorSettings settings = myTextArea.getSettings(); + settings.setLineNumbersShown(false); + settings.setLineMarkerAreaShown(false); + settings.setFoldingOutlineShown(false); + settings.setRightMarginShown(false); + settings.setAdditionalLinesCount(0); + settings.setAdditionalColumnsCount(0); + settings.setAdditionalPageAtBottom(false); + ((EditorEx)myTextArea).setBackgroundColor(UIUtil.getInactiveTextFieldBackgroundColor()); + return myTextArea.getComponent(); } protected JComponent createNorthPanel() { @@ -210,7 +226,7 @@ public class ExportToFileUtil { } public String getText() { - return myTextArea.getText(); + return myTextArea.getDocument().getText(); } public void setFileName(String s) { @@ -236,7 +252,7 @@ public class ExportToFileUtil { } public void actionPerformed(ActionEvent e) { - String s = StringUtil.convertLineSeparators(myTextArea.getText()); + String s = StringUtil.convertLineSeparators(getText()); CopyPasteManager.getInstance().setContents(new StringSelection(s)); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/SimpleDataContext.java b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/SimpleDataContext.java index 2d5cdc81b218..3592e481b757 100644 --- a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/SimpleDataContext.java +++ b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/SimpleDataContext.java @@ -18,25 +18,37 @@ package com.intellij.openapi.actionSystem.impl; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.project.Project; +import com.intellij.util.containers.HashMap; + +import java.util.Map; public class SimpleDataContext implements DataContext { - private final String myDataId; - private final Object myData; + private final Map myDataId2Data; private final DataContext myParent; private SimpleDataContext(String dataId, Object data, DataContext parent) { - myDataId = dataId; - myData = data; + myDataId2Data = new HashMap(1); + myDataId2Data.put(dataId, data); + myParent = parent; + } + + private SimpleDataContext(Map dataid2data, DataContext parent) { + myDataId2Data = dataid2data; myParent = parent; } public Object getData(String dataId) { - return myDataId.equals(dataId) ? myData : myParent == null ? null : myParent.getData(dataId); + return myDataId2Data.containsKey(dataId) ? myDataId2Data.get(dataId) : + myParent == null ? null : myParent.getData(dataId); } public static DataContext getSimpleContext(String dataId, Object data, DataContext parent) { return new SimpleDataContext(dataId, data, parent); } + + public static DataContext getSimpleContext(Map dataId2data, DataContext parent) { + return new SimpleDataContext(dataId2data, parent); + } public static DataContext getSimpleContext(String dataId, Object data) { return getSimpleContext(dataId, data, null); diff --git a/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedo.java b/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedo.java index 3ecf06dfcd4f..c265c4b2e94a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedo.java +++ b/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedo.java @@ -71,7 +71,7 @@ abstract class UndoRedo { } private Set getDecRefs() { - return myEditor == null ? Collections.EMPTY_SET : myManager.getDocumentReferences(myEditor); + return myEditor == null ? Collections.emptySet() : UndoManagerImpl.getDocumentReferences(myEditor); } protected abstract UndoRedoStacksHolder getStackHolder(); @@ -217,4 +217,4 @@ abstract class UndoRedo { myEditor.setState(pair.getState()); return true; } -} \ No newline at end of file +} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorEx.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorEx.java index ea689d85a0a3..8842992af6dc 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorEx.java @@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.highlighter.EditorHighlighter; +import com.intellij.openapi.editor.impl.TextDrawingCallback; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vfs.VirtualFile; @@ -123,4 +124,6 @@ public interface EditorEx extends Editor { int calcColumnNumber(CharSequence text, int start, int offset, int tabSize); int calcColumnNumber(int offset, int lineIndex); + + TextDrawingCallback getTextDrawingCallback(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorSettingsExternalizable.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorSettingsExternalizable.java index 0ab3aeffccc1..955c867d1d2b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorSettingsExternalizable.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorSettingsExternalizable.java @@ -55,6 +55,7 @@ public class EditorSettingsExternalizable implements NamedJDOMExternalizable, Ex public boolean IS_BLOCK_CURSOR = false; public boolean IS_WHITESPACES_SHOWN = false; + public boolean IS_SOFTWRAPS_SHOWN = false; public boolean IS_INDENT_GUIDES_SHOWN = true; public boolean IS_ANIMATED_SCROLLING = true; public boolean IS_CAMEL_WORDS = false; @@ -313,6 +314,14 @@ public class EditorSettingsExternalizable implements NamedJDOMExternalizable, Ex myOptions.IS_WHITESPACES_SHOWN = val; } + public boolean isSoftWrapsShown() { + return myOptions.IS_SOFTWRAPS_SHOWN; + } + + public void setSoftwrapsShown(boolean val) { + myOptions.IS_SOFTWRAPS_SHOWN = val; + } + public boolean isIndentGuidesShown() { return myOptions.IS_INDENT_GUIDES_SHOWN; } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/SoftWrapModelEx.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/SoftWrapModelEx.java index e67356537f17..f3d159d6b6e1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/SoftWrapModelEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/SoftWrapModelEx.java @@ -19,8 +19,10 @@ import com.intellij.openapi.editor.LogicalPosition; import com.intellij.openapi.editor.SoftWrapModel; import com.intellij.openapi.editor.TextChange; import com.intellij.openapi.editor.VisualPosition; +import com.intellij.openapi.editor.impl.softwrap.SoftWrapDrawingType; import org.jetbrains.annotations.NotNull; +import java.awt.*; import java.util.List; /** @@ -69,4 +71,16 @@ public interface SoftWrapModelEx extends SoftWrapModel { * @return unmodifiable collection of soft wraps currently registered within the current model */ List getRegisteredSoftWraps(); + + /** + * Asks to paint drawing of target type at the given graphics buffer at the given position. + * + * @param g target graphics buffer to draw in + * @param drawingType target drawing type + * @param x target 'x' coordinate to use + * @param y target 'y' coordinate to use + * @param lineHeight line height used at editor + * @return painted drawing width + */ + int paint(@NotNull Graphics g, @NotNull SoftWrapDrawingType drawingType, int x, int y, int lineHeight); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/ArrowPainter.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/ArrowPainter.java new file mode 100644 index 000000000000..a211348e6d3d --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/ArrowPainter.java @@ -0,0 +1,61 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.editor.impl; + +import com.intellij.openapi.util.Computable; +import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NotNull; + +import java.awt.*; + +/** + * Encapsulates logic of drawing arrows at graphics buffer (primary usage is to draw tabulation symbols representation arrows). + * + * @author Denis Zhdanov + * @since Jul 2, 2010 11:35:23 AM + */ +public class ArrowPainter { + + private final ColorHolder myColorHolder; + private final Computable myHeightProvider; + + public ArrowPainter(@NotNull ColorHolder colorHolder, @NotNull Computable heightProvider) { + myColorHolder = colorHolder; + myHeightProvider = heightProvider; + } + + /** + * Paints arrow at the given graphics buffer using given coordinate parameters. + * + * @param g target graphics buffer to use + * @param y defines baseline of the row where the arrow should be painted + * @param start starting 'x' position to use during drawing + * @param stop ending 'x' position to use during drawing + */ + public void paint(Graphics g, int y, int start, int stop) { + stop -= g.getFontMetrics().charWidth(' ') / 2; + Color oldColor = g.getColor(); + g.setColor(myColorHolder.getColor()); + final int height = myHeightProvider.compute(); + final int halfHeight = height / 2; + int mid = y - halfHeight; + int top = y - height; + UIUtil.drawLine(g, start, mid, stop, mid); + UIUtil.drawLine(g, stop, y, stop, top); + g.fillPolygon(new int[]{stop - halfHeight, stop - halfHeight, stop}, new int[]{y, y - height, y - halfHeight}, 3); + g.setColor(oldColor); + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java index 3310c6c80f17..b62353d3467d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java @@ -308,17 +308,13 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener { myOffset = myEditor.logicalPositionToOffset(myLogicalCaret); LOG.assertTrue(myOffset >= 0 && myOffset <= myEditor.getDocument().getTextLength()); - int caretOffset = myEditor.logicalPositionToOffset(myEditor.visualToLogicalPosition(new VisualPosition(myVisibleCaret.line, 0))); - int caretLine = doc.getLineNumber(caretOffset); - myVisualLineStart = doc.getLineStartOffset(caretLine); - myVisualLineEnd = doc.getLineEndOffset(caretLine) + 1; + myVisualLineStart = myEditor.logicalPositionToOffset(myEditor.visualToLogicalPosition(new VisualPosition(myVisibleCaret.line, 0))); + myVisualLineEnd = myEditor.logicalPositionToOffset(myEditor.visualToLogicalPosition(new VisualPosition(myVisibleCaret.line + 1, 0))); myEditor.updateCaretCursor(); requestRepaint(oldInfo); - if (oldCaretPosition.column + oldCaretPosition.softWrapColumnDiff != myLogicalCaret.column + myLogicalCaret.softWrapColumnDiff - || oldCaretPosition.line + oldCaretPosition.softWrapLinesBeforeCurrentLogicalLine != myLogicalCaret.line + myLogicalCaret.softWrapLinesBeforeCurrentLogicalLine) - { + if (!oldCaretPosition.toVisualPosition().equals(myLogicalCaret.toVisualPosition())) { CaretEvent event = new CaretEvent(myEditor, oldCaretPosition, myLogicalCaret); for (CaretListener listener : myCaretListeners) { listener.caretPositionChanged(event); @@ -366,18 +362,6 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener { return myOffset; } - /** - * There is a possible case that single logical line is spread to more than one visual lines because of soft wraps. This method - * allows to receive information about vertical range occupied by the active logical line, i.e. it identifies - * 'y' coordinate of the first visual line that corresponds to the logical line and total height - * of all visual lines that correspond to the active logical line. - * - * @return object that encapsulates information about visual vertical range occupied by the current logical line on a screen - */ - public VerticalInfo getVisualCaretInfo() { - return myCaretInfo; - } - public int getVisualLineStart() { return myVisualLineStart; } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/ColorHolder.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/ColorHolder.java new file mode 100644 index 000000000000..c2bda05bf4c9 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/ColorHolder.java @@ -0,0 +1,99 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.editor.impl; + +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.colors.ColorKey; +import com.intellij.openapi.editor.colors.EditorColorsScheme; + +import java.awt.*; + +/** + * Defines common contract for target {@link Color} retrieving. + * + * @author Denis Zhdanov + * @since Jul 2, 2010 11:12:07 AM + */ +public abstract class ColorHolder { + + /** + * @return target {@link Color} object managed by the current holder + */ + public abstract Color getColor(); + + /** + * Factory method for creating color holder that always returns given {@link Color} object. + * + * @param color target color to use + * @return color holder that uses given color all the time + */ + public static ColorHolder byColor(Color color) { + return new StaticColorHolder(color); + } + + /** + * Shortcut for calling {@link #byColorsScheme(EditorColorsScheme, ColorKey)} with colors scheme retrieved from the given editor. + * + * @param editor target colors scheme holder + * @param key target color identifier within the colors scheme + * @return color holder that delegate target color retrieval to the colors scheme associated + * with the given editor using given color key + */ + public static ColorHolder byColorsScheme(Editor editor, ColorKey key) { + return new ColorSchemeBasedHolder(editor.getColorsScheme(), key); + } + + /** + * Factory method for creating color holder that delegate target color retrieval to the given colors scheme using given color key. + * + * @param scheme target colors scheme to use + * @param key target color identifier + * @return color holder that delegate target color retrieval to the given colors scheme using given color key + */ + public static ColorHolder byColorsScheme(EditorColorsScheme scheme, ColorKey key) { + return new ColorSchemeBasedHolder(scheme, key); + } + + private static class StaticColorHolder extends ColorHolder { + + private final Color myColor; + + StaticColorHolder(Color color) { + myColor = color; + } + + @Override + public Color getColor() { + return myColor; + } + } + + private static class ColorSchemeBasedHolder extends ColorHolder { + + private final EditorColorsScheme myScheme; + private final ColorKey myKey; + + ColorSchemeBasedHolder(EditorColorsScheme scheme, ColorKey key) { + myScheme = scheme; + myKey = key; + } + + @Override + public Color getColor() { + return myScheme.getColor(myKey); + } + } +} 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 b540e898fe13..578bd2b92b99 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 @@ -258,11 +258,12 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse } private void paintCaretRowBackground(final Graphics g, final int x, final int width) { - CaretModelImpl.VerticalInfo caretInfo = myEditor.getCaretModel().getVisualCaretInfo(); + final VisualPosition visCaret = myEditor.getCaretModel().getVisualPosition(); Color caretRowColor = myEditor.getColorsScheme().getColor(EditorColors.CARET_ROW_COLOR); if (caretRowColor != null) { g.setColor(caretRowColor); - g.fillRect(x, caretInfo.y, width, caretInfo.height); + final Point caretPoint = myEditor.visualPositionToXY(visCaret); + g.fillRect(x, caretPoint.y, width, myEditor.getLineHeight()); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index ffe3b12fd5de..4e3858279e13 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -49,6 +49,7 @@ import com.intellij.openapi.editor.highlighter.EditorHighlighter; import com.intellij.openapi.editor.highlighter.HighlighterClient; import com.intellij.openapi.editor.impl.event.MarkupModelEvent; import com.intellij.openapi.editor.impl.event.MarkupModelListener; +import com.intellij.openapi.editor.impl.softwrap.SoftWrapDrawingType; import com.intellij.openapi.editor.markup.*; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.progress.ProgressManager; @@ -59,6 +60,8 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.GuiUtils; import com.intellij.ui.LightweightHint; +import com.intellij.ui.UI; +import com.intellij.ui.components.JBScrollBar; import com.intellij.ui.components.JBScrollPane; import com.intellij.util.Alarm; import com.intellij.util.IJSwingUtilities; @@ -76,7 +79,9 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.Timer; +import javax.swing.border.EmptyBorder; import javax.swing.plaf.ScrollBarUI; +import javax.swing.plaf.ScrollPaneUI; import javax.swing.plaf.basic.BasicScrollBarUI; import java.awt.*; import java.awt.datatransfer.Clipboard; @@ -152,6 +157,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi private MyEditable myEditable; private EditorColorsScheme myScheme; + private ArrowPainter myTabPainter; private final boolean myIsViewer; private final SelectionModelImpl mySelectionModel; private final EditorMarkupModelImpl myMarkupModel; @@ -176,6 +182,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi private boolean myUnderRepainting; private EditorHighlighter myHighlighter; + private final TextDrawingCallback myTextDrawingCallback = new MyTextDrawingCallback(); private int myScrollBarOrientation; private boolean myMousePressedInsideSelection; @@ -235,11 +242,11 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi ourCaretBlinkingCommand.start(); } - public EditorImpl(Document document, boolean viewer, Project project) { myProject = project; myDocument = (DocumentImpl)document; myScheme = new MyColorSchemeDelegate(); + initTabPainter(); myIsViewer = viewer; mySettings = new SettingsImpl(this); @@ -472,6 +479,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi myEditorComponent.repaint(); + initTabPainter(); updateCaretCursor(); if (myInitialMouseEvent != null) { @@ -479,6 +487,18 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi } } + private void initTabPainter() { + myTabPainter = new ArrowPainter( + ColorHolder.byColorsScheme(myScheme, EditorColors.WHITESPACES_COLOR), + new Computable() { + @Override + public Integer compute() { + return getCharHeight(); + } + } + ); + } + public void release() { if (isReleased) { LOG.error("Double release. First released at: =====\n" + myReleasedAt+"\n======"); @@ -529,8 +549,6 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi myGutterComponent.setOpaque(true); myScrollPane.setVerticalScrollBar(myVerticalScrollBar); - final MyScrollBar horizontalScrollBar = new MyScrollBar(Adjustable.HORIZONTAL); - myScrollPane.setHorizontalScrollBar(horizontalScrollBar); myScrollPane.setViewportView(myEditorComponent); //myScrollPane.setBorder(null); myScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); @@ -1382,6 +1400,11 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi return getBackgroundIgnoreForced(); } + @Override + public TextDrawingCallback getTextDrawingCallback() { + return myTextDrawingCallback; + } + private Color getBackgroundColor(final TextAttributes attributes) { final Color attrColor = attributes.getBackgroundColor(); return attrColor == myScheme.getDefaultBackground() ? getBackgroundColor() : attrColor; @@ -1543,6 +1566,14 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi CharSequence text = myDocument.getCharsNoThreadCheck(); int lastLineIndex = Math.max(0, myDocument.getLineCount() - 1); + // There is a possible case that we work with visual line that is introduced by soft wrap. That implies that additional + // space is reserved before the document text represented at the current line (soft wrap drawing is located there). + // Hence, we need to take that into consideration during determining if new soft wrap should be introduced. + // Example: + // 111 222 333 <- soft wrap is here + // soft wrap drawing -> 444 555 <- we need to consider soft wrap drawing on a start of the line during checking if we need to wrap 555. + boolean onSoftWrapIntroducedVisualLine = false; + outer: while (!iterationState.atEnd() && !lIterator.atEnd()) { int hEnd = iterationState.getEndOffset(); @@ -1571,6 +1602,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi position.x = 0; if (position.y > clip.y + clip.height) break; position.y += lineHeight; + onSoftWrapIntroducedVisualLine = false; start = lEnd; } @@ -1583,7 +1615,9 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi } else { TextChange softWrap = getSoftWrapModel().getSoftWrap(start); - if (softWrap == null && getSoftWrapModel().shouldWrap(myDocument.getRawChars(), start, hEnd, position)) { + if (softWrap == null + && getSoftWrapModel().shouldWrap(g, myDocument.getRawChars(), start, hEnd, position.x, onSoftWrapIntroducedVisualLine)) + { softWrap = getSoftWrapModel().wrap(myDocument.getRawChars(), start, hEnd); } if (softWrap != null) { @@ -1593,7 +1627,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi int softWrapEnd = 0; while (softWrapEnd < softWrapText.length()) { for (; softWrapEnd < softWrapText.length() && softWrapText.charAt(softWrapEnd) != '\n'; softWrapEnd++) ; - if (softWrapStart >= softWrapText.length() || softWrapEnd >= softWrapText.length()) { + if (softWrapEnd >= softWrapText.length()) { position.x = drawBackground( g, backColor, softWrapText.subSequence(softWrapStart, softWrapText.length()), position, fontType, defaultBackground, clip ); @@ -1607,6 +1641,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi if (position.y > clip.y + clip.height) break outer; position.x = 0; position.y += lineHeight; + onSoftWrapIntroducedVisualLine = true; softWrapStart = softWrapEnd + 1; softWrapEnd = softWrapStart; } @@ -1839,7 +1874,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi // to the first soft wrap symbol that is not drawn yet. int softWrapSegmentStartIndex = 0; for (int i = 0; i < softWrapChars.length; i++) { - // Delay soft wraps symbols drawing until EOL if found. + // Delay soft wraps symbols drawing until EOL is found. if (softWrapChars[i] != '\n') { continue; } @@ -1857,6 +1892,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi g, softWrapChars, softWrapSegmentStartIndex, i, position, clip, currentColor, effectType, fontType, currentColor ); } + mySoftWrapModel.paint(g, SoftWrapDrawingType.BEFORE_SOFT_WRAP_LINE_FEED, position.x, position.y, getLineHeight()); // Reset 'x' coordinate because of new line start. position.x = 0; @@ -1877,6 +1913,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi fontType, currentColor ); } + position.x += mySoftWrapModel.paint(g, SoftWrapDrawingType.AFTER_SOFT_WRAP_LINE_FEED, position.x, position.y, getLineHeight()); activeSoftWrapProcessed = true; } @@ -1964,7 +2001,9 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi if (count > 0) { final int lastCount = count - 1; final Color lastColor = color[lastCount]; - if (_data == myLastData && _start == ends[lastCount] && (_color == null || lastColor == null || _color == lastColor)) { + if (_data == myLastData && _start == ends[lastCount] && (_color == null || lastColor == null || _color == lastColor) + && _y == y[lastCount] /* there is a possible case that vertical position is adjusted because of soft wrap */) + { ends[lastCount] = _end; if (lastColor == null) color[lastCount] = _color; return; @@ -2195,17 +2234,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi private void drawTabPlacer(Graphics g, int y, int start, int stop) { if (mySettings.isWhitespacesShown()) { - stop -= g.getFontMetrics().charWidth(' ') / 2; - Color oldColor = g.getColor(); - g.setColor(myScheme.getColor(EditorColors.WHITESPACES_COLOR)); - final int charHeight = getCharHeight(); - final int halfCharHeight = charHeight / 2; - int mid = y - halfCharHeight; - int top = y - charHeight; - UIUtil.drawLine(g, start, mid, stop, mid); - UIUtil.drawLine(g, stop, y, stop, top); - g.fillPolygon(new int[]{stop - halfCharHeight, stop - halfCharHeight, stop}, new int[]{y, y - charHeight, y - halfCharHeight}, 3); - g.setColor(oldColor); + myTabPainter.paint(g, y, start, stop); } } @@ -2215,23 +2244,27 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi } else { FontInfo fnt = EditorUtil.fontForChar(data[start], fontType, this); - CachedFontContent cache = null; - for (CachedFontContent fontCache : myFontCache) { - if (fontCache.myFontType == fnt) { - cache = fontCache; - break; - } - } - if (cache == null) { - cache = new CachedFontContent(fnt); - myFontCache.add(cache); - } - - myLastCache = cache; - cache.addContent(g, data, start, end, x, y, color); + drawCharsCached(g, data, start, end, x, y, fnt, color); } } + private void drawCharsCached(Graphics g, char[] data, int start, int end, int x, int y, FontInfo fnt, Color color) { + CachedFontContent cache = null; + for (CachedFontContent fontCache : myFontCache) { + if (fontCache.myFontType == fnt) { + cache = fontCache; + break; + } + } + if (cache == null) { + cache = new CachedFontContent(fnt); + myFontCache.add(cache); + } + + myLastCache = cache; + cache.addContent(g, data, start, end, x, y, color); + } + private static boolean spacesOnly(char[] chars, int start, int end) { for (int i = start; i < end; i++) { if (chars[i] != ' ') return false; @@ -3299,20 +3332,25 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi } } - class MyScrollBar extends JScrollBar { + class MyScrollBar extends JBScrollBar { @NonNls private static final String DECREASE_BUTTON_FIELD = "decrButton"; @NonNls private static final String INCREASE_BUTTON_FIELD = "incrButton"; @NonNls private static final String APPLE_LAF_AQUA_SCROLL_BAR_UI_CLASS = "apple.laf.AquaScrollBarUI"; + private ScrollBarUI myPersistentUI; private MyScrollBar(int orientation) { super(orientation); - setFocusable(false); - putClientProperty("JScrollBar.fastWheelScrolling", Boolean.TRUE); // fast scrolling for JDK 6 + } + + public void setPersistendUI(ScrollBarUI ui) { + myPersistentUI = ui; + setUI(ui); } @Override - public void updateUI() { - setUI(ButtonlessScrollBarUI.createNormal()); + public void setUI(ScrollBarUI ui) { + if (myPersistentUI == null) myPersistentUI = ui; + super.setUI(myPersistentUI); } /** @@ -4680,6 +4718,12 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi } private class MyScrollPane extends JBScrollPane { + + + private MyScrollPane() { + setViewportBorder(new EmptyBorder(0, 0, 0, 0)); + } + protected void processMouseWheelEvent(MouseWheelEvent e) { if (mySettings.isWheelFontChangeEnabled()) { boolean changeFontSize = SystemInfo.isMac @@ -4687,12 +4731,17 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi : e.isControlDown() && !e.isMetaDown() && !e.isAltDown() && !e.isShiftDown(); if (changeFontSize) { setFontSize(myScheme.getEditorFontSize() + e.getWheelRotation()); - return; + return; } } super.processMouseWheelEvent(e); } + + @Override + public JScrollBar createVerticalScrollBar() { + return new MyScrollBar(Adjustable.VERTICAL); + } } private class MyHeaderPanel extends JPanel { @@ -4718,4 +4767,11 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi myOldHeight = getHeight(); } } + + private class MyTextDrawingCallback implements TextDrawingCallback { + @Override + public void drawChars(Graphics g, char[] data, int start, int end, int x, int y, Color color, FontInfo fontInfo) { + drawCharsCached(g, data, start, end, x, y, fontInfo, color); + } + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMarkupModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMarkupModelImpl.java index 84da444eb270..d65e4641278d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMarkupModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMarkupModelImpl.java @@ -67,7 +67,6 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark private static final Icon ERRORS_FOUND_ICON = IconLoader.getIcon("/general/errorsFound.png"); private final EditorImpl myEditor; - private MyErrorPanel myErrorPanel; private ErrorStripeRenderer myErrorStripeRenderer = null; private final List myErrorMarkerListeners = new ArrayList(); private ErrorStripeListener[] myCachedErrorMarkerListeners = null; @@ -464,18 +463,16 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark public void setErrorStripeVisible(boolean val) { if (val) { - myErrorPanel = new MyErrorPanel(); - myEditor.getVerticalScrollBar().setUI(myErrorPanel); + myEditor.getVerticalScrollBar().setPersistendUI(new MyErrorPanel()); } - else if (myErrorPanel != null) { - myEditor.getVerticalScrollBar().setUI(ButtonlessScrollBarUI.createNormal()); - myErrorPanel = null; + else { + myEditor.getVerticalScrollBar().setPersistendUI(ButtonlessScrollBarUI.createNormal()); } } public void setErrorPanelPopupHandler(@NotNull PopupHandler handler) { - if (myErrorPanel != null) { - myErrorPanel.setPopupHandler(handler); + if (myEditor.getVerticalScrollBar().getUI() instanceof MyErrorPanel) { + ((MyErrorPanel)myEditor.getVerticalScrollBar().getUI()).setPopupHandler(handler); } } @@ -498,9 +495,7 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark myErrorStripeRenderer = renderer; //try to not cancel tooltips here, since it is being called after every writeAction, even to the console //HintManager.getInstance().getTooltipController().cancelTooltips(); - if (myErrorPanel != null) { - myErrorPanel.repaint(); - } + myEditor.getVerticalScrollBar().repaint(); } private void assertIsDispatchThread() { @@ -520,10 +515,7 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark markDirtied(); EditorImpl.MyScrollBar scrollBar = myEditor.getVerticalScrollBar(); myScrollBarHeight = scrollBar.getSize().height; - - if (myErrorPanel != null) { - myErrorPanel.repaint(); - } + scrollBar.repaint(); } private List getSortedHighlighters() { @@ -592,10 +584,6 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark private class MyErrorPanel extends ButtonlessScrollBarUI implements MouseMotionListener, MouseListener { private PopupHandler myHandler; - private MyErrorPanel() { - super(false); - } - @Override protected JButton createDecreaseButton(int orientation) { return new ErrorStripeButton(); @@ -609,9 +597,10 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark } @Override - public void installUI(JComponent c) { - c.putClientProperty("JComponent.sizeVariant", "large"); - super.installUI(c); + protected void uninstallListeners() { + scrollbar.removeMouseMotionListener(this); + scrollbar.removeMouseListener(this); + super.uninstallListeners(); } @Override @@ -745,10 +734,6 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark myHandler = handler; scrollbar.addMouseListener(handler); } - - public void repaint() { - scrollbar.repaint(); - } } private void showTooltip(MouseEvent e, final TooltipRenderer tooltipObject) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SettingsImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SettingsImpl.java index 17085851d78e..4967097f74c8 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SettingsImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SettingsImpl.java @@ -73,6 +73,7 @@ public class SettingsImpl implements EditorSettings { private Boolean myIsRenameVariablesInplace = null; private Boolean myIsRefrainFromScrolling = null; private Boolean myUseSoftWraps = null; + private Boolean myIsSoftWrapsShown = null; public boolean isRightMarginShown() { return myIsRightMarginShown != null @@ -396,6 +397,16 @@ public class SettingsImpl implements EditorSettings { fireEditorRefresh(); } + @Override + public boolean isSoftWrapsShown() { + return myIsSoftWrapsShown != null ? myIsWhitespacesShown.booleanValue() : EditorSettingsExternalizable.getInstance().isSoftWrapsShown(); + } + + @Override + public void setShowSoftWraps(boolean show) { + myIsWhitespacesShown = Boolean.valueOf(show); + } + private void fireEditorRefresh() { if (myEditor != null) { myEditor.reinitSettings(); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java index f7580cb0ca4f..a2b7733b7d6b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java @@ -23,7 +23,7 @@ import com.intellij.openapi.editor.event.VisibleAreaListener; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.editor.ex.SoftWrapModelEx; import com.intellij.openapi.editor.ex.util.EditorUtil; -import com.intellij.openapi.editor.impl.softwrap.SoftWrapsStorage; +import com.intellij.openapi.editor.impl.softwrap.*; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.text.CharArrayUtil; import gnu.trove.TIntHashSet; @@ -64,6 +64,7 @@ public class SoftWrapModelImpl implements SoftWrapModelEx { private final CharBuffer myCharBuffer = CharBuffer.allocate(1); private final SoftWrapsStorage myStorage; + private final SoftWrapPainter myPainter; /** * Holds logical lines where soft wraps should be removed. @@ -93,12 +94,13 @@ public class SoftWrapModelImpl implements SoftWrapModelEx { private int myActive; public SoftWrapModelImpl(@NotNull EditorEx editor) { - this(editor, new SoftWrapsStorage()); + this(editor, new SoftWrapsStorage(), new CompositeSoftWrapPainter(editor)); } - public SoftWrapModelImpl(@NotNull EditorEx editor, @NotNull SoftWrapsStorage storage) { + public SoftWrapModelImpl(@NotNull EditorEx editor, @NotNull SoftWrapsStorage storage, @NotNull SoftWrapPainter painter) { myEditor = editor; myStorage = storage; + myPainter = painter; } public boolean isSoftWrappingEnabled() { @@ -155,13 +157,16 @@ public class SoftWrapModelImpl implements SoftWrapModelEx { * Allows to answer if symbols of the given char array located at [start; end) interval should be soft wrapped, * i.e. represented on a next line. * - * @param chars symbols holder - * @param start target symbols sub-sequence start within the given char array (inclusive) - * @param end target symbols sub-sequence end within the given char array (exclusive) - * @param position current drawing position - * @return true if target symbols sub-sequence should be soft-wrapped; false otherwise + * @param g graphics buffer being used + * @param chars symbols holder + * @param start target symbols sub-sequence start within the given char array (inclusive) + * @param end target symbols sub-sequence end within the given char array (exclusive) + * @param x 'x' coordinate of the current drawing position + * @param onSoftWrapIntroducedVisualLine defines if current visual position belongs to soft wrap-introduced visual line + * @return true if target symbols sub-sequence should be soft-wrapped; + * false otherwise */ - public boolean shouldWrap(char[] chars, int start, int end, Point position) { + public boolean shouldWrap(@NotNull Graphics g, @NotNull char[] chars, int start, int end, int x, boolean onSoftWrapIntroducedVisualLine) { if (!isSoftWrappingEnabled()) { return false; } @@ -178,7 +183,11 @@ public class SoftWrapModelImpl implements SoftWrapModelEx { } //TODO den implement - return position.x + (end - start) * 7 > myRightEdgeLocation; + int xAfterCharsDrawing = x + myPainter.getMinDrawingWidth(SoftWrapDrawingType.BEFORE_SOFT_WRAP_LINE_FEED) + (end - start) * 7; + if (onSoftWrapIntroducedVisualLine) { + xAfterCharsDrawing += myPainter.getMinDrawingWidth(SoftWrapDrawingType.AFTER_SOFT_WRAP_LINE_FEED); + } + return xAfterCharsDrawing > myRightEdgeLocation; } private static boolean containsOnlyWhiteSpaces(char[] chars, int start, int end) { @@ -243,6 +252,11 @@ public class SoftWrapModelImpl implements SoftWrapModelEx { myDirtyLines.clear(); } + @Override + public int paint(@NotNull Graphics g, @NotNull SoftWrapDrawingType drawingType, int x, int y, int lineHeight) { + return myPainter.paint(g, drawingType, x, y, lineHeight); + } + @NotNull public LogicalPosition adjustLogicalPosition(@NotNull LogicalPosition defaultLogical, @NotNull VisualPosition visual) { if (myActive > 0 || !isSoftWrappingEnabled() || myStorage.isEmpty() || myEditor.getDocument().getTextLength() <= 0) { @@ -706,7 +720,7 @@ public class SoftWrapModelImpl implements SoftWrapModelEx { Document document = myEditor.getDocument(); - if (softWrapIndex >= softWraps.size() || document.getTextLength() <= 0) { + if (softWrapIndex >= softWraps.size() || document.getTextLength() <= 0 || change.getStart() >= document.getTextLength()) { return; } int firstChangedLine = document.getLineNumber(change.getStart()); @@ -723,7 +737,7 @@ public class SoftWrapModelImpl implements SoftWrapModelEx { // Add modified soft wraps. for (TextChange softWrap : toModify) { - softWraps.add(softWrap.advance(change.getDiff())); + myStorage.storeSoftWrap(softWrap.advance(change.getDiff())); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/TextDrawingCallback.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/TextDrawingCallback.java new file mode 100644 index 000000000000..45a7f3631636 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/TextDrawingCallback.java @@ -0,0 +1,48 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.editor.impl; + +import java.awt.*; + +/** + * IDEA editors use highly-optimized drawing algorithm that is tuned for painting large amounts of text data. + *

+ * However, there is a possible case that particular editor extension or third-party component may want to draw text at + * IDEA editor on it own. It's not supposed to do that directly, contrary, it's expected to delegate the processing + * to the code that knows how to do that. + *

+ * Current interface defines a contract for such a text drawing delegation task. + * + * @author Denis Zhdanov + * @since Jul 1, 2010 8:01:30 PM + */ +public interface TextDrawingCallback { + + /** + * Asks to draw symbols from [start; end) range of given char array at given graphics buffer using given + * font info and color. + * + * @param g graphics buffer to use + * @param data target symbols holder + * @param start start offset within the symbols holder to use (inclusive) + * @param end end offset within the symbols holder to use (inclusive) + * @param x 'x' coordinate to use as a start position at the given graphics buffer + * @param y 'y' coordinate to use as a start position at the given graphics buffer + * @param fontInfo font info to use during drawing target text at the given graphics buffer + * @param color color to use during drawing target text at the given graphics buffer + */ + void drawChars(Graphics g, char[] data, int start, int end, int x, int y, Color color, FontInfo fontInfo); +} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/ArrowSoftWrapPainter.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/ArrowSoftWrapPainter.java new file mode 100644 index 000000000000..eed5d982730d --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/ArrowSoftWrapPainter.java @@ -0,0 +1,105 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.editor.impl.softwrap; + +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.ex.util.EditorUtil; +import com.intellij.openapi.editor.impl.ArrowPainter; +import com.intellij.openapi.editor.impl.ColorHolder; +import com.intellij.openapi.util.Computable; +import org.jetbrains.annotations.NotNull; + +import java.awt.*; + +/** + * {@link SoftWrapPainter} implementation that draws arrows in soft wrap location. + *

+ * Primary idea is to use dedicated unicode symbols as soft wrap drawings and this class is introduced only as a part + * of defensive programming - there is unlikely case that local client environment doesn't have a font that is able to + * represent target unicode symbol. We draw an arrow manually then (platform-independent approach). + * + * @author Denis Zhdanov + * @since Jul 2, 2010 11:31:36 AM + */ +public class ArrowSoftWrapPainter implements SoftWrapPainter { + + private final HeightProvider myHeightProvider = new HeightProvider(); + private final Editor myEditor; + private final ArrowPainter myArrowPainter; + private int myMinWidth = -1; + + public ArrowSoftWrapPainter(Editor editor) { + myEditor = editor; + myArrowPainter = new ArrowPainter(ColorHolder.byColor(myEditor.getColorsScheme().getDefaultForeground()), myHeightProvider); + } + + @Override + public int paint(@NotNull Graphics g, @NotNull SoftWrapDrawingType drawingType, int x, int y, int lineHeight) { + myHeightProvider.myHeight = lineHeight / 2; + + int start; + int end; + int result; + switch (drawingType) { + case BEFORE_SOFT_WRAP_LINE_FEED: + start = x; + end = myEditor.getScrollingModel().getVisibleArea().width; + result = end - start; + break; + case AFTER_SOFT_WRAP_LINE_FEED: + start = 0; + end = x; + result = 0; + break; + default: throw new IllegalStateException("Soft wrap arrow painting is not set up for drawing type " + drawingType); + } + myArrowPainter.paint(g, y + lineHeight - g.getFontMetrics().getDescent(), start, end); + return result; + } + + @Override + public int getDrawingHorizontalOffset(@NotNull Graphics g, @NotNull SoftWrapDrawingType drawingType, int x, int y, int lineHeight) { + switch (drawingType) { + case BEFORE_SOFT_WRAP_LINE_FEED: return myEditor.getScrollingModel().getVisibleArea().width - x; + case AFTER_SOFT_WRAP_LINE_FEED: return 0; + default: throw new IllegalStateException("Soft wrap arrow painting is not set up for drawing type " + drawingType); + } + } + + @Override + public int getMinDrawingWidth(@NotNull SoftWrapDrawingType drawingType) { + if (myMinWidth < 0) { + // We need to reserve a minimal space required for representing arrow before soft wrap-introduced line feed. + myMinWidth = EditorUtil.charWidth('a', Font.PLAIN, myEditor); + } + return myMinWidth; + } + + @Override + public boolean canUse() { + return true; + } + + private static class HeightProvider implements Computable { + + public int myHeight; + + @Override + public Integer compute() { + return myHeight; + } + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/CompositeSoftWrapPainter.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/CompositeSoftWrapPainter.java new file mode 100644 index 000000000000..78be12630843 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/CompositeSoftWrapPainter.java @@ -0,0 +1,140 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.editor.impl.softwrap; + +import com.intellij.openapi.editor.LogicalPosition; +import com.intellij.openapi.editor.VisualPosition; +import com.intellij.openapi.editor.colors.EditorColors; +import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.openapi.editor.impl.ColorHolder; +import com.intellij.openapi.editor.impl.TextDrawingCallback; +import org.jetbrains.annotations.NotNull; + +import java.awt.*; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import static com.intellij.openapi.editor.impl.softwrap.SoftWrapDrawingType.AFTER_SOFT_WRAP_LINE_FEED; +import static com.intellij.openapi.editor.impl.softwrap.SoftWrapDrawingType.BEFORE_SOFT_WRAP_LINE_FEED; +import static java.util.Arrays.asList; + +/** + * Composite (in terms of GoF patterns) object for {@link SoftWrapPainter} objects. + *

+ * Not thread-safe. + * + * @author Denis Zhdanov + * @since Jul 2, 2010 10:20:14 AM + */ +public class CompositeSoftWrapPainter implements SoftWrapPainter { + + private static final List> SYMBOLS = asList( + asMap(asList(BEFORE_SOFT_WRAP_LINE_FEED, AFTER_SOFT_WRAP_LINE_FEED), + asList('\uE48B', '\uE48C')), + asMap(asList(BEFORE_SOFT_WRAP_LINE_FEED, AFTER_SOFT_WRAP_LINE_FEED), + asList('\u2926', '\u2925')), + asMap(asList(BEFORE_SOFT_WRAP_LINE_FEED, AFTER_SOFT_WRAP_LINE_FEED), + asList('\u21B2', '\u21B3')), + asMap(asList(BEFORE_SOFT_WRAP_LINE_FEED, AFTER_SOFT_WRAP_LINE_FEED), + asList('\u2936', '\u2937')), + asMap(asList(BEFORE_SOFT_WRAP_LINE_FEED, AFTER_SOFT_WRAP_LINE_FEED), + asList('\u21A9', '\u21AA')) + ); + + private final EditorEx myEditor; + private SoftWrapPainter myDelegate; + + /** + * There is a possible case that particular symbols configured to be used as a soft wrap drawings are not supported by + * available fonts. We would like to try another symbols then. + *

+ * Current field points to the index of symbols collection from {@link #SYMBOLS} tried last time. + */ + private int mySymbolsDrawingIndex = -1; + + public CompositeSoftWrapPainter(EditorEx editor) { + myEditor = editor; + } + + @Override + public int paint(@NotNull Graphics g, @NotNull SoftWrapDrawingType drawingType, int x, int y, int lineHeight) { + initDelegateIfNecessary(); + if (!myEditor.getSettings().isSoftWrapsShown()) { + int visualLine = y / lineHeight; + LogicalPosition position = myEditor.visualToLogicalPosition(new VisualPosition(visualLine, 0)); + if (position.line != myEditor.getCaretModel().getLogicalPosition().line) { + return myDelegate.getDrawingHorizontalOffset(g, drawingType, x, y, lineHeight); + } + } + return myDelegate.paint(g, drawingType, x, y, lineHeight); + } + + @Override + public int getDrawingHorizontalOffset(@NotNull Graphics g, @NotNull SoftWrapDrawingType drawingType, int x, int y, int lineHeight) { + initDelegateIfNecessary(); + return myDelegate.getDrawingHorizontalOffset(g, drawingType, x, y, lineHeight); + } + + @Override + public int getMinDrawingWidth(@NotNull SoftWrapDrawingType drawingType) { + initDelegateIfNecessary(); + return myDelegate.getMinDrawingWidth(drawingType); + } + + @Override + public boolean canUse() { + return true; + } + + private void initDelegateIfNecessary() { + if (myDelegate != null && myDelegate.canUse()) { + return; + } + if (++mySymbolsDrawingIndex < SYMBOLS.size()) { + TextDrawingCallback callback = myEditor.getTextDrawingCallback(); + ColorHolder colorHolder = ColorHolder.byColorsScheme(myEditor, EditorColors.RIGHT_MARGIN_COLOR); + myDelegate = new TextBasedSoftWrapPainter(SYMBOLS.get(mySymbolsDrawingIndex), myEditor, callback, colorHolder); + initDelegateIfNecessary(); + return; + } + myDelegate = new ArrowSoftWrapPainter(myEditor); + } + + private static Map asMap(Iterable keys, Iterable values) throws IllegalArgumentException { + Map result = new HashMap(); + Iterator keyIterator = keys.iterator(); + Iterator valueIterator = values.iterator(); + while (keyIterator.hasNext()) { + if (!valueIterator.hasNext()) { + throw new IllegalArgumentException( + String.format("Can't build for the given data. Reason: number of keys differs from number of values. " + + "Keys: %s, values: %s", keys, values) + ); + } + result.put(keyIterator.next(), valueIterator.next()); + } + + if (valueIterator.hasNext()) { + throw new IllegalArgumentException( + String.format("Can't build for the given data. Reason: number of keys differs from number of values. " + + "Keys: %s, values: %s", keys, values) + ); + } + return result; + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/SoftWrapDrawingType.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/SoftWrapDrawingType.java new file mode 100644 index 000000000000..1224006dc01d --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/SoftWrapDrawingType.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.editor.impl.softwrap; + +/** + * Enumerates types soft wrap-related drawings supported by {@link SoftWrapPainter}. + * + * @author Denis Zhdanov + * @since Jul 1, 2010 5:19:45 PM + */ +public enum SoftWrapDrawingType { + BEFORE_SOFT_WRAP_LINE_FEED, AFTER_SOFT_WRAP_LINE_FEED +} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/SoftWrapPainter.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/SoftWrapPainter.java new file mode 100644 index 000000000000..5233a63f56df --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/SoftWrapPainter.java @@ -0,0 +1,84 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.editor.impl.softwrap; + +import org.jetbrains.annotations.NotNull; + +import java.awt.*; + +/** + * Defines contract for the service that manages soft wrap-related graphical effects. + *

+ * For example we may want to draw an arrow just before and after soft wrap-introduced line feed: + *

+ *

+ *     This is a long text 
+ *         that is soft-wrapped
+ * 
+ *

+ * Implementations of this interface are not obliged to be thread-safe. + * + * @author Denis Zhdanov + * @since Jul 1, 2010 5:02:37 PM + */ +public interface SoftWrapPainter { + + /** + * Asks to paint drawing of target type at the given graphics buffer at the given position. + * + * @param g target graphics buffer to draw in + * @param drawingType target drawing type + * @param x target 'x' coordinate to use + * @param y target 'y' coordinate to use + * @param lineHeight line height used at editor + * @return horizontal offset introduced to the given 'x' coordinate after target drawing painting + */ + int paint(@NotNull Graphics g, @NotNull SoftWrapDrawingType drawingType, int x, int y, int lineHeight); + + /** + * Allows to ask about horizontal offset to be applied to the given 'x' coordinate if drawing of the given + * type is performed at the given graphics buffer. + *

+ * Generally, this method is useful when we don't want to perform actual drawing for now but want to reserve + * a space necessary to do that in future. I.e. the aim is to avoid horizontal movement of already drawn content + * when the drawing is actually performed. + * + * @param g target graphics buffer to draw in + * @param drawingType target drawing type + * @param x target 'x' coordinate to use + * @param y target 'y' coordinate to use + * @param lineHeight line height used at editor + * @return horizontal offset that would be introduced if the drawing is performed + */ + int getDrawingHorizontalOffset(@NotNull Graphics g, @NotNull SoftWrapDrawingType drawingType, int x, int y, int lineHeight); + + /** + * Allows to ask for the minimal width in pixels required for painting of the given type. + * + * @param drawingType target drawing type + * @return width in pixels required for the painting of the given type + */ + int getMinDrawingWidth(@NotNull SoftWrapDrawingType drawingType); + + /** + * Allows to answer if it's possible to use current painter implementation at local environment (e.g. there is a possible + * case that particular painter that exploits unicode symbols for drawing can't be used because there is no font + * at local environment that knows how to draw target symbols). + * + * @return true if current painter can be used at local environment; false otherwise + */ + boolean canUse(); +} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/TextBasedSoftWrapPainter.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/TextBasedSoftWrapPainter.java new file mode 100644 index 000000000000..fd68ccc36163 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/TextBasedSoftWrapPainter.java @@ -0,0 +1,116 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.editor.impl.softwrap; + +import com.intellij.openapi.editor.impl.ColorHolder; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.ex.util.EditorUtil; +import com.intellij.openapi.editor.impl.FontInfo; +import com.intellij.openapi.editor.impl.TextDrawingCallback; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.awt.*; +import java.util.EnumMap; +import java.util.Map; + +/** + * {@link SoftWrapPainter} implementation that uses target unicode symbols as soft wrap drawings. + *

+ * Not thread-safe. + * + * @author Denis Zhdanov + * @since Jul 1, 2010 5:30:43 PM + */ +public class TextBasedSoftWrapPainter implements SoftWrapPainter { + + private final Map mySymbols = new EnumMap(SoftWrapDrawingType.class); + private final Map myFonts = new EnumMap(SoftWrapDrawingType.class); + private final Map myWidths = new EnumMap(SoftWrapDrawingType.class); + private final Map myVGaps = new EnumMap(SoftWrapDrawingType.class); + + private final TextDrawingCallback myDrawingCallback; + private final ColorHolder myColorHolder; + private final boolean myCanUse; + + public TextBasedSoftWrapPainter(Map symbols, Editor editor, TextDrawingCallback drawingCallback, + ColorHolder colorHolder) + throws IllegalArgumentException + { + if (symbols.size() != SoftWrapDrawingType.values().length) { + throw new IllegalArgumentException( + String.format("Can't create text-based soft wrap painter. Reason: given 'drawing type -> symbol' mappings " + + "are incomplete - expected size %d but got %d (%s)", SoftWrapDrawingType.values().length, symbols.size(), symbols) + ); + } + myDrawingCallback = drawingCallback; + myColorHolder = colorHolder; + myCanUse = init(symbols, editor); + } + + @Override + public int paint(@NotNull Graphics g, @NotNull SoftWrapDrawingType drawingType, int x, int y, int lineHeight) { + char[] buffer = mySymbols.get(drawingType); + FontInfo fontInfo = myFonts.get(drawingType); + int vGap = myVGaps.get(drawingType); + myDrawingCallback.drawChars(g, buffer, 0, buffer.length, x, y + lineHeight - vGap, myColorHolder.getColor(), fontInfo); + return getMinDrawingWidth(drawingType); + } + + @Override + public int getDrawingHorizontalOffset(@NotNull Graphics g, @NotNull SoftWrapDrawingType drawingType, int x, int y, int lineHeight) { + return getMinDrawingWidth(drawingType); + } + + @Override + public int getMinDrawingWidth(@NotNull SoftWrapDrawingType drawingType) { + return myWidths.get(drawingType); + } + + @Override + public boolean canUse() { + return myCanUse; + } + + /** + * Tries to find fonts that are capable to display all unicode symbols used by the current painter. + * + * @param symbols target symbols to use for drawing + * @param editor editor to use during font lookup + * @return true if target font that is capable to display all unicode symbols used by the current painter is found; + * false otherwise + */ + private boolean init(Map symbols, Editor editor) { + // We use dummy component here in order to being able to work with font metrics. + JLabel component = new JLabel(); + + for (Map.Entry entry : symbols.entrySet()) { + FontInfo fontInfo = EditorUtil.fontForChar(entry.getValue(), Font.PLAIN, editor); + if (!fontInfo.canDisplay(entry.getValue())) { + return false; + } + char[] buffer = new char[1]; + buffer[0] = entry.getValue(); + mySymbols.put(entry.getKey(), buffer); + myFonts.put(entry.getKey(), fontInfo); + FontMetrics metrics = component.getFontMetrics(fontInfo.getFont()); + myWidths.put(entry.getKey(), metrics.charWidth(buffer[0])); + int vGap = metrics.getDescent(); + myVGaps.put(entry.getKey(), vGap); + } + return true; + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditorContext.java b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditorContext.java index 323c8952a4ca..d6f85b3c6fd1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditorContext.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditorContext.java @@ -142,7 +142,7 @@ public class OptionsEditorContext { public Collection getChildren(final Configurable parent) { Collection result = myParentToChildrenMap.get(parent); - return result == null ? Collections.EMPTY_SET : result; + return result == null ? Collections.emptySet() : result; } interface ColleagueAction { diff --git a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java index 36b30d025a66..8741204fcec7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java @@ -490,7 +490,7 @@ public class OptionsTree extends JPanel implements Disposable, OptionsEditorColl return result; // TODO: DECIDE IF INNERS SHOULD BE SORTED: sort(result); } else { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java index f39fae603943..fc25cc78b99f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java @@ -126,23 +126,26 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Ap } @TestOnly - public void cleanupForNextTest() throws IOException { + public void cleanupForNextTest(Set survivors) throws IOException { ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { FileDocumentManager.getInstance().saveAllDocuments(); - refresh(false); } }); ((PersistentFS)ManagingFS.getInstance()).clearIdCache(); - - final VirtualFile[] roots = ManagingFS.getInstance().getRoots(this); - for (VirtualFile root : roots) { + + for (VirtualFile root : ManagingFS.getInstance().getRoots(this)) { if (root instanceof VirtualDirectoryImpl) { - final VirtualDirectoryImpl directory = (VirtualDirectoryImpl)root; - directory.cleanupCachedChildren(); + ((VirtualDirectoryImpl)root).cleanupCachedChildren(survivors); } } + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + refresh(false); + } + }); + myRootsToWatch.clear(); final File file = new File(FileUtil.getTempDirectory()); diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java index f04cd9ac6405..33847fc44028 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java @@ -360,7 +360,15 @@ public class VirtualDirectoryImpl extends VirtualFileSystemEntry { } @TestOnly - public synchronized void cleanupCachedChildren() { + public synchronized void cleanupCachedChildren(Set survivors) { + /*if (survivors.contains(this)) { + for (VirtualFile file : getCachedChildren()) { + if (file instanceof VirtualDirectoryImpl) { + ((VirtualDirectoryImpl)file).cleanupCachedChildren(survivors); + } + } + } else { + }*/ myChildren = null; } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java index f86abc0c1b11..ef570c6722fb 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java @@ -52,8 +52,8 @@ import java.awt.*; import java.awt.event.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.util.*; import java.util.List; +import java.util.Map; /** * @author Eugene Belyaev @@ -191,7 +191,7 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa myInfo = info; // Active final boolean active = info.isActive(); - myTitlePanel.setActive(active, !info.isSliding()); + myTitlePanel.setActive(active); //todo myToolWindowBorder.setActive(active); myFloatingDockSeparator.setActive(active); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/TitlePanel.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/TitlePanel.java index 51c5201d6ba6..2267ce00a4ae 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/TitlePanel.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/TitlePanel.java @@ -17,7 +17,7 @@ package com.intellij.openapi.wm.impl; import com.intellij.openapi.util.IconLoader; import com.intellij.ui.components.panels.NonOpaquePanel; -import com.intellij.util.Alarm; +import com.intellij.util.ui.SameColor; import com.intellij.util.ui.UIUtil; import javax.swing.*; @@ -29,32 +29,20 @@ import java.awt.*; * @author Vladimir Kondratyev */ public final class TitlePanel extends JPanel { - private static final int DELAY = 5; // Delay between frames - private static final int TOTAL_FRAME_COUNT = 7; // Total number of frames in animation sequence + private static final Color CNT_COLOR = new SameColor(184); + private static final Color BND_COLOR = CNT_COLOR; - private int myCurrentFrame; + public static final Color CNT_ACTIVE_COLOR = new Color(105, 128, 180); + public static final Color BND_ACTIVE_COLOR = CNT_ACTIVE_COLOR.brighter(); - public final static Color CNT_ENABLE_COLOR = new Color(105, 128, 180); - public final static Color BND_ENABLE_COLOR = CNT_ENABLE_COLOR.brighter(); + /* Gray-ish colors + public static final Color CNT_ACTIVE_COLOR = new SameColor(120); + public static final Color BND_ACTIVE_COLOR = new SameColor(160); + */ - private final static Color BND_DISABLE_COLOR = new Color(184, 184, 184); //new Color(160, 160, 160); - private final static Color CNT_DISABLE_COLOR = new Color(184, 184, 184); - - - private float myBndStartRed, myBndStartGreen, myBndStartBlue; // start boundary color for animation - private float myBndEndRed, myBndEndGreen, myBndEndBlue; // end boundary color for animation - private Color myBndColor; // current boundary color - - private float myCntStartRed, myCntStartGreen, myCntStartBlue; // start center color for animation - private float myCntEndRed, myCntEndGreen, myCntEndBlue; // end center color for animation - private Color myCntColor; // current center color - - private final Alarm myFrameTicker; // Determines moments of rendering of next frame - private final MyAnimator myAnimator; // Renders panel's color private boolean myActive = true; private JComponent mySideButtons; - public static final Color BUTTON_SEPARATOR_COLOR = Color.white; private final Icon mySeparatorActive = IconLoader.getIcon("/general/separator.png"); private final Icon mySeparatorInactive = IconLoader.getIcon("/general/inactiveSeparator.png"); @@ -64,15 +52,6 @@ public final class TitlePanel extends JPanel { TitlePanel() { super(new BorderLayout()); - - myFrameTicker = new Alarm(); - myAnimator = new MyAnimator(); - setLayout(new BorderLayout()); - - setupColors(false); - - myCurrentFrame = TOTAL_FRAME_COUNT; - updateColor(); } @@ -80,97 +59,15 @@ public final class TitlePanel extends JPanel { add(component, BorderLayout.CENTER); } - public final void setActive(final boolean active, boolean animate) { + public final void setActive(final boolean active) { if (active == myActive) { return; } myActive = active; - myFrameTicker.cancelAllRequests(); - if (myCurrentFrame > 0) { // reverse rendering - myCurrentFrame = TOTAL_FRAME_COUNT - myCurrentFrame; - } - - setupColors(active); - - if (animate) { - myFrameTicker.addRequest(myAnimator, DELAY); - } - else { - myCurrentFrame = TOTAL_FRAME_COUNT; - updateColor(); - } + repaint(); } - private void setupColors(final boolean active) { - if (active) { - - // Boundary color - - myBndStartRed = BND_DISABLE_COLOR.getRed(); - myBndStartGreen = BND_DISABLE_COLOR.getGreen(); - myBndStartBlue = BND_DISABLE_COLOR.getBlue(); - - myBndEndRed = BND_ENABLE_COLOR.getRed(); - myBndEndGreen = BND_ENABLE_COLOR.getGreen(); - myBndEndBlue = BND_ENABLE_COLOR.getBlue(); - - // Center color - - myCntStartRed = CNT_DISABLE_COLOR.getRed(); - myCntStartGreen = CNT_DISABLE_COLOR.getGreen(); - myCntStartBlue = CNT_DISABLE_COLOR.getBlue(); - - myCntEndRed = CNT_ENABLE_COLOR.getRed(); - myCntEndGreen = CNT_ENABLE_COLOR.getGreen(); - myCntEndBlue = CNT_ENABLE_COLOR.getBlue(); - } - else { - - // Boundary color - - myBndStartRed = BND_ENABLE_COLOR.getRed(); - myBndStartGreen = BND_ENABLE_COLOR.getGreen(); - myBndStartBlue = BND_ENABLE_COLOR.getBlue(); - - myBndEndRed = BND_DISABLE_COLOR.getRed(); - myBndEndGreen = BND_DISABLE_COLOR.getGreen(); - myBndEndBlue = BND_DISABLE_COLOR.getBlue(); - - // Center color - - myCntStartRed = CNT_ENABLE_COLOR.getRed(); - myCntStartGreen = CNT_ENABLE_COLOR.getGreen(); - myCntStartBlue = CNT_ENABLE_COLOR.getBlue(); - - myCntEndRed = CNT_DISABLE_COLOR.getRed(); - myCntEndGreen = CNT_DISABLE_COLOR.getGreen(); - myCntEndBlue = CNT_DISABLE_COLOR.getBlue(); - } - } - - private void updateColor() { - - // Update boundary color - - final int bndRed = (int) (myBndStartRed + (float) myCurrentFrame * (myBndEndRed - myBndStartRed) / TOTAL_FRAME_COUNT); - final int bndGreen = (int) (myBndStartGreen + (float) myCurrentFrame * (myBndEndGreen - myBndStartGreen) / TOTAL_FRAME_COUNT); - final int bndBlue = (int) (myBndStartBlue + (float) myCurrentFrame * (myBndEndBlue - myBndStartBlue) / TOTAL_FRAME_COUNT); - myBndColor = new Color(Math.max(0, Math.min(bndRed, 255)), - Math.max(0, Math.min(bndGreen, 255)), - Math.max(0, Math.min(bndBlue, 255))); - - // Update center color - - final int cntRed = (int) (myCntStartRed + (float) myCurrentFrame * (myCntEndRed - myCntStartRed) / TOTAL_FRAME_COUNT); - final int cntGreen = (int) (myCntStartGreen + (float) myCurrentFrame * (myCntEndGreen - myCntStartGreen) / TOTAL_FRAME_COUNT); - final int cntBlue = (int) (myCntStartBlue + (float) myCurrentFrame * (myCntEndBlue - myCntStartBlue) / TOTAL_FRAME_COUNT); - myCntColor = new Color(Math.max(0, Math.min(cntRed, 255)), - Math.max(0, Math.min(cntGreen, 255)), - Math.max(0, Math.min(cntBlue, 255))); - } - - @Override protected void addImpl(Component comp, Object constraints, int index) { UIUtil.removeQuaquaVisualMarginsIn(comp); @@ -183,7 +80,10 @@ public final class TitlePanel extends JPanel { final Graphics2D g2d = (Graphics2D) g; - g2d.setPaint(new GradientPaint(0, STRUT, myBndColor, 0, getHeight(), myCntColor)); + Color bndColor = myActive ? BND_ACTIVE_COLOR : BND_COLOR; + Color cntColor = myActive ? CNT_ACTIVE_COLOR : CNT_COLOR; + + g2d.setPaint(new GradientPaint(0, STRUT, bndColor, 0, getHeight(), cntColor)); if (mySideButtons.isVisible()) { final Rectangle sideRec = SwingUtilities.convertRectangle(mySideButtons.getParent(), mySideButtons.getBounds(), this); g2d.fillRect(0, STRUT, getWidth() - sideRec.width, getHeight()); @@ -201,9 +101,6 @@ public final class TitlePanel extends JPanel { g2d.fillRect(0, STRUT, getWidth(), getHeight()); } } - public JComponent getSideButtonsComponent() { - return mySideButtons; - } public void addButtons(final JComponent buttons, JComponent sideButtons) { mySideButtons = sideButtons; @@ -224,19 +121,4 @@ public final class TitlePanel extends JPanel { add(wrapper, BorderLayout.EAST); } - - private final class MyAnimator implements Runnable { - public void run() { - updateColor(); - paintImmediately(0, 0, getWidth(), getHeight()); - if (myCurrentFrame <= TOTAL_FRAME_COUNT) { - myCurrentFrame++; - myFrameTicker.addRequest(this, DELAY); - } - else { - myFrameTicker.cancelAllRequests(); - } - } - } - } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InfoAndProgressPanel.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InfoAndProgressPanel.java index 31e6f63d633a..5c3f01c4c1a6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InfoAndProgressPanel.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InfoAndProgressPanel.java @@ -457,46 +457,46 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge setLayout(new BorderLayout()); add(myRefreshAndInfoPanel, BorderLayout.CENTER); - long wastedTime = ProgressManagerImpl.getWastedTime(); - if (ApplicationManagerEx.getApplicationEx().isInternal() && wastedTime > 10 * 60 * 1000) { - JPanel wrapper = new JPanel(new BorderLayout()); - wrapper.setOpaque(false); - JLabel label = new JLabel(" Wasted time: " + formatTime(wastedTime) + " "); - label.setForeground(UIUtil.getPanelBackground().darker()); - label.setOpaque(false); - wrapper.add(label, BorderLayout.CENTER); - wrapper.add(myProgressIcon, BorderLayout.EAST); - - long time = System.currentTimeMillis() - ApplicationManagerEx.getApplicationEx().getStartTime(); - long percentage = wastedTime * 100 / time; - String period = new SimpleDateFormat("m 'min' H 'hours'").format(new Date(2000, 0, 1, 0, 0, 0).getTime() + time); - - List> list = ProgressManagerImpl.getTimeWasters(); - StringBuilder s = new StringBuilder("Successfully wasted " + percentage +"% of your time in " + period + ":
"); - for (Pair each : list) { - s.append(""); - s.append(each.first); - s.append(":"); - s.append(formatTime(each.second)); - s.append(""); - } - s.append(""); - wrapper.setToolTipText(s.toString()); - add(wrapper, BorderLayout.EAST); - } else { + //long wastedTime = ProgressManagerImpl.getWastedTime(); + //if (ApplicationManagerEx.getApplicationEx().isInternal() && wastedTime > 10 * 60 * 1000) { + // JPanel wrapper = new JPanel(new BorderLayout()); + // wrapper.setOpaque(false); + // JLabel label = new JLabel(" Wasted time: " + formatTime(wastedTime) + " "); + // label.setForeground(UIUtil.getPanelBackground().darker()); + // label.setOpaque(false); + // wrapper.add(label, BorderLayout.CENTER); + // wrapper.add(myProgressIcon, BorderLayout.EAST); + // + // long time = System.currentTimeMillis() - ApplicationManagerEx.getApplicationEx().getStartTime(); + // long percentage = wastedTime * 100 / time; + // String period = new SimpleDateFormat("m 'min' H 'hours'").format(new Date(2000, 0, 1, 0, 0, 0).getTime() + time); + // + // List> list = ProgressManagerImpl.getTimeWasters(); + // StringBuilder s = new StringBuilder("Successfully wasted " + percentage +"% of your time in " + period + ":
"); + // for (Pair each : list) { + // s.append(""); + // s.append(each.first); + // s.append(":"); + // s.append(formatTime(each.second)); + // s.append(""); + // } + // s.append(""); + // wrapper.setToolTipText(s.toString()); + // add(wrapper, BorderLayout.EAST); + //} else { add(myProgressIcon, BorderLayout.EAST); - } + //} myProgressIcon.suspend(); myRefreshAndInfoPanel.revalidate(); myRefreshAndInfoPanel.repaint(); } - private String formatTime(long t) { - if (t < 1000) return "< 1 sec"; - if (t < 60 * 1000) return (t / 1000) + " sec"; - return "~" + (int)Math.ceil(t / (60 * 1000f)) + " min"; - } + //private String formatTime(long t) { + // if (t < 1000) return "< 1 sec"; + // if (t < 60 * 1000) return (t / 1000) + " sec"; + // return "~" + (int)Math.ceil(t / (60 * 1000f)) + " min"; + //} public boolean isProcessWindowOpen() { return myPopup.isShowing(); diff --git a/platform/platform-impl/testSrc/com/intellij/openapi/editor/impl/SoftWrapModelImplTest.java b/platform/platform-impl/testSrc/com/intellij/openapi/editor/impl/SoftWrapModelImplTest.java index d1c97b570825..d85bee6e0b7f 100644 --- a/platform/platform-impl/testSrc/com/intellij/openapi/editor/impl/SoftWrapModelImplTest.java +++ b/platform/platform-impl/testSrc/com/intellij/openapi/editor/impl/SoftWrapModelImplTest.java @@ -18,6 +18,7 @@ package com.intellij.openapi.editor.impl; import com.intellij.mock.MockFoldRegion; import com.intellij.openapi.editor.*; import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.openapi.editor.impl.softwrap.SoftWrapPainter; import com.intellij.openapi.editor.impl.softwrap.SoftWrapsStorage; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; @@ -191,7 +192,9 @@ public class SoftWrapModelImplTest { }); }}); - myModel = new SoftWrapModelImpl(myEditor, myStorage); + SoftWrapPainter painter = myMockery.mock(SoftWrapPainter.class); + + myModel = new SoftWrapModelImpl(myEditor, myStorage, painter); } @After diff --git a/platform/platform-resources-en/src/messages/ApplicationBundle.properties b/platform/platform-resources-en/src/messages/ApplicationBundle.properties index 8676e25d3ca4..48fdec32a60c 100644 --- a/platform/platform-resources-en/src/messages/ApplicationBundle.properties +++ b/platform/platform-resources-en/src/messages/ApplicationBundle.properties @@ -262,6 +262,7 @@ tab.editor.settings.appearance=Appearance groupbox.display=Display checkbox.smooth.scrolling=Smooth scrolling checkbox.show.whitespaces=Show whitespaces +checkbox.show.softwraps=Show soft wraps checkbox.show.method.separators=Show method separators checkbox.show.small.icons.in.gutter=Show icons preview in gutter for small icons (Java) checkbox.show.line.numbers=Show line numbers diff --git a/platform/platform-resources-en/src/messages/XmlErrorMessages.properties b/platform/platform-resources-en/src/messages/XmlErrorMessages.properties index aa342d7436e5..af35e58f9cee 100644 --- a/platform/platform-resources-en/src/messages/XmlErrorMessages.properties +++ b/platform/platform-resources-en/src/messages/XmlErrorMessages.properties @@ -72,3 +72,5 @@ xml.parsing.unterminated.processing.instruction=Processing instruction not termi xml.parsing.closing.tag.matches.nothing=Closing tag matches nothing xml.parsing.closing.tag.name.missing=Closing tag name missing xml.parsing.closing.tag.is.not.done=Closing tag is not done +attribute.should.be.preceded.with.space=There should be a space between attribute and previous attribute +cdata.end.should.not.appear.in.content.unless.to.mark.end.of.cdata.section=Character sequence ']]>' must not appear in content unless used to mark the end of a CDATA section diff --git a/platform/testFramework/src/com/intellij/FileSetTestCase.java b/platform/testFramework/src/com/intellij/FileSetTestCase.java index 5b81b9543533..c197b1bbca44 100644 --- a/platform/testFramework/src/com/intellij/FileSetTestCase.java +++ b/platform/testFramework/src/com/intellij/FileSetTestCase.java @@ -18,10 +18,12 @@ import junit.framework.TestSuite; import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; public abstract class FileSetTestCase extends TestSuite { private final File[] myFiles; protected Project myProject; + private Pattern myPattern; public FileSetTestCase(String path) { File f = new File(path); @@ -35,7 +37,8 @@ public abstract class FileSetTestCase extends TestSuite { throw new IllegalArgumentException("invalid path: " + path); } - + final String pattern = System.getProperty("fileset.pattern"); + myPattern = pattern != null ? Pattern.compile(pattern) : null; addAllTests(); } @@ -68,6 +71,9 @@ public abstract class FileSetTestCase extends TestSuite { private void addFileTest(File file) { if (!StringUtil.startsWithChar(file.getName(), '_') && !"CVS".equals(file.getName())) { + if (myPattern != null && !myPattern.matcher(file.getPath()).matches()){ + return; + } final ActualTest t = new ActualTest(file); addTest(t); } diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java index 6139fac76449..7f6f7110b0b0 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java @@ -53,6 +53,7 @@ import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.impl.VirtualFilePointerManagerImpl; import com.intellij.openapi.vfs.impl.local.LocalFileSystemImpl; import com.intellij.openapi.vfs.newvfs.ManagingFS; +import com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl; import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS; import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager; import com.intellij.psi.PsiDocumentManager; @@ -62,6 +63,8 @@ import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; import com.intellij.psi.impl.PsiManagerEx; import com.intellij.util.PatchedWeakReference; +import com.intellij.util.indexing.IndexableSetContributor; +import com.intellij.util.indexing.IndexedRootsProvider; import junit.framework.TestCase; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; @@ -72,7 +75,9 @@ import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; +import java.util.Set; /** * @author yole @@ -96,6 +101,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro private ThreadTracker myThreadTracker; protected static boolean ourPlatformPrefixInitialized; + private static Set ourEternallyLivingFiles; static { Logger.setFactory(TestLoggerFactory.getInstance()); @@ -267,7 +273,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro try { LocalFileSystemImpl localFileSystem = (LocalFileSystemImpl)LocalFileSystem.getInstance(); if (localFileSystem != null) { - localFileSystem.cleanupForNextTest(); + localFileSystem.cleanupForNextTest(Collections.emptySet()); } } catch (IOException e) { @@ -283,6 +289,35 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro PatchedWeakReference.clearAll(); } + private static void addSubTree(VirtualFile root, Set to) { + if (root instanceof VirtualDirectoryImpl) { + for (VirtualFile child : ((VirtualDirectoryImpl)root).getCachedChildren()) { + to.add(child); + addSubTree(child, to); + } + } + } + + private static Set eternallyLivingFiles() { + if (ourEternallyLivingFiles != null) { + return ourEternallyLivingFiles; + } + + Set survivors = new HashSet(); + + for (IndexedRootsProvider provider : IndexedRootsProvider.EP_NAME.getExtensions()) { + for (VirtualFile file : IndexableSetContributor.getRootsToIndex(provider)) { + addSubTree(file, survivors); + while (file != null && survivors.add(file)) { + file = file.getParent(); + } + } + } + + ourEternallyLivingFiles = survivors; + return survivors; + } + protected void tearDown() throws Exception { LightPlatformTestCase.doTearDown(getProject(), ourApplication, false); diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index f017ac8a85a3..6bf2e3d1052f 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -838,6 +838,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig configureInspections(myInspections == null ? new LocalInspectionTool[0] : myInspections); DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false); DaemonCodeAnalyzer.getInstance(getProject()).setUpdateByTimerEnabled(false); + ensureIndexesUpToDate(getProject()); } private void enableInspectionTool(InspectionProfileEntry tool){ @@ -1188,7 +1189,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig } } - private static void ensureIndexesUpToDate(Project project) { + public static void ensureIndexesUpToDate(Project project) { FileBasedIndex.getInstance().ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, null); FileBasedIndex.getInstance().ensureUpToDate(TodoIndex.NAME, project, null); assertTrue(!DumbServiceImpl.getInstance(project).isDumb()); diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/ModuleFixtureBuilderImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/ModuleFixtureBuilderImpl.java index 9bcc3827b482..b9822cc970e4 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/ModuleFixtureBuilderImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/ModuleFixtureBuilderImpl.java @@ -62,7 +62,7 @@ public abstract class ModuleFixtureBuilderImpl implemen } public ModuleFixtureBuilder addSourceRoot(final String sourceRootPath) { - assert myContentRoots.size() > 0 : "content root should be added first"; + assert !myContentRoots.isEmpty() : "content root should be added first"; mySourceRoots.add(sourceRootPath); return this; } @@ -101,7 +101,7 @@ public abstract class ModuleFixtureBuilderImpl implemen protected abstract T instantiateFixture(); Module buildModule() { - final Module[] module = new Module[]{null}; + final Module[] module = {null}; ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { diff --git a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java index 68c6ff4e95f9..538ec7bc0d67 100644 --- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java +++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java @@ -890,7 +890,7 @@ public class StringUtil { if (separator.length() == 0) { return Collections.singletonList(s); } - ArrayList result = new ArrayList(); + List result = new ArrayList(); int pos = 0; while (true) { int index = s.indexOf(separator, pos); diff --git a/platform/util/src/com/intellij/util/QueryExecutor.java b/platform/util/src/com/intellij/util/QueryExecutor.java index c9919b9733eb..4f196c06e6bb 100644 --- a/platform/util/src/com/intellij/util/QueryExecutor.java +++ b/platform/util/src/com/intellij/util/QueryExecutor.java @@ -16,6 +16,8 @@ package com.intellij.util; /** + * Consider extending {@link com.intellij.openapi.application.QueryExecutorBase} instead unless you know what you're doing. + * * @author max */ public interface QueryExecutor { diff --git a/platform/util/testSrc/com/intellij/util/containers/ContainerUtilTest.java b/platform/util/testSrc/com/intellij/util/containers/ContainerUtilTest.java index 29cdef3c8cc0..d207334cf58c 100644 --- a/platform/util/testSrc/com/intellij/util/containers/ContainerUtilTest.java +++ b/platform/util/testSrc/com/intellij/util/containers/ContainerUtilTest.java @@ -20,23 +20,20 @@ import com.intellij.openapi.util.Condition; import java.util.*; -import static org.junit.Assert.assertEquals; - public class ContainerUtilTest extends junit.framework.TestCase { public void testFindInstanceOf() { - Iterator iterator = Arrays.asList(new Object[]{new Integer(1), new ArrayList(), "1"}).iterator(); - String string = (String)com.intellij.util.containers.ContainerUtil - .find(iterator, com.intellij.util.containers.FilteringIterator.instanceOf(String.class)); + Iterator iterator = Arrays.asList(new Integer(1), new ArrayList(), "1").iterator(); + String string = (String)ContainerUtil.find(iterator, FilteringIterator.instanceOf(String.class)); junit.framework.Assert.assertEquals("1", string); } public void testConcatMulti() { - List l = ContainerUtil.concat(Arrays.asList(1, 2), Collections.EMPTY_LIST, Arrays.asList(3, 4)); + List l = ContainerUtil.concat(Arrays.asList(1, 2), Collections.EMPTY_LIST, Arrays.asList(3, 4)); assertEquals(4, l.size()); - assertEquals(1, l.get(0)); - assertEquals(2, l.get(1)); - assertEquals(3, l.get(2)); - assertEquals(4, l.get(3)); + assertEquals(1, (int)l.get(0)); + assertEquals(2, (int)l.get(1)); + assertEquals(3, (int)l.get(2)); + assertEquals(4, (int)l.get(3)); try { l.get(-1); @@ -66,7 +63,7 @@ public class ContainerUtilTest extends junit.framework.TestCase { asserIterating(Arrays.asList(4), cond, 4); } - private void asserIterating(List collection, Condition condition, Integer... expected) { + private static void asserIterating(List collection, Condition condition, Integer... expected) { Iterable it = ContainerUtil.iterate(collection, condition); List actual = new ArrayList(); for (Integer each : it) { diff --git a/platform/util/testSrc/com/intellij/util/containers/WeakListTest.java b/platform/util/testSrc/com/intellij/util/containers/WeakListTest.java index 498e644ef2d4..a82cc3d5b5e9 100644 --- a/platform/util/testSrc/com/intellij/util/containers/WeakListTest.java +++ b/platform/util/testSrc/com/intellij/util/containers/WeakListTest.java @@ -21,23 +21,24 @@ import junit.framework.Assert; import java.util.Iterator; public class WeakListTest extends WeaksTestCase { - private final com.intellij.util.containers.WeakReferenceArray myWeakArray = new com.intellij.util.containers.WeakReferenceArray(); - private final com.intellij.util.containers.WeakList myWeakList = new com.intellij.util.containers.WeakList(myWeakArray); + private final WeakReferenceArray myWeakArray = new WeakReferenceArray(); + private final WeakList myWeakList = new WeakList(myWeakArray); protected void setUp() throws Exception { super.setUp(); - Assert.assertTrue(com.intellij.util.containers.WeakReferenceArray.PEFORM_CHECK_THREAD); - com.intellij.util.containers.WeakReferenceArray.PEFORM_CHECK_THREAD = false; + Assert.assertTrue(WeakReferenceArray.PEFORM_CHECK_THREAD); + WeakReferenceArray.PEFORM_CHECK_THREAD = false; } protected void tearDown() throws Exception { - com.intellij.util.containers.WeakReferenceArray.PEFORM_CHECK_THREAD = true; + WeakReferenceArray.PEFORM_CHECK_THREAD = true; super.tearDown(); } public void testCompresses() { - for (int i = 0; i < 20; i++) + for (int i = 0; i < 20; i++) { addElement(new Object(), myWeakArray); + } Assert.assertEquals(20, myWeakList.size()); checkSameElements(myWeakArray); String obj = "xxx"; @@ -46,10 +47,10 @@ public class WeakListTest extends WeaksTestCase { checkSameElements(myWeakArray); myHolder.clear(); gc(); - Assert.assertEquals(21, myWeakList.size()); - Assert.assertEquals(20, myWeakArray.getCorpseCount()); + assertEquals(21, myWeakList.size()); + assertTrue(20 >= myWeakArray.getCorpseCount()); myWeakList.add(new Object()); - Assert.assertTrue(String.valueOf(myWeakList.size()), myWeakList.size() < 20); + assertTrue(String.valueOf(myWeakList.size()), myWeakList.size() <= 22); gc(); myHolder.add(obj); checkSameNotNulls(myWeakArray); @@ -61,14 +62,13 @@ public class WeakListTest extends WeaksTestCase { myWeakArray.add(new Object()); addElement(new Object(), myWeakArray); gc(); - Assert.assertEquals(2, myWeakArray.getAliveCount()); + assertTrue(2 <= myWeakArray.getAliveCount()); int elementCount = 0; - for (Iterator iterator = myWeakList.iterator(); iterator.hasNext();) { - Object element = iterator.next(); - Assert.assertNotNull(element); + for (Object element : myWeakList) { + assertNotNull(element); elementCount++; } - Assert.assertEquals(2, elementCount); + assertEquals(2, elementCount); } public void testRemoveViaIterator() { @@ -77,19 +77,19 @@ public class WeakListTest extends WeaksTestCase { addElement(new Object(), myWeakArray); myWeakArray.add(new Object()); addElement(new Object(), myWeakArray); - Iterator iterator = myWeakList.iterator(); - Assert.assertSame(myHolder.get(0), iterator.next()); + Iterator iterator = myWeakList.iterator(); + assertSame(myHolder.get(0), iterator.next()); while (myHolder.get(1) != iterator.next()); gc(); - Assert.assertEquals(4, myWeakArray.getAliveCount()); + assertTrue(4 <= myWeakArray.getAliveCount()); iterator.remove(); gc(); - Assert.assertEquals(3, myWeakArray.getAliveCount()); + assertTrue(3 <= myWeakArray.getAliveCount()); iterator.next(); gc(); - Assert.assertEquals(2, myWeakArray.getAliveCount()); - Assert.assertSame(myHolder.get(2), iterator.next()); - Assert.assertFalse(iterator.hasNext()); + assertTrue(2 <= myWeakArray.getAliveCount()); + assertSame(myHolder.get(2), iterator.next()); + assertFalse(iterator.hasNext()); myHolder.remove(1); checkSameNotNulls(myWeakArray); myWeakArray.compress(-1); @@ -99,13 +99,13 @@ public class WeakListTest extends WeaksTestCase { public void testRemoveLastViaIterator() { addElement(new Object(), myWeakArray); addElement(new Object(), myWeakArray); - Iterator iterator = myWeakList.iterator(); + Iterator iterator = myWeakList.iterator(); iterator.next(); - Assert.assertTrue(iterator.hasNext()); + assertTrue(iterator.hasNext()); iterator.next(); - Assert.assertFalse(iterator.hasNext()); + assertFalse(iterator.hasNext()); iterator.remove(); - Assert.assertFalse(iterator.hasNext()); + assertFalse(iterator.hasNext()); myHolder.remove(1); checkSameNotNulls(myWeakArray); } @@ -113,24 +113,24 @@ public class WeakListTest extends WeaksTestCase { public void testIteratorKeepsFirstElement() { addElement(new Object(), myWeakArray); addElement(new Object(), myWeakArray); - Iterator iterator = myWeakList.iterator(); - Assert.assertTrue(iterator.hasNext()); + Iterator iterator = myWeakList.iterator(); + assertTrue(iterator.hasNext()); myHolder.clear(); gc(); - Assert.assertNotNull(iterator.next()); - Assert.assertFalse(iterator.hasNext()); + assertNotNull(iterator.next()); + assertFalse(iterator.hasNext()); } public void testIteratorKeepsNextElement() { addElement(new Object(), myWeakArray); addElement(new Object(), myWeakArray); addElement(new Object(), myWeakArray); - Iterator iterator = myWeakList.iterator(); + Iterator iterator = myWeakList.iterator(); iterator.next(); - Assert.assertTrue(iterator.hasNext()); + assertTrue(iterator.hasNext()); myHolder.clear(); gc(); - Assert.assertNotNull(iterator.next()); - Assert.assertFalse(iterator.hasNext()); + assertNotNull(iterator.next()); + assertFalse(iterator.hasNext()); } } diff --git a/platform/util/testSrc/com/intellij/util/containers/WeakReferenceArrayTest.java b/platform/util/testSrc/com/intellij/util/containers/WeakReferenceArrayTest.java index 5f5ca33e1c37..8beb40f2a92c 100644 --- a/platform/util/testSrc/com/intellij/util/containers/WeakReferenceArrayTest.java +++ b/platform/util/testSrc/com/intellij/util/containers/WeakReferenceArrayTest.java @@ -20,7 +20,7 @@ import java.lang.ref.WeakReference; public class WeakReferenceArrayTest extends WeaksTestCase { - private WeakReferenceArray myCollection = new WeakReferenceArray(); + private WeakReferenceArray myCollection = new WeakReferenceArray(); protected void setUp() throws Exception { super.setUp(); @@ -39,16 +39,16 @@ public class WeakReferenceArrayTest extends WeaksTestCase { checkSameElements(); myHolder.remove(3); gc(); - assertEquals(1, myCollection.getCorpseCount()); + assertTrue(1 >= myCollection.getCorpseCount()); myCollection.remove(3); checkSameNotNulls(); - assertEquals(1, myCollection.getCorpseCount()); + assertTrue(1 >= myCollection.getCorpseCount()); myCollection.remove(2); - assertEquals(2, myCollection.getCorpseCount()); + assertTrue(2 >= myCollection.getCorpseCount()); myHolder.remove(2); gc(); checkSameNotNulls(); - assertEquals(2, myCollection.getCorpseCount()); + assertTrue(2 >= myCollection.getCorpseCount()); } public void testAddRemove() { @@ -69,9 +69,9 @@ public class WeakReferenceArrayTest extends WeaksTestCase { myCollection.add(this); gc(); assertEquals(2, myCollection.size()); - assertEquals(1, myCollection.getCorpseCount()); + assertTrue(1 >= myCollection.getCorpseCount()); assertNull(myCollection.remove(0)); - assertEquals(1, myCollection.getCorpseCount()); + assertTrue(1 >= myCollection.getCorpseCount()); } public void testCompress() { @@ -93,7 +93,7 @@ public class WeakReferenceArrayTest extends WeaksTestCase { addElement(new Object()); myCollection.add(new Object()); gc(); - assertEquals(1, myCollection.compress(3)); + assertTrue(1 <= myCollection.compress(3)); } public void testCompressTrackingNotLastSurvived() { @@ -102,7 +102,7 @@ public class WeakReferenceArrayTest extends WeaksTestCase { myCollection.add(new Object()); addElement(new Object()); gc(); - assertEquals(0, myCollection.compress(1)); + assertTrue(0 <= myCollection.compress(1)); } public void testCompressTrackingLostIndex() { @@ -111,7 +111,7 @@ public class WeakReferenceArrayTest extends WeaksTestCase { myCollection.add(new Object()); addElement(new Object()); gc(); - assertEquals(-2, myCollection.compress(2)); + assertTrue(-2 <= myCollection.compress(2)); } public void testCompressTrackingLostLastIndex() { @@ -121,7 +121,7 @@ public class WeakReferenceArrayTest extends WeaksTestCase { addElement(new Object()); myCollection.add(new Object()); gc(); - assertEquals(-3, myCollection.compress(4)); + assertTrue(-3 <= myCollection.compress(4)); } public void testAddingManyElement() { @@ -168,7 +168,7 @@ public class WeakReferenceArrayTest extends WeaksTestCase { } public void testReduceCapacityOfAliveCollection() { - myCollection = new WeakReferenceArray(WeakReferenceArray.MINIMUM_CAPACITY * 3); + myCollection = new WeakReferenceArray(WeakReferenceArray.MINIMUM_CAPACITY * 3); addElement(new Object()); myCollection.reduceCapacity(-1); assertEquals(0, myCollection.getCorpseCount()); diff --git a/platform/util/testSrc/com/intellij/util/containers/WeaksTestCase.java b/platform/util/testSrc/com/intellij/util/containers/WeaksTestCase.java index 2a9397b759f3..ab4f71744646 100644 --- a/platform/util/testSrc/com/intellij/util/containers/WeaksTestCase.java +++ b/platform/util/testSrc/com/intellij/util/containers/WeaksTestCase.java @@ -21,9 +21,10 @@ import junit.framework.TestCase; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; public abstract class WeaksTestCase extends TestCase { - protected final ArrayList myHolder = new ArrayList(); + protected final List myHolder = new ArrayList(); protected void checkSameElements(Iterator holderIterator, Iterator collectionIterator) { while (holderIterator.hasNext() && collectionIterator.hasNext()) { @@ -80,12 +81,12 @@ public abstract class WeaksTestCase extends TestCase { int validCount = 0; for (int i = 0; i < myHolder.size(); i++) { validIndex = nextValidIndex(validIndex, collection); - assertSame(String.valueOf(i) + "==" + validIndex, myHolder.get(i), collection.get(validIndex)); + assertSame(i + "==" + validIndex, myHolder.get(i), collection.get(validIndex)); validCount++; } assertEquals(myHolder.size(), validCount); - assertEquals(collection.size(), nextValidIndex(validIndex, collection)); - assertEquals(collection.size() - myHolder.size(), collection.getCorpseCount()); + assertTrue(collection.size() >= nextValidIndex(validIndex, collection)); + assertTrue(collection.size() - myHolder.size() >= collection.getCorpseCount()); //validIndex = Math.max(validIndex, 0); WeakReference[] references = collection.getReferences(); diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcs.java b/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcs.java index 8a66c04795b5..10d66bd2789d 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcs.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcs.java @@ -446,6 +446,10 @@ public abstract class AbstractVcs extends S return RemoteDifferenceStrategy.ASK_LATEST_REVISION; } + public boolean areDirectoriesVersionedItems() { + return false; + } + @Nullable protected TreeDiffProvider getTreeDiffProviderImpl() { return null; diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsShowConfirmationOption.java b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsShowConfirmationOption.java index d077e7621ee4..0eb8ca02c32d 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsShowConfirmationOption.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsShowConfirmationOption.java @@ -43,6 +43,21 @@ public interface VcsShowConfirmationOption { } } + public static final VcsShowConfirmationOption STATIC_SHOW_CONFIRMATION = new VcsShowConfirmationOption() { + @Override + public Value getValue() { + return Value.SHOW_CONFIRMATION; + } + @Override + public void setValue(Value value) { + } + @Override + public boolean isPersistent() { + return false; + } + }; + Value getValue(); void setValue(Value value); + boolean isPersistent(); } diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsVFSListener.java b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsVFSListener.java index 4a7c13ba3653..09ae9dde27a2 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsVFSListener.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsVFSListener.java @@ -60,7 +60,7 @@ public abstract class VcsVFSListener implements Disposable { protected final List myDeletedWithoutConfirmFiles = new ArrayList(); protected final List myMovedFiles = new ArrayList(); - protected enum VcsDeleteType { SILENT, CONFIRM, IGNORE } + protected enum VcsDeleteType {SILENT, CONFIRM, IGNORE} protected VcsVFSListener(final Project project, final AbstractVcs vcs) { myProject = project; @@ -74,8 +74,8 @@ public abstract class VcsVFSListener implements Disposable { myAddOption = vcsManager.getStandardConfirmation(VcsConfiguration.StandardConfirmation.ADD, vcs); myRemoveOption = vcsManager.getStandardConfirmation(VcsConfiguration.StandardConfirmation.REMOVE, vcs); - VirtualFileManager.getInstance().addVirtualFileListener(myVFSListener,this); - CommandProcessor.getInstance().addCommandListener(myCommandListener,this); + VirtualFileManager.getInstance().addVirtualFileListener(myVFSListener, this); + CommandProcessor.getInstance().addCommandListener(myCommandListener, this); } public void dispose() { @@ -86,11 +86,36 @@ public abstract class VcsVFSListener implements Disposable { } protected void executeAdd() { - final List addedFiles = new ArrayList(myAddedFiles); - final Map copyFromMap = new HashMap(myCopyFromMap); - myAddedFiles.clear(); - myCopyFromMap.clear(); + final List addedFiles = acquireAddedFiles(); + final Map copyFromMap = acquireCopiedFiles(); + executeAdd(addedFiles, copyFromMap); + } + /** + * @return get map of copied files and clear the map + */ + protected Map acquireCopiedFiles() { + final Map copyFromMap = new HashMap(myCopyFromMap); + myCopyFromMap.clear(); + return copyFromMap; + } + + /** + * @return get list of added files and clear previous list + */ + protected List acquireAddedFiles() { + final List addedFiles = new ArrayList(myAddedFiles); + myAddedFiles.clear(); + return addedFiles; + } + + /** + * Execute add that performs adding from specific collections + * + * @param addedFiles the added files + * @param copyFromMap the copied files + */ + protected void executeAdd(List addedFiles, Map copyFromMap) { if (myAddOption.getValue() == VcsShowConfirmationOption.Value.DO_NOTHING_SILENTLY) return; if (myAddOption.getValue() == VcsShowConfirmationOption.Value.DO_ACTION_SILENTLY) { performAdding(addedFiles, copyFromMap); @@ -108,11 +133,12 @@ public abstract class VcsVFSListener implements Disposable { } private void addFileToDelete(VirtualFile file) { - if (file.isDirectory() && file instanceof NewVirtualFile && !isDirectoryVersioningSupported()){ + if (file.isDirectory() && file instanceof NewVirtualFile && !isDirectoryVersioningSupported()) { for (VirtualFile child : ((NewVirtualFile)file).getCachedChildren()) { addFileToDelete(child); } - } else { + } + else { final VcsDeleteType type = needConfirmDeletion(file); final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOnDeleted(new File(file.getPath()), file.isDirectory()); @@ -177,7 +203,7 @@ public abstract class VcsVFSListener implements Disposable { if (FileStatusManager.getInstance(myProject).getStatus(file) != FileStatus.UNKNOWN) { final String newPath = newParentPath + "/" + newName; boolean foundExistingInfo = false; - for(MovedFileInfo info: myMovedFiles) { + for (MovedFileInfo info : myMovedFiles) { if (info.myFile == file) { info.myNewPath = newPath; foundExistingInfo = true; @@ -201,22 +227,30 @@ public abstract class VcsVFSListener implements Disposable { } protected abstract String getAddTitle(); + protected abstract String getSingleFileAddTitle(); + protected abstract String getSingleFileAddPromptTemplate(); + protected abstract void performAdding(final Collection addedFiles, final Map copyFromMap); protected abstract String getDeleteTitle(); + protected abstract String getSingleFileDeleteTitle(); + protected abstract String getSingleFileDeletePromptTemplate(); + protected abstract void performDeletion(List filesToDelete); + protected abstract void performMoveRename(List movedFiles); + protected abstract boolean isDirectoryVersioningSupported(); private class MyVirtualFileAdapter extends VirtualFileAdapter { public void fileCreated(final VirtualFileEvent event) { if (!isEventIgnored(event) && !myChangeListManager.isIgnoredFile(event.getFile()) && - (isDirectoryVersioningSupported() || !event.getFile().isDirectory())) { - myAddedFiles.add(event.getFile()); + (isDirectoryVersioningSupported() || !event.getFile().isDirectory())) { + myAddedFiles.add(event.getFile()); } } @@ -237,7 +271,9 @@ public abstract class VcsVFSListener implements Disposable { public void beforeFileDeletion(final VirtualFileEvent event) { final VirtualFile file = event.getFile(); - if (isEventIgnored(event)) { return; } + if (isEventIgnored(event)) { + return; + } if (!myChangeListManager.isIgnoredFile(file)) { addFileToDelete(file); return; @@ -276,8 +312,8 @@ public abstract class VcsVFSListener implements Disposable { public void beforePropertyChange(final VirtualFilePropertyEvent event) { if (!isEventIgnored(event) && event.getPropertyName().equalsIgnoreCase(VirtualFile.PROP_NAME)) { - String oldName = (String) event.getOldValue(); - String newName = (String) event.getNewValue(); + String oldName = (String)event.getOldValue(); + String newName = (String)event.getNewValue(); // in order to force a reparse of a file, the rename event can be fired with old name equal to new name - // such events needn't be handled by the VCS if (!Comparing.equal(oldName, newName)) { diff --git a/platform/vcs-api/src/com/intellij/util/ui/ConfirmationDialog.java b/platform/vcs-api/src/com/intellij/util/ui/ConfirmationDialog.java index fce6d54ba9d8..d82ef7ee79a6 100644 --- a/platform/vcs-api/src/com/intellij/util/ui/ConfirmationDialog.java +++ b/platform/vcs-api/src/com/intellij/util/ui/ConfirmationDialog.java @@ -15,9 +15,9 @@ */ package com.intellij.util.ui; +import com.intellij.CommonBundle; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsShowConfirmationOption; -import com.intellij.CommonBundle; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,6 +34,9 @@ public class ConfirmationDialog extends OptionsMessageDialog{ @Nullable Icon icon) { if (option.getValue() == VcsShowConfirmationOption.Value.DO_NOTHING_SILENTLY) return false; final ConfirmationDialog dialog = new ConfirmationDialog(project, message, title, icon, option); + if (! option.isPersistent()) { + dialog.setDoNotAskOption(null); + } dialog.show(); return dialog.isOK(); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PatchApplier.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PatchApplier.java index 0be7938a10e5..1ae3557eb2f3 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PatchApplier.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PatchApplier.java @@ -33,6 +33,7 @@ import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; import com.intellij.openapi.vcs.FilePath; +import com.intellij.openapi.vcs.FilePathImpl; import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.changes.*; import com.intellij.openapi.vcs.changes.patch.ApplyPatchAction; @@ -77,6 +78,11 @@ public class PatchApplier { public VirtualFile getFile(FilePatch patch, String path) { return PathMerger.getFile(myBaseDirectory, path); } + + @Override + public FilePath getPath(FilePatch patch, String path) { + return PathMerger.getFile(new FilePathImpl(myBaseDirectory), path); + } }); } @@ -87,7 +93,10 @@ public class PatchApplier { public ApplyPatchStatus execute(boolean showSuccessNotification) { myRemainingPatches.addAll(myPatches); - final ApplyPatchStatus status = ApplicationManager.getApplication().runWriteAction(new Computable() { + final ApplyPatchStatus patchStatus = nonWriteActionPreCheck(); + if (ApplyPatchStatus.FAILURE.equals(patchStatus)) return patchStatus; + + final ApplyPatchStatus applyStatus = ApplicationManager.getApplication().runWriteAction(new Computable() { public ApplyPatchStatus compute() { final Ref refStatus = new Ref(ApplyPatchStatus.FAILURE); CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { @@ -98,10 +107,16 @@ public class PatchApplier { return refStatus.get(); } }); + final ApplyPatchStatus status = ApplyPatchStatus.SUCCESS.equals(patchStatus) ? applyStatus : + ApplyPatchStatus.and(patchStatus, applyStatus); + // listeners finished, all 'legal' file additions/deletions with VCS are done + final TriggerAdditionOrDeletion trigger = new TriggerAdditionOrDeletion(myProject); + addSkippedItems(trigger); + trigger.process(); if(showSuccessNotification || !ApplyPatchStatus.SUCCESS.equals(status)) { showApplyStatus(myProject, status); } - refreshFiles(); + refreshFiles(trigger.getAffected()); return status; } @@ -109,7 +124,12 @@ public class PatchApplier { if (group.isEmpty()) return ApplyPatchStatus.SUCCESS; //? final Project project = group.iterator().next().myProject; - ApplyPatchStatus result = ApplicationManager.getApplication().runWriteAction(new Computable() { + ApplyPatchStatus result = ApplyPatchStatus.SUCCESS; + for (PatchApplier patchApplier : group) { + result = ApplyPatchStatus.and(result, patchApplier.nonWriteActionPreCheck()); + if (ApplyPatchStatus.FAILURE.equals(result)) return result; + } + result = ApplyPatchStatus.and(result, ApplicationManager.getApplication().runWriteAction(new Computable() { public ApplyPatchStatus compute() { final Ref refStatus = new Ref(null); CommandProcessor.getInstance().executeCommand(project, new Runnable() { @@ -121,16 +141,36 @@ public class PatchApplier { }, VcsBundle.message("patch.apply.command"), null); return refStatus.get(); } - }); + })); result = result == null ? ApplyPatchStatus.FAILURE : result; + final TriggerAdditionOrDeletion trigger = new TriggerAdditionOrDeletion(project); + for (PatchApplier applier : group) { + applier.addSkippedItems(trigger); + } + trigger.process(); for (PatchApplier applier : group) { - applier.refreshFiles(); + applier.refreshFiles(trigger.getAffected()); } showApplyStatus(project, result); return result; } + protected void addSkippedItems(final TriggerAdditionOrDeletion trigger) { + trigger.addExisting(myVerifier.getToBeAdded()); + trigger.addDeleted(myVerifier.getToBeDeleted()); + } + + public ApplyPatchStatus nonWriteActionPreCheck() { + final boolean value = myVerifier.nonWriteActionPreCheck(); + if (! value) return ApplyPatchStatus.FAILURE; + + final List skipped = myVerifier.getSkipped(); + final boolean applyAll = skipped.isEmpty(); + myPatches.removeAll(skipped); + return applyAll ? ApplyPatchStatus.SUCCESS : ((skipped.size() == myPatches.size()) ? ApplyPatchStatus.ALREADY_APPLIED : ApplyPatchStatus.PARTIAL) ; + } + protected ApplyPatchStatus executeWritable() { return ApplicationManager.getApplication().runWriteAction(new Computable() { public ApplyPatchStatus compute() { @@ -175,9 +215,10 @@ public class PatchApplier { } } - protected void refreshFiles() { + protected void refreshFiles(final Collection additionalDirectly) { final List directlyAffected = myVerifier.getDirectlyAffected(); final List indirectlyAffected = myVerifier.getAllAffected(); + directlyAffected.addAll(additionalDirectly); final RefreshSession session = RefreshQueue.getInstance().createSession(false, true, new Runnable() { public void run() { @@ -274,6 +315,10 @@ public class PatchApplier { return myRemainingPatches; } + public boolean hasRemainingPatches() { + return ! myRemainingPatches.isEmpty(); + } + private boolean makeWritable(final List filesToMakeWritable) { final VirtualFile[] fileArray = VfsUtil.toVirtualFileArray(filesToMakeWritable); final ReadonlyStatusHandler.OperationStatus readonlyStatus = ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(fileArray); diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PathMerger.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PathMerger.java index 13979a71803d..04dc13aa6306 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PathMerger.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PathMerger.java @@ -16,6 +16,8 @@ package com.intellij.openapi.diff.impl.patch.formove; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.vcs.FilePath; +import com.intellij.openapi.vcs.FilePathImpl; import com.intellij.openapi.vcs.changes.patch.RelativePathCalculator; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.Nullable; @@ -49,6 +51,16 @@ public class PathMerger { return getFile(new IoFilePathMerger(base), path, tail); } + @Nullable + public static FilePath getFile(final FilePath base, final String path) { + return getFile(new FilePathPathMerger(base), path); + } + + @Nullable + public static FilePath getFile(final FilePath base, final String path, final List tail) { + return getFile(new FilePathPathMerger(base), path, tail); + } + @Nullable public static T getFile(final FilePathMerger merger, final String path) { if (path == null) { @@ -194,6 +206,39 @@ public class PathMerger { } } + public static class FilePathPathMerger implements FilePathMerger { + private final IoFilePathMerger myIoDelegate; + private boolean myIsDirectory; + + public FilePathPathMerger(final FilePath base) { + myIoDelegate = new IoFilePathMerger(base.getIOFile()); + } + + @Override + public boolean down(String name) { + return myIoDelegate.down(name); + } + + @Override + public boolean up() { + return myIoDelegate.up(); + } + + @Override + public FilePath getResult() { + return new FilePathImpl(myIoDelegate.getResult(), myIsDirectory); + } + + @Override + public String getCurrentName() { + return myIoDelegate.getCurrentName(); + } + + public void setIsDirectory(boolean isDirectory) { + myIsDirectory = isDirectory; + } + } + public interface FilePathMerger { boolean up(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PathsVerifier.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PathsVerifier.java index f5870cd2d08d..f6f5b20f91bf 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PathsVerifier.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PathsVerifier.java @@ -24,10 +24,7 @@ import com.intellij.openapi.diff.impl.patch.apply.ApplyTextFilePatch; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Pair; -import com.intellij.openapi.vcs.FilePath; -import com.intellij.openapi.vcs.FilePathImpl; -import com.intellij.openapi.vcs.ProjectLevelVcsManager; -import com.intellij.openapi.vcs.VcsBundle; +import com.intellij.openapi.vcs.*; import com.intellij.openapi.vcs.changes.patch.RelativePathCalculator; import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager; import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl; @@ -54,6 +51,8 @@ public class PathsVerifier { private final List myWritableFiles; private final BaseMapper myBaseMapper; private ProjectLevelVcsManager myVcsManager; + private final List mySkipped; + private DelayedPrecheckContext myDelayedPrecheckContext; public PathsVerifier(final Project project, final VirtualFile baseDirectory, final List patches, BaseMapper baseMapper) { myProject = project; @@ -68,6 +67,7 @@ public class PathsVerifier { myBinaryPatches = new ArrayList>>(); myWritableFiles = new ArrayList(); myVcsManager = ProjectLevelVcsManager.getInstance(myProject); + mySkipped = new ArrayList(); } // those to be moved to CL: target + created dirs @@ -108,15 +108,32 @@ public class PathsVerifier { } } + @CalledInAwt + public boolean nonWriteActionPreCheck() { + final List checkers = new ArrayList(myPatches.size()); + myDelayedPrecheckContext = new DelayedPrecheckContext(myProject); + for (FilePatch patch : myPatches) { + final CheckPath checker = getChecker(patch); + if (! checker.canBeApplied(myDelayedPrecheckContext)) { + revert(checker.getErrorMessage()); + return false; + } + } + final Collection skipped = myDelayedPrecheckContext.doDelayed(); + mySkipped.addAll(skipped); + myPatches.remove(skipped); + return true; + } + + public List getSkipped() { + return mySkipped; + } + public boolean execute() { try { final List checkers = new ArrayList(myPatches.size()); for (FilePatch patch : myPatches) { final CheckPath checker = getChecker(patch); - if (! checker.canBeApplied()) { - revert(checker.getErrorMessage()); - return false; - } checkers.add(checker); } for (CheckPath checker : checkers) { @@ -150,6 +167,14 @@ public class PathsVerifier { } } + public Collection getToBeAdded() { + return myDelayedPrecheckContext.getOverridenPaths(); + } + + public Collection getToBeDeleted() { + return myDelayedPrecheckContext.getAlreadyDeletedPaths(); + } + private class CheckModified extends CheckDeleted { private CheckModified(final FilePatch path) { super(path); @@ -161,17 +186,15 @@ public class PathsVerifier { super(path); } - protected boolean precheck(final VirtualFile beforeFile, final VirtualFile afterFile) { + protected boolean precheck(final VirtualFile beforeFile, final VirtualFile afterFile, DelayedPrecheckContext context) { if (beforeFile == null) { - setErrorMessage(fileNotFoundMessage(myBeforeName)); - return false; + context.addSkip(myBaseMapper.getPath(myPatch, myBeforeName), myPatch); } return true; } protected boolean check() throws IOException { final VirtualFile beforeFile = myBaseMapper.getFile(myPatch, myBeforeName); - // todo maybe deletion may be ok, just warning if (! checkExistsAndValid(beforeFile, myBeforeName)) { return false; } @@ -186,10 +209,9 @@ public class PathsVerifier { super(path); } - protected boolean precheck(final VirtualFile beforeFile, final VirtualFile afterFile) { + protected boolean precheck(final VirtualFile beforeFile, final VirtualFile afterFile, DelayedPrecheckContext context) { if (afterFile != null) { - setErrorMessage(fileAlreadyExists(afterFile.getPath())); - return false; + context.addOverrideExisting(myPatch, new FilePathImpl(afterFile)); } return true; } @@ -216,7 +238,7 @@ public class PathsVerifier { } // before exists; after does not exist - protected boolean precheck(final VirtualFile beforeFile, final VirtualFile afterFile) { + protected boolean precheck(final VirtualFile beforeFile, final VirtualFile afterFile, final DelayedPrecheckContext context) { if (beforeFile == null) { setErrorMessage(fileNotFoundMessage(myBeforeName)); } else if (afterFile != null) { @@ -262,13 +284,15 @@ public class PathsVerifier { myErrorMessage = errorMessage; } - public boolean canBeApplied() { + public boolean canBeApplied(DelayedPrecheckContext context) { final VirtualFile beforeFile = myBaseMapper.getFile(myPatch, myBeforeName); final VirtualFile afterFile = myBaseMapper.getFile(myPatch, myAfterName); - return precheck(beforeFile, afterFile); + return precheck(beforeFile, afterFile, context); } - protected abstract boolean precheck(final VirtualFile beforeFile, final VirtualFile afterFile); + protected abstract boolean precheck(final VirtualFile beforeFile, + final VirtualFile afterFile, + DelayedPrecheckContext context); protected abstract boolean check() throws IOException; protected boolean checkExistsAndValid(final VirtualFile file, final String name) { @@ -486,5 +510,60 @@ public class PathsVerifier { public interface BaseMapper { @Nullable VirtualFile getFile(final FilePatch patch, final String path); + FilePath getPath(final FilePatch patch, final String path); + } + + private static class DelayedPrecheckContext { + private final Map mySkipDeleted; + private final Map myOverrideExisting; + private final List myOverridenPaths; + private final Project myProject; + + private DelayedPrecheckContext(final Project project) { + myProject = project; + myOverrideExisting = new HashMap(); + mySkipDeleted = new HashMap(); + myOverridenPaths = new LinkedList(); + } + + public void addSkip(final FilePath path, final FilePatch filePatch) { + mySkipDeleted.put(path, filePatch); + } + + public void addOverrideExisting(final FilePatch patch, final FilePath filePath) { + if (! myOverrideExisting.containsKey(filePath)) { + myOverrideExisting.put(filePath, patch); + } + } + + // returns those to be skipped + public Collection doDelayed() { + final List result = new LinkedList(); + if (! myOverrideExisting.isEmpty()) { + final String prompt = myOverrideExisting.size() == 1 ? "The following file already exists. Do you want to override it?" : + "The following files already exist. Do you want to override them?"; + final String title = "Override existing files"; + final Collection selected = AbstractVcsHelper.getInstance(myProject).selectFilePathsToProcess( + new ArrayList(myOverrideExisting.keySet()), title, + "\nThe following files should be created by patch, but they already exist.\nDo you want to override them?\n", title, + "The following file should be created by patch, but it already exists.\nDo you want to override it?\n{0}", + VcsShowConfirmationOption.STATIC_SHOW_CONFIRMATION); + for (FilePath path : selected) { + myOverrideExisting.remove(path); + } + result.addAll(myOverrideExisting.values()); + myOverridenPaths.addAll(selected); + } + result.addAll(mySkipDeleted.values()); + return result; + } + + public List getOverridenPaths() { + return myOverridenPaths; + } + + public Collection getAlreadyDeletedPaths() { + return mySkipDeleted.keySet(); + } } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/TriggerAdditionOrDeletion.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/TriggerAdditionOrDeletion.java new file mode 100644 index 000000000000..b477f424fc56 --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/TriggerAdditionOrDeletion.java @@ -0,0 +1,186 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.diff.impl.patch.formove; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vcs.*; +import com.intellij.openapi.vcs.changes.ChangeListManager; +import com.intellij.openapi.vcs.changes.SortByVcsRoots; +import com.intellij.openapi.vcs.checkin.CheckinEnvironment; +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.FilePathByPathComparator; +import com.intellij.util.containers.Convertor; +import com.intellij.util.containers.MultiMap; + +import java.util.*; + +public class TriggerAdditionOrDeletion { + private final Collection myExisting; + private final Collection myDeleted; + private final Set myAffected; + private final Project myProject; + private ProjectLevelVcsManager myVcsManager; + private AbstractVcsHelper myVcsHelper; + + public TriggerAdditionOrDeletion(final Project project) { + myProject = project; + myExisting = new HashSet(); + myDeleted = new HashSet(); + myVcsManager = ProjectLevelVcsManager.getInstance(myProject); + myVcsHelper = AbstractVcsHelper.getInstance(myProject); + myAffected = new HashSet(); + } + + public void addExisting(final Collection files) { + myExisting.addAll(files); + } + + public void addDeleted(final Collection files) { + myDeleted.addAll(files); + } + + public void process() { + if (myExisting.isEmpty() && myDeleted.isEmpty()) return; + + final SortByVcsRoots sortByVcsRoots = new SortByVcsRoots(myProject, new Convertor.IntoSelf()); + final ChangeListManager clManager = ChangeListManager.getInstance(myProject); + + if (! myExisting.isEmpty()) { + processAddition(sortByVcsRoots); + } + if (! myDeleted.isEmpty()) { + processDeletion(sortByVcsRoots); + } + } + + public Set getAffected() { + return myAffected; + } + + private void processDeletion(SortByVcsRoots sortByVcsRoots) { + final MultiMap map = sortByVcsRoots.sort(myDeleted); + for (VcsRoot vcsRoot : map.keySet()) { + if (vcsRoot != null && vcsRoot.vcs != null) { + final CheckinEnvironment localChangesProvider = vcsRoot.vcs.getCheckinEnvironment(); + if (localChangesProvider == null) continue; + final boolean takeDirs = vcsRoot.vcs.areDirectoriesVersionedItems(); + + final Collection files = map.get(vcsRoot); + final List toBeDeleted = new LinkedList(); + for (FilePath file : files) { + final FilePath parent = file.getParentPath(); + if ((takeDirs || (! file.isDirectory())) && parent != null && parent.getIOFile().exists()) { + toBeDeleted.add(file); + } + } + if (toBeDeleted.isEmpty()) return; + askUserIfNeededDeletion(vcsRoot.vcs, toBeDeleted); + myAffected.addAll(toBeDeleted); + localChangesProvider.scheduleMissingFileForDeletion(toBeDeleted); + } + } + } + + private void processAddition(SortByVcsRoots sortByVcsRoots) { + final MultiMap map = sortByVcsRoots.sort(myExisting); + for (VcsRoot vcsRoot : map.keySet()) { + if (vcsRoot != null && vcsRoot.vcs != null) { + final CheckinEnvironment localChangesProvider = vcsRoot.vcs.getCheckinEnvironment(); + if (localChangesProvider == null) continue; + final boolean takeDirs = vcsRoot.vcs.areDirectoriesVersionedItems(); + + final Collection files = map.get(vcsRoot); + final List toBeAdded; + if (takeDirs) { + final RecursiveCheckAdder adder = new RecursiveCheckAdder(vcsRoot.path); + for (FilePath file : files) { + adder.process(file); + } + toBeAdded = adder.getToBeAdded(); + } else { + toBeAdded = new LinkedList(); + for (FilePath file : files) { + if (! file.isDirectory()) { + toBeAdded.add(file); + } + } + } + if (toBeAdded.isEmpty()) return; + Collections.sort(toBeAdded, FilePathByPathComparator.getInstance()); + + askUserIfNeededAddition(vcsRoot.vcs, toBeAdded); + myAffected.addAll(toBeAdded); + localChangesProvider.scheduleUnversionedFilesForAddition(ObjectsConvertor.fp2vf(toBeAdded)); + } + } + } + + private void askUserIfNeededAddition(final AbstractVcs vcs, final List toBeAdded) { + final VcsShowConfirmationOption confirmationOption = myVcsManager.getStandardConfirmation(VcsConfiguration.StandardConfirmation.ADD, vcs); + if (VcsShowConfirmationOption.Value.DO_NOTHING_SILENTLY.equals(confirmationOption.getValue())) { + toBeAdded.clear(); + } else if (VcsShowConfirmationOption.Value.SHOW_CONFIRMATION.equals(confirmationOption.getValue())) { + final Collection files = myVcsHelper.selectFilePathsToProcess(toBeAdded, "Select files to add to " + vcs.getDisplayName(), null, + "Schedule for addition", "Do you want to schedule the following file for addition to " + vcs.getDisplayName() + "\n{0}", confirmationOption); + toBeAdded.retainAll(files); + } + } + + private void askUserIfNeededDeletion(final AbstractVcs vcs, final List toBeDeleted) { + final VcsShowConfirmationOption confirmationOption = myVcsManager.getStandardConfirmation(VcsConfiguration.StandardConfirmation.REMOVE, vcs); + if (VcsShowConfirmationOption.Value.DO_NOTHING_SILENTLY.equals(confirmationOption.getValue())) { + toBeDeleted.clear(); + } else if (VcsShowConfirmationOption.Value.SHOW_CONFIRMATION.equals(confirmationOption.getValue())) { + final Collection files = myVcsHelper.selectFilePathsToProcess(toBeDeleted, "Select files to remove from " + vcs.getDisplayName(), null, + "Schedule for deletion", "Do you want to schedule the following file for deletion from " + vcs.getDisplayName() + "\n{0}", confirmationOption); + toBeDeleted.retainAll(files); + } + } + + private class RecursiveCheckAdder { + private final Set myToBeAdded; + private ChangeListManager myChangeListManager; + private final VirtualFile myRoot; + + private RecursiveCheckAdder(final VirtualFile root) { + myRoot = root; + myToBeAdded = new HashSet(); + myChangeListManager = ChangeListManager.getInstance(myProject); + } + + public void process(final FilePath path) { + FilePath current = path; + while (current != null) { + final VirtualFile vf = current.getVirtualFile(); + if (vf == null) return; + if (! VfsUtil.isAncestor(myRoot, vf, true)) return; + + final FileStatus status = myChangeListManager.getStatus(vf); + if (FileStatus.UNKNOWN.equals(status)) { + myToBeAdded.add(current); + current = current.getParentPath(); + } else { + return; + } + } + } + + public List getToBeAdded() { + return new ArrayList(myToBeAdded); + } + } +} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/VcsShowConfirmationOptionImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/VcsShowConfirmationOptionImpl.java index 62d3f658a4ee..092122b68287 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/VcsShowConfirmationOptionImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/VcsShowConfirmationOptionImpl.java @@ -44,4 +44,9 @@ public class VcsShowConfirmationOptionImpl extends VcsAbstractSetting implements public void setValue(Value value) { myValue = value; } + + @Override + public boolean isPersistent() { + return true; + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java index 5b56c0fc7a03..645aed04a90c 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java @@ -146,6 +146,11 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec public void setValue(Value value) { config.REMOVE_EMPTY_INACTIVE_CHANGELISTS = value; } + + @Override + public boolean isPersistent() { + return true; + } }, "The empty changelist '" + StringUtil.first(oldDefaultList.getName(), 30, true) + "' is no longer active.
" + "Do you want to remove it?", "&Remember my choice"); dialog.show(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/AbstractSelectFilesDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/AbstractSelectFilesDialog.java index d5df34ac2a29..a2981acb8136 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/AbstractSelectFilesDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/AbstractSelectFilesDialog.java @@ -25,6 +25,7 @@ import com.intellij.openapi.vcs.VcsShowConfirmationOption; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import javax.swing.border.EmptyBorder; import java.awt.*; /** @@ -46,6 +47,7 @@ public abstract class AbstractSelectFilesDialog extends DialogWrapper { if (prompt != null) { final JLabel label = new JLabel(prompt); label.setUI(new MultiLineLabelUI()); + label.setBorder(new EmptyBorder(5, 1, 5, 1)); myPanel.add(label, BorderLayout.NORTH); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitHelper.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitHelper.java index c9359fb45999..326441cc2bce 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitHelper.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitHelper.java @@ -489,6 +489,11 @@ public class CommitHelper { public void setValue(final Value value) { configuration.MOVE_TO_FAILED_COMMIT_CHANGELIST = value; } + + @Override + public boolean isPersistent() { + return true; + } }; boolean result = ConfirmationDialog.requestForConfirmation(option, project, VcsBundle.message("commit.failed.confirm.prompt"), VcsBundle.message("commit.failed.confirm.title"), diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java index c13e85eeaed8..9280b6d4f8bd 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java @@ -245,6 +245,9 @@ public class AbstractVcsHelperImpl extends AbstractVcsHelper { SelectFilesDialog dlg = new SelectFilesDialog(myProject, files, prompt, confirmationOption); dlg.setTitle(title); + if (! confirmationOption.isPersistent()) { + dlg.setDoNotAskOption(null); + } dlg.show(); if (dlg.isOK()) { final Collection selection = dlg.getSelectedFiles(); @@ -278,6 +281,9 @@ public class AbstractVcsHelperImpl extends AbstractVcsHelper { SelectFilePathsDialog dlg = new SelectFilePathsDialog(myProject, files, prompt, confirmationOption); dlg.setTitle(title); + if (! confirmationOption.isPersistent()) { + dlg.setDoNotAskOption(null); + } dlg.show(); return dlg.isOK() ? dlg.getSelectedFiles() : null; } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java index 0521789b86f0..229f95016d4f 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java @@ -97,6 +97,7 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme private final List myRegisteredBeforeCheckinHandlers = new ArrayList(); private final EventDispatcher myEventDispatcher = EventDispatcher.create(VcsListener.class); + private boolean myMappingsLoaded = false; private boolean myHaveLegacyVcsConfiguration = false; private boolean myCheckinHandlerFactoriesLoaded = false; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/naming/ConventionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/naming/ConventionInspection.java index 03ee14449d00..663e1a823236 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/naming/ConventionInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/naming/ConventionInspection.java @@ -95,7 +95,7 @@ public abstract class ConventionInspection extends BaseInspection { private static final int REGEX_COLUMN_COUNT = 25; public Collection createExtraOptions() { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } @Override @@ -221,4 +221,4 @@ public abstract class ConventionInspection extends BaseInspection { return panel; } -} \ No newline at end of file +} diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/MapReplaceableByEnumMapInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/MapReplaceableByEnumMapInspection.java index 99a1fbf2f1ee..0a6503a6aea8 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/MapReplaceableByEnumMapInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/MapReplaceableByEnumMapInspection.java @@ -15,10 +15,8 @@ */ package com.siyeh.ig.performance; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiClassType; -import com.intellij.psi.PsiNewExpression; -import com.intellij.psi.PsiType; +import com.intellij.psi.*; +import com.intellij.psi.util.PsiTreeUtil; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; @@ -81,6 +79,16 @@ public class MapReplaceableByEnumMapInspection extends BaseInspection { if (argumentClass == null || !argumentClass.isEnum()) { return; } + final PsiClass aClass = + PsiTreeUtil.getParentOfType(expression, PsiClass.class); + if (argumentClass.equals(aClass)) { + final PsiMember member = + PsiTreeUtil.getParentOfType(expression, PsiMember.class); + if (member != null && + !member.hasModifierProperty(PsiModifier.STATIC)) { + return; + } + } registerNewExpressionError(expression); } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java index 09d6147ecf0b..280e6c5545c2 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java @@ -47,7 +47,7 @@ public class WeakestTypeFinder { final PsiMethod method = (PsiMethod) variableOrMethod; variableOrMethodType = method.getReturnType(); if (PsiType.VOID.equals(variableOrMethodType)) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } else { throw new IllegalArgumentException( @@ -55,14 +55,14 @@ public class WeakestTypeFinder { variableOrMethod); } if (!(variableOrMethodType instanceof PsiClassType)) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } final PsiClassType variableOrMethodClassType = (PsiClassType) variableOrMethodType; final PsiClass variableOrMethodClass = variableOrMethodClassType.resolve(); if (variableOrMethodClass == null) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } final PsiManager manager = variableOrMethod.getManager(); final GlobalSearchScope scope = variableOrMethod.getResolveScope(); @@ -72,7 +72,7 @@ public class WeakestTypeFinder { facade.findClass("java.lang.Object", scope); if (javaLangObjectClass == null || variableOrMethodClass.equals(javaLangObjectClass)) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } Set weakestTypeClasses = new HashSet(); weakestTypeClasses.add(javaLangObjectClass); @@ -95,21 +95,21 @@ public class WeakestTypeFinder { if (referenceParent instanceof PsiExpressionList) { if (!(referenceGrandParent instanceof PsiMethodCallExpression)) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) referenceGrandParent; if (!findWeakestType(referenceElement, methodCallExpression, useParameterizedTypeForCollectionMethods, weakestTypeClasses)) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } else if (referenceGrandParent instanceof PsiMethodCallExpression) { final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) referenceGrandParent; if (!findWeakestType(methodCallExpression, weakestTypeClasses)) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } else if (referenceParent instanceof PsiAssignmentExpression) { final PsiAssignmentExpression assignmentExpression = @@ -117,24 +117,24 @@ public class WeakestTypeFinder { if (!findWeakestType(referenceElement, assignmentExpression, useRighthandTypeAsWeakestTypeInAssignments, weakestTypeClasses)) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } else if (referenceParent instanceof PsiVariable) { final PsiVariable variable = (PsiVariable)referenceParent; final PsiType type = variable.getType(); if (!checkType(type, weakestTypeClasses)) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } else if (referenceParent instanceof PsiForeachStatement) { final PsiForeachStatement foreachStatement = (PsiForeachStatement)referenceParent; if (foreachStatement.getIteratedValue() != referenceElement) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } final PsiClass javaLangIterableClass = facade.findClass("java.lang.Iterable", scope); if (javaLangIterableClass == null) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } checkClass(javaLangIterableClass, weakestTypeClasses); } else if (referenceParent instanceof PsiReturnStatement) { @@ -142,11 +142,11 @@ public class WeakestTypeFinder { PsiTreeUtil.getParentOfType(referenceParent, PsiMethod.class); if (containingMethod == null) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } final PsiType type = containingMethod.getReturnType(); if (!checkType(type, weakestTypeClasses)) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } else if (referenceParent instanceof PsiReferenceExpression) { // field access, method call is handled above. @@ -154,7 +154,7 @@ public class WeakestTypeFinder { (PsiReferenceExpression)referenceParent; final PsiElement target = referenceExpression.resolve(); if (!(target instanceof PsiField)) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } final PsiField field = (PsiField)target; final PsiClass containingClass = field.getContainingClass(); @@ -164,14 +164,14 @@ public class WeakestTypeFinder { (PsiArrayInitializerExpression)referenceParent; if (!findWeakestType(arrayInitializerExpression, weakestTypeClasses)) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } else if (referenceParent instanceof PsiThrowStatement) { final PsiThrowStatement throwStatement = (PsiThrowStatement)referenceParent; if (!findWeakestType(throwStatement, variableOrMethodClass, weakestTypeClasses)) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } else if (referenceParent instanceof PsiConditionalExpression) { final PsiConditionalExpression conditionalExpression = @@ -179,12 +179,12 @@ public class WeakestTypeFinder { final PsiExpression condition = conditionalExpression.getCondition(); if (referenceElement.equals(condition)) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } final PsiType type = ExpectedTypeUtils.findExpectedType( conditionalExpression, true); if (!checkType(type, weakestTypeClasses)) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } else if (referenceParent instanceof PsiBinaryExpression) { // strings only @@ -193,28 +193,28 @@ public class WeakestTypeFinder { final PsiType type = binaryExpression.getType(); if (variableOrMethodType.equals(type)) { if (!checkType(type, weakestTypeClasses)) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } } else if (referenceParent instanceof PsiSwitchStatement) { // only enums and primitives can be a switch expression - return Collections.EMPTY_LIST; + return Collections.emptyList(); } else if (referenceParent instanceof PsiPrefixExpression) { // only primitives and boxed types are the target of a prefix // expression - return Collections.EMPTY_LIST; + return Collections.emptyList(); } else if (referenceParent instanceof PsiPostfixExpression) { // only primitives and boxed types are the target of a postfix // expression - return Collections.EMPTY_LIST; + return Collections.emptyList(); } else if (referenceParent instanceof PsiIfStatement) { // only booleans and boxed Booleans are the condition of an if // statement - return Collections.EMPTY_LIST; + return Collections.emptyList(); } else if (referenceParent instanceof PsiForStatement) { // only booleans and boxed Booleans are the condition of an // for statement - return Collections.EMPTY_LIST; + return Collections.emptyList(); } else if (referenceParent instanceof PsiNewExpression) { final PsiNewExpression newExpression = (PsiNewExpression)referenceParent; @@ -222,12 +222,12 @@ public class WeakestTypeFinder { if (qualifier != null) { final PsiType type = newExpression.getType(); if (!(type instanceof PsiClassType)) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } final PsiClassType classType = (PsiClassType)type; final PsiClass innerClass = classType.resolve(); if (innerClass == null) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } final PsiClass outerClass = innerClass.getContainingClass(); @@ -238,11 +238,11 @@ public class WeakestTypeFinder { } if (weakestTypeClasses.contains(variableOrMethodClass) || weakestTypeClasses.isEmpty()) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } if (!hasUsages) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } weakestTypeClasses = filterAccessibleClasses(weakestTypeClasses, variableOrMethod); diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/encapsulation/ReturnOfCollectionFieldInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/encapsulation/ReturnOfCollectionFieldInspection.java index 9927094ca540..887cf780892b 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/encapsulation/ReturnOfCollectionFieldInspection.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/encapsulation/ReturnOfCollectionFieldInspection.java @@ -30,7 +30,7 @@ public class ReturnOfCollectionFieldInspection public List fooBarEmpty() { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } public int[] bar() @@ -39,4 +39,4 @@ public class ReturnOfCollectionFieldInspection } -} \ No newline at end of file +} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/performance/MapReplaceableByEnumMapInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/performance/MapReplaceableByEnumMapInspection.java deleted file mode 100644 index b3dda6dd7a77..000000000000 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/performance/MapReplaceableByEnumMapInspection.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.siyeh.igtest.performance; - -import com.siyeh.igtest.bugs.MyEnum; - -import java.util.HashSet; -import java.util.HashMap; - -public class MapReplaceableByEnumMapInspection { - public static void main(String[] args) { - final HashMap myEnums = new HashMap(); - } -} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/performance/map_replaceable_by_enum_map/MapReplaceableByEnumMap.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/performance/map_replaceable_by_enum_map/MapReplaceableByEnumMap.java new file mode 100644 index 000000000000..9f2a423ddd18 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/performance/map_replaceable_by_enum_map/MapReplaceableByEnumMap.java @@ -0,0 +1,17 @@ +package com.siyeh.igtest.performance.map_replaceable_by_enum_map; + +import java.util.HashMap; +import java.util.Map; + +public class MapReplaceableByEnumMap { + + public static void main(String[] args) { + final HashMap myEnums = new HashMap(); + } + + enum MyEnum{ + foo, bar, baz; + Map enums = new HashMap(); + // enum map here throws exception at runtime -> don't suggest it + } +} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/performance/map_replaceable_by_enum_map/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/performance/map_replaceable_by_enum_map/expected.xml new file mode 100644 index 000000000000..5e98fa3730b4 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/performance/map_replaceable_by_enum_map/expected.xml @@ -0,0 +1,11 @@ + + + + + MapReplaceableByEnumMap.java + 9 + Map replaceable with EnumMap + <code>HashMap<MyEnum, Object></code> replaceable with EnumMap #loc + + + \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/performance/MapReplaceableByEnumMapInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/performance/MapReplaceableByEnumMapInspectionTest.java new file mode 100644 index 000000000000..2a8f235409a6 --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/performance/MapReplaceableByEnumMapInspectionTest.java @@ -0,0 +1,11 @@ +package com.siyeh.ig.performance; + +import com.IGInspectionTestCase; + +public class MapReplaceableByEnumMapInspectionTest extends IGInspectionTestCase { + + public void test() throws Exception { + doTest("com/siyeh/igtest/performance/map_replaceable_by_enum_map", + new MapReplaceableByEnumMapInspection()); + } +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAccessUtils.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAccessUtils.java index 6ccc4aaf0eac..a169b5b30ccb 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAccessUtils.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAccessUtils.java @@ -158,7 +158,7 @@ public class VariableAccessUtils { public static Set collectUsedVariables( PsiElement context) { if (context == null) { - return Collections.EMPTY_SET; + return Collections.emptySet(); } final VariableCollectingVisitor visitor = new VariableCollectingVisitor(); @@ -187,4 +187,4 @@ public class VariableAccessUtils { return usedVariables; } } -} \ No newline at end of file +} diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java index d777dc608584..f23d6184686d 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java @@ -459,5 +459,10 @@ public class CvsVcs2 extends AbstractVcs implements TransactionProvider, EditFil public static VcsKey getKey() { return ourKey; } + + @Override + public boolean areDirectoriesVersionedItems() { + return true; + } } diff --git a/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/command/FileSystemScanner.java b/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/command/FileSystemScanner.java index 748c98ad188a..df3e9067db9c 100644 --- a/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/command/FileSystemScanner.java +++ b/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/command/FileSystemScanner.java @@ -83,7 +83,7 @@ final class FileSystemScanner { private List scanDirectory(DirectoryObject directoryObject, CvsFiles cvsFiles) throws IOException { if (!clientEnvironment.getLocalFileReader().exists(directoryObject, clientEnvironment.getCvsFileSystem())) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } cvsFiles.add(CvsFile.createCvsDirectory(directoryObject)); diff --git a/plugins/cvs/smartcvs-src/org/netbeans/lib/cvsclient/admin/AdminReader.java b/plugins/cvs/smartcvs-src/org/netbeans/lib/cvsclient/admin/AdminReader.java index 8ab3e19ce350..cf255569ca1f 100644 --- a/plugins/cvs/smartcvs-src/org/netbeans/lib/cvsclient/admin/AdminReader.java +++ b/plugins/cvs/smartcvs-src/org/netbeans/lib/cvsclient/admin/AdminReader.java @@ -76,7 +76,7 @@ public final class AdminReader return entriesHandler.getEntries().getEntries(); } catch (FileNotFoundException ex) { - return Collections.EMPTY_SET; + return Collections.emptySet(); } } diff --git a/plugins/git4idea/src/git4idea/vfs/GitVFSListener.java b/plugins/git4idea/src/git4idea/vfs/GitVFSListener.java index 8379f8819505..de7d531731e6 100644 --- a/plugins/git4idea/src/git4idea/vfs/GitVFSListener.java +++ b/plugins/git4idea/src/git4idea/vfs/GitVFSListener.java @@ -105,20 +105,20 @@ public class GitVFSListener extends VcsVFSListener { * {@inheritDoc} */ @Override - protected void executeAdd() { + protected void executeAdd(final List addedFiles, final Map copiedFiles) { // Filter added files before further processing final Map> sortedFiles; try { - sortedFiles = GitUtil.sortFilesByGitRoot(myAddedFiles, true); + sortedFiles = GitUtil.sortFilesByGitRoot(addedFiles, true); } catch (VcsException e) { throw new RuntimeException("The exception is not expected here", e); } final HashSet retainedFiles = new HashSet(); final ProgressManager progressManager = ProgressManager.getInstance(); - progressManager.runProcessWithProgressSynchronously(new Runnable() { - public void run() { - ProgressIndicator pi = progressManager.getProgressIndicator(); + progressManager.run(new Task.Backgroundable(myProject, GitBundle.getString("vfs.listener.checking.ignored"), false) { + @Override + public void run(@NotNull ProgressIndicator pi) { for (Map.Entry> e : sortedFiles.entrySet()) { VirtualFile root = e.getKey(); pi.setText(root.getPresentableUrl()); @@ -146,11 +146,26 @@ public class GitVFSListener extends VcsVFSListener { }); } } + addedFiles.retainAll(retainedFiles); + UIUtil.invokeLaterIfNeeded(new Runnable() { + @Override + public void run() { + originalExecuteAdd(addedFiles, copiedFiles); + } + }); } } - }, GitBundle.getString("vfs.listener.checking.ignored"), false, myProject); - myAddedFiles.retainAll(retainedFiles); - super.executeAdd(); + }); + } + + /** + * The version of execute add before overriding + * + * @param addedFiles the added files + * @param copiedFiles the copied files + */ + private void originalExecuteAdd(List addedFiles, final Map copiedFiles) { + super.executeAdd(addedFiles, copiedFiles); } /** diff --git a/plugins/groovy/src/META-INF/plugin.xml b/plugins/groovy/src/META-INF/plugin.xml index 8b085b2dd8cf..18d7de6eaea2 100644 --- a/plugins/groovy/src/META-INF/plugin.xml +++ b/plugins/groovy/src/META-INF/plugin.xml @@ -51,6 +51,7 @@ + @@ -70,6 +71,8 @@ + + diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java index 5db12cf6ed1c..8f6005b61cb6 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java @@ -91,6 +91,7 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.types.GrClosureSignatureUtil; import org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils; import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil; +import org.jetbrains.plugins.groovy.lang.resolve.noncode.GrInheritConstructorContributor; import org.jetbrains.plugins.groovy.lang.resolve.processors.PropertyResolverProcessor; import org.jetbrains.plugins.groovy.overrideImplement.GroovyOverrideImplementUtil; import org.jetbrains.plugins.groovy.overrideImplement.quickFix.ImplementMethodsQuickFix; @@ -289,6 +290,8 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator { final PsiClass superClass = typeDefinition.getSuperClass(); if (superClass == null) return; + if (GrInheritConstructorContributor.hasInheritConstructorsAnnotation(typeDefinition)) return; + PsiMethod defConstructor = getDefaultConstructor(superClass); boolean hasImplicitDefConstructor = superClass.getConstructors().length ==0; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/AbstractDslIndexedRootsProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/AbstractDslIndexedRootsProvider.java index e8c01b69eac4..de632f999bdb 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/AbstractDslIndexedRootsProvider.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/AbstractDslIndexedRootsProvider.java @@ -18,13 +18,14 @@ package org.jetbrains.plugins.groovy.dsl; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.PathUtil; +import com.intellij.util.indexing.IndexableSetContributor; import java.io.File; import java.util.Collections; import java.util.Set; -public class AbstractDslIndexedRootsProvider implements GroovyDslIndexedRootProvider { - private final Set ourDslsDirs; +public class AbstractDslIndexedRootsProvider extends IndexableSetContributor implements GroovyDslIndexedRootProvider{ + private final Set ourDslsDirs; public AbstractDslIndexedRootsProvider() { final File jarPath = new File(PathUtil.getJarPathForClass(getClass())); @@ -38,7 +39,7 @@ public class AbstractDslIndexedRootsProvider implements GroovyDslIndexedRootProv final VirtualFile parent = LocalFileSystem.getInstance().refreshAndFindFileByPath(dirPath); assert parent != null : dirPath; parent.getChildren(); - ourDslsDirs = Collections.singleton(parent.getUrl()); + ourDslsDirs = Collections.singleton(parent); parent.refresh(true, true); } @@ -46,7 +47,8 @@ public class AbstractDslIndexedRootsProvider implements GroovyDslIndexedRootProv return "standardDsls"; } - public Set getRootsToIndex() { + @Override + public Set getAdditionalRootsToIndex() { return ourDslsDirs; } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/holders/DelegatedMembersHolder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/holders/DelegatedMembersHolder.java index 6d9afbaba752..ba55a725a2ef 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/holders/DelegatedMembersHolder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/holders/DelegatedMembersHolder.java @@ -21,6 +21,7 @@ import com.intellij.psi.ResolveState; import com.intellij.psi.scope.NameHint; import com.intellij.psi.scope.PsiScopeProcessor; import com.intellij.util.containers.hash.HashSet; +import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil; import java.util.Set; @@ -36,11 +37,10 @@ public class DelegatedMembersHolder implements CustomMembersHolder { } public boolean processMembers(PsiScopeProcessor processor) { - final NameHint nameHint = processor.getHint(NameHint.KEY); - final String expectedName = nameHint == null ? null : nameHint.getName(ResolveState.initial()); + String name = ResolveUtil.getNameHint(processor); for (PsiMember member : myMembers) { - if ((expectedName == null || expectedName.equals(member.getName())) && !processor.execute(member, ResolveState.initial())) { + if ((name == null || name.equals(member.getName())) && !processor.execute(member, ResolveState.initial())) { return false; } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GroovyConstructorUsagesSearchHelper.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GroovyConstructorUsagesSearchHelper.java index a67e4ef7680b..9a00b46a3c04 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GroovyConstructorUsagesSearchHelper.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GroovyConstructorUsagesSearchHelper.java @@ -22,10 +22,12 @@ import com.intellij.openapi.util.NullableComputable; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import com.intellij.psi.impl.light.LightMemberReference; +import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.SearchScope; import com.intellij.psi.search.searches.DirectClassInheritorsSearch; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.util.Processor; +import org.jetbrains.plugins.groovy.GroovyFileType; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; @@ -45,9 +47,14 @@ public class GroovyConstructorUsagesSearchHelper { private GroovyConstructorUsagesSearchHelper() { } - public static boolean execute(final PsiMethod constructor, final SearchScope searchScope, final Processor consumer) { + public static boolean execute(final PsiMethod constructor, SearchScope searchScope, final Processor consumer) { if (!constructor.isConstructor()) return true; - final PsiClass clazz = ApplicationManager.getApplication().runReadAction(new NullableComputable(){ + + if (searchScope instanceof GlobalSearchScope) { + searchScope = GlobalSearchScope.getScopeRestrictedByFileTypes((GlobalSearchScope)searchScope, GroovyFileType.GROOVY_FILE_TYPE); + } + + final PsiClass clazz = ApplicationManager.getApplication().runReadAction(new NullableComputable() { public PsiClass compute() { return constructor.getContainingClass(); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/AntBuilderMethod.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/AntBuilderMethod.java index 27857d70ffde..f5637b62ef51 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/AntBuilderMethod.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/AntBuilderMethod.java @@ -4,7 +4,6 @@ import com.intellij.lang.ant.dom.AntDomExtender; import com.intellij.lang.ant.psi.impl.AntIntrospector; import com.intellij.psi.*; import com.intellij.psi.impl.light.LightMethodBuilder; -import com.intellij.psi.scope.NameHint; import com.intellij.psi.scope.PsiScopeProcessor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -48,15 +47,13 @@ class AntBuilderMethod extends LightMethodBuilder implements GrBuilderMethod { public boolean processNestedElements(PsiScopeProcessor processor) { final AntIntrospector introspector = AntDomExtender.getIntrospector(myAntClass); if (introspector != null) { - final NameHint hint = processor.getHint(NameHint.KEY); + String expectedName = ResolveUtil.getNameHint(processor); final PsiType closureType = getParameterList().getParameters()[1].getType(); for (String name : Collections.list(introspector.getNestedElements())) { - if (hint == null || hint.getName(ResolveState.initial()).equals(name)) { + if (expectedName == null || expectedName.equals(name)) { final AntBuilderMethod method = new AntBuilderMethod(myPlace, name, closureType, introspector.getElementType(name)); - if (!ResolveUtil.processElement(processor, method)) { - return false; - } + if (!processor.execute(method, ResolveState.initial())) return false; } } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionUtil.java index f09e23bc2fd7..1293b1b7f8f8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionUtil.java @@ -32,6 +32,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes; import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement; +import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration; @@ -48,6 +49,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrClassTypeElement; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; +import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil; import static org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils.*; @@ -287,7 +289,14 @@ public class GroovyCompletionUtil { } public static boolean hasConstructorParameters(PsiClass clazz) { - final PsiMethod[] constructors = clazz.getConstructors(); + final PsiMethod[] constructors; + if (clazz instanceof GroovyPsiElement) { + constructors = ResolveUtil.getAllClassConstructors(clazz, (GroovyPsiElement)clazz, PsiSubstitutor.EMPTY); + } + else { + constructors = clazz.getConstructors(); + } + for (PsiMethod constructor : constructors) { if (constructor.getParameterList().getParametersCount() > 0) return true; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyInsertHandler.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyInsertHandler.java index ddf5d564bd12..ffe728bd3e7f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyInsertHandler.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyInsertHandler.java @@ -30,6 +30,7 @@ import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes; import org.jetbrains.plugins.groovy.lang.psi.GrControlFlowOwner; +import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationNameValuePair; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression; @@ -37,6 +38,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrRefere import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement; import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; +import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil; import java.util.Arrays; @@ -114,7 +116,7 @@ public class GroovyInsertHandler implements InsertHandler { parent.getParent() instanceof GrNewExpression && (offset == text.length() || !text.substring(offset).trim().startsWith("("))) { document.insertString(offset, "()"); - final PsiMethod[] methods = clazz.getConstructors(); + final PsiMethod[] methods = ResolveUtil.getAllClassConstructors(clazz, (GroovyPsiElement)parent, PsiSubstitutor.EMPTY); for (PsiMethod method : methods) { if (method.getParameterList().getParameters().length > 0) { caretModel.moveToOffset(offset + 1); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/handlers/AfterNewClassInsertHandler.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/handlers/AfterNewClassInsertHandler.java index b4006fe9c70e..58c5e4c43d49 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/handlers/AfterNewClassInsertHandler.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/handlers/AfterNewClassInsertHandler.java @@ -28,11 +28,12 @@ import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.util.Condition; import com.intellij.psi.*; -import com.intellij.psi.util.PsiUtil; import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement; +import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; +import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil; /** * @author Maxim.Medvedev @@ -47,13 +48,16 @@ public class AfterNewClassInsertHandler implements InsertHandler item) { - final PsiClass psiClass = PsiUtil.resolveClassInType(myClassType); + final PsiClassType.ClassResolveResult resolveResult = myClassType.resolveGenerics(); + final PsiClass psiClass = resolveResult.getElement(); if (psiClass == null || !psiClass.isValid()) { return; } - - - PsiMethod[] constructors = psiClass.getConstructors(); + PsiElement place = myPlace; + if (!(place instanceof GroovyPsiElement)) { + place = myPlace.getContainingFile(); + } + PsiMethod[] constructors = ResolveUtil.getAllClassConstructors(psiClass, (GroovyPsiElement)place, resolveResult.getSubstitutor()); final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(psiClass.getProject()).getResolveHelper(); boolean hasParams = ContainerUtil.or(constructors, new Condition() { public boolean value(PsiMethod psiMethod) { @@ -151,8 +155,8 @@ public class AfterNewClassInsertHandler implements InsertHandler)Function.ID, context) != null) return true; if (args.length == 1) { + final GrClosureParameter[] parameters = signature.getParameters(); + if (parameters.length == 1 && parameters[0].getType() instanceof PsiArrayType) return false; PsiType arg = args[0]; if (arg instanceof GrTupleType) { args = ((GrTupleType)arg).getComponentTypes(); @@ -305,6 +307,16 @@ public class GrClosureSignatureUtil { return mapParametersToArguments(signature, list, GrClosableBlock.EMPTY_ARRAY, manager, scope); } + private static class InnerArg { + List list; + PsiType type; + + InnerArg(PsiType type, PsiElement... elements) { + this.list = new ArrayList(Arrays.asList(elements)); + this.type = type; + } + } + @Nullable public static ArgInfo[] mapParametersToArguments(@NotNull GrClosureSignature signature, @NotNull GrArgumentList list, @@ -315,16 +327,6 @@ public class GrClosureSignatureUtil { boolean hasNamedArgs = namedArgs.length > 0; GrClosureParameter[] params = signature.getParameters(); - class InnerArg { - List list; - PsiType type; - - InnerArg(PsiType type, PsiElement... elements) { - this.list = new ArrayList(Arrays.asList(elements)); - this.type = type; - } - } - List innerArgs = new ArrayList(); if (hasNamedArgs) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java index d5a72ae89ca2..b1308def84aa 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java @@ -51,6 +51,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGd import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember; import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl; import org.jetbrains.plugins.groovy.lang.resolve.processors.ClassResolverProcessor; +import org.jetbrains.plugins.groovy.lang.resolve.processors.MethodResolverProcessor; import org.jetbrains.plugins.groovy.lang.resolve.processors.PropertyResolverProcessor; import org.jetbrains.plugins.groovy.lang.resolve.processors.ResolverProcessor; @@ -130,6 +131,16 @@ public class ResolveUtil { return true; } + @Nullable + public static String getNameHint(PsiScopeProcessor processor) { + NameHint nameHint = processor.getHint(NameHint.KEY); + if (nameHint == null) { + return null; + } + + return nameHint.getName(ResolveState.initial()); + } + /** * @deprecated * use {@link #processElement(PsiScopeProcessor, PsiNamedElement, ResolveState)} instead @@ -493,4 +504,27 @@ public class ResolveUtil { } return variants; } + + public static GroovyResolveResult[] getNonCodeConstructors(PsiClass psiClass, GroovyPsiElement place, PsiSubstitutor substitutor) { + final PsiClassType qualifierType = JavaPsiFacade.getElementFactory(psiClass.getProject()).createType(psiClass); + final MethodResolverProcessor processor = new MethodResolverProcessor(psiClass.getName(), place, true, null, null, PsiType.EMPTY_ARRAY); + NonCodeMembersContributor + .runContributors(qualifierType, processor, place, ResolveState.initial().put(PsiSubstitutor.KEY, substitutor)); + return processor.getCandidates(); + } + + public static PsiMethod[] getAllClassConstructors(PsiClass psiClass, GroovyPsiElement place, PsiSubstitutor substitutor) { + final PsiMethod[] realConstructors = psiClass.getConstructors(); + final GroovyResolveResult[] nonCodeConstructors = getNonCodeConstructors(psiClass, place, substitutor); + PsiMethod[] constructors = new PsiMethod[realConstructors.length + nonCodeConstructors.length]; + System.arraycopy(realConstructors, 0, constructors, 0, realConstructors.length); + for (int i = 0; i < nonCodeConstructors.length; i++) { + GroovyResolveResult nonCodeConstructor = nonCodeConstructors[i]; + final PsiElement element = nonCodeConstructor.getElement(); + if (element instanceof PsiMethod) { + constructors[i + realConstructors.length] = (PsiMethod)element; + } + } + return constructors; + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/noncode/GrInheritConstructorContributor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/noncode/GrInheritConstructorContributor.java new file mode 100644 index 000000000000..cf2222a6c1e1 --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/noncode/GrInheritConstructorContributor.java @@ -0,0 +1,70 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.groovy.lang.resolve.noncode; + +import com.intellij.psi.*; +import com.intellij.psi.scope.PsiScopeProcessor; +import com.intellij.psi.util.TypeConversionUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition; +import org.jetbrains.plugins.groovy.lang.resolve.NonCodeMembersContributor; + +/** + * @author Maxim.Medvedev + */ +public class GrInheritConstructorContributor extends NonCodeMembersContributor { + public static final String INHERIT_CONSTRUCTOR_NAME = "groovy.transform.InheritConstructors"; + + @Override + public void processDynamicElements(@NotNull PsiType qualifierType, PsiScopeProcessor processor, PsiElement place, ResolveState state) { + if (!(qualifierType instanceof PsiClassType)) return; + final PsiClassType.ClassResolveResult resolveResult = ((PsiClassType)qualifierType).resolveGenerics(); + final PsiClass psiClass = resolveResult.getElement(); + if (!(psiClass instanceof GrTypeDefinition) || + ((GrTypeDefinition)psiClass).isAnonymous() || + psiClass.isInterface() || + psiClass.isEnum()) { + return; + } + + if (!hasInheritConstructorsAnnotation(psiClass)) return; + + final PsiClass superClass = psiClass.getSuperClass(); + if (superClass == null) return; + final PsiSubstitutor substitutor = state.get(PsiSubstitutor.KEY); + final PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, psiClass, substitutor); + final ResolveState currentState = state.put(PsiSubstitutor.KEY, superClassSubstitutor); + + final PsiMethod[] constructors = superClass.getConstructors(); + for (PsiMethod constructor : constructors) { + if (!processor.execute(constructor, currentState)) return; + } + } + + public static boolean hasInheritConstructorsAnnotation(PsiClass psiClass) { + final PsiModifierList modifierList = psiClass.getModifierList(); + if (modifierList == null) return false; + final PsiAnnotation[] annotations = modifierList.getAnnotations(); + boolean hasInheritConstructors = false; + for (PsiAnnotation annotation : annotations) { + if (INHERIT_CONSTRUCTOR_NAME.equals(annotation.getQualifiedName())) { + hasInheritConstructors = true; + break; + } + } + return hasInheritConstructors; + } +} diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyCompletionTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyCompletionTest.java index dda8d5055d00..d04ccbb008d8 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyCompletionTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyCompletionTest.java @@ -293,4 +293,17 @@ public class GroovyCompletionTest extends LightCodeInsightFixtureTestCase { public void testIncSmartCompletion() throws Exception { doSmartCompletion("a", "b"); } + + public void testInheritConstructorsAnnotation() throws Throwable { + myFixture.addFileToProject("groovy/transform/InheritConstructors.java", "package groovy.transform;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;@Retention(RetentionPolicy.SOURCE)\n" + + "@Target({ElementType.TYPE})\n" + + "public @interface InheritConstructors {\n" + + "}"); + doSmartTest(); + } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/LightGroovyTestCase.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/LightGroovyTestCase.java index 53896f74b717..752f7280b92d 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/LightGroovyTestCase.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/LightGroovyTestCase.java @@ -43,7 +43,7 @@ public abstract class LightGroovyTestCase extends LightCodeInsightFixtureTestCas } public Sdk getSdk() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.java index 83eb7bbe6af1..1ed0cf0d6444 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.java @@ -26,6 +26,7 @@ import com.intellij.openapi.module.ModifiableModuleModel; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.module.StdModuleTypes; +import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; import com.intellij.openapi.roots.*; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.JDOMExternalizable; @@ -56,6 +57,7 @@ import java.util.List; public abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestCase { private TempDirTestFixture myMainOutput; + @Override protected void setUp() throws Exception { myMainOutput = new TempDirTestFixtureImpl(); @@ -71,12 +73,12 @@ public abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestC }.execute(); addGroovyLibrary(myModule, getName().contains("1_7")); - } @Override protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) throws Exception { moduleBuilder.setMockJdkLevel(JavaModuleFixtureBuilder.MockJdkLevel.jdk15); + moduleBuilder.addJdk(JavaSdkImpl.getMockJdk14Path().getPath()); super.tuneFixture(moduleBuilder); } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/dsl/GroovyDslTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/dsl/GroovyDslTest.groovy index dfda8d3181b5..cdcabd3c709a 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/dsl/GroovyDslTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/dsl/GroovyDslTest.groovy @@ -16,15 +16,25 @@ package org.jetbrains.plugins.groovy.dsl; +import com.intellij.openapi.module.Module +import com.intellij.openapi.roots.ContentEntry +import com.intellij.openapi.roots.ModifiableRootModel import com.intellij.psi.PsiFile -import com.intellij.testFramework.builders.JavaModuleFixtureBuilder -import org.jetbrains.plugins.groovy.lang.completion.CompletionTestBase +import com.intellij.testFramework.LightProjectDescriptor +import com.intellij.testFramework.PsiTestUtil +import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor +import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import org.jetbrains.plugins.groovy.util.TestUtils /** * @author peter */ -public class GroovyDslTest extends CompletionTestBase { +public class GroovyDslTest extends LightCodeInsightFixtureTestCase { + static def descriptor = new DefaultLightProjectDescriptor() { + @Override def void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) { + PsiTestUtil.addLibrary(module, model, "GROOVY", TestUtils.getMockGroovyLibraryHome(), TestUtils.GROOVY_JAR); + } + } @Override protected String getBasePath() { @@ -84,7 +94,7 @@ public class GroovyDslTest extends CompletionTestBase { }) """) } - + public void testDelegateToArgument2() throws Throwable { doCustomTest(""" def ctx = context(scope: closureScope(isArgument: true)) @@ -109,9 +119,8 @@ public class GroovyDslTest extends CompletionTestBase { ) } - @Override - protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) { - moduleBuilder.addLibraryJars("GROOVY", TestUtils.getMockGroovyLibraryHome(), TestUtils.GROOVY_JAR); + @Override protected LightProjectDescriptor getProjectDescriptor() { + return descriptor; } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/dsl/GroovyTransformationsTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/dsl/GroovyTransformationsTest.groovy index 864dbb0a0227..58150bf681e3 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/dsl/GroovyTransformationsTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/dsl/GroovyTransformationsTest.groovy @@ -1,14 +1,23 @@ package org.jetbrains.plugins.groovy.dsl -import com.intellij.psi.PsiFile -import com.intellij.testFramework.builders.JavaModuleFixtureBuilder -import org.jetbrains.plugins.groovy.lang.completion.CompletionTestBase +import com.intellij.openapi.module.Module +import com.intellij.openapi.roots.ContentEntry +import com.intellij.openapi.roots.ModifiableRootModel +import com.intellij.testFramework.LightProjectDescriptor +import com.intellij.testFramework.PsiTestUtil +import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor +import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import org.jetbrains.plugins.groovy.util.TestUtils /** * @author ilyas */ -class GroovyTransformationsTest extends CompletionTestBase { +class GroovyTransformationsTest extends LightCodeInsightFixtureTestCase { + static def descriptor = new DefaultLightProjectDescriptor() { + @Override def void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) { + PsiTestUtil.addLibrary(module, model, "GROOVY", TestUtils.getMockGroovy1_7LibraryHome(), TestUtils.GROOVY_JAR_17); + } + } @Override protected String getBasePath() { @@ -23,9 +32,8 @@ class GroovyTransformationsTest extends CompletionTestBase { myFixture.testCompletionVariants(getTestName(false) + ".groovy", variants) } - @Override - protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) { - moduleBuilder.addLibraryJars("GROOVY", TestUtils.getMockGroovy1_7LibraryHome(), TestUtils.GROOVY_JAR_17); + @Override protected LightProjectDescriptor getProjectDescriptor() { + return descriptor; } public void testDelegateAnnotation() throws Throwable { doPlainTest() } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/gant/GantReferenceCompletionTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/gant/GantReferenceCompletionTest.groovy index e05bdbc4687c..5f684771af7f 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/gant/GantReferenceCompletionTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/gant/GantReferenceCompletionTest.groovy @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jetbrains.plugins.groovy.gant; @@ -139,7 +154,7 @@ class GantProjectDescriptor implements LightProjectDescriptor { } public Sdk getSdk() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java index d0b7c1fd300f..95530e311aa9 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java @@ -266,4 +266,16 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase { GroovyImportsTracker.getInstance(getProject()).getUnusedImportStatements(((GroovyFile)myFixture.getFile())); assertEquals(0, unusedImportStatements.size()); } + + public void testSignatureIsNotApplicableToList() throws Exception { + doTest(); + } + + public void testInheritConstructorsAnnotation() throws Exception { + doTest(); + } + + public void testCollectionAssignments() throws Exception { + doTest(new GroovyAssignabilityCheckInspection()); + } } \ No newline at end of file diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/completion/CompletionTestBase.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/completion/CompletionTestBase.java index 96b8da3defba..ba81c1d88d93 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/completion/CompletionTestBase.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/completion/CompletionTestBase.java @@ -4,13 +4,11 @@ import com.intellij.codeInsight.CodeInsightSettings; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.LookupManager; import com.intellij.codeInsight.lookup.impl.LookupImpl; -import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.util.Condition; import com.intellij.psi.PsiMember; import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.plugins.groovy.CompositeCompletionData; -import org.jetbrains.plugins.groovy.GroovyFileType; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; import org.jetbrains.plugins.groovy.util.TestUtils; @@ -19,6 +17,7 @@ import java.util.Comparator; import java.util.List; /** + * @deprecated use {@link com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase} * author ven */ public abstract class CompletionTestBase extends JavaCodeInsightFixtureTestCase { @@ -81,10 +80,6 @@ public abstract class CompletionTestBase extends JavaCodeInsightFixtureTestCase return "groovy"; } - protected FileType getFileType() { - return GroovyFileType.GROOVY_FILE_TYPE; - } - protected boolean addKeywords() { return true; } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/util/TestUtils.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/util/TestUtils.java index d8ca5fd0c791..acd4c395d50a 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/util/TestUtils.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/util/TestUtils.java @@ -63,7 +63,7 @@ public abstract class TestUtils { } public static String getMockGroovy1_7LibraryName() { - return getMockGroovy1_7LibraryHome()+"/groovy-all-1.7.jar"; + return getMockGroovy1_7LibraryHome()+"/groovy-all-1.7.3.jar"; } public static PsiFile createPseudoPhysicalGroovyFile(final Project project, final String text) throws IncorrectOperationException { diff --git a/plugins/groovy/testdata/groovy/completion/InheritConstructorsAnnotation.groovy b/plugins/groovy/testdata/groovy/completion/InheritConstructorsAnnotation.groovy new file mode 100644 index 000000000000..748ce3a69d4a --- /dev/null +++ b/plugins/groovy/testdata/groovy/completion/InheritConstructorsAnnotation.groovy @@ -0,0 +1,12 @@ +import groovy.transform.InheritConstructors + +class Base { + def Base(Date x) {} +} + +@InheritConstructors +class Inheritor extends Base { + +} + +Inheritor i = new Inheri \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/completion/InheritConstructorsAnnotation_after.groovy b/plugins/groovy/testdata/groovy/completion/InheritConstructorsAnnotation_after.groovy new file mode 100644 index 000000000000..a7712aa4ec28 --- /dev/null +++ b/plugins/groovy/testdata/groovy/completion/InheritConstructorsAnnotation_after.groovy @@ -0,0 +1,12 @@ +import groovy.transform.InheritConstructors + +class Base { + def Base(Date x) {} +} + +@InheritConstructors +class Inheritor extends Base { + +} + +Inheritor i = new Inheritor() \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/oldCompletion/keyword/imp4.test b/plugins/groovy/testdata/groovy/oldCompletion/keyword/imp4.test index 7f2476687da7..35f7f2ff4ddb 100644 --- a/plugins/groovy/testdata/groovy/oldCompletion/keyword/imp4.test +++ b/plugins/groovy/testdata/groovy/oldCompletion/keyword/imp4.test @@ -1,6 +1,6 @@ import static a.b ----- META-INF -com java -javax \ No newline at end of file +javax +org \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/oldCompletion/keyword/var3.test b/plugins/groovy/testdata/groovy/oldCompletion/keyword/var3.test index 24fcb08c1220..d77d173b6cc5 100644 --- a/plugins/groovy/testdata/groovy/oldCompletion/keyword/var3.test +++ b/plugins/groovy/testdata/groovy/oldCompletion/keyword/var3.test @@ -11,7 +11,7 @@ class A { } ----- META-INF -com java javax +org static \ No newline at end of file diff --git a/plugins/groovy/testdata/highlighting/CollectionAssignments.groovy b/plugins/groovy/testdata/highlighting/CollectionAssignments.groovy new file mode 100644 index 000000000000..6a16aadade4a --- /dev/null +++ b/plugins/groovy/testdata/highlighting/CollectionAssignments.groovy @@ -0,0 +1,4 @@ +class Pair {} +List otherPairs = new ArrayList(); +List pairs = otherPairs.findAll({it != null}) +List pairs2 = otherPairs.findAll({it != null}) \ No newline at end of file diff --git a/plugins/groovy/testdata/highlighting/InheritConstructorsAnnotation.groovy b/plugins/groovy/testdata/highlighting/InheritConstructorsAnnotation.groovy new file mode 100644 index 000000000000..3683804d6205 --- /dev/null +++ b/plugins/groovy/testdata/highlighting/InheritConstructorsAnnotation.groovy @@ -0,0 +1,13 @@ +import groovy.transform.InheritConstructors + +class Base { + def Base(T x) {} +} + +@InheritConstructors +class Inheritor extends Base { + +} + +Inheritor i = new Inheritor(new Date()) +Inheritor i2 = new Inheritor(2) diff --git a/plugins/groovy/testdata/highlighting/SignatureIsNotApplicableToList.groovy b/plugins/groovy/testdata/highlighting/SignatureIsNotApplicableToList.groovy new file mode 100644 index 000000000000..be1878b6974d --- /dev/null +++ b/plugins/groovy/testdata/highlighting/SignatureIsNotApplicableToList.groovy @@ -0,0 +1,3 @@ +def foo(int... i) {} +def list = [1, 2, 3] +foo(list) \ No newline at end of file diff --git a/plugins/groovy/testdata/mockGroovyLib1.7/groovy-all-1.7.3.jar b/plugins/groovy/testdata/mockGroovyLib1.7/groovy-all-1.7.3.jar new file mode 100644 index 000000000000..4a628324cfa4 Binary files /dev/null and b/plugins/groovy/testdata/mockGroovyLib1.7/groovy-all-1.7.3.jar differ diff --git a/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/MavenModelConverter.java b/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/MavenModelConverter.java index 08e033a4ec5d..20cbe56e66af 100644 --- a/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/MavenModelConverter.java +++ b/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/MavenModelConverter.java @@ -121,7 +121,7 @@ public class MavenModelConverter { } private static List ensurePatterns(List patterns) { - return patterns == null ? Collections.EMPTY_LIST : patterns; + return patterns == null ? Collections.emptyList() : patterns; } private static List convertRepositories(List repositories) { @@ -282,7 +282,7 @@ public class MavenModelConverter { } private static Element xppToElement(Xpp3Dom xpp) { - Element result = null; + Element result; try { result = new Element(xpp.getName()); } diff --git a/plugins/maven/facade-impl/test/org/jetbrains/idea/maven/embedder/MavenFacadeEmbedderTest.java b/plugins/maven/facade-impl/test/org/jetbrains/idea/maven/embedder/MavenFacadeEmbedderTest.java index 7163d401f576..80c44ffdb473 100644 --- a/plugins/maven/facade-impl/test/org/jetbrains/idea/maven/embedder/MavenFacadeEmbedderTest.java +++ b/plugins/maven/facade-impl/test/org/jetbrains/idea/maven/embedder/MavenFacadeEmbedderTest.java @@ -83,7 +83,7 @@ public class MavenFacadeEmbedderTest extends MavenImportingTestCase { "1"); myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS); - MavenWrapperExecutionResult result = myEmbedder.execute(myProjectPom, Collections.EMPTY_LIST, Arrays.asList("compile")); + MavenWrapperExecutionResult result = myEmbedder.execute(myProjectPom, Collections.emptyList(), Arrays.asList("compile")); assertNotNull(result.projectData); assertNotNull(new File(getProjectPath(), "target").exists()); @@ -108,7 +108,7 @@ public class MavenFacadeEmbedderTest extends MavenImportingTestCase { ""); myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS); - MavenWrapperExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.EMPTY_LIST); + MavenWrapperExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.emptyList()); assertNotNull(result.projectData); assertOrderedElementsAreEqual(result.unresolvedArtifacts); @@ -124,7 +124,7 @@ public class MavenFacadeEmbedderTest extends MavenImportingTestCase { "1"); myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS); - MavenWrapperExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.EMPTY_LIST); + MavenWrapperExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.emptyList()); MavenModel project = result.projectData.mavenModel; assertNotNull(project); @@ -160,7 +160,7 @@ public class MavenFacadeEmbedderTest extends MavenImportingTestCase { ""); myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS); - MavenWrapperExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.EMPTY_LIST); + MavenWrapperExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.emptyList()); assertNotNull(result.projectData); assertOrderedElementsAreEqual(result.unresolvedArtifacts); @@ -192,7 +192,7 @@ public class MavenFacadeEmbedderTest extends MavenImportingTestCase { ""); myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS); - MavenWrapperExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.EMPTY_LIST); + MavenWrapperExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.emptyList()); assertNotNull(result.projectData); assertOrderedElementsAreEqual(result.unresolvedArtifacts); @@ -245,7 +245,7 @@ public class MavenFacadeEmbedderTest extends MavenImportingTestCase { ""); myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS); - MavenWrapperExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.EMPTY_LIST); + MavenWrapperExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.emptyList()); assertNotNull(result.projectData); assertOrderedElementsAreEqual(result.unresolvedArtifacts, new MavenId("fff", "zzz", "666")); @@ -267,7 +267,7 @@ public class MavenFacadeEmbedderTest extends MavenImportingTestCase { ""); myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS); - MavenWrapperExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.EMPTY_LIST); + MavenWrapperExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.emptyList()); assertNotNull(result.projectData); assertOrderedElementsAreEqual(result.unresolvedArtifacts, new MavenId("fff", "zzz", "666")); @@ -285,7 +285,7 @@ public class MavenFacadeEmbedderTest extends MavenImportingTestCase { "1" + "pom"); myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS); - myEmbedder.execute(m, Collections.EMPTY_LIST, Arrays.asList("install")); + myEmbedder.execute(m, Collections.emptyList(), Arrays.asList("install")); myEmbedder.reset(); File fooParentFile = new File(repo, "test/foo-parent/1/foo-parent-1.pom"); assertTrue(fooParentFile.exists()); @@ -300,7 +300,7 @@ public class MavenFacadeEmbedderTest extends MavenImportingTestCase { " 1" + ""); myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS); - myEmbedder.execute(m, Collections.EMPTY_LIST, Arrays.asList("install")); + myEmbedder.execute(m, Collections.emptyList(), Arrays.asList("install")); myEmbedder.reset(); assertTrue(new File(repo, "test/foo/1/foo-1.pom").exists()); @@ -320,7 +320,7 @@ public class MavenFacadeEmbedderTest extends MavenImportingTestCase { ""); myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS); - MavenWrapperExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.EMPTY_LIST); + MavenWrapperExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.emptyList()); assertNotNull(result.projectData); assertOrderedElementsAreEqual(result.unresolvedArtifacts, new MavenId("test", "foo-parent", "1")); @@ -342,7 +342,7 @@ public class MavenFacadeEmbedderTest extends MavenImportingTestCase { ""); myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS); - MavenWrapperExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.EMPTY_LIST); + MavenWrapperExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.emptyList()); assertNotNull(result); assertOrderedElementsAreEqual(result.unresolvedArtifacts, new MavenId("fff", "zzz", "666")); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/FacetImporter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/FacetImporter.java index 4ac581ba9c12..e3d639359e6b 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/FacetImporter.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/FacetImporter.java @@ -136,18 +136,10 @@ public abstract class FacetImporter elements = new ArrayList(); elements.add(p.getBuildDirectory()); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigator.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigator.java index 2fed5ca3415d..5ca5529e766b 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigator.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigator.java @@ -351,11 +351,11 @@ public class MavenProjectsNavigator extends SimpleProjectComponent implements Pe public void projectResolved(Pair projectWithChanges, NativeMavenProjectHolder nativeMavenProject, Object message) { - scheduleUpdateProjects(Collections.singletonList(projectWithChanges.first), Collections.EMPTY_LIST); + scheduleUpdateProjects(Collections.singletonList(projectWithChanges.first), Collections.emptyList()); } public void pluginsResolved(MavenProject project) { - scheduleUpdateProjects(Collections.singletonList(project), Collections.EMPTY_LIST); + scheduleUpdateProjects(Collections.singletonList(project), Collections.emptyList()); } private void scheduleUpdateProjects(final List projects, final List deleted) { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java index 2dec57b9a9a0..cf60b185d88c 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java @@ -640,7 +640,7 @@ public class MavenProjectsManager extends SimpleProjectComponent myWatcher.scheduleUpdateAll(force, forceImport); } else { - myWatcher.scheduleUpdate(MavenUtil.collectFiles(projects), Collections.EMPTY_LIST, force, forceImport); + myWatcher.scheduleUpdate(MavenUtil.collectFiles(projects), Collections.emptyList(), force, forceImport); } } }); @@ -981,7 +981,7 @@ public class MavenProjectsManager extends SimpleProjectComponent try { MavenUtil.run(myProject, "Downloading dependency...", new MavenTask() { public void run(MavenProgressIndicator indicator) throws MavenProcessCanceledException { - artifact[0] = myProjectsTree.downloadArtifact(mavenProject, id, myEmbeddersManager, new SoutMavenConsole(), indicator); + artifact[0] = MavenProjectsTree.downloadArtifact(mavenProject, id, myEmbeddersManager, new SoutMavenConsole(), indicator); } }); } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java index 8bfb6b6ea0c3..ad302348bb8e 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java @@ -671,7 +671,7 @@ public class MavenProjectsTree { }); } - private long getFileTimestamp(VirtualFile file) { + private static long getFileTimestamp(VirtualFile file) { if (file == null || !file.isValid()) return -1; return file.getTimeStamp(); } @@ -1085,7 +1085,7 @@ public class MavenProjectsTree { } } - public MavenArtifact downloadArtifact(MavenProject mavenProject, + public static MavenArtifact downloadArtifact(MavenProject mavenProject, MavenId id, MavenEmbeddersManager embeddersManager, MavenConsole console, @@ -1226,13 +1226,13 @@ public class MavenProjectsTree { public void fireUpdatedIfNecessary(Object message) { if (updatedProjectsWithChanges.isEmpty() && deletedProjects.isEmpty()) return; - fireProjectsUpdated(updatedProjectsWithChanges.isEmpty() - ? Collections.EMPTY_LIST - : MavenUtil.mapToList(updatedProjectsWithChanges), - deletedProjects.isEmpty() - ? Collections.EMPTY_LIST - : new ArrayList(deletedProjects), - message); + List mavenProjects = deletedProjects.isEmpty() + ? Collections.emptyList() + : new ArrayList(deletedProjects); + List> updated = updatedProjectsWithChanges.isEmpty() + ? Collections.>emptyList() + : MavenUtil.mapToList(updatedProjectsWithChanges); + fireProjectsUpdated(updated, mavenProjects, message); } } @@ -1240,7 +1240,7 @@ public class MavenProjectsTree { void run(MavenEmbedderWrapper embedder) throws MavenProcessCanceledException; } - public static abstract class Visitor { + public abstract static class Visitor { private Result result; public boolean shouldVisit(MavenProject project) { @@ -1265,7 +1265,7 @@ public class MavenProjectsTree { } } - public static abstract class SimpleVisitor extends Visitor { + public abstract static class SimpleVisitor extends Visitor { } private static class MavenProjectTimestamp { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/OpenOrCreateSettingsXmlAction.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/OpenOrCreateSettingsXmlAction.java index dc597d2caaf6..fcd73f31ec7b 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/OpenOrCreateSettingsXmlAction.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/OpenOrCreateSettingsXmlAction.java @@ -26,7 +26,7 @@ import java.util.List; public class OpenOrCreateSettingsXmlAction extends MavenOpenOrCreateFilesAction { protected List getFiles(AnActionEvent e) { File file = MavenActionUtil.getProjectsManager(e.getDataContext()).getGeneralSettings().getEffectiveUserSettingsIoFile(); - return file != null ? Collections.singletonList(file) : Collections.EMPTY_LIST; + return file != null ? Collections.singletonList(file) : Collections.emptyList(); } @Override diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectBuilder.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectBuilder.java index 7d9f2dde754a..129c2b1d5574 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectBuilder.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectBuilder.java @@ -155,7 +155,7 @@ public class MavenProjectBuilder extends ProjectImportBuilder { for (VirtualFile f : getParameters().myFiles) { MavenProject project = new MavenProject(f); process.setText2(ProjectBundle.message("maven.reading.pom", f.getPath())); - project.read(generalSettings, Collections.EMPTY_LIST, reader, locator); + project.read(generalSettings, Collections.emptyList(), reader, locator); uniqueProfiles.addAll(project.getProfilesIds()); } getParameters().myProfiles = new ArrayList(uniqueProfiles); diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenImportingTestCase.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenImportingTestCase.java index b08d7ad00ba2..6c47a8dd88c3 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenImportingTestCase.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenImportingTestCase.java @@ -465,7 +465,7 @@ public abstract class MavenImportingTestCase extends MavenTestCase { } protected Sdk createJdk(String versionName) { - return JavaSdkImpl.getMockJdk15(versionName); + return JavaSdkImpl.getMockJdk17(versionName); } protected void compileModules(String... moduleNames) { diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/MavenPerformanceTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/MavenPerformanceTest.java index e40f2b544b30..7dace904c9c7 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/MavenPerformanceTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/MavenPerformanceTest.java @@ -33,7 +33,7 @@ public abstract class MavenPerformanceTest extends MavenImportingTestCase { super.setUp(); VirtualFile file = LocalFileSystem.getInstance().findFileByPath("C:\\projects\\mvn\\_projects\\geronimo\\pom.xml"); initProjectsManager(false); - myProjectsManager.resetManagedFilesAndProfilesInTests(Collections.singletonList(file), Collections.EMPTY_LIST); + myProjectsManager.resetManagedFilesAndProfilesInTests(Collections.singletonList(file), Collections.emptyList()); } public void testReading() throws Exception { diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/indices/MavenIndicesManagerTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/indices/MavenIndicesManagerTest.java index 3948fad04cb4..68f6be2f3fbf 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/indices/MavenIndicesManagerTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/indices/MavenIndicesManagerTest.java @@ -48,14 +48,18 @@ public class MavenIndicesManagerTest extends MavenIndicesTestCase { File dir3 = myIndicesFixture.getRepositoryHelper().getTestData("dir\\foo\\"); File dir4 = myIndicesFixture.getRepositoryHelper().getTestData("dir/bar"); - List indices1 = myIndicesFixture.getIndicesManager().ensureIndicesExist(myProject, dir1, Collections.EMPTY_LIST); + List indices1 = myIndicesFixture.getIndicesManager().ensureIndicesExist(myProject, dir1, + Collections.>emptyList()); assertEquals(1, indices1.size()); assertTrue(myIndicesFixture.getIndicesManager().getIndices().contains(indices1.get(0))); - assertEquals(indices1, myIndicesFixture.getIndicesManager().ensureIndicesExist(myProject, dir2, Collections.EMPTY_LIST)); - assertEquals(indices1, myIndicesFixture.getIndicesManager().ensureIndicesExist(myProject, dir3, Collections.EMPTY_LIST)); + assertEquals(indices1, myIndicesFixture.getIndicesManager().ensureIndicesExist(myProject, dir2, + Collections.>emptyList())); + assertEquals(indices1, myIndicesFixture.getIndicesManager().ensureIndicesExist(myProject, dir3, + Collections.>emptyList())); - List indices2 = myIndicesFixture.getIndicesManager().ensureIndicesExist(myProject, dir4, Collections.EMPTY_LIST); + List indices2 = myIndicesFixture.getIndicesManager().ensureIndicesExist(myProject, dir4, + Collections.>emptyList()); assertFalse(indices1.get(0).equals(indices2.get(0))); } @@ -81,7 +85,7 @@ public class MavenIndicesManagerTest extends MavenIndicesTestCase { public void testIndexedArchetypes() throws Exception { myIndicesFixture.getRepositoryHelper().addTestData("archetypes"); myIndicesFixture.getIndicesManager().ensureIndicesExist(myProject, myIndicesFixture.getRepositoryHelper().getTestData("archetypes"), - Collections.EMPTY_LIST); + Collections.>emptyList()); assertArchetypeExists("org.apache.maven.archetypes:maven-archetype-foobar:1.0"); } @@ -122,4 +126,4 @@ public class MavenIndicesManagerTest extends MavenIndicesTestCase { } assertTrue(actualNames.toString(), actualNames.contains(archetypeId)); } -} \ No newline at end of file +} diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigatorTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigatorTest.java index 7d277c5c3de6..86a80e0b98e6 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigatorTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigatorTest.java @@ -50,7 +50,7 @@ public class MavenProjectsNavigatorTest extends MavenImportingTestCase { createModulePom("m", "test" + "m" + "1"); - myProjectsManager.resetManagedFilesAndProfilesInTests(Collections.singletonList(myProjectPom), Collections.EMPTY_LIST); + myProjectsManager.resetManagedFilesAndProfilesInTests(Collections.singletonList(myProjectPom), Collections.emptyList()); waitForReadingCompletion(); myProjectsManager.fireActivatedInTests(); diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectReaderTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectReaderTest.java index 9a850e87e675..cbc32728efe4 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectReaderTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectReaderTest.java @@ -220,10 +220,10 @@ public class MavenProjectReaderTest extends MavenTestCase { assertPathEquals(pathFromBasedir("src/test/java"), p.getBuild().getTestSources().get(0)); assertEquals(1, p.getBuild().getResources().size()); assertResource(p.getBuild().getResources().get(0), pathFromBasedir("src/main/resources"), - false, null, Collections.EMPTY_LIST, Collections.EMPTY_LIST); + false, null, Collections.emptyList(), Collections.emptyList()); assertEquals(1, p.getBuild().getTestResources().size()); assertResource(p.getBuild().getTestResources().get(0), pathFromBasedir("src/test/resources"), - false, null, Collections.EMPTY_LIST, Collections.EMPTY_LIST); + false, null, Collections.emptyList(), Collections.emptyList()); assertPathEquals(pathFromBasedir("target"), p.getBuild().getDirectory()); assertPathEquals(pathFromBasedir("target/classes"), p.getBuild().getOutputDirectory()); assertPathEquals(pathFromBasedir("target/test-classes"), p.getBuild().getTestOutputDirectory()); @@ -319,7 +319,7 @@ public class MavenProjectReaderTest extends MavenTestCase { true, "dir", Collections.singletonList("**.properties"), Collections.singletonList("**.xml")); assertEquals(1, p.getBuild().getTestResources().size()); assertResource(p.getBuild().getTestResources().get(0), pathFromBasedir("myTestRes"), - false, null, Collections.singletonList("**.properties"), Collections.EMPTY_LIST); + false, null, Collections.singletonList("**.properties"), Collections.emptyList()); assertPathEquals(pathFromBasedir("myOutput"), p.getBuild().getDirectory()); assertPathEquals(pathFromBasedir("myClasses"), p.getBuild().getOutputDirectory()); assertPathEquals(pathFromBasedir("myTestClasses"), p.getBuild().getTestOutputDirectory()); @@ -391,10 +391,10 @@ public class MavenProjectReaderTest extends MavenTestCase { assertPathEquals(pathFromBasedir("subDir/myTestSrc"), p.getBuild().getTestSources().get(0)); assertEquals(1, p.getBuild().getResources().size()); assertResource(p.getBuild().getResources().get(0), pathFromBasedir("subDir/myRes"), - false, null, Collections.EMPTY_LIST, Collections.EMPTY_LIST); + false, null, Collections.emptyList(), Collections.emptyList()); assertEquals(1, p.getBuild().getTestResources().size()); assertResource(p.getBuild().getTestResources().get(0), pathFromBasedir("subDir/myTestRes"), - false, null, Collections.EMPTY_LIST, Collections.EMPTY_LIST); + false, null, Collections.emptyList(), Collections.emptyList()); assertPathEquals(pathFromBasedir("subDir/myOutput"), p.getBuild().getDirectory()); assertPathEquals(pathFromBasedir("subDir/myClasses"), p.getBuild().getOutputDirectory()); assertPathEquals(pathFromBasedir("subDir/myTestClasses"), p.getBuild().getTestOutputDirectory()); diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectsTreeIgnoresTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectsTreeIgnoresTest.java index 8beb1809fdd8..51219fc2a07d 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectsTreeIgnoresTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectsTreeIgnoresTest.java @@ -59,7 +59,7 @@ public class MavenProjectsTreeIgnoresTest extends MavenProjectsTreeTestCase { assertEquals("ignored: m1 ", myLog); myLog = ""; - myTree.setIgnoredFilesPatterns(Collections.EMPTY_LIST); + myTree.setIgnoredFilesPatterns(Collections.emptyList()); assertEquals("unignored: m1 ", myLog); myLog = ""; @@ -92,4 +92,4 @@ public class MavenProjectsTreeIgnoresTest extends MavenProjectsTreeTestCase { }, ", "); } } -} \ No newline at end of file +} diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/quickfixes/RenameTo.java b/plugins/spellchecker/src/com/intellij/spellchecker/quickfixes/RenameTo.java index 0602561dc62a..5d934b230f0d 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/quickfixes/RenameTo.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/quickfixes/RenameTo.java @@ -18,11 +18,16 @@ package com.intellij.spellchecker.quickfixes; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.ide.DataManager; import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.impl.SimpleDataContext; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; import com.intellij.refactoring.actions.RenameElementAction; import com.intellij.refactoring.rename.NameSuggestionProvider; import com.intellij.spellchecker.util.SpellCheckerBundle; +import com.intellij.util.containers.HashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -67,14 +72,22 @@ public class RenameTo extends ShowSuggestions implements SpellCheckerQuickFix { } @SuppressWarnings({"SSBasedInspection"}) - public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { - SwingUtilities.invokeLater(new Runnable() { + public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { + Runnable fix = new Runnable() { public void run() { DictionarySuggestionProvider provider = findProvider(); if (provider != null) { provider.setActive(true); } - DataContext dataContext = DataManager.getInstance().getDataContext(); + HashMap map = new HashMap(); + PsiElement psiElement = descriptor.getPsiElement(); + map.put(LangDataKeys.PSI_ELEMENT.getName(), psiElement); + map.put( + LangDataKeys.EDITOR.getName(), + InjectedLanguageUtil.openEditorFor(psiElement.getContainingFile(), project) + ); + + DataContext dataContext = SimpleDataContext.getSimpleContext(map, DataManager.getInstance().getDataContext()); AnAction action = new RenameElementAction(); AnActionEvent event = new AnActionEvent(null, dataContext, "", action.getTemplatePresentation(), ActionManager.getInstance(), 0); action.actionPerformed(event); @@ -82,7 +95,10 @@ public class RenameTo extends ShowSuggestions implements SpellCheckerQuickFix { provider.setActive(false); } } - }); + }; + + if (ApplicationManager.getApplication().isUnitTestMode()) fix.run(); + else SwingUtilities.invokeLater(fix); // TODO [shkate] this is ugly, has problem with undo and hard to test! } } \ No newline at end of file diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/tokenizer/XmlTextTokenizer.java b/plugins/spellchecker/src/com/intellij/spellchecker/tokenizer/XmlTextTokenizer.java index 85d065104f9f..0c09d78b3420 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/tokenizer/XmlTextTokenizer.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/tokenizer/XmlTextTokenizer.java @@ -15,19 +15,25 @@ */ package com.intellij.spellchecker.tokenizer; +import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.TextRange; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiLanguageInjectionHost; import com.intellij.psi.xml.XmlText; import com.intellij.spellchecker.inspections.SplitterFactory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; + public class XmlTextTokenizer extends Tokenizer { @Nullable @Override public Token[] tokenize(@NotNull XmlText element) { + List> list = ((PsiLanguageInjectionHost)element).getInjectedPsi(); + if (list != null && list.size() > 0) return null; return new Token[]{new Token(element, element.getText(),false, SplitterFactory.getInstance().getPlainTextSplitter())}; } - - } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/ForNestedRootChecker.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/ForNestedRootChecker.java index 8c9e4aea84ff..4559a3e603e2 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/ForNestedRootChecker.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/ForNestedRootChecker.java @@ -15,11 +15,11 @@ */ package org.jetbrains.idea.svn; +import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.util.Getter; import com.intellij.openapi.vcs.impl.VcsRootIterator; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.progress.ProcessCanceledException; import org.jetbrains.annotations.Nullable; import org.tmatesoft.svn.core.internal.util.SVNEncodingUtil; import org.tmatesoft.svn.core.internal.util.SVNPathUtil; @@ -178,6 +178,7 @@ public class ForNestedRootChecker { queue.add(constructor.createReplaceable(root)); while (! queue.isEmpty()) { final Node node = queue.removeFirst(); + if (Boolean.TRUE.equals(cancelledGetter.get())) throw new ProcessCanceledException(); // check self final Real real = constructor.createReal(node.getFile(), root); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnVcs.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnVcs.java index 209325d8c928..1a8fdaeb9d5d 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnVcs.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnVcs.java @@ -1048,4 +1048,9 @@ public class SvnVcs extends AbstractVcs { public SvnBranchPointsCalculator getSvnBranchPointsCalculator() { return mySvnBranchPointsCalculator; } + + @Override + public boolean areDirectoriesVersionedItems() { + return true; + } } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/config/SvnConfigureProxiesComponent.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/config/SvnConfigureProxiesComponent.java index a6487bdf07f5..492b007c3ed7 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/config/SvnConfigureProxiesComponent.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/config/SvnConfigureProxiesComponent.java @@ -89,7 +89,7 @@ public class SvnConfigureProxiesComponent extends MasterDetailsComponent { private void addGroup(final ProxyGroup template) { final ProxyGroup group; if (template == null) { - group = new ProxyGroup(getNewName(), "", Collections.EMPTY_MAP); + group = new ProxyGroup(getNewName(), "", Collections.emptyMap()); } else { group = new ProxyGroup(getNewName(), template.getPatterns(), template.getProperties()); } @@ -260,7 +260,7 @@ public class SvnConfigureProxiesComponent extends MasterDetailsComponent { myRoot.removeAllChildren(); DefaultProxyGroup defaultProxyGroup = myManager.getDefaultGroup(); - defaultProxyGroup = (defaultProxyGroup == null) ? new DefaultProxyGroup(Collections.EMPTY_MAP) : defaultProxyGroup; + defaultProxyGroup = (defaultProxyGroup == null) ? new DefaultProxyGroup(Collections.emptyMap()) : defaultProxyGroup; final Map userGroups = myManager.getGroups(); myRoot.add(createNodeForObject(defaultProxyGroup)); diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/componentTree/ComponentTreeBuilder.java b/plugins/ui-designer/src/com/intellij/uiDesigner/componentTree/ComponentTreeBuilder.java index cdf2bde56c5a..a8b1d72362bf 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/componentTree/ComponentTreeBuilder.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/componentTree/ComponentTreeBuilder.java @@ -250,6 +250,7 @@ public final class ComponentTreeBuilder extends AbstractTreeBuilder { boolean hasComponentInTab = false; int count = 0; for(ComponentPtr ptr: selectedElements) { + ptr.validate(); if(ptr.isValid()) { final RadComponent component=ptr.getComponent(); LOG.assertTrue(component!=null); diff --git a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/binding/FormEnumUsageTest.java b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/binding/FormEnumUsageTest.java index 51efe3403f97..34a684ff497c 100644 --- a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/binding/FormEnumUsageTest.java +++ b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/binding/FormEnumUsageTest.java @@ -49,7 +49,7 @@ public class FormEnumUsageTest extends PsiTestCase { public void run() { try{ String root = PluginPathManager.getPluginHomePath("ui-designer") + "/testData/binding/" + getTestName(true); - PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk("java 1.5")); + PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17()); myTestProjectRoot = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete); } catch(Exception e){ @@ -92,4 +92,4 @@ public class FormEnumUsageTest extends PsiTestCase { assertEquals(1, ReferencesSearch.search(valueBField).findAll().size()); } -} \ No newline at end of file +} diff --git a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/binding/FormPropertyUsageTest.java b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/binding/FormPropertyUsageTest.java index c62608b95b7f..9fe4c30c492a 100644 --- a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/binding/FormPropertyUsageTest.java +++ b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/binding/FormPropertyUsageTest.java @@ -48,7 +48,7 @@ public class FormPropertyUsageTest extends PsiTestCase { public void run() { try{ String root = PluginPathManager.getPluginHomePath("ui-designer") + "/testData/binding/" + getTestName(true); - PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk("java 1.4")); + PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17()); myTestProjectRoot = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete); } catch(Exception e){ diff --git a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/binding/RenameUIRelatedTest.java b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/binding/RenameUIRelatedTest.java index 79ca07d2bc3a..c6830069c4c2 100644 --- a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/binding/RenameUIRelatedTest.java +++ b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/binding/RenameUIRelatedTest.java @@ -42,7 +42,7 @@ public class RenameUIRelatedTest extends MultiFileTestCase { @Override protected Sdk getTestProjectJdk() { - return JavaSdkImpl.getMockJdk15("java 1.5"); + return JavaSdkImpl.getMockJdk17("java 1.5"); } protected void setupProject(VirtualFile rootDir) { diff --git a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/make/FormSourceCodeGeneratorTest.java b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/make/FormSourceCodeGeneratorTest.java index d89398ebdb69..3b77645f6828 100644 --- a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/make/FormSourceCodeGeneratorTest.java +++ b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/make/FormSourceCodeGeneratorTest.java @@ -46,7 +46,7 @@ public class FormSourceCodeGeneratorTest extends PsiTestCase { public void run() { try{ String root = PluginPathManager.getPluginHomePath("ui-designer") + "/testData/sourceCodeGenerator/" + getTestName(true); - PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk("java 1.5")); + PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17()); myTestProjectRoot = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete); } catch(Exception e){ @@ -120,4 +120,4 @@ public class FormSourceCodeGeneratorTest extends PsiTestCase { final String text = StringUtil.convertLineSeparators(psiFile.getText()); assertEquals(expectedText, text); } -} \ No newline at end of file +} diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/introduceParameter/IntroduceParameterProcessor.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/introduceParameter/IntroduceParameterProcessor.java index ff3368f26892..00c5220e1e72 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/introduceParameter/IntroduceParameterProcessor.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/introduceParameter/IntroduceParameterProcessor.java @@ -86,7 +86,7 @@ class IntroduceParameterProcessor extends BaseRefactoringProcessor { usageCount += callsToUpdate.size(); } else { //noinspection unchecked - callsToUpdate = Collections.EMPTY_LIST; + callsToUpdate = Collections.emptyList(); } final UsageInfo[] usageInfos = new UsageInfo[usageCount]; diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/util/ParamMatcher.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/util/ParamMatcher.java index 040be39b55e5..6547c5394e49 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/util/ParamMatcher.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/util/ParamMatcher.java @@ -35,7 +35,7 @@ public class ParamMatcher extends BaseMatcher { public ParamMatcher(XmlTag parent, String name) { myRoot = parent; myName = name; - myExcludedNames = Collections.EMPTY_SET; + myExcludedNames = Collections.emptySet(); } public ParamMatcher(XmlTag root, String[] excludedNames, String name) { diff --git a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/HistoryElement.java b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/HistoryElement.java index 4e54d3872aa3..cde2e552745b 100644 --- a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/HistoryElement.java +++ b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/HistoryElement.java @@ -40,8 +40,8 @@ public final class HistoryElement implements Copyable { @SuppressWarnings({"unchecked"}) private HistoryElement() { expression = null; - variables = Collections.EMPTY_SET; - namespaces = Collections.EMPTY_SET; + variables = Collections.emptySet(); + namespaces = Collections.emptySet(); } public boolean equals(Object o) { diff --git a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/FindByXPathAction.java b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/FindByXPathAction.java index 2ec5b86015f2..cf7e5fbea943 100644 --- a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/FindByXPathAction.java +++ b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/FindByXPathAction.java @@ -148,7 +148,7 @@ public class FindByXPathAction extends AnAction { private static boolean validateExpression(Project project, String expression) { try { //noinspection unchecked - XPathSupport.getInstance().createXPath(null, expression, Collections.EMPTY_LIST); + XPathSupport.getInstance().createXPath(null, expression, Collections.emptyList()); return true; } catch (XPathSyntaxException e) { Messages.showErrorDialog(project, e.getMultilineMessage(), "XPath Syntax Error"); diff --git a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/support/jaxen/PsiDocumentNavigator.java b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/support/jaxen/PsiDocumentNavigator.java index e9a78e4fdb11..d01275e1cce3 100644 --- a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/support/jaxen/PsiDocumentNavigator.java +++ b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/support/jaxen/PsiDocumentNavigator.java @@ -50,7 +50,7 @@ public class PsiDocumentNavigator extends DefaultNavigator { } if (!(contextNode instanceof XmlElement)) { - return Collections.EMPTY_LIST.iterator(); + return Collections.emptyList().iterator(); } return new PsiChildAxisIterator(contextNode); } @@ -62,7 +62,7 @@ public class PsiDocumentNavigator extends DefaultNavigator { } if (!(contextNode instanceof XmlElement)) { - return Collections.EMPTY_LIST.iterator(); + return Collections.emptyList().iterator(); } return new NodeIterator((XmlElement)contextNode) { @@ -183,7 +183,7 @@ public class PsiDocumentNavigator extends DefaultNavigator { if (isElement(contextNode)) { return new AttributeIterator((XmlElement)contextNode); } else { - return Collections.EMPTY_LIST.iterator(); + return Collections.emptyList().iterator(); } } diff --git a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/support/jaxen/extensions/XPathFunctionProviderImpl.java b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/support/jaxen/extensions/XPathFunctionProviderImpl.java index b7e050cc76c3..b68719d6e198 100644 --- a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/support/jaxen/extensions/XPathFunctionProviderImpl.java +++ b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/support/jaxen/extensions/XPathFunctionProviderImpl.java @@ -74,7 +74,7 @@ class XPathFunctionProviderImpl extends XPathFunctionProvider { return myFunctions; } else { //noinspection unchecked - return Collections.EMPTY_MAP; + return Collections.emptyMap(); } } diff --git a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/InputExpressionDialog.java b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/InputExpressionDialog.java index 1b6d4df97d25..660ce9d01175 100644 --- a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/InputExpressionDialog.java +++ b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/InputExpressionDialog.java @@ -86,7 +86,7 @@ public abstract class InputExpressionDialog extends private final ComboBox myComboBox = new ComboBox(); private JComponent myEditorComponent; - private @Nullable Set myNamespaceCache; + @Nullable private Set myNamespaceCache; private InteractiveContextProvider myContextProvider; private final PsiFile myXPathFile; @@ -163,8 +163,8 @@ public abstract class InputExpressionDialog extends n = selectedItem.namespaces; v = selectedItem.variables; } else { - n = Collections.EMPTY_SET; - v = Collections.EMPTY_SET; + n = Collections.emptySet(); + v = Collections.emptySet(); } // FIXME @@ -231,7 +231,7 @@ public abstract class InputExpressionDialog extends final PsiReference[] references = element.getReferences(); for (PsiReference reference : references) { if (reference instanceof PrefixReference) { - final PrefixReference prefixReference = ((PrefixReference)reference); + final PrefixReference prefixReference = (PrefixReference)reference; if (prefixReference.isUnresolved()) { prefixes.add(prefixReference.getPrefix()); } @@ -378,7 +378,7 @@ public abstract class InputExpressionDialog extends if (myNamespaceCache != null) { return Namespace.makeMap(myNamespaceCache); } else { - return Collections.EMPTY_MAP; + return Collections.emptyMap(); } } @@ -397,8 +397,8 @@ public abstract class InputExpressionDialog extends public Context getContext() { final HistoryElement context = myModel.getSelectedItem(); if (context == null || context.expression == null) { - final Set cache = myNamespaceCache != null ? myNamespaceCache : Collections.EMPTY_SET; - return new Context(new HistoryElement(myDocument.getText(), Collections.EMPTY_SET, cache), getMode()); + final Set cache = myNamespaceCache != null ? myNamespaceCache : Collections.emptySet(); + return new Context(new HistoryElement(myDocument.getText(), Collections.emptySet(), cache), getMode()); } final Collection namespaces = myNamespaceCache != null ? @@ -536,8 +536,8 @@ public abstract class InputExpressionDialog extends @Nullable public String getPrefixForURI(String uri, XmlElement context) { - final java.util.List list = myMap.getKeysByValue(uri); - return list != null && list.size() > 0 ? list.get(0) : null; + final List list = myMap.getKeysByValue(uri); + return list != null && !list.isEmpty() ? list.get(0) : null; } @NotNull @@ -617,7 +617,7 @@ public abstract class InputExpressionDialog extends } else { n = Collections.singleton(namespace); //noinspection unchecked - v = Collections.EMPTY_SET; + v = Collections.emptySet(); } updateContext(n, v); diff --git a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/util/HighlighterUtil.java b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/util/HighlighterUtil.java index 556390627531..b4bd76a8d5eb 100644 --- a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/util/HighlighterUtil.java +++ b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/util/HighlighterUtil.java @@ -112,7 +112,7 @@ public class HighlighterUtil { public static List getHighlighters(Editor editor) { if (!hasHighlighters(editor)) { //noinspection unchecked - return Collections.EMPTY_LIST; + return Collections.emptyList(); } else { return editor.getUserData(HIGHLIGHTERS_KEY); } diff --git a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/util/NamespaceCollector.java b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/util/NamespaceCollector.java index 2261f530baae..ef8132b52c2a 100644 --- a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/util/NamespaceCollector.java +++ b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/util/NamespaceCollector.java @@ -125,7 +125,7 @@ public class NamespaceCollector extends XmlRecursiveElementVisitor { public static CollectedInfo empty() { //noinspection unchecked - return new CollectedInfo(Collections.EMPTY_SET, Collections.EMPTY_SET, Collections.EMPTY_SET); + return new CollectedInfo(Collections.emptySet(), Collections.emptySet(), Collections.emptySet()); } public static CollectedInfo collectInfo(final XmlFile psiFile) { diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/DynamicGenericInfo.java b/xml/dom-impl/src/com/intellij/util/xml/impl/DynamicGenericInfo.java index 57df5b00e52c..3d7aa0ff0930 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/DynamicGenericInfo.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/DynamicGenericInfo.java @@ -112,7 +112,13 @@ public class DynamicGenericInfo extends DomGenericInfoEx { if (!collections.isEmpty()) { ChildrenDescriptionsHolder newCollections = new ChildrenDescriptionsHolder(myStaticGenericInfo.getCollections()); for (final DomExtensionImpl extension : collections) { - newCollections.addDescription(extension.addAnnotations(new CollectionChildDescriptionImpl(extension.getXmlName(), extension.getType(), Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST))); + newCollections.addDescription(extension.addAnnotations(new CollectionChildDescriptionImpl(extension.getXmlName(), extension.getType(), + Collections.emptyList(), + Collections.emptyList(), + Collections.emptyList(), + Collections.emptyList(), + Collections.emptyList(), + Collections.emptyList()))); } clearSubTags = true; myCollections = newCollections; diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlHighlightVisitor.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlHighlightVisitor.java index c1ac11c46fc4..97c49723b40e 100644 --- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlHighlightVisitor.java +++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlHighlightVisitor.java @@ -44,6 +44,7 @@ import com.intellij.psi.html.HtmlTag; import com.intellij.psi.impl.source.SourceTreeToPsiMap; import com.intellij.psi.meta.PsiMetaData; import com.intellij.psi.templateLanguages.OuterLanguageElement; +import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtilBase; import com.intellij.psi.xml.*; @@ -94,7 +95,8 @@ public class XmlHighlightVisitor extends XmlElementVisitor implements HighlightV } @Override public void visitXmlToken(XmlToken token) { - if (token.getTokenType() == XmlTokenType.XML_NAME || token.getTokenType() == XmlTokenType.XML_TAG_NAME) { + IElementType tokenType = token.getTokenType(); + if (tokenType == XmlTokenType.XML_NAME || tokenType == XmlTokenType.XML_TAG_NAME) { PsiElement element = token.getPrevSibling(); while(element instanceof PsiWhiteSpace) element = element.getPrevSibling(); @@ -113,6 +115,23 @@ public class XmlHighlightVisitor extends XmlElementVisitor implements HighlightV checkAttribute((XmlAttribute) parent); } } + } else if (tokenType == XmlTokenType.XML_DATA_CHARACTERS && token.getParent() instanceof XmlText) { + if (token.textContains(']') && token.textContains('>')) { + String s = token.getText(); + String marker = "]]>"; + int i = s.indexOf(marker); + + if (i != -1) { // TODO: fix + TextRange textRange = token.getTextRange(); + int start = textRange.getStartOffset() + i; + addToResults(HighlightInfo.createHighlightInfo( + PsiTreeUtil.getParentOfType(token, XmlTag.class) instanceof HtmlTag ? + HighlightInfoType.WARNING:HighlightInfoType.ERROR, + start, start + marker.length(), + XmlErrorMessages.message("cdata.end.should.not.appear.in.content.unless.to.mark.end.of.cdata.section") + )); + } + } } } @@ -355,6 +374,19 @@ public class XmlHighlightVisitor extends XmlElementVisitor implements HighlightV private void checkAttribute(XmlAttribute attribute) { XmlTag tag = attribute.getParent(); + final String name = attribute.getName(); + PsiElement prevLeaf = PsiTreeUtil.prevLeaf(attribute); + + if (!(prevLeaf instanceof PsiWhiteSpace)) { + TextRange textRange = attribute.getTextRange(); + addToResults(HighlightInfo.createHighlightInfo( + tag instanceof HtmlTag ? HighlightInfoType.WARNING:HighlightInfoType.ERROR, + textRange.getStartOffset(), + textRange.getStartOffset(), + XmlErrorMessages.message("attribute.should.be.preceded.with.space") + )); + } + if (attribute.isNamespaceDeclaration()) { checkReferences(attribute.getValueElement()); return; @@ -375,8 +407,6 @@ public class XmlHighlightVisitor extends XmlElementVisitor implements HighlightV XmlAttributeDescriptor attributeDescriptor = elementDescriptor.getAttributeDescriptor(attribute); - final String name = attribute.getName(); - if (attributeDescriptor == null) { if (!XmlUtil.attributeFromTemplateFramework(name, tag)) { final String localizedMessage = XmlErrorMessages.message("attribute.is.not.allowed.here", name); diff --git a/xml/impl/src/com/intellij/xml/actions/xmlbeans/GenerateInstanceDocumentFromSchemaDialog.java b/xml/impl/src/com/intellij/xml/actions/xmlbeans/GenerateInstanceDocumentFromSchemaDialog.java index a5e10800417a..44ee2ec0485c 100644 --- a/xml/impl/src/com/intellij/xml/actions/xmlbeans/GenerateInstanceDocumentFromSchemaDialog.java +++ b/xml/impl/src/com/intellij/xml/actions/xmlbeans/GenerateInstanceDocumentFromSchemaDialog.java @@ -151,14 +151,14 @@ public class GenerateInstanceDocumentFromSchemaDialog extends DialogWrapper { List myRootValues; if (psifile == null) { - configureComboBox(rootElementChooser, Collections.EMPTY_LIST); + configureComboBox(rootElementChooser, Collections.emptyList()); return; } final XmlTag rootTag = getRootTag(psifile); if (rootTag == null) { - configureComboBox(rootElementChooser, Collections.EMPTY_LIST); + configureComboBox(rootElementChooser, Collections.emptyList()); rootElementChooser.setSelectedIndex(-1); previousUri = uri; return; diff --git a/xml/impl/src/com/intellij/xml/index/ExternalResourcesRootsProvider.java b/xml/impl/src/com/intellij/xml/index/ExternalResourcesRootsProvider.java index d30732b5eb60..3506b1a0cddf 100644 --- a/xml/impl/src/com/intellij/xml/index/ExternalResourcesRootsProvider.java +++ b/xml/impl/src/com/intellij/xml/index/ExternalResourcesRootsProvider.java @@ -21,7 +21,7 @@ import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.hash.HashSet; -import com.intellij.util.indexing.IndexedRootsProvider; +import com.intellij.util.indexing.IndexableSetContributor; import org.jetbrains.annotations.Nullable; import java.net.URL; @@ -30,7 +30,7 @@ import java.util.Set; /** * @author Dmitry Avdeev */ -public class ExternalResourcesRootsProvider implements IndexedRootsProvider { +public class ExternalResourcesRootsProvider extends IndexableSetContributor { private static final URL ourRoot = ExternalResourcesRootsProvider.class.getResource(ExternalResourceManagerImpl.STANDARD_SCHEMAS); @Nullable @@ -38,17 +38,17 @@ public class ExternalResourcesRootsProvider implements IndexedRootsProvider { return ourRoot == null ? null : VfsUtil.findFileByURL(ourRoot); } - public Set getRootsToIndex() { + public Set getAdditionalRootsToIndex() { final VirtualFile standardSchemas = getStandardSchemas(); String path = FetchExtResourceAction.getExternalResourcesPath(); LocalFileSystem localFileSystem = LocalFileSystem.getInstance(); VirtualFile extResources = localFileSystem.findFileByPath(path); - HashSet roots = new HashSet(2); + HashSet roots = new HashSet(2); if (standardSchemas != null) { - roots.add(standardSchemas.getUrl()); + roots.add(standardSchemas); } if (extResources != null) { - roots.add(extResources.getUrl()); + roots.add(extResources); } return roots; }