diff --git a/platform/core-api/src/com/intellij/psi/ExternallyAnnotated.java b/platform/core-api/src/com/intellij/psi/ExternallyAnnotated.java index ed0adde37cfd..a18202feea7a 100644 --- a/platform/core-api/src/com/intellij/psi/ExternallyAnnotated.java +++ b/platform/core-api/src/com/intellij/psi/ExternallyAnnotated.java @@ -8,19 +8,20 @@ import org.jetbrains.annotations.Nullable; * Helper interface for PSI elements which may be added as ForeignLeaf and need to redirect annotations * to another text range. */ +@FunctionalInterface public interface ExternallyAnnotated { /** * If inspection started for files with ForeignLeaf substitutions founds any problem in them - * it should be able to display them locally. This method allows to define such substitution text range. + * it should be able to display it locally. This method allows to define such substitution text range. * An example from C/C++ macro substitution:
    * #define T(x) int x
    * int k;
-   * T(k) = 0; // the problem [duplicate declaration 'k'] need to be annotated
+   * T(k) = 0; // the problem [duplicate declaration 'k'] needs to be annotated
    *           // for macro parameter, not declarator
    * 

- * See {@code ProblemDescriptorBase} constructor for details. + * See {@link com.intellij.codeInspection.ProblemDescriptorBase} constructor for details. * - * @return TextRange to which problem descriptions should be redirected, {@code null} if annotator need to skip the problem + * @return TextRange to which problem descriptions should be redirected, {@code null} if annotator needs to skip the problem */ @Nullable TextRange getAnnotationRegion(); diff --git a/platform/core-api/src/com/intellij/psi/impl/ElementBase.java b/platform/core-api/src/com/intellij/psi/impl/ElementBase.java index 604aaa4d52c7..34a95dc746dc 100644 --- a/platform/core-api/src/com/intellij/psi/impl/ElementBase.java +++ b/platform/core-api/src/com/intellij/psi/impl/ElementBase.java @@ -85,10 +85,7 @@ public abstract class ElementBase extends UserDataHolderBase implements Iconable try { return computeIcon(flags); } - catch (ProcessCanceledException e) { - throw e; - } - catch (IndexNotReadyException e) { + catch (ProcessCanceledException | IndexNotReadyException e) { throw e; } catch (Exception e) { diff --git a/platform/core-impl/src/com/intellij/psi/DummyHolderViewProvider.java b/platform/core-impl/src/com/intellij/psi/DummyHolderViewProvider.java index 32bc8e76c8ff..5652219361a7 100644 --- a/platform/core-impl/src/com/intellij/psi/DummyHolderViewProvider.java +++ b/platform/core-impl/src/com/intellij/psi/DummyHolderViewProvider.java @@ -70,6 +70,7 @@ public class DummyHolderViewProvider extends AbstractFileViewProvider { return target == getBaseLanguage() ? myHolder : null; } + @NotNull @Override public List getCachedPsiFiles() { return Collections.singletonList(myHolder); diff --git a/platform/core-impl/src/com/intellij/psi/MultiplePsiFilesPerDocumentFileViewProvider.java b/platform/core-impl/src/com/intellij/psi/MultiplePsiFilesPerDocumentFileViewProvider.java index e1e776c8e587..dcfa24bcb800 100644 --- a/platform/core-impl/src/com/intellij/psi/MultiplePsiFilesPerDocumentFileViewProvider.java +++ b/platform/core-impl/src/com/intellij/psi/MultiplePsiFilesPerDocumentFileViewProvider.java @@ -29,7 +29,6 @@ import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.psi.impl.source.tree.FileElement; import com.intellij.psi.templateLanguages.OuterLanguageElement; import com.intellij.util.ConcurrencyUtil; -import com.intellij.util.NullableFunction; import com.intellij.util.ReflectionUtil; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -41,9 +40,9 @@ import java.util.concurrent.ConcurrentMap; public abstract class MultiplePsiFilesPerDocumentFileViewProvider extends AbstractFileViewProvider { private final ConcurrentMap myRoots = ContainerUtil.newConcurrentMap(1, 0.75f, 1); - private MultiplePsiFilesPerDocumentFileViewProvider myOriginal = null; + private MultiplePsiFilesPerDocumentFileViewProvider myOriginal; - public MultiplePsiFilesPerDocumentFileViewProvider(PsiManager manager, VirtualFile virtualFile, boolean eventSystemEnabled) { + public MultiplePsiFilesPerDocumentFileViewProvider(@NotNull PsiManager manager, @NotNull VirtualFile virtualFile, boolean eventSystemEnabled) { super(manager, virtualFile, eventSystemEnabled, virtualFile.getFileType()); } @@ -67,7 +66,7 @@ public abstract class MultiplePsiFilesPerDocumentFileViewProvider extends Abstra return roots; } - protected final void removeFile(final Language language) { + protected final void removeFile(@NotNull Language language) { PsiFileImpl file = myRoots.remove(language); if (file != null) { file.markInvalidated(); @@ -108,9 +107,10 @@ public abstract class MultiplePsiFilesPerDocumentFileViewProvider extends Abstra return myRoots.get(target); } + @NotNull @Override public final List getCachedPsiFiles() { - return ContainerUtil.mapNotNull(myRoots.keySet(), (NullableFunction)language -> getCachedPsi(language)); + return ContainerUtil.mapNotNull(myRoots.keySet(), this::getCachedPsi); } @NotNull @@ -148,7 +148,8 @@ public abstract class MultiplePsiFilesPerDocumentFileViewProvider extends Abstra return copy; } - protected abstract MultiplePsiFilesPerDocumentFileViewProvider cloneInner(VirtualFile fileCopy); + @NotNull + protected abstract MultiplePsiFilesPerDocumentFileViewProvider cloneInner(@NotNull VirtualFile fileCopy); @Override @Nullable diff --git a/platform/core-impl/src/com/intellij/psi/SingleRootFileViewProvider.java b/platform/core-impl/src/com/intellij/psi/SingleRootFileViewProvider.java index e8794cbda9f0..a29e6b97a0e3 100644 --- a/platform/core-impl/src/com/intellij/psi/SingleRootFileViewProvider.java +++ b/platform/core-impl/src/com/intellij/psi/SingleRootFileViewProvider.java @@ -149,6 +149,7 @@ public class SingleRootFileViewProvider extends AbstractFileViewProvider impleme return file == PsiUtilCore.NULL_PSI_FILE ? null : file; } + @NotNull @Override public final List getCachedPsiFiles() { return ContainerUtil.createMaybeSingletonList(getCachedPsi(getBaseLanguage())); @@ -219,7 +220,6 @@ public class SingleRootFileViewProvider extends AbstractFileViewProvider impleme return contentSize > PersistentFSConstants.getMaxIntellisenseFileSize(); } - @SuppressWarnings("UnusedParameters") public static boolean isTooLargeForContentLoading(@NotNull VirtualFile vFile, final long contentSize) { return contentSize > PersistentFSConstants.FILE_LENGTH_TO_CACHE_THRESHOLD; } diff --git a/platform/util/src/com/intellij/openapi/util/TextRange.java b/platform/util/src/com/intellij/openapi/util/TextRange.java index fa94e2805101..83934550169c 100644 --- a/platform/util/src/com/intellij/openapi/util/TextRange.java +++ b/platform/util/src/com/intellij/openapi/util/TextRange.java @@ -193,8 +193,9 @@ public class TextRange implements Segment, Serializable { @Nullable public TextRange intersection(@NotNull TextRange range) { - if (!intersects(range)) return null; - return new TextRange(Math.max(myStartOffset, range.getStartOffset()), Math.min(myEndOffset, range.getEndOffset())); + int newStart = Math.max(myStartOffset, range.getStartOffset()); + int newEnd = Math.min(myEndOffset, range.getEndOffset()); + return isProperRange(newStart, newEnd) ? new TextRange(newStart, newEnd) : null; } public boolean isEmpty() { @@ -224,8 +225,12 @@ public class TextRange implements Segment, Serializable { } public static void assertProperRange(int startOffset, int endOffset, @NotNull Object message) { - if (startOffset > endOffset || startOffset < 0) { + if (!isProperRange(startOffset, endOffset)) { LOG.error("Invalid range specified: (" + startOffset + "," + endOffset + "); " + message); } } + + private static boolean isProperRange(int startOffset, int endOffset) { + return startOffset <= endOffset && startOffset >= 0; + } } diff --git a/python/python-rest/src/com/jetbrains/rest/RestFileViewProvider.java b/python/python-rest/src/com/jetbrains/rest/RestFileViewProvider.java index 4b7bfb1b90f8..44b2ed16ae82 100644 --- a/python/python-rest/src/com/jetbrains/rest/RestFileViewProvider.java +++ b/python/python-rest/src/com/jetbrains/rest/RestFileViewProvider.java @@ -54,8 +54,9 @@ public class RestFileViewProvider extends MultiplePsiFilesPerDocumentFileViewPro return PythonLanguage.getInstance(); } + @NotNull @Override - protected MultiplePsiFilesPerDocumentFileViewProvider cloneInner(VirtualFile virtualFile) { + protected MultiplePsiFilesPerDocumentFileViewProvider cloneInner(@NotNull VirtualFile virtualFile) { return new RestFileViewProvider(getManager(), virtualFile, false); }