~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/scanner/ScannerContext.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2004, 2008 IBM Corporation and others.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 *
 
8
 * Contributors:
 
9
 *     IBM Corporation - initial implementation
 
10
 *     Anton Leherbauer - adding tokens for preprocessing directives
 
11
 *     Markus Schorn - classification of preprocessing directives.
 
12
 *******************************************************************************/
 
13
package org.eclipse.cdt.internal.formatter.scanner;
 
14
 
 
15
import java.io.IOException;
 
16
import java.io.Reader;
 
17
import java.util.Stack;
 
18
 
 
19
public class ScannerContext {
 
20
        private Reader fReader;
 
21
        private int fOffset;
 
22
        private Stack<Integer> fUndo = new Stack<Integer>();
 
23
 
 
24
        public ScannerContext() {
 
25
        }
 
26
 
 
27
        public ScannerContext initialize(Reader r) {
 
28
                fReader = r;
 
29
                fOffset = 0;
 
30
                return this;
 
31
        }
 
32
 
 
33
        public ScannerContext initialize(Reader r, int offset) {
 
34
                try {
 
35
                        r.skip(offset);
 
36
                } catch (IOException exc) {
 
37
                        throw new RuntimeException(exc);
 
38
                }
 
39
                fReader = r;
 
40
                fOffset = offset;
 
41
                return this;
 
42
        }
 
43
 
 
44
        public int read() throws IOException {
 
45
                ++fOffset;
 
46
                return fReader.read();
 
47
        }
 
48
 
 
49
        /**
 
50
         * Returns the offset.
 
51
         * @return int
 
52
         */
 
53
        public final int getOffset() {
 
54
                return fOffset;
 
55
        }
 
56
 
 
57
        /**
 
58
         * Returns the reader.
 
59
         * @return Reader
 
60
         */
 
61
        public final Reader getReader() {
 
62
                return fReader;
 
63
        }
 
64
 
 
65
        public final int undoStackSize() {
 
66
                return fUndo.size();
 
67
        }
 
68
 
 
69
        /**
 
70
         * Returns the undo.
 
71
         * @return int
 
72
         */
 
73
        public final int popUndo() {
 
74
                return fUndo.pop().intValue();
 
75
        }
 
76
 
 
77
        /**
 
78
         * Sets the undo.
 
79
         * @param undo The undo to set
 
80
         */
 
81
        public void pushUndo(int undo) {
 
82
                this.fUndo.push(new Integer(undo));
 
83
        }
 
84
}