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

The following examples show how to use org.eclipse.jdt.core.IType#isReadOnly() . 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: HierarchyProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected RefactoringStatus checkDeclaringType(final IProgressMonitor monitor) throws JavaModelException {
	try {
		final IType type= getDeclaringType();
		if (type.isEnum())
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.HierarchyRefactoring_enum_members);
		if (type.isAnnotation())
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.HierarchyRefactoring_annotation_members);
		if (type.isInterface())
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.HierarchyRefactoring_interface_members);
		if (type.isBinary())
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.HierarchyRefactoring_members_of_binary);
		if (type.isReadOnly())
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.HierarchyRefactoring_members_of_read_only);
		return new RefactoringStatus();
	} finally {
		if (monitor != null)
			monitor.done();
	}
}
 
Example 2
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected final void adjustTypeVisibility(final ITypeBinding binding) throws JavaModelException {
	Assert.isNotNull(binding);
	final IJavaElement element= binding.getJavaElement();
	if (element instanceof IType) {
		final IType type= (IType) element;
		if (!type.isBinary() && !type.isReadOnly() && !Flags.isPublic(type.getFlags())) {
			boolean same= false;
			final CompilationUnitRewrite rewrite= getCompilationUnitRewrite(fRewrites, type.getCompilationUnit());
			final AbstractTypeDeclaration declaration= ASTNodeSearchUtil.getAbstractTypeDeclarationNode(type, rewrite.getRoot());
			if (declaration != null) {
				final ITypeBinding declaring= declaration.resolveBinding();
				if (declaring != null && Bindings.equals(declaring.getPackage(), fTarget.getType().getPackage()))
					same= true;
				final Modifier.ModifierKeyword keyword= same ? null : Modifier.ModifierKeyword.PUBLIC_KEYWORD;
				final String modifier= same ? RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_default : RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_public;
				if (MemberVisibilityAdjustor.hasLowerVisibility(binding.getModifiers(), same ? Modifier.NONE : keyword == null ? Modifier.NONE : keyword.toFlagValue()) && MemberVisibilityAdjustor.needsVisibilityAdjustments(type, keyword, fAdjustments))
					fAdjustments.put(type, new MemberVisibilityAdjustor.OutgoingMemberVisibilityAdjustment(type, keyword, RefactoringStatus.createWarningStatus(Messages.format(RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_type_warning, new String[] { BindingLabelProvider.getBindingLabel(declaration.resolveBinding(), JavaElementLabels.ALL_FULLY_QUALIFIED), modifier }), JavaStatusContext.create(type.getCompilationUnit(), declaration))));
			}
		}
	}
}
 
Example 3
Source File: PullUpRefactoringProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public IType[] getCandidateTypes(final RefactoringStatus status, final IProgressMonitor monitor) throws JavaModelException {
	final IType declaring= getDeclaringType();
	final IType[] superTypes= declaring.newSupertypeHierarchy(fOwner, monitor).getAllSupertypes(declaring);
	final List<IType> list= new ArrayList<IType>(superTypes.length);
	int binary= 0;
	for (int index= 0; index < superTypes.length; index++) {
		final IType type= superTypes[index];
		if (type != null && type.exists() && !type.isReadOnly() && !type.isBinary() && !"java.lang.Object".equals(type.getFullyQualifiedName())) { //$NON-NLS-1$
			list.add(type);
		} else {
			if (type != null && type.isBinary()) {
				binary++;
			}
		}
	}
	if (superTypes.length == 1 && superTypes[0].getFullyQualifiedName().equals("java.lang.Object")) //$NON-NLS-1$
		status.addFatalError(RefactoringCoreMessages.PullUPRefactoring_not_java_lang_object);
	else if (superTypes.length == binary)
		status.addFatalError(RefactoringCoreMessages.PullUPRefactoring_no_all_binary);

	Collections.reverse(list);
	return list.toArray(new IType[list.size()]);
}
 
Example 4
Source File: PushDownRefactoringProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IType[] getAbstractDestinations(IProgressMonitor monitor) throws JavaModelException {
	IType[] allDirectSubclasses= getHierarchyOfDeclaringClass(monitor).getSubclasses(getDeclaringType());
	List<IType> result= new ArrayList<IType>(allDirectSubclasses.length);
	for (int index= 0; index < allDirectSubclasses.length; index++) {
		IType subclass= allDirectSubclasses[index];
		if (subclass.exists() && !subclass.isBinary() && !subclass.isReadOnly() && subclass.getCompilationUnit() != null && subclass.isStructureKnown())
			result.add(subclass);
	}
	return result.toArray(new IType[result.size()]);
}
 
Example 5
Source File: ExtractSupertypeProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public IType[] getCandidateTypes(final RefactoringStatus status, final IProgressMonitor monitor) {
	Assert.isNotNull(monitor);
	if (fPossibleCandidates == null || fPossibleCandidates.length == 0) {
		final IType declaring= getDeclaringType();
		if (declaring != null) {
			try {
				monitor.beginTask(RefactoringCoreMessages.ExtractSupertypeProcessor_computing_possible_types, 10);
				final IType superType= getDeclaringSuperTypeHierarchy(new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).getSuperclass(declaring);
				if (superType != null) {
					fPossibleCandidates= superType.newTypeHierarchy(fOwner, new SubProgressMonitor(monitor, 9, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).getSubtypes(superType);
					final LinkedList<IType> list= new LinkedList<IType>(Arrays.asList(fPossibleCandidates));
					final Set<String> names= new HashSet<String>();
					for (final Iterator<IType> iterator= list.iterator(); iterator.hasNext();) {
						final IType type= iterator.next();
						if (type.isReadOnly() || type.isBinary() || type.isAnonymous() || !type.isClass() || names.contains(type.getFullyQualifiedName()))
							iterator.remove();
						else
							names.add(type.getFullyQualifiedName());
					}
					fPossibleCandidates= list.toArray(new IType[list.size()]);
				}
			} catch (JavaModelException exception) {
				JavaPlugin.log(exception);
			} finally {
				monitor.done();
			}
		}
	}
	return fPossibleCandidates;
}
 
Example 6
Source File: MoveStaticMembersProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private RefactoringStatus checkDeclaringType(){
	IType declaringType= getDeclaringType();

	if (declaringType.getFullyQualifiedName('.').equals("java.lang.Object")) //$NON-NLS-1$
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveMembersRefactoring_Object);

	if (declaringType.isBinary())
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveMembersRefactoring_binary);

	if (declaringType.isReadOnly())
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveMembersRefactoring_read_only);

	return null;
}
 
Example 7
Source File: IntroduceIndirectionRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param fullyQualifiedTypeName the fully qualified name of the intermediary method
 * @return status for type name. Use {@link #setIntermediaryMethodName(String)} to check for overridden methods.
 */
public RefactoringStatus setIntermediaryTypeName(String fullyQualifiedTypeName) {
	IType target= null;

	try {
		if (fullyQualifiedTypeName.length() == 0)
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_type_not_selected_error);

		// find type (now including secondaries)
		target= getProject().findType(fullyQualifiedTypeName, new NullProgressMonitor());
		if (target == null || !target.exists())
			return RefactoringStatus.createErrorStatus(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_type_does_not_exist_error, BasicElementLabels.getJavaElementName(fullyQualifiedTypeName)));
		if (target.isAnnotation())
			return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_cannot_create_in_annotation);
		if (target.isInterface() && !(JavaModelUtil.is18OrHigher(target.getJavaProject()) && JavaModelUtil.is18OrHigher(getProject())))
			return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_cannot_create_on_interface);
	} catch (JavaModelException e) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_unable_determine_declaring_type);
	}

	if (target.isReadOnly())
		return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_cannot_create_in_readonly);

	if (target.isBinary())
		return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_cannot_create_in_binary);

	fIntermediaryType= target;

	return new RefactoringStatus();
}
 
Example 8
Source File: RefactoringAvailabilityTester.java    From eclipse.jdt.ls with Eclipse Public License 2.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 9
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public final RefactoringStatus checkFinalConditions(final IProgressMonitor monitor, final CheckConditionsContext context) throws CoreException, OperationCanceledException {
	Assert.isNotNull(monitor);
	Assert.isNotNull(context);
	Assert.isNotNull(fTarget);
	final RefactoringStatus status= new RefactoringStatus();
	fChangeManager= new TextChangeManager();
	try {
		monitor.beginTask("", 4); //$NON-NLS-1$
		monitor.setTaskName(RefactoringCoreMessages.MoveInstanceMethodProcessor_checking);
		status.merge(Checks.checkIfCuBroken(fMethod));
		if (!status.hasError()) {
			checkGenericTarget(new SubProgressMonitor(monitor, 1), status);
			if (status.isOK()) {
				final IType type= getTargetType();
				if (type != null) {
					if (type.isBinary() || type.isReadOnly() || !fMethod.exists() || fMethod.isBinary() || fMethod.isReadOnly())
						status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_binary, JavaStatusContext.create(fMethod)));
					else {
						status.merge(Checks.checkIfCuBroken(type));
						if (!status.hasError()) {
							if (!type.exists() || type.isBinary() || type.isReadOnly())
								status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_binary, JavaStatusContext.create(fMethod)));
							checkConflictingTarget(new SubProgressMonitor(monitor, 1), status);
							checkConflictingMethod(new SubProgressMonitor(monitor, 1), status);

							Checks.addModifiedFilesToChecker(computeModifiedFiles(fMethod.getCompilationUnit(), type.getCompilationUnit()), context);

							monitor.worked(1);
							if (!status.hasFatalError())
								fChangeManager= createChangeManager(status, new SubProgressMonitor(monitor, 1));
						}
					}
				} else
					status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_resolved_target, JavaStatusContext.create(fMethod)));
			}
		}
	} finally {
		monitor.done();
	}
	return status;
}
 
Example 10
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();
}