mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-43962 Indentation error on deep nesting levels
Provided bridging facilities between new and old wrap types api
This commit is contained in:
@@ -15,6 +15,11 @@
|
||||
*/
|
||||
package com.intellij.formatting;
|
||||
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Defines possible types of a wrap.
|
||||
*
|
||||
@@ -23,29 +28,69 @@ package com.intellij.formatting;
|
||||
*/
|
||||
|
||||
public enum WrapType {
|
||||
|
||||
/**
|
||||
* A line break is always inserted before the start of the element.
|
||||
* This corresponds to the "Wrap always" setting in Global Code Style | Wrapping.
|
||||
*/
|
||||
ALWAYS,
|
||||
ALWAYS(CodeStyleSettings.WRAP_ALWAYS),
|
||||
|
||||
/**
|
||||
* A line break is inserted before the start of the element if the right edge
|
||||
* of the element goes beyond the specified wrap margin.
|
||||
* This corresponds to the "Wrap if long" setting in Global Code Style | Wrapping.
|
||||
*/
|
||||
NORMAL,
|
||||
NORMAL(CodeStyleSettings.WRAP_AS_NEEDED),
|
||||
|
||||
/**
|
||||
* A line break is never inserted before the start of the element.
|
||||
* This corresponds to the "Do not wrap" setting in Global Code Style | Wrapping.
|
||||
*/
|
||||
NONE,
|
||||
NONE(CodeStyleSettings.DO_NOT_WRAP),
|
||||
|
||||
/**
|
||||
* A line break is inserted before the start of the element if it is a part
|
||||
* of list of elements of the same type and at least one of the elements was wrapped.
|
||||
* This corresponds to the "Chop down if long" setting in Global Code Style | Wrapping.
|
||||
*/
|
||||
CHOP_DOWN_IF_LONG
|
||||
CHOP_DOWN_IF_LONG(CodeStyleSettings.WRAP_ON_EVERY_ITEM);
|
||||
|
||||
private static final Map<Integer, WrapType> LEGACY_MAPPINGS = new HashMap<Integer, WrapType>();
|
||||
|
||||
static {
|
||||
for (WrapType wrapType : values()) {
|
||||
LEGACY_MAPPINGS.put(wrapType.getLegacyRepresentation(), wrapType);
|
||||
}
|
||||
}
|
||||
|
||||
private final int myLegacyRepresentation;
|
||||
|
||||
WrapType(int legacyRepresentation) {
|
||||
myLegacyRepresentation = legacyRepresentation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to retrieve wrap type by it's legacy non-type-safe representation (see {@link #getLegacyRepresentation()}).
|
||||
*
|
||||
* @param value legacy representation of the target wrap type
|
||||
* @return wrap type which {@link #getLegacyRepresentation() legacyRepresentation} is equal to the given value if any;
|
||||
* {@link #CHOP_DOWN_IF_LONG} otherwise
|
||||
*/
|
||||
public static WrapType byLegacyRepresentation(int value) {
|
||||
WrapType result = LEGACY_MAPPINGS.get(value);
|
||||
return result == null ? CHOP_DOWN_IF_LONG : result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapping types were used as a primitive constants during this enum introduction (e.g. {@link CodeStyleSettings#DO_NOT_WRAP} etc).
|
||||
* <p/>
|
||||
* It's possible to map that legacy representation to the object-level enum member via {@link #byLegacyRepresentation(int)}.
|
||||
* <p/>
|
||||
* Current getter exposes legacy value associated with the current object-level wrap type representation.
|
||||
*
|
||||
* @return legacy representation of the current wrap type
|
||||
*/
|
||||
public int getLegacyRepresentation() {
|
||||
return myLegacyRepresentation;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user