Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2008 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.jdt.internal.core;
 

This operation creates a initializer in a type.

Required Attributes:

  • Containing Type
  • The source code for the initializer. No verification of the source is performed.
 
The current number of initializers in the parent type. Used to retrieve the handle of the newly created initializer.
 
 	protected int numberOfInitializers= 1;
When executed, this operation will create an initializer with the given name in the given type with the specified source.

By default the new initializer is positioned after the last existing initializer declaration, or as the first member in the type if there are no initializers.

 
 public CreateInitializerOperation(IType parentElementString source) {
 	super(parentElementsourcefalse);
 }
 	ASTNode node = super.generateElementAST(rewritercu);
 	if (node.getNodeType() != .)
 	return node;
 }
 
 	try {
 		//update the children to be current
 		if (this. == null) {
 		} else {
 			IJavaElement[] children = getType().getChildren();
 			int count = 0;
 			for (int i = 0; i < children.lengthi++) {
 				IJavaElement child = children[i];
 				if (child.equals(this.)) {
 						count++;
 					}
 					return getType().getInitializer(count);
 				} else
 					if (child.getElementType() == .) {
 						count++;
 					}
 			}
 		}
 	} catch (JavaModelException e) {
 		// type doesn't exist: ignore
 	}
 	return null;
 }
 
 }
 protected SimpleName rename(ASTNode nodeSimpleName newName) {
 	return null// intializer cannot be renamed
 }
By default the new initializer is positioned after the last existing initializer declaration, or as the first member in the type if there are no initializers.
 
 protected void initializeDefaultPosition() {
	IType parentElement = getType();
	try {
		IJavaElement[] elements = parentElement.getInitializers();
		if (elements != null && elements.length > 0) {
			this. = elements.length;
			createAfter(elements[elements.length - 1]);
else {
			elements = parentElement.getChildren();
			if (elements != null && elements.length > 0) {
				createBefore(elements[0]);
			}
		}
catch (JavaModelException e) {
		// type doesn't exist: ignore
	}
New to GrepCode? Check out our FAQ X