use of com.intellij.openapi.application.AccessToken in project intellij-plugins by JetBrains.
the class Client method writeDocumentFactory.
/**
* You must rollback block out if this method returns false
*/
private boolean writeDocumentFactory(DocumentInfo documentInfo, Module module, XmlFile psiFile, ProblemsHolder problemsHolder) throws IOException {
final AccessToken token = ReadAction.start();
final int flags;
try {
final JSClass jsClass = XmlBackedJSClassFactory.getXmlBackedClass(psiFile);
assert jsClass != null;
out.writeAmfUtf(jsClass.getQualifiedName());
if (ActionScriptClassResolver.isParentClass(jsClass, FlexCommonTypeNames.SPARK_APPLICATION) || ActionScriptClassResolver.isParentClass(jsClass, FlexCommonTypeNames.MX_APPLICATION)) {
flags = 1;
} else if (ActionScriptClassResolver.isParentClass(jsClass, FlexCommonTypeNames.IUI_COMPONENT)) {
flags = 0;
} else {
flags = 2;
}
} finally {
token.finish();
}
out.write(flags);
Pair<ProjectComponentReferenceCounter, List<RangeMarker>> result = new MxmlWriter(out, problemsHolder, registeredModules.getInfo(module).getFlexLibrarySet().assetCounterInfo.demanded).write(psiFile);
if (result == null) {
return false;
}
blockOut.end();
documentInfo.setRangeMarkers(result.second);
return result.first.unregistered.isEmpty() || registerDocumentReferences(result.first.unregistered, module, problemsHolder);
}
use of com.intellij.openapi.application.AccessToken in project intellij-plugins by JetBrains.
the class FlexAutoImportsTest method getIntentions.
private List<IntentionAction> getIntentions(final String fileName, final String hint) throws Throwable {
List<IntentionAction> list = ContainerUtil.findAll(myFixture.getAvailableIntentions(fileName), intentionAction -> intentionAction.getText().startsWith(hint));
final AccessToken l = ReadAction.start();
try {
Document document = myFixture.getEditor().getDocument();
int offset = myFixture.getEditor().getCaretModel().getOffset();
int line = document.getLineNumber(offset);
boolean hasHint = !DaemonCodeAnalyzerEx.processHighlights(document, getProject(), HighlightSeverity.ERROR, document.getLineStartOffset(line), document.getLineEndOffset(line), info -> !info.hasHint());
if (!hasHint) {
fail("Auto import fix not found: " + DaemonCodeAnalyzerImpl.getHighlights(document, HighlightSeverity.INFORMATION, getProject()));
}
} finally {
l.finish();
}
return list;
}
use of com.intellij.openapi.application.AccessToken in project intellij-plugins by JetBrains.
the class MxmlWriter method write.
@Nullable
public Pair<ProjectComponentReferenceCounter, List<RangeMarker>> write(XmlFile psiFile) throws IOException {
document = MxmlUtil.getDocumentAndWaitIfNotCommitted(psiFile);
final AccessToken token = ReadAction.start();
try {
VirtualFile virtualFile = psiFile.getVirtualFile();
LOG.assertTrue(virtualFile != null);
problemsHolder.setCurrentFile(virtualFile);
XmlTag tag = psiFile.getRootTag();
XmlElementDescriptor untypedDescriptor = tag == null ? null : tag.getDescriptor();
final ClassBackedElementDescriptor descriptor;
if (untypedDescriptor instanceof ClassBackedElementDescriptor) {
descriptor = (ClassBackedElementDescriptor) untypedDescriptor;
} else {
return null;
}
final Trinity<Integer, String, Condition<AnnotationBackedDescriptor>> effectiveClassInfo;
try {
PsiElement declaration = descriptor.getDeclaration();
if (declaration == null) {
return null;
}
effectiveClassInfo = MxmlUtil.computeEffectiveClass(tag, declaration, projectComponentReferenceCounter, true);
} catch (InvalidPropertyException e) {
problemsHolder.add(e);
return null;
}
if (effectiveClassInfo.first == -1) {
out.write(Amf3Types.OBJECT);
writer.mxmlObjectHeader(effectiveClassInfo.second == null ? descriptor.getQualifiedName() : effectiveClassInfo.second);
} else {
writer.documentReference(effectiveClassInfo.first);
out.allocateClearShort();
}
processElements(tag, null, false, -1, out.size() - 2, true, effectiveClassInfo.third);
writer.endObject();
if (stateWriter != null) {
stateWriter.write();
hasStates = false;
} else {
out.write(0);
}
injectedASWriter.write();
writer.writeMessageHeader(projectComponentReferenceCounter);
return Pair.create(projectComponentReferenceCounter, rangeMarkers);
} finally {
token.finish();
problemsHolder.setCurrentFile(null);
writer.resetAfterMessage();
}
}
use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.
the class XSourcePositionImpl method createByOffset.
/**
* do not call this method from plugins, use {@link XDebuggerUtil#createPositionByOffset(VirtualFile, int)} instead
*/
@Nullable
public static XSourcePositionImpl createByOffset(@Nullable VirtualFile file, final int offset) {
if (file == null)
return null;
AccessToken lock = ApplicationManager.getApplication().acquireReadActionLock();
try {
Document document = FileDocumentManager.getInstance().getDocument(file);
if (document == null) {
return null;
}
int line = DocumentUtil.isValidOffset(offset, document) ? document.getLineNumber(offset) : -1;
return new XSourcePositionImpl(file, line, offset);
} finally {
lock.finish();
}
}
use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.
the class RefreshWorker method fullDirRefresh.
private void fullDirRefresh(NewVirtualFileSystem fs, PersistentFS persistence, TObjectHashingStrategy<String> strategy, VirtualDirectoryImpl dir) {
while (true) {
// obtaining directory snapshot
String[] currentNames;
VirtualFile[] children;
AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
try {
currentNames = persistence.list(dir);
children = dir.getChildren();
} finally {
token.finish();
}
// reading children attributes
String[] upToDateNames = VfsUtil.filterNames(fs.list(dir));
Set<String> newNames = newTroveSet(strategy, upToDateNames);
ContainerUtil.removeAll(newNames, currentNames);
Set<String> deletedNames = newTroveSet(strategy, currentNames);
ContainerUtil.removeAll(deletedNames, upToDateNames);
OpenTHashSet<String> actualNames = null;
if (!fs.isCaseSensitive()) {
actualNames = new OpenTHashSet<>(strategy, upToDateNames);
}
if (LOG.isTraceEnabled())
LOG.trace("current=" + Arrays.toString(currentNames) + " +" + newNames + " -" + deletedNames);
List<Pair<String, FileAttributes>> addedMap = ContainerUtil.newArrayListWithCapacity(newNames.size());
for (String name : newNames) {
checkCancelled(dir);
addedMap.add(pair(name, fs.getAttributes(new FakeVirtualFile(dir, name))));
}
List<Pair<VirtualFile, FileAttributes>> updatedMap = ContainerUtil.newArrayListWithCapacity(children.length);
for (VirtualFile child : children) {
if (deletedNames.contains(child.getName()))
continue;
checkCancelled(dir);
updatedMap.add(pair(child, fs.getAttributes(child)));
}
// generating events unless a directory was changed in between
token = ApplicationManager.getApplication().acquireReadActionLock();
try {
if (!Arrays.equals(currentNames, persistence.list(dir)) || !Arrays.equals(children, dir.getChildren())) {
if (LOG.isDebugEnabled())
LOG.debug("retry: " + dir);
continue;
}
for (String name : deletedNames) {
scheduleDeletion(dir.findChild(name));
}
for (Pair<String, FileAttributes> pair : addedMap) {
String name = pair.first;
FileAttributes childAttributes = pair.second;
if (childAttributes != null) {
scheduleCreation(dir, name, childAttributes.isDirectory(), false);
} else {
LOG.warn("[+] fs=" + fs + " dir=" + dir + " name=" + name);
}
}
for (Pair<VirtualFile, FileAttributes> pair : updatedMap) {
VirtualFile child = pair.first;
FileAttributes childAttributes = pair.second;
if (childAttributes != null) {
checkAndScheduleChildRefresh(dir, child, childAttributes);
checkAndScheduleFileNameChange(actualNames, child);
} else {
LOG.warn("[x] fs=" + fs + " dir=" + dir + " name=" + child.getName());
scheduleDeletion(child);
}
}
break;
} finally {
token.finish();
}
}
}
Aggregations