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);
   }
 }
Exemplo n.º 2
0
 private void registerScalaScriptTemplate() {
   String templateText = ScalaBundle.message("template.file.text");
   if (FileTemplateManager.getInstance().getTemplate(SCALA_FILE_TEMPLATE) == null) {
     FileTemplate scalaTemplate =
         FileTemplateManager.getInstance()
             .addTemplate(
                 SCALA_FILE_TEMPLATE, ScalaFileType.SCALA_FILE_TYPE.getDefaultExtension());
     ((FileTemplateImpl) scalaTemplate).setInternal(true);
     scalaTemplate.setText(templateText);
   }
 }
 @Override
 public void apply() throws ConfigurationException {
   if (myTemplate != null) {
     myTemplate.setText(myTemplateEditor.getDocument().getText());
     String name = myNameField.getText();
     String extension = myExtensionField.getText();
     int lastDotIndex = extension.lastIndexOf(".");
     if (lastDotIndex >= 0) {
       name += extension.substring(0, lastDotIndex + 1);
       extension = extension.substring(lastDotIndex + 1);
     }
     if (name.length() == 0 || !isValidFilename(name + "." + extension)) {
       throw new ConfigurationException(
           IdeBundle.message("error.invalid.template.file.name.or.extension"));
     }
     myTemplate.setName(name);
     myTemplate.setExtension(extension);
     myTemplate.setReformatCode(myAdjustBox.isSelected());
   }
   myModified = false;
 }