javax.lang.model.element.ElementKind#INSTANCE_INIT源码实例Demo

下面列出了javax.lang.model.element.ElementKind#INSTANCE_INIT 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: j2cl   文件: JavaEnvironment.java
private static List<TypeParameterElement> getTypeParameters(TypeElement typeElement) {
  List<TypeParameterElement> typeParameterElements =
      new ArrayList<>(typeElement.getTypeParameters());
  Element currentElement = typeElement;
  Element enclosingElement = typeElement.getEnclosingElement();
  while (enclosingElement != null) {
    if (isStatic(currentElement)) {
      break;
    }

    if (enclosingElement.getKind() != ElementKind.STATIC_INIT
        && enclosingElement.getKind() != ElementKind.INSTANCE_INIT
        && enclosingElement instanceof Parameterizable) {
      // Add the enclosing element type variables, skip STATIC_INIT and INSTANCE_INIT since they
      // never define type variables, and throw NPE if getTypeParameters is called on them.
      typeParameterElements.addAll(((Parameterizable) enclosingElement).getTypeParameters());
    }
    currentElement = enclosingElement;
    enclosingElement = enclosingElement.getEnclosingElement();
  }
  return typeParameterElements;
}
 
@Override
public ElementKind getKind() {
	MethodBinding binding = (MethodBinding)_binding;
	if (binding.isConstructor()) {
		return ElementKind.CONSTRUCTOR;
	}
	else if (CharOperation.equals(binding.selector, TypeConstants.CLINIT)) {
		return ElementKind.STATIC_INIT;
	}
	else if (CharOperation.equals(binding.selector, TypeConstants.INIT)) {
		return ElementKind.INSTANCE_INIT;
	}
	else {
		return ElementKind.METHOD;
	}
}
 
源代码3 项目: lua-for-android   文件: Symbol.java
@DefinedBy(Api.LANGUAGE_MODEL)
public ElementKind getKind() {
    if (name == name.table.names.init)
        return ElementKind.CONSTRUCTOR;
    else if (name == name.table.names.clinit)
        return ElementKind.STATIC_INIT;
    else if ((flags() & BLOCK) != 0)
        return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT;
    else
        return ElementKind.METHOD;
}
 
源代码4 项目: netbeans   文件: CodeStyle.java
/**
 * Returns the group number of the class member. Elements with the same
 * number form a group. Groups with lower numbers should be positioned
 * higher in the class member list.
 * @param tree the member tree
 * @return the group number
 * @since 0.96
 */
public int getGroupId(Tree tree) {
    ElementKind kind = ElementKind.OTHER;
    Set<Modifier> modifiers = null;
    switch (tree.getKind()) {
        case ANNOTATION_TYPE:
        case CLASS:
        case ENUM:
        case INTERFACE:
            kind = ElementKind.CLASS;
            modifiers = ((ClassTree)tree).getModifiers().getFlags();
            break;
        case METHOD:
            MethodTree mt = (MethodTree)tree;
            if (mt.getName().contentEquals("<init>")) { //NOI18N
                kind = ElementKind.CONSTRUCTOR;
            } else {
                kind = ElementKind.METHOD;
            }
            modifiers = mt.getModifiers().getFlags();
            break;
        case VARIABLE:
            kind = ElementKind.FIELD;
            modifiers = ((VariableTree)tree).getModifiers().getFlags();
            break;
        case BLOCK:
            kind = ((BlockTree)tree).isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT;
            break;
    }
    for (Info info : infos) {
        if (info.check(kind, modifiers))
            return info.groupId;
    }
    return infos.length;
}
 
源代码5 项目: netbeans   文件: CodeStyle.java
/**
 * Returns the group number of the class member. Elements with the same
 * number form a group. Groups with lower numbers should be positioned
 * higher in the class member list.
 * @param element the member element
 * @return the group number
 * @since 0.96
 */
public int getGroupId(Element element) {
    for (Info info : infos) {
        ElementKind kind = element.getKind();
        if (kind == ElementKind.ANNOTATION_TYPE || kind == ElementKind.ENUM || kind == ElementKind.INSTANCE_INIT)
            kind = ElementKind.CLASS;
        if (info.check(kind, element.getModifiers()));
            return info.groupId;
    }
    return infos.length;
}
 
源代码6 项目: netbeans   文件: Icons.java
private static String getIconName( ElementKind kind, String typeName, String extension, Collection<Modifier> modifiers ) {
    
    StringBuffer fileName = new StringBuffer( typeName );
    
    if ( modifiers.contains( Modifier.STATIC ) ) {
        fileName.append( "Static" );                        //NOI18N
    }
    if ( modifiers.contains( Modifier.ABSTRACT ) ) {
        fileName.append( "Abstract" );                        //NOI18N
    }
    if ( modifiers.contains( Modifier.DEFAULT ) ) {
        fileName.append( "Default" );                        //NOI18N
    }
    if (kind == ElementKind.STATIC_INIT || kind == ElementKind.INSTANCE_INIT) {
        return fileName.append(extension).toString();
    }
    if ( modifiers.contains( Modifier.PUBLIC ) ) {
        return fileName.append( "Public" ).append( extension ).toString();      //NOI18N
    }
    if ( modifiers.contains( Modifier.PROTECTED ) ) {
        return fileName.append( "Protected" ).append( extension ).toString();   //NOI18N
    }
    if ( modifiers.contains( Modifier.PRIVATE ) ) {
        return fileName.append( "Private" ).append( extension ).toString();     //NOI18N
    }
    return fileName.append( "Package" ).append( extension ).toString();         //NOI18N
                    
}
 
源代码7 项目: openjdk-jdk9   文件: Symbol.java
@DefinedBy(Api.LANGUAGE_MODEL)
public ElementKind getKind() {
    if (name == name.table.names.init)
        return ElementKind.CONSTRUCTOR;
    else if (name == name.table.names.clinit)
        return ElementKind.STATIC_INIT;
    else if ((flags() & BLOCK) != 0)
        return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT;
    else
        return ElementKind.METHOD;
}
 
源代码8 项目: lua-for-android   文件: Symbol.java
public boolean isStaticOrInstanceInit() {
    return getKind() == ElementKind.STATIC_INIT ||
            getKind() == ElementKind.INSTANCE_INIT;
}
 
源代码9 项目: openjdk-jdk9   文件: Symbol.java
public boolean isStaticOrInstanceInit() {
    return getKind() == ElementKind.STATIC_INIT ||
            getKind() == ElementKind.INSTANCE_INIT;
}
 
源代码10 项目: immutables   文件: Encodings.java
private void processMember(Element member) {
  if ((member.getKind() == ElementKind.FIELD
      || member.getKind() == ElementKind.METHOD)
      && !memberNames.add(memberPath(member))) {
    reporter.withElement(member)
        .error(
            "Duplicate member name '%s'. Encoding has limitation so that any duplicate method names are not supported,"
                + " even when allowed by JLS: methods cannot have overloads here."
                + " @Encoding.Naming annotation could be used so that actually generated methods might have the same name"
                + " if they are not conflicting as per JLS overload rules",
            member.getSimpleName());
    return;
  }

  if (member.getKind() == ElementKind.FIELD) {
    if (processField((VariableElement) member))
      return;
  }
  if (member.getKind() == ElementKind.METHOD) {
    if (!Ascii.isLowerCase(member.getSimpleName().charAt(0))) {
      reporter.withElement(member)
          .warning("Methods not starting with lowercase ascii letter might not work properly",
              member.getSimpleName());
    }
    if (processMethod((ExecutableElement) member))
      return;
  }
  if (member.getKind() == ElementKind.CLASS) {
    if (processClass((TypeElement) member))
      return;
  }
  if (member.getKind() == ElementKind.INSTANCE_INIT) {
    return;
  }

  if (member.getSimpleName().contentEquals("<init>")) {
    return;
  }

  reporter.withElement(member)
      .warning("Unrecognized encoding member '%s' will be ignored", member.getSimpleName());
}
 
源代码11 项目: immutables   文件: Encodings.java
private boolean processClass(TypeElement type) {
  if (BuilderMirror.isPresent(type)) {
    this.typeBuilder = type;

    if (!typeParams.equals(getTypeParameterNames(type))
        || !type.getModifiers().contains(Modifier.STATIC)) {
      reporter.withElement(type)
          .error("@Encoding.Builder class '%s' should be static with"
              + " the same type parameters as encoding type: %s",
              type.getSimpleName(),
              typesReader.parameters);

      return true;
    }

    for (Element member : type.getEnclosedElements()) {
      if ((member.getKind() == ElementKind.FIELD
          || member.getKind() == ElementKind.METHOD)
          && !memberNames.add(memberPath(member))) {
        reporter.withElement(member)
            .error(memberPath(member)
                + ": Duplicate builder member name '%s'."
                + " Encoding has limitation so that any duplicate method names are not supported,"
                + " even when allowed by JLS: methods cannot have overloads here."
                + " @Encoding.Naming annotation could be used so that actually generated methods might have the same name"
                + " if they are not conflicting as per JLS overload rules",
                member.getSimpleName());
        continue;
      }

      if (member.getKind() == ElementKind.FIELD) {
        if (processBuilderField((VariableElement) member))
          continue;
      }

      if (member.getKind() == ElementKind.METHOD) {
        if (processBuilderMethod((ExecutableElement) member))
          continue;
      }

      if (member.getKind() == ElementKind.INSTANCE_INIT) {
        continue;
      }

      if (member.getSimpleName().contentEquals("<init>")) {
        continue;
      }

      reporter.withElement(member)
          .warning("Unrecognized Builder member '%s' will be ignored", member.getSimpleName());
    }
    return true;
  }
  return false;
}