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


Java SingleVariableDeclaration.setName方法代碼示例

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


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

示例1: createPrivateConstructorDefinition

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public MethodDeclaration createPrivateConstructorDefinition(AST ast, TypeDeclaration originalType, TypeDeclaration builderType,
        List<BuilderField> builderFields) {

    MethodDeclaration method = ast.newMethodDeclaration();
    method.setConstructor(true);
    method.setName(ast.newSimpleName(originalType.getName().toString()));
    if (preferencesManager.getPreferenceValue(ADD_GENERATED_ANNOTATION)) {
        generatedAnnotationPopulator.addGeneratedAnnotation(ast, method);
    }
    method.modifiers().add(ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD));

    SingleVariableDeclaration methodParameterDeclaration = ast.newSingleVariableDeclaration();
    methodParameterDeclaration.setType(ast.newSimpleType(ast.newName(builderType.getName().toString())));
    methodParameterDeclaration.setName(ast.newSimpleName(camelCaseConverter.toLowerCamelCase(builderType.getName().toString())));

    method.parameters().add(methodParameterDeclaration);
    return method;
}
 
開發者ID:helospark,項目名稱:SparkBuilderGenerator,代碼行數:20,代碼來源:PrivateConstructorMethodDefinitionCreationFragment.java

示例2: addNewParameters

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
@Override
protected void addNewParameters(ASTRewrite rewrite, List<String> takenNames, List<SingleVariableDeclaration> params, ImportRewriteContext context) throws CoreException {
	AST ast= rewrite.getAST();

	List<Expression> arguments= fArguments;

	for (int i= 0; i < arguments.size(); i++) {
		Expression elem= arguments.get(i);
		SingleVariableDeclaration param= ast.newSingleVariableDeclaration();

		// argument type
		String argTypeKey= "arg_type_" + i; //$NON-NLS-1$
		Type type= evaluateParameterType(ast, elem, argTypeKey, context);
		param.setType(type);

		// argument name
		String argNameKey= "arg_name_" + i; //$NON-NLS-1$
		String name= evaluateParameterName(takenNames, elem, type, argNameKey);
		param.setName(ast.newSimpleName(name));

		params.add(param);
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:24,代碼來源:NewMethodCorrectionProposal.java

示例3: copyArguments

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
private void copyArguments(MethodDeclaration intermediary, CompilationUnitRewrite rew)
    throws JavaModelException {
  String[] names = fTargetMethod.getParameterNames();
  ITypeBinding[] types = fTargetMethodBinding.getParameterTypes();
  for (int i = 0; i < names.length; i++) {
    ITypeBinding typeBinding = types[i];
    SingleVariableDeclaration newElement = rew.getAST().newSingleVariableDeclaration();
    newElement.setName(rew.getAST().newSimpleName(names[i]));

    if (i == (names.length - 1) && fTargetMethodBinding.isVarargs()) {
      newElement.setVarargs(true);
      if (typeBinding.isArray()) typeBinding = typeBinding.getComponentType();
    }

    newElement.setType(rew.getImportRewrite().addImport(typeBinding, rew.getAST()));
    intermediary.parameters().add(newElement);
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:19,代碼來源:IntroduceIndirectionRefactoring.java

示例4: createWithMethodParameter

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
public SingleVariableDeclaration createWithMethodParameter(AST ast, Type type, String fieldName) {
    SingleVariableDeclaration methodParameterDeclaration = ast.newSingleVariableDeclaration();
    methodParameterDeclaration.setType((Type) ASTNode.copySubtree(ast, type));
    methodParameterDeclaration.setName(ast.newSimpleName(fieldName));
    if (preferencesManager.getPreferenceValue(PluginPreferenceList.ADD_NONNULL_ON_PARAMETERS)) {
        markerAnnotationAttacher.attachNonNull(ast, methodParameterDeclaration);
    }
    return methodParameterDeclaration;
}
 
開發者ID:helospark,項目名稱:SparkBuilderGenerator,代碼行數:10,代碼來源:WithMethodParameterCreatorFragment.java

示例5: addNewParameters

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
private void addNewParameters(ASTRewrite rewrite, List<SingleVariableDeclaration> params, ImportRewriteContext context) throws CoreException {
	if (!isGetter) {
		AST ast = rewrite.getAST();

		SingleVariableDeclaration param = ast.newSingleVariableDeclaration();
		Type type = getImportRewrite().addImport(fVariableBinding.getType(), ast, context, TypeLocation.PARAMETER);
		param.setType(type);
		param.setName(ast.newSimpleName(getArgumentName()));
		params.add(param);
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:12,代碼來源:SelfEncapsulateFieldProposal.java

示例6: createParameterDeclaration

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的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: createNewSingleVariableDeclaration

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
protected SingleVariableDeclaration createNewSingleVariableDeclaration(ParameterInfo info) {
  SingleVariableDeclaration newP = getASTRewrite().getAST().newSingleVariableDeclaration();
  newP.setName(getASTRewrite().getAST().newSimpleName(info.getNewName()));
  newP.setType(
      createNewTypeNode(
          ParameterInfo.stripEllipsis(info.getNewTypeName()), info.getNewTypeBinding()));
  newP.setVarargs(info.isNewVarargs());
  return newP;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:10,代碼來源:ChangeSignatureProcessor.java

示例8: newParameterDeclaration

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
private SingleVariableDeclaration newParameterDeclaration(
    AST ast, ImportRewrite importRewrite, String paramName, ITypeBinding paramType) {

  SingleVariableDeclaration param = ast.newSingleVariableDeclaration();
  param.setType(importRewrite.addImport(paramType, ast));
  param.setName(ast.newSimpleName(paramName));
  return param;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:9,代碼來源:ConvertAnonymousToNestedRefactoring.java

示例9: createFactoryMethodSignature

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
/**
 * Creates and adds the necessary argument declarations to the given factory method.<br>
 * An argument is needed for each original constructor argument for which the evaluation of the
 * actual arguments across all calls was not able to be pushed inside the factory method (e.g.
 * arguments with side-effects, references to fields if the factory method is to be static or
 * reside in a factory class, or arguments that varied across the set of constructor calls).<br>
 * <code>fArgTypes</code> identifies such arguments by a <code>null</code> value.
 *
 * @param ast utility object used to create AST nodes
 * @param newMethod the <code>MethodDeclaration</code> for the factory method
 */
private void createFactoryMethodSignature(AST ast, MethodDeclaration newMethod) {
  List<SingleVariableDeclaration> argDecls = newMethod.parameters();

  for (int i = 0; i < fArgTypes.length; i++) {
    SingleVariableDeclaration argDecl = ast.newSingleVariableDeclaration();
    Type argType;

    if (i == (fArgTypes.length - 1) && fCtorIsVarArgs) {
      // The trailing varargs arg has an extra array dimension, compared to
      // what we need to pass to setType()...
      argType =
          typeNodeForTypeBinding(
              fArgTypes[i].getElementType(), fArgTypes[i].getDimensions() - 1, ast);
      argDecl.setVarargs(true);
    } else argType = typeNodeForTypeBinding(fArgTypes[i], 0, ast);

    argDecl.setName(ast.newSimpleName(fFormalArgNames[i]));
    argDecl.setType(argType);
    argDecls.add(argDecl);
  }

  ITypeBinding[] ctorExcepts = fCtorBinding.getExceptionTypes();
  List<Type> exceptions = newMethod.thrownExceptionTypes();

  for (int i = 0; i < ctorExcepts.length; i++) {
    exceptions.add(fImportRewriter.addImport(ctorExcepts[i], ast));
  }

  copyTypeParameters(ast, newMethod);
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:42,代碼來源:IntroduceFactoryRefactoring.java

示例10: generateForEachRewrite

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
/**
 * Helper to generate a <code>foreach</code> loop to iterate over an {@link Iterable}.
 *
 * @param ast the {@link AST} instance to rewrite the loop to
 * @return the complete {@link ASTRewrite} object
 */
private ASTRewrite generateForEachRewrite(AST ast) {

  EnhancedForStatement loopStatement = ast.newEnhancedForStatement();

  ASTRewrite rewrite = ASTRewrite.create(ast);
  ITypeBinding loopOverType = extractElementType(ast);

  // generate name proposals and add them to the variable declaration
  SimpleName forDeclarationName =
      resolveLinkedVariableNameWithProposals(rewrite, loopOverType.getName(), null, true);

  SingleVariableDeclaration forLoopInitializer = ast.newSingleVariableDeclaration();
  forLoopInitializer.setType(
      getImportRewrite()
          .addImport(
              loopOverType,
              ast,
              new ContextSensitiveImportRewriteContext(fCurrentNode, getImportRewrite())));
  forLoopInitializer.setName(forDeclarationName);

  loopStatement.setParameter(forLoopInitializer);
  loopStatement.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression));

  Block forLoopBody = ast.newBlock();
  forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));

  loopStatement.setBody(forLoopBody);

  rewrite.replace(fCurrentNode, loopStatement, null);

  return rewrite;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:39,代碼來源:GenerateForLoopAssistProposal.java

示例11: addEnclosingInstanceAccess

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
private SuperConstructorInvocation addEnclosingInstanceAccess(
    ASTRewrite rewrite,
    ImportRewriteContext importRewriteContext,
    List<SingleVariableDeclaration> parameters,
    String[] paramNames,
    ITypeBinding enclosingInstance) {
  AST ast = rewrite.getAST();
  SuperConstructorInvocation invocation = ast.newSuperConstructorInvocation();

  SingleVariableDeclaration var = ast.newSingleVariableDeclaration();
  var.setType(getImportRewrite().addImport(enclosingInstance, ast, importRewriteContext));
  String[] enclosingArgNames =
      StubUtility.getArgumentNameSuggestions(
          getCompilationUnit().getJavaProject(),
          enclosingInstance.getTypeDeclaration().getName(),
          0,
          paramNames);
  String firstName = enclosingArgNames[0];
  var.setName(ast.newSimpleName(firstName));
  parameters.add(var);

  Name enclosing = ast.newSimpleName(firstName);
  invocation.setExpression(enclosing);

  String key = "arg_name_" + firstName; // $NON-NLS-1$
  addLinkedPosition(rewrite.track(enclosing), false, key);
  for (int i = 0; i < enclosingArgNames.length; i++) {
    addLinkedPositionProposal(key, enclosingArgNames[i], null); // alternative names
  }
  return invocation;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:32,代碼來源:ConstructorFromSuperclassProposal.java

示例12: addNewParameters

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
@Override
protected void addNewParameters(
    ASTRewrite rewrite, List<String> takenNames, List<SingleVariableDeclaration> params)
    throws CoreException {
  AST ast = rewrite.getAST();

  List<Expression> arguments = fArguments;
  ImportRewriteContext context =
      new ContextSensitiveImportRewriteContext(
          ASTResolving.findParentBodyDeclaration(getInvocationNode()), getImportRewrite());

  for (int i = 0; i < arguments.size(); i++) {
    Expression elem = arguments.get(i);
    SingleVariableDeclaration param = ast.newSingleVariableDeclaration();

    // argument type
    String argTypeKey = "arg_type_" + i; // $NON-NLS-1$
    Type type = evaluateParameterType(ast, elem, argTypeKey, context);
    param.setType(type);

    // argument name
    String argNameKey = "arg_name_" + i; // $NON-NLS-1$
    String name = evaluateParameterName(takenNames, elem, type, argNameKey);
    param.setName(ast.newSimpleName(name));

    params.add(param);

    addLinkedPosition(rewrite.track(param.getType()), false, argTypeKey);
    addLinkedPosition(rewrite.track(param.getName()), false, argNameKey);
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:32,代碼來源:NewMethodCorrectionProposal.java

示例13: addNewParameters

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
@Override
protected void addNewParameters(
    ASTRewrite rewrite, List<String> takenNames, List<SingleVariableDeclaration> params)
    throws CoreException {
  AST ast = rewrite.getAST();
  ImportRewrite importRewrite = getImportRewrite();
  ITypeBinding[] bindings = fMethod.getParameterTypes();

  IJavaProject project = getCompilationUnit().getJavaProject();
  String[][] paramNames = StubUtility.suggestArgumentNamesWithProposals(project, fParamNames);

  for (int i = 0; i < bindings.length; i++) {
    ITypeBinding curr = bindings[i];

    String[] proposedNames = paramNames[i];

    SingleVariableDeclaration newParam = ast.newSingleVariableDeclaration();

    newParam.setType(importRewrite.addImport(curr, ast));
    newParam.setName(ast.newSimpleName(proposedNames[0]));

    params.add(newParam);

    String groupId = "arg_name_" + i; // $NON-NLS-1$
    addLinkedPosition(rewrite.track(newParam.getName()), false, groupId);

    for (int k = 0; k < proposedNames.length; k++) {
      addLinkedPositionProposal(groupId, proposedNames[k], null);
    }
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:32,代碼來源:NewDefiningMethodProposal.java

示例14: cloneMethodParameter

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
/**
 * Clones the given parameter declaration.
 */
public static SingleVariableDeclaration cloneMethodParameter(AST ast,
    SingleVariableDeclaration param, ImportRewrite imports) {
  SingleVariableDeclaration newParam = ast.newSingleVariableDeclaration();

  // New parameter has a normalized type equivalent to the original
  Type type = normalizeTypeAndAddImport(ast, param.getType(), imports);
  newParam.setType(type);

  // Give new parameter same name as the original
  newParam.setName(ast.newSimpleName(param.getName().getIdentifier()));

  return newParam;
}
 
開發者ID:gwt-plugins,項目名稱:gwt-eclipse-plugin,代碼行數:17,代碼來源:JavaASTUtils.java

示例15: createAsyncCallbackParameter

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入方法依賴的package包/類
/**
 * Creates a GWT RPC async callback parameter declaration based on the sync
 * method return type.
 *
 * @param ast {@link AST} associated with the destination compilation unit
 * @param syncReturnType the sync method return type
 * @param callbackParameterName name of the callback parameter
 * @param imports {@link ImportsRewrite} for the destination compilation unit
 * @return callback paramter declaration
 */
@SuppressWarnings("unchecked")
public static SingleVariableDeclaration createAsyncCallbackParameter(AST ast,
    Type syncReturnType, String callbackParameterName, ImportRewrite imports) {
  ITypeBinding syncReturnTypeBinding = syncReturnType.resolveBinding();

  SingleVariableDeclaration parameter = ast.newSingleVariableDeclaration();

  String gwtCallbackTypeSig = Signature.createTypeSignature(
      RemoteServiceUtilities.ASYNCCALLBACK_QUALIFIED_NAME, true);
  Type gwtCallbackType = imports.addImportFromSignature(gwtCallbackTypeSig,
      ast);

  if (syncReturnTypeBinding.isPrimitive()) {
    String wrapperName = JavaASTUtils.getWrapperTypeName(syncReturnTypeBinding.getName());
    String wrapperTypeSig = Signature.createTypeSignature(wrapperName, true);
    syncReturnType = imports.addImportFromSignature(wrapperTypeSig, ast);
  } else {
    syncReturnType = JavaASTUtils.normalizeTypeAndAddImport(ast,
        syncReturnType, imports);
  }

  ParameterizedType type = ast.newParameterizedType(gwtCallbackType);
  List<Type> typeArgs = type.typeArguments();
  typeArgs.add(syncReturnType);

  parameter.setType(type);
  parameter.setName(ast.newSimpleName(callbackParameterName));

  return parameter;
}
 
開發者ID:gwt-plugins,項目名稱:gwt-eclipse-plugin,代碼行數:41,代碼來源:Util.java


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