Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
SirYwell committed Oct 13, 2021
2 parents bd05add + 1322bf6 commit 11b131d
Show file tree
Hide file tree
Showing 27 changed files with 606 additions and 109 deletions.
2 changes: 1 addition & 1 deletion doc/jenkins/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# $ curl http://spoon.gforge.inria.fr/jenkins/build.sh | bash

# Allow to define some options to the maven command, such as debug or memory options
MAVEN_COMMAND="mvn $MVN_OPTS"
MAVEN_COMMAND="mvn $MVN_OPTS -Dmaven.javadoc.skip=true"

echo " "
echo "-------------------------------------------------------"
Expand Down
4 changes: 2 additions & 2 deletions spoon-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.12.4</version>
<version>4.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -56,7 +56,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.12.4</version>
<version>4.0.0</version>
<scope>test</scope>
</dependency>

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/spoon/reflect/factory/TypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,7 @@ public <T> CtType<T> get(final String qualifiedName) {
return null;
}
String className = qualifiedName.substring(inertTypeIndex + 1);
final CtTypeReference<T> reference = t.getReference();
if (reference.isLocalType()) {
if (t.isLocalType()) {
final List<CtClass<T>> enclosingClasses = t.getElements(new TypeFilter<CtClass<T>>(CtClass.class) {
@Override
public boolean matches(CtClass<T> element) {
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/spoon/support/compiler/FileSystemFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import spoon.Launcher;
import spoon.SpoonException;
Expand Down Expand Up @@ -133,17 +134,23 @@ public File toFile() {
return file;
}



@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
return toString().equals(obj.toString());
public int hashCode() {
return Objects.hash(file);
}

@Override
public int hashCode() {
return toString().hashCode();
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof FileSystemFolder)) {
return false;
}
FileSystemFolder other = (FileSystemFolder) obj;
return Objects.equals(file, other.file);
}

@Override
Expand Down
32 changes: 24 additions & 8 deletions src/main/java/spoon/support/compiler/ZipFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,29 @@
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Objects;

import spoon.compiler.SpoonFile;
import spoon.compiler.SpoonFolder;

public class ZipFile implements SpoonFile {

byte[] buffer;
byte[] content;

String name;

ZipFolder parent;

public ZipFile(ZipFolder parent, String name, byte[] buffer) {
this.buffer = buffer;
public ZipFile(ZipFolder parent, String name, byte[] content) {
this.content = content;
this.name = name;
this.parent = parent;
}

@Override
public InputStream getContent() {
return new ByteArrayInputStream(buffer);
return new ByteArrayInputStream(content);
}

@Override
Expand Down Expand Up @@ -84,13 +86,27 @@ public boolean isActualFile() {
}

@Override
public boolean equals(Object obj) {
return toString().equals(obj.toString());
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.hashCode(content);
result = prime * result + Objects.hash(name, parent);
return result;
}

@Override
public int hashCode() {
return toString().hashCode();
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof ZipFile)) {
return false;
}
ZipFile other = (ZipFile) obj;
return Arrays.equals(content, other.content) && Objects.equals(name, other.name)
&& Objects.equals(parent, other.parent);
}



}
18 changes: 14 additions & 4 deletions src/main/java/spoon/support/compiler/ZipFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

Expand Down Expand Up @@ -142,14 +143,23 @@ public File toFile() {
return file;
}



@Override
public boolean equals(Object obj) {
return toString().equals(obj.toString());
public int hashCode() {
return file.hashCode();
}

@Override
public int hashCode() {
return toString().hashCode();
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof ZipFolder)) {
return false;
}
ZipFolder other = (ZipFolder) obj;
return Objects.equals(file, other.file);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand All @@ -101,6 +102,10 @@
import static spoon.support.compiler.jdt.JDTTreeBuilderQuery.searchTypeBinding;

public class ReferenceBuilder {
private static final Set<CtExtendedModifier> PUBLIC_PROTECTED = Set.of(
CtExtendedModifier.explicit(ModifierKind.PUBLIC),
CtExtendedModifier.explicit(ModifierKind.PROTECTED)
);

// Allow to detect circular references and to avoid endless recursivity
// when resolving parameterizedTypes (e.g. Enum<E extends Enum<E>>)
Expand Down Expand Up @@ -261,8 +266,7 @@ private boolean isTypeArgumentExplicit(TypeReference[][] typeArguments) {
* @return a type reference.
*/
<T> CtTypeReference<T> getQualifiedTypeReference(char[][] tokens, TypeBinding receiverType, ReferenceBinding enclosingType, JDTTreeBuilder.OnAccessListener listener) {
final List<CtExtendedModifier> listPublicProtected = Arrays.asList(new CtExtendedModifier(ModifierKind.PUBLIC), new CtExtendedModifier(ModifierKind.PROTECTED));
if (enclosingType != null && Collections.disjoint(listPublicProtected, JDTTreeBuilderQuery.getModifiers(enclosingType.modifiers, false, ModifierTarget.NONE))) {
if (enclosingType != null && Collections.disjoint(PUBLIC_PROTECTED, JDTTreeBuilderQuery.getModifiers(enclosingType.modifiers, false, ModifierTarget.NONE))) {
String access = "";
int i = 0;
final CompilationUnitDeclaration[] units = ((TreeBuilderCompiler) this.jdtTreeBuilder.getContextBuilder().compilationunitdeclaration.scope.environment.typeRequestor).unitsToProcess;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public <K, V> void onMapAdd(CtElement currentElement, CtRole role, Map<K, V> fie
propagateModelChange(new AddAction<>(new MapContext<>(currentElement, role, field, key), newValue));
}

@Override
public <K, V> void onMapDelete(CtElement currentElement, CtRole role, Map<K, V> field, K key, CtElement oldValue) {
propagateModelChange(new DeleteAction<>(new MapContext<>(currentElement, role, field, key), oldValue));
}

@Override
public <K, V> void onMapDeleteAll(CtElement currentElement, CtRole role, Map<K, V> field, Map<K, V> oldValue) {
propagateModelChange(new DeleteAllAction(new MapContext<>(currentElement, role, field), oldValue));
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/spoon/support/modelobs/ChangeCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ public <K, V> void onMapAdd(CtElement currentElement, CtRole role, Map<K, V> fie
onChange(currentElement, role);
}

@Override
public <K, V> void onMapDelete(CtElement currentElement, CtRole role, Map<K, V> field, K key, CtElement oldValue) {
onChange(currentElement, role);
}

@Override
public <K, V> void onMapDeleteAll(CtElement currentElement, CtRole role, Map<K, V> field, Map<K, V> oldValue) {
onChange(currentElement, role);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public <K, V> void onMapAdd(CtElement currentElement, CtRole role,
Map<K, V> field, K key, CtElement newValue) {
}

@Override
public <K, V> void onMapDelete(CtElement currentElement, CtRole role, Map<K, V> field, K key,
CtElement oldValue) {
}

@Override
public <K, V> void onMapDeleteAll(CtElement currentElement, CtRole role,
Map<K, V> field, Map<K, V> oldValue) {
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/spoon/support/modelobs/FineModelChangeListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
*/
package spoon.support.modelobs;

import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.ModifierKind;
import spoon.reflect.path.CtRole;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.ModifierKind;
import spoon.reflect.path.CtRole;


/** Can be subclassed by clients who want to be notified on all changes in AST nodes */
Expand Down Expand Up @@ -46,6 +45,19 @@ public interface FineModelChangeListener {
/** a newValue is appended to the map corresponding to the role in the AST node */
<K, V> void onMapAdd(CtElement currentElement, CtRole role, Map<K, V> field, K key, CtElement newValue);

/**
* A mapping is removed from the map corresponding to the role in the AST node
*
* @param currentElement the element that changed
* @param role the role of the field that changed
* @param field the current value of the field that changed
* @param key the key of the element that was deleted
* @param oldValue the element that was deleted
* @param <K> the key type
* @param <V> the value type
*/
<K, V> void onMapDelete(CtElement currentElement, CtRole role, Map<K, V> field, K key, CtElement oldValue);

/** a map corresponding to the role in the AST node is emptied */
<K, V> void onMapDeleteAll(CtElement currentElement, CtRole role, Map<K, V> field, Map<K, V> oldValue);

Expand Down
33 changes: 33 additions & 0 deletions src/main/java/spoon/support/reflect/CtExtendedModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,48 @@ public class CtExtendedModifier implements SourcePositionHolder, Serializable {
private ModifierKind kind;
private SourcePosition position;

/**
* Creates a new extended modifier of the given kind.
*
* @param kind the kind of this modifier.
* @deprecated use {@link #explicit(ModifierKind)} to create an explicit modifier.
*/
@Deprecated(since = "9.2.0")
public CtExtendedModifier(ModifierKind kind) {
this.kind = kind;
}

/**
* Creates a new extended modifier of the given kind with the given implicitness.
*
* @param kind the kind of this modifier.
* @param implicit whether this modifier should be implicit.
*/
public CtExtendedModifier(ModifierKind kind, boolean implicit) {
this(kind);
this.implicit = implicit;
}

/**
* Creates an extended modifier of the given kind that is explicit.
*
* @param kind the kind of the created modifier.
* @return an explicit extended modifier.
*/
public static CtExtendedModifier explicit(ModifierKind kind) {
return new CtExtendedModifier(kind, false);
}

/**
* Creates an extended modifier of the given kind that is implicit.
*
* @param kind the kind of the created modifier.
* @return an implicit extended modifier.
*/
public static CtExtendedModifier implicit(ModifierKind kind) {
return new CtExtendedModifier(kind, true);
}

public boolean isImplicit() {
return implicit;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/spoon/support/reflect/CtModifierHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public CtModifierHandler addModifier(ModifierKind modifier) {
}
getFactory().getEnvironment().getModelChangeListener().onSetAdd(element, MODIFIER, this.modifiers, modifier);
// we always add explicit modifiers, then we have to remove first implicit one
modifiers.remove(new CtExtendedModifier(modifier, true));
modifiers.add(new CtExtendedModifier(modifier));
modifiers.remove(CtExtendedModifier.implicit(modifier));
modifiers.add(CtExtendedModifier.explicit(modifier));
return this;
}

Expand All @@ -93,8 +93,8 @@ public CtModifierHandler removeModifier(ModifierKind modifier) {
}
getFactory().getEnvironment().getModelChangeListener().onSetDelete(element, MODIFIER, modifiers, modifier);
// we want to remove implicit OR explicit modifier
modifiers.remove(new CtExtendedModifier(modifier));
modifiers.remove(new CtExtendedModifier(modifier, true));
modifiers.remove(CtExtendedModifier.implicit(modifier));
modifiers.remove(CtExtendedModifier.explicit(modifier));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ public <N, C extends CtType<T>> C addNestedType(CtType<N> nestedType) {
// modifiers if they aren't public static already.
Set<CtExtendedModifier> modifiers = new HashSet<>(nestedType.getExtendedModifiers());
if (!nestedType.isPublic()) {
modifiers.add(new CtExtendedModifier(ModifierKind.PUBLIC, true));
modifiers.add(CtExtendedModifier.implicit(ModifierKind.PUBLIC));
}
if (!nestedType.isStatic()) {
modifiers.add(new CtExtendedModifier(ModifierKind.STATIC, true));
modifiers.add(CtExtendedModifier.implicit(ModifierKind.STATIC));
}
nestedType.setExtendedModifiers(modifiers);

Expand Down
Loading

0 comments on commit 11b131d

Please sign in to comment.