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


Java ClassOrInterfaceDeclaration.getMembers方法代碼示例

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


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

示例1: visit

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入方法依賴的package包/類
@Override
public void visit(ClassOrInterfaceDeclaration clazz, Object arg) {
    for (BodyDeclaration member : clazz.getMembers()) {
        if (member instanceof ClassOrInterfaceDeclaration)
            visit((ClassOrInterfaceDeclaration)member, arg);
        else if (member instanceof FieldDeclaration) {
            FieldDeclaration field = (FieldDeclaration)member;
            String type = null != field.getType() ? field.getType().toString() : "";
            if (type.equals("int")) {
                VariableDeclarator variable = field.getVariables().stream().findFirst().get();
                String name = variable.getId().toString();
                Integer value = null != variable.getInit() ? Integer.parseInt(variable.getInit().toString()) : 0;
                // decimal value of 0x7f000000, which is what AAPT starts numbering at - http://stackoverflow.com/a/6646113/311304
                if (value >= 2130706432) {
                    name = "R." + ((ClassOrInterfaceDeclaration)field.getParentNode()).getName() + "." + name;
                    transform.put(value, name);
                }
            }
        }
    }
}
 
開發者ID:justingarrick,項目名稱:android-reverse-r,代碼行數:22,代碼來源:Reverser.java

示例2: visit

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入方法依賴的package包/類
@Override
public void visit(ClassOrInterfaceDeclaration n, Object arg) {
  super.visit(n, arg);
  final EnumSet<Modifier> modifiers = n.getModifiers();
  if (!modifiers.contains(Modifier.PRIVATE)) {
    final List<BodyDeclaration<?>> members = n.getMembers();
    final SimpleName simpleName = n.getName();
    final String clazz = simpleName.getId();
    // String clazz = n.getName();
    this.className = this.pkg + '.' + clazz;
    log.debug("class {}", this.className);
    int i = 0;
    for (final BodyDeclaration<?> body : members) {
      if (body instanceof MethodDeclaration) {
        MethodDeclaration methodDeclaration = (MethodDeclaration) body;
        this.getParameterNames(methodDeclaration, n.isInterface());
        i++;
      } else if (body instanceof ConstructorDeclaration) {
        // Constructor
      } else if (body instanceof ClassOrInterfaceDeclaration) {
        final ClassOrInterfaceDeclaration classOrInterfaceDeclaration =
            (ClassOrInterfaceDeclaration) body;
        String name = classOrInterfaceDeclaration.getName().getIdentifier();
        String key = this.pkg + '.' + name;
        name = this.originClassName + '.' + name;
        for (MethodParameterNames mpn : this.parameterNamesList) {
          if (mpn != null && mpn.className != null && mpn.className.equals(key)) {
            mpn.className = name;
          }
        }
      }
    }

    if (i > 0 && this.names.className != null) {
      this.parameterNamesList.add(this.names);
      this.names = new MethodParameterNames();
    }
  }
}
 
開發者ID:mopemope,項目名稱:meghanada-server,代碼行數:40,代碼來源:ParameterNameVisitor.java

示例3: addResourceType

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入方法依賴的package包/類
/**
 * 複製資源 內部 class 到 R2 class 中
 *
 * 這裏是給 R2 的 TypeSpec 添加生成局域
 *
 * @param supportedTypes 支持的類型( "array", "attr", "bool", "color", "dimen", "drawable", "id",
 * "integer", "string" )
 * @param result R2 的 TypeSpec
 * @param node R 的 接口或者類 ClassOrInterfaceDeclaration
 */
private static void addResourceType(List<String> supportedTypes, TypeSpec.Builder result,
                                    ClassOrInterfaceDeclaration node) {

    // 判斷是否是資源內部類( "array", "attr", "bool", "color", "dimen", "drawable", "id", "integer", "string" )
    if (!supportedTypes.contains(node.getNameAsString())) {
        return;
    }

    // 創建 R2 的內部類 TypeSpec,為了進行資源複製
    String type = node.getNameAsString();
    TypeSpec.Builder resourceType = TypeSpec.classBuilder(type)
        .addModifiers(PUBLIC, STATIC, FINAL);

    /*
     * 遍曆 R 內部類的每個資源 field
     * 然後給 R2 的內部類 TypeSpec 添加 field 生成語句
     */
    for (BodyDeclaration field : node.getMembers()) {
        if (field instanceof FieldDeclaration) {
            addResourceField(resourceType, ((FieldDeclaration) field).getVariables().get(0),
                getSupportAnnotationClass(type));
        }
    }

    // R2 的內部類 TypeSpec 添加到 R2 TypeSpec 內
    result.addType(resourceType.build());
}
 
開發者ID:CaMnter,項目名稱:AndroidLife,代碼行數:38,代碼來源:R2ClassBuilder.java

示例4: visit

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入方法依賴的package包/類
@Override public Node visit(final ClassOrInterfaceDeclaration n, final A arg) {
	visitAnnotations(n, arg);
	visitComment(n, arg);
	final List<TypeParameter> typeParameters = n.getTypeParameters();
	if (typeParameters != null) {
		for (int i = 0; i < typeParameters.size(); i++) {
			typeParameters.set(i, (TypeParameter) typeParameters.get(i).accept(this, arg));
		}
		removeNulls(typeParameters);
	}
	final List<ClassOrInterfaceType> extendz = n.getExtends();
	if (extendz != null) {
		for (int i = 0; i < extendz.size(); i++) {
			extendz.set(i, (ClassOrInterfaceType) extendz.get(i).accept(this, arg));
		}
		removeNulls(extendz);
	}
	final List<ClassOrInterfaceType> implementz = n.getImplements();
	if (implementz != null) {
		for (int i = 0; i < implementz.size(); i++) {
			implementz.set(i, (ClassOrInterfaceType) implementz.get(i).accept(this, arg));
		}
		removeNulls(implementz);
	}
       final List<BodyDeclaration<?>> members = n.getMembers();
	if (members != null) {
		for (int i = 0; i < members.size(); i++) {
               members.set(i, (BodyDeclaration<?>) members.get(i).accept(this, arg));
		}
		removeNulls(members);
	}
	return n;
}
 
開發者ID:javaparser,項目名稱:javasymbolsolver,代碼行數:34,代碼來源:ModifierVisitorAdapter.java

示例5: visit

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入方法依賴的package包/類
@Override
  public Node visit(final ClassOrInterfaceDeclaration n, final Object arg) {

      if (!(n.isInterface())) {

          // Preserve the value of flag indicating that enclosing class
          // has found the default constructor.
          boolean storedprev = founddefault;
          founddefault = false;

          // Generates a new list, which might even be empty.
          Vector<BodyDeclaration> lnewlist = new Vector<BodyDeclaration>();

/* Code for unfolding field declaration */
          if (n.getMembers() != null) {
              for (final BodyDeclaration b : n.getMembers()) {
                  BodyDeclaration mydecl = (BodyDeclaration) b.accept(this, arg);

                  // Append the expanded list to list of bodydeclaration
                  if (mydecl instanceof ListFieldDeclaration) {
                      lnewlist.addAll(((ListFieldDeclaration) mydecl).getVarDecls());
                  } else {
                      lnewlist.add(mydecl);
                  }
              }
          }

/*
        Code for detecting declaration of default contructor.
 Clone metadata from class declaration.
 */
          if (!(founddefault)) {
              lnewlist.add(new ConstructorDeclaration(n.getModifiers(),
                      new Vector<AnnotationExpr>(),
                      new Vector<TypeParameter>(),
                      n.getName(),
                      new Vector<Parameter>(),
                      new Vector<NameExpr>(),
                      new BlockStmt(new Vector<Statement>())));
          }

          // Restore the value for the flag relative to enclosing class
          founddefault = storedprev;

          // Set the generated list
          n.setMembers(lnewlist);
      }

      return n;
  }
 
開發者ID:pcgomes,項目名稱:javaparser2jctree,代碼行數:51,代碼來源:ComplyToJCVisitor.java

示例6: visit

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入方法依賴的package包/類
@Override public Node visit(final ClassOrInterfaceDeclaration n, final A arg) {
	if (n.getJavaDoc() != null) {
		n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg));
	}
	final List<AnnotationExpr> annotations = n.getAnnotations();
	if (annotations != null) {
		for (int i = 0; i < annotations.size(); i++) {
			annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg));
		}
		removeNulls(annotations);
	}
	final List<TypeParameter> typeParameters = n.getTypeParameters();
	if (typeParameters != null) {
		for (int i = 0; i < typeParameters.size(); i++) {
			typeParameters.set(i, (TypeParameter) typeParameters.get(i).accept(this, arg));
		}
		removeNulls(typeParameters);
	}
	final List<ClassOrInterfaceType> extendz = n.getExtends();
	if (extendz != null) {
		for (int i = 0; i < extendz.size(); i++) {
			extendz.set(i, (ClassOrInterfaceType) extendz.get(i).accept(this, arg));
		}
		removeNulls(extendz);
	}
	final List<ClassOrInterfaceType> implementz = n.getImplements();
	if (implementz != null) {
		for (int i = 0; i < implementz.size(); i++) {
			implementz.set(i, (ClassOrInterfaceType) implementz.get(i).accept(this, arg));
		}
		removeNulls(implementz);
	}
	final List<BodyDeclaration> members = n.getMembers();
	if (members != null) {
		for (int i = 0; i < members.size(); i++) {
			members.set(i, (BodyDeclaration) members.get(i).accept(this, arg));
		}
		removeNulls(members);
	}
	return n;
}
 
開發者ID:plum-umd,項目名稱:java-sketch,代碼行數:42,代碼來源:ModifierVisitorAdapter.java


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