Java Code Examples for javax.lang.model.element.ElementKind#STATIC_INIT

The following examples show how to use javax.lang.model.element.ElementKind#STATIC_INIT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElementScanningTask.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void addMembers( final TypeElement e, final Description parentDescription, final CompilationInfo info, final Context ctx, boolean fqn) {
    List<? extends Element> members = info.getElements().getAllMembers( e );
    for( Element m : members ) {
        if( canceled.get() )
            return;

        if (m.getKind() == ElementKind.STATIC_INIT) {
            continue;
        }

        Description d = element2description(m, e, parentDescription.isInherited, info, ctx, fqn);
        if( null != d ) {
            if (!parentDescription.subs.add( d )) {
                LOG.log(Level.INFO, "Duplicate enclosed element: {0}", d.name);   //NOI18N  Should never happen
            }
            if( m instanceof TypeElement && !d.isInherited ) {
                addMembers( (TypeElement)m, d, info, ctx, fqn);
            }
        }
    }
}
 
Example 2
Source File: JavaEnvironment.java    From j2cl with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: ExecutableElementImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@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;
	}
}
 
Example 4
Source File: ClassFileConverter.java    From j2objc with Apache License 2.0 6 votes vote down vote up
private boolean isEnumSynthetic(Element e, TypeMirror enumType) {
  if (e.getKind() == ElementKind.STATIC_INIT) {
    return true;
  }
  if (e.getKind() == ElementKind.METHOD) {
    ExecutableElement method = (ExecutableElement) e;
    String enumSig = translationEnv.typeUtil().getSignatureName(enumType);
    String valueOfDesc = "(Ljava/lang/String;)" + enumSig;
    String valuesDesc = "()[" + enumSig;
    String name = method.getSimpleName().toString();
    String methodDesc = getMethodDescriptor(method);
    boolean isValueOf = name.equals("valueOf") && methodDesc.equals(valueOfDesc);
    boolean isValues = name.equals("values") && methodDesc.equals(valuesDesc);
    return isValueOf || isValues;
  }
  return false;
}
 
Example 5
Source File: Symbol.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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;
}
 
Example 6
Source File: CodeStyle.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: Icons.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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
                    
}
 
Example 8
Source File: Symbol.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example 9
Source File: Symbol.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public boolean isStaticOrInstanceInit() {
    return getKind() == ElementKind.STATIC_INIT ||
            getKind() == ElementKind.INSTANCE_INIT;
}
 
Example 10
Source File: Symbol.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public boolean isStaticOrInstanceInit() {
    return getKind() == ElementKind.STATIC_INIT ||
            getKind() == ElementKind.INSTANCE_INIT;
}