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


Java IExpressionFragment类代码示例

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


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

示例1: isLiteralNodeSelected

import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment; //导入依赖的package包/类
private boolean isLiteralNodeSelected() throws JavaModelException {
  IExpressionFragment fragment = getSelectedExpression();
  if (fragment == null) return false;
  Expression expression = fragment.getAssociatedExpression();
  if (expression == null) return false;
  switch (expression.getNodeType()) {
    case ASTNode.BOOLEAN_LITERAL:
    case ASTNode.CHARACTER_LITERAL:
    case ASTNode.NULL_LITERAL:
    case ASTNode.NUMBER_LITERAL:
      return true;

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

示例2: checkInitializer

import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment; //导入依赖的package包/类
private RefactoringStatus checkInitializer() {
  Expression initializer = getInitializer();
  if (initializer == null)
    return RefactoringStatus.createStatus(
        RefactoringStatus.FATAL,
        RefactoringCoreMessages.InlineConstantRefactoring_blank_finals,
        null,
        Corext.getPluginId(),
        RefactoringStatusCodes.CANNOT_INLINE_BLANK_FINAL,
        null);

  fInitializerAllStaticFinal =
      ConstantChecks.isStaticFinalConstant(
          (IExpressionFragment) ASTFragmentFactory.createFragmentForFullSubtree(initializer));
  fInitializerChecked = true;
  return new RefactoringStatus();
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:InlineConstantRefactoring.java

示例3: visit

import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment; //导入依赖的package包/类
@Override
public boolean visit(MethodInvocation node) {
  if (node.getExpression() == null) {
    visitName(node.getName());
  } else {
    fResult &=
        new LoadTimeConstantChecker(
                (IExpressionFragment)
                    ASTFragmentFactory.createFragmentForFullSubtree(node.getExpression()))
            .check();
  }

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

示例4: checkSelection

import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment; //导入依赖的package包/类
private RefactoringStatus checkSelection(IProgressMonitor pm) throws JavaModelException {
  try {
    pm.beginTask("", 2); // $NON-NLS-1$

    IExpressionFragment selectedExpression = getSelectedExpression();

    if (selectedExpression == null) {
      String message = RefactoringCoreMessages.ExtractConstantRefactoring_select_expression;
      return CodeRefactoringUtil.checkMethodSyntaxErrors(
          fSelectionStart, fSelectionLength, fCuRewrite.getRoot(), message);
    }
    pm.worked(1);

    RefactoringStatus result = new RefactoringStatus();
    result.merge(checkExpression());
    if (result.hasFatalError()) return result;
    pm.worked(1);

    return result;
  } finally {
    pm.done();
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:ExtractConstantRefactoring.java

示例5: depends

import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment; //导入依赖的package包/类
private static boolean depends(IExpressionFragment selected, BodyDeclaration bd) {
  /* We currently consider selected to depend on bd only if db includes a declaration
   * of a static field on which selected depends.
   *
   * A more accurate strategy might be to also check if bd contains (or is) a
   * static initializer containing code which changes the value of a static field on
   * which selected depends.  However, if a static is written to multiple times within
   * during class initialization, it is difficult to predict which value should be used.
   * This would depend on which value is used by expressions instances for which the new
   * constant will be substituted, and there may be many of these; in each, the
   * static field in question may have taken on a different value (if some of these uses
   * occur within static initializers).
   */

  if (bd instanceof FieldDeclaration) {
    FieldDeclaration fieldDecl = (FieldDeclaration) bd;
    for (Iterator<VariableDeclarationFragment> fragments = fieldDecl.fragments().iterator();
        fragments.hasNext(); ) {
      VariableDeclarationFragment fragment = fragments.next();
      SimpleName staticFieldName = fragment.getName();
      if (selected.getSubFragmentsMatching(
                  ASTFragmentFactory.createFragmentForFullSubtree(staticFieldName))
              .length
          != 0) return true;
    }
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:29,代码来源:ExtractConstantRefactoring.java

示例6: initializeSelectedExpression

import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment; //导入依赖的package包/类
private void initializeSelectedExpression(CompilationUnitRewrite cuRewrite) throws JavaModelException {
	IASTFragment fragment= ASTFragmentFactory.createFragmentForSourceRange(
			new SourceRange(fSelectionStart, fSelectionLength), cuRewrite.getRoot(), cuRewrite.getCu());

	if (! (fragment instanceof IExpressionFragment))
		return;

	//TODO: doesn't handle selection of partial Expressions
	Expression expression= ((IExpressionFragment) fragment).getAssociatedExpression();
	if (fragment.getStartPosition() != expression.getStartPosition()
			|| fragment.getLength() != expression.getLength())
		return;

	if (Checks.isInsideJavadoc(expression))
		return;
	//TODO: exclude invalid selections
	if (Checks.isEnumCase(expression.getParent()))
		return;

	fSelectedExpression= expression;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:IntroduceParameterRefactoring.java

示例7: isLiteralNodeSelected

import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment; //导入依赖的package包/类
private boolean isLiteralNodeSelected() throws JavaModelException {
	IExpressionFragment fragment= getSelectedExpression();
	if (fragment == null)
		return false;
	Expression expression= fragment.getAssociatedExpression();
	if (expression == null)
		return false;
	switch (expression.getNodeType()) {
		case ASTNode.BOOLEAN_LITERAL:
		case ASTNode.CHARACTER_LITERAL:
		case ASTNode.NULL_LITERAL:
		case ASTNode.NUMBER_LITERAL:
			return true;

		default:
			return false;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:ExtractTempRefactoring.java

示例8: checkSelection

import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment; //导入依赖的package包/类
private RefactoringStatus checkSelection(IProgressMonitor pm) throws JavaModelException {
	try {
		pm.beginTask("", 2); //$NON-NLS-1$

		IExpressionFragment selectedExpression= getSelectedExpression();

		if (selectedExpression == null) {
			String message= RefactoringCoreMessages.ExtractConstantRefactoring_select_expression;
			return CodeRefactoringUtil.checkMethodSyntaxErrors(fSelectionStart, fSelectionLength, fCuRewrite.getRoot(), message);
		}
		pm.worked(1);

		RefactoringStatus result= new RefactoringStatus();
		result.merge(checkExpression());
		if (result.hasFatalError())
			return result;
		pm.worked(1);

		return result;
	} finally {
		pm.done();
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:24,代码来源:ExtractConstantRefactoring.java

示例9: isLiteralNodeSelected

import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment; //导入依赖的package包/类
private boolean isLiteralNodeSelected() throws JavaModelException {
	IExpressionFragment fragment= getSelectedExpression();
	if (fragment == null)
		return false;
	Expression expression= fragment.getAssociatedExpression();
	if (expression == null)
		return false;
	switch (expression.getNodeType()) {
		case ASTNode.BOOLEAN_LITERAL :
		case ASTNode.CHARACTER_LITERAL :
		case ASTNode.NULL_LITERAL :
		case ASTNode.NUMBER_LITERAL :
			return true;

		default :
			return false;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:ExtractConstantRefactoring.java

示例10: checkExpression

import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment; //导入依赖的package包/类
private RefactoringStatus checkExpression() throws JavaModelException {
	RefactoringStatus result= new RefactoringStatus();
	result.merge(checkExpressionBinding());
	if(result.hasFatalError())
		return result;
	checkAllStaticFinal();

	IExpressionFragment selectedExpression= getSelectedExpression();
	Expression associatedExpression= selectedExpression.getAssociatedExpression();
	if (associatedExpression instanceof NullLiteral)
		result.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractConstantRefactoring_null_literals));
	else if (!ConstantChecks.isLoadTimeConstant(selectedExpression))
		result.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractConstantRefactoring_not_load_time_constant));
	else if (associatedExpression instanceof SimpleName) {
		if (associatedExpression.getParent() instanceof QualifiedName && associatedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY
				|| associatedExpression.getParent() instanceof FieldAccess && associatedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY)
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractConstantRefactoring_select_expression);
	}

	return result;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:ExtractConstantRefactoring.java

示例11: depends

import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment; //导入依赖的package包/类
private static boolean depends(IExpressionFragment selected, BodyDeclaration bd) {
	/* We currently consider selected to depend on bd only if db includes a declaration
	 * of a static field on which selected depends.
	 *
	 * A more accurate strategy might be to also check if bd contains (or is) a
	 * static initializer containing code which changes the value of a static field on
	 * which selected depends.  However, if a static is written to multiple times within
	 * during class initialization, it is difficult to predict which value should be used.
	 * This would depend on which value is used by expressions instances for which the new
	 * constant will be substituted, and there may be many of these; in each, the
	 * static field in question may have taken on a different value (if some of these uses
	 * occur within static initializers).
	 */

	if(bd instanceof FieldDeclaration) {
		FieldDeclaration fieldDecl = (FieldDeclaration) bd;
		for(Iterator<VariableDeclarationFragment> fragments = fieldDecl.fragments().iterator(); fragments.hasNext();) {
			VariableDeclarationFragment fragment = fragments.next();
			SimpleName staticFieldName = fragment.getName();
			if(selected.getSubFragmentsMatching(ASTFragmentFactory.createFragmentForFullSubtree(staticFieldName)).length != 0)
				return true;
		}
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:ExtractConstantRefactoring.java

示例12: getFirstReplacedExpression

import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment; //导入依赖的package包/类
private IExpressionFragment getFirstReplacedExpression() throws JavaModelException {
  if (!fReplaceAllOccurrences) return getSelectedExpression();
  IASTFragment[] nodesToReplace = retainOnlyReplacableMatches(getMatchingFragments());
  if (nodesToReplace.length == 0) return getSelectedExpression();
  Comparator<IASTFragment> comparator =
      new Comparator<IASTFragment>() {

        public int compare(IASTFragment o1, IASTFragment o2) {
          return o1.getStartPosition() - o2.getStartPosition();
        }
      };
  Arrays.sort(nodesToReplace, comparator);
  return (IExpressionFragment) nodesToReplace[0];
}
 
开发者ID:eclipse,项目名称:che,代码行数:15,代码来源:ExtractTempRefactoring.java

示例13: getExcludedVariableNames

import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment; //导入依赖的package包/类
private String[] getExcludedVariableNames() {
  if (fExcludedVariableNames == null) {
    try {
      IExpressionFragment expr = getSelectedExpression();
      Collection<String> takenNames =
          new ScopeAnalyzer(fCuRewrite.getRoot())
              .getUsedVariableNames(expr.getStartPosition(), expr.getLength());
      fExcludedVariableNames = takenNames.toArray(new String[takenNames.size()]);
    } catch (JavaModelException e) {
      fExcludedVariableNames = new String[0];
    }
  }
  return fExcludedVariableNames;
}
 
开发者ID:eclipse,项目名称:che,代码行数:15,代码来源:ExtractConstantRefactoring.java

示例14: checkExpression

import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment; //导入依赖的package包/类
private RefactoringStatus checkExpression() throws JavaModelException {
  RefactoringStatus result = new RefactoringStatus();
  result.merge(checkExpressionBinding());
  if (result.hasFatalError()) return result;
  checkAllStaticFinal();

  IExpressionFragment selectedExpression = getSelectedExpression();
  Expression associatedExpression = selectedExpression.getAssociatedExpression();
  if (associatedExpression instanceof NullLiteral)
    result.merge(
        RefactoringStatus.createFatalErrorStatus(
            RefactoringCoreMessages.ExtractConstantRefactoring_null_literals));
  else if (!ConstantChecks.isLoadTimeConstant(selectedExpression))
    result.merge(
        RefactoringStatus.createFatalErrorStatus(
            RefactoringCoreMessages.ExtractConstantRefactoring_not_load_time_constant));
  else if (associatedExpression instanceof SimpleName) {
    if (associatedExpression.getParent() instanceof QualifiedName
            && associatedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY
        || associatedExpression.getParent() instanceof FieldAccess
            && associatedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY)
      return RefactoringStatus.createFatalErrorStatus(
          RefactoringCoreMessages.ExtractConstantRefactoring_select_expression);
  }

  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:28,代码来源:ExtractConstantRefactoring.java

示例15: createConstantDeclaration

import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment; //导入依赖的package包/类
private void createConstantDeclaration() throws CoreException {
  Type type = getConstantType();

  IExpressionFragment fragment = getSelectedExpression();
  Expression initializer =
      getSelectedExpression().createCopyTarget(fCuRewrite.getASTRewrite(), true);

  AST ast = fCuRewrite.getAST();
  VariableDeclarationFragment variableDeclarationFragment = ast.newVariableDeclarationFragment();
  variableDeclarationFragment.setName(ast.newSimpleName(fConstantName));
  variableDeclarationFragment.setInitializer(initializer);

  FieldDeclaration fieldDeclaration = ast.newFieldDeclaration(variableDeclarationFragment);
  fieldDeclaration.setType(type);
  Modifier.ModifierKeyword accessModifier = Modifier.ModifierKeyword.toKeyword(fVisibility);
  if (accessModifier != null) fieldDeclaration.modifiers().add(ast.newModifier(accessModifier));
  fieldDeclaration.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD));
  fieldDeclaration.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD));

  boolean createComments =
      JavaPreferencesSettings.getCodeGenerationSettings(fCu.getJavaProject()).createComments;
  if (createComments) {
    String comment =
        CodeGeneration.getFieldComment(
            fCu, getConstantTypeName(), fConstantName, StubUtility.getLineDelimiterUsed(fCu));
    if (comment != null && comment.length() > 0) {
      Javadoc doc =
          (Javadoc) fCuRewrite.getASTRewrite().createStringPlaceholder(comment, ASTNode.JAVADOC);
      fieldDeclaration.setJavadoc(doc);
    }
  }

  AbstractTypeDeclaration parent = getContainingTypeDeclarationNode();
  ListRewrite listRewrite =
      fCuRewrite.getASTRewrite().getListRewrite(parent, parent.getBodyDeclarationsProperty());
  TextEditGroup msg =
      fCuRewrite.createGroupDescription(
          RefactoringCoreMessages.ExtractConstantRefactoring_declare_constant);
  if (insertFirst()) {
    listRewrite.insertFirst(fieldDeclaration, msg);
  } else {
    listRewrite.insertAfter(fieldDeclaration, getNodeToInsertConstantDeclarationAfter(), msg);
  }

  if (fLinkedProposalModel != null) {
    ASTRewrite rewrite = fCuRewrite.getASTRewrite();
    LinkedProposalPositionGroup nameGroup = fLinkedProposalModel.getPositionGroup(KEY_NAME, true);
    nameGroup.addPosition(rewrite.track(variableDeclarationFragment.getName()), true);

    String[] nameSuggestions = guessConstantNames();
    if (nameSuggestions.length > 0 && !nameSuggestions[0].equals(fConstantName)) {
      nameGroup.addProposal(fConstantName, null, nameSuggestions.length + 1);
    }
    for (int i = 0; i < nameSuggestions.length; i++) {
      nameGroup.addProposal(nameSuggestions[i], null, nameSuggestions.length - i);
    }

    LinkedProposalPositionGroup typeGroup = fLinkedProposalModel.getPositionGroup(KEY_TYPE, true);
    typeGroup.addPosition(rewrite.track(type), true);

    ITypeBinding typeBinding = guessBindingForReference(fragment.getAssociatedExpression());
    if (typeBinding != null) {
      ITypeBinding[] relaxingTypes = ASTResolving.getNarrowingTypes(ast, typeBinding);
      for (int i = 0; i < relaxingTypes.length; i++) {
        typeGroup.addProposal(relaxingTypes[i], fCuRewrite.getCu(), relaxingTypes.length - i);
      }
    }
    boolean isInterface =
        parent.resolveBinding() != null && parent.resolveBinding().isInterface();
    ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(
        fLinkedProposalModel, rewrite, fieldDeclaration.modifiers(), isInterface);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:74,代码来源:ExtractConstantRefactoring.java


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