use of com.intellij.psi.PsiIdentifier in project intellij-community by JetBrains.
the class FieldSelectioner method select.
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
List<TextRange> result = super.select(e, editorText, cursorOffset, editor);
final PsiField field = (PsiField) e;
final TextRange range = field.getTextRange();
final PsiIdentifier first = field.getNameIdentifier();
final TextRange firstRange = first.getTextRange();
final PsiElement last = field.getInitializer();
final int end = last == null ? firstRange.getEndOffset() : last.getTextRange().getEndOffset();
PsiDocComment comment = field.getDocComment();
if (comment != null) {
TextRange commentTextRange = comment.getTextRange();
addRangeElem(result, editorText, comment, commentTextRange.getEndOffset());
}
addRangeElem(result, editorText, first, end);
//addRangeElem (result, editorText, field, textLength, field.getTypeElement(), end);
addRangeElem(result, editorText, field.getModifierList(), range.getEndOffset());
//addRangeElem (result, editorText, field, textLength, field.getDocComment(), end);
result.addAll(expandToWholeLine(editorText, range));
return result;
}
use of com.intellij.psi.PsiIdentifier in project intellij-community by JetBrains.
the class HighlightSeverityTest method testErrorLikeUnusedSymbol.
public void testErrorLikeUnusedSymbol() throws Exception {
enableInspectionTool(new LocalInspectionTool() {
@NotNull
@Override
public String getShortName() {
return getDisplayName();
}
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly, @NotNull LocalInspectionToolSession session) {
return new JavaElementVisitor() {
@Override
public void visitIdentifier(PsiIdentifier identifier) {
if (identifier.getText().equals("k")) {
holder.registerProblem(identifier, "Variable 'k' is never used");
}
}
};
}
@NotNull
@Override
public HighlightDisplayLevel getDefaultLevel() {
return HighlightDisplayLevel.ERROR;
}
@Nls
@NotNull
@Override
public String getDisplayName() {
return "x";
}
@Nls
@NotNull
@Override
public String getGroupDisplayName() {
return getDisplayName();
}
});
doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false);
}
use of com.intellij.psi.PsiIdentifier in project intellij-community by JetBrains.
the class NamedElementTokenizer method tokenize.
@Override
public void tokenize(@NotNull T element, TokenConsumer consumer) {
final PsiIdentifier psiIdentifier = PsiTreeUtil.getChildOfType(element, PsiIdentifier.class);
final PsiTypeElement psiType = PsiTreeUtil.getChildOfType(element, PsiTypeElement.class);
if (psiIdentifier == null) {
return;
}
final String identifier = psiIdentifier.getText();
final String type = psiType == null ? null : psiType.getText();
if (identifier == null) {
return;
}
if (type == null || !type.equalsIgnoreCase(identifier)) {
myIdentifierTokenizer.tokenize(psiIdentifier, consumer);
}
if (psiType != null) {
myTypeTokenizer.tokenize(psiType, consumer);
}
}
use of com.intellij.psi.PsiIdentifier in project intellij-community by JetBrains.
the class ClassOnlyUsedInOnePackageInspection method checkElement.
@Nullable
@Override
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope scope, @NotNull InspectionManager manager, @NotNull GlobalInspectionContext globalContext) {
if (!(refEntity instanceof RefClass)) {
return null;
}
final RefClass refClass = (RefClass) refEntity;
final RefEntity owner = refClass.getOwner();
if (!(owner instanceof RefPackage)) {
return null;
}
final Set<RefClass> dependencies = DependencyUtils.calculateDependenciesForClass(refClass);
RefPackage otherPackage = null;
for (RefClass dependency : dependencies) {
final RefPackage refPackage = RefJavaUtil.getPackage(dependency);
if (owner == refPackage) {
return null;
}
if (otherPackage != refPackage) {
if (otherPackage == null) {
otherPackage = refPackage;
} else {
return null;
}
}
}
final Set<RefClass> dependents = DependencyUtils.calculateDependentsForClass(refClass);
for (RefClass dependent : dependents) {
final RefPackage refPackage = RefJavaUtil.getPackage(dependent);
if (owner == refPackage) {
return null;
}
if (otherPackage != refPackage) {
if (otherPackage == null) {
otherPackage = refPackage;
} else {
return null;
}
}
}
if (otherPackage == null) {
return null;
}
final PsiClass aClass = refClass.getElement();
final PsiIdentifier identifier = aClass.getNameIdentifier();
if (identifier == null) {
return null;
}
final String packageName = otherPackage.getName();
return new CommonProblemDescriptor[] { manager.createProblemDescriptor(identifier, InspectionGadgetsBundle.message("class.only.used.in.one.package.problem.descriptor", packageName), true, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false) };
}
use of com.intellij.psi.PsiIdentifier in project intellij-community by JetBrains.
the class ClassOnlyUsedInOneModuleInspection method checkElement.
@Nullable
@Override
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope scope, @NotNull InspectionManager manager, @NotNull GlobalInspectionContext globalContext) {
if (!(refEntity instanceof RefClass)) {
return null;
}
final RefClass refClass = (RefClass) refEntity;
final RefEntity owner = refClass.getOwner();
if (!(owner instanceof RefPackage)) {
return null;
}
final Set<RefClass> dependencies = DependencyUtils.calculateDependenciesForClass(refClass);
RefModule otherModule = null;
for (RefClass dependency : dependencies) {
final RefModule module = dependency.getModule();
if (refClass.getModule() == module) {
return null;
}
if (otherModule != module) {
if (otherModule == null) {
otherModule = module;
} else {
return null;
}
}
}
final Set<RefClass> dependents = DependencyUtils.calculateDependentsForClass(refClass);
for (RefClass dependent : dependents) {
final RefModule module = dependent.getModule();
if (refClass.getModule() == module) {
return null;
}
if (otherModule != module) {
if (otherModule == null) {
otherModule = module;
} else {
return null;
}
}
}
if (otherModule == null) {
return null;
}
final PsiClass aClass = refClass.getElement();
final PsiIdentifier identifier = aClass.getNameIdentifier();
if (identifier == null) {
return null;
}
final String moduleName = otherModule.getName();
return new CommonProblemDescriptor[] { manager.createProblemDescriptor(identifier, InspectionGadgetsBundle.message("class.only.used.in.one.module.problem.descriptor", moduleName), true, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false) };
}
Aggregations