当前位置: 首页>>代码示例>>Java>>正文


Java TypeDeclaration.addClinit方法代码示例

本文整理汇总了Java中org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.addClinit方法的典型用法代码示例。如果您正苦于以下问题:Java TypeDeclaration.addClinit方法的具体用法?Java TypeDeclaration.addClinit怎么用?Java TypeDeclaration.addClinit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.internal.compiler.ast.TypeDeclaration的用法示例。


在下文中一共展示了TypeDeclaration.addClinit方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: consumeAnnotationTypeDeclaration

import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; //导入方法依赖的package包/类
protected void consumeAnnotationTypeDeclaration() {
	int length;
	if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
		//there are length declarations
		//dispatch according to the type of the declarations
		dispatchDeclarationInto(length);
	}

	TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr];

	//convert constructor that do not have the type's name into methods
	typeDecl.checkConstructors(this);

	//always add <clinit> (will be remove at code gen time if empty)
	if (this.scanner.containsAssertKeyword) {
		typeDecl.bits |= ASTNode.ContainsAssertion;
	}
	typeDecl.addClinit();
	typeDecl.bodyEnd = this.endStatementPosition;
	if (length == 0 && !containsComment(typeDecl.bodyStart, typeDecl.bodyEnd)) {
		typeDecl.bits |= ASTNode.UndocumentedEmptyBlock;
	}
	typeDecl.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:Parser.java

示例2: injectField

import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; //导入方法依赖的package包/类
/**
 * Inserts a field into an existing type. The type must represent a {@code TypeDeclaration}.
 */
public static EclipseNode injectField(EclipseNode type, FieldDeclaration field) {
	TypeDeclaration parent = (TypeDeclaration) type.get();
	
	if (parent.fields == null) {
		parent.fields = new FieldDeclaration[1];
		parent.fields[0] = field;
	} else {
		int size = parent.fields.length;
		FieldDeclaration[] newArray = new FieldDeclaration[size + 1];
		System.arraycopy(parent.fields, 0, newArray, 0, size);
		int index = 0;
		for (; index < size; index++) {
			FieldDeclaration f = newArray[index];
			if (isEnumConstant(f) || isGenerated(f)) continue;
			break;
		}
		System.arraycopy(newArray, index, newArray, index + 1, size - index);
		newArray[index] = field;
		parent.fields = newArray;
	}
	
	if (isEnumConstant(field) || (field.modifiers & Modifier.STATIC) != 0) {
		if (!hasClinit(parent)) {
			parent.addClinit();
		}
	}
	
	return type.add(field, Kind.FIELD);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:33,代码来源:EclipseHandlerUtil.java

示例3: consumeEnumDeclaration

import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; //导入方法依赖的package包/类
protected void consumeEnumDeclaration() {
	// EnumDeclaration ::= EnumHeader ClassHeaderImplementsopt EnumBody
	int length;
	if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
		//there are length declarations
		//dispatch according to the type of the declarations
		dispatchDeclarationIntoEnumDeclaration(length);
	}

	TypeDeclaration enumDeclaration = (TypeDeclaration) this.astStack[this.astPtr];

	//convert constructor that do not have the type's name into methods
	boolean hasConstructor = enumDeclaration.checkConstructors(this);

	//add the default constructor when needed
	if (!hasConstructor) {
		boolean insideFieldInitializer = false;
		if (this.diet) {
			for (int i = this.nestedType; i > 0; i--){
				if (this.variablesCounter[i] > 0) {
					insideFieldInitializer = true;
					break;
				}
			}
		}
		enumDeclaration.createDefaultConstructor(!this.diet || insideFieldInitializer, true);
	}

	//always add <clinit> (will be remove at code gen time if empty)
	if (this.scanner.containsAssertKeyword) {
		enumDeclaration.bits |= ASTNode.ContainsAssertion;
	}
	enumDeclaration.addClinit();
	enumDeclaration.bodyEnd = this.endStatementPosition;
	if (length == 0 && !containsComment(enumDeclaration.bodyStart, enumDeclaration.bodyEnd)) {
		enumDeclaration.bits |= ASTNode.UndocumentedEmptyBlock;
	}

	enumDeclaration.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:41,代码来源:Parser.java

示例4: consumeInterfaceDeclaration

import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; //导入方法依赖的package包/类
protected void consumeInterfaceDeclaration() {
	// see consumeClassDeclaration in case of changes: duplicated code
	// InterfaceDeclaration ::= InterfaceHeader InterfaceBody
	int length;
	if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
		//there are length declarations
		//dispatch.....according to the type of the declarations
		dispatchDeclarationInto(length);
	}

	TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr];

	//convert constructor that do not have the type's name into methods
	typeDecl.checkConstructors(this);
	
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=212713, 
	// reject initializers that have been tolerated by the grammar.
	FieldDeclaration [] fields = typeDecl.fields;
	int fieldCount = fields == null ? 0 : fields.length;
	for (int i = 0; i < fieldCount; i++) {
		FieldDeclaration field = fields[i];
		if (field instanceof Initializer) {
			problemReporter().interfaceCannotHaveInitializers(typeDecl.name, field);
		}
	}

	//always add <clinit> (will be remove at code gen time if empty)
	if (this.scanner.containsAssertKeyword) {
		typeDecl.bits |= ASTNode.ContainsAssertion;
	}
	typeDecl.addClinit();
	typeDecl.bodyEnd = this.endStatementPosition;
	if (length == 0 && !containsComment(typeDecl.bodyStart, typeDecl.bodyEnd)) {
		typeDecl.bits |= ASTNode.UndocumentedEmptyBlock;
	}
	typeDecl.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:38,代码来源:Parser.java

示例5: changeModifiersAndGenerateConstructor

import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; //导入方法依赖的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();
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:49,代码来源:HandleUtilityClass.java

示例6: consumeClassDeclaration

import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; //导入方法依赖的package包/类
protected void consumeClassDeclaration() {
	// ClassDeclaration ::= ClassHeader ClassBody

	int length;
	if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
		//there are length declarations
		//dispatch according to the type of the declarations
		dispatchDeclarationInto(length);
	}

	TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr];

	//convert constructor that do not have the type's name into methods
	boolean hasConstructor = typeDecl.checkConstructors(this);

	//add the default constructor when needed (interface don't have it)
	if (!hasConstructor) {
		switch(TypeDeclaration.kind(typeDecl.modifiers)) {
			case TypeDeclaration.CLASS_DECL :
			case TypeDeclaration.ENUM_DECL :
				boolean insideFieldInitializer = false;
				if (this.diet) {
					for (int i = this.nestedType; i > 0; i--){
						if (this.variablesCounter[i] > 0) {
							insideFieldInitializer = true;
							break;
						}
					}
				}
				typeDecl.createDefaultConstructor(!this.diet || insideFieldInitializer, true);
		}
	}
	//always add <clinit> (will be remove at code gen time if empty)
	if (this.scanner.containsAssertKeyword) {
		typeDecl.bits |= ASTNode.ContainsAssertion;
	}
	typeDecl.addClinit();
	typeDecl.bodyEnd = this.endStatementPosition;
	if (length == 0 && !containsComment(typeDecl.bodyStart, typeDecl.bodyEnd)) {
		typeDecl.bits |= ASTNode.UndocumentedEmptyBlock;
	}

	typeDecl.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:45,代码来源:Parser.java


注:本文中的org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.addClinit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。