public void cleanTargetStorages(BuildTarget<?> target) throws IOException { try { AtomicNotNullLazyValue<BuildTargetStorages> storages = myTargetStorages.remove(target); if (storages != null) { storages.getValue().close(); } } finally { // delete all data except src-out mapping which is cleaned in a special way final File[] targetData = myDataPaths.getTargetDataRoot(target).listFiles(); if (targetData != null) { final File srcOutputMapRoot = getSourceToOutputMapRoot(target); for (File dataFile : targetData) { if (!FileUtil.filesEqual(dataFile, srcOutputMapRoot)) { FileUtil.delete(dataFile); } } } } }
private void closeSourceToOutputStorages() throws IOException { IOException ex = null; try { for (AtomicNotNullLazyValue<SourceToOutputMappingImpl> mapping : mySourceToOutputs.values()) { try { mapping.getValue().close(); } catch (IOException e) { if (ex == null) { ex = e; } } } } finally { mySourceToOutputs.clear(); } if (ex != null) { throw ex; } }
private static <K, V> V fetchValue(ConcurrentMap<K, AtomicNotNullLazyValue<V>> container, K key, final LazyValueFactory<K, V> valueFactory) throws IOException { AtomicNotNullLazyValue<V> lazy = container.get(key); if (lazy == null) { final AtomicNotNullLazyValue<V> newValue = valueFactory.create(key); lazy = container.putIfAbsent(key, newValue); if (lazy == null) { lazy = newValue; // just initialized } } try { return lazy.getValue(); } catch (BuildDataCorruptedException e) { throw e.getCause(); } }
public ClsReferenceListImpl(@NotNull PsiClassReferenceListStub stub) { super(stub); myRefs = new AtomicNotNullLazyValue<ClsJavaCodeReferenceElementImpl[]>() { @NotNull @Override protected ClsJavaCodeReferenceElementImpl[] compute() { String[] strings = getStub().getReferencedNames(); if (strings.length > 0) { ClsJavaCodeReferenceElementImpl[] refs = new ClsJavaCodeReferenceElementImpl[strings.length]; for (int i = 0; i < strings.length; i++) { refs[i] = new ClsJavaCodeReferenceElementImpl(ClsReferenceListImpl.this, strings[i]); } return refs; } else { return EMPTY_REFS_ARRAY; } } }; }
protected ClsMemberImpl(T stub) { super(stub); myDocComment = !isDeprecated() ? null : new AtomicNotNullLazyValue<PsiDocComment>() { @NotNull @Override protected PsiDocComment compute() { return new ClsDocCommentImpl(ClsMemberImpl.this); } }; myNameIdentifier = new AtomicNotNullLazyValue<PsiIdentifier>() { @NotNull @Override protected PsiIdentifier compute() { return new ClsIdentifierImpl(ClsMemberImpl.this, getName()); } }; }
public ClsAnnotationImpl(final PsiAnnotationStub stub) { super(stub); myReferenceElement = new AtomicNotNullLazyValue<ClsJavaCodeReferenceElementImpl>() { @NotNull @Override protected ClsJavaCodeReferenceElementImpl compute() { String annotationText = getStub().getText(); int index = annotationText.indexOf('('); String refText = index > 0 ? annotationText.substring(1, index) : annotationText.substring(1); return new ClsJavaCodeReferenceElementImpl(ClsAnnotationImpl.this, refText); } }; myParameterList = new AtomicNotNullLazyValue<ClsAnnotationParameterListImpl>() { @NotNull @Override protected ClsAnnotationParameterListImpl compute() { PsiNameValuePair[] attrs = getStub().getText().indexOf('(') > 0 ? PsiTreeUtil.getRequiredChildOfType(getStub().getPsiElement(), PsiAnnotationParameterList.class).getAttributes() : PsiNameValuePair.EMPTY_ARRAY; return new ClsAnnotationParameterListImpl(ClsAnnotationImpl.this, attrs); } }; }
public ClsTypeElementImpl(@NotNull PsiElement parent, @NotNull String typeText, char variance) { myParent = parent; myTypeText = TypeInfo.internFrequentType(typeText); myVariance = variance; myChild = new AtomicNullableLazyValue<ClsElementImpl>() { @Override protected ClsElementImpl compute() { return calculateChild(); } }; myCachedType = new AtomicNotNullLazyValue<PsiType>() { @NotNull @Override protected PsiType compute() { return calculateType(); } }; }
@NotNull public NotNullLazyValue<?> getValue() { if (value == null) { value = new AtomicNotNullLazyValue<Object>() { @NotNull @Override protected Object compute() { try { if (service == null) { Class<Object> aClass = findClass(implementation); return asInstance ? instantiate(aClass, ApplicationManager.getApplication().getPicoContainer(), true) : aClass; } else { return ServiceManager.getService(findClass(service)); } } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } }; } return value; }
private static <K, V> V fetchValue(ConcurrentMap<K, AtomicNotNullLazyValue<V>> container, K key, final LazyValueFactory<K, V> valueFactory) throws IOException { AtomicNotNullLazyValue<V> lazy = container.get(key); if (lazy == null) { final AtomicNotNullLazyValue<V> newValue = valueFactory.create(key); lazy = container.putIfAbsent(key, newValue); if (lazy == null) { lazy = newValue; // just initialized } } try { return lazy.getValue(); } catch (RuntimeException e) { final Throwable cause = e.getCause(); if (cause instanceof IOException) { throw (IOException)cause; } throw e; } }
public ClsAnnotationImpl(final PsiAnnotationStub stub) { super(stub); myReferenceElement = new AtomicNotNullLazyValue<ClsJavaCodeReferenceElementImpl>() { @NotNull @Override protected ClsJavaCodeReferenceElementImpl compute() { String text = PsiTreeUtil.getRequiredChildOfType(getStub().getPsiElement(), PsiJavaCodeReferenceElement.class).getText(); return new ClsJavaCodeReferenceElementImpl(ClsAnnotationImpl.this, text); } }; myParameterList = new AtomicNotNullLazyValue<ClsAnnotationParameterListImpl>() { @NotNull @Override protected ClsAnnotationParameterListImpl compute() { PsiAnnotationParameterList paramList = PsiTreeUtil.getRequiredChildOfType(getStub().getPsiElement(), PsiAnnotationParameterList.class); return new ClsAnnotationParameterListImpl(ClsAnnotationImpl.this, paramList.getAttributes()); } }; }
public ClsTypeElementImpl(@NotNull PsiElement parent, @NotNull String typeText, char variance) { myParent = parent; myTypeText = TypeInfo.internFrequentType(typeText); myVariance = variance; myChild = new VolatileNullableLazyValue<ClsElementImpl>() { @Nullable @Override protected ClsElementImpl compute() { return calculateChild(); } }; myCachedType = new AtomicNotNullLazyValue<PsiType>() { @NotNull @Override protected PsiType compute() { return calculateType(); } }; }
protected ConfigurableEP(PicoContainer picoContainer, @Nullable Project project) { myProject = project; myPicoContainer = picoContainer; myFactory = new AtomicNotNullLazyValue<NullableFactory<T>>() { @NotNull @Override protected NullableFactory<T> compute() { if (providerClass != null) { return new InstanceFromProviderFactory(); } else if (instanceClass != null) { return new NewInstanceFactory(); } else if (implementationClass != null) { return new ImplementationFactory(); } throw new RuntimeException(); } }; }
protected ConfigurableEP(PicoContainer picoContainer, @Nullable Project project) { myProject = project; myPicoContainer = picoContainer; myFactory = new AtomicNotNullLazyValue<NullableFactory<T>>() { @Nonnull @Override protected NullableFactory<T> compute() { if (providerClass != null) { return new InstanceFromProviderFactory(); } else if (instanceClass != null) { return new NewInstanceFactory(); } else if (implementationClass != null) { return new ImplementationFactory(); } throw new RuntimeException(); } }; }
public ClsReferenceListImpl(@NotNull PsiClassReferenceListStub stub) { super(stub); myRefs = new AtomicNotNullLazyValue<ClsJavaCodeReferenceElementImpl[]>() { @NotNull @Override protected ClsJavaCodeReferenceElementImpl[] compute() { String[] strings = getStub().getReferencedNames(); if(strings.length > 0) { ClsJavaCodeReferenceElementImpl[] refs = new ClsJavaCodeReferenceElementImpl[strings.length]; for(int i = 0; i < strings.length; i++) { refs[i] = new ClsJavaCodeReferenceElementImpl(ClsReferenceListImpl.this, strings[i]); } return refs; } else { return EMPTY_REFS_ARRAY; } } }; }
protected ClsMemberImpl(T stub) { super(stub); myDocComment = !stub.isDeprecated() ? null : new AtomicNotNullLazyValue<PsiDocComment>() { @NotNull @Override protected PsiDocComment compute() { return new ClsDocCommentImpl(ClsMemberImpl.this); } }; myNameIdentifier = new AtomicNotNullLazyValue<PsiIdentifier>() { @NotNull @Override protected PsiIdentifier compute() { return new ClsIdentifierImpl(ClsMemberImpl.this, getName()); } }; }
public ClsPackageAccessibilityStatementImpl(PsiPackageAccessibilityStatementStub stub) { super(stub); myPackageReference = new AtomicNullableLazyValue<PsiJavaCodeReferenceElement>() { @Override protected PsiJavaCodeReferenceElement compute() { String packageName = getPackageName(); return packageName != null ? new ClsJavaCodeReferenceElementImpl(ClsPackageAccessibilityStatementImpl.this, packageName) : null; } }; myModuleReferences = new AtomicNotNullLazyValue<Iterable<PsiJavaModuleReferenceElement>>() { @NotNull @Override protected Iterable<PsiJavaModuleReferenceElement> compute() { return ContainerUtil.map(getStub().getTargets(), target -> new ClsJavaModuleReferenceElementImpl(ClsPackageAccessibilityStatementImpl.this, target)); } }; }
@Override public AtomicNotNullLazyValue<SourceToOutputMappingImpl> create(final BuildTarget<?> key) { return new AtomicNotNullLazyValue<SourceToOutputMappingImpl>() { @NotNull @Override protected SourceToOutputMappingImpl compute() { try { return new SourceToOutputMappingImpl(new File(getSourceToOutputMapRoot(key), "data")); } catch (IOException e) { throw new BuildDataCorruptedException(e); } } }; }
@Override public AtomicNotNullLazyValue<BuildTargetStorages> create(final BuildTarget<?> target) { return new AtomicNotNullLazyValue<BuildTargetStorages>() { @NotNull @Override protected BuildTargetStorages compute() { return new BuildTargetStorages(target, myDataPaths); } }; }
public void flush(boolean memoryCachesOnly) { myTargetStoragesOwner.flush(memoryCachesOnly); for (AtomicNotNullLazyValue<SourceToOutputMappingImpl> mapping : mySourceToOutputs.values()) { mapping.getValue().flush(memoryCachesOnly); } myOutputToTargetRegistry.flush(memoryCachesOnly); mySrcToFormMap.flush(memoryCachesOnly); final Mappings mappings = myMappings; if (mappings != null) { synchronized (mappings) { mappings.flush(memoryCachesOnly); } } }
public void closeSourceToOutputStorages(Collection<BuildTargetChunk> chunks) throws IOException { for (BuildTargetChunk chunk : chunks) { for (BuildTarget<?> target : chunk.getTargets()) { final AtomicNotNullLazyValue<SourceToOutputMappingImpl> mapping = mySourceToOutputs.remove(target); if (mapping != null) { mapping.getValue().close(); } } } }
protected ConfigurableEP(PicoContainer picoContainer, @Nullable Project project) { myProject = project; myPicoContainer = picoContainer; myProducer = new AtomicNotNullLazyValue<ObjectProducer>() { @NotNull @Override protected ObjectProducer compute() { try { if (providerClass != null) { return new ProviderProducer((ConfigurableProvider)instantiate(providerClass, myPicoContainer)); } if (instanceClass != null) { return new ClassProducer(myPicoContainer, findClass(instanceClass)); } if (implementationClass != null) { return new ClassProducer(myPicoContainer, findClass(implementationClass)); } throw new RuntimeException("configurable class name is not set"); } catch (AssertionError error) { LOG.error(error); } catch (LinkageError error) { LOG.error(error); } catch (Exception exception) { LOG.error(exception); } return new ObjectProducer(); } }; }
@Override public AtomicNotNullLazyValue<SourceToOutputMappingImpl> create(final BuildTarget<?> key) { return new AtomicNotNullLazyValue<SourceToOutputMappingImpl>() { @NotNull @Override protected SourceToOutputMappingImpl compute() { try { return new SourceToOutputMappingImpl(new File(getSourceToOutputMapRoot(key), "data")); } catch (IOException e) { throw new RuntimeException(e); } } }; }
public void flush(boolean memoryCachesOnly) { myTargetStoragesOwner.flush(memoryCachesOnly); for (AtomicNotNullLazyValue<SourceToOutputMappingImpl> mapping : mySourceToOutputs.values()) { mapping.getValue().flush(memoryCachesOnly); } mySrcToFormMap.flush(memoryCachesOnly); final Mappings mappings = myMappings; if (mappings != null) { synchronized (mappings) { mappings.flush(memoryCachesOnly); } } }
public ClsRequiresStatementImpl(PsiRequiresStatementStub stub) { super(stub); myModuleReference = new AtomicNotNullLazyValue<PsiJavaModuleReferenceElement>() { @NotNull @Override protected PsiJavaModuleReferenceElement compute() { return new ClsJavaModuleReferenceElementImpl(ClsRequiresStatementImpl.this, getStub().getModuleName()); } }; }
AtomicNotNullLazyValue<V> create(K key);