Java 8 ExecutableElement - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ExecutableElement class.

This code example shows how to use the following methods:getParameters, getReturnType, getSimpleName
	public Set<ConstraintCheckError> checkMethod(ExecutableElement element,
												 AnnotationMirror annotation) {
 
		if ( !methodConstraintsSupported && !isGetterMethod( element ) ) {
			return CollectionHelper.asSet( 
					new ConstraintCheckError( 
							element, annotation, "ONLY_GETTERS_MAY_BE_ANNOTATED"
					) 
			); 
		} 
		else if (!hasReturnValue(element)) {
			return CollectionHelper.asSet( 
					new ConstraintCheckError( 
							element, annotation, "ONLY_NON_VOID_METHODS_MAY_BE_ANNOTATED"
					) 
			); 
		} 
 
		return Collections.emptySet();
	} 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getParameters
	public ValidatorParameterHelper(TargetAnnotationHelper targetAnnotationHelper) {
		annotationHelper = targetAnnotationHelper;
	} 
 
	public void zeroOrOneParameter(ExecutableElement executableElement, IsValid valid) {
		List<? extends VariableElement> parameters = executableElement.getParameters();
 
		if (parameters.size() > 1) {
			valid.invalidate();
			annotationHelper.printAnnotationError(executableElement, "%s can only be used on a method with zero or one parameter, instead of " + parameters.size());
		} 
	} 
 
	public void zeroParameter(ExecutableElement executableElement, IsValid valid) {
		List<? extends VariableElement> parameters = executableElement.getParameters();
 
		if (parameters.size() > 0) {
			valid.invalidate();
			annotationHelper.printAnnotationError(executableElement, "%s can only be used on a method with zero parameter, instead of " + parameters.size());
		} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getParameters, getReturnType
	@Override 
	public void process(Element element, HasOptionsMenu holder) {
		String methodName = element.getSimpleName().toString();
 
		ExecutableElement executableElement = (ExecutableElement) element;
		List<? extends VariableElement> parameters = executableElement.getParameters();
		TypeMirror returnType = executableElement.getReturnType();
		boolean returnMethodResult = returnType.getKind() != TypeKind.VOID;
 
		boolean hasItemParameter = parameters.size() == 1;
 
		List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(processHolder, element, IRClass.Res.ID, true);
		JExpression ifExpr = holder.getOnOptionsItemSelectedItemId().eq(idsRefs.get(0));
		for (int i = 1; i < idsRefs.size(); i++) {
			ifExpr = ifExpr.cor(holder.getOnOptionsItemSelectedItemId().eq(idsRefs.get(i)));
		} 
 
		JBlock itemIfBody = holder.getOnOptionsItemSelectedIfElseBlock()._if(ifExpr)._then();
		JInvocation methodCall = invoke(methodName);
 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getEnclosingElement, getModifiers
   * Returns true if generated code can invoke {@code constructor}. That is, if 
   * the constructor is non-private and its enclosing class is either a 
   * top-level class or a static nested class. 
   */ 
  public static boolean isCallableConstructor(ExecutableElement constructor) {
    if (constructor.getModifiers().contains(Modifier.PRIVATE)) {
      return false; 
    } 
    TypeElement type = (TypeElement) constructor.getEnclosingElement();
    return type.getEnclosingElement().getKind() == ElementKind.PACKAGE
        || type.getModifiers().contains(Modifier.STATIC);
  } 
 
 
  /** 
   * Returns a user-presentable string like {@code coffee.CoffeeModule}. 
   */ 
  public static String className(ExecutableElement method) {
    return ((TypeElement) method.getEnclosingElement()).getQualifiedName().toString();
  } 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getSimpleName
 
/** 
 * Common utility methods for this package. 
 * @since 0.2.0 
 */ 
final class Util { 
 
    static boolean isConcrete(OperatorCompilingEnvironment environment, TypeMirror type) {
        assert environment != null;
        assert type != null;
        if (type.getKind() != TypeKind.DECLARED) {
            return false; 
        } 
        if (isKindMatched(environment, type) == false) {
            return false; 
        } 
        TypeMirror datamodel = environment.getDeclaredType(DataModel.class);
        return environment.getTypeUtils().isSubtype(type, datamodel);
    } 
 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getReturnType, getSimpleName
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getDefaultValue, getReturnType
  /** 
   * Returns a string representation of the default value of the given annotation member, suitable 
   * for inclusion in a Java source file as the initializer of a variable of the appropriate type. 
   */ 
  String sourceForm(ExecutableElement memberMethod) {
    AnnotationValue defaultValue = memberMethod.getDefaultValue();
    TypeMirror type = memberMethod.getReturnType();
    StringBuilder sb = new StringBuilder();
    SourceFormVisitor visitor = new SourceFormVisitor(sb, memberMethod);
    visitor.visit(defaultValue);
    return sb.toString();
  } 
 
  private static StringBuilder appendQuoted(StringBuilder sb, String s) {
    sb.append('"');
    for (int i = 0; i < s.length(); i++) {
      appendEscaped(sb, s.charAt(i));
    } 
    return sb.append('"');
  } 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getEnclosingElement
    public void add( 
            AnnotationMirror annotation,
            ExecutableElement methodElement,
            OperatorProcessor processor) {
        Precondition.checkMustNotBeNull(annotation, "annotation"); //$NON-NLS-1$
        Precondition.checkMustNotBeNull(methodElement, "methodElement"); //$NON-NLS-1$
        Precondition.checkMustNotBeNull(processor, "processor"); //$NON-NLS-1$
        if (element.equals(methodElement.getEnclosingElement()) == false) {
            throw new IllegalArgumentException("methodElement must be a member of this class"); //$NON-NLS-1$
        } 
        OperatorMethod method = new OperatorMethod(annotation, methodElement, processor);
        methods.add(method);
    } 
 
    /** 
     * この演算子クラスに指定の演算子メソッドの情報を追加する。 
     * @param methodElement 演算子メソッドのメソッド宣言 
     * @param processor 対応する演算子プロセッサ 
     * @throws IllegalArgumentException 引数に{@code null}が含まれる場合 
     */ 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getSimpleName
 
    @Override 
    public T visitExecutable(ExecutableElement executableElement, Void aVoid) {
        //constructors and methods share this Element, the indication that the method is a constructor 
        //is that it is named <init> 
        if (executableElement.getSimpleName().contentEquals(STATIC_INITIALIZER_IDENTIFIER)){
            return null; // ignoring static initializer block 
        } 
        if (executableElement.getSimpleName().contentEquals(CONSTRUCTOR_IDENTIFIER)) {
            if (astTypeClass.isAssignableFrom(ASTConstructor.class)) {
                return (T) astElementFactory.getConstructor(executableElement);
            } 
        } else if (astTypeClass.isAssignableFrom(ASTMethod.class)) {
            return (T) astElementFactory.getMethod(executableElement);
        } 
        return null; 
    } 
 
    @Override 
    public T visitTypeParameter(TypeParameterElement typeParameterElement, Void aVoid) {
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getParameters
		} 
	} 
 
	private static Map<VariableElement, Collection<TypeInfo>> getTypeInfoMap(TypeMap type_map, ExecutableElement method) {
		Map<VariableElement, Collection<TypeInfo>> map = new HashMap<VariableElement, Collection<TypeInfo>>();
		for ( VariableElement param : method.getParameters() ) {
			Collection<TypeInfo> types = getTypeInfos(type_map, param);
			map.put(param, types);
		} 
		return map;
	} 
 
	public static Collection<Map<VariableElement, TypeInfo>> getTypeInfoCrossProduct(TypeMap type_map, ExecutableElement method) {
		List<? extends VariableElement> parameter_collection = method.getParameters();
		Collection<Map<VariableElement, TypeInfo>> cross_product = new ArrayList<Map<VariableElement, TypeInfo>>();
		getCrossProductRecursive(0, parameter_collection, getTypeInfoMap(type_map, method),
			new HashMap<VariableElement, TypeInfo>(), cross_product);
		return cross_product;
	} 
 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 ExecutableElement Methods: