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

Java ConditionalExpression类代码示例

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

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



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

示例1: getSize

import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; //导入依赖的package包/类
/** Generates 'this.<em>name</em>.size()' as an expression; if nullGuard is true, it's this.name == null ? 0 : this.name.size(). */
protected Expression getSize(EclipseNode builderType, char[] name, boolean nullGuard) {
	MessageSend invoke = new MessageSend();
	ThisReference thisRef = new ThisReference(0, 0);
	FieldReference thisDotName = new FieldReference(name, 0L);
	thisDotName.receiver = thisRef;
	invoke.receiver = thisDotName;
	invoke.selector = SIZE_TEXT;
	if (!nullGuard) return invoke;
	
	ThisReference cdnThisRef = new ThisReference(0, 0);
	FieldReference cdnThisDotName = new FieldReference(name, 0L);
	cdnThisDotName.receiver = cdnThisRef;
	NullLiteral nullLiteral = new NullLiteral(0, 0);
	EqualExpression isNull = new EqualExpression(cdnThisDotName, nullLiteral, OperatorIds.EQUAL_EQUAL);
	IntLiteral zeroLiteral = makeIntLiteral(new char[] {'0'}, null);
	ConditionalExpression conditional = new ConditionalExpression(isNull, zeroLiteral, invoke);
	return conditional;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:20,代码来源:EclipseSingularsRecipes.java


示例2: addConstraintsToC_OneExpr

import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; //导入依赖的package包/类
private boolean addConstraintsToC_OneExpr(Expression expri, Set<ConstraintFormula> c, TypeBinding fsi, TypeBinding substF, MethodBinding method) {
	// For all i (1 ≤ i ≤ k), if ei is not pertinent to applicability, the set contains ⟨ei → θ Fi⟩.
	if (!expri.isPertinentToApplicability(fsi, method)) {
		c.add(new ConstraintExpressionFormula(expri, substF, ReductionResult.COMPATIBLE, ARGUMENT_CONSTRAINTS_ARE_SOFT));
	}
	if (expri instanceof FunctionalExpression) {
		c.add(new ConstraintExceptionFormula((FunctionalExpression) expri, substF));
	} else if (expri instanceof Invocation && expri.isPolyExpression()) {
		Invocation invocation = (Invocation) expri;
		MethodBinding innerMethod = invocation.binding(null, false, null);
		if (innerMethod instanceof ParameterizedGenericMethodBinding) {
			InferenceContext18 innerCtx = invocation.getInferenceContext((ParameterizedMethodBinding) innerMethod);
			if (innerCtx != null) { // otherwise innerMethod does not participate in inference
				return addConstraintsToC(invocation.arguments(), c, innerMethod.genericMethod(), innerCtx.inferenceKind);
			}
		}
	} else if (expri instanceof ConditionalExpression) {
		ConditionalExpression ce = (ConditionalExpression) expri;
		return addConstraintsToC_OneExpr(ce.valueIfTrue, c, fsi, substF, method)
			 && addConstraintsToC_OneExpr(ce.valueIfFalse, c, fsi, substF, method);
	}
	return true;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:24,代码来源:InferenceContext18.java


示例3: visitAny

import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; //导入依赖的package包/类
@Override public void visitAny(ASTNode node) {
	Collection<ComponentField> fields = findFields(node);
	for (ComponentField f : fields) {
		String skipListKey = node.getClass().getSimpleName() + "/" + f.field.getName();
		if (propertySkipList.contains(skipListKey)) continue;
		
		Object value;
		
		if (node instanceof ConditionalExpression) ((ConditionalExpression)node).valueIfTrue.sourceEnd = -2;
		if ("originalSourceEnd".equals(f.field.getName()) && node instanceof ArrayTypeReference) {
			//workaround for eclipse arbitrarily skipping this field and setting it.
			value = -2;
		} else {
			value = readField(f.field, node);
		}
		if (value == null) {
			continue;
		}
		
		if (propertyIfValueSkipList.get(skipListKey).contains(value)) continue;
		
		boolean trackRef = true;
		for (ReferenceTrackingSkip skip : referenceTrackingSkipList) {
			if (skip.getParent() != null && !skip.getParent().isInstance(node)) continue;
			if (skip.getType() != null && !skip.getType().isInstance(value)) continue;
			trackRef = false;
			break;
		}
		f.print(printer, this, value, trackRef);
	}
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:32,代码来源:EcjTreePrinter.java


示例4: consumeConditionalExpression

import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; //导入依赖的package包/类
protected void consumeConditionalExpression(int op) {
	// ConditionalExpression ::= ConditionalOrExpression '?' Expression ':' ConditionalExpression
	//optimize the push/pop
	this.intPtr -= 2;//consume position of the question mark
	this.expressionPtr -= 2;
	this.expressionLengthPtr -= 2;
	this.expressionStack[this.expressionPtr] =
		new ConditionalExpression(
			this.expressionStack[this.expressionPtr],
			this.expressionStack[this.expressionPtr + 1],
			this.expressionStack[this.expressionPtr + 2]);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:13,代码来源:Parser.java


示例5: consumeConditionalExpressionWithName

import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; //导入依赖的package包/类
/**
 * @param op
 */
protected void consumeConditionalExpressionWithName(int op) {
	// ConditionalExpression ::= Name '?' Expression ':' ConditionalExpression
	this.intPtr -= 2;//consume position of the question mark
	pushOnExpressionStack(getUnspecifiedReferenceOptimized());
	this.expressionPtr -= 2;
	this.expressionLengthPtr -= 2;
	this.expressionStack[this.expressionPtr] =
		new ConditionalExpression(
			this.expressionStack[this.expressionPtr + 2],
			this.expressionStack[this.expressionPtr],
			this.expressionStack[this.expressionPtr + 1]);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:16,代码来源:Parser.java


示例6: conditionalArgumentsIncompatibleTypes

import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; //导入依赖的package包/类
public void conditionalArgumentsIncompatibleTypes(ConditionalExpression expression, TypeBinding trueType, TypeBinding falseType) {
	this.handle(
		IProblem.IncompatibleTypesInConditionalOperator,
		new String[] {new String(trueType.readableName()), new String(falseType.readableName())},
		new String[] {new String(trueType.shortReadableName()), new String(falseType.shortReadableName())},
		expression.sourceStart,
		expression.sourceEnd);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:9,代码来源:ProblemReporter.java


示例7: conditionalArgumentsIncompatibleTypes

import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; //导入依赖的package包/类
public void conditionalArgumentsIncompatibleTypes(ConditionalExpression expression, TypeBinding trueType, TypeBinding falseType) {
	this.handle(
		IProblem.IncompatibleTypesInConditionalOperator,
		new String[] {new String(trueType.readableName()), new String(falseType.readableName())},
		new String[] {new String(trueType.sourceName()), new String(falseType.sourceName())},
		expression.sourceStart,
		expression.sourceEnd);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:9,代码来源:ProblemReporter.java


示例8: endVisit

import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; //导入依赖的package包/类
@Override
public void endVisit(ConditionalExpression x, BlockScope scope) {
  try {
    SourceInfo info = makeSourceInfo(x);
    JType type = typeMap.get(x.resolvedType);
    JExpression valueIfFalse = pop(x.valueIfFalse);
    JExpression valueIfTrue = pop(x.valueIfTrue);
    JExpression condition = pop(x.condition);
    push(new JConditional(info, type, condition, valueIfTrue, valueIfFalse));
  } catch (Throwable e) {
    throw translateException(x, e);
  }
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:14,代码来源:GwtAstBuilder.java


示例9: createWither

import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; //导入依赖的package包/类
public MethodDeclaration createWither(TypeDeclaration parent, EclipseNode fieldNode, String name, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam, boolean makeAbstract ) {
	ASTNode source = sourceNode.get();
	if (name == null) return null;
	FieldDeclaration field = (FieldDeclaration) fieldNode.get();
	int pS = source.sourceStart, pE = source.sourceEnd;
	long p = (long) pS << 32 | pE;
	MethodDeclaration method = new MethodDeclaration(parent.compilationResult);
	if (makeAbstract) modifier = modifier | ClassFileConstants.AccAbstract | ExtraCompilerModifiers.AccSemicolonBody;
	method.modifiers = modifier;
	method.returnType = cloneSelfType(fieldNode, source);
	if (method.returnType == null) return null;
	
	Annotation[] deprecated = null;
	if (isFieldDeprecated(fieldNode)) {
		deprecated = new Annotation[] { generateDeprecatedAnnotation(source) };
	}
	method.annotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated);
	Argument param = new Argument(field.name, p, copyType(field.type, source), ClassFileConstants.AccFinal);
	param.sourceStart = pS; param.sourceEnd = pE;
	method.arguments = new Argument[] { param };
	method.selector = name.toCharArray();
	method.binding = null;
	method.thrownExceptions = null;
	method.typeParameters = null;
	method.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
	
	Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN);
	Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN);
	
	if (!makeAbstract) {
		List<Expression> args = new ArrayList<Expression>();
		for (EclipseNode child : fieldNode.up().down()) {
			if (child.getKind() != Kind.FIELD) continue;
			FieldDeclaration childDecl = (FieldDeclaration) child.get();
			// Skip fields that start with $
			if (childDecl.name != null && childDecl.name.length > 0 && childDecl.name[0] == '$') continue;
			long fieldFlags = childDecl.modifiers;
			// Skip static fields.
			if ((fieldFlags & ClassFileConstants.AccStatic) != 0) continue;
			// Skip initialized final fields.
			if (((fieldFlags & ClassFileConstants.AccFinal) != 0) && childDecl.initialization != null) continue;
			if (child.get() == fieldNode.get()) {
				args.add(new SingleNameReference(field.name, p));
			} else {
				args.add(createFieldAccessor(child, FieldAccess.ALWAYS_FIELD, source));
			}
		}
		
		AllocationExpression constructorCall = new AllocationExpression();
		constructorCall.arguments = args.toArray(new Expression[0]);
		constructorCall.type = cloneSelfType(fieldNode, source);
		
		Expression identityCheck = new EqualExpression(
				createFieldAccessor(fieldNode, FieldAccess.ALWAYS_FIELD, source),
				new SingleNameReference(field.name, p),
				OperatorIds.EQUAL_EQUAL);
		ThisReference thisRef = new ThisReference(pS, pE);
		Expression conditional = new ConditionalExpression(identityCheck, thisRef, constructorCall);
		Statement returnStatement = new ReturnStatement(conditional, pS, pE);
		method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart;
		method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;
		
		List<Statement> statements = new ArrayList<Statement>(5);
		if (nonNulls.length > 0) {
			Statement nullCheck = generateNullCheck(field, sourceNode);
			if (nullCheck != null) statements.add(nullCheck);
		}
		statements.add(returnStatement);
		
		method.statements = statements.toArray(new Statement[0]);
	}
	param.annotations = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0]));
	
	method.traverse(new SetGeneratedByVisitor(source), parent.scope);
	return method;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:77,代码来源:HandleWither.java


示例10: visit

import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; //导入依赖的package包/类
@Override public boolean visit(ConditionalExpression node, BlockScope scope) {
	fixPositions(setGeneratedBy(node, source));
	return super.visit(node, scope);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:5,代码来源:SetGeneratedByVisitor.java


示例11: createWither

import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; //导入依赖的package包/类
public MethodDeclaration createWither(TypeDeclaration parent, EclipseNode fieldNode, String name, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam) {
	ASTNode source = sourceNode.get();
	if (name == null) return null;
	FieldDeclaration field = (FieldDeclaration) fieldNode.get();
	int pS = source.sourceStart, pE = source.sourceEnd;
	long p = (long)pS << 32 | pE;
	MethodDeclaration method = new MethodDeclaration(parent.compilationResult);
	method.modifiers = modifier;
	method.returnType = cloneSelfType(fieldNode, source);
	if (method.returnType == null) return null;
	
	Annotation[] deprecated = null;
	if (isFieldDeprecated(fieldNode)) {
		deprecated = new Annotation[] { generateDeprecatedAnnotation(source) };
	}
	method.annotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated);
	Argument param = new Argument(field.name, p, copyType(field.type, source), Modifier.FINAL);
	param.sourceStart = pS; param.sourceEnd = pE;
	method.arguments = new Argument[] { param };
	method.selector = name.toCharArray();
	method.binding = null;
	method.thrownExceptions = null;
	method.typeParameters = null;
	method.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
	
	List<Expression> args = new ArrayList<Expression>();
	for (EclipseNode child : fieldNode.up().down()) {
		if (child.getKind() != Kind.FIELD) continue;
		FieldDeclaration childDecl = (FieldDeclaration) child.get();
		// Skip fields that start with $
		if (childDecl.name != null && childDecl.name.length > 0 && childDecl.name[0] == '$') continue;
		long fieldFlags = childDecl.modifiers;
		// Skip static fields.
		if ((fieldFlags & ClassFileConstants.AccStatic) != 0) continue;
		// Skip initialized final fields.
		if (((fieldFlags & ClassFileConstants.AccFinal) != 0) && childDecl.initialization != null) continue;
		if (child.get() == fieldNode.get()) {
			args.add(new SingleNameReference(field.name, p));
		} else {
			args.add(createFieldAccessor(child, FieldAccess.ALWAYS_FIELD, source));
		}
	}
	
	AllocationExpression constructorCall = new AllocationExpression();
	constructorCall.arguments = args.toArray(new Expression[0]);
	constructorCall.type = cloneSelfType(fieldNode, source);
	
	Expression identityCheck = new EqualExpression(
			createFieldAccessor(fieldNode, FieldAccess.ALWAYS_FIELD, source),
			new SingleNameReference(field.name, p),
			OperatorIds.EQUAL_EQUAL);
	ThisReference thisRef = new ThisReference(pS, pE);
	Expression conditional = new ConditionalExpression(identityCheck, thisRef, constructorCall);
	Statement returnStatement = new ReturnStatement(conditional, pS, pE);
	method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart;
	method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;
	
	Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN);
	Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN);
	List<Statement> statements = new ArrayList<Statement>(5);
	if (nonNulls.length > 0) {
		Statement nullCheck = generateNullCheck(field, sourceNode);
		if (nullCheck != null) statements.add(nullCheck);
	}
	statements.add(returnStatement);
	
	method.statements = statements.toArray(new Statement[0]);
	
	param.annotations = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0]));
	
	method.traverse(new SetGeneratedByVisitor(source), parent.scope);
	return method;
}
 
开发者ID:mobmead,项目名称:EasyMPermission,代码行数:74,代码来源:HandleWither.java


示例12: visit

import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; //导入依赖的package包/类
public boolean visit(
	ConditionalExpression conditionalExpression,
	BlockScope scope) {
		addRealFragment(conditionalExpression);
		return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:7,代码来源:BinaryExpressionFragmentBuilder.java


示例13: visit

import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; //导入依赖的package包/类
/**
 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.ConditionalExpression, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
 */
public boolean visit(
	ConditionalExpression conditionalExpression,
	BlockScope scope) {

	final int numberOfParens = (conditionalExpression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
	if (numberOfParens > 0) {
		manageOpeningParenthesizedExpression(conditionalExpression, numberOfParens);
	}
	conditionalExpression.condition.traverse(this, scope);

	Alignment conditionalExpressionAlignment =this.scribe.createAlignment(
			Alignment.CONDITIONAL_EXPRESSION,
			this.preferences.alignment_for_conditional_expression,
			2,
			this.scribe.scanner.currentPosition);

	this.scribe.enterAlignment(conditionalExpressionAlignment);
	boolean ok = false;
	do {
		try {
			this.scribe.alignFragment(conditionalExpressionAlignment, 0);
			this.scribe.printNextToken(TerminalTokens.TokenNameQUESTION, this.preferences.insert_space_before_question_in_conditional);

			if (this.preferences.insert_space_after_question_in_conditional) {
				this.scribe.space();
			}
			conditionalExpression.valueIfTrue.traverse(this, scope);
			this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
			this.scribe.alignFragment(conditionalExpressionAlignment, 1);
			this.scribe.printNextToken(TerminalTokens.TokenNameCOLON, this.preferences.insert_space_before_colon_in_conditional);

			if (this.preferences.insert_space_after_colon_in_conditional) {
				this.scribe.space();
			}
			conditionalExpression.valueIfFalse.traverse(this, scope);

			ok = true;
		} catch (AlignmentException e) {
			this.scribe.redoAlignment(e);
		}
	} while (!ok);
	this.scribe.exitAlignment(conditionalExpressionAlignment, true);

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


示例14: checkExpression

import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; //导入依赖的package包/类
private boolean checkExpression(Expression expri, TypeBinding[] u, TypeBinding r1, TypeBinding[] v, TypeBinding r2) 
		throws InferenceFailureException {
	if (expri instanceof LambdaExpression && !((LambdaExpression)expri).argumentsTypeElided()) {
		if (r2.id == TypeIds.T_void)
			return true;
		LambdaExpression lambda = (LambdaExpression) expri;
		Expression[] results = lambda.resultExpressions();
		if (r1.isFunctionalInterface(this.scope) && r2.isFunctionalInterface(this.scope)
				&& !(r1.isCompatibleWith(r2) || r2.isCompatibleWith(r1))) {
			// "these rules are applied recursively to R1 and R2, for each result expression in expi."
			// (what does "applied .. to R1 and R2" mean? Why mention R1/R2 and not U/V?)
			for (int i = 0; i < results.length; i++) {
				if (!checkExpression(results[i], u, r1, v, r2))
					return false;
			}
			return true;
		}
		checkPrimitive1: if (r1.isPrimitiveType() && !r2.isPrimitiveType()) {
			// check: each result expression is a standalone expression of a primitive type
			for (int i = 0; i < results.length; i++) {
				if (results[i].isPolyExpression() || (results[i].resolvedType != null && !results[i].resolvedType.isPrimitiveType()))
					break checkPrimitive1;
			}
			return true;
		}
		checkPrimitive2: if (r2.isPrimitiveType() && !r1.isPrimitiveType()) {
			for (int i = 0; i < results.length; i++) {
				// for all expressions (not for any expression not)
				if (!(
						(!results[i].isPolyExpression() && (results[i].resolvedType != null && !results[i].resolvedType.isPrimitiveType())) // standalone of a referencetype
						|| results[i].isPolyExpression()))	// or a poly
					break checkPrimitive2;
			}
			return true;
		}
		return reduceAndIncorporate(ConstraintTypeFormula.create(r1, r2, ReductionResult.SUBTYPE));
	} else if (expri instanceof ReferenceExpression && ((ReferenceExpression)expri).isExactMethodReference()) {
		for (int i = 0; i < u.length; i++) {
			ReferenceExpression reference = (ReferenceExpression) expri;
			if (!reduceAndIncorporate(ConstraintTypeFormula.create(u[i], v[i], ReductionResult.SAME)))
				return false;
			if (r2.id == TypeIds.T_void)
				return true;
			MethodBinding method = reference.findCompileTimeMethodTargeting(null, this.scope); // TODO directly access exactMethodBinding!
			TypeBinding returnType = method.isConstructor() ? method.declaringClass : method.returnType;
			if (r1.isPrimitiveType() && !r2.isPrimitiveType() && returnType.isPrimitiveType()) 
				return true;
			if (r2.isPrimitiveType() && !r1.isPrimitiveType() && !returnType.isPrimitiveType())
				return true;
		}
		return reduceAndIncorporate(ConstraintTypeFormula.create(r1, r2, ReductionResult.SUBTYPE));
	} else if (expri instanceof ConditionalExpression) {
		ConditionalExpression cond = (ConditionalExpression) expri;
		return  checkExpression(cond.valueIfTrue, u, r1, v, r2) && checkExpression(cond.valueIfFalse, u, r1, v, r2);
	} else {
		return false;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:59,代码来源:InferenceContext18.java


示例15: createWither

import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; //导入依赖的package包/类
private MethodDeclaration createWither(TypeDeclaration parent, EclipseNode fieldNode, String name, int modifier, ASTNode source, List<Annotation> onMethod, List<Annotation> onParam) {
	if (name == null) return null;
	FieldDeclaration field = (FieldDeclaration) fieldNode.get();
	int pS = source.sourceStart, pE = source.sourceEnd;
	long p = (long)pS << 32 | pE;
	MethodDeclaration method = new MethodDeclaration(parent.compilationResult);
	method.modifiers = modifier;
	method.returnType = cloneSelfType(fieldNode, source);
	if (method.returnType == null) return null;
	
	Annotation[] deprecated = null;
	if (isFieldDeprecated(fieldNode)) {
		deprecated = new Annotation[] { generateDeprecatedAnnotation(source) };
	}
	Annotation[] copiedAnnotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated);
	if (copiedAnnotations.length != 0) {
		method.annotations = copiedAnnotations;
	}
	Argument param = new Argument(field.name, p, copyType(field.type, source), Modifier.FINAL);
	param.sourceStart = pS; param.sourceEnd = pE;
	method.arguments = new Argument[] { param };
	method.selector = name.toCharArray();
	method.binding = null;
	method.thrownExceptions = null;
	method.typeParameters = null;
	method.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
	
	List<Expression> args = new ArrayList<Expression>();
	for (EclipseNode child : fieldNode.up().down()) {
		if (child.getKind() != Kind.FIELD) continue;
		FieldDeclaration childDecl = (FieldDeclaration) child.get();
		// Skip fields that start with $
		if (childDecl.name != null && childDecl.name.length > 0 && childDecl.name[0] == '$') continue;
		long fieldFlags = childDecl.modifiers;
		// Skip static fields.
		if ((fieldFlags & ClassFileConstants.AccStatic) != 0) continue;
		// Skip initialized final fields.
		if (((fieldFlags & ClassFileConstants.AccFinal) != 0) && childDecl.initialization != null) continue;
		if (child.get() == fieldNode.get()) {
			args.add(new SingleNameReference(field.name, p));
		} else {
			args.add(createFieldAccessor(child, FieldAccess.ALWAYS_FIELD, source));
		}
	}
	
	AllocationExpression constructorCall = new AllocationExpression();
	constructorCall.arguments = args.toArray(new Expression[0]);
	constructorCall.type = cloneSelfType(fieldNode, source);
	
	Expression identityCheck = new EqualExpression(
			createFieldAccessor(fieldNode, FieldAccess.ALWAYS_FIELD, source),
			new SingleNameReference(field.name, p),
			OperatorIds.EQUAL_EQUAL);
	ThisReference thisRef = new ThisReference(pS, pE);
	Expression conditional = new ConditionalExpression(identityCheck, thisRef, constructorCall);
	Statement returnStatement = new ReturnStatement(conditional, pS, pE);
	method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart;
	method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;
	
	Annotation[] nonNulls = findAnnotations(field, TransformationsUtil.NON_NULL_PATTERN);
	Annotation[] nullables = findAnnotations(field, TransformationsUtil.NULLABLE_PATTERN);
	List<Statement> statements = new ArrayList<Statement>(5);
	if (nonNulls.length > 0) {
		Statement nullCheck = generateNullCheck(field, source);
		if (nullCheck != null) statements.add(nullCheck);
	}
	statements.add(returnStatement);
	
	method.statements = statements.toArray(new Statement[0]);
	
	Annotation[] copiedAnnotationsParam = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0]));
	if (copiedAnnotationsParam.length != 0) param.annotations = copiedAnnotationsParam;
	
	method.traverse(new SetGeneratedByVisitor(source), parent.scope);
	return method;
}
 
开发者ID:redundent,项目名称:lombok,代码行数:77,代码来源:HandleWither.java


示例16: visit

import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; //导入依赖的package包/类
@Override public boolean visit(ConditionalExpression node, BlockScope scope) {
	setGeneratedBy(node, source);
	applyOffsetExpression(node);
	return super.visit(node, scope);
}
 
开发者ID:redundent,项目名称:lombok,代码行数:6,代码来源:SetGeneratedByVisitor.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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