本文整理汇总了Java中com.intellij.openapi.fileEditor.impl.LoadTextUtil.detectLineSeparator方法的典型用法代码示例。如果您正苦于以下问题:Java LoadTextUtil.detectLineSeparator方法的具体用法?Java LoadTextUtil.detectLineSeparator怎么用?Java LoadTextUtil.detectLineSeparator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.fileEditor.impl.LoadTextUtil
的用法示例。
在下文中一共展示了LoadTextUtil.detectLineSeparator方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: recalculateFileOffset
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的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;
}
示例2: changeLineSeparators
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
public static void changeLineSeparators(@NotNull final Project project,
@NotNull final VirtualFile virtualFile,
@NotNull final String newSeparator)
{
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
Document document = fileDocumentManager.getCachedDocument(virtualFile);
if (document != null) {
fileDocumentManager.saveDocument(document);
}
String currentSeparator = LoadTextUtil.detectLineSeparator(virtualFile, false);
final String commandText;
if (StringUtil.isEmpty(currentSeparator)) {
commandText = "Changed line separators to " + LineSeparator.fromString(newSeparator);
}
else {
commandText = String.format("Changed line separators from %s to %s",
LineSeparator.fromString(currentSeparator), LineSeparator.fromString(newSeparator));
}
new WriteCommandAction(project, commandText) {
@Override
protected void run(@NotNull Result result) throws Throwable {
try {
LoadTextUtil.changeLineSeparators(project, virtualFile, newSeparator, this);
}
catch (IOException e) {
LOG.info(e);
}
}
}.execute();
}
示例3: buildVisitor
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new PsiElementVisitor() {
@Override
public void visitFile(PsiFile file) {
if (!file.getLanguage().equals(file.getViewProvider().getBaseLanguage())) {
// There is a possible case that more than a single virtual file/editor contains more than one language (e.g. php and html).
// We want to process a virtual file once than, hence, ignore all non-base psi files.
return;
}
final Project project = holder.getProject();
final String projectLineSeparator = FileDocumentManager.getInstance().getLineSeparator(null, project);
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null || !AbstractConvertLineSeparatorsAction.shouldProcess(virtualFile, project)) {
return;
}
final String curLineSeparator = LoadTextUtil.detectLineSeparator(virtualFile, true);
if (curLineSeparator != null && !curLineSeparator.equals(projectLineSeparator)) {
holder.registerProblem(
file,
"Line separators in the current file (" + StringUtil.escapeStringCharacters(curLineSeparator) + ") " +
"differ from the project defaults (" + StringUtil.escapeStringCharacters(projectLineSeparator) + ")",
SET_PROJECT_LINE_SEPARATORS);
}
}
};
}
示例4: appendToFile
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
public static void appendToFile(@NotNull VirtualFile file, @NotNull String text) throws IOException {
String lineSeparator = LoadTextUtil.detectLineSeparator(file, true);
if (lineSeparator == null) {
lineSeparator = CodeStyleSettingsManager.getSettings(ProjectManagerEx.getInstanceEx().getDefaultProject()).getLineSeparator();
}
final String existingText = StringUtil.trimTrailing(VfsUtilCore.loadText(file));
String content = (StringUtil.isNotEmpty(existingText) ? existingText + lineSeparator : "") +
StringUtil.convertLineSeparators(text, lineSeparator);
VfsUtil.saveText(file, content);
}
示例5: changeLineSeparators
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
public static void changeLineSeparators(@NotNull final Project project,
@NotNull final VirtualFile virtualFile,
@NotNull final String newSeparator)
{
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
Document document = fileDocumentManager.getCachedDocument(virtualFile);
if (document != null) {
fileDocumentManager.saveDocument(document);
}
String currentSeparator = LoadTextUtil.detectLineSeparator(virtualFile, false);
final String commandText;
if (StringUtil.isEmpty(currentSeparator)) {
commandText = "Changed line separators to " + LineSeparator.fromString(newSeparator);
}
else {
commandText = String.format("Changed line separators from %s to %s",
LineSeparator.fromString(currentSeparator), LineSeparator.fromString(newSeparator));
}
CommandProcessor commandProcessor = CommandProcessor.getInstance();
commandProcessor.executeCommand(project, new Runnable() {
@Override
public void run() {
try {
LoadTextUtil.changeLineSeparators(project, virtualFile, newSeparator, this);
}
catch (IOException e) {
LOG.warn(e);
}
}
}, commandText, null);
}
示例6: buildVisitor
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new PsiElementVisitor() {
@Override
public void visitFile(PsiFile file) {
if (!file.getLanguage().equals(file.getViewProvider().getBaseLanguage())) {
// There is a possible case that more than a single virtual file/editor contains more than one language (e.g. php and html).
// We want to process a virtual file once than, hence, ignore all non-base psi files.
return;
}
final Project project = holder.getProject();
final String projectLineSeparator = CodeStyleFacade.getInstance(project).getLineSeparator();
if (projectLineSeparator == null) {
return;
}
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null || !AbstractConvertLineSeparatorsAction.shouldProcess(virtualFile, project)) {
return;
}
final String curLineSeparator = LoadTextUtil.detectLineSeparator(virtualFile, true);
if (curLineSeparator != null && !curLineSeparator.equals(projectLineSeparator)) {
holder.registerProblem(
file,
"Line separators in the current file (" + StringUtil.escapeStringCharacters(curLineSeparator) + ") " +
"differ from the project defaults (" + StringUtil.escapeStringCharacters(projectLineSeparator) + ")",
SET_PROJECT_LINE_SEPARATORS);
}
}
};
}
示例7: changeLineSeparators
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
public static void changeLineSeparators(@Nonnull final Project project,
@Nonnull final VirtualFile virtualFile,
@Nonnull final String newSeparator) {
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
Document document = fileDocumentManager.getCachedDocument(virtualFile);
if (document != null) {
fileDocumentManager.saveDocument(document);
}
String currentSeparator = LoadTextUtil.detectLineSeparator(virtualFile, false);
final String commandText;
if (StringUtil.isEmpty(currentSeparator)) {
commandText = "Changed line separators to " + LineSeparator.fromString(newSeparator);
}
else {
commandText = String.format("Changed line separators from %s to %s", LineSeparator.fromString(currentSeparator),
LineSeparator.fromString(newSeparator));
}
new WriteCommandAction(project, commandText) {
@Override
protected void run(@Nonnull Result result) throws Throwable {
try {
LoadTextUtil.changeLineSeparators(project, virtualFile, newSeparator, this);
}
catch (IOException e) {
LOG.info(e);
}
}
}.execute();
}
示例8: buildVisitor
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
@Nonnull
@Override
public PsiElementVisitor buildVisitor(@Nonnull final ProblemsHolder holder, boolean isOnTheFly) {
return new PsiElementVisitor() {
@Override
public void visitFile(PsiFile file) {
if (!file.getLanguage().equals(file.getViewProvider().getBaseLanguage())) {
// There is a possible case that more than a single virtual file/editor contains more than one language (e.g. php and html).
// We want to process a virtual file once than, hence, ignore all non-base psi files.
return;
}
final Project project = holder.getProject();
final String projectLineSeparator = CodeStyleFacade.getInstance(project).getLineSeparator();
if (projectLineSeparator == null) {
return;
}
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null || !AbstractConvertLineSeparatorsAction.shouldProcess(virtualFile, project)) {
return;
}
final String curLineSeparator = LoadTextUtil.detectLineSeparator(virtualFile, true);
if (curLineSeparator != null && !curLineSeparator.equals(projectLineSeparator)) {
holder.registerProblem(
file,
"Line separators in the current file (" + StringUtil.escapeStringCharacters(curLineSeparator) + ") " +
"differ from the project defaults (" + StringUtil.escapeStringCharacters(projectLineSeparator) + ")",
SET_PROJECT_LINE_SEPARATORS);
}
}
};
}
示例9: getSeparator
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
@Nullable
private static LineSeparator getSeparator(@NotNull VirtualFile file) {
String s = LoadTextUtil.detectLineSeparator(file, true);
if (s == null) return null;
return LineSeparator.fromString(s);
}
示例10: getLineSeparator
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
@Nullable
@Override
public String getLineSeparator(@NotNull VirtualFile file, boolean detect) {
return LoadTextUtil.detectLineSeparator(file, detect);
}
示例11: getSeparator
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
@javax.annotation.Nullable
private static LineSeparator getSeparator(@Nonnull VirtualFile file) {
String s = LoadTextUtil.detectLineSeparator(file, true);
if (s == null) return null;
return LineSeparator.fromString(s);
}
示例12: getLineSeparator
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
@Nullable
@Override
public String getLineSeparator(@Nonnull VirtualFile file, boolean detect) {
return LoadTextUtil.detectLineSeparator(file, detect);
}