Árvore de páginas

Versões comparadas

Chave

  • Esta linha foi adicionada.
  • Esta linha foi removida.
  • A formatação mudou.
Composition Setup
import.css=/download/attachments/6062824/tecnologia.css

Pagetitle
Reflection.getClassesByAnnotationgetMethodsByAnnotation
Reflection.getClassesByAnnotationgetMethodsByAnnotation

Efetua a busca da Annotation dentro de um objeto retornando uma lista contendo o(s) nome(s)  do(s)  método(s) onde a mesma foi encontrada.Retorna um array com o nome de todos os métodos que possuem a annotation passada como argumento

Sintaxe

Bloco de código
collapsefalse
Reflection.getMethodsByAnnotation( oObjxParam,cAnnotationName )

Parâmetros

Nome

Tipo

Descrição

Obrigatório

Referência

oObjxParam**

objeto/caractere**

Objeto instância da classe/nome da classe** na qual a busca será realizada

X


cAnnotationName 
caractereNome da annotation Annotation a ser procuradaX           X
Informações
titleImplementação de comportamento

A partir do build 24.3.0.0, também haverá a opção de passar simplesmente o nome da classe em xParam, conforme exemplo 2. Mas continua valendo a passagem da instância do objeto (exemplo 1). 

Retorno

Nome

Tipo

Descrição

aRet

Array

Retorna um array com o nome de todos Array contendo os métodos da classe que possuem esta annotationa Annotation solicitada. Caso não encontre a array retorna vazia.

...

Exemplo

Bloco de código
languagecpp
themeEclipse
titleexemplo1.tlpp
linenumberstrue
#INCLUDE#include "MsObjecttlpp-core.CHth"

NAMESPACE TesteReflection
MAIN FUNCTION Teste()
  ClasseTeste():New()
RETURN

@annotation AnnotationMethodAnnotationGetMethodsByAnnotation
    property1 as char
@end

@annotationClass AnnotationClassGetMethodsByAnnotation

	Public    Method New()

	@AnnotationGetMethodsByAnnotation(property1 as char
@end

@AnnotationClass("testeClass")
class ClasseUm

	public method New= "Method Annotation")
	Public Method MethodWithAnnotation()

	@AnnotationMethod@AnnotationGetMethodsByAnnotation("testeMethodproperty1 = "Method Annotation")
	publicPublic methodMethod testeMethodAnotherMethodWithAnnotation()

endclassEndClass

METHODMethod NEWNew() CLASSclass ClasseUmGetMethodsByAnnotation
returnReturn selfSelf

methodMethod testeMethodMethodWithAnnotation() CLASSclass ClasseUm
	conout("Teste de metodo")
return

CLASS ClasseTeste
  PUBLIC METHOD NEW()
ENDCLASS


METHOD NEW() CLASS ClasseTeste
  
  local classesGetMethodsByAnnotation
Return

Method AnotherMethodWithAnnotation() class GetMethodsByAnnotation
Return

Function u_testGetMethodsByAnnotation()
	Local aRet := {}
 as local methodsarray
	Local oObj

	oObj := {}
  local instance
  
  // Pego todas as classes que possuem a annotation "AnnotationClass"
  classes := Reflection.getClassesByAnnotation("AnnotationClass", "TesteReflection.*")
  
  conout(classes[1])
  
  // Instancio um novo objeto desta classe
  instance :=  &(classes [1] + "():New()")
  
  // Pego todos os metodos dentro da classe que possuem a annotation "AnnotationMethod"
  methodsGetMethodsByAnnotation():New()
	aRet := Reflection.getMethodsByAnnotation(oObj, "AnnotationGetMethodsByAnnotation")
	if(valType(aRet) == "A" .and. len(aRet) > 0)
		aEval(aRet,{|x| Conout(x)} )
	else
		Conout('Nao foi encontrada Annotation com os parametros solicitados')
	endIf
Return

Bloco de código
languagecpp
themeEclipse
titleexemplo2.tlpp
linenumberstrue
#include "tlpp-core.th"


@annotation AnnotationGetMethodsByAnnotation
property1 as char
@end

Class GetMethodsByAnnotation

	Public Method New()

	@AnnotationGetMethodsByAnnotation(property1 = "Method Annotation")
	Public Method MethodWithAnnotation()

	@AnnotationGetMethodsByAnnotation(property1 = "Method Annotation")
	Public Method AnotherMethodWithAnnotation()
EndClass

Method New() class GetMethodsByAnnotation
Return Self

Method MethodWithAnnotation() class GetMethodsByAnnotation
Return

Method AnotherMethodWithAnnotation() class GetMethodsByAnnotation
Return

Function u_testGetMethodsByAnnotation()
	Local aRet := {} as array
	
	aRet := Reflection.getMethodsByAnnotation(instance"GetMethodsByAnnotation", "AnnotationMethodAnnotationGetMethodsByAnnotation")
	if(valType(aRet) == 
  conout(methods[1])
  
  // Executo o metodo encontrado
  &("instance:" + methods[1] + "()")
  
RETURN self

Resultado do Exemplo

"A" .and. len(aRet) > 0)
		aEval(aRet,{|x| Conout(x)} )
	else
		Conout('Nao foi encontrada Annotation com os parametros solicitados')
	endIf
Return

Resultado dos Exemplos

ANOTHERMETHODWITHANNOTATION
METHODWITHANNOTATIONTESTEREFLECTION.CLASSEUM
TESTEMETHOD
Teste de metodo

Abrangência

17.3.0.3

Veja também

...