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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/*******************************************************************************
* Copyright (c) 2003, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
*******************************************************************************/
/*
* Created on Aug 8, 2003
*/
package org.eclipse.cdt.internal.core.search.matching;
import java.io.IOException;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.cdt.core.parser.ast.IASTMacro;
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.impl.IndexInput;
import org.eclipse.cdt.internal.core.index.impl.IndexedFile;
import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor;
import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer;
/**
* @author aniefer
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class MacroDeclarationPattern extends CSearchPattern {
/**
* @param name
* @param matchMode
* @param limitTo
* @param caseSensitive
*/
public MacroDeclarationPattern(char[] name, int matchMode, LimitTo limitTo, boolean caseSensitive) {
super( matchMode, caseSensitive, limitTo );
simpleName = name;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.search.ICSearchPattern#matchLevel(org.eclipse.cdt.core.parser.ast.IASTOffsetableElement)
*/
public int matchLevel(ISourceElementCallbackDelegate node, LimitTo limit ) {
if( !(node instanceof IASTMacro) || !canAccept( limit ) ){
return IMPOSSIBLE_MATCH;
}
char[] nodeName = ((IASTOffsetableNamedElement)node).getNameCharArray();
//check name, if simpleName == null, its treated the same as "*"
if( simpleName != null && !matchesName( simpleName, nodeName ) ){
return IMPOSSIBLE_MATCH;
}
return ACCURATE_MATCH;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#feedIndexRequestor(org.eclipse.cdt.internal.core.search.IIndexSearchRequestor, int, int[], org.eclipse.cdt.internal.core.index.impl.IndexInput, org.eclipse.cdt.core.search.ICSearchScope)
*/
public void feedIndexRequestor(IIndexSearchRequestor requestor, int detailLevel, int[] references, int[] indexFlags, IndexInput input, ICSearchScope scope) throws IOException {
for (int i = 0, max = references.length; i < max; i++) {
IndexedFile file = input.getIndexedFile(references[i]);
String path;
if (file != null && scope.encloses(path =file.getPath())) {
requestor.acceptMacroDeclaration(path, decodedSimpleName);
}
}
}
protected void resetIndexInfo(){
decodedSimpleName = null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#decodeIndexEntry(org.eclipse.cdt.internal.core.index.IEntryResult)
*/
protected void decodeIndexEntry(IEntryResult entryResult) {
char[] word = entryResult.getWord();
int firstSlash = CharOperation.indexOf( SEPARATOR, word, 0 );
this.decodedSimpleName = CharOperation.subarray(word, firstSlash + 1, -1);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#indexEntryPrefix()
*/
public char[] indexEntryPrefix() {
return AbstractIndexer.bestMacroPrefix(
_limitTo,
simpleName,
_matchMode, _caseSensitive
);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#matchIndexEntry()
*/
protected boolean matchIndexEntry() {
/* check simple name matches */
if (simpleName != null){
if( ! matchesName( simpleName, decodedSimpleName ) ){
return false;
}
}
return true;
}
protected char [] simpleName;
protected char [] decodedSimpleName;
}
|