blob: 7d0e0c1019e82f6b7cb26cbcf16fe265c49e21ce (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/*******************************************************************************
* Copyright (c) 2007, 2008 IBM Corporation and others.
* 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.search.internal.ui.text;
import java.util.ArrayList;
import org.eclipse.core.resources.IResource;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
import org.eclipse.search.ui.text.Match;
/**
* Element representing a line in a file
*
*/
public class LineElement {
private final IResource fParent;
private final int fLineNumber;
private final int fLineStartOffset;
private final String fLineContents;
public LineElement(IResource parent, int lineNumber, int lineStartOffset, String lineContents) {
fParent= parent;
fLineNumber= lineNumber;
fLineStartOffset= lineStartOffset;
fLineContents= lineContents;
}
public IResource getParent() {
return fParent;
}
public int getLine() {
return fLineNumber;
}
public String getContents() {
return fLineContents;
}
public int getOffset() {
return fLineStartOffset;
}
public boolean contains(int offset) {
return fLineStartOffset <= offset && offset < fLineStartOffset + fLineContents.length();
}
public int getLength() {
return fLineContents.length();
}
public FileMatch[] getMatches(AbstractTextSearchResult result) {
ArrayList res= new ArrayList();
Match[] matches= result.getMatches(fParent);
for (int i= 0; i < matches.length; i++) {
FileMatch curr= (FileMatch) matches[i];
if (curr.getLineElement() == this) {
res.add(curr);
}
}
return (FileMatch[]) res.toArray(new FileMatch[res.size()]);
}
public int getNumberOfMatches(AbstractTextSearchResult result) {
int count= 0;
Match[] matches= result.getMatches(fParent);
for (int i= 0; i < matches.length; i++) {
FileMatch curr= (FileMatch) matches[i];
if (curr.getLineElement() == this) {
count++;
}
}
return count;
}
}
|