Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2009 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;
 
 import java.util.Map;
 
 import  org.eclipse.core.runtime.IStatus;
This class is used to perform operations on multiple IJavaElement. It is responible for running each operation in turn, collecting the errors and merging the corresponding JavaElementDeltas.

If several errors occured, they are collected in a multi-status JavaModelStatus. Otherwise, a simple JavaModelStatus is thrown.

 
 public abstract class MultiOperation extends JavaModelOperation {
Table specifying insertion positions for elements being copied/moved/renamed. Keyed by elements being processed, and values are the corresponding insertion point.

See also:
processElements()
 
 	protected Map insertBeforeElements = new HashMap(1);
Table specifying the new parent for elements being copied/moved/renamed. Keyed by elements being processed, and values are the corresponding destination parent.
 
 	protected Map newParents;
This table presents the data in fRenamingList in a more convenient way.
 
 	protected Map renamings;
The list of renamings supplied to the operation
 
 	protected String[] renamingsList = null;
Creates a new MultiOperation on elementsToProcess.
 
 	protected MultiOperation(IJavaElement[] elementsToProcessboolean force) {
 		super(elementsToProcessforce);
 	}
Creates a new MultiOperation.
 
 	protected MultiOperation(IJavaElement[] elementsToProcessIJavaElement[] parentElementsboolean force) {
 		super(elementsToProcessparentElementsforce);
 		this. = new HashMap(elementsToProcess.length);
 		if (elementsToProcess.length == parentElements.length) {
 			for (int i = 0; i < elementsToProcess.lengthi++) {
 				this..put(elementsToProcess[i], parentElements[i]);
 			}
 		} else { //same destination for all elements to be moved/copied/renamed
 			for (int i = 0; i < elementsToProcess.lengthi++) {
 				this..put(elementsToProcess[i], parentElements[0]);
 			}
 		}
 
 	}
Convenience method to create a JavaModelException embending a JavaModelStatus.
 
 	protected void error(int codeIJavaElement elementthrows JavaModelException {
 		throw new JavaModelException(new JavaModelStatus(codeelement));
 	}
Executes the operation.

Throws:
JavaModelException if one or several errors occured during the operation. If multiple errors occured, the corresponding JavaModelStatus is a multi-status. Otherwise, it is a simple one.
 
 	protected void executeOperation() throws JavaModelException {
 	}
Returns the parent of the element being copied/moved/renamed.
 
 		return (IJavaElement)this..get(child);
 	}
Returns the name to be used by the progress monitor.
	protected abstract String getMainTaskName();
Returns the new name for element, or null if there are no renamings specified.
	protected String getNewNameFor(IJavaElement elementthrows JavaModelException {
		String newName = null;
		if (this. != null)
			newName = (Stringthis..get(element);
		if (newName == null && element instanceof IMethod && ((IMethodelement).isConstructor())
			newName = getDestinationParent(element).getElementName();
		return newName;
	}
Sets up the renamings hashtable - keys are the elements and values are the new name.
	private void initializeRenamings() {
		if (this. != null && this..length == this..length) {
			this. = new HashMap(this..length);
			for (int i = 0; i < this..lengthi++) {
				if (this.[i] != null) {
				}
			}
		}
	}
Returns true if this operation represents a move or rename, false if this operation represents a copy.
Note: a rename is just a move within the same parent with a name change.
	protected boolean isMove() {
		return false;
	}
Returns true if this operation represents a rename, false if this operation represents a copy or move.
	protected boolean isRename() {
		return false;
	}

Subclasses must implement this method to process a given IJavaElement.
	protected abstract void processElement(IJavaElement elementthrows JavaModelException;
Processes all the IJavaElements in turn, collecting errors and updating the progress monitor.

Throws:
JavaModelException if one or several operation(s) was unable to be completed.
	protected void processElements() throws JavaModelException {
		try {
			IJavaModelStatus[] errors = new IJavaModelStatus[3];
			int errorsCounter = 0;
			for (int i = 0; i < this..lengthi++) {
				try {
catch (JavaModelException jme) {
					if (errorsCounter == errors.length) {
						// resize
						System.arraycopy(errors, 0, (errors = new IJavaModelStatus[errorsCounter*2]), 0, errorsCounter);
					}
					errors[errorsCounter++] = jme.getJavaModelStatus();
finally {
				}
			}
			if (errorsCounter == 1) {
				throw new JavaModelException(errors[0]);
else if (errorsCounter > 1) {
				if (errorsCounter != errors.length) {
					// resize
					System.arraycopy(errors, 0, (errors = new IJavaModelStatus[errorsCounter]), 0, errorsCounter);
				}
				throw new JavaModelException(JavaModelStatus.newMultiStatus(errors));
			}
finally {
		}
	}
Sets the insertion position in the new container for the modified element. The element being modified will be inserted before the specified new sibling. The given sibling must be a child of the destination container specified for the modified element. The default is null, which indicates that the element is to be inserted at the end of the container.
	public void setInsertBefore(IJavaElement modifiedElementIJavaElement newSibling) {
		this..put(modifiedElementnewSibling);
	}
Sets the new names to use for each element being copied. The renamings correspond to the elements being processed, and the number of renamings must match the number of elements being processed. A null entry in the list indicates that an element is not to be renamed.

Note that some renamings may not be used. If both a parent and a child have been selected for copy/move, only the parent is changed. Therefore, if a new name is specified for the child, the child's name will not be changed.

	public void setRenamings(String[] renamingsList) {
		this. = renamingsList;
	}
This method is called for each IJavaElement before processElement. It should check that this element can be processed.
	protected abstract void verify(IJavaElement elementthrows JavaModelException;
Verifies that the destination specified for the element is valid for the types of the element and destination.
	protected void verifyDestination(IJavaElement elementIJavaElement destinationthrows JavaModelException {
		if (destination == null || !destination.exists())
		int destType = destination.getElementType();
		switch (element.getElementType()) {
				if (destType != .)
				break;
				if (destType != . && destType != .)
				break;
				if (destType != . || destination instanceof BinaryType)
				break;
				if (destType != .)
				else {
					if (isMove() && cu.isWorkingCopy() && !cu.isPrimary())
				}
				break;
				IPackageFragment fragment = (IPackageFragmentelement;
				IJavaElement parent = fragment.getParent();
				if (parent.isReadOnly())
				else if (destType != .)
				break;
			default :
		}
	}
Verify that the new name specified for element is valid for that type of Java element.
	protected void verifyRenaming(IJavaElement elementthrows JavaModelException {
		String newName = getNewNameFor(element);
		boolean isValid = true;
	    IJavaProject project = element.getJavaProject();
	    String sourceLevel = project.getOption(.true);
	    String complianceLevel = project.getOption(.true);
		switch (element.getElementType()) {
				if (((IPackageFragmentelement).isDefaultPackage()) {
					// don't allow renaming of default package (see PR #1G47GUM)
				}
				isValid = JavaConventions.validatePackageName(newNamesourceLevelcomplianceLevel).getSeverity() != IStatus.ERROR;
				break;
				isValid = JavaConventions.validateCompilationUnitName(newName,sourceLevelcomplianceLevel).getSeverity() != IStatus.ERROR;
				break;
				isValid = false//cannot rename initializers
				break;
			default :
				isValid = JavaConventions.validateIdentifier(newNamesourceLevelcomplianceLevel).getSeverity() != IStatus.ERROR;
				break;
		}
		if (!isValid) {
		}
	}
Verifies that the positioning sibling specified for the element is exists and its parent is the destination container of this element.
	protected void verifySibling(IJavaElement elementIJavaElement destinationthrows JavaModelException {
		IJavaElement insertBeforeElement = (IJavaElementthis..get(element);
		if (insertBeforeElement != null) {
			if (!insertBeforeElement.exists() || !insertBeforeElement.getParent().equals(destination)) {
			}
		}
	}
New to GrepCode? Check out our FAQ X