Delete PsiAnnotationWrapper

Merge its logic into KotlinSignatureAnnotation, move the latter to
resolve/java/kotlinSignature, delete resolve/java/kt package
This commit is contained in:
Alexander Udalov
2013-07-23 18:38:24 +04:00
committed by Pavel V. Talanov
parent bd54e070bb
commit cbdc157743
4 changed files with 33 additions and 117 deletions
@@ -14,45 +14,60 @@
* limitations under the License.
*/
package org.jetbrains.jet.lang.resolve.java.kt;
package org.jetbrains.jet.lang.resolve.java.kotlinSignature;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiModifierListOwner;
import com.intellij.psi.PsiAnnotationMemberValue;
import com.intellij.psi.PsiLiteralExpression;
import com.intellij.psi.PsiMember;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames;
import org.jetbrains.jet.lang.resolve.java.resolver.JavaAnnotationResolver;
public class KotlinSignatureAnnotation extends PsiAnnotationWrapper {
public class KotlinSignatureAnnotation {
private static final KotlinSignatureAnnotation NULL_ANNOTATION = new KotlinSignatureAnnotation(null);
static {
NULL_ANNOTATION.checkInitialized();
NULL_ANNOTATION.computeSignature();
}
@Nullable
private final PsiAnnotation psiAnnotation;
private String signature;
private KotlinSignatureAnnotation(@Nullable PsiAnnotation psiAnnotation) {
super(psiAnnotation);
this.psiAnnotation = psiAnnotation;
}
@Override
protected void initialize() {
signature = StringUtil.unescapeStringCharacters(getStringAttribute(JvmAnnotationNames.KOTLIN_SIGNATURE_VALUE_FIELD_NAME, ""));
@NotNull
public static KotlinSignatureAnnotation get(@NotNull PsiMember member) {
PsiAnnotation annotation = JavaAnnotationResolver.
findAnnotationWithExternal(member, JvmAnnotationNames.KOTLIN_SIGNATURE.getFqName().asString());
return annotation != null ? new KotlinSignatureAnnotation(annotation) : NULL_ANNOTATION;
}
@NotNull
private String computeSignature() {
if (psiAnnotation != null) {
PsiAnnotationMemberValue attribute = psiAnnotation.findAttributeValue(JvmAnnotationNames.KOTLIN_SIGNATURE_VALUE_FIELD_NAME);
if (attribute instanceof PsiLiteralExpression) {
Object value = ((PsiLiteralExpression) attribute).getValue();
if (value instanceof String) {
return StringUtil.unescapeStringCharacters((String) value);
}
}
}
return "";
}
@NotNull
public String signature() {
checkInitialized();
if (signature == null) {
signature = computeSignature();
}
return signature;
}
@NotNull
public static KotlinSignatureAnnotation get(PsiModifierListOwner psiModifierListOwner) {
PsiAnnotation annotation =
JavaAnnotationResolver
.findAnnotationWithExternal(psiModifierListOwner, JvmAnnotationNames.KOTLIN_SIGNATURE.getFqName().asString());
return annotation != null ? new KotlinSignatureAnnotation(annotation) : NULL_ANNOTATION;
}
}
@@ -1,52 +0,0 @@
/*
* Copyright 2010-2013 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.lang.resolve.java.kt;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiAnnotationMemberValue;
import com.intellij.psi.PsiLiteralExpression;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class PsiAnnotationUtils {
private PsiAnnotationUtils() {
}
@NotNull
public static String getStringAttribute(@Nullable PsiAnnotation annotation, @NotNull String field, @NotNull String defaultValue) {
return getAttribute(annotation, field, defaultValue);
}
@NotNull
private static <T> T getAttribute(@Nullable PsiAnnotation annotation, @NotNull String field, @NotNull T defaultValue) {
if (annotation == null) {
return defaultValue;
}
else {
PsiAnnotationMemberValue value = annotation.findAttributeValue(field);
if (value instanceof PsiLiteralExpression) {
PsiLiteralExpression attributeValue = (PsiLiteralExpression) value;
return (T) attributeValue.getValue();
}
else {
return defaultValue;
}
}
}
}
@@ -1,47 +0,0 @@
/*
* Copyright 2010-2013 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.lang.resolve.java.kt;
import com.intellij.psi.PsiAnnotation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class PsiAnnotationWrapper {
@Nullable
private final PsiAnnotation psiAnnotation;
private boolean initialized = false;
protected PsiAnnotationWrapper(@Nullable PsiAnnotation psiAnnotation) {
this.psiAnnotation = psiAnnotation;
}
protected abstract void initialize();
protected void checkInitialized () {
if (!initialized) {
initialize();
initialized = true;
}
}
@NotNull
protected String getStringAttribute(String name, String defaultValue) {
return PsiAnnotationUtils.getStringAttribute(psiAnnotation, name, defaultValue);
}
}
@@ -19,7 +19,7 @@ package org.jetbrains.jet.lang.resolve.java.wrapper;
import com.intellij.psi.PsiMember;
import com.intellij.psi.PsiModifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.java.kt.KotlinSignatureAnnotation;
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.KotlinSignatureAnnotation;
public abstract class PsiMemberWrapper {