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


Java Block.addStatement方法代码示例

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


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

示例1: createDefaultConstructorWithoutAccessModifier

import org.aikodi.chameleon.oo.statement.Block; //导入方法依赖的package包/类
/**
 * Create a default default constructor without an access modifier.
 */
protected JavaMethod createDefaultConstructorWithoutAccessModifier(boolean rebuildCache) {
	// FIXME Because this code is ran when a regular Java type is constructed,
	// we cannot ask the
	// language for the factory. Management of the constructor should be done
	// lazily. When
	// the type is actually used, we can assume that a language is attached.
	// Otherwise, we
	// throw an exception.
	JavaMethod cons = new JavaMethod(new SimpleNameMethodHeader(name(), new BasicJavaTypeReference(name())));
	cons.addModifier(new Constructor());
	Block body = new Block();
	cons.setImplementation(new RegularImplementation(body));
	body.addStatement(new StatementExpression(new SuperConstructorDelegation()));
	cons.setUniParent(this);
	setDefaultDefaultConstructor(cons);
	return cons;
}
 
开发者ID:markovandooren,项目名称:jnome,代码行数:21,代码来源:RegularJavaType.java

示例2: addFields

import org.aikodi.chameleon.oo.statement.Block; //导入方法依赖的package包/类
private void addFields(Type javaType, Type jloType) throws LookupException {
	Set<Type> allSuperTypes = jloType.getSelfAndAllSuperTypesView();
	List<RegularMemberVariable> collect = allSuperTypes.stream().<RegularMemberVariable>flatMap(x -> {
		try {
			return x.localMembers(RegularMemberVariable.class).stream();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new ChameleonProgrammerException(e);
		}
	}).collect(Collectors.toList());

	for(RegularMemberVariable v : collect) {
		MemberVariableDeclarator jloMemberVariableDeclarator = v.nearestAncestor(MemberVariableDeclarator.class);
		MemberVariableDeclarator f = new MemberVariableDeclarator(clone(jloMemberVariableDeclarator.typeReference()));
		VariableDeclaration variableDeclaration = (VariableDeclaration) v.origin();
		String fieldName = fieldName(variableDeclaration);
		//      Util.debug(fieldName.contains(IMPLEMENTATION_SUFFIX));
		f.add(new VariableDeclaration(fieldName));
		f.addModifier(new Private());
		javaType.add(f);
		Method getter = createGetterTemplate(jloMemberVariableDeclarator);
		createGetterImplementation(fieldName, getter);
		javaType.add(getter);
		Method setter = createSetterTemplate(jloMemberVariableDeclarator);
		setter.addModifier(new Public());
		Block setterBody = new Block();
		setter.setImplementation(new RegularImplementation(setterBody));
		setterBody.addStatement(new StatementExpression(new AssignmentExpression(new NameExpression(fieldName), new NameExpression("value"))));
		javaType.add(setter);
	}
}
 
开发者ID:markovandooren,项目名称:jlo,代码行数:33,代码来源:Java8ClassGenerator.java

示例3: visitBlock

import org.aikodi.chameleon.oo.statement.Block; //导入方法依赖的package包/类
@Override
public Block visitBlock(BlockContext ctx) {
  Block block = new Block();
  for(StatementContext sctx: ctx.statement()) {
    block.addStatement((Statement) visit(sctx));
  }
  return block;
}
 
开发者ID:markovandooren,项目名称:jlo,代码行数:9,代码来源:JLoConvertor.java

示例4: testMethodCalls

import org.aikodi.chameleon.oo.statement.Block; //导入方法依赖的package包/类
public void testMethodCalls() throws LookupException, ProjectException {
	Java7 language = (Java7)view().language();
	Namespace ns = view().namespace();
	DirectScanner scanner = new DirectScanner();
	view().addSource(scanner);
	Document document = new Document();
    NamespaceDeclaration nsd = new JavaNamespaceDeclaration("test");
    document.add(nsd);
	RegularJavaType type = new RegularJavaType("Test");
	nsd.add(type);
	DirectDocumentLoader loader = new DirectDocumentLoader(scanner, document);
	Type test = ns.find("test.Test", Type.class);
	NormalMethod caller = new NormalMethod(new SimpleNameMethodHeader("m", new BasicJavaTypeReference("void")));
	Block body = new Block();
	caller.setImplementation(new RegularImplementation(body));
	
	BasicJavaTypeReference listRef = new BasicJavaTypeReference("java.util.List");
	listRef.addArgument(new PureWildcard());
	LocalVariableDeclarator declarator = new LocalVariableDeclarator(listRef);
	declarator.add(new JavaVariableDeclaration("first"));
	declarator.add(new JavaVariableDeclaration("second"));
	body.addStatement(declarator);
	JavaMethodInvocation call = new JavaMethodInvocation("two", null);
	call.addArgument(new JavaNameExpression("first"));
	call.addArgument(new JavaNameExpression("second"));
	body.addStatement(new StatementExpression(call));
	type.add(caller);
	
	SimpleNameMethodHeader calleeHeader = new SimpleNameMethodHeader("two", new BasicJavaTypeReference("void"));
	calleeHeader.addTypeParameter(new FormalTypeParameter("T"));
	BasicJavaTypeReference listTRef = new BasicJavaTypeReference("java.util.List");
	listTRef.addArgument(new EqualityTypeArgument(new BasicJavaTypeReference("T")));
	calleeHeader.addFormalParameter(new FormalParameter("first", listTRef.clone(listTRef)));
	calleeHeader.addFormalParameter(new FormalParameter("second", listTRef.clone(listTRef)));
	NormalMethod callee = new NormalMethod(calleeHeader);
	callee.setImplementation(new RegularImplementation(new Block()));
	type.add(callee);
	try {
	  call.getElement();
		assertTrue(false);
	} catch(LookupException exc) {
	}
}
 
开发者ID:markovandooren,项目名称:jnome,代码行数:44,代码来源:TestCustomCases.java

示例5: createGetterImplementation

import org.aikodi.chameleon.oo.statement.Block; //导入方法依赖的package包/类
/**
 * <p>Turn the given method into a getter for a field
 * with the given name.</p>
 * 
 * <ul>
 *   <li>The method gets a public modifier</li>
 *   <li>The implementation is a block with a return statement.</li>
 *   <li>The return statement returns the given field.</li>
 * </ul>
 * 
 * @param fieldName The name of the field that must be returned
 *                  by the getter.
 * @param getter The getter to be modified.
 */
private void createGetterImplementation(String fieldName, Method getter) {
	getter.addModifier(new Public());
	Block getterBody = new Block();
	getter.setImplementation(new RegularImplementation(getterBody));
	getterBody.addStatement(new ReturnStatement(new NameExpression(fieldName)));
}
 
开发者ID:markovandooren,项目名称:jlo,代码行数:21,代码来源:Java8ClassGenerator.java


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