com.github.javaparser.ast.expr.NameExpr Java Examples

The following examples show how to use com.github.javaparser.ast.expr.NameExpr. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LazyTest.java    From TestSmellDetector with GNU General Public License v3.0 7 votes vote down vote up
/**
 * The purpose of this method is to identify the production class methods that are called from the test method
 * When the parser encounters a method call:
 * 1) the method is contained in the productionMethods list
 * or
 * 2) the code will check the 'scope' of the called method
 * A match is made if the scope is either:
 * equal to the name of the production class (as in the case of a static method) or
 * if the scope is a variable that has been declared to be of type of the production class (i.e. contained in the 'productionVariables' list).
 */
@Override
public void visit(MethodCallExpr n, Void arg) {
    super.visit(n, arg);
    if (currentMethod != null) {
        if (productionMethods.stream().anyMatch(i -> i.getNameAsString().equals(n.getNameAsString()) &&
                i.getParameters().size() == n.getArguments().size())) {
            calledProductionMethods.add(new MethodUsage(currentMethod.getNameAsString(), n.getNameAsString()));
        } else {
            if (n.getScope().isPresent()) {
                if (n.getScope().get() instanceof NameExpr) {
                    //checks if the scope of the method being called is either of production class (e.g. static method)
                    //or
                    ///if the scope matches a variable which, in turn, is of type of the production class
                    if (((NameExpr) n.getScope().get()).getNameAsString().equals(productionClassName) ||
                            productionVariables.contains(((NameExpr) n.getScope().get()).getNameAsString())) {
                        calledProductionMethods.add(new MethodUsage(currentMethod.getNameAsString(), n.getNameAsString()));
                    }
                }
            }
        }
    }
}
 
Example #2
Source File: RuleSetNodeVisitor.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
private MethodCallExpr handleDecision(RuleSetNode.RuleType.Decision ruleType) {

        StringLiteralExpr namespace = new StringLiteralExpr(ruleType.getNamespace());
        StringLiteralExpr model = new StringLiteralExpr(ruleType.getModel());
        Expression decision = ruleType.getDecision() == null ?
                new NullLiteralExpr() : new StringLiteralExpr(ruleType.getDecision());

        MethodCallExpr decisionModels =
                new MethodCallExpr(new NameExpr("app"), "decisionModels");
        MethodCallExpr decisionModel =
                new MethodCallExpr(decisionModels, "getDecisionModel")
                        .addArgument(namespace)
                        .addArgument(model);

        BlockStmt actionBody = new BlockStmt();
        LambdaExpr lambda = new LambdaExpr(new Parameter(new UnknownType(), "()"), actionBody);
        actionBody.addStatement(new ReturnStmt(decisionModel));

        return new MethodCallExpr(METHOD_DECISION)
                .addArgument(namespace)
                .addArgument(model)
                .addArgument(decision)
                .addArgument(lambda);
    }
 
Example #3
Source File: ProcessGenerator.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
private MethodDeclaration createInstanceGenericWithBusinessKeyMethod(String processInstanceFQCN) {
    MethodDeclaration methodDeclaration = new MethodDeclaration();

    ReturnStmt returnStmt = new ReturnStmt(
            new MethodCallExpr(new ThisExpr(), "createInstance")
            .addArgument(new NameExpr(BUSINESS_KEY))
            .addArgument(new CastExpr(new ClassOrInterfaceType(null, modelTypeName), new NameExpr("value"))));

    methodDeclaration.setName("createInstance")
            .addModifier(Modifier.Keyword.PUBLIC)
            .addParameter(String.class.getCanonicalName(), BUSINESS_KEY)
            .addParameter(Model.class.getCanonicalName(), "value")
            .setType(processInstanceFQCN)
            .setBody(new BlockStmt()
                             .addStatement(returnStmt));
    return methodDeclaration;
}
 
Example #4
Source File: LambdaSubProcessNodeVisitor.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
protected Expression dotNotationToSetExpression(String dotNotation, String value) {
    String[] elements = dotNotation.split("\\.");
    Expression scope = new NameExpr(elements[0]);
    if (elements.length == 1) {
        return new AssignExpr(
                scope,
                new NameExpr(value),
                AssignExpr.Operator.ASSIGN);
    }
    for (int i = 1; i < elements.length - 1; i++) {
        scope = new MethodCallExpr()
                .setScope(scope)
                .setName("get" + StringUtils.capitalize(elements[i]));
    }

    return new MethodCallExpr()
            .setScope(scope)
            .setName("set" + StringUtils.capitalize(elements[elements.length - 1]))
            .addArgument(value);
}
 
Example #5
Source File: LambdaSubProcessNodeVisitor.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
protected Expression dotNotationToGetExpression(String dotNotation) {
    String[] elements = dotNotation.split("\\.");
    Expression scope = new NameExpr(elements[0]);

    if (elements.length == 1) {
        return scope;
    }

    for (int i = 1; i < elements.length; i++) {
        scope = new MethodCallExpr()
                .setScope(scope)
                .setName("get" + StringUtils.capitalize(elements[i]));
    }

    return scope;
}
 
Example #6
Source File: ProcessGenerator.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
private MethodDeclaration createInstanceMethod(String processInstanceFQCN) {
    MethodDeclaration methodDeclaration = new MethodDeclaration();

    ReturnStmt returnStmt = new ReturnStmt(
            new ObjectCreationExpr()
                    .setType(processInstanceFQCN)
                    .setArguments(NodeList.nodeList(
                            new ThisExpr(),
                            new NameExpr("value"),
                            createProcessRuntime())));

    methodDeclaration.setName("createInstance")
            .addModifier(Modifier.Keyword.PUBLIC)
            .addParameter(modelTypeName, "value")
            .setType(processInstanceFQCN)
            .setBody(new BlockStmt()
                             .addStatement(returnStmt));
    return methodDeclaration;
}
 
Example #7
Source File: WorkItemNodeVisitor.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
private Expression getParameterExpr(String type, String value) {
    ParamType pType = ParamType.fromString(type);
    if (pType == null) {
        return new StringLiteralExpr(value);
    }
    switch (pType) {
        case BOOLEAN:
            return new BooleanLiteralExpr(Boolean.parseBoolean(value));
        case FLOAT:
            return new MethodCallExpr()
                    .setScope(new NameExpr(Float.class.getName()))
                    .setName("parseFloat")
                    .addArgument(new StringLiteralExpr(value));
        case INTEGER:
            return new IntegerLiteralExpr(Integer.parseInt(value));
        default:
            return new StringLiteralExpr(value);
    }
}
 
Example #8
Source File: RuleUnitInstanceGenerator.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public ClassOrInterfaceDeclaration classDeclaration() {
    String canonicalName = ruleUnitDescription.getRuleUnitName();
    ClassOrInterfaceDeclaration classDecl = new ClassOrInterfaceDeclaration()
            .setName(targetTypeName)
            .addModifier(Modifier.Keyword.PUBLIC);
    classDecl
            .addExtendedType(
                    new ClassOrInterfaceType(null, AbstractRuleUnitInstance.class.getCanonicalName())
                            .setTypeArguments(new ClassOrInterfaceType(null, canonicalName)))
            .addConstructor(Modifier.Keyword.PUBLIC)
            .addParameter(RuleUnitGenerator.ruleUnitType(canonicalName), "unit")
            .addParameter(canonicalName, "value")
            .addParameter(KieSession.class.getCanonicalName(), "session")
            .setBody(new BlockStmt().addStatement(new MethodCallExpr(
                    "super",
                    new NameExpr("unit"),
                    new NameExpr("value"),
                    new NameExpr("session")
            )));
    classDecl.addMember(bindMethod());
    classDecl.getMembers().sort(new BodyDeclarationComparator());
    return classDecl;
}
 
Example #9
Source File: AnnotatedMember.java    From jeddict with Apache License 2.0 6 votes vote down vote up
static Optional<String> getStringAttribute(AnnotationExpr annotationExpr, String attributeName) {
    Optional<Expression> expressionOpt = getAttribute(annotationExpr, attributeName);
    if (expressionOpt.isPresent()) {
        Expression expression = expressionOpt.get();
        if (expression.isStringLiteralExpr()) {
            return expression.toStringLiteralExpr()
                    .map(StringLiteralExpr::getValue);
        } else if (expression.isNameExpr()) {
            return expression.toNameExpr()
                    .map(NameExpr::getNameAsString);
        } else if (expression.isIntegerLiteralExpr()) {
            return expression.toIntegerLiteralExpr()
                    .map(IntegerLiteralExpr::asInt)
                    .map(String::valueOf);
        } else if (expression.isFieldAccessExpr() || expression.isBinaryExpr()) {
            return expressionOpt
                    .map(Expression::toString);
        } else {
            throw new UnsupportedOperationException();
        }
    }
    return Optional.empty();
}
 
Example #10
Source File: ProcessConfigGenerator.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public ObjectCreationExpr newInstance() {
    if (annotator != null) {
        return new ObjectCreationExpr()
                .setType(StaticProcessConfig.class.getCanonicalName())
                .addArgument(new MethodCallExpr(METHOD_EXTRACT_WORK_ITEM_HANDLER_CONFIG))
                .addArgument(new MethodCallExpr(METHOD_EXTRACT_PROCESS_EVENT_LISTENER_CONFIG))
                .addArgument(new MethodCallExpr(METHOD_EXTRACT_UNIT_OF_WORK_MANAGER))
                .addArgument(new MethodCallExpr(METHOD_EXTRACT_JOBS_SERVICE));
    } else {
        return new ObjectCreationExpr()
                .setType(StaticProcessConfig.class.getCanonicalName())
                .addArgument(new NameExpr(VAR_DEFAULT_WORK_ITEM_HANDLER_CONFIG))
                .addArgument(new NameExpr(VAR_DEFAULT_PROCESS_EVENT_LISTENER_CONFIG))
                .addArgument(new NameExpr(VAR_DEFAULT_UNIT_OF_WORK_MANAGER))
                .addArgument(new NameExpr(VAR_DEFAULT_JOBS_SEVICE));
    }
}
 
Example #11
Source File: DecisionContainerGenerator.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Override
public List<Statement> setupStatements() {
    return Collections.singletonList(
            new IfStmt(
                    new BinaryExpr(
                            new MethodCallExpr(new MethodCallExpr(null, "config"), "decision"),
                            new NullLiteralExpr(),
                            BinaryExpr.Operator.NOT_EQUALS
                    ),
                    new BlockStmt().addStatement(new ExpressionStmt(new MethodCallExpr(
                            new NameExpr("decisionModels"), "init", NodeList.nodeList(new ThisExpr())
                    ))),
                    null
            )
    );
}
 
Example #12
Source File: PrintStatement.java    From TestSmellDetector with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void visit(MethodCallExpr n, Void arg) {
    super.visit(n, arg);
    if (currentMethod != null) {
        // if the name of a method being called is 'print' or 'println' or 'printf' or 'write'
        if (n.getNameAsString().equals("print") || n.getNameAsString().equals("println") || n.getNameAsString().equals("printf") || n.getNameAsString().equals("write")) {
            //check the scope of the method & proceed only if the scope is "out"
            if ((n.getScope().isPresent() &&
                    n.getScope().get() instanceof FieldAccessExpr &&
                    (((FieldAccessExpr) n.getScope().get())).getNameAsString().equals("out"))) {

                FieldAccessExpr f1 = (((FieldAccessExpr) n.getScope().get()));

                //check the scope of the field & proceed only if the scope is "System"
                if ((f1.getScope() != null &&
                        f1.getScope() instanceof NameExpr &&
                        ((NameExpr) f1.getScope()).getNameAsString().equals("System"))) {
                    //a print statement exists in the method body
                    printCount++;
                }
            }

        }
    }
}
 
Example #13
Source File: SleepyTest.java    From TestSmellDetector with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void visit(MethodCallExpr n, Void arg) {
    super.visit(n, arg);
    if (currentMethod != null) {
        // if the name of a method being called is 'sleep'
        if (n.getNameAsString().equals("sleep")) {
            //check the scope of the method
            if ((n.getScope().isPresent() && n.getScope().get() instanceof NameExpr)) {
                //proceed only if the scope is "Thread"
                if ((((NameExpr) n.getScope().get()).getNameAsString().equals("Thread"))) {
                    sleepCount++;
                }
            }

        }
    }
}
 
Example #14
Source File: QueryEndpointGenerator.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
private BlockStmt wrapBodyAddingExceptionLogging(BlockStmt body, String nameURL) {
    TryStmt ts = new TryStmt();
    ts.setTryBlock(body);
    CatchClause cc = new CatchClause();
    String exceptionName = "e";
    cc.setParameter(new Parameter().setName(exceptionName).setType(Exception.class));
    BlockStmt cb = new BlockStmt();
    cb.addStatement(parseStatement(
            String.format(
                    "SystemMetricsCollector.registerException(\"%s\", %s.getStackTrace()[0].toString());",
                    nameURL,
                    exceptionName)
    ));
    cb.addStatement(new ThrowStmt(new NameExpr(exceptionName)));
    cc.setBody(cb);
    ts.setCatchClauses(new NodeList<>(cc));
    return new BlockStmt(new NodeList<>(ts));
}
 
Example #15
Source File: MigrateJCas.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
   * visitor for field access expressions
   *   - convert ((...type_Type)jcasType).casFeatCode_XXXX to _FI_xxx
   * @param n -
   * @param ignore -
   */
  @Override
  public void visit(FieldAccessExpr n, Object ignore) {
    Expression e;
    Optional<Expression> oe;
    String nname = n.getNameAsString();
    
    if (get_set_method != null) {  
      if (nname.startsWith("casFeatCode_") &&
          ((oe = n.getScope()).isPresent()) &&
          ((e = getUnenclosedExpr(oe.get())) instanceof CastExpr) &&
          ("jcasType".equals(getName(((CastExpr)e).getExpression())))) {
        String featureName = nname.substring("casFeatCode_".length());
//        replaceInParent(n, new NameExpr("_FI_" + featureName)); // repl last in List<Expression> (args)
        
        MethodCallExpr getint = new MethodCallExpr(null, "wrapGetIntCatchException");
        getint.addArgument(new NameExpr("_FH_" + featureName));
        replaceInParent(n, getint);
        
        return;
      } else if (nname.startsWith("casFeatCode_")) {
        reportMigrateFailed("Found field casFeatCode_ ... without a previous cast expr using jcasType");
      }
    }
    super.visit(n,  ignore);      
  }
 
Example #16
Source File: RuleSetNodeVisitor.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
private MethodCallExpr handleRuleFlowGroup(RuleSetNode.RuleType ruleType) {
    // build supplier for rule runtime
    BlockStmt actionBody = new BlockStmt();
    LambdaExpr lambda = new LambdaExpr(new Parameter(new UnknownType(), "()"), actionBody);

    MethodCallExpr ruleRuntimeBuilder = new MethodCallExpr(
            new MethodCallExpr(new NameExpr("app"), "ruleUnits"), "ruleRuntimeBuilder");
    MethodCallExpr ruleRuntimeSupplier = new MethodCallExpr(
            ruleRuntimeBuilder, "newKieSession",
            NodeList.nodeList(new StringLiteralExpr("defaultStatelessKieSession"), new NameExpr("app.config().rule()")));
    actionBody.addStatement(new ReturnStmt(ruleRuntimeSupplier));

    return new MethodCallExpr("ruleFlowGroup")
            .addArgument(new StringLiteralExpr(ruleType.getName()))
            .addArgument(lambda);

}
 
Example #17
Source File: PrettyPrintVisitor.java    From stategen with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void visit(final NameExpr n, final Void arg) {
    printJavaComment(n.getComment(), arg);
    n.getName().accept(this, arg);

    printOrphanCommentsEnding(n);
}
 
Example #18
Source File: EagerTest.java    From TestSmellDetector with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method is utilized to obtain the scope of a chained method statement
 */
private void getFinalScope(MethodCallExpr n) {
    if (n.getScope().isPresent()) {
        if ((n.getScope().get() instanceof MethodCallExpr)) {
            getFinalScope((MethodCallExpr) n.getScope().get());
        } else if ((n.getScope().get() instanceof NameExpr)) {
            tempNameExpr = ((NameExpr) n.getScope().get());
        }
    }
}
 
Example #19
Source File: JavaDocParserVisitor.java    From jaxrs-analyzer with Apache License 2.0 5 votes vote down vote up
private String createMemberParamValue(AnnotationExpr a) {
    Expression memberValue = a.asSingleMemberAnnotationExpr().getMemberValue();
    if (memberValue.getClass().isAssignableFrom(StringLiteralExpr.class))
        return memberValue.asStringLiteralExpr().asString();

    if (memberValue.getClass().isAssignableFrom(NameExpr.class))
        return memberValue.asNameExpr().getNameAsString();

    throw new IllegalArgumentException(String.format("Javadoc param type (%s) not supported.", memberValue.toString()));
}
 
Example #20
Source File: RemoveMethodParameter.java    From Refactoring-Bot with MIT License 5 votes vote down vote up
/**
 * @param method
 * @param paramName
 * @return true if given parameter name is present in given method, false
 *         otherwise
 */
private boolean isParameterUsed(MethodDeclaration method, String paramName) {
	Optional<BlockStmt> methodBody = method.getBody();
	if (methodBody.isPresent()) {
		List<NameExpr> expressions = methodBody.get().findAll(NameExpr.class);
		for (NameExpr expression : expressions) {
			if (expression.getNameAsString().equals(paramName)) {
				return true;
			}
		}
	}

	return false;
}
 
Example #21
Source File: GeneralFixture.java    From TestSmellDetector with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visit(NameExpr n, Void arg) {
    if (currentMethod != null) {
        //check if the variable contained in the current test method is also contained in the setup method
        if (setupFields.contains(n.getNameAsString())) {
            if(!fixtureCount.contains(n.getNameAsString())){
                fixtureCount.add(n.getNameAsString());
            }
            //System.out.println(currentMethod.getNameAsString() + " : " + n.getName().toString());
        }
    }

    super.visit(n, arg);
}
 
Example #22
Source File: AbstractVisitor.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
protected MethodCallExpr getFactoryMethod(String object, String methodName, Expression... args) {
    MethodCallExpr variableMethod = new MethodCallExpr(new NameExpr(object), methodName);

    for (Expression arg : args) {
        variableMethod.addArgument(arg);
    }
    return variableMethod;
}
 
Example #23
Source File: RuleUnitMetaModel.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public Statement injectScalar(String targetUnitVar, Expression sourceExpression) {
    BlockStmt blockStmt = new BlockStmt();
    RuleUnitVariable v = ruleUnitDescription.getVar(targetUnitVar);
    String appendMethod = appendMethodOf(v.getType());
    blockStmt.addStatement(assignVar(v));
    blockStmt.addStatement(
            new MethodCallExpr()
                    .setScope(new NameExpr(localVarName(v)))
                    .setName(appendMethod)
                    .addArgument(sourceExpression));
    return blockStmt;
}
 
Example #24
Source File: RuleSetNodeVisitor.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Override
public void visitNode(String factoryField, RuleSetNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
    String nodeName = node.getName();

    body.addStatement(getAssignedFactoryMethod(factoryField, RuleSetNodeFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId())))
            .addStatement(getNameMethod(node, "Rule"));

    RuleSetNode.RuleType ruleType = node.getRuleType();
    if (ruleType.getName().isEmpty()) {
        throw new IllegalArgumentException(
                MessageFormat.format(
                        "Rule task \"{0}\" is invalid: you did not set a unit name, a rule flow group or a decision model.", nodeName));
    }

    addNodeMappings(node, body, getNodeId(node));

    NameExpr methodScope = new NameExpr(getNodeId(node));
    MethodCallExpr m;
    if (ruleType.isRuleFlowGroup()) {
        m = handleRuleFlowGroup(ruleType);
    } else if (ruleType.isRuleUnit()) {
        m = handleRuleUnit(variableScope, metadata, node, nodeName, ruleType);
    } else if (ruleType.isDecision()) {
        m = handleDecision((RuleSetNode.RuleType.Decision) ruleType);
    } else {
        throw new IllegalArgumentException("Rule task " + nodeName + "is invalid: unsupported rule language " + node.getLanguage());
    }
    m.setScope(methodScope);
    body.addStatement(m);

    visitMetaData(node.getMetaData(), body, getNodeId(node));
    body.addStatement(getDoneMethod(getNodeId(node)));
}
 
Example #25
Source File: LambdaSubProcessNodeVisitor.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
private BlockStmt unbind(VariableScope variableScope, SubProcessNode subProcessNode) {
    BlockStmt stmts = new BlockStmt();

    for (Map.Entry<String, String> e : subProcessNode.getOutMappings().entrySet()) {

        // check if given mapping is an expression
        Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(e.getValue());
        if (matcher.find()) {

            String expression = matcher.group(1);
            String topLevelVariable = expression.split("\\.")[0];
            Map<String, String> dataOutputs = (Map<String, String>) subProcessNode.getMetaData("BPMN.OutputTypes");
            Variable variable = new Variable();
            variable.setName(topLevelVariable);
            variable.setType(new ObjectDataType(dataOutputs.get(e.getKey())));

            stmts.addStatement(makeAssignment(variableScope.findVariable(topLevelVariable)));
            stmts.addStatement(makeAssignmentFromModel(variable, e.getKey()));

            stmts.addStatement(dotNotationToSetExpression(expression, e.getKey()));

            stmts.addStatement(new MethodCallExpr()
                    .setScope(new NameExpr(KCONTEXT_VAR))
                    .setName("setVariable")
                    .addArgument(new StringLiteralExpr(topLevelVariable))
                    .addArgument(topLevelVariable));
        } else {

            stmts.addStatement(makeAssignmentFromModel(variableScope.findVariable(e.getValue()), e.getKey()));
            stmts.addStatement(new MethodCallExpr()
                    .setScope(new NameExpr(KCONTEXT_VAR))
                    .setName("setVariable")
                    .addArgument(new StringLiteralExpr(e.getValue()))
                    .addArgument(e.getKey()));
        }

    }

    return stmts;
}
 
Example #26
Source File: ModelMetaData.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public MethodCallExpr callSetter(String targetVar, String destField, Expression value) {
    String name = variableScope.getTypes().get(destField).getSanitizedName();
    String type = variableScope.getType(destField);
    String setter = "set" + StringUtils.capitalize(name); // todo cache FieldDeclarations in compilationUnit()
    return new MethodCallExpr(new NameExpr(targetVar), setter).addArgument(
            new CastExpr(
                    new ClassOrInterfaceType(null, type),
                    new EnclosedExpr(value)));
}
 
Example #27
Source File: A_Nodes.java    From deadcode4j with Apache License 2.0 5 votes vote down vote up
@Test
public void prependsQualifiedNameExpression() {
    QualifiedNameExpr qualifiedNameExpr =
            new QualifiedNameExpr(new QualifiedNameExpr(new NameExpr("de"), "is24"), "foo");
    StringBuilder buffy = Nodes.prepend(qualifiedNameExpr, new StringBuilder("Bar"));

    assertThat(buffy.toString(), is("de.is24.foo.Bar"));
}
 
Example #28
Source File: MigrateJCas.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Get the name of a field
 * @param e -
 * @return the field name or null
 */
private String getName(Expression e) {
  e = getUnenclosedExpr(e);
  if (e instanceof NameExpr) {
    return ((NameExpr)e).getNameAsString();
  }
  if (e instanceof FieldAccessExpr) {
    return ((FieldAccessExpr)e).getNameAsString();
  }
  return null;
}
 
Example #29
Source File: AbstractNodeVisitor.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
protected Statement makeAssignmentFromModel(Variable v, String name) {
    ClassOrInterfaceType type = parseClassOrInterfaceType(v.getType().getStringType());
    // `type` `name` = (`type`) `model.get<Name>
    AssignExpr assignExpr = new AssignExpr(
            new VariableDeclarationExpr(type, name),
            new CastExpr(
                    type,
                    new MethodCallExpr(
                            new NameExpr("model"),
                            "get" + StringUtils.capitalize(name))),
            AssignExpr.Operator.ASSIGN);

    return new ExpressionStmt(assignExpr);
}
 
Example #30
Source File: AbstractNodeVisitor.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public static Statement makeAssignment(String targetLocalVariable, Variable processVariable) {
    ClassOrInterfaceType type = parseClassOrInterfaceType(processVariable.getType().getStringType());
    // `type` `name` = (`type`) `kcontext.getVariable
    AssignExpr assignExpr = new AssignExpr(
            new VariableDeclarationExpr(type, targetLocalVariable),
            new CastExpr(
                    type,
                    new MethodCallExpr(
                            new NameExpr(KCONTEXT_VAR),
                            "getVariable")
                            .addArgument(new StringLiteralExpr(targetLocalVariable))),
            AssignExpr.Operator.ASSIGN);
    return new ExpressionStmt(assignExpr);
}