Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate: Removes getSignature() and create getShortRepresentation(). #738

Merged
merged 1 commit into from
Jul 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/main/java/spoon/processing/XMLAnnotationProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,12 @@
*/
package spoon.processing;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.log4j.Level;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

import spoon.Launcher;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtElement;
Expand All @@ -41,6 +31,14 @@
import spoon.reflect.reference.CtTypeReference;
import spoon.support.processing.XmlProcessorProperties;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;

/**
* A processor to add/replace/override/remove annotations described in an XML
* file. This version is based on java.util.regexp, but it can be subclassed to
Expand Down Expand Up @@ -149,8 +147,7 @@ protected boolean isExecutableMatching(CtExecutable<?> executable, String execut
* @see CtElement#getSignature()
*/
protected boolean isFieldMatching(CtField<?> field, String fieldExpression) {
String signature = field.getSignature();
return java.util.regex.Pattern.matches(fieldExpression, signature);
return java.util.regex.Pattern.matches(fieldExpression, field.getShortRepresentation());
}

public final void process() {
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/spoon/reflect/declaration/CtElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,10 @@ <A extends Annotation> CtAnnotation<A> getAnnotation(
*/
String getDocComment();


/**
* Gets the signature of the element.
* Has been introduced for CtMethod, see chapter "8.4.2 Method Signature" of the Java specification.
* Overtime, has been badly exploited.
*
* Deprecated, will be moved in {@link CtExecutable}, in order to follow the Java specification
* Build a short representation of any element.
*/
@Deprecated
String getSignature();
String getShortRepresentation();

/**
* Gets the position of this element in input source files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ public interface CtExecutableReference<T> extends CtReference, CtActualTypeConta
*/
boolean isFinal();

/**
* Gets the signature of this method or constructor as specified by chapter "8.4.2 Method Signature" of the Java specification
*/
String getSignature();

/**
* Replaces an executable reference by another one.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public void scan(CtElement element) {
}

private static String toDebugString(CtElement e) {
return "Element: " + e + "\nSignature: " + e.getSignature() + "\nClass: " + e.getClass() + "\n";
return "Element: " + e + "\nSignature: " + e.getShortRepresentation() + "\nClass: " + e.getClass() + "\n";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ private void adjustPosition(CtElement e) {
if (!removeLine()) {
if (line > e.getPosition().getEndLine()) {
env.report(null, Level.WARN, e,
"cannot adjust position of " + e.getClass().getSimpleName() + " '" + e.getSignature() + "' " + " to match lines: " + line + " > [" + e.getPosition().getLine() + ", "
"cannot adjust position of " + e.getClass().getSimpleName() + " '" + e.getShortRepresentation() + "' " + " to match lines: " + line + " > [" + e.getPosition().getLine() + ", "
+ e.getPosition().getEndLine() + "]");
}
break;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/spoon/support/reflect/code/CtLambdaImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ public boolean removeThrownType(CtTypeReference<? extends Throwable> throwType)
return thrownTypes.remove(throwType);
}

@Override
public String getSignature() {
throw new UnsupportedOperationException();
}

@Override
public CtExecutableReference<T> getReference() {
return getFactory().Executable().createReference(this);
Expand Down
24 changes: 9 additions & 15 deletions src/main/java/spoon/support/reflect/declaration/CtElementImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import spoon.support.util.EmptyClearableSet;
import spoon.support.visitor.EqualVisitor;
import spoon.support.visitor.HashcodeVisitor;
import spoon.support.visitor.SignaturePrinter;
import spoon.support.visitor.ShortRepresentationPrinter;
import spoon.support.visitor.TypeReferenceScanner;
import spoon.support.visitor.equals.CloneHelper;
import spoon.support.visitor.equals.EqualsVisitor;
Expand Down Expand Up @@ -77,20 +77,6 @@ public static <T> List<T> unmodifiableList(List<T> list) {
return list.isEmpty() ? Collections.<T>emptyList() : Collections.unmodifiableList(list);
}

public String getSignature() {
SignaturePrinter pr = new SignaturePrinter();
pr.scan(this);
String sig = pr.getSignature();

// we have a signature return it
if (sig.length() > 0) {
return sig;
}

// else fallback to backward compatibility
return getDeepRepresentation(this);
}

transient Factory factory;

protected CtElement parent;
Expand All @@ -111,6 +97,7 @@ public CtElementImpl() {
* based on the deep representation
* which is also used in {@link #equals(Object)}.
*/
@Override
public int compareTo(CtElement o) {
String current = getDeepRepresentation(this);
String other = getDeepRepresentation(o);
Expand All @@ -120,6 +107,13 @@ public int compareTo(CtElement o) {
return current.compareTo(other);
}

@Override
public String getShortRepresentation() {
final ShortRepresentationPrinter printer = new ShortRepresentationPrinter();
printer.scan(this);
return printer.getShortRepresentation();
}

private String getDeepRepresentation(CtElement elem) {
EqualVisitor prThis = new EqualVisitor();
prThis.scan(elem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import spoon.reflect.declaration.CtParameter;
import spoon.reflect.reference.CtExecutableReference;
import spoon.reflect.reference.CtTypeReference;
import spoon.support.visitor.SignaturePrinter;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -140,6 +141,13 @@ public boolean removeThrownType(CtTypeReference<? extends Throwable> throwType)
return thrownTypes.remove(throwType);
}

@Override
public String getSignature() {
final SignaturePrinter pr = new SignaturePrinter();
pr.scan(this);
return pr.getSignature();
}

@Override
public CtExecutableReference<R> getReference() {
return getFactory().Executable().createReference(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import spoon.reflect.visitor.filter.NameFilter;
import spoon.support.reflect.declaration.CtElementImpl;
import spoon.support.util.RtHelper;
import spoon.support.visitor.SignaturePrinter;

import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -430,6 +431,13 @@ public boolean removeActualTypeArgument(
&& actualTypeArguments.remove(actualTypeArgument);
}

@Override
public String getSignature() {
final SignaturePrinter pr = new SignaturePrinter();
pr.scan(this);
return pr.getSignature();
}

@Override
public CtExecutableReference<T> clone() {
return (CtExecutableReference<T>) super.clone();
Expand Down
Loading