Skip to content

Commit

Permalink
refactor: remove commented code (SonarQube defect fix) (#2251)
Browse files Browse the repository at this point in the history
  • Loading branch information
zielint0 authored and pvojtechovsky committed Jul 23, 2018
1 parent 87f4f79 commit 6be365c
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 153 deletions.
11 changes: 10 additions & 1 deletion src/main/java/spoon/pattern/PatternParameterConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,15 @@ public PatternParameterConfigurator setMinOccurence(int minOccurence) {
currentParameter.setMinOccurrences(minOccurence);
return this;
}

public PatternParameterConfigurator setMaxOccurence(int maxOccurence) {
if (maxOccurence == ParameterInfo.UNLIMITED_OCCURRENCES || maxOccurence > 1 && currentParameter.isMultiple() == false) {
throw new SpoonException("Cannot set maxOccurrences > 1 for single value parameter. Call setMultiple(true) first.");
}
currentParameter.setMaxOccurrences(maxOccurence);
return this;
}

public PatternParameterConfigurator setMatchingStrategy(Quantifier quantifier) {
currentParameter.setMatchingStrategy(quantifier);
return this;
Expand Down Expand Up @@ -185,6 +187,7 @@ public ParameterInfo getCurrentParameter() {
public PatternParameterConfigurator byType(Class<?> type) {
return byType(type.getName());
}

/**
* type identified by `typeQualifiedName` itself and all the references (with arbitrary actual type arguments)
* to that type are subject for substitution by current parameter
Expand All @@ -208,6 +211,7 @@ public PatternParameterConfigurator byType(String typeQualifiedName) {
}
return this;
}

/**
* type referred by {@link CtTypeReference} `type` and all the references (with same actual type arguments)
* to that type are subject for substitution by current parameter
Expand Down Expand Up @@ -243,6 +247,7 @@ public PatternParameterConfigurator byLocalType(CtType<?> searchScope, String lo
byLocalType(searchScope, localTypeSimpleName, false);
return this;
}

PatternParameterConfigurator byLocalType(CtType<?> searchScope, String localTypeSimpleName, boolean optional) {
String nestedType = getLocalTypeRefBySimpleName(searchScope, localTypeSimpleName);
if (nestedType == null) {
Expand Down Expand Up @@ -334,6 +339,7 @@ public PatternParameterConfigurator byFieldAccessOnVariable(String varName) {
}
return this;
}

/**
* Add parameters for each variable reference of `variable`
* @param variable to be substituted variable
Expand Down Expand Up @@ -371,6 +377,7 @@ private void createPatternParameterForVariable(CtVariable<?> variable) {
public PatternParameterConfigurator byTemplateParameter() {
return byTemplateParameter(null);
}

/**
* Creates pattern parameter for each field of type {@link TemplateParameter}
* @param parameterValues pattern parameter values.
Expand Down Expand Up @@ -630,7 +637,7 @@ protected void visitStringAttribute(RoleHandler roleHandler, CtElement element,
}
return oldAttrNode;
});
}
}
}
}.scan(patternBuilder.getPatternModel());
return this;
Expand Down Expand Up @@ -808,6 +815,7 @@ void addSubstitutionRequest(ParameterInfo parameter, CtElement element) {
void addSubstitutionRequest(ParameterInfo parameter, CtElement element, CtRole attributeRole) {
patternBuilder.setNodeOfAttributeOfElement(element, attributeRole, new ParameterNode(parameter), conflictResolutionMode);
}

/**
* Adds request to substitute substring of {@link String} value of `attributeRole` of `element`, by the value of this {@link ListOfNodes} parameter {@link ParameterInfo} value
* @param element whose part of String attribute of {@link CtRole} `attributeRole` have to be replaced
Expand Down Expand Up @@ -894,6 +902,7 @@ private ParameterElementPair transformVariableAccessToVariableReference(Paramete
}
return pep;
}

/**
* @return an invocation of {@link TemplateParameter#S()} if it is parent of `element`
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public Collection<CtElement> getElements(Collection<CtElement> roots) {
matchs.add(match);
}
} catch (CtPathException e) {
//System.err.println("[ERROR] Element not found for name: " + name);
//No element found for name.
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ public <T> void visitCtClass(CtClass<T> ctClass) {
elementPrinterHelper.writeExtendsClause(ctClass);
elementPrinterHelper.writeImplementsClause(ctClass);
}
// lst.addAll(elementPrinterHelper.getComments(ctClass, CommentOffset.INSIDE));
printer.writeSpace().writeSeparator("{").incTab();
elementPrinterHelper.writeElementList(ctClass.getTypeMembers());
getPrinterHelper().adjustEndPosition(ctClass);
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/spoon/reflect/visitor/chain/CtQueryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,6 @@ protected void onClassCastException(ClassCastException e, Object input) {
if (indexOfCallerInStack < 0) {
//this is an exotic JVM, where we cannot detect type of parameter of Lambda expression
//Silently ignore this CCE, which was may be expected or may be problem in client's code.
// if (Launcher.LOGGER.isDebugEnabled()) {
// Launcher.LOGGER.debug("ClassCastException thrown by client's code or Query engine ...", e);
// }
return;
}
//we can detect whether CCE was thrown in client's code (unexpected - must be rethrown) or Query engine (expected - has to be ignored)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,13 +863,6 @@ <T> CtTypeReference<T> getTypeReference(TypeBinding binding) {
} else {
ref.setPackage(getPackageReference(binding.getPackage()));
}
// if(((SourceTypeBinding) binding).typeVariables!=null &&
// ((SourceTypeBinding) binding).typeVariables.length>0){
// for (TypeBinding b : ((SourceTypeBinding)
// binding).typeVariables) {
// ref.getActualTypeArguments().add(getTypeReference(b));
// }
// }
}
} else if (binding instanceof ArrayBinding) {
CtArrayTypeReference<Object> arrayref;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ protected CompilationUnitDeclaration[] buildUnits(CompilationUnit[] sourceUnits)
for (; i < this.totalUnits; i++) {
unit = unitsToProcess[i];
this.reportProgress(Messages.bind(Messages.compilation_processing, new String(unit.getFileName())));
// System.err.println(unit);
this.parser.getMethodBodies(unit);

// fault in fields & methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ public <T> void visitCtInvocation(CtInvocation<T> invocation) {
// try to completely evaluate
T r = null;
try {
// System.err.println("invocking "+i);
r = RtHelper.invoke(i);
if (isLiteralType(r)) {
CtLiteral<T> l = invocation.getFactory().Core().createLiteral();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,66 +94,6 @@ public boolean isConstructor() {
return getSimpleName().equals(CONSTRUCTOR_NAME);
}

// @Override
// public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
// A annotation = super.getAnnotation(annotationType);
// if (annotation != null) {
// return annotation;
// }
// // use reflection
// Class<?> c = getDeclaringType().getActualClass();
// for (Method m : RtHelper.getAllMethods(c)) {
// if (!getSimpleName().equals(m.getName())) {
// continue;
// }
// if (getParameterTypes().size() != m.getParameterTypes().length) {
// continue;
// }
// int i = 0;
// for (Class<?> t : m.getParameterTypes()) {
// if (t != getParameterTypes().get(i).getActualClass()) {
// break;
// }
// i++;
// }
// if (i == getParameterTypes().size()) {
// m.setAccessible(true);
// return m.getAnnotation(annotationType);
// }
// }
// return null;
// }

// @Override
// public Annotation[] getAnnotations() {
// Annotation[] annotations = super.getAnnotations();
// if (annotations != null) {
// return annotations;
// }
// // use reflection
// Class<?> c = getDeclaringType().getActualClass();
// for (Method m : RtHelper.getAllMethods(c)) {
// if (!getSimpleName().equals(m.getName())) {
// continue;
// }
// if (getParameterTypes().size() != m.getParameterTypes().length) {
// continue;
// }
// int i = 0;
// for (Class<?> t : m.getParameterTypes()) {
// if (t != getParameterTypes().get(i).getActualClass()) {
// break;
// }
// i++;
// }
// if (i == getParameterTypes().size()) {
// m.setAccessible(true);
// return m.getAnnotations();
// }
// }
// return null;
// }

@Override
@SuppressWarnings("unchecked")
public CtExecutable<T> getDeclaration() {
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/spoon/support/visitor/TypeReferenceScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,6 @@ public <T> void visitCtFieldReference(CtFieldReference<T> reference) {
exit(reference);
}

// public <T> boolean isImported(CtTypeReference<T> ref) {
// if (imports.containsKey(ref.getSimpleName())) {
// CtTypeReference<?> exist = imports.get(ref.getSimpleName());
// if (exist.getQualifiedName().equals(ref.getQualifiedName()))
// return true;
// }
// return false;
// }

@Override
public <T> void visitCtExecutableReference(
CtExecutableReference<T> reference) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,6 @@ public void visitTypeReference(CtRole role, ParameterizedType type) {
ctTypeReference.setSimpleName(((Class) type.getRawType()).getSimpleName());

RuntimeBuilderContext context = new TypeReferenceRuntimeBuilderContext(type, ctTypeReference) {
// @Override
// public void addTypeReference(CtRole role, CtTypeReference<?> typeReference) {
// ctTypeReference.setSimpleName(typeReference.getSimpleName());
// ctTypeReference.setPackage(typeReference.getPackage());
// ctTypeReference.setDeclaringType(typeReference.getDeclaringType());
// ctTypeReference.setActualTypeArguments(typeReference.getActualTypeArguments());
// ctTypeReference.setAnnotations(typeReference.getAnnotations());
// }

@Override
public void addType(CtType<?> aType) {
Expand Down
35 changes: 1 addition & 34 deletions src/main/java/spoon/template/Substitution.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ public static <T> CtConstructor<T> insertConstructor(CtClass<T> targetClass, Tem
CtConstructor<T> newConstructor = targetClass.getFactory().Constructor().create(targetClass, sourceMethod);
newConstructor = substitute(targetClass, template, newConstructor);
targetClass.addConstructor(newConstructor);
// newConstructor.setParent(targetClass);
return newConstructor;
}

Expand All @@ -408,7 +407,6 @@ public static <T> CtMethod<T> insertMethod(CtType<?> targetType, Template<?> tem
newMethod.setBody(null);
}
targetType.addMethod(newMethod);
// newMethod.setParent(targetType);
return newMethod;
}

Expand Down Expand Up @@ -437,7 +435,6 @@ public static <T> CtConstructor<T> insertConstructor(CtClass<T> targetClass, Tem
}
}
targetClass.addConstructor(newConstrutor);
// newConstrutor.setParent(targetClass);
return newConstrutor;
}

Expand Down Expand Up @@ -536,35 +533,6 @@ public static <E extends CtElement> E substitute(CtType<?> targetType, Template<
return (E) tb.substituteSingle(targetType, CtElement.class);
}

/**
* Substitutes all the template parameters in the first template element
* annotated with an instance of the given annotation type.
*
* @param targetType
* the target type
* @param template
* the template instance
* @param annotationType
* the annotation type
* @return the element where all the template parameters has be substituted
* by their values
*/
// public static <E extends CtElement> E substitute(
// CtSimpleType<?> targetType, Template template,
// Class<? extends Annotation> annotationType) {
// CtClass<? extends Template> c = targetType.getFactory().Class
// .get(template.getClass());
// E element = (E) c.getAnnotatedChildren(annotationType).get(0);
// if (element == null)
// return null;
// if (targetType == null)
// throw new RuntimeException("target is null in substitution");
// E result = CtCloner.clone(element);
// new SubstitutionVisitor(targetType.getFactory(), targetType, template)
// .scan(result);
// return result;
// }

/**
* Substitutes all the template parameters in a given template type and
* returns the resulting type.
Expand Down Expand Up @@ -602,7 +570,6 @@ public static <T extends CtType<?>> T substitute(Template<?> template, T templat
public static <T> CtField<T> insertField(CtType<?> targetType, Template<?> template, CtField<T> sourceField) {
CtField<T> field = substitute(targetType, template, sourceField);
targetType.addField(field);
// field.setParent(targetType);
return field;
}

Expand Down Expand Up @@ -673,7 +640,7 @@ private static <T> void checkTemplateContracts(CtClass<T> c) {
if (fieldTypeQName.equals(String.class.getName())) {
// contract: the name of the template parameter must correspond to the name of the field
// as found, by Pavel, this is not good contract because it prevents easy refactoring of templates
// we remove it but keep th commented code in case somebody would come up with this bad idae
// we remove it but keep the commented code in case somebody would come up with this bad idea
// if (!f.getSimpleName().equals("_" + f.getAnnotation(Parameter.class).value())) {
// throw new TemplateException("the field name of a proxy template parameter must be called _" + f.getSimpleName());
// }
Expand Down
Loading

0 comments on commit 6be365c

Please sign in to comment.