]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/search/JavaElementLine.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / internal / ui / search / JavaElementLine.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2000, 2011 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 *******************************************************************************/
11
12package org.eclipse.jdt.internal.ui.search;
13
14import org.eclipse.core.runtime.CoreException;
15import org.eclipse.core.runtime.IStatus;
16import org.eclipse.core.runtime.Status;
17
18import org.eclipse.jdt.core.IBuffer;
19import org.eclipse.jdt.core.ITypeRoot;
20import org.eclipse.jdt.core.formatter.IndentManipulation;
21
22import org.eclipse.jdt.internal.corext.util.Messages;
23
24import org.eclipse.jdt.ui.JavaUI;
25
26import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
27
28public class JavaElementLine {
29
30
31 private final ITypeRoot fElement;
32 private final String fLineContents;
33 private final int fLineNumber;
34 private final int fLineStartOffset;
35
36 private int fFlags;
37
38 /**
39 * @param element either an ICompilationUnit or an IClassFile
40 * @param lineNumber the line number
41 * @param lineStartOffset the start offset of the line
42 * @throws CoreException thrown when accessing of the buffer failed
43 */
44 public JavaElementLine(ITypeRoot element, int lineNumber, int lineStartOffset) throws CoreException {
45 fElement= element;
46 fFlags= 0;
47
48 IBuffer buffer= element.getBuffer();
49 if (buffer == null) {
50 throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, Messages.format( SearchMessages.JavaElementLine_error_nobuffer, BasicElementLabels.getFileName(element))));
51 }
52
53 int length= buffer.getLength();
54 int i= lineStartOffset;
55
56 char ch= buffer.getChar(i);
57 while (lineStartOffset < length && IndentManipulation.isIndentChar(ch)) {
58 ch= buffer.getChar(++i);
59 }
60 fLineStartOffset= i;
61
62 StringBuffer buf= new StringBuffer();
63
64 while (i < length && !IndentManipulation.isLineDelimiterChar(ch)) {
65 if (Character.isISOControl(ch)) {
66 buf.append(' ');
67 } else {
68 buf.append(ch);
69 }
70 i++;
71 if (i < length)
72 ch= buffer.getChar(i);
73 }
74 fLineContents= buf.toString();
75 fLineNumber= lineNumber;
76 }
77
78 public void setFlags(int flags) {
79 fFlags= flags;
80 }
81
82 public int getFlags() {
83 return fFlags;
84 }
85
86 public ITypeRoot getJavaElement() {
87 return fElement;
88 }
89
90 public int getLine() {
91 return fLineNumber;
92 }
93
94 public String getLineContents() {
95 return fLineContents;
96 }
97
98 public int getLineStartOffset() {
99 return fLineStartOffset;
100 }
101}