Here you can find the source of normalizeRecorderColumn(int column, int tabSize, int[] tabIndices)
Normalizes the given column index computed by KeY's recorder component into a normal column index in that each tab ( '\t' ) character has a fixed tab size of one which means that a tab is treated as a normal character.
Parameter | Description |
---|---|
column | The column computed by KeY's recorder component. |
tabSize | The tab size to use. |
tabIndices | The indices of tab ( '\t' ) characters in the current line. They can be computed for instance via IOUtil#computeLineInformation(File) . |
public static int normalizeRecorderColumn(int column, int tabSize, int[] tabIndices)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 Karlsruhe Institute of Technology, Germany * Technical University Darmstadt, Germany * Chalmers University of Technology, Sweden * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from www. j ava 2s .c o m * Technical University Darmstadt - initial API and implementation and/or initial documentation *******************************************************************************/ public class Main { /** * The used tab size in KeY's recorder component. */ public static final int RECORDER_TAB_SIZE = 8; /** * <p> * Normalizes the given column index computed by KeY's recorder component into * a normal column index in that each tab ({@code '\t'}) character has a fixed tab size * of one which means that a tab is treated as a normal character. * </p> * <p> * KeY's recorder component has a default tab size of {@link #RECORDER_TAB_SIZE}. * But instead of using this fixed tab size the recorder component uses the following * simplified code to compute the column index: * <pre><code> * int column = 0; * for (char sign : signs) { * switch (sign) { * case '\t' : column += (tabSize - (column % tabSize)); * break; * default : column ++; * } * } * </code></pre> * The class of recorder which does the mentioned computation is {@link JavaCharStream}. * </p> * @param column The column computed by KeY's recorder component. * @param tabIndices The indices of tab ({@code '\t'}) characters in the current line. They can be computed for instance via {@link IOUtil#computeLineInformation(File)}. * @return The normalized column index in that each tab ({@code '\t'}) character has a fixed tab size of one which means that a tab is treated as a normal character. */ public static int normalizeRecorderColumn(int column, int[] tabIndices) { return normalizeRecorderColumn(column, RECORDER_TAB_SIZE, tabIndices); } /** * <p> * Normalizes the given column index computed by KeY's recorder component into * a normal column index in that each tab ({@code '\t'}) character has a fixed tab size * of one which means that a tab is treated as a normal character. * </p> * <p> * KeY's recorder component has a default tab size of {@link #RECORDER_TAB_SIZE}. * But instead of using this fixed tab size the recorder component uses the following * simplified code to compute the column index: * <pre><code> * int column = 0; * for (char sign : signs) { * switch (sign) { * case '\t' : column += (tabSize - (column % tabSize)); * break; * default : column ++; * } * } * </code></pre> * The class of recorder which does the mentioned computation is {@link JavaCharStream}. * </p> * @param column The column computed by KeY's recorder component. * @param tabSize The tab size to use. * @param tabIndices The indices of tab ({@code '\t'}) characters in the current line. They can be computed for instance via {@link IOUtil#computeLineInformation(File)}. * @return The normalized column index in that each tab ({@code '\t'}) character has a fixed tab size of one which means that a tab is treated as a normal character. */ public static int normalizeRecorderColumn(int column, int tabSize, int[] tabIndices) { if (column >= 0 && tabSize >= 2 && tabIndices != null) { int result = 0; int i = 0; int lastTab = -1; int tabOverhead = 0; while (i < tabIndices.length) { if (lastTab >= 0) { result += tabIndices[i] - lastTab; } else { result = tabIndices[i]; } if (result < column) { tabOverhead += (tabSize - (result % tabSize) - 1); result += (tabSize - (result % tabSize) - 1); } lastTab = tabIndices[i]; i++; } return column - tabOverhead; } else { return column; } } }