• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ConstructorDeclaration类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.github.javaparser.ast.body.ConstructorDeclaration的典型用法代码示例。如果您正苦于以下问题:Java ConstructorDeclaration类的具体用法?Java ConstructorDeclaration怎么用?Java ConstructorDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ConstructorDeclaration类属于com.github.javaparser.ast.body包,在下文中一共展示了ConstructorDeclaration类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
	}
}
 
开发者ID:sfPlayer1,项目名称:Matcher,代码行数:26,代码来源:SrcRemapper.java


示例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;
}
 
开发者ID:alek-sys,项目名称:dataj,代码行数:17,代码来源:ConstructorDeclarationMatcher.java


示例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;
}
 
开发者ID:beihaifeiwu,项目名称:dolphin,代码行数:17,代码来源:ConstructorDeclarationMerger.java


示例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 + ".");
	}
}
 
开发者ID:umlet,项目名称:umlet,代码行数:24,代码来源:JpJavaClass.java


示例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;
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:18,代码来源:CloneVisitor.java


示例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;
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:17,代码来源:CloneVisitor.java


示例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);
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:22,代码来源:VoidVisitorAdapter.java


示例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);
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:27,代码来源:JefParser.java


示例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;
    }
}
 
开发者ID:SETTE-Testing,项目名称:sette-tool,代码行数:21,代码来源:TestSuiteRunner2Helper.java


示例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 + ")";
}
 
开发者ID:bufferhe4d,项目名称:call-IDE,代码行数:29,代码来源:ConstructorNode.java


示例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();
    }
  }
}
 
开发者ID:mopemope,项目名称:meghanada-server,代码行数:40,代码来源:ParameterNameVisitor.java


示例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);
    }
}
 
开发者ID:benas,项目名称:jql,代码行数:10,代码来源:ConstructorIndexer.java


示例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);
	}
}
 
开发者ID:fjalvingh,项目名称:domui,代码行数:41,代码来源:ColumnWrapper.java


示例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());

}
 
开发者ID:fjalvingh,项目名称:domui,代码行数:15,代码来源:ClassWrapper.java


示例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();
    }
}
 
开发者ID:Zir0-93,项目名称:clarpse,代码行数:28,代码来源:JavaTreeListener.java


示例16: visit

import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@Override
public void visit(ConstructorDeclaration n, Object arg) {
    // here you can access the attributes of the method.
    // this method will be called for all methods in this
    // CompilationUnit, including inner class method
    super.visit(n, arg);
    ASTEnhanced ast = new ASTEnhanced();
    ast.buildConstructorAST(n);
    System.out.println(ast.toJSON());
}
 
开发者ID:shashanksingh28,项目名称:code-similarity,代码行数:11,代码来源:App.java


示例17: getParamTypes

import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
private ArrayList<String> getParamTypes(Node n){
	ArrayList<String> paramTypes = new ArrayList<String>();
	List<Parameter> params = new ArrayList<Parameter>();
	
	if(n instanceof MethodDeclaration){
		params = ((MethodDeclaration) n).getParameters();
	}else if(n instanceof ConstructorDeclaration){
		params = ((ConstructorDeclaration) n).getParameters();
	}
	
	for (Parameter param : params) {
  	  boolean isArray = false;
  	  for(Node node : param.getChildrenNodes()){
  		  if(node instanceof VariableDeclaratorId){
  			  VariableDeclaratorId id = (VariableDeclaratorId) node;
  			  if(id.getArrayCount() > 0){
  				  // This would be the case when var's are declared like String args[], but we want to extract String [] as parameter
  				  isArray = true;
  			  }
  		  }
  	  }
  	  if(isArray){
  		  paramTypes.add(param.getType().toString() + "[]");
  	  }
  	  else{
  		  paramTypes.add(param.getType().toString());
  	  }
  }
	
	return paramTypes;
}
 
开发者ID:shashanksingh28,项目名称:code-similarity,代码行数:32,代码来源:ASTEnhanced.java


示例18: visit

import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@Override
public void visit(final ConstructorDeclaration n, final Object arg) {
    printer.printLn("ConstructorDeclaration");
    printJavaComment(n.getComment(), arg);
    printJavadoc(n.getJavaDoc(), arg);
    printMemberAnnotations(n.getAnnotations(), arg);
    printModifiers(n.getModifiers());

    printTypeParameters(n.getTypeParameters(), arg);
    if (n.getTypeParameters() != null) {
        printer.print(" ");
    }
    printer.print(n.getName());

    printer.print("(");
    if (n.getParameters() != null) {
        for (final Iterator<Parameter> i = n.getParameters().iterator(); i.hasNext(); ) {
            final Parameter p = i.next();
            p.accept(this, arg);
            if (i.hasNext()) {
                printer.print(", ");
            }
        }
    }
    printer.print(")");

    if (!isNullOrEmpty(n.getThrows())) {
        printer.print(" throws ");
        for (final Iterator<NameExpr> i = n.getThrows().iterator(); i.hasNext(); ) {
            final NameExpr name = i.next();
            name.accept(this, arg);
            if (i.hasNext()) {
                printer.print(", ");
            }
        }
    }
    printer.print(" ");
    n.getBlock().accept(this, arg);
}
 
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:40,代码来源:ASTDumpVisitor.java


示例19: visit

import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@Override
public Node visit(final ConstructorDeclaration n, final Object arg) {
    ConstructorDeclaration myret = (ConstructorDeclaration) super.visit(n, arg);

    List<Parameter> parameters = n.getParameters();
    // I'd write short-circuit expression with ||,
    // but someone whom uses Eclipse would complain.
    if (parameters == null) {
        founddefault = true;
    } else if (parameters.size() == 0) {
        founddefault = true;
    }

    return myret;
}
 
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:16,代码来源:ComplyToJCVisitor.java


示例20: getMethods

import com.github.javaparser.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@Override
public Method[] getMethods() {
	Method[] newMethods = new Method[methods.size() + constructors.size()];
	int i = 0;
	for (ConstructorDeclaration constructor : constructors) {
		newMethods[i] = new JpConstructor(constructor);
		i++;
	}
	for (MethodDeclaration method : methods) {
		newMethods[i] = new JpMethod(method);
		i++;
	}
	return newMethods;
}
 
开发者ID:umlet,项目名称:umlet,代码行数:15,代码来源:JpJavaClass.java



注:本文中的com.github.javaparser.ast.body.ConstructorDeclaration类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java InterruptibleChannel类代码示例发布时间:2022-05-21
下一篇:
Java Route类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap