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


Java Block类代码示例

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


Block类属于org.eclipse.jdt.internal.compiler.ast包,在下文中一共展示了Block类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: returnVarNameIfNullCheck

import org.eclipse.jdt.internal.compiler.ast.Block; //导入依赖的package包/类
public char[] returnVarNameIfNullCheck(Statement stat) {
	if (!(stat instanceof IfStatement)) return null;
	
	/* Check that the if's statement is a throw statement, possibly in a block. */ {
		Statement then = ((IfStatement) stat).thenStatement;
		if (then instanceof Block) {
			Statement[] blockStatements = ((Block) then).statements;
			if (blockStatements == null || blockStatements.length == 0) return null;
			then = blockStatements[0];
		}
		
		if (!(then instanceof ThrowStatement)) return null;
	}
	
	/* Check that the if's conditional is like 'x == null'. Return from this method (don't generate
	   a nullcheck) if 'x' is equal to our own variable's name: There's already a nullcheck here. */ {
		Expression cond = ((IfStatement) stat).condition;
		if (!(cond instanceof EqualExpression)) return null;
		EqualExpression bin = (EqualExpression) cond;
		int operatorId = ((bin.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT);
		if (operatorId != OperatorIds.EQUAL_EQUAL) return null;
		if (!(bin.left instanceof SingleNameReference)) return null;
		if (!(bin.right instanceof NullLiteral)) return null;
		return ((SingleNameReference) bin.left).token;
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:27,代码来源:HandleNonNull.java

示例2: add

import org.eclipse.jdt.internal.compiler.ast.Block; //导入依赖的package包/类
public RecoveredElement add(Block nestedBlockDeclaration, int bracketBalanceValue) {

	/* default behavior is to delegate recording to parent if any,
	do not consider elements passed the known end (if set)
	it must be belonging to an enclosing element
	*/
	if (this.fieldDeclaration.declarationSourceEnd > 0
			&& nestedBlockDeclaration.sourceStart > this.fieldDeclaration.declarationSourceEnd){
		resetPendingModifiers();
		if (this.parent == null) return this; // ignore
		return this.parent.add(nestedBlockDeclaration, bracketBalanceValue);
	}
	/* consider that if the opening brace was not found, it is there */
	if (!this.foundOpeningBrace){
		this.foundOpeningBrace = true;
		this.bracketBalance++;
	}
	this.initializerBody = new RecoveredBlock(nestedBlockDeclaration, this, bracketBalanceValue);
	if (nestedBlockDeclaration.sourceEnd == 0) return this.initializerBody;
	return this;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:RecoveredInitializer.java

示例3: updatedFieldDeclaration

import org.eclipse.jdt.internal.compiler.ast.Block; //导入依赖的package包/类
public FieldDeclaration updatedFieldDeclaration(int depth, Set knownTypes){

	if (this.initializerBody != null){
		Block block = this.initializerBody.updatedBlock(depth, knownTypes);
		if (block != null){
			Initializer initializer = (Initializer) this.fieldDeclaration;
			initializer.block = block;

			if (initializer.declarationSourceEnd == 0) {
				initializer.declarationSourceEnd = block.sourceEnd;
				initializer.bodyEnd = block.sourceEnd;
			}
		}
		if (this.localTypeCount > 0) this.fieldDeclaration.bits |= ASTNode.HasLocalType;

	}
	if (this.fieldDeclaration.sourceEnd == 0){
		this.fieldDeclaration.sourceEnd = this.fieldDeclaration.declarationSourceEnd;
	}
	return this.fieldDeclaration;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:RecoveredInitializer.java

示例4: add

import org.eclipse.jdt.internal.compiler.ast.Block; //导入依赖的package包/类
public RecoveredElement add(Block nestedBlockDeclaration, int bracketBalanceValue) {
	/* default behavior is to delegate recording to parent if any,
	do not consider elements passed the known end (if set)
	it must be belonging to an enclosing element
	*/
	if (this.methodDeclaration.declarationSourceEnd > 0
		&& nestedBlockDeclaration.sourceStart
			> this.methodDeclaration.declarationSourceEnd){
				resetPendingModifiers();
				if (this.parent == null){
					return this; // ignore
				} else {
					return this.parent.add(nestedBlockDeclaration, bracketBalanceValue);
				}
	}
	/* consider that if the opening brace was not found, it is there */
	if (!this.foundOpeningBrace){
		this.foundOpeningBrace = true;
		this.bracketBalance++;
	}

	this.methodBody = new RecoveredBlock(nestedBlockDeclaration, this, bracketBalanceValue);
	if (nestedBlockDeclaration.sourceEnd == 0) return this.methodBody;
	return this;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:RecoveredMethod.java

示例5: consumeClassBodyDeclaration

import org.eclipse.jdt.internal.compiler.ast.Block; //导入依赖的package包/类
protected void consumeClassBodyDeclaration() {
	// ClassBodyDeclaration ::= Diet NestedMethod CreateInitializer Block
	//push an Initializer
	//optimize the push/pop
	this.nestedMethod[this.nestedType]--;
	Block block = (Block) this.astStack[this.astPtr--];
	this.astLengthPtr--;
	if (this.diet) block.bits &= ~ASTNode.UndocumentedEmptyBlock; // clear bit since was diet
	Initializer initializer = (Initializer) this.astStack[this.astPtr];
	initializer.declarationSourceStart = initializer.sourceStart = block.sourceStart;
	initializer.block = block;
	this.intPtr--; // pop sourcestart left on the stack by consumeNestedMethod.
	initializer.bodyStart = this.intStack[this.intPtr--];
	this.realBlockPtr--; // pop the block variable counter left on the stack by consumeNestedMethod
	int javadocCommentStart = this.intStack[this.intPtr--];
	if (javadocCommentStart != -1) {
		initializer.declarationSourceStart = javadocCommentStart;
		initializer.javadoc = this.javadoc;
		this.javadoc = null;
	}
	initializer.bodyEnd = this.endPosition;
	initializer.sourceEnd = this.endStatementPosition;
	initializer.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:Parser.java

示例6: consumeStatementSynchronized

import org.eclipse.jdt.internal.compiler.ast.Block; //导入依赖的package包/类
protected void consumeStatementSynchronized() {
	// SynchronizedStatement ::= OnlySynchronized '(' Expression ')' Block
	//optimize the push/pop

	if (this.astLengthStack[this.astLengthPtr] == 0) {
		this.astLengthStack[this.astLengthPtr] = 1;
		this.expressionLengthPtr--;
		this.astStack[++this.astPtr] =
			new SynchronizedStatement(
				this.expressionStack[this.expressionPtr--],
				null,
				this.intStack[this.intPtr--],
				this.endStatementPosition);
	} else {
		this.expressionLengthPtr--;
		this.astStack[this.astPtr] =
			new SynchronizedStatement(
				this.expressionStack[this.expressionPtr--],
				(Block) this.astStack[this.astPtr],
				this.intStack[this.intPtr--],
				this.endStatementPosition);
	}
	this.modifiers = ClassFileConstants.AccDefault;
	this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:Parser.java

示例7: consumeStaticInitializer

import org.eclipse.jdt.internal.compiler.ast.Block; //导入依赖的package包/类
protected void consumeStaticInitializer() {
	// StaticInitializer ::=  StaticOnly Block
	//push an Initializer
	//optimize the push/pop
	Block block = (Block) this.astStack[this.astPtr];
	if (this.diet) block.bits &= ~ASTNode.UndocumentedEmptyBlock; // clear bit set since was diet
	Initializer initializer = new Initializer(block, ClassFileConstants.AccStatic);
	this.astStack[this.astPtr] = initializer;
	initializer.sourceEnd = this.endStatementPosition;
	initializer.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
	this.nestedMethod[this.nestedType] --;
	initializer.declarationSourceStart = this.intStack[this.intPtr--];
	initializer.bodyStart = this.intStack[this.intPtr--];
	initializer.bodyEnd = this.endPosition;
	// doc comment
	initializer.javadoc = this.javadoc;
	this.javadoc = null;

	// recovery
	if (this.currentElement != null){
		this.lastCheckPoint = initializer.declarationSourceEnd;
		this.currentElement = this.currentElement.add(initializer, 0);
		this.lastIgnoredToken = -1;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:Parser.java

示例8: add

import org.eclipse.jdt.internal.compiler.ast.Block; //导入依赖的package包/类
public RecoveredElement add(Block nestedBlockDeclaration, int bracketBalanceValue) {
	resetPendingModifiers();

	/* do not consider a nested block starting passed the block end (if set)
		it must be belonging to an enclosing block */
	if (this.blockDeclaration.sourceEnd != 0
		&& nestedBlockDeclaration.sourceStart > this.blockDeclaration.sourceEnd){
		return this.parent.add(nestedBlockDeclaration, bracketBalanceValue);
	}

	RecoveredBlock element = new RecoveredBlock(nestedBlockDeclaration, this, bracketBalanceValue);

	// if we have a pending Argument, promote it into the new block
	if (this.pendingArgument != null){
		element.attach(this.pendingArgument);
		this.pendingArgument = null;
	}
	if(parser().statementRecoveryActivated) {
		addBlockStatement(element);
	}
	attach(element);
	if (nestedBlockDeclaration.sourceEnd == 0) return element;
	return this;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:RecoveredBlock.java

示例9: visitInitializer

import org.eclipse.jdt.internal.compiler.ast.Block; //导入依赖的package包/类
public void visitInitializer(EclipseNode node, Initializer initializer) {
	Block block = initializer.block;
	boolean s = (block != null && block.statements != null);
	print("<%s INITIALIZER: %s%s%s>",
			(initializer.modifiers & Modifier.STATIC) != 0 ? "static" : "instance",
					s ? "filled" : "blank",
					isGenerated(initializer) ? " (GENERATED)" : "", position(node));
	indent++;
	if (printContent) {
		if (initializer.block != null) print("%s", initializer.block);
		disablePrinting++;
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:14,代码来源:EclipseASTVisitor.java

示例10: generateClearMethod

import org.eclipse.jdt.internal.compiler.ast.Block; //导入依赖的package包/类
private void generateClearMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType) {
	MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
	md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
	md.modifiers = ClassFileConstants.AccPublic;
	
	String pN = new String(data.getPluralName());
	char[] keyFieldName = (pN + "$key").toCharArray();
	char[] valueFieldName = (pN + "$value").toCharArray();
	
	FieldReference thisDotField = new FieldReference(keyFieldName, 0L);
	thisDotField.receiver = new ThisReference(0, 0);
	FieldReference thisDotField2 = new FieldReference(keyFieldName, 0L);
	thisDotField2.receiver = new ThisReference(0, 0);
	FieldReference thisDotField3 = new FieldReference(valueFieldName, 0L);
	thisDotField3.receiver = new ThisReference(0, 0);
	md.selector = HandlerUtil.buildAccessorName("clear", new String(data.getPluralName())).toCharArray();
	MessageSend clearMsg1 = new MessageSend();
	clearMsg1.receiver = thisDotField2;
	clearMsg1.selector = "clear".toCharArray();
	MessageSend clearMsg2 = new MessageSend();
	clearMsg2.receiver = thisDotField3;
	clearMsg2.selector = "clear".toCharArray();
	Block clearMsgs = new Block(2);
	clearMsgs.statements = new Statement[] {clearMsg1, clearMsg2};
	Statement clearStatement = new IfStatement(new EqualExpression(thisDotField, new NullLiteral(0, 0), OperatorIds.NOT_EQUAL), clearMsgs, 0, 0);
	md.statements = returnStatement != null ? new Statement[] {clearStatement, returnStatement} : new Statement[] {clearStatement};
	md.returnType = returnType;
	injectMethod(builderType, md);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:30,代码来源:EclipseJavaUtilMapSingularizer.java

示例11: convert

import org.eclipse.jdt.internal.compiler.ast.Block; //导入依赖的package包/类
private Initializer convert(
    InitializerElementInfo initializerInfo, CompilationResult compilationResult)
    throws JavaModelException {

  Block block = new Block(0);
  Initializer initializer = new Initializer(block, ClassFileConstants.AccDefault);

  int start = initializerInfo.getDeclarationSourceStart();
  int end = initializerInfo.getDeclarationSourceEnd();

  initializer.sourceStart = initializer.declarationSourceStart = start;
  initializer.sourceEnd = initializer.declarationSourceEnd = end;
  initializer.modifiers = initializerInfo.getModifiers();

  /* convert local and anonymous types */
  IJavaElement[] children = initializerInfo.getChildren();
  int typesLength = children.length;
  if (typesLength > 0) {
    Statement[] statements = new Statement[typesLength];
    for (int i = 0; i < typesLength; i++) {
      SourceType type = (SourceType) children[i];
      TypeDeclaration localType = convert(type, compilationResult);
      if ((localType.bits & ASTNode.IsAnonymousType) != 0) {
        QualifiedAllocationExpression expression = new QualifiedAllocationExpression(localType);
        expression.type = localType.superclass;
        localType.superclass = null;
        localType.superInterfaces = null;
        localType.allocation = expression;
        statements[i] = expression;
      } else {
        statements[i] = localType;
      }
    }
    block.statements = statements;
  }

  return initializer;
}
 
开发者ID:eclipse,项目名称:che,代码行数:39,代码来源:SourceTypeConverter.java

示例12: formatGuardClauseBlock

import org.eclipse.jdt.internal.compiler.ast.Block; //导入依赖的package包/类
private void formatGuardClauseBlock(Block block, BlockScope scope) {

		this.scribe.printNextToken(TerminalTokens.TokenNameLBRACE, this.preferences.insert_space_before_opening_brace_in_block);
		this.scribe.space();

		final Statement[] statements = block.statements;
		statements[0].traverse(this, scope);
		this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE, true);
		this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
	}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:11,代码来源:CodeFormatterVisitor.java

示例13: visit

import org.eclipse.jdt.internal.compiler.ast.Block; //导入依赖的package包/类
/**
 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.LambdaExpression, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
 */
public boolean visit(LambdaExpression lambdaExpression, BlockScope scope) {
	
	final int numberOfParens = (lambdaExpression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
	if (numberOfParens > 0) {
		manageOpeningParenthesizedExpression(lambdaExpression, numberOfParens);
	}
	if (isNextToken(TerminalTokens.TokenNameLPAREN)) {
		// Format arguments
		formatMethodArguments(
			null,
			lambdaExpression.arguments(),
			lambdaExpression.getScope(),
			this.preferences.insert_space_before_opening_paren_in_method_declaration,
			this.preferences.insert_space_between_empty_parens_in_method_declaration,
			this.preferences.insert_space_before_closing_paren_in_method_declaration,
			this.preferences.insert_space_after_opening_paren_in_method_declaration,
			this.preferences.insert_space_before_comma_in_method_declaration_parameters,
			this.preferences.insert_space_after_comma_in_method_declaration_parameters,
			this.preferences.alignment_for_parameters_in_method_declaration);
	} else {
		// This MUST be a single, untyped parameter
		this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier);
	}
	if (this.preferences.insert_space_before_lambda_arrow) this.scribe.space();
	this.scribe.printNextToken(TerminalTokens.TokenNameARROW);
	if (this.preferences.insert_space_after_lambda_arrow) this.scribe.space();
	final Statement body = lambdaExpression.body();
	if (body instanceof Block) {
		formatBlock((Block) body, scope, this.preferences.brace_position_for_lambda_body, this.preferences.insert_space_before_opening_brace_in_block);
	} else {
		body.traverse(this, scope);
	}

	if (numberOfParens > 0) {
		manageClosingParenthesizedExpression(lambdaExpression, numberOfParens);
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:42,代码来源:CodeFormatterVisitor.java

示例14: add

import org.eclipse.jdt.internal.compiler.ast.Block; //导入依赖的package包/类
public RecoveredElement add(AbstractMethodDeclaration methodDeclaration, int bracketBalanceValue) {

	/* attach it to last type - if any */
	if (this.typeCount > 0){
		RecoveredType type = this.types[this.typeCount -1];
		int start = type.bodyEnd;
		int end = type.typeDeclaration.bodyEnd;
		type.bodyEnd = 0; // reset position
		type.typeDeclaration.declarationSourceEnd = 0; // reset position
		type.typeDeclaration.bodyEnd = 0;

		int kind = TypeDeclaration.kind(type.typeDeclaration.modifiers);
		if(start > 0 &&
				start < end &&
				kind != TypeDeclaration.INTERFACE_DECL &&
				kind != TypeDeclaration.ANNOTATION_TYPE_DECL) {
			// the } of the last type can be considered as the end of an initializer
			Initializer initializer = new Initializer(new Block(0), 0);
			initializer.bodyStart = end;
			initializer.bodyEnd = end;
			initializer.declarationSourceStart = end;
			initializer.declarationSourceEnd = end;
			initializer.sourceStart = end;
			initializer.sourceEnd = end;
			type.add(initializer, bracketBalanceValue);
		}

		resetPendingModifiers();

		return type.add(methodDeclaration, bracketBalanceValue);
	}
	return this; // ignore
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:34,代码来源:RecoveredUnit.java

示例15: add

import org.eclipse.jdt.internal.compiler.ast.Block; //导入依赖的package包/类
public RecoveredElement add(Block nestedBlockDeclaration, int bracketBalanceValue) {

	/* default behavior is to delegate recording to parent if any */
	resetPendingModifiers();
	if (this.parent == null) return this; // ignore
	this.updateSourceEndIfNecessary(previousAvailableLineEnd(nestedBlockDeclaration.sourceStart - 1));
	return this.parent.add(nestedBlockDeclaration, bracketBalanceValue);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:9,代码来源:RecoveredElement.java


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