Skip to content

Commit

Permalink
fix(type): Fix exception in noclasspath due to PolyTypeBinding. (Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot authored and monperrus committed Aug 25, 2016
1 parent 0ba75bf commit 8bc3509
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,11 @@ <T> CtTypeReference<T> getTypeReference(TypeBinding binding) {
arrayref = tmp;
}
arrayref.setComponentType(getTypeReference(binding.leafComponentType()));
} else if (binding instanceof ProblemReferenceBinding || binding instanceof PolyTypeBinding) {
} else if (binding instanceof PolyTypeBinding) {
// JDT can't resolve the type of this binding and we only have a string.
// In this case, we return a type Object because we can't know more about it.
ref = this.jdtTreeBuilder.getFactory().Type().objectType();
} else if (binding instanceof ProblemReferenceBinding) {
// Spoon is able to analyze also without the classpath
ref = this.jdtTreeBuilder.getFactory().Core().createTypeReference();
ref.setSimpleName(new String(binding.readableName()));
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/spoon/test/type/TypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import spoon.reflect.code.BinaryOperatorKind;
import spoon.reflect.code.CtBinaryOperator;
import spoon.reflect.code.CtBlock;
import spoon.reflect.code.CtConstructorCall;
import spoon.reflect.code.CtFieldRead;
import spoon.reflect.code.CtLambda;
import spoon.reflect.code.CtLocalVariable;
Expand Down Expand Up @@ -300,4 +301,21 @@ public void testDeclarationCreatedByFactory() throws Exception {
assertNotNull(factory.Interface().create("fr.inria.ITest").getReference().getDeclaration());
assertNotNull(factory.Enum().create("fr.inria.ETest").getReference().getDeclaration());
}

@Test
public void testPolyTypBindingInTernaryExpression() throws Exception {
Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/resources/noclasspath/ternary-bug");
launcher.getEnvironment().setNoClasspath(true);
launcher.buildModel();

CtType<Object> aType = launcher.getFactory().Type().get("de.uni_bremen.st.quide.persistence.transformators.IssueTransformator");
CtConstructorCall ctConstructorCall = aType.getElements(new TypeFilter<CtConstructorCall>(CtConstructorCall.class) {
@Override
public boolean matches(CtConstructorCall element) {
return "TOIssue".equals(element.getExecutable().getType().getSimpleName()) && super.matches(element);
}
}).get(0);
assertEquals(launcher.getFactory().Type().objectType(), ctConstructorCall.getExecutable().getParameters().get(9));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package de.uni_bremen.st.quide.persistence.data;

public enum IssueType {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package de.uni_bremen.st.quide.persistence.data.entities;

import java.time.ZonedDateTime;

import de.uni_bremen.st.quide.persistence.data.IssueType;

public class Issue {
public Long getId() {
return id;
}

public String getIdentifier() {
return "";
}

public String getTitle() {
return "";
}

public String getDescription() {
return "";
}

public String getUrl() {
return "";
}

public ZonedDateTime getCreatedAt() {
return null;
}

public ZonedDateTime getClosedAt() {
return null;
}

public IssueType getIssueType() {
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package de.uni_bremen.st.quide.persistence.transformators;

import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import de.uni_bremen.st.quide.datamodel.transferred_data.IViolation;
import de.uni_bremen.st.quide.datamodel.transferred_data.impl.TOIssue;
import de.uni_bremen.st.quide.persistence.IPersistence;
import de.uni_bremen.st.quide.persistence.data.entities.Filename;
import de.uni_bremen.st.quide.persistence.data.entities.Issue;
import de.uni_bremen.st.quide.persistence.data.entities.IssueLabel;
import de.uni_bremen.st.quide.persistence.data.entities.Version;
import de.uni_bremen.st.quide.persistence.data.relationships.FilenameVersion;
import de.uni_bremen.st.quide.persistence.exceptions.InvalidIDException;
import de.uni_bremen.st.quide.persistence.util.Condition;
import de.uni_bremen.st.quide.persistence.util.Condition.Type;

@Component
public class IssueTransformator {

@Autowired
private IPersistence persistence;

public List<TOIssue> getAllIssues() {
return getAll(null);
}

public List<TOIssue> getIssuesReferencedByVersion(long versionId) throws InvalidIDException {
Version version = persistence.checkID(Version.class, versionId);

return getAll(Collections.singletonList(new Condition(Type.REVERSE_IN, "versions", version)));
}

public List<TOIssue> getIssuesModifyingFile(long fileId) throws InvalidIDException {
Filename filename = persistence.checkID(Filename.class, fileId);

List<Condition> conditions = Collections.singletonList(new Condition("filename", filename));

return persistence.getAll(FilenameVersion.class, conditions).stream()
.map(FilenameVersion::getStartVersion)
.map(Version::getIssues)
.flatMap(Set::stream)
.map(this::createIssue)
.collect(Collectors.toList());
}

public List<IViolation> getViolationsFixedByIssue(long issueId) {
return Collections.emptyList();
}

public List<IViolation> getViolationsCreatedByIssue(long issueId) {
return Collections.emptyList();
}

private TOIssue createIssue(Issue issue) {
final ZonedDateTime closedAt = issue.getClosedAt();

final Set<String> labels = issue.getLabels().stream()
.map(IssueLabel::getName)
.collect(Collectors.toSet());

final Set<Long> versions = null;

return new TOIssue(
issue.getId(),
issue.getIdentifier(),
issue.getTitle(),
issue.getDescription(),
issue.getUrl(),
"",

labels,
versions,

Date.from(issue.getCreatedAt().toInstant()),
closedAt == null ? null : Date.from(issue.getClosedAt().toInstant()),

issue.getIssueType().toString());
}

private List<TOIssue> getAll(List<Condition> conditions) {
return persistence.getAll(Issue.class, conditions).stream()
.map(this::createIssue)
.collect(Collectors.toList());
}
}

0 comments on commit 8bc3509

Please sign in to comment.