/** * Returns the class declaring the field. */ public CtClass getDeclaringClass() { // this is redundant but for javadoc. return super.getDeclaringClass(); }
/** * Returns the class declaring the field. */ @Override public CtClass getDeclaringClass() { // this is redundant but for javadoc. return super.getDeclaringClass(); }
/** * Returns the class declaring the field. */ public CtClass getDeclaringClass() { // this is redundant but for javadoc. return super.getDeclaringClass(); }
/** * Returns the class declaring the field. */ public CtClass getDeclaringClass() { // this is redundant but for javadoc. return super.getDeclaringClass(); }
/** * Returns the class declaring the field. */ public CtClass getDeclaringClass() { // this is redundant but for javadoc. return super.getDeclaringClass(); }
/** * Returns the class declaring the field. */ public CtClass getDeclaringClass() { // this is redundant but for javadoc. return super.getDeclaringClass(); }
/** * Returns the class declaring the field. */ public CtClass getDeclaringClass() { // this is redundant but for javadoc. return super.getDeclaringClass(); }
static String unableToAddCatch(Class exceptionClass, CtMethod method, Throwable cause) { return _formatter.format("unable-to-add-catch", exceptionClass.getName(), method .getDeclaringClass().getName(), cause); }
private Map buildNameMap(CtMember[] members, String className) throws NotFoundException { Map namesMap = new Hashtable(); for (int i = 0; i < members.length; i++) { if (!isAPIMember(members[i])) { // System.out.println("ignore " + members[i].getName()); continue; } String name = getName4Map(members[i]); if (namesMap.containsKey(name)) { CtMember exists = (CtMember) namesMap.get(name); if (exists.getDeclaringClass().getName().equals(className)) { continue; } // throw new Error("duplicate member name " + name + " " + // members[i].getName()+ " = " + // ((Member)namesMap.get(name)).getName()); } namesMap.put(name, members[i]); } return namesMap; }
public void extend(String body, boolean asFinally) { try { _method.insertAfter(body, asFinally); } catch (Exception ex) { throw new ApplicationRuntimeException(ServiceMessages.unableToExtendMethod( _signature, _method.getDeclaringClass().getName(), ex), ex); } _descriptionBody.append("\n"); if (asFinally) _descriptionBody.append("finally\n"); _descriptionBody.append(body); }
/** * Unwraps the joinpoint. * @param member the member associated with the joinpoint. * @param transformationIndex index of the transformation text which, along with * <code>member</code>, identifies the joinpoint to be unwrapped. */ public void unwrap(CtMember member, int transformationIndex) { byte wrapperStatus = getWrapperStatusAttribute(member, transformationIndex); if (wrapperStatus != WRAPPED) { String errorMessage = "Member not wrapped: " + member.getName() + "." + member.getDeclaringClass().getName(); errorMessage += "\nMember status: "; errorMessage += (wrapperStatus == NOT_PREPARED)? "NOT_PREPARED" : "UNWRAPPED"; throw new RuntimeException(errorMessage); } setWrapperStatusAttribute(member, transformationIndex, UNWRAPPED); }
/** * Wraps the joinpoint. * @param member the member associated with the joinpoint. * @param transformationIndex index of the transformation text which, along with * <code>member</code>, identifies the joinpoint to be wrapped. */ public void wrap(CtMember member, int transformationIndex) { byte wrapperStatus = getWrapperStatusAttribute(member, transformationIndex); if (wrapperStatus != UNWRAPPED) { String errorMessage = "Member not unwrapped: " + member.getName() + "." + member.getDeclaringClass().getName(); errorMessage += "\nMember status: "; errorMessage += (wrapperStatus == NOT_PREPARED)? "NOT_PREPARED" : "WRAPPED"; throw new RuntimeException(errorMessage); } setWrapperStatusAttribute(member, transformationIndex, WRAPPED); }
public static Visibility effectiveVisibility(CtMember ctMember) { return leastVisible( effectiveVisibility(ctMember.getDeclaringClass()), fromModifiers(ctMember.getModifiers())); }
private static void fixMember(CtMember member, boolean useReflection) { //Make member public if (useReflection) { member.setModifiers(Modifier.setPublic(member.getModifiers())); AnnotationUtil.annotateReflectionAccessor(member, null, null, null); } //Create a RW alias for final fields if (member instanceof CtField && Modifier.isFinal(member.getModifiers())) { try { CtField rwField = new CtField((CtField) member, member.getDeclaringClass()); rwField.setName(member.getName() + "_rw"); rwField.setModifiers(Modifier.setPublic(rwField.getModifiers()) & ~Modifier.FINAL); AnnotationUtil.annotateReflectionAccessor(rwField, member.getName(), null, null); member.getDeclaringClass().addField(rwField); } catch (CannotCompileException e) { System.err.println("Cannot add field '" + member.getName() + "_rw' to " + member.getDeclaringClass().getName()); } } }
private static ReferencedMember getAliasFor(References references, ReflectionAccessor annotation, CtMember ctMember) throws NotFoundException, ClassNotFoundException, CannotCompileException { CtClass containerType = ctMember.getDeclaringClass(); ReflectionAccessor containerAnnotation = (ReflectionAccessor)containerType.getAnnotation(ReflectionAccessor.class); if (containerAnnotation != null && !containerAnnotation.alias_for().isEmpty()) {
public static void annotateVisibility(Object target, Visibility originalVisibility, Visibility effectiveVisibility) { CtClass cls = target instanceof CtClass ? (CtClass) target : ((CtMember) target).getDeclaringClass(); ClassFile clsFile = cls.getClassFile(); ConstPool constPool = clsFile.getConstPool(); Annotation annotation = new Annotation(OriginalVisibility.class.getName(), constPool); EnumMemberValue enumMemberValue = new EnumMemberValue(constPool); enumMemberValue.setType(Visibility.class.getName()); enumMemberValue.setValue(originalVisibility.name()); annotation.addMemberValue("value", enumMemberValue); enumMemberValue = new EnumMemberValue(constPool); enumMemberValue.setType(Visibility.class.getName()); enumMemberValue.setValue(effectiveVisibility.name()); annotation.addMemberValue("effective", enumMemberValue); annotate(target, annotation); } }
public static void annotateReflectionAccessor(Object target, String alias_for, ReflectionAccessor.Type type, CtClass[] argTypes) { CtClass cls = target instanceof CtClass ? (CtClass) target : ((CtMember) target).getDeclaringClass(); ClassFile clsFile = cls.getClassFile(); ConstPool constPool = clsFile.getConstPool(); Annotation annotation = new Annotation(ReflectionAccessor.class.getName(), constPool); if (alias_for != null) { annotation.addMemberValue("alias_for", new StringMemberValue(alias_for, constPool)); } if (type != null) { EnumMemberValue enumMemberValue = new EnumMemberValue(constPool); enumMemberValue.setType(ReflectionAccessor.Type.class.getName()); enumMemberValue.setValue(type.name()); annotation.addMemberValue("type", enumMemberValue); } if (argTypes != null) { ClassMemberValue[] classes = new ClassMemberValue[argTypes.length]; for (int i=0; i<classes.length; i++) { classes[i] = new ClassMemberValue(argTypes[i].getName(), constPool); } ArrayMemberValue typesMemberValue = new ArrayMemberValue(new ClassMemberValue(constPool), constPool); typesMemberValue.setValue(classes); annotation.addMemberValue("argTypes", typesMemberValue); } annotate(target, annotation); }