org.eclipse.jdt.core.Flags Java Examples
The following examples show how to use
org.eclipse.jdt.core.Flags.
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 |
protected static List<ASTNode> getDeclarationNodes(final CompilationUnit cuNode, final List<IMember> members) throws JavaModelException { final List<ASTNode> result= new ArrayList<ASTNode>(members.size()); for (final Iterator<IMember> iterator= members.iterator(); iterator.hasNext();) { final IMember member= iterator.next(); ASTNode node= null; if (member instanceof IField) { if (Flags.isEnum(member.getFlags())) node= ASTNodeSearchUtil.getEnumConstantDeclaration((IField) member, cuNode); else node= ASTNodeSearchUtil.getFieldDeclarationFragmentNode((IField) member, cuNode); } else if (member instanceof IType) node= ASTNodeSearchUtil.getAbstractTypeDeclarationNode((IType) member, cuNode); else if (member instanceof IMethod) node= ASTNodeSearchUtil.getMethodDeclarationNode((IMethod) member, cuNode); if (node != null) result.add(node); } return result; }
Example #2
Source File: AddGetterSetterOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Generates a new getter method for the specified field * * @param field the field * @param rewrite the list rewrite to use * @throws CoreException if an error occurs * @throws OperationCanceledException if the operation has been cancelled */ private void generateGetterMethod(final IField field, final ListRewrite rewrite) throws CoreException, OperationCanceledException { final IType type= field.getDeclaringType(); final String name= GetterSetterUtil.getGetterName(field, null); final IMethod existing= JavaModelUtil.findMethod(name, EMPTY_STRINGS, false, type); if (existing == null || !querySkipExistingMethods(existing)) { IJavaElement sibling= null; if (existing != null) { sibling= StubUtility.findNextSibling(existing); removeExistingAccessor(existing, rewrite); } else sibling= fInsert; ASTNode insertion= StubUtility2.getNodeToInsertBefore(rewrite, sibling); addNewAccessor(type, field, GetterSetterUtil.getGetterStub(field, name, fSettings.createComments, fVisibility | (field.getFlags() & Flags.AccStatic)), rewrite, insertion); } }
Example #3
Source File: PullUpRefactoringProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private MethodDeclaration createNewMethodDeclarationNode(final CompilationUnitRewrite sourceRewrite, final CompilationUnitRewrite targetRewrite, final IMethod sourceMethod, final MethodDeclaration oldMethod, final TypeVariableMaplet[] mapping, final Map<IMember, IncomingMemberVisibilityAdjustment> adjustments, final IProgressMonitor monitor, final RefactoringStatus status) throws JavaModelException { final ASTRewrite rewrite= targetRewrite.getASTRewrite(); final AST ast= rewrite.getAST(); final MethodDeclaration newMethod= ast.newMethodDeclaration(); if (!getDestinationType().isInterface()) copyBodyOfPulledUpMethod(sourceRewrite, targetRewrite, sourceMethod, oldMethod, newMethod, mapping, monitor); newMethod.setConstructor(oldMethod.isConstructor()); copyExtraDimensions(oldMethod, newMethod); copyJavadocNode(rewrite, oldMethod, newMethod); int modifiers= getModifiersWithUpdatedVisibility(sourceMethod, sourceMethod.getFlags(), adjustments, monitor, true, status); if (fDeletedMethods.length == 0 || getDestinationType().isInterface()) { modifiers&= ~Flags.AccFinal; } if (oldMethod.isVarargs()) modifiers&= ~Flags.AccVarargs; copyAnnotations(oldMethod, newMethod); newMethod.modifiers().addAll(ASTNodeFactory.newModifiers(ast, modifiers)); newMethod.setName(((SimpleName) ASTNode.copySubtree(ast, oldMethod.getName()))); copyReturnType(rewrite, getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping); copyParameters(rewrite, getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping); copyThrownExceptions(oldMethod, newMethod); copyTypeParameters(oldMethod, newMethod); return newMethod; }
Example #4
Source File: NLSSearchQuery.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private boolean isNLSField(IField field) throws JavaModelException { int flags= field.getFlags(); if (!Flags.isPublic(flags)) return false; if (!Flags.isStatic(flags)) return false; String fieldName= field.getElementName(); if (NLSRefactoring.BUNDLE_NAME_FIELD.equals(fieldName)) return false; if ("RESOURCE_BUNDLE".equals(fieldName)) //$NON-NLS-1$ return false; return true; }
Example #5
Source File: CompletionProposalLabelProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Appends the parameter list to <code>buffer</code>. * * @param buffer the buffer to append to * @param methodProposal the method proposal * @return the modified <code>buffer</code> */ private StyledString appendUnboundedParameterList(StyledString buffer, CompletionProposal methodProposal) { // TODO remove once https://bugs.eclipse.org/bugs/show_bug.cgi?id=85293 // gets fixed. char[] signature= SignatureUtil.fix83600(methodProposal.getSignature()); char[][] parameterNames= methodProposal.findParameterNames(null); char[][] parameterTypes= Signature.getParameterTypes(signature); for (int i= 0; i < parameterTypes.length; i++) parameterTypes[i]= createTypeDisplayName(SignatureUtil.getLowerBound(parameterTypes[i])); if (Flags.isVarargs(methodProposal.getFlags())) { int index= parameterTypes.length - 1; parameterTypes[index]= convertToVararg(parameterTypes[index]); } return appendParameterSignature(buffer, parameterTypes, parameterNames); }
Example #6
Source File: DeltaConverter.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * We don't include nested types because structural changes of nested types should not affect Xtend classes which * use top level types. * * @deprecated This method is not used anymore. */ @Deprecated protected void traverseType(IType type, NameBasedEObjectDescriptionBuilder acceptor) { try { if (type.exists()) { for (IField field : type.getFields()) { if (!Flags.isSynthetic(field.getFlags())) { String fieldName = field.getElementName(); acceptor.accept(fieldName); } } for (IMethod method : type.getMethods()) { if (!Flags.isSynthetic(method.getFlags())) { String methodName = method.getElementName(); acceptor.accept(methodName); } } } } catch (JavaModelException e) { if (LOGGER.isDebugEnabled()) LOGGER.debug(e, e); } }
Example #7
Source File: CompletionProposalDescriptionProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
/** * Appends the parameter list to <code>buffer</code>. * * @param buffer the buffer to append to * @param methodProposal the method proposal * @return the modified <code>buffer</code> */ private StringBuilder appendUnboundedParameterList(StringBuilder buffer, CompletionProposal methodProposal) { // TODO remove once https://bugs.eclipse.org/bugs/show_bug.cgi?id=85293 // gets fixed. char[] signature= SignatureUtil.fix83600(methodProposal.getSignature()); char[][] parameterNames; try { parameterNames = methodProposal.findParameterNames(null); } catch (Exception e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); parameterNames = CompletionEngine.createDefaultParameterNames(Signature.getParameterCount(signature)); methodProposal.setParameterNames(parameterNames); } char[][] parameterTypes= Signature.getParameterTypes(signature); for (int i= 0; i < parameterTypes.length; i++) { parameterTypes[i]= createTypeDisplayName(SignatureUtil.getLowerBound(parameterTypes[i])); } if (Flags.isVarargs(methodProposal.getFlags())) { int index= parameterTypes.length - 1; parameterTypes[index]= convertToVararg(parameterTypes[index]); } return appendParameterSignature(buffer, parameterTypes, parameterNames); }
Example #8
Source File: GetterSetterCompletionProposal.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
/** * @param document * @param offset * @param importRewrite * @param completionSnippetsSupported * @param addComments * @return * @throws CoreException * @throws BadLocationException */ public String updateReplacementString(IDocument document, int offset, ImportRewrite importRewrite, boolean completionSnippetsSupported, boolean addComments) throws CoreException, BadLocationException { int flags= Flags.AccPublic | (fField.getFlags() & Flags.AccStatic); String stub; if (fIsGetter) { String getterName= GetterSetterUtil.getGetterName(fField, null); stub = GetterSetterUtil.getGetterStub(fField, getterName, addComments, flags); } else { String setterName= GetterSetterUtil.getSetterName(fField, null); stub = GetterSetterUtil.getSetterStub(fField, setterName, addComments, flags); } // use the code formatter String lineDelim= TextUtilities.getDefaultLineDelimiter(document); String replacement = CodeFormatterUtil.format(CodeFormatter.K_CLASS_BODY_DECLARATIONS, stub, 0, lineDelim, fField.getJavaProject()); if (replacement.endsWith(lineDelim)) { replacement = replacement.substring(0, replacement.length() - lineDelim.length()); } return replacement; }
Example #9
Source File: MembersOrderPreferencePage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public Image getImage(Object element) { //access to image registry ImageDescriptorRegistry registry= JavaPlugin.getImageDescriptorRegistry(); ImageDescriptor descriptor= null; if (element instanceof String) { String s= (String) element; if (s.equals(PUBLIC)) { descriptor= JavaElementImageProvider.getMethodImageDescriptor(false, Flags.AccPublic); } else if (s.equals(PRIVATE)) { descriptor= JavaElementImageProvider.getMethodImageDescriptor(false, Flags.AccPrivate); } else if (s.equals(PROTECTED)) { descriptor= JavaElementImageProvider.getMethodImageDescriptor(false, Flags.AccProtected); } else if (s.equals(DEFAULT)) { descriptor= JavaElementImageProvider.getMethodImageDescriptor(false, Flags.AccDefault); } return registry.get(descriptor); } return null; }
Example #10
Source File: SelfEncapsulateFieldInputPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private Object[] createData(int visibility) { String pub= RefactoringMessages.SelfEncapsulateFieldInputPage_public; String pro= RefactoringMessages.SelfEncapsulateFieldInputPage_protected; String def= RefactoringMessages.SelfEncapsulateFieldInputPage_default; String priv= RefactoringMessages.SelfEncapsulateFieldInputPage_private; String[] labels= null; Integer[] data= null; if (Flags.isPrivate(visibility)) { labels= new String[] { pub, pro, def, priv }; data= new Integer[] {new Integer(Flags.AccPublic), new Integer(Flags.AccProtected), new Integer(0), new Integer(Flags.AccPrivate) }; } else if (Flags.isProtected(visibility)) { labels= new String[] { pub, pro }; data= new Integer[] {new Integer(Flags.AccPublic), new Integer(Flags.AccProtected)}; } else { labels= new String[] { pub, def }; data= new Integer[] {new Integer(Flags.AccPublic), new Integer(0)}; } return new Object[] {labels, data}; }
Example #11
Source File: AddGetterSetterAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * @param type the type * @return map IField -> GetterSetterEntry[] * @throws JavaModelException if the type does not exist or if an exception occurs while * accessing its corresponding resource */ private Map<IField, GetterSetterEntry[]> createGetterSetterMapping(IType type) throws JavaModelException { IField[] fields= type.getFields(); Map<IField, GetterSetterEntry[]> result= new LinkedHashMap<IField, GetterSetterEntry[]>(); for (int i= 0; i < fields.length; i++) { IField field= fields[i]; int flags= field.getFlags(); if (!Flags.isEnum(flags)) { List<GetterSetterEntry> l= new ArrayList<GetterSetterEntry>(2); if (GetterSetterUtil.getGetter(field) == null) { l.add(new GetterSetterEntry(field, true, Flags.isFinal(flags))); incNumEntries(); } if (GetterSetterUtil.getSetter(field) == null) { l.add(new GetterSetterEntry(field, false, Flags.isFinal(flags))); incNumEntries(); } if (!l.isEmpty()) result.put(field, l.toArray(new GetterSetterEntry[l.size()])); } } return result; }
Example #12
Source File: GetterSetterCorrectionSubProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
public static Change getRefactoringChange(IField field) { SelfEncapsulateFieldRefactoring refactoring; try { Preferences preferences = JavaLanguageServerPlugin.getPreferencesManager().getPreferences(); refactoring = new SelfEncapsulateFieldRefactoring(field); refactoring.setGenerateJavadoc(preferences.isCodeGenerationTemplateGenerateComments()); refactoring.setVisibility(Flags.AccPublic); refactoring.setConsiderVisibility(false);//private field references are just searched in local file refactoring.checkInitialConditions(new NullProgressMonitor()); refactoring.checkFinalConditions(new NullProgressMonitor()); return refactoring.createChange(new NullProgressMonitor()); } catch (CoreException e) { JavaLanguageServerPlugin.log(e); } return null; }
Example #13
Source File: PullUpRefactoringProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void createAbstractMethod(final IMethod sourceMethod, final CompilationUnitRewrite sourceRewriter, final CompilationUnit declaringCuNode, final AbstractTypeDeclaration destination, final TypeVariableMaplet[] mapping, final CompilationUnitRewrite targetRewrite, final Map<IMember, IncomingMemberVisibilityAdjustment> adjustments, final IProgressMonitor monitor, final RefactoringStatus status) throws JavaModelException { final MethodDeclaration oldMethod= ASTNodeSearchUtil.getMethodDeclarationNode(sourceMethod, declaringCuNode); if (JavaModelUtil.is50OrHigher(sourceMethod.getJavaProject()) && (fSettings.overrideAnnotation || JavaCore.ERROR.equals(sourceMethod.getJavaProject().getOption(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION, true)))) { final MarkerAnnotation annotation= sourceRewriter.getAST().newMarkerAnnotation(); annotation.setTypeName(sourceRewriter.getAST().newSimpleName("Override")); //$NON-NLS-1$ sourceRewriter.getASTRewrite().getListRewrite(oldMethod, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(annotation, sourceRewriter.createCategorizedGroupDescription(RefactoringCoreMessages.PullUpRefactoring_add_override_annotation, SET_PULL_UP)); } final MethodDeclaration newMethod= targetRewrite.getAST().newMethodDeclaration(); newMethod.setBody(null); newMethod.setConstructor(false); copyExtraDimensions(oldMethod, newMethod); newMethod.setJavadoc(null); int modifiers= getModifiersWithUpdatedVisibility(sourceMethod, Modifier.ABSTRACT | JdtFlags.clearFlag(Modifier.NATIVE | Modifier.FINAL, sourceMethod.getFlags()), adjustments, monitor, false, status); if (oldMethod.isVarargs()) modifiers&= ~Flags.AccVarargs; newMethod.modifiers().addAll(ASTNodeFactory.newModifiers(targetRewrite.getAST(), modifiers)); newMethod.setName(((SimpleName) ASTNode.copySubtree(targetRewrite.getAST(), oldMethod.getName()))); copyReturnType(targetRewrite.getASTRewrite(), getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping); copyParameters(targetRewrite.getASTRewrite(), getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping); copyThrownExceptions(oldMethod, newMethod); copyTypeParameters(oldMethod, newMethod); ImportRewriteContext context= new ContextSensitiveImportRewriteContext(destination, targetRewrite.getImportRewrite()); ImportRewriteUtil.addImports(targetRewrite, context, oldMethod, new HashMap<Name, String>(), new HashMap<Name, String>(), false); targetRewrite.getASTRewrite().getListRewrite(destination, destination.getBodyDeclarationsProperty()).insertAt(newMethod, ASTNodes.getInsertionIndex(newMethod, destination.bodyDeclarations()), targetRewrite.createCategorizedGroupDescription(RefactoringCoreMessages.PullUpRefactoring_add_abstract_method, SET_PULL_UP)); }
Example #14
Source File: JavaModelUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Evaluates if a member (possible from another package) is visible from * elements in a package. * @param member The member to test the visibility for * @param pack The package in focus * @return returns <code>true</code> if the member is visible from the package * @throws JavaModelException thrown when the member can not be accessed */ public static boolean isVisible(IMember member, IPackageFragment pack) throws JavaModelException { int type= member.getElementType(); if (type == IJavaElement.INITIALIZER || (type == IJavaElement.METHOD && member.getElementName().startsWith("<"))) { //$NON-NLS-1$ return false; } int otherflags= member.getFlags(); IType declaringType= member.getDeclaringType(); if (Flags.isPublic(otherflags) || (declaringType != null && isInterfaceOrAnnotation(declaringType))) { return true; } else if (Flags.isPrivate(otherflags)) { return false; } IPackageFragment otherpack= (IPackageFragment) member.getAncestor(IJavaElement.PACKAGE_FRAGMENT); return (pack != null && otherpack != null && isSamePackage(pack, otherpack)); }
Example #15
Source File: XtendProposalProvider.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public void completeType_Extends(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { final boolean isInterface = assignment == grammarAccess.getTypeAccess().getExtendsAssignment_2_1_5_1() || assignment == grammarAccess.getTypeAccess().getExtendsAssignment_2_1_5_2_1(); // FIXME filter "self" completeJavaTypes(context, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, true, getQualifiedNameValueConverter(), new ITypesProposalProvider.Filter() { @Override public int getSearchFor() { return isInterface ? IJavaSearchConstants.INTERFACE : IJavaSearchConstants.CLASS; } @Override public boolean accept(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { if (TypeMatchFilters.isInternalClass(simpleTypeName, enclosingTypeNames)) return false; if (!TypeMatchFilters.isAcceptableByPreference().accept(modifiers, packageName, simpleTypeName, enclosingTypeNames, path)) { return false; } return !Flags.isFinal(modifiers); } }, acceptor); }
Example #16
Source File: NewTypeWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Sets the modifiers. * * @param modifiers <code>F_PUBLIC</code>, <code>F_PRIVATE</code>, * <code>F_PROTECTED</code>, <code>F_ABSTRACT</code>, <code>F_FINAL</code> * or <code>F_STATIC</code> or a valid combination. * @param canBeModified if <code>true</code> the modifier fields are * editable; otherwise they are read-only * @see Flags */ public void setModifiers(int modifiers, boolean canBeModified) { if (Flags.isPublic(modifiers)) { fAccMdfButtons.setSelection(PUBLIC_INDEX, true); } else if (Flags.isPrivate(modifiers)) { fAccMdfButtons.setSelection(PRIVATE_INDEX, true); } else if (Flags.isProtected(modifiers)) { fAccMdfButtons.setSelection(PROTECTED_INDEX, true); } else { fAccMdfButtons.setSelection(DEFAULT_INDEX, true); } if (Flags.isAbstract(modifiers)) { fOtherMdfButtons.setSelection(ABSTRACT_INDEX, true); } if (Flags.isFinal(modifiers)) { fOtherMdfButtons.setSelection(FINAL_INDEX, true); } if (Flags.isStatic(modifiers)) { fOtherMdfButtons.setSelection(STATIC_INDEX, true); } fAccMdfButtons.setEnabled(canBeModified); fOtherMdfButtons.setEnabled(canBeModified); }
Example #17
Source File: SARLProposalProvider.java From sarl with Apache License 2.0 | 6 votes |
@Override public boolean accept(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { // Avoid auto reference of type. final String fullName = JavaModelUtil.concatenateName(packageName, simpleTypeName); if (Objects.equals(this.modelFullName, fullName)) { return false; } //The following tests are done by the visibility filter. //if (TypeMatchFilters.isInternalClass(simpleTypeName, enclosingTypeNames)) { // return false; //} //if (!TypeMatchFilters.isAcceptableByPreference().accept(modifiers, packageName, // simpleTypeName, enclosingTypeNames, path)) { // return false; //} // Final modifier test if (Flags.isFinal(modifiers)) { return false; } return this.visibilityFilter.accept(modifiers, packageName, simpleTypeName, enclosingTypeNames, path); }
Example #18
Source File: MethodOverrideTester.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Finds an overriding method in a type. * @param overridingType The type to find methods in * @param overridden The overridden method * @return The overriding method or <code>null</code> if no method is overriding. * @throws JavaModelException if a problem occurs */ public IMethod findOverridingMethodInType(IType overridingType, IMethod overridden) throws JavaModelException { int flags= overridden.getFlags(); if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overridden.isConstructor()) return null; IMethod[] overridingMethods= overridingType.getMethods(); for (int i= 0; i < overridingMethods.length; i++) { IMethod overriding= overridingMethods[i]; flags= overriding.getFlags(); if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overriding.isConstructor()) continue; if (isSubsignature(overriding, overridden)) { return overriding; } } return null; }
Example #19
Source File: SelfEncapsulateFieldRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException { if (fVisibility < 0) fVisibility= (fField.getFlags() & (Flags.AccPublic | Flags.AccProtected | Flags.AccPrivate)); RefactoringStatus result= new RefactoringStatus(); result.merge(Checks.checkAvailability(fField)); if (result.hasFatalError()) return result; fRoot= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(fField.getCompilationUnit(), true, pm); ISourceRange sourceRange= fField.getNameRange(); ASTNode node= NodeFinder.perform(fRoot, sourceRange.getOffset(), sourceRange.getLength()); if (node == null) { return mappingErrorFound(result, node); } fFieldDeclaration= (VariableDeclarationFragment)ASTNodes.getParent(node, VariableDeclarationFragment.class); if (fFieldDeclaration == null) { return mappingErrorFound(result, node); } if (fFieldDeclaration.resolveBinding() == null) { if (!processCompilerError(result, node)) result.addFatalError(RefactoringCoreMessages.SelfEncapsulateField_type_not_resolveable); return result; } computeUsedNames(); return result; }
Example #20
Source File: RefactoringAvailabilityTester.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static boolean isRenameElementAvailable(IJavaElement element) throws CoreException { switch (element.getElementType()) { case IJavaElement.JAVA_PROJECT: return isRenameAvailable((IJavaProject) element); case IJavaElement.PACKAGE_FRAGMENT_ROOT: return isRenameAvailable((IPackageFragmentRoot) element); case IJavaElement.PACKAGE_FRAGMENT: return isRenameAvailable((IPackageFragment) element); case IJavaElement.COMPILATION_UNIT: return isRenameAvailable((ICompilationUnit) element); case IJavaElement.TYPE: return isRenameAvailable((IType) element); case IJavaElement.METHOD: final IMethod method = (IMethod) element; if (method.isConstructor()) { return isRenameAvailable(method.getDeclaringType()); } else { return isRenameAvailable(method); } case IJavaElement.FIELD: final IField field = (IField) element; if (Flags.isEnum(field.getFlags())) { return isRenameEnumConstAvailable(field); } else { return isRenameFieldAvailable(field); } case IJavaElement.TYPE_PARAMETER: return isRenameAvailable((ITypeParameter) element); case IJavaElement.LOCAL_VARIABLE: return isRenameAvailable((ILocalVariable) element); } return false; }
Example #21
Source File: RenamePackageProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void updateImport(ICompilationUnit cu, IImportDeclaration importDeclaration, String updatedImport) throws JavaModelException { ImportChange importChange= fImportsManager.getImportChange(cu); if (Flags.isStatic(importDeclaration.getFlags())) { importChange.removeStaticImport(importDeclaration.getElementName()); importChange.addStaticImport(Signature.getQualifier(updatedImport), Signature.getSimpleName(updatedImport)); } else { importChange.removeImport(importDeclaration.getElementName()); importChange.addImport(updatedImport); } }
Example #22
Source File: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Creates the necessary changes to remove method type parameters if they * match with enclosing type parameters. * * @param rewrite * the ast rewrite to use * @param declaration * the method declaration to remove type parameters * @param status * the refactoring status */ protected void createMethodTypeParameters(final ASTRewrite rewrite, final MethodDeclaration declaration, final RefactoringStatus status) { ITypeBinding binding= fTarget.getType(); if (binding != null && binding.isParameterizedType()) { final IMethodBinding method= declaration.resolveBinding(); if (method != null) { final ITypeBinding[] parameters= method.getTypeParameters(); if (parameters.length > 0) { final ListRewrite rewriter= rewrite.getListRewrite(declaration, MethodDeclaration.TYPE_PARAMETERS_PROPERTY); boolean foundStatic= false; while (binding != null && !foundStatic) { if (Flags.isStatic(binding.getModifiers())) foundStatic= true; final ITypeBinding[] bindings= binding.getTypeArguments(); for (int index= 0; index < bindings.length; index++) { for (int offset= 0; offset < parameters.length; offset++) { if (parameters[offset].getName().equals(bindings[index].getName())) { rewriter.remove((ASTNode) rewriter.getOriginalList().get(offset), null); status.addWarning(Messages.format(RefactoringCoreMessages.MoveInstanceMethodProcessor_present_type_parameter_warning, new Object[] { BasicElementLabels.getJavaElementName(parameters[offset].getName()), BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED) }), JavaStatusContext.create(fMethod)); } } } binding= binding.getDeclaringClass(); } } } } }
Example #23
Source File: InlineConstantRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public Change createChange(IProgressMonitor pm) throws CoreException { try { pm.beginTask(RefactoringCoreMessages.InlineConstantRefactoring_preview, 2); final Map<String, String> arguments= new HashMap<String, String>(); String project= null; IJavaProject javaProject= fSelectionCu.getJavaProject(); if (javaProject != null) project= javaProject.getElementName(); int flags= RefactoringDescriptor.STRUCTURAL_CHANGE | JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT; try { if (!Flags.isPrivate(fField.getFlags())) flags|= RefactoringDescriptor.MULTI_CHANGE; } catch (JavaModelException exception) { JavaPlugin.log(exception); } final String description= Messages.format(RefactoringCoreMessages.InlineConstantRefactoring_descriptor_description_short, JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_DEFAULT)); final String header= Messages.format(RefactoringCoreMessages.InlineConstantRefactoring_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(fField.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED)}); final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header); comment.addSetting(Messages.format(RefactoringCoreMessages.InlineConstantRefactoring_original_pattern, JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED))); if (fRemoveDeclaration) comment.addSetting(RefactoringCoreMessages.InlineConstantRefactoring_remove_declaration); if (fReplaceAllReferences) comment.addSetting(RefactoringCoreMessages.InlineConstantRefactoring_replace_references); final InlineConstantDescriptor descriptor= RefactoringSignatureDescriptorFactory.createInlineConstantDescriptor(project, description, comment.asString(), arguments, flags); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fSelectionCu)); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString()); //$NON-NLS-1$ arguments.put(ATTRIBUTE_REMOVE, Boolean.valueOf(fRemoveDeclaration).toString()); arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(fReplaceAllReferences).toString()); return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.InlineConstantRefactoring_inline, fChanges); } finally { pm.done(); fChanges= null; } }
Example #24
Source File: RefactoringAvailabilityTester.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static boolean isMoveStaticAvailable(final IMember member) throws JavaModelException { if (!member.exists()) { return false; } final int type = member.getElementType(); if (type != IJavaElement.METHOD && type != IJavaElement.FIELD && type != IJavaElement.TYPE) { return false; } if (JdtFlags.isEnum(member) && type != IJavaElement.TYPE) { return false; } final IType declaring = member.getDeclaringType(); if (declaring == null) { return false; } if (!Checks.isAvailable(member)) { return false; } if (type == IJavaElement.METHOD && declaring.isInterface()) { boolean is18OrHigher = JavaModelUtil.is18OrHigher(member.getJavaProject()); if (!is18OrHigher || !Flags.isStatic(member.getFlags())) { return false; } } if (type == IJavaElement.METHOD && !JdtFlags.isStatic(member)) { return false; } if (type == IJavaElement.METHOD && ((IMethod) member).isConstructor()) { return false; } if (type == IJavaElement.TYPE && !JdtFlags.isStatic(member)) { return false; } if (!declaring.isInterface() && !JdtFlags.isStatic(member)) { return false; } return true; }
Example #25
Source File: SourceMapper.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public int getFlags(IJavaElement element) { switch(element.getElementType()) { case IJavaElement.LOCAL_VARIABLE : LocalVariableElementKey key = new LocalVariableElementKey(element.getParent(), element.getElementName()); if (this.finalParameters != null && this.finalParameters.contains(key)) { return Flags.AccFinal; } } return 0; }
Example #26
Source File: SelfEncapsulateFieldRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException { if (fVisibility < 0) { fVisibility = (fField.getFlags() & (Flags.AccPublic | Flags.AccProtected | Flags.AccPrivate)); } RefactoringStatus result = new RefactoringStatus(); result.merge(Checks.checkAvailability(fField)); if (result.hasFatalError()) { return result; } fRoot = new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL).parse(fField.getCompilationUnit(), true, pm); ISourceRange sourceRange = fField.getNameRange(); ASTNode node = NodeFinder.perform(fRoot, sourceRange.getOffset(), sourceRange.getLength()); if (node == null) { return mappingErrorFound(result, node); } fFieldDeclaration = ASTNodes.getParent(node, VariableDeclarationFragment.class); if (fFieldDeclaration == null) { return mappingErrorFound(result, node); } if (fFieldDeclaration.resolveBinding() == null) { if (!processCompilerError(result, node)) { result.addFatalError(RefactoringCoreMessages.SelfEncapsulateField_type_not_resolveable); } return result; } computeUsedNames(); return result; }
Example #27
Source File: SelfEncapsulateFieldRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private static void checkName(RefactoringStatus status, String name, List<IMethodBinding> usedNames, IType type, boolean reUseExistingField, IField field) { if ("".equals(name)) { //$NON-NLS-1$ status.addFatalError(RefactoringCoreMessages.Checks_Choose_name); return; } boolean isStatic = false; try { isStatic = Flags.isStatic(field.getFlags()); } catch (JavaModelException e) { JavaLanguageServerPlugin.log(e); } status.merge(Checks.checkMethodName(name, field)); for (Iterator<IMethodBinding> iter = usedNames.iterator(); iter.hasNext();) { IMethodBinding method = iter.next(); String selector = method.getName(); if (selector.equals(name)) { if (!reUseExistingField) { status.addFatalError(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_method_exists, new String[] { BindingLabelProviderCore.getBindingLabel(method, JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(type.getElementName()) })); } else { boolean methodIsStatic = Modifier.isStatic(method.getModifiers()); if (methodIsStatic && !isStatic) { status.addWarning(Messages.format(RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_static_method_but_nonstatic_field, new String[] { BasicElementLabels.getJavaElementName(method.getName()), BasicElementLabels.getJavaElementName(field.getElementName()) })); } if (!methodIsStatic && isStatic) { status.addFatalError(Messages.format(RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_nonstatic_method_but_static_field, new String[] { BasicElementLabels.getJavaElementName(method.getName()), BasicElementLabels.getJavaElementName(field.getElementName()) })); } return; } } } if (reUseExistingField) { status.addFatalError(Messages.format( RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_methoddoesnotexist_status_fatalError, new String[] { BasicElementLabels.getJavaElementName(name), BasicElementLabels.getJavaElementName(type.getElementName())})); } }
Example #28
Source File: SelfEncapsulateFieldRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private int createModifiers() throws JavaModelException { int result = 0; if (Flags.isPublic(fVisibility)) { result |= Modifier.PUBLIC; } else if (Flags.isProtected(fVisibility)) { result |= Modifier.PROTECTED; } else if (Flags.isPrivate(fVisibility)) { result |= Modifier.PRIVATE; } if (JdtFlags.isStatic(fField)) { result |= Modifier.STATIC; } return result; }
Example #29
Source File: JavaDocLocations.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private static void appendMethodReference(IMethod meth, StringBuffer buf) throws JavaModelException { buf.append(meth.getElementName()); /* * The Javadoc tool for Java SE 8 changed the anchor syntax and now tries to avoid "strange" characters in URLs. * This breaks all clients that directly create such URLs. * We can't know what format is required, so we just guess by the project's compiler compliance. */ boolean is18OrHigher = JavaModelUtil.is18OrHigher(meth.getJavaProject()); buf.append(is18OrHigher ? '-' : '('); String[] params = meth.getParameterTypes(); IType declaringType = meth.getDeclaringType(); boolean isVararg = Flags.isVarargs(meth.getFlags()); int lastParam = params.length - 1; for (int i = 0; i <= lastParam; i++) { if (i != 0) { buf.append(is18OrHigher ? "-" : ", "); //$NON-NLS-1$ //$NON-NLS-2$ } String curr = Signature.getTypeErasure(params[i]); String fullName = JavaModelUtil.getResolvedTypeName(curr, declaringType); if (fullName == null) { // e.g. a type parameter "QE;" fullName = Signature.toString(Signature.getElementType(curr)); } if (fullName != null) { buf.append(fullName); int dim = Signature.getArrayCount(curr); if (i == lastParam && isVararg) { dim--; } while (dim > 0) { buf.append(is18OrHigher ? ":A" : "[]"); //$NON-NLS-1$ //$NON-NLS-2$ dim--; } if (i == lastParam && isVararg) { buf.append("..."); //$NON-NLS-1$ } } } buf.append(is18OrHigher ? '-' : ')'); }
Example #30
Source File: TypeContextChecker.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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; }