Skip to content

Commit

Permalink
cleanup: dereference
Browse files Browse the repository at this point in the history
  • Loading branch information
cdracm committed Dec 10, 2013
1 parent 1018090 commit f0b5885
Show file tree
Hide file tree
Showing 156 changed files with 477 additions and 551 deletions.
5 changes: 2 additions & 3 deletions images/src/org/intellij/images/ImagesBundle.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -39,8 +39,7 @@ public static String message(@PropertyKey(resourceBundle = BUNDLE)String key, Ob
}

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<ResourceBundle>(bundle);
Expand Down
6 changes: 3 additions & 3 deletions images/src/org/intellij/images/vfs/IfsUtil.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -66,7 +66,7 @@ public final class IfsUtil {
private static boolean refresh(@NotNull VirtualFile file) throws IOException {
Long loadedTimeStamp = file.getUserData(TIMESTAMP_KEY);
SoftReference<BufferedImage> 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();

Expand Down Expand Up @@ -113,7 +113,7 @@ private static boolean refresh(@NotNull VirtualFile file) throws IOException {
public static BufferedImage getImage(@NotNull VirtualFile file) throws IOException {
refresh(file);
SoftReference<BufferedImage> imageRef = file.getUserData(BUFFERED_IMAGE_REF_KEY);
return imageRef != null ? imageRef.get() : null;
return SoftReference.dereference(imageRef);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -45,8 +45,7 @@ public static String message(@PropertyKey(resourceBundle = BUNDLE)String key, Ob
}

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<ResourceBundle>(bundle);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -41,6 +41,7 @@
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;
Expand Down Expand Up @@ -112,7 +113,7 @@ public DebuggerEditorImpl(Project project, PsiElement context, String recentsId,
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -45,8 +45,7 @@ public static String message(@PropertyKey(resourceBundle = BUNDLE)String key, Ob
}

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<ResourceBundle>(bundle);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -71,8 +86,7 @@ public VirtualFile getVirtualFile() {
@Override
@Nullable
public PsiFile getPsiFile() {
Reference<PsiFile> ref = myPsiFile;
PsiFile psiFile = ref == null ? null : ref.get();
PsiFile psiFile = com.intellij.reference.SoftReference.dereference(myPsiFile);

if (psiFile != null && psiFile.isValid()) {
return psiFile;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -77,7 +77,7 @@ private RefCountHolder release(@NotNull ProgressIndicator indicator) {

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);
Expand All @@ -88,7 +88,7 @@ private static RefCountHolder getInstance(@NotNull PsiFile file, @NotNull Progre
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public class Java15APIUsageInspectionBase extends BaseJavaBatchLocalInspectionTo
private static Set<String> getForbiddenApi(@NotNull LanguageLevel languageLevel) {
if (!ourPresentableShortMessage.containsKey(languageLevel)) return null;
Reference<Set<String>> ref = ourForbiddenAPI.get(languageLevel);
Set<String> result;
if (ref == null || (result = ref.get()) == null) {
Set<String> result = SoftReference.dereference(ref);
if (result == null) {
result = new THashSet<String>(1000);
loadForbiddenApi("api" + getShortName(languageLevel) + ".txt", result);
ourForbiddenAPI.put(languageLevel, new SoftReference<Set<String>>(result));
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -39,8 +39,7 @@ public static String message(@PropertyKey(resourceBundle = BUNDLE)String key, Ob
}

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<ResourceBundle>(bundle);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -85,12 +86,9 @@ public void setForcedPresentableName(String forcedPresentableName) {
@Override
public PsiClass getObject() {
if (myClass instanceof PsiAnchor) {
Reference<PsiClass> 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();
Expand Down
5 changes: 2 additions & 3 deletions java/java-impl/src/com/intellij/javadoc/JavadocBundle.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -39,8 +39,7 @@ public static String message(@PropertyKey(resourceBundle = BUNDLE) String key, O
}

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<ResourceBundle>(bundle);
Expand Down
5 changes: 2 additions & 3 deletions java/java-psi-api/src/com/intellij/core/JavaCoreBundle.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -39,8 +39,7 @@ public static String message(@PropertyKey(resourceBundle = BUNDLE)String key, Ob
}

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<ResourceBundle>(bundle);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -159,7 +159,7 @@ private void registerControlFlow(@NotNull PsiElement element,
@NotNull
private CopyOnWriteArrayList<ControlFlowContext> getOrCreateCachedFlowsForElement(@NotNull PsiElement element) {
Reference<CopyOnWriteArrayList<ControlFlowContext>> cachedRef = cachedFlows.get(element);
CopyOnWriteArrayList<ControlFlowContext> cached = cachedRef == null ? null : cachedRef.get();
CopyOnWriteArrayList<ControlFlowContext> cached = com.intellij.reference.SoftReference.dereference(cachedRef);
if (cached == null) {
cached = ContainerUtil.createEmptyCOWList();
cachedFlows.put(element, new SoftReference<CopyOnWriteArrayList<ControlFlowContext>>(cached));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ public PsiConstantEvaluationHelper getConstantEvaluationHelper() {

@Override
public PsiPackage findPackage(@NotNull String qualifiedName) {
SoftReference<ConcurrentMap<String, PsiPackage>> ref = myPackageCache;
ConcurrentMap<String, PsiPackage> cache = ref == null ? null : ref.get();
ConcurrentMap<String, PsiPackage> cache = SoftReference.dereference(myPackageCache);
if (cache == null) {
myPackageCache = new SoftReference<ConcurrentMap<String, PsiPackage>>(cache = new ConcurrentHashMap<String, PsiPackage>());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -39,6 +39,7 @@
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;
Expand All @@ -49,7 +50,7 @@ public class PsiPackageImpl extends PsiPackageBase implements PsiPackage, Querya
private volatile CachedValue<PsiModifierList> myAnnotationList;
private volatile CachedValue<Collection<PsiDirectory>> myDirectories;
private volatile CachedValue<Collection<PsiDirectory>> myDirectoriesWithLibSources;
private volatile SoftReference<Set<String>> myPublicClassNamesCache;
private volatile Reference<Set<String>> myPublicClassNamesCache;

public PsiPackageImpl(PsiManager manager, String qualifiedName) {
super(manager, qualifiedName);
Expand Down Expand Up @@ -176,8 +177,7 @@ private JavaPsiFacadeImpl getFacade() {
}

private Set<String> getClassNamesCache() {
SoftReference<Set<String>> ref = myPublicClassNamesCache;
Set<String> cache = ref == null ? null : ref.get();
Set<String> cache = SoftReference.dereference(myPublicClassNamesCache);
if (cache == null) {
GlobalSearchScope scope = allScope();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,15 @@ public String getText() {

@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<PsiAnnotation>(annotation);
return annotation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public String getImportReferenceText() {
@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<PsiJavaCodeReferenceElement>(ref);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public TypePointerBase(@NotNull T type) {

@Override
public T getType() {
Reference<T> typeRef = myTypeRef;
T myType = typeRef == null ? null : typeRef.get();
T myType = SoftReference.dereference(myTypeRef);
if (myType != null && myType.isValid()) return myType;

myType = calcType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,15 @@ public PsiAnnotationMemberValue getDefaultValue() {
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<PsiAnnotationMemberValue>(value);
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,17 @@ public PsiClassType getBaseClassType() {
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);
}
Expand Down
Loading

0 comments on commit f0b5885

Please sign in to comment.