List of usage examples for java.util.concurrent.atomic AtomicBoolean AtomicBoolean
public AtomicBoolean()
From source file:com.google.dart.engine.services.internal.refactoring.ExtractMethodRefactoringImpl.java
/** * @return <code>true</code> if the given {@link VariableElement} is referenced after the * {@link #selectionRange}.// w w w . ja v a2s. com */ private boolean isUsedAfterSelection(final VariableElement element) { final AtomicBoolean result = new AtomicBoolean(); parentMember.accept(new GeneralizingASTVisitor<Void>() { @Override public Void visitSimpleIdentifier(SimpleIdentifier node) { VariableElement nodeElement = CorrectionUtils.getLocalVariableElement(node); if (nodeElement == element) { int nodeOffset = node.getOffset(); if (nodeOffset > selectionRange.getEnd()) { result.set(true); } } return null; } }); return result.get(); }
From source file:com.android.tools.idea.tests.gui.gradle.GradleSyncTest.java
@Test public void shouldUseLibrary() throws IOException { guiTest.importSimpleApplication();//from w w w . j ava2s . com IdeFrameFixture ideFrame = guiTest.ideFrame(); Project project = ideFrame.getProject(); // Make sure the library was added. LibraryTable libraryTable = ProjectLibraryTable.getInstance(project); String libraryName = "org.apache.http.legacy-" + TestUtils.getLatestAndroidPlatform(); Library library = libraryTable.getLibraryByName(libraryName); // Verify that the library has the right j VirtualFile[] jarFiles = library.getFiles(CLASSES); assertThat(jarFiles).asList().hasSize(1); VirtualFile jarFile = jarFiles[0]; assertEquals("org.apache.http.legacy.jar", jarFile.getName()); // Verify that the module depends on the library Module appModule = ideFrame.getModule("app"); AtomicBoolean dependencyFound = new AtomicBoolean(); new ReadAction() { @Override protected void run(@NotNull Result result) throws Throwable { ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(appModule).getModifiableModel(); try { for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) { if (orderEntry instanceof LibraryOrderEntry) { LibraryOrderEntry libraryDependency = (LibraryOrderEntry) orderEntry; if (libraryDependency.getLibrary() == library) { dependencyFound.set(true); } } } } finally { modifiableModel.dispose(); } } }.execute(); assertTrue("Module app should depend on library '" + library.getName() + "'", dependencyFound.get()); }
From source file:com.google.dart.java2dart.Context.java
private void dontUseThisInFieldInitializers(CompilationUnit unit) { unit.accept(new RecursiveASTVisitor<Void>() { @Override//from w ww . j a va 2 s .c o m public Void visitClassDeclaration(ClassDeclaration node) { processClass(node); return super.visitClassDeclaration(node); } private void addAssignmentsToBlock(Block block, Map<SimpleIdentifier, Expression> initializers) { int index = 0; for (Entry<SimpleIdentifier, Expression> entry : initializers.entrySet()) { block.getStatements().add(index++, expressionStatement(assignmentExpression( propertyAccess(thisExpression(), entry.getKey()), TokenType.EQ, entry.getValue()))); } } private void processClass(final ClassDeclaration classDeclaration) { final Map<SimpleIdentifier, Expression> thisInitializers = Maps.newLinkedHashMap(); // find field initializers which use "this" classDeclaration.accept(new RecursiveASTVisitor<Void>() { @Override public Void visitVariableDeclaration(VariableDeclaration node) { if (node.getParent().getParent() instanceof FieldDeclaration) { if (hasThisExpression(node)) { thisInitializers.put(node.getName(), node.getInitializer()); node.setInitializer(null); } } return super.visitVariableDeclaration(node); } private boolean hasThisExpression(ASTNode node) { final AtomicBoolean result = new AtomicBoolean(); node.accept(new GeneralizingASTVisitor<Void>() { @Override public Void visitThisExpression(ThisExpression node) { result.set(true); return super.visitThisExpression(node); } }); return result.get(); } }); // add field assignment for each "this" field initializer if (thisInitializers.isEmpty()) { return; } ConstructorDeclaration singleConstructor = null; boolean hasImpl = false; for (ClassMember classMember : classDeclaration.getMembers()) { if (classMember instanceof ConstructorDeclaration) { singleConstructor = (ConstructorDeclaration) classMember; } if (classMember instanceof MethodDeclaration) { MethodDeclaration method = (MethodDeclaration) classMember; String methodName = method.getName().getName(); if (methodName.startsWith("_jtd_constructor_") && methodName.endsWith("_impl")) { hasImpl = true; Block block = ((BlockFunctionBody) method.getBody()).getBlock(); addAssignmentsToBlock(block, thisInitializers); } } } // no "_impl", add assignments to the single constructor if (!hasImpl && singleConstructor != null) { Block block = ((BlockFunctionBody) singleConstructor.getBody()).getBlock(); addAssignmentsToBlock(block, thisInitializers); } // no "_impl", generate default constructor if (singleConstructor == null) { Block block = block(); addAssignmentsToBlock(block, thisInitializers); ConstructorDeclaration constructor = constructorDeclaration(classDeclaration.getName(), null, formalParameterList(), null, blockFunctionBody(block)); classDeclaration.getMembers().add(constructor); } } }); }
From source file:com.microsoft.tfs.core.clients.versioncontrol.internal.localworkspace.BaselineFolderCollection.java
/** * Creates and opens a file with the specified path. If the parent folder * does not exist, we create it and mark it and its parent as hidden -- we * assume that file reside in $tf\10\ and we need to mark both $tf and 10 as * hidden./* w w w . j av a 2 s. c om*/ * * * @param filePath * the path to create the file at * @return * @throws IOException */ public static FileOutputStream createFile(final String filePath) throws IOException { final AtomicBoolean tempCreated = new AtomicBoolean(); return createFile(new AtomicReference<String>(filePath), false, null, tempCreated); }