javax.lang.model.element.Element.equals()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(166)

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

Element.equals介绍

[英]Returns true if the argument represents the same element as this, or false otherwise.

Note that the identity of an element involves implicit state not directly accessible from the element's methods, including state about the presence of unrelated types. Element objects created by different implementations of these interfaces should not be expected to be equal even if "the same" element is being modeled; this is analogous to the inequality of Class objects for the same class file loaded through different class loaders.
[中]如果参数表示与此相同的元素,则返回true,否则返回false。
请注意,元素的标识涉及无法从元素的方法直接访问的隐式状态,包括不相关类型的存在状态。由这些接口的不同实现创建的元素对象不应该是相等的,即使“相同”元素正在建模;这类似于通过不同类加载器加载的同一类文件的类对象不平等。

代码示例

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

@Override
public boolean equals(Object obj) {
 return delegate.equals(obj);
}

代码示例来源:origin: uber/NullAway

@Override
public boolean equals(Object o) {
 if (this == o) {
  return true;
 }
 if (o == null || getClass() != o.getClass()) {
  return false;
 }
 Root root = (Root) o;
 if (isMethodReceiver != root.isMethodReceiver) {
  return false;
 }
 return varElement != null ? varElement.equals(root.varElement) : root.varElement == null;
}

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

@Override
public boolean equals(Object obj) {
  if (obj instanceof ProcessableElement) {
    ProcessableElement other = (ProcessableElement) obj;
    return element.equals(other.element());
  }
  return false;
}

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

@Override
public boolean process( Set<? extends TypeElement> annotations, RoundEnvironment roundEnv )
{
  for ( TypeElement type : annotations )
  {
    for ( Element annotated : roundEnv.getElementsAnnotatedWith( type ) )
    {
      for ( AnnotationMirror mirror : annotated.getAnnotationMirrors() )
      {
        if ( mirror.getAnnotationType().asElement().equals( type ) )
        {
          try
          {
            process( type, annotated, mirror, processingEnv.getElementUtils()
                .getElementValuesWithDefaults( mirror ) );
          }
          catch ( Exception e )
          {
            e.printStackTrace();
            processingEnv.getMessager().printMessage( Kind.ERROR, "Internal error: " + e,
                annotated, mirror );
          }
        }
      }
    }
  }
  return false;
}

代码示例来源:origin: google/error-prone

@Override
public boolean equals(Object o) {
 if (o == this) {
  return true;
 }
 if (o instanceof AccessPath) {
  AccessPath that = (AccessPath) o;
  return ((this.base == null) ? (that.base() == null) : this.base.equals(that.base()))
     && (this.path.equals(that.path()));
 }
 return false;
}

代码示例来源:origin: remkop/picocli

private static boolean isNested(Object innerUserObject, Object outerUserObject) {
  if (innerUserObject instanceof Method) {
    Class<?> cls = ((Method) innerUserObject).getDeclaringClass();
    if (cls.equals(outerUserObject) || cls.equals(outerUserObject.getClass())) {
      return true;
    }
  } else if (innerUserObject instanceof Element) { // ExecutableElement or TypeElement
    Element enclosingElement = ((Element) innerUserObject).getEnclosingElement();
    while (enclosingElement != null) {
      if (enclosingElement.equals(outerUserObject)) {
        return true;
      }
      enclosingElement = enclosingElement.getEnclosingElement();
    }
    return false;
  } else if (innerUserObject instanceof Class) {
    Class<?> cls = (Class<?>) innerUserObject;
    if (cls.isMemberClass() &&
        (cls.getEnclosingClass().equals(outerUserObject) || cls.getEnclosingClass().equals(outerUserObject.getClass()))) {
      return true;
    }
  } else {
    Class<?> cls = innerUserObject.getClass();
    if (cls.isMemberClass() &&
        (cls.getEnclosingClass().equals(outerUserObject) || cls.getEnclosingClass().equals(outerUserObject.getClass()))) {
      return true;
    }
  }
  return false;
}

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

public static boolean equals(Element left, Element right) {
 return getDelegate(left).equals(getDelegate(right));
}

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

.forEach(getter ->
    names.addAll(map.entrySet().stream()
        .filter(entry -> entry.getKey().equals(getter))
        .map(entry -> entry.getValue().fieldName())
        .collect(Collectors.toList())));

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

public void uniqueResourceId(Element element, Res resourceType, ElementValidation valid) {
  if (valid.isValid()) {
    List<String> annotationQualifiedIds = idAnnotationHelper.extractAnnotationResources(element, resourceType, true);
    Element elementEnclosingElement = element.getEnclosingElement();
    Set<? extends Element> annotatedElements = validatedModel().getRootAnnotatedElements(annotationHelper.getTarget());
    for (Element uniqueCheckElement : annotatedElements) {
      Element uniqueCheckEnclosingElement = uniqueCheckElement.getEnclosingElement();
      if (elementEnclosingElement.equals(uniqueCheckEnclosingElement)) {
        List<String> checkQualifiedIds = idAnnotationHelper.extractAnnotationResources(uniqueCheckElement, resourceType, true);
        for (String checkQualifiedId : checkQualifiedIds) {
          for (String annotationQualifiedId : annotationQualifiedIds) {
            if (annotationQualifiedId.equals(checkQualifiedId)) {
              String annotationSimpleId = annotationQualifiedId.substring(annotationQualifiedId.lastIndexOf('.') + 1);
              valid.addError("The resource id " + annotationSimpleId + " is already used on the following " + annotationHelper.annotationName() + " method: " + uniqueCheckElement);
              return;
            }
          }
        }
      }
    }
  }
}

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

&& !javaLang.equals(imp.getEnclosingElement())) {
imports.add(imp.getQualifiedName().toString());

代码示例来源:origin: remkop/picocli

if (declaredType.asElement().getKind() == ENUM && !element.equals(declaredType.asElement())) {
  debugElement(declaredType.asElement(), indent + "  --> ");

代码示例来源:origin: yahoo/squidb

/**
 * Log an error to this model spec.
 *
 * This is generally intended for logging things like validation errors. Such errors do not stop the code
 * generation process (as logging an error using Messager and Kind.ERROR would), but instead generate
 * temporary code in the model class that will be picked up by a subsequent annotation processor and logged as
 * errors in a later round of annotation processing. This mechanism is designed to work around the fact that
 * logging Kind.ERROR messages during early rounds of annotation processing may suppress those errors, because
 * failing early during annotation processing can lead to a large number of "symbol not found" errors, which in
 * turn mask other validation errors.
 * <p>
 * If {@link PluginEnvironment#OPTIONS_USE_STANDARD_ERROR_LOGGING} is passed as an option to the code generator,
 * this SquiDB workaround is disabled and this method will log an error using a standard printMessage() call with
 * Kind.ERROR.
 *
 * @param message the error message to be logged
 * @param element the specific inner element in the model spec that is causing this error (e.g. a field or method),
 * or null for a general error
 */
public void logError(String message, Element element) {
  if (pluginEnvironment.hasSquidbOption(PluginEnvironment.OPTIONS_USE_STANDARD_ERROR_LOGGING)) {
    utils.getMessager().printMessage(Diagnostic.Kind.ERROR, message, element);
  } else {
    boolean isRootElement = element == null || element.equals(getModelSpecElement());
    loggedErrors.add(new ErrorInfo(getModelSpecName(),
        isRootElement ? "" : element.getSimpleName().toString(), message));
  }
}

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

target = ValueToBuilderTarget.BUILDER_CONSTRUCTOR;
} else if (copyMethod.getModifiers().contains(Modifier.STATIC)) {
 if (copyMethod.getEnclosingElement().equals(attributeValueType())) {
  target = ValueToBuilderTarget.VALUE_TYPE;
 } else {
 if (copyMethod.getEnclosingElement().equals(attributeValueType())) {
  target = ValueToBuilderTarget.VALUE_INSTANCE;
 } else {
if (builderMethod.getEnclosingElement().equals(attributeValueType())) {
 qualifiedBuilderConstructorMethod = String.format("%s.%s",
   attributeValueType().getQualifiedName(),

代码示例来源:origin: uber/NullAway

if (varElement.equals(fromVar.getElement())) {
 LocalVariableNode toVar = localVarTranslations.get(fromVar);
 AccessPath newAP =

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

if (attributeMethodCandidate.getEnclosingElement().equals(originalType)) {
 hasNonInheritedAttributes = true;

代码示例来源:origin: javaee/glassfish

private TypeMirror onDeclaredType(DeclaredType t, TypeElement sup) {
  // t = sup<...>
  if (t.asElement().equals(sup))
    return t;
  for (TypeMirror i : env.getTypeUtils().directSupertypes(t)) {
    TypeMirror r = visitDeclared((DeclaredType) i, sup);
    if (r != null) return r;
  }
  return null;
}

代码示例来源:origin: stephanenicolas/toothpick

private boolean isSingleInjectAnnotatedConstructor(Element constructorElement) {
 TypeElement enclosingElement = (TypeElement) constructorElement.getEnclosingElement();
 boolean isSingleInjectedConstructor = true;
 List<ExecutableElement> constructorElements = ElementFilter.constructorsIn(enclosingElement.getEnclosedElements());
 for (ExecutableElement constructorElementInClass : constructorElements) {
  if (constructorElementInClass.getAnnotation(Inject.class) != null && !constructorElement.equals(constructorElementInClass)) {
   isSingleInjectedConstructor = false;
  }
 }
 return isSingleInjectedConstructor;
}

代码示例来源:origin: com.google.gwt/gwt-servlet

private boolean hasServiceLocator(TypeElement x, State state) {
 Service service = x.getAnnotation(Service.class);
 if (service != null) {
  // See javadoc on getAnnotation
  try {
   service.locator();
   throw new RuntimeException("Should not reach here");
  } catch (MirroredTypeException expected) {
   TypeMirror locatorType = expected.getTypeMirror();
   return !state.types.asElement(locatorType).equals(state.serviceLocatorType.asElement());
  }
 }
 ServiceName serviceName = x.getAnnotation(ServiceName.class);
 return serviceName != null && !serviceName.locator().isEmpty();
}

代码示例来源:origin: com.google.gwt/gwt-servlet

private boolean hasProxyLocator(TypeElement x, State state) {
 ProxyFor proxyFor = x.getAnnotation(ProxyFor.class);
 if (proxyFor != null) {
  // See javadoc on getAnnotation
  try {
   proxyFor.locator();
   throw new RuntimeException("Should not reach here");
  } catch (MirroredTypeException expected) {
   TypeMirror locatorType = expected.getTypeMirror();
   return !state.types.asElement(locatorType).equals(state.locatorType.asElement());
  }
 }
 ProxyForName proxyForName = x.getAnnotation(ProxyForName.class);
 return proxyForName != null && !proxyForName.locator().isEmpty();
}

代码示例来源:origin: inferred/FreeBuilder

/**
 * Verifies {@code method} is an abstract getter. Any deviations will be logged as an error.
 */
private boolean methodIsAbstractGetter(TypeElement valueType, ExecutableElement method) {
 Set<Modifier> modifiers = method.getModifiers();
 if (!modifiers.contains(Modifier.ABSTRACT)) {
  return false;
 }
 boolean declaredOnValueType = method.getEnclosingElement().equals(valueType);
 TypeMirror returnType = getReturnType(valueType, method, types);
 if (returnType.getKind() == TypeKind.VOID || !method.getParameters().isEmpty()) {
  if (declaredOnValueType) {
   messager.printMessage(
     ERROR,
     "Only getter methods may be declared abstract on FreeBuilder types",
     method);
  } else {
   printNoImplementationMessage(valueType, method);
  }
  return false;
 }
 return true;
}

相关文章