Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the over-complicated generics #784

Merged
merged 20 commits into from
Jan 10, 2024
Merged

Conversation

stschott
Copy link
Collaborator

No description provided.

Copy link
Contributor

You updated the documentation - Doc Preview.

@swissiety
Copy link
Collaborator

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());
    }
}

@@ -461,17 +459,17 @@ public static Optional<? extends SootMethod> findConcreteMethod(
+ " to resolve the concrete method");
return Optional.empty();
}
Optional<? extends SootMethod> startMethod = startclass.getMethod(sig.getSubSignature());
Optional<SootMethod> startMethod = startclass.getMethod(sig.getSubSignature()).map(method -> (SootMethod) method);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to make SootClass.getMethod() return SootMethod (i.e. override getMethod() and cast it there) ?

Copy link
Collaborator Author

@stschott stschott Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not if we use an Optional.
In order to override it in the JavaSootClass with 'Optional<JavaSootClass> getMethod()', it needs to have Optional<? extends SootClass> as return type.

Copy link

codecov bot commented Jan 5, 2024

Codecov Report

Attention: 45 lines in your changes are missing coverage. Please review.

Comparison is base (71d5508) 63.86% compared to head (b1743b9) 63.70%.

Files Patch % Lines
...va/sootup/core/frontend/OverridingClassSource.java 9.09% 6 Missing and 4 partials ⚠️
...location/MultiReleaseJarAnalysisInputLocation.java 61.53% 5 Missing ⚠️
...va/sootup/java/core/OverridingJavaClassSource.java 70.58% 1 Missing and 4 partials ⚠️
...src/main/java/sootup/java/core/views/JavaView.java 78.94% 4 Missing ⚠️
...utlocation/JrtFileSystemAnalysisInputLocation.java 72.72% 3 Missing ⚠️
.../src/main/java/sootup/java/core/JavaSootClass.java 82.35% 3 Missing ⚠️
...in/java/sootup/java/core/views/JavaModuleView.java 90.62% 3 Missing ⚠️
...ore/src/main/java/sootup/core/model/SootClass.java 0.00% 2 Missing ⚠️
...main/java/sootup/core/cache/MutableClassCache.java 0.00% 1 Missing ⚠️
...java/sootup/core/frontend/AbstractClassSource.java 0.00% 1 Missing ⚠️
... and 8 more
Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #784      +/-   ##
=============================================
- Coverage      63.86%   63.70%   -0.16%     
- Complexity      3405     3440      +35     
=============================================
  Files            314      314              
  Lines          15097    15166      +69     
  Branches        2566     2568       +2     
=============================================
+ Hits            9641     9662      +21     
- Misses          4549     4598      +49     
+ Partials         907      906       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stschott stschott merged commit 570fd8b into develop Jan 10, 2024
9 checks passed
@stschott stschott deleted the featur/removeGenerics branch January 10, 2024 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants