本文整理汇总了Java中com.github.javaparser.ast.expr.StringLiteralExpr类的典型用法代码示例。如果您正苦于以下问题:Java StringLiteralExpr类的具体用法?Java StringLiteralExpr怎么用?Java StringLiteralExpr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringLiteralExpr类属于com.github.javaparser.ast.expr包,在下文中一共展示了StringLiteralExpr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderManyToOneAnnotations
import com.github.javaparser.ast.expr.StringLiteralExpr; //导入依赖的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: getNameMethod
import com.github.javaparser.ast.expr.StringLiteralExpr; //导入依赖的package包/类
/**
* Creates the Name method
*/
private MethodDeclaration getNameMethod() {
MethodDeclaration getName = new MethodDeclaration(
ModifierSet.PUBLIC,
Collections.singletonList(OVERRIDE_ANNOTATION),
null,
createReferenceType("String", 0),
"getName",
null, 0,
null,
null
);
BlockStmt methodBody = new BlockStmt(
Collections.singletonList(new ReturnStmt(
new StringLiteralExpr("CV " + definedMethod.getMethodName())))
);
getName.setBody(methodBody);
return getName;
}
示例3: getDescriptionMethod
import com.github.javaparser.ast.expr.StringLiteralExpr; //导入依赖的package包/类
/**
* Creates the description method
*/
private MethodDeclaration getDescriptionMethod() {
MethodDeclaration getDescription = new MethodDeclaration(
ModifierSet.PUBLIC,
Collections.singletonList(OVERRIDE_ANNOTATION),
null,
createReferenceType("String", 0),
"getDescription",
null, 0,
null,
null
);
BlockStmt methodBody = new BlockStmt(
Collections.singletonList(new ReturnStmt(
new StringLiteralExpr(this.definedMethod.getDescription())))
);
getDescription.setBody(methodBody);
return getDescription;
}
示例4: testExpressionCompatibleWithTypeReduce1
import com.github.javaparser.ast.expr.StringLiteralExpr; //导入依赖的package包/类
/**
* From JLS 18.1.2
*
* From Collections.singleton("hi"), we have the constraint formula ‹"hi" → α›.
* Through reduction, this will become the constraint formula: ‹String <: α›.
*/
@Test
public void testExpressionCompatibleWithTypeReduce1() {
ResolvedTypeParameterDeclaration tp = EasyMock.createMock(ResolvedTypeParameterDeclaration.class);
Expression e = new StringLiteralExpr("hi");
InferenceVariable inferenceVariable = new InferenceVariable("α", tp);
ExpressionCompatibleWithType formula = new ExpressionCompatibleWithType(typeSolver, e, inferenceVariable);
ConstraintFormula.ReductionResult res1 = formula.reduce(BoundSet.empty());
assertEquals(
ConstraintFormula.ReductionResult.empty().withConstraint(new TypeCompatibleWithType(typeSolver, stringType, inferenceVariable)),
res1);
assertEquals(
ConstraintFormula.ReductionResult.empty().withConstraint(new TypeSubtypeOfType(typeSolver, stringType, inferenceVariable)),
res1.getConstraint(0).reduce(BoundSet.empty()));
}
示例5: visit
import com.github.javaparser.ast.expr.StringLiteralExpr; //导入依赖的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);
}
}
}
示例6: visit
import com.github.javaparser.ast.expr.StringLiteralExpr; //导入依赖的package包/类
@Override
public void visit(final MethodCallExpr node, final Context ctx) {
List<MethodCallExpr> nodes = dump(node);
for (MethodCallExpr n : nodes) {
List<MethodCallExpr> call = call(n);
if (call.size() > 0) {
MethodCallExpr cparam = call.get(0);
String cname = cparam.getName();
String pname = cparam.getArgs().stream()
.findFirst()
.map(it -> ((StringLiteralExpr) it).getValue())
.orElse(BODY);
Entry<Type, Object> typeDef = type(call.get(call.size() - 1), ctx);
String doc = (String) this.doc.get(pname.equals(BODY) ? "body" : pname);
params.add(new RouteParamImpl(pname, typeDef.getKey(), type(typeDef.getKey(), pname, cname),
typeDef.getValue(), doc));
}
}
}
示例7: extractType
import com.github.javaparser.ast.expr.StringLiteralExpr; //导入依赖的package包/类
protected IsType extractType(Expression val) {
if (val instanceof LiteralExpr) {
if (val instanceof IntegerLiteralExpr) {
return new ImmutableType("", "int");
} else if (val instanceof LongLiteralExpr) {
return new ImmutableType("", "long");
} else if (val instanceof DoubleLiteralExpr) {
return new ImmutableType("", "double");
} else if (val instanceof CharLiteralExpr) {
return new ImmutableType("", "char");
} else if (val instanceof BooleanLiteralExpr) {
return new ImmutableType("", "boolean");
} else if (val instanceof StringLiteralExpr) {
return new ImmutableType("java.lang", "String");
}
// TODO: arrays, ui containers, annotated elements, constructors, etc...
}
return new ImmutableType("java.lang", "Object");
}
示例8: createCU
import com.github.javaparser.ast.expr.StringLiteralExpr; //导入依赖的package包/类
/**
* creates the compilation unit
*/
private static CompilationUnit createCU() {
CompilationUnit cu = new CompilationUnit();
// set the package
cu.setPackage(new PackageDeclaration(ASTHelper.createNameExpr("java.parser.test")));
// create the type declaration
ClassOrInterfaceDeclaration type = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, "GeneratedClass");
ASTHelper.addTypeDeclaration(cu, type);
// create a method
MethodDeclaration method = new MethodDeclaration(ModifierSet.PUBLIC, ASTHelper.VOID_TYPE, "main");
method.setModifiers(ModifierSet.addModifier(method.getModifiers(), ModifierSet.STATIC));
ASTHelper.addMember(type, method);
// add a parameter to the method
Parameter param = ASTHelper.createParameter(ASTHelper.createReferenceType("String", 0), "args");
param.setVarArgs(true);
ASTHelper.addParameter(method, param);
// add a body to the method
BlockStmt block = new BlockStmt();
method.setBody(block);
// add a statement do the method body
NameExpr clazz = new NameExpr("System");
FieldAccessExpr field = new FieldAccessExpr(clazz, "out");
MethodCallExpr call = new MethodCallExpr(field, "println");
ASTHelper.addArgument(call, new StringLiteralExpr("Hello World!"));
ASTHelper.addStmt(block, call);
return cu;
}
示例9: visit
import com.github.javaparser.ast.expr.StringLiteralExpr; //导入依赖的package包/类
@Override
public ResultType visit( MethodDeclaration declaration, MethodDeclaration arg ) {
List<Statement> statements = declaration.getBody().getStmts();
Statement lastStatement = statements.get( statements.size() - 1 );
if ( lastStatement instanceof ReturnStmt ) try {
Expression expr = ( ( ReturnStmt ) lastStatement ).getExpr();
if ( expr instanceof ClassExpr )
// we could return the correct class type here, but that would cause misleading auto-completions
// because the runtime of the expression is a Class without with the type parameter erased
return new ResultType( Class.class, false );
else if ( expr instanceof ObjectCreationExpr )
return new ResultType( typeDiscoverer.classForName(
( ( ObjectCreationExpr ) expr ).getType().getName() ), false );
else if ( expr instanceof ArrayCreationExpr )
return new ResultType( Array.class, false );
else if ( expr.getClass().equals( StringLiteralExpr.class ) )
return new ResultType( String.class, false );
else if ( expr.getClass().equals( NameExpr.class ) ) {
Map<String, Class<?>> typeByVariableName = typeDiscoverer.getTypesByVariableName( statements );
String name = ( ( NameExpr ) expr ).getName();
@Nullable Class<?> variableType = typeByVariableName.get( name );
if ( variableType == null ) {
// attempt to return a class matching the apparent-variable name
return new ResultType( typeDiscoverer.classForName( name ), true );
} else {
return new ResultType( variableType, false );
}
} else
return ResultType.VOID;
} catch ( ClassNotFoundException ignore ) {
// class does not exist
}
return ResultType.VOID;
}
示例10: setPair
import com.github.javaparser.ast.expr.StringLiteralExpr; //导入依赖的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));
}
}
示例11: resolveConstant
import com.github.javaparser.ast.expr.StringLiteralExpr; //导入依赖的package包/类
private String resolveConstant(Expression value) {
if(value == null)
return null;
if(value instanceof StringLiteralExpr) {
return ((StringLiteralExpr) value).asString();
}
error("Cannot get constant value for " + value);
return null;
}
示例12: visit
import com.github.javaparser.ast.expr.StringLiteralExpr; //导入依赖的package包/类
@Override
public void visit(final StringLiteralExpr n, final Object arg) {
printer.printLn("StringLiteralExpr");
printJavaComment(n.getComment(), arg);
printer.print("\"");
printer.print(n.getValue());
printer.print("\"");
}
示例13: visit
import com.github.javaparser.ast.expr.StringLiteralExpr; //导入依赖的package包/类
@Override
public JCTree visit(final StringLiteralExpr n, final Object arg) {
//ARG0: Object value
String arg0 = new String(n.getValue());
return new AJCLiteral(make.Literal(arg0), ((n.getComment() != null) ? n.getComment().getContent() : null));
}
示例14: setup
import com.github.javaparser.ast.expr.StringLiteralExpr; //导入依赖的package包/类
@Before
public void setup(){
CompilationUnit cu = new CompilationUnit();
// set the package
cu.setPackage(new PackageDeclaration(ASTHelper.createNameExpr("java.parser.test")));
// create the type declaration
ClassOrInterfaceDeclaration type = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, "GeneratedClass");
ASTHelper.addTypeDeclaration(cu, type);
// create a method
MethodDeclaration method = new MethodDeclaration(ModifierSet.PUBLIC, ASTHelper.VOID_TYPE, "main");
method.setModifiers(ModifierSet.addModifier(method.getModifiers(), ModifierSet.STATIC));
ASTHelper.addMember(type, method);
// add a parameter to the method
Parameter param = ASTHelper.createParameter(ASTHelper.createReferenceType("String", 0), "args");
param.setVarArgs(true);
ASTHelper.addParameter(method, param);
// add a body to the method
BlockStmt block = new BlockStmt();
method.setBody(block);
// add a statement do the method body
NameExpr clazz = new NameExpr("System");
FieldAccessExpr field = new FieldAccessExpr(clazz, "out");
MethodCallExpr call = new MethodCallExpr(field, "println");
ASTHelper.addArgument(call, new StringLiteralExpr("Hello World!"));
ASTHelper.addStmt(block, call);
unit = cu;
}
示例15: getDeclaration
import com.github.javaparser.ast.expr.StringLiteralExpr; //导入依赖的package包/类
/**
* Creates a socket hint declaration from the constructor.
*
* @return The field declaration
*/
public FieldDeclaration getDeclaration() {
final int modifiers = ModifierSet.addModifier(ModifierSet.FINAL, ModifierSet.PRIVATE);
final ClassOrInterfaceType socketHintType = new ClassOrInterfaceType(SOCKET_HINT_CLASS_NAME);
socketHintType.setTypeArgs(Collections.singletonList(genericType));
final ClassOrInterfaceType socketHintBuilderType = new ClassOrInterfaceType(new
ClassOrInterfaceType(SOCKET_HINT_CLASS_NAME), SOCKET_HINT_BUILDER_CLASS_NAME);
final List<VariableDeclarator> variableDeclarations = new ArrayList<>();
for (DefinedParamType paramType : paramTypes) {
// Don't generate hint for ignored param
if (paramType.isIgnored()) {
continue;
}
String hintName = paramType.getName();
// The variableId
final String fullHintName = hintName
+ (isOutput() ? OUTPUT_POSTFIX : INPUT_POSTFIX)
+ HINT_POSTFIX;
// The name hint of the socket hint
final StringLiteralExpr stringLiteralExpr = new StringLiteralExpr(hintName);
variableDeclarations.add(
new VariableDeclarator(
new VariableDeclaratorId(fullHintName),
// Create new instantiation of type socket hint type
socketHintBuilder(socketHintBuilderType, stringLiteralExpr, paramType)
)
);
}
if (variableDeclarations.isEmpty()) {
return null;
}
return new FieldDeclaration(modifiers, socketHintType, variableDeclarations);
}