001 /*
002 * Copyright 2010-2013 JetBrains s.r.o.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package org.jetbrains.jet.lang.resolve.java.wrapper;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.annotations.Nullable;
021 import org.jetbrains.jet.lang.resolve.java.TypeSource;
022
023 /**
024 * Some PSI corresponding to a property: getter, setter or field.
025 */
026 public final class PropertyPsiDataElement {
027
028 @NotNull
029 private final PsiMemberWrapper member;
030
031 // for methods
032 private final boolean getter;
033
034 @NotNull
035 private final TypeSource type;
036 @Nullable
037 private final TypeSource receiverType;
038
039
040 public PropertyPsiDataElement(
041 @NotNull PsiMethodWrapper method,
042 boolean getter,
043 @NotNull TypeSource type,
044 @Nullable TypeSource receiverType
045 ) {
046 this.member = method;
047 this.type = type;
048 this.receiverType = receiverType;
049 this.getter = getter;
050 }
051
052 public PropertyPsiDataElement(@NotNull PsiFieldWrapper field, @NotNull TypeSource type, @Nullable TypeSource receiverType) {
053 this.member = field;
054 this.type = type;
055 this.receiverType = receiverType;
056 this.getter = false;
057 }
058
059 @NotNull
060 public PsiMemberWrapper getMember() {
061 return member;
062 }
063
064 @NotNull
065 public TypeSource getType() {
066 return type;
067 }
068
069 @Nullable
070 public TypeSource getReceiverType() {
071 return receiverType;
072 }
073
074 boolean isExtension() {
075 return getReceiverType() != null;
076 }
077
078 public boolean isGetter() {
079 return member instanceof PsiMethodWrapper && getter;
080 }
081
082 public boolean isSetter() {
083 return member instanceof PsiMethodWrapper && !getter;
084 }
085
086 public boolean isField() {
087 return member instanceof PsiFieldWrapper;
088 }
089 }