use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class PsiNameValuePairImpl method getDetachedValue.
@Override
@Nullable
public PsiAnnotationMemberValue getDetachedValue() {
PsiNameValuePairStub stub = getStub();
if (stub != null) {
String text = stub.getValue();
PsiAnnotationMemberValue result = SoftReference.dereference(myDetachedValue);
if (result == null) {
PsiAnnotation anno = JavaPsiFacade.getElementFactory(getProject()).createAnnotationFromText("@F(" + text + ")", this);
((LightVirtualFile) anno.getContainingFile().getViewProvider().getVirtualFile()).setWritable(false);
myDetachedValue = new SoftReference<>(result = anno.findAttributeValue(null));
}
return result;
}
return getValue();
}
use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class FindManagerTest method testFindInCommentsProperlyWorksWithOffsets.
public void testFindInCommentsProperlyWorksWithOffsets() {
FindModel findModel = FindManagerTestUtils.configureFindModel("done");
String prefix = "/*";
String text = prefix + "done*/";
findModel.setSearchContext(FindModel.SearchContext.IN_COMMENTS);
LightVirtualFile file = new LightVirtualFile("A.java", text);
FindResult findResult = myFindManager.findString(text, prefix.length(), findModel, file);
assertTrue(findResult.isStringFound());
findModel.setRegularExpressions(true);
findResult = myFindManager.findString(text, prefix.length(), findModel, file);
assertTrue(findResult.isStringFound());
}
use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class DiffUtil method createEditorHighlighter.
@Nullable
private static EditorHighlighter createEditorHighlighter(@Nullable Project project, @NotNull DocumentContent content) {
FileType type = content.getContentType();
VirtualFile file = content.getHighlightFile();
Language language = content.getUserData(DiffUserDataKeys.LANGUAGE);
EditorHighlighterFactory highlighterFactory = EditorHighlighterFactory.getInstance();
if (language != null) {
SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, file);
return highlighterFactory.createEditorHighlighter(syntaxHighlighter, EditorColorsManager.getInstance().getGlobalScheme());
}
if (file != null && file.isValid()) {
if ((type == null || type == PlainTextFileType.INSTANCE) || file.getFileType() == type || file instanceof LightVirtualFile) {
return highlighterFactory.createEditorHighlighter(project, file);
}
}
if (type != null) {
return highlighterFactory.createEditorHighlighter(project, type);
}
return null;
}
use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class PsiFieldImpl method getDetachedInitializer.
// avoids stub-to-AST switch if possible,
// returns the light generated initializer literal expression if stored in stubs, the regular initializer if wasn't
public PsiExpression getDetachedInitializer() {
final PsiFieldStub stub = getGreenStub();
PsiExpression initializer;
if (stub == null) {
initializer = getInitializer();
} else {
String initializerText = stub.getInitializerText();
if (StringUtil.isEmpty(initializerText) || PsiFieldStub.INITIALIZER_NOT_STORED.equals(initializerText) || PsiFieldStub.INITIALIZER_TOO_LONG.equals(initializerText)) {
initializer = getInitializer();
} else {
PsiJavaParserFacade parserFacade = JavaPsiFacade.getInstance(getProject()).getParserFacade();
initializer = parserFacade.createExpressionFromText(initializerText, this);
((LightVirtualFile) initializer.getContainingFile().getViewProvider().getVirtualFile()).setWritable(false);
}
}
return initializer;
}
use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class FindManagerTestUtils method runFindForwardAndBackward.
public static void runFindForwardAndBackward(FindManager findManager, FindModel findModel, String text, String ext) {
findModel.setForward(true);
LightVirtualFile file = new LightVirtualFile("A." + ext, text);
FindResult findResult = findManager.findString(text, 0, findModel, file);
Assert.assertTrue(findResult.isStringFound());
int previousOffset = findResult.getStartOffset();
findResult = findManager.findString(text, findResult.getEndOffset(), findModel, file);
Assert.assertTrue(findResult.isStringFound());
Assert.assertTrue(findResult.getStartOffset() > previousOffset);
previousOffset = findResult.getStartOffset();
findResult = findManager.findString(text, findResult.getEndOffset(), findModel, file);
Assert.assertTrue(findResult.isStringFound());
Assert.assertTrue(findResult.getStartOffset() > previousOffset);
findModel.setForward(false);
findResult = findManager.findString(text, text.length(), findModel, file);
Assert.assertTrue(findResult.isStringFound());
previousOffset = findResult.getStartOffset();
findResult = findManager.findString(text, previousOffset, findModel, file);
Assert.assertTrue(findResult.isStringFound());
Assert.assertTrue(previousOffset > findResult.getStartOffset());
previousOffset = findResult.getStartOffset();
findResult = findManager.findString(text, previousOffset, findModel, file);
Assert.assertTrue(findResult.isStringFound());
Assert.assertTrue(previousOffset > findResult.getStartOffset());
}
Aggregations