private static String prepareExpression(GrExpression expr) { if (PsiUtil.isThisOrSuperRef(expr)) return expr.getText(); String text = expr.getText(); final PsiType type = expr.getType(); if (type != null && CommonClassNames.JAVA_LANG_STRING.equals(type.getCanonicalText())) { if (expr instanceof GrBinaryExpression && GroovyTokenTypes.mPLUS.equals(((GrBinaryExpression)expr).getOperationTokenType())) { return '(' + text + ')'; } else { return text; } } else { return "String.valueOf(" + text + ")"; } }
@Nullable public static String getEnumConstantName(@NotNull ObjectReference objRef, ClassType classType) { do { if (!classType.isPrepared()) { return null; } classType = classType.superclass(); if (classType == null) { return null; } } while (!(CommonClassNames.JAVA_LANG_ENUM.equals(classType.name()))); //noinspection HardCodedStringLiteral final Field field = classType.fieldByName("name"); if (field == null) { return null; } final Value value = objRef.getValue(field); if (!(value instanceof StringReference)) { return null; } return ((StringReference)value).value(); }
@Override public void visitMethodCallExpression(GrMethodCallExpression grMethodCallExpression) { super.visitMethodCallExpression(grMethodCallExpression); final GrExpression methodExpression = grMethodCallExpression.getInvokedExpression(); if (!(methodExpression instanceof GrReferenceExpression)) { return; } final GrReferenceExpression reference = (GrReferenceExpression) methodExpression; final String name = reference.getReferenceName(); if (!"wait".equals(name)) { return; } final PsiMethod method = grMethodCallExpression.resolveMethod(); if (method == null) { return; } final PsiClass containingClass = method.getContainingClass(); if (containingClass == null || !CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) { return; } if (ControlFlowUtils.isInLoop(grMethodCallExpression)) { return; } registerMethodCallError(grMethodCallExpression); }
@Override public void visitField(PsiField field) { super.visitField(field); if (field.hasModifierProperty(PsiModifier.FINAL)) { return; } final PsiClass containingClass = field.getContainingClass(); if (containingClass == null) { return; } if (!InheritanceUtil.isInheritor(containingClass, CommonClassNames.JAVA_LANG_EXCEPTION)) { return; } registerFieldError(field, field); }
public boolean satisfiedBy(PsiElement element) { final PsiElement parent = element.getParent(); if (!(parent instanceof PsiClass)) { return false; } final PsiClass aClass = (PsiClass)parent; if (!aClass.isInterface() || aClass.isAnnotationType()) { return false; } final PsiElement leftBrace = aClass.getLBrace(); final int offsetInParent = element.getStartOffsetInParent(); if (leftBrace == null || offsetInParent >= leftBrace.getStartOffsetInParent()) { return false; } final SearchScope useScope = aClass.getUseScope(); for (PsiClass inheritor : ClassInheritorsSearch.search(aClass, useScope, true)) { if (inheritor.isInterface()) { return false; } } return !AnnotationUtil.isAnnotated(aClass, CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE, false, true); }
@Override public boolean isAssignableFrom(@NotNull PsiType type) { if (type instanceof GrTupleType) { PsiType[] otherComponents = ((GrTupleType)type).getComponentTypes(); PsiType[] componentTypes = getComponentTypes(); for (int i = 0; i < Math.min(componentTypes.length, otherComponents.length); i++) { PsiType componentType = componentTypes[i]; PsiType otherComponent = otherComponents[i]; if (otherComponent == null) { if (componentType != null && !TypesUtil.isClassType(componentType, CommonClassNames.JAVA_LANG_OBJECT)) return false; } else if (componentType != null && !componentType.isAssignableFrom(otherComponent)) return false; } return true; } return super.isAssignableFrom(type); }
@Override @NotNull public PsiVariable getPsi(PsiManager manager, final String containingClassName) { if (myPsi != null) return myPsi; Boolean isStatic = isStatic(); String type = getType(); if (type == null || type.trim().isEmpty()) { type = CommonClassNames.JAVA_LANG_OBJECT; } myPsi = new GrDynamicImplicitProperty(manager, getName(), type, containingClassName); if (isStatic != null && isStatic.booleanValue()) { myPsi.getModifierList().addModifier(PsiModifier.STATIC); } return myPsi; }
private static boolean checkForListIsEmpty(GrExpression condition, GrExpression elseBranch) { if (condition instanceof GrMethodCall) condition = ((GrMethodCall)condition).getInvokedExpression(); if (!(condition instanceof GrReferenceExpression)) return false; final GrExpression qualifier = ((GrReferenceExpression)condition).getQualifier(); if (qualifier == null) return false; if (!PsiEquivalenceUtil.areElementsEquivalent(qualifier, elseBranch)) return false; final PsiType type = qualifier.getType(); if (type == null) return false; if (!InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_LIST)) return false; final PsiElement resolved = ((GrReferenceExpression)condition).resolve(); return resolved instanceof PsiMethod && "isEmpty".equals(((PsiMethod)resolved).getName()) && ((PsiMethod)resolved).getParameterList().getParametersCount() == 0; }
@Override public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) { final boolean inSources1 = myIndex.isInLibrarySource(file1); if (inSources1 != myIndex.isInLibrarySource(file2)) { //Consider class A implements Runnable in project source. //Super class Object for class A is found in cls, super interface Runnable is found in cls as well (class A resolve scope is simple modules scope with dependencies). //Super class of cls Runnable isn't explicitly specified in the cls psi, so PsiClassImplUtil.getSuperClass/getSuperTypes return java.lang.Object //found via file's resolve scope (this one). So for the two hierarchies to meet in one place we should return cls Object here. //By default this resolve scope prefers sdk sources, so we need to override this behavior for Object. //The problem doesn't arise for other super class references inside Android sdk cls (e.g. A extends B implements C, where B implements C and both are inside android sdk), //because these references (C) are explicit and resolved via ClsJavaCodeReferenceElementImpl#resolveClassPreferringMyJar which returns cls classes despite custom Android sdk scope. if (!CommonClassNames.JAVA_LANG_OBJECT_SHORT.equals(file1.getNameWithoutExtension())) { return inSources1 ? 1 : -1; } } return super.compare(file1, file2); }
@Override public void visitClass(@NotNull PsiClass aClass) { // no call to super, so that it doesn't drill down to inner classes if (aClass.isInterface() || aClass.isAnnotationType()) { return; } if (!aClass.hasModifierProperty(PsiModifier.ABSTRACT)) { return; } final PsiClass superClass = aClass.getSuperClass(); if (superClass == null) { return; } if (superClass.hasModifierProperty(PsiModifier.ABSTRACT)) { return; } final String superclassName = superClass.getQualifiedName(); if (CommonClassNames.JAVA_LANG_OBJECT.equals(superclassName)) { return; } registerClassError(aClass); }
@Override public void visitClass(@NotNull PsiClass aClass) { // no call to super, so it doesn't drill down into inner classes if (aClass instanceof PsiTypeParameter) { return; } final String className = aClass.getName(); if (className == null) { return; } @NonNls final String exception = "Exception"; if (className.endsWith(exception)) { return; } if (!InheritanceUtil.isInheritor(aClass, CommonClassNames.JAVA_LANG_EXCEPTION)) { return; } registerClassError(aClass); }
@Override public void visitClass(@NotNull PsiClass aClass) { // no call to super, so it doesn't drill down into inner classes final String className = aClass.getName(); if (className == null) { return; } @NonNls final String exception = "Exception"; if (!className.endsWith(exception)) { return; } if (InheritanceUtil.isInheritor(aClass, CommonClassNames.JAVA_LANG_EXCEPTION)) { return; } registerClassError(aClass, className, Boolean.valueOf(isOnTheFly())); }
public static GroovyElementPattern.Capture<GrArgumentLabel> namedArgumentLabel(@Nullable final ElementPattern<? extends String> namePattern) { return new GroovyElementPattern.Capture<GrArgumentLabel>(new InitialPatternCondition<GrArgumentLabel>(GrArgumentLabel.class) { @Override public boolean accepts(@Nullable final Object o, final ProcessingContext context) { if (o instanceof GrArgumentLabel) { PsiElement nameElement = ((GrArgumentLabel)o).getNameElement(); if (nameElement instanceof LeafPsiElement) { IElementType elementType = ((LeafPsiElement)nameElement).getElementType(); if (elementType == GroovyTokenTypes.mIDENT || CommonClassNames.JAVA_LANG_STRING.equals(TypesUtil.getBoxedTypeName(elementType))) { return namePattern == null || namePattern.accepts(((GrArgumentLabel)o).getName()); } } } return false; } }); }
/** * checks for the case string.isEmpty() ? something_else : string */ private static boolean checkForStringIsEmpty(GrExpression condition, GrExpression elseBranch) { if (condition instanceof GrMethodCall) condition = ((GrMethodCall)condition).getInvokedExpression(); if (!(condition instanceof GrReferenceExpression)) return false; final GrExpression qualifier = ((GrReferenceExpression)condition).getQualifier(); if (qualifier == null) return false; if (!PsiEquivalenceUtil.areElementsEquivalent(qualifier, elseBranch)) return false; final PsiType type = qualifier.getType(); if (type == null) return false; if (!type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) return false; final PsiElement resolved = ((GrReferenceExpression)condition).resolve(); return resolved instanceof PsiMethod && "isEmpty".equals(((PsiMethod)resolved).getName()) && ((PsiMethod)resolved).getParameterList().getParametersCount() == 0; }
@Override public void visitMethodCallExpression( @NotNull PsiMethodCallExpression expression) { super.visitMethodCallExpression(expression); final String methodName = MethodCallUtils.getMethodName(expression); if (!HardcodedMethodConstants.TO_STRING.equals(methodName)) { return; } final PsiType targetType = MethodCallUtils.getTargetType(expression); if (!TypeUtils.typeEquals(CommonClassNames.JAVA_UTIL_DATE, targetType)) { return; } final PsiExpressionList argumentList = expression.getArgumentList(); if (argumentList.getExpressions().length != 0) { return; } if (NonNlsUtils.isNonNlsAnnotatedUse(expression)) { return; } registerMethodCallError(expression); }
private static PsiTypeParameterStub parseTypeParameter(CharacterIterator iterator, PsiTypeParameterListStub parent) throws ClsFormatException { StringBuilder name = new StringBuilder(); while (iterator.current() != ':' && iterator.current() != CharacterIterator.DONE) { name.append(iterator.current()); iterator.next(); } if (iterator.current() == CharacterIterator.DONE) { throw new ClsFormatException(); } //todo parse annotations on type param PsiTypeParameterStub parameterStub = new PsiTypeParameterStubImpl(parent, StringRef.fromString(name.toString())); // postpone list allocation till a second bound is seen; ignore sole Object bound List<String> bounds = null; boolean jlo = false; while (iterator.current() == ':') { iterator.next(); String bound = parseTopLevelClassRefSignature(iterator); if (bound == null) continue; if (bounds == null) { if (CommonClassNames.JAVA_LANG_OBJECT.equals(bound)) { jlo = true; continue; } bounds = ContainerUtil.newSmartList(); if (jlo) { bounds.add(CommonClassNames.JAVA_LANG_OBJECT); } } bounds.add(bound); } StubBuildingVisitor.newReferenceList(JavaStubElementTypes.EXTENDS_BOUND_LIST, parameterStub, ArrayUtil.toStringArray(bounds)); return parameterStub; }
public Object evaluate(EvaluationContextImpl context) throws EvaluateException { final Object result = myOperand.evaluate(context); if (result == null || result instanceof ObjectReference) { return result; } if (result instanceof BooleanValue) { return convertToWrapper(context, (BooleanValue)result, CommonClassNames.JAVA_LANG_BOOLEAN); } if (result instanceof ByteValue) { return convertToWrapper(context, (ByteValue)result, CommonClassNames.JAVA_LANG_BYTE); } if (result instanceof CharValue) { return convertToWrapper(context, (CharValue)result, CommonClassNames.JAVA_LANG_CHARACTER); } if (result instanceof ShortValue) { return convertToWrapper(context, (ShortValue)result, CommonClassNames.JAVA_LANG_SHORT); } if (result instanceof IntegerValue) { return convertToWrapper(context, (IntegerValue)result, CommonClassNames.JAVA_LANG_INTEGER); } if (result instanceof LongValue) { return convertToWrapper(context, (LongValue)result, CommonClassNames.JAVA_LANG_LONG); } if (result instanceof FloatValue) { return convertToWrapper(context, (FloatValue)result, CommonClassNames.JAVA_LANG_FLOAT); } if (result instanceof DoubleValue) { return convertToWrapper(context, (DoubleValue)result, CommonClassNames.JAVA_LANG_DOUBLE); } throw new EvaluateException("Cannot perform boxing conversion for a value of type " + ((Value)result).type().name()); }
@SuppressWarnings({"HardCodedStringLiteral"}) private static boolean overridesToString(Type type) { if(type instanceof ClassType) { final List<Method> methods = ((ClassType)type).methodsByName("toString", "()Ljava/lang/String;"); for (Method method : methods) { if (!(method.declaringType().name()).equals(CommonClassNames.JAVA_LANG_OBJECT)) { return true; } } } return false; }
@Override public void visitClass(@NotNull PsiClass aClass) { if (!InheritanceUtil.isInheritor(aClass, CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION)) { return; } registerClassError(aClass); }
public Renderer createRenderer(final String rendererId) { if (ClassRenderer.UNIQUE_ID.equals(rendererId)) { return myClassRenderer; } else if (ArrayRenderer.UNIQUE_ID.equals(rendererId)) { return myArrayRenderer; } else if (PrimitiveRenderer.UNIQUE_ID.equals(rendererId)) { return myPrimitiveRenderer; } else if(HexRenderer.UNIQUE_ID.equals(rendererId)) { return myHexRenderer; } else if(rendererId.equals(ExpressionChildrenRenderer.UNIQUE_ID)) { return new ExpressionChildrenRenderer(); } else if(rendererId.equals(LabelRenderer.UNIQUE_ID)) { return new LabelRenderer(); } else if(rendererId.equals(EnumerationChildrenRenderer.UNIQUE_ID)) { return new EnumerationChildrenRenderer(); } else if(rendererId.equals(ToStringRenderer.UNIQUE_ID)) { return myToStringRenderer; } else if(rendererId.equals(CompoundNodeRenderer.UNIQUE_ID) || rendererId.equals(REFERENCE_RENDERER)) { return createCompoundReferenceRenderer("unnamed", CommonClassNames.JAVA_LANG_OBJECT, null, null); } return null; }
public ListObjectRenderer(NodeRendererSettings rendererSettings) { super(rendererSettings, "List", createLabelRenderer(" size = ", "size()", null), createExpressionChildrenRenderer("toArray()", "!isEmpty()")); setClassName(CommonClassNames.JAVA_UTIL_LIST); }
@Override public boolean value(PsiElement expr) { if (!(expr instanceof PsiExpression)) { return false; } PsiType type = ((PsiExpression)expr).getType(); return type != null && CommonClassNames.JAVA_LANG_STRING.equals(type.getCanonicalText()); }
@Override public void visitMethodCallExpression(GrMethodCallExpression grMethodCallExpression) { super.visitMethodCallExpression(grMethodCallExpression); final GrArgumentList args = grMethodCallExpression.getArgumentList(); if (args == null) { return; } if (args.getExpressionArguments().length != 2) { return; } if (PsiImplUtil.hasNamedArguments(args)) { return; } final GrExpression methodExpression = grMethodCallExpression.getInvokedExpression(); if (!(methodExpression instanceof GrReferenceExpression)) { return; } final GrReferenceExpression referenceExpression = (GrReferenceExpression) methodExpression; final String name = referenceExpression.getReferenceName(); if (!"put".equals(name)) { return; } final GrExpression qualifier = referenceExpression.getQualifierExpression(); if (qualifier == null || PsiUtil.isThisOrSuperRef(qualifier)) { return; } if (referenceExpression.getDotTokenType() == GroovyTokenTypes.mOPTIONAL_DOT) return; final PsiType type = qualifier.getType(); if (!InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_MAP)) { return; } registerMethodCallError(grMethodCallExpression); }
@Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { return myRef.isValid() && JavaPsiFacade.getInstance(project).findClass(CommonClassNames.JAVA_LANG_OBJECT, file.getResolveScope()) != null && myModule != null && isFqnsOk(project, getPossibleFqns(myRef)); }
public void testIntersectStrictStrict2() throws Exception { ExpectedTypeInfo info1 = createInfo("java.lang.Exception", ExpectedTypeInfo.TYPE_STRICTLY); ExpectedTypeInfo info2 = createInfo(CommonClassNames.JAVA_LANG_OBJECT, ExpectedTypeInfo.TYPE_STRICTLY); ExpectedTypeInfo[] result = info1.intersect(info2); assertEquals(result.length, 0); }
public void testIntersectStrictSubtype2() throws Exception { ExpectedTypeInfo info1 = createInfo(CommonClassNames.JAVA_LANG_OBJECT, ExpectedTypeInfo.TYPE_STRICTLY); ExpectedTypeInfo info2 = createInfo("java.lang.Exception", ExpectedTypeInfo.TYPE_OR_SUBTYPE); ExpectedTypeInfo[] result = info1.intersect(info2); assertEquals(result.length, 0); }
@Override public String getQualifiedClassName(PsiClass psiClass, @Nullable PsiElement context) { if (context != null && psiClass != null) { psiClass = GenerationUtil.findAccessibleSuperClass(context, psiClass); } if (psiClass == null) { return CommonClassNames.JAVA_LANG_OBJECT; } final String name = psiClass.getQualifiedName(); if (name != null) return name; return psiClass.getName(); }
@Override public void visitMethodCallExpression(GrMethodCallExpression grMethodCallExpression) { super.visitMethodCallExpression(grMethodCallExpression); final GrArgumentList args = grMethodCallExpression.getArgumentList(); if (args == null) { return; } if (args.getExpressionArguments().length != 1) { return; } if (PsiImplUtil.hasNamedArguments(args)) { return; } final GrExpression methodExpression = grMethodCallExpression.getInvokedExpression(); if (!(methodExpression instanceof GrReferenceExpression)) { return; } final GrReferenceExpression referenceExpression = (GrReferenceExpression) methodExpression; final String name = referenceExpression.getReferenceName(); if (!"get".equals(name)) { return; } final GrExpression qualifier = referenceExpression.getQualifierExpression(); if (qualifier == null || PsiUtil.isThisOrSuperRef(qualifier)) { return; } if (referenceExpression.getDotTokenType() == GroovyTokenTypes.mOPTIONAL_DOT) return; final PsiType type = qualifier.getType(); if (!InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_MAP)) { return; } registerMethodCallError(grMethodCallExpression); }
@Override public void visitMethodCallExpression(GrMethodCallExpression grMethodCallExpression) { super.visitMethodCallExpression(grMethodCallExpression); final GrExpression methodExpression = grMethodCallExpression.getInvokedExpression(); if (!(methodExpression instanceof GrReferenceExpression)) { return; } final GrReferenceExpression reference = (GrReferenceExpression) methodExpression; final String name = reference.getReferenceName(); if (!"notify".equals(name) && !"notifyAll".equals(name)) { return; } final PsiMethod method = grMethodCallExpression.resolveMethod(); if (method == null) { return; } final PsiClass containingClass = method.getContainingClass(); if (containingClass == null || !CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) { return; } final GrMethod containingMethod = PsiTreeUtil.getParentOfType(grMethodCallExpression, GrMethod.class); if (containingMethod != null && containingMethod.hasModifierProperty(PsiModifier.SYNCHRONIZED)) { return; } final GrStatement parent = PsiTreeUtil.getParentOfType(grMethodCallExpression, GrSynchronizedStatement.class, GrClosableBlock.class); if (parent instanceof GrSynchronizedStatement) { return; } registerMethodCallError(grMethodCallExpression); }
@Nullable @Override public ConversionResult isConvertibleEx(@NotNull PsiType targetType, @NotNull PsiType actualType, @NotNull GroovyPsiElement context, @NotNull ApplicableTo currentPosition) { if (!isEnum(targetType)) return null; if (InheritanceUtil.isInheritor(actualType, GroovyCommonClassNames.GROOVY_LANG_GSTRING) || InheritanceUtil.isInheritor(actualType, CommonClassNames.JAVA_LANG_STRING)) { return GroovyConfigUtils.getInstance().isVersionAtLeast(context, GroovyConfigUtils.GROOVY1_8) ? ConversionResult.OK : ConversionResult.ERROR; } return null; }
@Override @NotNull protected PsiType[] getAllKeyTypes() { Set<PsiType> result = new HashSet<PsiType>(); if (!myStringEntries.isEmpty()) { result.add(GroovyPsiManager.getInstance(myFacade.getProject()).createTypeByFQClassName(CommonClassNames.JAVA_LANG_STRING, getResolveScope())); } for (Couple<PsiType> entry : myOtherEntries) { result.add(entry.first); } result.remove(null); return result.toArray(createArray(result.size())); }
@Override public void visitMethodCallExpression(GrMethodCallExpression grMethodCallExpression) { super.visitMethodCallExpression(grMethodCallExpression); final GrArgumentList args = grMethodCallExpression.getArgumentList(); if (args == null) { return; } if (args.getExpressionArguments().length != 2) { return; } if (PsiImplUtil.hasNamedArguments(args)) { return; } final GrExpression methodExpression = grMethodCallExpression.getInvokedExpression(); if (!(methodExpression instanceof GrReferenceExpression)) { return; } final GrReferenceExpression referenceExpression = (GrReferenceExpression) methodExpression; final String name = referenceExpression.getReferenceName(); if (!"set".equals(name)) { return; } final GrExpression qualifier = referenceExpression.getQualifierExpression(); if (qualifier == null || PsiUtil.isThisOrSuperRef(qualifier)) { return; } if (referenceExpression.getDotTokenType() == GroovyTokenTypes.mOPTIONAL_DOT) return; final PsiType type = qualifier.getType(); if (!InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_LIST)) { return; } registerMethodCallError(grMethodCallExpression); }
@NotNull @Override protected PsiType[] getAllKeyTypes() { Set<PsiType> result = ContainerUtil.newHashSet(); if (!myStringEntries.isEmpty()) { result.add(GroovyPsiManager.getInstance(myFacade.getProject()).createTypeByFQClassName(CommonClassNames.JAVA_LANG_STRING, getResolveScope())); } for (Couple<GrExpression> entry : myOtherEntries) { result.add(inferTypePreventingRecursion(entry.first)); } result.remove(null); return result.toArray(createArray(result.size())); }
@Override public void visitMethodCallExpression(GrMethodCallExpression grMethodCallExpression) { super.visitMethodCallExpression(grMethodCallExpression); final GrArgumentList args = grMethodCallExpression.getArgumentList(); if (args == null) { return; } if (args.getExpressionArguments().length != 1) { return; } if (PsiImplUtil.hasNamedArguments(args)) { return; } final GrExpression methodExpression = grMethodCallExpression.getInvokedExpression(); if (!(methodExpression instanceof GrReferenceExpression)) { return; } final GrReferenceExpression referenceExpression = (GrReferenceExpression) methodExpression; final String name = referenceExpression.getReferenceName(); if (!"get".equals(name)) { return; } final GrExpression qualifier = referenceExpression.getQualifierExpression(); if (qualifier == null || PsiUtil.isThisOrSuperRef(qualifier)) { return; } if (referenceExpression.getDotTokenType() == GroovyTokenTypes.mOPTIONAL_DOT) return; final PsiType type = qualifier.getType(); if (!InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_LIST)) { return; } registerMethodCallError(grMethodCallExpression); }
@Nullable @Override public ConversionResult isConvertibleEx(@NotNull PsiType lType, @NotNull PsiType rType, @NotNull GroovyPsiElement context, @NotNull ApplicableTo currentPosition) { if (!TypesUtil.isClassType(lType, CommonClassNames.JAVA_LANG_STRING)) return null; if (currentPosition == ApplicableTo.EXPLICIT_CAST) { return TypesUtil.isClassType(rType, GroovyCommonClassNames.GROOVY_LANG_GSTRING) ? ConversionResult.OK : null; } return ConversionResult.OK; }
@Override public void visitClass(@NotNull PsiClass aClass) { if (aClass.isInterface() || aClass.isAnnotationType() || aClass.isEnum() || aClass instanceof PsiTypeParameter) { return; } final PsiClass superClass = aClass.getSuperClass(); if (superClass == null) { return; } final String superclassName = superClass.getQualifiedName(); if (!CommonClassNames.JAVA_LANG_THROWABLE.equals(superclassName)) { return; } registerClassError(aClass, aClass); }
private void checkBody(GrCodeBlock body) { final GrStatement[] statements = body.getStatements(); if (statements.length == 0) { return; } for (final GrStatement statement : statements) { if (isConditional(statement)) { return; } if (!(statement instanceof GrMethodCallExpression)) { continue; } final GrMethodCallExpression methodCallExpression = (GrMethodCallExpression) statement; final GrExpression methodExpression = methodCallExpression.getInvokedExpression(); if (!(methodExpression instanceof GrReferenceExpression)) { return; } final GrReferenceExpression reference = (GrReferenceExpression) methodExpression; final String name = reference.getReferenceName(); if (!"wait".equals(name)) { return; } final PsiMethod method = methodCallExpression.resolveMethod(); if (method == null) { return; } final PsiClass containingClass = method.getContainingClass(); if (containingClass == null || !CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) { return; } registerMethodCallError(methodCallExpression); } }
@Override public void visitMethodCallExpression(GrMethodCallExpression grMethodCallExpression) { super.visitMethodCallExpression(grMethodCallExpression); final GrExpression methodExpression = grMethodCallExpression.getInvokedExpression(); if (!(methodExpression instanceof GrReferenceExpression)) { return; } final GrReferenceExpression reference = (GrReferenceExpression) methodExpression; final String name = reference.getReferenceName(); if (!"wait".equals(name)) { return; } final PsiMethod method = grMethodCallExpression.resolveMethod(); if (method == null) { return; } final PsiClass containingClass = method.getContainingClass(); if (containingClass == null || !CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) { return; } final GrMethod containingMethod = PsiTreeUtil.getParentOfType(grMethodCallExpression, GrMethod.class); if(containingMethod!=null && containingMethod.hasModifierProperty(PsiModifier.SYNCHRONIZED)) { return; } final GrStatement parent = PsiTreeUtil.getParentOfType(grMethodCallExpression, GrSynchronizedStatement.class, GrClosableBlock.class); if (parent instanceof GrSynchronizedStatement) { return; } registerMethodCallError(grMethodCallExpression); }
@Override public void visitClass(PsiClass aClass) { if (aClass instanceof PsiAnonymousClass || !InheritanceUtil.isInheritor(aClass, CommonClassNames.JAVA_UTIL_COMPARATOR) || SerializationUtils.isSerializable(aClass)) { return; } registerClassError(aClass, aClass); }
@Override public void visitMethod(@NotNull PsiMethod method) { //no call to super, so we don't drill into anonymous classes if (method.isConstructor()) { return; } final PsiClass containingClass = method.getContainingClass(); if (containingClass == null) { return; } if (containingClass.isInterface() || containingClass.isAnnotationType()) { return; } if (!method.hasModifierProperty(PsiModifier.ABSTRACT)) { return; } final PsiMethod[] superMethods = method.findSuperMethods(); for (final PsiMethod superMethod : superMethods) { final PsiClass superClass = superMethod.getContainingClass(); if (superClass == null) { continue; } final String superClassName = superClass.getQualifiedName(); if (!superClass.isInterface() && !CommonClassNames.JAVA_LANG_OBJECT.equals(superClassName) && !superMethod.hasModifierProperty(PsiModifier.ABSTRACT)) { registerMethodError(method); return; } } }