com.github.javaparser.ast.expr.NullLiteralExpr Java Examples
The following examples show how to use
com.github.javaparser.ast.expr.NullLiteralExpr.
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: RuleSetNodeVisitor.java From kogito-runtimes with Apache License 2.0 | 6 votes |
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 #2
Source File: DecisionContainerGenerator.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@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 #3
Source File: CompositeContextNodeVisitor.java From kogito-runtimes with Apache License 2.0 | 5 votes |
protected void visitVariableScope(String contextNode, VariableScope variableScope, BlockStmt body, Set<String> visitedVariables) { if (variableScope != null && !variableScope.getVariables().isEmpty()) { for (Variable variable : variableScope.getVariables()) { if (!visitedVariables.add(variable.getName())) { continue; } String tags = (String) variable.getMetaData(Variable.VARIABLE_TAGS); ClassOrInterfaceType variableType = new ClassOrInterfaceType(null, ObjectDataType.class.getSimpleName()); ObjectCreationExpr variableValue = new ObjectCreationExpr(null, variableType, new NodeList<>(new StringLiteralExpr(variable.getType().getStringType()))); body.addStatement(getFactoryMethod(contextNode, METHOD_VARIABLE, new StringLiteralExpr(variable.getName()), variableValue, new StringLiteralExpr(Variable.VARIABLE_TAGS), (tags != null ? new StringLiteralExpr(tags) : new NullLiteralExpr()))); } } }
Example #4
Source File: MigrateJCas.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Visitor for if stmts * - removes feature missing test */ @Override public void visit(IfStmt n, Object ignore) { do { // if (get_set_method == null) break; // sometimes, these occur outside of recogn. getters/setters Expression c = n.getCondition(), e; BinaryExpr be, be2; List<Statement> stmts; if ((c instanceof BinaryExpr) && ((be = (BinaryExpr)c).getLeft() instanceof FieldAccessExpr) && ((FieldAccessExpr)be.getLeft()).getNameAsString().equals("featOkTst")) { // remove the feature missing if statement // verify the remaining form if (! (be.getRight() instanceof BinaryExpr) || ! ((be2 = (BinaryExpr)be.getRight()).getRight() instanceof NullLiteralExpr) || ! (be2.getLeft() instanceof FieldAccessExpr) || ! ((e = getExpressionFromStmt(n.getThenStmt())) instanceof MethodCallExpr) || ! (((MethodCallExpr)e).getNameAsString()).equals("throwFeatMissing")) { reportDeletedCheckModified("The featOkTst was modified:\n" + n.toString() + '\n'); } BlockStmt parent = (BlockStmt) n.getParentNode().get(); stmts = parent.getStatements(); stmts.set(stmts.indexOf(n), new EmptyStmt()); //dont remove // otherwise iterators fail // parent.getStmts().remove(n); return; } } while (false); super.visit(n, ignore); }
Example #5
Source File: ProcessVisitor.java From kogito-runtimes with Apache License 2.0 | 5 votes |
private void visitVariableScope(VariableScope variableScope, BlockStmt body, Set<String> visitedVariables) { if (variableScope != null && !variableScope.getVariables().isEmpty()) { for (Variable variable : variableScope.getVariables()) { if (!visitedVariables.add(variable.getName())) { continue; } String tags = (String) variable.getMetaData(Variable.VARIABLE_TAGS); ClassOrInterfaceType variableType = new ClassOrInterfaceType(null, ObjectDataType.class.getSimpleName()); ObjectCreationExpr variableValue = new ObjectCreationExpr(null, variableType, new NodeList<>(new StringLiteralExpr(variable.getType().getStringType()))); body.addStatement(getFactoryMethod(FACTORY_FIELD_NAME, METHOD_VARIABLE, new StringLiteralExpr(variable.getName()), variableValue, new StringLiteralExpr(Variable.VARIABLE_TAGS), tags != null ? new StringLiteralExpr(tags) : new NullLiteralExpr())); } } }
Example #6
Source File: ProcessesContainerGenerator.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public ClassOrInterfaceDeclaration classDeclaration() { byProcessIdMethodDeclaration .getBody() .orElseThrow(() -> new NoSuchElementException("A method declaration doesn't contain a body!")) .addStatement(new ReturnStmt(new NullLiteralExpr())); NodeList<Expression> processIds = NodeList.nodeList(processes.stream().map(p -> new StringLiteralExpr(p.processId())).collect(Collectors.toList())); processesMethodDeclaration .getBody() .orElseThrow(() -> new NoSuchElementException("A method declaration doesn't contain a body!")) .addStatement(new ReturnStmt(new MethodCallExpr(new NameExpr(Arrays.class.getCanonicalName()), "asList", processIds))); FieldDeclaration applicationFieldDeclaration = new FieldDeclaration(); applicationFieldDeclaration .addVariable( new VariableDeclarator( new ClassOrInterfaceType(null, "Application"), "application") ) .setModifiers( Modifier.Keyword.PRIVATE, Modifier.Keyword.FINAL ); applicationDeclarations.add( applicationFieldDeclaration ); ConstructorDeclaration constructorDeclaration = new ConstructorDeclaration("Processes") .addModifier(Modifier.Keyword.PUBLIC) .addParameter( "Application", "application" ) .setBody( new BlockStmt().addStatement( "this.application = application;" ) ); applicationDeclarations.add( constructorDeclaration ); ClassOrInterfaceDeclaration cls = super.classDeclaration().setMembers(applicationDeclarations); cls.getMembers().sort(new BodyDeclarationComparator()); return cls; }
Example #7
Source File: SpringDependencyInjectionAnnotator.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public Expression getMultiInstance(String fieldName) { return new ConditionalExpr( new BinaryExpr(new NameExpr(fieldName), new NullLiteralExpr(), BinaryExpr.Operator.NOT_EQUALS), new NameExpr(fieldName), new MethodCallExpr(new TypeExpr(new ClassOrInterfaceType(null, Collections.class.getCanonicalName())), "emptyList") ); }
Example #8
Source File: ProcessConfigGenerator.java From kogito-runtimes with Apache License 2.0 | 4 votes |
public List<BodyDeclaration<?>> members() { FieldDeclaration defaultWihcFieldDeclaration = new FieldDeclaration() .setModifiers(Modifier.Keyword.PRIVATE) .addVariable(new VariableDeclarator(new ClassOrInterfaceType(null, WorkItemHandlerConfig.class.getCanonicalName()), VAR_DEFAULT_WORK_ITEM_HANDLER_CONFIG, newObject(DefaultWorkItemHandlerConfig.class))); members.add(defaultWihcFieldDeclaration); FieldDeclaration defaultUowFieldDeclaration = new FieldDeclaration() .setModifiers(Modifier.Keyword.PRIVATE) .addVariable(new VariableDeclarator(new ClassOrInterfaceType(null, UnitOfWorkManager.class.getCanonicalName()), VAR_DEFAULT_UNIT_OF_WORK_MANAGER, newObject(DefaultUnitOfWorkManager.class, newObject(CollectingUnitOfWorkFactory.class)))); members.add(defaultUowFieldDeclaration); FieldDeclaration defaultJobsServiceFieldDeclaration = new FieldDeclaration() .setModifiers(Modifier.Keyword.PRIVATE) .addVariable(new VariableDeclarator(new ClassOrInterfaceType(null, JobsService.class.getCanonicalName()), VAR_DEFAULT_JOBS_SEVICE, new NullLiteralExpr())); members.add(defaultJobsServiceFieldDeclaration); if (annotator != null) { FieldDeclaration wihcFieldDeclaration = annotator.withInjection(new FieldDeclaration().addVariable(new VariableDeclarator(genericType(annotator.optionalInstanceInjectionType(), WorkItemHandlerConfig.class), VAR_WORK_ITEM_HANDLER_CONFIG))); members.add(wihcFieldDeclaration); FieldDeclaration uowmFieldDeclaration = annotator.withInjection(new FieldDeclaration().addVariable(new VariableDeclarator(genericType(annotator.optionalInstanceInjectionType(), UnitOfWorkManager.class), VAR_UNIT_OF_WORK_MANAGER))); members.add(uowmFieldDeclaration); FieldDeclaration jobsServiceFieldDeclaration = annotator.withInjection(new FieldDeclaration().addVariable(new VariableDeclarator(genericType(annotator.optionalInstanceInjectionType(), JobsService.class), VAR_JOBS_SERVICE))); members.add(jobsServiceFieldDeclaration); FieldDeclaration pelcFieldDeclaration = annotator.withOptionalInjection(new FieldDeclaration().addVariable(new VariableDeclarator(genericType(annotator.multiInstanceInjectionType(), ProcessEventListenerConfig.class), VAR_PROCESS_EVENT_LISTENER_CONFIGS))); members.add(pelcFieldDeclaration); FieldDeclaration pelFieldDeclaration = annotator.withOptionalInjection(new FieldDeclaration().addVariable(new VariableDeclarator(genericType(annotator.multiInstanceInjectionType(), ProcessEventListener.class), VAR_PROCESS_EVENT_LISTENERS))); members.add(pelFieldDeclaration); members.add(extractOptionalInjection(WorkItemHandlerConfig.class.getCanonicalName(), VAR_WORK_ITEM_HANDLER_CONFIG, VAR_DEFAULT_WORK_ITEM_HANDLER_CONFIG, annotator)); members.add(extractOptionalInjection(UnitOfWorkManager.class.getCanonicalName(), VAR_UNIT_OF_WORK_MANAGER, VAR_DEFAULT_UNIT_OF_WORK_MANAGER, annotator)); members.add(extractOptionalInjection(JobsService.class.getCanonicalName(), VAR_JOBS_SERVICE, VAR_DEFAULT_JOBS_SEVICE, annotator)); members.add(generateExtractEventListenerConfigMethod()); members.add(generateMergeEventListenerConfigMethod()); } else { FieldDeclaration defaultPelcFieldDeclaration = new FieldDeclaration() .setModifiers(Modifier.Keyword.PRIVATE) .addVariable(new VariableDeclarator(new ClassOrInterfaceType(null, ProcessEventListenerConfig.class.getCanonicalName()), VAR_DEFAULT_PROCESS_EVENT_LISTENER_CONFIG, newObject(DefaultProcessEventListenerConfig.class))); members.add(defaultPelcFieldDeclaration); } return members; }
Example #9
Source File: RuleUnitInstanceGenerator.java From kogito-runtimes with Apache License 2.0 | 4 votes |
private MethodDeclaration bindMethod() { MethodDeclaration methodDeclaration = new MethodDeclaration(); BlockStmt methodBlock = new BlockStmt(); methodDeclaration.setName("bind") .addAnnotation( "Override" ) .addModifier(Modifier.Keyword.PROTECTED) .addParameter(KieSession.class.getCanonicalName(), "runtime") .addParameter(ruleUnitDescription.getRuleUnitName(), "value") .setType(void.class) .setBody(methodBlock); try { for (RuleUnitVariable m : ruleUnitDescription.getUnitVarDeclarations()) { String methodName = m.getter(); String propertyName = m.getName(); if ( m.isDataSource() ) { if (m.setter() != null) { // if writable and DataSource is null create and set a new one Expression nullCheck = new BinaryExpr(new MethodCallExpr(new NameExpr("value"), methodName), new NullLiteralExpr(), BinaryExpr.Operator.EQUALS); Expression createDataSourceExpr = new MethodCallExpr(new NameExpr(DataSource.class.getCanonicalName()), ruleUnitHelper.createDataSourceMethodName(m.getBoxedVarType())); Expression dataSourceSetter = new MethodCallExpr(new NameExpr("value"), m.setter(), new NodeList<>(createDataSourceExpr)); methodBlock.addStatement( new IfStmt( nullCheck, new BlockStmt().addStatement( dataSourceSetter ), null ) ); } // value.$method()) Expression fieldAccessor = new MethodCallExpr(new NameExpr("value"), methodName); // .subscribe( new EntryPointDataProcessor(runtime.getEntryPoint()) ) String entryPointName = getEntryPointName(ruleUnitDescription, propertyName); MethodCallExpr drainInto = new MethodCallExpr(fieldAccessor, "subscribe") .addArgument(new ObjectCreationExpr(null, StaticJavaParser.parseClassOrInterfaceType( EntryPointDataProcessor.class.getName() ), NodeList.nodeList( new MethodCallExpr( new NameExpr("runtime"), "getEntryPoint", NodeList.nodeList(new StringLiteralExpr( entryPointName )))))); methodBlock.addStatement(drainInto); } MethodCallExpr setGlobalCall = new MethodCallExpr( new NameExpr("runtime"), "setGlobal" ); setGlobalCall.addArgument( new StringLiteralExpr( propertyName ) ); setGlobalCall.addArgument( new MethodCallExpr(new NameExpr("value"), methodName) ); methodBlock.addStatement(setGlobalCall); } } catch (Exception e) { throw new Error(e); } return methodDeclaration; }
Example #10
Source File: ConfigGeneratorTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Test public void newInstanceNoProcessConfig() { newInstanceTest(null, NullLiteralExpr.class); }
Example #11
Source File: ConfigGenerator.java From kogito-runtimes with Apache License 2.0 | 4 votes |
private Expression newProcessConfigInstance() { return processConfig == null ? new NullLiteralExpr() : processConfig.newInstance(); }
Example #12
Source File: ConfigGenerator.java From kogito-runtimes with Apache License 2.0 | 4 votes |
private Expression newDecisionConfigInstance() { return decisionConfig == null ? new NullLiteralExpr() : decisionConfig.newInstance(); }
Example #13
Source File: AbstractVisitor.java From kogito-runtimes with Apache License 2.0 | 4 votes |
protected Expression getOrNullExpr(String value) { if (value == null) { return new NullLiteralExpr(); } return new StringLiteralExpr(value); }
Example #14
Source File: PrettyPrintVisitor.java From stategen with GNU Affero General Public License v3.0 | 4 votes |
@Override public void visit(final NullLiteralExpr n, final Void arg) { printJavaComment(n.getComment(), arg); printer.print("null"); }
Example #15
Source File: RedundantAssertion.java From TestSmellDetector with GNU General Public License v3.0 | 4 votes |
@Override public void visit(MethodCallExpr n, Void arg) { String argumentValue = null; super.visit(n, arg); if (currentMethod != null) { switch (n.getNameAsString()) { case "assertTrue": case "assertFalse": if (n.getArguments().size() == 1 && n.getArgument(0) instanceof BooleanLiteralExpr) { // assertTrue(boolean condition) or assertFalse(boolean condition) argumentValue = Boolean.toString(((BooleanLiteralExpr) n.getArgument(0)).getValue()); } else if (n.getArguments().size() == 2 && n.getArgument(1) instanceof BooleanLiteralExpr) { // assertTrue(java.lang.String message, boolean condition) or assertFalse(java.lang.String message, boolean condition) argumentValue = Boolean.toString(((BooleanLiteralExpr) n.getArgument(1)).getValue()); } if (argumentValue != null && (argumentValue.toLowerCase().equals("true") || argumentValue.toLowerCase().equals("false"))) { redundantCount++; } break; case "assertNotNull": case "assertNull": if (n.getArguments().size() == 1 && n.getArgument(0) instanceof NullLiteralExpr) { // assertNotNull(java.lang.Object object) or assertNull(java.lang.Object object) argumentValue = (((NullLiteralExpr) n.getArgument(0)).toString()); } else if (n.getArguments().size() == 2 && n.getArgument(1) instanceof NullLiteralExpr) { // assertNotNull(java.lang.String message, java.lang.Object object) or assertNull(java.lang.String message, java.lang.Object object) argumentValue = (((NullLiteralExpr) n.getArgument(1)).toString()); } if (argumentValue != null && (argumentValue.toLowerCase().equals("null"))) { redundantCount++; } break; default: if (n.getNameAsString().startsWith("assert")) { if (n.getArguments().size() == 2) { //e.g. assertArrayEquals(byte[] expecteds, byte[] actuals); assertEquals(long expected, long actual); if (n.getArgument(0).equals(n.getArgument(1))) { redundantCount++; } } if (n.getArguments().size() == 3) { //e.g. assertArrayEquals(java.lang.String message, byte[] expecteds, byte[] actuals); assertEquals(java.lang.String message, long expected, long actual) if (n.getArgument(1).equals(n.getArgument(2))) { redundantCount++; } } } break; } } }
Example #16
Source File: NullLiteralExprMerger.java From dolphin with Apache License 2.0 | 4 votes |
@Override public NullLiteralExpr doMerge(NullLiteralExpr first, NullLiteralExpr second) { NullLiteralExpr nle = new NullLiteralExpr(); return nle; }
Example #17
Source File: NullLiteralExprMerger.java From dolphin with Apache License 2.0 | 4 votes |
@Override public boolean doIsEquals(NullLiteralExpr first, NullLiteralExpr second) { return true; }
Example #18
Source File: TraceVisitor.java From JCTools with Apache License 2.0 | 4 votes |
@Override public void visit(NullLiteralExpr n, Void arg) { out.println("NullLiteralExpr: " + (extended ? n : n)); super.visit(n, arg); }
Example #19
Source File: ConfigGenerator.java From kogito-runtimes with Apache License 2.0 | 4 votes |
private Expression newRuleConfigInstance() { return ruleConfig == null ? new NullLiteralExpr() : ruleConfig.newInstance(); }