• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CodeGeneration类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: rewriteAST

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的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


示例2: createFieldsForAccessedLocals

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的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


示例3: getNewConstructorComment

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的package包/类
private Javadoc getNewConstructorComment(ASTRewrite rewrite) throws CoreException {
  if (StubUtility.doAddComments(fCu.getJavaProject())) {
    String comment =
        CodeGeneration.getMethodComment(
            fCu,
            getEnclosingTypeName(),
            getEnclosingTypeName(),
            new String[0],
            new String[0],
            null,
            null,
            StubUtility.getLineDelimiterUsed(fCu));
    if (comment != null && comment.length() > 0) {
      return (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
    }
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:PromoteTempToFieldRefactoring.java


示例4: createNewMethod

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的package包/类
private MethodDeclaration createNewMethod(
    ASTNode[] selectedNodes, String lineDelimiter, TextEditGroup substitute)
    throws CoreException {
  MethodDeclaration result = createNewMethodDeclaration();
  result.setBody(createMethodBody(selectedNodes, substitute, result.getModifiers()));
  if (fGenerateJavadoc) {
    AbstractTypeDeclaration enclosingType =
        (AbstractTypeDeclaration)
            ASTNodes.getParent(
                fAnalyzer.getEnclosingBodyDeclaration(), AbstractTypeDeclaration.class);
    String string =
        CodeGeneration.getMethodComment(
            fCUnit, enclosingType.getName().getIdentifier(), result, null, lineDelimiter);
    if (string != null) {
      Javadoc javadoc = (Javadoc) fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC);
      result.setJavadoc(javadoc);
    }
  }
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:ExtractMethodRefactoring.java


示例5: addEnclosingInstanceDeclaration

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的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


示例6: createJavadocForStub

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的package包/类
private Javadoc createJavadocForStub(final String enclosingTypeName, final MethodDeclaration oldMethod, final MethodDeclaration newMethodNode, final ICompilationUnit cu, final ASTRewrite rewrite) throws CoreException {
	if (fSettings.createComments) {
		final IMethodBinding binding= oldMethod.resolveBinding();
		if (binding != null) {
			final ITypeBinding[] params= binding.getParameterTypes();
			final String fullTypeName= getDestinationType().getFullyQualifiedName('.');
			final String[] fullParamNames= new String[params.length];
			for (int i= 0; i < fullParamNames.length; i++) {
				fullParamNames[i]= Bindings.getFullyQualifiedName(params[i]);
			}
			final String comment= CodeGeneration.getMethodComment(cu, enclosingTypeName, newMethodNode, false, binding.getName(), fullTypeName, fullParamNames, StubUtility.getLineDelimiterUsed(cu));
			if (comment != null)
				return (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
		}
	}
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:PullUpRefactoringProcessor.java


示例7: createFieldsForAccessedLocals

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的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


示例8: createMethodComment

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的package包/类
/**
 * adds a comment (if necessary) and an <code>@Override</code> annotation to the generated
 * method
 * 
 * @throws CoreException if creation failed
 */
protected void createMethodComment() throws CoreException {
	ITypeBinding object= fAst.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
	IMethodBinding[] objms= object.getDeclaredMethods();
	IMethodBinding objectMethod= null;
	for (int i= 0; i < objms.length; i++) {
		if (objms[i].getName().equals(METHODNAME_TO_STRING) && objms[i].getParameterTypes().length == 0)
			objectMethod= objms[i];
	}
	if (fContext.isCreateComments()) {
		String docString= CodeGeneration.getMethodComment(fContext.getCompilationUnit(), fContext.getTypeBinding().getQualifiedName(), toStringMethod, objectMethod, StubUtility
				.getLineDelimiterUsed(fContext.getCompilationUnit()));
		if (docString != null) {
			Javadoc javadoc= (Javadoc)fContext.getASTRewrite().createStringPlaceholder(docString, ASTNode.JAVADOC);
			toStringMethod.setJavadoc(javadoc);
		}
	}
	if (fContext.isOverrideAnnotation() && fContext.is50orHigher())
		StubUtility2.addOverrideAnnotation(fContext.getTypeBinding().getJavaElement().getJavaProject(), fContext.getASTRewrite(), toStringMethod, objectMethod);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:AbstractToStringGenerator.java


示例9: constructCUContent

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的package包/类
/**
 * Uses the New Java file template from the code template page to generate a
 * compilation unit with the given type content.
 * 
 * @param cu The new created compilation unit
 * @param typeContent The content of the type, including signature and type
 * body.
 * @param lineDelimiter The line delimiter to be used.
 * @return String Returns the result of evaluating the new file template
 * with the given type content.
 * @throws CoreException when fetching the file comment fails or fetching the content for the
 *             new compilation unit fails
 * @since 2.1
 */
protected String constructCUContent(ICompilationUnit cu, String typeContent, String lineDelimiter) throws CoreException {
	String fileComment= getFileComment(cu, lineDelimiter);
	String typeComment= getTypeComment(cu, lineDelimiter);
	IPackageFragment pack= (IPackageFragment) cu.getParent();
	String content= CodeGeneration.getCompilationUnitContent(cu, fileComment, typeComment, typeContent, lineDelimiter);
	if (content != null) {
		ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
		parser.setProject(cu.getJavaProject());
		parser.setSource(content.toCharArray());
		CompilationUnit unit= (CompilationUnit) parser.createAST(null);
		if ((pack.isDefaultPackage() || unit.getPackage() != null) && !unit.types().isEmpty()) {
			return content;
		}
	}
	StringBuffer buf= new StringBuffer();
	if (!pack.isDefaultPackage()) {
		buf.append("package ").append(pack.getElementName()).append(';'); //$NON-NLS-1$
	}
	buf.append(lineDelimiter).append(lineDelimiter);
	if (typeComment != null) {
		buf.append(typeComment).append(lineDelimiter);
	}
	buf.append(typeContent);
	return buf.toString();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:40,代码来源:NewTypeWizardPage.java


示例10: getTypeComment

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的package包/类
/**
 * Hook method that gets called from <code>createType</code> to retrieve
 * a type comment. This default implementation returns the content of the
 * 'type comment' template.
 *
 * @param parentCU the parent compilation unit
 * @param lineDelimiter the line delimiter to use
 * @return the type comment or <code>null</code> if a type comment
 * is not desired
    *
    * @since 3.0
 */
protected String getTypeComment(ICompilationUnit parentCU, String lineDelimiter) {
	if (isAddComments()) {
		try {
			StringBuffer typeName= new StringBuffer();
			if (isEnclosingTypeSelected()) {
				typeName.append(getEnclosingType().getTypeQualifiedName('.')).append('.');
			}
			typeName.append(getTypeNameWithoutParameters());
			String[] typeParamNames= new String[0];
			String comment= CodeGeneration.getTypeComment(parentCU, typeName.toString(), typeParamNames, lineDelimiter);
			if (comment != null && isValidComment(comment)) {
				return comment;
			}
		} catch (CoreException e) {
			JavaPlugin.log(e);
		}
	}
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:32,代码来源:NewTypeWizardPage.java


示例11: createMethodTags

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的package包/类
private String createMethodTags(IDocument document, DocumentCommand command, String indentation, String lineDelimiter, IMethod method)
	throws CoreException, BadLocationException
{
	IRegion partition= TextUtilities.getPartition(document, fPartitioning, command.offset, false);
	IMethod inheritedMethod= getInheritedMethod(method);
	String comment= CodeGeneration.getMethodComment(method, inheritedMethod, lineDelimiter);
	if (comment != null) {
		comment= comment.trim();
		boolean javadocComment= comment.startsWith("/**"); //$NON-NLS-1$
		if (!isFirstComment(document, command, method, javadocComment))
			return null;
		boolean isJavaDoc= partition.getLength() >= 3 && document.get(partition.getOffset(), 3).equals("/**"); //$NON-NLS-1$
		if (javadocComment == isJavaDoc) {
			return prepareTemplateComment(comment, indentation, method.getJavaProject(), lineDelimiter);
		}
	}
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:JavaDocAutoIndentStrategy.java


示例12: constructCUContent

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的package包/类
/**
 * Uses the New Java file template from the code template page to generate a compilation unit with the given type content.
 * 
 * @param cu
 *           The new created compilation unit
 * @param typeContent
 *           The content of the type, including signature and type body.
 * @param lineDelimiter
 *           The line delimiter to be used.
 * @return String Returns the result of evaluating the new file template with the given type content.
 * @throws CoreException
 */
private String constructCUContent(IProgressMonitor monitor, ICompilationUnit cu, String typeContent) throws CoreException {

   StringBuffer typeQualifiedName = new StringBuffer();
   typeQualifiedName.append(fMemberName);
   final String typeComment = getTypeComment();

   try {
      monitor.beginTask("", 2); //$NON-NLS-1$
      final String content = CodeGeneration.getCompilationUnitContent(cu, typeComment, typeContent, EOL);
      cu.getBuffer().setContents(content);
   } finally {
      monitor.done();
   }
   return cu.getSource();

}
 
开发者ID:patternbox,项目名称:patternbox-eclipse,代码行数:29,代码来源:MemberCodeGenerator.java


示例13: createConstantDeclaration

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的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


示例14: createCuContent

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的package包/类
private String createCuContent(ICompilationUnit cu, String typeContent) throws CoreException {
  String fileComment = getFileComment(cu);
  String typeComment = getTypeComment(cu);
  IPackageFragment cuPckg = (IPackageFragment) cu.getParent();

  // Use the 'New Java File' code template specified by workspace preferences
  String content = CodeGeneration.getCompilationUnitContent(cu, fileComment, typeComment, typeContent, lineDelimiter);
  if (content != null) {
    // Parse the generated source to make sure it's error-free
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setProject(cu.getJavaProject());
    parser.setSource(content.toCharArray());
    CompilationUnit unit = (CompilationUnit) parser.createAST(null);
    if ((cuPckg.isDefaultPackage() || unit.getPackage() != null) && !unit.types().isEmpty()) {
      return content;
    }
  }

  // If we didn't have a template to use, just generate the source by hand
  StringBuffer buf = new StringBuffer();
  if (!cuPckg.isDefaultPackage()) {
    buf.append("package ").append(cuPckg.getElementName()).append(';');
  }
  buf.append(lineDelimiter).append(lineDelimiter);
  if (typeComment != null) {
    buf.append(typeComment).append(lineDelimiter);
  }
  buf.append(typeContent);
  return buf.toString();
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:31,代码来源:TypeCreator.java


示例15: createTypeStub

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的package包/类
private String createTypeStub(ICompilationUnit cu, ImportRewrite imports) throws CoreException {
  StringBuffer buffer = new StringBuffer();

  // Default modifiers is just: public
  buffer.append("public ");

  String type = "";
  String templateID = "";
  switch (elementType) {
  case CLASS:
    type = "class ";
    templateID = CodeGeneration.CLASS_BODY_TEMPLATE_ID;
    break;
  case INTERFACE:
    type = "interface ";
    templateID = CodeGeneration.INTERFACE_BODY_TEMPLATE_ID;
    break;
  }
  buffer.append(type);
  buffer.append(simpleTypeName);

  addInterfaces(buffer, imports);

  buffer.append(" {").append(lineDelimiter);

  // Generate the type body according to the template in preferences
  String typeBody = CodeGeneration.getTypeBody(templateID, cu, simpleTypeName, lineDelimiter);
  if (typeBody != null) {
    buffer.append(typeBody);
  } else {
    buffer.append(lineDelimiter);
  }

  buffer.append('}').append(lineDelimiter);
  return buffer.toString();
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:37,代码来源:TypeCreator.java


示例16: getTypeComment

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的package包/类
private String getTypeComment(ICompilationUnit cu) {
  if (addComments) {
    try {
      String comment = CodeGeneration.getTypeComment(cu, simpleTypeName, new String[0], lineDelimiter);
      if (comment != null && isValidComment(comment)) {
        return comment;
      }
    } catch (CoreException e) {
      CorePluginLog.logError(e);
    }
  }
  return null;
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:14,代码来源:TypeCreator.java


示例17: createConstructor

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的package包/类
private void createConstructor(final AbstractTypeDeclaration declaration, final ASTRewrite rewrite) throws CoreException {
	Assert.isNotNull(declaration);
	Assert.isNotNull(rewrite);
	final AST ast= declaration.getAST();
	final MethodDeclaration constructor= ast.newMethodDeclaration();
	constructor.setConstructor(true);
	constructor.setName(ast.newSimpleName(declaration.getName().getIdentifier()));
	final String comment= CodeGeneration.getMethodComment(fType.getCompilationUnit(), fType.getElementName(), fType.getElementName(), getNewConstructorParameterNames(), new String[0], null, null, StubUtility.getLineDelimiterUsed(fType.getJavaProject()));
	if (comment != null && comment.length() > 0) {
		final Javadoc doc= (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
		constructor.setJavadoc(doc);
	}
	if (fCreateInstanceField) {
		final SingleVariableDeclaration variable= ast.newSingleVariableDeclaration();
		final String name= getNameForEnclosingInstanceConstructorParameter();
		variable.setName(ast.newSimpleName(name));
		variable.setType(createEnclosingType(ast));
		constructor.parameters().add(variable);
		final Block body= ast.newBlock();
		final Assignment assignment= ast.newAssignment();
		if (fCodeGenerationSettings.useKeywordThis || fEnclosingInstanceFieldName.equals(fNameForEnclosingInstanceConstructorParameter)) {
			final FieldAccess access= ast.newFieldAccess();
			access.setExpression(ast.newThisExpression());
			access.setName(ast.newSimpleName(fEnclosingInstanceFieldName));
			assignment.setLeftHandSide(access);
		} else
			assignment.setLeftHandSide(ast.newSimpleName(fEnclosingInstanceFieldName));
		assignment.setRightHandSide(ast.newSimpleName(name));
		final Statement statement= ast.newExpressionStatement(assignment);
		body.statements().add(statement);
		constructor.setBody(body);
	} else
		constructor.setBody(ast.newBlock());
	rewrite.getListRewrite(declaration, declaration.getBodyDeclarationsProperty()).insertFirst(constructor, null);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:36,代码来源:MoveInnerToTopRefactoring.java


示例18: createSourceForNewCu

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的package包/类
private String createSourceForNewCu(final ICompilationUnit unit, final IProgressMonitor monitor) throws CoreException {
	Assert.isNotNull(unit);
	Assert.isNotNull(monitor);
	try {
		monitor.beginTask("", 2); //$NON-NLS-1$
		final String separator= StubUtility.getLineDelimiterUsed(fType.getJavaProject());
		final String block= getAlignedSourceBlock(unit, fNewSourceOfInputType);
		String fileComment= null;
		if (StubUtility.doAddComments(unit.getJavaProject()))
			fileComment= CodeGeneration.getFileComment(unit, separator);
		String content= CodeGeneration.getCompilationUnitContent(unit, fileComment, null, block, separator);
		if (content == null) {
			final StringBuffer buffer= new StringBuffer();
			if (!fType.getPackageFragment().isDefaultPackage()) {
				buffer.append("package ").append(fType.getPackageFragment().getElementName()).append(';'); //$NON-NLS-1$
			}
			buffer.append(separator).append(separator);
			buffer.append(block);
			content= buffer.toString();
		}
		unit.getBuffer().setContents(content);
		addImportsToTargetUnit(unit, new SubProgressMonitor(monitor, 1));
	} finally {
		monitor.done();
	}
	return unit.getSource();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:28,代码来源:MoveInnerToTopRefactoring.java


示例19: createGetter

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的package包/类
private MethodDeclaration createGetter(ParameterInfo pi, String declaringType, CompilationUnitRewrite cuRewrite) throws CoreException {
	AST ast= cuRewrite.getAST();
	ICompilationUnit cu= cuRewrite.getCu();
	IJavaProject project= cu.getJavaProject();

	MethodDeclaration methodDeclaration= ast.newMethodDeclaration();
	String fieldName= pi.getNewName();
	String getterName= getGetterName(pi, ast, project);
	String lineDelim= StubUtility.getLineDelimiterUsed(cu);
	String bareFieldname= NamingConventions.getBaseName(NamingConventions.VK_INSTANCE_FIELD, fieldName, project);
	if (createComments(project)) {
		String comment= CodeGeneration.getGetterComment(cu, declaringType, getterName, fieldName, pi.getNewTypeName(), bareFieldname, lineDelim);
		if (comment != null)
			methodDeclaration.setJavadoc((Javadoc) cuRewrite.getASTRewrite().createStringPlaceholder(comment, ASTNode.JAVADOC));
	}
	methodDeclaration.setName(ast.newSimpleName(getterName));
	methodDeclaration.setReturnType2(importBinding(pi.getNewTypeBinding(), cuRewrite));
	methodDeclaration.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
	Block block= ast.newBlock();
	methodDeclaration.setBody(block);
	boolean useThis= StubUtility.useThisForFieldAccess(project);
	if (useThis) {
		fieldName= "this." + fieldName; //$NON-NLS-1$
	}
	String bodyContent= CodeGeneration.getGetterMethodBodyContent(cu, declaringType, getterName, fieldName, lineDelim);
	ASTNode getterBody= cuRewrite.getASTRewrite().createStringPlaceholder(bodyContent, ASTNode.EXPRESSION_STATEMENT);
	block.statements().add(getterBody);
	return methodDeclaration;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:30,代码来源:ParameterObjectFactory.java


示例20: createSetter

import org.eclipse.jdt.ui.CodeGeneration; //导入依赖的package包/类
private MethodDeclaration createSetter(ParameterInfo pi, String declaringType, CompilationUnitRewrite cuRewrite) throws CoreException {
	AST ast= cuRewrite.getAST();
	ICompilationUnit cu= cuRewrite.getCu();
	IJavaProject project= cu.getJavaProject();

	MethodDeclaration methodDeclaration= ast.newMethodDeclaration();
	String fieldName= pi.getNewName();
	String setterName= getSetterName(pi, ast, project);
	String lineDelim= StubUtility.getLineDelimiterUsed(cu);
	String bareFieldname= NamingConventions.getBaseName(NamingConventions.VK_INSTANCE_FIELD, fieldName, project);
	String paramName= StubUtility.suggestArgumentName(project, bareFieldname, null);
	if (createComments(project)) {
		String comment= CodeGeneration.getSetterComment(cu, declaringType, setterName, fieldName, pi.getNewTypeName(), paramName, bareFieldname, lineDelim);
		if (comment != null)
			methodDeclaration.setJavadoc((Javadoc) cuRewrite.getASTRewrite().createStringPlaceholder(comment, ASTNode.JAVADOC));
	}
	methodDeclaration.setName(ast.newSimpleName(setterName));
	methodDeclaration.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
	SingleVariableDeclaration variable= ast.newSingleVariableDeclaration();
	variable.setType(importBinding(pi.getNewTypeBinding(), cuRewrite));
	variable.setName(ast.newSimpleName(paramName));
	methodDeclaration.parameters().add(variable);
	Block block= ast.newBlock();
	methodDeclaration.setBody(block);
	boolean useThis= StubUtility.useThisForFieldAccess(project);
	if (useThis || fieldName.equals(paramName)) {
		fieldName= "this." + fieldName; //$NON-NLS-1$
	}
	String bodyContent= CodeGeneration.getSetterMethodBodyContent(cu, declaringType, setterName, fieldName, paramName, lineDelim);
	ASTNode setterBody= cuRewrite.getASTRewrite().createStringPlaceholder(bodyContent, ASTNode.EXPRESSION_STATEMENT);
	block.statements().add(setterBody);
	return methodDeclaration;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:34,代码来源:ParameterObjectFactory.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CombinedInvWrapper类代码示例发布时间:2022-05-22
下一篇:
Java XMLParser类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap