1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug 327730: Different color for write access, by Andrey Eremchenko.

This commit is contained in:
Markus Schorn 2010-10-14 08:27:41 +00:00
parent 37c5e73b7f
commit 3670c10d89
6 changed files with 64 additions and 46 deletions

View file

@ -569,6 +569,12 @@
label="%Dummy.label"
value="206, 204, 247">
</colorDefinition>
<colorDefinition
id="org.eclipse.cdt.ui.ColoredLabels.writeaccess_highlight"
isEditable="false"
label="%Dummy.label"
value="240, 216, 168">
</colorDefinition>
<theme
id="org.eclipse.ui.ide.systemDefault">
<colorOverride

View file

@ -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
* 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 Corp. - Rational Software - initial implementation
* Andrew Niefer (Rational Software) - initial implementation
*******************************************************************************/
/*
* Created on Jun 12, 2003
*/
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.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 static int LRU_WORKINGSET_LIST_SIZE= 3;
@ -32,7 +27,6 @@ public class CSearchUtil {
public CSearchUtil() {
super();
// TODO Auto-generated constructor stub
}
public static void updateLRUWorkingSets(IWorkingSet[] workingSets) {
@ -49,11 +43,6 @@ public class CSearchUtil {
return CSearchUtil.workingSetsCache;
}
public static void warnIfBinaryConstant( ICElement element, Shell shell) {
// TODO Auto-generated method stub
}
public static String toString(IWorkingSet[] workingSets) {
if( workingSets != null && workingSets.length > 0 ){
String string = new String();
@ -69,8 +58,14 @@ public class CSearchUtil {
return null;
}
public static ICElement getCElement(IMarker marker) {
// TODO Auto-generated method stub
return null;
public static boolean isWriteOccurrence(IASTName node, IBinding binding) {
boolean isWrite;
if (binding instanceof ICPPVariable) {
isWrite = ((CPPVariableReadWriteFlags.getReadWriteFlags(node) & PDOMName.WRITE_ACCESS) != 0);
}
else {
isWrite = ((CVariableReadWriteFlags.getReadWriteFlags(node) & PDOMName.WRITE_ACCESS) != 0);
}
return isWrite;
}
}

View file

@ -37,12 +37,14 @@ public class LineSearchElement extends PDOMSearchElement {
private final int fLength;
private final boolean fIsPolymorphicCall;
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;
fLength = length;
fIsPolymorphicCall = isPolymorphicCall;
fEnclosingElement = enclosingElement;
fIsWriteAccess = isWriteAccess;
}
public int getOffset() {
@ -61,6 +63,10 @@ public class LineSearchElement extends PDOMSearchElement {
return fEnclosingElement;
}
public boolean isWriteAccess() {
return fIsWriteAccess;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Match))

View file

@ -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.cpp.ICPPASTTemplateId;
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.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.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.ui.util.Messages;
@ -174,15 +170,9 @@ public class OccurrencesFinder implements IOccurrencesFinder {
final int length= fileLocation.getNodeLength();
if (offset >= 0 && length > 0) {
if (binding instanceof IVariable) {
boolean isWrite;
if (binding instanceof ICPPVariable) {
isWrite = ((CPPVariableReadWriteFlags.getReadWriteFlags(node) & PDOMName.WRITE_ACCESS) != 0);
}
else {
isWrite = ((CVariableReadWriteFlags.getReadWriteFlags(node) & PDOMName.WRITE_ACCESS) != 0);
}
int flag = isWrite ? F_WRITE_OCCURRENCE : F_READ_OCCURRENCE;
String description = isWrite ? fWriteDescription : fReadDescription;
final boolean isWriteOccurrence = CSearchUtil.isWriteOccurrence(node, binding);
int flag = isWriteOccurrence ? F_WRITE_OCCURRENCE : F_READ_OCCURRENCE;
String description = isWriteOccurrence ? fWriteDescription : fReadDescription;
fResult.add(new OccurrenceLocation(offset, length, flag, description));
}
else {

View file

@ -19,6 +19,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.StyledString.Styler;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
@ -169,7 +170,8 @@ public class PDOMSearchLabelProvider extends LabelProvider implements IStyledLab
for (Match match : lineElement.getMatches()) {
int offset = Math.max(0, match.getOffset() - lineOffset);
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;
}

View file

@ -45,7 +45,9 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IPositionConverter;
import org.eclipse.cdt.core.browser.ITypeReference;
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.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
@ -200,10 +202,7 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
if (names == null)
return;
ICProject preferred= null;
if (projects != null && projects.length == 1) {
preferred= projects[0];
}
ICProject preferred = getPreferredProject();
for (IIndexName name : names) {
if (!filterName(name)) {
if (!isPolymorphicOnly || name.couldBePolymorphicMethodCall()) {
@ -221,7 +220,8 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
if (enclosingDefinition != null) {
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();
boolean isPolymorphicCall = match.isPolymorphicCall();
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;
}
@ -354,7 +355,7 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
names.addAll(Arrays.asList(bindingNames));
}
protected void createLocalMatches(IASTTranslationUnit ast, IBinding binding) {
protected void createLocalMatches(IASTTranslationUnit ast, IBinding binding) throws CoreException {
if (binding != null) {
Set<IASTName> names= new HashSet<IASTName>();
names.addAll(Arrays.asList(ast.getDeclarationsInAST(binding)));
@ -371,7 +372,17 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
if (typeInfo != null) {
ITypeReference ref= typeInfo.getResolvedReference();
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();
}
}
@ -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 {
PDOMSearchResult result= (PDOMSearchResult) getSearchResult();
result.removeAll();