Move common implementation to separate class
This commit is contained in:
@@ -16,49 +16,16 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.presentation;
|
||||
|
||||
import com.intellij.navigation.ColoredItemPresentation;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.navigation.ItemPresentationProvider;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.plugin.JetIconProvider;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public class JetClassPresenter implements ItemPresentationProvider<JetClass> {
|
||||
|
||||
@Override
|
||||
public ItemPresentation getPresentation(final JetClass item) {
|
||||
return new ColoredItemPresentation() {
|
||||
@Override
|
||||
public TextAttributesKey getTextAttributesKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return item.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocationString() {
|
||||
FqName name = JetPsiUtil.getFQName(item);
|
||||
if (name != null) {
|
||||
return "(" + name.parent().toString() + ")";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon(boolean unused) {
|
||||
return JetIconProvider.INSTANCE.getIcon(item, 0);
|
||||
}
|
||||
};
|
||||
return new JetDefaultNamedDeclarationPresentation(item);
|
||||
}
|
||||
}
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.presentation;
|
||||
|
||||
import com.intellij.navigation.ColoredItemPresentation;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.plugin.JetIconProvider;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class JetDefaultNamedDeclarationPresentation implements ColoredItemPresentation {
|
||||
private final JetNamedDeclaration declaration;
|
||||
|
||||
JetDefaultNamedDeclarationPresentation(JetNamedDeclaration declaration) {
|
||||
this.declaration = declaration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextAttributesKey getTextAttributesKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return declaration.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocationString() {
|
||||
FqName name = JetPsiUtil.getFQName(declaration);
|
||||
if (name != null) {
|
||||
return "(" + name.parent().toString() + ")";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon(boolean unused) {
|
||||
return JetIconProvider.INSTANCE.getIcon(declaration, 0);
|
||||
}
|
||||
}
|
||||
@@ -18,20 +18,16 @@ package org.jetbrains.jet.plugin.presentation;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.intellij.navigation.ColoredItemPresentation;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.navigation.ItemPresentationProvider;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.plugin.JetIconProvider;
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
@@ -40,12 +36,7 @@ import java.util.Collection;
|
||||
public class JetFunctionPresenter implements ItemPresentationProvider<JetNamedFunction> {
|
||||
@Override
|
||||
public ItemPresentation getPresentation(final JetNamedFunction function) {
|
||||
return new ColoredItemPresentation() {
|
||||
@Override
|
||||
public TextAttributesKey getTextAttributesKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new JetDefaultNamedDeclarationPresentation(function) {
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
StringBuilder presentation = new StringBuilder(function.getName());
|
||||
@@ -82,11 +73,6 @@ public class JetFunctionPresenter implements ItemPresentationProvider<JetNamedFu
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon(boolean unused) {
|
||||
return JetIconProvider.INSTANCE.getIcon(function, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user