~zsombi/ubuntu-ui-toolkit/theme-as-singleton

« back to all changes in this revision

Viewing changes to tests/qmlapicheck.py

  • Committer: Zsombor Egri
  • Date: 2013-12-13 14:10:39 UTC
  • mfrom: (890 trunk)
  • mto: This revision was merged to the branch mainline in revision 894.
  • Revision ID: zsombor.egri@canonical.com-20131213141039-tt2ra31geou2cgfl
trunk merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
    if fileinput.isfirstline():
71
71
        in_block = 0
72
72
        in_comment = in_builtin_type = False
73
 
        annotated_type = None
 
73
        block_meta = {}
 
74
        annotated_properties = {}
74
75
        if fileinput.filename()[-3:] == 'qml':
75
76
            filetype = 'qml'
76
77
            keywords = ['signal', 'property', 'function']
89
90
    line = line.split('//')[0]
90
91
    # alias properties only define their type through qdoc comments
91
92
    if '\\qmlproperty' in line:
92
 
        annotated_type = line
 
93
        words = line.strip().split(' ')
 
94
        name = words[2]
 
95
        # Strip namespace
 
96
        if '::' in name:
 
97
            name = name.split('::')[1]
 
98
        type = words[1]
 
99
        annotated_properties[name] = type
93
100
    elif '\\internal' in line:
94
 
        annotated_type = 'internal internal internal'
 
101
        # internal without type always relates to the next declared property
 
102
        annotated_properties['internal'] = 'internal'
95
103
 
96
104
    if '/*' in line and not '*/' in line:
97
105
        in_comment = True
110
118
    # End of function/ signal/ Item block
111
119
    if '}' in line:
112
120
        in_block -= 1
 
121
        block_meta = {}
113
122
        if in_block == 1 and in_builtin_type:
114
123
            in_builtin_type = False
115
124
        continue
120
129
        declaration = line.split(':')[0]
121
130
        words = declaration.strip().split(' ')
122
131
        # Skip types with prefixes considered builtin
123
 
        if words[0] == 'name':
 
132
        if filetype == 'qmltypes' and words[0] == 'name':
124
133
            found_builtin_type = False
125
134
            for builtin in builtins:
126
135
                if '"' + builtin in line:
129
138
            if found_builtin_type:
130
139
                in_builtin_type = True
131
140
                continue
 
141
            if 'prototype' in block_meta:
 
142
                print('    ' + block_meta['prototype'].strip())
 
143
                print('    ' + line.strip())
 
144
                continue
 
145
 
 
146
        block_meta[words[0]] = line
 
147
        # Omit prototype if it comes before the name since we may skip it
 
148
        if not 'name' in block_meta and words[0] == 'prototype':
 
149
            continue
132
150
 
133
151
        # Don't consider the qml variable name as a keyword
134
152
        if filetype == 'qml':
142
160
                if filetype == 'qml':
143
161
                    signature = declaration.split('{')[0].strip()
144
162
                    if 'alias' in line:
145
 
                        if not annotated_type:
 
163
                        no_mods = signature
 
164
                        for mod in ['readonly', 'default']:
 
165
                            no_mods = no_mods.replace(mod, '')
 
166
                        name = no_mods.strip().split(' ')[2]
 
167
                        if 'internal' in annotated_properties:
 
168
                            if not name in annotated_properties:
 
169
                                annotated_properties[name] = 'internal'
 
170
                            del annotated_properties['internal']
 
171
                        if not name in annotated_properties:
146
172
                            print('    %s' % (signature))
147
 
                            print('Error: Missing \\qmlproperty annotation')
 
173
                            print('Error: Missing \\qmlproperty for %s' % name)
148
174
                            sys.exit(1)
149
 
                        real_type = annotated_type.strip().split(' ')[1]
 
175
                        real_type = annotated_properties[name]
150
176
                        signature = signature.replace('alias', real_type)
151
 
                    annotated_type = None
152
177
                elif filetype == 'qmltypes':
153
178
                    signature = line.strip()
154
179
                if not in_builtin_type:
158
183
    # Start of function/ signal/ Item block
159
184
    if '{' in line:
160
185
        in_block += 1
 
186
        block_meta = {}
161
187
        # The parent type can affect API
162
188
        if in_block == 1 and filetype == 'qml':
163
189
            print(line.split('{')[0].strip())