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

Cosmetics.

This commit is contained in:
Sergey Prigogin 2014-05-07 18:28:05 -07:00
parent 1ae15f57fa
commit b88109c7f4
5 changed files with 40 additions and 58 deletions

View file

@ -6,22 +6,23 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* John Camelon (IBM) - Initial API and implementation * John Camelon (IBM) - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
/** /**
* This interface represent a preprocessor function-style macro definition. e.g. * This interface represent a preprocessor function-style macro definition. e.g.
* #define ABC( def ) GHI * <pre>
* * #define ABC(def) GHI
* Note: macros that are expanded as parameters to function style macros are not captured in this abstraction. * </pre>
* Note: macros that are expanded as parameters to function style macros are not captured in this
* abstraction.
* *
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface IASTPreprocessorFunctionStyleMacroDefinition extends public interface IASTPreprocessorFunctionStyleMacroDefinition extends
IASTPreprocessorMacroDefinition { IASTPreprocessorMacroDefinition {
/** /**
* This property represents the relationship between a function style macro * This property represents the relationship between a function style macro
* definition and one of its parameters. * definition and one of its parameters.
@ -30,18 +31,16 @@ public interface IASTPreprocessorFunctionStyleMacroDefinition extends
"IASTPreprocessorFunctionStyleMacroDefinition.PARAMETER - Function Macro Parameter"); //$NON-NLS-1$ "IASTPreprocessorFunctionStyleMacroDefinition.PARAMETER - Function Macro Parameter"); //$NON-NLS-1$
/** /**
* Get the macro parameters. * Returns the macro parameters.
* *
* @return <code>IASTFunctionStyleMacroParameter[]</code> parameters * @return <code>IASTFunctionStyleMacroParameter[]</code> parameters
*/ */
public IASTFunctionStyleMacroParameter[] getParameters(); public IASTFunctionStyleMacroParameter[] getParameters();
/** /**
* Add a function-style macro parameter. * Adds a function-style macro parameter.
* *
* @param parm * @param parm the parameter to add
* <code>IASTFunctionStyleMacroParameter</code>
*/ */
public void addParameter(IASTFunctionStyleMacroParameter parm); public void addParameter(IASTFunctionStyleMacroParameter parm);
} }

View file

@ -6,18 +6,18 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* John Camelon (IBM) - Initial API and implementation * John Camelon (IBM) - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
/** /**
* This interface represents an object-style macro definition. e.g. #define * This interface represents an object-style macro definition. e.g.
* ONE_TWO_THREE 123 * <pre>
* #define ONE_TWO_THREE 123
* </pre>
* *
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface IASTPreprocessorObjectStyleMacroDefinition extends public interface IASTPreprocessorObjectStyleMacroDefinition extends IASTPreprocessorMacroDefinition {
IASTPreprocessorMacroDefinition {
} }

View file

@ -125,7 +125,7 @@ class ASTComment extends ASTPreprocessorNode implements IASTComment {
@Override @Override
public int getOffset() { public int getOffset() {
if (fFilePath != null) { if (fFilePath != null) {
// Perform lazy conversion to sequence number // Perform lazy conversion to sequence number.
ILocationResolver lr= (ILocationResolver) getTranslationUnit().getAdapter(ILocationResolver.class); ILocationResolver lr= (ILocationResolver) getTranslationUnit().getAdapter(ILocationResolver.class);
if (lr != null) { if (lr != null) {
setOffset(lr.getSequenceNumberForFileOffset(fFilePath, super.getOffset())); setOffset(lr.getSequenceNumberForFileOffset(fFilePath, super.getOffset()));
@ -192,6 +192,7 @@ class ASTElse extends ASTPreprocessorNode implements IASTPreprocessorElseStateme
super(parent, IASTTranslationUnit.PREPROCESSOR_STATEMENT, startNumber, endNumber); super(parent, IASTTranslationUnit.PREPROCESSOR_STATEMENT, startNumber, endNumber);
fTaken= taken; fTaken= taken;
} }
@Override @Override
public boolean taken() { public boolean taken() {
return fTaken; return fTaken;
@ -207,9 +208,7 @@ class ASTIfndef extends ASTDirectiveWithCondition implements IASTPreprocessorIfn
fMacroRef= new ASTMacroReferenceName(this, IASTPreprocessorStatement.MACRO_NAME, condNumber, condEndNumber, macro, null); fMacroRef= new ASTMacroReferenceName(this, IASTPreprocessorStatement.MACRO_NAME, condNumber, condEndNumber, macro, null);
} }
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfdefStatement#getMacroReference()
*/
@Override @Override
public ASTPreprocessorName getMacroReference() { public ASTPreprocessorName getMacroReference() {
return fMacroRef; return fMacroRef;
@ -224,9 +223,7 @@ class ASTIfdef extends ASTDirectiveWithCondition implements IASTPreprocessorIfde
fMacroRef= new ASTMacroReferenceName(this, IASTPreprocessorStatement.MACRO_NAME, condNumber, condEndNumber, macro, null); fMacroRef= new ASTMacroReferenceName(this, IASTPreprocessorStatement.MACRO_NAME, condNumber, condEndNumber, macro, null);
} }
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfdefStatement#getMacroReference()
*/
@Override @Override
public ASTPreprocessorName getMacroReference() { public ASTPreprocessorName getMacroReference() {
return fMacroRef; return fMacroRef;
@ -816,25 +813,16 @@ class ASTMacroExpansion extends ASTPreprocessorNode implements IASTPreprocessorM
fContext= expansionCtx; fContext= expansionCtx;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion#getName()
*/
@Override @Override
public ASTMacroReferenceName getMacroReference() { public ASTMacroReferenceName getMacroReference() {
return fContext.getMacroReference(); return fContext.getMacroReference();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion#getMacroDefinition()
*/
@Override @Override
public IASTPreprocessorMacroDefinition getMacroDefinition() { public IASTPreprocessorMacroDefinition getMacroDefinition() {
return fContext.getMacroDefinition(); return fContext.getMacroDefinition();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion#getNestedExpansions()
*/
@Override @Override
public ASTPreprocessorName[] getNestedMacroReferences() { public ASTPreprocessorName[] getNestedMacroReferences() {
return fContext.getNestedMacroReferences(); return fContext.getNestedMacroReferences();
@ -857,9 +845,6 @@ class ASTMacroExpansionLocation implements IASTMacroExpansionLocation, org.eclip
fLength= length; fLength= length;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation#getExpansion()
*/
@Override @Override
public IASTPreprocessorMacroExpansion getExpansion() { public IASTPreprocessorMacroExpansion getExpansion() {
return fContext.getExpansion(); return fContext.getExpansion();

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.rename; package org.eclipse.cdt.internal.ui.refactoring.rename;
@ -22,9 +22,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
* Visitor to prefer simple ASTNames over the qualified ones. This is different * Visitor to prefer simple ASTNames over the qualified ones. This is different
* to the strategy used within the dom-package. * to the strategy used within the dom-package.
*/ */
abstract public class ASTNameVisitor extends ASTVisitor { public abstract class ASTNameVisitor extends ASTVisitor {
private int fOffset= -1; private final int fOffset;
private String fFileName; private final String fFileName;
public ASTNameVisitor(String fileName) { public ASTNameVisitor(String fileName) {
this(fileName, -1); this(fileName, -1);
@ -33,20 +33,21 @@ abstract public class ASTNameVisitor extends ASTVisitor {
public ASTNameVisitor(String fileName, int offset) { public ASTNameVisitor(String fileName, int offset) {
fFileName= fileName; fFileName= fileName;
fOffset= offset; fOffset= offset;
shouldVisitNames=true; shouldVisitNames = true;
} }
abstract protected int visitName(IASTName name); abstract protected int visitName(IASTName name);
@Override @Override
final public int visit(IASTName name) { public final int visit(IASTName name) {
if (name instanceof ICPPASTQualifiedName) { if (name instanceof ICPPASTQualifiedName) {
ICPPASTQualifiedName qn= (ICPPASTQualifiedName) name; ICPPASTQualifiedName qn= (ICPPASTQualifiedName) name;
ICPPASTNameSpecifier[] segments= qn.getAllSegments(); ICPPASTNameSpecifier[] segments= qn.getQualifier();
boolean visited= false; boolean visited= false;
for (int i = 0; i < segments.length; i++) { for (int i = 0; i <= segments.length; i++) {
if (segments[i] instanceof IASTName && checkLocation(segments[i])) { IASTNode segment = i < segments.length ? segments[i] : qn.getLastName();
if (visitName((IASTName) segments[i]) == PROCESS_ABORT) { if (segment instanceof IASTName && checkLocation(segment)) {
if (visitName((IASTName) segment) == PROCESS_ABORT) {
return PROCESS_ABORT; return PROCESS_ABORT;
} }
visited= true; visited= true;
@ -57,15 +58,14 @@ abstract public class ASTNameVisitor extends ASTVisitor {
return visitName(name.getLastName()); return visitName(name.getLastName());
} }
} }
} } else if (checkLocation(name)) {
else if (checkLocation(name)) {
return visitName(name); return visitName(name);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
private boolean checkLocation(IASTNode node) { private boolean checkLocation(IASTNode node) {
if (fFileName==null) { if (fFileName == null) {
return true; return true;
} }
if (!fFileName.equals(node.getContainingFilename())) { if (!fFileName.equals(node.getContainingFilename())) {
@ -74,23 +74,22 @@ abstract public class ASTNameVisitor extends ASTVisitor {
IASTFileLocation loc= null; IASTFileLocation loc= null;
if (node instanceof IASTName) { if (node instanceof IASTName) {
loc= ASTManager.getImageFileLocation((IASTName) node); loc= ASTManager.getImageFileLocation((IASTName) node);
} } else {
else {
IASTNodeLocation[] locs= node.getNodeLocations(); IASTNodeLocation[] locs= node.getNodeLocations();
if (locs!=null && locs.length==1) { if (locs != null && locs.length == 1) {
if (locs[0] instanceof IASTFileLocation) { if (locs[0] instanceof IASTFileLocation) {
loc= (IASTFileLocation) locs[0]; loc= (IASTFileLocation) locs[0];
} }
} }
} }
if (loc==null) { if (loc == null) {
return false; return false;
} }
if (fOffset==-1) { if (fOffset == -1) {
return true; return true;
} }
int off= loc.getNodeOffset(); int off= loc.getNodeOffset();
int len = loc.getNodeLength(); int len = loc.getNodeLength();
return off <= fOffset && fOffset < off+len; return off <= fOffset && fOffset < off + len;
} }
} }

View file

@ -6,9 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.rename; package org.eclipse.cdt.internal.ui.refactoring.rename;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
@ -17,7 +16,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
public abstract class ASTSpecificNameVisitor extends ASTNameVisitor { public abstract class ASTSpecificNameVisitor extends ASTNameVisitor {
private String fSearchForName; private final String fSearchForName;
public ASTSpecificNameVisitor(String name) { public ASTSpecificNameVisitor(String name) {
super(null); super(null);
@ -25,7 +24,7 @@ public abstract class ASTSpecificNameVisitor extends ASTNameVisitor {
} }
@Override @Override
final public int visitName(IASTName name) { public final int visitName(IASTName name) {
if (name instanceof ICPPASTTemplateId || name instanceof ICPPASTQualifiedName) if (name instanceof ICPPASTTemplateId || name instanceof ICPPASTQualifiedName)
return PROCESS_CONTINUE; return PROCESS_CONTINUE;