Skip to content

Commit

Permalink
Merge pull request #16 from deepsourcelabs/merge-upstream
Browse files Browse the repository at this point in the history
Merge upstream
  • Loading branch information
raghav-deepsource authored Apr 19, 2023
2 parents 33f7939 + 4614013 commit 7f0a3be
Show file tree
Hide file tree
Showing 38 changed files with 663 additions and 132 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/qodana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
with:
fetch-depth: 0
- name: 'Qodana Scan'
uses: JetBrains/qodana-action@3fdeefa830a7634a5c04f1cd70fcfb69956137a2 # v2022.3.0
uses: JetBrains/qodana-action@7afb26c0c2f325c0d5c21ea1f617c79c7f899337 # v2022.3.4
with:
args: --source-directory,./src/main/java , --fail-threshold, 0
- uses: github/codeql-action/upload-sarif@959cbb7472c4d4ad70cdfe6f4976053fe48ab394 # v2
- uses: github/codeql-action/upload-sarif@168b99b3c22180941ae7dbdd5f5c9678ede476ba # v2
with:
sarif_file: ${{ runner.temp }}/qodana/results/qodana.sarif.json
4 changes: 2 additions & 2 deletions .github/workflows/sbom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
fetch-depth: 0
- uses: actions/setup-java@1df8dbefe2a8cbc99770194893dd902763bee34b # v3.9.0
- uses: actions/setup-java@3f07048e3d294f56e9b90ac5ea2c6f74e9ad0f98 # v3.10.0
with:
java-version: 17
distribution: ${{ env.JAVA_DISTRIBUTION }}
Expand All @@ -34,7 +34,7 @@ jobs:
run: echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- name: Use Maven dependency cache
uses: actions/cache@58c146cc91c5b9e778e71775dfe9bf1442ad9a12 # v3.2.3
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/pom.xml') }}
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Disable Git's autocrlf
run: git config --global core.autocrlf false
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- uses: actions/setup-java@1df8dbefe2a8cbc99770194893dd902763bee34b # v3.9.0
- uses: actions/setup-java@3f07048e3d294f56e9b90ac5ea2c6f74e9ad0f98 # v3.10.0
with:
java-version: ${{ matrix.java }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
Expand All @@ -53,7 +53,7 @@ jobs:
run: echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- name: Use Maven dependency cache
uses: actions/cache@58c146cc91c5b9e778e71775dfe9bf1442ad9a12 # v3.2.3
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/pom.xml') }}
Expand All @@ -80,7 +80,7 @@ jobs:
name: Test with coverage
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- uses: actions/setup-java@1df8dbefe2a8cbc99770194893dd902763bee34b # v3.9.0
- uses: actions/setup-java@3f07048e3d294f56e9b90ac5ea2c6f74e9ad0f98 # v3.10.0
with:
java-version: 17
distribution: ${{ env.JAVA_DISTRIBUTION }}
Expand All @@ -90,7 +90,7 @@ jobs:
run: echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- name: Use Maven dependency cache
uses: actions/cache@58c146cc91c5b9e778e71775dfe9bf1442ad9a12 # v3.2.3
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/pom.xml') }}
Expand All @@ -116,11 +116,11 @@ jobs:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
fetch-depth: 0
- uses: actions/setup-java@1df8dbefe2a8cbc99770194893dd902763bee34b # v3.9.0
- uses: actions/setup-java@3f07048e3d294f56e9b90ac5ea2c6f74e9ad0f98 # v3.10.0
with:
java-version: 11
distribution: ${{ env.JAVA_DISTRIBUTION }}
- uses: actions/setup-python@5ccb29d8773c3f3f653e1705f474dfaa8a06a912 # v4.4.0
- uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 # v4.5.0
with:
python-version: 3.11

Expand All @@ -129,7 +129,7 @@ jobs:
run: echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- name: Use Maven dependency cache
uses: actions/cache@58c146cc91c5b9e778e71775dfe9bf1442ad9a12 # v3.2.3
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/pom.xml') }}
Expand All @@ -150,7 +150,7 @@ jobs:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
fetch-depth: 0
- uses: actions/setup-java@1df8dbefe2a8cbc99770194893dd902763bee34b # v3.9.0
- uses: actions/setup-java@3f07048e3d294f56e9b90ac5ea2c6f74e9ad0f98 # v3.10.0
with:
java-version: 17
distribution: ${{ env.JAVA_DISTRIBUTION }}
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.14.1</version>
<version>2.14.2</version>
</dependency>
<dependency>
<!-- support for compressed serialized ASTs -->
Expand Down Expand Up @@ -268,7 +268,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.2.0</version>
<version>3.2.1</version>
<configuration>
<failsOnError>true</failsOnError>
<consoleOutput>true</consoleOutput>
Expand Down
2 changes: 1 addition & 1 deletion spoon-control-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.2.0</version>
<version>3.2.1</version>
<configuration>
<failsOnError>true</failsOnError>
<configLocation>../checkstyle.xml</configLocation>
Expand Down
4 changes: 2 additions & 2 deletions spoon-dataflow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
// always depends on the latest snapshot of Spoon
// https://github.com/patrikerdes/gradle-use-latest-versions-plugin
id 'se.patrikerdes.use-latest-versions' version '0.2.18'
id 'com.github.ben-manes.versions' version '0.44.0'
id 'com.github.ben-manes.versions' version '0.46.0'
id "com.github.johnrengelman.shadow" version "7.1.2"
}

Expand All @@ -23,7 +23,7 @@ dependencies {
implementation group: 'fr.inria.gforge.spoon', name: 'spoon-core', version: '+'
implementation group: 'commons-cli', name: 'commons-cli', version: '1.5.0'
implementation group: 'com.microsoft', name: 'z3', version: '4.8.4'
testImplementation("org.junit.jupiter:junit-jupiter:5.9.1")
testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")
}

application {
Expand Down
2 changes: 1 addition & 1 deletion spoon-dataflow/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion spoon-decompiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.2.0</version>
<version>3.2.1</version>
<configuration>
<failsOnError>true</failsOnError>
<configLocation>../checkstyle.xml</configLocation>
Expand Down
26 changes: 13 additions & 13 deletions spoon-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,31 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.11.0</version>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.1</version>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.9.1</version>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.9.1</version>
<version>1.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.11.0</version>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -208,7 +208,7 @@
<!-- see https://github.com/castor-software/depclean -->
<groupId>se.kth.castor</groupId>
<artifactId>depclean-maven-plugin</artifactId>
<version>2.0.5</version>
<version>2.0.6</version>
<executions>
<execution>
<goals>
Expand All @@ -232,35 +232,35 @@
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<version>3.5.0</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<version>3.11.0</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.4.0</version>
<version>3.5.0</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0</version>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
<version>3.5.0</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.4.1</version>
<version>3.4.2</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
Expand All @@ -276,7 +276,7 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<version>3.0.0-M9</version>
</plugin>

<!--This plugin's configuration is used to store Eclipse m2e settings
Expand Down
2 changes: 1 addition & 1 deletion spoon-smpl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.2.0</version>
<version>3.2.1</version>
<configuration>
<failsOnError>true</failsOnError>
<configLocation>../checkstyle.xml</configLocation>
Expand Down
6 changes: 3 additions & 3 deletions spoon-visualisation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.4.0</version>
<version>3.5.0</version>
<executions>
<execution>
<id>main deps</id>
Expand Down Expand Up @@ -184,13 +184,13 @@
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.1.0</version>
<version>24.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.1</version>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
35 changes: 25 additions & 10 deletions src/main/java/spoon/reflect/factory/CodeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -596,16 +596,31 @@ public <T> CtTypeReference<T> createCtTypeReference(Class<?> originalClass) {
if (originalClass == null) {
return null;
}
CtTypeReference<T> typeReference = factory.Core().<T>createTypeReference();
typeReference.setSimpleName(originalClass.getSimpleName());
if (originalClass.isPrimitive()) {
return typeReference;
int arrayDimensionCount = 0;
Class<?> currentClass = originalClass;
while (currentClass.isArray()) {
currentClass = currentClass.getComponentType();
arrayDimensionCount++;
}
if (originalClass.getDeclaringClass() != null) {
// the inner class reference does not have package
return typeReference.setDeclaringType(createCtTypeReference(originalClass.getDeclaringClass()));
CtTypeReference<T> typeReference = factory.Core().createTypeReference();
if (currentClass.isAnonymousClass()) {
int end = currentClass.getName().lastIndexOf('$');
typeReference.setSimpleName(currentClass.getName().substring(end + 1));
} else {
typeReference.setSimpleName(currentClass.getSimpleName());
}
if (currentClass.getEnclosingClass() != null) {
typeReference.setDeclaringType(createCtTypeReference(currentClass.getEnclosingClass()));
}
if (currentClass.getPackage() != null) {
typeReference.setPackage(createCtPackageReference(currentClass.getPackage()));
}
return typeReference.setPackage(createCtPackageReference(originalClass.getPackage()));

if (arrayDimensionCount > 0) {
typeReference = (CtTypeReference<T>) factory.createArrayReference(typeReference, arrayDimensionCount);
}

return typeReference;
}

/**
Expand Down Expand Up @@ -724,7 +739,7 @@ public CtComment createInlineComment(String content) {
/**
* Creates a javadoc tag
*
* @param content The content of the javadoc tag with a possible paramater
* @param content The content of the javadoc tag with a possible parameter
* @param type The tag type
* @return a new CtJavaDocTag
*/
Expand Down Expand Up @@ -752,7 +767,7 @@ public CtJavaDocTag createJavaDocTag(String content, CtJavaDocTag.TagType type)
/**
* Creates a javadoc tag
*
* @param content The content of the javadoc tag with a possible paramater
* @param content The content of the javadoc tag with a possible parameter
* @param type The tag type
* @param realName The real name of the tag
* @return a new CtJavaDocTag
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/spoon/reflect/factory/TypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ public <T> CtArrayTypeReference<T[]> createArrayReference(CtTypeReference<T> ref
*/
public CtArrayTypeReference<?> createArrayReference(CtTypeReference<?> reference, int n) {
CtTypeReference<?> componentType;
if (n < 1) {
throw new SpoonException("Array dimension must be >= 1");
}
if (n == 1) {
return createArrayReference(reference);
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/spoon/reflect/visitor/ImportConflictDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import spoon.reflect.reference.CtTypeReference;
import spoon.support.Experimental;

import java.util.Map;

/**
* Detects conflicts needed to be required be a fully-qualified name.
Expand Down Expand Up @@ -196,6 +197,16 @@ protected void handleTypeReference(CtTypeReference<?> ref, LexicalScope nameScop
ref.setSimplyQualified(false);
return false;
});

if (!ref.isImplicit() && ref.isSimplyQualified()) {
Map<String, String> encounteredNames = ((LexicalScopeScanner) scanner).getEncounteredImportedQualifiedNames();
encounteredNames.putIfAbsent(ref.getSimpleName(), ref.getQualifiedName());
if (!encounteredNames.get(ref.getSimpleName()).equals(ref.getQualifiedName())) {
// We have found a different type with the same simple name, do not import this one
ref.setImplicit(false);
ref.setSimplyQualified(false);
}
}
} //else it is already fully qualified
checkConflictOfTypeReference(nameScope, ref);
}
Expand Down
Loading

0 comments on commit 7f0a3be

Please sign in to comment.