I want to count all inlinks of all objects in all modules in a IBM Doors Project. (with DXL)
So this is how I did it (in main im calling the function goThroughFolders(current Folder)):
Go through every folder in the project and check if there are modules if there are modules call the function "checkLinks(Module m)"
void goThroughFolders(Folder f)
{
Item itm
if (null f) return
for itm in f do{
print("\nScanning folder...")
if (null itm) continue
if (isDeleted(itm)) continue
else if ((type (itm) == "Project") || (type (itm) == "Folder"))
{
goThroughFolders(folder(itm))
}
else if (type (itm) == "Formal") {
print("\nFound Module")
checkLinks(module(itm))
}
}
}
Check modules for links
void checkLinks(Module m)
{
string objType = ""
Object o = null
Link anyLink
for o in m do {
objType = o."Object Type" ""
// Check if the type is right
if ( ( objType == "Req" ) || ( objType == "Obj" ) ) {
// Check for any outlinks at all
for anyLink in o <- "*" do{
LinkCount++
}
}
}
}
So my problem is the function call checkLinks(module(itm)) in goThroughFolders(Folder f) seems to hand over a null Object.
Error:
-R-E- DXL: <Line:11> null Module do loop parameter was passed
Backtrace:
<Line:69>
<Line:78>
-I- DXL: execution halted
But I dont know why? Can you help me?
Good job spotting the missing step. One other thing you might want to do is close the modules after you finish the analysis, otherwise, you're likely to forget and leave them open, sacrificing memory, until you exit DOORS.
I've made a few modifications and additions below to achieve this - if anything's unclear, please feel free to ask.
Richard
Module m
Skip skLinkSourceMods = create() // Create a skip list to hold references to all modules opened for link analysis
int linkCount = 0
void checkLinks(Item itm, Skip skOpenMods) // Function signature changed to pass in the skip list - not strictly necessary, but clean
{
m = read (fullName(itm), false, true)
put(skOpenMods, m, m) // Add the opened module to the skip list, so we can easily close it later
string objType = ""
Object o = null
Link anyLink
for o in m do {
objType = o."Object Type" ""
// Check if the type is right
if ( ( objType == "Req" ) || ( objType == "Obj" ) ) {
// Check for any outlinks at all
for anyLink in o <- "*" do {
linkCount++
}
}
}
}
void goThroughFolders(Folder f)
{
Item itm
if (null f) return
for itm in f do {
print("\nScanning folder...")
if (null itm) continue
if (isDeleted(itm)) continue
else if ((type (itm) == "Project") || (type (itm) == "Folder"))
{
goThroughFolders(folder(itm))
}
else if (type (itm) == "Formal") {
print("\nFound Module")
checkLinks(itm, skLinkSourceMods) // Function signature changed (see above) to pass in the skip list - not strictly necessary, but clean
}
}
}
void closeModules(Skip skOpenMods)
{
for m in skOpenMods do // Loop through each module in the skip list
{
close(m, false) // Close the module without saving changes (we shouldn't have any - they were opened read-only anyway!)
}
}
goThroughFolders(current Folder)
print "\n" linkCount " links."
closeModules(skLinkSourceMods)
delete(skLinkSourceMods)
Related
enum Move { rock, paper, scissors }
var playerMove = Move.rock;
print('Player played :${playerMove.name}'); <--- this line here gives me an error
print('AI played :${aiMove.name}'); <--- this line works perfectly though
this is the error code:
Unhandled exception:
NoSuchMethodError: Class 'Move' has no instance getter 'name'.
Receiver: Instance of 'Move'
Tried calling: name
import 'dart:io';
import 'dart:math';
enum Move { rock, paper, scissors }
void main() {
while (true) {
final rng = Random();
stdout.write('Rock, paper, scissors (r,p,s): ');
final input = stdin.readLineSync();
if (input == 'r' || input == 'p' || input == 's') {
var playerMove;
if (input == 'r') {
playerMove = Move.rock;
} else if (input == 'p') {
playerMove = Move.paper;
} else {
playerMove = Move.scissors;
}
var random = rng.nextInt(3);
var aiMove = Move.values[random];
print('Input: $input');
print('Player played :${playerMove.name}');
print('AI played :${aiMove.name}');
if (playerMove == aiMove) {
print("It's a draw");
} else if (playerMove == Move.paper && aiMove == Move.rock ||
playerMove == Move.rock && aiMove == Move.scissors ||
playerMove == Move.scissors && aiMove == Move.paper) {
print('Player win');
} else {
print('You lose');
}
} else if (input == 'q') {
break;
} else {
print('Invalid input');
}
}
}
.name is an extension on enum. Dart extensions are static: they are compile-time syntactic sugar, and they therefore require that the object's type be known at compilation time.
You have code:
var playerMove;
if (input == 'r') {
playerMove = Move.rock;
}
...
var playerMove; does not specify a type for the variable, and there is no initializer to infer its type from. It therefore is implicitly declared as dynamic, and extensions on enum will not be applied to it.
You can fix it by specifying an explicit type:
Move playerMove;
if (response.getSubscriber().getGroups() != null) {
List<SPMGetGroupResponse> groupResponses = response.getSubscriber().getGroups()
.stream()
.map(groupId -> callGetGroupAPI(groupId))
.filter(r -> r.getResultCode() == CommonResult.SUCCESS.getResultCode())
.collect(toList());
Is there a way in streams to make the above stop the moment r.getResultCode is not SUCCESSFUL?
the stream equivalent of
List<SPMGetGroupResponse> groupResponses = new ArrayList<>();
for (String groupId : groupIds) {
SPMGetGroupResponse grpResponse = callGetGroupAPI(groupId);
if (grpResponse.getResultCode() == CommonResult.SUCCESS.getResultCode()) {
groupResponses.add(grpResponse);
} else {
break;
}
}
There's no standard way in Java-8 to do this. In Java-9 new operation called takeWhile() was added for this purpose:
List<SPMGetGroupResponse> groupResponses = response.getSubscriber().getGroups()
.stream()
.map(groupId -> callGetGroupAPI(groupId))
.takeWhile(r -> r.getResultCode() == CommonResult.SUCCESS.getResultCode())
.collect(toList());
Some third-party libraries including my library StreamEx backported takeWhile():
List<SPMGetGroupResponse> groupResponses = StreamEx.of(response.getSubscriber().getGroups())
.map(groupId -> callGetGroupAPI(groupId))
.takeWhile(r -> r.getResultCode() == CommonResult.SUCCESS.getResultCode())
.toList();
I've recently started learning Kotlin, so I decided to implement some data structures in it.
So, I've tried implementing a singly linked list:
package datastructures
public class LinkedList {
private data class Node(var nodeValue: Int, var next: Node? = null)
private var head: Node? = null
fun insert(n: Int) {
if(head == null) head = Node(n)
else {
var cur = head
while(cur?.next != null) {
cur = cur?.next
}
cur?.next = Node(n)
}
}
fun print() {
var cur = head
while(cur != null) {
print("${cur.nodeValue} ")
cur = cur?.next
}
}
}
fun main(args: Array<String>) {
val n = LinkedList()
n.insert(5)
n.insert(3)
n.print()
}
and I got the following error:
Error:(22, 13) Kotlin: [Internal Error] org.jetbrains.jet.codegen.CompilationException: Back-end (JVM) Internal error: cannot store to value org.jetbrains.jet.codegen.StackValue$OnStack#a0a447f
Cause: cannot store to value org.jetbrains.jet.codegen.StackValue$OnStack#a0a447f
File being compiled and position: (22,13) in C:/Users/Khaled/IdeaProjects/Kotlin/src/LinkedList.kt
PsiElement: cur?.next = Node(n)
The root cause was thrown at: StackValue.java:75
at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:243)
at org.jetbrains.jet.codegen.ExpressionCodegen.genStatement(ExpressionCodegen.java:262)
at ...
I've been searching here and in google but I can't figure out what's the problem causing this error
Edit:
So I've tried to re-implement the insert function and use requireNotNull() to avoid having the compiler worry about the null-safety stuff.
Here is the code and it's now working:
fun insert(n: Int) {
if (head == null) head = Node(n)
else {
var cur = head!!
while (cur.next != null) {
cur = cur.next!!
}
cur.next = Node(n)
}
}
I think the problem lies in this line:
cur?.next = Node(n)
The problem is that the compiler doesn't know what to do if cur is null. Currently, this results in internal error, but this may be supported in a future version.
For now, the best solution is to rewrite the code such that the compiler could check that cur is never null. The problem is that the compiler assumes that fields declared as var can change at any time, so their values need to be loaded into local variables before checking for null:
var cur = head
if(cur == null) head = Node(n)
else {
var next = cur.next
while(next != null) {
cur = next
next = cur.next
}
cur.next = Node(n)
}
I'm using select2 with Bootstrap 3.
Now I would like to know whether it is possible to display all optgroup items if the search matches the optgroup name while still being able to search for items as well. If this is possible, how can I do it?
The above answers don't seem to work out of the box with Select2 4.0 so if you're hunting for that, check this out: https://github.com/select2/select2/issues/3034
(Use the function like this: $("#example").select2({matcher: modelMatcher});)
function modelMatcher (params, data) {
data.parentText = data.parentText || "";
// Always return the object if there is nothing to compare
if ($.trim(params.term) === '') {
return data;
}
// Do a recursive check for options with children
if (data.children && data.children.length > 0) {
// Clone the data object if there are children
// This is required as we modify the object to remove any non-matches
var match = $.extend(true, {}, data);
// Check each child of the option
for (var c = data.children.length - 1; c >= 0; c--) {
var child = data.children[c];
child.parentText += data.parentText + " " + data.text;
var matches = modelMatcher(params, child);
// If there wasn't a match, remove the object in the array
if (matches == null) {
match.children.splice(c, 1);
}
}
// If any children matched, return the new object
if (match.children.length > 0) {
return match;
}
// If there were no matching children, check just the plain object
return modelMatcher(params, match);
}
// If the typed-in term matches the text of this term, or the text from any
// parent term, then it's a match.
var original = (data.parentText + ' ' + data.text).toUpperCase();
var term = params.term.toUpperCase();
// Check if the text contains the term
if (original.indexOf(term) > -1) {
return data;
}
// If it doesn't contain the term, don't return anything
return null;
}
Actually found the solution by modifying the matcher opt
$("#myselect").select2({
matcher: function(term, text, opt){
return text.toUpperCase().indexOf(term.toUpperCase())>=0 || opt.parent("optgroup").attr("label").toUpperCase().indexOf(term.toUpperCase())>=0
}
});
Under the premise that the label attribute has been set in each optgroup.
Found a solution from select2/issues/3034
Tested with select2 v.4
$("select").select2({
matcher(params, data) {
const originalMatcher = $.fn.select2.defaults.defaults.matcher;
const result = originalMatcher(params, data);
if (
result &&
data.children &&
result.children &&
data.children.length
) {
if (
data.children.length !== result.children.length &&
data.text.toLowerCase().includes(params.term.toLowerCase())
) {
result.children = data.children;
}
return result;
}
return null;
},
});
A few minor changes to people suggested code, less repetitive and copes when there are no parent optgroups:
$('select').select2({
matcher: function(term, text, opt){
var matcher = opt.parent('select').select2.defaults.matcher;
return matcher(term, text) || (opt.parent('optgroup').length && matcher(term, opt.parent('optgroup').attr("label")));
}
});
below is the current codes i have.
what it does is basically loop thru project solution project file and detect if it is a C# file. however it can't detect files that are put in a folder , how can i modify it to read a C# file in a solution folder.
Regards , Andy
foreach (var projectItem in
_applicationObject.Solution.Projects.Cast<Project>().SelectMany(project => project.ProjectItems.Cast<ProjectItem>()))
{
//for (var i = 0; i < projectItem.FileCount; i++)
//{
if (projectItem.FileCount > 0 && projectItem.Name.EndsWith(".cs")) // check if project is .Cs files
{
string fileName;
try
{
fileName = projectItem.FileNames[0];
}
catch (Exception)
{
continue;
}
//end of find filename
}
}
This will print all items in the solution, I believe.
It works with C++ solution in VS 2012.
// XXX Test
IEnumerator enumerator = m_applicationObject.Solution.GetEnumerator();
string indent = " ";
while (enumerator.MoveNext())
{
Project p = enumerator.Current as Project;
if (p != null)
{
Debug.WriteLine(p.Name);
ProcessProjectItems(p.ProjectItems, indent);
}
}
// XXX Test
void ProcessProjectItems(ProjectItems pis, string indent)
{
if (pis == null)
return;
IEnumerator items = pis.GetEnumerator();
while (items.MoveNext())
{
ProjectItem pi = items.Current as ProjectItem;
if (pi != null)
{
Debug.WriteLine(indent + pi.Name);
if (pi.ProjectItems != null)
{
ProcessProjectItems(pi.ProjectItems, indent + " ");
}
else
{
Project p = pi.Object as Project;
if (p != null && p.ProjectItems != null)
ProcessProjectItems(p.ProjectItems, indent + " ");
}
}
}
}