diff options
Diffstat (limited to 'xml/impl/src/com/intellij/codeInsight')
17 files changed, 180 insertions, 32 deletions
diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/EmmetException.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/EmmetException.java new file mode 100644 index 000000000000..0105408ea790 --- /dev/null +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/EmmetException.java @@ -0,0 +1,22 @@ +/* + * 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. + */ +package com.intellij.codeInsight.template.emmet; + +public class EmmetException extends Exception { + public EmmetException() { + super("Cannot expand emmet abbreviation: output is too big"); + } +} diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/EmmetPreviewHint.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/EmmetPreviewHint.java index edde5a83a6d6..f9777958e689 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/EmmetPreviewHint.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/EmmetPreviewHint.java @@ -147,7 +147,7 @@ public class EmmetPreviewHint extends LightweightHint implements Disposable { EditorFactory editorFactory = EditorFactory.getInstance(); Document document = editorFactory.createDocument(templateText); final EditorEx previewEditor = (EditorEx)editorFactory.createEditor(document, parentEditor.getProject(), fileType, true); - EditorSettings settings = previewEditor.getSettings(); + final EditorSettings settings = previewEditor.getSettings(); settings.setLineNumbersShown(false); settings.setAdditionalLinesCount(1); settings.setAdditionalColumnsCount(1); @@ -172,7 +172,7 @@ public class EmmetPreviewHint extends LightweightHint implements Disposable { int maxWidth = (int)parentEditorSize.getWidth() / 3; int maxHeight = (int)parentEditorSize.getHeight() / 2; Dimension contentSize = previewEditor.getContentSize(); - return new Dimension(maxWidth > contentSize.getWidth() ? (int)size.getWidth() : maxWidth, + return new Dimension(maxWidth > contentSize.getWidth() && !settings.isUseSoftWraps() ? (int)size.getWidth() : maxWidth, maxHeight > contentSize.getHeight() ? (int)size.getHeight() : maxHeight); } diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/EmmetPreviewUtil.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/EmmetPreviewUtil.java index af106929bcea..a82ab071846b 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/EmmetPreviewUtil.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/EmmetPreviewUtil.java @@ -61,12 +61,19 @@ public class EmmetPreviewUtil { if (generator != null && generator instanceof XmlZenCodingGenerator) { final String templatePrefix = new ZenCodingTemplate().computeTemplateKeyWithoutContextChecking(callback); if (templatePrefix != null) { - ZenCodingTemplate.expand(templatePrefix, callback, generator, Collections.<ZenCodingFilter>emptyList(), expandPrimitiveAbbreviations, 0); - TemplateImpl template = generatedTemplate.get(); - String templateText = template != null ? template.getTemplateText() : null; - if (!StringUtil.isEmpty(templateText)) { - return template.isToReformat() ? reformatTemplateText(file, templateText) : templateText; + try { + ZenCodingTemplate.expand(templatePrefix, callback, generator, Collections.<ZenCodingFilter>emptyList(), + expandPrimitiveAbbreviations, 0); + TemplateImpl template = generatedTemplate.get(); + String templateText = template != null ? template.getTemplateText() : null; + if (!StringUtil.isEmpty(templateText)) { + return template.isToReformat() ? reformatTemplateText(file, templateText) : templateText; + } } + catch (EmmetException e) { + return e.getMessage(); + } + } } } diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/ZenCodingTemplate.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/ZenCodingTemplate.java index b0d623683912..f27903a49b5b 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/ZenCodingTemplate.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/ZenCodingTemplate.java @@ -52,6 +52,7 @@ import com.intellij.patterns.StandardPatterns; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.refactoring.util.CommonRefactoringUtil; import com.intellij.ui.*; import com.intellij.util.containers.ContainerUtil; import com.intellij.xml.XmlBundle; @@ -124,7 +125,12 @@ public class ZenCodingTemplate extends CustomLiveTemplateBase { public void expand(@NotNull String key, @NotNull CustomTemplateCallback callback) { ZenCodingGenerator defaultGenerator = findApplicableDefaultGenerator(callback.getContext(), false); assert defaultGenerator != null; - expand(key, callback, defaultGenerator, Collections.<ZenCodingFilter>emptyList(), true, Registry.intValue("emmet.segments.limit")); + try { + expand(key, callback, defaultGenerator, Collections.<ZenCodingFilter>emptyList(), true, Registry.intValue("emmet.segments.limit")); + } + catch (EmmetException e) { + CommonRefactoringUtil.showErrorHint(callback.getProject(), callback.getEditor(), e.getMessage(), "Emmet error", ""); + } } @Nullable @@ -182,7 +188,7 @@ public class ZenCodingTemplate extends CustomLiveTemplateBase { public static void expand(@NotNull String key, @NotNull CustomTemplateCallback callback, @NotNull ZenCodingGenerator defaultGenerator, @NotNull Collection<? extends ZenCodingFilter> extraFilters, - boolean expandPrimitiveAbbreviations, int segmentsLimit) { + boolean expandPrimitiveAbbreviations, int segmentsLimit) throws EmmetException { final ZenCodingNode node = parse(key, callback, defaultGenerator, null); if (node == null) { return; @@ -204,6 +210,8 @@ public class ZenCodingTemplate extends CustomLiveTemplateBase { List<ZenCodingFilter> filters = getFilters(node, context); filters.addAll(extraFilters); + checkTemplateOutputLength(node, callback); + callback.deleteTemplateKey(key); expand(node, generator, filters, null, callback, expandPrimitiveAbbreviations, segmentsLimit); } @@ -212,7 +220,10 @@ public class ZenCodingTemplate extends CustomLiveTemplateBase { ZenCodingGenerator generator, List<ZenCodingFilter> filters, String surroundedText, - CustomTemplateCallback callback, boolean expandPrimitiveAbbreviations, int segmentsLimit) { + CustomTemplateCallback callback, boolean expandPrimitiveAbbreviations, int segmentsLimit) throws EmmetException { + + checkTemplateOutputLength(node, callback); + if (surroundedText != null) { surroundedText = surroundedText.trim(); } @@ -282,6 +293,13 @@ public class ZenCodingTemplate extends CustomLiveTemplateBase { }); } + private static void checkTemplateOutputLength(ZenCodingNode node, CustomTemplateCallback callback) throws EmmetException { + int predictedOutputLength = node.getApproximateOutputLength(callback); + if (predictedOutputLength > 15 * 1024) { + throw new EmmetException(); + } + } + private static boolean isPrimitiveNode(@NotNull ZenCodingNode node) { if (node instanceof TemplateNode) { final TemplateToken token = ((TemplateNode)node).getTemplateToken(); @@ -434,7 +452,12 @@ public class ZenCodingTemplate extends CustomLiveTemplateBase { EditorModificationUtil.deleteSelectedText(callback.getEditor()); PsiDocumentManager.getInstance(callback.getProject()).commitAllDocuments(); - expand(node, generator, filters, selection, callback, true, Registry.intValue("emmet.segments.limit")); + try { + expand(node, generator, filters, selection, callback, true, Registry.intValue("emmet.segments.limit")); + } + catch (EmmetException e) { + CommonRefactoringUtil.showErrorHint(callback.getProject(), callback.getEditor(), e.getMessage(), "Emmet error", ""); + } } } }); @@ -509,7 +532,12 @@ public class ZenCodingTemplate extends CustomLiveTemplateBase { if (!regularTemplateWithSamePrefixExists) { // exclude perfect matches with existing templates because LiveTemplateCompletionContributor handles it final Collection<SingleLineEmmetFilter> extraFilters = ContainerUtil.newLinkedList(new SingleLineEmmetFilter()); - expand(templatePrefix, callback, generator, extraFilters, false, 0); + try { + expand(templatePrefix, callback, generator, extraFilters, false, 0); + } + catch (EmmetException e) { + generatedTemplate.set(null); + } if (!generatedTemplate.isNull()) { final TemplateImpl template = generatedTemplate.get(); template.setKey(templatePrefix); diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/generators/LoremGenerator.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/generators/LoremGenerator.java index a5f4aeef5f0d..37b6d4b15b53 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/generators/LoremGenerator.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/generators/LoremGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -16,6 +16,7 @@ package com.intellij.codeInsight.template.emmet.generators; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.ArrayUtil; import java.util.*; @@ -145,7 +146,7 @@ public class LoremGenerator { result.add(words[i]); } - return result.toArray(new String[result.size()]); + return ArrayUtil.toStringArray(result); } private char choice(String values) { diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/generators/XmlZenCodingGenerator.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/generators/XmlZenCodingGenerator.java index ef57f5ed4e49..c1732a306120 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/generators/XmlZenCodingGenerator.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/generators/XmlZenCodingGenerator.java @@ -19,6 +19,8 @@ import com.intellij.codeInsight.template.CustomTemplateCallback; import com.intellij.codeInsight.template.emmet.ZenCodingTemplate; import com.intellij.codeInsight.template.emmet.tokens.TemplateToken; import com.intellij.codeInsight.template.impl.TemplateImpl; +import com.intellij.diagnostic.AttachmentFactory; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.util.Couple; import com.intellij.openapi.util.TextRange; @@ -109,6 +111,11 @@ public abstract class XmlZenCodingGenerator extends ZenCodingGenerator { prevVisibleLeaf = PsiTreeUtil.prevVisibleLeaf(prevVisibleLeaf); } + if (startOffset < 0 || currentOffset > documentText.length() || currentOffset < startOffset) { + Logger.getInstance(getClass()).error("Error while calculating emmet abbreviation. Offset: " + currentOffset + "; Start: " + startOffset, + AttachmentFactory.createAttachment(editor.getDocument())); + return null; + } String key = computeKey(documentText.subSequence(startOffset, currentOffset)); return !StringUtil.isEmpty(key) && ZenCodingTemplate.checkTemplateKey(key, callback, this) ? key : null; } diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/AddOperationNode.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/AddOperationNode.java index c63375ef6808..12f2610962c4 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/AddOperationNode.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/AddOperationNode.java @@ -65,4 +65,9 @@ public class AddOperationNode extends ZenCodingNode { public String toString() { return "+"; } + + @Override + public int getApproximateOutputLength(CustomTemplateCallback callback) { + return myLeftOperand.getApproximateOutputLength(callback) + myRightOperand.getApproximateOutputLength(callback); + } } diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/ClimbUpOperationNode.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/ClimbUpOperationNode.java index 1648a36f6408..28cc0a8c1533 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/ClimbUpOperationNode.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/ClimbUpOperationNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -71,4 +71,9 @@ public class ClimbUpOperationNode extends ZenCodingNode { public String toString() { return "^"; } + + @Override + public int getApproximateOutputLength(CustomTemplateCallback callback) { + return myLeftOperand.getApproximateOutputLength(callback) + myRightOperand.getApproximateOutputLength(callback); + } } diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/FilterNode.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/FilterNode.java index 2de1c998e140..2ac50c7438aa 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/FilterNode.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/FilterNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * 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. @@ -17,6 +17,7 @@ package com.intellij.codeInsight.template.emmet.nodes; import com.intellij.codeInsight.template.CustomTemplateCallback; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -50,6 +51,11 @@ public class FilterNode extends ZenCodingNode { } @Override + public int getApproximateOutputLength(@Nullable CustomTemplateCallback callback) { + return myNode.getApproximateOutputLength(callback); + } + + @Override public String toString() { return "Filter(" + myFilter + ")"; } diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/LoremNode.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/LoremNode.java index 7beab3c721b4..542af14d8ec0 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/LoremNode.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/LoremNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -21,6 +21,7 @@ import com.intellij.codeInsight.template.emmet.tokens.TemplateToken; import com.intellij.codeInsight.template.impl.TemplateImpl; import com.intellij.openapi.util.Couple; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; @@ -54,6 +55,12 @@ public class LoremNode extends ZenCodingNode { } @Override + public int getApproximateOutputLength(@Nullable CustomTemplateCallback callback) { + + return myWordsCount * 7; + } + + @Override public String toString() { return "Lorem(" + myWordsCount + ")"; } diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/MoreOperationNode.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/MoreOperationNode.java index fa8021565511..0a1bea140d6b 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/MoreOperationNode.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/MoreOperationNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * 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. @@ -19,6 +19,7 @@ import com.intellij.codeInsight.template.CustomTemplateCallback; import com.intellij.openapi.util.text.LineTokenizer; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -49,6 +50,12 @@ public class MoreOperationNode extends ZenCodingNode { return ContainerUtil.newLinkedList(myLeftOperand, myRightOperand); } + @Override + public int getApproximateOutputLength(@Nullable CustomTemplateCallback callback) { + int mul = myLeftOperand instanceof MulOperationNode ? ((MulOperationNode)myLeftOperand).getRightOperand() : 1; + return myLeftOperand.getApproximateOutputLength(callback) + (myRightOperand.getApproximateOutputLength(callback) * mul); + } + @NotNull @Override public List<GenerationNode> expand(int numberInIteration, diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/MulOperationNode.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/MulOperationNode.java index ec9eee193c80..1934d9e07099 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/MulOperationNode.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/MulOperationNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * 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. @@ -17,6 +17,7 @@ package com.intellij.codeInsight.template.emmet.nodes; import com.intellij.codeInsight.template.CustomTemplateCallback; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -55,6 +56,11 @@ public class MulOperationNode extends ZenCodingNode { } @Override + public int getApproximateOutputLength(@Nullable CustomTemplateCallback callback) { + return myLeftOperand.getApproximateOutputLength(callback) * myRightOperand; + } + + @Override public String toString() { return "*"; } diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/TemplateNode.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/TemplateNode.java index 685f0b396899..28871e1069d6 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/TemplateNode.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/TemplateNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -60,21 +60,19 @@ public class TemplateNode extends ZenCodingNode { String templateKey = templateToken.getKey(); if (myGenerator != null && StringUtil.containsChar(templateKey, '$') && callback.findApplicableTemplate(templateKey) == null) { String newTemplateKey = ZenCodingUtil.replaceMarkers(templateKey, numberInIteration, totalIterations, surroundedText); - TemplateToken newTemplateToken = new TemplateToken(newTemplateKey, - templateToken.getAttribute2Value()); - + TemplateToken newTemplateToken = new TemplateToken(newTemplateKey, templateToken.getAttribute2Value()); TemplateImpl template = myGenerator.createTemplateByKey(newTemplateKey); if (template != null) { template.setDeactivated(true); newTemplateToken.setTemplate(template, callback); templateToken = newTemplateToken; } - } + } - GenerationNode node = new GenerationNode(templateToken, numberInIteration, totalIterations, - surroundedText, insertSurroundedTextAtTheEnd, parent); - return Arrays.asList(node); -} + GenerationNode node = new GenerationNode(templateToken, numberInIteration, totalIterations, + surroundedText, insertSurroundedTextAtTheEnd, parent); + return Arrays.asList(node); + } @Override public String toString() { @@ -85,4 +83,17 @@ public class TemplateNode extends ZenCodingNode { } return "Template(" + result + ")"; } + + @Override + public int getApproximateOutputLength(@Nullable CustomTemplateCallback callback) { + TemplateImpl template = myTemplateToken.getTemplate(); + if (template != null) { + int result = template.getTemplateText().length(); + for (Couple<String> attribute : myTemplateToken.getAttribute2Value()) { + result += attribute.first.length() + attribute.second.length() + 4; //plus space, eq, quotes + } + return result; + } + return 0; + } } diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/TextNode.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/TextNode.java index e47de7a937cc..d619387ecf31 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/TextNode.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/TextNode.java @@ -1,3 +1,18 @@ +/* + * 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. + */ package com.intellij.codeInsight.template.emmet.nodes; import com.intellij.codeInsight.template.CustomTemplateCallback; @@ -6,6 +21,7 @@ import com.intellij.codeInsight.template.emmet.tokens.TemplateToken; import com.intellij.codeInsight.template.emmet.tokens.TextToken; import com.intellij.codeInsight.template.impl.TemplateImpl; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; @@ -45,6 +61,11 @@ public class TextNode extends ZenCodingNode { } @Override + public int getApproximateOutputLength(@Nullable CustomTemplateCallback callback) { + return myText.length(); + } + + @Override public String toString() { return "Text(" + myText + ")"; } diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/UnaryMulOperationNode.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/UnaryMulOperationNode.java index 78eb446d1f59..96e1e2ec99ba 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/UnaryMulOperationNode.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/UnaryMulOperationNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * 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. @@ -18,6 +18,7 @@ package com.intellij.codeInsight.template.emmet.nodes; import com.intellij.codeInsight.template.CustomTemplateCallback; import com.intellij.openapi.util.text.LineTokenizer; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -43,7 +44,7 @@ public class UnaryMulOperationNode extends ZenCodingNode { CustomTemplateCallback callback, boolean insertSurroundedTextAtTheEnd, GenerationNode parent) { if (surroundedText == null) { - return myOperand.expand(numberInIteration, totalIterations, surroundedText, callback, insertSurroundedTextAtTheEnd, parent); + return myOperand.expand(numberInIteration, totalIterations, null, callback, insertSurroundedTextAtTheEnd, parent); } String[] lines = LineTokenizer.tokenize(surroundedText, false); List<GenerationNode> result = new ArrayList<GenerationNode>(); @@ -54,6 +55,11 @@ public class UnaryMulOperationNode extends ZenCodingNode { } @Override + public int getApproximateOutputLength(@Nullable CustomTemplateCallback callback) { + return myOperand.getApproximateOutputLength(callback); + } + + @Override public String toString() { return "*"; } diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/ZenCodingNode.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/ZenCodingNode.java index 550d05d5d186..d246f40007f4 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/ZenCodingNode.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/ZenCodingNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * 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. @@ -17,6 +17,7 @@ package com.intellij.codeInsight.template.emmet.nodes; import com.intellij.codeInsight.template.CustomTemplateCallback; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; @@ -35,4 +36,6 @@ public abstract class ZenCodingNode { public List<ZenCodingNode> getChildren() { return Collections.emptyList(); } + + public abstract int getApproximateOutputLength(@Nullable CustomTemplateCallback callback); } diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/ZenEmptyNode.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/ZenEmptyNode.java index 9b92681068cd..9282d36f1927 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/ZenEmptyNode.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/ZenEmptyNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -17,6 +17,7 @@ package com.intellij.codeInsight.template.emmet.nodes; import com.intellij.codeInsight.template.CustomTemplateCallback; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; @@ -39,6 +40,11 @@ public class ZenEmptyNode extends ZenCodingNode { } @Override + public int getApproximateOutputLength(@Nullable CustomTemplateCallback callback) { + return 0; + } + + @Override public String toString() { return "EMPTY_NODE"; } |