diff --git a/java/java-psi-api/src/com/intellij/codeInsight/AnnotationUtil.java b/java/java-psi-api/src/com/intellij/codeInsight/AnnotationUtil.java index 06489a5793d0..d77d06f10c7b 100644 --- a/java/java-psi-api/src/com/intellij/codeInsight/AnnotationUtil.java +++ b/java/java-psi-api/src/com/intellij/codeInsight/AnnotationUtil.java @@ -5,10 +5,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; import com.intellij.psi.*; import com.intellij.psi.util.*; -import com.intellij.util.ArrayUtil; -import com.intellij.util.Consumer; -import com.intellij.util.Processor; -import com.intellij.util.Processors; +import com.intellij.util.*; import com.intellij.util.containers.ConcurrentFactoryMap; import com.intellij.util.containers.ContainerUtil; import gnu.trove.THashMap; @@ -24,8 +21,6 @@ import java.lang.annotation.Target; import java.lang.reflect.Proxy; import java.util.*; -import static com.intellij.util.BitUtil.isSet; - /** * @author max */ @@ -76,7 +71,7 @@ public class AnnotationUtil { return skipExternal ? null : findNonCodeAnnotation(listOwner, annotationNames); } - private static PsiAnnotation findOwnAnnotation(final PsiModifierListOwner listOwner, Collection annotationNames) { + private static PsiAnnotation findOwnAnnotation(@NotNull final PsiModifierListOwner listOwner, @NotNull Collection annotationNames) { final PsiModifierList list = listOwner.getModifierList(); if (list == null) return null; for (PsiAnnotation annotation : list.getAnnotations()) { @@ -87,7 +82,7 @@ public class AnnotationUtil { return null; } - private static PsiAnnotation findNonCodeAnnotation(final PsiModifierListOwner listOwner, Collection annotationNames) { + private static PsiAnnotation findNonCodeAnnotation(@NotNull PsiModifierListOwner listOwner, @NotNull Collection annotationNames) { if (listOwner instanceof PsiLocalVariable) { // Non-code annotations for local variables are not supported: don't bother to search them return null; @@ -137,6 +132,7 @@ public class AnnotationUtil { return result == null ? PsiAnnotation.EMPTY_ARRAY : result.toArray(PsiAnnotation.EMPTY_ARRAY); } + @NotNull public static List getSuperAnnotationOwners(@NotNull T element) { return CachedValuesManager.getCachedValue(element, () -> { Set result = ContainerUtil.newLinkedHashSet(); @@ -155,7 +151,8 @@ public class AnnotationUtil { List list; if(result.isEmpty()) { list = Collections.emptyList(); - } else { + } + else { PsiModifierListOwner[] array = result.toArray(new PsiModifierListOwner[0]); //noinspection unchecked list = Arrays.asList((T[])array); @@ -179,7 +176,7 @@ public class AnnotationUtil { return null; } - private static void collectSuperParameters(@NotNull final Set result, @NotNull PsiParameter parameter) { + private static void collectSuperParameters(@NotNull final Set result, @NotNull PsiParameter parameter) { PsiElement parent = parameter.getParent(); if (!(parent instanceof PsiParameterList)) { return; @@ -209,7 +206,7 @@ public class AnnotationUtil { } } - private static void collectSuperMethods(@NotNull Set result, + private static void collectSuperMethods(@NotNull Set result, @NotNull HierarchicalMethodSignature signature, @NotNull PsiElement place, @NotNull PsiResolveHelper resolveHelper) { @@ -238,7 +235,7 @@ public class AnnotationUtil { return isAnnotated(listOwner, annotationFqn, flags, null); } - private static boolean isAnnotated(PsiModifierListOwner listOwner, String annotationFQN, int flags, @Nullable Set processed) { + private static boolean isAnnotated(@NotNull PsiModifierListOwner listOwner, @NotNull String annotationFQN, @Flags int flags, @Nullable Set processed) { if (!listOwner.isValid()) return false; PsiModifierList modifierList = listOwner.getModifierList(); @@ -247,7 +244,7 @@ public class AnnotationUtil { PsiAnnotation annotation = modifierList.findAnnotation(annotationFQN); if (annotation != null) return true; - if (isSet(flags, CHECK_TYPE)) { + if (BitUtil.isSet(flags, CHECK_TYPE)) { PsiType type = null; if (listOwner instanceof PsiMethod) { type = ((PsiMethod)listOwner).getReturnType(); @@ -260,21 +257,21 @@ public class AnnotationUtil { } } - if (isSet(flags, CHECK_EXTERNAL)) { + if (BitUtil.isSet(flags, CHECK_EXTERNAL)) { Project project = listOwner.getProject(); if (ExternalAnnotationsManager.getInstance(project).findExternalAnnotation(listOwner, annotationFQN) != null) { return true; } } - if (isSet(flags, CHECK_INFERRED)) { + if (BitUtil.isSet(flags, CHECK_INFERRED)) { Project project = listOwner.getProject(); if (InferredAnnotationsManager.getInstance(project).findInferredAnnotation(listOwner, annotationFQN) != null) { return true; } } - if (isSet(flags, CHECK_HIERARCHY)) { + if (BitUtil.isSet(flags, CHECK_HIERARCHY)) { if (listOwner instanceof PsiMethod) { PsiMethod method = (PsiMethod)listOwner; if (processed == null) processed = new THashSet<>(); @@ -449,7 +446,7 @@ public class AnnotationUtil { return annotations; } - public static boolean isInsideAnnotation(PsiElement element) { + public static boolean isInsideAnnotation(@NotNull PsiElement element) { for (int level = 0; level<4; level++) { if (element instanceof PsiNameValuePair) return true; element = element.getParent(); @@ -545,7 +542,7 @@ public class AnnotationUtil { return true; } - private static boolean fillValueMap(PsiAnnotationParameterList parameterList, Map valueMap) { + private static boolean fillValueMap(@NotNull PsiAnnotationParameterList parameterList, @NotNull Map valueMap) { final PsiNameValuePair[] attributes1 = parameterList.getAttributes(); for (PsiNameValuePair attribute : attributes1) { final PsiReference reference = attribute.getReference(); @@ -568,7 +565,7 @@ public class AnnotationUtil { return true; } - public static boolean equal(PsiAnnotationMemberValue value1, PsiAnnotationMemberValue value2) { + public static boolean equal(@Nullable PsiAnnotationMemberValue value1, @Nullable PsiAnnotationMemberValue value2) { if (value1 instanceof PsiArrayInitializerMemberValue && value2 instanceof PsiArrayInitializerMemberValue) { final PsiAnnotationMemberValue[] initializers1 = ((PsiArrayInitializerMemberValue)value1).getInitializers(); final PsiAnnotationMemberValue[] initializers2 = ((PsiArrayInitializerMemberValue)value2).getInitializers(); @@ -595,7 +592,7 @@ public class AnnotationUtil { /** * Ignores Override and SuppressWarnings annotations. */ - public static boolean equal(PsiAnnotation[] annotations1, PsiAnnotation[] annotations2) { + public static boolean equal(@NotNull PsiAnnotation[] annotations1, @NotNull PsiAnnotation[] annotations2) { final Map map1 = buildAnnotationMap(annotations1); final Map map2 = buildAnnotationMap(annotations2); if (map1.size() != map2.size()) { @@ -609,7 +606,8 @@ public class AnnotationUtil { return true; } - private static Map buildAnnotationMap(PsiAnnotation[] annotations) { + @NotNull + private static Map buildAnnotationMap(@NotNull PsiAnnotation[] annotations) { final Map map = new HashMap<>(); for (PsiAnnotation annotation : annotations) { map.put(annotation.getQualifiedName(), annotation); @@ -667,7 +665,8 @@ public class AnnotationUtil { return isAnnotated(listOwner, annotationFQN, flags(checkHierarchy, skipExternal, skipExternal)); } - private static @Flags int flags(boolean checkHierarchy, boolean skipExternal, boolean skipInferred) { + @Flags + private static int flags(boolean checkHierarchy, boolean skipExternal, boolean skipInferred) { int flags = CHECK_TYPE; if (checkHierarchy) flags |= CHECK_HIERARCHY; if (!skipExternal) flags |= CHECK_EXTERNAL; diff --git a/platform/core-api/src/com/intellij/util/indexing/ID.java b/platform/core-api/src/com/intellij/util/indexing/ID.java index d9fd5ef075f3..8a73b5b13e9a 100644 --- a/platform/core-api/src/com/intellij/util/indexing/ID.java +++ b/platform/core-api/src/com/intellij/util/indexing/ID.java @@ -41,14 +41,11 @@ public class ID extends IndexId { try { TObjectIntHashMap nameToIdRegistry = new TObjectIntHashMap<>(); try (BufferedReader reader = new BufferedReader(new FileReader(indices))) { - int cnt = 0; - do { - cnt++; + for (int cnt = 1; ; cnt++) { final String name = reader.readLine(); if (name == null) break; nameToIdRegistry.put(name, cnt); } - while (true); } synchronized (ourNameToIdRegistry) { @@ -67,12 +64,13 @@ public class ID extends IndexId { } } + @NotNull private static File getEnumFile() { final File indexFolder = PathManager.getIndexRoot(); return new File(indexFolder, "indices.enum"); } - protected ID(String name) { + protected ID(@NotNull String name) { super(name); myUniqueId = stringToId(name); @@ -80,14 +78,14 @@ public class ID extends IndexId { assert old == null : "ID with name '" + name + "' is already registered"; } - private static short stringToId(String name) { + private static short stringToId(@NotNull String name) { synchronized (ourNameToIdRegistry) { if (ourNameToIdRegistry.containsKey(name)) { return (short)ourNameToIdRegistry.get(name); } int n = ourNameToIdRegistry.size() + 1; - assert n <= MAX_NUMBER_OF_INDICES : "Number of indices exceeded"; + assert n <= MAX_NUMBER_OF_INDICES : "Number of indices exceeded: "+n; ourNameToIdRegistry.put(name, n); writeEnumFile(); @@ -95,7 +93,7 @@ public class ID extends IndexId { } } - public static void reinitializeDiskStorage() { + static void reinitializeDiskStorage() { synchronized (ourNameToIdRegistry) { writeEnumFile(); } @@ -126,7 +124,7 @@ public class ID extends IndexId { @NotNull public static ID create(@NonNls @NotNull String name) { final ID found = findByName(name); - return found != null ? found : new ID<>(name); + return found == null ? new ID<>(name) : found; } @Nullable @@ -134,13 +132,15 @@ public class ID extends IndexId { return (ID)findById(stringToId(name)); } + @Override public int hashCode() { - return (int)myUniqueId; + return myUniqueId; } /** * Consider to use {@link ID#getName()} instead of this method */ + @Override public String toString() { return getName(); } diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/tree/SharedImplUtil.java b/platform/core-impl/src/com/intellij/psi/impl/source/tree/SharedImplUtil.java index fc515f5553db..ae784041cb9e 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/tree/SharedImplUtil.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/tree/SharedImplUtil.java @@ -47,24 +47,24 @@ public class SharedImplUtil { return SourceTreeToPsiMap.treeElementToPsi(thisElement.getTreeParent()); } - public static PsiElement getFirstChild(ASTNode element) { + public static PsiElement getFirstChild(@NotNull ASTNode element) { return SourceTreeToPsiMap.treeElementToPsi(element.getFirstChildNode()); } @Nullable - public static PsiElement getLastChild(ASTNode element) { + public static PsiElement getLastChild(@NotNull ASTNode element) { return SourceTreeToPsiMap.treeElementToPsi(element.getLastChildNode()); } - public static PsiElement getNextSibling(ASTNode thisElement) { + public static PsiElement getNextSibling(@NotNull ASTNode thisElement) { return SourceTreeToPsiMap.treeElementToPsi(thisElement.getTreeNext()); } - public static PsiElement getPrevSibling(ASTNode thisElement) { + public static PsiElement getPrevSibling(@NotNull ASTNode thisElement) { return SourceTreeToPsiMap.treeElementToPsi(thisElement.getTreePrev()); } - public static PsiFile getContainingFile(ASTNode thisElement) { + public static PsiFile getContainingFile(@NotNull ASTNode thisElement) { FileASTNode node = findFileElement(thisElement); PsiElement psi = node == null ? null : node.getPsi(); if (psi == null || psi instanceof PsiFile) return (PsiFile)psi; @@ -186,7 +186,7 @@ public class SharedImplUtil { return count; } - public static void acceptChildren(PsiElementVisitor visitor, ASTNode root) { + public static void acceptChildren(@NotNull PsiElementVisitor visitor, @NotNull ASTNode root) { ASTNode childNode = root.getFirstChildNode(); while (childNode != null) { @@ -203,7 +203,7 @@ public class SharedImplUtil { } } - public static PsiElement doReplace(PsiElement psiElement, TreeElement treeElement, PsiElement newElement) { + public static PsiElement doReplace(@NotNull PsiElement psiElement, @NotNull TreeElement treeElement, @NotNull PsiElement newElement) { CompositeElement treeParent = treeElement.getTreeParent(); LOG.assertTrue(treeParent != null); CheckUtil.checkWritable(psiElement); diff --git a/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java b/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java index 807bbee8e991..be01ff93a2fd 100644 --- a/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java +++ b/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java @@ -132,10 +132,10 @@ public class FindInProjectUtil { VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(path); if (virtualFile == null || !virtualFile.isDirectory()) { virtualFile = null; - @SuppressWarnings("deprecation") VirtualFileSystem[] fileSystems = ApplicationManager.getApplication().getComponents(VirtualFileSystem.class); + VirtualFileSystem[] fileSystems = ApplicationManager.getApplication().getComponents(VirtualFileSystem.class); for (VirtualFileSystem fs : fileSystems) { if (fs instanceof LocalFileProvider) { - @SuppressWarnings("deprecation") VirtualFile file = ((LocalFileProvider)fs).findLocalVirtualFileByPath(path); + VirtualFile file = ((LocalFileProvider)fs).findLocalVirtualFileByPath(path); if (file != null && file.isDirectory()) { if (file.getChildren().length > 0) { virtualFile = file; @@ -249,7 +249,7 @@ public class FindInProjectUtil { @NotNull final PsiFile psiFile, @NotNull int[] offsetRef, int maxUsages, - @NotNull Processor consumer) { + @NotNull Processor consumer) { int count = 0; CharSequence text = document.getCharsSequence(); int textLength = document.getTextLength(); @@ -532,7 +532,7 @@ public class FindInProjectUtil { private static void addSourceDirectoriesFromLibraries(@NotNull Project project, @NotNull VirtualFile directory, - @NotNull Collection outSourceRoots) { + @NotNull Collection outSourceRoots) { ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(project); // if we already are in the sources, search just in this directory only if (!index.isInLibraryClasses(directory)) return; diff --git a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/parsing/PropertyListStubElementType.java b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/parsing/PropertyListStubElementType.java index 438d470f0177..58ed5cf6e235 100644 --- a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/parsing/PropertyListStubElementType.java +++ b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/parsing/PropertyListStubElementType.java @@ -44,6 +44,7 @@ public class PropertyListStubElementType extends ILightStubElementType