use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class SimpleFieldChooser method createCenterPanel.
@Override
protected JComponent createCenterPanel() {
final DefaultListModel model = new DefaultListModel();
for (PsiField member : myFields) {
model.addElement(member);
}
myList = new JBList(model);
myList.setCellRenderer(new MyListCellRenderer());
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent e) {
if (myList.getSelectedValues().length > 0) {
doOKAction();
return true;
}
return false;
}
}.installOn(myList);
myList.setPreferredSize(JBUI.size(300, 400));
return myList;
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class CreateFieldFromParameterDialog method doOKAction.
@Override
protected void doOKAction() {
if (myCbFinal.isEnabled()) {
PropertiesComponent.getInstance().setValue(PROPERTY_NAME, myCbFinal.isSelected());
}
final PsiField[] fields = myTargetClass.getFields();
for (PsiField field : fields) {
if (field.getName().equals(getEnteredName())) {
int result = Messages.showOkCancelDialog(getContentPane(), CodeInsightBundle.message("dialog.create.field.from.parameter.already.exists.text", getEnteredName()), CodeInsightBundle.message("dialog.create.field.from.parameter.already.exists.title"), Messages.getQuestionIcon());
if (result == Messages.OK) {
close(OK_EXIT_CODE);
} else {
return;
}
}
}
close(OK_EXIT_CODE);
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class CanBeFinalTest method testfieldImplicitWrite.
public void testfieldImplicitWrite() throws Exception {
PlatformTestUtil.registerExtension(ImplicitUsageProvider.EP_NAME, new ImplicitUsageProvider() {
@Override
public boolean isImplicitUsage(PsiElement element) {
return isImplicitWrite(element);
}
@Override
public boolean isImplicitRead(PsiElement element) {
return false;
}
@Override
public boolean isImplicitWrite(PsiElement element) {
return element instanceof PsiField && "implicitWrite".equals(((PsiNamedElement) element).getName());
}
}, getTestRootDisposable());
doTest();
}
use of com.intellij.psi.PsiField in project kotlin by JetBrains.
the class ResourceEvaluator method getResourceConstant.
/** Returns a resource URL based on the field reference in the code */
@Nullable
public static ResourceUrl getResourceConstant(@NonNull PsiElement node) {
// R.type.name
if (node instanceof PsiReferenceExpression) {
PsiReferenceExpression expression = (PsiReferenceExpression) node;
if (expression.getQualifier() instanceof PsiReferenceExpression) {
PsiReferenceExpression select = (PsiReferenceExpression) expression.getQualifier();
if (select.getQualifier() instanceof PsiReferenceExpression) {
PsiReferenceExpression reference = (PsiReferenceExpression) select.getQualifier();
if (R_CLASS.equals(reference.getReferenceName())) {
String typeName = select.getReferenceName();
String name = expression.getReferenceName();
ResourceType type = ResourceType.getEnum(typeName);
if (type != null && name != null) {
boolean isFramework = reference.getQualifier() instanceof PsiReferenceExpression && ANDROID_PKG.equals(((PsiReferenceExpression) reference.getQualifier()).getReferenceName());
return ResourceUrl.create(type, name, isFramework, false);
}
}
}
}
} else if (node instanceof PsiField) {
PsiField field = (PsiField) node;
PsiClass typeClass = field.getContainingClass();
if (typeClass != null) {
PsiClass rClass = typeClass.getContainingClass();
if (rClass != null && R_CLASS.equals(rClass.getName())) {
String name = field.getName();
ResourceType type = ResourceType.getEnum(typeClass.getName());
if (type != null && name != null) {
String qualifiedName = rClass.getQualifiedName();
boolean isFramework = qualifiedName != null && qualifiedName.startsWith(ANDROID_PKG_PREFIX);
return ResourceUrl.create(type, name, isFramework, false);
}
}
}
}
return null;
}
use of com.intellij.psi.PsiField in project kotlin by JetBrains.
the class ParcelDetector method checkClass.
@Override
public void checkClass(@NonNull JavaContext context, @NonNull UClass declaration) {
if (declaration instanceof UAnonymousClass) {
// Anonymous classes aren't parcelable
return;
}
// Only applies to concrete classes
if (declaration.isInterface()) {
return;
}
if (declaration.hasModifierProperty(PsiModifier.ABSTRACT)) {
return;
}
// Parceling spans is handled in TextUtils#CHAR_SEQUENCE_CREATOR
if (InheritanceUtil.isInheritor(declaration, false, "android.text.ParcelableSpan")) {
return;
}
PsiField field = declaration.findFieldByName("CREATOR", false);
if (field == null) {
Location location = context.getUastNameLocation(declaration);
context.reportUast(ISSUE, declaration, location, "This class implements `Parcelable` but does not " + "provide a `CREATOR` field");
}
}
Aggregations