| /******************************************************************************* |
| * Copyright (c) 2003 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Common Public License v0.5 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/cpl-v05.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; |
| } |
| |
| String nodeName = ((IASTOffsetableNamedElement)node).getName(); |
| |
| //check name, if simpleName == null, its treated the same as "*" |
| if( simpleName != null && !matchesName( simpleName, nodeName.toCharArray() ) ){ |
| 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, 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 size = word.length; |
| |
| 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; |
| } |