org.eclipse.jdt.core.Flags类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(210)

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

Flags介绍

[英]Utility class for decoding modifier flags in Java elements.

This class provides static methods only.

Note that the numeric values of these flags match the ones for class files as described in the Java Virtual Machine Specification (except for #AccDeprecated, #AccAnnotationDefault, and #AccDefaultMethod).

The AST class Modifier provides similar functionality as this class, only in the org.eclipse.jdt.core.dom package.
[中]用于解码Java元素中的修改器标志的实用程序类。
此类仅提供静态方法。
请注意,这些标志的数值与Java虚拟机规范中描述的类文件的数值相匹配(除了#AccDeprecated、#AccAnnotationDefault和#AccDefaultMethod)。
AST类Modifier仅在org.eclipse.jdt.core.dom包中提供与此类类似的功能。

代码示例

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

private ImageDescriptor decorate(ImageDescriptor descriptor, int modifiers, boolean isField) {
  int flags= 0;
  if (Flags.isDeprecated(modifiers))
    flags |= JavaElementImageDescriptor.DEPRECATED;
  if (Flags.isStatic(modifiers))
    flags |= JavaElementImageDescriptor.STATIC;
  if (Flags.isFinal(modifiers))
    flags |= JavaElementImageDescriptor.FINAL;
  if (Flags.isSynchronized(modifiers))
    flags |= JavaElementImageDescriptor.SYNCHRONIZED;
  if (Flags.isAbstract(modifiers))
    flags |= JavaElementImageDescriptor.ABSTRACT;
  
  if (isField) {
    if (Flags.isVolatile(modifiers))
      flags |= JavaElementImageDescriptor.VOLATILE;
    if (Flags.isTransient(modifiers))
      flags |= JavaElementImageDescriptor.TRANSIENT;
  }
  
  return new JavaElementImageDescriptor(descriptor, flags, JavaElementImageProvider.SMALL_SIZE);
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

private static ImageDescriptor getClassImageDescriptor(int flags) {
  if (Flags.isPublic(flags) || Flags.isProtected(flags) || Flags.isPrivate(flags))
    return JavaPluginImages.DESC_OBJS_CLASS;
  else
    return JavaPluginImages.DESC_OBJS_CLASS_DEFAULT;
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

int kind= proposal.getKind();
if (Flags.isDeprecated(flags))
  adornments |= JavaElementImageDescriptor.DEPRECATED;
  if (Flags.isStatic(flags))
    adornments |= JavaElementImageDescriptor.STATIC;
  if (Flags.isSynchronized(flags))
    adornments |= JavaElementImageDescriptor.SYNCHRONIZED;
if (kind == CompletionProposal.TYPE_REF && Flags.isAbstract(flags) && !Flags.isInterface(flags))
  adornments |= JavaElementImageDescriptor.ABSTRACT;
  if (Flags.isTransient(flags))
    adornments |= JavaElementImageDescriptor.TRANSIENT;
  if (Flags.isVolatile(flags))
    adornments |= JavaElementImageDescriptor.VOLATILE;

代码示例来源:origin: org.eclipse.tycho/org.eclipse.jdt.core

private static int getFieldVariableKind(int modifiers) {
  if (Flags.isStatic(modifiers)) {
    if (Flags.isFinal(modifiers)) {
      return VK_STATIC_FINAL_FIELD;
    }
    return VK_STATIC_FIELD;
  }
  return VK_INSTANCE_FIELD;
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

private ImageDescriptor getOverlayFromFlags(int flags)  {
  if (Flags.isAnnotation(flags)) {
    return JavaPluginImages.DESC_OVR_ANNOTATION;
  } else if (Flags.isEnum(flags)) {
    return JavaPluginImages.DESC_OVR_ENUM;
  } else if (Flags.isInterface(flags)) {
    return JavaPluginImages.DESC_OVR_INTERFACE;
  } else if (/* is class */ Flags.isAbstract(flags)) {
    return JavaPluginImages.DESC_OVR_ABSTRACT_CLASS;
  }
  return null;
}

代码示例来源:origin: eclipse/eclipse.jdt.ls

public static boolean isAbstract(IMember member) throws JavaModelException{
  int flags= member.getFlags();
  if (!member.isBinary() && isInterfaceOrAnnotationMethod(member)) {
    return !Flags.isPrivate(flags) && !Flags.isStatic(flags) && !Flags.isDefaultMethod(flags);
  }
  return Flags.isAbstract(flags);
}

代码示例来源:origin: org.eclipse/org.eclipse.ajdt.ui

if (Flags.isAbstract(modifiers) && confirmAbstract(member))
  flags |= JavaElementImageDescriptor.ABSTRACT;
if (Flags.isFinal(modifiers) || isInterfaceField(member))
  flags |= JavaElementImageDescriptor.FINAL;
if (Flags.isSynchronized(modifiers) && confirmSynchronized(member))
  flags |= JavaElementImageDescriptor.SYNCHRONIZED;
if (Flags.isStatic(modifiers) || isInterfaceField(member))
  flags |= JavaElementImageDescriptor.STATIC;
if (Flags.isDeprecated(modifiers))
  flags |= JavaElementImageDescriptor.DEPRECATED;

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

/**
 * Note: This method is for internal use only. Clients should not call this method.
 * @param element The element to decorate
 * @return Resulting decorations (combination of JavaElementImageDescriptor.IMPLEMENTS
 * and JavaElementImageDescriptor.OVERRIDES)
 */
public int computeAdornmentFlags(Object element) {
  if (element instanceof IMethod) {
    try {
      IMethod method= (IMethod) element;
      if (!method.getJavaProject().isOnClasspath(method)) {
        return 0;
      }
      int flags= method.getFlags();
      if (!method.isConstructor() && !Flags.isPrivate(flags) && !Flags.isStatic(flags)) {
        int res= getOverrideIndicators(method);
        if (res != 0 && Flags.isSynchronized(flags)) {
          return res | JavaElementImageDescriptor.SYNCHRONIZED;
        }
        return res;
      }
    } catch (JavaModelException e) {
      if (!e.isDoesNotExist()) {
        JavaPlugin.log(e);
      }
    }
  }
  return 0;
}

代码示例来源:origin: angelozerr/jdt-codemining

public static boolean isMethod(IMethod method, boolean onlyPublicMethod) {
  try {
    int flags = method.getFlags();
    if (onlyPublicMethod && !Flags.isPublic(flags)) {
      return false;
    }
    // 'V' is void signature
    return !(method.isConstructor() || Flags.isAbstract(flags) || Flags.isStatic(flags)
        || !"V".equals(method.getReturnType()));
  } catch (JavaModelException e) {
    // ignore
    return false;
  }
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

private boolean isOfKind(TypeNameMatch curr, int typeKinds, boolean is50OrHigher) {
  int flags= curr.getModifiers();
  if (Flags.isAnnotation(flags)) {
    return is50OrHigher && (typeKinds & TypeKinds.ANNOTATIONS) != 0;
  }
  if (Flags.isEnum(flags)) {
    return is50OrHigher && (typeKinds & TypeKinds.ENUMS) != 0;
  }
  if (Flags.isInterface(flags)) {
    return (typeKinds & TypeKinds.INTERFACES) != 0;
  }
  return (typeKinds & TypeKinds.CLASSES) != 0;
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

public static boolean isAbstract(IMember member) throws JavaModelException{
  int flags= member.getFlags();
  if (!member.isBinary() && isInterfaceOrAnnotationMethod(member)) {
    return !Flags.isStatic(flags) && !Flags.isDefaultMethod(flags);
  }
  return Flags.isAbstract(flags);
}

代码示例来源:origin: org.eclipse/org.eclipse.jpt.core

public boolean isAbstract() {
  try {
    return Flags.isAbstract(this.getJdtMember().getFlags());
  } catch (JavaModelException ex) {
    throw new RuntimeException(ex);
  }
}

代码示例来源:origin: org.eclipse.jdt.junit/core

public static void findTestImplementorClasses(ITypeHierarchy typeHierarchy, IType testInterface, IRegion region, Set result)
    throws JavaModelException {
  IType[] subtypes= typeHierarchy.getAllSubtypes(testInterface);
  for (int i= 0; i < subtypes.length; i++) {
    IType type= subtypes[i];
    int cachedFlags= typeHierarchy.getCachedFlags(type);
    if (!Flags.isInterface(cachedFlags) && !Flags.isAbstract(cachedFlags) // do the cheaper tests first
        && region.contains(type) && CoreTestSearchEngine.isAccessibleClass(type)) {
      result.add(type);
    }
  }
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

/**
 * Hook method that gets called when the modifiers have changed. The method validates 
 * the modifiers and returns the status of the validation.
 * <p>
 * Subclasses may extend this method to perform their own validation.
 * </p>
 * 
 * @return the status of the validation
 */
protected IStatus modifiersChanged() {
  StatusInfo status= new StatusInfo();
  int modifiers= getModifiers();
  if (Flags.isFinal(modifiers) && Flags.isAbstract(modifiers)) {
    status.setError(NewWizardMessages.NewTypeWizardPage_error_ModifiersFinalAndAbstract); 
  }
  return status;
}

代码示例来源:origin: eclipse/eclipse.jdt.ls

public static boolean isVarargs(IMethod method) throws JavaModelException{
  return Flags.isVarargs(method.getFlags());
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.junit.core

public static boolean hasSuiteMethod(IType type) throws JavaModelException {
  IMethod method= type.getMethod("suite", new String[0]); //$NON-NLS-1$
  if (!method.exists())
    return false;
  if (!Flags.isStatic(method.getFlags()) || !Flags.isPublic(method.getFlags())) {
    return false;
  }
  if (!Signature.getSimpleName(Signature.toString(method.getReturnType())).equals(JUnitCorePlugin.SIMPLE_TEST_INTERFACE_NAME)) {
    return false;
  }
  return true;
}

代码示例来源:origin: org.eclipse.pde/org.eclipse.pde.api.tools

@Override
public boolean visit(EnumDeclaration node) {
  int flags = node.getModifiers();
  if (node.isMemberTypeDeclaration()) {
    isvisible &= Flags.isPublic(flags);
  } else {
    isvisible &= !Flags.isPrivate(flags) && !Flags.isPackageDefault(flags);
  }
  fStack.push(new Item(getTypeName(node), node.getModifiers(), isvisible));
  return true;
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

public static boolean isStatic(IMember member) throws JavaModelException{
  if (isNestedInterfaceOrAnnotation(member))
    return true;
  if (member.getElementType() != IJavaElement.METHOD && isInterfaceOrAnnotationMember(member))
    return true;
  if (isEnumConstant(member))
    return true;
  return Flags.isStatic(member.getFlags());
}

代码示例来源:origin: org.eclipse/org.eclipse.jpt.core

/**
 * According to the spec, "All non-transient instance variables that are not 
 * annotated with the Transient annotation are persistent."
 */
private static boolean fieldIsPersistable_(IField field) throws JavaModelException {
  int flags = field.getFlags();
  if (Flags.isStatic(flags)) {
    return false;
  }
  if (Flags.isTransient(flags)) {
    return false;
  }
  return true;
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

ImageDescriptor createTypeImageDescriptor(CompletionProposal proposal) {
  final int flags= proposal.getFlags();
  boolean isInterfaceOrAnnotation= Flags.isInterface(flags) || Flags.isAnnotation(flags);
  return decorateImageDescriptor(JavaElementImageProvider.getTypeImageDescriptor(true /* in order to get all visibility decorations */, isInterfaceOrAnnotation, flags, false), proposal);
}

相关文章