Get "name" for object, corresponding to package name and object name - scala

Given the object:
package com.foo.bar
object Sample {
val LOG = org.slf4j.LoggerFactory.getLogger(???)
....
}
what statement/function/whatever I put into getLogger statement in order to get "com.foo.bar.Sample" ?
Basically, it's just a matter of code style, for the moment I configured IntelliJ to generate LOG statements with strings, evaluated from template like "packagename.classname". But may be there's some better way?
Thanks.

In this case you could use getClass().getName().

Related

How to generate code from custom scoping through instances?

I'm trying to write a code generator using xtext. There are instances of types declared in the corresponding DSL, attributes can be referenced through those instances by custom scoping (see code for example). The linking is performed directly from referencing element to attribute, so that there is no information about the surrounding instance - but for code generation, I exactly need the qualified name that is added in the DSL file. Is there any other possibility so that I can figure out through which instance the actual feature is referenced?
My first idea was to recall the ScopeProvider at code generation, which works but does not react on two instances of same type because the first matching Attribute is chosen - so if there are multiple instances, the generator cannot distinguish which one is meant.
Second idea was to include information from the corresponding DSL file, but I don't have any idea how to get this work. I already searched a lot if it is possible to get the corresponding DSL-file from the current model, but could not find any helpful answer.
Third idea was to include the instance as a hidden field in the referencing element - but I could not find any solution for this approach too.
Small extract of Grammar (simplified):
Screen:
(features += ScreenFeature)*
;
ScreenFeature:
name=ID ':' type=[ClientEntity]
;
ClientEntity:
(features += Feature)*
;
Feature:
name=ID ':' type=DefaultValue
;
DefaultValue:
'String'|'int'|'double'|'boolean'
;
ChangeViewParam:
param=[ScreenFeature|QualifiedName] ':' value=[ScreenFeature|QualifiedName]
;
DSL-Example:
ClientEntity Car {
id : int
name : String
}
Screen Details {
car : Car
car2 : Car
[...]
car2.id : car.id
}
Generation output of first approach (line: car2.id : car.id) :
car.id : car.id
Expected:
car2.id : car.id
I hope you can understand my problem and have an idea how to solve it. Thanks for your help!
You can use
org.eclipse.xtext.nodemodel.util.NodeModelUtils.findNodesForFeature(EObject, EStructuralFeature) to obtain the nodes for YourDslPackage.Literals.CHANGE_VIEW_PARAM__PARAM (should be only one) and ask that one for its text.
Alternatively you could split your param=[ScreenFeature|QualifiedName] into two references

Binding to Map entry

I have a rule maxNumConsecutiveCubicCustomersPerLocation as such:
Customer(..., $location: location, $consecAndWaitingMap: consecAndWaitingMap)
and all I want to do is to retrieve the entry of $consecAndWaitingMap with key $location (which is an enum type).
In the then part of the rule I can easily print the entry as so System.out.println($location+": "+$consecAndWaitingMap.get($location));, but I may not bind to it:
$consec: $consecAndWaitingMap.get($location)
The compile time error given:
Unable to resolve ObjectType '$consecAndWaitingMap.get'
I have imported all the necessary classes (import java.util.Map; import ...Customer;) so that can't be the problem. Other workarounds, such as fixing $location, or accessing by [], or by first binding to Customerand then retrieving my map using consecAndWaitingMap: HashMap() from $customer.getConsecAndWaitingMap() give similar errors.
How can I bind to $consecAndWaitingMap.get($location)? If that's not possible, any ideas for a workaround?
You can bind your entry in the same line as the other variables. The following code should work :
Customer(..., $location: location, $consecAndWaitingMap: consecAndWaitingMap, $mapEntry : consecAndWaitingMap.get(location))
Note that you can't use the other variables when binding the new one, you need to use the actual "location" field. (replacing "location" with "$location" will give an error)

Data factory lookup (dot) in the item() name

I am having lookup wherein salesforce query is there. I am using elements (item()) in subsequent activities. Till now i had item().name or item().email but now i have item().NVMStatsSF__Related_Lead__r.FirstName which has (dot) in the field name.
How should i parse it through body tag so that it reads it correctly?
So I have the following data in item()
{
"NVMStatsSF__Related_Lead__c": "00QE000egrtgrAK",
"NVMStatsSF__Agent__r.Name": "ABC",
"NVMStatsSF__Related_Lead__r.Email": "geggegg#gmail.com",
"NVMStatsSF__Related_Lead__r.FirstName": "ABC",
"NVMStatsSF__Related_Lead__r.OwnerId": "0025434535IIAW"
}
now when i use item().NVMStatsSF__Agent__r.Name it will not parse because of (dot) after NVMStatsSF__Agent__r. And it is giving me the following error.
'item().NVMStatsSF__Related_Lead__r.Email' cannot be evaluated because property 'NVMStatsSF__Related_Lead__r' doesn't exist, available properties are 'NVMStatsSF__Related_Lead__c, NVMStatsSF__Agent__r.Name, NVMStatsSF__Related_Lead__r.Email, NVMStatsSF__Related_Lead__r.FirstName, NVMStatsSF__Related_Lead__r.OwnerId'.",
"failureType": "UserError",
"target": "WebActivityToAddPerson"
this is because ADF uses '.' for object reading.
Could you find a way to rename the field name which contains '.'?
Seems like you need a built-in function to get the value of an object according to the key. Like getValue(item(), 'key.nestkey'). But unfortunately, seems there isn't such a function. You may need handle your key first.
Finally, it worked. I was being silly.
Instead of taking the value from the child table with the help of (dot) operator I just used subquery. Silly see.
And it worked.

pytest function without return value

I'm trying to do a pytest on a function without return value, but obviously value is None in pytets. I was wondering if there is a solution for that?
here is function which I'm trying to test:
def print_top_movies_url():
for item in movie_link[:100]:
print item.contents[1]
The best thing to do would be to separate getting the top movies and printing them.
For example, you could have a top_movie_urls which looks like this:
def top_movie_urls():
urls = []
for item in movie_link[:100]:
urls.append(item.contents[1])
return urls
(or make it a generator function)
That's easy to test, and wherever you call it, you can now just do something like print('\n'.join(top_movie_urls())).
If you really want to test the output instead, you can use pytest's output capturing to access the output of the tested function and check that.

Adding user defined keywords or Test Attribute

I would like to add custom attributes (or Keywords) to a test which I can access during pytest_runtest_logreport.
What I have been doing currently is to set a marker like this
#pytest.mark.TESTID(98157) for tests and then use this in pytest_runtest_logreport as report.keywords['TESTID'] which returns a tuple of length 1 having value 98157. So far so good.
But when I tried to add another marker with defect ID like this #pytest.mark.JIRA("MyJIRA-124") this report.keywords['JIRA'] this gives me integer 1.
So my question is can we not create parameterized marker with string parameters
AND
If that is the could be the probable workaround for me.
Unfortunately "report" will not have this vaules in default implmentation as it's only a dict with 1 as values for each key (source code)
I think that the easiest workaround would be to change how the "report" is constructed using pytest_runtest_makereport hook. It could be as simple as this:
from _pytest.runner import pytest_runtest_makereport as _makereport
def pytest_runtest_makereport(item, call):
report = _makereport(item, call)
report.keywords = dict(item.keywords)
return report
Then in pytest_runtest_logreport, under report.keyword['JIRA'] you will find MarkInfo object