use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.
the class VariableLookupItem method handleInsert.
@Override
public void handleInsert(InsertionContext context) {
PsiVariable variable = getObject();
Document document = context.getDocument();
document.replaceString(context.getStartOffset(), context.getTailOffset(), variable.getName());
context.commitDocument();
if (variable instanceof PsiField) {
if (willBeImported()) {
RangeMarker toDelete = JavaCompletionUtil.insertTemporary(context.getTailOffset(), document, " ");
context.commitDocument();
final PsiReferenceExpression ref = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiReferenceExpression.class, false);
if (ref != null) {
if (ref.isQualified()) {
// shouldn't happen, but sometimes we see exceptions because of this
return;
}
ref.bindToElementViaStaticImport(((PsiField) variable).getContainingClass());
PostprocessReformattingAspect.getInstance(ref.getProject()).doPostponedFormatting();
}
if (toDelete.isValid()) {
document.deleteString(toDelete.getStartOffset(), toDelete.getEndOffset());
}
context.commitDocument();
} else if (shouldQualify((PsiField) variable, context)) {
qualifyFieldReference(context, (PsiField) variable);
}
}
PsiReferenceExpression ref = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getTailOffset() - 1, PsiReferenceExpression.class, false);
if (ref != null) {
JavaCodeStyleManager.getInstance(context.getProject()).shortenClassReferences(ref);
}
ref = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getTailOffset() - 1, PsiReferenceExpression.class, false);
PsiElement target = ref == null ? null : ref.resolve();
if (target instanceof PsiLocalVariable || target instanceof PsiParameter) {
makeFinalIfNeeded(context, (PsiVariable) target);
}
final char completionChar = context.getCompletionChar();
if (completionChar == '=') {
context.setAddCompletionChar(false);
TailType.EQ.processTail(context.getEditor(), context.getTailOffset());
} else if (completionChar == ',' && getAttribute(LookupItem.TAIL_TYPE_ATTR) != TailType.UNKNOWN) {
context.setAddCompletionChar(false);
TailType.COMMA.processTail(context.getEditor(), context.getTailOffset());
AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), null);
} else if (completionChar == ':' && getAttribute(LookupItem.TAIL_TYPE_ATTR) != TailType.UNKNOWN && isTernaryCondition(ref)) {
context.setAddCompletionChar(false);
TailType.COND_EXPR_COLON.processTail(context.getEditor(), context.getTailOffset());
} else if (completionChar == '.') {
AutoPopupController.getInstance(context.getProject()).autoPopupMemberLookup(context.getEditor(), null);
} else if (completionChar == '!' && PsiType.BOOLEAN.isAssignableFrom(variable.getType())) {
context.setAddCompletionChar(false);
if (ref != null) {
FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EXCLAMATION_FINISH);
document.insertString(ref.getTextRange().getStartOffset(), "!");
}
}
}
use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.
the class FileStatusMap method getFileDirtyScope.
/**
* @return null for processed file, whole file for untouched or entirely dirty file, range(usually code block) for dirty region (optimization)
*/
@Nullable
public TextRange getFileDirtyScope(@NotNull Document document, int passId) {
synchronized (myDocumentToStatusMap) {
PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
if (!ProblemHighlightFilter.shouldHighlightFile(file))
return null;
FileStatus status = myDocumentToStatusMap.get(document);
if (status == null) {
return file == null ? null : file.getTextRange();
}
if (status.defensivelyMarked) {
status.markWholeFileDirty(myProject);
status.defensivelyMarked = false;
}
if (!status.dirtyScopes.containsKey(passId))
throw new IllegalStateException("Unknown pass " + passId);
RangeMarker marker = status.dirtyScopes.get(passId);
return marker == null ? null : marker.isValid() ? TextRange.create(marker) : new TextRange(0, document.getTextLength());
}
}
use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.
the class UpdateHighlightersUtil method addHighlighterToEditorIncrementally.
static void addHighlighterToEditorIncrementally(@NotNull Project project, @NotNull Document document, @NotNull PsiFile file, int startOffset, int endOffset, @NotNull final HighlightInfo info, // if null global scheme will be used
@Nullable final EditorColorsScheme colorsScheme, final int group, @NotNull Map<TextRange, RangeMarker> ranges2markersCache) {
ApplicationManager.getApplication().assertIsDispatchThread();
if (isFileLevelOrGutterAnnotation(info))
return;
if (info.getStartOffset() < startOffset || info.getEndOffset() > endOffset)
return;
MarkupModel markup = DocumentMarkupModel.forDocument(document, project, true);
final SeverityRegistrar severityRegistrar = SeverityRegistrar.getSeverityRegistrar(project);
final boolean myInfoIsError = isSevere(info, severityRegistrar);
Processor<HighlightInfo> otherHighlightInTheWayProcessor = oldInfo -> {
if (!myInfoIsError && isCovered(info, severityRegistrar, oldInfo)) {
return false;
}
return oldInfo.getGroup() != group || !oldInfo.equalsByActualOffset(info);
};
boolean allIsClear = DaemonCodeAnalyzerEx.processHighlights(document, project, null, info.getActualStartOffset(), info.getActualEndOffset(), otherHighlightInTheWayProcessor);
if (allIsClear) {
createOrReuseHighlighterFor(info, colorsScheme, document, group, file, (MarkupModelEx) markup, null, ranges2markersCache, severityRegistrar);
clearWhiteSpaceOptimizationFlag(document);
assertMarkupConsistent(markup, project);
}
}
use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.
the class DocumentFragmentContent method createRangeMarker.
@NotNull
private static RangeMarker createRangeMarker(@NotNull Document document, @NotNull TextRange range) {
RangeMarker rangeMarker = document.createRangeMarker(range.getStartOffset(), range.getEndOffset(), true);
rangeMarker.setGreedyToLeft(true);
rangeMarker.setGreedyToRight(true);
return rangeMarker;
}
use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.
the class SliceForwardTest method dotest.
private void dotest() throws Exception {
configureByFile("/codeInsight/slice/forward/" + getTestName(false) + ".java");
Map<String, RangeMarker> sliceUsageName2Offset = SliceTestUtil.extractSliceOffsetsFromDocument(getEditor().getDocument());
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
PsiElement element = new SliceForwardHandler().getExpressionAtCaret(getEditor(), getFile());
assertNotNull(element);
SliceTestUtil.calcRealOffsets(element, sliceUsageName2Offset, myFlownOffsets);
Collection<HighlightInfo> errors = highlightErrors();
assertEmpty(errors);
SliceAnalysisParams params = new SliceAnalysisParams();
params.scope = new AnalysisScope(getProject());
params.dataFlowToThis = false;
SliceUsage usage = LanguageSlicing.getProvider(element).createRootUsage(element, params);
SliceTestUtil.checkUsages(usage, myFlownOffsets);
}
Aggregations