diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTTemplateDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTTemplateDeclaration.java index 0464a48212f..6026aee47fe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTTemplateDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTTemplateDeclaration.java @@ -44,14 +44,14 @@ public interface ICPPASTTemplateDeclaration extends IASTDeclaration { "ICPPASTTemplateDeclaration.OWNED_DECLARATION - Subdeclaration maintained grammatically"); //$NON-NLS-1$ /** - * Get templated declaration. + * Get template declaration. * * @return IASTDeclaration */ public IASTDeclaration getDeclaration(); /** - * Set the templated declaration. + * Set the template declaration. * * @param declaration * IASTDeclaration @@ -67,18 +67,24 @@ public interface ICPPASTTemplateDeclaration extends IASTDeclaration { /** * Get template parameters. * - * @return ICPPASTTemplateParameter [] + * @return ICPPASTTemplateParameter[] */ public ICPPASTTemplateParameter[] getTemplateParameters(); /** * Add a template parameter. * - * @param parm - * ICPPASTTemplateParameter + * @param parm ICPPASTTemplateParameter + * @since 5.2 */ + public void addTemplateParameter(ICPPASTTemplateParameter parm); + + /** + * @deprecated Use addTemplateParameter. + */ + @Deprecated public void addTemplateParamter(ICPPASTTemplateParameter parm); - + /** * get the template scope representing this declaration in the logical tree * @return ICPPTemplateScope diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java index ee76c385100..8b6d4175ffb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java @@ -32,7 +32,8 @@ public class CPPASTTemplateDeclaration extends ASTNode implements private short nestingLevel= -1; private IASTDeclaration declaration; private ICPPTemplateScope templateScope; - + private ICPPASTTemplateParameter[] parameters = null; + private int parametersPos= -1; public CPPASTTemplateDeclaration() { } @@ -45,8 +46,8 @@ public class CPPASTTemplateDeclaration extends ASTNode implements CPPASTTemplateDeclaration copy = new CPPASTTemplateDeclaration(); copy.setDeclaration(declaration == null ? null : declaration.copy()); copy.exported = exported; - for(ICPPASTTemplateParameter param : getTemplateParameters()) - copy.addTemplateParamter(param == null ? null : param.copy()); + for (ICPPASTTemplateParameter param : getTemplateParameters()) + copy.addTemplateParameter(param == null ? null : param.copy()); copy.setOffsetAndLength(this); return copy; } @@ -73,61 +74,63 @@ public class CPPASTTemplateDeclaration extends ASTNode implements } } - public ICPPASTTemplateParameter [] getTemplateParameters() { - if( parameters == null ) return ICPPASTTemplateParameter.EMPTY_TEMPLATEPARAMETER_ARRAY; - parameters = (ICPPASTTemplateParameter[]) ArrayUtil.removeNullsAfter( ICPPASTTemplateParameter.class, parameters, parametersPos ); + public ICPPASTTemplateParameter[] getTemplateParameters() { + if (parameters == null) return ICPPASTTemplateParameter.EMPTY_TEMPLATEPARAMETER_ARRAY; + parameters = (ICPPASTTemplateParameter[]) ArrayUtil.removeNullsAfter(ICPPASTTemplateParameter.class, parameters, parametersPos); return parameters; } - public void addTemplateParamter(ICPPASTTemplateParameter parm) { + public void addTemplateParameter(ICPPASTTemplateParameter parm) { assertNotFrozen(); if (parm != null) { - parameters = (ICPPASTTemplateParameter[]) ArrayUtil.append( ICPPASTTemplateParameter.class, parameters, ++parametersPos, parm ); + parameters = (ICPPASTTemplateParameter[]) ArrayUtil.append(ICPPASTTemplateParameter.class, parameters, ++parametersPos, parm); parm.setParent(this); parm.setPropertyInParent(PARAMETER); } } - private ICPPASTTemplateParameter [] parameters = null; - private int parametersPos=-1; + @Deprecated + public void addTemplateParamter(ICPPASTTemplateParameter param) { + addTemplateParameter(param); + } + @Override - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitDeclarations ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - ICPPASTTemplateParameter [] params = getTemplateParameters(); - for ( int i = 0; i < params.length; i++ ) { - if( !params[i].accept( action ) ) return false; + ICPPASTTemplateParameter[] params = getTemplateParameters(); + for (int i = 0; i < params.length; i++) { + if (!params[i].accept(action)) return false; } - if( declaration != null ) if( !declaration.accept( action ) ) return false; + if (declaration != null && !declaration.accept(action)) return false; - if( action.shouldVisitDeclarations ){ - switch( action.leave( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + if (action.shouldVisitDeclarations) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } return true; } public ICPPTemplateScope getScope() { - if( templateScope == null ) - templateScope = new CPPTemplateScope( this ); + if (templateScope == null) + templateScope = new CPPTemplateScope(this); return templateScope; } public void replace(IASTNode child, IASTNode other) { - if( declaration == child ) - { - other.setParent( child.getParent() ); - other.setPropertyInParent( child.getPropertyInParent() ); + if (declaration == child) { + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); declaration = (IASTDeclaration) other; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateSpecialization.java index 19b0fb0cd97..3226ac33cb9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateSpecialization.java @@ -61,22 +61,22 @@ public class CPPASTTemplateSpecialization extends ASTNode implements } @Override - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitDeclarations ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - if( declaration != null ) if( !declaration.accept( action ) ) return false; + if (declaration != null && !declaration.accept(action)) return false; - if( action.shouldVisitDeclarations ){ - switch( action.leave( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + if (action.shouldVisitDeclarations) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } return true; @@ -94,20 +94,25 @@ public class CPPASTTemplateSpecialization extends ASTNode implements return ICPPASTTemplateParameter.EMPTY_TEMPLATEPARAMETER_ARRAY; } - public void addTemplateParamter(ICPPASTTemplateParameter parm) { + public void addTemplateParameter(ICPPASTTemplateParameter param) { assertNotFrozen(); } + @Deprecated + public void addTemplateParamter(ICPPASTTemplateParameter param) { + addTemplateParameter(param); + } + public ICPPTemplateScope getScope() { - if( templateScope == null ) - templateScope = new CPPTemplateScope( this ); + if (templateScope == null) + templateScope = new CPPTemplateScope(this); return templateScope; } public void replace(IASTNode child, IASTNode other) { - if( declaration == child ) { - other.setParent( child.getParent() ); - other.setPropertyInParent( child.getPropertyInParent() ); + if (declaration == child) { + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); declaration = (IASTDeclaration) other; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index 691d7fe1ef1..c93aac362b7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -295,7 +295,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { name= nodeFactory.newName(image); setRange(name, destructorOffset, nt.getEndOffset()); } - switch(nt.getType()) { + switch (nt.getType()) { case IToken.tEOC: case IToken.tCOMPLETION: createCompletionNode(nt).addName(name); @@ -306,7 +306,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private IASTName addTemplateArguments(IASTName templateName, CastExprCtx ctx) throws EndOfFileException, BacktrackException { boolean isAmbiguous= false; - switch(canBeTemplateArguments(ctx)) { + switch (canBeTemplateArguments(ctx)) { case -1: return templateName; case 0: @@ -319,7 +319,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { try { List list = templateArgumentList(isAmbiguous); IToken end= LA(1); - switch(end.getType()) { + switch (end.getType()) { case IToken.tGT_in_SHIFTR: case IToken.tGT: consume(); @@ -342,9 +342,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { for (IASTNode n : args) { if (n instanceof IASTTypeId) { result.addTemplateArgument((IASTTypeId) n); - } else if(n instanceof IASTExpression) { + } else if (n instanceof IASTExpression) { result.addTemplateArgument((IASTExpression) n); - } else if(n instanceof ICPPASTAmbiguousTemplateArgument) { + } else if (n instanceof ICPPASTAmbiguousTemplateArgument) { result.addTemplateArgument((ICPPASTAmbiguousTemplateArgument) n); } } @@ -368,7 +368,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { int limit= 10000; while(--limit > 0) { - switch(consume().getType()) { + switch (consume().getType()) { case IToken.tEOC: case IToken.tCOMPLETION: return ctx == CastExprCtx.eNotBExpr ? 0 : -1; @@ -392,7 +392,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // do the same check for the enclosing template lt1= LTcatchEOF(2); } - switch(lt1) { + switch (lt1) { // Can be some cast-expression or continuation after template-id case IToken.tCOLONCOLON: // CT::member case IToken.tLPAREN: // ft(args) @@ -704,7 +704,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // Brace initializers are allowed on the right hand side of an expression boolean allowBraceInitializer= false; lt1= LT(1); - switch(lt1) { + switch (lt1) { case IToken.tQUESTION: if (ctx == BinaryExprCtx.eAmbigTmplID) { throwBacktrack(LA(1)); @@ -1408,7 +1408,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } private ICPPASTLiteralExpression stringLiteral() throws EndOfFileException, BacktrackException { - switch(LT(1)) { + switch (LT(1)) { case IToken.tSTRING: case IToken.tLSTRING: case IToken.tUTF16STRING: @@ -1438,7 +1438,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } final int endOffset= consumeOrEOC(IToken.tRPAREN).getEndOffset(); int operator; - switch(optype) { + switch (optype) { case IToken.t_dynamic_cast: operator = ICPPASTCastExpression.op_dynamic_cast; break; @@ -1588,7 +1588,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { final int offset= LA(1).getOffset(); boolean exported = false; int explicitInstMod= 0; - switch(LT(1)) { + switch (LT(1)) { case IToken.t_export: exported = true; consume(); @@ -1640,7 +1640,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { templateDecl.setExported(exported); for (int i = 0; i < parms.size(); ++i) { ICPPASTTemplateParameter parm = parms.get(i); - templateDecl.addTemplateParamter(parm); + templateDecl.addTemplateParameter(parm); } return templateDecl; } @@ -2580,7 +2580,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { verifyDtor(declspec, dtor1, option); int lt1= LTcatchEOF(1); - switch(lt1) { + switch (lt1) { case 0: return dtor1; @@ -2925,7 +2925,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // Mark initializer lists directly as pack expansions ((ICPPASTPackExpandable) clause).setIsPackExpansion(true); adjustEndOffset(clause, endOffset); - } else if (clause instanceof IASTExpression){ + } else if (clause instanceof IASTExpression) { // Wrap pack expanded assignment expressions IASTExpression packExpansion= nodeFactory.newPackExpansionExpression((IASTExpression) clause); clause= setRange(packExpansion, clause, endOffset); @@ -2937,7 +2937,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { result.add(clause); if (LT(1) != IToken.tCOMMA) break; - switch(LT(2)) { + switch (LT(2)) { case IToken.tRBRACE: case IToken.tRPAREN: case IToken.tEOC: @@ -3126,7 +3126,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTName name= null; int coloncolon= LT(1) == IToken.tCOLONCOLON ? 1 : 0; loop: while (LTcatchEOF(coloncolon+1) == IToken.tIDENTIFIER) { - switch(LTcatchEOF(coloncolon+2)) { + switch (LTcatchEOF(coloncolon+2)) { case IToken.tCOLONCOLON: coloncolon+= 2; break; @@ -3180,7 +3180,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTPointer pointer; if (name != null) { - if(isRestrict) { + if (isRestrict) { IGPPASTPointerToMember gppp2m = nodeFactory.newPointerToMemberGPP(name); gppp2m.setRestrict(true); pointer= gppp2m; @@ -3188,7 +3188,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { pointer= nodeFactory.newPointerToMember(name); } } else { - if(isRestrict) { + if (isRestrict) { IGPPASTPointer gpppo = nodeFactory.newPointerGPP(); gpppo.setRestrict(true); pointer= gpppo; @@ -3337,7 +3337,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // cv-qualifiers cvloop: while(true) { - switch(LT(1)) { + switch (LT(1)) { case IToken.t_const: fc.setConst(true); endOffset= consume().getEndOffset(); @@ -3918,9 +3918,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (condition != null && (condition instanceof IASTExpression || condition instanceof IASTDeclaration)) // shouldn't be possible but failure in condition() makes it so { - if( condition instanceof IASTExpression ) + if (condition instanceof IASTExpression) new_if_statement.setConditionExpression((IASTExpression) condition); - else if( condition instanceof IASTDeclaration ) + else if (condition instanceof IASTDeclaration) new_if_statement.setConditionDeclaration((IASTDeclaration) condition); } if (thenClause != null) { @@ -4003,10 +4003,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { ICPPASTSwitchStatement switch_statement = nodeFactory.newSwitchStatement(); ((ASTNode) switch_statement).setOffsetAndLength(startOffset, (switch_body != null ? calculateEndOffset(switch_body) : LA(1).getEndOffset()) - startOffset); - if( switch_condition instanceof IASTExpression ) { + if (switch_condition instanceof IASTExpression) { switch_statement.setControllerExpression((IASTExpression) switch_condition); - } - else if( switch_condition instanceof IASTDeclaration ) { + } else if (switch_condition instanceof IASTDeclaration) { switch_statement.setControllerDeclaration((IASTDeclaration) switch_condition); } @@ -4066,10 +4065,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { for_statement.setInitializerStatement(init); if (for_condition != null) { - if( for_condition instanceof IASTExpression ) { + if (for_condition instanceof IASTExpression) { for_statement.setConditionExpression((IASTExpression) for_condition); - } - else if( for_condition instanceof IASTDeclaration ) { + } else if (for_condition instanceof IASTDeclaration) { for_statement.setConditionDeclaration((IASTDeclaration) for_condition); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java index 7979055c1d6..364264b9c92 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java @@ -673,7 +673,7 @@ public class ExtractFunctionRefactoring extends CRefactoring { templateDeclaration.setParent(unit); for(ICPPASTTemplateParameter templateParameter : ((ICPPASTTemplateDeclaration) insertpoint.getParent()).getTemplateParameters()) { - templateDeclaration.addTemplateParamter(templateParameter.copy()); + templateDeclaration.addTemplateParameter(templateParameter.copy()); } templateDeclaration.setDeclaration(func); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoring.java index ae67ef1730c..6f2bc6874f5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoring.java @@ -232,7 +232,7 @@ public class ImplementMethodRefactoring extends CRefactoring { templateDeclaration.setParent(unit); for(ICPPASTTemplateParameter templateParameter : ((ICPPASTTemplateDeclaration) declarationParent.getParent().getParent() ).getTemplateParameters()) { - templateDeclaration.addTemplateParamter(templateParameter.copy()); + templateDeclaration.addTemplateParameter(templateParameter.copy()); } templateDeclaration.setDeclaration(func);