diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java index fd5d00d45ee7..6e6bd9102279 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java @@ -115,7 +115,7 @@ public class CompileDriver { private static final boolean GENERATE_CLASSPATH_INDEX = "true".equals(System.getProperty("generate.classpath.index")); private static final String PROP_PERFORM_INITIAL_REFRESH = "compiler.perform.outputs.refresh.on.start"; - private boolean myInitialRefreshPerformed = false; + private static final Key REFRESH_DONE_KEY = Key.create("_compiler.initial.refresh.done_"); private static final FileProcessingCompilerAdapterFactory FILE_PROCESSING_COMPILER_ADAPTER_FACTORY = new FileProcessingCompilerAdapterFactory() { public FileProcessingCompilerAdapter create(CompileContext context, FileProcessingCompiler compiler) { @@ -663,8 +663,8 @@ public class CompileDriver { } boolean needRecalcOutputDirs = false; - if (Registry.is(PROP_PERFORM_INITIAL_REFRESH) || !myInitialRefreshPerformed) { - myInitialRefreshPerformed = true; + if (Registry.is(PROP_PERFORM_INITIAL_REFRESH) || !Boolean.valueOf(REFRESH_DONE_KEY.get(myProject, Boolean.FALSE))) { + REFRESH_DONE_KEY.set(myProject, Boolean.TRUE); final long refreshStart = System.currentTimeMillis(); //need this to make sure the VFS is built diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java b/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java index f4abe40f4b9d..5c7be0535dca 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java @@ -37,10 +37,7 @@ import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.project.ProjectManagerAdapter; import com.intellij.openapi.roots.*; import com.intellij.openapi.startup.StartupManager; -import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.Pair; -import com.intellij.openapi.util.Trinity; +import com.intellij.openapi.util.*; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.*; import com.intellij.openapi.vfs.newvfs.FileAttribute; @@ -389,7 +386,7 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { } public void updateOutputRootsLayout(Project project) { - final TIntObjectHashMap> map = buildOutputRootsLayout(project); + final TIntObjectHashMap> map = buildOutputRootsLayout(new ProjectRef(project)); synchronized (myProjectOutputRoots) { myProjectOutputRoots.put(getProjectId(project), map); } @@ -467,9 +464,9 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { } } - private TIntObjectHashMap> buildOutputRootsLayout(Project project) { + private TIntObjectHashMap> buildOutputRootsLayout(ProjectRef projRef) { final TIntObjectHashMap> map = new TIntObjectHashMap>(); - for (Module module : ModuleManager.getInstance(project).getModules()) { + for (Module module : ModuleManager.getInstance(projRef.get()).getModules()) { final CompilerModuleExtension manager = CompilerModuleExtension.getInstance(module); if (manager != null) { final VirtualFile output = manager.getCompilerOutputPath(); @@ -905,17 +902,18 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { } // made public for tests - public void scanSourceContent(final Project project, final Collection roots, final int totalRootCount, final boolean isNewRoots) { + public void scanSourceContent(final ProjectRef projRef, final Collection roots, final int totalRootCount, final boolean isNewRoots) { if (roots.size() == 0) { return; } - final int projectId = getProjectId(project); + final int projectId = getProjectId(projRef.get()); - final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); + final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(projRef.get()).getFileIndex(); final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); int processed = 0; for (VirtualFile srcRoot : roots) { if (indicator != null) { + projRef.get(); indicator.setText2(srcRoot.getPresentableUrl()); indicator.setFraction(++processed / (double)totalRootCount); } @@ -930,6 +928,9 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { } } } + else { + projRef.get(); + } return true; } }); @@ -944,6 +945,7 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { final int fileId = getFileId(file); if (fileId > 0 /*file is valid*/) { if (file.isDirectory()) { + projRef.get(); for (VirtualFile child : file.getChildren()) { processFile(child); } @@ -981,8 +983,8 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { } } - private void markOldOutputRoots(final Project project, final TIntObjectHashMap> currentLayout) { - final int projectId = getProjectId(project); + private void markOldOutputRoots(final ProjectRef projRef, final TIntObjectHashMap> currentLayout) { + final int projectId = getProjectId(projRef.get()); final TIntHashSet rootsToMark = new TIntHashSet(); synchronized (myProjectOutputRoots) { @@ -1043,16 +1045,14 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { public void run() { new Task.Backgroundable(project, CompilerBundle.message("compiler.initial.scanning.progress.text"), false) { public void run(@NotNull final ProgressIndicator indicator) { + final ProjectRef projRef = new ProjectRef(project); try { - if (project.isDisposed()) { - return; - } final IntermediateOutputCompiler[] compilers = - CompilerManager.getInstance(project).getCompilers(IntermediateOutputCompiler.class); + CompilerManager.getInstance(projRef.get()).getCompilers(IntermediateOutputCompiler.class); final Set intermediateRoots = new HashSet(); if (compilers.length > 0) { - final Module[] modules = ModuleManager.getInstance(project).getModules(); + final Module[] modules = ModuleManager.getInstance(projRef.get()).getModules(); for (IntermediateOutputCompiler compiler : compilers) { for (Module module : modules) { if (module.isDisposed()) { @@ -1070,9 +1070,9 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { } } - final List projectRoots = Arrays.asList(ProjectRootManager.getInstance(project).getContentSourceRoots()); + final List projectRoots = Arrays.asList(ProjectRootManager.getInstance(projRef.get()).getContentSourceRoots()); final int totalRootsCount = projectRoots.size() + intermediateRoots.size(); - scanSourceContent(project, projectRoots, totalRootsCount, true); + scanSourceContent(projRef, projectRoots, totalRootsCount, true); if (!intermediateRoots.isEmpty()) { final FileProcessor processor = new FileProcessor() { @@ -1087,13 +1087,16 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { }; int processed = projectRoots.size(); for (VirtualFile root : intermediateRoots) { + projRef.get(); indicator.setText2(root.getPresentableUrl()); indicator.setFraction(++processed / (double)totalRootsCount); processRecursively(root, false, processor); } } - - markOldOutputRoots(project, buildOutputRootsLayout(project)); + + markOldOutputRoots(projRef, buildOutputRootsLayout(projRef)); + } + catch (ProjectRef.ProjectClosedException swallowed) { } finally { synchronized (myInitializationLock) { @@ -1108,7 +1111,6 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { }); } - private class MyProjectManagerListener extends ProjectManagerAdapter { final Map myConnections = new HashMap(); @@ -1116,39 +1118,54 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { public void projectOpened(final Project project) { final MessageBusConnection conn = project.getMessageBus().connect(); myConnections.put(project, conn); + final ProjectRef projRef = new ProjectRef(project); conn.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() { private VirtualFile[] myRootsBefore; public void beforeRootsChange(final ModuleRootEvent event) { - myRootsBefore = ProjectRootManager.getInstance(project).getContentSourceRoots(); + try { + myRootsBefore = ProjectRootManager.getInstance(projRef.get()).getContentSourceRoots(); + } + catch (ProjectRef.ProjectClosedException e) { + myRootsBefore = null; + } } public void rootsChanged(final ModuleRootEvent event) { - final VirtualFile[] rootsAfter = ProjectRootManager.getInstance(project).getContentSourceRoots(); - - { - final Set newRoots = new HashSet(); - ContainerUtil.addAll(newRoots, rootsAfter); - if (myRootsBefore != null) { - newRoots.removeAll(Arrays.asList(myRootsBefore)); + try { + try { + final VirtualFile[] rootsAfter = ProjectRootManager.getInstance(projRef.get()).getContentSourceRoots(); + + { + final Set newRoots = new HashSet(); + ContainerUtil.addAll(newRoots, rootsAfter); + if (myRootsBefore != null) { + newRoots.removeAll(Arrays.asList(myRootsBefore)); + } + scanSourceContent(projRef, newRoots, newRoots.size(), true); + } + + { + final Set oldRoots = new HashSet(); + if (myRootsBefore != null) { + ContainerUtil.addAll(oldRoots, myRootsBefore); + } + if (!oldRoots.isEmpty()) { + oldRoots.removeAll(Arrays.asList(rootsAfter)); + } + scanSourceContent(projRef, oldRoots, oldRoots.size(), false); + } } - scanSourceContent(project, newRoots, newRoots.size(), true); + finally { + myRootsBefore = null; + } + + + markOldOutputRoots(projRef, buildOutputRootsLayout(projRef)); } - - { - final Set oldRoots = new HashSet(); - if (myRootsBefore != null) { - ContainerUtil.addAll(oldRoots, myRootsBefore); - } - if (!oldRoots.isEmpty()) { - oldRoots.removeAll(Arrays.asList(rootsAfter)); - } - scanSourceContent(project, oldRoots, oldRoots.size(), false); + catch (ProjectRef.ProjectClosedException e) { + LOG.info(e); } - - myRootsBefore = null; - - markOldOutputRoots(project, buildOutputRootsLayout(project)); } }); @@ -1465,4 +1482,24 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { } } + public static final class ProjectRef extends Ref { + static class ProjectClosedException extends RuntimeException { + } + + public ProjectRef() { + } + + public ProjectRef(Project project) { + super(project); + } + + public Project get() { + final Project project = super.get(); + if (project != null && project.isDisposed()) { + throw new ProjectClosedException(); + } + return project; + } + } + } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/UpdatableDebuggerView.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/UpdatableDebuggerView.java index 9863785dea78..c6b912883391 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/UpdatableDebuggerView.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/UpdatableDebuggerView.java @@ -23,6 +23,7 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.ShortcutSet; +import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import com.intellij.util.Alarm; @@ -91,7 +92,7 @@ public abstract class UpdatableDebuggerView extends JPanel implements DebuggerVi // ignored } } - }, 100); + }, 100, ModalityState.NON_MODAL); } else { myRefreshNeeded = true; diff --git a/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java b/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java index e5592528a78f..cf8e5c9ccea2 100644 --- a/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java +++ b/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java @@ -275,7 +275,14 @@ public class ExpectedTypesProvider { } @Override public void visitAnnotationArrayInitializer(PsiArrayInitializerMemberValue initializer) { - final PsiType type = getAnnotationMethodType((PsiNameValuePair)initializer.getParent()); + final PsiElement parent = initializer.getParent(); + final PsiType type; + if (parent instanceof PsiNameValuePair) { + type = getAnnotationMethodType((PsiNameValuePair)parent); + } + else { + type = ((PsiAnnotationMethod)parent).getReturnType(); + } if (type instanceof PsiArrayType) { myResult = new ExpectedTypeInfo[]{createInfoImpl(((PsiArrayType)type).getComponentType(), ExpectedTypeInfo.TYPE_OR_SUBTYPE, type, TailType.UNKNOWN)}; } diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaGlobalMemberNameCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaGlobalMemberNameCompletionContributor.java index 57d5496f2d55..831ee149ab27 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaGlobalMemberNameCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaGlobalMemberNameCompletionContributor.java @@ -3,6 +3,7 @@ package com.intellij.codeInsight.completion; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.VariableLookupItem; import com.intellij.psi.*; +import com.intellij.psi.impl.source.PostprocessReformattingAspect; import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; @@ -53,6 +54,7 @@ public class JavaGlobalMemberNameCompletionContributor extends CompletionContrib final PsiReferenceExpression ref = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiReferenceExpression.class, false); if (ref != null) { ref.bindToElementViaStaticImport(containingClass); + PostprocessReformattingAspect.getInstance(ref.getProject()).doPostponedFormatting(); } super.handleInsert(context); } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index 29c0f8f3c505..f399888ce64e 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -1731,21 +1731,20 @@ public class HighlightUtil { rTypeParams = psiClass == null ? PsiTypeParameter.EMPTY_ARRAY : psiClass.getTypeParameters(); } - int typeParamColumns = Math.max(lTypeParams.length, rTypeParams.length); - @Language("HTML") @NonNls String requredRow = ""; + @Language("HTML") @NonNls String requiredRow = ""; @Language("HTML") @NonNls String foundRow = ""; for (int i = 0; i < typeParamColumns; i++) { PsiTypeParameter lTypeParameter = i >= lTypeParams.length ? null : lTypeParams[i]; PsiTypeParameter rTypeParameter = i >= rTypeParams.length ? null : rTypeParams[i]; - PsiType lSubstedType = lTypeParameter == null ? null : lTypeSubstitutor.substitute(lTypeParameter); - PsiType rSubstedType = rTypeParameter == null ? null : rTypeSubstitutor.substitute(rTypeParameter); - boolean matches = Comparing.equal(lSubstedType, rSubstedType); + PsiType lSubstitutedType = lTypeParameter == null ? null : lTypeSubstitutor.substitute(lTypeParameter); + PsiType rSubstitutedType = rTypeParameter == null ? null : rTypeSubstitutor.substitute(rTypeParameter); + boolean matches = Comparing.equal(lSubstitutedType, rSubstitutedType); @NonNls String openBrace = i == 0 ? "<" : ""; @NonNls String closeBrace = i == typeParamColumns - 1 ? ">" : ","; - requredRow += "" + (lTypeParams.length == 0 ? "" : openBrace) + redIfNotMatch(lSubstedType, matches) + - (i < lTypeParams.length ? closeBrace : "") + ""; - foundRow += "" + (rTypeParams.length == 0 ? "" : openBrace) + redIfNotMatch(rSubstedType, matches) + + requiredRow += "" + (lTypeParams.length == 0 ? "" : openBrace) + redIfNotMatch(lSubstitutedType, matches) + + (i < lTypeParams.length ? closeBrace : "") + ""; + foundRow += "" + (rTypeParams.length == 0 ? "" : openBrace) + redIfNotMatch(rSubstitutedType, matches) + (i < rTypeParams.length ? closeBrace : "") + ""; } PsiType lRawType = lType1 instanceof PsiClassType ? ((PsiClassType)lType1).rawType() : lType1; @@ -1753,7 +1752,7 @@ public class HighlightUtil { boolean assignable = lRawType == null || rRawType == null || TypeConversionUtil.isAssignable(lRawType, rRawType); String toolTip = JavaErrorMessages.message("incompatible.types.html.tooltip", - redIfNotMatch(lRawType, assignable), requredRow, + redIfNotMatch(lRawType, assignable), requiredRow, redIfNotMatch(rRawType, assignable), foundRow); String description = JavaErrorMessages.message("incompatible.types", formatType(lType1), formatType(rType1)); diff --git a/java/java-impl/src/com/intellij/psi/impl/compiled/ClsClassImpl.java b/java/java-impl/src/com/intellij/psi/impl/compiled/ClsClassImpl.java index 9616168e2ef3..c4615730b454 100644 --- a/java/java-impl/src/com/intellij/psi/impl/compiled/ClsClassImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/compiled/ClsClassImpl.java @@ -38,6 +38,7 @@ import com.intellij.psi.search.SearchScope; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.util.Collection; @@ -466,10 +467,13 @@ public class ClsClassImpl extends ClsRepositoryPsiElement> imple return InheritanceImplUtil.isInheritor(this, baseClass, checkDeep); } + @Nullable public PsiClass getSourceMirrorClass() { PsiElement parent = getParent(); final String name = getName(); if (parent instanceof PsiFile) { + if (!(parent instanceof PsiClassOwner)) return null; + PsiClassOwner fileNavigationElement = (PsiClassOwner)parent.getNavigationElement(); for (PsiClass aClass : fileNavigationElement.getClasses()) { if (name.equals(aClass.getName())) return aClass; diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionConfidence.java b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionConfidence.java index 0d651e3cb9a4..84b44292f99f 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionConfidence.java +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionConfidence.java @@ -15,6 +15,8 @@ */ package com.intellij.codeInsight.completion; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -26,5 +28,8 @@ public abstract class CompletionConfidence { @Nullable public abstract Boolean shouldFocusLookup(@NotNull CompletionParameters parameters); - + @Nullable + public Boolean shouldSkipAutopopup(@Nullable PsiElement contextElement, @NotNull PsiFile psiFile, int offset) { + return null; + } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java index dd7e941c6253..7d3dd6825fc0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -193,6 +193,23 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { }; if (autopopup) { CommandProcessor.getInstance().runUndoTransparentAction(initCmd); + + int offset = editor.getCaretModel().getOffset(); + + PsiElement elementAt = InjectedLanguageUtil.findInjectedElementNoCommit(psiFile, offset); + if (elementAt == null) { + elementAt = psiFile.findElementAt(offset); + if (elementAt == null && offset > 0) { + elementAt = psiFile.findElementAt(offset - 1); + } + } + + Language language = elementAt != null ? PsiUtilBase.findLanguageFromElement(elementAt):psiFile.getLanguage(); + + for (CompletionConfidence confidence : CompletionConfidenceEP.forLanguage(language)) { + final Boolean result = confidence.shouldSkipAutopopup(elementAt, psiFile, offset); // TODO: Peter Lazy API + if (result == Boolean.TRUE) return; + } } else { CommandProcessor.getInstance().executeCommand(project, initCmd, null, null); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java index 878f97c9e7f3..6448270f048b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java @@ -622,6 +622,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement final String newPrefix = text.subSequence(pair.first, caretOffset).toString(); if (pair.second.accepts(newPrefix)) { scheduleRestart(); + myRestartingPrefixConditions.clear(); return; } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/FilePathCompletionContributor.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/FilePathCompletionContributor.java index 7a545f68a9a7..fc38b698fa13 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/FilePathCompletionContributor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/FilePathCompletionContributor.java @@ -21,7 +21,6 @@ import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.LookupElementPresentation; import com.intellij.navigation.ChooseByNameContributor; import com.intellij.openapi.actionSystem.IdeActions; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileNameMatcher; import com.intellij.openapi.fileTypes.FileType; @@ -32,7 +31,6 @@ import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; -import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; @@ -88,12 +86,7 @@ public class FilePathCompletionContributor extends CompletionContributor { final PsiElement e = parameters.getPosition(); final Project project = e.getProject(); - final PsiReference psiReference = ApplicationManager.getApplication().runReadAction(new Computable() { - public PsiReference compute() { - //noinspection ConstantConditions - return parameters.getPosition().getContainingFile().findReferenceAt(parameters.getOffset()); - } - }); + final PsiReference psiReference = parameters.getPosition().getContainingFile().findReferenceAt(parameters.getOffset()); final Pair fileReferencePair = getReference(psiReference); if (fileReferencePair != null) { @@ -102,11 +95,17 @@ public class FilePathCompletionContributor extends CompletionContributor { final FileReferenceSet set = first.getFileReferenceSet(); String prefix = set.getPathString().substring(0, parameters.getOffset() - set.getElement().getTextRange().getStartOffset() - set.getStartInElement()); + final String textBeforePosition = e.getContainingFile().getText().substring(0, parameters.getOffset()); + if (!textBeforePosition.endsWith(prefix)) { + final int len = textBeforePosition.length(); + final String fragment = len > 100 ? textBeforePosition.substring(len - 100) : textBeforePosition; + throw new AssertionError("prefix should be some actual file string just before caret: " + prefix + "\n text=" + fragment + ";\npathString=" + set.getPathString() + ";\nelementText=" + e.getParent().getText()); + } - final List[] pathPrefixParts = new List[] {null}; + List pathPrefixParts = null; int lastSlashIndex; if ((lastSlashIndex = prefix.lastIndexOf('/')) != -1) { - pathPrefixParts[0] = StringUtil.split(prefix.substring(0, lastSlashIndex), "/"); + pathPrefixParts = StringUtil.split(prefix.substring(0, lastSlashIndex), "/"); prefix = prefix.substring(lastSlashIndex + 1); } @@ -133,28 +132,20 @@ public class FilePathCompletionContributor extends CompletionContributor { for (final String name : resultNames) { ProgressManager.checkCanceled(); - final PsiFile[] files = ApplicationManager.getApplication().runReadAction(new Computable() { - public PsiFile[] compute() { - return FilenameIndex.getFilesByName(project, name, scope); - } - }); + final PsiFile[] files = FilenameIndex.getFilesByName(project, name, scope); if (files.length > 0) { for (final PsiFile file : files) { ProgressManager.checkCanceled(); - ApplicationManager.getApplication().runReadAction(new Runnable() { - public void run() { - final VirtualFile virtualFile = file.getVirtualFile(); - if (virtualFile != null && virtualFile.isValid() && virtualFile != contextFile) { - if (contextHelper.isMine(project, virtualFile)) { - if (pathPrefixParts[0] == null || fileMatchesPathPrefix(contextHelper.getPsiFileSystemItem(project, virtualFile), pathPrefixParts[0])) { - __result.addElement(new FilePathLookupItem(file, contextHelper)); - } - } + final VirtualFile virtualFile = file.getVirtualFile(); + if (virtualFile != null && virtualFile.isValid() && virtualFile != contextFile) { + if (contextHelper.isMine(project, virtualFile)) { + if (pathPrefixParts == null || fileMatchesPathPrefix(contextHelper.getPsiFileSystemItem(project, virtualFile), pathPrefixParts)) { + __result.addElement(new FilePathLookupItem(file, contextHelper)); } } - }); + } } } } @@ -220,11 +211,7 @@ public class FilePathCompletionContributor extends CompletionContributor { final ChooseByNameContributor[] nameContributors = ChooseByNameContributor.FILE_EP_NAME.getExtensions(); for (final ChooseByNameContributor contributor : nameContributors) { try { - names.addAll(ApplicationManager.getApplication().runReadAction(new Computable>() { - public Collection compute() { - return Arrays.asList(contributor.getNames(project, false)); - } - })); + names.addAll(Arrays.asList(contributor.getNames(project, false))); } catch (ProcessCanceledException ex) { // index corruption detected, ignore diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/actions/ShowJavaDocInfoAction.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/actions/ShowJavaDocInfoAction.java index fec51dee6671..dfa056a02260 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/actions/ShowJavaDocInfoAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/actions/ShowJavaDocInfoAction.java @@ -93,9 +93,14 @@ public class ShowJavaDocInfoAction extends BaseCodeInsightAction implements Hint } if (element == null && file != null) { - final PsiReference ref = file.findReferenceAt(editor.getCaretModel().getOffset()); - if (ref instanceof PsiPolyVariantReference) { - element = ref.getElement(); + try { + final PsiReference ref = file.findReferenceAt(editor.getCaretModel().getOffset()); + if (ref instanceof PsiPolyVariantReference) { + element = ref.getElement(); + } + } + catch (IndexNotReadyException e) { + element = null; } } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/EnterHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/EnterHandler.java index 02fafa6acb73..b5f0794f5e72 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/EnterHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/EnterHandler.java @@ -115,6 +115,10 @@ public class EnterHandler extends BaseEnterHandler { for(EnterHandlerDelegate delegate: Extensions.getExtensions(EnterHandlerDelegate.EP_NAME)) { EnterHandlerDelegate.Result result = delegate.preprocessEnter(file, editor, caretOffsetRef, caretAdvanceRef, dataContext, myOriginalHandler); + if (caretOffsetRef.get() > document.getTextLength()) { + throw new AssertionError("Wrong caret offset change by " + delegate); + } + if (result == EnterHandlerDelegate.Result.Stop) return; if (result != EnterHandlerDelegate.Result.Continue) { text = document.getCharsSequence(); diff --git a/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/IndexCacheManagerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/IndexCacheManagerImpl.java index 5273de0e288e..b381d41b5dae 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/IndexCacheManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/IndexCacheManagerImpl.java @@ -21,7 +21,9 @@ import com.intellij.injected.editor.VirtualFileWindow; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ReadActionProcessor; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; @@ -85,20 +87,25 @@ public class IndexCacheManagerImpl implements CacheManager{ public boolean processFilesWithWord(@NotNull final Processor psiFileProcessor, @NotNull final String word, final short occurrenceMask, @NotNull final GlobalSearchScope scope, final boolean caseSensitively) { final Set vFiles = new THashSet(); final GlobalSearchScope projectScope = GlobalSearchScope.allScope(myProject); - ApplicationManager.getApplication().runReadAction(new Runnable() { - public void run() { - FileBasedIndex.getInstance().processValues(IdIndex.NAME, new IdIndexEntry(word, caseSensitively), null, new FileBasedIndex.ValueProcessor() { - public boolean process(final VirtualFile file, final Integer value) { - ProgressManager.checkCanceled(); - final int mask = value.intValue(); - if ((mask & occurrenceMask) != 0) { - vFiles.add(file); + try { + ApplicationManager.getApplication().runReadAction(new Runnable() { + public void run() { + FileBasedIndex.getInstance().processValues(IdIndex.NAME, new IdIndexEntry(word, caseSensitively), null, new FileBasedIndex.ValueProcessor() { + public boolean process(final VirtualFile file, final Integer value) { + ProgressManager.checkCanceled(); + final int mask = value.intValue(); + if ((mask & occurrenceMask) != 0) { + vFiles.add(file); + } + return true; } - return true; - } - }, projectScope); - } - }); + }, projectScope); + } + }); + } + catch (IndexNotReadyException e) { + throw new ProcessCanceledException(); + } if (vFiles.isEmpty()) return true; diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/text/ASTDiffBuilder.java b/platform/lang-impl/src/com/intellij/psi/impl/source/text/ASTDiffBuilder.java index ba02345507a2..24c63ca26335 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/text/ASTDiffBuilder.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/text/ASTDiffBuilder.java @@ -59,6 +59,7 @@ public class ASTDiffBuilder implements DiffTreeChangeBuilder { } else { final ASTNode parent = oldNode.getTreeParent(); + assert parent != null : "old:" + oldNode + " new:" + newNode; TreeUtil.ensureParsed(oldNode); diff --git a/platform/util/src/com/intellij/openapi/util/JDOMUtil.java b/platform/util/src/com/intellij/openapi/util/JDOMUtil.java index f71c8bb6f10e..9abb7c0f743f 100644 --- a/platform/util/src/com/intellij/openapi/util/JDOMUtil.java +++ b/platform/util/src/com/intellij/openapi/util/JDOMUtil.java @@ -482,11 +482,12 @@ public class JDOMUtil { * Returns null if no escapement necessary. */ @Nullable - private static String escapeChar(char c, boolean escapeLineEnds) { + private static String escapeChar(char c, boolean escapeSpaces, boolean escapeLineEnds) { switch (c) { case '\n': return escapeLineEnds ? " " : null; case '\r': return escapeLineEnds ? " " : null; case '\t': return escapeLineEnds ? " " : null; + case ' ' : return escapeSpaces ? "" : null; case '<': return "<"; case '>': return ">"; case '\"': return """; @@ -497,15 +498,15 @@ public class JDOMUtil { @NotNull public static String escapeText(String text) { - return escapeText(text, false); + return escapeText(text, false, false); } @NotNull - private static String escapeText(String text, boolean escapeLineEnds) { + public static String escapeText(String text, boolean escapeSpaces, boolean escapeLineEnds) { StringBuffer buffer = null; for (int i = 0; i < text.length(); i++) { final char ch = text.charAt(i); - final String quotation = escapeChar(ch, escapeLineEnds); + final String quotation = escapeChar(ch, escapeSpaces, escapeLineEnds); if (buffer == null) { if (quotation != null) { @@ -548,11 +549,11 @@ public class JDOMUtil { public static class MyXMLOutputter extends XMLOutputter { public String escapeAttributeEntities(String str) { - return escapeText(str, true); + return escapeText(str, false, true); } public String escapeElementEntities(String str) { - return escapeText(str, false); + return escapeText(str, false, false); } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/SynchronizationUtil.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/SynchronizationUtil.java index fe56825018ed..9b4f598ac4d5 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/SynchronizationUtil.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/SynchronizationUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2008 Bas Leijdekkers + * Copyright 2006-2010 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,14 +30,11 @@ public class SynchronizationUtil { if (context instanceof PsiSynchronizedStatement) { return true; } - if (context != null) { - final PsiModifierListOwner modifierListOwner = - (PsiModifierListOwner)context; - if (modifierListOwner.hasModifierProperty( - PsiModifier.SYNCHRONIZED)) { - return true; - } + if (context == null) { + return false; } - return false; + final PsiModifierListOwner modifierListOwner = + (PsiModifierListOwner)context; + return modifierListOwner.hasModifierProperty(PsiModifier.SYNCHRONIZED); } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/threading/NonAtomicOperationOnVolatileFieldInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/threading/NonAtomicOperationOnVolatileFieldInspection.java index 920adbe19f62..e774adfbc949 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/threading/NonAtomicOperationOnVolatileFieldInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/threading/NonAtomicOperationOnVolatileFieldInspection.java @@ -20,6 +20,7 @@ import com.intellij.psi.tree.IElementType; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; +import com.siyeh.ig.psiutils.SynchronizationUtil; import com.siyeh.ig.psiutils.VariableAccessUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -57,7 +58,7 @@ public class NonAtomicOperationOnVolatileFieldInspection return; } final PsiExpression lhs = expression.getLExpression(); - final PsiField volatileField = findVolatileField(lhs); + final PsiField volatileField = findNonSynchronizedVolatileField(lhs); if (volatileField == null) { return; } @@ -88,7 +89,8 @@ public class NonAtomicOperationOnVolatileFieldInspection if (operand == null) { return; } - final PsiField volatileField = findVolatileField(operand); + final PsiField volatileField = + findNonSynchronizedVolatileField(operand); if (volatileField == null) { return; } @@ -99,7 +101,8 @@ public class NonAtomicOperationOnVolatileFieldInspection public void visitPostfixExpression(PsiPostfixExpression expression) { super.visitPostfixExpression(expression); final PsiExpression operand = expression.getOperand(); - final PsiField volatileField = findVolatileField(operand); + final PsiField volatileField = + findNonSynchronizedVolatileField(operand); if (volatileField == null) { return; } @@ -107,12 +110,16 @@ public class NonAtomicOperationOnVolatileFieldInspection } @Nullable - private static PsiField findVolatileField(PsiExpression expression) { + private static PsiField findNonSynchronizedVolatileField( + PsiExpression expression) { if (!(expression instanceof PsiReferenceExpression)) { return null; } final PsiReferenceExpression reference = (PsiReferenceExpression)expression; + if (SynchronizationUtil.isInSynchronizedContext(reference)) { + return null; + } final PsiElement referent = reference.resolve(); if (!(referent instanceof PsiField)) { return null; diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/NonAtomicOperationOnVolatileField.html b/plugins/InspectionGadgets/src/inspectionDescriptions/NonAtomicOperationOnVolatileField.html index 2e6bcad4ccad..7a53e3dbc4a5 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/NonAtomicOperationOnVolatileField.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/NonAtomicOperationOnVolatileField.html @@ -5,8 +5,8 @@ This inspection reports any non-atomic operations on volatile fields. Non-atomic operations on volatile fields are operations where the volatile field is read and the value is used to update the volatile field. It is possible for the value of the field to change between the read and write, making the operation possibly invalid. -In such cases it is better to use one of the Atomic* or +In such cases it is better to surround the operation with a synchronized block or +make use of one of the Atomic* or Atomic*FieldUpdater classes from the java.util.concurrent.atomic package. New in 10, Powered by InspectionGadgets diff --git a/plugins/IntelliLang/xml-support/org/intellij/plugins/intelliLang/inject/xml/XmlLanguageInjector.java b/plugins/IntelliLang/xml-support/org/intellij/plugins/intelliLang/inject/xml/XmlLanguageInjector.java index 23790afe6421..27392f44db5f 100644 --- a/plugins/IntelliLang/xml-support/org/intellij/plugins/intelliLang/inject/xml/XmlLanguageInjector.java +++ b/plugins/IntelliLang/xml-support/org/intellij/plugins/intelliLang/inject/xml/XmlLanguageInjector.java @@ -61,7 +61,7 @@ public final class XmlLanguageInjector implements MultiHostInjector { public XmlLanguageInjector(Configuration configuration) { myConfiguration = configuration; - mySupport = InjectorUtils.findInjectionSupport(LanguageInjectionSupport.JAVA_SUPPORT_ID); + mySupport = InjectorUtils.findInjectionSupport(LanguageInjectionSupport.XML_SUPPORT_ID); } @NotNull diff --git a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntConfigurationImpl.java b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntConfigurationImpl.java index 789e548f7743..f5b55e346115 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntConfigurationImpl.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntConfigurationImpl.java @@ -426,7 +426,7 @@ public class AntConfigurationImpl extends AntConfigurationBase implements Persis }); } else { - myStartupManager.registerPostStartupActivity(new Runnable() { + myStartupManager.runWhenProjectIsInitialized(new Runnable() { public void run() { runnable.run(); } diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java b/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java index 61606a2d0969..f9d4ef55250b 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java @@ -42,7 +42,7 @@ public class GithubUtil { public static HttpMethod doREST(final String login, final String password, final String request, final boolean post) throws Exception { final HttpClient client = getHttpClient(login, password); client.getParams().setContentCharset("UTF-8"); - final String uri = getUrl() + JDOMUtil.escapeText(request).replaceAll(" ", "%20"); + final String uri = JDOMUtil.escapeText(getUrl() + request, true, true); final HttpMethod method = post ? new PostMethod(uri) : new GetMethod(uri); client.executeMethod(method); return method; diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GitHubSettingsConfigurable.java b/plugins/github/src/org/jetbrains/plugins/github/ui/GitHubSettingsConfigurable.java index 8eedeb05851f..febbd21d6a4b 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GitHubSettingsConfigurable.java +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GitHubSettingsConfigurable.java @@ -13,7 +13,7 @@ import javax.swing.*; */ public class GitHubSettingsConfigurable implements SearchableConfigurable { public static final Icon ICON = IconLoader.getIcon("/icons/github.png"); - private GithubLoginPanel mySettingsPane; + private GithubSettingsPanel mySettingsPane; private final GithubSettings mySettings; public GitHubSettingsConfigurable() { @@ -34,7 +34,7 @@ public class GitHubSettingsConfigurable implements SearchableConfigurable { public JComponent createComponent() { if (mySettingsPane == null) { - mySettingsPane = new GithubLoginPanel(); + mySettingsPane = new GithubSettingsPanel(); } reset(); return mySettingsPane.getPanel(); diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCloneProjectPane.form b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCloneProjectPane.form index 1768b1d46fea..fe73f3ea0e53 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCloneProjectPane.form +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCloneProjectPane.form @@ -18,7 +18,7 @@ - + @@ -26,7 +26,7 @@ - + @@ -34,7 +34,7 @@ - + diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginDialog.java b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginDialog.java index 59c4054effd5..376ced9c7536 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginDialog.java +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginDialog.java @@ -17,7 +17,7 @@ public class GithubLoginDialog extends DialogWrapper { // TODO: login to github must be merged with tasks server settings public GithubLoginDialog(final Project project) { super(project, true); - myGithubLoginPanel = new GithubLoginPanel(); + myGithubLoginPanel = new GithubLoginPanel(this); final GithubSettings settings = GithubSettings.getInstance(); myGithubLoginPanel.setLogin(settings.getLogin()); myGithubLoginPanel.setPassword(settings.getPassword()); @@ -58,4 +58,8 @@ public class GithubLoginDialog extends DialogWrapper { setErrorText("Cannot login with given credentials"); } } + + public void clearErrors() { + setErrorText(null); + } } \ No newline at end of file diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginPanel.form b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginPanel.form index b29b3a13547b..47ce78058e35 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginPanel.form +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginPanel.form @@ -1,16 +1,16 @@
- + - + - + @@ -38,7 +38,8 @@ - + + @@ -53,7 +54,7 @@ - + @@ -62,17 +63,12 @@ - + - - - - - - - - - + + + + diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginPanel.java b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginPanel.java index 98de80bdc6d6..b291668e997d 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginPanel.java +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginPanel.java @@ -1,15 +1,28 @@ +/* + * 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.github.ui; import com.intellij.ide.BrowserUtil; -import com.intellij.openapi.ui.Messages; +import com.intellij.ui.DocumentAdapter; import com.intellij.ui.HyperlinkAdapter; -import org.jetbrains.plugins.github.GithubUtil; import javax.swing.*; +import javax.swing.event.DocumentEvent; import javax.swing.event.HyperlinkEvent; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; /** * @author oleg @@ -22,9 +35,8 @@ public class GithubLoginPanel { private JPasswordField myPasswordField; private JTextPane mySignupTextField; private JPanel myPane; - private JButton myTestButton; - public GithubLoginPanel() { + public GithubLoginPanel(final GithubLoginDialog dialog) { mySignupTextField.addHyperlinkListener(new HyperlinkAdapter() { @Override protected void hyperlinkActivated(final HyperlinkEvent e) { @@ -35,11 +47,16 @@ public class GithubLoginPanel { "Do not have an account? " + "Signup for free" + ""); mySignupTextField.setBackground(myPane.getBackground()); mySignupTextField.setCursor(new Cursor(Cursor.HAND_CURSOR)); - myTestButton.addActionListener(new ActionListener() { + myLoginTextField.getDocument().addDocumentListener(new DocumentAdapter() { @Override - public void actionPerformed(ActionEvent e) { - final boolean result = GithubUtil.testConnection(getLogin(), getPassword()); - Messages.showInfoMessage(result ? "Connection successful" : "Cannot login using given credentials", result ? "Success" : "Fail"); + protected void textChanged(DocumentEvent e) { + dialog.clearErrors(); + } + }); + myPasswordField.getDocument().addDocumentListener(new DocumentAdapter() { + @Override + protected void textChanged(DocumentEvent e) { + dialog.clearErrors(); } }); } diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.form b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.form new file mode 100644 index 000000000000..fdd82631348d --- /dev/null +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.form @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.java b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.java new file mode 100644 index 000000000000..08466ec61344 --- /dev/null +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.java @@ -0,0 +1,86 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.github.ui; + +import com.intellij.ide.BrowserUtil; +import com.intellij.openapi.ui.Messages; +import com.intellij.ui.HyperlinkAdapter; +import org.jetbrains.plugins.github.GithubUtil; + +import javax.swing.*; +import javax.swing.event.HyperlinkEvent; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * @author oleg + * @date 10/20/10 + */ +public class GithubSettingsPanel { + private static final String SIGNUP_FOR_FREE_ACOUNT = "https://github.com/signup/free"; + + private JTextField myLoginTextField; + private JPasswordField myPasswordField; + private JTextPane mySignupTextField; + private JPanel myPane; + private JButton myTestButton; + + public GithubSettingsPanel() { + mySignupTextField.addHyperlinkListener(new HyperlinkAdapter() { + @Override + protected void hyperlinkActivated(final HyperlinkEvent e) { + BrowserUtil.launchBrowser(e.getURL().toExternalForm()); + } + }); + mySignupTextField.setText( + "Do not have an account? " + "Signup for free" + ""); + mySignupTextField.setBackground(myPane.getBackground()); + mySignupTextField.setCursor(new Cursor(Cursor.HAND_CURSOR)); + myTestButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + final boolean result = GithubUtil.testConnection(getLogin(), getPassword()); + Messages.showInfoMessage(result ? "Connection successful" : "Cannot login using given credentials", result ? "Success" : "Fail"); + } + }); + } + + public JComponent getPanel() { + return myPane; + } + + public void setLogin(final String login) { + myLoginTextField.setText(login); + } + + public void setPassword(final String password) { + myPasswordField.setText(password); + } + + public String getLogin() { + return myLoginTextField.getText(); + } + + public String getPassword() { + return String.valueOf(myPasswordField.getPassword()); + } + + public JComponent getPreferrableFocusComponent() { + return myLoginTextField; + } +} + 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 89025123e458..60f29c6600e6 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 @@ -507,7 +507,7 @@ public abstract class MavenImportingTestCase extends MavenTestCase { CompilerManagerImpl.testSetup(); List roots = Arrays.asList(ProjectRootManager.getInstance(myProject).getContentRoots()); - TranslatingCompilerFilesMonitor.getInstance().scanSourceContent(myProject, roots, roots.size(), true); + TranslatingCompilerFilesMonitor.getInstance().scanSourceContent(new TranslatingCompilerFilesMonitor.ProjectRef(myProject), roots, roots.size(), true); final CompileScope scope = new ModuleCompileScope(myProject, modules.toArray(new Module[modules.size()]), false);