mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Bug 399149 - Syntax-coloring for class-virt-specifier
Change-Id: I13bd4b3fcc82e1ce0339f2a357f0854f9e56bba8 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com> Reviewed-on: https://git.eclipse.org/r/26555 Tested-by: Hudson CI Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
parent
c8b14a3c3e
commit
a7b73d776c
12 changed files with 194 additions and 15 deletions
|
@ -17,6 +17,7 @@ package org.eclipse.cdt.core.dom.ast;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCapture;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTClassVirtSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
|
@ -329,6 +330,13 @@ public abstract class ASTVisitor {
|
|||
public int visit(ICPPASTVirtSpecifier virtSpecifier) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 5.7
|
||||
*/
|
||||
public int visit(ICPPASTClassVirtSpecifier classVirtSpecifier) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
// leave methods
|
||||
public int leave(IASTTranslationUnit tu) {
|
||||
|
@ -446,6 +454,13 @@ public abstract class ASTVisitor {
|
|||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 5.7
|
||||
*/
|
||||
public int leave(ICPPASTClassVirtSpecifier virtSpecifier) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link IASTTranslationUnit#getComments()}, instead.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Nathan Ridge.
|
||||
* 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:
|
||||
* Nathan Ridge - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
|
||||
/**
|
||||
* A class-virt-specifier after a class name.
|
||||
* There is currently one specifier, 'final'.
|
||||
*
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
* @noextend This interface is not intended to be extended by clients.
|
||||
* @since 5.7
|
||||
*/
|
||||
public interface ICPPASTClassVirtSpecifier extends IASTNode {
|
||||
|
||||
public enum SpecifierKind {
|
||||
/**
|
||||
* 'final' specifier
|
||||
*/
|
||||
Final
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the kind of this class-virt-specifier.
|
||||
* Currently the only kind is 'final'.
|
||||
*/
|
||||
SpecifierKind getKind();
|
||||
|
||||
@Override
|
||||
public ICPPASTClassVirtSpecifier copy();
|
||||
|
||||
@Override
|
||||
public ICPPASTClassVirtSpecifier copy(CopyStyle style);
|
||||
}
|
|
@ -45,6 +45,10 @@ public interface ICPPASTCompositeTypeSpecifier extends IASTCompositeTypeSpecifie
|
|||
*/
|
||||
public static final ASTNodeProperty BASE_SPECIFIER = new ASTNodeProperty(
|
||||
"ICPPASTCompositeTypeSpecifier.BASE_SPECIFIER - Expresses the subclass role"); //$NON-NLS-1$
|
||||
|
||||
/** @since 5.7 */
|
||||
public static final ASTNodeProperty CLASS_VIRT_SPECIFIER = new ASTNodeProperty(
|
||||
"ICPPASTCompositeTypeSpecifier.CLASS_VIRT_SPECIFIER [ICPPASTClassVirtSpecifier]"); //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Base Specifiers are where a class expresses from whom it inherits.
|
||||
|
@ -150,6 +154,20 @@ public interface ICPPASTCompositeTypeSpecifier extends IASTCompositeTypeSpecifie
|
|||
* Sets whether the type is final.
|
||||
*
|
||||
* @since 5.5
|
||||
* @deprecated Use setVirtSpecifier() instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setFinal(boolean isFinal);
|
||||
|
||||
/**
|
||||
* Returns the class-virt-specifier of this class, or null if it doesn't have one.
|
||||
* @since 5.7
|
||||
*/
|
||||
public ICPPASTClassVirtSpecifier getVirtSpecifier();
|
||||
|
||||
/**
|
||||
* Set the class-virt-specifier for this class.
|
||||
* @since 5.7
|
||||
*/
|
||||
public void setVirtSpecifier(ICPPASTClassVirtSpecifier virtSpecifier);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|||
import org.eclipse.cdt.core.dom.ast.INodeFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUnaryTypeTransformation.Operator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVirtSpecifier.SpecifierKind;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPASTAttributeSpecifier;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
|
||||
|
@ -91,6 +90,11 @@ public interface ICPPNodeFactory extends INodeFactory {
|
|||
|
||||
public ICPPASTCatchHandler newCatchHandler(IASTDeclaration decl, IASTStatement body);
|
||||
|
||||
/**
|
||||
* @since 5.7
|
||||
*/
|
||||
public ICPPASTClassVirtSpecifier newClassVirtSpecifier(ICPPASTClassVirtSpecifier.SpecifierKind kind);
|
||||
|
||||
@Override
|
||||
public ICPPASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name);
|
||||
|
||||
|
@ -384,7 +388,7 @@ public interface ICPPNodeFactory extends INodeFactory {
|
|||
/**
|
||||
* @since 5.7
|
||||
*/
|
||||
public ICPPASTVirtSpecifier newVirtSpecifier(SpecifierKind kind);
|
||||
public ICPPASTVirtSpecifier newVirtSpecifier(ICPPASTVirtSpecifier.SpecifierKind kind);
|
||||
|
||||
public ICPPASTVisibilityLabel newVisibilityLabel(int visibility);
|
||||
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Nathan Ridge.
|
||||
* 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:
|
||||
* Nathan Ridge - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTClassVirtSpecifier;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
|
||||
public class CPPASTClassVirtSpecifier extends ASTNode implements ICPPASTClassVirtSpecifier {
|
||||
// Not much point storing the kind while there is only one.
|
||||
|
||||
@Override
|
||||
public SpecifierKind getKind() {
|
||||
return SpecifierKind.Final;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTClassVirtSpecifier copy() {
|
||||
return copy(CopyStyle.withoutLocations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTClassVirtSpecifier copy(CopyStyle style) {
|
||||
CPPASTClassVirtSpecifier copy = new CPPASTClassVirtSpecifier();
|
||||
return copy(copy, style);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(ASTVisitor action) {
|
||||
if (action.shouldVisitVirtSpecifiers) {
|
||||
switch (action.visit(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT: return false;
|
||||
case ASTVisitor.PROCESS_SKIP: return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
if (action.shouldVisitVirtSpecifiers) {
|
||||
switch (action.leave(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT: return false;
|
||||
case ASTVisitor.PROCESS_SKIP: return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTClassVirtSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
|
@ -37,7 +38,7 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
|
|||
private ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier[] baseSpecs;
|
||||
private int baseSpecsPos = -1;
|
||||
private boolean fAmbiguitiesResolved;
|
||||
private boolean isFinal;
|
||||
private ICPPASTClassVirtSpecifier virtSpecifier;
|
||||
|
||||
public CPPASTCompositeTypeSpecifier() {
|
||||
}
|
||||
|
@ -67,7 +68,7 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
|
|||
copy.addMemberDeclaration(member == null ? null : member.copy(style));
|
||||
for (ICPPASTBaseSpecifier baseSpecifier : getBaseSpecifiers())
|
||||
copy.addBaseSpecifier(baseSpecifier == null ? null : baseSpecifier.copy(style));
|
||||
copy.isFinal = isFinal;
|
||||
copy.setVirtSpecifier(virtSpecifier == null ? null : virtSpecifier.copy(style));
|
||||
return super.copy(copy, style);
|
||||
}
|
||||
|
||||
|
@ -185,6 +186,9 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
|
|||
if (fName != null && !fName.accept(action))
|
||||
return false;
|
||||
|
||||
if (virtSpecifier != null && !virtSpecifier.accept(action))
|
||||
return false;
|
||||
|
||||
ICPPASTBaseSpecifier[] bases = getBaseSpecifiers();
|
||||
for (int i = 0; i < bases.length; i++) {
|
||||
if (!bases[i].accept(action))
|
||||
|
@ -225,12 +229,28 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
|
|||
|
||||
@Override
|
||||
public boolean isFinal() {
|
||||
return isFinal;
|
||||
return virtSpecifier != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setFinal(boolean value) {
|
||||
assertNotFrozen();
|
||||
isFinal = value;
|
||||
// Do nothing here. Use setVirtSpecifier() instead.
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTClassVirtSpecifier getVirtSpecifier() {
|
||||
return virtSpecifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVirtSpecifier(ICPPASTClassVirtSpecifier virtSpecifier) {
|
||||
assertNotFrozen();
|
||||
this.virtSpecifier = virtSpecifier;
|
||||
if (virtSpecifier != null) {
|
||||
virtSpecifier.setParent(this);
|
||||
virtSpecifier.setPropertyInParent(CLASS_VIRT_SPECIFIER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCapture;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTClassVirtSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||
|
@ -226,6 +227,13 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
|
|||
return new CPPASTCatchHandler(decl, body);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTClassVirtSpecifier newClassVirtSpecifier(ICPPASTClassVirtSpecifier.SpecifierKind kind) {
|
||||
// Don't use the 'kind' argument as there is currently only one kind.
|
||||
assert kind == ICPPASTClassVirtSpecifier.SpecifierKind.Final;
|
||||
return new CPPASTClassVirtSpecifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name) {
|
||||
return new CPPASTCompositeTypeSpecifier(key, name);
|
||||
|
|
|
@ -96,6 +96,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerList;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression.CaptureDefault;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTClassVirtSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTName;
|
||||
|
@ -129,7 +130,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVirtSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVirtSpecifier.SpecifierKind;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNodeFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUnaryTypeTransformation;
|
||||
|
@ -3623,12 +3623,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
char[] tokenImage = token.getCharImage();
|
||||
if (Arrays.equals(Keywords.cOVERRIDE, tokenImage)) {
|
||||
consume();
|
||||
ICPPASTVirtSpecifier spec = nodeFactory.newVirtSpecifier(SpecifierKind.Override);
|
||||
ICPPASTVirtSpecifier spec = nodeFactory.newVirtSpecifier(
|
||||
ICPPASTVirtSpecifier.SpecifierKind.Override);
|
||||
setRange(spec, token.getOffset(), token.getOffset() + token.getLength());
|
||||
typeRelevantDtor.addVirtSpecifier(spec);
|
||||
} else if (Arrays.equals(Keywords.cFINAL, tokenImage)) {
|
||||
consume();
|
||||
ICPPASTVirtSpecifier spec = nodeFactory.newVirtSpecifier(SpecifierKind.Final);
|
||||
ICPPASTVirtSpecifier spec = nodeFactory.newVirtSpecifier(
|
||||
ICPPASTVirtSpecifier.SpecifierKind.Final);
|
||||
setRange(spec, token.getOffset(), token.getOffset() + token.getLength());
|
||||
typeRelevantDtor.addVirtSpecifier(spec);
|
||||
} else {
|
||||
|
@ -4454,7 +4456,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
char[] tokenImage = token.getCharImage();
|
||||
if (token.getType() == IToken.tIDENTIFIER && Arrays.equals(Keywords.cFINAL, tokenImage)){
|
||||
consume();
|
||||
astClassSpecifier.setFinal(true);
|
||||
ICPPASTClassVirtSpecifier spec = nodeFactory.newClassVirtSpecifier(
|
||||
ICPPASTClassVirtSpecifier.SpecifierKind.Final);
|
||||
setRange(spec, token.getOffset(), token.getOffset() + token.getLength());
|
||||
astClassSpecifier.setVirtSpecifier(spec);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -153,7 +153,7 @@ void g() {
|
|||
}
|
||||
|
||||
//http://bugs.eclipse.org/399149
|
||||
class C {
|
||||
class C final {
|
||||
void finalMethod() final;
|
||||
void overrideMethod() override;
|
||||
|
||||
|
|
|
@ -435,6 +435,7 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
|
|||
setUpSemanticHighlighting(ICColorConstants.C_KEYWORD);
|
||||
Position[] actual= getSemanticHighlightingPositions();
|
||||
Position[] expected= new Position[] {
|
||||
createPosition(155, 8, 5),
|
||||
createPosition(156, 23, 5),
|
||||
createPosition(157, 26, 8),
|
||||
};
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTClassVirtSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVirtSpecifier;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
|
@ -170,6 +171,12 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
|
|||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(ICPPASTClassVirtSpecifier classVirtSpecifier) {
|
||||
visitNode(classVirtSpecifier);
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
private boolean visitNode(IASTNode node) {
|
||||
boolean consumed= false;
|
||||
fToken.update(node);
|
||||
|
|
|
@ -43,6 +43,7 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
|
|||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTClassVirtSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNameSpecifier;
|
||||
|
@ -1517,10 +1518,12 @@ public class SemanticHighlightings {
|
|||
|
||||
@Override
|
||||
public boolean consumes(ISemanticToken token) {
|
||||
// Currently the only context-sensitive keywords are 'final'
|
||||
// and 'override', both of which are virt-specifiers at the
|
||||
// end of a method declaration.
|
||||
return token.getNode() instanceof ICPPASTVirtSpecifier;
|
||||
// Currently the only context-sensitive keywords are the
|
||||
// 'final' and 'override' virt-specifiers at the end of a
|
||||
// method declaration, and the 'final' class-virt-specifier
|
||||
// after a class name.
|
||||
return token.getNode() instanceof ICPPASTVirtSpecifier
|
||||
|| token.getNode() instanceof ICPPASTClassVirtSpecifier;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue