当前位置: 首页>>代码示例>>Java>>正文


Java Method.isDefault方法代码示例

本文整理汇总了Java中java.lang.reflect.Method.isDefault方法的典型用法代码示例。如果您正苦于以下问题:Java Method.isDefault方法的具体用法?Java Method.isDefault怎么用?Java Method.isDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.reflect.Method的用法示例。


在下文中一共展示了Method.isDefault方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleDefault

import java.lang.reflect.Method; //导入方法依赖的package包/类
private Object handleDefault(Object proxy, Method method, Object[] args) throws Throwable {
	// support default messages in interfaces
	if (method.isDefault()) {
		final Class<?> declaringClass = method.getDeclaringClass();
		final MethodHandles.Lookup lookup = MethodHandles.publicLookup().in(declaringClass);
		// ensure allowed mode will not check visibility
		final Field f = MethodHandles.Lookup.class.getDeclaredField("allowedModes");
		final int modifiers = f.getModifiers();
		if (Modifier.isFinal(modifiers)) { // should be done a single time
			final Field modifiersField = Field.class.getDeclaredField("modifiers");
			modifiersField.setAccessible(true);
			modifiersField.setInt(f, modifiers & ~Modifier.FINAL);
			f.setAccessible(true);
			f.set(lookup, MethodHandles.Lookup.PRIVATE);
		}
		return lookup.unreflectSpecial(method, declaringClass).bindTo(proxy).invokeWithArguments(args);
	}
	return null;
}
 
开发者ID:tudrobotics,项目名称:urdriver,代码行数:20,代码来源:URScriptInvocationHandler.java

示例2: handleDefaultMessage

import java.lang.reflect.Method; //导入方法依赖的package包/类
private Object handleDefaultMessage(Object proxy, Method method, Object[] args) throws Throwable {
	// support default messages in interfaces
	if (method.isDefault()) {
		final Class<?> declaringClass = method.getDeclaringClass();
		final MethodHandles.Lookup lookup = MethodHandles.publicLookup().in(declaringClass);

		// ensure allowed mode will not check visibility
		final Field f = MethodHandles.Lookup.class.getDeclaredField("allowedModes");
		final int modifiers = f.getModifiers();
		if (Modifier.isFinal(modifiers)) { // should be done a single time
			final Field modifiersField = Field.class.getDeclaredField("modifiers");
			modifiersField.setAccessible(true);
			modifiersField.setInt(f, modifiers & ~Modifier.FINAL);
			f.setAccessible(true);
			f.set(lookup, MethodHandles.Lookup.PRIVATE);
		}
		return lookup.unreflectSpecial(method, declaringClass).bindTo(proxy).invokeWithArguments(args);
	}
	return null;
}
 
开发者ID:tudrobotics,项目名称:urdriver,代码行数:21,代码来源:URDashboardInvocationHandler.java

示例3: intercept

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
    // Give our delegate a chance to intercept, and cache the decision
    if(delegatedMethods.get(method, () -> method.getDeclaringClass() != Object.class &&
                                          Methods.hasOverrideIn(Delegate.class, method))) {
        return method.invoke(delegate, args);
    }

    // If we have a value for the property, return that
    final Object value = values.get(method);
    if(value != null) return value;

    // If there's no value, then the method MUST be callable (or the code is broken).
    // This can only fail for an abstract non-property method (which we should probably be checking for).
    if(method.isDefault()) {
        // invokeSuper doesn't understand default methods
        return defaultMethodHandles.get(method)
                                   .bindTo(obj)
                                   .invokeWithArguments(args);
    } else {
        return proxy.invokeSuper(obj, args);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:24,代码来源:ReflectiveParserManifest.java

示例4: removeLessSpecifics

import java.lang.reflect.Method; //导入方法依赖的package包/类
void removeLessSpecifics() {
    if (!hasDefaults())
        return;

    for (int i = 0; i < length; i++) {
        Method m = get(i);
        if  (m == null || !m.isDefault())
            continue;

        for (int j  = 0; j < length; j++) {
            if (i == j)
                continue;

            Method candidate = get(j);
            if (candidate == null)
                continue;

            if (!matchesNameAndDescriptor(m, candidate))
                continue;

            if (hasMoreSpecificClass(m, candidate))
                remove(j);
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:Class.java

示例5: invoke

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static Object invoke( Map thiz, String name, Class returnType, Class[] paramTypes, Object[] args )
{
  Object value = thiz.get( name );
  if( value == null )
  {
    return ICallHandler.UNHANDLED;
  }
  try
  {
    for( Method m : value.getClass().getMethods() )
    {
      if( !m.isDefault() && !Modifier.isStatic( m.getModifiers() ) )
      {
        m.setAccessible( true );
        return m.invoke( value, args );
      }
    }
    return ICallHandler.UNHANDLED;
  }
  catch( Exception e )
  {
    throw new RuntimeException( e );
  }
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:25,代码来源:MapStructExt.java

示例6: invoke

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Override
public synchronized Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	if (method.isDefault()) {
		return handleDefaultMessage(proxy, method, args);
	}

	String command = buildURCommand(method);
	// replace the generic placeholder
	command = fillURCommand(command, args);

	String expectedReturn = null;

	// check if @ExpectedReturn is present
	if (method.isAnnotationPresent(ExpectedReturn.class)) {
		ExpectedReturn annotInstance = method.getAnnotation(ExpectedReturn.class);
		expectedReturn = annotInstance.value();
		for (int i = 0; i < annotInstance.parameters().length; i++) {
			expectedReturn += " " + args[i];
		}
	}

	LOG.log(Level.FINE, "call " + proxy.getClass().getInterfaces()[0].getSimpleName() + "." + command);
	//System.out.println(command);
	String string = client.call(command + newline);
	if ((method.getReturnType().equals(Boolean.class) || method.getReturnType().equals(Boolean.TYPE))) {
		if (expectedReturn != null) {
			if (string != null) {
				//System.out.println(string);
				return string.equalsIgnoreCase(expectedReturn);
			} else {
				return false;
			}
		} else {
			return true;
		}
	}
	return string;
}
 
开发者ID:tudrobotics,项目名称:urdriver,代码行数:39,代码来源:URDashboardInvocationHandler.java

示例7: trySamMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
public static @Nullable Method trySamMethod(Class<?> iface) {
    if(!iface.isInterface()) return null;

    final Method[] methods = iface.getMethods();
    if(methods.length == 1) {
        return methods[0];
    }

    Method sam = null;
    boolean first = true;
    for(Method method : methods) {
        if(Members.isStatic(method)) continue;

        if(first) {
            // If we've only seen one method, assume it's the SAM
            first = false;
            sam = method;
        } else {
            // If there are multiple methods, and we initially assumed that a default method was the
            // SAM, reverse that assumption.
            if(sam != null && sam.isDefault()) {
                sam = null;
            }

            // If we find an abstract method, and we already have a SAM (which must also be abstract),
            // then the interface is non-functional. Otherwise, assume this method is the SAM and keep
            // going (to make sure there are no more abstract methods).
            if(!method.isDefault()) {
                if(sam != null) {
                    return null;
                }
                sam = method;
            }
        }
    }

    return sam;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:39,代码来源:Methods.java

示例8: add

import java.lang.reflect.Method; //导入方法依赖的package包/类
void add(Method m) {
    if (length == methods.length) {
        methods = Arrays.copyOf(methods, 2 * methods.length);
    }
    methods[length++] = m;

    if (m != null && m.isDefault())
        defaults++;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:Class.java

示例9: requiresDefaultBodyFor

import java.lang.reflect.Method; //导入方法依赖的package包/类
static boolean requiresDefaultBodyFor(Method m) {
    try {
        Method m2 = LoggerBridgeMethodsWithNoBody.class
                .getDeclaredMethod(m.getName(),
                m.getParameterTypes());
        return !m2.isDefault();
    } catch (NoSuchMethodException x) {
        return true;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:LoggerFinderAPITest.java

示例10: genInterfaceMethodDecl

import java.lang.reflect.Method; //导入方法依赖的package包/类
private void genInterfaceMethodDecl( StringBuilder sb, Method mi, Class rootType )
{
  if( (mi.isDefault() && !implementsMethod( rootType, mi )) || Modifier.isStatic( mi.getModifiers() ) )
  {
    return;
  }
  if( mi.getAnnotation( ExtensionMethod.class ) != null )
  {
    return;
  }
  if( isObjectMethod( mi ) )
  {
    return;
  }

  Class returnType = mi.getReturnType();
  sb.append( "  public " )./*append( getTypeVarList( mi ) ).append( ' ' ).*/append( returnType.getCanonicalName() ).append( ' ' ).append( mi.getName() ).append( "(" );
  Class[] params = mi.getParameterTypes();
  for( int i = 0; i < params.length; i++ )
  {
    Class pi = params[i];
    sb.append( ' ' ).append( pi.getCanonicalName() ).append( " p" ).append( i );
    sb.append( i < params.length - 1 ? ',' : ' ' );
  }
  sb.append( ") {\n" )
    .append( returnType == void.class
             ? "    "
             : "    return " )
    .append( maybeCastReturnType( mi, returnType, rootType ) );
  if( !handleField( sb, mi ) )
  {
    handleMethod( sb, mi, params );
  }
  sb.append( "  }\n" );
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:36,代码来源:StructuralTypeProxyGenerator.java

示例11: isDefaultMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Override boolean isDefaultMethod(Method method) {
  return method.isDefault();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:4,代码来源:Platform.java

示例12: invoke

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * this method produce the call to UR
 */
/*
 * @Override public synchronized Object invoke(Object proxy, Method method,
 * Object[] args) throws Throwable { // support default messages in
 * interfaces if (method.isDefault()) { return handleDefault(proxy, method,
 * args); }
 * 
 * StringWriter call = new StringWriter(); call.append(method.getName());
 * call.append("("); if (args != null) { Annotation[][] parameterAnnotations
 * = method.getParameterAnnotations(); Annotation[] annotationOfParameter;
 * for (int i = 0; i < args.length; i++) { Validate.notNull(args[i],
 * args[i].getClass().getName()+" must be not NULL"); annotationOfParameter
 * = parameterAnnotations[i]; for (Annotation a : annotationOfParameter) {
 * //resolve the @Name annotation if (a instanceof Named) {
 * call.append(((Named) a).value()); } // resolve the @Min annotation if(a
 * instanceof Min) { try { Validate.isTrue(Long.valueOf(args[i].toString())
 * >= ((Min)a).value(), ((Min)a).message()); } catch (NumberFormatException
 * e){
 * 
 * } } // resolve the @Max annotation if(a instanceof Max) { try {
 * Validate.isTrue(Long.valueOf(args[i].toString()) <= ((Max)a).value(),
 * ((Max)a).message()); } catch (NumberFormatException e){
 * 
 * } } // resolve the @MinFloat annotation if(a instanceof MinFloat) { try {
 * Validate.isTrue(Double.valueOf(args[i].toString()) >=
 * ((MinFloat)a).value(), ((MinFloat)a).message()); } catch
 * (NumberFormatException e){
 * 
 * } } // resolve the @MaxFloat annotation if(a instanceof MaxFloat) { try {
 * Validate.isTrue(Double.valueOf(args[i].toString()) <=
 * ((MaxFloat)a).value(),((MaxFloat)a).message()); } catch
 * (NumberFormatException e){
 * 
 * } } } call.append(args[i].toString()); if (i + 1 < args.length) {
 * call.append(","); } } } call.append(")" + newline); LOG.log(Level.FINE,
 * "call " + proxy.getClass().getInterfaces()[0].getSimpleName() + "." +
 * call.toString()); System.out.println(call.toString()); // if the
 * returntype is null denn wie call the method if
 * (method.getReturnType().equals(Void.class) ||
 * method.getReturnType().equals(Void.TYPE)) {
 * client.write(call.toString()); } else { // TODO return requested value }
 * return null; }
 */

@Override
public synchronized Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	// support default messages in interfaces
	if (method.isDefault()) {
		return handleDefault(proxy, method, args);
	}
	// this throws an exception if Arguments are wrong
	validateArguments(method, args);

	String command = buildURCommand(method);
	// replace the generic placeholder
	command = fillURCommand(command, args);

	LOG.log(Level.FINE, "call " + proxy.getClass().getInterfaces()[0].getSimpleName() + "." + command);
	return callURCommand(method, command);
}
 
开发者ID:tudrobotics,项目名称:urdriver,代码行数:63,代码来源:URScriptInvocationHandler.java

示例13: genInterfaceMethodDecl

import java.lang.reflect.Method; //导入方法依赖的package包/类
private void genInterfaceMethodDecl( StringBuilder sb, Method mi, Class ifaceType )
{
  if( mi.isDefault() || Modifier.isStatic( mi.getModifiers() ) )
  {
    return;
  }
  if( mi.getAnnotation( ExtensionMethod.class ) != null )
  {
    return;
  }
  if( StructuralTypeProxyGenerator.isObjectMethod( mi ) )
  {
    return;
  }

  ActualName anno = mi.getAnnotation( ActualName.class );
  String actualName = anno == null ? "null" : "\""+anno.value()+"\"";
  Class returnType = mi.getReturnType();
  sb.append( "  public " )./*append( getTypeVarList( mi ) ).append( ' ' ).*/append( returnType.getCanonicalName() ).append( ' ' ).append( mi.getName() ).append( "(" );
  Class[] params = mi.getParameterTypes();
  for( int i = 0; i < params.length; i++ )
  {
    if( i > 0 )
    {
      sb.append( ", " );
    }
    Class pi = params[i];
    sb.append( pi.getCanonicalName() ).append( " p" ).append( i );
  }
  sb.append( ") {\n" )
    .append( returnType == void.class
             ? "    "
             : "    return " )
    .append( maybeCastReturnType( returnType ) )
    //## todo: maybe we need to explicitly parameterize if the method is generic for some cases?
    .append( "_root" ).append( ".call(" ).append( ifaceType.getCanonicalName() ).append( ".class, \"" ).append( mi.getName() ).append( "\", " ).append( actualName ).append( ", " ).append( mi.getReturnType().getCanonicalName() ).append( ".class, " ).append( "new Class[] {" );
  Class<?>[] parameterTypes = mi.getParameterTypes();
  for( int i = 0; i < parameterTypes.length; i++ )
  {
    if( i > 0 )
    {
      sb.append( ", " );
    }
    Class paramType = parameterTypes[i];
    sb.append( paramType.getCanonicalName() ).append( ".class" );
  }
  sb.append( "}, " );
  sb.append( "new Object[] {" );
  for( int i = 0; i < params.length; i++ )
  {
    if( i > 0 )
    {
      sb.append( ", " );
    }
    sb.append( " p" ).append( i );
  }
  sb.append( "});\n" );
  sb.append( "  }\n" );
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:60,代码来源:DynamicTypeProxyGenerator.java


注:本文中的java.lang.reflect.Method.isDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。