mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PsiClass#getMethods et al: don't allow clients to modify shared arrays
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user