I'm trying to replace with insert in all files in the directory with the following command:
find . -type f -exec sed -i.bak ':begin;$!N;s/\(#Autowired\)\n\(public .*\)\((ServletRequest\)/\2() \{\}\n&/;tbegin' {} \;
Here is what I'm trying to do:
Match:
#Autowired
public something(ServletRequest
Replace With:
public something() {}
#Autowired
public something(ServletRequest
I am basically trying to add a default constructor to all my java classes in a certain directory/package. I can't seem to match the newline
This seems to work:
sed '/#Autowired/{:l
N;s/\(.*public[ ]*\)\([^(]*\)\((ServletRequest\)/public \2() {}\n\1\3/;
/ServletRequest/!bl}' input
and if you have the ServletRequest bit always following the #autowired:
sed '/#Autowired/{
N;s/\(.*public[ ]*\)\([^(]*\)\((ServletRequest\)/public \2() { }\n\1\3/}'
input
Related
I downloaded jflex by doing brew install jflex everything worked the way it should.
But now when I'm trying to make it work with java_cup.runtime.*. And I keep getting the errors below
Lexer.java:681: error: cannot find symbol
{ return new java_cup.runtime.Symbol(sym.EOF); }
^
symbol: variable sym
location: class Lexer
My proffesor said,
"The Symbol class is
part of the parser (JavaCUP)’s runtime jar file. You may use it in the lexer simply by
setting the classpath to include the jar file from JavaCUP and importing it"
So I made bash file below and did what he said and it is not working.
#!/bin/bash
jflex MiniJava.jflex
javac -cp "/Users/carlosfield/Desktop/School/csc453/java-cup-bin-11b-20160615/java-cup-11b.jar" Lexer.java
java -cp "/Users/carlosfield/Desktop/School/csc453/java-cup-bin-11b-20160615/java-cup-11b-runtime.jar" Lexer Factorial.java
rm Lexer*
This is my jflex file
import java.util.*;
import java_cup.runtime.*;
%%
%class Lexer
%cup
%line
%column
%{
private Symbol symbol(int type) {
return new Symbol(type, yyline, yycolumn);
}
private Symbol symbol(int type, Object value) {
return new Symbol(type, yyline, yycolumn, value);
}
%}
WhiteSpace = [ \t\r\n]
Identifier = [a-zA-Z_][a-zA-Z0-9_]*
Integer = 0 | [1-9][0-9]*
%%
“+” { }
The fix for this issue is that if you use %cup in your jflex file you must then make your own sym class which contains public static final int EOF=0.
I need to parse some C# files to get the values of some constant variables. I know I can do something like
$input = Get-Content C:\somefile.cs ...
then loop over each line and do some text matching.
...but was wondering whether I can utilize some sort of a C# DOM object to get the values of constants?
You can load the type dynamically from the powershell command line, and then evaluate the constant.
Example:
C:\somefile.cs contents:
public static class Foo
{
public const string SOME_CONSTANT = "StackOverflow";
}
Powershell command line:
Add-Type -Path C:\somefile.cs
$constantValue = [Foo]::SOME_CONSTANT
I have a file like this:
function a() {
doSomething();
doSomethingElse();
}
Now I need to replace all text between function a() { and } with some other text
I tried several ways found here, but they all failed. I hope I could get the explanation along with an answer.
P.S. the trick need to be compatible with both OS X and GNU Sed.
You can do a standard substitution :
sed -i 's/\(\<\)doSomething()/\1somethingElse()/' your_file
We use the word boundary to delimit your string :
\(\<\)doSomething()
And then we replace that string with your new string (including the captured word boundary) :
\1somethingElse()
The -i flag stands for : inline replacement
I used this sample file :
function a() {
doSomething();
doSomething();
foo();doSomething();
}
Output :
function a() {
somethingElse();
somethingElse();
foo();somethingElse();
}
sed '/^function a() {/,/}/{
/^[[:blank:]]*doSomething();/ c\
Replace with\
whaterver you want \
where new line are backslash \
at the end for multiline.
}' YourFile
replace the line of doSomething inside function a() paragraph by some other line(s)
Highly depend on content of function a() (assuming there is no ending } line inside the function)
The question pretty much says it all- how could I import file2.vala to file1.vala?
You don't do it directly. If you run valac file1.vala file2.vala, it is as if you compiled them in one big file.
If you want to make them reusable, then you probably want a shared library. In which case, you compile one to produce a C header file and a VAPI definition:
valac --vapi file1.vapi -H file1.h --library libfile1.so file1.vala
The second one can then consume this:
valac --pkg file1 file2.vala
This assume that the VAPI file has been installed. If this is not the case, you'll need to pass --vapidir and the location where file1.vapi exists, probably .. Similarly, you'll need to inform the C compiler about where file1.h lives with -X -I/directory/containing, again, probably -X -I.. Finally, you'll need to tell the C linker where libfile1.so is via -X -L/directory/containing -X -lfile1. This is a little platform specific, and you can smooth the difference out using AutoMake, though this is a bit more involved. Ragel is the usual go-to project for how to use AutoMake with Vala.
just to supply apmasell:
you can use multiple files by using classes and public variables:
main.vala:
extern void cfunction(string text);
void main ()
{
first f = new first ();
f.say_something(f.mytext);
cfunction("c text\n");
}
class.vala:
public class first {
public string mytext = "yolo\n";
public first ()
{
stdout.printf("text from constructer in first\n");
}
public void say_something(string text)
{
stdout.printf("%s\n", text);
}
}
text.c:
#include <stdio.h>
void cfunction(const char *s)
{
puts("This is C code");
printf("%s\n", s);
}
compiles with: valac class.vala main.vala text.c
as you can see, you can even use C code
I often end up with blocks of code like this:
public class CustomFile {
public String path;
public String name;
public CustomFile (String pathToFile, String dbName) {
path = pathToFile;
name = dbName;
}
}
I want to be able to put my cursor on the line above public CustomFile and be able to delete all of the whitespace up to but not including public String name;. Is there a command or macro that will allow me to do this?
This looks like what you want:
C-x C-o runs the command delete-blank-lines, which is an interactive
compiled Lisp function in `simple.el'.
It is bound to C-x C-o.
(delete-blank-lines)
On blank line, delete all surrounding blank lines, leaving just one.
On isolated blank line, delete that one.
On nonblank line, delete any immediately following blank lines.