diff --git a/java/java-impl/src/com/intellij/codeInsight/template/impl/CodeBlockReformattingProcessor.java b/java/java-impl/src/com/intellij/codeInsight/template/impl/CodeBlockReformattingProcessor.java index b038422270f2..e74b93ceed7e 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/impl/CodeBlockReformattingProcessor.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/impl/CodeBlockReformattingProcessor.java @@ -1,21 +1,8 @@ -/* - * Copyright 2000-2017 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-2018 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.codeInsight.template.impl; import com.intellij.codeInsight.template.Template; +import com.intellij.injected.editor.EditorWindow; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.RangeMarker; @@ -43,7 +30,8 @@ public class CodeBlockReformattingProcessor implements TemplateOptionalProcessor if (!template.isToReformat()) return; PsiDocumentManager.getInstance(project).commitDocument(document); - PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project); + PsiFile file = editor instanceof EditorWindow ? ((EditorWindow)editor).getInjectedFile() + : PsiUtilBase.getPsiFileInEditor(editor, project); if (!(file instanceof PsiJavaFile)) return; CharSequence text = document.getImmutableCharSequence(); diff --git a/java/java-impl/src/com/intellij/codeInsight/template/impl/ShortenFQNamesProcessor.java b/java/java-impl/src/com/intellij/codeInsight/template/impl/ShortenFQNamesProcessor.java index f300836b2cd6..a9bb38e3f543 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/impl/ShortenFQNamesProcessor.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/impl/ShortenFQNamesProcessor.java @@ -1,22 +1,9 @@ -/* - * 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. - */ +// Copyright 2000-2018 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.codeInsight.template.impl; import com.intellij.codeInsight.CodeInsightBundle; import com.intellij.codeInsight.template.Template; +import com.intellij.injected.editor.EditorWindow; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.RangeMarker; @@ -36,7 +23,8 @@ public class ShortenFQNamesProcessor implements TemplateOptionalProcessor, DumbA if (!template.isToShortenLongNames()) return; PsiDocumentManager.getInstance(project).commitDocument(document); - PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project); + PsiFile file = editor instanceof EditorWindow ? ((EditorWindow)editor).getInjectedFile() + : PsiUtilBase.getPsiFileInEditor(editor, project); if (file == null) { throw new IllegalStateException(editor + " " + editor.getDocument()); } diff --git a/java/java-impl/src/com/intellij/codeInsight/template/impl/ShortenToStaticImportProcessor.java b/java/java-impl/src/com/intellij/codeInsight/template/impl/ShortenToStaticImportProcessor.java index f594e9563078..ac97fe42d477 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/impl/ShortenToStaticImportProcessor.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/impl/ShortenToStaticImportProcessor.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2014 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-2018 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.codeInsight.template.impl; import com.intellij.codeInsight.CodeInsightBundle; @@ -22,6 +8,7 @@ import com.intellij.codeInsight.template.JavaCodeContextType; import com.intellij.codeInsight.template.JavaCommentContextType; import com.intellij.codeInsight.template.Template; import com.intellij.codeInsight.template.TemplateContextType; +import com.intellij.injected.editor.EditorWindow; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.RangeMarker; @@ -59,7 +46,8 @@ public class ShortenToStaticImportProcessor implements TemplateOptionalProcessor } PsiDocumentManager.getInstance(project).commitDocument(document); - final PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project); + PsiFile file = editor instanceof EditorWindow ? ((EditorWindow)editor).getInjectedFile() + : PsiUtilBase.getPsiFileInEditor(editor, project); if (file == null) { return; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/template/GroovyShortenFQNamesProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/template/GroovyShortenFQNamesProcessor.java index 1ab08580abb7..5aec48592e45 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/template/GroovyShortenFQNamesProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/template/GroovyShortenFQNamesProcessor.java @@ -1,24 +1,11 @@ -/* - * Copyright 2000-2017 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-2018 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 org.jetbrains.plugins.groovy.template; import com.intellij.codeInsight.CodeInsightBundle; import com.intellij.codeInsight.template.Template; import com.intellij.codeInsight.template.impl.TemplateContext; import com.intellij.codeInsight.template.impl.TemplateOptionalProcessor; +import com.intellij.injected.editor.EditorWindow; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.RangeMarker; @@ -46,11 +33,11 @@ public class GroovyShortenFQNamesProcessor implements TemplateOptionalProcessor, if (!template.isToShortenLongNames()) return; PsiDocumentManager.getInstance(project).commitDocument(document); - final PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project); + PsiFile file = editor instanceof EditorWindow ? ((EditorWindow)editor).getInjectedFile() + : PsiUtilBase.getPsiFileInEditor(editor, project); if (file instanceof GroovyFile) { - DumbService.getInstance(project).withAlternativeResolveEnabled(() -> { - JavaCodeStyleManager.getInstance(project).shortenClassReferences(file, templateRange.getStartOffset(),templateRange.getEndOffset()); - }); + DumbService.getInstance(project).withAlternativeResolveEnabled(() -> JavaCodeStyleManager.getInstance(project) + .shortenClassReferences(file, templateRange.getStartOffset(), templateRange.getEndOffset())); } PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document); }