update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / codeInsight / template / impl / ShortenFQNamesProcessor.java
blob78b906d184a54044020e190325dfcbf46304d372
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.codeInsight.template.impl;
18 import com.intellij.codeInsight.template.Template;
19 import com.intellij.codeInsight.CodeInsightBundle;
20 import com.intellij.openapi.diagnostic.Logger;
21 import com.intellij.openapi.editor.Document;
22 import com.intellij.openapi.editor.RangeMarker;
23 import com.intellij.openapi.editor.Editor;
24 import com.intellij.openapi.project.Project;
25 import com.intellij.psi.PsiDocumentManager;
26 import com.intellij.psi.PsiFile;
27 import com.intellij.psi.util.PsiUtilBase;
28 import com.intellij.psi.codeStyle.JavaCodeStyleManager;
29 import com.intellij.util.IncorrectOperationException;
31 public class ShortenFQNamesProcessor implements TemplateOptionalProcessor {
32 private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.template.impl.ShortenFQNamesProcessor");
34 public void processText(final Project project, final Template template, final Document document, final RangeMarker templateRange,
35 final Editor editor) {
36 if (!template.isToShortenLongNames()) return;
38 try {
39 PsiDocumentManager.getInstance(project).commitDocument(document);
40 JavaCodeStyleManager javaStyle = JavaCodeStyleManager.getInstance(project);
41 final PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
42 assert file != null;
43 javaStyle.shortenClassReferences(file, templateRange.getStartOffset(), templateRange.getEndOffset());
44 PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
46 catch (IncorrectOperationException e) {
47 LOG.error(e);
51 public String getOptionName() {
52 return CodeInsightBundle.message("dialog.edit.template.checkbox.shorten.fq.names");
55 public boolean isEnabled(final Template template) {
56 return template.isToShortenLongNames();
59 public void setEnabled(final Template template, final boolean value) {
60 template.setToShortenLongNames(value);