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


Java ElementFilter.fieldsIn方法代碼示例

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


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

示例1: getParcelableFieldsOrError

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
/**
 * This method returns a list of all non private fields. If any <code>private</code> fields is
 * found, the method errors out
 *
 * @param type element
 * @return list of all non-<code>private</code> fields
 */
private List<VariableElement> getParcelableFieldsOrError(TypeElement type) {
    List<VariableElement> allFields = ElementFilter.fieldsIn(type.getEnclosedElements());
    List<VariableElement> nonPrivateFields = new ArrayList<>();

    for (VariableElement field : allFields) {
        if (!field.getModifiers().contains(PRIVATE)) {
            nonPrivateFields.add(field);
        } else {
            // return error, PRIVATE fields are not allowed
            mErrorReporter.abortWithError("getFieldsError error, PRIVATE fields not allowed", type);
        }
    }

    return nonPrivateFields;
}
 
開發者ID:foodora,項目名稱:android-auto-mapper,代碼行數:23,代碼來源:AutoMappperProcessor.java

示例2: run

import javax.lang.model.util.ElementFilter; //導入方法依賴的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());
    assertEquals(1, vars.size());
    GeneratorUtilities utilities = GeneratorUtilities.get(copy);
    assertNotNull(utilities);
    ClassTree newCt = utilities.insertClassMember(ct, getter
            ? utilities.createGetter(te, vars.get(0))
            : utilities.createSetter(te, vars.get(0)));
    copy.rewrite(ct, newCt);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:GeneratorUtilitiesTest.java

示例3: visitClass

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
@Override
public synchronized Void visitClass(ClassTree t, Void v) {
    Element el = info.getTrees().getElement(getCurrentPath());
    if (el == null) {
        return null;
    }
    TypeElement te = (TypeElement) el;
    List<VariableElement> fields = ElementFilter.fieldsIn(te.getEnclosedElements());
    enumConsts = new LinkedList<String>();
    for (VariableElement field : fields) {
        if (field.getKind() == ElementKind.ENUM_CONSTANT) {
            String name = field.getSimpleName().toString();
            enumConsts.add(name);
        }
    }
    return null;
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:18,代碼來源:EnumStructureFactory.java

示例4: collectTypedefs

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
private void collectTypedefs(TypeElement type, Map<String, TypeMirror> collected) {
  for (VariableElement field : ElementFilter.fieldsIn(elements.getAllMembers(type))) {
    if (field.getAnnotation(Generator.Typedef.class) != null) {
      collected.put(field.getSimpleName().toString(), field.asType());
    }
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:Imports.java

示例5: findSerialVersionUID

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
private Long findSerialVersionUID() {
  for (VariableElement field : ElementFilter.fieldsIn(element.getEnclosedElements())) {
    if (field.getSimpleName().contentEquals(SERIAL_VERSION_FIELD_NAME)
        && field.asType().getKind() == TypeKind.LONG) {
      return (Long) field.getConstantValue();
    }
  }
  return null;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:ValueType.java

示例6: getField

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
public static VariableElement getField(TypeElement clazz, String fieldName) {
    for (VariableElement field : ElementFilter.fieldsIn(clazz.getEnclosedElements())) {
        if (field.getSimpleName().contentEquals(fieldName)) {
            return field;
        }
    }

    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:Utils.java

示例7: guessField

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
public static VariableElement guessField(ExecutableElement getter) {
    String name = getter.getSimpleName().toString().substring(3);
    String guessFieldName = name.substring(0,1).toLowerCase() + name.substring(1);
    TypeElement typeElement = (TypeElement) getter.getEnclosingElement();
    for (VariableElement variableElement : ElementFilter.fieldsIn(typeElement.getEnclosedElements())) {
        if (variableElement.getSimpleName().contentEquals(guessFieldName)) {
            return variableElement;
        }
    }
    Logger.getLogger(JpaControllerUtil.class.getName()).log(Level.WARNING, "Cannot detect the field associated with property: {0}", guessFieldName);
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,代碼來源:JpaControllerUtil.java

示例8: guessGetter

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
/**
 * TODO: actually it's guess setter from setter, need to review if it's a problem of expected
 * @param setter
 * @return 
 */
public static VariableElement guessGetter(ExecutableElement setter) {
    String name = setter.getSimpleName().toString().substring(3);
    String guessGetterName = "set" + name;
    TypeElement typeElement = (TypeElement) setter.getEnclosingElement();
    for (VariableElement variableElement : ElementFilter.fieldsIn(typeElement.getEnclosedElements())) {
        if (variableElement.getSimpleName().contentEquals(guessGetterName)) {
            return variableElement;
        }
    }
    Logger.getLogger(JpaControllerUtil.class.getName()).log(Level.INFO, "Cannot detect setter associated with getter: {0}", guessGetterName);
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:JpaControllerUtil.java

示例9: doTwoWordFields

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
private int doTwoWordFields(FieldDefsRes res, TypeElement clazz,
                            int offset, String cname, boolean padWord) {
    boolean first = true;
    List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements());

    for (VariableElement field: fields) {
        TypeKind tk = field.asType().getKind();
        boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE);
        if (twoWords && doField(res, field, cname, first && padWord)) {
            offset += 8; first = false;
        }
    }
    return offset;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:15,代碼來源:LLNI.java

示例10: isLegalSei

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
protected boolean isLegalSei(TypeElement interfaceElement) {
    for (VariableElement field : ElementFilter.fieldsIn(interfaceElement.getEnclosedElements()))
        if (field.getConstantValue() != null) {
            builder.processError(WebserviceapMessages.WEBSERVICEAP_SEI_CANNOT_CONTAIN_CONSTANT_VALUES(
                    interfaceElement.getQualifiedName(), field.getSimpleName()));
            return false;
        }
    return methodsAreLegal(interfaceElement);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:WebServiceVisitor.java

示例11: write

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
protected void write(OutputStream o, TypeElement clazz) throws Util.Exit {
    try {
        String cname     = mangleClassName(clazz.getQualifiedName().toString());
        PrintWriter pw   = wrapWriter(o);
        fields = ElementFilter.fieldsIn(clazz.getEnclosedElements());
        methods = ElementFilter.methodsIn(clazz.getEnclosedElements());
        generateDeclsForClass(pw, clazz, cname);
        // FIXME check if errors occurred on the PrintWriter and throw exception if so
    } catch (TypeSignature.SignatureException e) {
        util.error("llni.sigerror", e.getMessage());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:LLNI.java

示例12: getValueMember

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
public static VariableElement getValueMember(TypeElement type) {
    VariableElement member = null;
    for (VariableElement field : ElementFilter.fieldsIn(type.getEnclosedElements())) {
        if ("value".equals(field.getSimpleName().toString())) {
            member = field;
            break;
        }
    }
    if (member == null && type.getKind().equals(ElementKind.CLASS))
        member = getValueMember(type.getSuperclass());
    return member;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:13,代碼來源:TypeModeler.java

示例13: getPropertyChangeSupport

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
private VariableTree getPropertyChangeSupport(javax.lang.model.element.TypeElement node, String support) {
    TypeElement supportElement = workingCopy.getElements().getTypeElement(support);
    if(supportElement != null) {
        for (VariableElement el : ElementFilter.fieldsIn(node.getEnclosedElements())) {
            if (el.asType().equals(supportElement.asType())) {
                return (VariableTree) workingCopy.getTrees().getPath(el).getLeaf();
            }
        }
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:EncapsulateFieldRefactoringPlugin.java

示例14: getDeclaredField

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
public VariableElement getDeclaredField(TypeElement clazz, String fieldName) {
    for (VariableElement fd : ElementFilter.fieldsIn(clazz.getEnclosedElements())) {
        if (fd.getSimpleName().toString().equals(fieldName))
            return fd;
    }
    return null;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:8,代碼來源:ApNavigator.java

示例15: complete

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
@Override
public List<CompletionItem> complete() {
    // get type of the enclosing instance
    FxInstance inst = (FxInstance)ctx.getElementParent();
    TypeElement instType = inst.getJavaType().resolve(ctx.getCompilationInfo());
    TypeElement ct = controllerType.resolve(ctx.getCompilationInfo());
    if (ct == null) {
        return null;
    }
    
    List<CompletionItem> items = new ArrayList<CompletionItem>();
    for (VariableElement v : ElementFilter.fieldsIn(
            ctx.getCompilationInfo().getElements().getAllMembers(ct))) {
        if (!FxClassUtils.isFxmlAccessible(v)) {
            continue;
        }
        // do not suggest a variable, whose ID is used elsewhere:
        String sn = v.getSimpleName().toString();
        if (ctx.getModel().getInstance(sn) != null) {
            continue;
        }
        // check that the instance is assignable to the var
        if (ctx.getCompilationInfo().getTypes().isAssignable(instType.asType(), v.asType())) {
            ValueItem vi = new ValueItem(
                ctx,
                v.getSimpleName().toString(),
                ICON_RESOURCE
            );
            vi.setAttribute(ctx.getType() == CompletionContext.Type.PROPERTY_VALUE);
            items.add(vi);
        }
    }
    
    return items;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:36,代碼來源:FxIdCompleter.java


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