Hi (most probably Peter), I am having troubles to figure out how to make parametrization of my RUTA project.
First of all I have several scripts that make kind of chain:
Project Adjectives.ruta
Project Anatomy.ruta (contains "SCRIPT Adjectives;" and "Document{->CALL(Adjectives)};")
Project Anamnesis.ruta (contains "SCRIPT Anatomy;" and "Document{->CALL(Anatomy)};")
For the result I am calling this:
File specFile = new File("C:/.../.../pipelines/AnamnesisEngine.xml");
String path = new File(specFile.toURI()).getParentFile().getAbsolutePath();
AnalysisEngineDescription desc = null;
String[] VarNames = {"Name1", "Name2"};
String[] VarValues = {"Value1", "Value2"};
try {
desc = AnalysisEngineFactory.createEngineDescriptionFromPath(
specFile.getAbsolutePath(), RutaEngine.PARAM_SCRIPT_PATHS, path+"/script",
RutaEngine.PARAM_DESCRIPTOR_PATHS, path+"/descriptor",
RutaEngine.PARAM_RESOURCE_PATHS,path+"/resources",
RutaEngine.PARAM_VAR_NAMES, VarNames,
RutaEngine.PARAM_VAR_VALUES, VarValues); ..... End so on (Those parameters (VarNames and VarValues) are filled from query, but that is not so important right now)
Everything works fine and I am getting nice JSON output. But now I am having troubles with those parameters (VarNames, VarValues) and I can't figure this out.
When I make something like this in script Anamnesis.ruta
STRING Name1;
Anamnesis{->SETFEATURE("Lemma",Name1)};
Everything works perfectly and I can see in my output that lemma for Anamnesis annotation is set to Value1...
However I also need to work with those variables in projects Adjectives.ruta and Anatomy.ruta. I suspect that those projects are controlled by their own descriptors (AdjectivesEngine.xml and AnatomyEngine.xml). Is there way to set the parameters for those projects and use them while creating ae from AnamnesisEngine.xml?
When I try to add this to Anatomy.ruta (And again call AnamnesisEngine.xml)
STRING Name1;
Anatomy{->SETFEATURE("Lemma",Name1)};
There is no Lemma at all in the output. Which kind of makes sense but I was hoping that maybe that whole chain can be controlled by AnamnesisEngine.xml and those first two projects would be able to "find", assign and work with those variables... Well I was wrong...
Please what would be the best way to achieve this?
If somebody is ever interested, I managed to achieve this with "Aggregate Engine Type" - which let's you import other descriptors into it and propagates variables into them... Epic!
I'm having a look at XText within the Eclipse framework, and have a question about the arithmetics example. I seem to be able to parse expressions but not evaluate them and wonder if this should be so. This is my workflow:
Create a new Example projext. Choose XText Simple Arithmetics Example.
Open Arithmetics.xtext and choose Run -> External Tools -> Run as -> "Generate XText artifacts".
No Error messages so far as. A bunch of info messages on the form:
119 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Registering project org.eclipse.xtext.example.arithmetics at 'file:/H:/2017/xtextworkspace/org.eclipse.xtext.example.arithmetics/'
119 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Registering project org.eclipse.xtext.example.arithmetics.tests at 'file:/H:/2017/xtextworkspace/org.eclipse.xtext.example.arithmetics.tests/'
Open plugin.xml and click "Launch an Eclipse application".
A second window now opens up and I can now create a new project and start typing expressions.
Create a new project and a new file calles a.calc with this content:
(I also seem to have to create a new Java project here which seems a bit counter-intuitive. Shouldn't it be possible in your new IDE to have a menu option here like "Create new Calc Project"?).
module A
def a:2;
def b:1;
a+b;
The editor seem to parse fine, content assist is working and it tells me if I do something wrong. But isn't it possible to actually run the program? I would like to have an option here similar to "Run -> Run as -> Calc application" Is this not included in the Arithmetics example? I feel like it should be because what else would be the purpose of the calculator.java class? How do I make it print out the value?
you get the expressions evaluated by typing "enter" inside the editor
module A
def a:2;
def b:1;
a+b;
// = 3
1+1;
// = 2
33*11;
// = 363
I am implementing an Eclipse plugin for C programmers.
I can't find a way to get the variable that the user already highlited.(The user will highlight a variable in the editor and I need to know which variable it is/variable's name/location of this variable in the editor, like line number..)
Can anyone help to achieve that ?
Well after searching in some links, I achvieved that by using the ISelectionProvider and ITextSelection Interfaces. Here a code to get the name of the highlighted variable :
ISelectionProvider selProvider = textEditor.getSelectionProvider();
ITextSelection txtSel = (ITextSelection) selProvider.getSelection();
String varName = txtSel.getText();
I'm trying to figure out how it would be more efficient to type a declaration of a collection type with a generic.
Typing:
List<
Automatically expands to:
List<|>
(cursor position is marked with "|")
Typing
List<St|>
using the autocomplete it gets to
List<String|>
notice the cursor position
Now the question: how could it be possible to get to the following state without using the arrow keys:
List<String> |
Ideally, id like to use statement autocompletion for this, but it rather jumps to the new line which is not desired in this situation.
Why don't you make a Live Template for yourself?
For example, go to Live Templates, add a new template under other, give it an abbreviation list, a description as you like, and enter the template text:
List<$TYPE$> $VAR$ = new $END$
Where it says No applicable contexts, define: Java -> Statement
Now click Edit variables and bind as follows
TYPE -> expectedType()
VAR -> suggestVariableName()
Et voila. The keypresses are now: list tab St enter enter (varname) enter
result, with cursor:
List<String> myvar = new |
And from here you can hit ctrl-shift-space to autocomplete like so:
List<String> myvar = new ArrayList<>(|);
Hope this helps :)
I want to use regions for code folding in Eclipse; how can that be done in Java?
An example usage in C#:
#region name
//code
#endregion
Jet Brains IDEA has this feature. You can use hotkey surround with for that (ctrl + alt + T). It's just IDEA feature.
Regions there look like this:
//region Description
Some code
//endregion
There's no such standard equivalent. Some IDEs - Intellij, for instance, or Eclipse - can fold depending on the code types involved (constructors, imports etc.), but there's nothing quite like #region.
With Android Studio, try this:
//region VARIABLES
private String _sMyVar1;
private String _sMyVar2;
//endregion
Careful : no blank line after //region ...
And you will get:
No equivalent in the language... Based on IDEs...
For example in netbeans:
NetBeans/Creator supports this syntax:
// <editor-fold defaultstate="collapsed" desc="Your Fold Comment">
...
// </editor-fold>
http://forums.java.net/jive/thread.jspa?threadID=1311
Custom code folding feature can be added to eclipse using CoffeeScript code folding plugin.
This is tested to work with eclipse Luna and Juno. Here are the steps
Download the plugin from here
Extract the contents of archive
Copy paste the contents of plugin and features folder to the same named folder inside eclipse installation directory
Restart the eclipse
Navigate Window >Preferences >Java >Editor >Folding >Select folding to use: Coffee Bytes Java >General tab >Tick checkboxes in front of User Defined Fold
Create new region as shown:
Restart the Eclipse.
Try out if folding works with comments prefixed with specified starting and ending identifiers
You can download archive and find steps at this Blog also.
For Eclipse IDE the Coffee-Bytes plugin can do it, download link is here.
EDIT:
Latest information about Coffee-Bytes is here.
This is more of an IDE feature than a language feature. Netbeans allows you to define your own folding definitions using the following definition:
// <editor-fold defaultstate="collapsed" desc="user-description">
...any code...
// </editor-fold>
As noted in the article, this may be supported by other editors too, but there are no guarantees.
the fastest way in Android Studio (or IntelliJ IDEA)
highlight the code you want to surround it
press ctrl + alt + t
press c ==> then enter the description
enjoy
AndroidStudio region
Create region
First, find (and define short cut if need) for Surround With menu
Then, select the code, press Ctrl+Alt+Semicolon -> choose region..endregion...
Go to region
First, find Custom Folding short cut
Second, from anywhere in your code, press Ctrl+Alt+Period('>' on keyboard)
Contrary to what most are posting, this is NOT an IDE thing. It is a language thing. The #region is a C# statement.
I were coming from C# to java and had the same problem and the best and exact alternative for region is something like below (working in Android Studio, dont know about intelliJ):
//region [Description]
int a;
int b;
int c;
//endregion
the shortcut is like below:
1- select the code
2- press ctrl + alt + t
3- press c and write your description
The best way
//region DESCRIPTION_REGION
int x = 22;
// Comments
String s = "SomeString";
//endregion;
Tip: Put ";" at the end of the "endregion"
If anyone is interested, in Eclipse you can collapse all your methods etc in one go, just right click when you'd normally insert a break point, click 'Folding' > 'Collapse all'. It know it's not an answer to the question, but just providing an alternative to quick code folding.
here is an example:
//region regionName
//code
//endregion
100% works in Android studio
#region
// code
#endregion
Really only gets you any benefit in the IDE. With Java, there's no set standard in IDE, so there's really no standard parallel to #region.
I usually need this for commented code so I use curly brackets at start and end of that.
{
// Code
// Code
// Code
// Code
}
It could be used for code snippets but can create problems in some code because it changes the scope of variable.
vscode
I use vscode for java and it works pretty much the same as visual studio except you use comments:
//#region name
//code
//#endregion
Meet custom folding regions ⌥⌘T
Actually johann, the # indicates that it's a preprocessor directive, which basically means it tells the IDE what to do.
In the case of using #region and #endregion in your code, it makes NO difference in the final code whether it's there or not. Can you really call it a language element if using it changes nothing?
Apart from that, java doesn't have preprocessor directives, which means the option of code folding is defined on a per-ide basis, in netbeans for example with a //< code-fold> statement
On Mac and Android Studio follow this sequence:
Highlight the source code to fold
Press Alt+Command+t
Select <editor-fold>
Also you can select other options:
In Visual Studio Code, try this:
//region Variables
// Code you need
//endregion
In Eclipse you can collapse the brackets wrapping variable region block. The closest is to do something like this:
public class counter_class
{
{ // Region
int variable = 0;
}
}
Just intall and enable Coffee-Bytes plugin (Eclipse)
There is some option to achieve the same, Follow the below points.
1) Open Macro explorer:
2) Create new macro:
3) Name it "OutlineRegions" (Or whatever you want)
4) Right Click on the "OutlineRegions" (Showing on Macro Explorer) select the "Edit" option and paste the following VB code into it:
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Imports System.Collections
Public Module OutlineRegions
Sub OutlineRegions()
Dim selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection
Const REGION_START As String = "//#region"
Const REGION_END As String = "//#endregion"
selection.SelectAll()
Dim text As String = selection.Text
selection.StartOfDocument(True)
Dim startIndex As Integer
Dim endIndex As Integer
Dim lastIndex As Integer = 0
Dim startRegions As Stack = New Stack()
Do
startIndex = text.IndexOf(REGION_START, lastIndex)
endIndex = text.IndexOf(REGION_END, lastIndex)
If startIndex = -1 AndAlso endIndex = -1 Then
Exit Do
End If
If startIndex <> -1 AndAlso startIndex < endIndex Then
startRegions.Push(startIndex)
lastIndex = startIndex + 1
Else
' Outline region ...
selection.MoveToLineAndOffset(CalcLineNumber(text, CInt(startRegions.Pop())), 1)
selection.MoveToLineAndOffset(CalcLineNumber(text, endIndex) + 1, 1, True)
selection.OutlineSection()
lastIndex = endIndex + 1
End If
Loop
selection.StartOfDocument()
End Sub
Private Function CalcLineNumber(ByVal text As String, ByVal index As Integer)
Dim lineNumber As Integer = 1
Dim i As Integer = 0
While i < index
If text.Chars(i) = vbCr Then
lineNumber += 1
i += 1
End If
i += 1
End While
Return lineNumber
End Function
End Module
5) Save the macro and close the editor.
6) Now let's assign shortcut to the macro. Go to Tools->Options->Environment->Keyboard and search for your macro in "show commands containing" textbox (Type: Macro into the text box, it will suggest the macros name, choose yours one.)
7) now in textbox under the "Press shortcut keys" you can enter the desired shortcut. I use Ctrl+M+N.
Use:
return
{
//Properties
//#region
Name:null,
Address:null
//#endregion
}
8) Press the saved shortcut key
See below result: