當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。