This commit is contained in:
Alexey Kudravtsev
2017-12-14 14:24:04 +03:00
parent 91df3fa3e0
commit e6423cd6fd
15 changed files with 45 additions and 42 deletions
@@ -53,6 +53,7 @@ public class JShellFileImpl extends PsiJavaFileBaseImpl implements PsiJShellFile
return JShellFileType.INSTANCE;
}
@Override
public boolean isPhysical() {
return getViewProvider().isPhysical();
}
@@ -46,9 +46,11 @@ public interface BaseJspFile extends XmlFile {
*/
PsiFile getErrorPage();
@Override
@NotNull
JspxFileViewProvider getViewProvider();
@Override
@NotNull
XmlTag getRootTag();
}
@@ -27,7 +27,7 @@ public interface PsiCheckedRenameElement extends PsiNamedElement {
* and throws an exception if the rename is not possible. Does not actually modify anything.
*
* @param name the new name to check the renaming possibility for.
* @throws com.intellij.util.IncorrectOperationException if the rename is not supported or not possible for some reason.
* @throws IncorrectOperationException if the rename is not supported or not possible for some reason.
*/
void checkSetName(String name) throws IncorrectOperationException;
}
@@ -50,8 +50,7 @@ public interface PsiElement extends UserDataHolder, Iconable {
* Returns the project to which the PSI element belongs.
*
* @return the project instance.
* @throws PsiInvalidElementAccessException
* if this element is invalid
* @throws PsiInvalidElementAccessException if this element is invalid
*/
@NotNull
@Contract(pure=true)
@@ -27,8 +27,8 @@ import org.jetbrains.annotations.NotNull;
* for high-level overview.
*
* @see com.intellij.openapi.actionSystem.LangDataKeys#PSI_FILE
* @see com.intellij.psi.PsiElement#getContainingFile()
* @see PsiManager#findFile(com.intellij.openapi.vfs.VirtualFile)
* @see PsiElement#getContainingFile()
* @see PsiManager#findFile(VirtualFile)
* @see PsiDocumentManager#getPsiFile(com.intellij.openapi.editor.Document)
*/
public interface PsiFile extends PsiFileSystemItem {
@@ -60,7 +60,7 @@ public interface PsiFile extends PsiFileSystemItem {
* of the content of the file. Note that it is not related to the file modification time.
*
* @return the modification stamp value
* @see com.intellij.openapi.vfs.VirtualFile#getModificationStamp()
* @see VirtualFile#getModificationStamp()
*/
long getModificationStamp();
@@ -33,7 +33,8 @@ public interface PsiNamedElement extends PsiElement {
*
* @return the element name.
*/
@Nullable String getName();
@Nullable
String getName();
/**
* Renames the element.
@@ -213,12 +213,11 @@ public class FileManagerImpl implements FileManager {
if (fileViewProvider == null) {
myVFileToViewProviderMap.remove(virtualFile);
}
else if (virtualFile instanceof LightVirtualFile) {
virtualFile.putUserData(myPsiHardRefKey, fileViewProvider);
}
else {
if (virtualFile instanceof LightVirtualFile) {
virtualFile.putUserData(myPsiHardRefKey, fileViewProvider);
} else {
myVFileToViewProviderMap.put(virtualFile, fileViewProvider);
}
myVFileToViewProviderMap.put(virtualFile, fileViewProvider);
}
}
}
@@ -1108,7 +1108,7 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
if (!useStrongRefs()) {
synchronized (myPsiLock) {
for (PsiFile root : myViewProvider.getAllFiles()) {
if ((root instanceof PsiFileImpl)) {
if (root instanceof PsiFileImpl) {
((PsiFileImpl)root).switchToStrongRefs();
}
}
@@ -52,7 +52,6 @@ import com.intellij.psi.impl.source.codeStyle.CodeFormatterFacade;
import com.intellij.psi.impl.source.codeStyle.IndentHelperImpl;
import com.intellij.psi.impl.source.tree.*;
import com.intellij.util.LocalTimeCounter;
import com.intellij.util.containers.ContainerUtilRt;
import com.intellij.util.text.CharArrayUtil;
import com.intellij.util.text.TextRangeUtil;
import org.jetbrains.annotations.NonNls;
@@ -73,7 +72,7 @@ public class PostprocessReformattingAspect implements PomModelAspect {
private static final boolean STORE_REFORMAT_ORIGINATOR_STACKTRACE = ApplicationManager.getApplication().isInternal();
}
private final ThreadLocal<Context> myContext = ThreadLocal.withInitial(() -> new Context());
private final ThreadLocal<Context> myContext = ThreadLocal.withInitial(Context::new);
public PostprocessReformattingAspect(Project project, PsiManager psiManager, TreeAspect treeAspect,final CommandProcessor processor) {
myProject = project;
@@ -155,7 +154,7 @@ public class PostprocessReformattingAspect implements PomModelAspect {
doPostponedFormatting();
}
else {
application.runWriteAction(() -> doPostponedFormatting());
application.runWriteAction((Runnable)this::doPostponedFormatting);
}
}
}
@@ -286,7 +285,7 @@ public class PostprocessReformattingAspect implements PomModelAspect {
break;
}
if (sb.length() > 0) sb.append(", ");
sb.append(node.getElementType().toString()).append(node.getTextRange());
sb.append(node.getElementType()).append(node.getTextRange());
count ++;
}
return sb.toString();
@@ -335,12 +334,12 @@ public class PostprocessReformattingAspect implements PomModelAspect {
}
}
final TreeSet<PostprocessFormattingTask> postProcessTasks = new TreeSet<>();
Collection<Disposable> toDispose = ContainerUtilRt.newArrayList();
Collection<Disposable> toDispose = Collections.emptyList();
try {
// process all roots in viewProvider to find marked for reformat before elements and create appropriate range markers
Set<PostprocessFormattingTask> postProcessTasks = new TreeSet<>();
handleReformatMarkers(key, postProcessTasks);
toDispose.addAll(postProcessTasks);
toDispose = new ArrayList<>(postProcessTasks);
// then we create ranges by changed nodes. One per node. There ranges can intersect. Ranges are sorted by end offset.
if (astNodes != null) createActionsMap(astNodes, key, postProcessTasks);
@@ -374,9 +373,9 @@ public class PostprocessReformattingAspect implements PomModelAspect {
}
}
private void reparseByTextIfNeeded(@NotNull FileViewProvider key, Document document) {
private void reparseByTextIfNeeded(@NotNull FileViewProvider viewProvider, @NotNull Document document) {
if (PsiDocumentManager.getInstance(myProject).isCommitted(document)) {
for (PsiFile file : key.getAllFiles()) {
for (PsiFile file : viewProvider.getAllFiles()) {
if (file.getUserData(REPARSE_PENDING) != null) {
((PsiDocumentManagerBase)PsiDocumentManager.getInstance(myProject)).reparseFileFromText((PsiFileImpl)file);
file.putUserData(REPARSE_PENDING, null);
@@ -479,13 +478,7 @@ public class PostprocessReformattingAspect implements PomModelAspect {
rangeMarker = document.createRangeMarker(newStart, newEnd);
}
if (withLeadingWhitespace) {
accumulatedTask = new ReformatWithHeadingWhitespaceTask(rangeMarker);
}
else {
accumulatedTask = new ReformatTask(rangeMarker);
}
accumulatedTask = withLeadingWhitespace ? new ReformatWithHeadingWhitespaceTask(rangeMarker) : new ReformatTask(rangeMarker);
}
else if (currentTask instanceof ReindentTask) {
iterator.remove();
@@ -501,10 +494,10 @@ public class PostprocessReformattingAspect implements PomModelAspect {
}
}
final List<PostponedAction> result = new ArrayList<>();
Collections.reverse(freeFormattingActions);
Collections.reverse(indentActions);
List<PostponedAction> result = new ArrayList<>();
if (!freeFormattingActions.isEmpty()) {
FormatTextRanges ranges = new FormatTextRanges();
for (PostprocessFormattingTask action : freeFormattingActions) {
@@ -538,7 +531,7 @@ public class PostprocessReformattingAspect implements PomModelAspect {
private static void createActionsMap(@NotNull List<ASTNode> astNodes,
@NotNull FileViewProvider provider,
@NotNull final TreeSet<PostprocessFormattingTask> rangesToProcess) {
@NotNull Collection<PostprocessFormattingTask> rangesToProcess) {
final Set<ASTNode> nodesToProcess = new HashSet<>(astNodes);
final Document document = provider.getDocument();
if (document == null) {
@@ -679,7 +672,7 @@ public class PostprocessReformattingAspect implements PomModelAspect {
private abstract static class PostprocessFormattingTask implements Comparable<PostprocessFormattingTask>, Segment, Disposable {
@NotNull private final RangeMarker myRange;
public PostprocessFormattingTask(@NotNull RangeMarker rangeMarker) {
PostprocessFormattingTask(@NotNull RangeMarker rangeMarker) {
myRange = rangeMarker;
}
@@ -722,13 +715,13 @@ public class PostprocessReformattingAspect implements PomModelAspect {
}
private static class ReformatTask extends PostprocessFormattingTask {
public ReformatTask(@NotNull RangeMarker rangeMarker) {
ReformatTask(@NotNull RangeMarker rangeMarker) {
super(rangeMarker);
}
}
private static class ReformatWithHeadingWhitespaceTask extends PostprocessFormattingTask {
public ReformatWithHeadingWhitespaceTask(@NotNull RangeMarker rangeMarker) {
ReformatWithHeadingWhitespaceTask(@NotNull RangeMarker rangeMarker) {
super(rangeMarker);
}
}
@@ -736,12 +729,12 @@ public class PostprocessReformattingAspect implements PomModelAspect {
private static class ReindentTask extends PostprocessFormattingTask {
private final int myOldIndent;
public ReindentTask(@NotNull RangeMarker rangeMarker, int oldIndent) {
ReindentTask(@NotNull RangeMarker rangeMarker, int oldIndent) {
super(rangeMarker);
myOldIndent = oldIndent;
}
public int getOldIndent() {
int getOldIndent() {
return myOldIndent;
}
}
@@ -753,7 +746,7 @@ public class PostprocessReformattingAspect implements PomModelAspect {
private class ReformatRangesAction implements PostponedAction {
private final FormatTextRanges myRanges;
public ReformatRangesAction(@NotNull FormatTextRanges ranges) {
ReformatRangesAction(@NotNull FormatTextRanges ranges) {
myRanges = ranges;
}
@@ -812,8 +805,8 @@ public class PostprocessReformattingAspect implements PomModelAspect {
}
private static class Context {
private int myPostponedCounter = 0;
private int myDisabledCounter = 0;
private int myPostponedCounter;
private int myDisabledCounter;
private final Set<FileViewProvider> myUpdatedProviders = new HashSet<>();
private final Map<FileViewProvider, List<ASTNode>> myReformatElements = new HashMap<>();
}
@@ -322,7 +322,7 @@ public class ContainerUtilRt {
}
@Override
public boolean containsAll(Collection<?> c) {
public boolean containsAll(@NotNull Collection<?> c) {
return c.isEmpty();
}
@@ -335,7 +335,7 @@ public class ContainerUtilRt {
@Override
@Contract(pure = true)
public boolean equals(Object o) {
return (o instanceof List) && ((List)o).isEmpty();
return o instanceof List && ((List)o).isEmpty();
}
@Override
@@ -1431,7 +1431,7 @@ public class ContainerUtil extends ContainerUtilRt {
throw new ConcurrentModificationException("The list has changed. Its size was " + finalSize + "; now it's " + from);
}
}
throw new IndexOutOfBoundsException("index: " + index + "size: " + size());
throw new IndexOutOfBoundsException("index: " + index + "; size: " + size());
}
@Override
@@ -44,6 +44,7 @@ public class XPathElementImpl extends ASTWrapperPsiElement implements XPathEleme
return name.substring(name.lastIndexOf('.') + 1) + ": " + getText();
}
@Override
public PsiElement addBefore(@NotNull PsiElement psiElement, final PsiElement anchor) throws IncorrectOperationException {
final ASTNode node = getNode();
final ASTNode child = psiElement.getNode();
@@ -52,6 +53,7 @@ public class XPathElementImpl extends ASTWrapperPsiElement implements XPathEleme
return node.getPsi();
}
@Override
public PsiElement addAfter(@NotNull PsiElement psiElement, final PsiElement anchor) throws IncorrectOperationException {
final ASTNode astNode = anchor.getNode();
assert astNode != null;
@@ -49,12 +49,14 @@ public class IpnbPyFragment extends PyFileImpl {
return clone;
}
@Override
@NotNull
public FileViewProvider getViewProvider() {
if (myViewProvider != null) return myViewProvider;
return super.getViewProvider();
}
@Override
public boolean isPhysical() {
return myPhysical;
}
@@ -59,12 +59,14 @@ public class PyExpressionCodeFragmentImpl extends PyFileImpl implements PyExpres
return myContext != null && myContext.isValid() ? myContext : super.getContext();
}
@Override
@NotNull
public FileViewProvider getViewProvider() {
if(myViewProvider != null) return myViewProvider;
return super.getViewProvider();
}
@Override
public boolean isPhysical() {
return myPhysical;
}
@@ -50,12 +50,14 @@ public class PyListLiteralExpressionImpl extends PySequenceExpressionImpl implem
}
}
@Override
public PsiElement addAfter(@NotNull PsiElement psiElement, PsiElement afterThis) throws IncorrectOperationException {
checkPyExpression(psiElement);
checkPyExpression(afterThis);
return PyElementGenerator.getInstance(getProject()).insertItemIntoList(this, (PyExpression)afterThis, (PyExpression)psiElement);
}
@Override
public PsiElement addBefore(@NotNull PsiElement psiElement, PsiElement beforeThis) throws IncorrectOperationException {
checkPyExpression(psiElement);
return PyElementGenerator.getInstance(getProject()).insertItemIntoList(this, null, (PyExpression)psiElement);