mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for 197643: coloring macro references
Fix deprecation warnings
This commit is contained in:
parent
46aa7c01e8
commit
8de29f871a
3 changed files with 44 additions and 44 deletions
|
@ -33,7 +33,6 @@ import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansion;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
@ -1202,7 +1201,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
||||||
* @param astName
|
* @param astName
|
||||||
* @throws CModelException
|
* @throws CModelException
|
||||||
*/
|
*/
|
||||||
private void setIdentifierPosition(SourceManipulation element, IASTNode astName) throws CModelException {
|
private void setIdentifierPosition(SourceManipulation element, IASTName astName) throws CModelException {
|
||||||
setIdentifierPosition(element.getSourceManipulationInfo(), astName);
|
setIdentifierPosition(element.getSourceManipulationInfo(), astName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1213,9 +1212,13 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
||||||
* @param astName
|
* @param astName
|
||||||
*/
|
*/
|
||||||
private void setIdentifierPosition(SourceManipulationInfo info, IASTNode astName) {
|
private void setIdentifierPosition(SourceManipulationInfo info, IASTNode astName) {
|
||||||
final IASTFileLocation location= astName.getFileLocation();
|
final IASTFileLocation location;
|
||||||
|
if (astName instanceof IASTName) {
|
||||||
|
location= ((IASTName)astName).getImageLocation();
|
||||||
|
} else {
|
||||||
|
location= astName.getFileLocation();
|
||||||
|
}
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
assert fTranslationUnitFileName.equals(location.getFileName());
|
|
||||||
info.setIdPos(location.getNodeOffset(), location.getNodeLength());
|
info.setIdPos(location.getNodeOffset(), location.getNodeLength());
|
||||||
} else {
|
} else {
|
||||||
final IASTNodeLocation[] locations= astName.getNodeLocations();
|
final IASTNodeLocation[] locations= astName.getNodeLocations();
|
||||||
|
@ -1236,13 +1239,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final IASTNodeLocation nodeLocation= locations[locations.length-1];
|
final IASTNodeLocation nodeLocation= locations[locations.length-1];
|
||||||
if (nodeLocation instanceof IASTFileLocation) {
|
return nodeLocation.asFileLocation();
|
||||||
return (IASTFileLocation)nodeLocation;
|
|
||||||
} else if (nodeLocation instanceof IASTMacroExpansion) {
|
|
||||||
IASTNodeLocation[] macroLocations= ((IASTMacroExpansion)nodeLocation).getExpansionLocations();
|
|
||||||
return getMaxFileLocation(macroLocations);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IASTFileLocation getMinFileLocation(IASTNodeLocation[] locations) {
|
private static IASTFileLocation getMinFileLocation(IASTNodeLocation[] locations) {
|
||||||
|
@ -1250,13 +1247,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final IASTNodeLocation nodeLocation= locations[0];
|
final IASTNodeLocation nodeLocation= locations[0];
|
||||||
if (nodeLocation instanceof IASTFileLocation) {
|
return nodeLocation.asFileLocation();
|
||||||
return (IASTFileLocation)nodeLocation;
|
|
||||||
} else if (nodeLocation instanceof IASTMacroExpansion) {
|
|
||||||
IASTNodeLocation[] macroLocations= ((IASTMacroExpansion)nodeLocation).getExpansionLocations();
|
|
||||||
return getMinFileLocation(macroLocations);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,7 +26,6 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansion;
|
|
||||||
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.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||||
|
@ -515,13 +514,7 @@ class CStructureCreatorVisitor extends CPPASTVisitor {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final IASTNodeLocation nodeLocation= locations[locations.length-1];
|
final IASTNodeLocation nodeLocation= locations[locations.length-1];
|
||||||
if (nodeLocation instanceof IASTFileLocation) {
|
return nodeLocation.asFileLocation();
|
||||||
return (IASTFileLocation)nodeLocation;
|
|
||||||
} else if (nodeLocation instanceof IASTMacroExpansion) {
|
|
||||||
IASTNodeLocation[] macroLocations= ((IASTMacroExpansion)nodeLocation).getExpansionLocations();
|
|
||||||
return getMaxFileLocation(macroLocations);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IASTFileLocation getMinFileLocation(IASTNodeLocation[] locations) {
|
private static IASTFileLocation getMinFileLocation(IASTNodeLocation[] locations) {
|
||||||
|
@ -529,12 +522,6 @@ class CStructureCreatorVisitor extends CPPASTVisitor {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final IASTNodeLocation nodeLocation= locations[0];
|
final IASTNodeLocation nodeLocation= locations[0];
|
||||||
if (nodeLocation instanceof IASTFileLocation) {
|
return nodeLocation.asFileLocation();
|
||||||
return (IASTFileLocation)nodeLocation;
|
|
||||||
} else if (nodeLocation instanceof IASTMacroExpansion) {
|
|
||||||
IASTNodeLocation[] macroLocations= ((IASTMacroExpansion)nodeLocation).getExpansionLocations();
|
|
||||||
return getMinFileLocation(macroLocations);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTImageLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansion;
|
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansion;
|
||||||
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.IASTNode;
|
||||||
|
@ -200,7 +201,7 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
|
||||||
final int useOffset = useLocation.getNodeOffset();
|
final int useOffset = useLocation.getNodeOffset();
|
||||||
if (useOffset <= fMinLocation) {
|
if (useOffset <= fMinLocation) {
|
||||||
// performance: we had that macro expansion already
|
// performance: we had that macro expansion already
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
fMinLocation= useOffset;
|
fMinLocation= useOffset;
|
||||||
// TLETODO This does not work correctly for nested macro substitutions
|
// TLETODO This does not work correctly for nested macro substitutions
|
||||||
|
@ -214,7 +215,7 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
|
||||||
}
|
}
|
||||||
IASTNode macroNode= node.getTranslationUnit().selectNodeForLocation(fFilePath, useOffset, macroLength);
|
IASTNode macroNode= node.getTranslationUnit().selectNodeForLocation(fFilePath, useOffset, macroLength);
|
||||||
if (macroNode != null && visitMacro(macroNode, macroLength)) {
|
if (macroNode != null && visitMacro(macroNode, macroLength)) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,7 +227,11 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
|
||||||
for (int i= 0, n= fJobSemanticHighlightings.length; i < n; ++i) {
|
for (int i= 0, n= fJobSemanticHighlightings.length; i < n; ++i) {
|
||||||
SemanticHighlighting semanticHighlighting= fJobSemanticHighlightings[i];
|
SemanticHighlighting semanticHighlighting= fJobSemanticHighlightings[i];
|
||||||
if (fJobHighlightings[i].isEnabled() && semanticHighlighting.consumes(fToken)) {
|
if (fJobHighlightings[i].isEnabled() && semanticHighlighting.consumes(fToken)) {
|
||||||
addMacroLocation(node.getFileLocation(), macroLength, fJobHighlightings[i]);
|
if (node instanceof IASTName) {
|
||||||
|
addNameLocation((IASTName)node, fJobHighlightings[i]);
|
||||||
|
} else {
|
||||||
|
addMacroLocation(node.getFileLocation(), macroLength, fJobHighlightings[i]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,7 +246,11 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
|
||||||
for (int i= 0, n= fJobSemanticHighlightings.length; i < n; ++i) {
|
for (int i= 0, n= fJobSemanticHighlightings.length; i < n; ++i) {
|
||||||
SemanticHighlighting semanticHighlighting= fJobSemanticHighlightings[i];
|
SemanticHighlighting semanticHighlighting= fJobSemanticHighlightings[i];
|
||||||
if (fJobHighlightings[i].isEnabled() && semanticHighlighting.consumes(fToken)) {
|
if (fJobHighlightings[i].isEnabled() && semanticHighlighting.consumes(fToken)) {
|
||||||
addNodeLocation(node.getFileLocation(), fJobHighlightings[i]);
|
if (node instanceof IASTName) {
|
||||||
|
addNameLocation((IASTName)node, fJobHighlightings[i]);
|
||||||
|
} else {
|
||||||
|
addNodeLocation(node.getFileLocation(), fJobHighlightings[i]);
|
||||||
|
}
|
||||||
consumed= true;
|
consumed= true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -250,6 +259,25 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
|
||||||
return consumed;
|
return consumed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the a location range for the given name.
|
||||||
|
*
|
||||||
|
* @param name The name
|
||||||
|
* @param highlighting The highlighting
|
||||||
|
*/
|
||||||
|
private void addNameLocation(IASTName name, HighlightingStyle highlightingStyle) {
|
||||||
|
IASTImageLocation imageLocation= name.getImageLocation();
|
||||||
|
if (imageLocation == null) {
|
||||||
|
addNodeLocation(name.getFileLocation(), highlightingStyle);
|
||||||
|
} else {
|
||||||
|
int offset= imageLocation.getNodeOffset();
|
||||||
|
int length= imageLocation.getNodeLength();
|
||||||
|
if (offset > -1 && length > 0) {
|
||||||
|
addPosition(offset, length, highlightingStyle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the a location range for the given highlighting.
|
* Add the a location range for the given highlighting.
|
||||||
*
|
*
|
||||||
|
@ -290,13 +318,7 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final IASTNodeLocation nodeLocation= locations[0];
|
final IASTNodeLocation nodeLocation= locations[0];
|
||||||
if (nodeLocation instanceof IASTFileLocation) {
|
return nodeLocation.asFileLocation();
|
||||||
return (IASTFileLocation)nodeLocation;
|
|
||||||
} else if (nodeLocation instanceof IASTMacroExpansion) {
|
|
||||||
IASTNodeLocation[] macroLocations= ((IASTMacroExpansion)nodeLocation).getExpansionLocations();
|
|
||||||
return getMinFileLocation(macroLocations);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue