mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 01:36:01 +02:00
Bug 327730: Different color for write access, by Andrey Eremchenko.
This commit is contained in:
parent
37c5e73b7f
commit
3670c10d89
6 changed files with 64 additions and 46 deletions
|
@ -569,6 +569,12 @@
|
||||||
label="%Dummy.label"
|
label="%Dummy.label"
|
||||||
value="206, 204, 247">
|
value="206, 204, 247">
|
||||||
</colorDefinition>
|
</colorDefinition>
|
||||||
|
<colorDefinition
|
||||||
|
id="org.eclipse.cdt.ui.ColoredLabels.writeaccess_highlight"
|
||||||
|
isEditable="false"
|
||||||
|
label="%Dummy.label"
|
||||||
|
value="240, 216, 168">
|
||||||
|
</colorDefinition>
|
||||||
<theme
|
<theme
|
||||||
id="org.eclipse.ui.ide.systemDefault">
|
id="org.eclipse.ui.ide.systemDefault">
|
||||||
<colorOverride
|
<colorOverride
|
||||||
|
|
|
@ -1,30 +1,25 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2003, 2008 IBM Corporation and others.
|
* Copyright (c) 2003, 2010 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corp. - Rational Software - initial implementation
|
* Andrew Niefer (Rational Software) - initial implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
/*
|
|
||||||
* Created on Jun 12, 2003
|
|
||||||
*/
|
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IMarker;
|
|
||||||
import org.eclipse.swt.widgets.Shell;
|
|
||||||
import org.eclipse.ui.IWorkingSet;
|
import org.eclipse.ui.IWorkingSet;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.c.CVariableReadWriteFlags;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVariableReadWriteFlags;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author aniefer
|
|
||||||
*
|
|
||||||
* To change the template for this generated type comment go to
|
|
||||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
|
||||||
*/
|
|
||||||
public class CSearchUtil {
|
public class CSearchUtil {
|
||||||
|
|
||||||
public static int LRU_WORKINGSET_LIST_SIZE= 3;
|
public static int LRU_WORKINGSET_LIST_SIZE= 3;
|
||||||
|
@ -32,7 +27,6 @@ public class CSearchUtil {
|
||||||
|
|
||||||
public CSearchUtil() {
|
public CSearchUtil() {
|
||||||
super();
|
super();
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateLRUWorkingSets(IWorkingSet[] workingSets) {
|
public static void updateLRUWorkingSets(IWorkingSet[] workingSets) {
|
||||||
|
@ -49,11 +43,6 @@ public class CSearchUtil {
|
||||||
return CSearchUtil.workingSetsCache;
|
return CSearchUtil.workingSetsCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warnIfBinaryConstant( ICElement element, Shell shell) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String toString(IWorkingSet[] workingSets) {
|
public static String toString(IWorkingSet[] workingSets) {
|
||||||
if( workingSets != null && workingSets.length > 0 ){
|
if( workingSets != null && workingSets.length > 0 ){
|
||||||
String string = new String();
|
String string = new String();
|
||||||
|
@ -69,8 +58,14 @@ public class CSearchUtil {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ICElement getCElement(IMarker marker) {
|
public static boolean isWriteOccurrence(IASTName node, IBinding binding) {
|
||||||
// TODO Auto-generated method stub
|
boolean isWrite;
|
||||||
return null;
|
if (binding instanceof ICPPVariable) {
|
||||||
|
isWrite = ((CPPVariableReadWriteFlags.getReadWriteFlags(node) & PDOMName.WRITE_ACCESS) != 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
isWrite = ((CVariableReadWriteFlags.getReadWriteFlags(node) & PDOMName.WRITE_ACCESS) != 0);
|
||||||
|
}
|
||||||
|
return isWrite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,12 +37,14 @@ public class LineSearchElement extends PDOMSearchElement {
|
||||||
private final int fLength;
|
private final int fLength;
|
||||||
private final boolean fIsPolymorphicCall;
|
private final boolean fIsPolymorphicCall;
|
||||||
private final ICElement fEnclosingElement;
|
private final ICElement fEnclosingElement;
|
||||||
|
private final boolean fIsWriteAccess;
|
||||||
|
|
||||||
public Match(int offset, int length, boolean isPolymorphicCall, ICElement enclosingElement) {
|
public Match(int offset, int length, boolean isPolymorphicCall, ICElement enclosingElement, boolean isWriteAccess) {
|
||||||
fOffset = offset;
|
fOffset = offset;
|
||||||
fLength = length;
|
fLength = length;
|
||||||
fIsPolymorphicCall = isPolymorphicCall;
|
fIsPolymorphicCall = isPolymorphicCall;
|
||||||
fEnclosingElement = enclosingElement;
|
fEnclosingElement = enclosingElement;
|
||||||
|
fIsWriteAccess = isWriteAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOffset() {
|
public int getOffset() {
|
||||||
|
@ -61,6 +63,10 @@ public class LineSearchElement extends PDOMSearchElement {
|
||||||
return fEnclosingElement;
|
return fEnclosingElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isWriteAccess() {
|
||||||
|
return fIsWriteAccess;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (!(obj instanceof Match))
|
if (!(obj instanceof Match))
|
||||||
|
|
|
@ -22,14 +22,10 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
|
||||||
import org.eclipse.cdt.core.parser.Keywords;
|
import org.eclipse.cdt.core.parser.Keywords;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVariableReadWriteFlags;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVariableReadWriteFlags;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.util.Messages;
|
import org.eclipse.cdt.internal.ui.util.Messages;
|
||||||
|
|
||||||
|
@ -174,15 +170,9 @@ public class OccurrencesFinder implements IOccurrencesFinder {
|
||||||
final int length= fileLocation.getNodeLength();
|
final int length= fileLocation.getNodeLength();
|
||||||
if (offset >= 0 && length > 0) {
|
if (offset >= 0 && length > 0) {
|
||||||
if (binding instanceof IVariable) {
|
if (binding instanceof IVariable) {
|
||||||
boolean isWrite;
|
final boolean isWriteOccurrence = CSearchUtil.isWriteOccurrence(node, binding);
|
||||||
if (binding instanceof ICPPVariable) {
|
int flag = isWriteOccurrence ? F_WRITE_OCCURRENCE : F_READ_OCCURRENCE;
|
||||||
isWrite = ((CPPVariableReadWriteFlags.getReadWriteFlags(node) & PDOMName.WRITE_ACCESS) != 0);
|
String description = isWriteOccurrence ? fWriteDescription : fReadDescription;
|
||||||
}
|
|
||||||
else {
|
|
||||||
isWrite = ((CVariableReadWriteFlags.getReadWriteFlags(node) & PDOMName.WRITE_ACCESS) != 0);
|
|
||||||
}
|
|
||||||
int flag = isWrite ? F_WRITE_OCCURRENCE : F_READ_OCCURRENCE;
|
|
||||||
String description = isWrite ? fWriteDescription : fReadDescription;
|
|
||||||
fResult.add(new OccurrenceLocation(offset, length, flag, description));
|
fResult.add(new OccurrenceLocation(offset, length, flag, description));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
|
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
|
||||||
import org.eclipse.jface.viewers.LabelProvider;
|
import org.eclipse.jface.viewers.LabelProvider;
|
||||||
import org.eclipse.jface.viewers.StyledString;
|
import org.eclipse.jface.viewers.StyledString;
|
||||||
|
import org.eclipse.jface.viewers.StyledString.Styler;
|
||||||
import org.eclipse.search.ui.text.AbstractTextSearchResult;
|
import org.eclipse.search.ui.text.AbstractTextSearchResult;
|
||||||
import org.eclipse.swt.graphics.Image;
|
import org.eclipse.swt.graphics.Image;
|
||||||
import org.eclipse.ui.ISharedImages;
|
import org.eclipse.ui.ISharedImages;
|
||||||
|
@ -169,7 +170,8 @@ public class PDOMSearchLabelProvider extends LabelProvider implements IStyledLab
|
||||||
for (Match match : lineElement.getMatches()) {
|
for (Match match : lineElement.getMatches()) {
|
||||||
int offset = Math.max(0, match.getOffset() - lineOffset);
|
int offset = Math.max(0, match.getOffset() - lineOffset);
|
||||||
int length = Math.min(match.getLength(), lineContent.length() - offset);
|
int length = Math.min(match.getLength(), lineContent.length() - offset);
|
||||||
styled.setStyle(offset, length, ColoringLabelProvider.HIGHLIGHT_STYLE);
|
Styler style = match.isWriteAccess() ? ColoringLabelProvider.HIGHLIGHT_WRITE_STYLE : ColoringLabelProvider.HIGHLIGHT_STYLE;
|
||||||
|
styled.setStyle(offset, length, style);
|
||||||
}
|
}
|
||||||
return styled;
|
return styled;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,9 @@ import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.IPositionConverter;
|
import org.eclipse.cdt.core.IPositionConverter;
|
||||||
import org.eclipse.cdt.core.browser.ITypeReference;
|
import org.eclipse.cdt.core.browser.ITypeReference;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||||
|
@ -200,10 +202,7 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
||||||
if (names == null)
|
if (names == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ICProject preferred= null;
|
ICProject preferred = getPreferredProject();
|
||||||
if (projects != null && projects.length == 1) {
|
|
||||||
preferred= projects[0];
|
|
||||||
}
|
|
||||||
for (IIndexName name : names) {
|
for (IIndexName name : names) {
|
||||||
if (!filterName(name)) {
|
if (!filterName(name)) {
|
||||||
if (!isPolymorphicOnly || name.couldBePolymorphicMethodCall()) {
|
if (!isPolymorphicOnly || name.couldBePolymorphicMethodCall()) {
|
||||||
|
@ -221,7 +220,8 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
||||||
if (enclosingDefinition != null) {
|
if (enclosingDefinition != null) {
|
||||||
enclosingElement = IndexUI.getCElementForName(preferred, index, enclosingDefinition);
|
enclosingElement = IndexUI.getCElementForName(preferred, index, enclosingDefinition);
|
||||||
}
|
}
|
||||||
matches.add(new Match(nodeOffset, nodeLength, isPolymorphicOnly, enclosingElement));
|
boolean isWriteAccess = name.isWriteAccess();
|
||||||
|
matches.add(new Match(nodeOffset, nodeLength, isPolymorphicOnly, enclosingElement, isWriteAccess));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +241,8 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
||||||
int length = region.getLength();
|
int length = region.getLength();
|
||||||
boolean isPolymorphicCall = match.isPolymorphicCall();
|
boolean isPolymorphicCall = match.isPolymorphicCall();
|
||||||
ICElement enclosingElement = match.getEnclosingElement();
|
ICElement enclosingElement = match.getEnclosingElement();
|
||||||
convertedMatches.add(new Match(offset, length, isPolymorphicCall, enclosingElement));
|
boolean isWriteAccess = match.isWriteAccess();
|
||||||
|
convertedMatches.add(new Match(offset, length, isPolymorphicCall, enclosingElement, isWriteAccess));
|
||||||
}
|
}
|
||||||
matches = convertedMatches;
|
matches = convertedMatches;
|
||||||
}
|
}
|
||||||
|
@ -354,7 +355,7 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
||||||
names.addAll(Arrays.asList(bindingNames));
|
names.addAll(Arrays.asList(bindingNames));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createLocalMatches(IASTTranslationUnit ast, IBinding binding) {
|
protected void createLocalMatches(IASTTranslationUnit ast, IBinding binding) throws CoreException {
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
Set<IASTName> names= new HashSet<IASTName>();
|
Set<IASTName> names= new HashSet<IASTName>();
|
||||||
names.addAll(Arrays.asList(ast.getDeclarationsInAST(binding)));
|
names.addAll(Arrays.asList(ast.getDeclarationsInAST(binding)));
|
||||||
|
@ -371,7 +372,17 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
||||||
if (typeInfo != null) {
|
if (typeInfo != null) {
|
||||||
ITypeReference ref= typeInfo.getResolvedReference();
|
ITypeReference ref= typeInfo.getResolvedReference();
|
||||||
if (ref != null) {
|
if (ref != null) {
|
||||||
localMatches.add(new Match(ref.getOffset(), ref.getLength(), false, null));
|
ICElement element = null;
|
||||||
|
IASTNode node = name;
|
||||||
|
while (node != null && !(node instanceof IASTFunctionDefinition)) {
|
||||||
|
node= node.getParent();
|
||||||
|
}
|
||||||
|
if (node != null) {
|
||||||
|
IASTFunctionDefinition definition = (IASTFunctionDefinition) node;
|
||||||
|
element = IndexUI.getCElementForName(getPreferredProject(), ast.getIndex(), definition.getDeclarator().getName());
|
||||||
|
}
|
||||||
|
boolean isWrite = CSearchUtil.isWriteOccurrence(name, binding);
|
||||||
|
localMatches.add(new Match(ref.getOffset(), ref.getLength(), false, element , isWrite));
|
||||||
fileLocation = typeInfo.getIFL();
|
fileLocation = typeInfo.getIFL();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -418,6 +429,14 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ICProject getPreferredProject() {
|
||||||
|
ICProject preferred= null;
|
||||||
|
if (projects != null && projects.length == 1) {
|
||||||
|
preferred= projects[0];
|
||||||
|
}
|
||||||
|
return preferred;
|
||||||
|
}
|
||||||
|
|
||||||
public final IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
public final IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
||||||
PDOMSearchResult result= (PDOMSearchResult) getSearchResult();
|
PDOMSearchResult result= (PDOMSearchResult) getSearchResult();
|
||||||
result.removeAll();
|
result.removeAll();
|
||||||
|
|
Loading…
Add table
Reference in a new issue