List of usage examples for org.eclipse.jdt.core.dom Modifier SYNCHRONIZED
int SYNCHRONIZED
To view the source code for org.eclipse.jdt.core.dom Modifier SYNCHRONIZED.
Click Source Link
From source file:astview.Binding.java
License:Open Source License
private static StringBuffer getModifiersString(int flags, boolean isMethod) { StringBuffer sb = new StringBuffer().append("0x").append(Integer.toHexString(flags)).append(" ("); int prologLen = sb.length(); int rest = flags; rest &= ~appendFlag(sb, flags, Modifier.PUBLIC, "public "); rest &= ~appendFlag(sb, flags, Modifier.PRIVATE, "private "); rest &= ~appendFlag(sb, flags, Modifier.PROTECTED, "protected "); rest &= ~appendFlag(sb, flags, Modifier.STATIC, "static "); rest &= ~appendFlag(sb, flags, Modifier.FINAL, "final "); if (isMethod) { rest &= ~appendFlag(sb, flags, Modifier.SYNCHRONIZED, "synchronized "); rest &= ~appendFlag(sb, flags, Modifier.DEFAULT, "default "); } else {/*from w ww . j av a 2s. c o m*/ rest &= ~appendFlag(sb, flags, Modifier.VOLATILE, "volatile "); rest &= ~appendFlag(sb, flags, Modifier.TRANSIENT, "transient "); } rest &= ~appendFlag(sb, flags, Modifier.NATIVE, "native "); rest &= ~appendFlag(sb, flags, Modifier.ABSTRACT, "abstract "); rest &= ~appendFlag(sb, flags, Modifier.STRICTFP, "strictfp "); if (rest != 0) sb.append("unknown:0x").append(Integer.toHexString(rest)).append(" "); int len = sb.length(); if (len != prologLen) sb.setLength(len - 1); sb.append(")"); return sb; }
From source file:com.google.devtools.j2objc.translate.OcniExtractor.java
License:Apache License
@Override public void endVisit(MethodDeclaration node) { int modifiers = node.getModifiers(); if (Modifier.isNative(modifiers)) { String nativeCode = extractNativeCode(node); if (nativeCode != null) { Block body = new Block(); body.getStatements().add(new NativeStatement(nativeCode)); node.setBody(body);/*from w ww .j a v a 2s. c om*/ node.removeModifiers(Modifier.NATIVE); } } if (Modifier.isSynchronized(modifiers)) { ITypeBinding declaringClass = node.getMethodBinding().getDeclaringClass(); SynchronizedStatement syncStmt = new SynchronizedStatement( Modifier.isStatic(modifiers) ? new TypeLiteral(declaringClass, typeEnv) : new ThisExpression(declaringClass)); syncStmt.setBody(TreeUtil.remove(node.getBody())); Block newBody = new Block(); newBody.getStatements().add(syncStmt); node.setBody(newBody); node.removeModifiers(Modifier.SYNCHRONIZED); } }
From source file:com.ibm.wala.cast.java.translator.jdt.JDT2CAstUtils.java
License:Open Source License
public static Collection<CAstQualifier> mapModifiersToQualifiers(int modifiers, boolean isInterface, boolean isAnnotation) { Set<CAstQualifier> quals = new LinkedHashSet<CAstQualifier>(); if (isInterface) quals.add(CAstQualifier.INTERFACE); if (isAnnotation) quals.add(CAstQualifier.ANNOTATION); if ((modifiers & Modifier.ABSTRACT) != 0) quals.add(CAstQualifier.ABSTRACT); if ((modifiers & Modifier.FINAL) != 0) quals.add(CAstQualifier.FINAL);/*from w ww . j a va 2s . com*/ if ((modifiers & Modifier.NATIVE) != 0) quals.add(CAstQualifier.NATIVE); // if (flags.isPackage()) quals.add(CAstQualifier.PACKAGE); if ((modifiers & Modifier.PRIVATE) != 0) quals.add(CAstQualifier.PRIVATE); if ((modifiers & Modifier.PROTECTED) != 0) quals.add(CAstQualifier.PROTECTED); if ((modifiers & Modifier.PUBLIC) != 0) quals.add(CAstQualifier.PUBLIC); if ((modifiers & Modifier.STATIC) != 0) quals.add(CAstQualifier.STATIC); if ((modifiers & Modifier.STRICTFP) != 0) quals.add(CAstQualifier.STRICTFP); if ((modifiers & Modifier.SYNCHRONIZED) != 0) quals.add(CAstQualifier.SYNCHRONIZED); if ((modifiers & Modifier.TRANSIENT) != 0) quals.add(CAstQualifier.TRANSIENT); if ((modifiers & Modifier.VOLATILE) != 0) quals.add(CAstQualifier.VOLATILE); return quals; }
From source file:org.modeshape.sequencer.javafile.JdtRecorder.java
License:Apache License
/** * <pre>//w ww . j av a2s. c om * MethodDeclaration: * [ Javadoc ] { ExtendedModifier } * [ < TypeParameter { , TypeParameter } > ] * ( Type | void ) Identifier ( * [ FormalParameter * { , FormalParameter } ] ) {[ ] } * [ throws TypeName { , TypeName } ] ( Block | ; ) * * ConstructorDeclaration: * [ Javadoc ] { ExtendedModifier } * [ < TypeParameter { , TypeParameter } > ] * Identifier ( * [ FormalParameter * { , FormalParameter } ] ) * [throws TypeName { , TypeName } ] Block * * </pre> * * @param method the {@link MethodDeclaration method} being recorded (cannot be <code>null</code>) * @param parentNode the parent {@link Node node} (cannot be <code>null</code>) * @throws Exception if there is a problem */ protected void record(final MethodDeclaration method, final Node parentNode) throws Exception { final String name = method.getName().getFullyQualifiedName(); final Node methodNode = parentNode.addNode(name, ClassFileSequencerLexicon.METHOD); methodNode.setProperty(ClassFileSequencerLexicon.NAME, name); { // javadocs final Javadoc javadoc = method.getJavadoc(); if (javadoc != null) { record(javadoc, methodNode); } } { // type parameters @SuppressWarnings("unchecked") final List<TypeParameter> typeParams = method.typeParameters(); if ((typeParams != null) && !typeParams.isEmpty()) { final Node containerNode = methodNode.addNode(ClassFileSequencerLexicon.TYPE_PARAMETERS, ClassFileSequencerLexicon.TYPE_PARAMETERS); for (final TypeParameter param : typeParams) { record(param, containerNode); } } } { // modifiers final int modifiers = method.getModifiers(); methodNode.setProperty(ClassFileSequencerLexicon.ABSTRACT, (modifiers & Modifier.ABSTRACT) != 0); methodNode.setProperty(ClassFileSequencerLexicon.FINAL, (modifiers & Modifier.FINAL) != 0); methodNode.setProperty(ClassFileSequencerLexicon.NATIVE, (modifiers & Modifier.NATIVE) != 0); methodNode.setProperty(ClassFileSequencerLexicon.STATIC, (modifiers & Modifier.STATIC) != 0); methodNode.setProperty(ClassFileSequencerLexicon.STRICT_FP, (modifiers & Modifier.STRICTFP) != 0); methodNode.setProperty(ClassFileSequencerLexicon.SYNCHRONIZED, (modifiers & Modifier.SYNCHRONIZED) != 0); methodNode.setProperty(ClassFileSequencerLexicon.VISIBILITY, getVisibility(modifiers)); } { // annotations @SuppressWarnings("unchecked") final List<IExtendedModifier> modifiers = method.modifiers(); recordAnnotations(modifiers, methodNode); } { // parameters @SuppressWarnings("unchecked") final List<SingleVariableDeclaration> params = method.parameters(); if ((params != null) && !params.isEmpty()) { final Node containerNode = methodNode.addNode(ClassFileSequencerLexicon.METHOD_PARAMETERS, ClassFileSequencerLexicon.PARAMETERS); for (final SingleVariableDeclaration param : params) { record(param, containerNode); } } } { // return type if (method.isConstructor()) { methodNode.setProperty(ClassFileSequencerLexicon.RETURN_TYPE_CLASS_NAME, Void.TYPE.getCanonicalName()); } else { final Type returnType = method.getReturnType2(); methodNode.setProperty(ClassFileSequencerLexicon.RETURN_TYPE_CLASS_NAME, getTypeName(returnType)); record(returnType, ClassFileSequencerLexicon.RETURN_TYPE, methodNode); } } { // thrown exceptions @SuppressWarnings("unchecked") final List<Name> errors = method.thrownExceptions(); if ((errors != null) && !errors.isEmpty()) { final String[] errorNames = new String[errors.size()]; int i = 0; for (final Name error : errors) { errorNames[i++] = error.getFullyQualifiedName(); } methodNode.setProperty(ClassFileSequencerLexicon.THROWN_EXCEPTIONS, errorNames); } } { // body final Block body = method.getBody(); if ((body != null) && (body.statements() != null) && !body.statements().isEmpty()) { final Node bodyNode = methodNode.addNode(ClassFileSequencerLexicon.BODY, ClassFileSequencerLexicon.STATEMENTS); record(body, bodyNode); } } recordSourceReference(method, methodNode); }
From source file:org.smartfrog.tools.eclipse.ui.project.document.BaseComponentCreationWizardPage.java
License:Open Source License
/** * add smartFrog methods to template (memory only) * @param cu/*from w w w . j a v a2 s. c o m*/ * @param unit * @param typeDeclaration * @param methodName * @param needToThrow * @param needParam * @throws CoreException * @throws InterruptedException */ private void addSfDeployMethod(ICompilationUnit cu, CompilationUnit unit, TypeDeclaration typeDeclaration, String methodName, boolean needToThrow, boolean needParam) throws CoreException, InterruptedException { AST localAst = typeDeclaration.getAST(); MethodDeclaration methodDeclaration = localAst.newMethodDeclaration(); methodDeclaration.setConstructor(false); methodDeclaration.setModifiers(Modifier.PUBLIC | Modifier.SYNCHRONIZED); methodDeclaration.setName(localAst.newSimpleName(methodName)); methodDeclaration.setReturnType(localAst.newPrimitiveType(PrimitiveType.VOID)); if (needParam) { SingleVariableDeclaration variableDeclaration = localAst.newSingleVariableDeclaration(); variableDeclaration.setModifiers(Modifier.NONE); variableDeclaration.setType(localAst.newSimpleType(localAst.newSimpleName(TERMINATIONRECORD_VAR))); variableDeclaration.setName(localAst.newSimpleName(SFTERMINATE_STATUS_ARGUMENT_NAME)); methodDeclaration.parameters().add(variableDeclaration); } Block block = localAst.newBlock(); methodDeclaration.setBody(block); SuperMethodInvocation superMethodInvocation = localAst.newSuperMethodInvocation(); superMethodInvocation.setName(localAst.newSimpleName(methodName)); if (needParam) { List list = superMethodInvocation.arguments(); list.add(localAst.newSimpleName(SFTERMINATE_STATUS_ARGUMENT_NAME)); } ExpressionStatement expressionStatement = localAst.newExpressionStatement(superMethodInvocation); block.statements().add(expressionStatement); if (needToThrow) { List throwsExceptions = methodDeclaration.thrownExceptions(); throwsExceptions.add(localAst.newSimpleName(SMARTFROGEXCEPTION_NAME)); throwsExceptions.add(localAst.newSimpleName(REMOTEEXCEPTION_NAME)); } typeDeclaration.bodyDeclarations().add(methodDeclaration); }