From a545cf2965106a0b7f1cab55b031e00df85f1a42 Mon Sep 17 00:00:00 2001 From: Rustam Vishnyakov Date: Wed, 31 Aug 2016 18:20:50 +0300 Subject: [PATCH] Remove unused WrapImpl ID (fixes EA-86397) --- .../formatting/FormatInfoPrinter.java | 107 ------------------ .../src/com/intellij/formatting/WrapImpl.java | 17 +-- 2 files changed, 3 insertions(+), 121 deletions(-) delete mode 100644 platform/lang-impl/src/com/intellij/formatting/FormatInfoPrinter.java diff --git a/platform/lang-impl/src/com/intellij/formatting/FormatInfoPrinter.java b/platform/lang-impl/src/com/intellij/formatting/FormatInfoPrinter.java deleted file mode 100644 index d7d7f2691d38..000000000000 --- a/platform/lang-impl/src/com/intellij/formatting/FormatInfoPrinter.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2000-2009 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.formatting; - -import org.jdom.Element; - -import java.util.List; - -public class FormatInfoPrinter { - private final Block myRootBlock; - private final FormattingDocumentModel myDocumentModel; - - - public FormatInfoPrinter(final Block rootBlock, final FormattingDocumentModel documentModel) { - myRootBlock = rootBlock; - myDocumentModel = documentModel; - } - - public Element blocksAsTree(){ - return createBlockElement(myRootBlock); - } - - private Element createBlockElement(final Block block) { - final Element result = new Element("Block"); - printSimpleBlock(block, result); - - result.setAttribute("class", block.getClass().getName()); - - if (block.getSubBlocks().size() == 0) { - result.setAttribute("text", myDocumentModel.getText(block.getTextRange()).toString()); - } - - Wrap wrap = block.getWrap(); - if (wrap != null) { - Element wrapElem = new Element("Wrap"); - result.addContent(wrapElem); - WrapImpl wrapImpl = (WrapImpl)wrap; - wrapElem.setAttribute("id", wrapImpl.getId()); - wrapElem.setAttribute("type", wrapImpl.getType().name()); - wrapElem.setAttribute("ignoreParents", String.valueOf(wrapImpl.getIgnoreParentWraps())); - wrapElem.setAttribute("wrapFirst", String.valueOf(wrapImpl.isWrapFirstElement())); - - WrapImpl parent = wrapImpl.getParent(); - if (parent != null) { - wrapElem.setAttribute("parent", parent.getId()); - } - } - Indent indent = block.getIndent(); - if (indent != null) { - Element indentElement = new Element("Indent"); - result.addContent(indentElement); - indentElement.setAttribute("type", ((IndentImpl)indent).getType().toString()); - } - AlignmentImpl alignment = (AlignmentImpl)block.getAlignment(); - if (alignment != null) { - Element alEl = new Element("Alignment"); - result.addContent(alEl); - alEl.setAttribute("id", alignment.getId()); - } - final List subBlocks = block.getSubBlocks(); - for (int i = 0; i < subBlocks.size(); i++) { - if (i > 0 && i < subBlocks.size() - 1) { - Spacing spacing = block.getSpacing(subBlocks.get(i), subBlocks.get(i + 1)); - if (spacing != null) { - result.addContent(createSpacingElement(spacing)); - } - } - result.addContent(createBlockElement(subBlocks.get(i))); - } - - return result; - } - - private Element createSpacingElement(final Spacing spacing) { - final Element result = new Element("Spacing"); - final SpacingImpl impl = ((SpacingImpl)spacing); - - result.setAttribute("keepBlankLines", String.valueOf(impl.getKeepBlankLines())); - result.setAttribute("keepLineBreaks", String.valueOf(impl.shouldKeepLineFeeds())); - result.setAttribute("minspaces", String.valueOf(impl.getMinSpaces())); - result.setAttribute("maxspaces", String.valueOf(impl.getMaxSpaces())); - result.setAttribute("minlinefeeds", String.valueOf(impl.getMinLineFeeds())); - result.setAttribute("readOnly", String.valueOf(impl.isReadOnly())); - result.setAttribute("safe", String.valueOf(impl.isSafe())); - - return result; - } - - private void printSimpleBlock(final Block block, Element element) { - element.setAttribute("start", String.valueOf(block.getTextRange().getStartOffset())); - element.setAttribute("end", String.valueOf(block.getTextRange().getEndOffset())); - } -} diff --git a/platform/lang-impl/src/com/intellij/formatting/WrapImpl.java b/platform/lang-impl/src/com/intellij/formatting/WrapImpl.java index b6c8b2a7d00a..9d1b52a187e2 100644 --- a/platform/lang-impl/src/com/intellij/formatting/WrapImpl.java +++ b/platform/lang-impl/src/com/intellij/formatting/WrapImpl.java @@ -27,7 +27,6 @@ public class WrapImpl extends Wrap { private LeafBlockWrapper myChopStartBlock = null; private int myWrapOffset = -1; private int myFlags; - private static int ourId = 0; private static final Set emptyParentsSet = Collections.emptySet(); private Set myParents = emptyParentsSet; @@ -38,8 +37,6 @@ public class WrapImpl extends Wrap { private static final int WRAP_FIRST_ELEMENT_MASK = 4; private static final int TYPE_MASK = 0x18; private static final int TYPE_SHIFT = 3; - private static final int ID_SHIFT = 5; - private static final int ID_MAX = 1 << 26; private static final Type[] myTypes = Type.values(); @@ -118,9 +115,7 @@ public class WrapImpl extends Wrap { if (myIgnoredWraps == null) { myIgnoredWraps = new HashMap<>(5); } - if (myIgnoredWraps.get(wrap) == null) { - myIgnoredWraps.put(wrap, new HashSet<>(2)); - } + myIgnoredWraps.putIfAbsent(wrap, new HashSet<>(2)); myIgnoredWraps.get(wrap).add(currentBlock); } @@ -175,9 +170,7 @@ public class WrapImpl extends Wrap { default: myType = Type.CHOP_IF_NEEDED; } - int myId = ourId++; - assert myId < ID_MAX; - myFlags |= (wrapFirstElement ? WRAP_FIRST_ELEMENT_MASK:0) | (myType.ordinal() << TYPE_SHIFT) | (myId << ID_SHIFT); + myFlags |= (wrapFirstElement ? WRAP_FIRST_ELEMENT_MASK:0) | (myType.ordinal() << TYPE_SHIFT); } public final Type getType() { @@ -207,11 +200,7 @@ public class WrapImpl extends Wrap { public String toString() { return getType().toString(); } - - public String getId() { - return String.valueOf(myFlags >>> ID_SHIFT); - } - + /** * Allows to instruct current wrap to ignore all parent wraps, i.e. all calls to {@link #isChildOf(WrapImpl, LeafBlockWrapper)} * return 'false' after invocation of this method.