當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeElement.getNestingKind方法代碼示例

本文整理匯總了Java中javax.lang.model.element.TypeElement.getNestingKind方法的典型用法代碼示例。如果您正苦於以下問題:Java TypeElement.getNestingKind方法的具體用法?Java TypeElement.getNestingKind怎麽用?Java TypeElement.getNestingKind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.lang.model.element.TypeElement的用法示例。


在下文中一共展示了TypeElement.getNestingKind方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: create

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
public static TargetDescription create(CompilationInfo info, TypeElement type, TreePath path, boolean allowForDuplicates, boolean iface) {
    boolean canStatic = true;
    if (iface) {
        // interface cannot have static methods
        canStatic = false;
    } else {
        if (type.getNestingKind() == NestingKind.ANONYMOUS || 
            type.getNestingKind() == NestingKind.LOCAL ||
            (type.getNestingKind() != NestingKind.TOP_LEVEL && !type.getModifiers().contains(Modifier.STATIC))) {
            canStatic = false;
        }
    }
    return new TargetDescription(Utilities.target2String(type), 
            ElementHandle.create(type), 
            TreePathHandle.create(path, info),
            allowForDuplicates, 
            type.getSimpleName().length() == 0, iface, canStatic);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:TargetDescription.java

示例2: addInstanceForConstructor

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
/**
 * Registers an instance for the resolved constructor. If a 
 * 
 * @param el 
 */
private void addInstanceForConstructor(Element el) {
    TypeElement pt = findEnclosingType(el);
    if (pt == null) {
        return;
    }
    switch (pt.getNestingKind()) {
        case ANONYMOUS:
            // the anonymous class itself may not need an enclosing instance, if its
            // contents do not reference anything from the instance.
            break;
            
        case LOCAL:
            // implicit reference to the enclosing instance, but since a type with no qualname is referenced,
            // the expression / statement can't be probably moved anywhere.
            addLocalReference(pt);
            break;
        case MEMBER:
            // add enclosing type's reference
            if (!pt.getModifiers().contains(Modifier.STATIC)) {
                addRequiredInstance((TypeElement)pt.getEnclosingElement());
            }
            break;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:30,代碼來源:InstanceRefFinder.java

示例3: generateComment

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
public String generateComment(TypeElement clazz, CompilationInfo javac) {
        StringBuilder builder = new StringBuilder(
//                "/**\n" + // NOI18N
                "\n" // NOI18N
                );
        
        if (clazz.getNestingKind() == NestingKind.TOP_LEVEL) {
            builder.append("@author ").append(author).append("\n"); // NOI18N
        }
        
        if (SourceVersion.RELEASE_5.compareTo(srcVersion) <= 0) {
            for (TypeParameterElement param : clazz.getTypeParameters()) {
                builder.append("@param <").append(param.getSimpleName().toString()).append("> \n"); // NOI18N
            }
        }
        
        if (SourceVersion.RELEASE_5.compareTo(srcVersion) <= 0 &&
                JavadocUtilities.isDeprecated(javac, clazz)) {
            builder.append("@deprecated\n"); // NOI18N
        }
        
//        builder.append("*/\n"); // NOI18N

        return builder.toString();
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:JavadocGenerator.java

示例4: getRealClassName

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
/**
 * 獲取TypeElement真實的類名
 */
public String getRealClassName(TypeElement typeElement) {
	NestingKind nestingKind = typeElement.getNestingKind();
	if (nestingKind.isNested()) {
		Element enclosingElement = typeElement.getEnclosingElement();
		if (enclosingElement.getKind() == ElementKind.CLASS || enclosingElement.getKind() == ElementKind.INTERFACE){
			String enclosingClassName = getRealClassName((TypeElement) enclosingElement);
			return enclosingClassName + "$" + typeElement.getSimpleName();
		}else {
			mErrorReporter.reportError("the type(" + enclosingElement.getKind()+ ") of enclosing element is not CLASS or INTERFACE.",typeElement);
			return null;
		}
	}else {
		return typeElement.getQualifiedName().toString();
	}
}
 
開發者ID:tik5213,項目名稱:DUnit,代碼行數:19,代碼來源:DUnitModelUtil.java

示例5: hasStaticRoot

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
private boolean hasStaticRoot(final Element element) {
	final TypeElement parent = (TypeElement) element.getEnclosingElement();

	if (parent == null) {
		return true;
	}

	switch (parent.getNestingKind()) {
		case TOP_LEVEL:
			return true;
		case MEMBER:
			return parent.getModifiers().contains(STATIC);
		case LOCAL:
			return false;
		case ANONYMOUS:
			return false;
	}

	throw new RuntimeException("Should never get here.");
}
 
開發者ID:MatthewTamlin,項目名稱:Spyglass,代碼行數:21,代碼來源:BasicValidator.java

示例6: getParentChain

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
private static String getParentChain(final TypeElement targetClass) {
	// if input is top level class return it
	// otherwise return the parent chain plus it

	if (targetClass.getNestingKind() == NestingKind.TOP_LEVEL) {
		return targetClass.getSimpleName().toString();
	} else {
		final Element parent = targetClass.getEnclosingElement();

		if (parent.getKind() != ElementKind.CLASS) {
			throw new RuntimeException("Cannot create parent chain. Non-class parent found.");
		}

		return (getParentChain((TypeElement) parent)) + "_" + targetClass.getSimpleName().toString();
	}
}
 
開發者ID:MatthewTamlin,項目名稱:Spyglass,代碼行數:17,代碼來源:CompanionNamer.java

示例7: ReplaceConstructorWithBuilderUI

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
private ReplaceConstructorWithBuilderUI(TreePathHandle constructor, CompilationInfo info) {
    this.refactoring = new ReplaceConstructorWithBuilderRefactoring(constructor);
    ExecutableElement contructorElement = (ExecutableElement) constructor.resolveElement(info);
    this.name = contructorElement.getSimpleName().toString();
    MethodTree constTree = (MethodTree) constructor.resolve(info).getLeaf();
    paramaterNames = new ArrayList<String>();
    parameterTypes = new ArrayList<String>();
    parameterTypeVars = new ArrayList<Boolean>();
    boolean varargs = contructorElement.isVarArgs();
    List<? extends VariableElement> parameterElements = contructorElement.getParameters();
    List<? extends VariableTree> parameters = constTree.getParameters();
    for (int i = 0; i < parameters.size(); i++) {
        VariableTree var = parameters.get(i);
        paramaterNames.add(var.getName().toString());
        String type = contructorElement.getParameters().get(i).asType().toString();
        if(varargs && i+1 == parameters.size()) {
            if(var.getType().getKind() == Tree.Kind.ARRAY_TYPE) {
                ArrayTypeTree att = (ArrayTypeTree) var.getType();
                type = att.getType().toString();
                type += "..."; //NOI18N
            }
        }
        parameterTypes.add(type);
        parameterTypeVars.add(parameterElements.get(i).asType().getKind() == TypeKind.TYPEVAR);
    }
    TypeElement typeEl = (TypeElement) contructorElement.getEnclosingElement();
    if(typeEl.getNestingKind() != NestingKind.TOP_LEVEL) {
        PackageElement packageOf = info.getElements().getPackageOf(typeEl);
        builderFQN = packageOf.toString() + "." + typeEl.getSimpleName().toString();
    } else {
        builderFQN = typeEl.getQualifiedName().toString();
    }
    buildMethodName = "create" + typeEl.getSimpleName();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:35,代碼來源:ReplaceConstructorWithBuilderUI.java

示例8: tooComplexClass

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
@Hint(
    displayName = "#DN_ClassTooComplex",
    description = "#DESC_ClassTooComplex",
    category = "metrics",
    options = { Hint.Options.HEAVY, Hint.Options.QUERY },
    enabled = false
)
@UseOptions(OPTION_COMPLEXITY_LIMIT)
@TriggerTreeKind(Tree.Kind.CLASS)
public static ErrorDescription tooComplexClass(HintContext ctx) {
    ClassTree clazz = (ClassTree)ctx.getPath().getLeaf();
    TypeElement e = (TypeElement)ctx.getInfo().getTrees().getElement(ctx.getPath());
    if (e.getNestingKind() == NestingKind.ANONYMOUS) {
        return null;
    }
    CyclomaticComplexityVisitor v = new CyclomaticComplexityVisitor();
    v.scan(ctx.getPath(), null);
    
    int complexity = v.getComplexity();
    int limit = ctx.getPreferences().getInt(OPTION_COMPLEXITY_LIMIT, DEFAULT_COMPLEXITY_LIMIT);
    if (complexity > limit) {
        return ErrorDescriptionFactory.forName(ctx, 
                ctx.getPath(), 
                TEXT_ClassTooComplex(clazz.getSimpleName().toString(), complexity));
    } else {
        return null;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:29,代碼來源:ClassMetrics.java

示例9: isAccessible

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
@Override
public boolean isAccessible(Scope scope, TypeElement te) {
    if (te == null || scope == null) {
        return false;
    }
    if (te.getQualifiedName().toString().startsWith("REPL.") && te.getNestingKind() == NestingKind.TOP_LEVEL) {
        return false;
    }
    return delegate.isAccessible(scope, te);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:11,代碼來源:CompletionFilter.java

示例10: run

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
@TriggerTreeKind(Tree.Kind.BLOCK)
public static ErrorDescription run(HintContext ctx) {
    TreePath path = ctx.getPath();
    if (((BlockTree)path.getLeaf()).isStatic()) {
        return null;
    }
    TreePath parentPath = path.getParentPath();
    if (parentPath == null) {
        return null;
    }
    Tree l = parentPath.getLeaf();
    if (!(l instanceof ClassTree)) {
        return null;
    }
    Element el = ctx.getInfo().getTrees().getElement(parentPath);
    if (el == null || !el.getKind().isClass()) {
        return null;
    }
    TypeElement tel = (TypeElement)el;
    // do not suggest for anonymous classes, local classes or members which are not static.
    if (tel.getNestingKind() != NestingKind.TOP_LEVEL && 
        (tel.getNestingKind() != NestingKind.MEMBER || !tel.getModifiers().contains(Modifier.STATIC))) {
        return null;
    }
    InstanceRefFinder finder = new InstanceRefFinder(ctx.getInfo(), path);
    finder.process();
    if (finder.containsInstanceReferences() || finder.containsReferencesToSuper()) {
        return null;
    }
    
    return ErrorDescriptionFactory.forTree(ctx, path, Bundle.TEXT_InitializerCanBeStatic(),
            new MakeInitStatic(TreePathHandle.create(path, ctx.getInfo())).toEditorFix());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:34,代碼來源:InitializerCanBeStatic.java

示例11: addLocalClassVariable

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
/**
 * If the variable is typed as a local class, record the local class; it may need to go along
 * with the factored expression, unless the expression only uses some specific interface
 * implemented by the local class.
 * 
 * @param el 
 */
private void addLocalClassVariable(Element el) {
    TypeMirror tm = el.asType();
    if (tm.getKind() != TypeKind.DECLARED)  {
        return;
    }
    Element e = ((DeclaredType)tm).asElement();
    if (!(e instanceof TypeElement)) {
        return;
    }
    TypeElement t = (TypeElement)e;
    if (t.getNestingKind() == NestingKind.LOCAL) {
        addLocalReference(t);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:InstanceRefFinder.java

示例12: apply

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
@TriggerPatterns(value = {
    @TriggerPattern(value = JPAAnnotations.ENTITY),
    @TriggerPattern(value = JPAAnnotations.EMBEDDABLE),
    @TriggerPattern(value = JPAAnnotations.MAPPED_SUPERCLASS)})
public static ErrorDescription apply(HintContext hc) {
    if (hc.isCanceled() || (hc.getPath().getLeaf().getKind() != Tree.Kind.IDENTIFIER || hc.getPath().getParentPath().getLeaf().getKind() != Tree.Kind.ANNOTATION)) {//NOI18N
        return null;//we pass only if it is an annotation
    }

    final JPAProblemContext ctx = ModelUtils.getOrCreateCachedContext(hc);
    if (ctx == null || hc.isCanceled()) {
        return null;
    }

    TypeElement subject = ctx.getJavaClass();
    
    if (subject.getNestingKind() == NestingKind.TOP_LEVEL){
        return null;
    }
    TreePath par = hc.getPath();
    while (par != null && par.getParentPath() != null && par.getLeaf().getKind() != Tree.Kind.CLASS) {
        par = par.getParentPath();
    }

    Utilities.TextSpan underlineSpan = Utilities.getUnderlineSpan(
            ctx.getCompilationInfo(), par.getLeaf());

    return ErrorDescriptionFactory.forSpan(
            hc,
            underlineSpan.getStartOffset(),
            underlineSpan.getEndOffset(),
            NbBundle.getMessage(TopLevelClass.class, "MSG_NestedClassAsEntity"));        
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:34,代碼來源:TopLevelClass.java

示例13: ComponentDescriptor

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
ComponentDescriptor( @Nonnull final String name,
                     @Nonnull final PackageElement packageElement,
                     @Nonnull final TypeElement element )
{
  _name = Objects.requireNonNull( name );
  _packageElement = Objects.requireNonNull( packageElement );
  _element = Objects.requireNonNull( element );

  if ( ElementKind.CLASS != element.getKind() )
  {
    throw new ReactProcessorException( "@ReactComponent target must be a class", element );
  }
  else if ( element.getModifiers().contains( Modifier.ABSTRACT ) )
  {
    throw new ReactProcessorException( "@ReactComponent target must not be abstract", element );
  }
  else if ( element.getModifiers().contains( Modifier.FINAL ) )
  {
    throw new ReactProcessorException( "@ReactComponent target must not be final", element );
  }
  else if ( NestingKind.TOP_LEVEL != element.getNestingKind() &&
            !element.getModifiers().contains( Modifier.STATIC ) )
  {
    throw new ReactProcessorException( "@ReactComponent target must not be a non-static nested class", element );
  }

  final List<ExecutableElement> constructors = element.getEnclosedElements().stream().
    filter( m -> m.getKind() == ElementKind.CONSTRUCTOR ).
    map( m -> (ExecutableElement) m ).
    collect( Collectors.toList() );
  if ( !( 1 == constructors.size() &&
          constructors.get( 0 ).getParameters().isEmpty() &&
          !constructors.get( 0 ).getModifiers().contains( Modifier.PRIVATE ) ) )
  {
    throw new ReactProcessorException( "@ReactComponent target must have a single non-private, no-argument " +
                                       "constructor or the default constructor", element );
  }
}
 
開發者ID:react4j,項目名稱:react4j,代碼行數:39,代碼來源:ComponentDescriptor.java

示例14: getPackage

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
private PackageElement getPackage(final TypeElement type) {
	if (type.getNestingKind() == NestingKind.TOP_LEVEL) {
		return (PackageElement) type.getEnclosingElement();
	} else {
		return getPackage((TypeElement) type.getEnclosingElement());
	}
}
 
開發者ID:MatthewTamlin,項目名稱:Spyglass,代碼行數:8,代碼來源:CompanionGenerator.java

示例15: getFlatName

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
public static String getFlatName(TypeElement classRepresenter) {
    if (classRepresenter.getNestingKind() == NestingKind.MEMBER) {
        return classRepresenter.getEnclosingElement() + "" + classRepresenter.getSimpleName().toString();
    } else {
        return classRepresenter.getQualifiedName().toString();
    }
}
 
開發者ID:intendia-oss,項目名稱:qualifier,代碼行數:8,代碼來源:StaticQualifierMetamodelProcessor.java


注:本文中的javax.lang.model.element.TypeElement.getNestingKind方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。