SootUp icon indicating copy to clipboard operation
SootUp copied to clipboard

Properly reintroduce generics

Open stschott opened this issue 2 years ago • 0 comments

WIP: Generics Draft/Playground:


package com.github.apiassist.sast;

import com.google.common.collect.Sets;

import java.util.Collections;
import java.util.Optional;
import java.util.Set;

public class SootUpGenericTest {

    public static void main(String[] args) {

        JView jView = new JView();
        Optional<JSC> c = jView.getC();
        Set<AnaInp<? extends JSCS>> anaInps2 = jView.getAnaInps();
        // make this possible Set<JavAnaInp> anaInps = jView.getAnaInps();


    }

}

interface Lang<C, M, CS, MS> {
    // unused.. necessary?
    // intention: subclass with actual values and use that to define grouped generic parameters?
}

interface JLang extends Lang<JSC, JSM, JSCS, JSMS> {
}


interface AnaInp<CS> {
    CS getClassSource();
}

class JSCAnaInp implements AnaInp<JSCS> {
    @Override
    public JSCS getClassSource() {
        return new JSCS();
    }
}

class JCPAnaInp implements AnaInp<JSCS> {

    @Override
    public JSCS getClassSource() {
        return new JSCS();
    }
}


interface View<C, M, CS extends SCS> {

    Set<AnaInp<? extends CS>> getAnaInps();

    Set<M> getM();

    Optional<C> getC();
}


class SMS {
}

class JSMS extends SMS {

}

class SCS {
}


class JSCS extends SCS {
}

class JASCS extends JSCS {
}

class JMSCS extends JSMS {
}


class SM {
}


class JSM extends SM {
}

class JASM extends JSM {
}

abstract class SC<SM, SMS> {
    Set<SMS> classSources;

    abstract public Set<SM> getM();
}

abstract class AbstractJSC<M extends SM, MS extends SMS> extends SC<M, MS> {
    MS methodSource;

    abstract public Set<M> getM();
}

class JSC extends AbstractJSC<JSM, JSMS> {
    public Set<JSM> getM() {
        return Collections.singleton(new JSM());
    }
}

class JASC extends AbstractJSC<JASM, JSMS> {
    public Set<JASM> getM() {
        return Collections.singleton(new JASM());
    }
}


abstract class AbsJavAnaInp<CS> implements AnaInp<CS> {

    public abstract CS getClassSource();
}


class JavAnaInp extends AbsJavAnaInp<JSCS> {

    public JSCS getClassSource() {
        return new JSCS();
    }
}

abstract class AbsView<SC, SM, CS extends SCS> implements View<SC, SM, CS> {

    @Override
    public abstract Set<AnaInp<? extends CS>> getAnaInps();

    public abstract Set<SM> getM();

    public abstract Optional<SC> getC();
}


class JView extends AbsView<JSC, JSM, JSCS> {
    @Override
    public Set<AnaInp<? extends JSCS>> getAnaInps() {
        return Sets.newHashSet(new JSCAnaInp(), new JCPAnaInp());
    }

    public Set<JSM> getM() {
        return Collections.singleton(new JSM());
    }

    public Optional<JSC> getC() {
        return Optional.of(new JSC());
    }
}

Originally posted by @swissiety in https://github.com/soot-oss/SootUp/issues/784#issuecomment-1867469431

stschott avatar Jan 05 '24 13:01 stschott