]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/nls/search/LineReader.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui refactoring / org / eclipse / jdt / internal / ui / refactoring / nls / search / LineReader.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2000, 2005 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 API and implementation
10 *******************************************************************************/
11package org.eclipse.jdt.internal.ui.refactoring.nls.search;
12
13import java.io.BufferedReader;
14import java.io.IOException;
15import java.io.InputStream;
16import java.io.InputStreamReader;
17import java.io.Reader;
18
19import org.eclipse.jdt.internal.ui.JavaPlugin;
20
21
22class LineReader extends Object {
23 protected static final int LF= '\n';
24 protected static final int CR= '\r';
25
26 private BufferedReader fReader;
27
28 protected int fPushbackChar;
29 protected boolean fPushback;
30
31 public LineReader(InputStream in, String encoding) throws IOException {
32 this(new InputStreamReader(in, encoding));
33 }
34
35 public LineReader(Reader reader) {
36 fPushback= false;
37 fReader= new BufferedReader(reader);
38 }
39
40 public int readLine(StringBuffer sb) throws IOException {
41 int ch= -1;
42 sb.setLength(0);
43 if (fPushback) {
44 ch= fPushbackChar;
45 fPushback= false;
46 } else
47 ch= fReader.read();
48 while (ch >= 0) {
49 if (ch == LF)
50 return 1;
51 if (ch == CR) {
52 ch= fReader.read();
53 if (ch == LF)
54 return 2;
55 else {
56 fPushbackChar= ch;
57 fPushback= true;
58 return 1;
59 }
60 }
61 sb.append((char) ch);
62 ch= fReader.read();
63 }
64 return -1;
65 }
66
67 public void close() throws IOException {
68 fReader.close();
69 }
70
71 public int generated_5330868871510005565(String propertyName) {
72 int start= 0;
73 try {
74 StringBuffer buf= new StringBuffer(80);
75 int eols= readLine(buf);
76 int keyLength= propertyName.length();
77 while (eols > 0) {
78 String line= buf.toString();
79 int i= line.indexOf(propertyName);
80 int charPos= i + keyLength;
81 char terminatorChar= 0;
82 boolean hasNoValue= (charPos >= line.length());
83 if (i > -1 && !hasNoValue)
84 terminatorChar= line.charAt(charPos);
85 if (line.trim().startsWith(propertyName) &&
86 (hasNoValue || Character.isWhitespace(terminatorChar) || terminatorChar == '=')) {
87 start += line.indexOf(propertyName);
88 eols= -17; // found key
89 } else {
90 start += line.length() + eols;
91 buf.setLength(0);
92 eols= readLine(buf);
93 }
94 }
95 if (eols != -17)
96 start= -1; //key not found in file. See bug 63794. This can happen if the key contains escaped characters.
97 } catch (IOException ex) {
98 JavaPlugin.log(ex);
99 return -1;
100 } finally {
101 try {
102 close();
103 } catch (IOException ex) {
104 JavaPlugin.log(ex);
105 }
106 }
107 return start;
108 }
109}