diff --git a/src/main/java/spoon/pattern/InlinedStatementConfigurator.java b/src/main/java/spoon/pattern/InlinedStatementConfigurator.java index 2b1474ae81b..a661550c6c6 100644 --- a/src/main/java/spoon/pattern/InlinedStatementConfigurator.java +++ b/src/main/java/spoon/pattern/InlinedStatementConfigurator.java @@ -135,7 +135,6 @@ public InlinedStatementConfigurator markAsInlined(CtForEach foreach) { throw new SpoonException("Each inline `for(x : iterable)` statement must have defined pattern parameter for `iterable` expression"); } PrimitiveMatcher parameterOfExpression = (PrimitiveMatcher) vr; -// PatternBuilder localPatternBuilder = patternBuilder.create(bodyToStatements(foreach.getBody())); ForEachNode mvr = new ForEachNode(); mvr.setIterableParameter(parameterOfExpression); CtLocalVariable lv = foreach.getVariable(); diff --git a/src/main/java/spoon/pattern/PatternBuilder.java b/src/main/java/spoon/pattern/PatternBuilder.java index e381a6da9f6..4ad653b7959 100644 --- a/src/main/java/spoon/pattern/PatternBuilder.java +++ b/src/main/java/spoon/pattern/PatternBuilder.java @@ -84,7 +84,6 @@ public static PatternBuilder create(CtElement... elems) { private CtTypeReference templateTypeRef; private final Map parameterInfos = new HashMap<>(); -// ListOfNodes pattern; CtQueryable patternQuery; private ValueConvertor valueConvertor; private boolean addGeneratedBy = false; diff --git a/src/main/java/spoon/pattern/PatternParameterConfigurator.java b/src/main/java/spoon/pattern/PatternParameterConfigurator.java index d2aaf3dcae5..df910db7c88 100644 --- a/src/main/java/spoon/pattern/PatternParameterConfigurator.java +++ b/src/main/java/spoon/pattern/PatternParameterConfigurator.java @@ -571,32 +571,6 @@ public PatternParameterConfigurator byTemplateParameterReference(CtVariable v return this; } - /** - * CodeElement element identified by `simpleName` - * @param simpleName the name of the element or reference - * @return {@link PatternParameterConfigurator} to support fluent API - */ -// public PatternParameterConfigurator codeElementBySimpleName(String simpleName) { -// ParameterInfo pi = getCurrentParameter(); -// pattern.getModel().filterChildren((CtNamedElement named) -> simpleName.equals(named.getSimpleName())) -// .forEach((CtNamedElement named) -> { -// if (named instanceof CtCodeElement) { -// addSubstitutionRequest(pi, named); -// } -// }); -// pattern.getModel().filterChildren((CtReference ref) -> simpleName.equals(ref.getSimpleName())) -// .forEach((CtReference ref) -> { -// if (ref instanceof CtTypeReference) { -// return; -// } -// CtCodeElement codeElement = ref.getParent(CtCodeElement.class); -// if (codeElement != null) { -// addSubstitutionRequest(pi, codeElement); -// } -// }); -// return this; -// } - /** * All spoon model string attributes whose value is equal to `stringMarker` * are subject for substitution by current parameter diff --git a/src/main/java/spoon/pattern/internal/matcher/TobeMatched.java b/src/main/java/spoon/pattern/internal/matcher/TobeMatched.java index 142db89dd33..9bd241bc92c 100644 --- a/src/main/java/spoon/pattern/internal/matcher/TobeMatched.java +++ b/src/main/java/spoon/pattern/internal/matcher/TobeMatched.java @@ -63,9 +63,6 @@ public static TobeMatched create(ImmutableMap parameters, ContainerKind containe private TobeMatched(ImmutableMap parameters, Object target) { //It is correct to put whole container as single value in cases when ParameterNode matches agains whole attribute value -// if (target instanceof Collection || target instanceof Map) { -// throw new SpoonException("Invalid argument. Use other constructors"); -// } this.parameters = parameters; //make a copy of origin collection, because it might be modified during matching process (by a refactoring algorithm) this.targets = Collections.singletonList(target); diff --git a/src/main/java/spoon/pattern/internal/node/ElementNode.java b/src/main/java/spoon/pattern/internal/node/ElementNode.java index 165bcd250c0..9536103874a 100644 --- a/src/main/java/spoon/pattern/internal/node/ElementNode.java +++ b/src/main/java/spoon/pattern/internal/node/ElementNode.java @@ -170,10 +170,6 @@ private static RootNode create(ContainerKind containerKind, Object templates, Ma @SuppressWarnings({ "unchecked", "rawtypes" }) private static ListOfNodes listOfNodesToNode(List nodes) { - //The attribute is matched different if there is List of one ParameterizedNode and when there is one ParameterizedNode -// if (nodes.size() == 1) { -// return nodes.get(0); -// } return new ListOfNodes((List) nodes); } @@ -378,33 +374,6 @@ private static boolean isMatchingRole(CtRole role, Class targetClass) { public String toString() { return elementType.getName() + ": " + super.toString(); } -// @Override -// public String toString() { -// PrinterHelper printer = new PrinterHelper(getTemplateNode().getFactory().getEnvironment()); -// printer.write(NodeAttributeSubstitutionRequest.getElementTypeName(getTemplateNode().getParent())).writeln().incTab(); -// appendDescription(printer); -// return printer.toString(); -// } -// -// public void appendDescription(PrinterHelper printer) { -// if (attributeSubstititionRequests == null || attributeSubstititionRequests.values().isEmpty()) { -// printer.write("** no attribute substitution **"); -// } else { -// boolean multipleAttrs = attributeSubstititionRequests.size() > 1; -// if (multipleAttrs) { -// printer.incTab(); -// } -// for (Node node : attributeSubstititionRequests.values()) { -// if (multipleAttrs) { -// printer.writeln(); -// } -// printer.write(node.toString()); -// } -// if (multipleAttrs) { -// printer.decTab(); -// } -// } -// } public MetamodelConcept getElementType() { return elementType; diff --git a/src/main/java/spoon/reflect/factory/SubFactory.java b/src/main/java/spoon/reflect/factory/SubFactory.java index bb258447074..9a49a81b63f 100644 --- a/src/main/java/spoon/reflect/factory/SubFactory.java +++ b/src/main/java/spoon/reflect/factory/SubFactory.java @@ -16,7 +16,6 @@ */ package spoon.reflect.factory; - /** * This class is the superclass for all the sub-factories of * {@link spoon.reflect.factory.Factory}. @@ -32,26 +31,5 @@ public SubFactory(Factory factory) { super(); this.factory = factory; } - - /** - * Generically sets the parent of a set of elements or lists of elements. - * - * @param parent - * the parent - * @param elements - * some {@link CtElement} or lists of {@link CtElement} - */ - // protected void setParent(CtElement parent, Object... elements) { - // for (Object o : elements) { - // if (o instanceof CtElement) { - // ((CtElement) o).setParent(parent); - // } else if (o instanceof Collection) { - // for (Object o2 : (Collection) o) { - // ((CtElement) o2).setParent(parent); - // } - // } - // } - // } - } diff --git a/src/main/java/spoon/reflect/factory/TypeFactory.java b/src/main/java/spoon/reflect/factory/TypeFactory.java index a622f22ca14..375c53c785c 100644 --- a/src/main/java/spoon/reflect/factory/TypeFactory.java +++ b/src/main/java/spoon/reflect/factory/TypeFactory.java @@ -605,18 +605,7 @@ protected String getSimpleName(String qualifiedName) { * Tells if a given Java qualified name is that of an inner type. */ protected int hasInnerType(String qualifiedName) { - int ret = qualifiedName.lastIndexOf(CtType.INNERTTYPE_SEPARATOR); - // if (ret < 0) { - // if (hasPackage(qualifiedName) > 0) { - // String buf = qualifiedName.substring(0, - // hasPackage(qualifiedName)); - // int tmp = buf.lastIndexOf(CtPackage.PACKAGE_SEPARATOR); - // if (Character.isUpperCase(buf.charAt(tmp + 1))) { - // ret = hasPackage(qualifiedName); - // } - // } - // } - return ret; + return qualifiedName.lastIndexOf(CtType.INNERTTYPE_SEPARATOR); } /** diff --git a/src/main/java/spoon/reflect/meta/impl/SingleHandler.java b/src/main/java/spoon/reflect/meta/impl/SingleHandler.java index 2362d26b272..53bd906a03d 100644 --- a/src/main/java/spoon/reflect/meta/impl/SingleHandler.java +++ b/src/main/java/spoon/reflect/meta/impl/SingleHandler.java @@ -45,7 +45,6 @@ public java.util.Collection asCollection(W element) { } public java.util.List asList(W e) { -// return Collections.singletonList(getValue(element)); return new AbstractList() { T element = castTarget(e); boolean hasValue = SingleHandler.this.getValue(element) != null; @@ -73,6 +72,7 @@ public X set(int index, X value) { SingleHandler.this.setValue(element, value); return (X) oldValue; } + @Override public boolean add(X value) { if (hasValue) { @@ -96,6 +96,7 @@ public X remove(int index) { hasValue = false; return oldValue; } + @Override public boolean remove(Object value) { if (hasValue == false) { @@ -111,6 +112,7 @@ public boolean remove(Object value) { } return false; } + private boolean equals(Object v1, Object v2) { if (v1 == v2) { return true;