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

wurstscript / WurstScript / 215

08 Nov 2023 06:49PM CUT coverage: 62.561% (-0.04%) from 62.602%
215

Pull #1081

circleci

Frotty
fixes and master merge
Pull Request #1081: More performance improvements

17307 of 27664 relevant lines covered (62.56%)

0.63 hits per line

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

62.07
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/jassinterpreter/ReflectionBasedNativeProvider.java
1
package de.peeeq.wurstio.jassinterpreter;
2

3
import de.peeeq.wurstscript.WLogger;
4
import de.peeeq.wurstscript.intermediatelang.ILconst;
5
import de.peeeq.wurstscript.intermediatelang.interpreter.NativesProvider;
6
import de.peeeq.wurstscript.intermediatelang.interpreter.NoSuchNativeException;
7
import de.peeeq.wurstscript.utils.Pair;
8

9
import java.io.PrintStream;
10
import java.lang.reflect.InvocationTargetException;
11
import java.lang.reflect.Method;
12
import java.util.Arrays;
13
import java.util.HashMap;
14
import java.util.stream.Collectors;
15

16
public abstract class ReflectionBasedNativeProvider implements NativesProvider {
17

18
    protected PrintStream outStream = System.err;
1✔
19

20
    private final HashMap<Pair<String, Integer>, Method> methodMap = new HashMap<>();
1✔
21

22
    public ReflectionBasedNativeProvider() {
1✔
23
        for (Method method : this.getClass().getMethods()) {
1✔
24
            Pair<String, Integer> keyPair = Pair.create(method.getName(), method.getParameterTypes().length);
1✔
25
            if (methodMap.containsKey(keyPair)) {
1✔
26
                System.err.println(">>>>>>>>>>>>>> ALRDY EXISTS");
×
27
                throw new RuntimeException("alrdy exists");
×
28
            }
29
            methodMap.put(keyPair, method);
1✔
30
        }
31
    }
1✔
32

33
    @Override
34
    public ILconst invoke(String funcname, ILconst[] args) throws NoSuchNativeException {
35
        Method method = methodMap.get(Pair.create(funcname, args.length));
1✔
36
        if (method == null) {
1✔
37
            String msg = "Calling method " + funcname + "(" +
1✔
38
                Arrays.stream(args).map(Object::toString).collect(Collectors.joining(", ")) + ")";
1✔
39
            msg += "\nwith types " + funcname + "(" +
1✔
40
                Arrays.stream(args).map(o -> o.getClass().getSimpleName()).collect(Collectors.joining(", ")) + ")";
1✔
41
//        if (candidate != null) {
42
//            msg += "\nDid you mean " + funcname + "(" +
43
//                Arrays.stream(candidate.getParameterTypes()).map(Class::getSimpleName).collect(Collectors.joining(", ")) + ")?";
44
//        }
45
            throw new NoSuchNativeException(msg);
1✔
46
        }
47
        try {
48
            return (ILconst) method.invoke(this, (Object[]) args);
1✔
49
        } catch (IllegalAccessException | IllegalArgumentException e) {
×
50
            WLogger.severe(e);
×
51
            throw new Error(e);
×
52
        } catch (InvocationTargetException e) {
×
53
            if (e.getCause() instanceof InterpreterException) {
×
54
                throw (InterpreterException) e.getCause();
×
55
            }
56
            if (e.getCause() instanceof Error) {
×
57
                throw (Error) e.getCause();
×
58
            }
59
            throw new Error(e.getCause());
×
60
        }
61

62
    }
63

64
    @Override
65
    public void setOutStream(PrintStream outStream) {
66
        this.outStream = outStream;
1✔
67
    }
1✔
68

69
}
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

© 2025 Coveralls, Inc