use of com.github.javaparser.ast.body.ClassOrInterfaceDeclaration in project meghanada-server by mopemope.
the class ParameterNameVisitor method visit.
@Override
public void visit(ClassOrInterfaceDeclaration n, Object arg) {
super.visit(n, arg);
final EnumSet<Modifier> modifiers = n.getModifiers();
if (!modifiers.contains(Modifier.PRIVATE)) {
final List<BodyDeclaration<?>> members = n.getMembers();
final SimpleName simpleName = n.getName();
final String clazz = simpleName.getId();
// String clazz = n.getName();
this.className = this.pkg + '.' + clazz;
log.debug("class {}", this.className);
int i = 0;
for (final BodyDeclaration<?> body : members) {
if (body instanceof MethodDeclaration) {
MethodDeclaration methodDeclaration = (MethodDeclaration) body;
this.getParameterNames(methodDeclaration, n.isInterface());
i++;
} else if (body instanceof ConstructorDeclaration) {
// Constructor
} else if (body instanceof ClassOrInterfaceDeclaration) {
final ClassOrInterfaceDeclaration classOrInterfaceDeclaration = (ClassOrInterfaceDeclaration) body;
String name = classOrInterfaceDeclaration.getName().getIdentifier();
String key = this.pkg + '.' + name;
name = this.originClassName + '.' + name;
for (MethodParameterNames mpn : this.parameterNamesList) {
if (mpn != null && mpn.className != null && mpn.className.equals(key)) {
mpn.className = name;
}
}
}
}
if (i > 0 && this.names.className != null) {
this.parameterNamesList.add(this.names);
this.names = new MethodParameterNames();
}
}
}
use of com.github.javaparser.ast.body.ClassOrInterfaceDeclaration in project actframework by actframework.
the class ApiManager method exploreDeclaration.
private void exploreDeclaration(ClassOrInterfaceDeclaration classDeclaration, Map<String, Javadoc> methodJavaDocs, String prefix) {
String className = classDeclaration.getName();
String newPrefix = S.blank(prefix) ? className : S.concat(prefix, ".", className);
for (Node node : classDeclaration.getChildrenNodes()) {
if (node instanceof ClassOrInterfaceDeclaration) {
exploreDeclaration((ClassOrInterfaceDeclaration) node, methodJavaDocs, newPrefix);
} else if (node instanceof MethodDeclaration) {
MethodDeclaration methodDeclaration = (MethodDeclaration) node;
List<AnnotationExpr> annoList = methodDeclaration.getAnnotations();
boolean needJavadoc = false;
if (null != annoList && !annoList.isEmpty()) {
for (AnnotationExpr anno : annoList) {
String annoName = anno.getName().getName();
if (actionAnnotations.contains(annoName)) {
needJavadoc = true;
break;
}
}
}
if (!needJavadoc) {
continue;
}
Comment comment = methodDeclaration.getComment();
if (!(comment instanceof JavadocComment)) {
continue;
}
JavadocComment javadocComment = (JavadocComment) comment;
Javadoc javadoc = JavadocParser.parse(javadocComment);
methodJavaDocs.put(S.concat(newPrefix, ".", methodDeclaration.getName()), javadoc);
}
}
}
use of com.github.javaparser.ast.body.ClassOrInterfaceDeclaration in project drools by kiegroup.
the class AccumulateInline method initInlineAccumulateTemplate.
private void initInlineAccumulateTemplate() {
accumulateInlineClassName = StringUtil.toId(context.getRuleDescr().getName()) + "Accumulate" + accumulateDescr.getLine();
CompilationUnit templateCU;
try {
templateCU = StaticJavaParser.parseResource("AccumulateInlineTemplate.java");
} catch (IOException e) {
throw new InvalidInlineTemplateException(e);
}
ClassOrInterfaceDeclaration parsedClass = templateCU.getClassByName("AccumulateInlineFunction").orElseThrow(InvalidInlineTemplateException::new);
parsedClass.setName(accumulateInlineClassName);
parsedClass.findAll(ClassOrInterfaceType.class, c -> "CONTEXT_DATA_GENERIC".equals(c.asString())).forEach(c -> c.setName(accumulateInlineClassName + ".ContextData"));
this.accumulateInlineClass = parsedClass;
contextData = this.accumulateInlineClass.findFirst(ClassOrInterfaceDeclaration.class, c -> "ContextData".equals(c.getNameAsString())).orElseThrow(InvalidInlineTemplateException::new);
}
use of com.github.javaparser.ast.body.ClassOrInterfaceDeclaration in project drools by kiegroup.
the class QueryDefImplGenerator method generate.
public CompilationUnit generate() {
CompilationUnit cu = new CompilationUnit("org.drools.model.impl");
cu.setImports(nodeList(parseImport("import org.drools.model.Argument;"), parseImport(String.format("import org.drools.model.Query%dDef;", arity)), parseImport("import org.drools.model.Variable;"), parseImport("import org.drools.model.view.QueryCallViewItem;"), parseImport("import org.drools.model.view.QueryCallViewItemImpl;"), parseImport("import static org.drools.model.FlowDSL.declarationOf;"), parseImport("import static org.drools.model.impl.RuleBuilder.DEFAULT_PACKAGE;")));
ClassOrInterfaceDeclaration clazz = classDeclaration(cu);
nameClassConstructor(clazz);
packageNameClassConstructor(clazz);
nameClassArgConstructor(clazz);
pkgNameClassArgConstructor(clazz);
callMethod(clazz);
getArgumentsMethod(clazz);
getters(clazz);
generateEquals(clazz);
return cu;
}
use of com.github.javaparser.ast.body.ClassOrInterfaceDeclaration in project drools by kiegroup.
the class QueryDefImplGenerator method generateEquals.
private void generateEquals(ClassOrInterfaceDeclaration clazz) {
String template = " @Override\n" + " public boolean isEqualTo( ModelComponent other ) {\n" + " if ( this == other ) return true;\n" + " if ( !(other instanceof DEF_IMPL_TYPE) ) return false;\n" + "\n" + " DEF_IMPL_TYPE that = (DEF_IMPL_TYPE) other;\n" + "\n" + " return EQUALS_CALL;\n" + " }";
BodyDeclaration<?> parse = parseBodyDeclaration(template);
Expression andExpr = new BooleanLiteralExpr(true);
for (int i : rangeArity().toArray()) {
String argWithIndex = argIndex(i);
Expression e = parseExpression(String.format("ModelComponent.areEqualInModel( %s, that.%s )", argWithIndex, argWithIndex));
andExpr = new BinaryExpr(andExpr, e, BinaryExpr.Operator.AND);
}
final Expression finalAndExpr = andExpr;
parse.findAll(ClassOrInterfaceType.class, n -> n.toString().equals("DEF_IMPL_TYPE")).forEach(s -> s.replace(parseType("Query" + arity + "DefImpl")));
parse.findAll(NameExpr.class, n -> n.toString().equals("EQUALS_CALL")).forEach(s -> s.replace(finalAndExpr));
clazz.addMember(parse);
}
Aggregations