Java Code Examples for org.eclipse.jdt.core.Flags#isSynchronized()
The following examples show how to use
org.eclipse.jdt.core.Flags#isSynchronized() .
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: OverrideIndicatorLabelDecorator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Note: This method is for internal use only. Clients should not call this method. * @param element The element to decorate * @return Resulting decorations (combination of JavaElementImageDescriptor.IMPLEMENTS * and JavaElementImageDescriptor.OVERRIDES) * * @noreference This method is not intended to be referenced by clients. */ public int computeAdornmentFlags(Object element) { if (element instanceof IMethod) { try { IMethod method= (IMethod) element; if (!method.getJavaProject().isOnClasspath(method)) { return 0; } int flags= method.getFlags(); if (!method.isConstructor() && !Flags.isPrivate(flags) && !Flags.isStatic(flags)) { int res= getOverrideIndicators(method); if (res != 0 && Flags.isSynchronized(flags)) { return res | JavaElementImageDescriptor.SYNCHRONIZED; } return res; } } catch (JavaModelException e) { if (!e.isDoesNotExist()) { JavaPlugin.log(e); } } } return 0; }
Example 2
Source File: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * 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 3
Source File: JdtFlags.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public static boolean isSynchronized(IMember member) throws JavaModelException{ return Flags.isSynchronized(member.getFlags()); }
Example 4
Source File: JdtFlags.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public static boolean isSynchronized(IMember member) throws JavaModelException{ return Flags.isSynchronized(member.getFlags()); }
Example 5
Source File: GetterSetterUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Create a stub for a getter of the given field using getter/setter templates. The resulting code * has to be formatted and indented. * @param field The field to create a getter for * @param setterName The chosen name for the setter * @param addComments If <code>true</code>, comments will be added. * @param flags The flags signaling visibility, if static, synchronized or final * @return Returns the generated stub. * @throws CoreException when stub creation failed */ public static String getSetterStub(IField field, String setterName, boolean addComments, int flags) throws CoreException { String fieldName= field.getElementName(); IType parentType= field.getDeclaringType(); String returnSig= field.getTypeSignature(); String typeName= Signature.toString(returnSig); IJavaProject project= field.getJavaProject(); String accessorName= StubUtility.getBaseName(field); String argname= StubUtility.suggestArgumentName(project, accessorName, EMPTY); boolean isStatic= Flags.isStatic(flags); boolean isSync= Flags.isSynchronized(flags); boolean isFinal= Flags.isFinal(flags); String lineDelim= "\n"; // Use default line delimiter, as generated stub has to be formatted anyway //$NON-NLS-1$ StringBuffer buf= new StringBuffer(); if (addComments) { String comment= CodeGeneration.getSetterComment(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), setterName, field.getElementName(), typeName, argname, accessorName, lineDelim); if (comment != null) { buf.append(comment); buf.append(lineDelim); } } buf.append(JdtFlags.getVisibilityString(flags)); buf.append(' '); if (isStatic) buf.append("static "); //$NON-NLS-1$ if (isSync) buf.append("synchronized "); //$NON-NLS-1$ if (isFinal) buf.append("final "); //$NON-NLS-1$ buf.append("void "); //$NON-NLS-1$ buf.append(setterName); buf.append('('); buf.append(typeName); buf.append(' '); buf.append(argname); buf.append(") {"); //$NON-NLS-1$ buf.append(lineDelim); boolean useThis= StubUtility.useThisForFieldAccess(project); if (argname.equals(fieldName) || (useThis && !isStatic)) { if (isStatic) fieldName= parentType.getElementName() + '.' + fieldName; else fieldName= "this." + fieldName; //$NON-NLS-1$ } String body= CodeGeneration.getSetterMethodBodyContent(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), setterName, fieldName, argname, lineDelim); if (body != null) { buf.append(body); } buf.append("}"); //$NON-NLS-1$ buf.append(lineDelim); return buf.toString(); }
Example 6
Source File: GetterSetterUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Create a stub for a getter of the given field using getter/setter templates. The resulting code * has to be formatted and indented. * @param field The field to create a getter for * @param getterName The chosen name for the getter * @param addComments If <code>true</code>, comments will be added. * @param flags The flags signaling visibility, if static, synchronized or final * @return Returns the generated stub. * @throws CoreException when stub creation failed */ public static String getGetterStub(IField field, String getterName, boolean addComments, int flags) throws CoreException { String fieldName= field.getElementName(); IType parentType= field.getDeclaringType(); boolean isStatic= Flags.isStatic(flags); boolean isSync= Flags.isSynchronized(flags); boolean isFinal= Flags.isFinal(flags); String typeName= Signature.toString(field.getTypeSignature()); String accessorName= StubUtility.getBaseName(field); String lineDelim= "\n"; // Use default line delimiter, as generated stub has to be formatted anyway //$NON-NLS-1$ StringBuffer buf= new StringBuffer(); if (addComments) { String comment= CodeGeneration.getGetterComment(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), getterName, field.getElementName(), typeName, accessorName, lineDelim); if (comment != null) { buf.append(comment); buf.append(lineDelim); } } buf.append(JdtFlags.getVisibilityString(flags)); buf.append(' '); if (isStatic) buf.append("static "); //$NON-NLS-1$ if (isSync) buf.append("synchronized "); //$NON-NLS-1$ if (isFinal) buf.append("final "); //$NON-NLS-1$ buf.append(typeName); buf.append(' '); buf.append(getterName); buf.append("() {"); //$NON-NLS-1$ buf.append(lineDelim); boolean useThis= StubUtility.useThisForFieldAccess(field.getJavaProject()); if (useThis && !isStatic) { fieldName= "this." + fieldName; //$NON-NLS-1$ } String body= CodeGeneration.getGetterMethodBodyContent(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), getterName, fieldName, lineDelim); if (body != null) { buf.append(body); } buf.append("}"); //$NON-NLS-1$ buf.append(lineDelim); return buf.toString(); }
Example 7
Source File: CompletionProposalLabelProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * 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 8
Source File: JavaElementImageProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
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; }