Skip to content

Commit

Permalink
Applied mvn checkstyle fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Auties00 committed Jul 12, 2022
1 parent 38424ef commit b962a40
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 63 deletions.
2 changes: 0 additions & 2 deletions src/main/java/spoon/ContractVerifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*/
package spoon;


import spoon.reflect.CtModelImpl;
import spoon.reflect.code.CtArrayWrite;
import spoon.reflect.code.CtAssignment;
import spoon.reflect.code.CtExpression;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/spoon/reflect/CtModelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import spoon.support.reflect.declaration.CtModuleImpl;
import spoon.support.util.internal.ElementNameMap;

import java.util.*;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class CtModelImpl implements CtModel {
Expand Down Expand Up @@ -126,7 +128,7 @@ public void updateModuleName(CtModule newModule, String oldName) {
modules.updateKey(oldName, newModule.getSimpleName());
}

private static class Modules extends ElementNameMap<CtModule>{
private static class Modules extends ElementNameMap<CtModule> {
@Override
protected CtElement getOwner() {
return null;
Expand Down
41 changes: 21 additions & 20 deletions src/main/java/spoon/reflect/factory/ModuleFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


import java.util.Collection;

import spoon.reflect.declaration.CtModule;
import spoon.reflect.declaration.CtModuleRequirement;
import spoon.reflect.declaration.CtPackageExport;
Expand All @@ -19,30 +20,30 @@
import spoon.reflect.reference.CtTypeReference;

public class ModuleFactory extends SubFactory {
public ModuleFactory(Factory factory) {
super(factory);
}
public ModuleFactory(Factory factory) {
super(factory);
}

public CtModule getUnnamedModule() {
return factory.getModel().getUnnamedModule();
}
public CtModule getUnnamedModule() {
return factory.getModel().getUnnamedModule();
}

public Collection<CtModule> getAllModules() {
return factory.getModel().getAllModules();
}
public Collection<CtModule> getAllModules() {
return factory.getModel().getAllModules();
}

public CtModule getModule(String moduleName) {
public CtModule getModule(String moduleName) {
if (moduleName == null || moduleName.isEmpty()) {
return getUnnamedModule();
}

return factory.getModel().getModule(moduleName);
}
return factory.getModel().getModule(moduleName);
}

public CtModule getOrCreate(String moduleName) {
if (moduleName == null || moduleName.isEmpty()) {
return getUnnamedModule();
}
public CtModule getOrCreate(String moduleName) {
if (moduleName == null || moduleName.isEmpty()) {
return getUnnamedModule();
}

CtModule known = getModule(moduleName);
if (known != null) {
Expand All @@ -52,11 +53,11 @@ public CtModule getOrCreate(String moduleName) {
CtModule fresh = factory.Core().createModule().setSimpleName(moduleName);
factory.getModel().addModule(fresh);
return fresh;
}
}

public CtModuleReference createReference(CtModule module) {
return createReference(module.getSimpleName());
}
public CtModuleReference createReference(CtModule module) {
return createReference(module.getSimpleName());
}

public CtModuleReference createReference(String module) {
return factory.Core().createModuleReference().setSimpleName(module);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/spoon/reflect/factory/PackageFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public CtPackage getOrCreate(String qualifiedName) {
private CtModule findModuleByPackage(String qualifiedName) {
String owner = getOwner(qualifiedName);
CtModule known = packageModuleCache.get(owner);
if(known != null){
if (known != null) {
return known;
}

Expand All @@ -135,11 +135,11 @@ private CtModule findModuleByPackage(String qualifiedName) {

private CtModule findCtModule(String qualifiedName) {
List<Module> modules = findModules(qualifiedName);
if(modules.isEmpty()){
if (modules.isEmpty()) {
return factory.getModel().getUnnamedModule();
}

if(modules.size() != 1){
if (modules.size() != 1) {
throw new SpoonException(
"Ambiguous package name detected. If you believe the code you analyzed is correct, please"
+ " file an issue and reference https://github.com/INRIA/spoon/issues/4051. "
Expand All @@ -151,9 +151,9 @@ private CtModule findCtModule(String qualifiedName) {
return factory.Module().getOrCreate(modules.get(0).getName());
}

private String getOwner(String qualifiedName){
private String getOwner(String qualifiedName) {
int index = qualifiedName.indexOf(".");
if(index == -1){
if (index == -1) {
return qualifiedName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public boolean matches(CtLambda<?> lambda) {
CtType<?> declaringType = targetMethod.getDeclaringType();
lambdaFilter.addImplementingInterface(declaringType);

for(CtModule ctModule : declaringType.getFactory().getModel().getAllModules()) {
for (CtModule ctModule : declaringType.getFactory().getModel().getAllModules()) {
//search for all declarations and implementations of this method in sub and super classes and interfaces of all related hierarchies.
class Context {
boolean haveToSearchForSubtypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public SubInheritanceHierarchyFunction failOnClassNotFound(boolean failOnClassNo
@Override
public void apply(CtTypeInformation input, final CtConsumer<Object> outputConsumer) {
Factory factory = ((CtElement) input).getFactory();
for(CtModule ctModule : factory.getModel().getAllModules()) {
for (CtModule ctModule : factory.getModel().getAllModules()) {
final SubInheritanceHierarchyResolver fnc = new SubInheritanceHierarchyResolver(ctModule.getRootPackage())
.failOnClassNotFound(failOnClassNotFound)
.includingInterfaces(includingInterfaces);
Expand All @@ -81,7 +81,7 @@ public void apply(CtTypeInformation input, final CtConsumer<Object> outputConsum
fnc.forEachSubTypeInPackage((CtType<?> typeInfo) -> {
outputConsumer.accept(typeInfo);
// Cannot terminate, because its support was removed.
// I think there are cases where it might be useful.
// I think there are cases where it might be useful.
// fnc.terminate();
query.isTerminated();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static void compileAndReplaceSnippetsIn(CtType<?> initialClass) {
CtType<?> newClass = f.Type().get(initialClass.getQualifiedName());

// we find the snippets that are now ASTs
for(CtModule ctModule : f.getModel().getAllModules()) {
for (CtModule ctModule : f.getModel().getAllModules()) {
for (CtPath p : elements2before.keySet()) {
elements2after.put(p, p.evaluateOn(ctModule.getRootPackage()).iterator().next());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void instantiateAndProcess(List<String> processors) {
factory.getEnvironment().debugMessage("Loaded processor " + processorName + ".");
}

for(CtModule ctModule : factory.getModel().getAllModules()){
for (CtModule ctModule : factory.getModel().getAllModules()) {
processing.process(ctModule.getRootPackage());
}
}
Expand All @@ -196,7 +196,7 @@ public void process(Collection<Processor<? extends CtElement>> processors) {
factory.getEnvironment().debugMessage("Loaded processor " + processorName + ".");
}

for(CtModule ctModule : factory.getModel().getAllModules()){
for (CtModule ctModule : factory.getModel().getAllModules()) {
processing.process(ctModule.getRootPackage());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spoon/support/gui/SpoonModelTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class SpoonModelTree extends JFrame implements KeyListener,
*/
public SpoonModelTree(Factory factory) {
SpoonTreeBuilder cst = new SpoonTreeBuilder();
for(CtModule ctModule : factory.getModel().getAllModules()) {
for (CtModule ctModule : factory.getModel().getAllModules()) {
cst.scan(ctModule.getRootPackage());
}

Expand Down
22 changes: 18 additions & 4 deletions src/main/java/spoon/support/reflect/declaration/CtModuleImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@

import spoon.reflect.CtModelImpl;
import spoon.reflect.annotations.MetamodelPropertyField;
import spoon.reflect.declaration.*;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.CtModule;
import spoon.reflect.declaration.CtModuleDirective;
import spoon.reflect.declaration.CtModuleRequirement;
import spoon.reflect.declaration.CtNamedElement;
import spoon.reflect.declaration.CtPackage;
import spoon.reflect.declaration.CtPackageExport;
import spoon.reflect.declaration.CtProvidedService;
import spoon.reflect.declaration.CtShadowable;
import spoon.reflect.declaration.CtUsedService;
import spoon.reflect.declaration.ParentNotInitializedException;
import spoon.reflect.factory.Factory;
import spoon.reflect.path.CtRole;
import spoon.reflect.reference.CtModuleReference;
Expand All @@ -18,7 +28,11 @@
import spoon.support.comparator.CtLineElementComparator;
import spoon.support.util.SortedList;

import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Stream;

public class CtModuleImpl extends CtNamedElementImpl implements CtModule {
Expand All @@ -34,7 +48,7 @@ public class CtModuleImpl extends CtNamedElementImpl implements CtModule {
@MetamodelPropertyField(role = CtRole.SUB_PACKAGE)
private CtPackage rootPackage;

public CtModuleImpl(Factory factory){
public CtModuleImpl(Factory factory) {
this.setFactory(factory);
this.moduleDirectives = CtElementImpl.emptyList();
this.rootPackage = new CtPackageImpl.RootPackage(this);
Expand All @@ -51,7 +65,7 @@ public <E extends CtNamedElement> E setSimpleName(String simpleName) {
super.setSimpleName(simpleName);

CtModelImpl ctModel = (CtModelImpl) factory.getModel();
if(ctModel != null) {
if (ctModel != null) {
ctModel.updateModuleName(this, oldName);
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/spoon/support/util/internal/ElementNameMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public T put(String key, T e) {
return null;
}
CtElement owner = getOwner();
if(owner != null) {
if (owner != null) {
linkToParent(owner, e);
getModelChangeListener().onMapAdd(owner, getRole(), map, key, e);
}
Expand All @@ -87,7 +87,7 @@ public T remove(Object key) {
return null;
}

if(getOwner() != null) {
if (getOwner() != null) {
getModelChangeListener().onMapDelete(
getOwner(),
getRole(),
Expand All @@ -108,7 +108,7 @@ public void clear() {
// Only an approximation as the concurrent map is only weakly consistent
Map<String, T> old = new LinkedHashMap<>(map);
map.clear();
if(getOwner() != null){
if (getOwner() != null) {
getModelChangeListener().onMapDeleteAll(
getOwner(),
getRole(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,19 @@ public <T, R extends CtType<T>> R scan(Class<T> clazz) {
} else {
CtPackage ctPackage = clazz.getPackage() != null ? factory.Package().getOrCreate(clazz.getPackage().getName())
: factory.Package().getRootPackage();
if(contexts.isEmpty()){
if (contexts.isEmpty()) {
contexts.add(new PackageRuntimeBuilderContext(ctPackage));
}

if (clazz.isAnnotation()) {
visitAnnotationClass((Class<Annotation>) clazz);
}else if (clazz.isInterface()) {
} else if (clazz.isInterface()) {
visitInterface(clazz);
}else if (clazz.isEnum()) {
} else if (clazz.isEnum()) {
visitEnum(clazz);
}else if (MethodHandleUtils.isRecord(clazz)) {
} else if (MethodHandleUtils.isRecord(clazz)) {
visitRecord(clazz);
}else {
} else {
visitClass(clazz);
}
exit();
Expand All @@ -143,7 +143,7 @@ public void visitModule(Module module) {

CtModule fresh = know != null ? know : factory.Module().getOrCreate(module.getName());
ModuleDescriptor descriptor = module.getDescriptor();
if(descriptor != null){
if (descriptor != null) {
createModuleData(fresh, descriptor);
}

Expand Down Expand Up @@ -183,11 +183,11 @@ private void createModuleData(CtModule fresh, ModuleDescriptor descriptor) {
private CtModuleRequirement createRequires(ModuleDescriptor.Requires instruction) {
CtModuleReference requiredModule = factory.Module().createReference(instruction.name());
Set<CtModuleRequirement.RequiresModifier> modifiers = new HashSet<>();
if(instruction.modifiers().contains(ModuleDescriptor.Requires.Modifier.STATIC)){
if (instruction.modifiers().contains(ModuleDescriptor.Requires.Modifier.STATIC)) {
modifiers.add(CtModuleRequirement.RequiresModifier.STATIC);
}

if(instruction.modifiers().contains(ModuleDescriptor.Requires.Modifier.TRANSITIVE)){
if (instruction.modifiers().contains(ModuleDescriptor.Requires.Modifier.TRANSITIVE)) {
modifiers.add(CtModuleRequirement.RequiresModifier.TRANSITIVE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@
import java.lang.reflect.WildcardType;
import java.util.ArrayList;
import java.util.List;

import spoon.SpoonException;
import spoon.reflect.path.CtRole;
import spoon.support.visitor.java.reflect.RtMethod;
import spoon.support.visitor.java.reflect.RtParameter;

class JavaReflectionVisitorImpl implements JavaReflectionVisitor {
private static final Class<?> recordClass = getRecordClass();
private static final Class<?> recordClass = getRecordClass();

@Override
public void visitModule(Module module) {
for (Annotation annotation : module.getAnnotations()) {
visitAnnotation(annotation);
}
}
@Override
public void visitModule(Module module) {
for (Annotation annotation : module.getAnnotations()) {
visitAnnotation(annotation);
}
}

@Override
public void visitPackage(Package aPackage) {
Expand All @@ -46,7 +47,7 @@ public void visitPackage(Package aPackage) {

@Override
public <T> void visitClass(Class<T> clazz) {
visitModule(clazz.getModule());
visitModule(clazz.getModule());
if (clazz.getPackage() != null) {
visitPackage(clazz.getPackage());
}
Expand Down Expand Up @@ -132,7 +133,7 @@ protected final <T> void visitType(Class<T> aClass) {
@Override
public <T> void visitInterface(Class<T> clazz) {
assert clazz.isInterface();
visitModule(clazz.getModule());
visitModule(clazz.getModule());
if (clazz.getPackage() != null) {
visitPackage(clazz.getPackage());
}
Expand Down Expand Up @@ -190,7 +191,7 @@ public <T> void visitInterface(Class<T> clazz) {
@Override
public <T> void visitEnum(Class<T> clazz) {
assert clazz.isEnum();
visitModule(clazz.getModule());
visitModule(clazz.getModule());
if (clazz.getPackage() != null) {
visitPackage(clazz.getPackage());
}
Expand Down Expand Up @@ -264,7 +265,7 @@ public <T> void visitEnum(Class<T> clazz) {
@Override
public <T extends Annotation> void visitAnnotationClass(Class<T> clazz) {
assert clazz.isAnnotation();
visitModule(clazz.getModule());
visitModule(clazz.getModule());
if (clazz.getPackage() != null) {
visitPackage(clazz.getPackage());
}
Expand Down Expand Up @@ -533,7 +534,7 @@ public <T> void visitRecord(Class<T> clazz) {
}
try {
for (TypeVariable<Class<T>> generic : clazz.getTypeParameters()) {
visitTypeParameter(generic);
visitTypeParameter(generic);
}
} catch (NoClassDefFoundError ignore) {
// partial classpath
Expand Down

0 comments on commit b962a40

Please sign in to comment.