Java Code Examples for org.eclipse.jdt.core.dom.AbstractTypeDeclaration#setName()

The following examples show how to use org.eclipse.jdt.core.dom.AbstractTypeDeclaration#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NewCUProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private TextEdit constructEnclosingTypeEdit(ICompilationUnit icu) throws CoreException {
	ASTParser astParser = ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
	astParser.setSource(icu);
	CompilationUnit cu = (CompilationUnit) astParser.createAST(null);
	TypeDeclaration enclosingDecl = findEnclosingTypeDeclaration(cu, fTypeContainer.getElementName());
	AST ast = cu.getAST();
	ASTRewrite rewrite = ASTRewrite.create(ast);
	final AbstractTypeDeclaration newDeclaration;
	switch (fTypeKind) {
		case K_CLASS:
			newDeclaration = ast.newTypeDeclaration();
			((TypeDeclaration) newDeclaration).setInterface(false);
			break;
		case K_INTERFACE:
			newDeclaration = ast.newTypeDeclaration();
			((TypeDeclaration) newDeclaration).setInterface(true);
			break;
		case K_ENUM:
			newDeclaration = ast.newEnumDeclaration();
			break;
		case K_ANNOTATION:
			newDeclaration = ast.newAnnotationTypeDeclaration();
			break;
		default:
			return null;
	}
	newDeclaration.setJavadoc(null);
	newDeclaration.setName(ast.newSimpleName(ASTNodes.getSimpleNameIdentifier(fNode)));
	newDeclaration.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
	if (isParameterizedType(fTypeKind, fNode)) {
		addTypeParameters((TypeDeclaration) newDeclaration);
	}

	ListRewrite lrw = rewrite.getListRewrite(enclosingDecl, TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
	lrw.insertLast(newDeclaration, null);
	return rewrite.rewriteAST();
}
 
Example 2
Source File: CreateTypeOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected SimpleName rename(ASTNode node, SimpleName newName) {
	AbstractTypeDeclaration type = (AbstractTypeDeclaration) node;
	SimpleName oldName = type.getName();
	type.setName(newName);
	return oldName;
}