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

Java ASTNodes类代码示例

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

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



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

示例1: createDeclaration

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
private VariableDeclarationStatement createDeclaration(
    IVariableBinding binding, Expression intilizer) {
  VariableDeclaration original =
      ASTNodes.findVariableDeclaration(binding, fAnalyzer.getEnclosingBodyDeclaration());
  VariableDeclarationFragment fragment = fAST.newVariableDeclarationFragment();
  fragment.setName((SimpleName) ASTNode.copySubtree(fAST, original.getName()));
  fragment.setInitializer(intilizer);
  VariableDeclarationStatement result = fAST.newVariableDeclarationStatement(fragment);
  result.modifiers().addAll(ASTNode.copySubtrees(fAST, ASTNodes.getModifiers(original)));
  result.setType(
      ASTNodeFactory.newType(
          fAST,
          original,
          fImportRewriter,
          new ContextSensitiveImportRewriteContext(original, fImportRewriter)));
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:ExtractMethodRefactoring.java


示例2: getVariableNameSuggestions

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
private static String[] getVariableNameSuggestions(int variableKind, IJavaProject project, Type expectedType, Collection<String> excluded, boolean evaluateDefault) {
	int dim= 0;
	if (expectedType.isArrayType()) {
		ArrayType arrayType= (ArrayType)expectedType;
		dim= arrayType.getDimensions();
		expectedType= arrayType.getElementType();
	}
	if (expectedType.isParameterizedType()) {
		expectedType= ((ParameterizedType)expectedType).getType();
	}
	String typeName= ASTNodes.getTypeName(expectedType);

	if (typeName.length() > 0) {
		return getVariableNameSuggestions(variableKind, project, typeName, dim, excluded, evaluateDefault);
	}
	return EMPTY;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:18,代码来源:StubUtility.java


示例3: isLeftHandSideOfAssignment

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
static boolean isLeftHandSideOfAssignment(ASTNode node) {
	Assignment assignment = (Assignment) ASTNodes.getParent(node, ASTNode.ASSIGNMENT);
	if (assignment != null) {
		Expression leftHandSide = assignment.getLeftHandSide();
		if (leftHandSide == node) {
			return true;
		}
		if (ASTNodes.isParent(node, leftHandSide)) {
			switch (leftHandSide.getNodeType()) {
				case ASTNode.SIMPLE_NAME:
					return true;
				case ASTNode.FIELD_ACCESS:
					return node == ((FieldAccess) leftHandSide).getName();
				case ASTNode.QUALIFIED_NAME:
					return node == ((QualifiedName) leftHandSide).getName();
				case ASTNode.SUPER_FIELD_ACCESS:
					return node == ((SuperFieldAccess) leftHandSide).getName();
				default:
					return false;
			}
		}
	}
	return false;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:25,代码来源:SnippetFinder.java


示例4: doAddField

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
private ASTRewrite doAddField(CompilationUnit astRoot) {
  SimpleName node = fOriginalNode;
  boolean isInDifferentCU = false;

  ASTNode newTypeDecl = astRoot.findDeclaringNode(fSenderBinding);
  if (newTypeDecl == null) {
    astRoot = ASTResolving.createQuickFixAST(getCompilationUnit(), null);
    newTypeDecl = astRoot.findDeclaringNode(fSenderBinding.getKey());
    isInDifferentCU = true;
  }
  ImportRewrite imports = createImportRewrite(astRoot);
  ImportRewriteContext importRewriteContext =
      new ContextSensitiveImportRewriteContext(
          ASTResolving.findParentBodyDeclaration(node), imports);

  if (newTypeDecl != null) {
    AST ast = newTypeDecl.getAST();

    ASTRewrite rewrite = ASTRewrite.create(ast);

    VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment();
    fragment.setName(ast.newSimpleName(node.getIdentifier()));

    Type type = evaluateVariableType(ast, imports, importRewriteContext, fSenderBinding);

    FieldDeclaration newDecl = ast.newFieldDeclaration(fragment);
    newDecl.setType(type);
    newDecl
        .modifiers()
        .addAll(ASTNodeFactory.newModifiers(ast, evaluateFieldModifiers(newTypeDecl)));

    if (fSenderBinding.isInterface() || fVariableKind == CONST_FIELD) {
      fragment.setInitializer(ASTNodeFactory.newDefaultExpression(ast, type, 0));
    }

    ChildListPropertyDescriptor property = ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
    List<BodyDeclaration> decls =
        ASTNodes.<BodyDeclaration>getChildListProperty(newTypeDecl, property);

    int maxOffset = isInDifferentCU ? -1 : node.getStartPosition();

    int insertIndex = findFieldInsertIndex(decls, newDecl, maxOffset);

    ListRewrite listRewriter = rewrite.getListRewrite(newTypeDecl, property);
    listRewriter.insertAt(newDecl, insertIndex, null);

    ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(
        getLinkedProposalModel(), rewrite, newDecl.modifiers(), fSenderBinding.isInterface());

    addLinkedPosition(rewrite.track(newDecl.getType()), false, KEY_TYPE);
    if (!isInDifferentCU) {
      addLinkedPosition(rewrite.track(node), true, KEY_NAME);
    }
    addLinkedPosition(rewrite.track(fragment.getName()), false, KEY_NAME);

    if (fragment.getInitializer() != null) {
      addLinkedPosition(rewrite.track(fragment.getInitializer()), false, KEY_INITIALIZER);
    }
    return rewrite;
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:63,代码来源:NewVariableCorrectionProposal.java


示例5: canAddFinal

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
private static boolean canAddFinal(IBinding binding, ASTNode declNode) {
  if (!(binding instanceof IVariableBinding)) return false;

  IVariableBinding varbinding = (IVariableBinding) binding;
  int modifiers = varbinding.getModifiers();
  if (Modifier.isFinal(modifiers)
      || Modifier.isVolatile(modifiers)
      || Modifier.isTransient(modifiers)) return false;

  ASTNode parent = ASTNodes.getParent(declNode, VariableDeclarationExpression.class);
  if (parent != null && ((VariableDeclarationExpression) parent).fragments().size() > 1)
    return false;

  if (varbinding.isField() && !Modifier.isPrivate(modifiers)) return false;

  if (varbinding.isParameter()) {
    ASTNode varDecl = declNode.getParent();
    if (varDecl instanceof MethodDeclaration) {
      MethodDeclaration declaration = (MethodDeclaration) varDecl;
      if (declaration.getBody() == null) return false;
    }
  }

  return true;
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:VariableDeclarationFix.java


示例6: doAddLocal

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
private ASTRewrite doAddLocal() {
  Expression expression = ((ExpressionStatement) fNodeToAssign).getExpression();
  AST ast = fNodeToAssign.getAST();

  ASTRewrite rewrite = ASTRewrite.create(ast);

  createImportRewrite((CompilationUnit) fNodeToAssign.getRoot());

  String[] varNames = suggestLocalVariableNames(fTypeBinding, expression);
  for (int i = 0; i < varNames.length; i++) {
    addLinkedPositionProposal(KEY_NAME, varNames[i], null);
  }

  VariableDeclarationFragment newDeclFrag = ast.newVariableDeclarationFragment();
  newDeclFrag.setName(ast.newSimpleName(varNames[0]));
  newDeclFrag.setInitializer((Expression) rewrite.createCopyTarget(expression));

  Type type = evaluateType(ast);

  if (ASTNodes.isControlStatementBody(fNodeToAssign.getLocationInParent())) {
    Block block = ast.newBlock();
    block.statements().add(rewrite.createMoveTarget(fNodeToAssign));
    rewrite.replace(fNodeToAssign, block, null);
  }

  if (needsSemicolon(expression)) {
    VariableDeclarationStatement varStatement = ast.newVariableDeclarationStatement(newDeclFrag);
    varStatement.setType(type);
    rewrite.replace(expression, varStatement, null);
  } else {
    // trick for bug 43248: use an VariableDeclarationExpression and keep the ExpressionStatement
    VariableDeclarationExpression varExpression =
        ast.newVariableDeclarationExpression(newDeclFrag);
    varExpression.setType(type);
    rewrite.replace(expression, varExpression, null);
  }

  addLinkedPosition(rewrite.track(newDeclFrag.getName()), true, KEY_NAME);
  addLinkedPosition(rewrite.track(type), false, KEY_TYPE);
  setEndPosition(rewrite.track(fNodeToAssign)); // set cursor after expression statement

  return rewrite;
}
 
开发者ID:eclipse,项目名称:che,代码行数:44,代码来源:AssignToVariableAssistProposal.java


示例7: getArgument

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
private static String getArgument(TagElement curr) {
  List<? extends ASTNode> fragments = curr.fragments();
  if (!fragments.isEmpty()) {
    Object first = fragments.get(0);
    if (first instanceof Name) {
      return ASTNodes.getSimpleNameIdentifier((Name) first);
    } else if (first instanceof TextElement && TagElement.TAG_PARAM.equals(curr.getTagName())) {
      String text = ((TextElement) first).getText();
      if ("<".equals(text) && fragments.size() >= 3) { // $NON-NLS-1$
        Object second = fragments.get(1);
        Object third = fragments.get(2);
        if (second instanceof Name
            && third instanceof TextElement
            && ">".equals(((TextElement) third).getText())) { // $NON-NLS-1$
          return '<' + ASTNodes.getSimpleNameIdentifier((Name) second) + '>';
        }
      } else if (text.startsWith(String.valueOf('<'))
          && text.endsWith(String.valueOf('>'))
          && text.length() > 2) {
        return text.substring(1, text.length() - 1);
      }
    }
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:JavadocTagsSubProcessor.java


示例8: getFullTypeName

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
protected String getFullTypeName() {
  ASTNode node = getNode();
  while (true) {
    node = node.getParent();
    if (node instanceof AbstractTypeDeclaration) {
      String typeName = ((AbstractTypeDeclaration) node).getName().getIdentifier();
      if (getNode() instanceof LambdaExpression) {
        return Messages.format(
            RefactoringCoreMessages.ChangeSignatureRefactoring_lambda_expression, typeName);
      }
      return typeName;
    } else if (node instanceof ClassInstanceCreation) {
      ClassInstanceCreation cic = (ClassInstanceCreation) node;
      return Messages.format(
          RefactoringCoreMessages.ChangeSignatureRefactoring_anonymous_subclass,
          BasicElementLabels.getJavaElementName(ASTNodes.asString(cic.getType())));
    } else if (node instanceof EnumConstantDeclaration) {
      EnumDeclaration ed = (EnumDeclaration) node.getParent();
      return Messages.format(
          RefactoringCoreMessages.ChangeSignatureRefactoring_anonymous_subclass,
          BasicElementLabels.getJavaElementName(ASTNodes.asString(ed.getName())));
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:ChangeSignatureProcessor.java


示例9: endVisit

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
@Override
public void endVisit(ReturnStatement node) {
  Expression expression = node.getExpression();
  if (expression == null) return;
  ConstraintVariable2 expressionCv = getConstraintVariable(expression);
  if (expressionCv == null) return;

  MethodDeclaration methodDeclaration =
      (MethodDeclaration) ASTNodes.getParent(node, ASTNode.METHOD_DECLARATION);
  if (methodDeclaration == null) return;
  IMethodBinding methodBinding = methodDeclaration.resolveBinding();
  if (methodBinding == null) return;
  ReturnTypeVariable2 returnTypeCv = fTCModel.makeReturnTypeVariable(methodBinding);
  if (returnTypeCv == null) return;

  fTCModel.createElementEqualsConstraints(returnTypeCv, expressionCv);
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:InferTypeArgumentsConstraintCreator.java


示例10: addExtractCheckedLocalProposal

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
/**
 * Fix for {@link IProblem#NullableFieldReference}
 *
 * @param context context
 * @param problem problem to be fixed
 * @param proposals accumulator for computed proposals
 */
public static void addExtractCheckedLocalProposal(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
  CompilationUnit compilationUnit = context.getASTRoot();
  ICompilationUnit cu = (ICompilationUnit) compilationUnit.getJavaElement();

  ASTNode selectedNode = problem.getCoveringNode(compilationUnit);

  SimpleName name = findProblemFieldName(selectedNode, problem.getProblemId());
  if (name == null) return;

  ASTNode method = ASTNodes.getParent(selectedNode, MethodDeclaration.class);
  if (method == null) method = ASTNodes.getParent(selectedNode, Initializer.class);
  if (method == null) return;

  proposals.add(new ExtractToNullCheckedLocalProposal(cu, compilationUnit, name, method));
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:NullAnnotationsCorrectionProcessor.java


示例11: isIntroduceFactoryAvailable

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
public static boolean isIntroduceFactoryAvailable(final JavaTextSelection selection)
    throws JavaModelException {
  final IJavaElement[] elements = selection.resolveElementAtOffset();
  if (elements.length == 1 && elements[0] instanceof IMethod)
    return isIntroduceFactoryAvailable((IMethod) elements[0]);

  // there's no IMethod for the default constructor
  if (!Checks.isAvailable(selection.resolveEnclosingElement())) return false;
  ASTNode node = selection.resolveCoveringNode();
  if (node == null) {
    ASTNode[] selectedNodes = selection.resolveSelectedNodes();
    if (selectedNodes != null && selectedNodes.length == 1) {
      node = selectedNodes[0];
      if (node == null) return false;
    } else {
      return false;
    }
  }

  if (node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) return true;

  node = ASTNodes.getNormalizedNode(node);
  if (node.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) return true;

  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:RefactoringAvailabilityTester.java


示例12: addFieldDeclaration

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
private VariableDeclarationFragment addFieldDeclaration(
    ASTRewrite rewrite, ASTNode newTypeDecl, int modifiers, Expression expression) {
  if (fExistingFragment != null) {
    return fExistingFragment;
  }

  ChildListPropertyDescriptor property = ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
  List<BodyDeclaration> decls = ASTNodes.getBodyDeclarations(newTypeDecl);
  AST ast = newTypeDecl.getAST();
  String[] varNames = suggestFieldNames(fTypeBinding, expression, modifiers);
  for (int i = 0; i < varNames.length; i++) {
    addLinkedPositionProposal(KEY_NAME, varNames[i], null);
  }
  String varName = varNames[0];

  VariableDeclarationFragment newDeclFrag = ast.newVariableDeclarationFragment();
  newDeclFrag.setName(ast.newSimpleName(varName));

  FieldDeclaration newDecl = ast.newFieldDeclaration(newDeclFrag);

  Type type = evaluateType(ast);
  newDecl.setType(type);
  newDecl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, modifiers));

  ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(
      getLinkedProposalModel(), rewrite, newDecl.modifiers(), false);

  int insertIndex = findFieldInsertIndex(decls, fNodeToAssign.getStartPosition());
  rewrite.getListRewrite(newTypeDecl, property).insertAt(newDecl, insertIndex, null);

  return newDeclFrag;
}
 
开发者ID:eclipse,项目名称:che,代码行数:33,代码来源:AssignToVariableAssistProposal.java


示例13: visit

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
@Override
public boolean visit(SimpleName node) {
  addReferencesToName(node);
  IBinding binding = node.resolveBinding();
  if (binding instanceof ITypeBinding) {
    ITypeBinding type = (ITypeBinding) binding;
    if (type.isTypeVariable()) {
      addTypeVariableReference(type, node);
    }
  } else if (binding instanceof IVariableBinding) {
    IVariableBinding vb = (IVariableBinding) binding;
    if (vb.isField() && !isStaticallyImported(node)) {
      Name topName = ASTNodes.getTopMostName(node);
      if (node == topName || node == ASTNodes.getLeftMostSimpleName(topName)) {
        StructuralPropertyDescriptor location = node.getLocationInParent();
        if (location != SingleVariableDeclaration.NAME_PROPERTY
            && location != VariableDeclarationFragment.NAME_PROPERTY) {
          fImplicitReceivers.add(node);
        }
      }
    } else if (!vb.isField()) {
      // we have a local. Check if it is a parameter.
      ParameterData data = fParameters.get(binding);
      if (data != null) {
        ASTNode parent = node.getParent();
        if (parent instanceof Expression) {
          int precedence = OperatorPrecedence.getExpressionPrecedence((Expression) parent);
          if (precedence != Integer.MAX_VALUE) {
            data.setOperatorPrecedence(precedence);
          }
        }
      }
    }
  }
  return true;
}
 
开发者ID:eclipse,项目名称:che,代码行数:37,代码来源:SourceAnalyzer.java


示例14: match

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
@Override
public boolean match(SimpleName candidate, Object s) {
  if (!(s instanceof SimpleName)) return false;

  SimpleName snippet = (SimpleName) s;
  if (candidate.isDeclaration() != snippet.isDeclaration()) return false;

  IBinding cb = candidate.resolveBinding();
  IBinding sb = snippet.resolveBinding();
  if (cb == null || sb == null) return false;
  IVariableBinding vcb = ASTNodes.getVariableBinding(candidate);
  IVariableBinding vsb = ASTNodes.getVariableBinding(snippet);
  if (vcb == null || vsb == null) return Bindings.equals(cb, sb);
  if (!vcb.isField() && !vsb.isField() && Bindings.equals(vcb.getType(), vsb.getType())) {
    SimpleName mapped = fMatch.getMappedName(vsb);
    if (mapped != null) {
      IVariableBinding mappedBinding = ASTNodes.getVariableBinding(mapped);
      if (!Bindings.equals(vcb, mappedBinding)) return false;
    }
    fMatch.addLocal(vsb, candidate);
    return true;
  }
  return Bindings.equals(cb, sb);
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:SnippetFinder.java


示例15: isLeftHandSideOfAssignment

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
private static boolean isLeftHandSideOfAssignment(ASTNode node) {
  Assignment assignment = (Assignment) ASTNodes.getParent(node, ASTNode.ASSIGNMENT);
  if (assignment != null) {
    Expression leftHandSide = assignment.getLeftHandSide();
    if (leftHandSide == node) {
      return true;
    }
    if (ASTNodes.isParent(node, leftHandSide)) {
      switch (leftHandSide.getNodeType()) {
        case ASTNode.SIMPLE_NAME:
          return true;
        case ASTNode.FIELD_ACCESS:
          return node == ((FieldAccess) leftHandSide).getName();
        case ASTNode.QUALIFIED_NAME:
          return node == ((QualifiedName) leftHandSide).getName();
        case ASTNode.SUPER_FIELD_ACCESS:
          return node == ((SuperFieldAccess) leftHandSide).getName();
        default:
          return false;
      }
    }
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:SnippetFinder.java


示例16: addRedundantSuperInterfaceProposal

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
public static void addRedundantSuperInterfaceProposal(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
  ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
  if (!(selectedNode instanceof Name)) {
    return;
  }
  ASTNode node = ASTNodes.getNormalizedNode(selectedNode);

  ASTRewrite rewrite = ASTRewrite.create(node.getAST());
  rewrite.remove(node, null);

  String label = CorrectionMessages.LocalCorrectionsSubProcessor_remove_redundant_superinterface;
  Image image =
      JavaPluginImages.get(
          JavaPluginImages
              .IMG_TOOL_DELETE); // JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);

  ASTRewriteCorrectionProposal proposal =
      new ASTRewriteCorrectionProposal(
          label,
          context.getCompilationUnit(),
          rewrite,
          IProposalRelevance.REMOVE_REDUNDANT_SUPER_INTERFACE,
          image);
  proposals.add(proposal);
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:LocalCorrectionsSubProcessor.java


示例17: getReceiver

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
private String getReceiver(
    CallContext context, int modifiers, ImportRewriteContext importRewriteContext) {
  String receiver = context.receiver;
  ITypeBinding invocationType = ASTNodes.getEnclosingType(context.invocation);
  ITypeBinding sourceType = fDeclaration.resolveBinding().getDeclaringClass();
  if (!context.receiverIsStatic && Modifier.isStatic(modifiers)) {
    if ("this".equals(receiver)
        && invocationType != null
        && Bindings.equals(invocationType, sourceType)) { // $NON-NLS-1$
      receiver = null;
    } else {
      receiver = context.importer.addImport(sourceType, importRewriteContext);
    }
  }
  return receiver;
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:SourceProvider.java


示例18: replaceSelectedExpressionWithTempDeclaration

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
private void replaceSelectedExpressionWithTempDeclaration() throws CoreException {
  ASTRewrite rewrite = fCURewrite.getASTRewrite();
  Expression selectedExpression =
      getSelectedExpression().getAssociatedExpression(); // whole expression selected

  Expression initializer = (Expression) rewrite.createMoveTarget(selectedExpression);
  ASTNode replacement =
      createTempDeclaration(initializer); // creates a VariableDeclarationStatement

  ExpressionStatement parent = (ExpressionStatement) selectedExpression.getParent();
  if (ASTNodes.isControlStatementBody(parent.getLocationInParent())) {
    Block block = rewrite.getAST().newBlock();
    block.statements().add(replacement);
    replacement = block;
  }
  rewrite.replace(
      parent,
      replacement,
      fCURewrite.createGroupDescription(
          RefactoringCoreMessages.ExtractTempRefactoring_declare_local_variable));
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:ExtractTempRefactoring.java


示例19: checkExpression

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
private void checkExpression(RefactoringStatus status) {
  ASTNode[] nodes = getSelectedNodes();
  if (nodes != null && nodes.length == 1) {
    ASTNode node = nodes[0];
    if (node instanceof Type) {
      status.addFatalError(
          RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_type_reference,
          JavaStatusContext.create(fCUnit, node));
    } else if (node.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) {
      status.addFatalError(
          RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_switch_case,
          JavaStatusContext.create(fCUnit, node));
    } else if (node instanceof Annotation || ASTNodes.getParent(node, Annotation.class) != null) {
      status.addFatalError(
          RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_from_annotation,
          JavaStatusContext.create(fCUnit, node));
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:ExtractMethodAnalyzer.java


示例20: getRewrite

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入依赖的package包/类
@Override
protected ASTRewrite getRewrite() {
  CompilationUnit targetAstRoot = ASTResolving.createQuickFixAST(
      getCompilationUnit(), null);
  createImportRewrite(targetAstRoot);

  // Find the target type declaration
  TypeDeclaration typeDecl = JavaASTUtils.findTypeDeclaration(targetAstRoot,
      targetQualifiedTypeName);
  if (typeDecl == null) {
    return null;
  }

  ASTRewrite rewrite = ASTRewrite.create(targetAstRoot.getAST());

  // Generate the new method declaration
  MethodDeclaration methodDecl = createMethodDeclaration(rewrite.getAST());

  // Add the new method declaration to the interface
  ChildListPropertyDescriptor property = ASTNodes.getBodyDeclarationsProperty(typeDecl);
  ListRewrite listRewriter = rewrite.getListRewrite(typeDecl, property);
  listRewriter.insertLast(methodDecl, null);

  return rewrite;
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:26,代码来源:AbstractCreateMethodProposal.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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