Commit 9b53cdb6 authored by Marco Konersmann's avatar Marco Konersmann

adds update annotated member references for annotation type multi targets

parent c691cfcc
package org.codeling.mechanisms.transformations.references
import de.mkonersmann.advert.java.embed.ASTUtils
import de.mkonersmann.advert.java.embed.transformation.references.IALTransformation
import java.util.Collection
import java.util.LinkedHashSet
import java.util.LinkedList
......@@ -17,6 +18,7 @@ import org.eclipse.jdt.core.IBuffer
import org.eclipse.jdt.core.ICompilationUnit
import org.eclipse.jdt.core.IField
import org.eclipse.jdt.core.IType
import org.eclipse.jdt.core.JavaModelException
import org.eclipse.jdt.core.dom.AST
abstract class AnnotatedMemberReferenceTransformation<OWNERECLASS extends EObject, TARGETECLASS extends EObject> extends ReferenceMechanismTransformation<OWNERECLASS, TARGETECLASS, IType> {
......@@ -113,7 +115,45 @@ abstract class AnnotatedMemberReferenceTransformation<OWNERECLASS extends EObjec
def void updateMarkerInterfaceReferenceSingle(EObject target) {}
def void updateTypeAnnotationReferenceMulti(LinkedList<EObject> priorTargets, LinkedList<EObject> targets) {}
def void updateTypeAnnotationReferenceMulti(LinkedList<EObject> priorTargets, LinkedList<EObject> targets) {
// Create fields
for (EObject target : targets) {
val String originalTargetName = getNameAttributeValue(target);
var String targetName = originalTargetName;
targetName = Character.toLowerCase(targetName.charAt(0)) + targetName.substring(1);
val IType type = if (this instanceof IALTransformation<?, ?>) {
(this as IALTransformation<?, ?>).getIALHolder().getIALCodeElement() as IType
} else {
codeElement;
};
val IField field = type.getField(targetName);
if (field === null || !field.exists()) {
try {
var String content = "@Inject\r";
content += "" + originalTargetName + " " + targetName + ";\r\r";
type.createField(content, null, true, null);
} catch (JavaModelException e) {
e.printStackTrace();
}
}
}
// Delete fields
for (EObject priorTarget : priorTargets) {
val String priorName = priorTarget.nameAttributeValue;
if (!targets.exists[it.nameAttributeValue == priorName]) {
val String originalTargetName = getNameAttributeValue(priorTarget);
var String targetName = originalTargetName;
targetName = Character.toLowerCase(targetName.charAt(0)) + targetName.substring(1);
val IType type = if (this instanceof IALTransformation<?, ?>) {
(this as IALTransformation<?, ?>).getIALHolder().getIALCodeElement() as IType
} else {
codeElement;
};
val IField field = type.getField(targetName);
field.delete(true, null);
}
}
}
def void updateMarkerInterfaceReferenceMulti(LinkedList<EObject> targets) {
var ICompilationUnit cu = codeElement.compilationUnit;
......@@ -186,9 +226,9 @@ abstract class AnnotatedMemberReferenceTransformation<OWNERECLASS extends EObjec
if (fields.isEmpty)
resolveCodeElement();
if(fields.isEmpty()){
return targetTypes;
}
if (fields.isEmpty()) {
return targetTypes;
}
if (targetIsMarkerInterface) {
val Object annotationValues = ASTUtils.getAnnotationMemberValue(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment