本文整理汇总了Java中com.github.javaparser.ast.expr.MemberValuePair类的典型用法代码示例。如果您正苦于以下问题:Java MemberValuePair类的具体用法?Java MemberValuePair怎么用?Java MemberValuePair使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemberValuePair类属于com.github.javaparser.ast.expr包,在下文中一共展示了MemberValuePair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderManyToOneAnnotations
import com.github.javaparser.ast.expr.MemberValuePair; //导入依赖的package包/类
private void renderManyToOneAnnotations(MethodDeclaration getter) {
/*
* We need JoinColumn and ManyToOne
*/
NormalAnnotationExpr m2o = createOrFindAnnotation(getter, "javax.persistence.ManyToOne");
MemberValuePair fetch = findAnnotationPair(m2o, "fetch");
if(null == fetch) {
importIf("javax.persistence.FetchType");
m2o.addPair("fetch", "FetchType.LAZY");
}
MemberValuePair p = findAnnotationPair(m2o, "optional");
if(null == p) {
m2o.addPair("optional", Boolean.toString(m_column.isNullable()));
} else {
p.setValue(new BooleanLiteralExpr(m_column.isNullable()));
}
NormalAnnotationExpr na = createOrFindAnnotation(getter, "javax.persistence.JoinColumn");
p = findAnnotationPair(na, "name");
if(null == p) {
na.addPair("name", "\"" + m_column.getName() + "\"");
} else {
p.setValue(new StringLiteralExpr(m_column.getName()));
}
}
示例2: createOrFindAnnotation
import com.github.javaparser.ast.expr.MemberValuePair; //导入依赖的package包/类
protected NormalAnnotationExpr createOrFindAnnotation(BodyDeclaration<?> getter, String fullAnnotationName) {
String name = AbstractGenerator.finalName(fullAnnotationName);
//importIf(fullAnnotationName);
for(AnnotationExpr annotationExpr : getter.getAnnotations()) {
String annName = annotationExpr.getName().asString();
if(annName.equals(fullAnnotationName) || name.equals(annName)) {
return (NormalAnnotationExpr) annotationExpr;
}
}
importIf(fullAnnotationName);
String pkg = AbstractGenerator.packageName(fullAnnotationName);
NodeList<MemberValuePair> nodes = NodeList.nodeList();
//Name nm = new Name(new Name(pkg), name);
NormalAnnotationExpr ax = new NormalAnnotationExpr(new Name(name), nodes);
getter.addAnnotation(ax);
return ax;
}
示例3: createOrFindMarkerAnnotation
import com.github.javaparser.ast.expr.MemberValuePair; //导入依赖的package包/类
protected MarkerAnnotationExpr createOrFindMarkerAnnotation(BodyDeclaration<?> getter, String fullAnnotationName) {
String name = AbstractGenerator.finalName(fullAnnotationName);
importIf(fullAnnotationName);
//getUnit().addImport(fullAnnotationName);
for(AnnotationExpr annotationExpr : getter.getAnnotations()) {
String annName = annotationExpr.getName().asString();
if(annName.equals(fullAnnotationName) || name.equals(annName)) {
return (MarkerAnnotationExpr) annotationExpr;
}
}
String pkg = AbstractGenerator.packageName(fullAnnotationName);
NodeList<MemberValuePair> nodes = NodeList.nodeList();
//Name nm = new Name(new Name(pkg), name);
MarkerAnnotationExpr ax = new MarkerAnnotationExpr(new Name(name));
getter.addAnnotation(ax);
return ax;
}
示例4: visit
import com.github.javaparser.ast.expr.MemberValuePair; //导入依赖的package包/类
@Override
public void visit(final NormalAnnotationExpr n, final Object arg) {
printer.printLn("NormalAnnotationExpr");
printJavaComment(n.getComment(), arg);
printer.print("@");
n.getName().accept(this, arg);
printer.print("(");
if (n.getPairs() != null) {
for (final Iterator<MemberValuePair> i = n.getPairs().iterator(); i.hasNext(); ) {
final MemberValuePair m = i.next();
m.accept(this, arg);
if (i.hasNext()) {
printer.print(", ");
}
}
}
printer.print(")");
}
示例5: matchNode
import com.github.javaparser.ast.expr.MemberValuePair; //导入依赖的package包/类
private boolean matchNode(Node node, Node candidate) {
if (node.getClass() != candidate.getClass()) {
return false;
}
if (node instanceof AnnotationExpr) {
return AnnotationExpr.class.cast(node).getName().getName().equals(AnnotationExpr.class.cast(candidate).getName().getName());
}
if (node instanceof MemberValuePair && MemberValuePair.class.cast(node).getName().equals(MemberValuePair.class.cast(candidate).getName())) {
return true;
}
if (node instanceof Expression) {
return true;
}
return false;
}
示例6: getRequiredJavaVersion
import com.github.javaparser.ast.expr.MemberValuePair; //导入依赖的package包/类
private static JavaVersion getRequiredJavaVersion(List<AnnotationExpr> classAnnotations) {
Optional<AnnotationExpr> containerAnnotation = classAnnotations.stream()
.filter(a -> "SetteSnippetContainer".equals(a.getName().getName())).findAny();
if (containerAnnotation.isPresent()) {
List<Node> children = containerAnnotation.get().getChildrenNodes();
Optional<String> reqJavaVerStr = children.stream()
.filter(c -> c instanceof MemberValuePair).map(c -> (MemberValuePair) c)
.filter(mvp -> "requiredJavaVersion".equals(mvp.getName()))
.map(mvp -> mvp.getValue().toString()).findAny();
if (reqJavaVerStr.isPresent()) {
Optional<JavaVersion> reqJavaVer = Stream.of(JavaVersion.values())
.filter(jv -> reqJavaVerStr.get().endsWith(jv.name())).findAny();
if (reqJavaVer.isPresent()) {
return reqJavaVer.get();
} else {
// NOTE make better
throw new RuntimeException("Cannot recignize java version:" + reqJavaVerStr);
}
}
}
return null;
}
示例7: visit
import com.github.javaparser.ast.expr.MemberValuePair; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void visit(@Nullable MethodDeclaration methodDec,
@Nullable List<String> groupNames) {
if (null == methodDec || null == groupNames)
throw GlobalUtils
.createNotInitializedException("classorinterfacedeclaration");
else {
if (methodDec.getName().equals("runTest")) {
List<Expression> groups = new ArrayList<Expression>();
for (int i = 1; i < groupNames.size(); i++) {
groups.add(new StringLiteralExpr(groupNames.get(i)));
}
List<MemberValuePair> testAnnoParams = new ArrayList<MemberValuePair>();
testAnnoParams.add(new MemberValuePair("groups",
new ArrayInitializerExpr(groups)));
NormalAnnotationExpr testAnno = new NormalAnnotationExpr(
ASTHelper.createNameExpr("Test"), testAnnoParams);
methodDec.getAnnotations().add(testAnno);
}
}
}
示例8: getTagName
import com.github.javaparser.ast.expr.MemberValuePair; //导入依赖的package包/类
private String getTagName(ClassOrInterfaceDeclaration cls) {
for (AnnotationExpr anno : cls.getAnnotations()) {
if (anno.getName().getSimpleName().equals("WebComponent")) {
if (anno instanceof NormalAnnotationExpr) {
for (MemberValuePair pair : ((NormalAnnotationExpr) anno).getPairs()) {
if (pair.getName().equals("tagName")) {
String val = ASTHelper.extractAnnoValue(pair);
if (val != null) {
return val;
} else {
X_Log.error(
getClass(),
"Type of annotation value not supported: " + pair.getValue().getClass() + " : " + pair.toSource()
);
throw new AssertionError("Must use string literals for tagName values of @WebComponent attributes");
}
}
}
}
}
}
throw new AssertionError("Unable to find the generated tag name from component " + cls.toSource());
}
示例9: setPair
import com.github.javaparser.ast.expr.MemberValuePair; //导入依赖的package包/类
private void setPair(NormalAnnotationExpr ca, String name, String value, boolean quoted) {
MemberValuePair p = findAnnotationPair(ca, name);
if(null == p) {
ca.addPair(name, quoted ? "\"" + value + "\"" : value);
} else {
p.setValue(quoted ? new StringLiteralExpr(value) : new NameExpr(value));
}
}
示例10: handleTableAnnotation
import com.github.javaparser.ast.expr.MemberValuePair; //导入依赖的package包/类
private void handleTableAnnotation(AnnotationExpr tableAnn) {
if(! (tableAnn instanceof NormalAnnotationExpr)) {
return;
}
NormalAnnotationExpr nax = (NormalAnnotationExpr) tableAnn;
String tableName = null;
String schemaName = null;
for(MemberValuePair pair : nax.getPairs()) {
if(pair.getName().asString().equals("name")) {
tableName = resolveConstant(pair.getValue());
} else if(pair.getName().asString().equals("schema")) {
schemaName = resolveConstant(pair.getValue());
}
}
if(null == tableName)
return;
//-- Try to resolve table
DbTable table = m_generator.findTableByNames(schemaName, tableName);
if(null == table) {
error("Database table " + tableName + " in schema " + schemaName + " not found");
} else {
m_table = table;
m_type = ClassWrapperType.tableClass;
}
}
示例11: findAnnotationPair
import com.github.javaparser.ast.expr.MemberValuePair; //导入依赖的package包/类
static protected MemberValuePair findAnnotationPair(NormalAnnotationExpr nx, String name) {
for(MemberValuePair mvp : nx.getPairs()) {
if(mvp.getName().asString().equals(name)) {
return mvp;
}
}
return null;
}
示例12: visit
import com.github.javaparser.ast.expr.MemberValuePair; //导入依赖的package包/类
@Override
public JCTree visit(final MemberValuePair n, final Object arg) {
/* TODO - Used in the member/value annotations
* However, annotations are not supported yet
{
JCTree result = n.getValue().accept(this, arg);
if (result != null) {
return result;
}
}
return new AJCMemberValuePair( make.MemberValuePair( ), ( (n.getComment()!=null)?n.getComment().getContent():null ) );
*/
System.err.println("Assigning null at:" + Thread.currentThread().getStackTrace()[1].getLineNumber());
return null;
}
示例13: defineUriParameterWithValueReference
import com.github.javaparser.ast.expr.MemberValuePair; //导入依赖的package包/类
@Test
public void defineUriParameterWithValueReference() throws Exception {
final File basedir = resources.getBasedir("spring-web-generator_uri-parameter-pattern-value-ref");
maven.executeMojo(basedir, "spring-web");
assertFilesPresent(basedir, "target/generated-sources/raml/tld/example/resources/UsersResource.java");
final File file = new File(basedir, "target/generated-sources/raml/tld/example/resources/UsersResource.java");
final MethodDeclaration methodDeclaration = getMethodDeclaration(getClassDeclaration(file), "getUsers");
final Optional<NormalAnnotationExpr> requestMapping = methodDeclaration.getAnnotations().stream()
.filter(NormalAnnotationExpr.class::isInstance)
.map(NormalAnnotationExpr.class::cast)
.filter(a -> a.getName().getName().equals("RequestMapping"))
.findFirst();
assertThat("@RequestMapping annotation with 'value' parameter generated", requestMapping.isPresent(), is(true));
final Optional<MemberValuePair> valueAttribute = requestMapping.get().getPairs().stream()
.filter(pair -> pair.getName().equals("value"))
.findFirst();
assertThat("@RequestMapping.value generated", requestMapping.isPresent(), is(true));
assertThat("@RequestMapping value contains pattern reference",
valueAttribute.get().getValue().toStringWithoutComments(),
is("\"/users/{userId:\" + RegexPatterns.UUID_REGEX + \"}\""));
}
示例14: doMerge
import com.github.javaparser.ast.expr.MemberValuePair; //导入依赖的package包/类
@Override public MemberValuePair doMerge(MemberValuePair first, MemberValuePair second) {
MemberValuePair mvp = new MemberValuePair();
mvp.setName(first.getName());
mvp.setValue(mergeSingle(first.getValue(),second.getValue()));
return mvp;
}
示例15: visit
import com.github.javaparser.ast.expr.MemberValuePair; //导入依赖的package包/类
@Override public Node visit(final NormalAnnotationExpr n, final A arg) {
n.setName((NameExpr) n.getName().accept(this, arg));
final List<MemberValuePair> pairs = n.getPairs();
if (pairs != null) {
for (int i = 0; i < pairs.size(); i++) {
pairs.set(i, (MemberValuePair) pairs.get(i).accept(this, arg));
}
removeNulls(pairs);
}
return n;
}