本文整理汇总了Java中org.eclipse.jdt.internal.compiler.ast.ASTNode.IsDefaultConstructor方法的典型用法代码示例。如果您正苦于以下问题:Java ASTNode.IsDefaultConstructor方法的具体用法?Java ASTNode.IsDefaultConstructor怎么用?Java ASTNode.IsDefaultConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.compiler.ast.ASTNode
的用法示例。
在下文中一共展示了ASTNode.IsDefaultConstructor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: constructorExists
import org.eclipse.jdt.internal.compiler.ast.ASTNode; //导入方法依赖的package包/类
/**
* Checks if there is a (non-default) constructor. In case of multiple constructors (overloading), only
* the first constructor decides if EXISTS_BY_USER or EXISTS_BY_LOMBOK is returned.
*
* @param node Any node that represents the Type (TypeDeclaration) to look in, or any child node thereof.
*/
public static MemberExistsResult constructorExists(EclipseNode node) {
while (node != null && !(node.get() instanceof TypeDeclaration)) {
node = node.up();
}
if (node != null && node.get() instanceof TypeDeclaration) {
TypeDeclaration typeDecl = (TypeDeclaration)node.get();
if (typeDecl.methods != null) top: for (AbstractMethodDeclaration def : typeDecl.methods) {
if (def instanceof ConstructorDeclaration) {
if ((def.bits & ASTNode.IsDefaultConstructor) != 0) continue;
if (def.annotations != null) for (Annotation anno : def.annotations) {
if (typeMatches(Tolerate.class, node, anno.type)) continue top;
}
return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
}
}
}
return MemberExistsResult.NOT_EXISTS;
}
示例2: injectMethod
import org.eclipse.jdt.internal.compiler.ast.ASTNode; //导入方法依赖的package包/类
/**
* Inserts a method into an existing type. The type must represent a {@code TypeDeclaration}.
*/
public static EclipseNode injectMethod(EclipseNode type, AbstractMethodDeclaration method) {
method.annotations = addSuppressWarningsAll(type, method, method.annotations);
method.annotations = addGenerated(type, method, method.annotations);
TypeDeclaration parent = (TypeDeclaration) type.get();
if (parent.methods == null) {
parent.methods = new AbstractMethodDeclaration[1];
parent.methods[0] = method;
} else {
if (method instanceof ConstructorDeclaration) {
for (int i = 0 ; i < parent.methods.length ; i++) {
if (parent.methods[i] instanceof ConstructorDeclaration &&
(parent.methods[i].bits & ASTNode.IsDefaultConstructor) != 0) {
EclipseNode tossMe = type.getNodeFor(parent.methods[i]);
AbstractMethodDeclaration[] withoutGeneratedConstructor = new AbstractMethodDeclaration[parent.methods.length - 1];
System.arraycopy(parent.methods, 0, withoutGeneratedConstructor, 0, i);
System.arraycopy(parent.methods, i + 1, withoutGeneratedConstructor, i, parent.methods.length - i - 1);
parent.methods = withoutGeneratedConstructor;
if (tossMe != null) tossMe.up().removeChild(tossMe);
break;
}
}
}
//We insert the method in the last position of the methods registered to the type
//When changing this behavior, this may trigger issue #155 and #377
AbstractMethodDeclaration[] newArray = new AbstractMethodDeclaration[parent.methods.length + 1];
System.arraycopy(parent.methods, 0, newArray, 0, parent.methods.length);
newArray[parent.methods.length] = method;
parent.methods = newArray;
}
return type.add(method, Kind.METHOD);
}
示例3: changeModifiersAndGenerateConstructor
import org.eclipse.jdt.internal.compiler.ast.ASTNode; //导入方法依赖的package包/类
private void changeModifiersAndGenerateConstructor(EclipseNode typeNode, EclipseNode annotationNode) {
TypeDeclaration classDecl = (TypeDeclaration) typeNode.get();
boolean makeConstructor = true;
classDecl.modifiers |= ClassFileConstants.AccFinal;
boolean markStatic = true;
boolean requiresClInit = false;
boolean alreadyHasClinit = false;
if (typeNode.up().getKind() == Kind.COMPILATION_UNIT) markStatic = false;
if (markStatic && typeNode.up().getKind() == Kind.TYPE) {
TypeDeclaration typeDecl = (TypeDeclaration) typeNode.up().get();
if ((typeDecl.modifiers & ClassFileConstants.AccInterface) != 0) markStatic = false;
}
if (markStatic) classDecl.modifiers |= ClassFileConstants.AccStatic;
for (EclipseNode element : typeNode.down()) {
if (element.getKind() == Kind.FIELD) {
FieldDeclaration fieldDecl = (FieldDeclaration) element.get();
if ((fieldDecl.modifiers & ClassFileConstants.AccStatic) == 0) {
requiresClInit = true;
fieldDecl.modifiers |= ClassFileConstants.AccStatic;
}
} else if (element.getKind() == Kind.METHOD) {
AbstractMethodDeclaration amd = (AbstractMethodDeclaration) element.get();
if (amd instanceof ConstructorDeclaration) {
ConstructorDeclaration constrDecl = (ConstructorDeclaration) element.get();
if (getGeneratedBy(constrDecl) == null && (constrDecl.bits & ASTNode.IsDefaultConstructor) == 0) {
element.addError("@UtilityClasses cannot have declared constructors.");
makeConstructor = false;
continue;
}
} else if (amd instanceof MethodDeclaration) {
amd.modifiers |= ClassFileConstants.AccStatic;
} else if (amd instanceof Clinit) {
alreadyHasClinit = true;
}
} else if (element.getKind() == Kind.TYPE) {
((TypeDeclaration) element.get()).modifiers |= ClassFileConstants.AccStatic;
}
}
if (makeConstructor) createPrivateDefaultConstructor(typeNode, annotationNode);
if (requiresClInit && !alreadyHasClinit) classDecl.addClinit();
}