Java Code Examples for org.eclipse.jdt.core.dom.IExtendedModifier#isAnnotation()
The following examples show how to use
org.eclipse.jdt.core.dom.IExtendedModifier#isAnnotation() .
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: UMLModelASTReader.java From RefactoringMiner with MIT License | 6 votes |
private void processModifiers(CompilationUnit cu, String sourceFile, AbstractTypeDeclaration typeDeclaration, UMLClass umlClass) { int modifiers = typeDeclaration.getModifiers(); if((modifiers & Modifier.ABSTRACT) != 0) umlClass.setAbstract(true); if((modifiers & Modifier.PUBLIC) != 0) umlClass.setVisibility("public"); else if((modifiers & Modifier.PROTECTED) != 0) umlClass.setVisibility("protected"); else if((modifiers & Modifier.PRIVATE) != 0) umlClass.setVisibility("private"); else umlClass.setVisibility("package"); List<IExtendedModifier> extendedModifiers = typeDeclaration.modifiers(); for(IExtendedModifier extendedModifier : extendedModifiers) { if(extendedModifier.isAnnotation()) { Annotation annotation = (Annotation)extendedModifier; umlClass.addAnnotation(new UMLAnnotation(cu, sourceFile, annotation)); } } }
Example 2
Source File: VariableDeclaration.java From RefactoringMiner with MIT License | 6 votes |
public VariableDeclaration(CompilationUnit cu, String filePath, SingleVariableDeclaration fragment) { this.annotations = new ArrayList<UMLAnnotation>(); List<IExtendedModifier> extendedModifiers = fragment.modifiers(); for(IExtendedModifier extendedModifier : extendedModifiers) { if(extendedModifier.isAnnotation()) { Annotation annotation = (Annotation)extendedModifier; this.annotations.add(new UMLAnnotation(cu, filePath, annotation)); } } this.locationInfo = new LocationInfo(cu, filePath, fragment, extractVariableDeclarationType(fragment)); this.variableName = fragment.getName().getIdentifier(); this.initializer = fragment.getInitializer() != null ? new AbstractExpression(cu, filePath, fragment.getInitializer(), CodeElementType.VARIABLE_DECLARATION_INITIALIZER) : null; Type astType = extractType(fragment); this.type = UMLType.extractTypeObject(cu, filePath, astType, fragment.getExtraDimensions()); int startOffset = fragment.getStartPosition(); ASTNode scopeNode = getScopeNode(fragment); int endOffset = scopeNode.getStartPosition() + scopeNode.getLength(); this.scope = new VariableScope(cu, filePath, startOffset, endOffset); }
Example 3
Source File: ModifierRewrite.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public void copyAllAnnotations(ASTNode otherDecl, TextEditGroup editGroup) { ListRewrite modifierList = evaluateListRewrite(fModifierRewrite.getASTRewrite(), otherDecl); List<IExtendedModifier> originalList = modifierList.getOriginalList(); for (Iterator<IExtendedModifier> iterator = originalList.iterator(); iterator.hasNext();) { IExtendedModifier modifier = iterator.next(); if (modifier.isAnnotation()) { fModifierRewrite.insertLast(fModifierRewrite.getASTRewrite().createCopyTarget((Annotation) modifier), editGroup); } } }
Example 4
Source File: MethodUtils.java From api-mining with GNU General Public License v3.0 | 5 votes |
public static boolean hasOverrideAnnotation(final MethodDeclaration node) { final List modifiers = node.modifiers(); for (final Object mod : modifiers) { final IExtendedModifier modifier = (IExtendedModifier) mod; if (modifier.isAnnotation()) { final Annotation annotation = (Annotation) modifier; if (annotation.getTypeName().toString().equals("Override")) { return true; } } } return false; }
Example 5
Source File: SharedUtils.java From txtUML with Eclipse Public License 1.0 | 5 votes |
/** * @return the annotation node if it is present on the declaration or null */ public static Annotation obtainAnnotation(BodyDeclaration declaration, Class<?> annotationClass) { for (Object mod : declaration.modifiers()) { IExtendedModifier modifier = (IExtendedModifier) mod; if (modifier.isAnnotation()) { Annotation annotation = (Annotation) modifier; if (identicalAnnotations(annotation, annotationClass)) { return annotation; } } } return null; }
Example 6
Source File: SharedUtils.java From txtUML with Eclipse Public License 1.0 | 5 votes |
public static IAnnotationBinding obtainAnnotationBinding(BodyDeclaration declaration, Class<?> annotationClass) { for (Object mod : declaration.modifiers()) { IExtendedModifier modifier = (IExtendedModifier) mod; if (modifier.isAnnotation()) { Annotation annotation = (Annotation) modifier; if (identicalAnnotations(annotation, annotationClass)) { return annotation.resolveAnnotationBinding(); } } } return null; }
Example 7
Source File: MethodUtils.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static boolean hasOverrideAnnotation(final MethodDeclaration node) { final List modifiers = node.modifiers(); for (final Object mod : modifiers) { final IExtendedModifier modifier = (IExtendedModifier) mod; if (modifier.isAnnotation()) { final Annotation annotation = (Annotation) modifier; if (annotation.getTypeName().toString().equals("Override")) { return true; } } } return false; }
Example 8
Source File: ExtractClassRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public void fieldCreated(CompilationUnitRewrite cuRewrite, FieldDeclaration field, ParameterInfo pi) { FieldInfo fieldInfo= getFieldInfo(pi.getOldName()); FieldDeclaration parent= (FieldDeclaration) fieldInfo.declaration.getParent(); List<IExtendedModifier> modifiers= parent.modifiers(); ListRewrite listRewrite= cuRewrite.getASTRewrite().getListRewrite(field, FieldDeclaration.MODIFIERS2_PROPERTY); for (Iterator<IExtendedModifier> iterator= modifiers.iterator(); iterator.hasNext();) { IExtendedModifier mod= iterator.next(); //Temporarily disabled until initialization of final fields is handled correctly // if (mod.isModifier()) { // Modifier modifier= (Modifier) mod; // if (modifier.isFinal()) // listRewrite.insertLast(moveNode(cuRewrite, modifier), null); // } if (mod.isAnnotation()) { listRewrite.insertFirst(moveNode(cuRewrite, (ASTNode) mod), null); } } if (fieldInfo.initializer != null && fieldInfo.hasFieldReference()) { List<VariableDeclarationFragment> fragments= field.fragments(); for (Iterator<VariableDeclarationFragment> iterator= fragments.iterator(); iterator.hasNext();) { VariableDeclarationFragment vdf= iterator.next(); vdf.setInitializer((Expression) moveNode(cuRewrite, fieldInfo.initializer)); } } if (parent.getJavadoc() != null) { field.setJavadoc((Javadoc) moveNode(cuRewrite, parent.getJavadoc())); } }
Example 9
Source File: ModifierRewrite.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void copyAllAnnotations(ASTNode otherDecl, TextEditGroup editGroup) { ListRewrite modifierList= evaluateListRewrite(fModifierRewrite.getASTRewrite(), otherDecl); List<IExtendedModifier> originalList= modifierList.getOriginalList(); for (Iterator<IExtendedModifier> iterator= originalList.iterator(); iterator.hasNext();) { IExtendedModifier modifier= iterator.next(); if (modifier.isAnnotation()) { fModifierRewrite.insertLast(fModifierRewrite.getASTRewrite().createCopyTarget((Annotation) modifier), editGroup); } } }
Example 10
Source File: MethodUtils.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static boolean hasOverrideAnnotation(final MethodDeclaration node) { final List modifiers = node.modifiers(); for (final Object mod : modifiers) { final IExtendedModifier modifier = (IExtendedModifier) mod; if (modifier.isAnnotation()) { final Annotation annotation = (Annotation) modifier; if (annotation.getTypeName().toString().equals("Override")) { return true; } } } return false; }
Example 11
Source File: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Creates the necessary changes to create the delegate method with the * original method body. * * @param document * the buffer containing the source of the source compilation * unit * @param declaration * the method declaration to use as source * @param rewrite * the ast rewrite to use for the copy of the method body * @param rewrites * the compilation unit rewrites * @param adjustments * the map of elements to visibility adjustments * @param status * the refactoring status * @param monitor * the progress monitor to display progress * @throws CoreException * if an error occurs */ protected void createMethodCopy(IDocument document, MethodDeclaration declaration, ASTRewrite rewrite, Map<ICompilationUnit, CompilationUnitRewrite> rewrites, Map<IMember, IncomingMemberVisibilityAdjustment> adjustments, RefactoringStatus status, IProgressMonitor monitor) throws CoreException { Assert.isNotNull(document); Assert.isNotNull(declaration); Assert.isNotNull(rewrite); Assert.isNotNull(rewrites); Assert.isNotNull(adjustments); Assert.isNotNull(status); Assert.isNotNull(monitor); final CompilationUnitRewrite rewriter= getCompilationUnitRewrite(rewrites, getTargetType().getCompilationUnit()); try { rewrite.set(declaration, MethodDeclaration.NAME_PROPERTY, rewrite.getAST().newSimpleName(fMethodName), null); boolean same= false; final IMethodBinding binding= declaration.resolveBinding(); if (binding != null) { final ITypeBinding declaring= binding.getDeclaringClass(); if (declaring != null && Bindings.equals(declaring.getPackage(), fTarget.getType().getPackage())) same= true; final Modifier.ModifierKeyword keyword= same ? null : Modifier.ModifierKeyword.PUBLIC_KEYWORD; ModifierRewrite modifierRewrite= ModifierRewrite.create(rewrite, declaration); if (JdtFlags.isDefaultMethod(binding) && getTargetType().isClass()) { // Remove 'default' modifier and add 'public' visibility modifierRewrite.setVisibility(Modifier.PUBLIC, null); modifierRewrite.setModifiers(Modifier.NONE, Modifier.DEFAULT, null); } else if (!JdtFlags.isDefaultMethod(binding) && getTargetType().isInterface()) { // Remove visibility modifiers and add 'default' modifierRewrite.setModifiers(Modifier.DEFAULT, Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE, null); } else if (MemberVisibilityAdjustor.hasLowerVisibility(binding.getModifiers(), same ? Modifier.NONE : keyword == null ? Modifier.NONE : keyword.toFlagValue()) && MemberVisibilityAdjustor.needsVisibilityAdjustments(fMethod, keyword, adjustments)) { final MemberVisibilityAdjustor.IncomingMemberVisibilityAdjustment adjustment= new MemberVisibilityAdjustor.IncomingMemberVisibilityAdjustment(fMethod, keyword, RefactoringStatus.createStatus(RefactoringStatus.WARNING, Messages.format(RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_method_warning, new String[] { MemberVisibilityAdjustor.getLabel(fMethod), MemberVisibilityAdjustor.getLabel(keyword) }), JavaStatusContext.create(fMethod), null, RefactoringStatusEntry.NO_CODE, null)); modifierRewrite.setVisibility(keyword == null ? Modifier.NONE : keyword.toFlagValue(), null); adjustment.setNeedsRewriting(false); adjustments.put(fMethod, adjustment); } } for (IExtendedModifier modifier : (List<IExtendedModifier>) declaration.modifiers()) { if (modifier.isAnnotation()) { Annotation annotation= (Annotation) modifier; ITypeBinding typeBinding= annotation.resolveTypeBinding(); if (typeBinding != null && typeBinding.getQualifiedName().equals("java.lang.Override")) { //$NON-NLS-1$ rewrite.remove(annotation, null); } } } createMethodArguments(rewrites, rewrite, declaration, adjustments, status); createMethodTypeParameters(rewrite, declaration, status); createMethodComment(rewrite, declaration); createMethodBody(rewriter, rewrite, declaration); } finally { if (fMethod.getCompilationUnit().equals(getTargetType().getCompilationUnit())) rewriter.clearImportRewrites(); } }