本文整理汇总了Java中org.walkmod.javalang.ast.body.ConstructorDeclaration类的典型用法代码示例。如果您正苦于以下问题:Java ConstructorDeclaration类的具体用法?Java ConstructorDeclaration怎么用?Java ConstructorDeclaration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConstructorDeclaration类属于org.walkmod.javalang.ast.body包,在下文中一共展示了ConstructorDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadMethods
import org.walkmod.javalang.ast.body.ConstructorDeclaration; //导入依赖的package包/类
private void loadMethods(List<BodyDeclaration> members, Scope scope) {
if (!scope.hasMethodsLoaded() && members != null) {
try {
for (BodyDeclaration member : members) {
if (member instanceof ConstructorDeclaration) {
ConstructorDeclaration cd = (ConstructorDeclaration) member;
pushConstructor((SymbolType) ((SymbolDataAware<?>) member.getParentNode()).getSymbolData(),
table, cd);
}
if (member instanceof MethodDeclaration) {
MethodDeclaration md = (MethodDeclaration) member;
pushMethod((SymbolType) ((SymbolDataAware<?>) member.getParentNode()).getSymbolData(),
table, md);
}
}
} catch (Exception e) {
throw new RuntimeException("Error loading methods in a given scope", e);
}
scope.setHasMethodsLoaded(true);
}
}
示例2: visit
import org.walkmod.javalang.ast.body.ConstructorDeclaration; //导入依赖的package包/类
public Boolean visit(ConstructorDeclaration n1, Node arg) {
ConstructorDeclaration n2 = (ConstructorDeclaration) arg;
if (n1.getModifiers() != n2.getModifiers()) {
return Boolean.FALSE;
}
if (!objEquals(n1.getName(), n2.getName())) {
return Boolean.FALSE;
}
if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) {
return Boolean.FALSE;
}
if (!nodeEquals(n1.getBlock(), n2.getBlock())) {
return Boolean.FALSE;
}
if (!nodesEquals(n1.getParameters(), n2.getParameters())) {
return Boolean.FALSE;
}
if (!nodesEquals(n1.getThrows(), n2.getThrows())) {
return Boolean.FALSE;
}
if (!nodesEquals(n1.getTypeParameters(), n2.getTypeParameters())) {
return Boolean.FALSE;
}
return Boolean.TRUE;
}
示例3: visit
import org.walkmod.javalang.ast.body.ConstructorDeclaration; //导入依赖的package包/类
public void visit(ConstructorDeclaration n, A arg) {
if (n.getJavaDoc() != null) {
n.getJavaDoc().accept(this, arg);
}
if (n.getAnnotations() != null) {
for (AnnotationExpr a : n.getAnnotations()) {
a.accept(this, arg);
}
}
if (n.getTypeParameters() != null) {
for (TypeParameter t : n.getTypeParameters()) {
t.accept(this, arg);
}
}
if (n.getParameters() != null) {
for (Parameter p : n.getParameters()) {
p.accept(this, arg);
}
}
if (n.getThrows() != null) {
for (ClassOrInterfaceType name : n.getThrows()) {
name.accept(this, arg);
}
}
n.getBlock().accept(this, arg);
}
示例4: compare
import org.walkmod.javalang.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@Override
public int compare(ConstructorDeclaration o1, ConstructorDeclaration o2) {
if (o1.getName().equals(o2.getName())) {
List<Parameter> params1 = o1.getParameters();
List<Parameter> params2 = o2.getParameters();
if ((params1 == null || params1.size() == 0) && (params2 == null || params2.size() == 0)) {
return 0;
} else if (params1 != null && params2 != null) {
if (params1.size() == params2.size()) {
Iterator<Parameter> itprms = o1.getParameters().iterator();
Iterator<Parameter> itprms2 = o2.getParameters().iterator();
boolean equalParams = false;
while (itprms.hasNext() && itprms2.hasNext() && !equalParams) {
equalParams = itprms.next().getType().toString().equals(itprms2.next().getType().toString());
}
if (equalParams)
return 0;
else
return new Integer(params1.size()).compareTo(params2.size());
} else {
return new Integer(params1.size()).compareTo(params2.size());
}
}
}
return o1.getName().compareTo(o2.getName());
}
示例5: visit
import org.walkmod.javalang.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@Override
public void visit(ConstructorDeclaration n, A arg) {
List<Symbol<?>> symbols = symbolTable.getScopes().peek().getSymbolsByLocation(n);
Scope scope = symbols.get(0).getInnerScope();
if (scope == null) {
scope = new Scope(symbols.get(0));
symbols.get(0).setInnerScope(scope);
}
symbolTable.pushScope(scope);
LoadTypeParamsAction action = new LoadTypeParamsAction();
action.load(symbolTable, n.getTypeParameters(), (SymbolType) n.getSymbolData());
super.visit(n, arg);
symbolTable.popScope();
}
示例6: visit
import org.walkmod.javalang.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@Override
public void visit(ExplicitConstructorInvocationStmt n, A arg) {
if (n.getTypeArgs() != null) {
for (Type t : n.getTypeArgs()) {
t.accept(this, arg);
}
}
Node p = n.getParentNode();
while (p != null && !(p instanceof ConstructorDeclaration)) {
p = p.getParentNode();
}
if (p != null) {
final SymbolType st;
final ConstructorDeclaration constructorDeclaration = (ConstructorDeclaration) p;
if (n.isThis()) {
st = (SymbolType) constructorDeclaration.getSymbolData();
} else {
final ClassOrInterfaceDeclaration parentNode =
(ClassOrInterfaceDeclaration) constructorDeclaration.getParentNode();
final List<ClassOrInterfaceType> anExtends = parentNode.getExtends();
st = anExtends != null && !anExtends.isEmpty() ? (SymbolType) anExtends.get(0).getSymbolData() : null;
}
if (st != null) {
resolveConstructor(n, n.getArgs(), st, arg);
}
}
}
示例7: pushConstructor
import org.walkmod.javalang.ast.body.ConstructorDeclaration; //导入依赖的package包/类
private void pushConstructor(SymbolType st, SymbolTable table, ConstructorDeclaration md) throws Exception {
Type type = new ClassOrInterfaceType(md.getName());
SymbolType resolvedType = ASTSymbolTypeResolver.getInstance().valueOf(type);
type.setSymbolData(resolvedType);
List<Parameter> params = md.getParameters();
List<TypeParameter> tps = md.getTypeParameters();
SymbolType[] args = null;
boolean hasDynamicArgs = false;
if (params != null) {
args = new SymbolType[params.size()];
for (int i = 0; i < args.length; i++) {
args[i] = ASTSymbolTypeResolver.getInstance().valueOf(params.get(i).getType(), tps);
params.get(i).getType().setSymbolData(args[i]);
if (i == args.length - 1) {
hasDynamicArgs = params.get(i).isVarArgs();
}
}
}
List<SymbolAction> actions = null;
if (actionProvider != null) {
actions = actionProvider.getActions(md);
}
MethodSymbol method = new MethodSymbol(md.getName(), resolvedType, md, st, args, false, hasDynamicArgs,
(java.lang.reflect.Constructor<?>) null, actions);
Scope scope = new Scope(method);
method.setInnerScope(scope);
table.pushScope(scope);
md.accept(expressionTypeAnalyzer, null);
table.popScope(true);
method.setReferencedConstructor(md.getSymbolData().getConstructor());
table.pushSymbol(method);
}
示例8: testConstructorResolution
import org.walkmod.javalang.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@Test
public void testConstructorResolution() throws Exception {
CompilationUnit cu = run("public class A { private String name; public A(String name){this.name = name;}}");
ConstructorDeclaration cd = (ConstructorDeclaration) cu.getTypes().get(0).getMembers().get(1);
Assert.assertNotNull(cd.getSymbolData().getConstructor());
Assert.assertEquals(1, cd.getSymbolData().getConstructor().getParameterTypes().length);
}
示例9: testExplicitThisConstructorInvocationResolution
import org.walkmod.javalang.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@Test
public void testExplicitThisConstructorInvocationResolution() throws Exception {
CompilationUnit cu = run(
"public class A { private String name; public A() { this(\"empty\"); } public A(String name){this.name = name;}}");
ExplicitConstructorInvocationStmt st =
(ExplicitConstructorInvocationStmt) ((ConstructorDeclaration) cu.getTypes().get(0).getMembers().get(1))
.getBlock().getStmts().get(0);
Assert.assertNotNull(st.getSymbolData());
Assert.assertEquals("public A(java.lang.String)", st.getSymbolData().getConstructor().toString());
}
示例10: testExplicitSuperConstructorInvocationResolution
import org.walkmod.javalang.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@Test
public void testExplicitSuperConstructorInvocationResolution() throws Exception {
CompilationUnit cu = run("class A { private String name; public A(String name){this.name = name;}}"
+ "class B extends A { B() { super(\"empty\"); } } ");
ExplicitConstructorInvocationStmt st =
(ExplicitConstructorInvocationStmt) ((ConstructorDeclaration) cu.getTypes().get(1).getMembers().get(0))
.getBlock().getStmts().get(0);
Assert.assertNotNull(st.getSymbolData());
Assert.assertEquals("public A(java.lang.String)", st.getSymbolData().getConstructor().toString());
}
示例11: testGenericMethodWithArrays
import org.walkmod.javalang.ast.body.ConstructorDeclaration; //导入依赖的package包/类
@Test
public void testGenericMethodWithArrays() throws Exception {
CompilationUnit cu = run("import java.util.Collections;\n" + "import java.util.Map;\n"
+ "import java.util.HashMap;\n" + " public class A {\n"
+ " private final Map<String, Integer[]> params;\n" + " public A(Map<String,Integer[]> p) {\n"
+ " Map<String,Integer[]> m = new HashMap<String,Integer[]>(p);\n"
+ " this.params = Collections.unmodifiableMap(m);\n" + " }\n" + "}");
ClassOrInterfaceDeclaration type = (ClassOrInterfaceDeclaration) cu.getTypes().get(0);
ConstructorDeclaration md = (ConstructorDeclaration) type.getMembers().get(1);
Assert.assertNotNull(md.getSymbolData());
}
示例12: visit
import org.walkmod.javalang.ast.body.ConstructorDeclaration; //导入依赖的package包/类
public R visit(ConstructorDeclaration n, A arg) {
if (n.getJavaDoc() != null) {
n.getJavaDoc().accept(this, arg);
}
if (n.getAnnotations() != null) {
for (AnnotationExpr a : n.getAnnotations()) {
a.accept(this, arg);
}
}
if (n.getTypeParameters() != null) {
for (TypeParameter t : n.getTypeParameters()) {
t.accept(this, arg);
}
}
if (n.getParameters() != null) {
for (Parameter p : n.getParameters()) {
p.accept(this, arg);
}
}
if (n.getThrows() != null) {
for (ClassOrInterfaceType name : n.getThrows()) {
name.accept(this, arg);
}
}
n.getBlock().accept(this, arg);
return null;
}
示例13: visit
import org.walkmod.javalang.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<ClassOrInterfaceType> throws_ = visit(_n.getThrows(), _arg);
BlockStmt block = cloneNodes(_n.getBlock(), _arg);
ConstructorDeclaration r = new ConstructorDeclaration(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(),
_n.getEndColumn(), javaDoc, _n.getModifiers(), annotations, typeParameters, _n.getName(), parameters,
throws_, block);
return r;
}
示例14: visit
import org.walkmod.javalang.ast.body.ConstructorDeclaration; //导入依赖的package包/类
public void visit(ConstructorDeclaration n, VisitorContext arg) {
if (preVisitor != null) {
preVisitor.visit(n, arg);
}
super.visit(n, arg);
if (postVisitor != null) {
postVisitor.visit(n, arg);
}
}
示例15: visit
import org.walkmod.javalang.ast.body.ConstructorDeclaration; //导入依赖的package包/类
public Node visit(ConstructorDeclaration n, A arg) {
if (n.getJavaDoc() != null) {
n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg));
}
List<AnnotationExpr> annotations = n.getAnnotations();
if (annotations != null) {
for (int i = 0; i < annotations.size(); i++) {
annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg));
}
removeNulls(annotations);
}
List<TypeParameter> typeParameters = n.getTypeParameters();
if (typeParameters != null) {
for (int i = 0; i < typeParameters.size(); i++) {
typeParameters.set(i, (TypeParameter) typeParameters.get(i).accept(this, arg));
}
removeNulls(typeParameters);
}
List<Parameter> parameters = n.getParameters();
if (parameters != null) {
for (int i = 0; i < parameters.size(); i++) {
parameters.set(i, (Parameter) parameters.get(i).accept(this, arg));
}
removeNulls(parameters);
}
List<ClassOrInterfaceType> throwz = n.getThrows();
if (throwz != null) {
for (int i = 0; i < throwz.size(); i++) {
throwz.set(i, (ClassOrInterfaceType) throwz.get(i).accept(this, arg));
}
removeNulls(throwz);
}
n.setBlock((BlockStmt) n.getBlock().accept(this, arg));
return n;
}