當前位置: 首頁>>代碼示例>>Java>>正文


Java SingleVariableDeclaration.getInitializer方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.dom.SingleVariableDeclaration.getInitializer方法的典型用法代碼示例。如果您正苦於以下問題:Java SingleVariableDeclaration.getInitializer方法的具體用法?Java SingleVariableDeclaration.getInitializer怎麽用?Java SingleVariableDeclaration.getInitializer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.dom.SingleVariableDeclaration的用法示例。


在下文中一共展示了SingleVariableDeclaration.getInitializer方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: create

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
@Override
public ITypeConstraint[] create(SingleVariableDeclaration svd) {
  ITypeConstraint[] defines =
      fTypeConstraintFactory.createDefinesConstraint(
          fConstraintVariableFactory.makeExpressionOrTypeVariable(svd.getName(), getContext()),
          fConstraintVariableFactory.makeTypeVariable(svd.getType()));
  if (svd.getInitializer() == null) return defines;
  ITypeConstraint[] constraints =
      fTypeConstraintFactory.createSubtypeConstraint(
          fConstraintVariableFactory.makeExpressionOrTypeVariable(
              svd.getInitializer(), getContext()),
          fConstraintVariableFactory.makeExpressionOrTypeVariable(svd.getName(), getContext()));
  if (defines.length == 0 && constraints.length == 0) {
    return new ITypeConstraint[0];
  } else if (defines.length == 0) {
    return constraints;
  } else if (constraints.length == 0) {
    return defines;
  } else {
    List<ITypeConstraint> all = new ArrayList<ITypeConstraint>();
    all.addAll(Arrays.asList(defines));
    all.addAll(Arrays.asList(constraints));
    return (ITypeConstraint[]) all.toArray();
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:26,代碼來源:FullConstraintCreator.java

示例2: hasSideEffect

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
private static boolean hasSideEffect(SimpleName reference) {
	ASTNode parent= reference.getParent();
	while (parent instanceof QualifiedName) {
		parent= parent.getParent();
	}
	if (parent instanceof FieldAccess) {
		parent= parent.getParent();
	}

	ASTNode node= null;
	int nameParentType= parent.getNodeType();
	if (nameParentType == ASTNode.ASSIGNMENT) {
		Assignment assignment= (Assignment) parent;
		node= assignment.getRightHandSide();
	} else if (nameParentType == ASTNode.SINGLE_VARIABLE_DECLARATION) {
		SingleVariableDeclaration decl= (SingleVariableDeclaration)parent;
		node= decl.getInitializer();
		if (node == null) {
			return false;
		}
	} else if (nameParentType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
		node= parent;
	} else {
		return false;
	}

	ArrayList<Expression> sideEffects= new ArrayList<>();
	node.accept(new SideEffectFinder(sideEffects));
	return sideEffects.size() > 0;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:31,代碼來源:UnusedCodeFix.java

示例3: endVisit

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
@Override
public void endVisit(SingleVariableDeclaration node) {
	if (skipNode(node)) {
		return;
	}

	IVariableBinding binding = node.resolveBinding();
	LocalFlowInfo nameInfo = null;
	Expression initializer = node.getInitializer();
	if (binding != null && !binding.isField() && initializer != null) {
		nameInfo = new LocalFlowInfo(binding, FlowInfo.WRITE, fFlowContext);
	}
	GenericSequentialFlowInfo info = processSequential(node, node.getType(), initializer);
	info.merge(nameInfo, fFlowContext);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:16,代碼來源:FlowAnalyzer.java

示例4: hasSideEffect

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
private static boolean hasSideEffect(SimpleName reference) {
  ASTNode parent = reference.getParent();
  while (parent instanceof QualifiedName) {
    parent = parent.getParent();
  }
  if (parent instanceof FieldAccess) {
    parent = parent.getParent();
  }

  ASTNode node = null;
  int nameParentType = parent.getNodeType();
  if (nameParentType == ASTNode.ASSIGNMENT) {
    Assignment assignment = (Assignment) parent;
    node = assignment.getRightHandSide();
  } else if (nameParentType == ASTNode.SINGLE_VARIABLE_DECLARATION) {
    SingleVariableDeclaration decl = (SingleVariableDeclaration) parent;
    node = decl.getInitializer();
    if (node == null) return false;
  } else if (nameParentType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
    node = parent;
  } else {
    return false;
  }

  ArrayList<Expression> sideEffects = new ArrayList<Expression>();
  node.accept(new SideEffectFinder(sideEffects));
  return sideEffects.size() > 0;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:29,代碼來源:UnusedCodeFix.java

示例5: endVisit

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
@Override
public void endVisit(SingleVariableDeclaration node) {
  // used for formal method parameters and catch clauses
  // TODO: extra dimensions?

  //		ConstraintVariable2 typeCv= getConstraintVariable(node.getType()); //TODO: who needs this?

  //		ConstraintVariable2 nameCv;
  //		switch (node.getParent().getNodeType()) {
  //			case ASTNode.METHOD_DECLARATION :
  //				MethodDeclaration parent= (MethodDeclaration) node.getParent();
  //				int index= parent.parameters().indexOf(node);
  //				nameCv= fTCFactory.makeParameterTypeVariable(parent.resolveBinding(), index,
  // node.getType());
  //				//store source range even if variable not used in constraint here. TODO: move to
  // visit(MethodDeclaration)?
  //				break;
  //			case ASTNode.CATCH_CLAUSE :
  //				nameCv= fTCFactory.makeVariableVariable(node.resolveBinding());
  //
  //				break;
  //			default:
  //				unexpectedNode(node.getParent());
  //		}
  //		setConstraintVariable(node, nameCv);

  // TODO: Move this into visit(SimpleName) or leave it here?
  //		ExpressionVariable2 name= fTCFactory.makeExpressionVariable(node.getName());
  //		TypeVariable2 type= fTCFactory.makeTypeVariable(node.getType());
  //		ITypeConstraint2[] nameEqualsType= fTCFactory.createEqualsConstraint(name, type);
  //		addConstraints(nameEqualsType);

  // TODO: When can a SingleVariableDeclaration have an initializer? Never up to Java 1.5?
  Expression initializer = node.getInitializer();
  if (initializer == null) return;

  //		ConstraintVariable2 initializerCv= getConstraintVariable(initializer);
  //		ConstraintVariable2 nameCv= getConstraintVariable(node);
  // TODO: check: property has been set in visit(CatchClause), visit(MethodDeclaration),
  // visit(EnhancedForStatament)
  // fTCFactory.createSubtypeConstraint(initializerCv, nameCv); //TODO: not for augment raw
  // container clients
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:44,代碼來源:InferTypeArgumentsConstraintCreator.java


注:本文中的org.eclipse.jdt.core.dom.SingleVariableDeclaration.getInitializer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。