diff --git a/.idea/modules.xml b/.idea/modules.xml index 315b69f7138f..00437da65030 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -46,8 +46,8 @@ - - + + @@ -106,10 +106,10 @@ - + @@ -136,9 +136,9 @@ - + - + diff --git a/build/update.sh b/build/update.sh index 7fdd5029aec8..b58f117a8315 100755 --- a/build/update.sh +++ b/build/update.sh @@ -24,7 +24,7 @@ echo "Updating $WORK_IDEA_HOME from compiled classes in $DEV_IDEA_HOME" ANT_HOME="$DEV_IDEA_HOME/lib/ant" ANT_CLASSPATH="$DEV_IDEA_HOME/build/lib/gant/lib/jps.jar" java -Xms64m -Xmx512m -Dant.home="$ANT_HOME" -classpath "$ANT_HOME/lib/ant-launcher.jar" org.apache.tools.ant.launch.Launcher \ - -lib "$ANT_CLASSPATH" -f $DEV_IDEA_HOME/build/update.xml $TARGET + -lib "$ANT_CLASSPATH" -f "$DEV_IDEA_HOME/build/update.xml" $TARGET if [ "$?" != "0" ]; then echo "Update failed; work IDEA build not modified." @@ -32,17 +32,17 @@ if [ "$?" != "0" ]; then exit 2 fi -rm -rf $WORK_IDEA_HOME/lib -rm -rf $WORK_IDEA_HOME/plugins +rm -rf "$WORK_IDEA_HOME/lib" +rm -rf "$WORK_IDEA_HOME/plugins" -cp -R $DEV_IDEA_HOME/out/deploy/* $WORK_IDEA_HOME +cp -R "$DEV_IDEA_HOME/out/deploy/"* "$WORK_IDEA_HOME" OS_TYPE=`uname -s` if [ "$OS_TYPE" = "Linux" ]; then cp -a $DEV_IDEA_HOME/bin/linux/*.so $WORK_IDEA_HOME/bin cp -a $DEV_IDEA_HOME/bin/linux/fsnotifier* $WORK_IDEA_HOME/bin elif [ "$OS_TYPE" = "Darwin" ]; then - cp -a $DEV_IDEA_HOME/bin/mac/*.jnilib $WORK_IDEA_HOME/bin - cp -a $DEV_IDEA_HOME/bin/mac/fsnotifier $WORK_IDEA_HOME/bin - cp -a $DEV_IDEA_HOME/bin/mac/restarter $WORK_IDEA_HOME/bin + cp -a "$DEV_IDEA_HOME/bin/mac/"*.jnilib "$WORK_IDEA_HOME/bin" + cp -a "$DEV_IDEA_HOME/bin/mac/fsnotifier" "$WORK_IDEA_HOME/bin" + cp -a "$DEV_IDEA_HOME/bin/mac/restarter" "$WORK_IDEA_HOME/bin" fi diff --git a/images/src/org/intellij/images/ImagesBundle.java b/images/src/org/intellij/images/ImagesBundle.java index b2a7092b1306..056e4403546a 100644 --- a/images/src/org/intellij/images/ImagesBundle.java +++ b/images/src/org/intellij/images/ImagesBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class ImagesBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/images/src/org/intellij/images/vfs/IfsUtil.java b/images/src/org/intellij/images/vfs/IfsUtil.java index bb2f1541f299..12b8e590c0b7 100644 --- a/images/src/org/intellij/images/vfs/IfsUtil.java +++ b/images/src/org/intellij/images/vfs/IfsUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -66,7 +66,7 @@ public final class IfsUtil { private static boolean refresh(@NotNull VirtualFile file) throws IOException { Long loadedTimeStamp = file.getUserData(TIMESTAMP_KEY); SoftReference imageRef = file.getUserData(BUFFERED_IMAGE_REF_KEY); - if (loadedTimeStamp == null || loadedTimeStamp.longValue() != file.getTimeStamp() || imageRef == null || imageRef.get() == null) { + if (loadedTimeStamp == null || loadedTimeStamp.longValue() != file.getTimeStamp() || SoftReference.dereference(imageRef) == null) { try { final byte[] content = file.contentsToByteArray(); @@ -113,7 +113,7 @@ public final class IfsUtil { public static BufferedImage getImage(@NotNull VirtualFile file) throws IOException { refresh(file); SoftReference imageRef = file.getUserData(BUFFERED_IMAGE_REF_KEY); - return imageRef != null ? imageRef.get() : null; + return SoftReference.dereference(imageRef); } @Nullable diff --git a/java/compiler/openapi/src/com/intellij/openapi/compiler/CompilerBundle.java b/java/compiler/openapi/src/com/intellij/openapi/compiler/CompilerBundle.java index eac8c804e7ec..5e01ff64f604 100644 --- a/java/compiler/openapi/src/com/intellij/openapi/compiler/CompilerBundle.java +++ b/java/compiler/openapi/src/com/intellij/openapi/compiler/CompilerBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -45,8 +45,7 @@ public class CompilerBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/ViewTextAction.java b/java/debugger/impl/src/com/intellij/debugger/actions/ViewTextAction.java index 9c4ec5d39bca..52cc1b1441f8 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/ViewTextAction.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/ViewTextAction.java @@ -19,14 +19,10 @@ import com.intellij.debugger.impl.DebuggerContextImpl; import com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl; import com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl; import com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.EditorFactory; -import com.intellij.openapi.editor.ex.EditorEx; -import com.intellij.openapi.editor.impl.DocumentImpl; -import com.intellij.openapi.fileTypes.FileTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.ui.EditorTextField; +import com.intellij.xdebugger.impl.ui.TextViewer; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -36,6 +32,7 @@ import java.awt.*; * @author Jeka */ public class ViewTextAction extends BaseValueAction { + @Override protected void processText(final Project project, final String text, DebuggerTreeNodeImpl node, DebuggerContextImpl debuggerContext) { final NodeDescriptorImpl descriptor = node.getDescriptor(); final String labelText = descriptor instanceof ValueDescriptorImpl? ((ValueDescriptorImpl)descriptor).getValueLabel() : null; @@ -46,8 +43,7 @@ public class ViewTextAction extends BaseValueAction { } private static class MyDialog extends DialogWrapper { - - private EditorTextField myTextViewer; + private final EditorTextField myTextViewer; private MyDialog(Project project) { super(project, false); @@ -55,7 +51,7 @@ public class ViewTextAction extends BaseValueAction { setCancelButtonText("Close"); setCrossClosesWindow(true); - myTextViewer = new TextViewer(project); + myTextViewer = new TextViewer(project, true, true); init(); } @@ -63,48 +59,23 @@ public class ViewTextAction extends BaseValueAction { myTextViewer.setText(text); } + @Override @NotNull protected Action[] createActions() { return new Action[] {getCancelAction()}; } + @Override protected String getDimensionServiceKey() { return "#com.intellij.debugger.actions.ViewTextAction"; } + @Override protected JComponent createCenterPanel() { final JPanel panel = new JPanel(new BorderLayout()); panel.add(myTextViewer, BorderLayout.CENTER); panel.setPreferredSize(new Dimension(300, 200)); return panel; } - } - - - private static class TextViewer extends EditorTextField { - - private TextViewer(Project project) { - super(createDocument(), project, FileTypes.PLAIN_TEXT, true, false); - } - - private static Document createDocument() { - final Document document = EditorFactory.getInstance().createDocument(""); - if (document instanceof DocumentImpl) { - ((DocumentImpl)document).setAcceptSlashR(true); - } - return document; - } - - protected EditorEx createEditor() { - final EditorEx editor = super.createEditor(); - editor.setHorizontalScrollbarVisible(true); - editor.setVerticalScrollbarVisible(true); - editor.setEmbeddedIntoDialogWrapper(true); - editor.getComponent().setPreferredSize(null); - editor.getSettings().setUseSoftWraps(true); - return editor; - } - } - } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerEditorImpl.java b/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerEditorImpl.java index 6b514f3b4dfa..f43d36b2185a 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerEditorImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerEditorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -41,6 +41,7 @@ import com.intellij.psi.*; import com.intellij.psi.impl.PsiDocumentManagerBase; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.reference.SoftReference; import com.intellij.ui.ClickListener; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -112,7 +113,7 @@ public abstract class DebuggerEditorImpl extends CompletionEditor{ new ClickListener() { @Override public boolean onClick(MouseEvent e, int clickCount) { - ListPopup oldPopup = myPopup != null ? myPopup.get() : null; + ListPopup oldPopup = SoftReference.dereference(myPopup); if (oldPopup != null && !oldPopup.isDisposed()) { oldPopup.cancel(); myPopup = null; diff --git a/java/debugger/openapi/src/com/intellij/debugger/DebuggerBundle.java b/java/debugger/openapi/src/com/intellij/debugger/DebuggerBundle.java index 179cf4ac5453..d83053bd56c5 100644 --- a/java/debugger/openapi/src/com/intellij/debugger/DebuggerBundle.java +++ b/java/debugger/openapi/src/com/intellij/debugger/DebuggerBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -45,8 +45,7 @@ public class DebuggerBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/java/idea-ui/src/com/intellij/util/descriptors/impl/ConfigFileImpl.java b/java/idea-ui/src/com/intellij/util/descriptors/impl/ConfigFileImpl.java index 45edd4a46677..db9b58b575ba 100644 --- a/java/idea-ui/src/com/intellij/util/descriptors/impl/ConfigFileImpl.java +++ b/java/idea-ui/src/com/intellij/util/descriptors/impl/ConfigFileImpl.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2013 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.util.descriptors.impl; import com.intellij.openapi.project.Project; @@ -71,8 +86,7 @@ public class ConfigFileImpl implements ConfigFile { @Override @Nullable public PsiFile getPsiFile() { - Reference ref = myPsiFile; - PsiFile psiFile = ref == null ? null : ref.get(); + PsiFile psiFile = com.intellij.reference.SoftReference.dereference(myPsiFile); if (psiFile != null && psiFile.isValid()) { return psiFile; diff --git a/java/java-analysis-api/src/com/intellij/codeInspection/BaseJavaBatchLocalInspectionTool.java b/java/java-analysis-api/src/com/intellij/codeInspection/BaseJavaBatchLocalInspectionTool.java index 36d4596b1147..18f1c5128ab6 100644 --- a/java/java-analysis-api/src/com/intellij/codeInspection/BaseJavaBatchLocalInspectionTool.java +++ b/java/java-analysis-api/src/com/intellij/codeInspection/BaseJavaBatchLocalInspectionTool.java @@ -20,6 +20,12 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * Base java local inspection which provides batch suppress actions, i.e. actions which don't need UI components to run (e.g. Editor). + * Please use this class if your inspection and its fixes + * - work with PSI or document only and + * - don't provide {@link com.intellij.codeInsight.intention.IntentionAction} for quick fixes/suppression, making do with {@link LocalQuickFix} only. + */ public abstract class BaseJavaBatchLocalInspectionTool extends AbstractBaseJavaLocalInspectionTool implements BatchSuppressableTool { @NotNull @Override diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/RefCountHolder.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/RefCountHolder.java index 175c1332db46..66de82fb585b 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/RefCountHolder.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/RefCountHolder.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -77,7 +77,7 @@ public class RefCountHolder { private static RefCountHolder getInstance(@NotNull PsiFile file, @NotNull ProgressIndicator indicator, boolean acquire) { HolderReference ref = file.getUserData(REF_COUNT_HOLDER_IN_FILE_KEY); - RefCountHolder holder = ref == null ? null : ref.get(); + RefCountHolder holder = com.intellij.reference.SoftReference.dereference(ref); if (holder == null && acquire) { holder = new RefCountHolder(file); HolderReference newRef = new HolderReference(holder); @@ -88,7 +88,7 @@ public class RefCountHolder { break; } ref = file.getUserData(REF_COUNT_HOLDER_IN_FILE_KEY); - RefCountHolder newHolder = ref == null ? null : ref.get(); + RefCountHolder newHolder = com.intellij.reference.SoftReference.dereference(ref); if (newHolder != null) { holder = newHolder; break; diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/java15api/Java15APIUsageInspectionBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/java15api/Java15APIUsageInspectionBase.java index 90fe1c0ff115..ca13b50f56eb 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/java15api/Java15APIUsageInspectionBase.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/java15api/Java15APIUsageInspectionBase.java @@ -85,8 +85,8 @@ public class Java15APIUsageInspectionBase extends BaseJavaBatchLocalInspectionTo private static Set getForbiddenApi(@NotNull LanguageLevel languageLevel) { if (!ourPresentableShortMessage.containsKey(languageLevel)) return null; Reference> ref = ourForbiddenAPI.get(languageLevel); - Set result; - if (ref == null || (result = ref.get()) == null) { + Set result = SoftReference.dereference(ref); + if (result == null) { result = new THashSet(1000); loadForbiddenApi("api" + getShortName(languageLevel) + ".txt", result); ourForbiddenAPI.put(languageLevel, new SoftReference>(result)); diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspectionBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspectionBase.java index e05c4b166ff5..e01a3f18a6be 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspectionBase.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspectionBase.java @@ -77,14 +77,20 @@ public class NullableStuffInspectionBase extends BaseJavaBatchLocalInspectionToo if (!AnnotationUtil.isAnnotatingApplicable(field, anno)) { final PsiAnnotation notNull = AnnotationUtil.findAnnotation(field, manager.getNotNulls()); final PsiAnnotation nullable = AnnotationUtil.findAnnotation(field, manager.getNullables()); - String message = ""; + final PsiAnnotation annotation; + String message = "Not \'"; if (annotated.isDeclaredNullable) { message += nullable.getQualifiedName(); + annotation = nullable; } else { message += notNull.getQualifiedName(); + annotation = notNull; } - message += " contradicts to configured defaults"; - holder.registerProblem(field.getNameIdentifier(), message, + message += "\' but \'" + anno + "\' would be used for code generation."; + final PsiJavaCodeReferenceElement annotationNameReferenceElement = annotation.getNameReferenceElement(); + holder.registerProblem(annotationNameReferenceElement != null ? annotationNameReferenceElement : field.getNameIdentifier(), + message, + ProblemHighlightType.WEAK_WARNING, new ChangeNullableDefaultsFix(notNull, nullable, manager)); return; } diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefClassImpl.java b/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefClassImpl.java index 1e2aee542e7f..13a18f075aa4 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefClassImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefClassImpl.java @@ -268,6 +268,10 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass { for (PsiMethod psiMethod : psiMethods) { getRefManager().getReference(psiMethod); } + + RefJavaUtil.getInstance().addReferences(psiClass, this, psiClass.getExtendsList()); + RefJavaUtil.getInstance().addReferences(psiClass, this, psiClass.getImplementsList()); + getRefManager().fireBuildReferences(this); } } diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefJavaUtilImpl.java b/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefJavaUtilImpl.java index c46bfb656769..06fb5725c00b 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefJavaUtilImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefJavaUtilImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -38,6 +38,17 @@ public class RefJavaUtilImpl extends RefJavaUtil{ findIn.accept( new JavaRecursiveElementWalkingVisitor() { @Override public void visitReferenceElement(PsiJavaCodeReferenceElement reference) { + final PsiElement target = reference.resolve(); + + if (target instanceof PsiClass) { + final PsiClass aClass = (PsiClass)target; + final RefClassImpl refClass = (RefClassImpl)refFrom.getRefManager().getReference(aClass); + refFrom.addReference(refClass, aClass, psiFrom, false, true, null); + } + + if (target instanceof PsiModifierListOwner && isDeprecated(target)) { + refFrom.setUsesDeprecatedApi(true); + } } @Override public void visitReferenceExpression(PsiReferenceExpression expression) { diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/CompletionBundle.java b/java/java-impl/src/com/intellij/codeInsight/completion/CompletionBundle.java index 0f5942a55ef6..d2ac5c1d8f9f 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/CompletionBundle.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/CompletionBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class CompletionBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java index c1bfeda87531..6adeaa50bcdb 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -27,6 +27,7 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; import com.intellij.psi.util.PsiUtilCore; +import com.intellij.reference.SoftReference; import com.intellij.util.Function; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -85,12 +86,9 @@ public class JavaPsiClassReferenceElement extends LookupItem { @Override public PsiClass getObject() { if (myClass instanceof PsiAnchor) { - Reference cache = myCache; - if (cache != null) { - PsiClass psiClass = cache.get(); - if (psiClass != null) { - return psiClass; - } + PsiClass psiClass = SoftReference.dereference(myCache); + if (psiClass != null) { + return psiClass; } final PsiClass retrieve = (PsiClass)((PsiAnchor)myClass).retrieve(); diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/OverrideImplementUtil.java b/java/java-impl/src/com/intellij/codeInsight/generation/OverrideImplementUtil.java index e58de2929ee1..8f854b1d8b2b 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/OverrideImplementUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/OverrideImplementUtil.java @@ -246,7 +246,10 @@ public class OverrideImplementUtil extends OverrideImplementExploreUtil { public static void annotateOnOverrideImplement(PsiMethod method, PsiClass targetClass, PsiMethod overridden, boolean insertOverride) { if (insertOverride && canInsertOverride(overridden, targetClass)) { - AddAnnotationPsiFix.addPhysicalAnnotation(Override.class.getName(), PsiNameValuePair.EMPTY_ARRAY, method.getModifierList()); + final String overrideAnnotationName = Override.class.getName(); + if (!AnnotationUtil.isAnnotated(method, overrideAnnotationName, false, true)) { + AddAnnotationPsiFix.addPhysicalAnnotation(overrideAnnotationName, PsiNameValuePair.EMPTY_ARRAY, method.getModifierList()); + } } final Module module = ModuleUtilCore.findModuleForPsiElement(targetClass); final GlobalSearchScope moduleScope = module != null ? GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module) : null; diff --git a/java/java-impl/src/com/intellij/javadoc/JavadocBundle.java b/java/java-impl/src/com/intellij/javadoc/JavadocBundle.java index b59c698e5954..5310d247c4c9 100644 --- a/java/java-impl/src/com/intellij/javadoc/JavadocBundle.java +++ b/java/java-impl/src/com/intellij/javadoc/JavadocBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class JavadocBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/java/java-impl/src/com/intellij/javadoc/JavadocConfiguration.java b/java/java-impl/src/com/intellij/javadoc/JavadocConfiguration.java index fe598e3e8d7f..fbd46ac8a138 100644 --- a/java/java-impl/src/com/intellij/javadoc/JavadocConfiguration.java +++ b/java/java-impl/src/com/intellij/javadoc/JavadocConfiguration.java @@ -56,9 +56,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; -import java.util.Collection; -import java.util.List; -import java.util.Set; +import java.util.*; /** * @author Eugene Zhuravlev @@ -230,36 +228,7 @@ public class JavadocConfiguration implements ModuleRunProfile, JDOMExternalizabl parameters.addParametersString(OTHER_OPTIONS); - final Set modules = new HashSet(); - myGenerationOptions.accept(new PsiRecursiveElementWalkingVisitor() { - @Override - public void visitFile(PsiFile file) { - final Module module = ModuleUtilCore.findModuleForPsiElement(file); - if (module != null) { - modules.add(module); - } - } - }); - final PathsList classPath; - final OrderEnumerator orderEnumerator = ProjectRootManager.getInstance(myProject).orderEntries(modules); - if (jdk.getSdkType() instanceof JavaSdk) { - classPath = orderEnumerator.withoutSdk().withoutModuleSourceEntries().getPathsList(); - } - else { - //libraries are included into jdk - classPath = orderEnumerator.withoutModuleSourceEntries().getPathsList(); - } - final String classPathString = classPath.getPathsString(); - if (classPathString.length() > 0) { - parameters.add("-classpath"); - parameters.add(classPathString); - } - - if (OUTPUT_DIRECTORY != null) { - parameters.add("-d"); - parameters.add(OUTPUT_DIRECTORY.replace('/', File.separatorChar)); - } - + final Set modules = new LinkedHashSet(); try { final File sourcePathTempFile = FileUtil.createTempFile("javadoc", "args.txt", true); parameters.add("@" + sourcePathTempFile.getCanonicalPath()); @@ -274,10 +243,10 @@ public class JavadocConfiguration implements ModuleRunProfile, JDOMExternalizabl scopeType == AnalysisScope.MODULES || scopeType == AnalysisScope.PROJECT || scopeType == AnalysisScope.DIRECTORY; - myGenerationOptions.accept(new MyContentIterator(myProject, packages, sources, usePackageNotation)); + myGenerationOptions.accept(new MyContentIterator(myProject, packages, sources, modules, usePackageNotation)); } }; - if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(findRunnable, "Search for sources to generate javadoc in...", false, myProject)) { + if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(findRunnable, "Search for sources to generate javadoc in...", true, myProject)) { return; } if (packages.size() + sources.size() == 0) { @@ -319,6 +288,27 @@ public class JavadocConfiguration implements ModuleRunProfile, JDOMExternalizabl catch (IOException e) { LOGGER.error(e); } + + final PathsList classPath; + final OrderEnumerator orderEnumerator = ProjectRootManager.getInstance(myProject).orderEntries(modules); + if (jdk.getSdkType() instanceof JavaSdk) { + classPath = orderEnumerator.withoutSdk().withoutModuleSourceEntries().getPathsList(); + } + else { + //libraries are included into jdk + classPath = orderEnumerator.withoutModuleSourceEntries().getPathsList(); + } + final String classPathString = classPath.getPathsString(); + if (classPathString.length() > 0) { + parameters.add("-classpath"); + parameters.add(classPathString); + } + + if (OUTPUT_DIRECTORY != null) { + parameters.add("-d"); + parameters.add(OUTPUT_DIRECTORY.replace('/', File.separatorChar)); + } + } @NotNull @@ -343,9 +333,15 @@ public class JavadocConfiguration implements ModuleRunProfile, JDOMExternalizabl private final PsiManager myPsiManager; private final Collection myPackages; private final Collection mySourceFiles; + private final Set myModules; private final boolean myUsePackageNotation; - public MyContentIterator(Project project, Collection packages, Collection sources, boolean canUsePackageNotation) { + public MyContentIterator(Project project, + Collection packages, + Collection sources, + Set modules, + boolean canUsePackageNotation) { + myModules = modules; myUsePackageNotation = canUsePackageNotation; myPsiManager = PsiManager.getInstance(project); myPackages = packages; @@ -357,7 +353,10 @@ public class JavadocConfiguration implements ModuleRunProfile, JDOMExternalizabl final VirtualFile fileOrDir = file.getVirtualFile(); if (fileOrDir == null) return; if (!fileOrDir.isInLocalFileSystem()) return; - final Module module = ModuleUtil.findModuleForFile(fileOrDir, myPsiManager.getProject()); + final Module module = ModuleUtilCore.findModuleForFile(fileOrDir, myPsiManager.getProject()); + if (module != null) { + myModules.add(module); + } if (file instanceof PsiJavaFile) { final PsiJavaFile javaFile = (PsiJavaFile)file; final String packageName = javaFile.getPackageName(); diff --git a/java/java-psi-api/src/com/intellij/core/JavaCoreBundle.java b/java/java-psi-api/src/com/intellij/core/JavaCoreBundle.java index ffac7af60302..4f315b15b0bb 100644 --- a/java/java-psi-api/src/com/intellij/core/JavaCoreBundle.java +++ b/java/java-psi-api/src/com/intellij/core/JavaCoreBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class JavaCoreBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowFactory.java b/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowFactory.java index a1b28c5c59a8..904ae5fb9aec 100644 --- a/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowFactory.java +++ b/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -159,7 +159,7 @@ public class ControlFlowFactory { @NotNull private CopyOnWriteArrayList getOrCreateCachedFlowsForElement(@NotNull PsiElement element) { Reference> cachedRef = cachedFlows.get(element); - CopyOnWriteArrayList cached = cachedRef == null ? null : cachedRef.get(); + CopyOnWriteArrayList cached = com.intellij.reference.SoftReference.dereference(cachedRef); if (cached == null) { cached = ContainerUtil.createEmptyCOWList(); cachedFlows.put(element, new SoftReference>(cached)); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/JavaPsiFacadeImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/JavaPsiFacadeImpl.java index 782d82f46f97..25d09a7ba297 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/JavaPsiFacadeImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/JavaPsiFacadeImpl.java @@ -179,8 +179,7 @@ public class JavaPsiFacadeImpl extends JavaPsiFacadeEx { @Override public PsiPackage findPackage(@NotNull String qualifiedName) { - SoftReference> ref = myPackageCache; - ConcurrentMap cache = ref == null ? null : ref.get(); + ConcurrentMap cache = SoftReference.dereference(myPackageCache); if (cache == null) { myPackageCache = new SoftReference>(cache = new ConcurrentHashMap()); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/file/PsiPackageImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/file/PsiPackageImpl.java index 12964bc69dac..e2cca2d8332b 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/file/PsiPackageImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/file/PsiPackageImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,6 +39,7 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.lang.ref.Reference; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -49,7 +50,7 @@ public class PsiPackageImpl extends PsiPackageBase implements PsiPackage, Querya private volatile CachedValue myAnnotationList; private volatile CachedValue> myDirectories; private volatile CachedValue> myDirectoriesWithLibSources; - private volatile SoftReference> myPublicClassNamesCache; + private volatile Reference> myPublicClassNamesCache; public PsiPackageImpl(PsiManager manager, String qualifiedName) { super(manager, qualifiedName); @@ -176,8 +177,7 @@ public class PsiPackageImpl extends PsiPackageBase implements PsiPackage, Querya } private Set getClassNamesCache() { - SoftReference> ref = myPublicClassNamesCache; - Set cache = ref == null ? null : ref.get(); + Set cache = SoftReference.dereference(myPublicClassNamesCache); if (cache == null) { GlobalSearchScope scope = allScope(); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiAnnotationStubImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiAnnotationStubImpl.java index 3262f35b2d5c..f704bf042e03 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiAnnotationStubImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiAnnotationStubImpl.java @@ -57,17 +57,15 @@ public class PsiAnnotationStubImpl extends StubBase implements Ps @Override public PsiAnnotation getPsiElement() { - if (myParsedFromRepository != null) { - PsiAnnotation annotation = myParsedFromRepository.get(); - if (annotation != null) { - return annotation; - } + PsiAnnotation annotation = SoftReference.dereference(myParsedFromRepository); + if (annotation != null) { + return annotation; } final String text = getText(); try { PsiJavaParserFacade facade = JavaPsiFacade.getInstance(getProject()).getParserFacade(); - PsiAnnotation annotation = facade.createAnnotationFromText(text, getPsi()); + annotation = facade.createAnnotationFromText(text, getPsi()); myParsedFromRepository = new SoftReference(annotation); return annotation; } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiImportStatementStubImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiImportStatementStubImpl.java index 1de00bfc002d..65c60197491c 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiImportStatementStubImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiImportStatementStubImpl.java @@ -77,7 +77,7 @@ public class PsiImportStatementStubImpl extends StubBase @Override @Nullable public PsiJavaCodeReferenceElement getReference() { - PsiJavaCodeReferenceElement ref = myReference != null ? myReference.get() : null; + PsiJavaCodeReferenceElement ref = SoftReference.dereference(myReference); if (ref == null) { ref = isStatic() ? getStaticReference() : getRegularReference(); myReference = new SoftReference(ref); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/smartPointers/TypePointerBase.java b/java/java-psi-impl/src/com/intellij/psi/impl/smartPointers/TypePointerBase.java index 895ea667a906..1f3baf50696a 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/smartPointers/TypePointerBase.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/smartPointers/TypePointerBase.java @@ -35,8 +35,7 @@ public abstract class TypePointerBase implements SmartTypePoi @Override public T getType() { - Reference typeRef = myTypeRef; - T myType = typeRef == null ? null : typeRef.get(); + T myType = SoftReference.dereference(myTypeRef); if (myType != null && myType.isValid()) return myType; myType = calcType(); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiAnnotationMethodImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiAnnotationMethodImpl.java index 70229d13e67b..def3bb307a14 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiAnnotationMethodImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiAnnotationMethodImpl.java @@ -57,17 +57,15 @@ public class PsiAnnotationMethodImpl extends PsiMethodImpl implements PsiAnnotat final String text = stub.getDefaultValueText(); if (StringUtil.isEmpty(text)) return null; - if (myCachedDefaultValue != null) { - final PsiAnnotationMemberValue value = myCachedDefaultValue.get(); - if (value != null) { - return value; - } + PsiAnnotationMemberValue value = SoftReference.dereference(myCachedDefaultValue); + if (value != null) { + return value; } @NonNls final String annoText = "@interface _Dummy_ { Class foo() default " + text + "; }"; final PsiFileFactory factory = PsiFileFactory.getInstance(getProject()); final PsiJavaFile file = (PsiJavaFile)factory.createFileFromText("a.java", JavaFileType.INSTANCE, annoText); - final PsiAnnotationMemberValue value = ((PsiAnnotationMethod)file.getClasses()[0].getMethods()[0]).getDefaultValue(); + value = ((PsiAnnotationMethod)file.getClasses()[0].getMethods()[0]).getDefaultValue(); myCachedDefaultValue = new SoftReference(value); return value; } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiAnonymousClassImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiAnonymousClassImpl.java index 9d14b52babb6..b25f033e74b9 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiAnonymousClassImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiAnonymousClassImpl.java @@ -72,19 +72,17 @@ public class PsiAnonymousClassImpl extends PsiClassImpl implements PsiAnonymousC return getTypeByTree(); } - PsiClassType type = null; - if (myCachedBaseType != null) type = myCachedBaseType.get(); + PsiClassType type = SoftReference.dereference(myCachedBaseType); if (type != null) return type; if (!isInQualifiedNew()) { - final PsiJavaCodeReferenceElement ref; final String refText = stub.getBaseClassReferenceText(); assert refText != null : stub; final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory(); final PsiElement context = calcBasesResolveContext(PsiNameHelper.getShortClassName(refText), getExtendsList()); try { - ref = factory.createReferenceFromText(refText, context); + final PsiJavaCodeReferenceElement ref = factory.createReferenceFromText(refText, context); ((PsiJavaCodeReferenceElementImpl)ref).setKindWhenDummy(PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND); type = factory.createType(ref); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiFieldImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiFieldImpl.java index 3535bfe5bbfa..367a8bb6e014 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiFieldImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiFieldImpl.java @@ -128,15 +128,12 @@ public class PsiFieldImpl extends JavaStubPsiElement implements Ps public PsiType getType() { final PsiFieldStub stub = getStub(); if (stub != null) { - SoftReference cachedType = myCachedType; - if (cachedType != null) { - PsiType type = cachedType.get(); - if (type != null) return type; - } + PsiType type = SoftReference.dereference(myCachedType); + if (type != null) return type; String typeText = TypeInfo.createTypeText(stub.getType(true)); try { - final PsiType type = JavaPsiFacade.getInstance(getProject()).getParserFacade().createTypeFromText(typeText, this); + type = JavaPsiFacade.getInstance(getProject()).getParserFacade().createTypeFromText(typeText, this); myCachedType = new SoftReference(type); return type; } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiMethodImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiMethodImpl.java index 7423b3c836f3..456398fc2cd3 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiMethodImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiMethodImpl.java @@ -195,14 +195,11 @@ public class PsiMethodImpl extends JavaStubPsiElement implements final String typeText = TypeInfo.createTypeText(stub.getReturnTypeText(true)); if (typeText == null) return null; - SoftReference cachedType = myCachedType; - if (cachedType != null) { - PsiType type = cachedType.get(); - if (type != null) return type; - } + PsiType type = SoftReference.dereference(myCachedType); + if (type != null) return type; try { - final PsiType type = JavaPsiFacade.getInstance(getProject()).getElementFactory().createTypeFromText(typeText, this); + type = JavaPsiFacade.getInstance(getProject()).getElementFactory().createTypeFromText(typeText, this); myCachedType = new SoftReference(type); return type; } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiParameterImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiParameterImpl.java index 52827e2fb82b..287fba0238e4 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiParameterImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiParameterImpl.java @@ -39,12 +39,13 @@ import com.intellij.util.PlatformIcons; import org.jetbrains.annotations.NotNull; import javax.swing.*; +import java.lang.ref.Reference; import java.util.Arrays; public class PsiParameterImpl extends JavaStubPsiElement implements PsiParameter { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.PsiParameterImpl"); - private volatile SoftReference myCachedType = null; + private volatile Reference myCachedType = null; public PsiParameterImpl(@NotNull PsiParameterStub stub) { this(stub, JavaStubElementTypes.PARAMETER); @@ -116,16 +117,13 @@ public class PsiParameterImpl extends JavaStubPsiElement imple public PsiType getType() { PsiParameterStub stub = getStub(); if (stub != null) { - SoftReference cachedType = myCachedType; - if (cachedType != null) { - PsiType type = cachedType.get(); - if (type != null) return type; - } + PsiType type = SoftReference.dereference(myCachedType); + if (type != null) return type; String typeText = TypeInfo.createTypeText(stub.getType(true)); assert typeText != null : stub; try { - PsiType type = JavaPsiFacade.getInstance(getProject()).getParserFacade().createTypeFromText(typeText, this); + type = JavaPsiFacade.getInstance(getProject()).getParserFacade().createTypeFromText(typeText, this); myCachedType = new SoftReference(type); return type; } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveCache.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveCache.java index 73895177261c..185d08ee8fd3 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveCache.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -124,7 +124,7 @@ public class JavaResolveCache { private PsiType getCachedType(T expr) { Reference reference = myCalculatedTypes.get(expr); - return reference == null ? null : reference.get(); + return SoftReference.dereference(reference); } @Nullable diff --git a/java/java-tests/testData/codeInsight/completion/customFileType/foo.cs b/java/java-tests/testData/codeInsight/completion/customFileType/foo.cs new file mode 100644 index 000000000000..1fcab381a621 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/customFileType/foo.cs @@ -0,0 +1 @@ +// ca diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/CustomFileTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/CustomFileTypeCompletionTest.java index 97ba3b314541..dd0dc3acb1ff 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/CustomFileTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/CustomFileTypeCompletionTest.java @@ -37,6 +37,11 @@ public class CustomFileTypeCompletionTest extends LightCompletionTestCase { testByCount(2, "case", "catch"); } + public void testComment() throws Throwable { + configureByFile(BASE_PATH + "foo.cs"); + testByCount(0, new String[] { null }); + } + public void testPlainTextSubstitution() throws IOException { FileTypeManagerEx.getInstanceEx().registerFileType(MockLanguageFileType.INSTANCE, "xxx"); try { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/HippieCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/HippieCompletionTest.groovy index 2a8572ab1926..669f0f53bed2 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/HippieCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/HippieCompletionTest.groovy @@ -36,16 +36,29 @@ $some_long_variable_name public void testFromAnotherFile() { myFixture.configureByText "b.txt", ''' -$some_long_variable_name = Obj::instance(); +$some_local = 1; ''' myFixture.configureByText "a.txt", ''' -$some_lon +$some_long_variable_name = Obj::instance(); +$some_lo ''' complete() myFixture.checkResult ''' +$some_long_variable_name = Obj::instance(); $some_long_variable_name ''' + complete() + myFixture.checkResult ''' +$some_long_variable_name = Obj::instance(); +$some_local +''' + backComplete() + myFixture.checkResult ''' +$some_long_variable_name = Obj::instance(); +$some_long_variable_name +''' + } public void "test no middle matching"() { @@ -144,4 +157,8 @@ class Xoo { private void complete() { myFixture.performEditorAction(IdeActions.ACTION_HIPPIE_COMPLETION) } + + private void backComplete() { + myFixture.performEditorAction(IdeActions.ACTION_HIPPIE_BACKWARD_COMPLETION) + } } diff --git a/java/openapi/src/com/intellij/codeInspection/BaseJavaLocalInspectionTool.java b/java/openapi/src/com/intellij/codeInspection/BaseJavaLocalInspectionTool.java index 129dc58fdaa1..201084a2cc90 100644 --- a/java/openapi/src/com/intellij/codeInspection/BaseJavaLocalInspectionTool.java +++ b/java/openapi/src/com/intellij/codeInspection/BaseJavaLocalInspectionTool.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -27,11 +27,19 @@ import org.jetbrains.annotations.NotNull; * lie under corresponding first parameter of one method. * * @see GlobalInspectionTool + * + * Please note that if your inspection/fixes/suppressions don't need UI components (e.g. Editor) to run, consider using + * {@link BaseJavaBatchLocalInspectionTool} instead. */ public abstract class BaseJavaLocalInspectionTool extends AbstractBaseJavaLocalInspectionTool implements CustomSuppressableInspectionTool { @Override public SuppressIntentionAction[] getSuppressActions(final PsiElement element) { - return SuppressManager.getInstance().createSuppressActions(HighlightDisplayKey.find(getShortName())); + String shortName = getShortName(); + HighlightDisplayKey key = HighlightDisplayKey.find(shortName); + if (key == null) { + throw new AssertionError("HighlightDisplayKey.find(" + shortName + ") is null. Inspection: "+getClass()); + } + return SuppressManager.getInstance().createSuppressActions(key); } @Override diff --git a/java/remote-servers/api/src/com/intellij/remoteServer/configuration/deployment/JavaDeploymentSourceUtil.java b/java/remote-servers/api/src/com/intellij/remoteServer/configuration/deployment/JavaDeploymentSourceUtil.java index d096d8eef166..77ad3c7478eb 100644 --- a/java/remote-servers/api/src/com/intellij/remoteServer/configuration/deployment/JavaDeploymentSourceUtil.java +++ b/java/remote-servers/api/src/com/intellij/remoteServer/configuration/deployment/JavaDeploymentSourceUtil.java @@ -19,6 +19,7 @@ import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; import com.intellij.packaging.artifacts.Artifact; import com.intellij.packaging.artifacts.ArtifactPointer; +import com.intellij.packaging.artifacts.ArtifactType; import org.jetbrains.annotations.NotNull; import java.util.Collection; @@ -38,4 +39,7 @@ public abstract class JavaDeploymentSourceUtil { @NotNull public abstract List createArtifactDeploymentSources(@NotNull Project project, @NotNull Collection artifacts); + + @NotNull + public abstract List createArtifactDeploymentSources(Project project, ArtifactType... artifactTypes); } diff --git a/java/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/deployment/JavaDeploymentSourceUtilImpl.java b/java/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/deployment/JavaDeploymentSourceUtilImpl.java index 25f2229e9c2a..680124876cd2 100644 --- a/java/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/deployment/JavaDeploymentSourceUtilImpl.java +++ b/java/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/deployment/JavaDeploymentSourceUtilImpl.java @@ -16,17 +16,14 @@ package com.intellij.remoteServer.impl.configuration.deployment; import com.intellij.openapi.project.Project; -import com.intellij.packaging.artifacts.Artifact; -import com.intellij.packaging.artifacts.ArtifactPointer; -import com.intellij.packaging.artifacts.ArtifactPointerManager; +import com.intellij.packaging.artifacts.*; import com.intellij.remoteServer.configuration.deployment.ArtifactDeploymentSource; import com.intellij.remoteServer.configuration.deployment.DeploymentSource; import com.intellij.remoteServer.configuration.deployment.JavaDeploymentSourceUtil; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; +import java.util.*; /** * @author nik @@ -49,4 +46,19 @@ public class JavaDeploymentSourceUtilImpl extends JavaDeploymentSourceUtil { } return sources; } + + @NotNull + @Override + public List createArtifactDeploymentSources(Project project, ArtifactType... artifactTypes) { + if (project.isDefault()) return Collections.emptyList(); + Artifact[] artifacts = ArtifactManager.getInstance(project).getArtifacts(); + List supportedArtifacts = new ArrayList(); + Set typeSet = ContainerUtil.set(artifactTypes); + for (Artifact artifact : artifacts) { + if (typeSet.contains(artifact.getArtifactType())) { + supportedArtifacts.add(artifact); + } + } + return createArtifactDeploymentSources(project, supportedArtifacts); + } } diff --git a/platform/analysis-api/src/com/intellij/analysis/AnalysisScopeBundle.java b/platform/analysis-api/src/com/intellij/analysis/AnalysisScopeBundle.java index cdb72e244a0d..44e1d4a48f16 100644 --- a/platform/analysis-api/src/com/intellij/analysis/AnalysisScopeBundle.java +++ b/platform/analysis-api/src/com/intellij/analysis/AnalysisScopeBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class AnalysisScopeBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/analysis-api/src/com/intellij/codeInsight/daemon/DaemonBundle.java b/platform/analysis-api/src/com/intellij/codeInsight/daemon/DaemonBundle.java index a7b4d79874c3..3d848632342d 100644 --- a/platform/analysis-api/src/com/intellij/codeInsight/daemon/DaemonBundle.java +++ b/platform/analysis-api/src/com/intellij/codeInsight/daemon/DaemonBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class DaemonBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/analysis-api/src/com/intellij/codeInspection/InspectionsBundle.java b/platform/analysis-api/src/com/intellij/codeInspection/InspectionsBundle.java index 95b24828e481..585c2f6f7bac 100644 --- a/platform/analysis-api/src/com/intellij/codeInspection/InspectionsBundle.java +++ b/platform/analysis-api/src/com/intellij/codeInspection/InspectionsBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class InspectionsBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/analysis-api/src/com/intellij/psi/search/scope/packageSet/FilePatternPackageSet.java b/platform/analysis-api/src/com/intellij/psi/search/scope/packageSet/FilePatternPackageSet.java index f936e50f333e..7f01ead5359f 100644 --- a/platform/analysis-api/src/com/intellij/psi/search/scope/packageSet/FilePatternPackageSet.java +++ b/platform/analysis-api/src/com/intellij/psi/search/scope/packageSet/FilePatternPackageSet.java @@ -81,7 +81,9 @@ public class FilePatternPackageSet extends PatternBasedPackageSet { private boolean fileMatcher(VirtualFile virtualFile, ProjectFileIndex fileIndex, VirtualFile projectBaseDir){ final String relativePath = getRelativePath(virtualFile, fileIndex, true, projectBaseDir); - LOG.assertTrue(relativePath != null, "vFile: " + virtualFile + "; projectBaseDir: " + projectBaseDir + "; content File: "+fileIndex.getContentRootForFile(virtualFile)); + if (relativePath == null) { + LOG.error("vFile: " + virtualFile + "; projectBaseDir: " + projectBaseDir + "; content File: "+fileIndex.getContentRootForFile(virtualFile)); + } return myFilePattern.matcher(relativePath).matches(); } diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/QuickFixBundle.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/QuickFixBundle.java index 508aa95cbd89..9a32d315f95f 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/QuickFixBundle.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/QuickFixBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class QuickFixBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/core-api/src/com/intellij/codeInsight/CodeInsightBundle.java b/platform/core-api/src/com/intellij/codeInsight/CodeInsightBundle.java index 94d27d7fdf18..572bcf4065eb 100644 --- a/platform/core-api/src/com/intellij/codeInsight/CodeInsightBundle.java +++ b/platform/core-api/src/com/intellij/codeInsight/CodeInsightBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class CodeInsightBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/core-api/src/com/intellij/core/CoreBundle.java b/platform/core-api/src/com/intellij/core/CoreBundle.java index 36f4ccd8ddfb..5c7451fd31ae 100644 --- a/platform/core-api/src/com/intellij/core/CoreBundle.java +++ b/platform/core-api/src/com/intellij/core/CoreBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class CoreBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/core-api/src/com/intellij/ide/IdeBundle.java b/platform/core-api/src/com/intellij/ide/IdeBundle.java index d604862e8a64..44a707b37288 100644 --- a/platform/core-api/src/com/intellij/ide/IdeBundle.java +++ b/platform/core-api/src/com/intellij/ide/IdeBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -40,8 +40,7 @@ public class IdeBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/core-api/src/com/intellij/openapi/editor/EditorBundle.java b/platform/core-api/src/com/intellij/openapi/editor/EditorBundle.java index 933ddf21f4c5..a7657f74db13 100644 --- a/platform/core-api/src/com/intellij/openapi/editor/EditorBundle.java +++ b/platform/core-api/src/com/intellij/openapi/editor/EditorBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class EditorBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/core-api/src/com/intellij/patterns/PsiFilePattern.java b/platform/core-api/src/com/intellij/patterns/PsiFilePattern.java index 1a5743683c7f..6b944e20fb16 100644 --- a/platform/core-api/src/com/intellij/patterns/PsiFilePattern.java +++ b/platform/core-api/src/com/intellij/patterns/PsiFilePattern.java @@ -16,6 +16,7 @@ package com.intellij.patterns; +import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; @@ -63,6 +64,15 @@ public class PsiFilePattern fileTypePattern) { + return with(new PatternCondition("withFileType") { + @Override + public boolean accepts(@NotNull T file, ProcessingContext context) { + return fileTypePattern.accepts(file.getFileType(), context); + } + }); + } + public static class Capture extends PsiFilePattern> { protected Capture(final Class aClass) { diff --git a/platform/core-api/src/com/intellij/psi/PsiBundle.java b/platform/core-api/src/com/intellij/psi/PsiBundle.java index b1965974a73f..b403743043a9 100644 --- a/platform/core-api/src/com/intellij/psi/PsiBundle.java +++ b/platform/core-api/src/com/intellij/psi/PsiBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -40,8 +40,7 @@ public class PsiBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/core-api/src/com/intellij/psi/util/PsiCacheKey.java b/platform/core-api/src/com/intellij/psi/util/PsiCacheKey.java index 1e21c807b195..1f31645ed258 100644 --- a/platform/core-api/src/com/intellij/psi/util/PsiCacheKey.java +++ b/platform/core-api/src/com/intellij/psi/util/PsiCacheKey.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -51,7 +51,7 @@ public class PsiCacheKey extends Key> ref = h.getUserData(this); - Pair data = ref == null ? null : ref.get(); + Pair data = SoftReference.dereference(ref); if (data == null || data.getFirst() != h.getManager().getModificationTracker().getJavaStructureModificationCount()) { return null; } diff --git a/platform/core-impl/src/com/intellij/lang/LangBundle.java b/platform/core-impl/src/com/intellij/lang/LangBundle.java index ceab51505f01..5727dd06bdec 100644 --- a/platform/core-impl/src/com/intellij/lang/LangBundle.java +++ b/platform/core-impl/src/com/intellij/lang/LangBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -40,8 +40,7 @@ public class LangBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/core-impl/src/com/intellij/mock/MockFileDocumentManagerImpl.java b/platform/core-impl/src/com/intellij/mock/MockFileDocumentManagerImpl.java index 798078b78a9f..c655b8d1e0db 100644 --- a/platform/core-impl/src/com/intellij/mock/MockFileDocumentManagerImpl.java +++ b/platform/core-impl/src/com/intellij/mock/MockFileDocumentManagerImpl.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2013 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.mock; import com.intellij.openapi.editor.Document; @@ -8,6 +23,7 @@ import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.reference.SoftReference; import com.intellij.util.Function; import com.intellij.util.containers.WeakFactoryMap; import org.jetbrains.annotations.NotNull; @@ -51,7 +67,7 @@ public class MockFileDocumentManagerImpl extends FileDocumentManager { public Document getCachedDocument(@NotNull VirtualFile file) { if (myCachedDocumentKey != null) { Reference reference = file.getUserData(myCachedDocumentKey); - return reference != null ? reference.get() : null; + return SoftReference.dereference(reference); } return null; } diff --git a/platform/core-impl/src/com/intellij/openapi/editor/impl/CharArray.java b/platform/core-impl/src/com/intellij/openapi/editor/impl/CharArray.java index 62dc9d961071..5fba46ac4ed7 100644 --- a/platform/core-impl/src/com/intellij/openapi/editor/impl/CharArray.java +++ b/platform/core-impl/src/com/intellij/openapi/editor/impl/CharArray.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -188,7 +188,7 @@ abstract class CharArray implements CharSequenceBackedByArray, Dumpable { } CharSequence originalSequence = myOriginalSequence; int origLen = originalSequence == null ? -1 : originalSequence.length(); - String string = myStringRef == null ? null : myStringRef.get(); + String string = com.intellij.reference.SoftReference.dereference(myStringRef); int stringLen = string == null ? -1 : string.length(); assert origLen == stringLen || origLen==-1 || stringLen==-1; @@ -219,7 +219,7 @@ abstract class CharArray implements CharSequenceBackedByArray, Dumpable { myDebugArray.assertConsistency(); - CharSequence str = myStringRef == null ? null : myStringRef.get(); + CharSequence str = com.intellij.reference.SoftReference.dereference(myStringRef); if (str == null) { if (myHasDeferredChanges) { str = doSubString(0, myCount + myDeferredShift).toString(); @@ -388,7 +388,7 @@ abstract class CharArray implements CharSequenceBackedByArray, Dumpable { @NotNull public String toString() { assertConsistency(); - String str = myStringRef == null ? null : myStringRef.get(); + String str = com.intellij.reference.SoftReference.dereference(myStringRef); if (str == null) { if (myHasDeferredChanges) { str = substring(0, length()).toString(); diff --git a/platform/core-impl/src/com/intellij/openapi/fileTypes/FileTypesBundle.java b/platform/core-impl/src/com/intellij/openapi/fileTypes/FileTypesBundle.java index acae6299b1a5..22d89a69049f 100644 --- a/platform/core-impl/src/com/intellij/openapi/fileTypes/FileTypesBundle.java +++ b/platform/core-impl/src/com/intellij/openapi/fileTypes/FileTypesBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class FileTypesBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/core-impl/src/com/intellij/psi/SingleRootFileViewProvider.java b/platform/core-impl/src/com/intellij/psi/SingleRootFileViewProvider.java index 243f0e198d2a..e4a4eb76d024 100644 --- a/platform/core-impl/src/com/intellij/psi/SingleRootFileViewProvider.java +++ b/platform/core-impl/src/com/intellij/psi/SingleRootFileViewProvider.java @@ -355,14 +355,14 @@ public class SingleRootFileViewProvider extends UserDataHolderBase implements Fi @Nullable private Document getCachedDocument() { - final Document document = myDocument != null ? myDocument.get() : null; + final Document document = com.intellij.reference.SoftReference.dereference(myDocument); if (document != null) return document; return FileDocumentManager.getInstance().getCachedDocument(getVirtualFile()); } @Override public Document getDocument() { - Document document = myDocument != null ? myDocument.get() : null; + Document document = com.intellij.reference.SoftReference.dereference(myDocument); if (document == null/* TODO[ik] make this change && isEventSystemEnabled()*/) { document = FileDocumentManager.getInstance().getDocument(getVirtualFile()); myDocument = new SoftReference(document); @@ -535,7 +535,7 @@ public class SingleRootFileViewProvider extends UserDataHolderBase implements Fi @Override public long getModificationStamp() { - Document document = myDocument == null ? null : myDocument.get(); + Document document = com.intellij.reference.SoftReference.dereference(myDocument); if (document != null) return document.getModificationStamp(); return myVirtualFile.getModificationStamp(); } diff --git a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java index f61cab6c550b..01124e1c6ecb 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java +++ b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java @@ -193,8 +193,7 @@ public class SelfElementInfo implements SmartPointerElementInfo { } private RangeMarker getMarker() { - Reference ref = myMarkerRef; - return ref == null ? null : ref.get(); + return com.intellij.reference.SoftReference.dereference(myMarkerRef); } @Override diff --git a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerManagerImpl.java b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerManagerImpl.java index 6f6f27507641..8476372d57e4 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerManagerImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerManagerImpl.java @@ -139,7 +139,7 @@ public class SmartPointerManagerImpl extends SmartPointerManager { private static SmartPointerEx getCachedPointer(@NotNull E element) { Reference data = element.getUserData(CACHED_SMART_POINTER_KEY); - SmartPointerEx cachedPointer = data == null ? null : data.get(); + SmartPointerEx cachedPointer = SoftReference.dereference(data); if (cachedPointer != null) { PsiElement cachedElement = cachedPointer.getCachedElement(); if (cachedElement != null && cachedElement != element) { diff --git a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPsiElementPointerImpl.java b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPsiElementPointerImpl.java index bf6d1a5a2bfd..7c66ef4539fa 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPsiElementPointerImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPsiElementPointerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -93,8 +93,7 @@ class SmartPsiElementPointerImpl implements SmartPointerEx @Override public E getCachedElement() { - Reference ref = myElement; - return ref == null ? null : ref.get(); + return com.intellij.reference.SoftReference.dereference(myElement); } @Override diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java b/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java index 70996679e896..1dad21e9d1b8 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java @@ -393,8 +393,7 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF } private void clearStub(@NotNull String reason) { - SoftReference stubRef = myStub; - StubTree stubHolder = stubRef == null ? null : stubRef.get(); + StubTree stubHolder = SoftReference.dereference(myStub); if (stubHolder != null) { ((PsiFileStubImpl)stubHolder.getRoot()).clearPsi(reason); } @@ -730,7 +729,7 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF if (myStub == null) return null; synchronized (PsiLock.LOCK) { - return myStub != null ? myStub.get() : null; + return SoftReference.dereference(myStub); } } @@ -993,7 +992,7 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF FileElement fileElement = calcTreeElement(); synchronized (myStubFromTreeLock) { SoftReference ref = fileElement.getUserData(STUB_TREE_IN_PARSED_TREE); - StubTree tree = ref == null ? null : ref.get(); + StubTree tree = SoftReference.dereference(ref); if (tree == null) { ApplicationManager.getApplication().assertReadAccessAllowed(); diff --git a/platform/core-impl/src/com/intellij/util/CachedValueBase.java b/platform/core-impl/src/com/intellij/util/CachedValueBase.java index d6befd8e6564..5be82afc2304 100644 --- a/platform/core-impl/src/com/intellij/util/CachedValueBase.java +++ b/platform/core-impl/src/com/intellij/util/CachedValueBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -96,8 +96,7 @@ public abstract class CachedValueBase { @Nullable private Data getData() { - final SoftReference> ref = myData; - return ref == null ? null : ref.get(); + return SoftReference.dereference(myData); } protected boolean isUpToDate(@NotNull Data data) { diff --git a/platform/core-impl/src/com/intellij/util/CompressionUtil.java b/platform/core-impl/src/com/intellij/util/CompressionUtil.java index 6785695358d9..e5e7d0bdf3f2 100644 --- a/platform/core-impl/src/com/intellij/util/CompressionUtil.java +++ b/platform/core-impl/src/com/intellij/util/CompressionUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -52,7 +52,7 @@ public class CompressionUtil { public static int writeCompressed(DataOutput out, byte[] bytes, int length) throws IOException { if (length > COMPRESSION_THRESHOLD && ourCanUseSnappy) { SoftReference reference = spareBufferLocal.get(); - byte[] compressedOutputBuffer = reference != null ? reference.get():null; + byte[] compressedOutputBuffer = com.intellij.reference.SoftReference.dereference(reference); int maxCompressedSize = 32 + length + length / 6; // snappy.cc#MaxCompressedLength if (compressedOutputBuffer == null || compressedOutputBuffer.length < maxCompressedSize) { compressedOutputBuffer = new byte[maxCompressedSize]; diff --git a/platform/dvcs/src/com/intellij/dvcs/ui/DvcsBundle.java b/platform/dvcs/src/com/intellij/dvcs/ui/DvcsBundle.java index 1bb752040c33..df38abd544f4 100644 --- a/platform/dvcs/src/com/intellij/dvcs/ui/DvcsBundle.java +++ b/platform/dvcs/src/com/intellij/dvcs/ui/DvcsBundle.java @@ -40,8 +40,7 @@ public class DvcsBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/lang-api/src/com/intellij/refactoring/RefactoringBundle.java b/platform/lang-api/src/com/intellij/refactoring/RefactoringBundle.java index e1604d6db078..fbeb5409a8e9 100644 --- a/platform/lang-api/src/com/intellij/refactoring/RefactoringBundle.java +++ b/platform/lang-api/src/com/intellij/refactoring/RefactoringBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -81,8 +81,7 @@ public class RefactoringBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/lang-api/src/com/intellij/usageView/UsageViewBundle.java b/platform/lang-api/src/com/intellij/usageView/UsageViewBundle.java index ebbff1026939..3e249f8e3637 100644 --- a/platform/lang-api/src/com/intellij/usageView/UsageViewBundle.java +++ b/platform/lang-api/src/com/intellij/usageView/UsageViewBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -55,8 +55,7 @@ public class UsageViewBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/lang-impl/src/com/intellij/codeEditor/printing/CodeEditorBundle.java b/platform/lang-impl/src/com/intellij/codeEditor/printing/CodeEditorBundle.java index ab636b1f9fd4..8aa01a6ea4cb 100644 --- a/platform/lang-impl/src/com/intellij/codeEditor/printing/CodeEditorBundle.java +++ b/platform/lang-impl/src/com/intellij/codeEditor/printing/CodeEditorBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -40,8 +40,7 @@ public class CodeEditorBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); 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 57b73230a86a..901e10dc2e58 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -781,7 +781,7 @@ public class CodeCompletionHandlerBase { final Document document = cached.second; assert document != null; file.putUserData(FILE_COPY_KEY, new SoftReference>(Trinity.create(copy, document, combinedOffsets))); - document.setText(file.getText()); + document.setText(file.getViewProvider().getContents()); return copy; } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CustomFileTypeCompletionContributor.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CustomFileTypeCompletionContributor.java new file mode 100644 index 000000000000..aabd9a2d2fbe --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CustomFileTypeCompletionContributor.java @@ -0,0 +1,93 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.completion; + +import com.intellij.codeInsight.lookup.LookupElementBuilder; +import com.intellij.ide.highlighter.custom.SyntaxTable; +import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.openapi.editor.highlighter.HighlighterIterator; +import com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType; +import com.intellij.psi.CustomHighlighterTokenType; +import com.intellij.psi.PsiElement; +import com.intellij.psi.tree.IElementType; +import com.intellij.util.ProcessingContext; +import org.jetbrains.annotations.NotNull; + +import java.util.Set; + +import static com.intellij.patterns.PlatformPatterns.psiElement; +import static com.intellij.patterns.PlatformPatterns.psiFile; +import static com.intellij.patterns.StandardPatterns.instanceOf; + +/** + * @author yole + */ +public class CustomFileTypeCompletionContributor extends CompletionContributor { + public CustomFileTypeCompletionContributor() { + extend(CompletionType.BASIC, psiElement().inFile(psiFile().withFileType(instanceOf(CustomSyntaxTableFileType.class))), + new CompletionProvider() { + @Override + protected void addCompletions(@NotNull CompletionParameters parameters, + ProcessingContext context, + @NotNull CompletionResultSet result) { + if (inCommentOrLiteral(parameters)) { + return; + } + + CustomSyntaxTableFileType fileType = (CustomSyntaxTableFileType)parameters.getOriginalFile().getFileType(); + SyntaxTable syntaxTable = fileType.getSyntaxTable(); + String prefix = findPrefix(parameters.getPosition(), parameters.getOffset()); + CompletionResultSet resultSetWithPrefix = result.withPrefixMatcher(prefix); + + addVariants(resultSetWithPrefix, syntaxTable.getKeywords1()); + addVariants(resultSetWithPrefix, syntaxTable.getKeywords2()); + addVariants(resultSetWithPrefix, syntaxTable.getKeywords3()); + addVariants(resultSetWithPrefix, syntaxTable.getKeywords4()); + } + }); + } + + private static boolean inCommentOrLiteral(CompletionParameters parameters) { + HighlighterIterator iterator = ((EditorEx)parameters.getEditor()).getHighlighter().createIterator(parameters.getOffset()); + IElementType elementType = iterator.getTokenType(); + if (elementType == CustomHighlighterTokenType.WHITESPACE) { + iterator.retreat(); + elementType = iterator.getTokenType(); + } + return elementType == CustomHighlighterTokenType.LINE_COMMENT || + elementType == CustomHighlighterTokenType.MULTI_LINE_COMMENT || + elementType == CustomHighlighterTokenType.STRING || + elementType == CustomHighlighterTokenType.SINGLE_QUOTED_STRING; + } + + private static void addVariants(CompletionResultSet resultSet, Set keywords) { + for (String keyword : keywords) { + resultSet.addElement(LookupElementBuilder.create(keyword)); + } + } + + private static String findPrefix(PsiElement insertedElement, int offset) { + String text = insertedElement.getText(); + int offsetInElement = offset - insertedElement.getTextOffset(); + int start = offsetInElement - 1; + while(start >=0 ) { + if(!Character.isJavaIdentifierStart(text.charAt(start))) break; + --start; + } + return text.substring(start+1, offsetInElement).trim(); + } + +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/SyntaxTableCompletionData.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/SyntaxTableCompletionData.java deleted file mode 100644 index 49cbdcc0142c..000000000000 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/SyntaxTableCompletionData.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.codeInsight.completion; - -import com.intellij.codeInsight.TailType; -import com.intellij.ide.highlighter.custom.SyntaxTable; -import com.intellij.psi.PsiElement; -import com.intellij.psi.filters.TrueFilter; - -/** - * @author Maxim.Mossienko - */ -public class SyntaxTableCompletionData extends CompletionData{ - private final SyntaxTable mySyntaxTable; - - public SyntaxTableCompletionData(SyntaxTable _syntaxTable) { - mySyntaxTable = _syntaxTable; - mySyntaxTable.getKeywords1(); - - final CompletionVariant variant = new CompletionVariant(TrueFilter.INSTANCE); - variant.includeScopeClass(PsiElement.class, true); - variant.addCompletionFilter(TrueFilter.INSTANCE); - final String[] empty = {}; - - variant.addCompletion(mySyntaxTable.getKeywords1().toArray(empty), TailType.NONE); - variant.addCompletion(mySyntaxTable.getKeywords2().toArray(empty), TailType.NONE); - variant.addCompletion(mySyntaxTable.getKeywords3().toArray(empty), TailType.NONE); - variant.addCompletion(mySyntaxTable.getKeywords4().toArray(empty), TailType.NONE); - - registerVariant(variant); - } - - @Override - public String findPrefix(PsiElement insertedElement, int offset) { - String text = insertedElement.getText(); - int offsetInElement = offset - insertedElement.getTextOffset(); - int start = offsetInElement - 1; - while(start >=0 ) { - if(!Character.isJavaIdentifierStart(text.charAt(start))) break; - --start; - } - return text.substring(start+1, offsetInElement).trim(); - } -} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/WordCompletionContributor.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/WordCompletionContributor.java index f56553a7ea76..5d1ef95ffb4c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/WordCompletionContributor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/WordCompletionContributor.java @@ -138,7 +138,7 @@ public class WordCompletionContributor extends CompletionContributor implements final PsiFile file = insertedElement.getContainingFile(); final CompletionData data = CompletionUtil.getCompletionDataByElement(insertedElement, file); - if (data != null && !(data instanceof SyntaxTableCompletionData)) { + if (data != null) { Set toAdd = new HashSet(); data.addKeywordVariants(toAdd, insertedElement, file); for (CompletionVariant completionVariant : toAdd) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/actions/HippieWordCompletionHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/actions/HippieWordCompletionHandler.java index cbfa8ed941c2..3302b163d119 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/actions/HippieWordCompletionHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/actions/HippieWordCompletionHandler.java @@ -65,6 +65,7 @@ public class HippieWordCompletionHandler implements CodeInsightActionHandler { String oldPrefix = completionState.oldPrefix; CompletionVariant lastProposedVariant = completionState.lastProposedVariant; + boolean fromOtherFiles = completionState.fromOtherFiles; if (lastProposedVariant == null || oldPrefix == null || !new CamelHumpMatcher(oldPrefix).isStartMatch(currentPrefix) || !currentPrefix.equals(lastProposedVariant.variant)) { @@ -72,15 +73,17 @@ public class HippieWordCompletionHandler implements CodeInsightActionHandler { oldPrefix = currentPrefix; completionState.oldPrefix = oldPrefix; lastProposedVariant = null; + fromOtherFiles = false; } - CompletionVariant nextVariant = computeNextVariant(editor, oldPrefix, lastProposedVariant, data, file); + CompletionVariant nextVariant = computeNextVariant(editor, oldPrefix, lastProposedVariant, data, file, fromOtherFiles); if (nextVariant == null) return; int replacementEnd = data.startOffset + data.myWordUnderCursor.length(); editor.getDocument().replaceString(data.startOffset, replacementEnd, nextVariant.variant); editor.getCaretModel().moveToOffset(data.startOffset + nextVariant.variant.length()); completionState.lastProposedVariant = nextVariant; + completionState.fromOtherFiles = nextVariant.editor != editor; highlightWord(nextVariant, project, data); } @@ -105,12 +108,15 @@ public class HippieWordCompletionHandler implements CodeInsightActionHandler { private CompletionVariant computeNextVariant(final Editor editor, @Nullable final String prefix, @Nullable CompletionVariant lastProposedVariant, - final CompletionData data, PsiFile file) { - final List variants = computeVariants(editor, new CamelHumpMatcher(StringUtil.notNullize(prefix)), file); + final CompletionData data, + PsiFile file, + boolean includeWordsFromOtherFiles + ) { + final List variants = computeVariants(editor, new CamelHumpMatcher(StringUtil.notNullize(prefix)), file, includeWordsFromOtherFiles); if (variants.isEmpty()) return null; - for (CompletionVariant variant : variants) { - if (lastProposedVariant != null) { + if (lastProposedVariant != null) { + for (CompletionVariant variant : variants) { if (variant.variant.equals(lastProposedVariant.variant)) { if (lastProposedVariant.offset > data.startOffset && variant.offset > data.startOffset) lastProposedVariant = variant; if (lastProposedVariant.offset < data.startOffset && variant.offset < data.startOffset) lastProposedVariant = variant; @@ -135,7 +141,9 @@ public class HippieWordCompletionHandler implements CodeInsightActionHandler { } else { for (CompletionVariant variant : variants) { - if (variant.offset > data.startOffset) return variant; + if (variant.offset > data.startOffset) { + return variant; + } } return variants.iterator().next(); @@ -149,7 +157,9 @@ public class HippieWordCompletionHandler implements CodeInsightActionHandler { CompletionVariant result = null; for (CompletionVariant variant : variants) { if (variant == lastProposedVariant) { - if (result == null) return variants.get(variants.size() - 1); + if (result == null) { + return computeNextVariant(editor, prefix, null, data, file, !includeWordsFromOtherFiles); + } return result; } result = variant; @@ -165,7 +175,7 @@ public class HippieWordCompletionHandler implements CodeInsightActionHandler { return i.next(); } else { - return variants.iterator().next(); + return computeNextVariant(editor, prefix, null, data, file, !includeWordsFromOtherFiles); } } } @@ -186,7 +196,7 @@ public class HippieWordCompletionHandler implements CodeInsightActionHandler { this.offset = offset; } } - + private static boolean containsLetters(CharSequence seq, int start, int end) { for (int i = start; i < end; i++) { if (Character.isLetter(seq.charAt(i))) { @@ -196,7 +206,10 @@ public class HippieWordCompletionHandler implements CodeInsightActionHandler { return false; } - private static List computeVariants(@NotNull final Editor editor, CamelHumpMatcher matcher, PsiFile file) { + private static List computeVariants(@NotNull final Editor editor, + CamelHumpMatcher matcher, + PsiFile file, + boolean includeWordsFromOtherFiles) { final CharSequence chars = editor.getDocument().getCharsSequence(); @@ -205,15 +218,17 @@ public class HippieWordCompletionHandler implements CodeInsightActionHandler { final int caretOffset = editor.getCaretModel().getOffset(); - addWordsForEditor((EditorEx)editor, matcher, chars, words, afterWords, caretOffset); - - for(FileEditor fileEditor: FileEditorManager.getInstance(file.getProject()).getAllEditors()) { - if (fileEditor instanceof TextEditor) { - Editor anotherEditor = ((TextEditor)fileEditor).getEditor(); - if (anotherEditor != editor) { - addWordsForEditor((EditorEx)anotherEditor, matcher, anotherEditor.getDocument().getCharsSequence(), words, afterWords, 0); + if (includeWordsFromOtherFiles) { + for(FileEditor fileEditor: FileEditorManager.getInstance(file.getProject()).getAllEditors()) { + if (fileEditor instanceof TextEditor) { + Editor anotherEditor = ((TextEditor)fileEditor).getEditor(); + if (anotherEditor != editor) { + addWordsForEditor((EditorEx)anotherEditor, matcher, anotherEditor.getDocument().getCharsSequence(), words, afterWords, 0); + } } } + } else { + addWordsForEditor((EditorEx)editor, matcher, chars, words, afterWords, caretOffset); } Set allWords = new HashSet(); @@ -240,10 +255,10 @@ public class HippieWordCompletionHandler implements CodeInsightActionHandler { return result; } - + private interface TokenProcessor { boolean processToken(int start, int end); - } + } private static void addWordsForEditor(final EditorEx editor, final CamelHumpMatcher matcher, @@ -304,7 +319,7 @@ public class HippieWordCompletionHandler implements CodeInsightActionHandler { final int offset = editor.getCaretModel().getOffset(); final CompletionData data = new CompletionData(); - + processWords(editor, Math.max(offset - 1, 0), new TokenProcessor() { @Override public boolean processToken(int start, int end) { @@ -347,5 +362,6 @@ public class HippieWordCompletionHandler implements CodeInsightActionHandler { private static class CompletionState { public String oldPrefix; public CompletionVariant lastProposedVariant; + public boolean fromOtherFiles; } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/QuickDocOnMouseOverManager.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/QuickDocOnMouseOverManager.java index 7c237915a1fa..89e8b55f9b4c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/QuickDocOnMouseOverManager.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/QuickDocOnMouseOverManager.java @@ -32,6 +32,7 @@ import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiWhiteSpace; +import com.intellij.reference.SoftReference; import com.intellij.ui.popup.PopupFactoryImpl; import com.intellij.util.Alarm; import com.intellij.util.containers.WeakHashMap; @@ -169,11 +170,7 @@ public class QuickDocOnMouseOverManager { if (hint != null) { // Skip the event if the control is shown because of explicit 'show quick doc' action call. - WeakReference ref = myDocumentationManager; - if (ref == null) { - return; - } - DocumentationManager manager = ref.get(); + DocumentationManager manager = SoftReference.dereference(myDocumentationManager); if (manager == null || !manager.isCloseOnSneeze()) { return; } @@ -257,16 +254,7 @@ public class QuickDocOnMouseOverManager { @Nullable private DocumentationManager getDocManager() { - WeakReference ref = myDocumentationManager; - if (ref == null) { - return null; - } - - DocumentationManager docManager = ref.get(); - if (docManager == null) { - return null; - } - return docManager; + return SoftReference.dereference(myDocumentationManager); } private static class DelayedQuickDocInfo { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/wordSelection/NaturalLanguageTextSelectioner.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/wordSelection/NaturalLanguageTextSelectioner.java index a574ce0c5465..528187a0e6b2 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/wordSelection/NaturalLanguageTextSelectioner.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/wordSelection/NaturalLanguageTextSelectioner.java @@ -18,6 +18,7 @@ package com.intellij.codeInsight.editorActions.wordSelection; import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiComment; import com.intellij.psi.PsiElement; @@ -38,7 +39,8 @@ public class NaturalLanguageTextSelectioner extends ExtendWordSelectionHandlerBa @Override public boolean canSelect(PsiElement e) { - return e instanceof PsiPlainText || e instanceof PsiComment; + return (e instanceof PsiPlainText || e instanceof PsiComment) && + !(e.getContainingFile().getFileType() instanceof CustomSyntaxTableFileType); } private static TextRange findParagraphRange(String text, int start, int end) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/HighlightUsagesHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/HighlightUsagesHandler.java index 6b94a3f6a61e..0576f1d09a76 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/HighlightUsagesHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/HighlightUsagesHandler.java @@ -82,7 +82,7 @@ public class HighlightUsagesHandler extends HighlightHandlerBase { if (usageTargets == null) { PsiElement targetElement = getTargetElement(editor, file); - if (targetElement != null) { + if (targetElement != null && targetElement != file) { if (!(targetElement instanceof NavigationItem)) { targetElement = targetElement.getNavigationElement(); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/ShowContainerInfoHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/ShowContainerInfoHandler.java index b0e1e6c38265..5ccd71b866c7 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/ShowContainerInfoHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/ShowContainerInfoHandler.java @@ -29,6 +29,7 @@ import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.reference.SoftReference; import com.intellij.ui.LightweightHint; import org.jetbrains.annotations.NotNull; @@ -45,14 +46,12 @@ public class ShowContainerInfoHandler implements CodeInsightActionHandler { PsiElement container = null; WeakReference ref = editor.getUserData(MY_LAST_HINT_KEY); - if (ref != null){ - LightweightHint hint = ref.get(); - if (hint != null && hint.isVisible()){ - hint.hide(); - container = hint.getUserData(CONTAINER_KEY); - if (container != null && !container.isValid()){ - container = null; - } + LightweightHint hint = SoftReference.dereference(ref); + if (hint != null && hint.isVisible()){ + hint.hide(); + container = hint.getUserData(CONTAINER_KEY); + if (container != null && !container.isValid()){ + container = null; } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java index f9f37713e138..2af811074a54 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java @@ -44,6 +44,7 @@ import com.intellij.psi.*; import com.intellij.psi.presentation.java.SymbolPresentationUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtilCore; +import com.intellij.reference.SoftReference; import com.intellij.ui.popup.AbstractPopup; import com.intellij.ui.popup.NotLookupOrSearchCondition; import com.intellij.ui.popup.PopupPositionManager; @@ -226,18 +227,16 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { final Ref usageView = new Ref(); final String title = CodeInsightBundle.message("implementation.view.title", text); - if (myPopupRef != null) { - final JBPopup popup = myPopupRef.get(); - if (popup != null && popup.isVisible() && popup instanceof AbstractPopup) { - final ImplementationViewComponent component = (ImplementationViewComponent) ((AbstractPopup)popup).getComponent(); - ((AbstractPopup)popup).setCaption(title); - component.update(impls, index); - updateInBackground(editor, element, component, title, (AbstractPopup)popup, usageView); - if (invokedByShortcut) { - ((AbstractPopup)popup).focusPreferredComponent(); - } - return; + JBPopup popup = SoftReference.dereference(myPopupRef); + if (popup != null && popup.isVisible() && popup instanceof AbstractPopup) { + final ImplementationViewComponent component = (ImplementationViewComponent) ((AbstractPopup)popup).getComponent(); + ((AbstractPopup)popup).setCaption(title); + component.update(impls, index); + updateInBackground(editor, element, component, title, (AbstractPopup)popup, usageView); + if (invokedByShortcut) { + ((AbstractPopup)popup).focusPreferredComponent(); } + return; } final ImplementationViewComponent component = new ImplementationViewComponent(impls, index); @@ -250,7 +249,7 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { } }; - final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component.getPreferredFocusableComponent()) + popup = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component.getPreferredFocusableComponent()) .setRequestFocusCondition(project, NotLookupOrSearchCondition.INSTANCE) .setProject(project) .addListener(updateProcessor) @@ -284,11 +283,9 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { ImplementationViewComponent component, String title, AbstractPopup popup, Ref usageView) { - if (myTaskRef != null) { - final BackgroundUpdaterTask updaterTask = myTaskRef.get(); - if (updaterTask != null) { - updaterTask.setCanceled(); - } + final BackgroundUpdaterTask updaterTask = SoftReference.dereference(myTaskRef); + if (updaterTask != null) { + updaterTask.setCanceled(); } if (element == null) return; //already found diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/AbstractDocumentationTooltipAction.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/AbstractDocumentationTooltipAction.java index 713b434cb395..c0a4780a24cc 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/AbstractDocumentationTooltipAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/AbstractDocumentationTooltipAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -20,6 +20,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.util.Pair; import com.intellij.psi.PsiElement; +import com.intellij.reference.SoftReference; import com.intellij.util.PatchedWeakReference; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -64,19 +65,11 @@ public abstract class AbstractDocumentationTooltipAction extends AnAction { @Nullable private Pair getDocInfo() { - WeakReference docAnchorRef = myDocAnchor; - if (docAnchorRef == null) { - return null; - } - PsiElement docAnchor = docAnchorRef.get(); + PsiElement docAnchor = SoftReference.dereference(myDocAnchor); if (docAnchor == null) { return null; } - WeakReference originalElementRef = myOriginalElement; - if (originalElementRef == null) { - return null; - } - PsiElement originalElement = originalElementRef.get(); + PsiElement originalElement = SoftReference.dereference(myOriginalElement); if (originalElement == null) { return null; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/preview/ImageOrColorPreviewManager.java b/platform/lang-impl/src/com/intellij/codeInsight/preview/ImageOrColorPreviewManager.java index 2336a9c19196..b96666b00e1c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/preview/ImageOrColorPreviewManager.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/preview/ImageOrColorPreviewManager.java @@ -33,6 +33,7 @@ import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; +import com.intellij.reference.SoftReference; import com.intellij.util.Alarm; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -160,15 +161,17 @@ public class ImageOrColorPreviewManager implements Disposable, EditorMouseMotion if (elementRef == null && event.getMouseEvent().isShiftDown()) { alarm.addRequest(new PreviewRequest(point, editor, false), 100); } - else if (elementRef != null && elementRef.get() != getPsiElementAt(point, editor)) { - PsiElement element = elementRef.get(); - elementRef = null; - for (ElementPreviewProvider provider : Extensions.getExtensions(ElementPreviewProvider.EP_NAME)) { - try { - provider.hide(element, editor); - } - catch (Exception e) { - LOG.error(e); + else { + PsiElement element = SoftReference.dereference(elementRef); + if (element != getPsiElementAt(point, editor)) { + elementRef = null; + for (ElementPreviewProvider provider : Extensions.getExtensions(ElementPreviewProvider.EP_NAME)) { + try { + provider.hide(element, editor); + } + catch (Exception e) { + LOG.error(e); + } } } } @@ -193,7 +196,7 @@ public class ImageOrColorPreviewManager implements Disposable, EditorMouseMotion @Override public void run() { PsiElement element = getPsiElementAt(point, editor); - if (element == null || !element.isValid() || (elementRef != null && elementRef.get() == element)) { + if (element == null || !element.isValid() || SoftReference.dereference(elementRef) == element) { return; } if (PsiDocumentManager.getInstance(element.getProject()).isUncommited(editor.getDocument()) || DumbService.getInstance(element.getProject()).isDumb()) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/preview/ImagePreviewComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/preview/ImagePreviewComponent.java index 3baa777939ce..ca3e581dfd73 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/preview/ImagePreviewComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/preview/ImagePreviewComponent.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -103,7 +103,7 @@ public class ImagePreviewComponent extends JPanel implements PreviewHintComponen private static boolean refresh(@NotNull VirtualFile file) throws IOException { Long loadedTimeStamp = file.getUserData(TIMESTAMP_KEY); SoftReference imageRef = file.getUserData(BUFFERED_IMAGE_REF_KEY); - if (loadedTimeStamp == null || loadedTimeStamp < file.getTimeStamp() || imageRef == null || imageRef.get() == null) { + if (loadedTimeStamp == null || loadedTimeStamp < file.getTimeStamp() || SoftReference.dereference(imageRef) == null) { try { final byte[] content = file.contentsToByteArray(); InputStream inputStream = new ByteArrayInputStream(content, 0, content.length); @@ -153,11 +153,9 @@ public class ImagePreviewComponent extends JPanel implements PreviewHintComponen try { refresh(file); SoftReference imageRef = file.getUserData(BUFFERED_IMAGE_REF_KEY); - if (imageRef != null) { - final BufferedImage image = imageRef.get(); - if (image != null) { - return new ImagePreviewComponent(image, file.getLength()); - } + final BufferedImage image = SoftReference.dereference(imageRef); + if (image != null) { + return new ImagePreviewComponent(image, file.getLength()); } } catch (IOException ignored) { diff --git a/platform/lang-impl/src/com/intellij/find/FindBundle.java b/platform/lang-impl/src/com/intellij/find/FindBundle.java index 129858ae9ce8..e4c431bf9bf3 100644 --- a/platform/lang-impl/src/com/intellij/find/FindBundle.java +++ b/platform/lang-impl/src/com/intellij/find/FindBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -40,8 +40,7 @@ public class FindBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/lang-impl/src/com/intellij/find/impl/RegExHelpPopup.java b/platform/lang-impl/src/com/intellij/find/impl/RegExHelpPopup.java index 669b7d81a826..23dee12e362f 100644 --- a/platform/lang-impl/src/com/intellij/find/impl/RegExHelpPopup.java +++ b/platform/lang-impl/src/com/intellij/find/impl/RegExHelpPopup.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -22,6 +22,7 @@ import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.ui.popup.util.MinimizeButton; import com.intellij.ui.ScrollPaneFactory; +import com.intellij.util.ui.UIUtil; import javax.swing.*; import javax.swing.event.HyperlinkEvent; @@ -52,8 +53,10 @@ public class RegExHelpPopup extends JPanel { " summary=\"Regular expression constructs, and what they match\"> \n" + " \n" + " \n" + - " Construct \n" + - " Matches \n" + + " Construct \n" + + " Matches \n" + " \n" + " \n" + "   \n" + @@ -340,4 +343,7 @@ public class RegExHelpPopup extends JPanel { .setTitle("Regular expressions syntax").setDimensionServiceKey(null, "RegExHelpPopup", true).createPopup(); } + private static String toHTMLColor(Color color) { + return "#" + Integer.toHexString(color.getRGB() & 0xffffff); + } } diff --git a/platform/lang-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeFoldingBuilder.java b/platform/lang-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeFoldingBuilder.java new file mode 100644 index 000000000000..9dca9c5b7f60 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeFoldingBuilder.java @@ -0,0 +1,100 @@ +/* + * Copyright 2000-2013 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.ide.highlighter.custom.impl; + +import com.intellij.codeInsight.highlighting.BraceMatcher; +import com.intellij.codeInsight.highlighting.BraceMatchingUtil; +import com.intellij.ide.highlighter.custom.CustomFileHighlighter; +import com.intellij.lang.ASTNode; +import com.intellij.lang.folding.CustomFoldingBuilder; +import com.intellij.lang.folding.FoldingDescriptor; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.colors.EditorColorsManager; +import com.intellij.openapi.editor.ex.util.LexerEditorHighlighter; +import com.intellij.openapi.editor.highlighter.HighlighterIterator; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.fileTypes.SyntaxHighlighter; +import com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType; +import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.util.Trinity; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.PsiElement; +import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; + +import java.util.LinkedList; +import java.util.List; + +/** + * @author yole + */ +public class CustomFileTypeFoldingBuilder extends CustomFoldingBuilder { + + @Override + protected void buildLanguageFoldRegions(@NotNull List descriptors, + @NotNull PsiElement root, + @NotNull Document document, + boolean quick) { + FileType fileType = root.getContainingFile().getFileType(); + if (!(fileType instanceof CustomSyntaxTableFileType)) { + return; + } + CustomFileHighlighter highlighter = new CustomFileHighlighter(((CustomSyntaxTableFileType) fileType).getSyntaxTable()); + buildBraceMatcherBasedFolding(descriptors, root, document, highlighter); + } + + public static void buildBraceMatcherBasedFolding(List descriptors, + PsiElement root, + Document document, + SyntaxHighlighter highlighter) { + LexerEditorHighlighter editorHighlighter = new LexerEditorHighlighter(highlighter, EditorColorsManager.getInstance().getGlobalScheme()); + editorHighlighter.setText(document.getText()); + FileType fileType = root.getContainingFile().getFileType(); + BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(fileType, root.getLanguage()); + TextRange totalRange = root.getTextRange(); + final HighlighterIterator iterator = editorHighlighter.createIterator(totalRange.getStartOffset()); + + final LinkedList> stack = new LinkedList>(); + String editorText = document.getText(); + while (!iterator.atEnd() && iterator.getStart() < totalRange.getEndOffset()) { + final Trinity last; + if (braceMatcher.isLBraceToken(iterator, editorText, fileType) && + braceMatcher.isStructuralBrace(iterator, editorText, fileType)) { + stack.addLast(Trinity.create(iterator.getStart(), iterator.getEnd(), iterator.getTokenType())); + } + else if (braceMatcher.isRBraceToken(iterator, editorText, fileType) && + braceMatcher.isStructuralBrace(iterator, editorText, fileType) + && !stack.isEmpty() && braceMatcher.isPairBraces((last = stack.getLast()).third, iterator.getTokenType())) { + stack.removeLast(); + TextRange range = new TextRange(last.first, iterator.getEnd()); + if (StringUtil.countChars(document.getText(range), '\n') >= 3) { + descriptors.add(new FoldingDescriptor(root, range)); + } + } + iterator.advance(); + } + } + + @Override + protected String getLanguagePlaceholderText(@NotNull ASTNode node, @NotNull TextRange range) { + return "{...}"; + } + + @Override + protected boolean isRegionCollapsedByDefault(@NotNull ASTNode node) { + return false; + } +} diff --git a/platform/lang-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeSelectWordHandler.java b/platform/lang-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeSelectWordHandler.java new file mode 100644 index 000000000000..cc1b3108d4c6 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeSelectWordHandler.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2013 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.ide.highlighter.custom.impl; + +import com.intellij.codeInsight.editorActions.BraceMatcherBasedSelectioner; +import com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType; +import com.intellij.psi.PsiElement; + +/** + * @author yole + */ +public class CustomFileTypeSelectWordHandler extends BraceMatcherBasedSelectioner { + @Override + public boolean canSelect(PsiElement e) { + return e.getContainingFile().getFileType() instanceof CustomSyntaxTableFileType; + } +} diff --git a/platform/lang-impl/src/com/intellij/ide/highlighter/custom/impl/StandardFileTypeRegistrator.java b/platform/lang-impl/src/com/intellij/ide/highlighter/custom/impl/StandardFileTypeRegistrator.java index 772adf695ea5..07b5bb58edd7 100644 --- a/platform/lang-impl/src/com/intellij/ide/highlighter/custom/impl/StandardFileTypeRegistrator.java +++ b/platform/lang-impl/src/com/intellij/ide/highlighter/custom/impl/StandardFileTypeRegistrator.java @@ -16,8 +16,6 @@ package com.intellij.ide.highlighter.custom.impl; -import com.intellij.codeInsight.completion.CompletionUtil; -import com.intellij.codeInsight.completion.SyntaxTableCompletionData; import com.intellij.codeInsight.editorActions.TypedHandler; import com.intellij.codeInsight.highlighting.BraceMatchingUtil; import com.intellij.ide.highlighter.FileTypeRegistrator; @@ -37,7 +35,6 @@ public class StandardFileTypeRegistrator implements FileTypeRegistrator { private static void init(final AbstractFileType abstractFileType) { SyntaxTable table = abstractFileType.getSyntaxTable(); - CompletionUtil.registerCompletionData(abstractFileType,new SyntaxTableCompletionData(table)); if (!isEmpty(table.getStartComment()) && !isEmpty(table.getEndComment()) || !isEmpty(table.getLineComment())) { diff --git a/platform/lang-impl/src/com/intellij/indentation/AbstractIndentParser.java b/platform/lang-impl/src/com/intellij/indentation/AbstractIndentParser.java index 310f3f025f17..a298b73fda23 100644 --- a/platform/lang-impl/src/com/intellij/indentation/AbstractIndentParser.java +++ b/platform/lang-impl/src/com/intellij/indentation/AbstractIndentParser.java @@ -1,9 +1,23 @@ +/* + * Copyright 2000-2013 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.indentation; import com.intellij.lang.ASTNode; import com.intellij.lang.PsiBuilder; import com.intellij.lang.PsiParser; -import com.intellij.psi.TokenType; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; import com.intellij.util.containers.HashMap; @@ -114,7 +128,7 @@ public abstract class AbstractIndentParser implements PsiParser { } protected static boolean tokenIn(@Nullable final IElementType elementType, @NotNull final TokenSet tokenSet) { - return tokenIn(elementType, tokenSet.getTypes()); + return tokenSet.contains(elementType); } @NotNull diff --git a/platform/lang-impl/src/com/intellij/psi/formatter/WhiteSpaceFormattingStrategyFactory.java b/platform/lang-impl/src/com/intellij/psi/formatter/WhiteSpaceFormattingStrategyFactory.java index 77acdd406810..4d268f8da1d6 100644 --- a/platform/lang-impl/src/com/intellij/psi/formatter/WhiteSpaceFormattingStrategyFactory.java +++ b/platform/lang-impl/src/com/intellij/psi/formatter/WhiteSpaceFormattingStrategyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -20,6 +20,7 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; +import com.intellij.reference.SoftReference; import com.intellij.util.PatchedWeakReference; import org.jetbrains.annotations.NotNull; @@ -74,11 +75,9 @@ public class WhiteSpaceFormattingStrategyFactory { @NotNull public static Collection getAllStrategies() { final WeakReference> reference = myCachedStrategies.get(); - if (reference != null) { - final Collection strategies = reference.get(); - if (strategies != null) { - return strategies; - } + final Collection strategies = SoftReference.dereference(reference); + if (strategies != null) { + return strategies; } final Collection languages = Language.getRegisteredLanguages(); if (languages == null) { diff --git a/platform/lang-impl/src/com/intellij/semantic/SemServiceImpl.java b/platform/lang-impl/src/com/intellij/semantic/SemServiceImpl.java index 7d2329aa88fe..ebc286a2dfb0 100644 --- a/platform/lang-impl/src/com/intellij/semantic/SemServiceImpl.java +++ b/platform/lang-impl/src/com/intellij/semantic/SemServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -282,7 +282,7 @@ public class SemServiceImpl extends SemService{ @Nullable private SemCacheChunk obtainChunk(@Nullable PsiElement root) { final SoftReference ref = myCache.get(root); - return ref == null ? null : ref.get(); + return com.intellij.reference.SoftReference.dereference(ref); } @Override diff --git a/platform/lang-impl/src/com/intellij/tools/ToolsBundle.java b/platform/lang-impl/src/com/intellij/tools/ToolsBundle.java index f2ec53652e85..997da889eb9c 100644 --- a/platform/lang-impl/src/com/intellij/tools/ToolsBundle.java +++ b/platform/lang-impl/src/com/intellij/tools/ToolsBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -40,8 +40,7 @@ public class ToolsBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java index feba37c8888a..57c917b44219 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -1095,13 +1095,13 @@ public class FileBasedIndexImpl extends FileBasedIndex { if (myProjectsBeingUpdated.contains(project)) return null; SoftReference reference = project.getUserData(ourProjectFilesSetKey); - ProjectIndexableFilesFilter data = reference != null ? reference.get() : null; + ProjectIndexableFilesFilter data = com.intellij.reference.SoftReference.dereference(reference); if (data != null && data.myModificationCount == myFilesModCount) return data; if (myCalcIndexableFilesLock.tryLock()) { // make best effort for calculating filter try { reference = project.getUserData(ourProjectFilesSetKey); - data = reference != null ? reference.get() : null; + data = com.intellij.reference.SoftReference.dereference(reference); if (data != null && data.myModificationCount == myFilesModCount) { return data; } @@ -1557,7 +1557,7 @@ public class FileBasedIndexImpl extends FileBasedIndex { getInputFilter(requestedIndexId).acceptInput(vFile)) { // Reasonably attempt to use same file content when calculating indices as we can evaluate them several at once and store in file content WeakReference previousContentRef = document.getUserData(ourFileContentKey); - FileContentImpl previousContent = previousContentRef != null ? previousContentRef.get() : null; + FileContentImpl previousContent = com.intellij.reference.SoftReference.dereference(previousContentRef); final FileContentImpl newFc; if (previousContent != null && previousContent.getStamp() == currentDocStamp) { newFc = previousContent; diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryBundle.java b/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryBundle.java index df58d44c4743..6ff6d8d21fec 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryBundle.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -32,8 +32,7 @@ public class LocalHistoryBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/platform-api/src/com/intellij/featureStatistics/FeatureStatisticsBundle.java b/platform/platform-api/src/com/intellij/featureStatistics/FeatureStatisticsBundle.java index b4d2bf408c85..22136335e239 100644 --- a/platform/platform-api/src/com/intellij/featureStatistics/FeatureStatisticsBundle.java +++ b/platform/platform-api/src/com/intellij/featureStatistics/FeatureStatisticsBundle.java @@ -54,8 +54,7 @@ public class FeatureStatisticsBundle { } } - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeBuilder.java b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeBuilder.java index 2917ad27b80c..5f4417c920f6 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeBuilder.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -25,6 +25,7 @@ import com.intellij.openapi.progress.Progressive; import com.intellij.openapi.util.ActionCallback; import com.intellij.openapi.util.AsyncResult; import com.intellij.openapi.util.Condition; +import com.intellij.reference.SoftReference; import com.intellij.util.Processor; import com.intellij.util.containers.TransferToEDTQueue; import com.intellij.util.ui.UIUtil; @@ -634,7 +635,7 @@ public class AbstractTreeBuilder implements Disposable { @Nullable public static AbstractTreeBuilder getBuilderFor(@NotNull JTree tree) { final WeakReference ref = (WeakReference)tree.getClientProperty(TREE_BUILDER); - return ref != null ? (AbstractTreeBuilder)ref.get() : null; + return (AbstractTreeBuilder)SoftReference.dereference(ref); } @Nullable diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java b/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java index 61fda59ac4f6..94277aed0277 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -20,6 +20,7 @@ import com.intellij.openapi.progress.EmptyProgressIndicator; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.Progressive; import com.intellij.openapi.util.*; +import com.intellij.reference.SoftReference; import com.intellij.util.ui.tree.TreeUtil; import org.jdom.Element; import org.jetbrains.annotations.NonNls; @@ -442,10 +443,8 @@ public class TreeState implements JDOMExternalizable { @Override public ActionCallback getInitialized() { final WeakReference ref = (WeakReference)myTree.getClientProperty(CALLBACK); - if (ref != null) { - final ActionCallback callback = ref.get(); - if (callback != null) return callback; - } + final ActionCallback callback = SoftReference.dereference(ref); + if (callback != null) return callback; return new ActionCallback.Done(); } diff --git a/platform/platform-api/src/com/intellij/idea/ActionsBundle.java b/platform/platform-api/src/com/intellij/idea/ActionsBundle.java index 43318d00108b..68fb85a3f501 100644 --- a/platform/platform-api/src/com/intellij/idea/ActionsBundle.java +++ b/platform/platform-api/src/com/intellij/idea/ActionsBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -52,8 +52,7 @@ public class ActionsBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(IDEA_ACTIONS_BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/platform-api/src/com/intellij/notification/Notification.java b/platform/platform-api/src/com/intellij/notification/Notification.java index 5a538dcbfba2..674e20282334 100644 --- a/platform/platform-api/src/com/intellij/notification/Notification.java +++ b/platform/platform-api/src/com/intellij/notification/Notification.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.Balloon; import com.intellij.openapi.ui.popup.JBPopupAdapter; import com.intellij.openapi.ui.popup.LightweightWindowEvent; +import com.intellij.reference.SoftReference; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -129,8 +130,7 @@ public class Notification { balloon.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { - WeakReference ref = myBalloonRef; - if (ref != null && ref.get() == balloon) { + if (SoftReference.dereference(myBalloonRef) == balloon) { myBalloonRef = null; } } @@ -139,7 +139,7 @@ public class Notification { @Nullable public Balloon getBalloon() { - return myBalloonRef == null ? null : myBalloonRef.get(); + return SoftReference.dereference(myBalloonRef); } public void notify(@Nullable Project project) { diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java index 568abafab1cc..7f9e40550a6d 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java @@ -71,6 +71,7 @@ public interface IdeActions { @NonNls String ACTION_SMART_TYPE_COMPLETION = "SmartTypeCompletion"; @Deprecated @NonNls String ACTION_CLASS_NAME_COMPLETION = "ClassNameCompletion"; @NonNls String ACTION_HIPPIE_COMPLETION = "HippieCompletion"; + @NonNls String ACTION_HIPPIE_BACKWARD_COMPLETION = "HippieBackwardCompletion"; @NonNls String ACTION_CHOOSE_LOOKUP_ITEM = "EditorChooseLookupItem"; @NonNls String ACTION_CHOOSE_LOOKUP_ITEM_ALWAYS = "EditorChooseLookupItemAlways"; @NonNls String ACTION_CHOOSE_LOOKUP_ITEM_REPLACE = "EditorChooseLookupItemReplace"; diff --git a/platform/platform-api/src/com/intellij/openapi/application/ApplicationBundle.java b/platform/platform-api/src/com/intellij/openapi/application/ApplicationBundle.java index c64536b8775f..2f42278c3ee2 100644 --- a/platform/platform-api/src/com/intellij/openapi/application/ApplicationBundle.java +++ b/platform/platform-api/src/com/intellij/openapi/application/ApplicationBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class ApplicationBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/platform-api/src/com/intellij/openapi/diff/DiffBundle.java b/platform/platform-api/src/com/intellij/openapi/diff/DiffBundle.java index 42fda764171e..35ad6170213e 100644 --- a/platform/platform-api/src/com/intellij/openapi/diff/DiffBundle.java +++ b/platform/platform-api/src/com/intellij/openapi/diff/DiffBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class DiffBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/platform-api/src/com/intellij/openapi/fileEditor/OpenFileDescriptor.java b/platform/platform-api/src/com/intellij/openapi/fileEditor/OpenFileDescriptor.java index 3acfb0df70aa..d8f6572042e9 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileEditor/OpenFileDescriptor.java +++ b/platform/platform-api/src/com/intellij/openapi/fileEditor/OpenFileDescriptor.java @@ -118,12 +118,12 @@ public class OpenFileDescriptor implements Navigatable { throw new IllegalStateException("Navigation is not possible with null project"); } - if (!myFile.isDirectory() && navigateInEditor(myProject, requestFocus)) return; + if (!myFile.isDirectory() && navigateInEditorOrNativeApp(myProject, requestFocus)) return; navigateInProjectView(requestFocus); } - private boolean navigateInEditor(@NotNull Project project, boolean requestFocus) { + private boolean navigateInEditorOrNativeApp(@NotNull Project project, boolean requestFocus) { FileType type = FileTypeManager.getInstance().getKnownFileTypeOrAssociate(myFile,project); if (type == null || !myFile.isValid()) return false; @@ -131,6 +131,10 @@ public class OpenFileDescriptor implements Navigatable { return ((INativeFileType) type).openFileInAssociatedApplication(project, myFile); } + return navigateInEditor(project, requestFocus); + } + + public boolean navigateInEditor(@NotNull Project project, boolean requestFocus) { return navigateInRequestedEditor() || navigateInAnyFileEditor(project, requestFocus); } diff --git a/platform/platform-api/src/com/intellij/openapi/keymap/KeyMapBundle.java b/platform/platform-api/src/com/intellij/openapi/keymap/KeyMapBundle.java index 2e6d14fb2cf5..efd081cc53d9 100644 --- a/platform/platform-api/src/com/intellij/openapi/keymap/KeyMapBundle.java +++ b/platform/platform-api/src/com/intellij/openapi/keymap/KeyMapBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -44,8 +44,7 @@ public class KeyMapBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/platform-api/src/com/intellij/openapi/options/OptionsBundle.java b/platform/platform-api/src/com/intellij/openapi/options/OptionsBundle.java index d80d5704d80d..e86d07d7a133 100644 --- a/platform/platform-api/src/com/intellij/openapi/options/OptionsBundle.java +++ b/platform/platform-api/src/com/intellij/openapi/options/OptionsBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class OptionsBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/platform-api/src/com/intellij/openapi/vcs/VcsBundle.java b/platform/platform-api/src/com/intellij/openapi/vcs/VcsBundle.java index 54dac0ecee93..536db1ebd279 100644 --- a/platform/platform-api/src/com/intellij/openapi/vcs/VcsBundle.java +++ b/platform/platform-api/src/com/intellij/openapi/vcs/VcsBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -43,8 +43,7 @@ public class VcsBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/platform-api/src/com/intellij/ui/tabs/TabInfo.java b/platform/platform-api/src/com/intellij/ui/tabs/TabInfo.java index 40cbb9a94307..302ad819cd7f 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/TabInfo.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/TabInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -18,6 +18,7 @@ package com.intellij.ui.tabs; import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.ActionGroup; import com.intellij.openapi.ui.Queryable; +import com.intellij.reference.SoftReference; import com.intellij.ui.PlaceProvider; import com.intellij.ui.SimpleColoredText; import com.intellij.ui.SimpleTextAttributes; @@ -237,7 +238,7 @@ public final class TabInfo implements Queryable, PlaceProvider { @Nullable public JComponent getLastFocusOwner() { - return myLastFocusOwner != null ? myLastFocusOwner.get() : null; + return SoftReference.dereference(myLastFocusOwner); } public TabInfo setAlertIcon(final AlertIcon alertIcon) { diff --git a/platform/platform-impl/src/com/intellij/diagnostic/DiagnosticBundle.java b/platform/platform-impl/src/com/intellij/diagnostic/DiagnosticBundle.java index 3e0b118e953e..6ecd54988fab 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/DiagnosticBundle.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/DiagnosticBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class DiagnosticBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/platform-impl/src/com/intellij/execution/process/KillableColoredProcessHandler.java b/platform/platform-impl/src/com/intellij/execution/process/KillableColoredProcessHandler.java index 6b47c0a053c2..267e386ac45c 100644 --- a/platform/platform-impl/src/com/intellij/execution/process/KillableColoredProcessHandler.java +++ b/platform/platform-impl/src/com/intellij/execution/process/KillableColoredProcessHandler.java @@ -106,16 +106,7 @@ public class KillableColoredProcessHandler extends ColoredProcessHandler impleme protected void doDestroyProcess() { boolean gracefulTerminationAttempted = false; if (canKillProcessSoftly() && shouldKillProcessSoftly()) { - if (SystemInfo.isWindows) { - if (myProcess instanceof RunnerWinProcess) { - RunnerWinProcess runnerWinProcess = (RunnerWinProcess) myProcess; - runnerWinProcess.destroyGracefully(true); - gracefulTerminationAttempted = true; - } - } - else if (SystemInfo.isUnix) { - gracefulTerminationAttempted = UnixProcessManager.sendSigIntToProcessTree(myProcess); - } + gracefulTerminationAttempted = gracefulProcessTermination(); } if (!gracefulTerminationAttempted) { // execute default process destroy @@ -123,6 +114,20 @@ public class KillableColoredProcessHandler extends ColoredProcessHandler impleme } } + protected boolean gracefulProcessTermination() { + if (SystemInfo.isWindows) { + if (myProcess instanceof RunnerWinProcess) { + RunnerWinProcess runnerWinProcess = (RunnerWinProcess) myProcess; + runnerWinProcess.destroyGracefully(true); + return true; + } + } + else if (SystemInfo.isUnix) { + return UnixProcessManager.sendSigIntToProcessTree(myProcess); + } + return false; + } + /** * @return true, if graceful process termination should be attempted first */ diff --git a/platform/platform-impl/src/com/intellij/ide/IdeRepaintManager.java b/platform/platform-impl/src/com/intellij/ide/IdeRepaintManager.java index bb2cf498987c..8aa0e38c0d0d 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeRepaintManager.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeRepaintManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -23,6 +23,7 @@ package com.intellij.ide; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.reference.SoftReference; import org.jetbrains.annotations.NonNls; import javax.swing.*; @@ -160,7 +161,7 @@ public class IdeRepaintManager extends RepaintManager { return; } //ignore the last processed component - if (myLastComponent != null && c == myLastComponent.get()) { + if (SoftReference.dereference(myLastComponent) == c) { return; } myLastComponent = new WeakReference(c); diff --git a/platform/platform-impl/src/com/intellij/ide/dnd/DnDManagerImpl.java b/platform/platform-impl/src/com/intellij/ide/dnd/DnDManagerImpl.java index 84d516265588..621ff0d2346d 100644 --- a/platform/platform-impl/src/com/intellij/ide/dnd/DnDManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/dnd/DnDManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -20,6 +20,7 @@ import com.intellij.openapi.application.Application; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; +import com.intellij.reference.SoftReference; import com.intellij.ui.awt.RelativeRectangle; import com.intellij.util.ui.GeometryUtil; import com.intellij.util.ui.UIUtil; @@ -741,6 +742,6 @@ public class DnDManagerImpl extends DnDManager implements Disposable { @Nullable public Component getLastDropHandler() { - return myLastDropHandler != null ? myLastDropHandler.get() : null; + return SoftReference.dereference(myLastDropHandler); } } diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/RepositoryContentHandler.java b/platform/platform-impl/src/com/intellij/ide/plugins/RepositoryContentHandler.java index d36731d87858..6092139d3e0f 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/RepositoryContentHandler.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/RepositoryContentHandler.java @@ -53,7 +53,7 @@ class RepositoryContentHandler extends DefaultHandler { @NonNls private static final String DATE = "date"; private PluginNode currentPlugin; - private String currentValue; + private final StringBuilder currentValue = new StringBuilder(); private ArrayList plugins; private Stack categoriesStack; @@ -86,45 +86,47 @@ class RepositoryContentHandler extends DefaultHandler { currentPlugin.setVendorEmail(atts.getValue(EMAIL)); currentPlugin.setVendorUrl(atts.getValue(URL)); } - currentValue = ""; + currentValue.setLength(0); } public void endElement(String namespaceURI, String localName, String qName) throws SAXException { + String currentValueString = currentValue.toString(); + currentValue.setLength(0); + if (qName.equals(ID)) { - currentPlugin.setId(currentValue); + currentPlugin.setId(currentValueString); } else if (qName.equals(NAME)) { - currentPlugin.setName(currentValue); + currentPlugin.setName(currentValueString); } else if (qName.equals(DESCRIPTION)) { - currentPlugin.setDescription(currentValue); + currentPlugin.setDescription(currentValueString); } else if (qName.equals(VERSION)) { - currentPlugin.setVersion(currentValue); + currentPlugin.setVersion(currentValueString); } else if (qName.equals(VENDOR)) { - currentPlugin.setVendor(currentValue); + currentPlugin.setVendor(currentValueString); } else if (qName.equals(DEPENDS)) { - currentPlugin.addDepends(PluginId.getId(currentValue)); + currentPlugin.addDepends(PluginId.getId(currentValueString)); } else if (qName.equals(CHNAGE_NOTES)) { - currentPlugin.setChangeNotes(currentValue); + currentPlugin.setChangeNotes(currentValueString); } else if (qName.equals(CATEGORY)) { categoriesStack.pop(); } else if (qName.equals(RATING)) { - currentPlugin.setRating(currentValue); + currentPlugin.setRating(currentValueString); } else if (qName.equals(DOWNLOAD_URL)) { - currentPlugin.setDownloadUrl(currentValue); + currentPlugin.setDownloadUrl(currentValueString); } - currentValue = ""; } public void characters(char[] ch, int start, int length) throws SAXException { - currentValue += new String(ch, start, length); + currentValue.append(ch, start, length); } public ArrayList getPluginsList() { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorHighlighterCache.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorHighlighterCache.java index a90d575f9e3c..c1499a71a71b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorHighlighterCache.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorHighlighterCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -19,6 +19,7 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.ex.util.LexerEditorHighlighter; import com.intellij.openapi.editor.highlighter.EditorHighlighter; import com.intellij.openapi.util.Key; +import com.intellij.reference.SoftReference; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -43,7 +44,7 @@ public class EditorHighlighterCache { return null; } final WeakReference editorHighlighterWeakReference = document.getUserData(ourSomeEditorSyntaxHighlighter); - final EditorHighlighter someEditorHighlighter = editorHighlighterWeakReference != null ? editorHighlighterWeakReference.get() : null; + final EditorHighlighter someEditorHighlighter = SoftReference.dereference(editorHighlighterWeakReference); if (someEditorHighlighter instanceof LexerEditorHighlighter && ((LexerEditorHighlighter)someEditorHighlighter).isValid() 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 ce640085e6d4..9ad2d81c0846 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 @@ -6299,13 +6299,10 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi int documentLength = myDocument.getTextLength(); int x = 0; boolean lastLineLengthCalculated = false; - final int fontSize = myScheme.getEditorFontSize(); - final String fontName = myScheme.getEditorFontName(); List softWraps = getSoftWrapModel().getRegisteredSoftWraps(); int softWrapsIndex = -1; - FontInfo lastFontInfo = null; for (int line = 0; line < lineCount; line++) { if (myLineWidths.getQuick(line) != -1) continue; if (line == lineCount - 1) { @@ -6404,10 +6401,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi } } else { - if (lastFontInfo == null || !lastFontInfo.canDisplay(c)) { - lastFontInfo = ComplementaryFontsRegistry.getFontAbleToDisplay(c, fontSize, fontType, fontName); - } - x += lastFontInfo.charWidth(c); + x += EditorUtil.charWidth(c, fontType, EditorImpl.this); offset++; } } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/BaseRemoteFileEditor.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/BaseRemoteFileEditor.java index b3dde8163544..fc12a045783a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/BaseRemoteFileEditor.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/BaseRemoteFileEditor.java @@ -13,6 +13,7 @@ import com.intellij.openapi.fileEditor.impl.text.TextEditorState; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.UserDataHolderBase; +import com.intellij.pom.Navigatable; import com.intellij.util.EventDispatcher; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -22,6 +23,7 @@ import java.beans.PropertyChangeListener; public abstract class BaseRemoteFileEditor implements TextEditor, PropertyChangeListener { protected Editor myMockTextEditor; + protected volatile Navigatable myPendingNavigatable; protected final Project myProject; private final UserDataHolderBase myUserDataHolder = new UserDataHolderBase(); @@ -129,4 +131,31 @@ public abstract class BaseRemoteFileEditor implements TextEditor, PropertyChange public void propertyChange(PropertyChangeEvent evt) { myDispatcher.getMulticaster().propertyChange(evt); } + + @Override + public boolean canNavigateTo(@NotNull Navigatable navigatable) { + TextEditor editor = getTextEditor(); + return editor == null ? isValid() : editor.canNavigateTo(navigatable); + } + + @Override + public void navigateTo(@NotNull Navigatable navigatable) { + TextEditor editor = getTextEditor(); + if (editor != null) { + editor.navigateTo(navigatable); + } + else if (isValid()) { + myPendingNavigatable = navigatable; + } + } + + protected void checkPendingNavigable() { + Navigatable navigatable = myPendingNavigatable; + if (navigatable != null) { + myPendingNavigatable = null; + TextEditor editor = getTextEditor(); + assert editor != null; + editor.navigateTo(navigatable); + } + } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.java index 354e0c774a51..5c34d2eb2523 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.java @@ -792,7 +792,7 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec for (int i = 0; i < providers.length; i++) { try { final FileEditorProvider provider = providers[i]; - LOG.assertTrue(provider != null); + LOG.assertTrue(provider != null, "Provider for file "+file+" is null. All providers: "+Arrays.asList(providers)); LOG.assertTrue(provider.accept(myProject, file), "Provider " + provider + " doesn't accept file " + file); final FileEditor editor = provider.createEditor(myProject, file); LOG.assertTrue(editor != null); diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/HttpFileEditor.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/HttpFileEditor.java index 57e37184e364..fd7c5710ab5d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/HttpFileEditor.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/HttpFileEditor.java @@ -15,11 +15,11 @@ */ package com.intellij.openapi.fileEditor.impl.http; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.fileEditor.TextEditor; import com.intellij.openapi.fileEditor.impl.BaseRemoteFileEditor; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.impl.http.HttpVirtualFile; -import com.intellij.pom.Navigatable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -35,6 +35,22 @@ public class HttpFileEditor extends BaseRemoteFileEditor { super(project); myPanel = new RemoteFilePanel(project, virtualFile, this); + virtualFile.getFileInfo().download().doWhenDone(new Runnable() { + @Override + public void run() { + ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override + public void run() { + checkPendingNavigable(); + } + }); + } + }).doWhenRejected(new Runnable() { + @Override + public void run() { + myPendingNavigatable = null; + } + }); } @Override @@ -68,20 +84,6 @@ public class HttpFileEditor extends BaseRemoteFileEditor { myPanel.deselectNotify(); } - @Override - public boolean canNavigateTo(@NotNull Navigatable navigatable) { - TextEditor textEditor = getTextEditor(); - return textEditor != null && textEditor.canNavigateTo(navigatable); - } - - @Override - public void navigateTo(@NotNull Navigatable navigatable) { - final TextEditor textEditor = myPanel.getFileEditor(); - if (textEditor != null) { - textEditor.navigateTo(navigatable); - } - } - @Override @Nullable protected TextEditor getTextEditor() { diff --git a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/KeyProcessorContext.java b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/KeyProcessorContext.java index d01bc8e1a068..e832caae4775 100644 --- a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/KeyProcessorContext.java +++ b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/KeyProcessorContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -17,6 +17,7 @@ package com.intellij.openapi.keymap.impl; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.reference.SoftReference; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -44,7 +45,7 @@ public class KeyProcessorContext { @Nullable public JComponent getFoundComponent() { - return myFoundComponent != null ? myFoundComponent.get() : null; + return SoftReference.dereference(myFoundComponent); } public void setFoundComponent(final JComponent foundComponent) { @@ -77,7 +78,7 @@ public class KeyProcessorContext { @Nullable public Component getFocusOwner() { - return myFocusOwner != null ? myFocusOwner.get() : null; + return SoftReference.dereference(myFocusOwner); } public void setFocusOwner(final Component focusOwner) { diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/impl/DialogWrapperPeerImpl.java b/platform/platform-impl/src/com/intellij/openapi/ui/impl/DialogWrapperPeerImpl.java index b58811c930fb..dc9821ec9836 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/impl/DialogWrapperPeerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/impl/DialogWrapperPeerImpl.java @@ -43,6 +43,7 @@ import com.intellij.openapi.wm.ex.LayoutFocusTraversalPolicyExt; import com.intellij.openapi.wm.ex.WindowManagerEx; import com.intellij.openapi.wm.impl.IdeFrameImpl; import com.intellij.openapi.wm.impl.IdeGlassPaneImpl; +import com.intellij.reference.SoftReference; import com.intellij.ui.*; import com.intellij.ui.components.JBLayeredPane; import com.intellij.ui.mac.foundation.Foundation; @@ -788,7 +789,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra @Nullable private Project getProject() { - return myProject != null ? myProject.get() : null; + return SoftReference.dereference(myProject); } @Override diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32FsCache.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32FsCache.java index f21d2c06bb21..aef53edeb096 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32FsCache.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32FsCache.java @@ -44,8 +44,7 @@ class Win32FsCache { @NotNull private Map getMap() { - Reference> cache = myCache; - Map map = cache == null ? null : cache.get(); + Map map = com.intellij.reference.SoftReference.dereference(myCache); if (map == null) { map = new THashMap(FileUtil.PATH_HASHING_STRATEGY); myCache = new SoftReference>(map); diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java index db7be8ee990a..e6d42d67df93 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java @@ -960,10 +960,13 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone LOG.error(sb); return null; } - if (visited == null) visited = new TIntArrayList(DEPTH_LIMIT); - visited.add(id); int parentId = getParent(id); + if (parentId >= id) { + if (visited == null) visited = new TIntArrayList(DEPTH_LIMIT); + } + if (visited != null) visited.add(id); + VirtualFileSystemEntry result; if (parentId == 0) { myRootsLock.readLock().lock(); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/FocusManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/FocusManagerImpl.java index 46c5190b0cac..5b1ddc60b337 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/FocusManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/FocusManagerImpl.java @@ -35,6 +35,7 @@ import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.wm.*; import com.intellij.openapi.wm.ex.IdeFocusTraversalPolicy; import com.intellij.openapi.wm.ex.LayoutFocusTraversalPolicyExt; +import com.intellij.reference.SoftReference; import com.intellij.ui.FocusTrackback; import com.intellij.util.containers.WeakValueHashMap; import com.intellij.util.ui.UIUtil; @@ -417,8 +418,7 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable { @Nullable private FocusCommand getLastEffectiveForcedRequest() { - if (myLastForcedRequest == null) return null; - final FocusCommand request = myLastForcedRequest.get(); + final FocusCommand request = SoftReference.dereference(myLastForcedRequest); return request != null && !request.isExpired() ? request : null; } diff --git a/platform/platform-impl/src/com/intellij/psi/statistics/impl/StatisticsManagerImpl.java b/platform/platform-impl/src/com/intellij/psi/statistics/impl/StatisticsManagerImpl.java index 9d28881403c2..a62832a6e18b 100644 --- a/platform/platform-impl/src/com/intellij/psi/statistics/impl/StatisticsManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/psi/statistics/impl/StatisticsManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -138,11 +138,9 @@ public class StatisticsManagerImpl extends StatisticsManager { private StatisticsUnit getUnit(int unitNumber) { SoftReference ref = myUnits[unitNumber]; - if (ref != null){ - StatisticsUnit unit = (StatisticsUnit)ref.get(); - if (unit != null) return unit; - } - StatisticsUnit unit = loadUnit(unitNumber); + StatisticsUnit unit = (StatisticsUnit)SoftReference.dereference(ref); + if (unit != null) return unit; + unit = loadUnit(unitNumber); if (unit == null){ unit = new StatisticsUnit(unitNumber); } diff --git a/platform/platform-impl/src/com/intellij/ui/mac/MacMessagesImpl.java b/platform/platform-impl/src/com/intellij/ui/mac/MacMessagesImpl.java index a4e5dce7ee0e..b9cf1e39fdb7 100644 --- a/platform/platform-impl/src/com/intellij/ui/mac/MacMessagesImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/mac/MacMessagesImpl.java @@ -702,7 +702,9 @@ public class MacMessagesImpl extends MacMessages { } //Actually can, but not in this implementation. If you know a reasonable scenario, please ask Denis Fokin for the improvement. - LOG.assertTrue(MacUtil.getWindowTitle(_window) != null, "A window without a title should not be used for showing MacMessages"); + if (SystemInfo.isAppleJvm) { + LOG.assertTrue(MacUtil.getWindowTitle(_window) != null, "A window without a title should not be used for showing MacMessages"); + } while (_window != null && MacUtil.getWindowTitle(_window) == null) { _window = _window.getOwner(); //At least our frame should have a title diff --git a/platform/platform-impl/src/net/sf/cglib/core/AbstractClassGenerator.java b/platform/platform-impl/src/net/sf/cglib/core/AbstractClassGenerator.java index 9f2bbc11f62f..42bc23096a66 100644 --- a/platform/platform-impl/src/net/sf/cglib/core/AbstractClassGenerator.java +++ b/platform/platform-impl/src/net/sf/cglib/core/AbstractClassGenerator.java @@ -15,6 +15,7 @@ */ package net.sf.cglib.core; +import com.intellij.reference.SoftReference; import org.objectweb.asm.ClassReader; import java.lang.ref.Reference; @@ -199,7 +200,7 @@ implements ClassGenerator source.cache.put(loader, cache2); } else if (useCache) { Reference ref = (Reference)cache2.get(key); - gen = (Class) (( ref == null ) ? null : ref.get()); + gen = (Class) SoftReference.dereference(ref); } if (gen == null) { Object save = CURRENT.get(); diff --git a/platform/platform-main/src/com/intellij/idea/MainImpl.java b/platform/platform-main/src/com/intellij/idea/MainImpl.java index 32269afde611..afaf62e87e9d 100644 --- a/platform/platform-main/src/com/intellij/idea/MainImpl.java +++ b/platform/platform-main/src/com/intellij/idea/MainImpl.java @@ -29,18 +29,24 @@ public class MainImpl { * Called from PluginManager via reflection. */ protected static void start(final String[] args) { - System.setProperty(PlatformUtilsCore.PLATFORM_PREFIX_KEY, PlatformUtils.getPlatformPrefix(PlatformUtils.COMMUNITY_PREFIX)); + System.setProperty(PlatformUtilsCore.PLATFORM_PREFIX_KEY, PlatformUtils.getPlatformPrefix(PlatformUtilsCore.COMMUNITY_PREFIX)); StartupUtil.prepareAndStart(args, new StartupUtil.AppStarter() { @Override public void start(boolean newConfigFolder) { - final IdeaApplication app = new IdeaApplication(args); //noinspection SSBasedInspection SwingUtilities.invokeLater(new Runnable() { @Override public void run() { PluginManager.installExceptionHandler(); - app.run(); + final IdeaApplication app = new IdeaApplication(args); + //noinspection SSBasedInspection + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + app.run(); + } + }); } }); } diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 65fd47d6baf1..2f6a4de3a727 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -563,6 +563,7 @@ + @@ -838,6 +839,8 @@ + + @@ -862,6 +865,8 @@ + + diff --git a/platform/platform-tests/testData/selectWord/customFileTypeBraces/after1.cs b/platform/platform-tests/testData/selectWord/customFileTypeBraces/after1.cs new file mode 100644 index 000000000000..359af75c3a66 --- /dev/null +++ b/platform/platform-tests/testData/selectWord/customFileTypeBraces/after1.cs @@ -0,0 +1,3 @@ +if (true) { + x = foo[bar(xyzzy + fizzy)]; +} diff --git a/platform/platform-tests/testData/selectWord/customFileTypeBraces/after2.cs b/platform/platform-tests/testData/selectWord/customFileTypeBraces/after2.cs new file mode 100644 index 000000000000..ec957fb8449f --- /dev/null +++ b/platform/platform-tests/testData/selectWord/customFileTypeBraces/after2.cs @@ -0,0 +1,3 @@ +if (true) { + x = foo[bar(xyzzy + fizzy)]; +} diff --git a/platform/platform-tests/testData/selectWord/customFileTypeBraces/after3.cs b/platform/platform-tests/testData/selectWord/customFileTypeBraces/after3.cs new file mode 100644 index 000000000000..4f6eb2934077 --- /dev/null +++ b/platform/platform-tests/testData/selectWord/customFileTypeBraces/after3.cs @@ -0,0 +1,3 @@ +if (true) { + x = foo[bar(xyzzy + fizzy)]; +} diff --git a/platform/platform-tests/testData/selectWord/customFileTypeBraces/after4.cs b/platform/platform-tests/testData/selectWord/customFileTypeBraces/after4.cs new file mode 100644 index 000000000000..6357e59ac2f6 --- /dev/null +++ b/platform/platform-tests/testData/selectWord/customFileTypeBraces/after4.cs @@ -0,0 +1,3 @@ +if (true) { + x = foo[bar(xyzzy + fizzy)]; +} diff --git a/platform/platform-tests/testData/selectWord/customFileTypeBraces/after5.cs b/platform/platform-tests/testData/selectWord/customFileTypeBraces/after5.cs new file mode 100644 index 000000000000..414d4e118dc4 --- /dev/null +++ b/platform/platform-tests/testData/selectWord/customFileTypeBraces/after5.cs @@ -0,0 +1,3 @@ +if (true) { + x = foo[bar(xyzzy + fizzy)]; +} diff --git a/platform/platform-tests/testData/selectWord/customFileTypeBraces/after6.cs b/platform/platform-tests/testData/selectWord/customFileTypeBraces/after6.cs new file mode 100644 index 000000000000..054e064d4d7b --- /dev/null +++ b/platform/platform-tests/testData/selectWord/customFileTypeBraces/after6.cs @@ -0,0 +1,3 @@ +if (true) { + x = foo[bar(xyzzy + fizzy)]; +} diff --git a/platform/platform-tests/testData/selectWord/customFileTypeBraces/after7.cs b/platform/platform-tests/testData/selectWord/customFileTypeBraces/after7.cs new file mode 100644 index 000000000000..a1a1e9e3e6e2 --- /dev/null +++ b/platform/platform-tests/testData/selectWord/customFileTypeBraces/after7.cs @@ -0,0 +1,3 @@ +if (true) { + x = foo[bar(xyzzy + fizzy)]; +} diff --git a/platform/platform-tests/testData/selectWord/customFileTypeBraces/after8.cs b/platform/platform-tests/testData/selectWord/customFileTypeBraces/after8.cs new file mode 100644 index 000000000000..ba5a73382a52 --- /dev/null +++ b/platform/platform-tests/testData/selectWord/customFileTypeBraces/after8.cs @@ -0,0 +1,3 @@ +if (true) { + x = foo[bar(xyzzy + fizzy)]; +} diff --git a/platform/platform-tests/testData/selectWord/customFileTypeBraces/before.cs b/platform/platform-tests/testData/selectWord/customFileTypeBraces/before.cs new file mode 100644 index 000000000000..d45787fe2a02 --- /dev/null +++ b/platform/platform-tests/testData/selectWord/customFileTypeBraces/before.cs @@ -0,0 +1,3 @@ +if (true) { + x = foo[bar(xyzzy + fizzy)]; +} diff --git a/platform/platform-tests/testData/selectWord/customFileTypeSkipMatchedPair/after1.cs b/platform/platform-tests/testData/selectWord/customFileTypeSkipMatchedPair/after1.cs new file mode 100644 index 000000000000..96bd024246d3 --- /dev/null +++ b/platform/platform-tests/testData/selectWord/customFileTypeSkipMatchedPair/after1.cs @@ -0,0 +1 @@ +if (!gets_s(buffer, sizeof(buffer)-1)) \ No newline at end of file diff --git a/platform/platform-tests/testData/selectWord/customFileTypeSkipMatchedPair/after2.cs b/platform/platform-tests/testData/selectWord/customFileTypeSkipMatchedPair/after2.cs new file mode 100644 index 000000000000..5602c0fde01d --- /dev/null +++ b/platform/platform-tests/testData/selectWord/customFileTypeSkipMatchedPair/after2.cs @@ -0,0 +1 @@ +if (!gets_s(buffer, sizeof(buffer)-1)) \ No newline at end of file diff --git a/platform/platform-tests/testData/selectWord/customFileTypeSkipMatchedPair/before.cs b/platform/platform-tests/testData/selectWord/customFileTypeSkipMatchedPair/before.cs new file mode 100644 index 000000000000..a21f832ccfce --- /dev/null +++ b/platform/platform-tests/testData/selectWord/customFileTypeSkipMatchedPair/before.cs @@ -0,0 +1 @@ +if (!gets_s(buffer, sizeof(buffer)-1)) \ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/ide/highlighter/custom/CustomFileTypeWordSelectionTest.java b/platform/platform-tests/testSrc/com/intellij/ide/highlighter/custom/CustomFileTypeWordSelectionTest.java new file mode 100644 index 000000000000..9f6bd1bcb2d0 --- /dev/null +++ b/platform/platform-tests/testSrc/com/intellij/ide/highlighter/custom/CustomFileTypeWordSelectionTest.java @@ -0,0 +1,51 @@ +/* + * Copyright 2000-2013 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.ide.highlighter.custom; + +import com.intellij.testFramework.PlatformTestCase; +import com.intellij.testFramework.fixtures.CodeInsightTestUtil; +import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; + +/** + * @author yole + */ +public class CustomFileTypeWordSelectionTest extends LightPlatformCodeInsightFixtureTestCase { + public CustomFileTypeWordSelectionTest() { + PlatformTestCase.initPlatformLangPrefix(); + } + + public void testCustomFileTypeBraces() { + doTest(); + } + + public void testCustomFileTypeSkipMatchedPair() { + doTest(); + } + + @Override + protected boolean isCommunity() { + return true; + } + + @Override + protected String getBasePath() { + return "/platform/platform-tests/testData/selectWord/"; + } + + private void doTest() { + CodeInsightTestUtil.doWordSelectionTestOnDirectory(myFixture, getTestName(true), "cs"); + } +} diff --git a/platform/projectModel-api/src/com/intellij/openapi/project/ProjectBundle.java b/platform/projectModel-api/src/com/intellij/openapi/project/ProjectBundle.java index 8bdea29f5a38..961e91842e24 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/project/ProjectBundle.java +++ b/platform/projectModel-api/src/com/intellij/openapi/project/ProjectBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -36,8 +36,7 @@ public class ProjectBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudBundle.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudBundle.java index b2036536859a..6353510c0fb9 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudBundle.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudBundle.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2013 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.remoteServer.util; import com.intellij.CommonBundle; @@ -26,8 +41,7 @@ public class CloudBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/SMTestsRunnerBundle.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/SMTestsRunnerBundle.java index c1d67981c6fb..87d7d7d3a391 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/SMTestsRunnerBundle.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/SMTestsRunnerBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class SMTestsRunnerBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java index 37f360cfe6bf..26c9c896512e 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java @@ -462,6 +462,7 @@ public class PlatformTestUtil { public void assertTiming() { assert expectedMs != 0 : "Must call .expect() before run test"; if (COVERAGE_ENABLED_BUILD) return; + Timings.getStatistics(); // warmup, measure while (true) { attempts--; 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 a9795e406c4c..3a204cfdff76 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -667,13 +667,17 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @NotNull public PsiElement getElementAtCaret() { assertInitialized(); - final PsiElement element = TargetElementUtilBase.findTargetElement(getCompletionEditor(), - TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED | - TargetElementUtilBase.ELEMENT_NAME_ACCEPTED); - assert element != null : "element not found in file " + - myFile.getName() + - " at caret position, offset " + - myEditor.getCaretModel().getOffset() + "\"" + + Editor editor = getCompletionEditor(); + int findTargetFlags = TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtilBase.ELEMENT_NAME_ACCEPTED; + PsiElement element = TargetElementUtilBase.findTargetElement(editor, findTargetFlags); + + // if no references found in injected fragment, try outer document + if (element == null && editor instanceof EditorWindow) { + element = TargetElementUtilBase.findTargetElement(((EditorWindow)editor).getDelegate(), findTargetFlags); + } + + assert element != null : "element not found in file " + myFile.getName() + + " at caret position, offset " + myEditor.getCaretModel().getOffset() + "\"" + " psi structure: " + DebugUtil.psiToString(myFile, true, true); return element; } diff --git a/platform/usageView/src/com/intellij/usages/ChunkExtractor.java b/platform/usageView/src/com/intellij/usages/ChunkExtractor.java index dc9068e2814b..930321fc61d5 100644 --- a/platform/usageView/src/com/intellij/usages/ChunkExtractor.java +++ b/platform/usageView/src/com/intellij/usages/ChunkExtractor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -36,6 +36,7 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; import com.intellij.psi.tree.IElementType; +import com.intellij.reference.SoftReference; import com.intellij.usageView.UsageTreeColors; import com.intellij.usageView.UsageTreeColorsScheme; import com.intellij.util.Processor; @@ -75,7 +76,7 @@ public class ChunkExtractor { @NotNull public T getValue() { - final T cur = myRef == null ? null : myRef.get(); + final T cur = SoftReference.dereference(myRef); if (cur != null) return cur; final T result = create(); myRef = new WeakReference(result); diff --git a/platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java b/platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java index da6d75ff5fad..d7949f370a48 100644 --- a/platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java +++ b/platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java @@ -437,8 +437,7 @@ public class UsageInfo2UsageAdapter implements UsageInModule, @Override @NotNull public TextChunk[] getText() { - Reference reference = myTextChunks; - TextChunk[] chunks = reference == null ? null : reference.get(); + TextChunk[] chunks = SoftReference.dereference(myTextChunks); final long currentModificationStamp = getCurrentModificationStamp(); boolean isModified = currentModificationStamp != myModificationStamp; if (chunks == null || isValid() && isModified) { diff --git a/platform/util-rt/src/com/intellij/reference/SoftLazyValue.java b/platform/util-rt/src/com/intellij/reference/SoftLazyValue.java index 379ab3cf799e..1f301eca13c0 100644 --- a/platform/util-rt/src/com/intellij/reference/SoftLazyValue.java +++ b/platform/util-rt/src/com/intellij/reference/SoftLazyValue.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -27,8 +27,8 @@ public abstract class SoftLazyValue { private SoftReference myReference; public T getValue() { - T t; - if (myReference == null || (t = myReference.get()) == null) { + T t = com.intellij.reference.SoftReference.dereference(myReference); + if (t == null) { t = compute(); myReference = new SoftReference(t); } diff --git a/platform/util/src/com/intellij/AbstractBundle.java b/platform/util/src/com/intellij/AbstractBundle.java index 52ef3ef94927..372094e2211a 100644 --- a/platform/util/src/com/intellij/AbstractBundle.java +++ b/platform/util/src/com/intellij/AbstractBundle.java @@ -60,8 +60,7 @@ public abstract class AbstractBundle { } private ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (myBundle != null) bundle = myBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(myBundle); if (bundle == null) { bundle = getResourceBundle(myPathToBundle, getClass().getClassLoader()); myBundle = new SoftReference(bundle); diff --git a/platform/util/src/com/intellij/CommonBundle.java b/platform/util/src/com/intellij/CommonBundle.java index fdcdb06e4bcf..ce678364a5ba 100644 --- a/platform/util/src/com/intellij/CommonBundle.java +++ b/platform/util/src/com/intellij/CommonBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -43,8 +43,7 @@ public class CommonBundle extends BundleBase { @NotNull private static ResourceBundle getCommonBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/util/src/com/intellij/openapi/util/JDOMUtil.java b/platform/util/src/com/intellij/openapi/util/JDOMUtil.java index 665776f71e24..7a429f82dec1 100644 --- a/platform/util/src/com/intellij/openapi/util/JDOMUtil.java +++ b/platform/util/src/com/intellij/openapi/util/JDOMUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -315,7 +315,7 @@ public class JDOMUtil { private static SAXBuilder getSaxBuilder() { SoftReference reference = ourSaxBuilder.get(); - SAXBuilder saxBuilder = reference != null ? reference.get() : null; + SAXBuilder saxBuilder = com.intellij.reference.SoftReference.dereference(reference); if (saxBuilder == null) { saxBuilder = new SAXBuilder(); saxBuilder.setEntityResolver(new EntityResolver() { diff --git a/platform/util/src/com/intellij/openapi/util/registry/Registry.java b/platform/util/src/com/intellij/openapi/util/registry/Registry.java index 0b86055bf5a9..e418e553fb6b 100644 --- a/platform/util/src/com/intellij/openapi/util/registry/Registry.java +++ b/platform/util/src/com/intellij/openapi/util/registry/Registry.java @@ -91,8 +91,7 @@ public class Registry { } static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(REGISTRY_BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/util/src/com/intellij/openapi/wm/FocusWatcher.java b/platform/util/src/com/intellij/openapi/wm/FocusWatcher.java index f3f522be330b..d8b774b30400 100644 --- a/platform/util/src/com/intellij/openapi/wm/FocusWatcher.java +++ b/platform/util/src/com/intellij/openapi/wm/FocusWatcher.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.wm; +import com.intellij.reference.SoftReference; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -111,11 +112,11 @@ public class FocusWatcher implements ContainerListener,FocusListener{ * @return last focused component or null. */ public final Component getFocusedComponent(){ - return myFocusedComponent != null ? myFocusedComponent.get() : null; + return SoftReference.dereference(myFocusedComponent); } public final Component getNearestFocusableComponent() { - return myNearestFocusableComponent != null ? myNearestFocusableComponent.get() : null; + return SoftReference.dereference(myNearestFocusableComponent); } public final void install(@NotNull Component component){ diff --git a/platform/util/src/com/intellij/ui/UIBundle.java b/platform/util/src/com/intellij/ui/UIBundle.java index 4d63e4b387e9..b2381649a424 100644 --- a/platform/util/src/com/intellij/ui/UIBundle.java +++ b/platform/util/src/com/intellij/ui/UIBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -36,8 +36,7 @@ public class UIBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/util/src/com/intellij/util/containers/SoftFactoryMap.java b/platform/util/src/com/intellij/util/containers/SoftFactoryMap.java index 17ba065ea122..3a620a8f4210 100644 --- a/platform/util/src/com/intellij/util/containers/SoftFactoryMap.java +++ b/platform/util/src/com/intellij/util/containers/SoftFactoryMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -31,17 +31,15 @@ public abstract class SoftFactoryMap { public final V get(T key) { final SoftReference reference = myMap.get(key); - if (reference != null) { - final V v = reference.get(); - if (v != null) { - return v == NULL ? null : v; - } + final V v = com.intellij.reference.SoftReference.dereference(reference); + if (v != null) { + return v == NULL ? null : v; } final V value = create(key); SoftReference valueRef = new SoftReference(value == null ? (V)NULL : value); SoftReference prevRef = myMap.putIfAbsent(key, valueRef); - V prev = prevRef == null ? null : prevRef.get(); + V prev = com.intellij.reference.SoftReference.dereference(prevRef); return prev == null || prev == NULL ? value : prev; } diff --git a/platform/util/src/com/intellij/util/containers/SoftKeySoftValueHashMap.java b/platform/util/src/com/intellij/util/containers/SoftKeySoftValueHashMap.java index f5398d564106..076ecd7ede50 100644 --- a/platform/util/src/com/intellij/util/containers/SoftKeySoftValueHashMap.java +++ b/platform/util/src/com/intellij/util/containers/SoftKeySoftValueHashMap.java @@ -50,8 +50,7 @@ public final class SoftKeySoftValueHashMap implements Map{ @Override public V get(Object key) { MyValueReference ref = mySoftKeyMap.get(key); - if (ref == null) return null; - return ref.get(); + return com.intellij.reference.SoftReference.dereference(ref); } @Override @@ -60,14 +59,14 @@ public final class SoftKeySoftValueHashMap implements Map{ SoftHashMap.Key softKey = mySoftKeyMap.createKey(key); MyValueReference reference = new MyValueReference(softKey, value, myQueue); MyValueReference oldRef = mySoftKeyMap.putKey(softKey, reference); - return oldRef == null ? null : oldRef.get(); + return com.intellij.reference.SoftReference.dereference(oldRef); } @Override public V remove(Object key) { processQueue(); MyValueReference ref = mySoftKeyMap.remove(key); - return ref != null ? ref.get() : null; + return com.intellij.reference.SoftReference.dereference(ref); } @Override diff --git a/platform/util/src/com/intellij/util/containers/UnsafeWeakList.java b/platform/util/src/com/intellij/util/containers/UnsafeWeakList.java index d2b71e23043e..7be7ad63ff4f 100644 --- a/platform/util/src/com/intellij/util/containers/UnsafeWeakList.java +++ b/platform/util/src/com/intellij/util/containers/UnsafeWeakList.java @@ -16,6 +16,7 @@ package com.intellij.util.containers; import com.intellij.openapi.util.Condition; +import com.intellij.reference.SoftReference; import com.intellij.util.Function; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; @@ -159,8 +160,7 @@ public class UnsafeWeakList extends AbstractList { nextElement = null; nextIndex = -1; for (int i= curIndex +1; i reference = myList.get(i); - T t = reference == null ? null : reference.get(); + T t = SoftReference.dereference(myList.get(i)); if (t != null) { nextElement = t; nextIndex = i; @@ -194,8 +194,7 @@ public class UnsafeWeakList extends AbstractList { public boolean remove(@NotNull Object o) { processQueue(); for (int i = 0; i < myList.size(); i++) { - MyReference reference = myList.get(i); - T t = reference == null ? null : reference.get(); + T t = SoftReference.dereference(myList.get(i)); if (t != null && t.equals(o)) { nullizeAt(i); return true; @@ -219,10 +218,10 @@ public class UnsafeWeakList extends AbstractList { private static final Function, Object> DEREF = new Function, Object>() { @Override public Object fun(MyReference reference) { - return reference == null ? null : reference.get(); + return SoftReference.dereference(reference); } }; - private static Function, T> deref() { + private static Function, X> deref() { return (Function)DEREF; } @NotNull @@ -250,7 +249,7 @@ public class UnsafeWeakList extends AbstractList { private static final Condition> NOT_NULL = new Condition>() { @Override public boolean value(MyReference reference) { - return reference != null && reference.get() != null; + return SoftReference.dereference(reference) != null; } }; diff --git a/platform/util/src/com/intellij/util/containers/WeakFactoryMap.java b/platform/util/src/com/intellij/util/containers/WeakFactoryMap.java index 2df74cd24c94..eee100e9781f 100644 --- a/platform/util/src/com/intellij/util/containers/WeakFactoryMap.java +++ b/platform/util/src/com/intellij/util/containers/WeakFactoryMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -15,6 +15,8 @@ */ package com.intellij.util.containers; +import com.intellij.reference.SoftReference; + import java.lang.ref.WeakReference; import java.util.concurrent.ConcurrentMap; @@ -30,17 +32,15 @@ public abstract class WeakFactoryMap { public final V get(T key) { final WeakReference reference = myMap.get(key); - if (reference != null) { - final V v = reference.get(); - if (v != null) { - return v == NULL ? null : v; - } + final V v = SoftReference.dereference(reference); + if (v != null) { + return v == NULL ? null : v; } final V value = create(key); WeakReference valueRef = new WeakReference(value == null ? (V)NULL : value); WeakReference prevRef = myMap.putIfAbsent(key, valueRef); - V prev = prevRef == null ? null : prevRef.get(); + V prev = SoftReference.dereference(prevRef); return prev == null || prev == NULL ? value : prev; } diff --git a/platform/util/src/com/intellij/util/containers/WeakKeyWeakValueHashMap.java b/platform/util/src/com/intellij/util/containers/WeakKeyWeakValueHashMap.java index 84eacc1fbea1..ed0e0019517d 100644 --- a/platform/util/src/com/intellij/util/containers/WeakKeyWeakValueHashMap.java +++ b/platform/util/src/com/intellij/util/containers/WeakKeyWeakValueHashMap.java @@ -15,6 +15,7 @@ */ package com.intellij.util.containers; +import com.intellij.reference.SoftReference; import org.jetbrains.annotations.NotNull; import java.lang.ref.ReferenceQueue; @@ -50,8 +51,7 @@ public final class WeakKeyWeakValueHashMap implements Map{ @Override public V get(Object key) { MyValueReference ref = myWeakKeyMap.get(key); - if (ref == null) return null; - return ref.get(); + return SoftReference.dereference(ref); } @Override @@ -60,14 +60,14 @@ public final class WeakKeyWeakValueHashMap implements Map{ WeakHashMap.Key weakKey = myWeakKeyMap.createKey(key); MyValueReference reference = new MyValueReference(weakKey, value, myQueue); MyValueReference oldRef = myWeakKeyMap.putKey(weakKey, reference); - return oldRef == null ? null : oldRef.get(); + return SoftReference.dereference(oldRef); } @Override public V remove(Object key) { processQueue(); MyValueReference ref = myWeakKeyMap.remove(key); - return ref != null ? ref.get() : null; + return SoftReference.dereference(ref); } @Override diff --git a/platform/util/src/com/intellij/util/containers/WeakValueIntObjectHashMap.java b/platform/util/src/com/intellij/util/containers/WeakValueIntObjectHashMap.java index e58460a92faf..b3731e286015 100644 --- a/platform/util/src/com/intellij/util/containers/WeakValueIntObjectHashMap.java +++ b/platform/util/src/com/intellij/util/containers/WeakValueIntObjectHashMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -15,6 +15,7 @@ */ package com.intellij.util.containers; +import com.intellij.reference.SoftReference; import gnu.trove.TIntObjectHashMap; import org.jetbrains.annotations.NotNull; @@ -56,8 +57,7 @@ public class WeakValueIntObjectHashMap { public final V get(int key) { MyReference ref = myMap.get(key); - if (ref == null) return null; - return ref.get(); + return SoftReference.dereference(ref); } public final V put(int key, @NotNull V value) { @@ -65,13 +65,13 @@ public class WeakValueIntObjectHashMap { MyReference ref = new MyReference(key, value, myQueue); ref.name = value.toString(); MyReference oldRef = myMap.put(key, ref); - return oldRef != null ? oldRef.get() : null; + return SoftReference.dereference(oldRef); } public final V remove(int key) { processQueue(); MyReference ref = myMap.remove(key); - return ref != null ? ref.get() : null; + return SoftReference.dereference(ref); } public final void clear() { diff --git a/platform/util/src/com/intellij/util/io/IOUtil.java b/platform/util/src/com/intellij/util/io/IOUtil.java index c10f04a78dba..625b1e693b10 100644 --- a/platform/util/src/com/intellij/util/io/IOUtil.java +++ b/platform/util/src/com/intellij/util/io/IOUtil.java @@ -18,6 +18,7 @@ package com.intellij.util.io; import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.CharsetToolkit; +import com.intellij.reference.SoftReference; import com.intellij.util.SystemProperties; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -113,6 +114,8 @@ public class IOUtil { } public static final Charset US_ASCII = Charset.forName("US-ASCII"); + private static final ThreadLocal> spareBufferLocal = new ThreadLocal>(); + public static String readUTFFast(@NotNull byte[] buffer, @NotNull DataInput storage) throws IOException { int len = 0xFF & (int)storage.readByte(); if (len == 0xFF) { @@ -126,7 +129,15 @@ public class IOUtil { if (len == 0) return ""; storage.readFully(buffer, 0, len); - return new String(buffer, 0, len, US_ASCII); + + SoftReference reference = spareBufferLocal.get(); + char[] chars = reference != null ? reference.get() : null; + if (chars == null) { + chars = new char[STRING_LENGTH_THRESHOLD]; + spareBufferLocal.set(new SoftReference(chars)); + } + for(int i = 0; i < len; ++i) chars[i] = (char)(buffer[i] &0xFF); + return new String(chars, 0, len); } public static boolean isAscii(@NotNull String str) { diff --git a/platform/util/src/com/intellij/util/lang/JarLoader.java b/platform/util/src/com/intellij/util/lang/JarLoader.java index 72323c111dbe..8f3937eafd0d 100644 --- a/platform/util/src/com/intellij/util/lang/JarLoader.java +++ b/platform/util/src/com/intellij/util/lang/JarLoader.java @@ -147,12 +147,10 @@ class JarLoader extends Loader { @Nullable Resource getResource(String name, boolean flag) { final long started = myDebugTime ? System.nanoTime():0; - if (myMemoryLoader != null) { - JarMemoryLoader loader = myMemoryLoader.get(); - if (loader != null) { - Resource resource = loader.getResource(name); - if (resource != null) return resource; - } + JarMemoryLoader loader = com.intellij.reference.SoftReference.dereference(myMemoryLoader); + if (loader != null) { + Resource resource = loader.getResource(name); + if (resource != null) return resource; } ZipFile file = null; try { diff --git a/platform/util/src/com/intellij/util/xmlb/XmlSerializerImpl.java b/platform/util/src/com/intellij/util/xmlb/XmlSerializerImpl.java index 49b4e8ac653d..5f5f62221b4f 100644 --- a/platform/util/src/com/intellij/util/xmlb/XmlSerializerImpl.java +++ b/platform/util/src/com/intellij/util/xmlb/XmlSerializerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -88,8 +88,7 @@ class XmlSerializerImpl { } private static Map, Binding> getBindingCacheMap() { - SoftReference, Binding>> ref = ourBindings; - Map, Binding> map = ref == null ? null : ref.get(); + Map, Binding> map = com.intellij.reference.SoftReference.dereference(ourBindings); if (map == null) { map = new ConcurrentHashMap, Binding>(); ourBindings = new SoftReference, Binding>>(map); diff --git a/platform/util/testSrc/com/intellij/util/containers/WeakListTest.java b/platform/util/testSrc/com/intellij/util/containers/WeakListTest.java index 70aa78e09224..9fe0140cbea3 100644 --- a/platform/util/testSrc/com/intellij/util/containers/WeakListTest.java +++ b/platform/util/testSrc/com/intellij/util/containers/WeakListTest.java @@ -33,17 +33,25 @@ public class WeakListTest extends TestCase { myHolder.add(element); } + private static final String HARD_REFERENCED = "xxx"; public void testCompresses() { for (int i = 0; i < 20; i++) { addElement(new Object()); } assertEquals(20, myWeakList.listSize()); - String obj = "xxx"; - addElement(obj); + addElement(HARD_REFERENCED); + assertEquals(21, myWeakList.listSize()); myHolder.clear(); - gc(); - myWeakList.remove(new Object()); // invoke processQueue() - //obj is held here in the codeblock + while (myWeakList.toStrongList().size() == 21) { + synchronized (myWeakList) { + gc(); + } + } + synchronized (myWeakList) { + boolean processed = myWeakList.processQueue(); + assertTrue(processed); // some refs must be in the queue + } + //HARD_REFERENCED is held there assertEquals(1, myWeakList.listSize()); } @@ -166,13 +174,13 @@ public class WeakListTest extends TestCase { iterator.next(); fail("must not allow to next"); } - catch (NoSuchElementException e) { + catch (NoSuchElementException ignored) { } try { iterator.remove(); fail("must not allow to remove"); } - catch (NoSuchElementException e) { + catch (NoSuchElementException ignored) { } } @@ -189,7 +197,11 @@ public class WeakListTest extends TestCase { gc(); assertEquals(N + 1 + N, myWeakList.listSize()); myHolder.clear(); - gc(); + while (myWeakList.toStrongList().size() == N + 1 + N) { + synchronized (myWeakList) { + gc(); + } + } boolean removed = myWeakList.remove("zzz"); assertFalse(removed); assertEquals(1, myWeakList.listSize()); diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/impl/ContentRevisionCache.java b/platform/vcs-api/src/com/intellij/openapi/vcs/impl/ContentRevisionCache.java index e3ab8d9d5491..3dd5cdfeacf3 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/impl/ContentRevisionCache.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/impl/ContentRevisionCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -175,7 +175,7 @@ public class ContentRevisionCache { public byte[] getBytes(FilePath path, VcsRevisionNumber number, @NotNull VcsKey vcsKey, @NotNull UniqueType type) { synchronized (myLock) { final SoftReference reference = myCache.get(new Key(path, number, vcsKey, type)); - return reference != null ? reference.get() : null; + return SoftReference.dereference(reference); } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/ShowUpdatedDiffAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/ShowUpdatedDiffAction.java index 87f37fc968cb..d6158c594e4f 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/ShowUpdatedDiffAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/ShowUpdatedDiffAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -151,11 +151,9 @@ public class ShowUpdatedDiffAction extends AnAction implements DumbAware { } public String getContent() throws VcsException { - if (myContent != null) { - final String s = myContent.get(); - if (s != null) { - return s; - } + final String s = com.intellij.reference.SoftReference.dereference(myContent); + if (s != null) { + return s; } final String loaded = myLoader.convert(myPointer); diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/DetailsPanel.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/DetailsPanel.java index 1cd7398fd877..15cb9f6bf220 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/DetailsPanel.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/DetailsPanel.java @@ -149,6 +149,7 @@ class DetailsPanel extends JPanel implements ListSelectionListener { setEditable(false); myProject = project; addHyperlinkListener(new BrowserHyperlinkListener()); + setOpaque(false); } void setData(@Nullable VcsFullCommitDetails commit) { diff --git a/platform/xdebugger-api/src/com/intellij/xdebugger/XDebuggerBundle.java b/platform/xdebugger-api/src/com/intellij/xdebugger/XDebuggerBundle.java index c1bfe06b7b3f..8242c6dfdd49 100644 --- a/platform/xdebugger-api/src/com/intellij/xdebugger/XDebuggerBundle.java +++ b/platform/xdebugger-api/src/com/intellij/xdebugger/XDebuggerBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class XDebuggerBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java index 05027048b80e..ca8ac443e70b 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java @@ -17,12 +17,8 @@ package com.intellij.xdebugger.impl.ui; import com.intellij.codeInsight.hint.HintUtil; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.LogicalPosition; -import com.intellij.openapi.editor.impl.DocumentImpl; -import com.intellij.openapi.fileTypes.FileTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.Balloon; import com.intellij.openapi.ui.popup.JBPopupFactory; @@ -35,7 +31,6 @@ import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.openapi.wm.WindowManager; import com.intellij.ui.AppUIUtil; import com.intellij.ui.EditorTextField; -import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.awt.RelativePoint; import com.intellij.xdebugger.XDebuggerManager; import com.intellij.xdebugger.breakpoints.XBreakpoint; @@ -105,28 +100,21 @@ public class DebuggerUIUtil { } public static void showValuePopup(@NotNull XFullValueEvaluator text, @NotNull MouseEvent event, @NotNull Project project) { - Document document = EditorFactory.getInstance().createDocument("Evaluating..."); - if (document instanceof DocumentImpl) { - ((DocumentImpl)document).setAcceptSlashR(true); - } - - EditorTextField textArea = new EditorTextField(document, project, FileTypes.PLAIN_TEXT, true); + EditorTextField textArea = new TextViewer("Evaluating...", project); textArea.setBackground(HintUtil.INFORMATION_COLOR); final FullValueEvaluationCallbackImpl callback = new FullValueEvaluationCallbackImpl(textArea); text.startEvaluation(callback); - final JScrollPane component = ScrollPaneFactory.createScrollPane(textArea); final Dimension frameSize = WindowManager.getInstance().getFrame(project).getSize(); Dimension size = DimensionService.getInstance().getSize(FULL_VALUE_POPUP_DIMENSION_KEY, project); if (size == null) { size = new Dimension(frameSize.width / 2, frameSize.height / 2); } - component.setPreferredSize(size); - component.setBorder(null); + textArea.setPreferredSize(size); - JBPopupFactory.getInstance().createComponentPopupBuilder(component, null) + JBPopupFactory.getInstance().createComponentPopupBuilder(textArea, null) .setResizable(true) .setMovable(true) .setDimensionServiceKey(project, FULL_VALUE_POPUP_DIMENSION_KEY, false) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/TextViewer.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/TextViewer.java new file mode 100644 index 000000000000..bd43d870c2d5 --- /dev/null +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/TextViewer.java @@ -0,0 +1,49 @@ +package com.intellij.xdebugger.impl.ui; + +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.EditorFactory; +import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.openapi.editor.impl.DocumentImpl; +import com.intellij.openapi.fileTypes.FileTypes; +import com.intellij.openapi.project.Project; +import com.intellij.ui.EditorTextField; +import org.jetbrains.annotations.NotNull; + +public final class TextViewer extends EditorTextField { + private final boolean myEmbeddedIntoDialogWrapper; + private final boolean myUseSoftWraps; + + public TextViewer(@NotNull Project project, boolean embeddedIntoDialogWrapper, boolean useSoftWraps) { + this(createDocument(""), project, embeddedIntoDialogWrapper, useSoftWraps); + } + + public TextViewer(@NotNull String initialText, @NotNull Project project) { + this(createDocument(initialText), project, false, false); + } + + public TextViewer(@NotNull Document document, @NotNull Project project, boolean embeddedIntoDialogWrapper, boolean useSoftWraps) { + super(document, project, FileTypes.PLAIN_TEXT, true, false); + + myEmbeddedIntoDialogWrapper = embeddedIntoDialogWrapper; + myUseSoftWraps = useSoftWraps; + } + + private static Document createDocument(@NotNull String initialText) { + final Document document = EditorFactory.getInstance().createDocument(initialText); + if (document instanceof DocumentImpl) { + ((DocumentImpl)document).setAcceptSlashR(true); + } + return document; + } + + @Override + protected EditorEx createEditor() { + final EditorEx editor = super.createEditor(); + editor.setHorizontalScrollbarVisible(true); + editor.setVerticalScrollbarVisible(true); + editor.setEmbeddedIntoDialogWrapper(myEmbeddedIntoDialogWrapper); + editor.getComponent().setPreferredSize(null); + editor.getSettings().setUseSoftWraps(myUseSoftWraps); + return editor; + } +} \ No newline at end of file diff --git a/plugins/IdeaTestAssistant/src/com/intellij/testAssistant/TestDataGroupFileEditor.java b/plugins/IdeaTestAssistant/src/com/intellij/testAssistant/TestDataGroupFileEditor.java index f690d969e658..3dcdb5e0ecfd 100644 --- a/plugins/IdeaTestAssistant/src/com/intellij/testAssistant/TestDataGroupFileEditor.java +++ b/plugins/IdeaTestAssistant/src/com/intellij/testAssistant/TestDataGroupFileEditor.java @@ -25,6 +25,7 @@ import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Splitter; import com.intellij.openapi.util.UserDataHolderBase; +import com.intellij.reference.SoftReference; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -49,12 +50,7 @@ public class TestDataGroupFileEditor extends UserDataHolderBase implements FileE @NotNull public JComponent getComponent() { - JComponent result; - if (myComponent == null) { - myComponent = new WeakReference(result = createComponent()); - return result; - } - result = myComponent.get(); + JComponent result = SoftReference.dereference(myComponent); if (result == null) { myComponent = new WeakReference(result = createComponent()); } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.java index 2b655e4a8bfb..ebc18f2b498a 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class InspectionGadgetsBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/VariableNotUsedInsideIfInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/VariableNotUsedInsideIfInspection.java index bae56e94b550..658835629bcf 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/VariableNotUsedInsideIfInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/VariableNotUsedInsideIfInspection.java @@ -17,6 +17,7 @@ package com.siyeh.ig.bugs; import com.intellij.psi.*; import com.intellij.psi.tree.IElementType; +import com.intellij.psi.util.PsiUtil; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; @@ -56,7 +57,7 @@ public class VariableNotUsedInsideIfInspection extends BaseInspection { @Override public void visitConditionalExpression(PsiConditionalExpression expression) { super.visitConditionalExpression(expression); - final PsiExpression condition = expression.getCondition(); + final PsiExpression condition = PsiUtil.skipParenthesizedExprDown(expression.getCondition()); if (!(condition instanceof PsiBinaryExpression)) { return; } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/ProblematicVarargsMethodOverrideInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/ProblematicVarargsMethodOverrideInspection.java index bf121ff8c08a..c9605e7f2518 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/ProblematicVarargsMethodOverrideInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/ProblematicVarargsMethodOverrideInspection.java @@ -66,7 +66,7 @@ public class ProblematicVarargsMethodOverrideInspection extends BaseInspection { } final PsiParameter parameter = parameters[parameters.length - 1]; final PsiType type = parameter.getType(); - if (!(type instanceof PsiArrayType)) { + if (!(type instanceof PsiArrayType) || type instanceof PsiEllipsisType) { return; } final PsiMethod[] superMethods = method.findDeepestSuperMethods(); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/LoggerInitializedWithForeignClassInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/LoggerInitializedWithForeignClassInspectionBase.java index 5a70933d865b..a862e90a966b 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/LoggerInitializedWithForeignClassInspectionBase.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/LoggerInitializedWithForeignClassInspectionBase.java @@ -73,7 +73,7 @@ public class LoggerInitializedWithForeignClassInspectionBase extends BaseInspect super.readSettings(element); parseString(loggerClassName, loggerFactoryClassNames); parseString(loggerFactoryMethodName, loggerFactoryMethodNames); - if (loggerFactoryClassNames.size() != loggerFactoryMethodNames.size()) { + if (loggerFactoryClassNames.size() != loggerFactoryMethodNames.size() || loggerFactoryClassNames.isEmpty()) { parseString(DEFAULT_LOGGER_CLASS_NAMES, loggerFactoryClassNames); parseString(DEFAULT_FACTORY_METHOD_NAMES, loggerFactoryMethodNames); } diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/AssignmentToSuperclassField.html b/plugins/InspectionGadgets/src/inspectionDescriptions/AssignmentToSuperclassField.html index c9708f2437c8..186e523f4e59 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/AssignmentToSuperclassField.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/AssignmentToSuperclassField.html @@ -4,6 +4,6 @@ Reports any assignments to fields from a superclass from within a constructor. I superclass to initialize the fields.

-New in 12.1 +New in 13 \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassInitializer.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ClassInitializer.html index 45c5f81d1805..e3f57a89a5cd 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassInitializer.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ClassInitializer.html @@ -5,9 +5,10 @@ in classes. Some coding standards prohibit instance initializers, preferring ini in constructors or field initializers. Non-static initializers may also be inadvertently created by deleting the static keyword, resulting in obscure bugs. +This inspection does not warn on instance initializers in anonymous classes.

-Use the checkbox below to have this inspection ignore instance initializers in classes which do not have constructors. +Use the checkbox below to ignore instance initializers in classes which do not have any constructors.

diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/PlaceholderCountMatchesArgumentCount.html b/plugins/InspectionGadgets/src/inspectionDescriptions/PlaceholderCountMatchesArgumentCount.html index aaa60cd4e395..11af3ae7d689 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/PlaceholderCountMatchesArgumentCount.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/PlaceholderCountMatchesArgumentCount.html @@ -4,6 +4,6 @@ Reports SLF4J logging calls where the number of {}-placeholders in the string co does not match the number of other arguments to the logging call.

-New in 12.1 +New in 13 \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/variable_not_used_inside_if/VariableNotUsedInsideIf.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/variable_not_used_inside_if/VariableNotUsedInsideIf.java index c6d13025555d..33925cea2eec 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/variable_not_used_inside_if/VariableNotUsedInsideIf.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/variable_not_used_inside_if/VariableNotUsedInsideIf.java @@ -61,4 +61,9 @@ public class VariableNotUsedInsideIf { private int someValue() { return 0; } + + void perenthesis(String[] args) + { + String message = (args == null) ? "not null" : "null"; + } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/variable_not_used_inside_if/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/variable_not_used_inside_if/expected.xml index 603a54209ebd..c3a2f7643220 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/variable_not_used_inside_if/expected.xml +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/variable_not_used_inside_if/expected.xml @@ -41,4 +41,12 @@ Reference checked for 'null' is not used inside 'if' <code>x</code> checked for 'null' is not used inside conditional #loc + + + VariableNotUsedInsideIf.java + 67 + Reference checked for 'null' is not used inside 'if' + <code>args</code> checked for 'null' is not used inside conditional #loc + + \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/packaging/disjoint_package/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/packaging/disjoint_package/expected.xml new file mode 100644 index 000000000000..e8f00e82629f --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/packaging/disjoint_package/expected.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/packaging/disjoint_package/extends_implements_reference/Ferrari.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/packaging/disjoint_package/extends_implements_reference/Ferrari.java new file mode 100644 index 000000000000..7bbeb16c20ef --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/packaging/disjoint_package/extends_implements_reference/Ferrari.java @@ -0,0 +1,8 @@ +package extends_implements_reference; + +public class Ferrari implements Car { + public void start() {} +} +interface Car { + void start(); +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/ProblematicVarargsMethodOverrideInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/ProblematicVarargsMethodOverrideInspectionTest.java index 46ec84b1c9fb..036feda6492d 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/ProblematicVarargsMethodOverrideInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/ProblematicVarargsMethodOverrideInspectionTest.java @@ -34,6 +34,17 @@ public class ProblematicVarargsMethodOverrideInspectionTest extends LightInspect "}"); } + public void testVarargsOverriding() { + doTest("class One {" + + " void m(String... ss) {" + + " }" + + "}" + + "class Two extends One {" + + " void m(String... ss) {" + + " }" + + "}"); + } + @Override protected InspectionProfileEntry getInspection() { return new ProblematicVarargsMethodOverrideInspection(); diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/packaging/DisjointPackageInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/packaging/DisjointPackageInspectionTest.java new file mode 100644 index 000000000000..93c53b504337 --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/packaging/DisjointPackageInspectionTest.java @@ -0,0 +1,29 @@ +/* + * Copyright 2000-2013 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.siyeh.ig.packaging; + +import com.siyeh.ig.IGInspectionTestCase; + +/** + * @author Bas Leijdekkers + */ +public class DisjointPackageInspectionTest extends IGInspectionTestCase { + + public void test() { + doTest("com/siyeh/igtest/packaging/disjoint_package", new DisjointPackageInspection(), false, true); + } + +} diff --git a/plugins/IntentionPowerPak/src/com/siyeh/IntentionPowerPackBundle.java b/plugins/IntentionPowerPak/src/com/siyeh/IntentionPowerPackBundle.java index 4c930f86d46b..7a7e23cfe4f2 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/IntentionPowerPackBundle.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/IntentionPowerPackBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -43,8 +43,7 @@ public class IntentionPowerPackBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/ant/src/com/intellij/lang/ant/AntBundle.java b/plugins/ant/src/com/intellij/lang/ant/AntBundle.java index 552e5172ff7c..a0821abe4bf2 100644 --- a/plugins/ant/src/com/intellij/lang/ant/AntBundle.java +++ b/plugins/ant/src/com/intellij/lang/ant/AntBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -37,8 +37,7 @@ public class AntBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/ant/src/com/intellij/lang/ant/config/execution/ExecutionHandler.java b/plugins/ant/src/com/intellij/lang/ant/config/execution/ExecutionHandler.java index 87972fd50e81..3efff18aa441 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/execution/ExecutionHandler.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/execution/ExecutionHandler.java @@ -106,12 +106,10 @@ public final class ExecutionHandler { } } - final boolean startInBackground = buildFile.isRunInBackground(); - new Task.Backgroundable(buildFile.getProject(), AntBundle.message("ant.build.progress.dialog.title"), true) { public boolean shouldStartInBackground() { - return startInBackground; + return true; } public void run(@NotNull final ProgressIndicator indicator) { diff --git a/plugins/ant/src/com/intellij/lang/ant/resources/AntActionsBundle.java b/plugins/ant/src/com/intellij/lang/ant/resources/AntActionsBundle.java index 33872e16b50f..f42ec62f253b 100644 --- a/plugins/ant/src/com/intellij/lang/ant/resources/AntActionsBundle.java +++ b/plugins/ant/src/com/intellij/lang/ant/resources/AntActionsBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -46,8 +46,7 @@ public final class AntActionsBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(IDEA_ACTIONS_BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/cvs/cvs-core/src/com/intellij/CvsBundle.java b/plugins/cvs/cvs-core/src/com/intellij/CvsBundle.java index 21ada03b88f8..b1ad597f9b6c 100644 --- a/plugins/cvs/cvs-core/src/com/intellij/CvsBundle.java +++ b/plugins/cvs/cvs-core/src/com/intellij/CvsBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -69,8 +69,7 @@ public class CvsBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE_NAME); ourBundle = new SoftReference(bundle); diff --git a/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/JavaCvsSrcBundle.java b/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/JavaCvsSrcBundle.java index 69a92928f383..8e5ea9159077 100644 --- a/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/JavaCvsSrcBundle.java +++ b/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/JavaCvsSrcBundle.java @@ -1,5 +1,17 @@ /* - * Copyright (c) 2005 JetBrains s.r.o. All Rights Reserved. + * Copyright 2000-2013 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.netbeans.lib.cvsclient; @@ -27,8 +39,7 @@ public class JavaCvsSrcBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/cvs/smartcvs-src/org/netbeans/lib/cvsclient/SmartCvsSrcBundle.java b/plugins/cvs/smartcvs-src/org/netbeans/lib/cvsclient/SmartCvsSrcBundle.java index f0c28fe6cfe5..93b1d78f1ccd 100644 --- a/plugins/cvs/smartcvs-src/org/netbeans/lib/cvsclient/SmartCvsSrcBundle.java +++ b/plugins/cvs/smartcvs-src/org/netbeans/lib/cvsclient/SmartCvsSrcBundle.java @@ -1,5 +1,17 @@ /* - * Copyright (c) 2005 JetBrains s.r.o. All Rights Reserved. + * Copyright 2000-2013 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.netbeans.lib.cvsclient; @@ -27,8 +39,7 @@ public class SmartCvsSrcBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/devkit/src/DevKitBundle.java b/plugins/devkit/src/DevKitBundle.java index d507273905be..a08cb196e0ce 100644 --- a/plugins/devkit/src/DevKitBundle.java +++ b/plugins/devkit/src/DevKitBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -40,8 +40,7 @@ public class DevKitBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/eclipse/src/org/jetbrains/idea/eclipse/EclipseBundle.java b/plugins/eclipse/src/org/jetbrains/idea/eclipse/EclipseBundle.java index d3c9174d2f4f..dfcc1a4bc699 100644 --- a/plugins/eclipse/src/org/jetbrains/idea/eclipse/EclipseBundle.java +++ b/plugins/eclipse/src/org/jetbrains/idea/eclipse/EclipseBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -37,8 +37,7 @@ public class EclipseBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/git4idea/rt/src/org/jetbrains/git4idea/ssh/SSHMainBundle.java b/plugins/git4idea/rt/src/org/jetbrains/git4idea/ssh/SSHMainBundle.java index 507d1fc52919..17c90a0c9526 100644 --- a/plugins/git4idea/rt/src/org/jetbrains/git4idea/ssh/SSHMainBundle.java +++ b/plugins/git4idea/rt/src/org/jetbrains/git4idea/ssh/SSHMainBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class SSHMainBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/git4idea/src/git4idea/i18n/GitBundle.java b/plugins/git4idea/src/git4idea/i18n/GitBundle.java index eb9d41941eb7..701adf6e2bc8 100644 --- a/plugins/git4idea/src/git4idea/i18n/GitBundle.java +++ b/plugins/git4idea/src/git4idea/i18n/GitBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -52,8 +52,7 @@ public class GitBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/gradle/resources/i18n/GradleBundle.properties b/plugins/gradle/resources/i18n/GradleBundle.properties index 1447b37baeb6..254b5a99333c 100644 --- a/plugins/gradle/resources/i18n/GradleBundle.properties +++ b/plugins/gradle/resources/i18n/GradleBundle.properties @@ -23,6 +23,9 @@ gradle.notifications.use.distribution.with.sources=You can configure Gradle wrap It will provide IDE with Gradle API/DSL documentation. gradle.notifications.hide.tip=Hide the tip gradle.notifications.apply.suggestion=Ok, apply suggestion! +gradle.notifications.unlinked.project.found.title=Unlinked Gradle project? +gradle.notifications.unlinked.project.found.msg=Import Gradle project, this will also enable Gradle Tool Window. +gradle.notifications.do.not.show=Don't want to see the message for the project again: press here. gradle.codeInsight.action.apply_plugin.text=Add gradle plugin gradle.codeInsight.action.apply_plugin.description=Add selected gradle plugin to the project diff --git a/plugins/gradle/src/META-INF/plugin.xml b/plugins/gradle/src/META-INF/plugin.xml index 93e9448c7745..9e7f9285bbb4 100644 --- a/plugins/gradle/src/META-INF/plugin.xml +++ b/plugins/gradle/src/META-INF/plugin.xml @@ -25,6 +25,13 @@ com.intellij.javaee org.jetbrains.idea.maven + + + org.jetbrains.plugins.gradle.service.project.GradleProjectComponent + + + + @@ -46,7 +53,7 @@ - + @@ -69,6 +76,7 @@ + diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/codeInspection/GradleInspectionBundle.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/codeInspection/GradleInspectionBundle.java index 9602b1d2e58f..9bb1b6e5a0d9 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/codeInspection/GradleInspectionBundle.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/codeInspection/GradleInspectionBundle.java @@ -39,13 +39,11 @@ public class GradleInspectionBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); - ourBundle = new SoftReference(bundle); + ourBundle = new SoftReference(bundle); } return bundle; } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleNotification.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleNotification.java new file mode 100644 index 000000000000..32f37d1b615c --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleNotification.java @@ -0,0 +1,69 @@ +/* + * Copyright 2000-2013 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.gradle.service.project; + +import com.intellij.notification.Notification; +import com.intellij.notification.NotificationGroup; +import com.intellij.notification.NotificationListener; +import com.intellij.notification.NotificationType; +import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.project.Project; +import com.intellij.ui.AppUIUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Vladislav.Soroka + * @since 12/10/13 + */ +public class GradleNotification { + private static final NotificationGroup NOTIFICATION_GROUP = NotificationGroup.balloonGroup("Gradle Notification Group"); + + @Nullable private Notification myNotification; + @NotNull private final Project myProject; + + @NotNull + public static GradleNotification getInstance(@NotNull Project project) { + return ServiceManager.getService(project, GradleNotification.class); + } + + public GradleNotification(@NotNull Project project) { + myProject = project; + } + + public void showBalloon(@NotNull final String title, + @NotNull final String message, + @NotNull final NotificationType type, + @Nullable final NotificationListener listener) { + Runnable notificationTask = new Runnable() { + @Override + public void run() { + if (!myProject.isDisposed() && myProject.isOpen()) { + Notification notification = NOTIFICATION_GROUP.createNotification(title, message, type, listener); + Notification old = myNotification; + if (old != null && old.getContent().equals(notification.getContent())) { + old.expire(); + } + myNotification = notification; + notification.notify(myProject); + } + } + }; + + AppUIUtil.invokeLaterIfProjectAlive(myProject, notificationTask); + } +} + diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectComponent.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectComponent.java new file mode 100644 index 000000000000..4446dad08bb9 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectComponent.java @@ -0,0 +1,101 @@ +/* + * Copyright 2000-2013 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.gradle.service.project; + +import com.intellij.ide.actions.ImportModuleAction; +import com.intellij.ide.util.PropertiesComponent; +import com.intellij.ide.util.newProjectWizard.AddModuleWizard; +import com.intellij.notification.Notification; +import com.intellij.notification.NotificationListener; +import com.intellij.notification.NotificationType; +import com.intellij.openapi.components.AbstractProjectComponent; +import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VfsUtilCore; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.gradle.service.project.wizard.GradleProjectImportBuilder; +import org.jetbrains.plugins.gradle.service.project.wizard.GradleProjectImportProvider; +import org.jetbrains.plugins.gradle.settings.GradleSettings; +import org.jetbrains.plugins.gradle.util.GradleBundle; +import org.jetbrains.plugins.gradle.util.GradleConstants; + +import javax.swing.event.HyperlinkEvent; +import java.io.File; +import java.io.FilenameFilter; + +/** + * @author Vladislav.Soroka + * @since 12/10/13 + */ +public class GradleProjectComponent extends AbstractProjectComponent { + + @NonNls private static final String SHOW_UNLINKED_GRADLE_POPUP = "show.inlinked.gradle.project.popup"; + private static final String IMPORT_EVENT_DESCRIPTION = "import"; + private static final String DO_NOT_SHOW_EVENT_DESCRIPTION = "do.not.show"; + + protected GradleProjectComponent(Project project) { + super(project); + } + + @Override + public void projectOpened() { + showNotificationForUnlinkedGradleProject(); + } + + private void showNotificationForUnlinkedGradleProject() { + if (!PropertiesComponent.getInstance(myProject).getBoolean(SHOW_UNLINKED_GRADLE_POPUP, true) + || !GradleSettings.getInstance(myProject).getLinkedProjectsSettings().isEmpty()) { + return; + } + + File baseDir = VfsUtilCore.virtualToIoFile(myProject.getBaseDir()); + final File[] files = baseDir.listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return GradleConstants.DEFAULT_SCRIPT_NAME.equals(name); + } + }); + + if (files != null && files.length != 0) { + String message = String.format("%s
\n%s", + GradleBundle.message("gradle.notifications.unlinked.project.found.msg", IMPORT_EVENT_DESCRIPTION), + GradleBundle.message("gradle.notifications.do.not.show", DO_NOT_SHOW_EVENT_DESCRIPTION)); + + GradleNotification.getInstance(myProject).showBalloon( + GradleBundle.message("gradle.notifications.unlinked.project.found.title"), + message, NotificationType.INFORMATION, new NotificationListener.Adapter() { + @Override + protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) { + if (IMPORT_EVENT_DESCRIPTION.equals(e.getDescription())) { + final ProjectDataManager projectDataManager = ServiceManager.getService(ProjectDataManager.class); + GradleProjectImportBuilder gradleProjectImportBuilder = new GradleProjectImportBuilder(projectDataManager); + final GradleProjectImportProvider gradleProjectImportProvider = new GradleProjectImportProvider(gradleProjectImportBuilder); + AddModuleWizard wizard = new AddModuleWizard(null, files[0].getPath(), gradleProjectImportProvider); + if ((wizard.getStepCount() <= 0 || wizard.showAndGet())) { + ImportModuleAction.createFromWizard(myProject, wizard); + } + } + else if (DO_NOT_SHOW_EVENT_DESCRIPTION.equals(e.getDescription())) { + PropertiesComponent.getInstance(myProject).setValue(SHOW_UNLINKED_GRADLE_POPUP, Boolean.FALSE.toString()); + } + } + } + ); + } + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/util/GradleDocumentationBundle.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/util/GradleDocumentationBundle.java index 4751d60475bf..c38e3946f1ce 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/util/GradleDocumentationBundle.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/util/GradleDocumentationBundle.java @@ -31,7 +31,7 @@ public class GradleDocumentationBundle extends AbstractBundle { public static final String PATH_TO_BUNDLE = "i18n.GradleDocumentationBundle"; private static final GradleDocumentationBundle BUNDLE = new GradleDocumentationBundle(); - private static Reference myBundle; + private static Reference ourBundle; public GradleDocumentationBundle() { super(PATH_TO_BUNDLE); @@ -46,13 +46,10 @@ public class GradleDocumentationBundle extends AbstractBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (myBundle != null) { - bundle = myBundle.get(); - } + ResourceBundle bundle = SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); - myBundle = new SoftReference(bundle); + ourBundle = new SoftReference(bundle); } return bundle; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.java index d2f8ba7f27ce..75b5306f149f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -41,9 +41,7 @@ public class GroovyBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/GroovyCodeInsightBundle.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/GroovyCodeInsightBundle.java index 615e0be4d482..4627bc381f60 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/GroovyCodeInsightBundle.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/GroovyCodeInsightBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,13 +39,11 @@ public class GroovyCodeInsightBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); - ourBundle = new SoftReference(bundle); + ourBundle = new SoftReference(bundle); } return bundle; } 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 136839183d14..cea5b5bc0b6c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java @@ -399,7 +399,9 @@ public class GroovyAnnotator extends GroovyElementVisitor { private static void checkSameNameMethodsWithDifferentAccessModifiers(AnnotationHolder holder, GrMethod[] methods) { MultiMap map = MultiMap.create(); for (GrMethod method : methods) { - map.putValue(method.getName(), method); + if (!method.isConstructor()) { + map.putValue(method.getName(), method); + } } for (Map.Entry> entry : map.entrySet()) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/GroovyInspectionBundle.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/GroovyInspectionBundle.java index 552c29125a3b..9493104433bd 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/GroovyInspectionBundle.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/GroovyInspectionBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,13 +39,11 @@ public class GroovyInspectionBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); - ourBundle = new SoftReference(bundle); + ourBundle = new SoftReference(bundle); } return bundle; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/doc/GroovyDocBundle.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/doc/GroovyDocBundle.java index b0d8df166be7..198cbbbd2a45 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/doc/GroovyDocBundle.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/doc/GroovyDocBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -36,9 +36,7 @@ public class GroovyDocBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/CustomMembersGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/CustomMembersGenerator.java index b35fb5a0f03b..8f9958b2a024 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/CustomMembersGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/CustomMembersGenerator.java @@ -23,6 +23,7 @@ import com.intellij.psi.scope.PsiScopeProcessor; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.FList; import groovy.lang.Closure; import groovy.lang.GroovyObjectSupport; import groovy.lang.MetaMethod; @@ -53,7 +54,7 @@ public class CustomMembersGenerator extends GroovyObjectSupport implements GdslM private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.dsl.CustomMembersGenerator"); private static final GdslMembersProvider[] PROVIDERS = GdslMembersProvider.EP_NAME.getExtensions(); public static final String THROWS = "throws"; - private final List myDeclarations = ContainerUtil.newArrayList(); + private FList myDeclarations = FList.emptyList(); private final Project myProject; private final CompoundMembersHolder myDepot = new CompoundMembersHolder(); private final GroovyClassDescriptor myDescriptor; @@ -101,7 +102,8 @@ public class CustomMembersGenerator extends GroovyObjectSupport implements GdslM addMemberHolder(new CustomMembersHolder() { @Override public boolean processMembers(GroovyClassDescriptor descriptor, PsiScopeProcessor processor, ResolveState state) { - return NonCodeMembersHolder.generateMembers(myDeclarations, descriptor.justGetPlaceFile()).processMembers(descriptor, processor, state); + return NonCodeMembersHolder.generateMembers(ContainerUtil.reverse(myDeclarations), descriptor.justGetPlaceFile()).processMembers( + descriptor, processor, state); } }); } @@ -166,9 +168,10 @@ public class CustomMembersGenerator extends GroovyObjectSupport implements GdslM public void method(Map args) { if (args == null) return; + args = ContainerUtil.newLinkedHashMap(args); parseMethod(args); args.put("declarationType", DeclarationType.METHOD); - myDeclarations.add(args); + myDeclarations = myDeclarations.prepend(args); } public void methodCall(Closure> generator) { @@ -253,23 +256,25 @@ public class CustomMembersGenerator extends GroovyObjectSupport implements GdslM public void closureInMethod(Map args) { if (args == null) return; + args = ContainerUtil.newLinkedHashMap(args); parseMethod(args); final Object method = args.get("method"); if (method instanceof Map) { parseMethod((Map)method); } args.put("declarationType", DeclarationType.CLOSURE); - myDeclarations.add(args); + myDeclarations = myDeclarations.prepend(args); } public void variable(Map args) { if (args == null) return; + args = ContainerUtil.newLinkedHashMap(args); parseVariable(args); - myDeclarations.add(args); + myDeclarations = myDeclarations.prepend(args); } - private void parseVariable(Map args) { + private static void parseVariable(Map args) { String type = stringifyType(args.get("type")); args.put("type", type); args.put("declarationType", DeclarationType.VARIABLE); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java index 73d9621b769e..a1eb90dd510e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java @@ -343,8 +343,7 @@ public class GroovyDslFileIndex extends ScalarIndexExtension { @Nullable private static List> derefStandardScripts() { - SoftReference>> ref = ourStandardScripts; - return ref == null ? null : ref.get(); + return SoftReference.dereference(ourStandardScripts); } private static List> getStandardScripts() { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/GroovyImportHelper.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/GroovyImportHelper.java index 2b0dc1febe0d..d6a3214072f7 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/GroovyImportHelper.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/GroovyImportHelper.java @@ -23,6 +23,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase; import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement; +import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager; import org.jetbrains.plugins.groovy.lang.resolve.DefaultImportContributor; import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil; @@ -106,8 +107,9 @@ public class GroovyImportHelper { } } + GroovyPsiManager groovyPsiManager = GroovyPsiManager.getInstance(file.getProject()); for (String implicitlyImportedClass : GroovyFileBase.IMPLICITLY_IMPORTED_CLASSES) { - PsiClass clazz = facade.findClass(implicitlyImportedClass, file.getResolveScope()); + PsiClass clazz = groovyPsiManager.findClassWithCache(implicitlyImportedClass, file.getResolveScope()); if (clazz != null && !ResolveUtil.processElement(processor, clazz, state)) return false; } return true; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle.java index 64b47c72fb35..93b0b0fe825f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,9 +39,7 @@ public class GroovyIntentionsBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyFileBaseImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyFileBaseImpl.java index 9641abfae28a..679b6edaa6b0 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyFileBaseImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyFileBaseImpl.java @@ -243,8 +243,7 @@ public abstract class GroovyFileBaseImpl extends PsiFileBase implements GroovyFi public Instruction[] getControlFlow() { assert isValid(); - SoftReference flow = myControlFlow; - Instruction[] result = flow != null ? flow.get() : null; + Instruction[] result = SoftReference.dereference(myControlFlow); if (result == null) { result = new ControlFlowBuilder(getProject()).buildControlFlow(this); myControlFlow = new SoftReference(result); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiManager.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiManager.java index d1822bb83b07..96e232dc87e5 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiManager.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiManager.java @@ -36,6 +36,7 @@ import com.intellij.util.Function; import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.*; import com.intellij.util.messages.MessageBusConnection; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; @@ -186,7 +187,49 @@ public class GroovyPsiManager { } - private static final PsiType UNKNOWN_TYPE = new PsiPrimitiveType("unknown type", PsiAnnotation.EMPTY_ARRAY); + private static final PsiType UNKNOWN_TYPE = new PsiType(PsiAnnotation.EMPTY_ARRAY) { + @Override + public String getPresentableText() { + return null; + } + + @Override + public String getCanonicalText() { + return null; + } + + @Override + public String getInternalCanonicalText() { + return null; + } + + @Override + public boolean isValid() { + return true; + } + + @Override + public boolean equalsToText(@NonNls String text) { + return false; + } + + @Override + public A accept(@NotNull PsiTypeVisitor visitor) { + return null; + } + + @Nullable + @Override + public GlobalSearchScope getResolveScope() { + return null; + } + + @NotNull + @Override + public PsiType[] getSuperTypes() { + return PsiType.EMPTY_ARRAY; + } + }; @Nullable public PsiType getType(@NotNull T element, @NotNull Function calculator) { PsiType type = myCalculatedTypes.get(element); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/PsiImplUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/PsiImplUtil.java index 1fe5e6fa06e8..ba2f35c09fb5 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/PsiImplUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/PsiImplUtil.java @@ -582,7 +582,7 @@ public class PsiImplUtil { if (block == null) return null; final SoftReference ref = block.getUserData(PSI_CODE_BLOCK); - final PsiCodeBlock body = ref == null ? null : ref.get(); + final PsiCodeBlock body = SoftReference.dereference(ref); if (body != null) return body; final GrSyntheticCodeBlock newBody = new GrSyntheticCodeBlock(block); block.putUserData(PSI_CODE_BLOCK, new SoftReference(newBody)); @@ -593,7 +593,7 @@ public class PsiImplUtil { if (typeElement == null) return null; final SoftReference ref = typeElement.getUserData(PSI_TYPE_ELEMENT); - final PsiTypeElement element = ref == null ? null : ref.get(); + final PsiTypeElement element = SoftReference.dereference(ref); if (element != null) return element; final GrSyntheticTypeElement newTypeElement = new GrSyntheticTypeElement(typeElement); typeElement.putUserData(PSI_TYPE_ELEMENT, new SoftReference(newTypeElement)); @@ -604,7 +604,7 @@ public class PsiImplUtil { if (expr == null) return null; final SoftReference ref = expr.getUserData(PSI_EXPRESSION); - final PsiExpression element = ref == null ? null : ref.get(); + final PsiExpression element = SoftReference.dereference(ref); if (element != null) return element; final GrSyntheticExpression newExpr = new GrSyntheticExpression(expr); expr.putUserData(PSI_EXPRESSION, new SoftReference(newExpr)); @@ -615,7 +615,7 @@ public class PsiImplUtil { if (list == null) return null; final SoftReference ref = list.getUserData(PSI_REFERENCE_LIST); - final PsiReferenceList element = ref == null ? null : ref.get(); + final PsiReferenceList element = SoftReference.dereference(ref); if (element != null) return element; final GrSyntheticReferenceList newList = new GrSyntheticReferenceList(list, role); list.putUserData(PSI_REFERENCE_LIST, new SoftReference(newList)); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/GrAnonymousClassDefinitionImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/GrAnonymousClassDefinitionImpl.java index aa7876a19db6..2ff2a006a4de 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/GrAnonymousClassDefinitionImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/GrAnonymousClassDefinitionImpl.java @@ -106,8 +106,7 @@ public class GrAnonymousClassDefinitionImpl extends GrTypeDefinitionImpl impleme return createClassType(); } - PsiClassType type = null; - if (myCachedBaseType != null) type = myCachedBaseType.get(); + PsiClassType type = SoftReference.dereference(myCachedBaseType); if (type != null && type.isValid()) return type; type = createClassType(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrMethodWrapper.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrMethodWrapper.java index b850b44bcf3b..cab5fb9accba 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrMethodWrapper.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrMethodWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -17,14 +17,59 @@ package org.jetbrains.plugins.groovy.lang.psi.impl.synthetic; import com.intellij.codeInsight.completion.originInfo.OriginInfoAwareElement; import com.intellij.psi.*; +import com.intellij.psi.search.GlobalSearchScope; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author Sergey Evdokimov */ public class GrMethodWrapper extends GrLightMethodBuilder { - private static PsiType TYPE_MARKER = new PsiPrimitiveType("xxx", PsiAnnotation.EMPTY_ARRAY); + private static final PsiType TYPE_MARKER = new PsiType(PsiAnnotation.EMPTY_ARRAY) { + @Override + public String getPresentableText() { + return null; + } + + @Override + public String getCanonicalText() { + return null; + } + + @Override + public String getInternalCanonicalText() { + return null; + } + + @Override + public boolean isValid() { + return false; + } + + @Override + public boolean equalsToText(@NonNls String text) { + return false; + } + + @Override + public A accept(@NotNull PsiTypeVisitor visitor) { + return null; + } + + @Nullable + @Override + public GlobalSearchScope getResolveScope() { + return null; + } + + @NotNull + @Override + public PsiType[] getSuperTypes() { + return EMPTY_ARRAY; + } + }; private volatile boolean myNavigationElementInit; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrSyntheticCodeBlock.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrSyntheticCodeBlock.java index e0344e8fbf36..2b925cf36dad 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrSyntheticCodeBlock.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrSyntheticCodeBlock.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -84,7 +84,7 @@ public class GrSyntheticCodeBlock extends LightElement implements PsiCodeBlock { if (element == null) return null; final SoftReference ref = element.getUserData(PSI_JAVA_TOKEN); - final PsiJavaToken token = ref == null ? null : ref.get(); + final PsiJavaToken token = SoftReference.dereference(ref); if (token != null) return token; final LightJavaToken newToken = new LightJavaToken(element, type); element.putUserData(PSI_JAVA_TOKEN, new SoftReference(newToken)); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/toplevel/imports/GrImportStatementImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/toplevel/imports/GrImportStatementImpl.java index 6e51ce64ef82..761cbeb31b6c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/toplevel/imports/GrImportStatementImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/toplevel/imports/GrImportStatementImpl.java @@ -99,14 +99,13 @@ public class GrImportStatementImpl extends GrStubElementBase kinds = kind == CLASS ? ResolverProcessor.RESOLVE_KINDS_CLASS : - ResolverProcessor.RESOLVE_KINDS_CLASS_PACKAGE; + case CLASS: { + EnumSet kinds = kind == CLASS ? ResolverProcessor.RESOLVE_KINDS_CLASS : ResolverProcessor.RESOLVE_KINDS_CLASS_PACKAGE; ResolverProcessor processor = new ClassResolverProcessor(refName, ref, kinds); GrCodeReferenceElement qualifier = ref.getQualifier(); if (qualifier != null) { @@ -529,6 +527,21 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl { } public GrAnnotation getPsiElement() { - if (myPsiRef != null) { - final GrAnnotation annotation = myPsiRef.get(); - if (annotation != null) { - return annotation; - } + GrAnnotation annotation = SoftReference.dereference(myPsiRef); + if (annotation != null) { + return annotation; } try { - GrAnnotation annotation = GroovyPsiElementFactory.getInstance(getProject()).createAnnotationFromText(myText, getPsi()); + annotation = GroovyPsiElementFactory.getInstance(getProject()).createAnnotationFromText(myText, getPsi()); myPsiRef = new SoftReference(annotation); return annotation; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringBundle.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringBundle.java index ab4d5876241d..ad5c5e9a1571 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringBundle.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -41,9 +41,7 @@ public class GroovyRefactoringBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyScriptRunner.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyScriptRunner.java index 33e32242a226..f4457d9bc8c2 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyScriptRunner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyScriptRunner.java @@ -103,9 +103,7 @@ public abstract class GroovyScriptRunner { protected static VirtualFile findGroovyJar(@NotNull Module module) { final VirtualFile[] files = OrderEnumerator.orderEntries(module).getAllLibrariesAndSdkClassesRoots(); for (VirtualFile root : files) { - if (root.getName().matches(GroovyConfigUtils.GROOVY_JAR_PATTERN) - || GroovyConfigUtils.matchesGroovyAll(root.getName())) - { + if (GroovyConfigUtils.GROOVY_JAR_PATTERN.matcher(root.getName()).matches() || GroovyConfigUtils.matchesGroovyAll(root.getName())) { return root; } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy index e5692615da6c..87f7ba7e73ae 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy @@ -1704,6 +1704,11 @@ class E { private foo(){} def foo(int x) {} } + +class Z { + private Z() {} //correct + private Z(x) {} //correct +} ''') } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveClassTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveClassTest.groovy index 2092272b3647..485f91eaeeac 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveClassTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveClassTest.groovy @@ -306,5 +306,93 @@ public interface OuterInterface { ''', PsiClass) } + void testCollisionOfClassAndPackage() { + myFixture.addFileToProject('foo/Bar.groovy', '''\ +package foo + +class Bar { + static void xyz(){} +} +''') + def ref = configureByText('foo.groovy', '''\ +import foo.Bar + +print new Bar() +''') + + assertNotNull(ref.resolve()) + } + + void testCollisionOfClassAndPackage2() { + myFixture.addFileToProject('foo/Bar.groovy', '''\ +package foo + +class Bar { + static void xyz(){} +} +''') + def ref = configureByText('foo.groovy', '''\ +import static foo.Bar.xyz + +class foo { + public static void main(args) { + xyz() //should resolve to inner class + } + + static class Bar { + static void xyz() {} + } +} +''') + + PsiElement resolved = ref.resolve() + assertInstanceOf(resolved, PsiMethod) + + PsiClass clazz = resolved.containingClass + assertNotNull(clazz.containingClass) + } + + + void testCollisionOfClassAndPackage3() { + myFixture.addFileToProject('foo/Bar.groovy', '''\ +package foo + +class Bar { + static void xyz(){} +} +''') + def ref = configureByText('foo.groovy', '''\ +import static foo.Bar.xyz + +xyz() +''') + + assertNotNull(ref.resolve()) + } + + void testCollisionOfClassAndPackage4() { + myFixture.addFileToProject('foo/Bar.groovy', '''\ +package foo + +class Bar { + static void xyz(){} +} +''') + + def ref = configureByText('foo.groovy', '''\ +import static foo.Bar.xyz + +class foo { + public static void main(String[] args) { + xyz() + } +} +''') + + PsiElement resolved = ref.resolve() + assertInstanceOf(resolved, PsiMethod) + } + + private void doTest(String fileName = getTestName(false) + ".groovy") { resolve(fileName, PsiClass) } } diff --git a/plugins/groovy/testdata/refactoring/move/moveClass/staticImport/after/p2/C1.groovy b/plugins/groovy/testdata/refactoring/move/moveClass/staticImport/after/p2/C1.groovy index 6edb22916242..c07883e50e86 100644 --- a/plugins/groovy/testdata/refactoring/move/moveClass/staticImport/after/p2/C1.groovy +++ b/plugins/groovy/testdata/refactoring/move/moveClass/staticImport/after/p2/C1.groovy @@ -1,6 +1,6 @@ package p2 -import static C1.E.e +import static p2.C1.E.e class C1 { def foo() { diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcsMessages.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcsMessages.java index 2ad3893b62bd..27a7234ea72a 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcsMessages.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcsMessages.java @@ -34,10 +34,7 @@ public final class HgVcsMessages { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) { - bundle = ourBundle.get(); - } + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenDomBundle.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenDomBundle.java index 52849f6a60c4..f980dce4573e 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenDomBundle.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenDomBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -37,8 +37,7 @@ public class MavenDomBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/IndicesBundle.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/IndicesBundle.java index 524e18dc8e47..60560940078a 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/IndicesBundle.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/IndicesBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -37,8 +37,7 @@ public class IndicesBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/ProjectBundle.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/ProjectBundle.java index c4f5241d800b..1bf7a9a43cbb 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/ProjectBundle.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/ProjectBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -37,8 +37,7 @@ public class ProjectBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/TasksBundle.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/TasksBundle.java index 3fbe42200a1b..f0b1f38c0771 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/TasksBundle.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/TasksBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -37,8 +37,7 @@ public class TasksBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/properties/src/com/intellij/lang/properties/PropertiesBundle.java b/plugins/properties/src/com/intellij/lang/properties/PropertiesBundle.java index 56e69d4984f1..e766152be274 100644 --- a/plugins/properties/src/com/intellij/lang/properties/PropertiesBundle.java +++ b/plugins/properties/src/com/intellij/lang/properties/PropertiesBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -36,8 +36,7 @@ public class PropertiesBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.java index d74e63803a51..7e2ff1e86cbe 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -40,8 +40,7 @@ public class SvnBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/ui-designer-core/src/com/intellij/designer/DesignerBundle.java b/plugins/ui-designer-core/src/com/intellij/designer/DesignerBundle.java index fe7f687d0a08..691276ca2f96 100644 --- a/plugins/ui-designer-core/src/com/intellij/designer/DesignerBundle.java +++ b/plugins/ui-designer-core/src/com/intellij/designer/DesignerBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,10 +39,7 @@ public class DesignerBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) { - bundle = ourBundle.get(); - } + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/ui-designer-core/src/com/intellij/designer/componentTree/AttributeWrapper.java b/plugins/ui-designer-core/src/com/intellij/designer/componentTree/AttributeWrapper.java index 7214a6df438b..34bb3aa70ee6 100644 --- a/plugins/ui-designer-core/src/com/intellij/designer/componentTree/AttributeWrapper.java +++ b/plugins/ui-designer-core/src/com/intellij/designer/componentTree/AttributeWrapper.java @@ -28,5 +28,12 @@ public interface AttributeWrapper { } }; + AttributeWrapper REGULAR = new AttributeWrapper() { + @Override + public SimpleTextAttributes getAttribute(SimpleTextAttributes attributes) { + return SimpleTextAttributes.REGULAR_ATTRIBUTES; + } + }; + SimpleTextAttributes getAttribute(SimpleTextAttributes attributes); } \ No newline at end of file diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/UIDesignerBundle.java b/plugins/ui-designer/src/com/intellij/uiDesigner/UIDesignerBundle.java index 4afcef39ef76..0984ae126847 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/UIDesignerBundle.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/UIDesignerBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -39,8 +39,7 @@ public class UIDesignerBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/CachedGridImage.java b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/CachedGridImage.java index e570bdb49eb5..a2982780d463 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/CachedGridImage.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/CachedGridImage.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -188,12 +188,9 @@ public class CachedGridImage { } public static Image getGridImage(final RadContainer container) { - CachedGridImage gridImage = null; //noinspection unchecked SoftReference imageRef = (SoftReference) container.getDelegee().getClientProperty(CACHED_GRID_IMAGE_KEY); - if (imageRef != null) { - gridImage = imageRef.get(); - } + CachedGridImage gridImage = SoftReference.dereference(imageRef); if (gridImage != null && gridImage.sizeEquals(container)) { gridImage.update(container); } diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/XsltDocumentationProvider.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/XsltDocumentationProvider.java index 6158699b9435..9a7493e17639 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/XsltDocumentationProvider.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/XsltDocumentationProvider.java @@ -169,8 +169,8 @@ public class XsltDocumentationProvider implements DocumentationProvider { } private Document getDocumentationDocument() throws IOException, JDOMException { - Document d; - if (myDocument == null || ((d = myDocument.get()) == null)) { + Document d = com.intellij.reference.SoftReference.dereference(myDocument); + if (d == null) { d = new SAXBuilder().build(XsltSupport.class.getResource("resources/documentation.xml")); myDocument = new SoftReference(d); } @@ -178,8 +178,8 @@ public class XsltDocumentationProvider implements DocumentationProvider { } private Templates getTemplate() throws TransformerConfigurationException, IOException { - Templates t; - if (myTemplates == null || (t = myTemplates.get()) == null) { + Templates t = com.intellij.reference.SoftReference.dereference(myTemplates); + if (t == null) { t = TransformerFactory.newInstance().newTemplates(makeSource("resources/documentation.xsl")); myTemplates = new SoftReference(t); } diff --git a/plugins/xslt-debugger/src/org/intellij/plugins/xsltDebugger/ui/GeneratedStructureModel.java b/plugins/xslt-debugger/src/org/intellij/plugins/xsltDebugger/ui/GeneratedStructureModel.java index 20f1942ed60f..195ad1b5c693 100644 --- a/plugins/xslt-debugger/src/org/intellij/plugins/xsltDebugger/ui/GeneratedStructureModel.java +++ b/plugins/xslt-debugger/src/org/intellij/plugins/xsltDebugger/ui/GeneratedStructureModel.java @@ -18,10 +18,10 @@ package org.intellij.plugins.xsltDebugger.ui; import com.intellij.ide.DataManager; import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.pom.Navigatable; +import com.intellij.reference.SoftReference; import com.intellij.util.SmartList; import com.intellij.util.containers.StringInterner; import org.intellij.plugins.xsltDebugger.XsltDebuggerSession; @@ -59,8 +59,8 @@ public class GeneratedStructureModel extends DefaultTreeModel { // all instances (and their toolwindow contents) are gone. This should minimize the memory usage of the generated // structure tree. private static StringInterner getInterner() { - StringInterner interner; - if (ourSharedInterner == null || (interner = ourSharedInterner.get()) == null) { + StringInterner interner = SoftReference.dereference(ourSharedInterner); + if (interner == null) { interner = new StringInterner(); ourSharedInterner = new WeakReference(interner); } diff --git a/python/helpers/pydev/pydev_console_utils.py b/python/helpers/pydev/pydev_console_utils.py index 4676da3c3120..54a85850c48f 100644 --- a/python/helpers/pydev/pydev_console_utils.py +++ b/python/helpers/pydev/pydev_console_utils.py @@ -4,6 +4,7 @@ import sys import traceback from pydevd_constants import USE_LIB_COPY +from pydevd_constants import IS_JYTHON try: if USE_LIB_COPY: @@ -156,7 +157,7 @@ class BaseInterpreterInterface: if hasattr(self.interpreter, 'is_complete'): return not self.interpreter.is_complete(source) try: - code = self.interpreter.compile(source, "", "exec") + code = self.interpreter.compile(source, '', 'exec') except (OverflowError, SyntaxError, ValueError): # Case 1 return False @@ -173,7 +174,7 @@ class BaseInterpreterInterface: else: self.buffer.append(code_fragment) - return self.needMoreForCode(code_fragment.text) + return self.needMoreForCode(self.buffer.text) def addExec(self, code_fragment): original_in = sys.stdin @@ -208,7 +209,7 @@ class BaseInterpreterInterface: self._input_error_printed = True sys.stderr.write('\nError when trying to update pydoc.help.input\n') sys.stderr.write('(help() may not work -- please report this as a bug in the pydev bugtracker).\n\n') - import traceback; + import traceback traceback.print_exc() @@ -320,7 +321,11 @@ class BaseInterpreterInterface: try: code_fragment = CodeFragment(code, is_single_line) more = self.needMore(code_fragment) - self.exec_queue.put(code_fragment) + if not more: + code_fragment = self.buffer + self.buffer = None + self.exec_queue.put(code_fragment) + return more except: traceback.print_exc() @@ -331,7 +336,11 @@ class BaseInterpreterInterface: def execMultipleLines(self, lines): - return self.doExecCode(lines, False) + if IS_JYTHON: + for line in lines.split('\n'): + self.doExecCode(line, True) + else: + return self.doExecCode(lines, False) def interrupt(self): diff --git a/python/helpers/pydev/pydev_monkey.py b/python/helpers/pydev/pydev_monkey.py index c5dd39a87870..8dd94ab1842d 100644 --- a/python/helpers/pydev/pydev_monkey.py +++ b/python/helpers/pydev/pydev_monkey.py @@ -100,8 +100,9 @@ def patch_arg_str_win(arg_str): args = str_to_args(new_arg_str) if not is_python(args[0]): return arg_str - art = args_to_str(patch_args(args)) - return art + arg_str = args_to_str(patch_args(args)) + pydev_log.debug("New args: %s"% arg_str) + return arg_str def monkey_patch_module(module, funcname, create_func): if hasattr(module, funcname): diff --git a/python/helpers/pydev/pydevconsole.py b/python/helpers/pydev/pydevconsole.py index a15fd83bc94c..e8b8d297ff0f 100644 --- a/python/helpers/pydev/pydevconsole.py +++ b/python/helpers/pydev/pydevconsole.py @@ -75,7 +75,7 @@ except ImportError: class Command: - def __init__(self, interpreter, code_fragment, buffer): + def __init__(self, interpreter, code_fragment): """ :type code_fragment: CodeFragment :type interpreter: InteractiveConsole @@ -83,24 +83,19 @@ class Command: self.interpreter = interpreter self.code_fragment = code_fragment self.more = None - self.buffer = buffer @staticmethod def symbol_for_fragment(code_fragment): - if IS_JYTHON or code_fragment.is_single_line: + if code_fragment.is_single_line: symbol = 'single' else: symbol = 'exec' # Jython doesn't support this return symbol def run(self): - if self.buffer is None: - text = self.code_fragment.text - symbol = self.symbol_for_fragment(self.code_fragment) - else: - text = self.buffer.text - symbol = self.symbol_for_fragment(self.buffer) - + text = self.code_fragment.text + symbol = self.symbol_for_fragment(self.code_fragment) + self.more = self.interpreter.runsource(text, '', symbol) try: @@ -133,7 +128,7 @@ class InterpreterInterface(BaseInterpreterInterface): def doAddExec(self, codeFragment): - command = Command(self.interpreter, codeFragment, self.buffer) + command = Command(self.interpreter, codeFragment) command.run() return command.more @@ -170,9 +165,6 @@ def process_exec_queue(interpreter): continue more = interpreter.addExec(codeFragment) - - if not more: - interpreter.buffer = None except KeyboardInterrupt: interpreter.buffer = None continue diff --git a/python/helpers/pydev/test_debug.py b/python/helpers/pydev/test_debug.py index 89051c80babf..bc55de16907d 100644 --- a/python/helpers/pydev/test_debug.py +++ b/python/helpers/pydev/test_debug.py @@ -1,16 +1,20 @@ __author__ = 'Dmitry.Trofimov' import unittest +import os + +test_data_path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..', 'python', 'testData', 'debug')) class PyDevTestCase(unittest.TestCase): def testZipFileExits(self): from pydevd_file_utils import exists - self.assertTrue(exists('../../../testData/debug/zipped_lib.zip/zipped_module.py')) - self.assertFalse(exists('../../../testData/debug/zipped_lib.zip/zipped_module2.py')) - self.assertFalse(exists('../../../testData/debug/zipped_lib2.zip/zipped_module.py')) + + self.assertTrue(exists(test_data_path +'/zipped_lib.zip/zipped_module.py')) + self.assertFalse(exists(test_data_path + '/zipped_lib.zip/zipped_module2.py')) + self.assertFalse(exists(test_data_path + '/zipped_lib2.zip/zipped_module.py')) def testEggFileExits(self): from pydevd_file_utils import exists - self.assertTrue(exists('../../../testData/debug/pycharm-debug.egg/pydev/pydevd.py')) - self.assertFalse(exists('../../../testData/debug/pycharm-debug.egg/pydev/pydevd2.py')) + self.assertTrue(exists(test_data_path + '/pycharm-debug.egg/pydev/pydevd.py')) + self.assertFalse(exists(test_data_path + '/pycharm-debug.egg/pydev/pydevd2.py')) diff --git a/python/rest/src/com/jetbrains/rest/RestBundle.java b/python/rest/src/com/jetbrains/rest/RestBundle.java index ed1b66328012..eacf64ed73b2 100644 --- a/python/rest/src/com/jetbrains/rest/RestBundle.java +++ b/python/rest/src/com/jetbrains/rest/RestBundle.java @@ -43,8 +43,7 @@ public class RestBundle { // Cached loading private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/python/src/com/jetbrains/python/PyBundle.java b/python/src/com/jetbrains/python/PyBundle.java index 3cb565d48b58..042973fafcf2 100644 --- a/python/src/com/jetbrains/python/PyBundle.java +++ b/python/src/com/jetbrains/python/PyBundle.java @@ -43,8 +43,7 @@ public class PyBundle { // Cached loading private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/python/src/com/jetbrains/python/codeInsight/controlflow/ControlFlowCache.java b/python/src/com/jetbrains/python/codeInsight/controlflow/ControlFlowCache.java index 02b70403c9ae..a8db9b68d87f 100644 --- a/python/src/com/jetbrains/python/codeInsight/controlflow/ControlFlowCache.java +++ b/python/src/com/jetbrains/python/codeInsight/controlflow/ControlFlowCache.java @@ -39,7 +39,7 @@ public class ControlFlowCache { public static ControlFlow getControlFlow(@NotNull ScopeOwner element) { SoftReference ref = element.getUserData(CONTROL_FLOW_KEY); - ControlFlow flow = ref != null ? ref.get() : null; + ControlFlow flow = SoftReference.dereference(ref); if (flow == null) { flow = new PyControlFlowBuilder().buildControlFlow(element); element.putUserData(CONTROL_FLOW_KEY, new SoftReference(flow)); @@ -50,7 +50,7 @@ public class ControlFlowCache { @NotNull public static Scope getScope(@NotNull ScopeOwner element) { SoftReference ref = element.getUserData(SCOPE_KEY); - Scope scope = ref != null ? ref.get() : null; + Scope scope = SoftReference.dereference(ref); if (scope == null) { scope = new ScopeImpl(element); element.putUserData(SCOPE_KEY, new SoftReference(scope)); diff --git a/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java b/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java index b04ff3b0ef82..6af6c133cd33 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java +++ b/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java @@ -281,6 +281,15 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl else { object = execute; } + Pair result = parseResult(object); + if (result.second) { + setExecuting(false); + } + + return result; + } + + private Pair parseResult(Object object) { if (object instanceof Boolean) { return new Pair(null, (Boolean)object); } diff --git a/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java b/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java index f16850e0ceeb..e3c589922bec 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java @@ -442,7 +442,7 @@ public class PyFileImpl extends PsiFileBase implements PyFile, PyExpression { private ExportedNameCache getExportedNameCache() { ExportedNameCache cache; synchronized (myENCLock) { - cache = myExportedNameCache != null ? myExportedNameCache.get() : null; + cache = SoftReference.dereference(myExportedNameCache); final long modificationStamp = getModificationStamp(); if (myExportedNameCache != null && cache != null && modificationStamp != cache.getModificationStamp()) { myExportedNameCache.clear(); diff --git a/python/src/com/jetbrains/python/psi/types/functionalParser/FunctionalParserBase.java b/python/src/com/jetbrains/python/psi/types/functionalParser/FunctionalParserBase.java index bde4559335d4..6d33b68284b9 100644 --- a/python/src/com/jetbrains/python/psi/types/functionalParser/FunctionalParserBase.java +++ b/python/src/com/jetbrains/python/psi/types/functionalParser/FunctionalParserBase.java @@ -203,11 +203,9 @@ public abstract class FunctionalParserBase implements FunctionalParser> ref = myCache.get(state.getPos()); - if (ref != null) { - final Pair cached = ref.get(); - if (cached != null) { - return cached; - } + final Pair cached = SoftReference.dereference(ref); + if (cached != null) { + return cached; } final Pair result = myParser.parse(tokens, state); myCache.put(state.getPos(), new SoftReference>(result)); diff --git a/python/src/com/jetbrains/python/sdk/PythonSdkType.java b/python/src/com/jetbrains/python/sdk/PythonSdkType.java index 65d808210ec6..6ce5abdcac9e 100644 --- a/python/src/com/jetbrains/python/sdk/PythonSdkType.java +++ b/python/src/com/jetbrains/python/sdk/PythonSdkType.java @@ -52,6 +52,7 @@ import com.intellij.openapi.util.text.CharFilter; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.*; import com.intellij.psi.PsiElement; +import com.intellij.reference.SoftReference; import com.intellij.remotesdk.RemoteSdkData; import com.intellij.remotesdk.RemoteSdkDataHolder; import com.intellij.ui.awt.RelativePoint; @@ -495,11 +496,8 @@ public class PythonSdkType extends SdkType { public void setupSdkPaths(@NotNull final Sdk sdk) { final Project project; - Component ownerComponent = null; final WeakReference ownerComponentRef = sdk.getUserData(SDK_CREATOR_COMPONENT_KEY); - if (ownerComponentRef != null) { - ownerComponent = ownerComponentRef.get(); - } + Component ownerComponent = SoftReference.dereference(ownerComponentRef); if (ownerComponent != null) { project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(ownerComponent)); } diff --git a/python/src/com/jetbrains/python/testing/PythonTestConfigurationProducer.java b/python/src/com/jetbrains/python/testing/PythonTestConfigurationProducer.java index 3875cd31ed5a..8c28e08d4833 100644 --- a/python/src/com/jetbrains/python/testing/PythonTestConfigurationProducer.java +++ b/python/src/com/jetbrains/python/testing/PythonTestConfigurationProducer.java @@ -18,6 +18,7 @@ package com.jetbrains.python.testing; import com.google.common.collect.Sets; import com.intellij.execution.Location; import com.intellij.execution.actions.ConfigurationContext; +import com.intellij.execution.actions.ConfigurationFromContext; import com.intellij.execution.actions.RunConfigurationProducer; import com.intellij.execution.configurations.ConfigurationFactory; import com.intellij.facet.Facet; @@ -39,6 +40,7 @@ import com.intellij.psi.util.PsiTreeUtil; import com.jetbrains.python.PythonModuleTypeBase; import com.jetbrains.python.facet.PythonFacetSettings; import com.jetbrains.python.psi.*; +import com.jetbrains.python.run.PythonRunConfigurationProducer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -254,4 +256,8 @@ abstract public class PythonTestConfigurationProducer extends RunConfigurationPr return PythonUnitTestUtil.getTestCaseClassesFromFile(pyFile); } + @Override + public boolean isPreferredConfiguration(ConfigurationFromContext self, ConfigurationFromContext other) { + return other.isProducedBy(PythonTestConfigurationProducer.class) || other.isProducedBy(PythonRunConfigurationProducer.class); + } } \ No newline at end of file diff --git a/python/src/com/jetbrains/python/testing/doctest/PythonDocTestConfigurationProducer.java b/python/src/com/jetbrains/python/testing/doctest/PythonDocTestConfigurationProducer.java index cfa2be7caee1..e3eef2958409 100644 --- a/python/src/com/jetbrains/python/testing/doctest/PythonDocTestConfigurationProducer.java +++ b/python/src/com/jetbrains/python/testing/doctest/PythonDocTestConfigurationProducer.java @@ -21,6 +21,8 @@ package com.jetbrains.python.testing.doctest; import com.intellij.execution.Location; import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiRecursiveElementVisitor; @@ -85,4 +87,10 @@ public class PythonDocTestConfigurationProducer extends PythonTestConfigurationP } } } + + @Override + protected boolean isTestFolder(@NotNull VirtualFile virtualFile, @NotNull Project project) { + return false; + } + } \ No newline at end of file diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/DomManagerImpl.java b/xml/dom-impl/src/com/intellij/util/xml/impl/DomManagerImpl.java index 083546e62288..b9a93e147291 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/DomManagerImpl.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/DomManagerImpl.java @@ -42,6 +42,7 @@ import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlElement; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; +import com.intellij.reference.SoftReference; import com.intellij.semantic.SemKey; import com.intellij.semantic.SemService; import com.intellij.util.EventDispatcher; @@ -372,7 +373,7 @@ public final class DomManagerImpl extends DomManager { @Nullable static DomFileElementImpl getCachedFileElement(@NotNull XmlFile file) { WeakReference ref = file.getUserData(CACHED_FILE_ELEMENT); - return ref == null ? null : ref.get(); + return SoftReference.dereference(ref); } @Nullable 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 fa95b8a4ccb7..96fbf46095e3 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 @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -138,7 +138,7 @@ public class DynamicGenericInfo extends DomGenericInfoEx { private static ChildrenDescriptionsHolder internChildrenHolder(XmlFile file, ChildrenDescriptionsHolder holder) { SoftReference> ref = file.getUserData(HOLDERS_CACHE); - ConcurrentHashMap cache = ref == null ? null : ref.get(); + ConcurrentHashMap cache = SoftReference.dereference(ref); if (cache == null) { cache = new ConcurrentHashMap(); file.putUserData(HOLDERS_CACHE, new SoftReference>(cache)); diff --git a/xml/dom-openapi/src/com/intellij/util/xml/DomBundle.java b/xml/dom-openapi/src/com/intellij/util/xml/DomBundle.java index b1379dc945cd..07a41223a74e 100644 --- a/xml/dom-openapi/src/com/intellij/util/xml/DomBundle.java +++ b/xml/dom-openapi/src/com/intellij/util/xml/DomBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -40,8 +40,7 @@ public class DomBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/xml/impl/src/com/intellij/ide/browsers/StartBrowserPanel.java b/xml/impl/src/com/intellij/ide/browsers/StartBrowserPanel.java index 7b8c39d1f436..fed8cdb950ba 100644 --- a/xml/impl/src/com/intellij/ide/browsers/StartBrowserPanel.java +++ b/xml/impl/src/com/intellij/ide/browsers/StartBrowserPanel.java @@ -3,6 +3,7 @@ package com.intellij.ide.browsers; import com.intellij.ide.DataManager; import com.intellij.ide.browsers.impl.WebBrowserServiceImpl; import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.fileChooser.FileChooserDescriptor; @@ -17,6 +18,7 @@ import com.intellij.psi.PsiBinaryFile; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.intellij.ui.AncestorListenerAdapter; +import com.intellij.util.Consumer; import com.intellij.util.Url; import com.intellij.util.io.URLUtil; import com.intellij.util.ui.UIUtil; @@ -45,9 +47,20 @@ public class StartBrowserPanel { myRoot.addAncestorListener(new AncestorListenerAdapter() { @Override public void ancestorAdded(AncestorEvent event) { - Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myUrlField)); - assert project != null; - setupUrlField(myUrlField, project); + Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myRoot)); + if (project == null) { + DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer() { + @Override + public void consume(DataContext context) { + Project project = CommonDataKeys.PROJECT.getData(context); + assert project != null; + setupUrlField(myUrlField, project); + } + }); + } + else { + setupUrlField(myUrlField, project); + } } }); } diff --git a/xml/tests/src/com/intellij/xml/index/XmlSchemaIndexTest.java b/xml/tests/src/com/intellij/xml/index/XmlSchemaIndexTest.java index b0a6380d9a92..1edf485aada6 100644 --- a/xml/tests/src/com/intellij/xml/index/XmlSchemaIndexTest.java +++ b/xml/tests/src/com/intellij/xml/index/XmlSchemaIndexTest.java @@ -94,14 +94,14 @@ public class XmlSchemaIndexTest extends CodeInsightFixtureTestCase { assertEquals(2, files.size()); IndexedRelevantResource - resource = XmlNamespaceIndex.guessSchema(NS, "web-app", "3.0", myModule); + resource = XmlNamespaceIndex.guessSchema(NS, "web-app", "3.0", myModule, getProject()); assertNotNull(resource); XsdNamespaceBuilder builder = resource.getValue(); assertEquals(NS, builder.getNamespace()); assertEquals("3.0", builder.getVersion()); assertEquals(Arrays.asList("web-app"), builder.getTags()); - resource = XmlNamespaceIndex.guessSchema(NS, "web-app", "2.5", myModule); + resource = XmlNamespaceIndex.guessSchema(NS, "web-app", "2.5", myModule, getProject()); assertNotNull(resource); builder = resource.getValue(); assertEquals(NS, builder.getNamespace()); diff --git a/xml/xml-psi-api/src/com/intellij/xml/XmlBundle.java b/xml/xml-psi-api/src/com/intellij/xml/XmlBundle.java index 5f5a7326bb5a..0abf03a3593f 100644 --- a/xml/xml-psi-api/src/com/intellij/xml/XmlBundle.java +++ b/xml/xml-psi-api/src/com/intellij/xml/XmlBundle.java @@ -39,8 +39,7 @@ public class XmlBundle { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/xml/xml-psi-impl/src/com/intellij/codeInsight/daemon/XmlErrorMessages.java b/xml/xml-psi-impl/src/com/intellij/codeInsight/daemon/XmlErrorMessages.java index 77d0c1ee4b3b..38dbb11f93e3 100644 --- a/xml/xml-psi-impl/src/com/intellij/codeInsight/daemon/XmlErrorMessages.java +++ b/xml/xml-psi-impl/src/com/intellij/codeInsight/daemon/XmlErrorMessages.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -41,8 +41,7 @@ public class XmlErrorMessages { } private static ResourceBundle getBundle() { - ResourceBundle bundle = null; - if (ourBundle != null) bundle = ourBundle.get(); + ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); ourBundle = new SoftReference(bundle); diff --git a/xml/xml-psi-impl/src/com/intellij/xml/impl/ExternalDocumentValidator.java b/xml/xml-psi-impl/src/com/intellij/xml/impl/ExternalDocumentValidator.java index ba7f346e7006..debb58ae0891 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/impl/ExternalDocumentValidator.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/impl/ExternalDocumentValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -104,8 +104,7 @@ public class ExternalDocumentValidator { file != null && myModificationStamp == file.getModificationStamp() && !ValidateXmlActionHandler.isValidationDependentFilesOutOfDate((XmlFile)file) && - myInfos!=null && - myInfos.get()!=null // we have validated before + SoftReference.dereference(myInfos)!=null // we have validated before ) { addAllInfos(host,myInfos.get()); return; @@ -375,7 +374,7 @@ public class ExternalDocumentValidator { if (!profile.isToolEnabled(HighlightDisplayKey.find(INSPECTION_SHORT_NAME), containingFile)) return; SoftReference validatorReference = project.getUserData(validatorInstanceKey); - ExternalDocumentValidator validator = validatorReference != null? validatorReference.get() : null; + ExternalDocumentValidator validator = SoftReference.dereference(validatorReference); if(validator == null) { validator = new ExternalDocumentValidator(); diff --git a/xml/xml-psi-impl/src/com/intellij/xml/index/IndexedRelevantResource.java b/xml/xml-psi-impl/src/com/intellij/xml/index/IndexedRelevantResource.java index 5b62a6a8f2fd..9005a94f76dc 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/index/IndexedRelevantResource.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/index/IndexedRelevantResource.java @@ -50,9 +50,7 @@ public class IndexedRelevantResource implements Compara FileBasedIndex.getInstance().processValues(indexId, key, null, new FileBasedIndex.ValueProcessor() { public boolean process(VirtualFile file, V value) { ResourceRelevance relevance = ResourceRelevance.getRelevance(file, module, fileIndex, additionalScope); - if (relevance != ResourceRelevance.NONE) { - resources.add(new IndexedRelevantResource(file, key, value, relevance)); - } + resources.add(new IndexedRelevantResource(file, key, value, relevance)); return true; } }, new AdditionalIndexedRootsScope(GlobalSearchScope.allScope(project))); diff --git a/xml/xml-psi-impl/src/com/intellij/xml/index/ResourceRelevance.java b/xml/xml-psi-impl/src/com/intellij/xml/index/ResourceRelevance.java index ffa06cde615d..a20842b79421 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/index/ResourceRelevance.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/index/ResourceRelevance.java @@ -28,7 +28,6 @@ import org.jetbrains.annotations.Nullable; */ public enum ResourceRelevance { - NONE, STANDARD, LIBRARY, SOURCE, @@ -55,12 +54,6 @@ public enum ResourceRelevance { return LIBRARY; } ExternalResourceManagerEx resourceManager = (ExternalResourceManagerEx)ExternalResourceManager.getInstance(); - if (resourceManager.isUserResource(resource)) { - return MAPPED; - } - if (resourceManager.isStandardResource(resource)) { - return STANDARD; - } - return NONE; + return resourceManager.isUserResource(resource) ? MAPPED : STANDARD; } } diff --git a/xml/xml-psi-impl/src/com/intellij/xml/index/XmlNamespaceIndex.java b/xml/xml-psi-impl/src/com/intellij/xml/index/XmlNamespaceIndex.java index 4806b878ce19..0953dff430f2 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/index/XmlNamespaceIndex.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/index/XmlNamespaceIndex.java @@ -142,11 +142,9 @@ public class XmlNamespaceIndex extends XmlIndex { public static IndexedRelevantResource guessSchema(String namespace, @Nullable final String tagName, @Nullable final String version, - @Nullable Module module) { + @Nullable Module module, + @NotNull Project project) { - if (module == null) return null; - - Project project = module.getProject(); final List> resources = getResourcesByNamespace(namespace, project, module); @@ -173,7 +171,7 @@ public class XmlNamespaceIndex extends XmlIndex { if (DumbService.isDumb(file.getProject()) || XmlUtil.isStubBuilding()) return null; IndexedRelevantResource resource = - guessSchema(namespace, tagName, version, ModuleUtilCore.findModuleForPsiElement(file)); + guessSchema(namespace, tagName, version, ModuleUtilCore.findModuleForPsiElement(file), file.getProject()); if (resource == null) return null; return findSchemaFile(resource.getFile(), file); }