Java Code Examples for org.eclipse.jdt.core.Flags#isDefaultMethod()

The following examples show how to use org.eclipse.jdt.core.Flags#isDefaultMethod() . 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: ChangeSignatureProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public String getOldMethodSignature() throws JavaModelException{
	StringBuffer buff= new StringBuffer();

	int flags= getMethod().getFlags();
	buff.append(getVisibilityString(flags));
	if (Flags.isStatic(flags)) {
		buff.append("static "); //$NON-NLS-1$
	} else if (Flags.isDefaultMethod(flags)) {
		buff.append("default "); //$NON-NLS-1$
	}
	if (! getMethod().isConstructor())
		buff.append(fReturnTypeInfo.getOldTypeName())
			.append(' ');

	buff.append(JavaElementLabels.getElementLabel(fMethod.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED));
	buff.append('.');
	buff.append(fMethod.getElementName())
		.append(Signature.C_PARAM_START)
		.append(getOldMethodParameters())
		.append(Signature.C_PARAM_END);

	buff.append(getOldMethodThrows());

	return BasicElementLabels.getJavaCodeString(buff.toString());
}
 
Example 2
Source File: ChangeSignatureProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public String getNewMethodSignature() throws JavaModelException{
	StringBuffer buff= new StringBuffer();

	buff.append(getVisibilityString(fVisibility));
	int flags= getMethod().getFlags();
	if (Flags.isStatic(flags)) {
		buff.append("static "); //$NON-NLS-1$
	} else if (Flags.isDefaultMethod(flags)) {
		buff.append("default "); //$NON-NLS-1$
	}
	if (! getMethod().isConstructor())
		buff.append(getReturnTypeString())
			.append(' ');

	buff.append(getMethodName())
		.append(Signature.C_PARAM_START)
		.append(getMethodParameters())
		.append(Signature.C_PARAM_END);

	buff.append(getMethodThrows());

	return BasicElementLabels.getJavaCodeString(buff.toString());
}
 
Example 3
Source File: JdtFlags.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean isAbstract(IMember member) throws JavaModelException{
	int flags= member.getFlags();
	if (!member.isBinary() && isInterfaceOrAnnotationMethod(member)) {
		return !Flags.isPrivate(flags) && !Flags.isStatic(flags) && !Flags.isDefaultMethod(flags);
	}
	return Flags.isAbstract(flags);
}
 
Example 4
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks whether the instance method declaration is compatible with this
 * refactoring.
 *
 * @param monitor
 *            the progress monitor to display progress
 * @param status
 *            the status of the condition checking
 * @throws JavaModelException
 *             if the method does not exist
 */
protected void checkMethodDeclaration(final IProgressMonitor monitor, final RefactoringStatus status) throws JavaModelException {
	Assert.isNotNull(monitor);
	Assert.isNotNull(status);
	try {
		monitor.beginTask("", 5); //$NON-NLS-1$
		monitor.setTaskName(RefactoringCoreMessages.MoveInstanceMethodProcessor_checking);
		final int flags= fMethod.getFlags();
		if (Flags.isStatic(flags))
			status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_static_methods, JavaStatusContext.create(fMethod)));
		else if (Flags.isAbstract(flags))
			status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_single_implementation, JavaStatusContext.create(fMethod)));
		monitor.worked(1);
		if (Flags.isNative(flags))
			status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_native_methods, JavaStatusContext.create(fMethod)));
		monitor.worked(1);
		if (Flags.isSynchronized(flags))
			status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_synchronized_methods, JavaStatusContext.create(fMethod)));
		monitor.worked(1);
		if (fMethod.isConstructor())
			status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_constructors, JavaStatusContext.create(fMethod)));
		monitor.worked(1);
		if (fMethod.getDeclaringType().isAnnotation())
			status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_annotation, JavaStatusContext.create(fMethod)));
		else if (fMethod.getDeclaringType().isInterface() && !Flags.isDefaultMethod(flags))
			status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_interface, JavaStatusContext.create(fMethod)));
		monitor.worked(1);
	} finally {
		monitor.done();
	}
}
 
Example 5
Source File: TypeContextChecker.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int appendMethodDeclaration(StringBuffer cuString, String[] types, int parameterCount) throws JavaModelException {
	int flags= fMethod.getFlags();
	if (Flags.isStatic(flags)) {
		cuString.append("static "); //$NON-NLS-1$
	} else if (Flags.isDefaultMethod(flags)) {
		cuString.append("default "); //$NON-NLS-1$
	}

	ITypeParameter[] methodTypeParameters= fMethod.getTypeParameters();
	if (methodTypeParameters.length != 0) {
		cuString.append('<');
		for (int i= 0; i < methodTypeParameters.length; i++) {
			ITypeParameter typeParameter= methodTypeParameters[i];
			if (i > 0)
				cuString.append(',');
			cuString.append(typeParameter.getElementName());
		}
		cuString.append("> "); //$NON-NLS-1$
	}

	cuString.append(types[parameterCount]).append(' ');
	int offsetBeforeMethodName= cuString.length();
	cuString.append(METHOD_NAME).append('(');
	for (int i= 0; i < parameterCount; i++) {
		if (i > 0)
			cuString.append(',');
		cuString.append(types[i]).append(" p").append(i); //$NON-NLS-1$
	}
	cuString.append(");"); //$NON-NLS-1$

	return offsetBeforeMethodName;
}
 
Example 6
Source File: JdtFlags.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isAbstract(IMember member) throws JavaModelException{
	int flags= member.getFlags();
	if (!member.isBinary() && isInterfaceOrAnnotationMethod(member)) {
		return !Flags.isStatic(flags) && !Flags.isDefaultMethod(flags);
	}
	return Flags.isAbstract(flags);
}
 
Example 7
Source File: JdtFlags.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public static boolean isDefaultMethod(IMethod method) throws JavaModelException {
	return Flags.isDefaultMethod(method.getFlags());
}
 
Example 8
Source File: JdtFlags.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isDefaultMethod(IMethod method) throws JavaModelException {
	return Flags.isDefaultMethod(method.getFlags());
}
 
Example 9
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns a version of <code>descriptor</code> decorated according to
 * the passed <code>modifier</code> flags.
 *
 * @param descriptor the image descriptor to decorate
 * @param proposal the proposal
 * @return an image descriptor for a method proposal
 * @see Flags
 */
private ImageDescriptor decorateImageDescriptor(ImageDescriptor descriptor, CompletionProposal proposal) {
	int adornments= 0;
	int flags= proposal.getFlags();
	int kind= proposal.getKind();

	boolean deprecated= Flags.isDeprecated(flags);
	if (!deprecated) {
		CompletionProposal[] requiredProposals= proposal.getRequiredProposals();
		if (requiredProposals != null) {
			for (int i= 0; i < requiredProposals.length; i++) {
				CompletionProposal requiredProposal= requiredProposals[i];
				if (requiredProposal.getKind() == CompletionProposal.TYPE_REF) {
					deprecated |= Flags.isDeprecated(requiredProposal.getFlags());
				}
			}
		}
	}
	if (deprecated)
		adornments |= JavaElementImageDescriptor.DEPRECATED;

	if (kind == CompletionProposal.FIELD_REF || kind == CompletionProposal.METHOD_DECLARATION || kind == CompletionProposal.METHOD_NAME_REFERENCE
			|| kind == CompletionProposal.METHOD_REF || kind == CompletionProposal.CONSTRUCTOR_INVOCATION)
		if (Flags.isStatic(flags))
			adornments |= JavaElementImageDescriptor.STATIC;

	if (kind == CompletionProposal.METHOD_DECLARATION || kind == CompletionProposal.METHOD_NAME_REFERENCE || kind == CompletionProposal.METHOD_REF
			|| kind == CompletionProposal.CONSTRUCTOR_INVOCATION)
		if (Flags.isSynchronized(flags))
			adornments |= JavaElementImageDescriptor.SYNCHRONIZED;
	if (kind == CompletionProposal.METHOD_DECLARATION || kind == CompletionProposal.METHOD_NAME_REFERENCE || kind == CompletionProposal.METHOD_REF)
		if (Flags.isDefaultMethod(flags))
			adornments|= JavaElementImageDescriptor.DEFAULT_METHOD;
	if (kind == CompletionProposal.ANNOTATION_ATTRIBUTE_REF)
		if (Flags.isAnnnotationDefault(flags))
			adornments|= JavaElementImageDescriptor.ANNOTATION_DEFAULT;

	if (kind == CompletionProposal.TYPE_REF && Flags.isAbstract(flags) && !Flags.isInterface(flags))
		adornments |= JavaElementImageDescriptor.ABSTRACT;

	if (kind == CompletionProposal.FIELD_REF) {
		if (Flags.isFinal(flags))
			adornments |= JavaElementImageDescriptor.FINAL;
		if (Flags.isTransient(flags))
			adornments |= JavaElementImageDescriptor.TRANSIENT;
		if (Flags.isVolatile(flags))
			adornments |= JavaElementImageDescriptor.VOLATILE;
	}

	return new JavaElementImageDescriptor(descriptor, adornments, JavaElementImageProvider.SMALL_SIZE);
}
 
Example 10
Source File: JavaElementImageProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private int computeJavaAdornmentFlags(IJavaElement element, int renderFlags) {
	int flags= 0;
	if (showOverlayIcons(renderFlags)) {
		try {
			if (element instanceof IMember) {
				IMember member= (IMember)element;

				int modifiers= member.getFlags();
				if (confirmAbstract(member) && JdtFlags.isAbstract(member))
					flags|= JavaElementImageDescriptor.ABSTRACT;
				if (Flags.isFinal(modifiers) || isInterfaceOrAnnotationField(member) || isEnumConstant(member, modifiers))
					flags|= JavaElementImageDescriptor.FINAL;
				if (Flags.isStatic(modifiers) || isInterfaceOrAnnotationFieldOrType(member) || isEnumConstant(member, modifiers))
					flags|= JavaElementImageDescriptor.STATIC;

				if (Flags.isDeprecated(modifiers))
					flags|= JavaElementImageDescriptor.DEPRECATED;

				int elementType= element.getElementType();
				if (elementType == IJavaElement.METHOD) {
					if (((IMethod)element).isConstructor())
						flags|= JavaElementImageDescriptor.CONSTRUCTOR;
					if (Flags.isSynchronized(modifiers)) // collides with 'super' flag
						flags|= JavaElementImageDescriptor.SYNCHRONIZED;
					if (Flags.isNative(modifiers))
						flags|= JavaElementImageDescriptor.NATIVE;
					if (Flags.isDefaultMethod(modifiers))
						flags|= JavaElementImageDescriptor.DEFAULT_METHOD;
					if (Flags.isAnnnotationDefault(modifiers))
						flags|= JavaElementImageDescriptor.ANNOTATION_DEFAULT;
				}

				if (member.getElementType() == IJavaElement.TYPE) {
					if (JavaModelUtil.hasMainMethod((IType)member)) {
						flags|= JavaElementImageDescriptor.RUNNABLE;
					}
				}

				if (member.getElementType() == IJavaElement.FIELD) {
					if (Flags.isVolatile(modifiers))
						flags|= JavaElementImageDescriptor.VOLATILE;
					if (Flags.isTransient(modifiers))
						flags|= JavaElementImageDescriptor.TRANSIENT;
				}
			} else if (element instanceof ILocalVariable && Flags.isFinal(((ILocalVariable)element).getFlags())) {
				flags|= JavaElementImageDescriptor.FINAL;
			}
		} catch (JavaModelException e) {
			// do nothing. Can't compute runnable adornment or get flags
		}
	}
	return flags;
}