configurationengine/source/cone/validation/builtinvalidators/implml.py
changeset 3 e7e0ae78773e
equal deleted inserted replaced
2:87cfa131b535 3:e7e0ae78773e
       
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 #
       
    16 
       
    17 from cone.public import api, plugin
       
    18 from cone.validation.implmlvalidation import GlobalValidatorBase
       
    19 
       
    20 class DuplicateTempFeatureRefValidator(GlobalValidatorBase):
       
    21     """
       
    22     Validator for checking for duplicate refs in temporary variable
       
    23     definitions.
       
    24     """
       
    25     PROBLEM_TYPES = ['model.implml.container.duplicate_tempvar']
       
    26     
       
    27     def validate(self):
       
    28         # Collect a dictionary of all temporary variable locations,
       
    29         # i.e. (file, lineno) tuples
       
    30         tempvar_locations_by_ref = {}
       
    31         for impl in self.context.all_impls:
       
    32             if isinstance(impl, plugin.ImplContainer):
       
    33                 for td in impl._tempvar_defs:
       
    34                     lst = tempvar_locations_by_ref.get(td.ref, [])
       
    35                     lst.append((impl.ref, td.lineno))
       
    36                     tempvar_locations_by_ref[td.ref] = lst
       
    37         
       
    38         # Check for duplicates
       
    39         for ref, locations in tempvar_locations_by_ref.iteritems():
       
    40             if len(locations) > 1:
       
    41                 for impl_file, lineno in locations:
       
    42                     prob = api.Problem(
       
    43                         msg = "Duplicate temporary variable ref '%s'" % ref,
       
    44                         type = self.PROBLEM_TYPES[0],
       
    45                         line = lineno,
       
    46                         file = impl_file)
       
    47                     self.context.problems.append(prob)
       
    48 
       
    49 #: List of all built-in ImplML validator classes
       
    50 VALIDATOR_CLASSES = [
       
    51     DuplicateTempFeatureRefValidator,
       
    52 ]