I want to create a variable named MameGap which is accessible from every where.
I can print some words to transcript for ex. from a method of a class. I want to do this for MameGap too.
I tried something like this
MameGap:= MyClass new.
Smalltalk at: #myMap put: MameGap.
I want to access MameGap like this
doSomething: aVar
|x|
x:= MameGap getInt.
^x*3
You have to do:
Smalltalk at: #MameGap put: MyClass new
also you can put there just a class object, like
Smalltalk at: #MameGap put: MyClass
and sen to it class-side messages
Related
I am very new to JAVAFX. I just started looking at how to store user files and in my case I don't want to use XML. I am creating a new version of a tool that in the past was done in perl. The user files were text based, and were done with a proprietary definition.
As an example
PROJECT_NAME some_device;
DATA_BUS_WIDTH 32;
LINE_TYPE_A name_A mask:0xFFFFFFFF default:0x00000000 "Some documentation about this line type
SUB_LINE_TYPE_A_0 sub_name_0 PROP0 "Some documentation about what the sub line does";
SUB_LINE_TYPE_A_1 sub_name_1 PROP0 "Some documentation about what the sub line does";
LINE_TYPE_B name_B PROP_2 Size:0x1000 "Some documentation about this line type - important Linetype B has different properties than the previous line type A"
SUB_LINE_TYPE_B_0 sub_name_0 "Some documentation about what the sub line does";
LINE_TYPE_C name_C Other PROPs "And more documentation"
What I am thinking about doing is creating a document class, and then creating an array, that would hold each of the lines. But the rub is that the document class would hold an array of objects where there are three (or even more) types of objects. A LINE_TYPE_A, LINE_TYPE_B, etc.. objects, where there are different properties for each type. I am familiar with creating an array of One type of object. Creating an array of multiple types, seems odd to me, but it seems like there should be a way. As I rolled through the list, I would have to be able to look at each item and say, you're a TYPE A or your a TYPE C, so I could work with the data appropriately.
Is this the right thing to do to create a custom document format? Or is there something else I should be doing? Again, though, I do want to stay away from XML.
There are a few ways you can go about structuring this:
A) Define a data structure, say DataLine, to hold your data. It would contain all the information in a particular line: TYPE, name, etc. Then continue with what you wanted to do:
class Document {
//array or list or some other collection type of `DataLine`
DataLine[] lines;
void doStuff() {
for (DataLine line : lines) {
// line.getType(), line.getName(), etc
}
}
}
B) Define an inheritance based structure that would isolate common fields / query methods, e.g.
// abstract class if you have some common methods or interface
abstract class DataLine {
abstract DataType getType();
}
// some specific data that belongs to only TypeA
class DataLineTypeA extends / implements DataLine {
}
class Document {
//array or list or some other collection type of `DataLine`
DataLine[] lines;
void doStuff() {
for (DataLine line : lines) {
// can also check with getType() if you have it stored
if (line instanceof DataLineTypeA) {
DataLineTypeA typeA = (DataLineTypeA) line;
// do stuff with typeA specific methods
}
// etc.
}
}
}
Finally, you either create your own data parser if you have a formal definition of your data, or use an intermediate format like JSON. Alternatively, you can make data persistent by using the default Java serialization mechanism.
I need to do some operations on the AST produced by the java parser. My problem is I want to check a class initialization cycle problem is there or not.
One example is,
class mark1 {
public static final int x = mark2.p * 5;
//Do some operations here
}
class mark2 {
public static final int p = mark1.x + 100;
//Do some operations here
}
The initialization order of the classes can vary, causing computation of different values for mark1.x and mark2.p. I am trying to implement it using javaparser produced AST but didn't get a feasible solution.
With JavaParser you can easily get all the static fields and the static initializers.
The problem I see with this is that you need to resolve references. For example you need to understand that "mark2.p" and "mark1.x" refer to static fields of other classes. From the point of view of the ASTs they are field accesses, but the AST and JavaParser alone cannot tell you that that particular field is static. To do so you need to use a symbol solver like https://github.com/ftomassetti/java-symbol-solver/ or you can build the logic yourself. For example you could need to look at the imports and see if the class mark1 has been imported or if one class named mark1 is present in the same package as mark2. Doing that you could recognize that mark1 is the name of a class and look into that class for the symbol p. You could then find it and notice it is a static field.
Source: I am a JavaParser contributor
Handlebars has a built-in helper called lookup. The documentation is not very clear about how it works. Could I see an example?
Sure, past me! Here's an example from your future.
Suppose you have an object or array obj and a variable field and you want to output the value of obj[field], you would use the lookup helper {{lookup obj field}}.
The code defining the helper is simply:
function(obj, field) {
return obj && obj[field];
}
The lookup property is useful if we don't know the name of the property we want, for instance because it's in a variable or the result of an expression.
If we have this object:
var book = {
title: 'Discovery of Heaven'
};
We could put this in the HTML like this:
<p>{{book.title}}</p>
Which is equivalent to:
<p>{{lookup book 'title'}}</p>
Maybe we don't know that we want the title. Say the property name is somewhere in a variable instead:
var property = 'title';
Now we could show the book title like this:
<p>{{lookup book property}}</p>
Is there a possibility in Itcl to extend a class dynamically with methods inside the constructor?
I have some functions which are generated dynamically...
They look somehow like this:
proc attributeFunction fname {
set res "proc $fname args {
#set a attribute list in the class
}"
uplevel 1 $res
}
Now I have a file which has a list of possible attributes:
attributeFunction ::func1
attributeFunction ::func2
attributeFunction ::func3
...
This file gets sourced. But until now I am adding global functions.
It would be way nicer to add these functions as methods to an Itcl object.
A little background information:
This is used to generate an abstract language where the user can easily add these attributes by writing them without any other keyword. The use of functions here offers a lot of advantages I do not want to miss.
In Itcl 3, all you can do is redefine an existing method (using the itcl::body command). You can't create new methods in the constructor.
You can do this in Itcl 4, because is built on the foundation of TclOO (a fully dynamic OO core). You'll need the underlying TclOO facilities to do this, but the command you call is something like this:
::oo::objdefine [self] method myMethodName {someargument} {
puts "in the method we can do what we want..."
}
Here's a more complete example:
% package require itcl
4.0.2
% itcl::class Foo {
constructor {} {
::oo::objdefine [self] method myMethodName {someargument} {
puts "in the method we can do what we want..."
}
}
}
% Foo abc
abc
% abc myMethodName x
in the method we can do what we want...
Looks like it works to me…
I tryout some ways to use postsharp
The definition of one of my custom aspects looks like:
<Serializable> _
<MulticastAttributeUsage(PersistMetaData:=True)> _
Public Class StringChecker
Inherits LocationInterceptionAspect
Public Overrides Sub OnGetValue(ByVal args As LocationInterceptionArgs)
MyBase.OnGetValue(args)
..... ..... .....
When I try to find all classes that are tagged with the attribute / aspect , the result ist always empty.
I use this code to discover the assemblys at runtime:
Dim targetClasses As IEnumerable(Of Type) = From asm In AppDomain.CurrentDomain.GetAssemblies().Where(Function(A) A.FullName.Contains("MyNameSpace")) _
.SelectMany(Function(A) A.GetTypes()) _
.Where(Function(T) T.IsDefined(GetType(StringChecker), True))
When I use for testing proposals, a normal atttribute, the query delivers the espected types.
Hoppefully some can give me a hint what I have to do.
edit: It looks like the custom attributes can only be found in the class propertys..
Regards,
Markus
There are two ways to do it:
Use ReflectionSearch but it does not retrieve aspects added with IAspectProvider.
Use IAspectRepositoryService