summaryrefslogtreecommitdiff
path: root/platform/lang-impl/src/com/intellij/psi/impl/source
diff options
context:
space:
mode:
Diffstat (limited to 'platform/lang-impl/src/com/intellij/psi/impl/source')
-rw-r--r--platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java5
-rw-r--r--platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleManagerImpl.java2
-rw-r--r--platform/lang-impl/src/com/intellij/psi/impl/source/tree/PsiCommentImpl.java45
-rw-r--r--platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/CommentLiteralEscaper.java59
-rw-r--r--platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedFileViewProvider.java2
-rw-r--r--platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedLanguageUtil.java53
-rw-r--r--platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/MultiHostRegistrarImpl.java2
-rw-r--r--platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/Place.java6
-rw-r--r--platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/ShredImpl.java1
9 files changed, 60 insertions, 115 deletions
diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java
index fa1dd9e86b4a..c7b9bf3a3adf 100644
--- a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java
+++ b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java
@@ -391,14 +391,15 @@ public class CodeFormatterFacade {
/**
- * Inspects all lines of the given document and wraps all of them that exceed {@link CodeStyleSettings#RIGHT_MARGIN right margin}.
+ * Inspects all lines of the given document and wraps all of them that exceed {@link CodeStyleSettings#getRightMargin(com.intellij.lang.Language)}
+ * right margin}.
* <p/>
* I.e. the algorithm is to do the following for every line:
* <p/>
* <pre>
* <ol>
* <li>
- * Check if the line exceeds {@link CodeStyleSettings#RIGHT_MARGIN right margin}. Go to the next line in the case of
+ * Check if the line exceeds {@link CodeStyleSettings#getRightMargin(com.intellij.lang.Language)} right margin}. Go to the next line in the case of
* negative answer;
* </li>
* <li>Determine line wrap position; </li>
diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleManagerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleManagerImpl.java
index 767152fc1e2b..d51ef1216a59 100644
--- a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleManagerImpl.java
+++ b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleManagerImpl.java
@@ -181,7 +181,7 @@ public class CodeStyleManagerImpl extends CodeStyleManager {
transformAllChildren(treeElement);
final CodeFormatterFacade codeFormatter = new CodeFormatterFacade(getSettings(), file.getLanguage());
- LOG.assertTrue(file.isValid());
+ LOG.assertTrue(file.isValid(), "File name: " + file.getName() + " , class: " + file.getClass().getSimpleName());
if (editor == null) {
editor = PsiUtilBase.findEditor(file);
diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/PsiCommentImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/PsiCommentImpl.java
deleted file mode 100644
index d4e1b0d52f53..000000000000
--- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/PsiCommentImpl.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2000-2009 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.
- */
-
-package com.intellij.psi.impl.source.tree;
-
-import com.intellij.psi.LiteralTextEscaper;
-import com.intellij.psi.PsiLanguageInjectionHost;
-import com.intellij.psi.impl.source.tree.injected.CommentLiteralEscaper;
-import com.intellij.psi.tree.IElementType;
-import org.jetbrains.annotations.NotNull;
-
-public class PsiCommentImpl extends PsiCoreCommentImpl implements PsiLanguageInjectionHost {
- public PsiCommentImpl(IElementType type, CharSequence text) {
- super(type, text);
- }
-
- @Override
- public boolean isValidHost() {
- return true;
- }
-
- @Override
- public PsiLanguageInjectionHost updateText(@NotNull final String text) {
- return (PsiCommentImpl)replaceWithText(text);
- }
-
- @Override
- @NotNull
- public LiteralTextEscaper<PsiCommentImpl> createLiteralTextEscaper() {
- return new CommentLiteralEscaper(this);
- }
-}
diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/CommentLiteralEscaper.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/CommentLiteralEscaper.java
deleted file mode 100644
index c6399e30b5f6..000000000000
--- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/CommentLiteralEscaper.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2000-2009 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.
- */
-
-package com.intellij.psi.impl.source.tree.injected;
-
-import com.intellij.openapi.util.ProperTextRange;
-import com.intellij.lang.CodeDocumentationAwareCommenter;
-import com.intellij.lang.Commenter;
-import com.intellij.lang.LanguageCommenters;
-import com.intellij.openapi.util.TextRange;
-import com.intellij.psi.LiteralTextEscaper;
-import com.intellij.psi.impl.source.tree.PsiCommentImpl;
-import org.jetbrains.annotations.NotNull;
-
-/**
- * @author cdr
-*/
-public class CommentLiteralEscaper extends LiteralTextEscaper<PsiCommentImpl> {
- public CommentLiteralEscaper(PsiCommentImpl host) {
- super(host);
- }
-
- @Override
- public boolean decode(@NotNull final TextRange rangeInsideHost, @NotNull StringBuilder outChars) {
- ProperTextRange.assertProperRange(rangeInsideHost);
- outChars.append(myHost.getText(), rangeInsideHost.getStartOffset(), rangeInsideHost.getEndOffset());
- return true;
- }
-
- @Override
- public int getOffsetInHost(int offsetInDecoded, @NotNull final TextRange rangeInsideHost) {
- int offset = offsetInDecoded + rangeInsideHost.getStartOffset();
- if (offset < rangeInsideHost.getStartOffset()) offset = rangeInsideHost.getStartOffset();
- if (offset > rangeInsideHost.getEndOffset()) offset = rangeInsideHost.getEndOffset();
- return offset;
- }
-
- @Override
- public boolean isOneLine() {
- final Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(myHost.getLanguage());
- if (commenter instanceof CodeDocumentationAwareCommenter) {
- return myHost.getTokenType() == ((CodeDocumentationAwareCommenter) commenter).getLineCommentTokenType();
- }
- return false;
- }
-} \ No newline at end of file
diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedFileViewProvider.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedFileViewProvider.java
index f4a6d576e6b8..58a9463b755d 100644
--- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedFileViewProvider.java
+++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedFileViewProvider.java
@@ -61,7 +61,7 @@ public class InjectedFileViewProvider extends SingleRootFileViewProvider impleme
@NotNull Language language) {
super(psiManager, (VirtualFile)virtualFile, true, language);
myDocumentWindow = documentWindow;
- myProject = documentWindow.getShreds().get(0).getHost().getProject();
+ myProject = documentWindow.getShreds().getHostPointer().getProject();
}
@Override
diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedLanguageUtil.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedLanguageUtil.java
index fdc434d8d11a..647ace567d5d 100644
--- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedLanguageUtil.java
+++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedLanguageUtil.java
@@ -24,7 +24,6 @@ import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.editor.impl.EditorImpl;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
@@ -38,6 +37,7 @@ import com.intellij.psi.impl.PsiParameterizedCachedValue;
import com.intellij.psi.impl.source.DummyHolder;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.*;
+import com.intellij.testFramework.LightVirtualFile;
import com.intellij.util.containers.ConcurrentList;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
@@ -93,7 +93,12 @@ public class InjectedLanguageUtil {
public static Place getShreds(@NotNull FileViewProvider viewProvider) {
if (!(viewProvider instanceof InjectedFileViewProvider)) return null;
InjectedFileViewProvider myFileViewProvider = (InjectedFileViewProvider)viewProvider;
- return ((DocumentWindowImpl)myFileViewProvider.getDocument()).getShreds();
+ return getShreds(myFileViewProvider.getDocument());
+ }
+
+ @NotNull
+ public static Place getShreds(@NotNull DocumentWindow document) {
+ return ((DocumentWindowImpl)document).getShreds();
}
public static void enumerate(@NotNull DocumentWindow documentWindow,
@@ -162,6 +167,13 @@ public class InjectedLanguageUtil {
return getEditorForInjectedLanguageNoCommit(editor, file, offset);
}
+ public static Editor getEditorForInjectedLanguageNoCommit(@Nullable Editor editor, @Nullable Caret caret, @Nullable PsiFile file) {
+ if (editor == null || file == null || editor instanceof EditorWindow || caret == null) return editor;
+
+ PsiFile injectedFile = findInjectedPsiNoCommit(file, caret.getOffset());
+ return getInjectedEditorForInjectedFile(editor, caret, injectedFile);
+ }
+
public static Caret getCaretForInjectedLanguageNoCommit(@Nullable Caret caret, @Nullable PsiFile file) {
if (caret == null || file == null || caret instanceof InjectedCaret) return caret;
@@ -212,17 +224,21 @@ public class InjectedLanguageUtil {
@NotNull
public static Editor getInjectedEditorForInjectedFile(@NotNull Editor hostEditor, @Nullable final PsiFile injectedFile) {
+ return getInjectedEditorForInjectedFile(hostEditor, hostEditor.getCaretModel().getCurrentCaret(), injectedFile);
+ }
+
+ @NotNull
+ public static Editor getInjectedEditorForInjectedFile(@NotNull Editor hostEditor, @NotNull Caret hostCaret, @Nullable final PsiFile injectedFile) {
if (injectedFile == null || hostEditor instanceof EditorWindow || hostEditor.isDisposed()) return hostEditor;
Project project = hostEditor.getProject();
if (project == null) project = injectedFile.getProject();
Document document = PsiDocumentManager.getInstance(project).getDocument(injectedFile);
if (!(document instanceof DocumentWindowImpl)) return hostEditor;
DocumentWindowImpl documentWindow = (DocumentWindowImpl)document;
- SelectionModel selectionModel = hostEditor.getSelectionModel();
- if (selectionModel.hasSelection()) {
- int selstart = selectionModel.getSelectionStart();
+ if (hostCaret.hasSelection()) {
+ int selstart = hostCaret.getSelectionStart();
if (selstart != -1) {
- int selend = Math.max(selstart, selectionModel.getSelectionEnd());
+ int selend = Math.max(selstart, hostCaret.getSelectionEnd());
if (!documentWindow.containsRange(selstart, selend)) {
// selection spreads out the injected editor range
return hostEditor;
@@ -573,4 +589,29 @@ public class InjectedLanguageUtil {
});
return ref.get();
}
+
+ @Nullable
+ public static PsiLanguageInjectionHost findInjectionHost(@Nullable PsiElement psi) {
+ if (psi == null) return null;
+ PsiFile containingFile = psi.getContainingFile().getOriginalFile(); // * formatting
+ PsiElement fileContext = containingFile.getContext(); // * quick-edit-handler
+ if (fileContext instanceof PsiLanguageInjectionHost) return (PsiLanguageInjectionHost)fileContext;
+ Place shreds = getShreds(containingFile.getViewProvider()); // * injection-registrar
+ if (shreds == null) {
+ VirtualFile virtualFile = PsiUtilCore.getVirtualFile(containingFile);
+ if (virtualFile instanceof LightVirtualFile) {
+ virtualFile = ((LightVirtualFile)virtualFile).getOriginalFile(); // * dynamic files-from-text
+ }
+ if (virtualFile instanceof VirtualFileWindow) {
+ shreds = getShreds(((VirtualFileWindow)virtualFile).getDocumentWindow());
+ }
+ }
+ return shreds != null ? shreds.getHostPointer().getElement() : null;
+ }
+
+ @Nullable
+ public static PsiLanguageInjectionHost findInjectionHost(@Nullable VirtualFile virtualFile) {
+ return virtualFile instanceof VirtualFileWindow ?
+ getShreds(((VirtualFileWindow)virtualFile).getDocumentWindow()).getHostPointer().getElement() : null;
+ }
}
diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/MultiHostRegistrarImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/MultiHostRegistrarImpl.java
index 183af7374072..e520eea741be 100644
--- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/MultiHostRegistrarImpl.java
+++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/MultiHostRegistrarImpl.java
@@ -389,7 +389,7 @@ public class MultiHostRegistrarImpl implements MultiHostRegistrar, ModificationT
"\nLeaf texts concatenated:'"+ patcher.catLeafs +"';" +
"\nFile root: "+parsedNode+
"\nLanguage: "+parsedNode.getPsi().getLanguage()+
- "\nHost file: "+ shreds.get(0).getHost().getContainingFile().getVirtualFile()
+ "\nHost file: "+ shreds.getHostPointer().getVirtualFile()
;
DebugUtil.startPsiModification("injection leaf patching");
try {
diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/Place.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/Place.java
index afaf499b9bb9..f6be385077c2 100644
--- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/Place.java
+++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/Place.java
@@ -17,6 +17,7 @@
package com.intellij.psi.impl.source.tree.injected;
import com.intellij.psi.PsiLanguageInjectionHost;
+import com.intellij.psi.SmartPsiElementPointer;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;
@@ -30,6 +31,11 @@ public class Place extends SmartList<PsiLanguageInjectionHost.Shred> {
super(shreds);
}
+ @NotNull
+ public SmartPsiElementPointer<PsiLanguageInjectionHost> getHostPointer() {
+ return ((ShredImpl)get(0)).getSmartPointer();
+ }
+
public boolean isValid() {
for (PsiLanguageInjectionHost.Shred shred : this) {
if (!shred.isValid()) {
diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/ShredImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/ShredImpl.java
index aea41ab16f72..5c60a1c2254f 100644
--- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/ShredImpl.java
+++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/ShredImpl.java
@@ -45,6 +45,7 @@ class ShredImpl implements PsiLanguageInjectionHost.Shred {
assert relevantRangeInHost.isValid();
}
+ @NotNull
public SmartPsiElementPointer<PsiLanguageInjectionHost> getSmartPointer() {
return hostElementPointer;
}