• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

moosetechnology / Famix-Value / 15719309325

17 Jun 2025 10:25PM UTC coverage: 22.736%. Remained the same
15719309325

push

github

Gabriel-Darbord
Start embracing mooseName naturally with dots

0 of 9 new or added lines in 3 files covered. (0.0%)

1 existing line in 1 file now uncovered.

796 of 3501 relevant lines covered (22.74%)

0.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Famix-Value-Importer/FamixJavaEntityFinder.class.st
1
"
2
An importer helper for finding Java types represented by `FamixJavaType` and its subclasses in a FamixJava model.
3
"
4
Class {
5
        #name : 'FamixJavaEntityFinder',
6
        #superclass : 'FamixEntityFinder',
7
        #classVars : [
8
                'FieldDescriptors'
9
        ],
10
        #category : 'Famix-Value-Importer',
11
        #package : 'Famix-Value-Importer'
12
}
13

14
{ #category : 'class initialization' }
15
FamixJavaEntityFinder class >> initialize [
×
16
        "See https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.3.2"
×
17

×
18
        FieldDescriptors := IdentityDictionary new.
×
19
        FieldDescriptors
×
20
                at: $B put: 'byte';
×
21
                at: $C put: 'char';
×
22
                at: $D put: 'double';
×
23
                at: $F put: 'float';
×
24
                at: $I put: 'int';
×
25
                at: $J put: 'long';
×
26
                at: $S put: 'short';
×
27
                at: $Z put: 'boolean'
×
28
]
×
29

30
{ #category : 'enumerating' }
31
FamixJavaEntityFinder >> methodNameFromSignature: signature [
×
32

×
33
        ^ signature copyUpTo: $(
×
34
]
×
35

36
{ #category : 'enumerating' }
37
FamixJavaEntityFinder >> parseTypeName: name [
×
38
        "The name may not be fully qualified.
×
39
        Even if we want to find a name in java.lang or java.util packages, we want to search using the mooseName if it is parameterized.
×
40
        Famix does not represent arrays, but we need the information, so we use a wrapper around the type."
×
41

×
42
        | typeName dimensions type |
×
43
        typeName := self translateFieldDescriptor: name.
×
44
        dimensions := name occurrencesOf: $[.
×
45
        type := (typeName includes: $.)
×
46
                        ifFalse: [ self findTypeWithName: typeName ]
×
47
                        ifTrue: [ "Search by translating the type name to a mooseName."
×
48
                                self findTypeWithMooseName:
×
NEW
49
                                        (typeName allButLast: dimensions * 2) ].
×
50
        ^ dimensions > 0
×
51
                  ifFalse: [ type ]
×
52
                  ifTrue: [
×
53
                  (FamixValueJavaArray wrapping: type) dimensions: dimensions ]
×
54
]
×
55

56
{ #category : 'matching' }
57
FamixJavaEntityFinder >> signatureOf: method matches: signature [
×
58
        "Assume the signature includes the method name and the field descriptors of the parameters, e.g. `main([Ljava.lang.String;)`.
×
59
        Because Famix doesn't represent arrays, use the method's signature string which contains array information.
×
60
        However, its format is the one used in source code, e.g. `main(String[])`, so there needs to be a translation."
×
61

×
62
        | parameters |
×
63
        parameters := (signature
×
64
                               copyFrom: method name size + 2
×
65
                               to: signature size - 1)
×
66
                              ifEmpty: [ #(  ) ]
×
67
                              ifNotEmpty: [ :params | params splitOn: $, ].
×
68
        method parameters size = parameters size ifFalse: [ ^ false ].
×
69
        ^ method signatureWithoutParameterTypes
×
70
          = (String streamContents: [ :stream |
×
71
                           stream nextPutAll: method name.
×
72
                           stream nextPut: $(.
×
73
                           self translateFieldDescriptors: parameters on: stream.
×
74
                           stream nextPut: $) ])
×
75
]
×
76

77
{ #category : 'translating' }
78
FamixJavaEntityFinder >> translateFieldDescriptor: fieldDescriptor [
×
79
        "Translate Java field descriptors to a type name used by Moose, e.g. '[I' -> 'int[]'
×
80
        See https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.3.2"
×
81

×
82
        | dimensions typeName |
×
83
        dimensions := 0.
×
84
        [ (fieldDescriptor at: dimensions + 1) == $[ ] whileTrue: [
×
85
                dimensions := dimensions + 1 ].
×
86
        dimensions = 0 ifTrue: [ ^ fieldDescriptor ].
×
87
        typeName := fieldDescriptor allButFirst: dimensions.
×
88
        typeName := FieldDescriptors
×
89
                            at: (typeName at: 1)
×
NEW
90
                            ifAbsent: [ "A class, e.g. Ljava.lang.String;"
×
91
                                    (typeName at: 1) == $L
×
92
                                            ifTrue: [ typeName copyFrom: 2 to: typeName size - 1 ]
×
93
                                            ifFalse: [
×
NEW
94
                                            self error:
×
NEW
95
                                                    'Incoherent Java field descriptor: ' , typeName ] ].
×
96
        [
×
97
        typeName := typeName , '[]'.
×
98
        (dimensions := dimensions - 1) > 0 ] whileTrue.
×
99
        ^ typeName
×
100
]
×
101

102
{ #category : 'matching' }
103
FamixJavaEntityFinder >> translateFieldDescriptors: parameters on: stream [
×
104
        "Only keep the type's simple name, discard the qualifying prefix."
×
105

×
106
        parameters
×
107
                do: [ :parameter |
×
108
                        | translation index |
×
109
                        translation := self translateFieldDescriptor: parameter.
×
110
                        index := translation
×
111
                                         lastIndexOfAnyOf: '.$'
×
112
                                         startingAt: translation size
×
113
                                         ifAbsent: 0.
×
114
                        stream nextPutAll: (index = 0
×
115
                                         ifTrue: [ translation ]
×
116
                                         ifFalse: [ translation allButFirst: index ]) ]
×
117
                separatedBy: [ stream nextPut: $, ]
×
118
]
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc