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


Java Element.toString方法代码示例

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


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

示例1: ensureValidType

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private String ensureValidType(Type type, Element element) {
    if (type == null) {
        return "Type could not be determined for " + element.toString();
    } else {
        if (type instanceof CollectionType) {
            for (Type parameterType : type.parameterTypes) {
                String errorMessage = ensureValidType(parameterType, element);
                if (errorMessage != null) {
                    return errorMessage;
                }
            }
        }

        return null;
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:JsonFieldHolder.java

示例2: settingsFile

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private static String settingsFile(Element e) throws LayerGenerationException {
    String clazz, method;
    switch (e.getKind()) {
        case CLASS: clazz = e.toString(); method = null; break;
        case METHOD: clazz = e.getEnclosingElement().toString(); method = e.getSimpleName().toString(); break;
        default:
            throw new LayerGenerationException("Cannot work on given element", e);
    }
    StringBuilder sb = new StringBuilder();
    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    sb.append("<!DOCTYPE settings PUBLIC \"-//NetBeans//DTD Session settings 1.0//EN\" \"http://www.netbeans.org/dtds/sessionsettings-1_0.dtd\">\n");
    sb.append("<settings version=\"1.0\">\n");
    sb.append("  <instance class=\"").append(clazz).append("\"");
    if (method != null) {
        sb.append(" method=\"").append(method).append("\"");
    }
    sb.append("/>\n");
    sb.append("</settings>\n");
    return sb.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:TopComponentProcessor.java

示例3: parseToSurgeonMethod

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private SurgeonMethod parseToSurgeonMethod(Element element) {
    SurgeonMethod method = new SurgeonMethod();
    String args = ((ExecutableElement) element).getParameters().toString();
    String types = "";
    String additionParamsTypes = element.toString();
    int start = additionParamsTypes.indexOf("(");
    int end = additionParamsTypes.indexOf(")");
    if (end - start > 1) {
        // open1(java.lang.Object) => java.lang.Object.class)
        types = additionParamsTypes.substring(start + 1, end);
        if (types.lastIndexOf("...") != -1)
            types = types.replace("...", "[]");
        additionParamsTypes = getFullTypesString(types) + ")";
    } else {
        additionParamsTypes = ")";
    }

    //TODO maybe used in future
    //method.simpleParamsName = args;
    //method.simpleParamsTypes = types;
    method.simpleParamsName = "";
    method.simpleParamsTypes = "";
    method.method = "$T.class.getMethod($S," + additionParamsTypes;
    return method;
}
 
开发者ID:TangXiaoLv,项目名称:Surgeon,代码行数:26,代码来源:SurgeonProcessor.java

示例4: simpleVisibility

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private static void simpleVisibility(Set<Modifier> targetMods,
                                     PackageElement targetPkg,
                                     String fromPkg,
                                     Element target) {
    if (fromPkg == null) {
        if (!targetMods.contains(Modifier.PUBLIC)) {
            throw new EasyPluginException(target.toString() + " must be public.");
        }
    } else {
        // TODO this is terrible
        if ((!targetPkg.getQualifiedName().toString().equals(fromPkg)
                || targetMods.contains(Modifier.PROTECTED)
                || targetMods.contains(Modifier.PRIVATE))
                && !targetMods.contains(Modifier.PUBLIC)) {
            throw new EasyPluginException("Access modifiers block usage of " + target.toString());
        }
    }
}
 
开发者ID:c0d3d,项目名称:easy-plugins,代码行数:19,代码来源:Util.java

示例5: getPrimitiveArrayClassName

import javax.lang.model.element.Element; //导入方法依赖的package包/类
public static String getPrimitiveArrayClassName(Element element) {
    if (element.asType().getKind() != TypeKind.ARRAY) {
        throw new IllegalArgumentException("element is not array: " + element.toString());
    }

    ArrayType arrayType = (ArrayType) element.asType();
    TypeMirror componentType = arrayType.getComponentType();
    ClassName className = (ClassName) TypeName.get(componentType).box();
    return className.simpleName() + "Array";
}
 
开发者ID:srym,项目名称:vulture,代码行数:11,代码来源:TypeUtils.java

示例6: elementToName

import javax.lang.model.element.Element; //导入方法依赖的package包/类
public String elementToName(Element element) {
  switch (element.getKind()) {
    case CLASS:
      return element.toString();
    case METHOD:
      return element.getEnclosingElement().toString() + "." + element.toString();
    case CONSTRUCTOR:
      return element.getEnclosingElement().toString() + "." + element.toString();
    default:
      return element.toString();
  }
}
 
开发者ID:salesforce,项目名称:AptSpring,代码行数:13,代码来源:NamingTools.java

示例7: elementSignature

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private String elementSignature(Element el) {
    switch (el.getKind()) {
        case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE:
            return ((TypeElement) el).getQualifiedName().toString();
        case FIELD:
            return elementSignature(el.getEnclosingElement()) + "." + el.getSimpleName() + ":" + el.asType();
        case ENUM_CONSTANT:
            return elementSignature(el.getEnclosingElement()) + "." + el.getSimpleName();
        case EXCEPTION_PARAMETER: case LOCAL_VARIABLE: case PARAMETER: case RESOURCE_VARIABLE:
            return el.getSimpleName() + ":" + el.asType();
        case CONSTRUCTOR: case METHOD:
            StringBuilder header = new StringBuilder();
            header.append(elementSignature(el.getEnclosingElement()));
            if (el.getKind() == ElementKind.METHOD) {
                header.append(".");
                header.append(el.getSimpleName());
            }
            header.append("(");
            String sep = "";
            ExecutableElement method = (ExecutableElement) el;
            for (Iterator<? extends VariableElement> i = method.getParameters().iterator(); i.hasNext();) {
                VariableElement p = i.next();
                header.append(sep);
                header.append(p.asType());
                sep = ", ";
            }
            header.append(")");
            return header.toString();
       default:
            return el.toString();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:JavadocHelper.java

示例8: symbolToString

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private static String symbolToString(Element el) {
    switch (el.getKind()) {
        case METHOD: return symbolToString(el.getEnclosingElement()) + "." + el.toString();
        case CONSTRUCTOR: return symbolToString(el.getEnclosingElement().getEnclosingElement()) + "." + el.toString();
        default:
            return el.toString();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:TestGetElementReference.java

示例9: checkClassVisibility

import javax.lang.model.element.Element; //导入方法依赖的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

示例10: collectFields

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private List<Field> collectFields(TypeElement presentersContainer) {
	List<Field> fields = new ArrayList<>();

	outer:
	for (Element element : presentersContainer.getEnclosedElements()) {
		if (!(element instanceof VariableElement)) {
			continue;
		}

		final VariableElement presenterFieldElement = (VariableElement) element;

		for (AnnotationMirror annotationMirror : presenterFieldElement.getAnnotationMirrors()) {
			if (annotationMirror.getAnnotationType().asElement().toString().equals(PRESENTER_FIELD_ANNOTATION)) {
				String type = null;
				String tag = null;
				String presenterId = null;

				final String name = element.toString();
				TypeMirror clazz = ((DeclaredType) element.asType()).asElement().asType();

				final Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror.getElementValues();

				final Set<? extends ExecutableElement> keySet = elementValues.keySet();

				for (ExecutableElement executableElement : keySet) {
					String key = executableElement.getSimpleName().toString();

					if ("type".equals(key)) {
						type = elementValues.get(executableElement).getValue().toString();
					} else if ("tag".equals(key)) {
						tag = elementValues.get(executableElement).toString();
					} else if ("presenterId".equals(key)) {
						presenterId = elementValues.get(executableElement).toString();
					}
				}
				Field field = new Field(clazz, name, type, tag, presenterId);
				fields.add(field);
				continue outer;
			}
		}
	}
	return fields;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:44,代码来源:PresenterBinderClassGenerator.java

示例11: isJPAAttrAnnotation

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private boolean isJPAAttrAnnotation(CompilationInfo cinfo, AnnotationTree ann){
    TreePath path = cinfo.getTrees().getPath(cinfo.getCompilationUnit(), ann.getAnnotationType());
    Element elem = cinfo.getTrees().getElement(path);
    String annType = elem.toString();
    return JPAAnnotations.MEMBER_LEVEL.contains(annType);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:UnifyAccessType.java

示例12: getEnclosingClassName

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private String getEnclosingClassName(Element elementWithAnnotation1) {
    return elementWithAnnotation1.toString();
}
 
开发者ID:gradle,项目名称:incap,代码行数:4,代码来源:Processor1.java

示例13: process

import javax.lang.model.element.Element; //导入方法依赖的package包/类
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    Messager messager = this.processingEnv.getMessager();
    messager.printMessage(Kind.NOTE, "实现@LetvClassAutoLoad注解的class 数量: " + annotations.size());
    if (annotations.size() > 0) {
        String path = "./app/src/main/assets/";
        File folder = new File(path);
        if (!folder.exists()) {
            folder.mkdir();
        }
        try {
            File staticJsonFile = new File(path + "static.txt");
            if (!staticJsonFile.exists()) {
                staticJsonFile.createNewFile();
            }
            InputStreamReader inputReader = new InputStreamReader(new FileInputStream(staticJsonFile));
            BufferedReader bufReader = new BufferedReader(inputReader);
            Set<String> resultSet = new HashSet();
            while (true) {
                String line = bufReader.readLine();
                if (line == null) {
                    break;
                }
                resultSet.add(line);
            }
            bufReader.close();
            inputReader.close();
            boolean hasDif = false;
            for (TypeElement te : annotations) {
                for (Element e : roundEnv.getElementsAnnotatedWith(te)) {
                    String className = e.toString();
                    if (!resultSet.contains(className)) {
                        resultSet.add(className);
                        hasDif = true;
                    }
                }
            }
            if (hasDif) {
                messager.printMessage(Kind.NOTE, "更新class映射文件 static.txt");
                BufferedWriter outPut = new BufferedWriter(new FileWriter(staticJsonFile));
                for (String str : resultSet) {
                    outPut.write(str + "\n");
                    messager.printMessage(Kind.NOTE, "写入中: " + str);
                }
                outPut.close();
                messager.printMessage(Kind.NOTE, "更新class映射文件 static.txt 成功");
            } else {
                messager.printMessage(Kind.NOTE, "不存在未包含 class name");
                return true;
            }
        } catch (IOException e2) {
            e2.printStackTrace();
            messager.printMessage(Kind.NOTE, "更新class映射文件static.txt 失败 :  /app/src/main/assets/ 路径无效,请检查路径");
        }
    }
    return true;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:57,代码来源:LetvPluginAnnotationProcessor.java

示例14: process

import javax.lang.model.element.Element; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver()) {
        if (!processed) {
            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Did not find any annotated classes to generate a plugin.yml for...");
        }

        return false;
    }

    if (!containsAll(annotations, Cmd.class, Pl.class)) {
        return false;
    }

    try {
        for (Element pluginElement : roundEnv.getElementsAnnotatedWith(Pl.class)) {
            if (pluginElement.getKind() != ElementKind.CLASS)
                throw new ProcessingException(pluginElement, "cannot process non-class");

            TypeElement typeElement = (TypeElement) pluginElement;
            if (!processingEnv.getTypeUtils().isSubtype(typeElement.asType(), pluginType))
                throw new ProcessingException(pluginElement, "plugin is not a plugin type");

            String name = typeElement.getQualifiedName().toString();
            Pl annotation = typeElement.getAnnotation(Pl.class);

            Map<String, Command> commands = new HashMap<>();

            for (Element commandElement : roundEnv.getElementsAnnotatedWith(Cmd.class)) {
                if (commandElement.getKind() != ElementKind.CLASS)
                    throw new ProcessingException(commandElement, "You cannot annotate %s (%s) with @Cmd.",
                                                  commandElement.toString(), commandElement.getKind().toString());

                Cmd cmd = commandElement.getAnnotation(Cmd.class);
                if (cmd.disable())
                    continue;

                String commandName = cmd.value().trim();
                if (commandName.length() == 0)
                    throw new ProcessingException(commandElement, "invalid command name '%s'", commandName);

                if (!isVanillaCommandHandler(commandElement.asType()) && !processingEnv.getTypeUtils().isAssignable(commandElement.asType(), commandType))
                    throw new ProcessingException(commandElement, "The class '%s' was annotated with @Cmd, but does not implement '%s'!",
                                                  commandElement.toString(), commandType.toString());

                commands.put(commandName, new Command(commandElement.toString(), commandName, cmd));
            }

            FileObject pluginResource = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "plugin.yml");
            PluginSpec spec = new PluginSpec(name, annotation, commands);
            try (Writer writer = pluginResource.openWriter()) {
                try (BufferedWriter bufferedWriter = new BufferedWriter(writer)) {
                    bufferedWriter.write(PluginYamlProducer.generate(yaml, spec));
                    bufferedWriter.flush();
                }
            }

            if (commands.size() > 0) {
                FileObject commandsResource = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/.pl.commands.yml");
                try (Writer writer = commandsResource.openWriter()) {
                    try (BufferedWriter bufferedWriter = new BufferedWriter(writer)) {
                        bufferedWriter.write(CommandMapProducer.commandMapProducer(yaml, commands));
                        bufferedWriter.flush();
                    }
                }
            }

            messager.printMessage(Diagnostic.Kind.NOTE, "wrote plugin.yml for " + PluginYamlProducer.getName(spec));
            processed = true;
        }
    } catch (ProcessingException e) {
        error(e.getElement(), e.getMessage());
    } catch (Throwable t) {
        error(null, t.getMessage());
        t.printStackTrace();
    }

    return true;
}
 
开发者ID:Twister915,项目名称:pl,代码行数:80,代码来源:PluginYamlAnnotationProcessor.java

示例15: getThrownException

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private String getThrownException(JavacTask task, TreePath rootOn, DocCommentTree comment, ThrowsTree tt) {
    DocTrees trees = DocTrees.instance(task);
    Element exc = trees.getElement(new DocTreePath(new DocTreePath(rootOn, comment), tt.getExceptionName()));
    return exc != null ? exc.toString() : null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:JavadocHelper.java


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