本文整理汇总了Java中com.intellij.util.LineSeparator类的典型用法代码示例。如果您正苦于以下问题:Java LineSeparator类的具体用法?Java LineSeparator怎么用?Java LineSeparator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LineSeparator类属于com.intellij.util包,在下文中一共展示了LineSeparator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTempFile
import com.intellij.util.LineSeparator; //导入依赖的package包/类
@NotNull
private static File createTempFile(@NotNull final DocumentContent content, @NotNull String tempFileName) throws IOException {
FileDocumentManager.getInstance().saveDocument(content.getDocument());
LineSeparator separator = content.getLineSeparator();
if (separator == null) separator = LineSeparator.getSystemLineSeparator();
Charset charset = content.getCharset();
if (charset == null) charset = Charset.defaultCharset();
String contentData = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
return content.getDocument().getText();
}
});
if (separator != LineSeparator.LF) {
contentData = StringUtil.convertLineSeparators(contentData, separator.getSeparatorString());
}
byte[] bytes = contentData.getBytes(charset);
return createFile(bytes, tempFileName);
}
示例2: createTitle
import com.intellij.util.LineSeparator; //导入依赖的package包/类
@NotNull
public static JComponent createTitle(@NotNull String title,
@Nullable Charset charset,
@Nullable LineSeparator separator,
boolean readOnly) {
if (readOnly) title += " " + DiffBundle.message("diff.content.read.only.content.title.suffix");
JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(IdeBorderFactory.createEmptyBorder(0, 4, 0, 4));
panel.add(createTitlePanel(title), BorderLayout.CENTER);
if (charset != null && separator != null) {
JPanel panel2 = new JPanel();
panel2.setLayout(new BoxLayout(panel2, BoxLayout.X_AXIS));
panel2.add(createCharsetPanel(charset));
panel2.add(Box.createRigidArea(new Dimension(4, 0)));
panel2.add(createSeparatorPanel(separator));
panel.add(panel2, BorderLayout.EAST);
}
else if (charset != null) {
panel.add(createCharsetPanel(charset), BorderLayout.EAST);
}
else if (separator != null) {
panel.add(createSeparatorPanel(separator), BorderLayout.EAST);
}
return panel;
}
示例3: createSeparatorPanel
import com.intellij.util.LineSeparator; //导入依赖的package包/类
@NotNull
private static JComponent createSeparatorPanel(@NotNull LineSeparator separator) {
JLabel label = new JLabel(separator.name());
Color color;
if (separator == LineSeparator.CRLF) {
color = JBColor.RED;
}
else if (separator == LineSeparator.LF) {
color = JBColor.BLUE;
}
else if (separator == LineSeparator.CR) {
color = JBColor.MAGENTA;
}
else {
color = JBColor.BLACK;
}
label.setForeground(color);
return label;
}
示例4: createComponentForTitle
import com.intellij.util.LineSeparator; //导入依赖的package包/类
static JComponent createComponentForTitle(@Nullable String title,
@Nullable final LineSeparator sep1,
@Nullable final LineSeparator sep2,
boolean left) {
if (sep1 != null && sep2 != null && !sep1.equals(sep2)) {
LineSeparator separator = left ? sep1 : sep2;
JPanel bottomPanel = new JPanel(new BorderLayout());
JLabel sepLabel = new JLabel(separator.name());
sepLabel.setForeground(separator.equals(LineSeparator.CRLF) ? JBColor.RED : PlatformColors.BLUE);
bottomPanel.add(sepLabel, left ? BorderLayout.EAST : BorderLayout.WEST);
JPanel panel = new JPanel(new BorderLayout());
panel.add(new JLabel(title == null ? "" : title));
panel.add(bottomPanel, BorderLayout.SOUTH);
return panel;
}
else {
return new JBLabel(title == null ? "" : title);
}
}
示例5: testDetectSeparators
import com.intellij.util.LineSeparator; //导入依赖的package包/类
@Test
public void testDetectSeparators() {
assertEquals(null, StringUtil.detectSeparators(""));
assertEquals(null, StringUtil.detectSeparators("asd"));
assertEquals(null, StringUtil.detectSeparators("asd\t"));
assertEquals(LineSeparator.LF, StringUtil.detectSeparators("asd\n"));
assertEquals(LineSeparator.LF, StringUtil.detectSeparators("asd\nads\r"));
assertEquals(LineSeparator.LF, StringUtil.detectSeparators("asd\nads\n"));
assertEquals(LineSeparator.CR, StringUtil.detectSeparators("asd\r"));
assertEquals(LineSeparator.CR, StringUtil.detectSeparators("asd\rads\r"));
assertEquals(LineSeparator.CR, StringUtil.detectSeparators("asd\rads\n"));
assertEquals(LineSeparator.CRLF, StringUtil.detectSeparators("asd\r\n"));
assertEquals(LineSeparator.CRLF, StringUtil.detectSeparators("asd\r\nads\r"));
assertEquals(LineSeparator.CRLF, StringUtil.detectSeparators("asd\r\nads\n"));
}
示例6: applySettings
import com.intellij.util.LineSeparator; //导入依赖的package包/类
private void applySettings(VirtualFile file) {
if (file == null) return;
if (!Utils.isEnabled(CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings())) return;
final String filePath = Utils.getFilePath(myProject, file);
final List<EditorConfig.OutPair> outPairs = SettingsProviderComponent.getInstance().getOutPairs(myProject, filePath);
final String lineEndings = Utils.configValueForKey(outPairs, lineEndingsKey);
if (!lineEndings.isEmpty()) {
try {
LineSeparator separator = LineSeparator.valueOf(lineEndings.toUpperCase(Locale.US));
String oldSeparator = file.getDetectedLineSeparator();
String newSeparator = separator.getSeparatorString();
if (!StringUtil.equals(oldSeparator, newSeparator)) {
file.setDetectedLineSeparator(newSeparator);
if (!statusBarUpdated) {
statusBarUpdated = true;
updateStatusBar();
}
}
}
catch (IllegalArgumentException e) {
Utils.invalidConfigMessage(myProject, lineEndings, lineEndingsKey, filePath);
}
}
}
示例7: setTitles
import com.intellij.util.LineSeparator; //导入依赖的package包/类
private void setTitles(@NotNull DiffRequest data) {
LineSeparator sep1 = data.getContents()[0].getLineSeparator();
LineSeparator sep2 = data.getContents()[1].getLineSeparator();
String title1 = addReadOnly(data.getContentTitles()[0], myLeftSide.getEditor());
String title2 = addReadOnly(data.getContentTitles()[1], myRightSide.getEditor());
if (title1 != null && title2 != null && sep1 != null && sep2 != null && !sep1.equals(sep2)) {
setTitle1(createComponentForTitle(title1, sep1, true));
setTitle2(createComponentForTitle(title2, sep2, false));
}
else {
setTitle1(new JBLabel(title1 == null ? "" : title1));
setTitle2(new JBLabel(title2 == null ? "" : title2));
}
}
示例8: createMessagePanel
import com.intellij.util.LineSeparator; //导入依赖的package包/类
@NotNull
private JPanel createMessagePanel(@Nullable LineSeparator sep1, @Nullable LineSeparator sep2) {
String message;
if (DiffUtil.oneIsUnknown(myRequest.getContents()[0], myRequest.getContents()[1])) {
message = DiffBundle.message("diff.can.not.show.unknown");
}
else if (LineSeparator.knownAndDifferent(sep1, sep2)) {
message = DiffBundle.message("diff.contents.have.differences.only.in.line.separators.message.text");
}
else {
message = DiffBundle.message("diff.contents.are.identical.message.text");
}
final JLabel label = new JLabel(message);
label.setForeground(UIUtil.getInactiveTextColor());
final JPanel wrapper = new JPanel(new GridBagLayout());
wrapper.add(label, new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(1,1,1,1), 0,0));
return wrapper;
}
示例9: recalculateFileOffset
import com.intellij.util.LineSeparator; //导入依赖的package包/类
private int recalculateFileOffset(@NotNull PsiFile file, @NotNull PsiElement position, Editor editor) {
int offset = position.getTextOffset();;
VirtualFile virtualFile = file.getVirtualFile();
if (null == virtualFile) { // In memory file, the position doesn't change.
return offset;
}
// Get the separator, checking the file if we don't know yet. May still return null.
String separator = LoadTextUtil.detectLineSeparator(virtualFile, true);
// IntelliJ IDEA normalizes file line endings, so if file line endings is
// CRLF - then we have to shift an offset so Haxe compiler could get proper offset
if (LineSeparator.CRLF.getSeparatorString().equals(separator)) {
int lineNumber =
com.intellij.openapi.util.text.StringUtil.offsetToLineNumber(editor.getDocument().getText(), offset);
offset += lineNumber;
}
return offset;
}
示例10: applySettings
import com.intellij.util.LineSeparator; //导入依赖的package包/类
private void applySettings(VirtualFile file) {
if (file == null || !file.isInLocalFileSystem()) return;
final String filePath = file.getCanonicalPath();
final List<EditorConfig.OutPair> outPairs = SettingsProviderComponent.getInstance().getOutPairs(filePath);
final String lineEndings = Utils.configValueForKey(outPairs, lineEndingsKey);
if (!lineEndings.isEmpty()) {
try {
LineSeparator separator = LineSeparator.valueOf(lineEndings.toUpperCase(Locale.US));
String oldSeparator = file.getDetectedLineSeparator();
String newSeparator = separator.getSeparatorString();
if (!StringUtil.equals(oldSeparator, newSeparator)) {
file.setDetectedLineSeparator(newSeparator);
if (!statusBarUpdated) {
statusBarUpdated = true;
updateStatusBar();
}
LOG.debug(Utils.appliedConfigMessage(lineEndings, lineEndingsKey, filePath));
}
} catch (IllegalArgumentException e) {
LOG.warn(Utils.invalidConfigMessage(lineEndings, lineEndingsKey, filePath));
}
}
}
示例11: createTitle
import com.intellij.util.LineSeparator; //导入依赖的package包/类
@Nonnull
public static JComponent createTitle(@Nonnull String title,
@Nullable Charset charset,
@Nullable LineSeparator separator,
boolean readOnly) {
if (readOnly) title += " " + DiffBundle.message("diff.content.read.only.content.title.suffix");
JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(IdeBorderFactory.createEmptyBorder(0, 4, 0, 4));
panel.add(new JBLabel(title).setCopyable(true), BorderLayout.CENTER);
if (charset != null && separator != null) {
JPanel panel2 = new JPanel();
panel2.setLayout(new BoxLayout(panel2, BoxLayout.X_AXIS));
panel2.add(createCharsetPanel(charset));
panel2.add(Box.createRigidArea(new Dimension(4, 0)));
panel2.add(createSeparatorPanel(separator));
panel.add(panel2, BorderLayout.EAST);
}
else if (charset != null) {
panel.add(createCharsetPanel(charset), BorderLayout.EAST);
}
else if (separator != null) {
panel.add(createSeparatorPanel(separator), BorderLayout.EAST);
}
return panel;
}
示例12: createSeparatorPanel
import com.intellij.util.LineSeparator; //导入依赖的package包/类
@Nonnull
private static JComponent createSeparatorPanel(@Nonnull LineSeparator separator) {
JLabel label = new JLabel(separator.name());
Color color;
if (separator == LineSeparator.CRLF) {
color = JBColor.RED;
}
else if (separator == LineSeparator.LF) {
color = JBColor.BLUE;
}
else if (separator == LineSeparator.CR) {
color = JBColor.MAGENTA;
}
else {
color = JBColor.BLACK;
}
label.setForeground(color);
return label;
}
示例13: createImpl
import com.intellij.util.LineSeparator; //导入依赖的package包/类
@Nonnull
private static DocumentContent createImpl(@Nullable Project project,
@Nonnull String text,
@Nullable FileType fileType,
@javax.annotation.Nullable String fileName,
@Nullable VirtualFile highlightFile,
@javax.annotation.Nullable Charset charset,
@javax.annotation.Nullable Boolean bom,
boolean respectLineSeparators,
boolean readOnly) {
if (UnknownFileType.INSTANCE == fileType) fileType = PlainTextFileType.INSTANCE;
// TODO: detect invalid (different across the file) separators ?
LineSeparator separator = respectLineSeparators ? StringUtil.detectSeparators(text) : null;
String correctedContent = StringUtil.convertLineSeparators(text);
Document document = createDocument(project, correctedContent, fileType, fileName, readOnly);
DocumentContent content = new DocumentContentImpl(project, document, fileType, highlightFile, separator, charset, bom);
if (fileName != null) content.putUserData(DiffUserDataKeysEx.FILE_NAME, fileName);
return content;
}
示例14: createFromBytesImpl
import com.intellij.util.LineSeparator; //导入依赖的package包/类
@Nonnull
private static DocumentContent createFromBytesImpl(@javax.annotation.Nullable Project project,
@Nonnull byte[] content,
@Nonnull FileType fileType,
@Nonnull String fileName,
@javax.annotation.Nullable VirtualFile highlightFile,
@Nonnull Charset charset) {
Charset bomCharset = CharsetToolkit.guessFromBOM(content);
boolean isBOM = bomCharset != null;
if (isBOM) charset = bomCharset;
boolean malformedContent = false;
String text = CharsetToolkit.tryDecodeString(content, charset);
LineSeparator separator = StringUtil.detectSeparators(text);
String correctedContent = StringUtil.convertLineSeparators(text);
DocumentContent documentContent = createImpl(project, correctedContent, fileType, fileName, highlightFile, charset, isBOM, true, true);
if (malformedContent) {
String notificationText = "Content was decoded with errors (using " + "'" + charset.name() + "' charset)";
DiffUtil.addNotification(DiffNotifications.createNotification(notificationText, LightColors.RED), documentContent);
}
return documentContent;
}
示例15: createComponentForTitle
import com.intellij.util.LineSeparator; //导入依赖的package包/类
static JComponent createComponentForTitle(@Nullable String title, @Nullable final LineSeparator sep1, @Nullable final LineSeparator sep2, boolean left) {
if (sep1 != null && sep2 != null && !sep1.equals(sep2)) {
LineSeparator separator = left ? sep1 : sep2;
JPanel bottomPanel = new JPanel(new BorderLayout());
JLabel sepLabel = new JLabel(separator.name());
sepLabel.setForeground(separator.equals(LineSeparator.CRLF) ? JBColor.RED : PlatformColors.BLUE);
bottomPanel.add(sepLabel, left ? BorderLayout.EAST : BorderLayout.WEST);
JPanel panel = new JPanel(new BorderLayout());
panel.add(new JLabel(title == null ? "" : title));
panel.add(bottomPanel, BorderLayout.SOUTH);
return panel;
}
else {
return new JBLabel(title == null ? "" : title);
}
}