List of usage examples for org.eclipse.jdt.core.dom Modifier isAbstract
public static boolean isAbstract(int flags)
From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
public static boolean isDefaultMethod(IMethodBinding method) { int modifiers = method.getModifiers(); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=405517#c7 ITypeBinding declaringClass = method.getDeclaringClass(); if (declaringClass.isInterface()) { return !Modifier.isAbstract(modifiers) && !Modifier.isStatic(modifiers); }/*from ww w . j a v a 2 s. c om*/ return false; }
From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
public static boolean isAbstract(IMethodBinding member) { return Modifier.isAbstract(member.getModifiers()); }
From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java
License:Open Source License
@Override public boolean visit(TypeDeclaration type) { if (!Modifier.isPublic(type.getModifiers())) { // non-public types cannot be (or have nested) components if (errorLevel.isNone()) return false; Annotation annotation = findComponentAnnotation(type); if (annotation != null) reportProblem(annotation, null, problems, NLS.bind(Messages.AnnotationProcessor_invalidComponentImplementationClass, type.getName().getIdentifier()), type.getName().getIdentifier()); return true; }//www . j a v a2s . co m Annotation annotation = findComponentAnnotation(type); if (annotation != null) { if (type.isInterface() || Modifier.isAbstract(type.getModifiers()) || (!type.isPackageMemberTypeDeclaration() && !isNestedPublicStatic(type)) || !hasDefaultConstructor(type)) { // interfaces, abstract types, non-static/non-public nested types, or types with no default constructor cannot be components reportProblem(annotation, null, problems, NLS.bind(Messages.AnnotationProcessor_invalidComponentImplementationClass, type.getName().getIdentifier()), type.getName().getIdentifier()); } else { ITypeBinding typeBinding = type.resolveBinding(); if (typeBinding == null) { if (debug.isDebugging()) debug.trace(String.format("Unable to resolve binding for type: %s", type)); //$NON-NLS-1$ } else { IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding(); if (annotationBinding == null) { if (debug.isDebugging()) debug.trace(String.format("Unable to resolve binding for annotation: %s", annotation)); //$NON-NLS-1$ } else { IDSModel model = processComponent(type, typeBinding, annotation, annotationBinding, problems); models.add(model); } } } } return true; }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
private void addCallRelation(final ASTNode pNode, final IMethodBinding pBinding, final boolean pStatic) { // assert( pBinding != null ); TODO if (this.aCurrMethod == null) // constructors calling itself. Ignore it. return;/*from w ww .ja v a 2 s. c o m*/ // lAcceptor could be a Java.util method if (pBinding == null) return; final IElement lAcceptor = ASTCrawler.convertBinding(pBinding); final IElement lCaller = this.aCurrMethod; // lCaller instanceof IClassElement // lAcceptor instanceof IMethodElement int lModifiers = pBinding.getModifiers(); if (pBinding.getDeclaringClass().isInterface() || Modifier.isAbstract(lModifiers)) lModifiers = lModifiers | ASTCrawler.ABSTRACT_FLAG; this.aDB.addElement(lAcceptor, lModifiers); if (pStatic) this.aDB.addRelationAndTranspose(lCaller, Relation.STATIC_CALLS, lAcceptor); else this.aDB.addRelationAndTranspose(lCaller, Relation.CALLS, lAcceptor); }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
private void saveMethodRelation(final IMethodBinding pMBinding) { if (this.aCurrMethod != null) this.aCurrMethodReminder.push(this.aCurrMethod); this.aCurrMethod = (MethodElement) ASTCrawler.convertBinding(pMBinding); int lModifiers = pMBinding.getModifiers(); if (pMBinding.getDeclaringClass().isInterface() || Modifier.isAbstract(lModifiers)) lModifiers = lModifiers | ASTCrawler.ABSTRACT_FLAG; this.aDB.addElement(this.aCurrMethod, lModifiers); }
From source file:ca.mcgill.cs.swevo.jayfx.JayFX.java
License:Open Source License
/** * Initializes the program database with information about relations between * all the source elements in pProject and all of its dependent projects. * // www .j a v a 2s. co m * @param pProject * The project to analyze. Should never be null. * @param pProgress * A progress monitor. Can be null. * @param pCHA * Whether to calculate overriding relationships between methods * and to use these in the calculation of CALLS and CALLS_BY * relations. * @throws JayFXException * If the method cannot complete correctly * @throws ConversionException * @throws ElementNotFoundException * @throws JavaModelException */ @SuppressWarnings({ "restriction", "unchecked" }) public void initialize(final Collection<? extends IProject> pProjectCol, final IProgressMonitor pProgress, boolean pCHA, TimeCollector timeCollector) throws JayFXException, ElementNotFoundException, ConversionException, JavaModelException { this.aCHAEnabled = pCHA; // Collect all target classes final List<ICompilationUnit> lTargets = new ArrayList<ICompilationUnit>(); for (final IProject pProject : pProjectCol) for (final IJavaProject lNext : JayFX.getJavaProjects(pProject)) lTargets.addAll(JayFX.getCompilationUnits(lNext)); // Process all the target classes final ASTCrawler lAnalyzer = new ASTCrawler(this.aDB, this.aConverter); if (pProgress != null) pProgress.beginTask("Building program database", lTargets.size()); int successfullyAnalyzedCompilationUnits = lTargets.size(); for (final ICompilationUnit lCU : lTargets) { try { final IPackageDeclaration[] lPDs = lCU.getPackageDeclarations(); if (lPDs.length > 0) this.aPackages.add(lPDs[0].getElementName()); } catch (final JavaModelException lException) { if (pProgress != null) pProgress.done(); throw new JayFXException(lException); } // try to analyze the compilation unit. try { lAnalyzer.analyze(lCU, timeCollector); } catch (Exception e) { System.err.println( "Failed to analyze compilation unit: " + lCU.getElementName() + ". Skipping ..." + e); successfullyAnalyzedCompilationUnits--; } if (pProgress != null) pProgress.worked(1); } System.out.println("Successfully analyzed " + successfullyAnalyzedCompilationUnits + "/" + lTargets.size() + " compilation units."); /* * int lSize = lTargets.size(); int k = 0; for( Iterator i = * lTargets.iterator(); i.hasNext(); ) { k++; ICompilationUnit lCU = * (ICompilationUnit)i.next(); try { IPackageDeclaration[] lPDs = * lCU.getPackageDeclarations(); if( lPDs.length > 0 ) { aPackages.add( * lPDs[0].getElementName() ); } } catch( JavaModelException pException * ) { throw new JavaDBException( pException ); } lAnalyzer.analyze( lCU * ); if( pProgress != null ) pProgress.worked(1); * * System.out.println( k + "/" + lSize ); if( k == 1414 ) { * System.out.println( k + "/" + lSize ); } } */ if (!pCHA) // if (pProgress != null) // pProgress.done(); return; // Process the class hierarchy analysis if (pProgress != null) pProgress.beginTask("Performing class hierarchy analysis", this.aDB.getAllElements().size()); final Set<IElement> lToProcess = new HashSet<IElement>(); lToProcess.addAll(this.aDB.getAllElements()); // int lSize = aDB.getAllElements().size(); // k = 0; while (lToProcess.size() > 0) { // k++; final IElement lNext = lToProcess.iterator().next(); lToProcess.remove(lNext); if (lNext.getCategory() == Category.METHOD) if (!this.isAbstractMethod(lNext)) { final Set<IElement> lOverrides = this.getOverridenMethods(lNext); for (final IElement lMethod : lOverrides) { if (!this.isProjectElement(lMethod)) { int lModifiers = 0; try { final IJavaElement lElement = this.convertToJavaElement(lMethod); if (lElement instanceof IMember) { lModifiers = ((IMember) lElement).getFlags(); if (Modifier.isAbstract(lModifiers)) lModifiers += 16384; } } catch (final ConversionException lException) { // Ignore, the modifiers used is 0 } catch (final JavaModelException lException) { // Ignore, the modifierds used is 0 } this.aDB.addElement(lMethod, lModifiers); } this.aDB.addRelationAndTranspose(lNext, Relation.OVERRIDES, lMethod); } /* * for( Iterator j = lOverrides.iterator(); j.hasNext(); ) { * IElement lMethod = (IElement)j.next(); if( * !isProjectElement( lMethod )) { int lModifiers = 0; try { * IJavaElement lElement = convertToJavaElement( lMethod ); * if( lElement instanceof IMember ) { lModifiers = * ((IMember)lElement).getFlags(); if( Modifier.isAbstract( * lModifiers )) { lModifiers += 16384; } } } catch( * ConversionException pException ) { // Ignore, the * modifiers used is 0 } catch( JavaModelException * pException ) { // Ignore, the modifiers used is 0 } * aDB.addElement( lMethod, lModifiers ); } * aDB.addRelationAndTranspose( lNext, Relation.OVERRIDES, * lMethod ); } */ } pProgress.worked(1); // System.out.println( k + "/" + lSize ); } // process the aspects, if any. // if ( AspectJPlugin.isAJProject(pProject)) { // AjASTCrawler aspectAnalyzer = new AjASTCrawler( aDB, aConverter ); // if( pProgress != null ) pProgress.subTask("Analyzing aspects."); // // AjBuildManager.setAsmHierarchyBuilder(aspectAnalyzer); // try { // pProject.open(pProgress); // } catch (CoreException e) { // throw new JayFXException( "Could not open project ", e); // } // // try { // pProject.build(IncrementalProjectBuilder.FULL_BUILD, pProgress); // } catch (CoreException e) { // throw new JayFXException( "Could not build project ", e); // } // } // pProgress.done(); }
From source file:cc.kave.eclipse.commons.analysis.transformer.DeclarationVisitor.java
License:Apache License
private void methodDeclHelper(MethodDeclaration decl) { if (decl != null) { MethodName methodName = (MethodName) NodeFactory.createNodeName(decl); // if (!isNestedDeclaration(methodName, context)) { cc.kave.commons.model.ssts.impl.declarations.MethodDeclaration sstDecl = new cc.kave.commons.model.ssts.impl.declarations.MethodDeclaration(); sstDecl.setName(methodName);//www. j av a 2 s . c o m sstDecl.setEntryPoint(entryPoints.contains(methodName)); context.getMethods().add(sstDecl); if (decl == marker.getAffectedNode()) { ExpressionStatement expStatement = new ExpressionStatement(); expStatement.setExpression(new CompletionExpression()); sstDecl.getBody().add(expStatement); } if (!Modifier.isAbstract(decl.getModifiers())) { BodyVisitor bodyVisitor = new BodyVisitor(new UniqueVariableNameGenerator(), marker, new ArrayList<IStatement>()); decl.accept(bodyVisitor); } } // } }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
/** * Appends the text representation of the given modifier flags, followed by * a single space. Used for JLS2 modifiers. * /*from w ww . jav a2s.co m*/ * @param modifiers * the modifier flags */ void printModifiers(int modifiers) { if (Modifier.isPublic(modifiers)) { this.buffer.append("public ");//$NON-NLS-1$ } if (Modifier.isProtected(modifiers)) { this.buffer.append("protected ");//$NON-NLS-1$ } if (Modifier.isPrivate(modifiers)) { this.buffer.append("private ");//$NON-NLS-1$ } if (Modifier.isStatic(modifiers)) { this.buffer.append("static ");//$NON-NLS-1$ } if (Modifier.isAbstract(modifiers)) { this.buffer.append("abstract ");//$NON-NLS-1$ } if (Modifier.isFinal(modifiers)) { this.buffer.append("final ");//$NON-NLS-1$ } if (Modifier.isSynchronized(modifiers)) { this.buffer.append("synchronized ");//$NON-NLS-1$ } if (Modifier.isVolatile(modifiers)) { this.buffer.append("volatile ");//$NON-NLS-1$ } if (Modifier.isNative(modifiers)) { this.buffer.append("native ");//$NON-NLS-1$ } if (Modifier.isStrictfp(modifiers)) { this.buffer.append("strictfp ");//$NON-NLS-1$ } if (Modifier.isTransient(modifiers)) { this.buffer.append("transient ");//$NON-NLS-1$ } }
From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.JavaSyncUtils.java
License:Open Source License
/** * Updates java code according to the model value for abstract or static modifiers * //ww w . ja v a2 s . com * @author Luiza * @param bd <code>{@link BodyDeclaration}</code> for a class, method or field. * @param isTrue value for the modifier * @param modifier flag indicating the modifier to update. * This should be one of the predefined flags: * <ul> * <li>{@link #MODIFIER_ABSTRACT}</li> * <li>{@link #MODIFIER_STATIC}</li> * </ul> * @flowerModelElementId _zVs8cJiOEd6aNMdNFvR5WQ */ @SuppressWarnings("unchecked") public static void updateModifierFromModelToJavaClass(BodyDeclaration bd, boolean isTrue, String modifier) { ModifierKeyword javaModifierFlag = null; ModifierKeyword modelModifierFlag = null; boolean isForAbstractModif = modifier.equals(MODIFIER_ABSTRACT); boolean isForStaticModif = modifier.equals(MODIFIER_STATIC); boolean isForFinalModif = modifier.equals(MODIFIER_FINAL); if (isForAbstractModif) { javaModifierFlag = Modifier.isAbstract(bd.getModifiers()) ? ModifierKeyword.ABSTRACT_KEYWORD : null; modelModifierFlag = isTrue ? ModifierKeyword.ABSTRACT_KEYWORD : null; } else if (isForStaticModif) { javaModifierFlag = Modifier.isStatic(bd.getModifiers()) ? ModifierKeyword.STATIC_KEYWORD : null; modelModifierFlag = isTrue ? ModifierKeyword.STATIC_KEYWORD : null; } else if (isForFinalModif) { javaModifierFlag = Modifier.isFinal(bd.getModifiers()) ? ModifierKeyword.FINAL_KEYWORD : null; modelModifierFlag = isTrue ? ModifierKeyword.FINAL_KEYWORD : null; } else throw new IllegalArgumentException( "updateModifierFromModelToJavaClass - can't update java code for modifier " + modifier); //if there are differences between the model and the java file if (modelModifierFlag != javaModifierFlag) { //if this modifier has been set before find it and remove it if (javaModifierFlag != null) { //Modifier toRemove = null; /* * we use bd.modifiers() instead of bd.getModifiers(), which computes a bit-wise integer consisting in all the modifier values * because it also iterates over the modifiers and method bd.setModifiers(modifiers) is deprecated */ for (Iterator<Modifier> it = bd.modifiers().iterator(); it.hasNext();) { Modifier modif = it.next(); if (isForAbstractModif && modif.isAbstract()) { it.remove(); break; } else if (isForStaticModif && modif.isStatic()) { it.remove(); break; } else if (isForFinalModif && modif.isFinal()) { it.remove(); break; } } //bd.modifiers().remove(toRemove); } // add the new modifier value if changes have been made in the model if (modelModifierFlag != null) { Modifier newModif = bd.getAST().newModifier(modelModifierFlag); bd.modifiers().add(newModif); } } }
From source file:com.drgarbage.ast.ASTGraphUtil.java
License:Apache License
private static void appendModifiers(int mod, StringBuffer buf) { if (Modifier.isAbstract(mod)) { buf.append(Modifier.ModifierKeyword.ABSTRACT_KEYWORD.toString()); buf.append(' '); }// w w w.j a v a2 s . co m if (Modifier.isFinal(mod)) { buf.append(Modifier.ModifierKeyword.FINAL_KEYWORD.toString()); buf.append(' '); } if (Modifier.isNative(mod)) { buf.append(Modifier.ModifierKeyword.NATIVE_KEYWORD.toString()); buf.append(' '); } if (Modifier.isPrivate(mod)) { buf.append(Modifier.ModifierKeyword.PRIVATE_KEYWORD.toString()); buf.append(' '); } if (Modifier.isProtected(mod)) { buf.append(Modifier.ModifierKeyword.PROTECTED_KEYWORD.toString()); buf.append(' '); } if (Modifier.isPublic(mod)) { buf.append(Modifier.ModifierKeyword.PUBLIC_KEYWORD.toString()); buf.append(' '); } if (Modifier.isStatic(mod)) { buf.append(Modifier.ModifierKeyword.STATIC_KEYWORD.toString()); buf.append(' '); } if (Modifier.isStrictfp(mod)) { buf.append(Modifier.ModifierKeyword.STRICTFP_KEYWORD.toString()); buf.append(' '); } if (Modifier.isSynchronized(mod)) { buf.append(Modifier.ModifierKeyword.SYNCHRONIZED_KEYWORD.toString()); buf.append(' '); } if (Modifier.isTransient(mod)) { buf.append(Modifier.ModifierKeyword.TRANSIENT_KEYWORD.toString()); buf.append(' '); } if (Modifier.isVolatile(mod)) { buf.append(Modifier.ModifierKeyword.VOLATILE_KEYWORD.toString()); buf.append(' '); } }