本文整理匯總了Java中com.siyeh.ipp.psiutils.HighlightUtil類的典型用法代碼示例。如果您正苦於以下問題:Java HighlightUtil類的具體用法?Java HighlightUtil怎麽用?Java HighlightUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HighlightUtil類屬於com.siyeh.ipp.psiutils包,在下文中一共展示了HighlightUtil類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTextForElement
import com.siyeh.ipp.psiutils.HighlightUtil; //導入依賴的package包/類
@Override
protected String getTextForElement(PsiElement element) {
final PsiJavaToken token;
if (element instanceof PsiJavaToken) {
token = (PsiJavaToken)element;
} else {
final PsiElement prevSibling = element.getPrevSibling();
if (prevSibling instanceof PsiJavaToken) {
token = (PsiJavaToken)prevSibling;
} else {
throw new AssertionError();
}
}
final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)element.getParent();
final PsiPolyadicExpression subexpression = ConstantSubexpressionPredicate.getSubexpression(polyadicExpression, token);
final String text = HighlightUtil.getPresentableText(subexpression);
return IntentionPowerPackBundle.message("constant.expression.intention.name", text);
}
示例2: getTextForElement
import com.siyeh.ipp.psiutils.HighlightUtil; //導入依賴的package包/類
@Override
protected String getTextForElement(PsiElement element) {
final String text = HighlightUtil.getPresentableText(element);
return IntentionPowerPackBundle.message("constant.expression.intention.name", text);
}
示例3: processIntention
import com.siyeh.ipp.psiutils.HighlightUtil; //導入依賴的package包/類
@Override
public void processIntention(@NotNull PsiElement element) {
final PsiField field = (PsiField)element.getParent();
final PsiExpression initializer = field.getInitializer();
if (initializer == null) {
return;
}
final String initializerText = RefactoringUtil.convertInitializerToNormalExpression(initializer, field.getType()).getText();
final PsiClass containingClass = field.getContainingClass();
if (containingClass == null) {
return;
}
final boolean fieldIsStatic =
field.hasModifierProperty(PsiModifier.STATIC);
final PsiClassInitializer[] classInitializers =
containingClass.getInitializers();
PsiClassInitializer classInitializer = null;
final int fieldOffset = field.getTextOffset();
for (PsiClassInitializer existingClassInitializer : classInitializers) {
final int initializerOffset =
existingClassInitializer.getTextOffset();
if (initializerOffset <= fieldOffset) {
continue;
}
final boolean initializerIsStatic =
existingClassInitializer.hasModifierProperty(
PsiModifier.STATIC);
if (initializerIsStatic == fieldIsStatic) {
classInitializer = existingClassInitializer;
break;
}
}
final PsiManager manager = field.getManager();
final Project project = manager.getProject();
final PsiElementFactory elementFactory =
JavaPsiFacade.getInstance(project).getElementFactory();
if (classInitializer == null) {
classInitializer = elementFactory.createClassInitializer();
classInitializer = (PsiClassInitializer)
containingClass.addAfter(classInitializer, field);
// add some whitespace between the field and the class initializer
final PsiElement whitespace =
PsiParserFacade.SERVICE.getInstance(project).createWhiteSpaceFromText("\n");
containingClass.addAfter(whitespace, field);
}
final PsiCodeBlock body = classInitializer.getBody();
@NonNls final String initializationStatementText =
field.getName() + " = " + initializerText + ';';
final PsiExpressionStatement statement =
(PsiExpressionStatement)elementFactory.createStatementFromText(
initializationStatementText, body);
final PsiElement addedElement = body.add(statement);
if (fieldIsStatic) {
final PsiModifierList modifierList =
classInitializer.getModifierList();
if (modifierList != null) {
modifierList.setModifierProperty(PsiModifier.STATIC, true);
}
}
initializer.delete();
CodeStyleManager.getInstance(manager.getProject()).reformat(classInitializer);
HighlightUtil.highlightElement(addedElement,
IntentionPowerPackBundle.message(
"press.escape.to.remove.highlighting.message"));
}
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:67,代碼來源:SplitDeclarationAndInitializationIntention.java
示例4: processIntention
import com.siyeh.ipp.psiutils.HighlightUtil; //導入依賴的package包/類
@Override
public void processIntention(@NotNull PsiElement element) {
PsiJavaCodeReferenceElement reference = (PsiJavaCodeReferenceElement)element;
PsiElement target = reference.resolve();
if (!(target instanceof PsiClass)) {
PsiElement parent = reference.getParent();
while (parent instanceof PsiJavaCodeReferenceElement) {
reference = (PsiJavaCodeReferenceElement)parent;
target = reference.resolve();
if (target instanceof PsiClass) {
break;
}
parent = parent.getParent();
}
}
if (!(target instanceof PsiClass)) {
return;
}
final PsiClass aClass = (PsiClass)target;
final String qualifiedName = aClass.getQualifiedName();
if (qualifiedName == null) {
return;
}
final PsiJavaFile file =
PsiTreeUtil.getParentOfType(reference, PsiJavaFile.class);
if (file == null) {
return;
}
ImportUtils.addImportIfNeeded(aClass, reference);
final String fullyQualifiedText = reference.getText();
final QualificationRemover qualificationRemover = new QualificationRemover(fullyQualifiedText);
file.accept(qualificationRemover);
final Collection<PsiJavaCodeReferenceElement> shortenedElements = qualificationRemover.getShortenedElements();
final int elementCount = shortenedElements.size();
final String text;
if (elementCount == 1) {
text = IntentionPowerPackBundle.message(
"1.fully.qualified.name.status.bar.escape.highlighting.message");
}
else {
text = IntentionPowerPackBundle.message(
"multiple.fully.qualified.names.status.bar.escape.highlighting.message",
Integer.valueOf(elementCount));
}
HighlightUtil.highlightElements(shortenedElements, text);
}
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:47,代碼來源:ReplaceFullyQualifiedNameWithImportIntention.java