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


Java FieldDeclaration.setJavadoc方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.FieldDeclaration.setJavadoc方法的典型用法代码示例。如果您正苦于以下问题:Java FieldDeclaration.setJavadoc方法的具体用法?Java FieldDeclaration.setJavadoc怎么用?Java FieldDeclaration.setJavadoc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.dom.FieldDeclaration的用法示例。


在下文中一共展示了FieldDeclaration.setJavadoc方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: rewriteAST

import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException {
	final ASTRewrite rewrite = cuRewrite.getASTRewrite();
	VariableDeclarationFragment fragment = null;
	for (int i = 0; i < fNodes.length; i++) {
		final ASTNode node = fNodes[i];

		final AST ast = node.getAST();

		fragment = ast.newVariableDeclarationFragment();
		fragment.setName(ast.newSimpleName(NAME_FIELD));

		final FieldDeclaration declaration = ast.newFieldDeclaration(fragment);
		declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
		declaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));

		if (!addInitializer(fragment, node)) {
			continue;
		}

		if (fragment.getInitializer() != null) {

			final TextEditGroup editGroup = createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
			if (node instanceof AbstractTypeDeclaration) {
				rewrite.getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty()).insertAt(declaration, 0, editGroup);
			} else if (node instanceof AnonymousClassDeclaration) {
				rewrite.getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
			} else if (node instanceof ParameterizedType) {
				final ParameterizedType type = (ParameterizedType) node;
				final ASTNode parent = type.getParent();
				if (parent instanceof ClassInstanceCreation) {
					final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
					final AnonymousClassDeclaration anonymous = creation.getAnonymousClassDeclaration();
					if (anonymous != null) {
						rewrite.getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
					}
				}
			} else {
				Assert.isTrue(false);
			}

			addLinkedPositions(rewrite, fragment, positionGroups);
		}

		final String comment = CodeGeneration.getFieldComment(fUnit, declaration.getType().toString(), NAME_FIELD, "\n" /* StubUtility.getLineDelimiterUsed(fUnit) */);
		if (comment != null && comment.length() > 0 && !"/**\n *\n */\n".equals(comment)) {
			final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
			declaration.setJavadoc(doc);
		}
	}
	if (fragment == null) {
		return;
	}

	positionGroups.setEndPosition(rewrite.track(fragment));
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:57,代码来源:AbstractSerialVersionOperation.java

示例2: rewriteAST

import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups)
    throws CoreException {
  final ASTRewrite rewrite = cuRewrite.getASTRewrite();
  VariableDeclarationFragment fragment = null;
  for (int i = 0; i < fNodes.length; i++) {
    final ASTNode node = fNodes[i];

    final AST ast = node.getAST();

    fragment = ast.newVariableDeclarationFragment();
    fragment.setName(ast.newSimpleName(NAME_FIELD));

    final FieldDeclaration declaration = ast.newFieldDeclaration(fragment);
    declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
    declaration
        .modifiers()
        .addAll(
            ASTNodeFactory.newModifiers(
                ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));

    if (!addInitializer(fragment, node)) continue;

    if (fragment.getInitializer() != null) {

      final TextEditGroup editGroup =
          createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
      if (node instanceof AbstractTypeDeclaration)
        rewrite
            .getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty())
            .insertAt(declaration, 0, editGroup);
      else if (node instanceof AnonymousClassDeclaration)
        rewrite
            .getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY)
            .insertAt(declaration, 0, editGroup);
      else if (node instanceof ParameterizedType) {
        final ParameterizedType type = (ParameterizedType) node;
        final ASTNode parent = type.getParent();
        if (parent instanceof ClassInstanceCreation) {
          final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
          final AnonymousClassDeclaration anonymous = creation.getAnonymousClassDeclaration();
          if (anonymous != null)
            rewrite
                .getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY)
                .insertAt(declaration, 0, editGroup);
        }
      } else Assert.isTrue(false);

      addLinkedPositions(rewrite, fragment, positionGroups);
    }

    final String comment =
        CodeGeneration.getFieldComment(
            fUnit,
            declaration.getType().toString(),
            NAME_FIELD,
            StubUtility.getLineDelimiterUsed(fUnit));
    if (comment != null && comment.length() > 0) {
      final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
      declaration.setJavadoc(doc);
    }
  }
  if (fragment == null) return;

  positionGroups.setEndPosition(rewrite.track(fragment));
}
 
开发者ID:eclipse,项目名称:che,代码行数:68,代码来源:AbstractSerialVersionOperation.java

示例3: createFieldsForAccessedLocals

import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
private void createFieldsForAccessedLocals(
    CompilationUnitRewrite rewrite,
    IVariableBinding[] varBindings,
    String[] fieldNames,
    List<BodyDeclaration> newBodyDeclarations)
    throws CoreException {
  final ImportRewrite importRewrite = rewrite.getImportRewrite();
  final ASTRewrite astRewrite = rewrite.getASTRewrite();
  final AST ast = astRewrite.getAST();

  for (int i = 0; i < varBindings.length; i++) {
    VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment();
    fragment.setInitializer(null);
    fragment.setName(ast.newSimpleName(fieldNames[i]));
    FieldDeclaration field = ast.newFieldDeclaration(fragment);
    ITypeBinding varType = varBindings[i].getType();
    field.setType(importRewrite.addImport(varType, ast));
    field.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.FINAL));
    if (doAddComments()) {
      String string =
          CodeGeneration.getFieldComment(
              rewrite.getCu(),
              varType.getName(),
              fieldNames[i],
              StubUtility.getLineDelimiterUsed(fCu));
      if (string != null) {
        Javadoc javadoc = (Javadoc) astRewrite.createStringPlaceholder(string, ASTNode.JAVADOC);
        field.setJavadoc(javadoc);
      }
    }

    newBodyDeclarations.add(field);

    addLinkedPosition(KEY_FIELD_NAME_EXT + i, fragment.getName(), astRewrite, false);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:37,代码来源:ConvertAnonymousToNestedRefactoring.java

示例4: addEnclosingInstanceDeclaration

import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
private void addEnclosingInstanceDeclaration(final AbstractTypeDeclaration declaration, final ASTRewrite rewrite) throws CoreException {
	Assert.isNotNull(declaration);
	Assert.isNotNull(rewrite);
	final AST ast= declaration.getAST();
	final VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
	fragment.setName(ast.newSimpleName(fEnclosingInstanceFieldName));
	final FieldDeclaration newField= ast.newFieldDeclaration(fragment);
	newField.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getEnclosingInstanceAccessModifiers()));
	newField.setType(createEnclosingType(ast));
	final String comment= CodeGeneration.getFieldComment(fType.getCompilationUnit(), declaration.getName().getIdentifier(), fEnclosingInstanceFieldName, StubUtility.getLineDelimiterUsed(fType.getJavaProject()));
	if (comment != null && comment.length() > 0) {
		final Javadoc doc= (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
		newField.setJavadoc(doc);
	}
	rewrite.getListRewrite(declaration, declaration.getBodyDeclarationsProperty()).insertFirst(newField, null);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:MoveInnerToTopRefactoring.java

示例5: createField

import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
private FieldDeclaration createField(ParameterInfo pi, CompilationUnitRewrite cuRewrite) throws CoreException {
	AST ast= cuRewrite.getAST();
	ICompilationUnit unit= cuRewrite.getCu();

	VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
	String lineDelim= StubUtility.getLineDelimiterUsed(unit);
	SimpleName fieldName= ast.newSimpleName(pi.getNewName());
	fragment.setName(fieldName);
	FieldDeclaration declaration= ast.newFieldDeclaration(fragment);
	if (createComments(unit.getJavaProject())) {
		String comment= StubUtility.getFieldComment(unit, pi.getNewTypeName(), pi.getNewName(), lineDelim);
		if (comment != null) {
			Javadoc doc= (Javadoc) cuRewrite.getASTRewrite().createStringPlaceholder(comment, ASTNode.JAVADOC);
			declaration.setJavadoc(doc);
		}
	}
	List<Modifier> modifiers= new ArrayList<Modifier>();
	if (fCreateGetter) {
		modifiers.add(ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD));
	} else {
		modifiers.add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
	}
	declaration.modifiers().addAll(modifiers);
	declaration.setType(importBinding(pi.getNewTypeBinding(), cuRewrite));
	return declaration;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:27,代码来源:ParameterObjectFactory.java

示例6: createFieldsForAccessedLocals

import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
private void createFieldsForAccessedLocals(CompilationUnitRewrite rewrite, IVariableBinding[] varBindings, String[] fieldNames, List<BodyDeclaration> newBodyDeclarations) throws CoreException {
	final ImportRewrite importRewrite= rewrite.getImportRewrite();
	final ASTRewrite astRewrite= rewrite.getASTRewrite();
	final AST ast= astRewrite.getAST();

	for (int i= 0; i < varBindings.length; i++) {
		VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
		fragment.setInitializer(null);
		fragment.setName(ast.newSimpleName(fieldNames[i]));
		FieldDeclaration field= ast.newFieldDeclaration(fragment);
		ITypeBinding varType= varBindings[i].getType();
		field.setType(importRewrite.addImport(varType, ast));
		field.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.FINAL));
		if (doAddComments()) {
			String string= CodeGeneration.getFieldComment(rewrite.getCu(), varType.getName(), fieldNames[i], StubUtility.getLineDelimiterUsed(fCu));
			if (string != null) {
				Javadoc javadoc= (Javadoc) astRewrite.createStringPlaceholder(string, ASTNode.JAVADOC);
				field.setJavadoc(javadoc);
			}
		}

		newBodyDeclarations.add(field);

		addLinkedPosition(KEY_FIELD_NAME_EXT + i, fragment.getName(), astRewrite, false);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:27,代码来源:ConvertAnonymousToNestedRefactoring.java

示例7: createConstantDeclaration

import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的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

示例8: fieldCreated

import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
@Override
		public void fieldCreated(CompilationUnitRewrite cuRewrite, FieldDeclaration field, ParameterInfo pi) {
			FieldInfo fieldInfo= getFieldInfo(pi.getOldName());
			FieldDeclaration parent= (FieldDeclaration) fieldInfo.declaration.getParent();
			List<IExtendedModifier> modifiers= parent.modifiers();
			ListRewrite listRewrite= cuRewrite.getASTRewrite().getListRewrite(field, FieldDeclaration.MODIFIERS2_PROPERTY);
			for (Iterator<IExtendedModifier> iterator= modifiers.iterator(); iterator.hasNext();) {
				IExtendedModifier mod= iterator.next();
				//Temporarily disabled until initialization of final fields is handled correctly
//				if (mod.isModifier()) {
//					Modifier modifier= (Modifier) mod;
//					if (modifier.isFinal())
//						listRewrite.insertLast(moveNode(cuRewrite, modifier), null);
//				}
				if (mod.isAnnotation()) {
					listRewrite.insertFirst(moveNode(cuRewrite, (ASTNode) mod), null);
				}
			}
			if (fieldInfo.initializer != null && fieldInfo.hasFieldReference()) {
				List<VariableDeclarationFragment> fragments= field.fragments();
				for (Iterator<VariableDeclarationFragment> iterator= fragments.iterator(); iterator.hasNext();) {
					VariableDeclarationFragment vdf= iterator.next();
					vdf.setInitializer((Expression) moveNode(cuRewrite, fieldInfo.initializer));
				}
			}
			if (parent.getJavadoc() != null) {
				field.setJavadoc((Javadoc) moveNode(cuRewrite, parent.getJavadoc()));
			}
		}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:30,代码来源:ExtractClassRefactoring.java

示例9: createFieldsForAccessedLocals

import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
private void createFieldsForAccessedLocals(CompilationUnitRewrite rewrite, IVariableBinding[] varBindings, String[] fieldNames, List<BodyDeclaration> newBodyDeclarations) throws CoreException {
	final ImportRewrite importRewrite= rewrite.getImportRewrite();
	final ASTRewrite astRewrite= rewrite.getASTRewrite();
	final AST ast= astRewrite.getAST();

	for (int i= 0; i < varBindings.length; i++) {
		VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
		fragment.setExtraDimensions(0);
		fragment.setInitializer(null);
		fragment.setName(ast.newSimpleName(fieldNames[i]));
		FieldDeclaration field= ast.newFieldDeclaration(fragment);
		ITypeBinding varType= varBindings[i].getType();
		field.setType(importRewrite.addImport(varType, ast));
		field.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.FINAL));
		if (doAddComments()) {
			String string= CodeGeneration.getFieldComment(rewrite.getCu(), varType.getName(), fieldNames[i], StubUtility.getLineDelimiterUsed(fCu));
			if (string != null) {
				Javadoc javadoc= (Javadoc) astRewrite.createStringPlaceholder(string, ASTNode.JAVADOC);
				field.setJavadoc(javadoc);
			}
		}

		newBodyDeclarations.add(field);

		addLinkedPosition(KEY_FIELD_NAME_EXT + i, fragment.getName(), astRewrite, false);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:28,代码来源:ConvertAnonymousToNestedRefactoring.java

示例10: createConstantDeclaration

import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的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:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:65,代码来源:ExtractConstantRefactoring.java

示例11: rewriteAST

import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException {
	final ASTRewrite rewrite= cuRewrite.getASTRewrite();
	VariableDeclarationFragment fragment= null;
	for (int i= 0; i < fNodes.length; i++) {
		final ASTNode node= fNodes[i];

		final AST ast= node.getAST();

		fragment= ast.newVariableDeclarationFragment();
		fragment.setName(ast.newSimpleName(NAME_FIELD));

		final FieldDeclaration declaration= ast.newFieldDeclaration(fragment);
		declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
		declaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));

		if (!addInitializer(fragment, node))
			continue;

		if (fragment.getInitializer() != null) {

			final TextEditGroup editGroup= createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
			if (node instanceof AbstractTypeDeclaration)
				rewrite.getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty()).insertAt(declaration, 0, editGroup);
			else if (node instanceof AnonymousClassDeclaration)
				rewrite.getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
			else if (node instanceof ParameterizedType) {
				final ParameterizedType type= (ParameterizedType) node;
				final ASTNode parent= type.getParent();
				if (parent instanceof ClassInstanceCreation) {
					final ClassInstanceCreation creation= (ClassInstanceCreation) parent;
					final AnonymousClassDeclaration anonymous= creation.getAnonymousClassDeclaration();
					if (anonymous != null)
						rewrite.getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
				}
			} else
				Assert.isTrue(false);

			addLinkedPositions(rewrite, fragment, positionGroups);
		}

		final String comment= CodeGeneration.getFieldComment(fUnit, declaration.getType().toString(), NAME_FIELD, StubUtility.getLineDelimiterUsed(fUnit));
		if (comment != null && comment.length() > 0) {
			final Javadoc doc= (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
			declaration.setJavadoc(doc);
		}
	}
	if (fragment == null)
		return;

	positionGroups.setEndPosition(rewrite.track(fragment));
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:56,代码来源:AbstractSerialVersionOperation.java


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