3163 /** VariableDeclaratorRest = BracketsOpt ["=" VariableInitializer] 3164 * ConstantDeclaratorRest = BracketsOpt "=" VariableInitializer 3165 * 3166 * @param reqInit Is an initializer always required? 3167 * @param dc The documentation comment for the variable declarations, or null. 3168 */ 3169 JCVariableDecl variableDeclaratorRest(int pos, JCModifiers mods, JCExpression type, Name name, 3170 boolean reqInit, Comment dc, boolean localDecl, boolean compound) { 3171 type = bracketsOpt(type); 3172 JCExpression init = null; 3173 if (token.kind == EQ) { 3174 nextToken(); 3175 init = variableInitializer(); 3176 } 3177 else if (reqInit) syntaxError(token.pos, Errors.Expected(EQ)); 3178 JCTree elemType = TreeInfo.innermostType(type, true); 3179 int startPos = Position.NOPOS; 3180 if (elemType.hasTag(IDENT)) { 3181 Name typeName = ((JCIdent)elemType).name; 3182 if (isRestrictedLocalVarTypeName(typeName, pos, !compound && localDecl)) { 3183 if (compound) { 3184 //error - 'var' in compound local var decl 3185 reportSyntaxError(pos, Errors.VarNotAllowedCompound); 3186 } else if (type.hasTag(TYPEARRAY)) { 3187 //error - 'var' and arrays 3188 reportSyntaxError(pos, Errors.VarNotAllowedArray); 3189 } else { 3190 startPos = TreeInfo.getStartPos(mods); 3191 if (startPos == Position.NOPOS) 3192 startPos = TreeInfo.getStartPos(type); 3193 //implicit type 3194 type = null; 3195 } 3196 } 3197 } 3198 JCVariableDecl result = 3199 toP(F.at(pos).VarDef(mods, name, type, init)); 3200 attach(result, dc); 3201 result.startPos = startPos; 3202 return result; 3203 } 3204 3205 boolean isRestrictedLocalVarTypeName(JCExpression e, boolean shouldWarn) { 3206 switch (e.getTag()) { 3207 case IDENT: 3208 return isRestrictedLocalVarTypeName(((JCIdent)e).name, e.pos, shouldWarn); 3209 case TYPEARRAY: | 3163 /** VariableDeclaratorRest = BracketsOpt ["=" VariableInitializer] 3164 * ConstantDeclaratorRest = BracketsOpt "=" VariableInitializer 3165 * 3166 * @param reqInit Is an initializer always required? 3167 * @param dc The documentation comment for the variable declarations, or null. 3168 */ 3169 JCVariableDecl variableDeclaratorRest(int pos, JCModifiers mods, JCExpression type, Name name, 3170 boolean reqInit, Comment dc, boolean localDecl, boolean compound) { 3171 type = bracketsOpt(type); 3172 JCExpression init = null; 3173 if (token.kind == EQ) { 3174 nextToken(); 3175 init = variableInitializer(); 3176 } 3177 else if (reqInit) syntaxError(token.pos, Errors.Expected(EQ)); 3178 JCTree elemType = TreeInfo.innermostType(type, true); 3179 int startPos = Position.NOPOS; 3180 if (elemType.hasTag(IDENT)) { 3181 Name typeName = ((JCIdent)elemType).name; 3182 if (isRestrictedLocalVarTypeName(typeName, pos, !compound && localDecl)) { 3183 if (type.hasTag(TYPEARRAY) && !compound) { 3184 //error - 'var' and arrays 3185 reportSyntaxError(pos, Errors.VarNotAllowedArray); 3186 } else { 3187 if(compound) 3188 //error - 'var' in compound local var decl 3189 reportSyntaxError(pos, Errors.VarNotAllowedCompound); 3190 startPos = TreeInfo.getStartPos(mods); 3191 if (startPos == Position.NOPOS) 3192 startPos = TreeInfo.getStartPos(type); 3193 //implicit type 3194 type = null; 3195 } 3196 } 3197 } 3198 JCVariableDecl result = 3199 toP(F.at(pos).VarDef(mods, name, type, init)); 3200 attach(result, dc); 3201 result.startPos = startPos; 3202 return result; 3203 } 3204 3205 boolean isRestrictedLocalVarTypeName(JCExpression e, boolean shouldWarn) { 3206 switch (e.getTag()) { 3207 case IDENT: 3208 return isRestrictedLocalVarTypeName(((JCIdent)e).name, e.pos, shouldWarn); 3209 case TYPEARRAY: |