I'm devaloping a very simple Java compiler in Visual Basic. I want to parse the class name in a Java code which I paste into a textbox of my VB program. For example:
class MyPro { // in this case i need to get "MyPro"
I used Regex.Match for this but I failed. Below is the code I tried:
Dim regex As Regex = New Regex("(class)*{")
Dim match As Match = regex.Match("class mypro{")
If match.Success Then
Console.WriteLine(match.ToString)
End If
Edit:
Sometimes the source code looks like:
class Football extends Sports{
In this case I want to get Football.
And sometimes it is:
class Dog implements ISpeak{
In this case I want to get Dog.
Sometimes the classes both also implement and extend, like this:
class hello implements Serializable extends Object {
There are 4 patterns:
class MyPro { //I want to get "MyPro"
class Football extends Sports{ //"Football"
class Dog implements ISpeak{ //"Dog"
class hello implements Serializable extends Object { //"hello"
You could use the following regular expression:
class\s+([^\s]+)[\s\r\n{]
The value of the class will be captured in the group with index = 1. In C#, it would be: match.Groups[1].Value
Related
A simplified version. I have two classes:
Public Class mSystem
Public Property ID as ObjectID
Public Property Name as string
End Class
Public Class mEmulator
Public Property ID as ObjectID
Public Property Name as string
<BsonRef("mSystems")>
Public Property AssociatedSystems as New List(Of mSystem)
End Class
Public Class Main
Public Sub EmaultorsLinkedToSystem
dim SelectedSystem as mSystem = db.Collections.mSystems.Find(Function(x) x.Name = "Sony Playstation").FirstOrDefault
test = db.Collections.mEmulators.Include(Function(x) x.AssociatedSystems).Find(Function(y) y.AssociatedSystems.Contains(SelectedSystem)).ToList
End sub
End Class
Now I know one mEmulator data object has "Sony Playstation" in its List(of mSystem). However, test returns null. Why isn't this finding it? I've tried a few permutations, but cant get this to work. Any ideas?
The Include method is used for resolving references to other collections, and you're not using BsonRef with AssociatedSystems (at least not in this example you provided). In your example, the instances of mSystem in AssociatedSystems are not being stored in a separate collection, but as an array of embedded documents in the emulators collection.
Try removing the Include call, it should work fine.
I am trying to get the recycle view using onData but i am stuck in this error:
No views in hierarchy found matching: is assignable from class: class
android.widget.AdapterView
The code is just this:
onData(allOf(isAssignableFrom(RecyclerView.class), withId(R.id.ce_musers_list)))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
My adaptor extends RecyclerView.Adapter as it should for a RecycleView, yet, seams the matcher is looking for a simple Adapter.
This is my first time with espress, so i may be failing in something basic.
My Espresso version is 3.0.0
onData() is used only with the AdapterView and its subclasses, which RecyclerView does not belong to.
There is a helper class that espresso comes with: RecyclerViewActions that can be used to perform various actions on a recyclerview and itemviews of the viewholders.
For instance, if you want to make an assertion - you can scroll to the itemview and then use regular onView()... to check particulars of that viewholder.
val recyclerView = onView(
allOf(
withId(R.id.myRecyclerView),
childAtPosition(
withClassName(`is`("androidx.constraintlayout.widget.ConstraintLayout")),
0
)
)
)
recyclerView.perform(actionOnItemAtPosition<ViewHolder>(1, click()))
I've begun experimenting with ANTLR3 today. There seems to be a discrepency in the expressions that I use.
I want my class name to start with a capital letter, followed by mixed case letters and numbers. For instance, Car is valid, 8Car is invalid.
CLASS_NAME : ('A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9')*;
This works fine when I test it individually. However when I use it in the following rule,
model
: '~model' CLASS_NAME model_block
;
However, the CLASS_NAME begins to pick up class names beginning with numbers as well. In this case, ANTLR picks up Car, 8Car or even #Car as valid tokens. I'm missing something silly. Any pointers would be appreciated. Thanks.
CLASS_NAME will not match 8Car or #Car. You're probably using ANTLRWorks' interpreter (or the Eclipse plugin, which uses the same interpreter), which is printing errors on a UI tab you're not aware of, and displaying the incorrect chars in the tokens. Use ANTLRWorks' debugger instead, or write a small test class yourself:
T.g
grammar T;
parse : CLASS_NAME EOF;
CLASS_NAME : ('A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9')*;
Main.java
import org.antlr.runtime.*;
public class Main {
public static void main(String[] args) throws Exception {
TLexer lexer = new TLexer(new ANTLRStringStream("8Car"));
TParser parser = new TParser(new CommonTokenStream(lexer));
parser.parse();
}
}
I am trying to learn MVC4 and i've come to this chapter called validation.
I came to know about DataAnnotations and they have pretty neat attributes to do some server side validation. In book they have only explained about [Required] and [Datatype] attribute. However in asp.net website i saw something called ScaffoldColumn and RegularExpression.
Can someone explain what they are, even though I know little what RegularExpression does.
Also are there any other important validation attributes I should know?
Scaffold Column dictates if when adding a view based on that datamodel it should/not scaffold the column. So forexample your model's id field is a good candidate for you to specify ScaffoldColumn(false), and other foreign key fields etc.
I you specify a regular expression, then if you scaffold a new view for that model,edit customer for example, a regex or regular expression on field will enforce that entered data must match that format.
You can read about ScaffoldColumnAttribute Class here
[MetadataType(typeof(ProductMetadata))]
public partial class Product
{
}
public class ProductMetadata
{
[ScaffoldColumn(true)]
public object ProductID;
[ScaffoldColumn(false)]
public object ThumbnailPhotoFileName;
}
And about RegularExpressionAttribute Class you can read here.
using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;
[MetadataType(typeof(CustomerMetaData))]
public partial class Customer
{
}
public class CustomerMetaData
{
// Allow up to 40 uppercase and lowercase
// characters. Use custom error.
[RegularExpression(#"^[a-zA-Z''-'\s]{1,40}$",
ErrorMessage = "Characters are not allowed.")]
public object FirstName;
// Allow up to 40 uppercase and lowercase
// characters. Use standard error.
[RegularExpression(#"^[a-zA-Z''-'\s]{1,40}$")]
public object LastName;
}
I have some complex classes which many of then have a class as a property. I have tried to mark up the class file with th ROWLEX attribute markers but when more than one class has the same property name, the Rowlex extractor gives an error.
I have produced a very simple set of classes Leg, Animal, Table. Both Table & Animal have Legs which is an Array of Leg....
The error message is:http://nc3a.nato.int/10/16/ZooOntology#Legs is assigned to more than one type.
Imports NC3A.SI.Rowlex
http://nc3a.nato.int/10/16/ZooOntology")>
Namespace Namespace1
<RdfSerializable(Ontology:="http://nc3a.nato.int/10/16/ZooOntology", HasResourceUri:=False)> _
Public Class Leg
End Class
<RdfSerializable(Ontology:="http://nc3a.nato.int/10/16/ZooOntology", HasResourceUri:=False)> _
Public Class House
<RdfProperty(False)> _
Public readonly Property Legs() As Leg()
Get
Return Nothing
End Get
End Property
End Class
<RdfSerializable(Ontology:="http://nc3a.nato.int/10/16/ZooOntology", HasResourceUri:=False)> _
Public Class Table
<RdfProperty(False)> _
Public ReadOnly Property Legs() As Leg()
Get
Return Nothing
End Get
End Property
End Class
End Namespace
ROWLEX2.1 solves the issue, you may download it from http://rowlex.nc3a.nato.int. For more detailed explanation and sample code, please look at this similar StackOverflow question.