Cleanup (fixes formatting after lambda conversion)

This commit is contained in:
Roman Shevchenko
2017-10-10 20:16:48 +02:00
parent 77ea9762c9
commit 81c25dc132
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 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.
*/
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.psi.impl.source;
import com.intellij.openapi.diagnostic.Logger;
@@ -35,6 +21,7 @@ import java.util.List;
import java.util.Map;
import static com.intellij.psi.util.PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT;
import static com.intellij.util.ObjectUtils.notNull;
public class ClassInnerStuffCache {
private final PsiExtensibleClass myClass;
@@ -44,33 +31,24 @@ public class ClassInnerStuffCache {
myClass = aClass;
}
@NotNull
private static <T> T[] copy(T[] value) {
return value.length == 0 ? value : value.clone();
}
@NotNull
public PsiMethod[] getConstructors() {
return copy(CachedValuesManager.getCachedValue(myClass, () -> CachedValueProvider.Result
.create(PsiImplUtil.getConstructors(myClass), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker)));
return copy(CachedValuesManager.getCachedValue(myClass, () -> makeResult(PsiImplUtil.getConstructors(myClass))));
}
@NotNull
public PsiField[] getFields() {
return copy(CachedValuesManager.getCachedValue(myClass, () -> CachedValueProvider.Result
.create(getAllFields(), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker)));
return copy(CachedValuesManager.getCachedValue(myClass, () -> makeResult(getAllFields())));
}
@NotNull
public PsiMethod[] getMethods() {
return copy(CachedValuesManager.getCachedValue(myClass, () -> CachedValueProvider.Result
.create(getAllMethods(), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker)));
return copy(CachedValuesManager.getCachedValue(myClass, () -> makeResult(getAllMethods())));
}
@NotNull
public PsiClass[] getInnerClasses() {
return copy(CachedValuesManager.getCachedValue(myClass, () -> CachedValueProvider.Result
.create(getAllInnerClasses(), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker)));
return copy(CachedValuesManager.getCachedValue(myClass, () -> makeResult(getAllInnerClasses())));
}
@Nullable
@@ -78,9 +56,9 @@ public class ClassInnerStuffCache {
if (checkBases) {
return PsiClassImplUtil.findFieldByName(myClass, name, true);
}
return CachedValuesManager.getCachedValue(myClass,
() -> CachedValueProvider.Result
.create(getFieldsMap(), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker)).get(name);
else {
return CachedValuesManager.getCachedValue(myClass, () -> makeResult(getFieldsMap())).get(name);
}
}
@NotNull
@@ -88,36 +66,37 @@ public class ClassInnerStuffCache {
if (checkBases) {
return PsiClassImplUtil.findMethodsByName(myClass, name, true);
}
PsiMethod[] methods = CachedValuesManager.getCachedValue(myClass, () -> CachedValueProvider.Result
.create(getMethodsMap(), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker)).get(name);
return methods == null ? PsiMethod.EMPTY_ARRAY : methods.clone();
else {
return copy(notNull(CachedValuesManager.getCachedValue(myClass, () -> makeResult(getMethodsMap())).get(name), PsiMethod.EMPTY_ARRAY));
}
}
@Nullable
public PsiClass findInnerClassByName(final String name, final boolean checkBases) {
public PsiClass findInnerClassByName(String name, boolean checkBases) {
if (checkBases) {
return PsiClassImplUtil.findInnerByName(myClass, name, true);
}
else {
return CachedValuesManager.getCachedValue(myClass, () -> CachedValueProvider.Result
.create(getInnerClassesMap(), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker)).get(name);
return CachedValuesManager.getCachedValue(myClass, () -> makeResult(getInnerClassesMap())).get(name);
}
}
@Nullable
public PsiMethod getValuesMethod() {
return !myClass.isEnum() || myClass.getName() == null ? null : CachedValuesManager.getCachedValue(myClass, () -> {
String text = "public static " + myClass.getName() + "[] values() { }";
return new CachedValueProvider.Result<>(getSyntheticMethod(text), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker);
});
return myClass.isEnum() && myClass.getName() != null ? CachedValuesManager.getCachedValue(myClass, () -> makeResult(makeValuesMethod())) : null;
}
@Nullable
public PsiMethod getValueOfMethod() {
return !myClass.isEnum() || myClass.getName() == null ? null : CachedValuesManager.getCachedValue(myClass, () -> {
String text = "public static " + myClass.getName() + " valueOf(java.lang.String name) throws java.lang.IllegalArgumentException { }";
return new CachedValueProvider.Result<>(getSyntheticMethod(text), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker);
});
return myClass.isEnum() && myClass.getName() != null ? CachedValuesManager.getCachedValue(myClass, () -> makeResult(makeValueOfMethod())) : null;
}
private static <T> T[] copy(T[] value) {
return value.length == 0 ? value : value.clone();
}
private <T> CachedValueProvider.Result<T> makeResult(T value) {
return CachedValueProvider.Result.create(value, OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker);
}
@NotNull
@@ -196,6 +175,14 @@ public class ClassInnerStuffCache {
return cachedInners;
}
private PsiMethod makeValuesMethod() {
return getSyntheticMethod("public static " + myClass.getName() + "[] values() { }");
}
private PsiMethod makeValueOfMethod() {
return getSyntheticMethod("public static " + myClass.getName() + " valueOf(java.lang.String name) throws java.lang.IllegalArgumentException { }");
}
private PsiMethod getSyntheticMethod(String text) {
PsiElementFactory factory = JavaPsiFacade.getInstance(myClass.getProject()).getElementFactory();
PsiMethod method = factory.createMethodFromText(text, myClass);