Java Code Examples for org.eclipse.jdt.core.IType#isAnonymous()

The following examples show how to use org.eclipse.jdt.core.IType#isAnonymous() . 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: RefactoringAvailabilityTester.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static boolean isRenameAvailable(final IType type) throws JavaModelException {
	if (type == null) {
		return false;
	}
	if (type.isAnonymous()) {
		return false;
	}
	if (type.isLambda()) {
		return false;
	}
	if (!Checks.isAvailable(type)) {
		return false;
	}
	if (isRenameProhibited(type)) {
		return false;
	}
	return true;
}
 
Example 2
Source File: CallHierarchyContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets the default "expand with constructors" mode for the method wrapper. Does nothing if the
 * mode has already been set.
 * 
 * 
 * @param wrapper the caller method wrapper
 * @since 3.5
 */
static void ensureDefaultExpandWithConstructors(CallerMethodWrapper wrapper) {

	if (!wrapper.isExpandWithConstructorsSet()) {
		if (CallHierarchyContentProvider.canExpandWithConstructors(wrapper)) {
			IMethod method= (IMethod)wrapper.getMember();
			IType type= method.getDeclaringType();
			try {
				boolean withConstructors= false;
				if (type != null) {
					boolean anonymousPref= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS);
					if (anonymousPref && type.isAnonymous()) {
						withConstructors= true;
					} else if (isInTheDefaultExpandWithConstructorList(method)) {
						withConstructors= true;
					}
				}
				wrapper.setExpandWithConstructors(withConstructors);
			} catch (JavaModelException e) {
				// ignore: expand mode will be off
			}
		}
	}

}
 
Example 3
Source File: SourceCreationOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Runs the stub generation on the specified class file.
 *
 * @param file
 *            the class file
 * @param parent
 *            the parent store
 * @param monitor
 *            the progress monitor to use
 * @throws CoreException
 *             if an error occurs
 */
@Override
protected void run(final IClassFile file, final IFileStore parent, final IProgressMonitor monitor) throws CoreException {
	try {
		monitor.beginTask(getOperationLabel(), 2);
		final IType type= file.getType();
		if (type.isAnonymous() || type.isLocal() || type.isMember())
			return;
		final String source= file.getSource();
		createCompilationUnit(parent, type.getElementName() + JavaModelUtil.DEFAULT_CU_SUFFIX, source != null ? source : "", monitor); //$NON-NLS-1$
	} finally {
		monitor.done();
	}
}
 
Example 4
Source File: ASTNodeSearchUtil.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static List<BodyDeclaration> getBodyDeclarationList(IType iType, CompilationUnit cuNode) throws JavaModelException {
	if (iType.isAnonymous()) {
		return getClassInstanceCreationNode(iType, cuNode).getAnonymousClassDeclaration().bodyDeclarations();
	} else {
		return getAbstractTypeDeclarationNode(iType, cuNode).bodyDeclarations();
	}
}
 
Example 5
Source File: AddUnimplementedConstructorsAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean canEnable(IStructuredSelection selection) throws JavaModelException {
	if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) {
		IType type= (IType) selection.getFirstElement();
		return type.getCompilationUnit() != null && !type.isInterface() && !type.isEnum() && !type.isAnonymous();
	}

	if ((selection.size() == 1) && (selection.getFirstElement() instanceof ICompilationUnit))
		return true;

	return false;
}
 
Example 6
Source File: ConvertAnonymousToNestedAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IType getElement(IStructuredSelection selection) {
	if (selection.size() != 1)
		return null;
	Object element= selection.getFirstElement();
	if (!(element instanceof IType))
		return null;
	IType type= (IType)element;
	try {
		if (type.isAnonymous())
			return type;
	} catch (JavaModelException e) {
		// fall through
	}
	return null;
}
 
Example 7
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean hasAnonymousClassDeclarations(IJavaElement[] javaElements) throws JavaModelException {
	for (int i= 0; i < javaElements.length; i++) {
		if (javaElements[i] instanceof IType) {
			IType type= (IType) javaElements[i];
			if (type.isAnonymous())
				return true;
		}
	}
	return false;
}
 
Example 8
Source File: RenameEnumConstProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected RenameJavaElementDescriptor createRefactoringDescriptor() {
	final IField field= getField();
	String project= null;
	IJavaProject javaProject= field.getJavaProject();
	if (javaProject != null)
		project= javaProject.getElementName();
	int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE;
	final IType declaring= field.getDeclaringType();
	try {
		if (!Flags.isPrivate(declaring.getFlags()))
			flags|= RefactoringDescriptor.MULTI_CHANGE;
		if (declaring.isAnonymous() || declaring.isLocal())
			flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
	} catch (JavaModelException exception) {
		JavaPlugin.log(exception);
	}
	final String description= Messages.format(RefactoringCoreMessages.RenameEnumConstProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fField.getElementName()));
	final String header= Messages.format(RefactoringCoreMessages.RenameEnumConstProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(field.getElementName()), JavaElementLabels.getElementLabel(field.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(getNewElementName())});
	final String comment= new JDTRefactoringDescriptorComment(project, this, header).asString();
	final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_ENUM_CONSTANT);
	descriptor.setProject(project);
	descriptor.setDescription(description);
	descriptor.setComment(comment);
	descriptor.setFlags(flags);
	descriptor.setJavaElement(field);
	descriptor.setNewName(getNewElementName());
	descriptor.setUpdateReferences(fUpdateReferences);
	descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
	return descriptor;
}
 
Example 9
Source File: MoveStaticMembersProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private MoveStaticMembersDescriptor createDescriptor() {
	final IMember[] members= getMembersToMove();
	String project= null;
	final IJavaProject javaProject= getDeclaringType().getJavaProject();
	if (javaProject != null)
		project= javaProject.getElementName();
	String header= null;
	if (members.length == 1)
		header= Messages.format(RefactoringCoreMessages.MoveStaticMembersProcessor_descriptor_description_single, new String[] { JavaElementLabels.getElementLabel(members[0], JavaElementLabels.ALL_FULLY_QUALIFIED), getQualifiedTypeLabel(fDestinationType) });
	else
		header= Messages.format(RefactoringCoreMessages.MoveStaticMembersProcessor_descriptor_description_multi, new String[] { String.valueOf(members.length), getQualifiedTypeLabel(fDestinationType) });
	int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
	final IType declaring= members[0].getDeclaringType();
	try {
		if (declaring.isLocal() || declaring.isAnonymous())
			flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
	} catch (JavaModelException exception) {
		JavaPlugin.log(exception);
	}
	final String description= members.length == 1 ? Messages.format(RefactoringCoreMessages.MoveStaticMembersProcessor_description_descriptor_short_multi, BasicElementLabels.getJavaElementName(members[0].getElementName())) : RefactoringCoreMessages.MoveMembersRefactoring_move_members;
	final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
	comment.addSetting(Messages.format(RefactoringCoreMessages.MoveStaticMembersProcessor_target_element_pattern, getQualifiedTypeLabel(fDestinationType)));
	final MoveStaticMembersDescriptor descriptor= RefactoringSignatureDescriptorFactory.createMoveStaticMembersDescriptor();
	descriptor.setProject(project);
	descriptor.setDescription(description);
	descriptor.setComment(comment.asString());
	descriptor.setFlags(flags);
	descriptor.setDestinationType(fDestinationType);
	descriptor.setKeepOriginal(fDelegateUpdating);
	descriptor.setDeprecateDelegate(fDelegateDeprecation);
	descriptor.setMembers(members);
	return descriptor;
}
 
Example 10
Source File: TypeSearchRequestor.java    From JDeodorant with MIT License 5 votes vote down vote up
public void acceptSearchMatch(SearchMatch match) throws CoreException {
	Object element = match.getElement();
	if (match.getElement() instanceof IType) {
		IType iType = (IType)element;
		if(!iType.isAnonymous()) {
			subTypes.add(iType);
		}
	}
}
 
Example 11
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isRenameAvailable(final IType type) throws JavaModelException {
	if (type == null)
		return false;
	if (type.isAnonymous())
		return false;
	if (type.isLambda())
		return false;
	if (!Checks.isAvailable(type))
		return false;
	if (isRenameProhibited(type))
		return false;
	return true;
}
 
Example 12
Source File: IntroduceIndirectionRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ITypeBinding typeToBinding(IType type, CompilationUnit root) throws JavaModelException {
	ASTNode typeNode= typeToDeclaration(type, root);
	if (type.isAnonymous()) {
		return ((AnonymousClassDeclaration) typeNode).resolveBinding();
	} else {
		return ((AbstractTypeDeclaration) typeNode).resolveBinding();
	}
}
 
Example 13
Source File: GenerateNewConstructorUsingFieldsAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IField[] getSelectedFields(IStructuredSelection selection) {
	List<?> elements= selection.toList();
	if (elements.size() > 0) {
		IField[] fields= new IField[elements.size()];
		ICompilationUnit unit= null;
		for (int index= 0; index < elements.size(); index++) {
			if (elements.get(index) instanceof IField) {
				IField field= (IField) elements.get(index);
				if (index == 0) {
					// remember the CU of the first element
					unit= field.getCompilationUnit();
					if (unit == null) {
						return null;
					}
				} else if (!unit.equals(field.getCompilationUnit())) {
					// all fields must be in the same CU
					return null;
				}
				try {
					final IType declaringType= field.getDeclaringType();
					if (declaringType.isInterface() || declaringType.isAnnotation() || declaringType.isAnonymous())
						return null;
				} catch (JavaModelException exception) {
					JavaPlugin.log(exception);
					return null;
				}
				fields[index]= field;
			} else {
				return null;
			}
		}
		return fields;
	}
	return null;
}
 
Example 14
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isExtractInterfaceAvailable(final IType type) throws JavaModelException {
	return Checks.isAvailable(type) && !type.isBinary() && !type.isReadOnly() && !type.isAnnotation() && !type.isAnonymous() && !type.isLambda();
}
 
Example 15
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public final Change createChange(final IProgressMonitor monitor) throws CoreException, OperationCanceledException {
	Assert.isNotNull(monitor);
	try {
		monitor.beginTask("", 6); //$NON-NLS-1$
		monitor.setTaskName(RefactoringCoreMessages.MoveInstanceMethodProcessor_creating);
		final TextChange[] changes= fChangeManager.getAllChanges();
		if (changes.length == 1)
			return changes[0];
		final List<TextChange> list= new ArrayList<TextChange>(changes.length);
		list.addAll(Arrays.asList(changes));
		final Map<String, String> arguments= new HashMap<String, String>();
		String project= null;
		final IJavaProject javaProject= fMethod.getJavaProject();
		if (javaProject != null)
			project= javaProject.getElementName();
		int flags= JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
		final IType declaring= fMethod.getDeclaringType();
		try {
			if (declaring.isAnonymous() || declaring.isLocal())
				flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
		} catch (JavaModelException exception) {
			JavaPlugin.log(exception);
		}
		final String description= Messages.format(RefactoringCoreMessages.MoveInstanceMethodProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fMethod.getElementName()));
		final String header= Messages.format(RefactoringCoreMessages.MoveInstanceMethodProcessor_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fMethod, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(fTarget, JavaElementLabels.ALL_FULLY_QUALIFIED) });
		final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
		comment.addSetting(Messages.format(RefactoringCoreMessages.MoveInstanceMethodProcessor_moved_element_pattern, RefactoringCoreMessages.JavaRefactoringDescriptor_not_available));
		comment.addSetting(Messages.format(RefactoringCoreMessages.MoveInstanceMethodProcessor_target_element_pattern, BindingLabelProvider.getBindingLabel(fTarget, JavaElementLabels.ALL_FULLY_QUALIFIED)));
		comment.addSetting(Messages.format(RefactoringCoreMessages.MoveInstanceMethodProcessor_method_name_pattern, BasicElementLabels.getJavaElementName(getMethodName())));
		if (needsTargetNode())
			comment.addSetting(Messages.format(RefactoringCoreMessages.MoveInstanceMethodProcessor_parameter_name_pattern, BasicElementLabels.getJavaElementName(getTargetName())));
		final MoveMethodDescriptor descriptor= RefactoringSignatureDescriptorFactory.createMoveMethodDescriptor(project, description, comment.asString(), arguments, flags);
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fMethod));
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fMethodName);
		arguments.put(ATTRIBUTE_TARGET_NAME, fTargetName);
		arguments.put(ATTRIBUTE_DEPRECATE, Boolean.valueOf(fDelegateDeprecation).toString());
		arguments.put(ATTRIBUTE_REMOVE, Boolean.valueOf(fRemove).toString());
		arguments.put(ATTRIBUTE_INLINE, Boolean.valueOf(fInline).toString());
		arguments.put(ATTRIBUTE_USE_GETTER, Boolean.valueOf(fUseGetters).toString());
		arguments.put(ATTRIBUTE_USE_SETTER, Boolean.valueOf(fUseSetters).toString());
		arguments.put(ATTRIBUTE_TARGET_INDEX, new Integer(getTargetIndex()).toString());
		return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.MoveInstanceMethodRefactoring_name, list.toArray(new Change[list.size()]));
	} finally {
		monitor.done();
	}
}
 
Example 16
Source File: PullUpRefactoringProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Change createChange(final IProgressMonitor monitor) throws CoreException, OperationCanceledException {
	try {
		final Map<String, String> arguments= new HashMap<String, String>();
		String project= null;
		final IType declaring= getDeclaringType();
		final IJavaProject javaProject= declaring.getJavaProject();
		if (javaProject != null)
			project= javaProject.getElementName();
		int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
		try {
			if (declaring.isLocal() || declaring.isAnonymous())
				flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
		} catch (JavaModelException exception) {
			JavaPlugin.log(exception);
		}
		final String description= fMembersToMove.length == 1 ? Messages.format(RefactoringCoreMessages.PullUpRefactoring_descriptor_description_short, new String[] { JavaElementLabels.getElementLabel(fMembersToMove[0], JavaElementLabels.ALL_DEFAULT), JavaElementLabels.getElementLabel(fDestinationType, JavaElementLabels.ALL_DEFAULT)}) : Messages.format(RefactoringCoreMessages.PullUpRefactoring_descriptor_description_short_multiple, BasicElementLabels.getJavaElementName(fDestinationType.getElementName()));
		final String header= fMembersToMove.length == 1 ? Messages.format(RefactoringCoreMessages.PullUpRefactoring_descriptor_description_full, new String[] { JavaElementLabels.getElementLabel(fMembersToMove[0], JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(fDestinationType, JavaElementLabels.ALL_FULLY_QUALIFIED)}) : Messages.format(RefactoringCoreMessages.PullUpRefactoring_descriptor_description, new String[] { JavaElementLabels.getElementLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(fDestinationType, JavaElementLabels.ALL_FULLY_QUALIFIED)});
		final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
		comment.addSetting(Messages.format(RefactoringCoreMessages.MoveStaticMembersProcessor_target_element_pattern, JavaElementLabels.getElementLabel(fDestinationType, JavaElementLabels.ALL_FULLY_QUALIFIED)));
		addSuperTypeSettings(comment, true);
		final PullUpDescriptor descriptor= RefactoringSignatureDescriptorFactory.createPullUpDescriptor(project, description, comment.asString(), arguments, flags);
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fDestinationType));
		arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(fReplace).toString());
		arguments.put(ATTRIBUTE_INSTANCEOF, Boolean.valueOf(fInstanceOf).toString());
		arguments.put(ATTRIBUTE_STUBS, Boolean.valueOf(fCreateMethodStubs).toString());
		arguments.put(ATTRIBUTE_PULL, new Integer(fMembersToMove.length).toString());
		for (int offset= 0; offset < fMembersToMove.length; offset++)
			arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fMembersToMove[offset]));
		arguments.put(ATTRIBUTE_DELETE, new Integer(fDeletedMethods.length).toString());
		for (int offset= 0; offset < fDeletedMethods.length; offset++)
			arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + fMembersToMove.length + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fDeletedMethods[offset]));
		arguments.put(ATTRIBUTE_ABSTRACT, new Integer(fAbstractMethods.length).toString());
		for (int offset= 0; offset < fAbstractMethods.length; offset++)
			arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + fMembersToMove.length + fDeletedMethods.length + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fAbstractMethods[offset]));
		return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.PullUpRefactoring_Pull_Up, fChangeManager.getAllChanges());
	} finally {
		monitor.done();
		clearCaches();
	}
}
 
Example 17
Source File: ExtractSupertypeProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Change createChange(final IProgressMonitor monitor) throws CoreException, OperationCanceledException {
	try {
		final Map<String, String> arguments= new HashMap<String, String>();
		String project= null;
		final IType declaring= getDeclaringType();
		final IJavaProject javaProject= declaring.getJavaProject();
		if (javaProject != null)
			project= javaProject.getElementName();
		int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
		try {
			if (declaring.isLocal() || declaring.isAnonymous())
				flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
		} catch (JavaModelException exception) {
			JavaPlugin.log(exception);
		}
		final String description= Messages.format(RefactoringCoreMessages.ExtractSupertypeProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fTypeName));
		final String header= Messages.format(RefactoringCoreMessages.ExtractSupertypeProcessor_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fDestinationType, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(fCachedDeclaringType, JavaElementLabels.ALL_FULLY_QUALIFIED)});
		final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
		final IType[] types= getTypesToExtract();
		String[] settings= new String[types.length];
		for (int index= 0; index < settings.length; index++)
			settings[index]= JavaElementLabels.getElementLabel(types[index], JavaElementLabels.ALL_FULLY_QUALIFIED);
		comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ExtractSupertypeProcessor_subtypes_pattern, settings));
		comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractSupertypeProcessor_refactored_element_pattern, JavaElementLabels.getElementLabel(fDestinationType, JavaElementLabels.ALL_FULLY_QUALIFIED)));
		settings= new String[fMembersToMove.length];
		for (int index= 0; index < settings.length; index++)
			settings[index]= JavaElementLabels.getElementLabel(fMembersToMove[index], JavaElementLabels.ALL_FULLY_QUALIFIED);
		comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ExtractInterfaceProcessor_extracted_members_pattern, settings));
		addSuperTypeSettings(comment, true);
		final ExtractSuperclassDescriptor descriptor= RefactoringSignatureDescriptorFactory.createExtractSuperclassDescriptor(project, description, comment.asString(), arguments, flags);
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fTypeName);
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, getDeclaringType()));
		arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(fReplace).toString());
		arguments.put(ATTRIBUTE_INSTANCEOF, Boolean.valueOf(fInstanceOf).toString());
		arguments.put(ATTRIBUTE_STUBS, Boolean.valueOf(fCreateMethodStubs).toString());
		arguments.put(ATTRIBUTE_EXTRACT, new Integer(fMembersToMove.length).toString());
		for (int offset= 0; offset < fMembersToMove.length; offset++)
			arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fMembersToMove[offset]));
		arguments.put(ATTRIBUTE_DELETE, new Integer(fDeletedMethods.length).toString());
		for (int offset= 0; offset < fDeletedMethods.length; offset++)
			arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + fMembersToMove.length + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fDeletedMethods[offset]));
		arguments.put(ATTRIBUTE_ABSTRACT, new Integer(fAbstractMethods.length).toString());
		for (int offset= 0; offset < fAbstractMethods.length; offset++)
			arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + fMembersToMove.length + fDeletedMethods.length + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fAbstractMethods[offset]));
		arguments.put(ATTRIBUTE_TYPES, new Integer(fTypesToExtract.length).toString());
		for (int offset= 0; offset < fTypesToExtract.length; offset++)
			arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + fMembersToMove.length + fDeletedMethods.length + fAbstractMethods.length + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fTypesToExtract[offset]));
		final DynamicValidationRefactoringChange change= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.ExtractSupertypeProcessor_extract_supertype, fChangeManager.getAllChanges());
		final IFile file= ResourceUtil.getFile(declaring.getCompilationUnit());
		if (fSuperSource != null && fSuperSource.length() > 0)
			change.add(new CreateCompilationUnitChange(declaring.getPackageFragment().getCompilationUnit(JavaModelUtil.getRenamedCUName(declaring.getCompilationUnit(), fTypeName)), fSuperSource, file.getCharset(false)));
		return change;
	} finally {
		monitor.done();
		clearCaches();
	}
}
 
Example 18
Source File: ReorgUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private static String createNamePattern(IJavaElement element) throws JavaModelException {
	switch(element.getElementType()){
		case IJavaElement.CLASS_FILE:
			return RefactoringCoreMessages.ReorgUtils_3;
		case IJavaElement.COMPILATION_UNIT:
			return RefactoringCoreMessages.ReorgUtils_4;
		case IJavaElement.FIELD:
			return RefactoringCoreMessages.ReorgUtils_5;
		case IJavaElement.IMPORT_CONTAINER:
			return RefactoringCoreMessages.ReorgUtils_6;
		case IJavaElement.IMPORT_DECLARATION:
			return RefactoringCoreMessages.ReorgUtils_7;
		case IJavaElement.INITIALIZER:
			return RefactoringCoreMessages.ReorgUtils_8;
		case IJavaElement.JAVA_PROJECT:
			return RefactoringCoreMessages.ReorgUtils_9;
		case IJavaElement.METHOD:
			if (((IMethod)element).isConstructor()) {
				return RefactoringCoreMessages.ReorgUtils_10;
			} else {
				return RefactoringCoreMessages.ReorgUtils_11;
			}
		case IJavaElement.PACKAGE_DECLARATION:
			return RefactoringCoreMessages.ReorgUtils_12;
		case IJavaElement.PACKAGE_FRAGMENT:
			if (JavaElementUtil.isDefaultPackage(element)) {
				return RefactoringCoreMessages.ReorgUtils_13;
			} else {
				return RefactoringCoreMessages.ReorgUtils_14;
			}
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			if (((IPackageFragmentRoot) element).isArchive()) {
				return RefactoringCoreMessages.ReorgUtils_21;
			}
			if (isSourceFolder(element)) {
				return RefactoringCoreMessages.ReorgUtils_15;
			}
			if (isClassFolder(element)) {
				return RefactoringCoreMessages.ReorgUtils_16;
			}
			return RefactoringCoreMessages.ReorgUtils_17;
		case IJavaElement.TYPE:
			IType type= (IType)element;
			if (type.isAnonymous()) {
				return RefactoringCoreMessages.ReorgUtils_20;
			}
			return RefactoringCoreMessages.ReorgUtils_18;
		default:
			Assert.isTrue(false);
			return null;
	}
}
 
Example 19
Source File: SelfEncapsulateFieldRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
	final Map<String, String> arguments= new HashMap<String, String>();
	String project= null;
	IJavaProject javaProject= fField.getJavaProject();
	if (javaProject != null)
		project= javaProject.getElementName();
	int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
	final IType declaring= fField.getDeclaringType();
	try {
		if (declaring.isAnonymous() || declaring.isLocal())
			flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
	} catch (JavaModelException exception) {
		JavaPlugin.log(exception);
	}
	final String description= Messages.format(RefactoringCoreMessages.SelfEncapsulateField_descriptor_description_short, BasicElementLabels.getJavaElementName(fField.getElementName()));
	final String header= Messages.format(RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED)});
	final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
	comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_original_pattern, JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED)));
	comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_getter_pattern, BasicElementLabels.getJavaElementName(fGetterName)));
	comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_setter_pattern, BasicElementLabels.getJavaElementName(fSetterName)));
	String visibility= JdtFlags.getVisibilityString(fVisibility);
	if ("".equals(visibility)) //$NON-NLS-1$
		visibility= RefactoringCoreMessages.SelfEncapsulateField_default_visibility;
	comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_visibility_pattern, visibility));
	if (fEncapsulateDeclaringClass)
		comment.addSetting(RefactoringCoreMessages.SelfEncapsulateField_use_accessors);
	else
		comment.addSetting(RefactoringCoreMessages.SelfEncapsulateField_do_not_use_accessors);
	if (fGenerateJavadoc)
		comment.addSetting(RefactoringCoreMessages.SelfEncapsulateField_generate_comments);
	final EncapsulateFieldDescriptor descriptor= RefactoringSignatureDescriptorFactory.createEncapsulateFieldDescriptor(project, description, comment.asString(), arguments, flags);
	arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fField));
	arguments.put(ATTRIBUTE_VISIBILITY, new Integer(fVisibility).toString());
	arguments.put(ATTRIBUTE_INSERTION, new Integer(fInsertionIndex).toString());
	arguments.put(ATTRIBUTE_SETTER, fSetterName);
	arguments.put(ATTRIBUTE_GETTER, fGetterName);
	arguments.put(ATTRIBUTE_COMMENTS, Boolean.valueOf(fGenerateJavadoc).toString());
	arguments.put(ATTRIBUTE_DECLARING, Boolean.valueOf(fEncapsulateDeclaringClass).toString());
	final DynamicValidationRefactoringChange result= new DynamicValidationRefactoringChange(descriptor, getName());
	TextChange[] changes= fChangeManager.getAllChanges();
	pm.beginTask(NO_NAME, changes.length);
	pm.setTaskName(RefactoringCoreMessages.SelfEncapsulateField_create_changes);
	for (int i= 0; i < changes.length; i++) {
		result.add(changes[i]);
		pm.worked(1);
	}
	pm.done();
	return result;
}
 
Example 20
Source File: DefaultJavaFoldingStructureProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Returns <code>true</code> if <code>type</code> is an anonymous enum declaration,
 * <code>false</code> otherwise. See also https://bugs.eclipse.org/bugs/show_bug.cgi?id=143276
 *
 * @param type the type to test
 * @return <code>true</code> if <code>type</code> is an anonymous enum declaration
 * @since 3.3
 */
private boolean isAnonymousEnum(IType type) {
	try {
		return type.isEnum() && type.isAnonymous();
	} catch (JavaModelException x) {
		return false; // optimistically
	}
}