* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package com.intellij.codeInsight.template.impl;
-
import com.google.common.annotations.VisibleForTesting;
import com.intellij.codeInsight.template.TemplateContextType;
import com.intellij.openapi.util.WriteExternalException;
// used during initialization => no sync
@VisibleForTesting
- public void readTemplateContext(Element element) {
+ public void readTemplateContext(@NotNull Element element) {
for (Element option : element.getChildren("option")) {
String name = option.getAttributeValue("name");
String value = option.getAttributeValue("value");
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.SmartList;
-import com.intellij.util.containers.IntArrayList;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
private boolean myIsInline = false;
-
-
public TemplateImpl(@NotNull String key, @NotNull String group) {
this(key, null, group);
toParseSegments = false;
myGroupName = group;
}
-
@Override
public void addTextSegment(@NotNull String text) {
text = StringUtil.convertLineSeparators(text);
for (Property property : Property.values()) {
boolean value = another.getValue(property);
if (value != Template.getDefaultValue(property)) {
- setValue(property, value);
+ setValue(property, true);
}
}
for (Variable variable : another.myVariables) {
return isDeactivated;
}
- @NotNull public TemplateContext getTemplateContext() {
+ @NotNull
+ public TemplateContext getTemplateContext() {
return myTemplateContext;
}
return -1;
}
- public IntArrayList getVariableSegmentNumbers(String variableName) {
- IntArrayList result = new IntArrayList();
- parseSegments();
- for (int i = 0; i < mySegments.size(); i++) {
- Segment segment = mySegments.get(i);
- if (segment.name.equals(variableName)) {
- result.add(i);
- }
- }
- return result;
- }
-
@NotNull
@Override
public String getTemplateText() {
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.WriteExternalException;
+import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.JdomKt;
import com.intellij.util.SmartList;
import com.intellij.util.containers.MultiMap;
}
}
- private static TemplateImpl createTemplate(String key, String string, String group, String description, String shortcut, String id) {
+ @NotNull
+ private static TemplateImpl createTemplate(@NotNull String key, String string, @NotNull String group, String description, @Nullable String shortcut, String id) {
TemplateImpl template = new TemplateImpl(key, string, group);
template.setId(id);
template.setDescription(description);
}
String groupName = element.getAttributeValue(GROUP);
- if (groupName == null || groupName.isEmpty()) groupName = defGroupName;
+ if (StringUtil.isEmpty(groupName)) {
+ groupName = defGroupName;
+ }
TemplateGroup result = new TemplateGroup(groupName, element.getAttributeValue("REPLACE"));
template = readTemplateFromElement(groupName, child, classLoader);
}
catch (Exception e) {
- LOG.info("failed to load template " + element.getAttributeValue(NAME), e);
+ LOG.warn("failed to load template " + element.getAttributeValue(NAME), e);
continue;
}
else {
description = element.getAttributeValue(DESCRIPTION);
}
+
String shortcut = element.getAttributeValue(SHORTCUT);
TemplateImpl template = createTemplate(name, value, groupName, description, shortcut, id);
element.setAttribute(VALUE, template.getString());
if (template.getShortcutChar() == TAB_CHAR) {
element.setAttribute(SHORTCUT, TAB);
- } else if (template.getShortcutChar() == ENTER_CHAR) {
+ }
+ else if (template.getShortcutChar() == ENTER_CHAR) {
element.setAttribute(SHORTCUT, ENTER);
- } else if (template.getShortcutChar() == SPACE_CHAR) {
+ }
+ else if (template.getShortcutChar() == SPACE_CHAR) {
element.setAttribute(SHORTCUT, SPACE);
}
if (template.getDescription() != null) {
element.setAttribute(TO_REFORMAT, Boolean.toString(template.isToReformat()));
element.setAttribute(TO_SHORTEN_FQ_NAMES, Boolean.toString(template.isToShortenLongNames()));
if (template.getValue(Template.Property.USE_STATIC_IMPORT_IF_POSSIBLE)
- != Template.getDefaultValue(Template.Property.USE_STATIC_IMPORT_IF_POSSIBLE))
- {
+ != Template.getDefaultValue(Template.Property.USE_STATIC_IMPORT_IF_POSSIBLE)) {
element.setAttribute(USE_STATIC_IMPORT, Boolean.toString(template.getValue(Template.Property.USE_STATIC_IMPORT_IF_POSSIBLE)));
}
if (template.isDeactivated()) {
Element contextElement = new Element(CONTEXT);
template.getTemplateContext().writeTemplateContext(contextElement);
element.addContent(contextElement);
- } catch (WriteExternalException ignore) {
+ }
+ catch (WriteExternalException e) {
+ LOG.warn(e);
}
return element;
}