本文整理汇总了Java中org.eclipse.jdt.core.dom.Block类的典型用法代码示例。如果您正苦于以下问题:Java Block类的具体用法?Java Block怎么用?Java Block使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Block类属于org.eclipse.jdt.core.dom包,在下文中一共展示了Block类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createUnobservedInitStmt
import org.eclipse.jdt.core.dom.Block; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void createUnobservedInitStmt(final int logRecNo, final Block methodBlock, final AST ast)
{
// NOTE: PLAIN INIT: has always one non-null param
// TODO: use primitives
final int oid = this.log.objectIds.get(logRecNo);
final String type = this.log.oidClassNames.get(this.log.oidRecMapping.get(oid));
final Object value = this.log.params.get(logRecNo)[0];
this.isXStreamNeeded = true;
final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
// handling because there must always be a new instantiation statement for pseudo inits
this.oidToVarMapping.remove(oid);
vd.setName(ast.newSimpleName(this.createNewVarName(oid, type)));
final MethodInvocation methodInvocation = ast.newMethodInvocation();
final Name name = ast.newSimpleName("XSTREAM");
methodInvocation.setExpression(name);
methodInvocation.setName(ast.newSimpleName("fromXML"));
final StringLiteral xmlParam = ast.newStringLiteral();
xmlParam.setLiteralValue((String) value);
methodInvocation.arguments().add(xmlParam);
final CastExpression castExpr = ast.newCastExpression();
castExpr.setType(this.createAstType(type, ast));
castExpr.setExpression(methodInvocation);
vd.setInitializer(castExpr);
final VariableDeclarationStatement vs = ast.newVariableDeclarationStatement(vd);
vs.setType(this.createAstType(type, ast));
methodBlock.statements().add(vs);
}
示例2: createMethod
import org.eclipse.jdt.core.dom.Block; //导入依赖的package包/类
public RastNode createMethod(String methodSignature, HasChildrenNodes parent, String sourceFilePath, boolean constructor, MethodDeclaration ast) {
String methodName = ast.isConstructor() ? "" : ast.getName().getIdentifier();
RastNode rastNode = new RastNode(++nodeCounter);
rastNode.setType(ast.getClass().getSimpleName());
Block body = ast.getBody();
int bodyStart;
int bodyLength;
if (body == null) {
rastNode.addStereotypes(Stereotype.ABSTRACT);
bodyStart = ast.getStartPosition() + ast.getLength();
bodyLength = 0;
} else {
bodyStart = body.getStartPosition();
bodyLength = body.getLength();
}
rastNode.setLocation(new Location(sourceFilePath, ast.getStartPosition(), ast.getStartPosition() + ast.getLength(), bodyStart, bodyStart + bodyLength));
rastNode.setLocalName(methodSignature);
rastNode.setSimpleName(methodName);
parent.addNode(rastNode);
keyMap.put(JavaParser.getKey(rastNode), rastNode);
return rastNode;
}
示例3: checkMethodsBody
import org.eclipse.jdt.core.dom.Block; //导入依赖的package包/类
/**
* Method that check the method's body to detect some
* connection between them
* @author Mariana Azevedo
* @since 20/01/2016
* @param firstMethod
* @param secondMethod
*/
private void checkMethodsBody(MethodDeclaration firstMethod, MethodDeclaration secondMethod) {
if (firstMethod != null && secondMethod != null){
Block firstMethodBody = firstMethod.getBody();
Block secondMethodBody = secondMethod.getBody();
if (firstMethodBody != null && secondMethodBody != null){
for (String attribute : listOfAttributes){
if (firstMethodBody.toString().contains(attribute) &&
secondMethodBody.toString().contains(attribute)){
numDirectConnections++;
}
}
}
}
}
示例4: calculateMethodCalls
import org.eclipse.jdt.core.dom.Block; //导入依赖的package包/类
/**
* Method to calculate method calls in the method's body.
*/
@SuppressWarnings("unchecked")
private void calculateMethodCalls(){
Iterator<MethodDeclaration> itMethods = methodsList.iterator();
while (itMethods.hasNext()){
MethodDeclaration firstMethod = itMethods.next();
Block firstMethodBody = firstMethod.getBody();
if (firstMethodBody != null){
List<Statement> firstMethodStatements = firstMethodBody.statements();
if (!firstMethodStatements.isEmpty()){
for (IMethod mtd : listOfMethodsName){
if (firstMethodStatements.toString().contains(mtd.getElementName())){
numberMethodCalls++;
}
}
}
}
}
}
示例5: getNumberOfIndirectConnections
import org.eclipse.jdt.core.dom.Block; //导入依赖的package包/类
/**
* Method to get the number of methods with indirect connections.
* @author Mariana Azevedo
* @since 13/07/2014
* @param methodsWithDirectConn
* @param itMethods
*/
private void getNumberOfIndirectConnections(List<MethodDeclaration> methodsWithDirectConn,
Iterator<MethodDeclaration> itMethods){
int i=0;
while (itMethods.hasNext()){
MethodDeclaration firstMethod = itMethods.next();
if (firstMethod != null){
Block firstMethodBody = firstMethod.getBody();
if (firstMethodBody != null){
SimpleName methodDeclaration = methodsWithDirectConn.get(i).getName();
if (firstMethodBody.toString().contains(methodDeclaration.toString())){
numIndirectConnections++;
}
}
}
}
}
示例6: createWithMethodBody
import org.eclipse.jdt.core.dom.Block; //导入依赖的package包/类
private Block createWithMethodBody(AST ast, BuilderField builderField) {
String originalFieldName = builderField.getOriginalFieldName();
String builderFieldName = builderField.getBuilderFieldName();
Block newBlock = ast.newBlock();
ReturnStatement builderReturnStatement = ast.newReturnStatement();
builderReturnStatement.setExpression(ast.newThisExpression());
Assignment newAssignment = ast.newAssignment();
FieldAccess fieldAccess = ast.newFieldAccess();
fieldAccess.setExpression(ast.newThisExpression());
fieldAccess.setName(ast.newSimpleName(originalFieldName));
newAssignment.setLeftHandSide(fieldAccess);
newAssignment.setRightHandSide(ast.newSimpleName(builderFieldName));
newBlock.statements().add(ast.newExpressionStatement(newAssignment));
newBlock.statements().add(builderReturnStatement);
return newBlock;
}
示例7: createWithMethodBody
import org.eclipse.jdt.core.dom.Block; //导入依赖的package包/类
private Block createWithMethodBody(AST ast, String originalFieldName, String builderFieldName) {
Block newBlock = ast.newBlock();
ReturnStatement builderReturnStatement = ast.newReturnStatement();
builderReturnStatement.setExpression(ast.newThisExpression());
Assignment newAssignment = ast.newAssignment();
FieldAccess fieldAccess = ast.newFieldAccess();
fieldAccess.setExpression(ast.newThisExpression());
fieldAccess.setName(ast.newSimpleName(originalFieldName));
newAssignment.setLeftHandSide(fieldAccess);
newAssignment.setRightHandSide(ast.newSimpleName(builderFieldName));
newBlock.statements().add(ast.newExpressionStatement(newAssignment));
newBlock.statements().add(builderReturnStatement);
return newBlock;
}
示例8: createNewWithMethod
import org.eclipse.jdt.core.dom.Block; //导入依赖的package包/类
private MethodDeclaration createNewWithMethod(AST ast, String fieldName, Block newBlock,
SingleVariableDeclaration methodParameterDeclaration, TypeDeclaration builderType,
BuilderField builderField) {
MethodDeclaration builderMethod = ast.newMethodDeclaration();
builderMethod.setName(ast.newSimpleName(builderClassMethodNameGeneratorService.build(fieldName)));
builderMethod.setReturnType2(ast.newSimpleType(
ast.newName(builderType.getName().getIdentifier())));
builderMethod.setBody(newBlock);
builderMethod.parameters().add(methodParameterDeclaration);
javadocAdder.addJavadocForWithMethod(ast, fieldName, builderMethod);
if (preferencesManager.getPreferenceValue(ADD_NONNULL_ON_RETURN)) {
markerAnnotationAttacher.attachNonNull(ast, builderMethod);
}
builderMethod.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
return builderMethod;
}
示例9: createReturnBlock
import org.eclipse.jdt.core.dom.Block; //导入依赖的package包/类
public Block createReturnBlock(AST ast, TypeDeclaration builderType, String withName, String parameterName) {
Block builderMethodBlock = ast.newBlock();
ReturnStatement returnStatement = ast.newReturnStatement();
ClassInstanceCreation newClassInstanceCreation = ast.newClassInstanceCreation();
newClassInstanceCreation.setType(ast.newSimpleType(ast.newName(builderType.getName().toString())));
MethodInvocation withMethodInvocation = ast.newMethodInvocation();
withMethodInvocation.setExpression(newClassInstanceCreation);
withMethodInvocation.setName(ast.newSimpleName(withName));
withMethodInvocation.arguments().add(ast.newSimpleName(parameterName));
returnStatement.setExpression(withMethodInvocation);
builderMethodBlock.statements().add(returnStatement);
return builderMethodBlock;
}
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:16,代码来源:NewBuilderAndWithMethodCallCreationFragment.java
示例10: addBuilderMethodToCompilationUnit
import org.eclipse.jdt.core.dom.Block; //导入依赖的package包/类
public void addBuilderMethodToCompilationUnit(CompilationUnitModificationDomain modificationDomain, TypeDeclaration builderType,
StagedBuilderProperties currentStage) {
AST ast = modificationDomain.getAst();
ListRewrite listRewrite = modificationDomain.getListRewrite();
BuilderField firstField = currentStage.getNamedVariableDeclarationField().get(0);
StagedBuilderProperties nextStage = currentStage.getNextStage().orElse(currentStage);
MethodDeclaration staticWithMethod = stagedBuilderWithMethodDefiniationCreatorFragment.createNewWithMethod(ast, firstField, nextStage);
staticWithMethod.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
String parameterName = firstField.getBuilderFieldName();
String withMethodName = staticWithMethod.getName().toString();
Block block = newBuilderAndWithMethodCallCreationFragment.createReturnBlock(ast, builderType, withMethodName, parameterName);
javadocAdder.addJavadocForWithBuilderMethod(ast, builderType.getName().toString(), parameterName, staticWithMethod);
staticWithMethod.setBody(block);
listRewrite.insertLast(staticWithMethod, null);
}
示例11: handleOneMany
import org.eclipse.jdt.core.dom.Block; //导入依赖的package包/类
@Override
protected void handleOneMany(ASTNode[] replacements, TextEditGroup description) {
AST ast= fToReplace[0].getAST();
// to replace == 1, but more than one replacement. Have to check if we
// need to insert a block to not change structure
if (ASTNodes.isControlStatementBody(fDescriptor)) {
Block block= ast.newBlock();
ListRewrite statements= fRewrite.getListRewrite(block, Block.STATEMENTS_PROPERTY);
for (int i= 0; i < replacements.length; i++) {
statements.insertLast(replacements[i], description);
}
fRewrite.replace(fToReplace[0], block, description);
} else {
ListRewrite container= fRewrite.getListRewrite(fToReplace[0].getParent(), (ChildListPropertyDescriptor)fDescriptor);
container.replace(fToReplace[0], replacements[0], description);
for (int i= 1; i < replacements.length; i++) {
container.insertAfter(replacements[i], replacements[i - 1], description);
}
}
}
示例12: visit
import org.eclipse.jdt.core.dom.Block; //导入依赖的package包/类
@Override
public boolean visit(TryStatement node) {
if (traverseNode(node)) {
fFlowContext.pushExcptions(node);
for (Iterator<VariableDeclarationExpression> iterator = node.resources().iterator(); iterator.hasNext();) {
iterator.next().accept(this);
}
node.getBody().accept(this);
fFlowContext.popExceptions();
List<CatchClause> catchClauses = node.catchClauses();
for (Iterator<CatchClause> iter = catchClauses.iterator(); iter.hasNext();) {
iter.next().accept(this);
}
Block finallyBlock = node.getFinally();
if (finallyBlock != null) {
finallyBlock.accept(this);
}
}
return false;
}
示例13: annotateMethods
import org.eclipse.jdt.core.dom.Block; //导入依赖的package包/类
/**
* @param rewrite
* @param declaration
*/
private void annotateMethods(ASTRewrite rewrite, TypeDeclaration declaration) {
MethodDeclaration[] methods = declaration.getMethods();
for (int i = 0; i < methods.length; i++) {
MethodDeclaration methodDeclaration = methods[i];
annotateMethodReturnType(rewrite, methodDeclaration);
annotateMethodParameters(rewrite, methodDeclaration);
DefaultingVisitor visitor = new DefaultingVisitor();
visitor.rewrite = rewrite;
Block body = methodDeclaration.getBody();
if (body != null) {
body.accept(visitor);
}
}
}
示例14: isEquivalent
import org.eclipse.jdt.core.dom.Block; //导入依赖的package包/类
private boolean isEquivalent(IMethod method, IMethod otherMethod, Optional<IProgressMonitor> monitor)
throws JavaModelException {
monitor.ifPresent(m -> m.beginTask("Checking method equivalence ...", 2));
MethodDeclaration methodDeclaration = this.getMethodDeclaration(method,
monitor.map(m -> new SubProgressMonitor(m, 1)));
MethodDeclaration otherMethodDeclaration = this.getMethodDeclaration(otherMethod,
monitor.map(m -> new SubProgressMonitor(m, 1)));
monitor.ifPresent(IProgressMonitor::done);
Block methodDeclarationBody = methodDeclaration.getBody();
Block otherMethodDeclarationBody = otherMethodDeclaration.getBody();
boolean match = methodDeclarationBody.subtreeMatch(new ASTMatcher(), otherMethodDeclarationBody);
return match;
}
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:19,代码来源:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java
示例15: analyzeBaseMethod
import org.eclipse.jdt.core.dom.Block; //导入依赖的package包/类
private void analyzeBaseMethod(IMethod method, Method tmlMethod)
throws IllegalArgumentException, JavaModelException {
CompilationUnit cu = JDTUtils
.createASTRoot(method.getCompilationUnit());
MethodDeclaration md = JDTUtils.createMethodDeclaration(cu, method);
Block body = md.getBody();
if (body != null) {
for (Object statement : body.statements()) {
if (statement instanceof Statement) {
Statement st = (Statement) statement;
processIfStatements(st, tmlMethod);
}
}
}
}