當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。