1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for 100640

Fix for 96286
This commit is contained in:
Bogdan Gheorghe 2005-06-20 17:14:04 +00:00
parent 9c09cf1ebb
commit 08eb1c00e5
9 changed files with 60 additions and 79 deletions

View file

@ -236,8 +236,14 @@ public class WordEntry {
* @return
*/
private int getEncodedNumber(int offsetType, int offset) {
String offsetString = Integer.toString(offsetType) + Integer.toString(offset);
return Integer.parseInt(offsetString);
/* String offsetString = Integer.toString(offsetType) + Integer.toString(offset);
return Integer.parseInt(offsetString);*/
int m = 10;
while (m <= offset) {
m = m * 10;
}
return m * offsetType + offset;
}
/**
* @param filePosition

View file

@ -39,6 +39,9 @@ import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.IMatchLocatable;
import org.eclipse.cdt.core.search.LineLocatable;
import org.eclipse.cdt.core.search.OffsetLocatable;
import org.eclipse.cdt.core.search.OrPattern;
import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser;
@ -638,6 +641,34 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
}
}
/**
* Decodes the passed in offset and returns an IMatchLocatable object of the appropriate type
* (either IOffsetLocatable or ILineLocatable)
*/
public static IMatchLocatable getMatchLocatable(int offset, int offsetLength){
// pull off the first digit for the offset type
int encodedVal = offset;
int offsetType = encodedVal;
int m = 1;
while (offsetType >= 10) {
offsetType = offsetType / 10;
m *= 10;
}
int startOffset = encodedVal - offsetType * m;
int endOffset = startOffset + offsetLength;
IMatchLocatable locatable = null;
if (offsetType==IIndex.LINE){
locatable = new LineLocatable(startOffset,0);
}else if (offsetType==IIndex.OFFSET){
locatable = new OffsetLocatable(startOffset, endOffset);
}
return locatable;
}
/**
* Feed the requestor according to the current search pattern
*/

View file

@ -27,8 +27,6 @@ import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.LineLocatable;
import org.eclipse.cdt.core.search.OffsetLocatable;
import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.IIndex;
@ -175,16 +173,9 @@ public class ClassDeclarationPattern extends CSearchPattern {
}
match.setQualifiedName(qualifiedName);
}
//Don't forget that offsets are encoded ICIndexStorageConstants
//Offsets can either be LINE or OFFSET
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
if (offsetType==IIndex.LINE){
match.setLocatable(new LineLocatable(Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(),0));
}else if (offsetType==IIndex.OFFSET){
int startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
int endOffset= startOffset + offsetLengths[i][j];
match.setLocatable(new OffsetLocatable(startOffset, endOffset));
}
//Decode the offsetse
//Offsets can either be IIndex.LINE or IIndex.OFFSET
match.setLocatable(getMatchLocatable(offsets[i][j],offsetLengths[i][j]));
match.setParentName(""); //$NON-NLS-1$

View file

@ -28,8 +28,6 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.LineLocatable;
import org.eclipse.cdt.core.search.OffsetLocatable;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.cindexstorage.Index;
import org.eclipse.cdt.internal.core.index.cindexstorage.IndexedFileEntry;
@ -156,16 +154,9 @@ public class FieldDeclarationPattern extends CSearchPattern {
for (int j=0; j<offsets[i].length; j++){
BasicSearchMatch match = new BasicSearchMatch();
match.setName(new String(this.decodedSimpleName));
//Don't forget that offsets are encoded ICIndexStorageConstants
//Offsets can either be LINE or OFFSET
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
if (offsetType==Index.LINE){
match.setLocatable(new LineLocatable(Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(),0));
}else if (offsetType==Index.OFFSET){
int startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
int endOffset= startOffset + offsetLengths[i][j];
match.setLocatable(new OffsetLocatable(startOffset, endOffset));
}
//Decode the offsetse
//Offsets can either be IIndex.LINE or IIndex.OFFSET
match.setLocatable(getMatchLocatable(offsets[i][j],offsetLengths[i][j]));
match.setParentName(""); //$NON-NLS-1$
if (searchFor == FIELD){
match.setType(ICElement.C_FIELD);

View file

@ -19,11 +19,8 @@ import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.LineLocatable;
import org.eclipse.cdt.core.search.OffsetLocatable;
import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.cindexstorage.Index;
import org.eclipse.cdt.internal.core.index.cindexstorage.IndexedFileEntry;
import org.eclipse.cdt.internal.core.index.cindexstorage.io.IndexInput;
@ -69,16 +66,9 @@ public class IncludePattern extends CSearchPattern {
for (int j=0; j<offsets[i].length; j++){
BasicSearchMatch match = new BasicSearchMatch();
match.setName(new String(this.decodedSimpleName));
//Don't forget that offsets are encoded ICIndexStorageConstants
//Offsets can either be LINE or OFFSET
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
if (offsetType==IIndex.LINE){
match.setLocatable(new LineLocatable(Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(),0));
}else if (offsetType==IIndex.OFFSET){
int startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
int endOffset= startOffset + offsetLengths[i][j];
match.setLocatable(new OffsetLocatable(startOffset, endOffset));
}
// Decode the offsetse
//Offsets can either be IIndex.LINE or IIndex.OFFSET
match.setLocatable(getMatchLocatable(offsets[i][j],offsetLengths[i][j]));
match.setParentName(""); //$NON-NLS-1$
match.setType(ICElement.C_INCLUDE);

View file

@ -22,10 +22,7 @@ import org.eclipse.cdt.core.parser.ast.IASTMacro;
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.LineLocatable;
import org.eclipse.cdt.core.search.OffsetLocatable;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.cindexstorage.Index;
import org.eclipse.cdt.internal.core.index.cindexstorage.IndexedFileEntry;
import org.eclipse.cdt.internal.core.index.cindexstorage.io.IndexInput;
@ -85,16 +82,9 @@ public class MacroDeclarationPattern extends CSearchPattern {
for (int j=0; j<offsets[i].length; j++){
BasicSearchMatch match = new BasicSearchMatch();
match.setName(new String(this.decodedSimpleName));
//Don't forget that offsets are encoded ICIndexStorageConstants
//Offsets can either be LINE or OFFSET
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
if (offsetType==IIndex.LINE){
match.setLocatable(new LineLocatable(Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(),0));
}else if (offsetType==IIndex.OFFSET){
int startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
int endOffset= startOffset + offsetLengths[i][j];
match.setLocatable(new OffsetLocatable(startOffset, endOffset));
}
//Decode the offsetse
//Offsets can either be IIndex.LINE or IIndex.OFFSET
match.setLocatable(getMatchLocatable(offsets[i][j],offsetLengths[i][j]));
match.setParentName(""); //$NON-NLS-1$
match.setType(ICElement.C_MACRO);
IFile tempFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path));

View file

@ -24,11 +24,8 @@ import org.eclipse.cdt.core.parser.ast.IASTMethod;
import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.LineLocatable;
import org.eclipse.cdt.core.search.OffsetLocatable;
import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.cindexstorage.Index;
import org.eclipse.cdt.internal.core.index.cindexstorage.IndexedFileEntry;
import org.eclipse.cdt.internal.core.index.cindexstorage.Util;
@ -294,16 +291,9 @@ public class MethodDeclarationPattern extends CSearchPattern {
for (int j=0; j<offsets[i].length; j++){
BasicSearchMatch match = new BasicSearchMatch();
match.setName(new String(this.decodedSimpleName));
//Don't forget that offsets are encoded ICIndexStorageConstants
//Offsets can either be LINE or OFFSET
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
if (offsetType==IIndex.LINE){
match.setLocatable(new LineLocatable(Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(),0));
} else if (offsetType==IIndex.OFFSET){
int startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
int endOffset= startOffset + offsetLengths[i][j];
match.setLocatable(new OffsetLocatable(startOffset, endOffset));
}
//Decode the offsetse
//Offsets can either be IIndex.LINE or IIndex.OFFSET
match.setLocatable(getMatchLocatable(offsets[i][j],offsetLengths[i][j]));
match.setParentName(""); //$NON-NLS-1$
if (searchFor == METHOD){
match.setType(ICElement.C_METHOD);

View file

@ -21,10 +21,7 @@ import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.LineLocatable;
import org.eclipse.cdt.core.search.OffsetLocatable;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.cindexstorage.Index;
import org.eclipse.cdt.internal.core.index.cindexstorage.IndexedFileEntry;
import org.eclipse.cdt.internal.core.index.cindexstorage.io.IndexInput;
@ -97,16 +94,9 @@ public class NamespaceDeclarationPattern extends CSearchPattern {
for (int j=0; j<offsets[i].length; j++){
BasicSearchMatch match = new BasicSearchMatch();
match.setName(new String(this.decodedSimpleName));
//Don't forget that offsets are encoded ICIndexStorageConstants
//Offsets can either be LINE or OFFSET
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
if (offsetType==IIndex.LINE){
match.setLocatable(new LineLocatable(Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(),0));
}else if (offsetType==IIndex.OFFSET){
int startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
int endOffset= startOffset + offsetLengths[i][j];
match.setLocatable(new OffsetLocatable(startOffset, endOffset));
}
//Decode the offsetse
//Offsets can either be IIndex.LINE or IIndex.OFFSET
match.setLocatable(getMatchLocatable(offsets[i][j],offsetLengths[i][j]));
match.setParentName(""); //$NON-NLS-1$
match.setType(ICElement.C_NAMESPACE);

View file

@ -210,6 +210,7 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover
startOffset = doc.getLineOffset(tempstartOffset-1);
length=doc.getLineLength(tempstartOffset-1);
} catch (BadLocationException e) {}
catch (NullPointerException e) {return null;}
//Check to see if an end offset is provided
int tempendOffset = ((ILineLocatable)searchLocatable).getEndLine();
@ -219,7 +220,8 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover
//See NOTE above
int endOffset = doc.getLineOffset(tempendOffset-1);
length=endOffset - startOffset;
} catch (BadLocationException e) {}
} catch (BadLocationException e) {}
catch (NullPointerException e) {return null;}
}
}