当前位置: 首页>>代码示例>>Java>>正文


Java TypeElement.getEnclosingElement方法代码示例

本文整理汇总了Java中javax.lang.model.element.TypeElement.getEnclosingElement方法的典型用法代码示例。如果您正苦于以下问题:Java TypeElement.getEnclosingElement方法的具体用法?Java TypeElement.getEnclosingElement怎么用?Java TypeElement.getEnclosingElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.lang.model.element.TypeElement的用法示例。


在下文中一共展示了TypeElement.getEnclosingElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processLimitJSON

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private void processLimitJSON(RoundEnvironment roundEnv) {
        for (Element element : roundEnv.getElementsAnnotatedWith(LIMITJSON.class)) {
            LJSONTypeElement ljsonElement = LJSONTypeElement.create(elements, element);
            processorHelper.setLimitJSONTypeElements(ljsonElement);
            processorHelper.i("---------------------" + ljsonElement.toString());
//
            TypeElement typeElement = (TypeElement) element;
            Element a = typeElement.getEnclosingElement();
            processorHelper.i("LJSON ++" + a + " " + element.getKind().name());
            List<? extends Element> param = typeElement.getEnclosedElements();
            for (Element p : param) {
                if (p instanceof VariableElement) {
                    processorHelper.i("LJSON ........" + p.getSimpleName() + " " + p.asType().toString());
                }
            }

        }
    }
 
开发者ID:freelifer,项目名称:limitjson,代码行数:19,代码来源:JSONProcessor.java

示例2: 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

示例3: 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

示例4: getDeclaredType

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private DeclaredType getDeclaredType(TypeElement e, HashMap<? extends Element, ? extends TypeMirror> map, Types types) {
    List<? extends TypeParameterElement> tpes = e.getTypeParameters();
    TypeMirror[] targs = new TypeMirror[tpes.size()];
    int i = 0;
    for (Iterator<? extends TypeParameterElement> it = tpes.iterator(); it.hasNext();) {
        TypeParameterElement tpe = it.next();
        TypeMirror t = map.get(tpe);
        targs[i++] = t != null ? t : tpe.asType();
    }
    Element encl = e.getEnclosingElement();
    if ((encl.getKind().isClass() || encl.getKind().isInterface()) && !((TypeElement)encl).getTypeParameters().isEmpty())
            return types.getDeclaredType(getDeclaredType((TypeElement)encl, map, types), e, targs);
    return types.getDeclaredType(e, targs);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:ElementUtilities.java

示例5: getRelativeName

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private String getRelativeName(TypeElement elem) {
    StringBuilder sb = new StringBuilder();
    sb.append(elem.getSimpleName().toString());
    Element parent = elem.getEnclosingElement();
    while(parent.getKind() != ElementKind.PACKAGE) {
        sb.insert(0, parent.getSimpleName().toString() + "$"); // NOI18N
        parent = parent.getEnclosingElement();
    }

    return sb.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:SpringXMLConfigCompletionItem.java

示例6: addLocalReference

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private void addLocalReference(TypeElement el) {
    if (this.enclosingElement != el.getEnclosingElement()) {
        return;
    }
    if (localReferences.isEmpty()) {
        localReferences = new HashSet<TypeElement>();
    }
    localReferences.add(el);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:InstanceRefFinder.java

示例7: getAccessModifiers

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public static Visibility getAccessModifiers(@NonNull CompilationInfo info, @NullAllowed TypeElement source, @NonNull TypeElement target) {
    if (target.getKind().isInterface()) {
        return Visibility.PUBLIC;
    }

    TypeElement outterMostSource = source != null ? info.getElementUtilities().outermostTypeElement(source) : null;
    TypeElement outterMostTarget = info.getElementUtilities().outermostTypeElement(target);

    if (outterMostTarget.equals(outterMostSource)) {
        return Visibility.PRIVATE;
    }

    Element sourcePackage;

    if (outterMostSource != null) {
        sourcePackage = outterMostSource.getEnclosingElement();
    } else if (info.getCompilationUnit().getPackageName() != null) {
        sourcePackage = info.getTrees().getElement(new TreePath(new TreePath(info.getCompilationUnit()), info.getCompilationUnit().getPackageName()));
    } else {
        sourcePackage = info.getElements().getPackageElement("");
    }

    Element targetPackage = outterMostTarget.getEnclosingElement();

    if (sourcePackage != null && sourcePackage.equals(targetPackage)) {
        return Visibility.PACKAGE_PRIVATE;
    }

    //TODO: protected?
    return Visibility.PUBLIC;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:Utilities.java

示例8: printType

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
Void printType(TypeElement e, DeclaredType dt, Boolean highlightName) {
    modifier(e.getModifiers());
    switch (e.getKind()) {
        case CLASS:
            result.append("class ");
            break;
        case INTERFACE:
            result.append("interface ");
            break;
        case ENUM:
            result.append("enum ");
            break;
        case ANNOTATION_TYPE:
            result.append("@interface ");
            break;
    }
    Element enclosing = e.getEnclosingElement();
    
    if (enclosing == SourceUtils.getEnclosingTypeElement(e)) {
        result.append(((TypeElement) enclosing).getQualifiedName());
        result.append('.');
        boldStartCheck(highlightName);
        result.append(e.getSimpleName());
        boldStopCheck(highlightName);
    } else {
        result.append(e.getQualifiedName());
    }
    
    if (dt != null) {
        dumpRealTypeArguments(dt.getTypeArguments());
    }

    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:GoToSupport.java

示例9: getRelativeName

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private String getRelativeName(TypeElement elem) {
    StringBuilder sb = new StringBuilder();
    sb.append(elem.getSimpleName().toString());
    Element parent = elem.getEnclosingElement();
    while (parent.getKind() != ElementKind.PACKAGE) {
        sb.insert(0, parent.getSimpleName().toString() + "$"); // NOI18N
        parent = parent.getEnclosingElement();
    }

    return sb.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:HibernateCompletionItem.java

示例10: getFinalClassName

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private static ClassName getFinalClassName(Context context) {
  TypeElement autoValueClass = context.autoValueClass();
  String name = autoValueClass.getSimpleName().toString();

  Element enclosingElement = autoValueClass.getEnclosingElement();
  while (enclosingElement instanceof TypeElement) {
    name = enclosingElement.getSimpleName().toString() + "_" + name;
    enclosingElement = enclosingElement.getEnclosingElement();
  }

  return ClassName.get(context.packageName(), "AutoValue_" + name);
}
 
开发者ID:setheclark,项目名称:auto-value-json,代码行数:13,代码来源:AutoValueJsonExtension.java

示例11: 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

示例12: CodeInjector

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public CodeInjector(TypeElement classElement, Map<String,EgLanguage> languageForClassName, EgLanguage defaultLanguage) {
    this.classElement = classElement;
    this.languageForClassName = languageForClassName;
    this.defaultLanguage = languageForClassName.getOrDefault(AnnotationCollector.className(classElement), defaultLanguage);

    PackageElement packageElement = (PackageElement) classElement.getEnclosingElement();
    this.packageName = ""+packageElement.getQualifiedName();
    if (EgLanguage.INHERIT.equals(this.defaultLanguage)) {
        throw new IllegalArgumentException("Cannot use INHERIT as a default EgTest language");
    }
}
 
开发者ID:dleppik,项目名称:EgTest,代码行数:12,代码来源:CodeInjector.java

示例13: checkClassVisibility

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private static void checkClassVisibility(Elements eles, TypeElement target, String fromPkg) {
    Set<Modifier> targetMods = target.getModifiers();
    if (!isNestedClass(target)) {
        simpleVisibility(target.getModifiers(), eles.getPackageOf(target), fromPkg, target);
    } else {
        Element surround = target.getEnclosingElement();

        if (surround.getKind() != CLASS
                && surround.getKind() != INTERFACE
                // Not sure if that is allowed, but we include it anyways.
                && surround.getKind() != ENUM) {
            throw new IllegalStateException(
                    target.toString() + " is not nested? " + surround.toString());
        }

        TypeElement enclosingType = (TypeElement) surround;

        // The surrounding class must be visible for us to see the nested class
        if (!isElementVisibleFrom(eles, enclosingType, fromPkg)) {
            throw new EasyPluginException(enclosingType.toString()
                    + " is not visible from output package; need for access to " + target.toString());
        }
        // Nested class must be static since we don't have an enclosing instance
        if (!targetMods.contains(Modifier.STATIC)) {
            throw new EasyPluginException(target.toString() + " must be static.");
        }

        simpleVisibility(target.getModifiers(), eles.getPackageOf(target), fromPkg, target);
    }
}
 
开发者ID:c0d3d,项目名称:easy-plugins,代码行数:31,代码来源:Util.java

示例14: visitType

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
@Override
public Boolean visitType(TypeElement e, Void p) {
    if (includedTypeElements.contains(e)) {
        return true;
    }
    if (isTypeElementSelected(e)) {
        // Class is nameable from top-level and
        // the class and all enclosing classes
        // pass the modifier filter.
        PackageElement pkg = toolEnv.elements.getPackageOf(e);
        if (specifiedPackageElements.contains(pkg)) {
            return true;
        }
        Element enclosing = e.getEnclosingElement();
        if (enclosing != null) {
            switch(enclosing.getKind()) {
                case PACKAGE:
                    return specifiedPackageElements.contains((PackageElement)enclosing);
                case CLASS: case INTERFACE: case ENUM: case ANNOTATION_TYPE:
                    return visit((TypeElement) enclosing);
                default:
                    throw new AssertionError("unknown element: " + enclosing);
            }
        }
    }
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:ElementsTable.java

示例15: isLegalImplementation

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
protected boolean isLegalImplementation(WebService webService, TypeElement classElement) {
    boolean isStateful = isStateful(classElement);

    Collection<Modifier> modifiers = classElement.getModifiers();
    if (!modifiers.contains(Modifier.PUBLIC)) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_CLASS_NOT_PUBLIC(classElement.getQualifiedName()), classElement);
        return false;
    }
    if (modifiers.contains(Modifier.FINAL) && !isStateful) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_CLASS_IS_FINAL(classElement.getQualifiedName()), classElement);
        return false;
    }
    if (modifiers.contains(Modifier.ABSTRACT) && !isStateful) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_CLASS_IS_ABSTRACT(classElement.getQualifiedName()), classElement);
        return false;
    }
    boolean hasDefaultConstructor = false;
    for (ExecutableElement constructor : ElementFilter.constructorsIn(classElement.getEnclosedElements())) {
        if (constructor.getModifiers().contains(Modifier.PUBLIC) &&
                constructor.getParameters().isEmpty()) {
            hasDefaultConstructor = true;
            break;
        }
    }
    if (!hasDefaultConstructor && !isStateful) {
        if (classElement.getEnclosingElement() != null && !modifiers.contains(Modifier.STATIC)) {
            builder.processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_CLASS_IS_INNERCLASS_NOT_STATIC(
                    classElement.getQualifiedName()), classElement);
            return false;
        }

        builder.processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_NO_DEFAULT_CONSTRUCTOR(
                classElement.getQualifiedName()), classElement);
        return false;
    }
    if (webService.endpointInterface().isEmpty()) {
        if (!methodsAreLegal(classElement))
            return false;
    } else {
        TypeElement interfaceElement = getEndpointInterfaceElement(webService.endpointInterface(), classElement);
        if (!classImplementsSei(classElement, interfaceElement))
            return false;
    }

    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:47,代码来源:WebServiceVisitor.java


注:本文中的javax.lang.model.element.TypeElement.getEnclosingElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。