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


Java VariableElement类代码示例

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


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

示例1: dumpArguments

import javax.lang.model.element.VariableElement; //导入依赖的package包/类
private void dumpArguments(List<? extends VariableElement> list, List<? extends TypeMirror> types) {
    boolean addSpace = false;
    
    result.append('(');

    Iterator<? extends VariableElement> listIt = list.iterator();
    Iterator<? extends TypeMirror> typesIt = types != null ? types.iterator() : null;

    while (listIt.hasNext()) {
        if (addSpace) {
            result.append(", ");
        }
        
        VariableElement ve = listIt.next();
        TypeMirror      type = typesIt != null ? typesIt.next() : ve.asType();

        result.append(getTypeName(info, type, true));
        result.append(" ");
        result.append(ve.getSimpleName());

        addSpace = true;
    }
        
    result.append(')');
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:GoToSupport.java

示例2: createSetter

import javax.lang.model.element.VariableElement; //导入依赖的package包/类
/**
 * Creates a setter method for a field.
 *
 * @param clazz the class to create the setter within
 * @param field field to create setter for
 * @return the setter method
 * @since 0.20
 */
public MethodTree createSetter(TypeElement clazz, VariableElement field) {
    assert clazz != null && field != null;
    TreeMaker make = copy.getTreeMaker();
    CodeStyle cs = DiffContext.getCodeStyle(copy);
    Set<Modifier> mods = EnumSet.of(Modifier.PUBLIC);
    boolean isStatic = field.getModifiers().contains(Modifier.STATIC);
    if (isStatic) {
        mods.add(Modifier.STATIC);
    }
    CharSequence name = field.getSimpleName();
    assert name.length() > 0;
    TypeMirror type = copy.getTypes().asMemberOf((DeclaredType)clazz.asType(), field);
    String setterName = CodeStyleUtils.computeSetterName(field.getSimpleName(), isStatic, cs);
    String paramName = addParamPrefixSuffix(removeFieldPrefixSuffix(field, cs), cs);
    List<VariableTree> params = Collections.singletonList(make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), paramName, make.Type(type), null));
    BlockTree body = make.Block(Collections.singletonList(make.ExpressionStatement(make.Assignment(make.MemberSelect(isStatic? make.Identifier(field.getEnclosingElement().getSimpleName()) : make.Identifier("this"), name), make.Identifier(paramName)))), false); //NOI18N
    return make.Method(make.Modifiers(mods), setterName, make.Type(copy.getTypes().getNoType(TypeKind.VOID)), Collections.<TypeParameterTree>emptyList(), params, Collections.<ExpressionTree>emptyList(), body, null);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:GeneratorUtilities.java

示例3: visitVariable

import javax.lang.model.element.VariableElement; //导入依赖的package包/类
@Override
public State visitVariable(VariableTree node, Void p) {
    Element e = info.getTrees().getElement(getCurrentPath());
    Map<VariableElement, State> orig = new HashMap<>(variable2State);
    State r = scan(node.getInitializer(), p);
    
    mergeHypotheticalVariable2State(orig);
    
    if (e != null) {
        variable2State.put((VariableElement) e, r);
        TreePath pp = getCurrentPath().getParentPath();
        if (pp != null) {
            addScopedVariable(pp.getLeaf(), (VariableElement)e);
        }
    }
    
    return r;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:NPECheck.java

示例4: run

import javax.lang.model.element.VariableElement; //导入依赖的package包/类
public void run(WorkingCopy copy) throws Exception {
    copy.toPhase(JavaSource.Phase.RESOLVED);
    TreePath tp = copy.getTreeUtilities().pathFor(offset);
    assertTrue(TreeUtilities.CLASS_TREE_KINDS.contains(tp.getLeaf().getKind()));
    ClassTree ct = (ClassTree)tp.getLeaf();
    TypeElement te = (TypeElement)copy.getTrees().getElement(tp);
    assertNotNull(te);
    List<? extends VariableElement> vars = ElementFilter.fieldsIn(te.getEnclosedElements());
    TypeElement sup = (TypeElement)((DeclaredType)te.getSuperclass()).asElement();
    assertNotNull(sup);
    List<? extends ExecutableElement> ctors = sup.getQualifiedName().contentEquals("java.lang.Object")
            ? null : ElementFilter.constructorsIn(sup.getEnclosedElements());
    if (ctors != null)
        assertEquals(numCtors, ctors.size());
    GeneratorUtilities utilities = GeneratorUtilities.get(copy);
    assertNotNull(utilities);
    ClassTree newCt = utilities.insertClassMember(ct, utilities.createConstructor(te, vars, ctors != null ? ctors.get(ctorToUse) : null));
    copy.rewrite(ct, newCt);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:GeneratorUtilitiesTest.java

示例5: getFragment

import javax.lang.model.element.VariableElement; //导入依赖的package包/类
@NonNull
private static Collection<? extends CharSequence> getFragment(Element e) {
    final FragmentBuilder fb = new FragmentBuilder();
    if (!e.getKind().isClass() && !e.getKind().isInterface()) {
        if (e.getKind() == ElementKind.CONSTRUCTOR) {
            fb.append(e.getEnclosingElement().getSimpleName());
        } else {
            fb.append(e.getSimpleName());
        }
        if (e.getKind() == ElementKind.METHOD || e.getKind() == ElementKind.CONSTRUCTOR) {
            ExecutableElement ee = (ExecutableElement) e;
            fb.append("("); //NOI18N
            for (Iterator<? extends VariableElement> it = ee.getParameters().iterator(); it.hasNext();) {
                VariableElement param = it.next();
                appendType(fb, param.asType(), ee.isVarArgs() && !it.hasNext());
                if (it.hasNext()) {
                    fb.append(", ");    //NOI18N
                }
            }
            fb.append(")"); //NOI18N
        }
    }
    return fb.getFragments();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:JavadocHelper.java

示例6: isInjectionRequired

import javax.lang.model.element.VariableElement; //导入依赖的package包/类
private boolean isInjectionRequired( @Nonnull final TypeElement typeElement )
{
  final VariableElement injectParameter = (VariableElement)
    ProcessorUtil.getAnnotationValue( processingEnv.getElementUtils(),
                                      typeElement,
                                      Constants.REACT_COMPONENT_ANNOTATION_CLASSNAME,
                                      "inject" ).getValue();
  switch ( injectParameter.getSimpleName().toString() )
  {
    case "ENABLE":
      return true;
    case "DISABLE":
      return false;
    default:
      return ProcessorUtil.getFieldElements( typeElement ).stream().anyMatch( this::hasInjectAnnotation ) ||
             ProcessorUtil.getMethods( typeElement, processingEnv.getTypeUtils() ).
               stream().anyMatch( this::hasInjectAnnotation );
  }
}
 
开发者ID:react4j,项目名称:react4j,代码行数:20,代码来源:ReactProcessor.java

示例7: generateRequestOptionOverride

import javax.lang.model.element.VariableElement; //导入依赖的package包/类
private MethodSpec generateRequestOptionOverride(ExecutableElement methodToOverride) {
  return MethodSpec.overriding(methodToOverride)
      .returns(glideOptionsName)
      .addCode(CodeBlock.builder()
          .add("return ($T) super.$N(", glideOptionsName, methodToOverride.getSimpleName())
          .add(FluentIterable.from(methodToOverride.getParameters())
              .transform(new Function<VariableElement, String>() {
                @Override
                public String apply(VariableElement input) {
                  return input.getSimpleName().toString();
                }
              })
              .join(Joiner.on(", ")))
          .add(");\n")
          .build())
      .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:RequestOptionsGenerator.java

示例8: isMethodDeclaredByInterface

import javax.lang.model.element.VariableElement; //导入依赖的package包/类
/**
 * Checks whether the interface declare given method
 *
 * @param trgInterface interface to be declaring the method
 * @param srcMethod method to be declared
 * @return {@code true} if the method is declared by the interface, {@code false} otherwise
 */
private static boolean isMethodDeclaredByInterface(TypeElement trgInterface, ExecutableElement srcMethod) {
    List<? extends Element> enclosedElements = trgInterface.getEnclosedElements();
    List<? extends VariableElement> methodParameters = srcMethod.getParameters();
    for (Element enclosedElement : enclosedElements) {
        if (enclosedElement instanceof ExecutableElement) {
            ExecutableElement exElement = (ExecutableElement) enclosedElement;
            List<? extends VariableElement> elementParameters = exElement.getParameters();
            if (srcMethod.getSimpleName() != exElement.getSimpleName()
                    || (methodParameters.size() != elementParameters.size())) {
                continue;
            }
            for (int i = 0; i < methodParameters.size(); i++) {
                if (!((VariableElement) methodParameters.get(i)).asType().toString().equals(
                        ((VariableElement) elementParameters.get(i)).asType().toString())) {
                    continue;
                }
            }
            return true;
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:AbstractTestGenerator.java

示例9: emitPersistedFieldAccessors

import javax.lang.model.element.VariableElement; //导入依赖的package包/类
private void emitPersistedFieldAccessors(final JavaWriter writer) throws IOException {
    for (final VariableElement field : metadata.getFields()) {
        final String fieldName = field.getSimpleName().toString();
        final String fieldTypeCanonicalName = field.asType().toString();

        if (Constants.JAVA_TO_REALM_TYPES.containsKey(fieldTypeCanonicalName)) {
            emitPrimitiveType(writer, field, fieldName, fieldTypeCanonicalName);
        } else if (Utils.isMutableRealmInteger(field)) {
            emitMutableRealmInteger(writer, field, fieldName, fieldTypeCanonicalName);
        } else if (Utils.isRealmModel(field)) {
            emitRealmModel(writer, field, fieldName, fieldTypeCanonicalName);
        } else if (Utils.isRealmList(field)) {
            final TypeMirror elementTypeMirror = TypeMirrors.getRealmListElementTypeMirror(field);
            emitRealmList(writer, field, fieldName, fieldTypeCanonicalName, elementTypeMirror);
        } else {
            throw new UnsupportedOperationException(String.format(Locale.US,
                    "Field \"%s\" of type \"%s\" is not supported.", fieldName, fieldTypeCanonicalName));
        }

        writer.emitEmptyLine();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:RealmProxyClassGenerator.java

示例10: generateGettersAndSetters

import javax.lang.model.element.VariableElement; //导入依赖的package包/类
public static void generateGettersAndSetters(WorkingCopy wc, TreePath path, Iterable<? extends VariableElement> fields, int type, int offset) {
    assert TreeUtilities.CLASS_TREE_KINDS.contains(path.getLeaf().getKind());
    TypeElement te = (TypeElement)wc.getTrees().getElement(path);
    if (te != null) {
        GeneratorUtilities gu = GeneratorUtilities.get(wc);
        ClassTree clazz = (ClassTree)path.getLeaf();
        List<Tree> members = new ArrayList<>();
        for(VariableElement element : fields) {
            if (type != SETTERS_ONLY) {
                members.add(gu.createGetter(te, element));
            }
            if (type != GETTERS_ONLY) {
                members.add(gu.createSetter(te, element));
            }
        }
        wc.rewrite(clazz, insertClassMembers(wc, clazz, members, offset));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:GeneratorUtils.java

示例11: deepSame

import javax.lang.model.element.VariableElement; //导入依赖的package包/类
/**
 * 两组参数类型相同
 */
public static boolean deepSame(List<? extends VariableElement> _this, List<? extends VariableElement> _that) {
    if (null == _this && null == _that) {
        return true;
    }

    if (null == _this || null == _that) {
        return false;
    }

    if (_this.size() != _that.size()) {
        return false;
    }

    for (int i = 0, len = _this.size(); i < len; i++) {
        VariableElement _thisEle = _this.get(i);
        VariableElement _thatEle = _that.get(i);

        if (!MoreElements.asType(_thisEle).getQualifiedName().toString()
                .equals(MoreElements.asType(_thatEle).getQualifiedName().toString())) {
            return false;
        }
    }

    return true;
}
 
开发者ID:wangjiegulu,项目名称:RapidRouter,代码行数:29,代码来源:ElementUtil.java

示例12: makeVariableString

import javax.lang.model.element.VariableElement; //导入依赖的package包/类
/**
 * Creates a String representation of a variable element with everything
 * necessary to track all public aspects of it in an API.
 * @param e Element to create String for.
 * @return String representation of element.
 */
protected String makeVariableString(VariableElement e) {
    StringBuilder result = new StringBuilder();
    for (Modifier modifier : e.getModifiers()) {
        result.append(modifier.toString());
        result.append(" ");
    }
    result.append(e.asType().toString());
    result.append(" ");
    result.append(e.toString());
    Object value = e.getConstantValue();
    if (value != null) {
        result.append(" = ");
        if (e.asType().toString().equals("char")) {
            int v = (int)value.toString().charAt(0);
            result.append("'\\u"+Integer.toString(v,16)+"'");
        } else {
            result.append(value.toString());
        }
    }
    return result.toString();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:PubapiVisitor.java

示例13: findFieldElementOnType

import javax.lang.model.element.VariableElement; //导入依赖的package包/类
public static VariableElement findFieldElementOnType(ElementUtilities eu, TypeMirror type, String fieldName) {
    FieldAcceptor fieldAcceptor = new FieldAcceptor(fieldName);
    Iterable<? extends Element> matchingProp = eu.getMembers(type, fieldAcceptor);
    Iterator<? extends Element> it = matchingProp.iterator();
    
    // no matching element found
    if (!it.hasNext()) {
        return null;
    } else
        return (VariableElement)it.next();
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:JPAEditorUtil.java

示例14: addParam

import javax.lang.model.element.VariableElement; //导入依赖的package包/类
/**
 * Add the parameter for the executable member.
 *
 * @param member the member to write parameter for.
 * @param param the parameter that needs to be written.
 * @param isVarArg true if this is a link to var arg.
 * @param tree the content tree to which the parameter information will be added.
 */
protected void addParam(ExecutableElement member, VariableElement param,
        boolean isVarArg, Content tree) {
    Content link = writer.getLink(new LinkInfoImpl(configuration, EXECUTABLE_MEMBER_PARAM,
            param.asType()).varargs(isVarArg));
    tree.addContent(link);
    if(name(param).length() > 0) {
        tree.addContent(Contents.SPACE);
        tree.addContent(name(param));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:AbstractExecutableMemberWriter.java

示例15: findIntrinsifyFactoryMethod

import javax.lang.model.element.VariableElement; //导入依赖的package包/类
private List<ExecutableElement> findIntrinsifyFactoryMethod(TypeElement nodeClass, TypeMirror[] signature, Map<ExecutableElement, String> nonMatches, boolean requiresInjectedStamp) {
    List<ExecutableElement> methods = ElementFilter.methodsIn(nodeClass.getEnclosedElements());
    List<ExecutableElement> found = new ArrayList<>(methods.size());
    for (ExecutableElement method : methods) {
        if (!method.getSimpleName().toString().equals("intrinsify")) {
            continue;
        }

        if (method.getParameters().size() < 2) {
            continue;
        }

        VariableElement firstArg = method.getParameters().get(0);
        if (!isTypeCompatible(firstArg.asType(), graphBuilderContextType())) {
            continue;
        }

        VariableElement secondArg = method.getParameters().get(1);
        if (!isTypeCompatible(secondArg.asType(), resolvedJavaMethodType())) {
            continue;
        }

        if (method.getReturnType().getKind() != TypeKind.BOOLEAN) {
            continue;
        }

        if (matchSignature(2, method, signature, nonMatches, requiresInjectedStamp)) {
            found.add(method);
        }
    }
    return found;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:NodeIntrinsicVerifier.java


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