mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
enabling live templates for java files
This commit is contained in:
@@ -24,6 +24,7 @@ import com.intellij.ide.fileTemplates.FileTemplate;
|
||||
import com.intellij.ide.fileTemplates.FileTemplateManager;
|
||||
import com.intellij.ide.fileTemplates.FileTemplateUtil;
|
||||
import com.intellij.ide.fileTemplates.JavaTemplateUtil;
|
||||
import com.intellij.ide.fileTemplates.actions.CreateFromTemplateActionBase;
|
||||
import com.intellij.ide.fileTemplates.ui.CreateFromTemplateDialog;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -160,6 +161,9 @@ public class JavaDirectoryServiceImpl extends CoreJavaDirectoryService {
|
||||
if (classes.length < 1) {
|
||||
throw new IncorrectOperationException(getIncorrectTemplateMessage(templateName, project));
|
||||
}
|
||||
if (template.isLiveTemplateEnabled()) {
|
||||
CreateFromTemplateActionBase.startLiveTemplate(file);
|
||||
}
|
||||
return classes[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package com.intellij.java.ide.actions
|
||||
|
||||
import com.intellij.ide.fileTemplates.FileTemplateManager
|
||||
import com.intellij.psi.JavaDirectoryService
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
|
||||
class CreateClassActionTest: LightCodeInsightFixtureTestCase() {
|
||||
|
||||
fun testLiveTemplate() {
|
||||
val dir = myFixture.tempDirFixture.findOrCreateDir("foo")
|
||||
val psiDirectory = PsiManager.getInstance(project).findDirectory(dir)
|
||||
val template = FileTemplateManager.getInstance(project).addTemplate("fooBar", "java")
|
||||
template.text = "public class \${NAME} { #[[\$Title$]]# } "
|
||||
template.isLiveTemplateEnabled = true
|
||||
val clazz = JavaDirectoryService.getInstance().createClass(psiDirectory!!, "Bar", template.name)
|
||||
assertEquals("public class Bar {\n Title\n}", clazz.text)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user