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


Java VariableDeclarationFragment.getParent方法代碼示例

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


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

示例1: visit

import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的package包/類
@Override
      public boolean visit(VariableDeclarationFragment param) {

	ASTNode parent = param.getParent();
	if (parent instanceof VariableDeclarationStatement) {
		VariableDeclarationStatement statement = (VariableDeclarationStatement) parent;

		ASTNode annotation = getAnnotation(statement.modifiers(), "Domain");
		if (annotation != null) {
			ListRewrite paramRewrite = rewrite.getListRewrite(statement,
			        VariableDeclarationStatement.MODIFIERS2_PROPERTY);
			paramRewrite.remove(annotation, null);
		}
	}
	return super.visit(param);
}
 
開發者ID:aroog,項目名稱:code,代碼行數:17,代碼來源:RemoveAnnotations.java

示例2: visit

import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的package包/類
@Override
public boolean visit(VariableDeclarationFragment node) {
  boolean result = super.visit(node);
  if (isFirstSelectedNode(node)) {
    if (node.getParent() instanceof FieldDeclaration) {
      invalidSelection(
          RefactoringCoreMessages
              .ExtractMethodAnalyzer_cannot_extract_variable_declaration_fragment_from_field,
          JavaStatusContext.create(fCUnit, node));
    } else {
      invalidSelection(
          RefactoringCoreMessages
              .ExtractMethodAnalyzer_cannot_extract_variable_declaration_fragment,
          JavaStatusContext.create(fCUnit, node));
    }
    return false;
  }
  return result;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:20,代碼來源:ExtractMethodAnalyzer.java

示例3: visit

import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的package包/類
@Override
public boolean visit(VariableDeclarationFragment node) {
	boolean result = super.visit(node);
	if (isFirstSelectedNode(node)) {
		if (node.getParent() instanceof FieldDeclaration) {
			invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_variable_declaration_fragment_from_field, JavaStatusContext.create(fCUnit, node));
		} else {
			invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_variable_declaration_fragment, JavaStatusContext.create(fCUnit, node));
		}
		return false;
	}
	return result;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:14,代碼來源:ExtractMethodAnalyzer.java

示例4: getDeclaredType

import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的package包/類
Type getDeclaredType(VariableDeclarationFragment frg) {
	ASTNode parent = frg.getParent();
	if(parent instanceof VariableDeclarationStatement ) {
		VariableDeclarationStatement varDecl = (VariableDeclarationStatement)parent;
		return varDecl.getType();
	}
	else if (parent instanceof VariableDeclarationExpression ) {
		VariableDeclarationExpression varExpr = (VariableDeclarationExpression)parent;
		return varExpr.getType();
	}
	
	return null;
}
 
開發者ID:aroog,項目名稱:code,代碼行數:14,代碼來源:SaveAnnotationsImpl.java

示例5: visit

import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的package包/類
@Override
/**
 * Annotate local variables by visiting the enclosing statement.
 * 
 * Handles both VariableDeclarationStatement and VariableDeclarationExpression
 */
public boolean visit(VariableDeclarationFragment varDecl) {
	ASTNode parent = varDecl.getParent();
	Type declaredType = null;
	List parentMods = null;
	if(parent instanceof VariableDeclarationStatement ) {
		VariableDeclarationStatement varDeclStmt = (VariableDeclarationStatement)parent;
		parent = varDeclStmt;
		declaredType = varDeclStmt.getType();
		parentMods = varDeclStmt.modifiers();
	}
	else if (parent instanceof VariableDeclarationExpression ) {
		VariableDeclarationExpression varDeclExpr = (VariableDeclarationExpression)parent;
		parent = varDeclExpr;
		declaredType = varDeclExpr.getType();
		// Not allowed to call varExpr.modifiers();
		parentMods = null;
	}
	else {
		parent = null;
		// We handle FieldDeclaration elsewhere...
		return false;
	}
	
	ITypeBinding type = declaredType.resolveBinding();
	// XXX. Why would type be null here? Need to investigate.
	if (type != null && !type.isPrimitive()) {
		
		String annotation = "lent"; // XXX. Bad hard-coded default. What about <p>?
		if (HARD_CODE_STATICS && isStaticScope(parent)) {
			annotation = "shared<shared>";
		}
		else {
			annotation = strategy.getAnnotationForLocalVariable(varDecl);
		}
		
		ChildListPropertyDescriptor property = parent instanceof VariableDeclarationStatement ? 
					VariableDeclarationStatement.MODIFIERS2_PROPERTY
					: VariableDeclarationExpression.MODIFIERS2_PROPERTY;
		
		SingleMemberAnnotation currentAnnotation = getCurrentAnnotation(parentMods);
		if (currentAnnotation == null) {
			setVariableAnnotation2(parent, annotation, property);
		}
		else {
			updateVariableAnnotation2(parent, annotation, currentAnnotation, property);
		}		
		
		
		// XXX. Lookup enclosing type declaration from local variable
		String srcType = type.getQualifiedName();
		String dstType = Utils.getEnclosingTypeName(varDecl);
		// XXX. Come up with a better key
		trackChanges(varDecl.toString(), annotation, getValue(currentAnnotation), CSVConst.VARIABLE, srcType, dstType);
		
	}
	return super.visit(varDecl);
}
 
開發者ID:aroog,項目名稱:code,代碼行數:64,代碼來源:SaveAnnotations.java

示例6: createParameterDeclaration

import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的package包/類
private SingleVariableDeclaration createParameterDeclaration(
    String parameterName,
    VariableDeclarationFragment fragement,
    Expression arrayAccess,
    ForStatement statement,
    ImportRewrite importRewrite,
    ASTRewrite rewrite,
    TextEditGroup group,
    LinkedProposalPositionGroup pg,
    boolean makeFinal) {
  CompilationUnit compilationUnit = (CompilationUnit) arrayAccess.getRoot();
  AST ast = compilationUnit.getAST();

  SingleVariableDeclaration result = ast.newSingleVariableDeclaration();

  SimpleName name = ast.newSimpleName(parameterName);
  pg.addPosition(rewrite.track(name), true);
  result.setName(name);

  ITypeBinding arrayTypeBinding = arrayAccess.resolveTypeBinding();
  Type type =
      importType(arrayTypeBinding.getElementType(), statement, importRewrite, compilationUnit);
  if (arrayTypeBinding.getDimensions() != 1) {
    type = ast.newArrayType(type, arrayTypeBinding.getDimensions() - 1);
  }
  result.setType(type);

  if (fragement != null) {
    VariableDeclarationStatement declaration =
        (VariableDeclarationStatement) fragement.getParent();
    ModifierRewrite.create(rewrite, result).copyAllModifiers(declaration, group);
  }
  if (makeFinal
      && (fragement == null
          || ASTNodes.findModifierNode(Modifier.FINAL, ASTNodes.getModifiers(fragement))
              == null)) {
    ModifierRewrite.create(rewrite, result).setModifiers(Modifier.FINAL, 0, group);
  }

  return result;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:42,代碼來源:ConvertForLoopOperation.java

示例7: removeVariableReferences

import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的package包/類
/**
 * Remove the field or variable declaration including the initializer.
 *
 * @param rewrite the ast rewrite
 * @param reference the reference
 */
private void removeVariableReferences(ASTRewrite rewrite, SimpleName reference) {
  ASTNode parent = reference.getParent();
  while (parent instanceof QualifiedName) {
    parent = parent.getParent();
  }
  if (parent instanceof FieldAccess) {
    parent = parent.getParent();
  }

  int nameParentType = parent.getNodeType();
  if (nameParentType == ASTNode.ASSIGNMENT) {
    Assignment assignment = (Assignment) parent;
    Expression rightHand = assignment.getRightHandSide();

    ASTNode assignParent = assignment.getParent();
    if (assignParent.getNodeType() == ASTNode.EXPRESSION_STATEMENT
        && rightHand.getNodeType() != ASTNode.ASSIGNMENT) {
      removeVariableWithInitializer(rewrite, rightHand, assignParent);
    } else {
      rewrite.replace(assignment, rewrite.createCopyTarget(rightHand), null);
    }
  } else if (nameParentType == ASTNode.SINGLE_VARIABLE_DECLARATION) {
    rewrite.remove(parent, null);
  } else if (nameParentType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
    VariableDeclarationFragment frag = (VariableDeclarationFragment) parent;
    ASTNode varDecl = frag.getParent();
    List<VariableDeclarationFragment> fragments;
    if (varDecl instanceof VariableDeclarationExpression) {
      fragments = ((VariableDeclarationExpression) varDecl).fragments();
    } else if (varDecl instanceof FieldDeclaration) {
      fragments = ((FieldDeclaration) varDecl).fragments();
    } else {
      fragments = ((VariableDeclarationStatement) varDecl).fragments();
    }
    if (fragments.size() == 1) {
      rewrite.remove(varDecl, null);
    } else {
      rewrite.remove(frag, null); // don't try to preserve
    }
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:48,代碼來源:RemoveDeclarationCorrectionProposal.java


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