Is there a clojure IDE can help autocomplete Java object method? [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Is there a clojure IDE that can help autocomplete a Java object method?
For example:
(def my-temp-file (java.io.File/createTempFile "filename" ".txt"))
then i want to input:
(.deleteOnExit my-temp-file)
how can i :
(. my-temp-file delet|"cursor here") ;; how can i get auto-complate del* methods
or
(.delet|"cursor here" my-temp-file) ;; how can i get auto-complate del* methods
...
just now, I tried intellij14.1.4 + cursive0.1.60, it's wonderful.
i tried to auto-complate from "delete" to " deleteOnExist"
Situation 1 ,This is ok:
Situation 2 ,this canot work :
How can I get the "deleteOnExist" autocomplete in Situation 2? please help

Cursive Clojure, an IntelliJ plugin has excellent Java interop that can do this for you.

The problem with your example is that def does not automatically add the :tag metadata based on the type of its initialiser. You can see this as follows:
Connecting to local IDE...
Clojure 1.7.0
(import java.io.File)
=> java.io.File
(def temp-file (File/createTempFile "filename" ".txt"))
=> #'user/temp-file
temp-file
=> #object[java.io.File 0x6c8b97fd "/var/folders/x1/9k18lcbn4qnfs4pptm0dm8fm0000gn/T/filename8344242261832815384.txt"]
(meta #'temp-file)
=> {:line 1, :column 1, :file "NO_SOURCE_PATH", :name temp-file, :ns #object[clojure.lang.Namespace 0x548b68c5 "user"]}
So your example will work in cases like the following:
(let [temp-file (File/createTempFile "filename" ".txt")]
(temp-file .dele|))
Where | represents the caret. It will also work if you manually add the tag to your def, like:
(def ^File temp-file (File/createTempFile "filename" ".txt"))

Since you put the tag emacs, you can try cider with ac-cider. However, I found this combo a bit error-prone in terms of auto-completion precision. The suggested options can be methods from other classes.

Related

Is there a way to use python and java in the same program? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I want to use both python and java in the same program. Since the print() function of python is better, but java's int variable; is more efficient.
If I'm interpreting correctly, you want to use to use both interchangeably in the same file, so you'd end up with code like:
def main():
int x = 5;
print(x)
This is impossible, because there would be ambiguity when trying to interpret code if you allowed constructs from both languages. For example, "X" + 1 is allowed in java, and would give you the string "X1". In python, it would give you an error because you can't add an int to a string. This would mean that there would be no way to know what your code should do because it's runnable in both languages.
This is a problem that all of us face, where we like some parts of some languages and other parts of other languages. The solution is pretty much just to decide what's most important, choose one language based on that, and then put up with the parts you don't like.
You can use Jython, which is a Python implementation based on the JVM/JDK. This allows calling between Java and Python code in both directions.

String express evaluation matching [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
It is possible to do expression evolution comparison using string in java.
Say if I have list of rules :
create AND [table OR view] AND as AND select
[insert OR delete] AND table
Assume that OR group is always within the square brackets []
I would like do a pattern match (similar to the database GRANT permissions)
I want to block the following commands :
create table something as select * from test => should be blocked (from condition 1)
create view something as select ***** => should be blocked (from condition 1)
insert into table => should be blocked (from condition 2)
delete table => should be blocked (from condition 2)
select * from test => allowed as it doesn't match the rule pattern
In general I want to build something similar to block/grant permission on database queries.
Is there any Java library for expression evaluation matching in Java?
You can make use of the below two simple regex
1.create (table|view).*?as select .*
2.(insert|delete)?.*table
You can test it in https://regex101.com/ and let me know if you find any issue.

How to expand the Regex to actual values [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I am looking for Opensource Java library which could help me in expanding all the possible values out of Numeric Regex, for example: if I give a range 1234[7-9] as input, it should output 12347,12348, 12349, similarly taking care of 123[4-6][7-9], which would translate to 12347, 12357, 12367 so on. Instead of reinventing wheel I would like to know if there are any libraries which could do this. This is only for Numeric regex with defined range.
I have once tried out Xeger which was good enough for such simple expressions similar to yours above. You will also need automaton jar package, that you can download as a library in order to use Xeger.
Example how to use:
String regex = "123[4-6][7-9]";
Xeger generator = new Xeger(regex);
Set<String> generated = new HashSet<>();
for (int i = 0; i < 100; i++) {
generated.add(generator.generate());
}
System.out.println(generated);
//[12367, 12348, 12359, 12349, 12357, 12368, 12369, 12347, 12358]

Is there any ADA parser written in Java? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I am looking to parse ADA code and construct its AST using Java. My belief was that there's a parser written in Java to parse almost every programming language, however after days of research I haven't found anything.
The only promising tool I've found is libadalang (https://github.com/AdaCore/libadalang) by Adacore. However, this only provides api for Ada and Python (although in the readme file Java is mentioned).
Do you have anything to suggest? If there's no direct way of parsing Ada using Java, is any of you familiar with any library that could work as an intermediate? For example, parse Ada using XXX tool and store the AST in a schema (e.g. XML) and then parse the XML using Java?
I'm one of the Libadalang developers, we have indeed planned adding Java bindings at some point, but this is not a high priority item for the moment.
Having a serializer for a common format is something that would be quite easy to add though, especially to the python API were you have full introspection on the tree.
Here is a JSON serializer for the python API of Libadalang:
import json
def node_to_data(self):
if isinstance(self, ASTList):
return [i.to_data() for i in self if i is not None]
else:
return {n: v.to_data()
for n, v in self.iter_fields(with_properties=False)
if v is not None}
def token_to_data(self):
return {"kind": "Token", "token_kind": self.kind, "text": self.text}
ASTNode.to_data = node_to_data
Token.to_data = token_to_data
ASTNode.to_json = lambda self: json.dumps(self.to_data())
I'll add this to the development version of Libadalang soon!
I think I've read that it is possible to call native C libraries from Java.
You could make a C binding to ASIS (Ada Semantic Interface Specification), and then call that from Java.

creating and checking URL in Java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I have a use case where values my function accepts could be of type:-
1. mailto:abc#abc.com
2. tel:3402904323
3. http(s)://www.google.com
4. www.google.com
5. //www.google.com
6. /content/abc/def/index
7. javascript:;
8. blank
9. #
10. http(s)://www.google.com/index.html#abc
11. http(s)://www.google.com/index.html
All these are to be treated as valid and i have to create a URL out of them for e.g. for input 6 i would need to append (.html). For 7th i might need to escapeHtml and rest could be returned as is.
Is there a standard java API to do this or any standard logic i could put into doing this.
Please help.
Use String#matches with the the following regular expressions, respectively.
(?i)mailto:[a-z0-9]{1,}[.a-z0-9]*#[a-z0-9]{1,}[.a-z0-9].[a-z0-9]{2,}
tel:[0-9]{10}
http[s]{0,}://
www\.[a-z0-9\-]{1,}\.com
//www\.[a-z0-9\-]{1,}\.com
/content/([a-z0-9\.\-]{1,}/*)*
nice try
[^\w\W]*
#
http[s]*://[a-z0-9-]{1,}\.[a-z0-9-]{1,}\.com/([a-z0-9-_%\?\=]{1,}/)*[a-zA-Z0-9_-]{1,}\.html#[a-zA-Z_\-\.]{1,}
http[s]*://[a-z0-9-]{1,}\.[a-z0-9-]{1,}\.com/([a-z0-9-_%\?\=]{1,}/)*[a-zA-Z0-9_-]{1,}\.html[a-zA-Z_\-\.]{1,}
Here is an example of using a regular expression, in this case it will return a boolean value (it matches or it doesn't match)
public static void main(String[] args)
{
String pattern = "http[s]*://[a-z0-9-]{1,}\\.[a-z0-9-]{1,}\\.com/([a-z0-9-_%\\?\\=]{1,}/)*[a-zA-Z0-9_-]{1,}\\.html#[a-zA-Z_\\-\\.]{1,}";
String string = "http://docs.oracle.com/javase/8/docs/api/java/lang/String.html#matches-java.lang.String-";
/*
* This will print the boolean literal true or false
*/
System.out.println( string.matches(pattern) );
}
Just try to create a java.net.URI with the string. If there is a syntax error you will get a URISyntaxException. All the above pass provided that "http(s)" really means "http" and "https" separately. If you need to restrict the scheme to what is shown above, just get the scheme and look it up in a table, and fail it if isn't there.

Categories

Resources