java.lang.Class.getCanonicalName()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(408)

本文整理了Java中java.lang.Class.getCanonicalName()方法的一些代码示例,展示了Class.getCanonicalName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Class.getCanonicalName()方法的具体详情如下:
包路径:java.lang.Class
类名称:Class
方法名:getCanonicalName

Class.getCanonicalName介绍

[英]Returns the canonical name of this class. If this class does not have a canonical name as defined in the Java Language Specification, then the method returns null.
[中]返回此类的规范名称。如果该类没有Java语言规范中定义的规范名称,则该方法返回null。

代码示例

代码示例来源:origin: apache/incubator-dubbo

public static boolean isExcludedInterface(Class<?> clazz) {
  if (includedInterfacePackages == null || includedInterfacePackages.length == 0) {
    return false;
  }
  for (String packagePrefix : includedInterfacePackages) {
    if (clazz.getCanonicalName().startsWith(packagePrefix)) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: apache/incubator-dubbo

public static boolean isExcludedInterface(Class<?> clazz) {
  if (includedInterfacePackages == null || includedInterfacePackages.length == 0) {
    return false;
  }
  for (String packagePrefix : includedInterfacePackages) {
    if (clazz.getCanonicalName().startsWith(packagePrefix)) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: apache/incubator-dubbo

public static boolean isExcludedType(Class<?> clazz) {
  if (includedTypePackages == null || includedTypePackages.length == 0) {
    return false;
  }
  for (String packagePrefix : includedTypePackages) {
    if (clazz.getCanonicalName().startsWith(packagePrefix)) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: apache/incubator-dubbo

public static boolean isExcludedType(Class<?> clazz) {
  if (includedTypePackages == null || includedTypePackages.length == 0) {
    return false;
  }
  for (String packagePrefix : includedTypePackages) {
    if (clazz.getCanonicalName().startsWith(packagePrefix)) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: JakeWharton/butterknife

private static @Nullable AnnotationMirror getMirror(Element element,
  Class<? extends Annotation> annotation) {
 for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
  if (annotationMirror.getAnnotationType().toString().equals(annotation.getCanonicalName())) {
   return annotationMirror;
  }
 }
 return null;
}

代码示例来源:origin: apache/incubator-dubbo

public static boolean needAnalyzing(Class<?> clazz) {
  String canonicalName = clazz.getCanonicalName();
  if (closedTypes != null && closedTypes.length > 0) {
    for (String type : closedTypes) {
      if (canonicalName.startsWith(type)) {
        return false;
      }
    }
  }
  return !isExcludedType(clazz);
}

代码示例来源:origin: apache/incubator-dubbo

public static boolean needAnalyzing(Class<?> clazz) {
  String canonicalName = clazz.getCanonicalName();
  if (closedTypes != null && closedTypes.length > 0) {
    for (String type : closedTypes) {
      if (canonicalName.startsWith(type)) {
        return false;
      }
    }
  }
  return !isExcludedType(clazz);
}

代码示例来源:origin: JakeWharton/butterknife

@Override public Set<String> getSupportedAnnotationTypes() {
 Set<String> types = new LinkedHashSet<>();
 for (Class<? extends Annotation> annotation : getSupportedAnnotations()) {
  types.add(annotation.getCanonicalName());
 }
 return types;
}

代码示例来源:origin: androidannotations/androidannotations

public static void assertClassSourcesGeneratedToOutput(Class<?> clazz) {
  String canonicalName = clazz.getCanonicalName();
  String filePath = canonicalName.replace(".", "/").concat(".java");
  File generatedSourcesDir = new File(OUTPUT_DIRECTORY);
  File generatedSourceFile = new File(generatedSourcesDir, filePath);
  File sourcesDir = new File(MAIN_SOURCE_FOLDER);
  File expectedResult = new File(sourcesDir, filePath);
  assertOutput(expectedResult, generatedSourceFile);
}

代码示例来源:origin: androidannotations/androidannotations

public static void assertClassSourcesNotGeneratedToOutput(Class<?> clazz) {
  String canonicalName = clazz.getCanonicalName();
  String filePath = canonicalName.replace(".", "/").concat(".java");
  File generatedSourcesDir = new File(OUTPUT_DIRECTORY);
  File output = new File(generatedSourcesDir, filePath);
  assertFalse(output.exists());
}

代码示例来源:origin: androidannotations/androidannotations

public AbstractJClass refClass(Class<?> clazz) {
  AbstractJClass referencedClass = codeModel.ref(clazz);
  loadedClasses.put(clazz.getCanonicalName(), referencedClass);
  return referencedClass;
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public TypeDefinition build(Type type, Class<?> clazz, Map<Class<?>, TypeDefinition> typeCache) {
  // Process the component type of an array.
  Class<?> componentType = clazz.getComponentType();
  TypeDefinitionBuilder.build(componentType, componentType, typeCache);
  final String canonicalName = clazz.getCanonicalName();
  return new TypeDefinition(canonicalName);
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public TypeDefinition build(Type type, Class<?> clazz, Map<Class<?>, TypeDefinition> typeCache) {
  // Process the component type of an array.
  Class<?> componentType = clazz.getComponentType();
  TypeDefinitionBuilder.build(componentType, componentType, typeCache);
  final String canonicalName = clazz.getCanonicalName();
  return new TypeDefinition(canonicalName);
}

代码示例来源:origin: iluwatar/java-design-patterns

@Override
 public String toString() {
  return getDeclaringClass().getCanonicalName() + "@" + hashCode();
 }
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public TypeDefinition build(Type type, Class<?> clazz, Map<Class<?>, TypeDefinition> typeCache) {
  TypeDefinition td = new TypeDefinition(clazz.getCanonicalName());
  try {
    Method methodValues = clazz.getDeclaredMethod("values", new Class<?>[0]);
    Object[] values = (Object[]) methodValues.invoke(clazz, new Object[0]);
    int length = values.length;
    for (int i = 0; i < length; i++) {
      Object value = values[i];
      td.getEnums().add(value.toString());
    }
  } catch (Throwable t) {
    td.setId("-1");
  }
  typeCache.put(clazz, td);
  return td;
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public TypeDefinition build(Type type, Class<?> clazz, Map<Class<?>, TypeDefinition> typeCache) {
  TypeDefinition td = new TypeDefinition(clazz.getCanonicalName());
  try {
    Method methodValues = clazz.getDeclaredMethod("values", new Class<?>[0]);
    Object[] values = (Object[]) methodValues.invoke(clazz, new Object[0]);
    int length = values.length;
    for (int i = 0; i < length; i++) {
      Object value = values[i];
      td.getEnums().add(value.toString());
    }
  } catch (Throwable t) {
    td.setId("-1");
  }
  typeCache.put(clazz, td);
  return td;
}

代码示例来源:origin: org.mockito/mockito-core

public <T> T mock(Class<T> typeToMock, MockSettings settings) {
  if (!MockSettingsImpl.class.isInstance(settings)) {
    throw new IllegalArgumentException("Unexpected implementation of '" + settings.getClass().getCanonicalName() + "'\n" + "At the moment, you cannot provide your own implementations of that class.");
  }
  MockSettingsImpl impl = MockSettingsImpl.class.cast(settings);
  MockCreationSettings<T> creationSettings = impl.build(typeToMock);
  T mock = createMock(creationSettings);
  mockingProgress().mockingStarted(mock, creationSettings);
  return mock;
}

代码示例来源:origin: ch.qos.logback/logback-classic

@Override
public void contextDestroyed(ServletContextEvent sce) {
  ILoggerFactory iLoggerFactory = LoggerFactory.getILoggerFactory();
  if (iLoggerFactory instanceof LoggerContext) {
    LoggerContext loggerContext = (LoggerContext) iLoggerFactory;
    contextAwareBase.setContext(loggerContext);
    StatusViaSLF4JLoggerFactory.addInfo("About to stop " + loggerContext.getClass().getCanonicalName() + " [" + loggerContext.getName() + "]", this);
    loggerContext.stop();
  }
}

代码示例来源:origin: org.mockito/mockito-core

public static MockitoException cannotInjectDependency(Field field, Object matchingMock, Exception details) {
  return new MockitoException(join(
      "Mockito couldn't inject mock dependency '" + MockUtil.getMockName(matchingMock) + "' on field ",
      "'" + field + "'",
      "whose type '" + field.getDeclaringClass().getCanonicalName() + "' was annotated by @InjectMocks in your test.",
      "Also I failed because: " + exceptionCauseMessageIfAvailable(details),
      ""
  ), details);
}

代码示例来源:origin: org.mockito/mockito-core

private GenericMetadataSupport resolveGenericType(Type type, Method method) {
  if (type instanceof Class) {
    return new NotGenericReturnTypeSupport(this, type);
  }
  if (type instanceof ParameterizedType) {
    return new ParameterizedReturnType(this, method.getTypeParameters(), (ParameterizedType) type);
  }
  if (type instanceof TypeVariable) {
    return new TypeVariableReturnType(this, method.getTypeParameters(), (TypeVariable<?>) type);
  }
  throw new MockitoException("Ouch, it shouldn't happen, type '" + type.getClass().getCanonicalName() + "' on method : '" + method.toGenericString() + "' is not supported : " + type);
}

相关文章

Class类方法