PsiClass#getMethods et al: don't allow clients to modify shared arrays

This commit is contained in:
peter
2016-08-23 12:55:03 +02:00
parent b09dc5d412
commit 5eba3ed388
4 changed files with 41 additions and 22 deletions
@@ -108,7 +108,7 @@ public class PsiClassReferenceListStubImpl extends StubBase<PsiReferenceList> im
}
myTypes = types;
return types;
return types.clone();
}
@NotNull
@@ -38,55 +38,58 @@ import static com.intellij.psi.util.PsiModificationTracker.OUT_OF_CODE_BLOCK_MOD
public class ClassInnerStuffCache {
private final PsiExtensibleClass myClass;
private final SimpleModificationTracker myTracker;
private final SimpleModificationTracker myTracker = new SimpleModificationTracker();
public ClassInnerStuffCache(@NotNull PsiExtensibleClass aClass) {
myClass = aClass;
myTracker = new SimpleModificationTracker();
}
private static <T> T[] copy(T[] value) {
return value.length == 0 ? value : value.clone();
}
@NotNull
public PsiMethod[] getConstructors() {
return CachedValuesManager.getCachedValue(myClass, new CachedValueProvider<PsiMethod[]>() {
return copy(CachedValuesManager.getCachedValue(myClass, new CachedValueProvider<PsiMethod[]>() {
@Nullable
@Override
public Result<PsiMethod[]> compute() {
return Result.create(PsiImplUtil.getConstructors(myClass), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker);
}
});
}));
}
@NotNull
public PsiField[] getFields() {
return CachedValuesManager.getCachedValue(myClass, new CachedValueProvider<PsiField[]>() {
return copy(CachedValuesManager.getCachedValue(myClass, new CachedValueProvider<PsiField[]>() {
@Nullable
@Override
public Result<PsiField[]> compute() {
return Result.create(getAllFields(), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker);
}
});
}));
}
@NotNull
public PsiMethod[] getMethods() {
return CachedValuesManager.getCachedValue(myClass, new CachedValueProvider<PsiMethod[]>() {
return copy(CachedValuesManager.getCachedValue(myClass, new CachedValueProvider<PsiMethod[]>() {
@Nullable
@Override
public Result<PsiMethod[]> compute() {
return Result.create(getAllMethods(), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker);
}
});
}));
}
@NotNull
public PsiClass[] getInnerClasses() {
return CachedValuesManager.getCachedValue(myClass, new CachedValueProvider<PsiClass[]>() {
return copy(CachedValuesManager.getCachedValue(myClass, new CachedValueProvider<PsiClass[]>() {
@Nullable
@Override
public Result<PsiClass[]> compute() {
return Result.create(getAllInnerClasses(), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker);
}
});
}));
}
@Nullable
@@ -115,7 +118,7 @@ public class ClassInnerStuffCache {
return Result.create(getMethodsMap(), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker);
}
}).get(name);
return methods == null ? PsiMethod.EMPTY_ARRAY : methods;
return methods == null ? PsiMethod.EMPTY_ARRAY : methods.clone();
}
@Nullable