Hi @matozoid ,
i migrate from 1.0 to 3.0
i have following Syntax errors
1- setTypeArgs
private Type getGenericType(IType typeParameter) {
if (typeParameter instanceof IParameterizedType) {
IParameterizedType paramType = (IParameterizedType)typeParameter;
List<Type> recursiveType = getGenericTypes(paramType.getTypeArguments());
ClassOrInterfaceType classType = new ClassOrInterfaceType(paramType.getTypeName());
classType.setTypeArgs(recursiveType);
return classType;
} else {
return ASTHelper.createReferenceType(typeParameter.getTypeName(), 0);
}
}
how to replace classType.setTypeArgs(recursiveType);?
2- getTypes
private TypeDeclaration findType(String typeName) {
List<TypeDeclaration> types = (List<TypeDeclaration>) cu.getTypes();
for(TypeDeclaration td : types) {
if (td.getName().equals(typeName)) {
return td;
}
}
return null;
}
with which method should i replace getTypes?
3- ModifierSet.PUBLIC
public void createInterface(String name) {
currentClass = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, true, name);
ASTHelper.addTypeDeclaration(cu, currentClass);
}
What is the Variante for ModifierSet.PUBLIC in 3.0.0?
Thanks
Laure
Hi again!
Try setTypeArguments.
I guess you want this:
private TypeDeclaration<?> findType(String typeName) {
CompilationUnit cu = new CompilationUnit();
NodeList<TypeDeclaration<?>> types = cu.getTypes();
for (TypeDeclaration<?> td : types) {
if (td.getNameAsString().equals(typeName)) {
return td;
}
}
return null;
}
import static com.github.javaparser.ast.Modifier.PUBLIC;
----
ClassOrInterfaceDeclaration currentClass = new ClassOrInterfaceDeclaration(EnumSet.of(PUBLIC), true, name);
cu.addType(currentClass);
----
ClassOrInterfaceDeclaration currentClass = cu.addInterface(name).setPublic(true);
HI @matozoid ,
thanks for the quick Feedback. That Help me. Unfortunally setTypeArguments does not works
1- setTypeArguments does not works
```
private Type getGenericType(IType typeParameter) {
if (typeParameter instanceof IParameterizedType) {
IParameterizedType paramType = (IParameterizedType)typeParameter;
List
ClassOrInterfaceType classType = new ClassOrInterfaceType(paramType.getTypeName());
classType.setTypeArguments(recursiveType);
return classType;
} else {
return ASTHelper.createReferenceType(typeParameter.getTypeName(), 0);
}
}
2- Hier too
```
public Object invokeGenericMethod(Object site, String methodName,
List<Object> parameters, List<IType> typeParameters) {
MethodCallExpr expr = (MethodCallExpr)invokeMethod(site, methodName, parameters);
expr.setTypeArguments(getGenericTypes(typeParameters));
return expr;
}
3- setModifiers error
public void createMethod(String name, IType returnType,
List<TypedName> parameters, boolean isPrivate) {
MethodDeclaration method = new MethodDeclaration();
method.addOrphanComment(comment);
method.getAllContainedComments();
method.getOrphanComments();
method.getComment();
method.setName(name);
int modifier = isPrivate ? ModifierSet.PRIVATE : EnumSet.of(PUBLIC);
method.setModifiers(modifier);
if (null != returnType) {
method.setType(toImplType(returnType));
} else {
method.setType(ASTHelper.VOID_TYPE);
}
if (null != parameters && parameters.size() > 0) {
for(TypedName tn : parameters) {
Parameter param = ASTHelper.createParameter(toImplType(tn.getType()),tn.getName());
method.addParameter(param);
}
}
currentClass.addMember(method);
emptyMethodBody(method);
}
Here
int modifier = isPrivate ? ModifierSet.PRIVATE : EnumSet.of(PUBLIC);
method.setModifiers(modifier);
Okay, cool. If you want more help with that, please give a little bit of code that compiles (except the setTypeArguments part.)
please give your email adresse. I will share the code with you. Thanks
I'm afraid I only answer public questions. I'm sure you can create a sample of a few lines.
Hey @freddielaure, how is it going?
Hi @matozoid ,
thanks to ask.
1- DO you know how to replace method.setJavaDoc(comment); ? I have imported that Library
import com.github.javaparser.ast.comments.Comment;
import com.github.javaparser.ast.comments.JavadocComment;
But method.setJavaDoc(comment); does not works. Here is the Error
cannot find symbol; symbol: method setJavaDoc(com.github.javaparser.ast.comments.JavadocComment); location: variable method of type com.github.javaparser.ast.body.MethodDeclaration
2- methodName Errors: incompatible types: java.lang.String cannot be converted to com.github.javaparser.ast.expr.SimpleName
public Object invokeMethod(Object site, String methodName, List<Object> parameters) {
List<Expression> params = getParamExpr(parameters);
MethodCallExpr expr = new MethodCallExpr(getExpr(site), **methodName**, NodeList.nodeList(params));
return expr;
}
3- qualifiedClassName: incompatible types: java.lang.String cannot be converted to com.github.javaparser.ast.expr.Name
private void createImport(String qualifiedClassName) {
ImportDeclaration decl = new ImportDeclaration(qualifiedClassName, false, false);
cu.getImports().add(decl);
}
4- ASTHelper.createReferenceType(typeParameter.getTypeName(), 0): cannot find symbol; symbol: variable ASTHelper; location: class plsql2java.javaAST.JavaParserASTImpl
Thanks
1- that's setJavadocComment now, right? Are you using an IDE? I would expect that method to be easy to find with an IDE, so if you're not using one, try Netbeans, Eclipse, or Intellij or so.
2- as the migration guide points out, all names are now nodes (https://github.com/javaparser/javaparser/wiki/Migration-Guide) so you will have to new SimpleName there.
3- same as 2. The nicest way to go from String to Name is with JavaParser.parseName.
4- that's also mentioned in the migration guide. You don't show me any context, so I can't say how exactly to fix it, but in principle ReferenceType is a wrapper that you need to remove - and with a little luck the remaining code gets simpler.
I think it would help us help you to figure out more about the context.
Are you a professional java developer? A student? A developer not familiar
with Java?
On Thu, 20 Sep 2018 at 12:11, Danny van Bruggen notifications@github.com
wrote:
1- that's setJavadocComment now, right? Are you using an IDE? I would
expect that method to be easy to find with an IDE, so if you're not using
one, try Netbeans, Eclipse, or Intellij or so.2- as the migration guide points out, all names are now nodes (
https://github.com/javaparser/javaparser/wiki/Migration-Guide) so you
will have to new SimpleName there.3- same as 2. The nicest way to go from String to Name is with
JavaParser.parseName.4- that's also mentioned in the migration guide. You don't show me any
context, so I can't say how exactly to fix it, but in principle
ReferenceType is a wrapper that you need to remove - and with a little
luck the remaining code gets simpler.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/javaparser/javaparser/issues/1824#issuecomment-423126384,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAazJjffk4EJ8o-SCMsNr8LUzJLGwJ8wks5uc2negaJpZM4WXz33
.
--
Website at https://tomassetti.me
GitHub https://github.com/ftomassetti
No more replies, so I guess everything is solved.
Most helpful comment
I'm afraid I only answer public questions. I'm sure you can create a sample of a few lines.