Search in sources :

Example 41 with FileTemplate

use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.

the class JavaTestGenerator method createTestClassFromCodeTemplate.

private static PsiClass createTestClassFromCodeTemplate(final CreateTestDialog d, final FileTemplateDescriptor fileTemplateDescriptor, final PsiDirectory targetDirectory) {
    final String templateName = fileTemplateDescriptor.getFileName();
    final FileTemplate fileTemplate = FileTemplateManager.getInstance(targetDirectory.getProject()).getCodeTemplate(templateName);
    final Properties defaultProperties = FileTemplateManager.getInstance(targetDirectory.getProject()).getDefaultProperties();
    Properties properties = new Properties(defaultProperties);
    properties.setProperty(FileTemplate.ATTRIBUTE_NAME, d.getClassName());
    final PsiClass targetClass = d.getTargetClass();
    if (targetClass != null && targetClass.isValid()) {
        properties.setProperty(FileTemplate.ATTRIBUTE_CLASS_NAME, targetClass.getQualifiedName());
    }
    try {
        final PsiElement psiElement = FileTemplateUtil.createFromTemplate(fileTemplate, templateName, properties, targetDirectory);
        if (psiElement instanceof PsiClass) {
            return (PsiClass) psiElement;
        }
        return null;
    } catch (Exception e) {
        return null;
    }
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) Properties(java.util.Properties) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 42 with FileTemplate

use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.

the class JavaSurroundWithTest method testSurroundWithTryCatchProperties.

public void testSurroundWithTryCatchProperties() {
    FileTemplate template = FileTemplateManager.getInstance(getProject()).getCodeTemplate(JavaTemplateUtil.TEMPLATE_CATCH_BODY);
    String old = template.getText();
    template.setText("// ${DS} \n" + "${EXCEPTION}.printStackTrace();");
    try {
        doTest(new JavaWithTryCatchSurrounder());
    } finally {
        template.setText(old);
    }
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate)

Example 43 with FileTemplate

use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.

the class CreateFromTemplateGroup method update.

@Override
public void update(AnActionEvent e) {
    super.update(e);
    Presentation presentation = e.getPresentation();
    Project project = e.getProject();
    if (project != null) {
        FileTemplate[] allTemplates = FileTemplateManager.getInstance(project).getAllTemplates();
        for (FileTemplate template : allTemplates) {
            if (canCreateFromTemplate(e, template)) {
                presentation.setEnabled(true);
                return;
            }
        }
    }
    presentation.setEnabled(false);
}
Also used : Project(com.intellij.openapi.project.Project) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate)

Example 44 with FileTemplate

use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.

the class FileTemplateManagerImpl method validateRecentNames.

private void validateRecentNames() {
    final Collection<FileTemplateBase> allTemplates = getSettings().getDefaultTemplatesManager().getAllTemplates(false);
    final List<String> allNames = new ArrayList<>(allTemplates.size());
    for (FileTemplate fileTemplate : allTemplates) {
        allNames.add(fileTemplate.getName());
    }
    myState.validateNames(allNames);
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate)

Example 45 with FileTemplate

use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.

the class GroovyGeneratePropertyMissingHandler method generateMemberPrototypes.

@NotNull
@Override
protected List<? extends GenerationInfo> generateMemberPrototypes(PsiClass aClass, ClassMember[] members) throws IncorrectOperationException {
    final String templName = JavaTemplateUtil.TEMPLATE_FROM_USAGE_METHOD_BODY;
    final FileTemplate template = FileTemplateManager.getInstance(aClass.getProject()).getCodeTemplate(templName);
    final GrMethod getter = genGetter(aClass, template);
    final GrMethod setter = genSetter(aClass, template);
    final ArrayList<GroovyGenerationInfo<GrMethod>> result = new ArrayList<>();
    if (getter != null)
        result.add(new GroovyGenerationInfo<>(getter, true));
    if (setter != null)
        result.add(new GroovyGenerationInfo<>(setter, true));
    return result;
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) GroovyGenerationInfo(org.jetbrains.plugins.groovy.actions.generate.GroovyGenerationInfo) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)66 FileTemplateManager (com.intellij.ide.fileTemplates.FileTemplateManager)20 Project (com.intellij.openapi.project.Project)13 IOException (java.io.IOException)12 PsiFile (com.intellij.psi.PsiFile)10 Properties (java.util.Properties)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 IncorrectOperationException (com.intellij.util.IncorrectOperationException)8 PsiDirectory (com.intellij.psi.PsiDirectory)7 NotNull (org.jetbrains.annotations.NotNull)7 PsiElement (com.intellij.psi.PsiElement)6 Module (com.intellij.openapi.module.Module)5 File (java.io.File)5 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)5 Nullable (org.jetbrains.annotations.Nullable)4 Editor (com.intellij.openapi.editor.Editor)3 ConfigurationException (com.intellij.openapi.options.ConfigurationException)3 ArrayList (java.util.ArrayList)3 Pattern (java.util.regex.Pattern)3 ReformatCodeProcessor (com.intellij.codeInsight.actions.ReformatCodeProcessor)2