本文整理汇总了Java中com.github.javaparser.ast.body.ConstructorDeclaration类的典型用法代码示例。如果您正苦于以下问题:Java ConstructorDeclaration类的具体用法?Java ConstructorDeclaration怎么用?Java ConstructorDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstructorDeclaration类属于com.github.javaparser.ast.body包,在下文中一共展示了ConstructorDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printMembers
import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
private void printMembers(final NodeList<BodyDeclaration<?>> members, final Void arg) {
BodyDeclaration<?> prev = null;
members.sort((a, b) -> {
if (a instanceof FieldDeclaration && b instanceof CallableDeclaration) {
return 1;
} else if (b instanceof FieldDeclaration && a instanceof CallableDeclaration) {
return -1;
} else if (a instanceof MethodDeclaration && !((MethodDeclaration) a).getModifiers().contains(Modifier.STATIC) && b instanceof ConstructorDeclaration) {
return 1;
} else if (b instanceof MethodDeclaration && !((MethodDeclaration) b).getModifiers().contains(Modifier.STATIC) && a instanceof ConstructorDeclaration) {
return -1;
} else {
return 0;
}
});
for (final BodyDeclaration<?> member : members) {
if (prev != null && (!prev.isFieldDeclaration() || !member.isFieldDeclaration())) printer.println();
member.accept(this, arg);
printer.println();
prev = member;
}
}
示例2: matches
import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@Override
public boolean matches(Object item) {
Optional<ClassOrInterfaceDeclaration> referenceClass = compilationUnit.getClassByName(className);
Optional<ClassOrInterfaceDeclaration> actualClass = ((CompilationUnit) item).getClassByName(className);
if (referenceClass.isPresent() && actualClass.isPresent()) {
Optional<ConstructorDeclaration> referenceConstructor = referenceClass.get().getConstructorByParameterTypes(params);
Optional<ConstructorDeclaration> actualConstructor = actualClass.get().getConstructorByParameterTypes(params);
return referenceConstructor.isPresent()
&& actualConstructor.isPresent()
&& referenceConstructor.get().equals(actualConstructor.get());
}
return false;
}
示例3: doMerge
import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@Override
public ConstructorDeclaration doMerge(ConstructorDeclaration first, ConstructorDeclaration second) {
ConstructorDeclaration cd = new ConstructorDeclaration();
cd.setName(first.getName());
cd.setJavaDoc(mergeSingle(first.getJavaDoc(), second.getJavaDoc()));
cd.setModifiers(mergeModifiers(first.getModifiers(), second.getModifiers()));
cd.setAnnotations(mergeCollections(first.getAnnotations(), second.getAnnotations()));
cd.setParameters(mergeCollectionsInOrder(first.getParameters(), second.getParameters()));
cd.setTypeParameters(mergeCollectionsInOrder(first.getTypeParameters(), second.getTypeParameters()));
cd.setThrows(mergeListNoDuplicate(first.getThrows(), second.getThrows(), false));
cd.setBlock(mergeSingle(first.getBlock(), second.getBlock()));
return cd;
}
示例4: extractInformation
import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
private void extractInformation(String filename) throws ClassParserException {
List<TypeDeclaration> types = cu.getTypes();
for (TypeDeclaration type : types) {
if (type instanceof ClassOrInterfaceDeclaration) {
clazz = (ClassOrInterfaceDeclaration) type;
}
List<BodyDeclaration> members = type.getMembers();
for (BodyDeclaration member : members) {
if (member instanceof FieldDeclaration) {
fields.add((FieldDeclaration) member);
}
else if (member instanceof ConstructorDeclaration) {
constructors.add((ConstructorDeclaration) member);
}
else if (member instanceof MethodDeclaration) {
methods.add((MethodDeclaration) member);
}
}
}
if (clazz == null) {
throw new ClassParserException("No toplevel type declaration found in " + filename + ".");
}
}
示例5: visit
import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@Override
public Node visit(ConstructorDeclaration _n, Object _arg) {
JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg);
List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
List<TypeParameter> typeParameters = visit(_n.getTypeParameters(), _arg);
List<Parameter> parameters = visit(_n.getParameters(), _arg);
List<NameExpr> throws_ = visit(_n.getThrows(), _arg);
BlockStmt block = cloneNodes(_n.getBlock(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
ConstructorDeclaration r = new ConstructorDeclaration(
_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(),
_n.getModifiers(), annotations, typeParameters, _n.getName(), parameters, throws_, block
);
r.setComment(comment);
return r;
}
示例6: visit
import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@Override
public Node visit(ConstructorDeclaration _n, Object _arg) {
List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
List<TypeParameter> typeParameters = visit(_n.getTypeParameters(), _arg);
List<Parameter> parameters = visit(_n.getParameters(), _arg);
List<ReferenceType> throws_ = visit(_n.getThrows(), _arg);
BlockStmt block = cloneNodes(_n.getBody(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
ConstructorDeclaration r = new ConstructorDeclaration(
_n.getRange(),
_n.getModifiers(), annotations, typeParameters, _n.getName(), parameters, throws_, block
);
r.setComment(comment);
return r;
}
示例7: visit
import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@Override public void visit(final ConstructorDeclaration n, final A arg) {
visitComment(n.getComment(), arg);
visitAnnotations(n, arg);
if (n.getTypeParameters() != null) {
for (final TypeParameter t : n.getTypeParameters()) {
t.accept(this, arg);
}
}
n.getNameExpr().accept(this, arg);
if (n.getParameters() != null) {
for (final Parameter p : n.getParameters()) {
p.accept(this, arg);
}
}
if (n.getThrows() != null) {
for (final ReferenceType name : n.getThrows()) {
name.accept(this, arg);
}
}
n.getBody().accept(this, arg);
}
示例8: processConstructor
import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
private void processConstructor(JavaUnit java, ConstructorDeclaration c, int i) throws IOException {
DefaultJavaElement element=new DefaultJavaElement();
boolean isStarted=false;
for(;lineNum<i;lineNum++){
String line=reader.readLine();
if(StringUtils.isBlank(line) && !isStarted){
continue;
}
if(isStarted==false){
element.addContent(line.trim());
}else{
element.addContent(line);
}
isStarted=true;
}
JavaConstructor jm=new JavaConstructor();
if(c.getParameters()!=null){
for(Parameter param:c.getParameters()){
jm.addparam(param.getType().toString(), param.getId().getName(),param.getModifiers());
if(param.isVarArgs()){
jm.setVarArg(true);
}
}
}
java.addMethod(jm.getKey(), element);
}
示例9: getCuConstructorDecl
import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
private static ConstructorDeclaration getCuConstructorDecl(CompilationUnit compilationUnit,
String name) {
// maybe default ctor not present in source
ConstructorDeclaration[] ctorDecls = compilationUnit.getTypes().get(0).getMembers().stream()
.filter(bd -> bd instanceof ConstructorDeclaration)
.map(bd -> (ConstructorDeclaration) bd).toArray(ConstructorDeclaration[]::new);
if (ctorDecls.length == 0) {
return null;
} else {
for (ConstructorDeclaration ctorDecl : ctorDecls) {
// FIXME test this part
if (ctorDecl.getName().equals(name)) {
return ctorDecl;
}
throw new RuntimeException("SETTE RUNTIME ERROR");
}
return null;
}
}
示例10: ConstructorNode
import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
public ConstructorNode(ConstructorDeclaration conDec)
{
super();
this.conDec = conDec;
if(conDec.isPrivate())
modifier = "- ";
else if(conDec.isPublic())
modifier = "+ ";
else if(conDec.isProtected())
modifier = "# ";
else
modifier = "~ ";
nodeName = modifier + conDec.getName() + "(";
if( conDec.getParameters() != null )
{
parameters = new ArrayList<Parameter>(conDec.getParameters());
for( Parameter p : parameters )
{
nodeName = nodeName + " " + p + ", ";
}
if( nodeName.lastIndexOf(',') > 0 )
{
nodeName = nodeName.substring(0, nodeName.lastIndexOf(','));
}
}
nodeName = nodeName + ")";
}
示例11: visit
import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@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();
}
}
}
示例12: index
import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
public void index(ConstructorDeclaration constructorDeclaration, int typeId) {
List<Parameter> parameters = constructorDeclaration.getParameters();
String name = constructorDeclaration.getNameAsString();
int methodId = methodDao.save(new Method(name,
constructorDeclaration.isPublic(), constructorDeclaration.isStatic(), constructorDeclaration.isFinal(), constructorDeclaration.isAbstract(), true, typeId));
for (Parameter parameter : parameters) {
parameterIndexer.index(parameter, methodId);
}
}
示例13: renameFieldName
import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
public void renameFieldName() {
String fieldPrefix = g().getFieldPrefix();
String propertyName = getPropertyName();
String fieldName = propertyName;
if(null != fieldPrefix) {
fieldName = fieldPrefix + propertyName;
}
VariableDeclarator vd = getVariableDeclaration();
if(null == vd)
return;
//if(m_classWrapper.getTable().getName().equals("definition")) {
// System.out.println("GOTCHA");
//}
String oldName = vd.getName().asString();
if(! oldName.equals(fieldName)) {
vd.setName(fieldName);
//-- We need to rename inside the getter and setter too
MethodDeclaration getter = getGetter();
GetterFieldRenamingVisitor fieldVisitor = new GetterFieldRenamingVisitor(oldName, fieldName);
if(null != getter) {
getter.accept(fieldVisitor, null);
}
MethodDeclaration setter = getSetter();
if(null != setter) {
setter.accept(fieldVisitor, null);
}
m_classWrapper.getRootType().accept(new VoidVisitorAdapter<Void>() {
@Override public void visit(ConstructorDeclaration n, Void arg) {
n.accept(fieldVisitor, null);
}
}, null);
}
}
示例14: destroyConstructors
import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
/**
* Delete all constructors.
*/
public void destroyConstructors() {
List<ConstructorDeclaration> list = new ArrayList<>();
getRootType().accept(new VoidVisitorAdapter<Void>() {
@Override public void visit(ConstructorDeclaration n, Void arg) {
list.add(n);
}
}, null);
list.forEach(n -> n.remove());
}
示例15: visit
import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@Override
public final void visit(EnumDeclaration ctx, Object arg) {
if (!componentStackContainsMethod()) {
final Component enumCmp = createComponent(ctx, OOPSourceModelConstants.ComponentType.ENUM);
enumCmp.setComponentName(generateComponentName(ctx.getNameAsString()));
enumCmp.setImports(currentImports);
enumCmp.setName(ctx.getNameAsString());
enumCmp.setAccessModifiers(resolveJavaParserModifiers(ctx.getModifiers()));
pointParentsToGivenChild(enumCmp);
if (ctx.getComment().isPresent()) {
enumCmp.setComment(ctx.getComment().get().toString());
}
for (final AnnotationExpr annot : ctx.getAnnotations()) {
populateAnnotation(enumCmp, annot);
}
componentStack.push(enumCmp);
for (final Node node : ctx.getChildNodes()) {
if (node instanceof FieldDeclaration || node instanceof MethodDeclaration
|| node instanceof ConstructorDeclaration || node instanceof ClassOrInterfaceDeclaration
|| node instanceof EnumDeclaration || node instanceof EnumConstantDeclaration) {
node.accept(this, arg);
}
}
completeComponent();
}
}