text
stringlengths
30
1.67M
<s> package org . codehaus . groovy . eclipse . codebrowsing . requestor ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . GenericsType ; import org . codehaus . groovy . ast . ImportNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Parameter ; import org . codehaus . groovy . ast . PropertyNode ; import org . codehaus . groovy . ast . Variable ; import org . codehaus . groovy . ast . expr . VariableExpression ; import org . codehaus . groovy . eclipse . codebrowsing . elements . GroovyResolvedBinaryField ; import org . codehaus . groovy . eclipse . codebrowsing . elements . GroovyResolvedBinaryMethod ; import org . codehaus . groovy . eclipse . codebrowsing . elements . GroovyResolvedBinaryType ; import org . codehaus . groovy . eclipse . codebrowsing . elements . GroovyResolvedSourceField ; import org . codehaus . groovy . eclipse . codebrowsing . elements . GroovyResolvedSourceMethod ; import org . codehaus . groovy . eclipse . codebrowsing . elements . GroovyResolvedSourceType ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . groovy . eclipse . core . model . GroovyProjectFacade ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . core . IField ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . ISourceRange ; import org . eclipse . jdt . core . ISourceReference ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . groovy . core . util . ReflectionUtils ; import org . eclipse . jdt . groovy . search . AccessorSupport ; import org . eclipse . jdt . groovy . search . GenericsMapper ; import org . eclipse . jdt . groovy . search . ITypeRequestor ; import org . eclipse . jdt . groovy . search . TypeLookupResult ; import org . eclipse . jdt . groovy . search . VariableScope ; import org . eclipse . jdt . internal . core . JavaElement ; import org . eclipse . jdt . internal . core . LocalVariable ; import org . eclipse . jdt . internal . core . util . Util ; public class CodeSelectRequestor implements ITypeRequestor { private final ASTNode nodeToLookFor ; private IJavaElement requestedElement ; private ASTNode requestedNode ; private final GroovyProjectFacade project ; private final GroovyCompilationUnit unit ; public CodeSelectRequestor ( ASTNode nodeToLookFor , GroovyCompilationUnit unit ) { this . nodeToLookFor = nodeToLookFor ; this . unit = unit ; this . project = new GroovyProjectFacade ( unit ) ; } public VisitStatus acceptASTNode ( ASTNode node , TypeLookupResult result , IJavaElement enclosingElement ) { if ( ! interestingElement ( enclosingElement ) ) { return VisitStatus . CANCEL_MEMBER ; } if ( node instanceof ImportNode ) { node = ( ( ImportNode ) node ) . getType ( ) ; if ( node == null ) { return VisitStatus . CONTINUE ; } } if ( doTest ( node ) ) { requestedNode = result . declaration ; if ( requestedNode instanceof ClassNode ) { requestedNode = ( ( ClassNode ) requestedNode ) . redirect ( ) ; } if ( requestedNode != null ) { if ( result . declaration instanceof VariableExpression ) { VariableExpression var = ( VariableExpression ) result . declaration ; requestedElement = createLocalVariable ( result , enclosingElement , var ) ; } else if ( result . declaration instanceof Parameter ) { Parameter var = ( Parameter ) result . declaration ; int position = var . getStart ( ) - <NUM_LIT:1> ; if ( position < <NUM_LIT:0> ) { position = nodeToLookFor . getStart ( ) - <NUM_LIT:1> ; } try { requestedElement = createLocalVariable ( result , ( JavaElement ) unit . getElementAt ( position ) , var ) ; } catch ( JavaModelException e ) { Util . log ( e , "<STR_LIT>" + position + "<STR_LIT>" + unit . getElementName ( ) ) ; } } else { ClassNode declaringType = findDeclaringType ( result ) ; if ( declaringType != null ) { IType type = project . groovyClassToJavaType ( declaringType ) ; if ( type == null && ! unit . isOnBuildPath ( ) ) { type = unit . getType ( declaringType . getNameWithoutPackage ( ) ) ; if ( ! type . exists ( ) ) { type = null ; } } if ( type != null ) { try { IJavaElement maybeRequested = findRequestedElement ( result , type ) ; requestedElement = resolveRequestedElement ( result , maybeRequested ) ; } catch ( JavaModelException e ) { GroovyCore . logException ( "<STR_LIT>" + node , e ) ; } } } } } return VisitStatus . STOP_VISIT ; } return VisitStatus . CONTINUE ; } private boolean interestingElement ( IJavaElement enclosingElement ) { if ( enclosingElement . getElementName ( ) . equals ( "<STR_LIT>" ) ) { return true ; } if ( enclosingElement instanceof ISourceReference ) { try { ISourceRange range = ( ( ISourceReference ) enclosingElement ) . getSourceRange ( ) ; return range . getOffset ( ) <= nodeToLookFor . getStart ( ) && range . getOffset ( ) + range . getLength ( ) >= nodeToLookFor . getEnd ( ) ; } catch ( JavaModelException e ) { Util . log ( e ) ; } } return false ; } private ClassNode findDeclaringType ( TypeLookupResult result ) { ClassNode declaringType = null ; if ( result . declaringType != null ) { declaringType = removeArray ( result . declaringType ) ; } else { if ( result . declaration instanceof FieldNode ) { declaringType = ( ( FieldNode ) result . declaration ) . getDeclaringClass ( ) ; } else if ( result . declaration instanceof MethodNode ) { declaringType = ( ( MethodNode ) result . declaration ) . getDeclaringClass ( ) ; } else if ( result . declaration instanceof PropertyNode ) { declaringType = ( ( PropertyNode ) result . declaration ) . getDeclaringClass ( ) ; } else if ( result . declaration instanceof ClassNode ) { declaringType = removeArray ( ( ClassNode ) result . declaration ) ; } } return declaringType ; } private IJavaElement findRequestedElement ( TypeLookupResult result , IType type ) throws JavaModelException { IJavaElement maybeRequested = null ; ASTNode declaration = result . declaration ; if ( declaration instanceof ClassNode ) { maybeRequested = type ; } else if ( type . getTypeRoot ( ) != null ) { if ( declaration . getEnd ( ) > <NUM_LIT:0> ) { IJavaElement [ ] children = type . getChildren ( ) ; int start = declaration . getStart ( ) ; int end = declaration . getEnd ( ) ; String name ; if ( declaration instanceof MethodNode ) { name = ( ( MethodNode ) declaration ) . getName ( ) ; } else if ( declaration instanceof FieldNode ) { name = ( ( FieldNode ) declaration ) . getName ( ) ; } else if ( declaration instanceof PropertyNode ) { name = ( ( PropertyNode ) declaration ) . getName ( ) ; } else { name = declaration . getText ( ) ; } for ( IJavaElement child : children ) { ISourceRange range = ( ( ISourceReference ) child ) . getSourceRange ( ) ; if ( range . getOffset ( ) <= start && range . getOffset ( ) + range . getLength ( ) >= end && child . getElementName ( ) . equals ( name ) ) { maybeRequested = child ; break ; } else if ( start + end < range . getOffset ( ) ) { break ; } } } if ( maybeRequested == null ) { String name = null ; int preferredParamNumber = - <NUM_LIT:1> ; if ( declaration instanceof MethodNode ) { name = ( ( MethodNode ) declaration ) . getName ( ) ; Parameter [ ] parameters = ( ( MethodNode ) declaration ) . getParameters ( ) ; preferredParamNumber = parameters == null ? <NUM_LIT:0> : parameters . length ; } else if ( declaration instanceof PropertyNode ) { name = ( ( PropertyNode ) declaration ) . getName ( ) ; } else if ( declaration instanceof FieldNode ) { name = ( ( FieldNode ) declaration ) . getName ( ) ; } if ( name != null ) { maybeRequested = findElement ( type , name , preferredParamNumber ) ; } if ( maybeRequested == null ) { maybeRequested = type ; } } } return maybeRequested ; } private IJavaElement resolveRequestedElement ( TypeLookupResult result , IJavaElement maybeRequested ) { AnnotatedNode declaration = ( AnnotatedNode ) result . declaration ; if ( declaration instanceof PropertyNode && maybeRequested instanceof IMethod ) { String getterName = maybeRequested . getElementName ( ) ; MethodNode maybeDeclaration = ( MethodNode ) declaration . getDeclaringClass ( ) . getMethods ( getterName ) . get ( <NUM_LIT:0> ) ; declaration = maybeDeclaration == null ? declaration : maybeDeclaration ; } String uniqueKey = createUniqueKey ( declaration , result . type , result . declaringType , maybeRequested ) ; IJavaElement candidate ; switch ( maybeRequested . getElementType ( ) ) { case IJavaElement . FIELD : if ( maybeRequested . isReadOnly ( ) ) { candidate = new GroovyResolvedBinaryField ( ( JavaElement ) maybeRequested . getParent ( ) , maybeRequested . getElementName ( ) , uniqueKey , result . extraDoc , result . declaration ) ; } else { candidate = new GroovyResolvedSourceField ( ( JavaElement ) maybeRequested . getParent ( ) , maybeRequested . getElementName ( ) , uniqueKey , result . extraDoc , result . declaration ) ; } break ; case IJavaElement . METHOD : if ( maybeRequested . isReadOnly ( ) ) { candidate = new GroovyResolvedBinaryMethod ( ( JavaElement ) maybeRequested . getParent ( ) , maybeRequested . getElementName ( ) , ( ( IMethod ) maybeRequested ) . getParameterTypes ( ) , uniqueKey , result . extraDoc , result . declaration ) ; } else { candidate = new GroovyResolvedSourceMethod ( ( JavaElement ) maybeRequested . getParent ( ) , maybeRequested . getElementName ( ) , ( ( IMethod ) maybeRequested ) . getParameterTypes ( ) , uniqueKey , result . extraDoc , result . declaration ) ; } break ; case IJavaElement . TYPE : if ( maybeRequested . isReadOnly ( ) ) { candidate = new GroovyResolvedBinaryType ( ( JavaElement ) maybeRequested . getParent ( ) , maybeRequested . getElementName ( ) , uniqueKey , result . extraDoc , result . declaration ) ; } else { candidate = new GroovyResolvedSourceType ( ( JavaElement ) maybeRequested . getParent ( ) , maybeRequested . getElementName ( ) , uniqueKey , result . extraDoc , result . declaration ) ; } break ; default : candidate = maybeRequested ; } requestedElement = candidate ; return requestedElement ; } private LocalVariable createLocalVariable ( TypeLookupResult result , IJavaElement enclosingElement , Variable var ) { ASTNode node = ( ASTNode ) var ; ClassNode type = result . type != null ? result . type : var . getType ( ) ; int start ; if ( node instanceof Parameter ) { start = ( ( Parameter ) node ) . getNameStart ( ) ; } else { start = node . getStart ( ) ; } return ReflectionUtils . createLocalVariable ( enclosingElement , var . getName ( ) , start , Signature . createTypeSignature ( createGenericsAwareName ( type , true ) , false ) ) ; } private String createGenericsAwareName ( ClassNode node , boolean useSimple ) { StringBuilder sb = new StringBuilder ( ) ; String name = node . getName ( ) ; StringBuilder sbArr ; if ( name . charAt ( <NUM_LIT:0> ) == '<CHAR_LIT:[>' ) { sbArr = new StringBuilder ( ) ; int arrayCount = <NUM_LIT:0> ; while ( name . charAt ( arrayCount ) == '<CHAR_LIT:[>' ) { sbArr . append ( "<STR_LIT:[]>" ) ; node = node . getComponentType ( ) ; arrayCount ++ ; } } else { sbArr = null ; } if ( useSimple ) { sb . append ( node . getNameWithoutPackage ( ) ) ; } else { sb . append ( node . getName ( ) ) ; } GenericsType [ ] genericsTypes = node . getGenericsTypes ( ) ; if ( genericsTypes != null && genericsTypes . length > <NUM_LIT:0> ) { sb . append ( '<CHAR_LIT>' ) ; for ( GenericsType gt : genericsTypes ) { ClassNode genericsType = gt . getType ( ) ; if ( genericsType == null || ! genericsType . getName ( ) . equals ( gt . getName ( ) ) ) { sb . append ( useSimple ? genericsType . getNameWithoutPackage ( ) : genericsType . getName ( ) ) ; } else { sb . append ( createGenericsAwareName ( genericsType , useSimple ) ) ; } sb . append ( '<CHAR_LIT:U+002C>' ) ; } sb . replace ( sb . length ( ) - <NUM_LIT:1> , sb . length ( ) , "<STR_LIT:>>" ) ; } if ( sbArr != null ) { sb . append ( sbArr ) ; } return sb . toString ( ) ; } private String createUniqueKey ( AnnotatedNode node , ClassNode resolvedType , ClassNode resolvedDeclaringType , IJavaElement maybeRequested ) { if ( resolvedDeclaringType == null ) { resolvedDeclaringType = node . getDeclaringClass ( ) ; if ( resolvedDeclaringType == null ) { resolvedDeclaringType = VariableScope . OBJECT_CLASS_NODE ; } } StringBuilder sb = new StringBuilder ( ) ; if ( node instanceof PropertyNode ) { node = ( ( PropertyNode ) node ) . getField ( ) ; } if ( node instanceof FieldNode ) { return createUniqueKeyForField ( ( FieldNode ) node , resolvedType , resolvedDeclaringType ) . toString ( ) ; } else if ( node instanceof MethodNode ) { if ( maybeRequested . getElementType ( ) == IJavaElement . FIELD ) { return createUniqueKeyForGeneratedAccessor ( ( MethodNode ) node , resolvedType , resolvedDeclaringType , ( IField ) maybeRequested ) . toString ( ) ; } else { return createUniqueKeyForMethod ( ( MethodNode ) node , resolvedType , resolvedDeclaringType ) . toString ( ) ; } } else if ( node instanceof ClassNode ) { return createUniqueKeyForClass ( resolvedType , resolvedDeclaringType ) . toString ( ) ; } return sb . toString ( ) ; } private StringBuilder createUniqueKeyForMethod ( MethodNode node , ClassNode resolvedType , ClassNode resolvedDeclaringType ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( createUniqueKeyForClass ( node . getDeclaringClass ( ) , resolvedDeclaringType ) ) ; sb . append ( '<CHAR_LIT:.>' ) . append ( node . getName ( ) ) ; sb . append ( '<CHAR_LIT:(>' ) ; if ( node . getParameters ( ) != null ) { for ( Parameter param : node . getParameters ( ) ) { ClassNode paramType = param . getType ( ) != null ? param . getType ( ) : VariableScope . OBJECT_CLASS_NODE ; sb . append ( createUniqueKeyForClass ( paramType , resolvedDeclaringType ) ) ; } } sb . append ( '<CHAR_LIT:)>' ) ; sb . append ( createUniqueKeyForResolvedClass ( resolvedType ) ) ; return sb ; } private StringBuilder createUniqueKeyForField ( FieldNode node , ClassNode resolvedType , ClassNode resolvedDeclaringType ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( createUniqueKeyForClass ( node . getDeclaringClass ( ) , resolvedDeclaringType ) ) ; sb . append ( '<CHAR_LIT:.>' ) . append ( node . getName ( ) ) . append ( '<CHAR_LIT:)>' ) ; sb . append ( createUniqueKeyForResolvedClass ( resolvedType ) ) ; return sb ; } private StringBuilder createUniqueKeyForGeneratedAccessor ( MethodNode node , ClassNode resolvedType , ClassNode resolvedDeclaringType , IField actualField ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( createUniqueKeyForClass ( node . getDeclaringClass ( ) , resolvedDeclaringType ) ) ; sb . append ( '<CHAR_LIT:.>' ) . append ( actualField . getElementName ( ) ) . append ( '<CHAR_LIT:)>' ) ; ClassNode typeOfField = node . getName ( ) . startsWith ( "<STR_LIT>" ) && node . getParameters ( ) != null && node . getParameters ( ) . length > <NUM_LIT:0> ? node . getParameters ( ) [ <NUM_LIT:0> ] . getType ( ) : resolvedType ; sb . append ( createUniqueKeyForResolvedClass ( typeOfField ) ) ; return sb ; } private StringBuilder createUniqueKeyForResolvedClass ( ClassNode resolvedType ) { if ( resolvedType . getName ( ) . equals ( "<STR_LIT>" ) ) { resolvedType = VariableScope . VOID_CLASS_NODE ; } return new StringBuilder ( Signature . createTypeSignature ( createGenericsAwareName ( resolvedType , false ) , true ) . replace ( '<CHAR_LIT:.>' , '<CHAR_LIT:/>' ) ) ; } private StringBuilder createUniqueKeyForClass ( ClassNode unresolvedType , ClassNode resolvedDeclaringType ) { GenericsMapper mapper = GenericsMapper . gatherGenerics ( resolvedDeclaringType , resolvedDeclaringType . redirect ( ) ) ; ClassNode resolvedType = VariableScope . resolveTypeParameterization ( mapper , VariableScope . clone ( unresolvedType ) ) ; return createUniqueKeyForResolvedClass ( resolvedType ) ; } private boolean doTest ( ASTNode node ) { return node . getClass ( ) == nodeToLookFor . getClass ( ) && nodeToLookFor . getStart ( ) == node . getStart ( ) && nodeToLookFor . getEnd ( ) == node . getEnd ( ) ; } private ClassNode removeArray ( ClassNode declaration ) { return declaration . getComponentType ( ) != null ? removeArray ( declaration . getComponentType ( ) ) : declaration ; } private IJavaElement findElement ( IType type , String text , int preferredParamNumber ) throws JavaModelException { if ( text . equals ( type . getElementName ( ) ) ) { return type ; } String setMethod = AccessorSupport . SETTER . createAccessorName ( text ) ; String getMethod = AccessorSupport . GETTER . createAccessorName ( text ) ; String isMethod = AccessorSupport . ISSER . createAccessorName ( text ) ; IMethod lastFound = null ; for ( IMethod method : type . getMethods ( ) ) { if ( method . getElementName ( ) . equals ( text ) ) { if ( method . getParameterTypes ( ) . length == preferredParamNumber ) { return method ; } else { lastFound = method ; } } } if ( lastFound != null ) { return lastFound ; } IField field = type . getField ( text ) ; String prefix ; if ( ! field . exists ( ) && ( prefix = extractPrefix ( text ) ) != null ) { String newName = Character . toLowerCase ( text . charAt ( prefix . length ( ) ) ) + text . substring ( prefix . length ( ) + <NUM_LIT:1> ) ; field = type . getField ( newName ) ; } if ( field . exists ( ) ) { return field ; } for ( IMethod method : type . getMethods ( ) ) { if ( method . getElementName ( ) . equals ( setMethod ) || method . getElementName ( ) . equals ( getMethod ) || method . getElementName ( ) . equals ( isMethod ) ) { return method ; } } return null ; } private String extractPrefix ( String text ) { if ( text . startsWith ( "<STR_LIT>" ) ) { if ( text . length ( ) > <NUM_LIT:2> ) { return "<STR_LIT>" ; } } else if ( text . startsWith ( "<STR_LIT:get>" ) ) { if ( text . length ( ) > <NUM_LIT:3> ) { return "<STR_LIT:get>" ; } } else if ( text . startsWith ( "<STR_LIT>" ) ) { if ( text . length ( ) > <NUM_LIT:3> ) { return "<STR_LIT>" ; } } return null ; } public ASTNode getRequestedNode ( ) { return requestedNode ; } public IJavaElement getRequestedElement ( ) { return requestedElement ; } } </s>
<s> package org . codehaus . groovy . eclipse . codebrowsing . requestor ; import java . util . Iterator ; import java . util . List ; import java . util . Map ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . AnnotationNode ; import org . codehaus . groovy . ast . ClassCodeVisitorSupport ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . GenericsType ; import org . codehaus . groovy . ast . ImportNode ; import org . codehaus . groovy . ast . ImportNodeCompatibilityWrapper ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . ast . PackageNode ; import org . codehaus . groovy . ast . Parameter ; import org . codehaus . groovy . ast . expr . AnnotationConstantExpression ; import org . codehaus . groovy . ast . expr . ArrayExpression ; import org . codehaus . groovy . ast . expr . BinaryExpression ; import org . codehaus . groovy . ast . expr . CastExpression ; import org . codehaus . groovy . ast . expr . ClassExpression ; import org . codehaus . groovy . ast . expr . ClosureExpression ; import org . codehaus . groovy . ast . expr . ConstantExpression ; import org . codehaus . groovy . ast . expr . ConstructorCallExpression ; import org . codehaus . groovy . ast . expr . DeclarationExpression ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . ast . expr . FieldExpression ; import org . codehaus . groovy . ast . expr . GStringExpression ; import org . codehaus . groovy . ast . expr . StaticMethodCallExpression ; import org . codehaus . groovy . ast . expr . VariableExpression ; import org . codehaus . groovy . ast . stmt . BlockStatement ; import org . codehaus . groovy . ast . stmt . CatchStatement ; import org . codehaus . groovy . ast . stmt . ForStatement ; import org . codehaus . groovy . ast . stmt . ReturnStatement ; import org . codehaus . groovy . ast . stmt . Statement ; import org . codehaus . groovy . control . SourceUnit ; import org . codehaus . groovy . eclipse . core . util . VisitCompleteException ; import org . codehaus . groovy . runtime . GeneratedClosure ; import org . eclipse . jdt . groovy . core . util . ReflectionUtils ; public class ASTNodeFinder extends ClassCodeVisitorSupport { protected ASTNode nodeFound ; private Region r ; public ASTNodeFinder ( Region r ) { this . r = r ; } public Region getRegion ( ) { return r ; } @ Override protected SourceUnit getSourceUnit ( ) { return null ; } @ Override public void visitReturnStatement ( ReturnStatement ret ) { if ( ret . getExpression ( ) instanceof AnnotationConstantExpression ) { check ( ( ( AnnotationConstantExpression ) ret . getExpression ( ) ) . getType ( ) ) ; } super . visitReturnStatement ( ret ) ; } @ Override public void visitVariableExpression ( VariableExpression expression ) { Object maybeAnnotatedNode = expression ; if ( maybeAnnotatedNode instanceof AnnotatedNode ) { visitAnnotations ( ( AnnotatedNode ) maybeAnnotatedNode ) ; } check ( expression ) ; super . visitVariableExpression ( expression ) ; } @ Override public void visitFieldExpression ( FieldExpression expression ) { check ( expression ) ; super . visitFieldExpression ( expression ) ; } @ Override public void visitClassExpression ( ClassExpression expression ) { check ( expression ) ; super . visitClassExpression ( expression ) ; } @ Override public void visitClosureExpression ( ClosureExpression expression ) { checkParameters ( expression . getParameters ( ) ) ; super . visitClosureExpression ( expression ) ; } @ Override protected void visitConstructorOrMethod ( MethodNode node , boolean isConstructor ) { if ( node . getEnd ( ) > <NUM_LIT:0> ) { ClassNode expression = node . getReturnType ( ) ; if ( expression != null ) { visitClassReference ( expression ) ; } if ( node . getExceptions ( ) != null ) { for ( ClassNode e : node . getExceptions ( ) ) { visitClassReference ( e ) ; } } checkParameters ( node . getParameters ( ) ) ; } super . visitConstructorOrMethod ( node , isConstructor ) ; if ( node . getNameEnd ( ) > <NUM_LIT:0> ) { checkNameRange ( node ) ; } } private void checkParameters ( Parameter [ ] params ) { if ( params != null ) { for ( Parameter p : params ) { checkParameter ( p ) ; } } } private void checkParameter ( Parameter p ) { if ( p != null && p . getEnd ( ) > <NUM_LIT:0> ) { check ( p . getType ( ) ) ; if ( p . getInitialExpression ( ) != null ) { p . getInitialExpression ( ) . visit ( this ) ; } check ( p ) ; } } @ Override public void visitField ( FieldNode node ) { if ( node . getName ( ) . contains ( "<STR_LIT:$>" ) ) { return ; } visitClassReference ( node . getType ( ) ) ; super . visitField ( node ) ; if ( node . getNameEnd ( ) > <NUM_LIT:0> ) { checkNameRange ( node ) ; } } @ Override public void visitCastExpression ( CastExpression node ) { check ( node . getType ( ) ) ; super . visitCastExpression ( node ) ; } @ Override public void visitConstantExpression ( ConstantExpression expression ) { if ( expression == ConstantExpression . NULL ) { return ; } if ( expression . getText ( ) . length ( ) == <NUM_LIT:0> && expression . getLength ( ) != <NUM_LIT:0> ) { return ; } check ( expression ) ; super . visitConstantExpression ( expression ) ; } @ Override public void visitDeclarationExpression ( DeclarationExpression expression ) { Object maybeAnnotatedNode = expression ; if ( maybeAnnotatedNode instanceof AnnotatedNode ) { visitAnnotations ( ( AnnotatedNode ) maybeAnnotatedNode ) ; } check ( expression . getLeftExpression ( ) . getType ( ) ) ; super . visitDeclarationExpression ( expression ) ; } @ Override public void visitConstructorCallExpression ( ConstructorCallExpression call ) { check ( call . getType ( ) ) ; super . visitConstructorCallExpression ( call ) ; } @ Override public void visitCatchStatement ( CatchStatement statement ) { checkParameter ( statement . getVariable ( ) ) ; super . visitCatchStatement ( statement ) ; } @ Override public void visitForLoop ( ForStatement forLoop ) { checkParameter ( forLoop . getVariable ( ) ) ; super . visitForLoop ( forLoop ) ; } @ Override public void visitArrayExpression ( ArrayExpression expression ) { ClassNode arrayClass = expression . getElementType ( ) ; if ( arrayClass != arrayClass . redirect ( ) ) { check ( arrayClass ) ; } else { } super . visitArrayExpression ( expression ) ; } @ Override public void visitStaticMethodCallExpression ( StaticMethodCallExpression call ) { if ( call . getOwnerType ( ) != call . getOwnerType ( ) . redirect ( ) ) { check ( call . getOwnerType ( ) ) ; } super . visitStaticMethodCallExpression ( call ) ; check ( call ) ; } @ Override public void visitClass ( ClassNode node ) { if ( node . getNameEnd ( ) > <NUM_LIT:0> ) { checkNameRange ( node ) ; } ClassNode unresolvedSuperClass = node . getUnresolvedSuperClass ( ) ; if ( unresolvedSuperClass != null && unresolvedSuperClass . getEnd ( ) > <NUM_LIT:0> ) { visitClassReference ( unresolvedSuperClass ) ; } if ( node . getInterfaces ( ) != null ) { for ( ClassNode inter : node . getInterfaces ( ) ) { if ( inter . getEnd ( ) > <NUM_LIT:0> ) { visitClassReference ( inter ) ; } } } if ( node . getObjectInitializerStatements ( ) != null ) { for ( Statement element : ( Iterable < Statement > ) node . getObjectInitializerStatements ( ) ) { element . visit ( this ) ; } } Iterator < ClassNode > innerClasses ; try { innerClasses = ( Iterator < ClassNode > ) ReflectionUtils . throwableExecutePrivateMethod ( ClassNode . class , "<STR_LIT>" , new Class < ? > [ <NUM_LIT:0> ] , node , new Object [ <NUM_LIT:0> ] ) ; } catch ( Exception e ) { innerClasses = null ; } if ( innerClasses != null ) { while ( innerClasses . hasNext ( ) ) { ClassNode inner = innerClasses . next ( ) ; if ( ! inner . isSynthetic ( ) || inner instanceof GeneratedClosure ) { this . visitClass ( inner ) ; } } } VisitCompleteException candidate = null ; try { MethodNode clinit = node . getMethod ( "<STR_LIT>" , new Parameter [ <NUM_LIT:0> ] ) ; if ( clinit != null && clinit . getCode ( ) instanceof BlockStatement ) { for ( Statement element : ( Iterable < Statement > ) ( ( BlockStatement ) clinit . getCode ( ) ) . getStatements ( ) ) { element . visit ( this ) ; } } } catch ( VisitCompleteException e ) { candidate = e ; } visitAnnotations ( node ) ; node . visitContents ( this ) ; if ( candidate != null ) { throw candidate ; } } private void visitClassReference ( ClassNode node ) { if ( node . isUsingGenerics ( ) && node . getGenericsTypes ( ) != null ) { for ( GenericsType gen : node . getGenericsTypes ( ) ) { if ( gen . getLowerBound ( ) != null ) { visitClassReference ( gen . getLowerBound ( ) ) ; } if ( gen . getUpperBounds ( ) != null ) { for ( ClassNode upper : gen . getUpperBounds ( ) ) { if ( ! upper . getName ( ) . equals ( node . getName ( ) ) ) { visitClassReference ( upper ) ; } } } if ( gen . getType ( ) != null && gen . getName ( ) . charAt ( <NUM_LIT:0> ) != '<CHAR_LIT>' ) { visitClassReference ( gen . getType ( ) ) ; } } } check ( node ) ; } @ Override public void visitAnnotations ( AnnotatedNode node ) { List < AnnotationNode > annotations = node . getAnnotations ( ) ; if ( annotations . isEmpty ( ) ) return ; for ( AnnotationNode an : annotations ) { if ( an . isBuiltIn ( ) ) continue ; check ( an . getClassNode ( ) ) ; for ( Map . Entry < String , Expression > member : ( Iterable < Map . Entry < String , Expression > > ) an . getMembers ( ) . entrySet ( ) ) { Expression value = member . getValue ( ) ; if ( value instanceof AnnotationConstantExpression ) { check ( ( ( AnnotationConstantExpression ) value ) . getType ( ) ) ; } value . visit ( this ) ; } } } @ Override public void visitGStringExpression ( GStringExpression expression ) { super . visitGStringExpression ( expression ) ; } public void visitPackage ( PackageNode node ) { visitAnnotations ( node ) ; if ( node != null ) { check ( node ) ; } } @ Override public void visitImports ( ModuleNode module ) { for ( ImportNode importNode : new ImportNodeCompatibilityWrapper ( module ) . getAllImportNodes ( ) ) { if ( importNode . getType ( ) != null ) { visitAnnotations ( importNode ) ; check ( importNode . getType ( ) ) ; if ( importNode . getFieldNameExpr ( ) != null ) { check ( importNode . getFieldNameExpr ( ) ) ; } if ( importNode . getAliasExpr ( ) != null ) { check ( importNode . getAliasExpr ( ) ) ; } } } } @ Override public void visitBinaryExpression ( BinaryExpression expression ) { super . visitBinaryExpression ( expression ) ; check ( expression ) ; } protected void check ( ASTNode node ) { if ( doTest ( node ) ) { nodeFound = node ; throw new VisitCompleteException ( ) ; } if ( node instanceof ClassNode ) { checkGenerics ( ( ClassNode ) node ) ; } } protected void checkNameRange ( AnnotatedNode node ) { if ( doNameRangeTest ( node ) ) { nodeFound = node ; throw new VisitCompleteException ( ) ; } if ( node instanceof ClassNode ) { checkGenerics ( ( ClassNode ) node ) ; } } private void checkGenerics ( ClassNode node ) { if ( node . isUsingGenerics ( ) && node . getGenericsTypes ( ) != null ) { for ( GenericsType gen : node . getGenericsTypes ( ) ) { if ( gen . getLowerBound ( ) != null ) { check ( gen . getLowerBound ( ) ) ; } if ( gen . getUpperBounds ( ) != null ) { for ( ClassNode upper : gen . getUpperBounds ( ) ) { if ( ! upper . getName ( ) . equals ( node . getName ( ) ) ) { check ( upper ) ; } } } if ( gen . getType ( ) != null && gen . getType ( ) . getName ( ) . charAt ( <NUM_LIT:0> ) != '<CHAR_LIT>' ) { check ( gen . getType ( ) ) ; } } } } protected boolean doTest ( ASTNode node ) { return node . getEnd ( ) > <NUM_LIT:0> && r . regionIsCoveredByNode ( node ) ; } protected boolean doNameRangeTest ( AnnotatedNode node ) { return r . regionIsCoveredByNameRange ( node ) ; } public ASTNode doVisit ( ModuleNode module ) { try { PackageNode pack = module . getPackage ( ) ; if ( pack != null ) { visitPackage ( pack ) ; } visitImports ( module ) ; for ( ClassNode clazz : ( Iterable < ClassNode > ) module . getClasses ( ) ) { this . visitClass ( clazz ) ; } } catch ( VisitCompleteException e ) { } return nodeFound ; } } </s>
<s> package org . codehaus . groovy . eclipse . codebrowsing . requestor ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . expr . VariableExpression ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . IASTFragment ; public class Region { private final int start ; private final int length ; public Region ( ASTNode node ) { this . start = node . getStart ( ) ; this . length = node . getLength ( ) ; } public Region ( IASTFragment node ) { this . start = node . getStart ( ) ; this . length = node . getLength ( ) ; } public Region ( int start , int length ) { this . start = start ; this . length = length ; } public int getLength ( ) { return length ; } public int getOffset ( ) { return start ; } public int getEnd ( ) { return start + length ; } public boolean regionCoversNode ( ASTNode node ) { return this . start <= node . getStart ( ) && this . getEnd ( ) >= node . getEnd ( ) ; } public boolean regionIsCoveredByNode ( ASTNode node ) { return this . start >= node . getStart ( ) && this . getEnd ( ) <= node . getEnd ( ) ; } public boolean regionIsCoveredByNameRange ( AnnotatedNode node ) { return this . start >= node . getNameStart ( ) && this . getEnd ( ) <= node . getNameEnd ( ) + <NUM_LIT:1> ; } public boolean regionIsGStringCoveredByNode ( ASTNode node ) { if ( node instanceof VariableExpression ) { return this . start >= node . getStart ( ) - <NUM_LIT:1> && this . getEnd ( ) <= node . getEnd ( ) ; } else { return regionIsCoveredByNode ( node ) ; } } public boolean isNonOverlapping ( ASTNode node ) { return ( this . getEnd ( ) <= node . getStart ( ) ) || ( this . start >= node . getEnd ( ) ) ; } public boolean isSame ( ASTNode node ) { return this . start == node . getStart ( ) && this . getEnd ( ) == node . getEnd ( ) ; } public boolean isSame ( IASTFragment node ) { return this . start == node . getStart ( ) && this . getEnd ( ) == node . getEnd ( ) ; } @ Override public int hashCode ( ) { final int prime = <NUM_LIT:31> ; int result = <NUM_LIT:1> ; result = prime * result + length ; result = prime * result + start ; return result ; } @ Override public boolean equals ( Object obj ) { if ( this == obj ) return true ; if ( obj == null ) return false ; if ( getClass ( ) != obj . getClass ( ) ) return false ; Region other = ( Region ) obj ; if ( length != other . length ) return false ; if ( start != other . start ) return false ; return true ; } @ Override public String toString ( ) { return "<STR_LIT>" + start + "<STR_LIT>" + length + "<STR_LIT:]>" ; } public boolean endsIn ( ASTNode node ) { return node . getStart ( ) < getEnd ( ) && length < node . getLength ( ) ; } public boolean isEmpty ( ) { return start == <NUM_LIT:0> && length == <NUM_LIT:0> ; } } </s>
<s> package org . codehaus . groovy . eclipse . codebrowsing . requestor ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . eclipse . GroovyLogManager ; import org . codehaus . groovy . eclipse . TraceCategory ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . codehaus . jdt . groovy . model . ICodeSelectHelper ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . groovy . search . TypeInferencingVisitorFactory ; import org . eclipse . jdt . groovy . search . TypeInferencingVisitorWithRequestor ; public class CodeSelectHelper implements ICodeSelectHelper { public IJavaElement [ ] select ( GroovyCompilationUnit unit , int start , int length ) { ModuleNode module = unit . getModuleNode ( ) ; char [ ] contents = unit . getContents ( ) ; if ( length > <NUM_LIT:1> && start + length < contents . length && contents [ start ] == '<CHAR_LIT>' && contents [ start + <NUM_LIT:1> ] != '<CHAR_LIT>' ) { start ++ ; length -- ; } if ( module != null ) { String event = null ; if ( GroovyLogManager . manager . hasLoggers ( ) ) { GroovyLogManager . manager . log ( TraceCategory . CODESELECT , "<STR_LIT>" + unit . getElementName ( ) + "<STR_LIT>" + start + "<STR_LIT:U+002C>" + length + "<STR_LIT>" ) ; event = "<STR_LIT>" + unit . getElementName ( ) ; GroovyLogManager . manager . logStart ( event ) ; } try { ASTNode nodeToLookFor = findASTNodeAt ( module , new Region ( start , length ) ) ; if ( nodeToLookFor != null ) { if ( isTypeDeclaration ( module , nodeToLookFor ) ) { return returnThisNode ( unit , nodeToLookFor ) ; } CodeSelectRequestor requestor = createRequestor ( unit , nodeToLookFor ) ; TypeInferencingVisitorWithRequestor visitor = new TypeInferencingVisitorFactory ( ) . createVisitor ( unit ) ; visitor . visitCompilationUnit ( requestor ) ; return requestor . getRequestedElement ( ) != null ? new IJavaElement [ ] { requestor . getRequestedElement ( ) } : new IJavaElement [ <NUM_LIT:0> ] ; } } finally { if ( event != null ) { GroovyLogManager . manager . logEnd ( event , TraceCategory . CODESELECT ) ; } } } return new IJavaElement [ <NUM_LIT:0> ] ; } protected CodeSelectRequestor createRequestor ( GroovyCompilationUnit unit , ASTNode nodeToLookFor ) { return new CodeSelectRequestor ( nodeToLookFor , unit ) ; } public ASTNode selectASTNode ( GroovyCompilationUnit unit , int start , int length ) { ModuleNode module = unit . getModuleNode ( ) ; if ( module != null ) { String event = null ; if ( GroovyLogManager . manager . hasLoggers ( ) ) { GroovyLogManager . manager . log ( TraceCategory . CODESELECT , "<STR_LIT>" + unit . getElementName ( ) + "<STR_LIT>" + start + "<STR_LIT:U+002C>" + length + "<STR_LIT>" ) ; event = "<STR_LIT>" + unit . getElementName ( ) ; GroovyLogManager . manager . logStart ( event ) ; } try { ASTNode nodeToLookFor = findASTNodeAt ( module , new Region ( start , length ) ) ; if ( nodeToLookFor != null ) { if ( isTypeDeclaration ( module , nodeToLookFor ) ) { return ( ( ClassNode ) nodeToLookFor ) . redirect ( ) ; } CodeSelectRequestor requestor = createRequestor ( unit , nodeToLookFor ) ; TypeInferencingVisitorWithRequestor visitor = new TypeInferencingVisitorFactory ( ) . createVisitor ( unit ) ; visitor . visitCompilationUnit ( requestor ) ; return requestor . getRequestedNode ( ) ; } } finally { if ( event != null ) { GroovyLogManager . manager . logEnd ( event , TraceCategory . CODESELECT ) ; } } } return null ; } private IJavaElement [ ] returnThisNode ( GroovyCompilationUnit unit , ASTNode nodeToLookFor ) { String rawName = ( ( ClassNode ) nodeToLookFor ) . getNameWithoutPackage ( ) ; String [ ] enclosingTypes = rawName . split ( "<STR_LIT>" ) ; IType candidate = null ; for ( int i = <NUM_LIT:0> ; i < enclosingTypes . length ; i ++ ) { if ( i == <NUM_LIT:0> ) { candidate = unit . getType ( enclosingTypes [ i ] ) ; } else { candidate = candidate . getType ( enclosingTypes [ i ] ) ; } } return new IJavaElement [ ] { candidate } ; } private boolean isTypeDeclaration ( ModuleNode module , ASTNode nodeToLookFor ) { if ( nodeToLookFor instanceof ClassNode ) { for ( ClassNode clazz : ( Iterable < ClassNode > ) module . getClasses ( ) ) { if ( clazz == nodeToLookFor ) { return true ; } } } return false ; } private ASTNode findASTNodeAt ( ModuleNode module , Region r ) { ASTNodeFinder finder = new ASTNodeFinder ( r ) ; return finder . doVisit ( module ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . proposals ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Set ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . eclipse . GroovyLogManager ; import org . codehaus . groovy . eclipse . TraceCategory ; import org . codehaus . groovy . eclipse . codeassist . processors . IProposalProvider ; import org . codehaus . groovy . eclipse . codeassist . proposals . IGroovyProposal ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistLocation ; import org . codehaus . groovy . eclipse . codeassist . requestor . MethodInfoContentAssistContext ; import org . codehaus . groovy . eclipse . dsl . DSLDStore ; import org . codehaus . groovy . eclipse . dsl . DSLPreferences ; import org . codehaus . groovy . eclipse . dsl . GroovyDSLCoreActivator ; import org . codehaus . groovy . eclipse . dsl . contributions . IContributionElement ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . jdt . groovy . model . ModuleNodeMapper . ModuleNodeInfo ; import org . eclipse . core . runtime . CoreException ; public class DSLDProposalProvider implements IProposalProvider { public List < IGroovyProposal > getStatementAndExpressionProposals ( ContentAssistContext context , ClassNode completionType , boolean isStatic , Set < ClassNode > categories ) { String event = null ; if ( GroovyLogManager . manager . hasLoggers ( ) ) { GroovyLogManager . manager . log ( TraceCategory . DSL , "<STR_LIT>" + context . fullCompletionExpression ) ; event = "<STR_LIT>" ; GroovyLogManager . manager . logStart ( event ) ; } List < IContributionElement > contributions ; List < IGroovyProposal > proposals = new ArrayList < IGroovyProposal > ( ) ; try { DSLDStore store = GroovyDSLCoreActivator . getDefault ( ) . getContextStoreManager ( ) . getDSLDStore ( context . unit . getJavaProject ( ) ) ; ModuleNodeInfo info = context . unit . getModuleInfo ( true ) ; if ( info == null ) { if ( GroovyLogManager . manager . hasLoggers ( ) ) { GroovyLogManager . manager . log ( TraceCategory . CONTENT_ASSIST , "<STR_LIT>" + context . unit . getElementName ( ) ) ; } return Collections . EMPTY_LIST ; } GroovyDSLDContext pattern = new GroovyDSLDContext ( context . unit , info . module , info . resolver ) ; pattern . setCurrentScope ( context . currentScope ) ; pattern . setTargetType ( completionType ) ; pattern . setStatic ( isStatic ) ; pattern . setPrimaryNode ( context . location == ContentAssistLocation . STATEMENT || ( context . location == ContentAssistLocation . METHOD_CONTEXT && context . currentScope . isPrimaryNode ( ) ) ) ; contributions = store . findContributions ( pattern , DSLPreferences . getDisabledScriptsAsSet ( ) ) ; boolean isMethodContext = context instanceof MethodInfoContentAssistContext ; for ( IContributionElement element : contributions ) { if ( element . contributionName ( ) . startsWith ( context . getPerceivedCompletionExpression ( ) ) ) { IGroovyProposal proposal = element . toProposal ( completionType , pattern . getResolverCache ( ) ) ; if ( proposal != null ) { proposals . add ( proposal ) ; } if ( isMethodContext ) { proposals . addAll ( element . extraProposals ( completionType , pattern . getResolverCache ( ) , ( Expression ) ( ( MethodInfoContentAssistContext ) context ) . completionNode ) ) ; } } } } catch ( CoreException e ) { GroovyDSLCoreActivator . logException ( e ) ; } if ( event != null ) { GroovyLogManager . manager . logEnd ( event , TraceCategory . DSL ) ; } return proposals ; } public List < MethodNode > getNewMethodProposals ( ContentAssistContext context ) { return null ; } public List < String > getNewFieldProposals ( ContentAssistContext context ) { return null ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl ; import java . util . HashSet ; import java . util . Set ; import org . eclipse . core . resources . IResource ; public class DSLPreferences { public static final String AUTO_ADD_DSL_SUPPORT = "<STR_LIT>" ; public static final String DISABLED_SCRIPTS = "<STR_LIT>" ; private final static String [ ] EMPTY = new String [ <NUM_LIT:0> ] ; private DSLPreferences ( ) { } public static String [ ] getDisabledScripts ( ) { String disabled = GroovyDSLCoreActivator . getDefault ( ) . getPreferenceStore ( ) . getString ( DISABLED_SCRIPTS ) ; if ( disabled == null ) { return EMPTY ; } return disabled . split ( "<STR_LIT:U+002C>" ) ; } public static Set < String > getDisabledScriptsAsSet ( ) { String [ ] disabled = getDisabledScripts ( ) ; Set < String > set = new HashSet < String > ( disabled . length * <NUM_LIT:2> ) ; for ( String dis : disabled ) { set . add ( dis ) ; } return set ; } public static void setDisabledScripts ( String [ ] disabled ) { String [ ] filtered = filter ( disabled ) ; GroovyDSLCoreActivator . getDefault ( ) . getPreferenceStore ( ) . putValue ( DISABLED_SCRIPTS , join ( filtered ) ) ; } private static String join ( String [ ] filtered ) { StringBuilder sb = new StringBuilder ( ) ; if ( filtered . length > <NUM_LIT:0> ) { for ( String s : filtered ) { sb . append ( s ) ; sb . append ( '<CHAR_LIT:U+002C>' ) ; } sb . replace ( sb . length ( ) - <NUM_LIT:1> , sb . length ( ) , "<STR_LIT>" ) ; return sb . toString ( ) ; } else { return "<STR_LIT>" ; } } private static String [ ] filter ( String [ ] disabled ) { return disabled ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . contributions ; import java . util . List ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . eclipse . codeassist . proposals . IGroovyProposal ; import org . codehaus . groovy . eclipse . dsl . lookup . ResolverCache ; import org . eclipse . jdt . groovy . search . AbstractSimplifiedTypeLookup . TypeAndDeclaration ; public interface IContributionElement { String GROOVY_DSL_PROVIDER = "<STR_LIT>" ; String NO_DOC = "<STR_LIT>" ; IGroovyProposal toProposal ( ClassNode declaringType , ResolverCache resolver ) ; List < IGroovyProposal > extraProposals ( ClassNode declaringType , ResolverCache resolver , Expression enclosingExpression ) ; TypeAndDeclaration lookupType ( String name , ClassNode declaringType , ResolverCache resolver ) ; String contributionName ( ) ; String description ( ) ; String getDeclaringTypeName ( ) ; } </s>
<s> package org . codehaus . groovy . eclipse . dsl . contributions ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Map . Entry ; import org . codehaus . groovy . ast . ClassHelper ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Parameter ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . ast . expr . MapEntryExpression ; import org . codehaus . groovy . ast . expr . MapExpression ; import org . codehaus . groovy . ast . expr . MethodCallExpression ; import org . codehaus . groovy . ast . expr . TupleExpression ; import org . codehaus . groovy . ast . stmt . BlockStatement ; import org . codehaus . groovy . eclipse . codeassist . ProposalUtils ; import org . codehaus . groovy . eclipse . codeassist . completions . NamedArgsMethodNode ; import org . codehaus . groovy . eclipse . codeassist . proposals . GroovyMethodProposal ; import org . codehaus . groovy . eclipse . codeassist . proposals . GroovyNamedArgumentProposal ; import org . codehaus . groovy . eclipse . codeassist . proposals . IGroovyProposal ; import org . codehaus . groovy . eclipse . codeassist . proposals . ProposalFormattingOptions ; import org . codehaus . groovy . eclipse . dsl . lookup . ResolverCache ; import org . eclipse . jdt . groovy . search . AbstractSimplifiedTypeLookup . TypeAndDeclaration ; import org . eclipse . jdt . groovy . search . VariableScope ; import org . objectweb . asm . Opcodes ; public class MethodContributionElement implements IContributionElement { private static final BlockStatement EMPTY_BLOCK = new BlockStatement ( ) ; private static final ClassNode [ ] NO_EXCEPTIONS = new ClassNode [ <NUM_LIT:0> ] ; private static final Parameter [ ] NO_PARAMETERS = new Parameter [ <NUM_LIT:0> ] ; private static final ParameterContribution [ ] NO_PARAMETER_CONTRIBUTION = new ParameterContribution [ <NUM_LIT:0> ] ; private static final ClassNode UNKNOWN_TYPE = ClassHelper . DYNAMIC_TYPE ; private final String methodName ; private final ParameterContribution [ ] params ; private final ParameterContribution [ ] namedParams ; private final ParameterContribution [ ] optionalParams ; private final String returnType ; private final String declaringType ; private final boolean isStatic ; private final boolean useNamedArgs ; private final String provider ; private final String doc ; private ClassNode cachedDeclaringType ; private ClassNode cachedReturnType ; private Parameter [ ] cachedRegularParameters ; private Parameter [ ] cachedNamedParameters ; private Parameter [ ] cachedOptionalParameters ; private ProposalFormattingOptions options = ProposalFormattingOptions . newFromOptions ( ) ; private final int relevanceMultiplier ; private final boolean isDeprecated ; private final boolean noParens ; public MethodContributionElement ( String methodName , ParameterContribution [ ] params , String returnType , String declaringType , boolean isStatic , String provider , String doc , boolean useNamedArgs , boolean isDeprecated , int relevanceMultiplier ) { this ( methodName , params , NO_PARAMETER_CONTRIBUTION , NO_PARAMETER_CONTRIBUTION , returnType , declaringType , isStatic , provider , doc , useNamedArgs , false , isDeprecated , relevanceMultiplier ) ; } public MethodContributionElement ( String methodName , ParameterContribution [ ] params , ParameterContribution [ ] namedParams , ParameterContribution [ ] optionalParams , String returnType , String declaringType , boolean isStatic , String provider , String doc , boolean useNamedArgs , boolean noParens , boolean isDeprecated , int relevanceMultiplier ) { this . methodName = methodName ; this . params = params ; this . namedParams = namedParams ; this . optionalParams = optionalParams ; this . returnType = returnType ; this . isStatic = isStatic ; this . declaringType = declaringType ; this . useNamedArgs = useNamedArgs ; this . noParens = noParens ; this . isDeprecated = isDeprecated ; this . relevanceMultiplier = relevanceMultiplier ; this . provider = provider == null ? GROOVY_DSL_PROVIDER : provider ; this . doc = doc == null ? NO_DOC + this . provider : doc ; } public TypeAndDeclaration lookupType ( String name , ClassNode declaringType , ResolverCache resolver ) { if ( name . equals ( methodName ) ) return new TypeAndDeclaration ( ensureReturnType ( resolver ) , toMethod ( declaringType , resolver ) , ensureDeclaringType ( declaringType , resolver ) , doc ) ; else return null ; } public IGroovyProposal toProposal ( ClassNode declaringType , ResolverCache resolver ) { GroovyMethodProposal groovyMethodProposal = new GroovyMethodProposal ( toMethod ( declaringType . redirect ( ) , resolver ) , provider , options ) ; groovyMethodProposal . setUseNamedArguments ( useNamedArgs ) ; groovyMethodProposal . setNoParens ( noParens ) ; groovyMethodProposal . setRelevanceMultiplier ( relevanceMultiplier ) ; return groovyMethodProposal ; } public List < IGroovyProposal > extraProposals ( ClassNode declaringType , ResolverCache resolver , Expression expression ) { Map < String , ClassNode > availableParams = findAvailableParameters ( resolver ) ; if ( availableParams . isEmpty ( ) ) { return ProposalUtils . NO_PROPOSALS ; } removeUsedParameters ( expression , availableParams ) ; List < IGroovyProposal > extraProposals = new ArrayList < IGroovyProposal > ( availableParams . size ( ) ) ; for ( Entry < String , ClassNode > available : availableParams . entrySet ( ) ) { extraProposals . add ( new GroovyNamedArgumentProposal ( available . getKey ( ) , available . getValue ( ) , toMethod ( declaringType . redirect ( ) , resolver ) , provider ) ) ; } return extraProposals ; } private void removeUsedParameters ( Expression expression , Map < String , ClassNode > availableParams ) { if ( expression instanceof MethodCallExpression ) { MethodCallExpression call = ( MethodCallExpression ) expression ; Expression arguments = call . getArguments ( ) ; if ( arguments instanceof TupleExpression ) { for ( Expression maybeArg : ( ( TupleExpression ) arguments ) . getExpressions ( ) ) { if ( maybeArg instanceof MapExpression ) { arguments = maybeArg ; break ; } } } if ( arguments instanceof MapExpression ) { MapExpression enclosingCallArgs = ( MapExpression ) arguments ; for ( MapEntryExpression entry : enclosingCallArgs . getMapEntryExpressions ( ) ) { String paramName = entry . getKeyExpression ( ) . getText ( ) ; availableParams . remove ( paramName ) ; } } } } private Map < String , ClassNode > findAvailableParameters ( ResolverCache resolver ) { Map < String , ClassNode > available = new HashMap < String , ClassNode > ( params . length ) ; if ( useNamedArgs ) { for ( ParameterContribution param : params ) { available . put ( param . name , param . toParameter ( resolver ) . getType ( ) ) ; } } for ( ParameterContribution param : namedParams ) { available . put ( param . name , param . toParameter ( resolver ) . getType ( ) ) ; } for ( ParameterContribution param : optionalParams ) { available . put ( param . name , param . toParameter ( resolver ) . getType ( ) ) ; } return available ; } private MethodNode toMethod ( ClassNode declaringType , ResolverCache resolver ) { if ( cachedRegularParameters == null ) { cachedRegularParameters = initParams ( params , resolver ) ; cachedOptionalParameters = initParams ( optionalParams , resolver ) ; cachedNamedParameters = initParams ( namedParams , resolver ) ; if ( cachedReturnType == null ) { if ( resolver != null ) { cachedReturnType = resolver . resolve ( returnType ) ; } else { cachedReturnType = VariableScope . OBJECT_CLASS_NODE ; } } } MethodNode meth = new NamedArgsMethodNode ( methodName , opcode ( ) , cachedReturnType , cachedRegularParameters , cachedNamedParameters , cachedOptionalParameters , NO_EXCEPTIONS , EMPTY_BLOCK ) ; meth . setDeclaringClass ( ensureDeclaringType ( declaringType , resolver ) ) ; return meth ; } private Parameter [ ] initParams ( ParameterContribution [ ] pcs , ResolverCache resolver ) { Parameter [ ] ps ; if ( pcs == null ) { ps = NO_PARAMETERS ; } else { ps = new Parameter [ pcs . length ] ; for ( int i = <NUM_LIT:0> ; i < pcs . length ; i ++ ) { ps [ i ] = pcs [ i ] . toParameter ( resolver ) ; } } return ps ; } protected ClassNode ensureReturnType ( ResolverCache resolver ) { if ( cachedReturnType == null ) { cachedReturnType = resolver . resolve ( returnType ) ; } return cachedReturnType == null ? UNKNOWN_TYPE : cachedReturnType ; } protected ClassNode ensureDeclaringType ( ClassNode lexicalDeclaringType , ResolverCache resolver ) { if ( declaringType != null && cachedDeclaringType == null ) { cachedDeclaringType = resolver . resolve ( declaringType ) ; } return cachedDeclaringType == null ? lexicalDeclaringType : cachedDeclaringType ; } protected int opcode ( ) { int modifiers = isStatic ? Opcodes . ACC_STATIC : Opcodes . ACC_PUBLIC ; modifiers |= isDeprecated ? Opcodes . ACC_DEPRECATED : <NUM_LIT:0> ; return modifiers ; } public String contributionName ( ) { return methodName ; } public String description ( ) { return "<STR_LIT>" + declaringType + "<STR_LIT:.>" + methodName + "<STR_LIT>" ; } public String getDeclaringTypeName ( ) { return declaringType ; } @ Override public String toString ( ) { return "<STR_LIT>" + ( isStatic ? "<STR_LIT>" : "<STR_LIT>" ) + ( isDeprecated ? "<STR_LIT>" : "<STR_LIT>" ) + ( useNamedArgs ? "<STR_LIT>" : "<STR_LIT>" ) + returnType + "<STR_LIT:U+0020>" + declaringType + "<STR_LIT:.>" + methodName + "<STR_LIT:(>" + Arrays . toString ( params ) + "<STR_LIT>" + provider + "<STR_LIT:)>" ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . contributions ; import groovy . lang . GroovyObjectSupport ; import java . util . ArrayList ; import java . util . List ; import org . codehaus . groovy . eclipse . dsl . pointcuts . BindingSet ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; public class ContributionGroup extends GroovyObjectSupport implements IContributionGroup { protected final static String DEFAULT_PROVIDER = "<STR_LIT>" ; protected final static int DEFAULT_RELEVANCE_MULTIPLIER = <NUM_LIT:11> ; protected List < IContributionElement > contributions = new ArrayList < IContributionElement > ( ) ; public void addMethodContribution ( String name , ParameterContribution [ ] params , String returnType , String declaringType , boolean isStatic , boolean useNamedArgs ) { contributions . add ( new MethodContributionElement ( name , params , returnType , declaringType , isStatic , DEFAULT_PROVIDER , null , useNamedArgs , false , DEFAULT_RELEVANCE_MULTIPLIER ) ) ; } public void addPropertyContribution ( String name , String type , String declaringType , boolean isStatic ) { contributions . add ( new PropertyContributionElement ( name , type , declaringType , isStatic , DEFAULT_PROVIDER , null , false , DEFAULT_RELEVANCE_MULTIPLIER ) ) ; } public List < IContributionElement > getContributions ( GroovyDSLDContext pattern , BindingSet matches ) { List < IContributionElement > currentContributions = new ArrayList < IContributionElement > ( ) ; for ( IContributionElement element : contributions ) { if ( pattern . matchesType ( element . getDeclaringTypeName ( ) ) ) { currentContributions . add ( element ) ; } } return currentContributions ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . contributions ; import groovy . lang . Closure ; import java . util . ArrayList ; import java . util . Collection ; import java . util . List ; import java . util . Map ; import java . util . Map . Entry ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . AnnotationNode ; import org . codehaus . groovy . ast . ClassHelper ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . ConstructorNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . GenericsType ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Parameter ; import org . codehaus . groovy . ast . Variable ; import org . codehaus . groovy . ast . expr . ClassExpression ; import org . codehaus . groovy . ast . expr . ConstantExpression ; import org . codehaus . groovy . eclipse . GroovyLogManager ; import org . codehaus . groovy . eclipse . TraceCategory ; import org . codehaus . groovy . eclipse . dsl . GroovyDSLCoreActivator ; import org . codehaus . groovy . eclipse . dsl . lookup . ResolverCache ; import org . codehaus . groovy . eclipse . dsl . pointcuts . BindingSet ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . eclipse . jdt . groovy . search . GenericsMapper ; import org . eclipse . jdt . groovy . search . VariableScope ; public class DSLContributionGroup extends ContributionGroup { private static final ParameterContribution [ ] NO_PARAMS = new ParameterContribution [ <NUM_LIT:0> ] ; private static final String NO_TYPE = "<STR_LIT>" ; private static final String NO_NAME = "<STR_LIT>" ; @ SuppressWarnings ( "<STR_LIT:rawtypes>" ) private final Closure contributionClosure ; private VariableScope scope ; private String provider = null ; private ResolverCache resolver ; private Map < String , Collection < Object > > bindings ; private ClassNode currentType ; private Map < String , Object > wormhole ; private boolean staticScope ; private boolean isPrimaryExpression ; public DSLContributionGroup ( @ SuppressWarnings ( "<STR_LIT:rawtypes>" ) Closure contributionClosure ) { this . contributionClosure = contributionClosure ; if ( contributionClosure != null ) { contributionClosure . setDelegate ( this ) ; contributionClosure . setResolveStrategy ( Closure . DELEGATE_FIRST ) ; } } public List < IContributionElement > getContributions ( GroovyDSLDContext pattern , BindingSet matches ) { synchronized ( this ) { List < IContributionElement > result ; try { this . contributions = new ArrayList < IContributionElement > ( ) ; this . scope = pattern . getCurrentScope ( ) ; this . resolver = pattern . getResolverCache ( ) ; this . bindings = matches . getBindings ( ) ; this . currentType = pattern . getCurrentType ( ) ; this . wormhole = scope . getWormhole ( ) ; this . staticScope = pattern . isStatic ( ) ; this . isPrimaryExpression = pattern . isPrimaryNode ( ) ; contributionClosure . call ( ) ; } catch ( Exception e ) { GroovyLogManager . manager . logException ( TraceCategory . DSL , e ) ; } finally { result = contributions ; pattern . setTargetType ( currentType ) ; this . contributions = null ; this . scope = null ; this . resolver = null ; this . bindings = null ; this . currentType = null ; this . wormhole = null ; } return result ; } } @ Override public Object getProperty ( String property ) { if ( "<STR_LIT>" . equals ( property ) ) { return wormhole ; } else if ( "<STR_LIT>" . equals ( property ) ) { return scope . getCurrentNode ( ) ; } else if ( "<STR_LIT>" . equals ( property ) ) { return scope . getEnclosingNode ( ) ; } else if ( "<STR_LIT>" . equals ( property ) ) { return currentType ; } else if ( "<STR_LIT>" . equals ( property ) ) { return resolver ; } return bindings . get ( property ) ; } void setDelegateType ( Object arg ) { ClassNode delegate = asClassNode ( arg ) ; if ( delegate != null ) { scope . addVariable ( "<STR_LIT>" , delegate , VariableScope . CLOSURE_CLASS ) ; scope . addVariable ( "<STR_LIT>" , delegate , VariableScope . CLOSURE_CLASS ) ; contributions . add ( new EmptyContributionElement ( currentType ) ) ; if ( isPrimaryExpression ) { currentType = delegate ; } } } private ClassNode asClassNode ( Object value ) { if ( value == null ) { return null ; } else if ( value instanceof String ) { return resolver . resolve ( ( String ) value ) ; } else if ( value instanceof ClassNode ) { return ( ClassNode ) value ; } else if ( value instanceof Class ) { return resolver . resolve ( ( ( Class < ? > ) value ) . getName ( ) ) ; } else { return resolver . resolve ( value . toString ( ) ) ; } } void method ( Map < String , Object > args ) { String name = asString ( args . get ( "<STR_LIT:name>" ) ) ; Object value = args . get ( "<STR_LIT:type>" ) ; String returnType = value == null ? "<STR_LIT>" : asString ( value ) ; value = args . get ( "<STR_LIT>" ) ; String declaringType = value == null ? getTypeName ( currentType ) : asString ( value ) ; value = args . get ( "<STR_LIT>" ) ; String provider = value == null ? this . provider : asString ( value ) ; value = args . get ( "<STR_LIT>" ) ; String doc = value == null ? null : asString ( value ) ; boolean useNamedArgs = asBoolean ( args . get ( "<STR_LIT>" ) ) ; boolean noParens = asBoolean ( args . get ( "<STR_LIT>" ) ) ; ParameterContribution [ ] params = extractParams ( args , "<STR_LIT>" ) ; ParameterContribution [ ] namedParams = extractParams ( args , "<STR_LIT>" ) ; ParameterContribution [ ] optionalParams = extractParams ( args , "<STR_LIT>" ) ; boolean isStatic = isStatic ( args ) ; boolean isDeprecated = isDeprecated ( args ) ; if ( ! staticScope || ( staticScope && isStatic ) ) { contributions . add ( new MethodContributionElement ( name == null ? NO_NAME : name , params , namedParams , optionalParams , returnType == null ? NO_TYPE : returnType , declaringType , isStatic , provider == null ? this . provider : provider , doc , useNamedArgs , noParens , isDeprecated , DEFAULT_RELEVANCE_MULTIPLIER ) ) ; } } private ParameterContribution [ ] extractParams ( Map < String , Object > args , String paramKind ) { Object value ; Map < Object , Object > paramsMap = ( Map < Object , Object > ) args . get ( paramKind ) ; ParameterContribution [ ] params ; if ( paramsMap != null ) { params = new ParameterContribution [ paramsMap . size ( ) ] ; int i = <NUM_LIT:0> ; for ( Entry < Object , Object > entry : paramsMap . entrySet ( ) ) { value = entry . getValue ( ) ; String type = value == null ? "<STR_LIT>" : asString ( value ) ; params [ i ++ ] = new ParameterContribution ( asString ( entry . getKey ( ) ) , type ) ; } } else { params = NO_PARAMS ; } return params ; } private boolean asBoolean ( Object object ) { if ( object == null ) { return false ; } if ( object instanceof Boolean ) { return ( Boolean ) object ; } String str = object . toString ( ) ; return str . equalsIgnoreCase ( "<STR_LIT:true>" ) || str . equalsIgnoreCase ( "<STR_LIT:yes>" ) ; } void property ( Map < String , Object > args ) { String name = asString ( args . get ( "<STR_LIT:name>" ) ) ; Object value = args . get ( "<STR_LIT:type>" ) ; String type = value == null ? NO_TYPE : asString ( value ) ; value = args . get ( "<STR_LIT>" ) ; String declaringType = value == null ? getTypeName ( currentType ) : asString ( value ) ; value = args . get ( "<STR_LIT>" ) ; String provider = value == null ? this . provider : asString ( value ) ; String doc = asString ( args . get ( "<STR_LIT>" ) ) ; boolean isStatic = isStatic ( args ) ; boolean isDeprecated = isDeprecated ( args ) ; if ( ! scope . isStatic ( ) || ( scope . isStatic ( ) && isStatic ) ) { contributions . add ( new PropertyContributionElement ( name == null ? NO_NAME : name , type , declaringType , isStatic , provider , doc , isDeprecated , DEFAULT_RELEVANCE_MULTIPLIER ) ) ; } } void template ( Map < String , String > args ) { } void delegatesTo ( Map < String , Object > args ) { String name = asString ( args . get ( "<STR_LIT:type>" ) ) ; boolean isStatic = isStatic ( args ) ; boolean isDeprecated = isDeprecated ( args ) ; boolean asCategory = getBoolean ( "<STR_LIT>" , args ) ; boolean useNamed = getBoolean ( "<STR_LIT>" , args ) ; boolean noParens = getBoolean ( "<STR_LIT>" , args ) ; List < String > except = ( List < String > ) args . get ( "<STR_LIT>" ) ; ClassNode type = this . resolver . resolve ( name ) ; internalDelegatesTo ( type , useNamed , isStatic , asCategory , isDeprecated , except , noParens ) ; } void delegatesTo ( String className ) { delegatesTo ( this . resolver . resolve ( className ) ) ; } void delegatesTo ( Class < ? > clazz ) { ClassNode resolved = this . resolver . resolve ( clazz . getCanonicalName ( ) ) ; if ( resolved == VariableScope . OBJECT_CLASS_NODE && ! clazz . getName ( ) . equals ( Object . class . getName ( ) ) ) { try { resolved = ClassHelper . make ( clazz ) ; } catch ( Exception e ) { GroovyDSLCoreActivator . logException ( e ) ; } } delegatesTo ( resolved ) ; } void delegatesTo ( AnnotatedNode expr ) { internalDelegatesTo ( expr , false , false , false , false , null , false ) ; } void delegatesToUseNamedArgs ( String className ) { delegatesToUseNamedArgs ( this . resolver . resolve ( className ) ) ; } void delegatesToUseNamedArgs ( Class < ? > clazz ) { delegatesToUseNamedArgs ( this . resolver . resolve ( clazz . getCanonicalName ( ) ) ) ; } void delegatesToUseNamedArgs ( AnnotatedNode expr ) { internalDelegatesTo ( expr , true , false , false , false , null , false ) ; } void delegatesToCategory ( String className ) { delegatesToCategory ( this . resolver . resolve ( className ) ) ; } void delegatesToCategory ( Class < ? > clazz ) { delegatesToCategory ( this . resolver . resolve ( clazz . getCanonicalName ( ) ) ) ; } void delegatesToCategory ( AnnotatedNode expr ) { internalDelegatesTo ( expr , false , false , true , false , null , false ) ; } static String getTypeName ( ClassNode clazz ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( clazz . getName ( ) ) ; if ( clazz . getGenericsTypes ( ) != null && clazz . getGenericsTypes ( ) . length > <NUM_LIT:0> ) { sb . append ( '<CHAR_LIT>' ) ; for ( GenericsType gt : clazz . getGenericsTypes ( ) ) { sb . append ( getTypeName ( gt . getType ( ) ) ) ; sb . append ( '<CHAR_LIT:U+002C>' ) ; } sb . replace ( sb . length ( ) - <NUM_LIT:1> , sb . length ( ) , "<STR_LIT:>>" ) ; } return sb . toString ( ) ; } private void internalDelegatesTo ( AnnotatedNode expr , boolean useNamedArgs , boolean isStatic , boolean asCategory , boolean isDeprecated , List < String > exceptions , boolean noParens ) { if ( staticScope && ! isStatic && ! currentType . getName ( ) . equals ( VariableScope . CLASS_CLASS_NODE ) ) { return ; } ClassNode type ; if ( expr instanceof ClassNode ) { type = ( ClassNode ) expr ; } else if ( expr instanceof FieldNode ) { type = ( ( FieldNode ) expr ) . getType ( ) ; } else if ( expr instanceof MethodNode ) { type = ( ( MethodNode ) expr ) . getReturnType ( ) ; } else if ( expr instanceof ClassExpression ) { type = ( ( ClassExpression ) expr ) . getType ( ) ; } else { if ( GroovyLogManager . manager . hasLoggers ( ) ) { GroovyLogManager . manager . log ( TraceCategory . DSL , "<STR_LIT>" + expr ) ; } return ; } if ( ! type . getName ( ) . equals ( Object . class . getName ( ) ) ) { GenericsMapper mapper = GenericsMapper . gatherGenerics ( type , type . redirect ( ) ) ; List < IContributionElement > accessorContribs = new ArrayList < IContributionElement > ( <NUM_LIT:1> ) ; for ( MethodNode method : type . getMethods ( ) ) { if ( ( exceptions == null || ! exceptions . contains ( method . getName ( ) ) ) && ! ( method instanceof ConstructorNode ) && ! method . getName ( ) . contains ( "<STR_LIT:$>" ) ) { ClassNode resolvedReturnType = VariableScope . resolveTypeParameterization ( mapper , VariableScope . clone ( method . getReturnType ( ) ) ) ; if ( asCategory ) { delegateToCategoryMethod ( useNamedArgs , isStatic , type , method , resolvedReturnType , isDeprecated , accessorContribs , noParens ) ; } else { delegateToNonCategoryMethod ( useNamedArgs , isStatic , type , method , resolvedReturnType , isDeprecated , accessorContribs , noParens ) ; } } } contributions . addAll ( accessorContribs ) ; } } private void delegateToNonCategoryMethod ( boolean useNamedArgs , boolean isStatic , ClassNode type , MethodNode method , ClassNode resolvedReturnType , boolean isDeprecated , List < IContributionElement > accessorContribs , boolean noParens ) { String name = method . getName ( ) ; contributions . add ( new MethodContributionElement ( name , toParameterContribution ( method . getParameters ( ) ) , NO_PARAMS , NO_PARAMS , getTypeName ( resolvedReturnType ) , getTypeName ( type ) , ( method . isStatic ( ) || isStatic ) , provider , null , useNamedArgs , noParens , isDeprecated , DEFAULT_RELEVANCE_MULTIPLIER ) ) ; String prefix ; if ( ( prefix = isAccessor ( method , name , false ) ) != null ) { accessorContribs . add ( new PropertyContributionElement ( Character . toLowerCase ( name . charAt ( prefix . length ( ) ) ) + name . substring ( prefix . length ( ) + <NUM_LIT:1> ) , getTypeName ( resolvedReturnType ) , getTypeName ( method . getDeclaringClass ( ) ) , ( method . isStatic ( ) || isStatic ) , provider , null , isDeprecated , DEFAULT_RELEVANCE_MULTIPLIER ) ) ; } } private void delegateToCategoryMethod ( boolean useNamedArgs , boolean isStatic , ClassNode type , MethodNode method , ClassNode resolvedReturnType , boolean isDeprecated , List < IContributionElement > accessorContribs , boolean noParens ) { String name = method . getName ( ) ; if ( method . getParameters ( ) != null && method . getParameters ( ) . length > <NUM_LIT:0> ) { ClassNode firstType = method . getParameters ( ) [ <NUM_LIT:0> ] . getType ( ) ; if ( ( firstType . isInterface ( ) && currentType . implementsInterface ( firstType ) ) || currentType . isDerivedFrom ( firstType ) ) { contributions . add ( new MethodContributionElement ( name , toParameterContributionRemoveFirst ( method . getParameters ( ) ) , NO_PARAMS , NO_PARAMS , getTypeName ( resolvedReturnType ) , getTypeName ( type ) , isStatic , provider , null , useNamedArgs , noParens , isDeprecated , DEFAULT_RELEVANCE_MULTIPLIER ) ) ; String prefix ; if ( ( prefix = isAccessor ( method , name , true ) ) != null ) { accessorContribs . add ( new PropertyContributionElement ( Character . toLowerCase ( name . charAt ( prefix . length ( ) ) ) + name . substring ( prefix . length ( ) + <NUM_LIT:1> ) , getTypeName ( resolvedReturnType ) , getTypeName ( method . getDeclaringClass ( ) ) , ( method . isStatic ( ) || isStatic ) , provider , null , isDeprecated , DEFAULT_RELEVANCE_MULTIPLIER ) ) ; } } } } private String isAccessor ( MethodNode method , String name , boolean isCategory ) { int paramCount = isCategory ? <NUM_LIT:1> : <NUM_LIT:0> ; if ( method . getParameters ( ) == null || method . getParameters ( ) . length == paramCount ) { if ( name . startsWith ( "<STR_LIT:get>" ) && name . length ( ) > <NUM_LIT:3> ) { return "<STR_LIT:get>" ; } else if ( name . startsWith ( "<STR_LIT>" ) && name . length ( ) > <NUM_LIT:2> ) { return "<STR_LIT>" ; } } return null ; } private ParameterContribution [ ] toParameterContribution ( Parameter [ ] params ) { if ( params != null ) { ParameterContribution [ ] contribs = new ParameterContribution [ params . length ] ; for ( int i = <NUM_LIT:0> ; i < contribs . length ; i ++ ) { contribs [ i ] = new ParameterContribution ( params [ i ] ) ; } return contribs ; } else { return new ParameterContribution [ <NUM_LIT:0> ] ; } } private ParameterContribution [ ] toParameterContributionRemoveFirst ( Parameter [ ] params ) { if ( params != null ) { ParameterContribution [ ] contribs = new ParameterContribution [ params . length - <NUM_LIT:1> ] ; for ( int i = <NUM_LIT:1> ; i < params . length ; i ++ ) { contribs [ i - <NUM_LIT:1> ] = new ParameterContribution ( params [ i ] ) ; } return contribs ; } else { return new ParameterContribution [ <NUM_LIT:0> ] ; } } void provider ( Object args ) { provider = args == null ? null : asString ( args ) ; } private boolean isStatic ( Map < ? , ? > args ) { return getBoolean ( "<STR_LIT>" , args ) ; } private boolean isDeprecated ( Map < ? , ? > args ) { return getBoolean ( "<STR_LIT>" , args ) ; } private boolean getBoolean ( String name , Map < ? , ? > args ) { Object maybeStatic = args . get ( name ) ; if ( maybeStatic == null ) { return false ; } else if ( maybeStatic instanceof Boolean ) { return ( Boolean ) maybeStatic ; } else { return Boolean . getBoolean ( maybeStatic . toString ( ) ) ; } } private String asString ( Object value ) { if ( value == null ) { return null ; } else if ( value instanceof String ) { return ( String ) value ; } else if ( value instanceof ClassNode ) { return getTypeName ( ( ( ClassNode ) value ) ) ; } else if ( value instanceof FieldNode ) { return getTypeName ( ( ( FieldNode ) value ) . getDeclaringClass ( ) ) + "<STR_LIT:.>" + ( ( FieldNode ) value ) . getName ( ) ; } else if ( value instanceof MethodNode ) { return getTypeName ( ( ( MethodNode ) value ) . getDeclaringClass ( ) ) + "<STR_LIT:.>" + ( ( MethodNode ) value ) . getName ( ) ; } else if ( value instanceof ConstantExpression ) { return ( ( ConstantExpression ) value ) . getText ( ) ; } else if ( value instanceof Variable ) { return ( ( Variable ) value ) . getName ( ) ; } else if ( value instanceof AnnotationNode ) { return ( ( AnnotationNode ) value ) . getClassNode ( ) . getName ( ) ; } else if ( value instanceof Class ) { return ( ( Class < ? > ) value ) . getName ( ) ; } else { return value . toString ( ) ; } } Object log ( Object msg ) { if ( GroovyLogManager . manager . hasLoggers ( ) ) { GroovyLogManager . manager . log ( TraceCategory . DSL , "<STR_LIT>" + msg ) ; } return msg ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . contributions ; import java . util . List ; import org . codehaus . groovy . ast . ClassHelper ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . PropertyNode ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . eclipse . codeassist . ProposalUtils ; import org . codehaus . groovy . eclipse . codeassist . proposals . GroovyPropertyProposal ; import org . codehaus . groovy . eclipse . codeassist . proposals . IGroovyProposal ; import org . codehaus . groovy . eclipse . dsl . lookup . ResolverCache ; import org . eclipse . jdt . groovy . search . AbstractSimplifiedTypeLookup . TypeAndDeclaration ; import org . objectweb . asm . Opcodes ; public class PropertyContributionElement implements IContributionElement { private static final ClassNode UNKNOWN_TYPE = ClassHelper . DYNAMIC_TYPE ; private final String propName ; private final String propType ; private final String declaringType ; private final boolean isStatic ; private ClassNode cachedDeclaringType ; private ClassNode cachedType ; private final String provider ; private final String doc ; private final int relevanceMultiplier ; private final boolean isDeprecated ; public PropertyContributionElement ( String propName , String propType , String declaringType , boolean isStatic , String provider , String doc , boolean isDeprecated , int relevanceMultiplier ) { super ( ) ; this . propName = propName ; this . propType = propType ; this . isStatic = isStatic ; this . declaringType = declaringType ; this . isDeprecated = isDeprecated ; this . relevanceMultiplier = relevanceMultiplier ; this . provider = provider == null ? GROOVY_DSL_PROVIDER : provider ; this . doc = doc == null ? NO_DOC + this . provider : doc ; } public IGroovyProposal toProposal ( ClassNode declaringType , ResolverCache resolver ) { GroovyPropertyProposal groovyPropertyProposal = new GroovyPropertyProposal ( toProperty ( declaringType , resolver ) , provider ) ; groovyPropertyProposal . setRelevanceMultiplier ( relevanceMultiplier ) ; return groovyPropertyProposal ; } public TypeAndDeclaration lookupType ( String name , ClassNode declaringType , ResolverCache resolver ) { return name . equals ( propName ) ? new TypeAndDeclaration ( ensureReturnType ( resolver ) , toProperty ( declaringType , resolver ) , ensureDeclaringType ( declaringType , resolver ) , doc ) : null ; } private PropertyNode toProperty ( ClassNode declaringType , ResolverCache resolver ) { ClassNode realDeclaringType = ensureDeclaringType ( declaringType , resolver ) ; PropertyNode prop = new PropertyNode ( new FieldNode ( propName , opcode ( ) , ensureReturnType ( resolver ) , realDeclaringType , null ) , opcode ( ) , null , null ) ; prop . setDeclaringClass ( realDeclaringType ) ; prop . getField ( ) . setDeclaringClass ( realDeclaringType ) ; return prop ; } protected int opcode ( ) { int modifiers = isStatic ? Opcodes . ACC_STATIC : Opcodes . ACC_PUBLIC ; modifiers |= isDeprecated ? Opcodes . ACC_DEPRECATED : <NUM_LIT:0> ; return modifiers ; } protected ClassNode ensureReturnType ( ResolverCache resolver ) { if ( cachedType == null ) { cachedType = resolver . resolve ( propType ) ; } return cachedType == null ? UNKNOWN_TYPE : cachedType ; } protected ClassNode ensureDeclaringType ( ClassNode lexicalDeclaringType , ResolverCache resolver ) { if ( declaringType != null && cachedDeclaringType == null ) { cachedDeclaringType = resolver . resolve ( declaringType ) ; } return cachedDeclaringType == null ? lexicalDeclaringType : cachedDeclaringType ; } public String contributionName ( ) { return propName ; } public String description ( ) { return "<STR_LIT>" + declaringType + "<STR_LIT:.>" + propName ; } public String getDeclaringTypeName ( ) { return declaringType ; } @ Override public String toString ( ) { return "<STR_LIT>" + ( isStatic ? "<STR_LIT>" : "<STR_LIT>" ) + ( isDeprecated ? "<STR_LIT>" : "<STR_LIT>" ) + propType + "<STR_LIT:U+0020>" + declaringType + "<STR_LIT:.>" + propName + "<STR_LIT:U+0020(>" + provider + "<STR_LIT:)>" ; } public List < IGroovyProposal > extraProposals ( ClassNode declaringType , ResolverCache resolver , Expression enclosingExpression ) { return ProposalUtils . NO_PROPOSALS ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . contributions ; import java . util . Collections ; import java . util . List ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . eclipse . codeassist . proposals . IGroovyProposal ; import org . codehaus . groovy . eclipse . dsl . lookup . ResolverCache ; import org . eclipse . jdt . groovy . search . AbstractSimplifiedTypeLookup . TypeAndDeclaration ; public class EmptyContributionElement implements IContributionElement { private ClassNode declaringType ; public EmptyContributionElement ( ClassNode declaringType ) { this . declaringType = declaringType ; } public IGroovyProposal toProposal ( ClassNode declaringType , ResolverCache resolver ) { return null ; } public List < IGroovyProposal > extraProposals ( ClassNode declaringType , ResolverCache resolver , Expression enclosingExpression ) { return Collections . emptyList ( ) ; } public TypeAndDeclaration lookupType ( String name , ClassNode declaringType , ResolverCache resolver ) { return null ; } public String contributionName ( ) { return "<STR_LIT>" ; } public String description ( ) { return "<STR_LIT>" ; } public String getDeclaringTypeName ( ) { return declaringType . getName ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . contributions ; import org . codehaus . groovy . ast . ClassHelper ; import org . codehaus . groovy . ast . Parameter ; import org . codehaus . groovy . eclipse . dsl . lookup . ResolverCache ; public class ParameterContribution { final String name ; final String type ; private Parameter cachedParameter ; public ParameterContribution ( String name , String type ) { this . name = name ; this . type = type ; } public ParameterContribution ( Parameter cachedParameter ) { this . cachedParameter = cachedParameter ; this . name = cachedParameter . getName ( ) ; this . type = DSLContributionGroup . getTypeName ( cachedParameter . getType ( ) ) ; } public ParameterContribution ( String name ) { this . name = name ; this . type = null ; } public Parameter toParameter ( ResolverCache resolver ) { if ( cachedParameter == null ) { if ( resolver != null ) { cachedParameter = new Parameter ( resolver . resolve ( type ) , name ) ; } else { cachedParameter = new Parameter ( ClassHelper . DYNAMIC_TYPE , name ) ; } } return cachedParameter ; } @ Override public String toString ( ) { return type + "<STR_LIT:U+0020>" + name ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . contributions ; import java . util . List ; import org . codehaus . groovy . eclipse . dsl . pointcuts . BindingSet ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; public interface IContributionGroup { List < IContributionElement > getContributions ( GroovyDSLDContext pattern , BindingSet matches ) ; } </s>
<s> package org . codehaus . groovy . eclipse . dsl . lookup ; import java . util . HashMap ; import java . util . Map ; import org . codehaus . groovy . ast . ClassHelper ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . GenericsType ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . jdt . groovy . internal . compiler . ast . JDTResolver ; import org . eclipse . jdt . groovy . search . VariableScope ; public class ResolverCache { private final Map < String , ClassNode > nameTypeCache ; private final JDTResolver resolver ; public ResolverCache ( JDTResolver resolver , ModuleNode thisModule ) { this . nameTypeCache = new HashMap < String , ClassNode > ( ) ; this . resolver = resolver ; } public ClassNode resolve ( String qName ) { if ( qName == null || qName . length ( ) == <NUM_LIT:0> ) { return ClassHelper . DYNAMIC_TYPE ; } qName = qName . trim ( ) ; if ( qName . equals ( "<STR_LIT>" ) || qName . equals ( "<STR_LIT>" ) ) { return VariableScope . VOID_CLASS_NODE ; } ClassNode clazz = nameTypeCache . get ( qName ) ; if ( clazz == null && resolver != null ) { int typeParamStart = qName . indexOf ( '<CHAR_LIT>' ) ; String erasureName ; if ( typeParamStart > <NUM_LIT:0> ) { erasureName = qName . substring ( <NUM_LIT:0> , typeParamStart ) ; } else { erasureName = qName ; } clazz = resolver . resolve ( erasureName ) ; if ( clazz == null ) { clazz = VariableScope . OBJECT_CLASS_NODE ; } nameTypeCache . put ( erasureName , clazz ) ; if ( typeParamStart > <NUM_LIT:0> ) { clazz = VariableScope . clone ( clazz ) ; String [ ] typeParameterNames = qName . substring ( typeParamStart + <NUM_LIT:1> , qName . length ( ) - <NUM_LIT:1> ) . split ( "<STR_LIT:U+002C>" ) ; ClassNode [ ] typeParameters = new ClassNode [ typeParameterNames . length ] ; for ( int i = <NUM_LIT:0> ; i < typeParameterNames . length ; i ++ ) { typeParameters [ i ] = resolve ( typeParameterNames [ i ] ) ; } clazz = VariableScope . clone ( clazz ) ; GenericsType [ ] genericsTypes = clazz . getGenericsTypes ( ) ; if ( genericsTypes != null ) { for ( int i = <NUM_LIT:0> ; i < genericsTypes . length && i < typeParameters . length ; i ++ ) { genericsTypes [ i ] . setType ( typeParameters [ i ] ) ; genericsTypes [ i ] . setName ( typeParameters [ i ] . getName ( ) ) ; } nameTypeCache . put ( qName , clazz ) ; } } } return clazz ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . lookup ; import java . util . List ; import java . util . Set ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . ast . stmt . BlockStatement ; import org . codehaus . groovy . eclipse . dsl . DSLDStore ; import org . codehaus . groovy . eclipse . dsl . DSLPreferences ; import org . codehaus . groovy . eclipse . dsl . GroovyDSLCoreActivator ; import org . codehaus . groovy . eclipse . dsl . contributions . IContributionElement ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . jdt . groovy . internal . compiler . ast . JDTResolver ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . groovy . search . AbstractSimplifiedTypeLookup ; import org . eclipse . jdt . groovy . search . ITypeLookup ; import org . eclipse . jdt . groovy . search . ITypeResolver ; import org . eclipse . jdt . groovy . search . TypeLookupResult . TypeConfidence ; import org . eclipse . jdt . groovy . search . VariableScope ; public class DSLDTypeLookup extends AbstractSimplifiedTypeLookup implements ITypeLookup , ITypeResolver { private DSLDStore store ; private GroovyDSLDContext pattern ; private Set < String > disabledScriptsAsSet ; private ModuleNode module ; private JDTResolver resolver ; public void setResolverInformation ( ModuleNode module , JDTResolver resolver ) { this . module = module ; this . resolver = resolver ; } public void initialize ( GroovyCompilationUnit unit , VariableScope topLevelScope ) { disabledScriptsAsSet = DSLPreferences . getDisabledScriptsAsSet ( ) ; try { pattern = new GroovyDSLDContext ( unit , module , resolver ) ; pattern . setCurrentScope ( topLevelScope ) ; } catch ( CoreException e ) { GroovyDSLCoreActivator . logException ( e ) ; } store = GroovyDSLCoreActivator . getDefault ( ) . getContextStoreManager ( ) . getDSLDStore ( unit . getJavaProject ( ) ) ; store = store . createSubStore ( pattern ) ; } @ Override protected TypeAndDeclaration lookupTypeAndDeclaration ( ClassNode declaringType , String name , VariableScope scope ) { pattern . setCurrentScope ( scope ) ; pattern . setTargetType ( declaringType ) ; pattern . setStatic ( isStatic ( ) ) ; List < IContributionElement > elts = store . findContributions ( pattern , disabledScriptsAsSet ) ; declaringType = pattern . getCurrentType ( ) ; for ( IContributionElement elt : elts ) { TypeAndDeclaration td = elt . lookupType ( name , declaringType , pattern . getResolverCache ( ) ) ; if ( td != null ) { return td ; } } return null ; } @ Override public void lookupInBlock ( BlockStatement node , VariableScope scope ) { pattern . setCurrentScope ( scope ) ; ClassNode delegateOrThis = scope . getDelegateOrThis ( ) ; if ( delegateOrThis != null ) { pattern . setTargetType ( delegateOrThis ) ; pattern . setStatic ( isStatic ( ) ) ; store . findContributions ( pattern , disabledScriptsAsSet ) ; } } @ Override protected TypeConfidence confidence ( ) { return TypeConfidence . INFERRED ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl ; import org . codehaus . groovy . eclipse . GroovyLogManager ; import org . codehaus . groovy . eclipse . TraceCategory ; import org . codehaus . groovy . eclipse . dsl . classpath . AutoAddContainerSupport ; import org . eclipse . core . resources . IResourceChangeEvent ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . IStatus ; import org . eclipse . core . runtime . Path ; import org . eclipse . core . runtime . Status ; import org . eclipse . jdt . core . ElementChangedEvent ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jface . resource . ImageDescriptor ; import org . eclipse . ui . plugin . AbstractUIPlugin ; import org . osgi . framework . BundleContext ; public class GroovyDSLCoreActivator extends AbstractUIPlugin { public static final String PLUGIN_ID = "<STR_LIT>" ; private static BundleContext context ; private static GroovyDSLCoreActivator plugin ; private final DSLDStoreManager contextStoreManager ; private DSLDResourceListener dsldResourceListener ; private DSLDElementListener dsldElementListener ; private AutoAddContainerSupport containerListener ; public final static String MARKER_ID = "<STR_LIT>" ; public static IPath CLASSPATH_CONTAINER_ID = new Path ( "<STR_LIT>" ) ; public GroovyDSLCoreActivator ( ) { plugin = this ; this . contextStoreManager = new DSLDStoreManager ( ) ; } public static GroovyDSLCoreActivator getDefault ( ) { return plugin ; } static BundleContext getContext ( ) { return context ; } @ Override public void start ( BundleContext bundleContext ) throws Exception { super . start ( bundleContext ) ; GroovyDSLCoreActivator . context = bundleContext ; dsldElementListener = new DSLDElementListener ( ) ; JavaCore . addElementChangedListener ( dsldElementListener , ElementChangedEvent . POST_CHANGE ) ; dsldResourceListener = new DSLDResourceListener ( ) ; ResourcesPlugin . getWorkspace ( ) . addResourceChangeListener ( dsldResourceListener ) ; containerListener = new AutoAddContainerSupport ( ) ; containerListener . addContainerToAll ( ) ; ResourcesPlugin . getWorkspace ( ) . addResourceChangeListener ( containerListener , IResourceChangeEvent . POST_CHANGE ) ; } @ Override public void stop ( BundleContext bundleContext ) throws Exception { super . stop ( bundleContext ) ; GroovyDSLCoreActivator . context = null ; ResourcesPlugin . getWorkspace ( ) . removeResourceChangeListener ( dsldResourceListener ) ; dsldResourceListener = null ; JavaCore . removeElementChangedListener ( dsldElementListener ) ; dsldElementListener = null ; ResourcesPlugin . getWorkspace ( ) . removeResourceChangeListener ( containerListener ) ; containerListener . dispose ( ) ; containerListener = null ; } public AutoAddContainerSupport getContainerListener ( ) { return containerListener ; } public DSLDStoreManager getContextStoreManager ( ) { return contextStoreManager ; } private static void log ( int severity , String message , Throwable throwable ) { final IStatus status = new Status ( severity , PLUGIN_ID , <NUM_LIT:0> , message , throwable ) ; try { getDefault ( ) . getLog ( ) . log ( status ) ; } catch ( NullPointerException e ) { } if ( GroovyLogManager . manager . hasLoggers ( ) ) { if ( throwable != null ) { GroovyLogManager . manager . log ( TraceCategory . DSL , "<STR_LIT>" + throwable . getLocalizedMessage ( ) ) ; } else if ( message != null ) { GroovyLogManager . manager . log ( TraceCategory . DSL , "<STR_LIT>" + message ) ; } } } public static void logException ( String message , Throwable throwable ) { log ( IStatus . ERROR , message , throwable ) ; } public static void logException ( Throwable throwable ) { log ( IStatus . ERROR , throwable . getLocalizedMessage ( ) , throwable ) ; } public static void logWarning ( String message ) { log ( IStatus . WARNING , message , null ) ; } public static ImageDescriptor getImageDescriptor ( String path ) { return imageDescriptorFromPlugin ( PLUGIN_ID , path ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl ; import java . util . ArrayList ; import java . util . Collection ; import java . util . HashMap ; import java . util . HashSet ; import java . util . LinkedHashMap ; import java . util . List ; import java . util . Map ; import java . util . Map . Entry ; import java . util . Set ; import org . codehaus . groovy . eclipse . GroovyLogManager ; import org . codehaus . groovy . eclipse . TraceCategory ; import org . codehaus . groovy . eclipse . dsl . contributions . IContributionElement ; import org . codehaus . groovy . eclipse . dsl . contributions . IContributionGroup ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IStorage ; import org . eclipse . jdt . internal . core . NonJavaResource ; public class DSLDStore { private final Map < IPointcut , List < IContributionGroup > > pointcutContributionMap ; private final Map < IStorage , Set < IPointcut > > keyContextMap ; public DSLDStore ( ) { pointcutContributionMap = new LinkedHashMap < IPointcut , List < IContributionGroup > > ( ) ; keyContextMap = new HashMap < IStorage , Set < IPointcut > > ( ) ; } public void addContributionGroup ( IPointcut pointcut , IContributionGroup contribution ) { List < IContributionGroup > contributions = pointcutContributionMap . get ( pointcut ) ; if ( contributions == null ) { contributions = new ArrayList < IContributionGroup > ( ) ; pointcutContributionMap . put ( pointcut , contributions ) ; } contributions . add ( contribution ) ; IStorage identifier = pointcut . getContainerIdentifier ( ) ; Set < IPointcut > pointcuts = keyContextMap . get ( identifier ) ; if ( pointcuts == null ) { pointcuts = new HashSet < IPointcut > ( ) ; keyContextMap . put ( identifier , pointcuts ) ; } pointcuts . add ( pointcut ) ; } public void purgeIdentifier ( IStorage identifier ) { if ( GroovyLogManager . manager . hasLoggers ( ) ) { GroovyLogManager . manager . log ( TraceCategory . DSL , "<STR_LIT>" + identifier ) ; } Set < IPointcut > pointcuts = keyContextMap . remove ( identifier ) ; if ( pointcuts != null ) { for ( IPointcut pointcut : pointcuts ) { pointcutContributionMap . remove ( pointcut ) ; } } } public void purgeAll ( ) { keyContextMap . clear ( ) ; pointcutContributionMap . clear ( ) ; } public DSLDStore createSubStore ( GroovyDSLDContext pattern ) { DSLDStore subStore = new DSLDStore ( ) ; for ( Entry < IPointcut , List < IContributionGroup > > entry : pointcutContributionMap . entrySet ( ) ) { if ( entry . getKey ( ) . fastMatch ( pattern ) ) { subStore . addAllContributions ( entry . getKey ( ) , entry . getValue ( ) ) ; } } return subStore ; } public void addAllContributions ( IPointcut pointcut , List < IContributionGroup > contributions ) { List < IContributionGroup > existing = pointcutContributionMap . get ( pointcut ) ; if ( existing == null ) { pointcutContributionMap . put ( pointcut , contributions ) ; } else { existing . addAll ( contributions ) ; } } public void addAllContexts ( List < IPointcut > pointcuts , IContributionGroup contribution ) { for ( IPointcut pointcut : pointcuts ) { addContributionGroup ( pointcut , contribution ) ; } } public List < IContributionElement > findContributions ( GroovyDSLDContext pattern , Set < String > disabledScripts ) { List < IContributionElement > elts = new ArrayList < IContributionElement > ( ) ; for ( Entry < IPointcut , List < IContributionGroup > > entry : pointcutContributionMap . entrySet ( ) ) { IPointcut pointcut = entry . getKey ( ) ; if ( ! disabledScripts . contains ( DSLDStore . toUniqueString ( pointcut . getContainerIdentifier ( ) ) ) ) { pattern . resetBinding ( ) ; Collection < ? > results = pointcut . matches ( pattern , pattern . getCurrentType ( ) ) ; if ( results != null ) { for ( IContributionGroup group : entry . getValue ( ) ) { elts . addAll ( group . getContributions ( pattern , pattern . getCurrentBinding ( ) ) ) ; } } } } return elts ; } public IStorage [ ] getAllContextKeys ( ) { return keyContextMap . keySet ( ) . toArray ( new IStorage [ <NUM_LIT:0> ] ) ; } public static String toUniqueString ( IStorage storage ) { if ( storage instanceof IFile ) { return storage . getFullPath ( ) . toPortableString ( ) ; } else if ( storage instanceof NonJavaResource ) { return ( ( NonJavaResource ) storage ) . getPackageFragmentRoot ( ) . getJavaProject ( ) . getElementName ( ) + "<STR_LIT>" + storage . getName ( ) ; } else { return storage . getName ( ) ; } } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts ; import java . util . Collection ; import java . util . Collections ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Map ; import java . util . Map . Entry ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . PropertyNode ; public class BindingSet { private final Map < String , Collection < Object > > namedBindings = new HashMap < String , Collection < Object > > ( ) ; public BindingSet ( ) { } public BindingSet addToBinding ( String name , Collection < ? > value ) { Collection < Object > binding = namedBindings . get ( name ) ; if ( binding == null ) { binding = new HashSet < Object > ( ) ; namedBindings . put ( name , binding ) ; } binding . addAll ( value ) ; return this ; } public Map < String , Collection < Object > > getBindings ( ) { return Collections . unmodifiableMap ( namedBindings ) ; } public Collection < Object > getBinding ( String name ) { return namedBindings . get ( name ) ; } public int size ( ) { return namedBindings . size ( ) ; } @ Override public String toString ( ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "<STR_LIT>" ) ; for ( Entry < String , Collection < Object > > entry : namedBindings . entrySet ( ) ) { sb . append ( "<STR_LIT:U+0020U+0020>" ) . append ( entry . getKey ( ) ) . append ( "<STR_LIT:U+0020:U+0020>" ) ; sb . append ( printCollection ( entry . getValue ( ) ) ) ; } sb . append ( '<CHAR_LIT:]>' ) ; return sb . toString ( ) ; } public static String printCollection ( Collection < ? extends Object > value ) { StringBuilder sb = new StringBuilder ( ) ; for ( Object object : value ) { sb . append ( "<STR_LIT>" ) ; sb . append ( printValue ( object ) ) ; sb . append ( "<STR_LIT>" ) ; } return sb . toString ( ) ; } public static String printValue ( Object value ) { if ( value instanceof ClassNode ) { return ( ( ClassNode ) value ) . getName ( ) ; } else if ( value instanceof FieldNode ) { return ( ( FieldNode ) value ) . getDeclaringClass ( ) . getName ( ) + "<STR_LIT:.>" + ( ( FieldNode ) value ) . getName ( ) ; } else if ( value instanceof MethodNode ) { return ( ( MethodNode ) value ) . getDeclaringClass ( ) . getName ( ) + "<STR_LIT:.>" + ( ( MethodNode ) value ) . getName ( ) ; } else if ( value instanceof PropertyNode ) { return ( ( PropertyNode ) value ) . getDeclaringClass ( ) . getName ( ) + "<STR_LIT:.>" + ( ( PropertyNode ) value ) . getName ( ) ; } else if ( value instanceof ASTNode ) { return ( ( ASTNode ) value ) . getText ( ) ; } else if ( value != null ) { value . toString ( ) ; } return null ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts ; import groovy . lang . Closure ; import java . util . Collection ; import org . codehaus . groovy . eclipse . dsl . DSLDStore ; import org . codehaus . groovy . eclipse . dsl . contributions . IContributionGroup ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IStorage ; public interface IPointcut { Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) ; IStorage getContainerIdentifier ( ) ; IPointcut normalize ( ) ; void addArgument ( String name , Object argument ) ; void addArgument ( Object argument ) ; void verify ( ) throws PointcutVerificationException ; Object getFirstArgument ( ) ; String getFirstArgumentName ( ) ; Object [ ] getArgumentValues ( ) ; String [ ] getArgumentNames ( ) ; void setProject ( IProject project ) ; void accept ( @ SuppressWarnings ( "<STR_LIT:rawtypes>" ) Closure contributionGroupClosure ) ; boolean fastMatch ( GroovyDSLDContext pattern ) ; String getPointcutName ( ) ; String getPointcutDebugName ( ) ; } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts ; public class PointcutVerificationException extends Exception { private static final long serialVersionUID = <NUM_LIT:1L> ; private final IPointcut pointcut ; public PointcutVerificationException ( String message , IPointcut pointcut ) { super ( message ) ; this . pointcut = pointcut ; } public IPointcut getPointcut ( ) { return pointcut ; } public String getPointcutMessage ( ) { return "<STR_LIT>" + pointcut . getPointcutDebugName ( ) + "<STR_LIT>" + pointcut . getContainerIdentifier ( ) + "<STR_LIT>" + getMessage ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts ; import java . util . Collection ; import java . util . LinkedHashSet ; import java . util . Set ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . eclipse . dsl . lookup . ResolverCache ; import org . codehaus . jdt . groovy . internal . compiler . ast . JDTResolver ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . groovy . search . VariableScope ; public class GroovyDSLDContext { public final String [ ] projectNatures ; public final String fullPathName ; public final String simpleFileName ; public final String packageRootPath ; public final String packageFolderPath ; private ResolverCache resolverCache ; private BindingSet currentBinding ; private VariableScope currentScope ; private ClassNode targetType ; public GroovyDSLDContext ( GroovyCompilationUnit unit , ModuleNode module , JDTResolver jdtResolver ) throws CoreException { this ( getProjectNatures ( unit ) , getFullPathToFile ( unit ) , getPathToPackage ( unit ) ) ; resolverCache = new ResolverCache ( jdtResolver , module ) ; } @ Deprecated public GroovyDSLDContext ( String [ ] projectNatures , String fullPathName , String packageRootPath ) { this . fullPathName = fullPathName ; this . packageRootPath = packageRootPath ; if ( fullPathName != null ) { int lastDot = fullPathName . lastIndexOf ( '<CHAR_LIT:/>' ) ; this . simpleFileName = fullPathName . substring ( lastDot + <NUM_LIT:1> ) ; } else { this . simpleFileName = null ; } String candidate ; if ( packageRootPath != null && packageRootPath . length ( ) < fullPathName . length ( ) ) { candidate = fullPathName . substring ( packageRootPath . length ( ) ) ; if ( simpleFileName != null ) { int indexOf = candidate . lastIndexOf ( "<STR_LIT:/>" + simpleFileName ) ; int start = candidate . startsWith ( "<STR_LIT:/>" ) ? <NUM_LIT:1> : <NUM_LIT:0> ; if ( indexOf > <NUM_LIT:0> && candidate . length ( ) > <NUM_LIT:0> ) { candidate = candidate . substring ( start , indexOf ) ; } } } else { candidate = "<STR_LIT>" ; } packageFolderPath = candidate ; this . projectNatures = projectNatures ; } private static String getPathToPackage ( GroovyCompilationUnit unit ) { return unit . getPackageFragmentRoot ( ) . getResource ( ) . getFullPath ( ) . removeFirstSegments ( <NUM_LIT:1> ) . toPortableString ( ) ; } private static String getFullPathToFile ( GroovyCompilationUnit unit ) { return unit . getResource ( ) . getFullPath ( ) . removeFirstSegments ( <NUM_LIT:1> ) . toPortableString ( ) ; } private static String [ ] getProjectNatures ( GroovyCompilationUnit unit ) throws CoreException { return unit . getJavaProject ( ) . getProject ( ) . getDescription ( ) . getNatureIds ( ) ; } private Set < ClassNode > cachedHierarchy ; private boolean isStatic ; private boolean isPrimaryNode ; public void setTargetType ( ClassNode targetType ) { cachedHierarchy = null ; this . targetType = targetType ; } public void setCurrentBinding ( BindingSet currentBinding ) { this . currentBinding = currentBinding ; } public void resetBinding ( ) { this . currentBinding = new BindingSet ( ) ; } public BindingSet getCurrentBinding ( ) { return currentBinding ; } public void addToBinding ( String bindingName , Collection < ? > toAdd ) { currentBinding . addToBinding ( bindingName , toAdd ) ; } public boolean matchesNature ( String natureId ) { if ( natureId == null ) { return false ; } for ( String nature : projectNatures ) { if ( natureId . equals ( nature ) ) { return true ; } } return false ; } public boolean matchesType ( String typeName ) { return matchesType ( typeName , targetType ) ; } public boolean matchesType ( String typeName , ClassNode toCheck ) { if ( typeName == null || toCheck == null ) { return true ; } if ( typeName . equals ( toCheck . getName ( ) ) ) { return true ; } if ( cachedHierarchy == null ) { cachedHierarchy = new LinkedHashSet < ClassNode > ( ) ; getAllSupers ( toCheck , cachedHierarchy ) ; } for ( ClassNode node : cachedHierarchy ) { if ( typeName . equals ( node . getName ( ) ) ) { return true ; } } return false ; } public VariableScope getCurrentScope ( ) { return currentScope ; } public void setCurrentScope ( VariableScope currentScope ) { this . currentScope = currentScope ; isPrimaryNode = currentScope . isPrimaryNode ( ) ; } public ClassNode getCurrentType ( ) { return targetType ; } @ SuppressWarnings ( "<STR_LIT:cast>" ) private void getAllSupers ( ClassNode type , Set < ClassNode > set ) { if ( type == null ) { return ; } set . add ( type ) ; getAllSupers ( type . getSuperClass ( ) , set ) ; for ( ClassNode inter : ( Iterable < ClassNode > ) type . getAllInterfaces ( ) ) { if ( ! inter . getName ( ) . equals ( type . getName ( ) ) ) { getAllSupers ( inter , set ) ; } } } @ Override public String toString ( ) { StringBuilder builder = new StringBuilder ( ) ; builder . append ( "<STR_LIT>" ) ; builder . append ( fullPathName ) ; builder . append ( "<STR_LIT>" ) ; builder . append ( targetType ) ; builder . append ( "<STR_LIT>" ) ; builder . append ( currentScope ) ; builder . append ( "<STR_LIT:]>" ) ; return builder . toString ( ) ; } public ResolverCache getResolverCache ( ) { return resolverCache ; } public boolean isPrimaryNode ( ) { return isPrimaryNode ; } public void setPrimaryNode ( boolean isPrimaryNode ) { this . isPrimaryNode = isPrimaryNode ; } public void setStatic ( boolean s ) { isStatic = s ; } public boolean isStatic ( ) { return isStatic ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts ; import java . util . HashMap ; import java . util . Map ; public final class StringObjectVector { static int INITIAL_SIZE = <NUM_LIT:10> ; public int size ; public int maxSize ; private String [ ] names ; private Object [ ] elements ; private Map < String , Object > cachedMap ; public StringObjectVector ( int initialSize ) { this . maxSize = initialSize > <NUM_LIT:0> ? initialSize : INITIAL_SIZE ; this . size = <NUM_LIT:0> ; this . elements = new Object [ this . maxSize ] ; this . names = new String [ this . maxSize ] ; } public void add ( String newName , Object newElement ) { if ( this . size == this . maxSize ) { System . arraycopy ( this . elements , <NUM_LIT:0> , ( this . elements = new Object [ this . maxSize *= <NUM_LIT:2> ] ) , <NUM_LIT:0> , this . size ) ; System . arraycopy ( this . names , <NUM_LIT:0> , ( this . names = new String [ this . maxSize ] ) , <NUM_LIT:0> , this . size ) ; } this . names [ this . size ] = newName ; this . elements [ this . size ++ ] = newElement ; cachedMap = null ; } public void setElement ( Object newElement , int index ) { this . elements [ index ] = newElement ; cachedMap = null ; } public boolean contains ( Object element ) { if ( element == null ) { for ( int i = this . size ; -- i >= <NUM_LIT:0> ; ) if ( this . elements [ i ] == null ) return true ; } else { for ( int i = this . size ; -- i >= <NUM_LIT:0> ; ) if ( element . equals ( this . elements [ i ] ) ) return true ; } return false ; } public boolean containsName ( String name ) { if ( name == null ) { for ( int i = this . size ; -- i >= <NUM_LIT:0> ; ) if ( this . names [ i ] == null ) return true ; } else { for ( int i = this . size ; -- i >= <NUM_LIT:0> ; ) if ( name . equals ( this . names [ i ] ) ) return true ; } return false ; } public Object elementAt ( int index ) { if ( index >= size ) { throw new ArrayIndexOutOfBoundsException ( index ) ; } return this . elements [ index ] ; } public Object find ( String name ) { if ( name == null ) { for ( int i = this . size ; -- i >= <NUM_LIT:0> ; ) { if ( this . names [ i ] == null ) { return this . elements [ i ] ; } } } else { for ( int i = this . size ; -- i >= <NUM_LIT:0> ; ) { if ( name . equals ( this . names [ i ] ) ) { return this . elements [ i ] ; } } } return null ; } public String toString ( ) { StringBuilder sb = new StringBuilder ( ) ; formattedString ( sb , <NUM_LIT:0> ) ; return sb . toString ( ) ; } public String nameAt ( int index ) { if ( index >= size ) { throw new ArrayIndexOutOfBoundsException ( index ) ; } return this . names [ index ] ; } public Object [ ] getElements ( ) { Object [ ] res = new Object [ size ] ; System . arraycopy ( this . elements , <NUM_LIT:0> , res , <NUM_LIT:0> , size ) ; return res ; } public String [ ] getNames ( ) { String [ ] res = new String [ size ] ; System . arraycopy ( this . names , <NUM_LIT:0> , res , <NUM_LIT:0> , size ) ; return res ; } public String nameOf ( Object arg ) { for ( int i = <NUM_LIT:0> ; i < size ; i ++ ) { if ( elements [ i ] == arg ) { return names [ i ] ; } } return null ; } Map < String , Object > asMap ( ) { if ( cachedMap == null ) { cachedMap = new HashMap < String , Object > ( ) ; for ( int i = <NUM_LIT:0> ; i < this . size ; i ++ ) { if ( names [ i ] != null ) { cachedMap . put ( names [ i ] , elements [ i ] ) ; } } } return cachedMap ; } void formattedString ( StringBuilder sb , int indent ) { String spaces = AbstractPointcut . spaces ( indent ) ; if ( this . size > <NUM_LIT:0> ) { sb . append ( spaces + "<STR_LIT:n>" ) ; for ( int i = <NUM_LIT:0> ; i < this . size ; i ++ ) { sb . append ( spaces ) ; if ( this . names [ i ] != null ) { sb . append ( this . names [ i ] ) . append ( "<STR_LIT:U+0020=U+0020>" ) ; } if ( this . elements [ i ] instanceof AbstractPointcut ) { ( ( AbstractPointcut ) this . elements [ i ] ) . formatedString ( sb , indent + <NUM_LIT:2> ) ; } else { sb . append ( this . elements [ i ] ) ; } } } else { } } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import org . codehaus . groovy . ast . expr . ConstantExpression ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . ast . expr . VariableExpression ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . eclipse . core . resources . IStorage ; public class CurrentIdentifierPointcut extends FilteringPointcut < Expression > { public CurrentIdentifierPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName , Expression . class ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { return super . matches ( pattern , pattern . getCurrentScope ( ) . getCurrentNode ( ) ) ; } @ Override protected Expression filterObject ( Expression result , GroovyDSLDContext context , String firstArgAsString ) { if ( result instanceof VariableExpression || result instanceof ConstantExpression ) { if ( firstArgAsString == null || result . getText ( ) . equals ( firstArgAsString ) ) { return result ; } } return null ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Collections ; import java . util . List ; import org . codehaus . groovy . ast . expr . MethodCallExpression ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; import org . eclipse . jdt . groovy . search . VariableScope . CallAndType ; public class EnclosingCallPointcut extends AbstractPointcut { public EnclosingCallPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { List < CallAndType > enclosing = pattern . getCurrentScope ( ) . getAllEnclosingMethodCallExpressions ( ) ; if ( enclosing == null || enclosing . isEmpty ( ) ) { return null ; } Object firstArgument = getFirstArgument ( ) ; if ( firstArgument == null || firstArgument instanceof String ) { MethodCallExpression matchingCall = matchesInCalls ( enclosing , ( String ) firstArgument , pattern ) ; if ( matchingCall != null ) { return Collections . singleton ( matchingCall ) ; } else { return null ; } } else { return matchOnPointcutArgument ( ( IPointcut ) firstArgument , pattern , asCallList ( enclosing ) ) ; } } private List < MethodCallExpression > asCallList ( List < CallAndType > enclosing ) { List < MethodCallExpression > types = new ArrayList < MethodCallExpression > ( enclosing . size ( ) ) ; for ( CallAndType callAndType : enclosing ) { types . add ( callAndType . call ) ; } return types ; } private MethodCallExpression matchesInCalls ( List < CallAndType > enclosing , String callName , GroovyDSLDContext pattern ) { for ( CallAndType callAndType : enclosing ) { if ( callName == null || callName . equals ( callAndType . call . getMethodAsString ( ) ) ) { return callAndType . call ; } } return null ; } @ Override public void verify ( ) throws PointcutVerificationException { String hasOneOrNoArgs = hasOneOrNoArgs ( ) ; if ( hasOneOrNoArgs != null ) { throw new PointcutVerificationException ( hasOneOrNoArgs , this ) ; } super . verify ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . Collections ; import java . util . HashMap ; import java . util . Map ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IStorage ; import org . eclipse . jdt . core . JavaCore ; public class ProjectNaturePointcut extends AbstractPointcut { public ProjectNaturePointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { for ( String nature : pattern . projectNatures ) { Object firstArgument = getFirstArgument ( ) ; if ( nature . equals ( firstArgument ) || nature . equals ( SHORTCUTS . get ( firstArgument ) ) ) { return Collections . singleton ( nature ) ; } } return null ; } @ Override public boolean fastMatch ( GroovyDSLDContext pattern ) { return matches ( pattern , null ) != null ; } @ Override public void verify ( ) throws PointcutVerificationException { String maybeStatus = allArgsAreStrings ( ) ; if ( maybeStatus != null ) { throw new PointcutVerificationException ( maybeStatus , this ) ; } maybeStatus = hasOneArg ( ) ; if ( maybeStatus != null ) { throw new PointcutVerificationException ( maybeStatus , this ) ; } super . verify ( ) ; } private static final Map < String , String > SHORTCUTS = new HashMap < String , String > ( ) ; static { SHORTCUTS . put ( "<STR_LIT>" , GroovyNature . GROOVY_NATURE ) ; SHORTCUTS . put ( "<STR_LIT>" , JavaCore . NATURE_ID ) ; SHORTCUTS . put ( "<STR_LIT>" , "<STR_LIT>" ) ; SHORTCUTS . put ( "<STR_LIT>" , "<STR_LIT>" ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Collections ; import java . util . List ; import org . codehaus . groovy . ast . expr . MethodCallExpression ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; import org . eclipse . jdt . groovy . search . VariableScope . CallAndType ; public class EnclosingCallNamePointcut extends AbstractPointcut { public EnclosingCallNamePointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { List < CallAndType > enclosing = pattern . getCurrentScope ( ) . getAllEnclosingMethodCallExpressions ( ) ; if ( enclosing == null ) { return null ; } Object firstArgument = getFirstArgument ( ) ; if ( firstArgument instanceof String ) { MethodCallExpression matchingCall = matchesInCalls ( enclosing , ( String ) firstArgument , pattern ) ; if ( matchingCall != null ) { return Collections . singleton ( matchingCall ) ; } else { return null ; } } else { return matchOnPointcutArgument ( ( IPointcut ) firstArgument , pattern , asCallList ( enclosing ) ) ; } } private List < MethodCallExpression > asCallList ( List < CallAndType > enclosing ) { List < MethodCallExpression > types = new ArrayList < MethodCallExpression > ( enclosing . size ( ) ) ; for ( CallAndType callAndType : enclosing ) { types . add ( callAndType . call ) ; } return types ; } private MethodCallExpression matchesInCalls ( List < CallAndType > enclosing , String callName , GroovyDSLDContext pattern ) { for ( CallAndType callAndType : enclosing ) { if ( callName . equals ( callAndType . call . getMethodAsString ( ) ) ) { return callAndType . call ; } } return null ; } @ Override public void verify ( ) throws PointcutVerificationException { String hasOneOrNoArgs = hasOneOrNoArgs ( ) ; if ( hasOneOrNoArgs != null ) { throw new PointcutVerificationException ( hasOneOrNoArgs , this ) ; } super . verify ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . HashMap ; import java . util . HashSet ; import java . util . LinkedHashSet ; import java . util . Map ; import java . util . Set ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . eclipse . core . resources . IStorage ; public class SubTypePointcut extends FilteringPointcut < ClassNode > { private Map < ClassNode , Set < ClassNode > > cachedHierarchies = new HashMap < ClassNode , Set < ClassNode > > ( ) ; public SubTypePointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName , ClassNode . class ) ; } @ Override protected Collection < ClassNode > explodeObject ( Object toMatch ) { if ( toMatch instanceof Collection < ? > ) { Set < ClassNode > classes = new LinkedHashSet < ClassNode > ( ) ; for ( Object elt : ( Collection < ? > ) toMatch ) { if ( elt instanceof ClassNode ) { classes . addAll ( getAllSupers ( ( ClassNode ) elt ) ) ; } } return classes ; } else if ( toMatch instanceof ClassNode ) { return getAllSupers ( ( ( ClassNode ) toMatch ) ) ; } return null ; } @ Override protected ClassNode filterObject ( ClassNode result , GroovyDSLDContext context , String firstArgAsString ) { if ( firstArgAsString == null || result . getName ( ) . equals ( firstArgAsString ) ) { return result ; } else { return null ; } } private Set < ClassNode > getAllSupers ( ClassNode type ) { Set < ClassNode > cached = cachedHierarchies . get ( type ) ; if ( cached == null ) { cached = new HashSet < ClassNode > ( ) ; internalGetAllSupers ( type , cached ) ; cachedHierarchies . put ( type , cached ) ; } return cached ; } private void internalGetAllSupers ( ClassNode type , Set < ClassNode > set ) { if ( type == null ) { return ; } set . add ( type ) ; internalGetAllSupers ( type . getSuperClass ( ) , set ) ; for ( ClassNode inter : type . getAllInterfaces ( ) ) { if ( ! inter . getName ( ) . equals ( type . getName ( ) ) ) { internalGetAllSupers ( inter , set ) ; } } } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . Collections ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . expr . MethodCallExpression ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . eclipse . core . resources . IStorage ; public class DeclaringTypePointcut extends FilteringPointcut < ClassNode > { public DeclaringTypePointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName , ClassNode . class ) ; } @ Override protected Collection < ClassNode > explodeObject ( Object toMatch ) { if ( toMatch instanceof AnnotatedNode ) { return Collections . singleton ( ( ( AnnotatedNode ) toMatch ) . getDeclaringClass ( ) ) ; } return null ; } @ Override protected ClassNode filterObject ( ClassNode result , GroovyDSLDContext context , String firstArgAsString ) { return result != null && result . getName ( ) . equals ( firstArgAsString ) ? result : null ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . Collections ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public class EnclosingClassPointcut extends AbstractPointcut { public EnclosingClassPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { ClassNode enclosing = pattern . getCurrentScope ( ) . getEnclosingTypeDeclaration ( ) ; if ( enclosing == null || enclosing . isScript ( ) || enclosing . isInterface ( ) || enclosing . isAnnotationDefinition ( ) || enclosing . isEnum ( ) ) { return null ; } Collection < ClassNode > enclosingCollection = Collections . singleton ( enclosing ) ; Object firstArgument = getFirstArgument ( ) ; if ( firstArgument instanceof String ) { if ( enclosing . getName ( ) . equals ( firstArgument ) ) { return enclosingCollection ; } else { return null ; } } else if ( firstArgument instanceof Class < ? > ) { if ( enclosing . getName ( ) . equals ( ( ( Class < ? > ) firstArgument ) . getName ( ) ) ) { return enclosingCollection ; } else { return null ; } } else if ( firstArgument == null ) { return enclosingCollection ; } else { return matchOnPointcutArgument ( ( IPointcut ) firstArgument , pattern , enclosingCollection ) ; } } @ Override public void verify ( ) throws PointcutVerificationException { String hasOneOrNoArgs = hasOneOrNoArgs ( ) ; if ( hasOneOrNoArgs != null ) { throw new PointcutVerificationException ( hasOneOrNoArgs , this ) ; } super . verify ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . Collections ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . codehaus . jdt . groovy . internal . compiler . ast . JDTClassNode ; import org . eclipse . core . resources . IStorage ; import org . eclipse . jdt . core . compiler . CharOperation ; public class SourceFolderOfTypePointcut extends AbstractPointcut { public SourceFolderOfTypePointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { String sourceFolder = extractFileName ( toType ( toMatch ) , pattern ) ; if ( sourceFolder != null && sourceFolder . startsWith ( ( String ) getFirstArgument ( ) ) ) { return Collections . singleton ( pattern . fullPathName ) ; } else { return null ; } } private ClassNode toType ( Object toMatch ) { if ( toMatch instanceof ClassNode ) { return ( ClassNode ) toMatch ; } else if ( toMatch instanceof AnnotatedNode ) { return ( ( AnnotatedNode ) toMatch ) . getDeclaringClass ( ) ; } else { return null ; } } private String extractFileName ( ClassNode type , GroovyDSLDContext pattern ) { if ( type == null ) { return null ; } ClassNode redirect = type . redirect ( ) ; if ( redirect instanceof JDTClassNode ) { JDTClassNode jdtClass = ( JDTClassNode ) redirect ; char [ ] fileName = jdtClass . getJdtBinding ( ) . getFileName ( ) ; if ( fileName != null ) { int slashIndex = CharOperation . indexOf ( '<CHAR_LIT:/>' , fileName ) ; if ( slashIndex >= <NUM_LIT:0> ) { slashIndex = CharOperation . indexOf ( '<CHAR_LIT:/>' , fileName , slashIndex + <NUM_LIT:1> ) ; } if ( slashIndex > <NUM_LIT:0> ) { return String . valueOf ( CharOperation . subarray ( fileName , slashIndex + <NUM_LIT:1> , fileName . length ) ) ; } } } else { ModuleNode module = pattern . getCurrentScope ( ) . getEnclosingTypeDeclaration ( ) . getModule ( ) ; if ( module != null && module . getClasses ( ) . contains ( redirect ) ) { return pattern . fullPathName ; } } return "<STR_LIT>" ; } @ Override public void verify ( ) throws PointcutVerificationException { String maybeStatus = allArgsAreStrings ( ) ; if ( maybeStatus != null ) { throw new PointcutVerificationException ( maybeStatus , this ) ; } maybeStatus = hasOneArg ( ) ; if ( maybeStatus != null ) { throw new PointcutVerificationException ( maybeStatus , this ) ; } super . verify ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public class BindPointcut extends AbstractPointcut { public BindPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { return matchOnPointcutArgumentReturnInner ( ( IPointcut ) getFirstArgument ( ) , pattern , ensureCollection ( toMatch ) ) ; } public IPointcut normalize ( ) { return super . normalize ( ) ; } @ Override public void verify ( ) throws PointcutVerificationException { super . verify ( ) ; Object arg = getFirstArgument ( ) ; if ( arg instanceof IPointcut ) { String name = getFirstArgumentName ( ) ; if ( name == null ) { throw new PointcutVerificationException ( "<STR_LIT>" , this ) ; } ( ( IPointcut ) arg ) . verify ( ) ; } else { throw new PointcutVerificationException ( "<STR_LIT>" , this ) ; } } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Collections ; import java . util . List ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . AnnotationNode ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . eclipse . core . resources . IStorage ; public class FindAnnotationPointcut extends FilteringPointcut < AnnotationNode > { public FindAnnotationPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName , AnnotationNode . class ) ; } @ Override protected Collection < AnnotationNode > explodeObject ( Object toMatch ) { if ( toMatch instanceof Collection < ? > ) { List < AnnotationNode > annotations = new ArrayList < AnnotationNode > ( ) ; for ( Object elt : ( Collection < ? > ) toMatch ) { Collection < AnnotationNode > explodedElt = explodeObject ( elt ) ; if ( explodedElt != null ) { annotations . addAll ( explodedElt ) ; } } return annotations ; } else if ( toMatch instanceof AnnotatedNode ) { return ( ( AnnotatedNode ) toMatch ) . getAnnotations ( ) ; } else if ( toMatch instanceof AnnotationNode ) { return Collections . singleton ( ( AnnotationNode ) toMatch ) ; } return null ; } protected AnnotationNode filterObject ( AnnotationNode result , GroovyDSLDContext context , String firstArgAsString ) { if ( result . getClassNode ( ) . getName ( ) . equals ( firstArgAsString ) ) { return result ; } return null ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import groovy . lang . Closure ; import java . util . Collection ; import java . util . HashMap ; import java . util . Map ; import java . util . Map . Entry ; import org . codehaus . groovy . eclipse . GroovyLogManager ; import org . codehaus . groovy . eclipse . TraceCategory ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public class UserExtensiblePointcut extends AbstractPointcut { @ SuppressWarnings ( "<STR_LIT:rawtypes>" ) private Closure closure ; public UserExtensiblePointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ SuppressWarnings ( "<STR_LIT:rawtypes>" ) public UserExtensiblePointcut ( IStorage containerIdentifier , String pointcutName , Closure closure ) { super ( containerIdentifier , pointcutName ) ; setClosure ( closure ) ; } public void setClosure ( @ SuppressWarnings ( "<STR_LIT:rawtypes>" ) Closure closure ) { this . closure = closure ; closure . setResolveStrategy ( Closure . DELEGATE_FIRST ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { if ( closure == null ) { return null ; } try { Map < String , Object > args = namedArgumentsAsMap ( ) ; Map < String , Object > newMap = new HashMap < String , Object > ( args . size ( ) , <NUM_LIT:1.0f> ) ; for ( Entry < String , Object > entry : args . entrySet ( ) ) { String key = entry . getKey ( ) ; if ( entry . getValue ( ) instanceof IPointcut ) { Collection < ? > matches = matchOnPointcutArgument ( ( IPointcut ) entry . getValue ( ) , pattern , ensureCollection ( toMatch ) ) ; if ( matches != null && matches . size ( ) > <NUM_LIT:0> ) { newMap . put ( key , pattern . getCurrentBinding ( ) . getBinding ( key ) ) ; } else { newMap . put ( key , null ) ; } } else { newMap . put ( key , entry . getValue ( ) ) ; } } Object result = null ; synchronized ( closure ) { closure . setDelegate ( newMap ) ; result = closure . call ( toMatch ) ; closure . setDelegate ( null ) ; } return ensureCollection ( result ) ; } catch ( Exception e ) { GroovyLogManager . manager . logException ( TraceCategory . DSL , e ) ; return null ; } } @ Override public void verify ( ) throws PointcutVerificationException { } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Collections ; import java . util . List ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; import org . eclipse . jdt . groovy . search . VariableScope . CallAndType ; public class EnclosingCallDeclaringTypePointcut extends AbstractPointcut { public EnclosingCallDeclaringTypePointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { List < CallAndType > enclosing = pattern . getCurrentScope ( ) . getAllEnclosingMethodCallExpressions ( ) ; if ( enclosing == null ) { return null ; } Object firstArgument = getFirstArgument ( ) ; if ( firstArgument == null ) { List < CallAndType > allEnclosingMethodCallExpressions = pattern . getCurrentScope ( ) . getAllEnclosingMethodCallExpressions ( ) ; if ( allEnclosingMethodCallExpressions != null && allEnclosingMethodCallExpressions . size ( ) > <NUM_LIT:0> ) { List < ClassNode > enclosingCallTypes = new ArrayList < ClassNode > ( allEnclosingMethodCallExpressions . size ( ) ) ; for ( CallAndType callAndType : allEnclosingMethodCallExpressions ) { enclosingCallTypes . add ( callAndType . declaringType ) ; } return enclosingCallTypes ; } return null ; } if ( firstArgument instanceof Class < ? > ) { firstArgument = ( ( Class < ? > ) firstArgument ) . getName ( ) ; } if ( firstArgument instanceof String ) { ClassNode matchingType = matchesInCalls ( enclosing , ( String ) firstArgument , pattern ) ; if ( matchingType != null ) { return Collections . singleton ( matchingType ) ; } else { return null ; } } else { return matchOnPointcutArgument ( ( IPointcut ) firstArgument , pattern , asTypeList ( enclosing ) ) ; } } private List < ClassNode > asTypeList ( List < CallAndType > enclosing ) { List < ClassNode > types = new ArrayList < ClassNode > ( enclosing . size ( ) ) ; for ( CallAndType callAndType : enclosing ) { types . add ( callAndType . declaringType ) ; } return types ; } private ClassNode matchesInCalls ( List < CallAndType > enclosing , String typeName , GroovyDSLDContext pattern ) { for ( CallAndType callAndType : enclosing ) { if ( callAndType . declaringType . getName ( ) . equals ( typeName ) ) { return callAndType . declaringType ; } } return null ; } @ Override public void verify ( ) throws PointcutVerificationException { String result = hasNoArgs ( ) ; if ( result == null ) { return ; } result = oneStringOrOnePointcutOrOneClassArg ( ) ; if ( result != null ) { throw new PointcutVerificationException ( result , this ) ; } super . verify ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . Collections ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public class SourceFolderOfFilePointcut extends AbstractPointcut { public SourceFolderOfFilePointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { if ( pattern . fullPathName != null && pattern . fullPathName . startsWith ( ( String ) getFirstArgument ( ) ) ) { return Collections . singleton ( pattern . fullPathName ) ; } else { return null ; } } @ Override public boolean fastMatch ( GroovyDSLDContext pattern ) { return matches ( pattern , null ) != null ; } @ Override public void verify ( ) throws PointcutVerificationException { String maybeStatus = allArgsAreStrings ( ) ; if ( maybeStatus != null ) { throw new PointcutVerificationException ( maybeStatus , this ) ; } maybeStatus = hasOneArg ( ) ; if ( maybeStatus != null ) { throw new PointcutVerificationException ( maybeStatus , this ) ; } super . verify ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Map ; import java . util . Map . Entry ; import org . codehaus . groovy . ast . AnnotationNode ; import org . codehaus . groovy . ast . expr . ConstantExpression ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . ast . expr . MapEntryExpression ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . eclipse . core . resources . IStorage ; public class HasAttributesPointcut extends FilteringPointcut < Expression > { public HasAttributesPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName , Expression . class ) ; } @ Override protected Collection < Expression > explodeObject ( Object toMatch ) { if ( toMatch instanceof AnnotationNode ) { Map < String , Expression > members = ( ( AnnotationNode ) toMatch ) . getMembers ( ) ; Collection < Expression > expressions = new ArrayList < Expression > ( members . size ( ) ) ; for ( Entry < String , Expression > entry : members . entrySet ( ) ) { expressions . add ( new MapEntryExpression ( new ConstantExpression ( entry . getKey ( ) ) , entry . getValue ( ) ) ) ; } return expressions ; } return null ; } @ Override protected Expression filterObject ( Expression result , GroovyDSLDContext context , String firstArgAsString ) { if ( firstArgAsString == null ) { if ( result instanceof MapEntryExpression ) { return ( ( MapEntryExpression ) result ) . getValueExpression ( ) ; } else { return result ; } } if ( result instanceof MapEntryExpression ) { MapEntryExpression entry = ( MapEntryExpression ) result ; if ( entry . getKeyExpression ( ) instanceof ConstantExpression ) { String argName = entry . getKeyExpression ( ) . getText ( ) ; if ( argName . equals ( firstArgAsString ) ) { return entry . getValueExpression ( ) ; } } } return null ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . Collections ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public class PackageFolderPointcut extends AbstractPointcut { public PackageFolderPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { if ( pattern . packageFolderPath != null && pattern . packageFolderPath . equals ( getFirstArgument ( ) ) ) { return Collections . singleton ( pattern . packageFolderPath ) ; } else { return null ; } } @ Override public boolean fastMatch ( GroovyDSLDContext pattern ) { return matches ( pattern , null ) != null ; } @ Override public void verify ( ) throws PointcutVerificationException { String maybeStatus = allArgsAreStrings ( ) ; if ( maybeStatus != null ) { throw new PointcutVerificationException ( maybeStatus , this ) ; } maybeStatus = hasOneArg ( ) ; if ( maybeStatus != null ) { throw new PointcutVerificationException ( maybeStatus , this ) ; } super . verify ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Collections ; import java . util . List ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . eclipse . core . resources . IStorage ; public class FindMethodPointcut extends FilteringPointcut < MethodNode > { public FindMethodPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName , MethodNode . class ) ; } @ Override protected Collection < MethodNode > explodeObject ( Object toMatch ) { if ( toMatch instanceof Collection < ? > ) { List < MethodNode > methods = new ArrayList < MethodNode > ( ) ; for ( Object elt : ( Collection < ? > ) toMatch ) { if ( elt instanceof MethodNode ) { methods . add ( ( MethodNode ) elt ) ; } else if ( elt instanceof ClassNode ) { methods . addAll ( ( ( ClassNode ) elt ) . getMethods ( ) ) ; } } return methods ; } else if ( toMatch instanceof ClassNode ) { return ( ( ClassNode ) toMatch ) . getMethods ( ) ; } else if ( toMatch instanceof FieldNode ) { return Collections . singleton ( ( MethodNode ) toMatch ) ; } return null ; } @ Override protected MethodNode filterObject ( MethodNode result , GroovyDSLDContext context , String firstArgAsString ) { if ( firstArgAsString == null || result . getName ( ) . equals ( firstArgAsString ) ) { return result ; } else { return null ; } } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . Collections ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public class FileNamePointcut extends AbstractPointcut { public FileNamePointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { if ( pattern . simpleFileName != null && pattern . simpleFileName . equals ( getFirstArgument ( ) ) ) { return Collections . singleton ( pattern . fullPathName ) ; } else { return null ; } } @ Override public boolean fastMatch ( GroovyDSLDContext pattern ) { return matches ( pattern , null ) != null ; } @ Override public void verify ( ) throws PointcutVerificationException { String maybeStatus = allArgsAreStrings ( ) ; if ( maybeStatus != null ) { throw new PointcutVerificationException ( maybeStatus , this ) ; } maybeStatus = hasOneArg ( ) ; if ( maybeStatus != null ) { throw new PointcutVerificationException ( maybeStatus , this ) ; } super . verify ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . Collections ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public class CurrentTypePointcut extends AbstractPointcut { public CurrentTypePointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { Object firstArgument = getFirstArgument ( ) ; ClassNode currentType = pattern . getCurrentType ( ) ; if ( firstArgument instanceof String ) { if ( currentType . getName ( ) . equals ( firstArgument ) ) { return Collections . singleton ( currentType ) ; } else { return null ; } } else if ( firstArgument instanceof Class < ? > ) { if ( currentType . getName ( ) . equals ( ( ( Class < ? > ) firstArgument ) . getName ( ) ) ) { return Collections . singleton ( currentType ) ; } else { return null ; } } else if ( firstArgument != null ) { return matchOnPointcutArgument ( ( IPointcut ) firstArgument , pattern , Collections . singleton ( currentType ) ) ; } else { return Collections . singleton ( currentType ) ; } } @ Override public void verify ( ) throws PointcutVerificationException { String oneStringOrOnePointcutArg = oneStringOrOnePointcutOrOneClassArg ( ) ; String argNumber = hasOneOrNoArgs ( ) ; if ( oneStringOrOnePointcutArg == null || argNumber == null ) { super . verify ( ) ; return ; } throw new PointcutVerificationException ( "<STR_LIT>" , this ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . Collections ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public class FileExtensionPointcut extends AbstractPointcut { public FileExtensionPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { if ( pattern . fullPathName != null && pattern . fullPathName . endsWith ( "<STR_LIT:.>" + ( String ) getFirstArgument ( ) ) ) { return Collections . singleton ( pattern . fullPathName ) ; } else { return null ; } } @ Override public boolean fastMatch ( GroovyDSLDContext pattern ) { return matches ( pattern , null ) != null ; } @ Override public void verify ( ) throws PointcutVerificationException { String maybeStatus = allArgsAreStrings ( ) ; if ( maybeStatus != null ) { throw new PointcutVerificationException ( maybeStatus , this ) ; } maybeStatus = hasOneArg ( ) ; if ( maybeStatus != null ) { throw new PointcutVerificationException ( maybeStatus , this ) ; } super . verify ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . Collections ; import org . codehaus . groovy . ast . expr . ClosureExpression ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public class EnclosingClosurePointcut extends AbstractPointcut { public EnclosingClosurePointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { ClosureExpression enclosing = pattern . getCurrentScope ( ) . getEnclosingClosure ( ) ; if ( enclosing == null ) { return null ; } return Collections . singleton ( enclosing ) ; } @ Override public void verify ( ) throws PointcutVerificationException { String args = hasNoArgs ( ) ; if ( args != null ) { throw new PointcutVerificationException ( args , this ) ; } super . verify ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . Collections ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public class CurrentTypeIsEnclosingTypePointcut extends AbstractPointcut { public CurrentTypeIsEnclosingTypePointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { ClassNode enclosing = pattern . getCurrentScope ( ) . getEnclosingTypeDeclaration ( ) ; ClassNode currentType = pattern . getCurrentType ( ) ; if ( enclosing != null && currentType != null && enclosing . redirect ( ) == currentType . redirect ( ) ) { return Collections . singleton ( currentType ) ; } return null ; } @ Override public void verify ( ) throws PointcutVerificationException { String noArgs = hasNoArgs ( ) ; if ( noArgs != null ) { throw new PointcutVerificationException ( noArgs , this ) ; } super . verify ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . Collections ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public class EnclosingScriptPointcut extends AbstractPointcut { public EnclosingScriptPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { ClassNode enclosing = pattern . getCurrentScope ( ) . getEnclosingTypeDeclaration ( ) ; if ( enclosing == null || ! enclosing . isScript ( ) ) { return null ; } Collection < ClassNode > enclosingCollection = Collections . singleton ( enclosing ) ; Object firstArgument = getFirstArgument ( ) ; if ( firstArgument instanceof String ) { if ( enclosing . getName ( ) . equals ( firstArgument ) ) { return enclosingCollection ; } else { return null ; } } else if ( firstArgument instanceof Class < ? > ) { if ( enclosing . getName ( ) . equals ( ( ( Class < ? > ) firstArgument ) . getName ( ) ) ) { return enclosingCollection ; } else { return null ; } } else if ( firstArgument == null ) { return enclosingCollection ; } else { return matchOnPointcutArgument ( ( IPointcut ) firstArgument , pattern , enclosingCollection ) ; } } @ Override public void verify ( ) throws PointcutVerificationException { String hasOneOrNoArgs = hasOneOrNoArgs ( ) ; if ( hasOneOrNoArgs != null ) { throw new PointcutVerificationException ( hasOneOrNoArgs , this ) ; } super . verify ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . Collections ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public class IsThisTypePointcut extends AbstractPointcut { public IsThisTypePointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { if ( pattern . isPrimaryNode ( ) ) { ClassNode currentType = pattern . getCurrentType ( ) ; return Collections . singleton ( currentType ) ; } return null ; } @ Override public void verify ( ) throws PointcutVerificationException { String noArgs = hasNoArgs ( ) ; if ( noArgs != null ) { throw new PointcutVerificationException ( noArgs , this ) ; } super . verify ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Collections ; import java . util . List ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . PropertyNode ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . eclipse . core . resources . IStorage ; public class FindPropertyPointcut extends FilteringPointcut < PropertyNode > { public FindPropertyPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName , PropertyNode . class ) ; } @ Override protected Collection < PropertyNode > explodeObject ( Object toMatch ) { if ( toMatch instanceof Collection < ? > ) { List < PropertyNode > properties = new ArrayList < PropertyNode > ( ) ; for ( Object elt : ( Collection < ? > ) toMatch ) { if ( elt instanceof PropertyNode ) { properties . add ( ( PropertyNode ) elt ) ; } else if ( elt instanceof ClassNode ) { properties . addAll ( ( ( ClassNode ) elt ) . getProperties ( ) ) ; } } return properties ; } else if ( toMatch instanceof ClassNode ) { return ( ( ClassNode ) toMatch ) . getProperties ( ) ; } else if ( toMatch instanceof PropertyNode ) { return Collections . singleton ( ( PropertyNode ) toMatch ) ; } return null ; } @ Override protected PropertyNode filterObject ( PropertyNode result , GroovyDSLDContext context , String firstArgAsString ) { if ( firstArgAsString == null || result . getName ( ) . equals ( firstArgAsString ) ) { return result ; } else { return null ; } } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . HashSet ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public class OrPointcut extends AbstractPointcut { public OrPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { Object [ ] args = getArgumentValues ( ) ; Collection < Object > result = new HashSet < Object > ( ) ; for ( Object arg : args ) { Collection < ? > intermediate = matchOnPointcutArgumentReturnInner ( ( IPointcut ) arg , pattern , ensureCollection ( toMatch ) ) ; if ( intermediate != null ) { result . addAll ( intermediate ) ; } } return result . size ( ) > <NUM_LIT:0> ? result : null ; } public IPointcut normalize ( ) { IPointcut newPointcut = super . normalize ( ) ; if ( newPointcut instanceof OrPointcut ) { OrPointcut newOr = ( OrPointcut ) newPointcut ; OrPointcut newNewOr = new OrPointcut ( getContainerIdentifier ( ) , "<STR_LIT>" ) ; for ( int i = <NUM_LIT:0> ; i < newOr . getArgumentValues ( ) . length ; i ++ ) { String name = newOr . getArgumentNames ( ) [ i ] ; Object argument = newOr . getArgumentValues ( ) [ i ] ; if ( argument instanceof OrPointcut && name == null ) { OrPointcut other = ( OrPointcut ) argument ; Object [ ] argumentValues = other . getArgumentValues ( ) ; String [ ] argumentNames = other . getArgumentNames ( ) ; int argCount = argumentNames . length ; for ( int j = <NUM_LIT:0> ; j < argCount ; j ++ ) { newNewOr . addArgument ( argumentNames [ j ] , argumentValues [ j ] ) ; } } else { newNewOr . addArgument ( name , argument ) ; } } return newNewOr ; } else { return newPointcut ; } } @ Override public void verify ( ) throws PointcutVerificationException { String allArgsArePointcuts = allArgsArePointcuts ( ) ; if ( allArgsArePointcuts != null ) { throw new PointcutVerificationException ( allArgsArePointcuts , this ) ; } } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . PropertyNode ; import org . codehaus . groovy . ast . expr . ConstantExpression ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . ast . expr . MapEntryExpression ; import org . codehaus . groovy . ast . expr . PropertyExpression ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . eclipse . core . resources . IStorage ; public class ValuePointcut extends FilteringPointcut < Object > { public ValuePointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName , Object . class ) ; } @ Override protected Object filterObject ( Object result , GroovyDSLDContext context , String firstArgAsString ) { if ( firstArgAsString == null ) { return reify ( result ) ; } String toCompare ; if ( result instanceof ClassNode ) { toCompare = ( ( ClassNode ) result ) . getName ( ) ; } else if ( result instanceof FieldNode ) { toCompare = ( ( FieldNode ) result ) . getName ( ) ; } else if ( result instanceof MethodNode ) { toCompare = ( ( MethodNode ) result ) . getName ( ) ; } else if ( result instanceof PropertyNode ) { toCompare = ( ( PropertyNode ) result ) . getName ( ) ; } else if ( result instanceof Expression ) { toCompare = ( ( Expression ) result ) . getText ( ) ; } else { toCompare = String . valueOf ( result . toString ( ) ) ; } return toCompare . equals ( firstArgAsString ) ? reify ( result ) : null ; } private Object reify ( Object result ) { if ( result instanceof MapEntryExpression ) { return reify ( ( ( MapEntryExpression ) result ) . getValueExpression ( ) ) ; } else if ( result instanceof ConstantExpression ) { return ( ( ConstantExpression ) result ) . getValue ( ) ; } else if ( result instanceof PropertyExpression ) { PropertyExpression prop = ( PropertyExpression ) result ; return reify ( prop . getObjectExpression ( ) ) . toString ( ) + '<CHAR_LIT:.>' + reify ( prop . getProperty ( ) ) ; } else { return super . asString ( result ) ; } } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . Collections ; import java . util . Set ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public class NotPointcut extends AbstractPointcut { private static final Set < Object > EMPTY_MATCH = Collections . singleton ( new Object ( ) ) ; public NotPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } public boolean fastMatch ( GroovyDSLDContext pattern ) { return matches ( pattern , EMPTY_MATCH ) != null ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { Collection < ? > collection ; if ( toMatch instanceof Collection ) { collection = ( Collection < ? > ) toMatch ; } else { collection = Collections . singleton ( toMatch ) ; } Collection < ? > result = matchOnPointcutArgument ( ( IPointcut ) getFirstArgument ( ) , pattern , collection ) ; if ( result != null ) { return null ; } else { return EMPTY_MATCH ; } } @ Override public void verify ( ) throws PointcutVerificationException { super . verify ( ) ; Object arg = getFirstArgument ( ) ; if ( arg instanceof IPointcut ) { ( ( IPointcut ) arg ) . verify ( ) ; } else { throw new PointcutVerificationException ( "<STR_LIT>" , this ) ; } } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . Collections ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public class EnclosingFieldPointcut extends AbstractPointcut { public EnclosingFieldPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { FieldNode enclosing = pattern . getCurrentScope ( ) . getEnclosingFieldDeclaration ( ) ; if ( enclosing == null ) { return null ; } Object firstArgument = getFirstArgument ( ) ; Collection < FieldNode > enclosingCollection = Collections . singleton ( enclosing ) ; if ( firstArgument instanceof String ) { if ( enclosing . getName ( ) . equals ( firstArgument ) ) { return enclosingCollection ; } else { return null ; } } else { return matchOnPointcutArgument ( ( IPointcut ) firstArgument , pattern , enclosingCollection ) ; } } @ Override public void verify ( ) throws PointcutVerificationException { String oneStringOrOnePointcutArg = oneStringOrOnePointcutArg ( ) ; if ( oneStringOrOnePointcutArg != null ) { throw new PointcutVerificationException ( oneStringOrOnePointcutArg , this ) ; } super . verify ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . HashSet ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public class AndPointcut extends AbstractPointcut { public AndPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { Object [ ] args = getArgumentValues ( ) ; Collection < Object > result = new HashSet < Object > ( ) ; for ( Object arg : args ) { Collection < ? > intermediate = matchOnPointcutArgumentReturnInner ( ( IPointcut ) arg , pattern , ensureCollection ( toMatch ) ) ; if ( intermediate == null ) { return null ; } result . addAll ( intermediate ) ; } return result . size ( ) > <NUM_LIT:0> ? result : null ; } public IPointcut normalize ( ) { IPointcut newPointcut = super . normalize ( ) ; if ( newPointcut instanceof AndPointcut ) { AndPointcut newAnd = ( AndPointcut ) newPointcut ; AndPointcut newNewAnd = new AndPointcut ( getContainerIdentifier ( ) , "<STR_LIT>" ) ; for ( int i = <NUM_LIT:0> ; i < newAnd . getArgumentValues ( ) . length ; i ++ ) { String name = newAnd . getArgumentNames ( ) [ i ] ; Object argument = newAnd . getArgumentValues ( ) [ i ] ; if ( argument instanceof AndPointcut && name == null ) { AndPointcut other = ( AndPointcut ) argument ; Object [ ] argumentValues = other . getArgumentValues ( ) ; String [ ] argumentNames = other . getArgumentNames ( ) ; int argCount = argumentNames . length ; for ( int j = <NUM_LIT:0> ; j < argCount ; j ++ ) { newNewAnd . addArgument ( argumentNames [ j ] , argumentValues [ j ] ) ; } } else { newNewAnd . addArgument ( name , argument ) ; } } return newNewAnd ; } else { return newPointcut ; } } @ Override public void verify ( ) throws PointcutVerificationException { String allArgsArePointcuts = allArgsArePointcuts ( ) ; if ( allArgsArePointcuts != null ) { throw new PointcutVerificationException ( allArgsArePointcuts , this ) ; } } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . Collections ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public class EnclosingMethodPointcut extends AbstractPointcut { public EnclosingMethodPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName ) ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { MethodNode enclosing = pattern . getCurrentScope ( ) . getEnclosingMethodDeclaration ( ) ; if ( enclosing == null ) { return null ; } Object firstArgument = getFirstArgument ( ) ; Collection < MethodNode > enclosingCollection = Collections . singleton ( enclosing ) ; if ( firstArgument instanceof String ) { if ( enclosing . getName ( ) . equals ( firstArgument ) ) { return enclosingCollection ; } else { return null ; } } else { return matchOnPointcutArgument ( ( IPointcut ) firstArgument , pattern , enclosingCollection ) ; } } @ Override public void verify ( ) throws PointcutVerificationException { String oneStringOrOnePointcutArg = oneStringOrOnePointcutArg ( ) ; if ( oneStringOrOnePointcutArg != null ) { throw new PointcutVerificationException ( oneStringOrOnePointcutArg , this ) ; } super . verify ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import org . codehaus . groovy . ast . AnnotationNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . PropertyNode ; import org . codehaus . groovy . ast . Variable ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . ast . expr . MapEntryExpression ; import org . codehaus . groovy . ast . expr . MethodCallExpression ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . eclipse . core . resources . IStorage ; public class NamePointcut extends FilteringPointcut < Object > { public NamePointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName , Object . class ) ; } @ Override protected Object filterObject ( Object result , GroovyDSLDContext context , String firstArgAsString ) { String toCompare ; if ( result instanceof ClassNode ) { toCompare = ( ( ClassNode ) result ) . getName ( ) ; } else if ( result instanceof AnnotationNode ) { toCompare = ( ( AnnotationNode ) result ) . getClassNode ( ) . getName ( ) ; } else if ( result instanceof FieldNode ) { toCompare = ( ( FieldNode ) result ) . getName ( ) ; } else if ( result instanceof MethodNode ) { toCompare = ( ( MethodNode ) result ) . getName ( ) ; } else if ( result instanceof PropertyNode ) { toCompare = ( ( PropertyNode ) result ) . getName ( ) ; } else if ( result instanceof MapEntryExpression ) { toCompare = ( ( MapEntryExpression ) result ) . getKeyExpression ( ) . getText ( ) ; } else if ( result instanceof MethodCallExpression ) { toCompare = ( ( MethodCallExpression ) result ) . getMethodAsString ( ) ; } else if ( result instanceof Variable ) { toCompare = ( ( Variable ) result ) . getName ( ) ; } else if ( result instanceof Expression ) { toCompare = ( ( Expression ) result ) . getText ( ) ; } else { toCompare = String . valueOf ( result . toString ( ) ) ; } if ( firstArgAsString == null ) { return toCompare ; } return toCompare . equals ( firstArgAsString ) ? toCompare : null ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Collections ; import java . util . List ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . expr . ClassExpression ; import org . codehaus . groovy . eclipse . dsl . pointcuts . AbstractPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; public abstract class FilteringPointcut < T > extends AbstractPointcut { private final Class < T > filterBy ; public FilteringPointcut ( IStorage containerIdentifier , String pointcutName , Class < T > filterBy ) { super ( containerIdentifier , pointcutName ) ; this . filterBy = filterBy ; } @ Override public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { Collection < T > explodedList = explodeObject ( toMatch ) ; if ( explodedList == null || explodedList . size ( ) == <NUM_LIT:0> ) { return null ; } Object first = getFirstArgument ( ) ; if ( first instanceof IPointcut ) { return matchOnPointcutArgument ( ( IPointcut ) first , pattern , explodedList ) ; } else { Collection < ? > filtered = filterResult ( explodedList , pattern ) ; if ( filtered != null ) { return filtered ; } return null ; } } protected Collection < ? > filterResult ( Collection < T > results , GroovyDSLDContext context ) { Object o = getFirstArgument ( ) ; String firstArg = asString ( o ) ; Collection < T > filtered = new ArrayList < T > ( results . size ( ) ) ; for ( T obj : results ) { T maybe = filterObject ( obj , context , firstArg ) ; if ( maybe != null ) { filtered . add ( maybe ) ; } } return reduce ( filtered ) ; } protected String asString ( Object o ) { if ( o instanceof String ) { return ( String ) o ; } else if ( o instanceof Class ) { return ( ( Class < ? > ) o ) . getName ( ) ; } else if ( o instanceof ClassNode ) { return ( ( ClassNode ) o ) . getName ( ) ; } else if ( o instanceof ClassExpression ) { return ( ( ClassExpression ) o ) . getType ( ) . getName ( ) ; } return null ; } protected Collection < T > reduce ( Collection < T > filtered ) { if ( filtered == null || filtered . size ( ) == <NUM_LIT:0> ) { return null ; } else { return filtered ; } } protected abstract T filterObject ( T result , GroovyDSLDContext context , String firstArgAsString ) ; protected Collection < T > explodeObject ( Object toMatch ) { if ( toMatch instanceof Collection < ? > ) { List < T > objs = new ArrayList < T > ( ) ; for ( Object elt : ( Collection < ? > ) toMatch ) { if ( filterBy . isInstance ( elt ) ) { objs . add ( ( T ) elt ) ; } } if ( objs . size ( ) > <NUM_LIT:0> ) { return objs ; } } else if ( filterBy . isInstance ( toMatch ) ) { return Collections . singletonList ( ( T ) toMatch ) ; } return null ; } @ Override public void verify ( ) throws PointcutVerificationException { super . verify ( ) ; String oneStringOrOnePointcutArg = oneStringOrOnePointcutOrOneClassArg ( ) ; if ( oneStringOrOnePointcutArg != null ) { String hasNoArgs = hasNoArgs ( ) ; if ( hasNoArgs != null ) { throw new PointcutVerificationException ( "<STR_LIT>" , this ) ; } } } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Collections ; import java . util . List ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . eclipse . core . resources . IStorage ; public class FindFieldPointcut extends FilteringPointcut < FieldNode > { public FindFieldPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName , FieldNode . class ) ; } @ Override protected Collection < FieldNode > explodeObject ( Object toMatch ) { if ( toMatch instanceof Collection < ? > ) { List < FieldNode > fields = new ArrayList < FieldNode > ( ) ; for ( Object elt : ( Collection < ? > ) toMatch ) { if ( elt instanceof FieldNode ) { fields . add ( ( FieldNode ) elt ) ; } else if ( elt instanceof ClassNode ) { fields . addAll ( ( ( ClassNode ) elt ) . getFields ( ) ) ; } } return fields ; } else if ( toMatch instanceof ClassNode ) { return ( ( ClassNode ) toMatch ) . getFields ( ) ; } else if ( toMatch instanceof FieldNode ) { return Collections . singleton ( ( FieldNode ) toMatch ) ; } return null ; } @ Override protected FieldNode filterObject ( FieldNode result , GroovyDSLDContext context , String firstArgAsString ) { if ( firstArgAsString == null || result . getName ( ) . equals ( firstArgAsString ) ) { return result ; } else { return null ; } } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . PropertyNode ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IStorage ; import org . objectweb . asm . Opcodes ; public class AbstractModifierPointcut extends FilteringPointcut < AnnotatedNode > { public static class FinalPointcut extends AbstractModifierPointcut { public FinalPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName , Opcodes . ACC_FINAL ) ; } } public static class StaticPointcut extends AbstractModifierPointcut { public StaticPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName , Opcodes . ACC_STATIC ) ; } } public static class PublicPointcut extends AbstractModifierPointcut { public PublicPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName , Opcodes . ACC_PUBLIC ) ; } } public static class PrivatePointcut extends AbstractModifierPointcut { public PrivatePointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName , Opcodes . ACC_PRIVATE ) ; } } public static class SynchronizedPointcut extends AbstractModifierPointcut { public SynchronizedPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName , Opcodes . ACC_SYNCHRONIZED ) ; } } private final int modifier ; public AbstractModifierPointcut ( IStorage containerIdentifier , String pointcutName , int modifier ) { super ( containerIdentifier , pointcutName , AnnotatedNode . class ) ; this . modifier = modifier ; } @ Override protected AnnotatedNode filterObject ( AnnotatedNode result , GroovyDSLDContext pattern , String firstArgAsString ) { boolean success = false ; if ( result instanceof ClassNode ) { success = ( ( ( ClassNode ) result ) . getModifiers ( ) & modifier ) != <NUM_LIT:0> ; } else if ( result instanceof FieldNode ) { success = ( ( ( FieldNode ) result ) . getModifiers ( ) & modifier ) != <NUM_LIT:0> ; } else if ( result instanceof MethodNode ) { success = ( ( ( MethodNode ) result ) . getModifiers ( ) & modifier ) != <NUM_LIT:0> ; } else if ( result instanceof PropertyNode ) { success = ( ( ( PropertyNode ) result ) . getModifiers ( ) & modifier ) != <NUM_LIT:0> ; } return success ? result : null ; } @ Override public void verify ( ) throws PointcutVerificationException { if ( getArgumentValues ( ) . length > <NUM_LIT:0> ) { throw new PointcutVerificationException ( "<STR_LIT>" , this ) ; } } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . Collection ; import java . util . Collections ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . PropertyNode ; import org . codehaus . groovy . ast . Variable ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . eclipse . core . resources . IStorage ; public class TypePointcut extends FilteringPointcut < ClassNode > { public TypePointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName , ClassNode . class ) ; } @ Override protected Collection < ClassNode > explodeObject ( Object toMatch ) { ClassNode type ; if ( toMatch instanceof ClassNode ) { type = ( ClassNode ) toMatch ; } else if ( toMatch instanceof FieldNode ) { type = ( ( FieldNode ) toMatch ) . getType ( ) ; } else if ( toMatch instanceof MethodNode ) { type = ( ( MethodNode ) toMatch ) . getReturnType ( ) ; } else if ( toMatch instanceof PropertyNode ) { type = ( ( PropertyNode ) toMatch ) . getType ( ) ; } else if ( toMatch instanceof Expression ) { type = ( ( Expression ) toMatch ) . getType ( ) ; } else if ( toMatch instanceof Variable ) { type = ( ( Variable ) toMatch ) . getType ( ) ; } else { type = null ; } if ( type != null ) { return Collections . singleton ( type ) ; } else { return null ; } } @ Override protected ClassNode filterObject ( ClassNode result , GroovyDSLDContext context , String firstArgAsString ) { return firstArgAsString == null ? result : ( result . getName ( ) . equals ( firstArgAsString ) ? result : null ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts . impl ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collection ; import java . util . Collections ; import java . util . List ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Parameter ; import org . codehaus . groovy . ast . expr . ConstantExpression ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . ast . expr . ListExpression ; import org . codehaus . groovy . ast . expr . MapEntryExpression ; import org . codehaus . groovy . ast . expr . MapExpression ; import org . codehaus . groovy . ast . expr . MethodCallExpression ; import org . codehaus . groovy . ast . expr . TupleExpression ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . eclipse . core . resources . IStorage ; public class HasArgumentsPointcut extends FilteringPointcut < AnnotatedNode > { public HasArgumentsPointcut ( IStorage containerIdentifier , String pointcutName ) { super ( containerIdentifier , pointcutName , AnnotatedNode . class ) ; } @ Override protected Collection < AnnotatedNode > explodeObject ( Object toMatch ) { if ( toMatch instanceof MethodCallExpression ) { Expression arguments = ( ( MethodCallExpression ) toMatch ) . getArguments ( ) ; if ( arguments instanceof TupleExpression ) { List < Expression > innerArgs = ( ( TupleExpression ) arguments ) . getExpressions ( ) ; List < AnnotatedNode > actualArgs = new ArrayList < AnnotatedNode > ( innerArgs . size ( ) ) ; for ( Expression innerArg : innerArgs ) { if ( innerArg instanceof MapExpression ) { actualArgs . addAll ( ( ( MapExpression ) innerArg ) . getMapEntryExpressions ( ) ) ; } else { actualArgs . add ( innerArg ) ; } } return actualArgs ; } else if ( arguments instanceof ListExpression ) { return new ArrayList < AnnotatedNode > ( ( ( ListExpression ) arguments ) . getExpressions ( ) ) ; } else if ( arguments instanceof MapExpression ) { List < MapEntryExpression > mapEntryExpressions = ( ( MapExpression ) arguments ) . getMapEntryExpressions ( ) ; List < AnnotatedNode > result = new ArrayList < AnnotatedNode > ( mapEntryExpressions ) ; result . addAll ( mapEntryExpressions ) ; return result ; } else { return Collections . < AnnotatedNode > singleton ( arguments ) ; } } else if ( toMatch instanceof MethodNode ) { Parameter [ ] parameters = ( ( MethodNode ) toMatch ) . getParameters ( ) ; if ( parameters != null ) { return Arrays . < AnnotatedNode > asList ( parameters ) ; } } return null ; } @ Override protected AnnotatedNode filterObject ( AnnotatedNode result , GroovyDSLDContext context , String firstArgAsString ) { if ( firstArgAsString == null ) { if ( result instanceof MapEntryExpression ) { return ( ( MapEntryExpression ) result ) . getValueExpression ( ) ; } else { return result ; } } else if ( result instanceof MapEntryExpression ) { MapEntryExpression entry = ( MapEntryExpression ) result ; if ( entry . getKeyExpression ( ) instanceof ConstantExpression ) { String argName = entry . getKeyExpression ( ) . getText ( ) ; if ( argName . equals ( firstArgAsString ) ) { return entry . getValueExpression ( ) ; } } } else if ( result instanceof Parameter ) { String name = ( ( Parameter ) result ) . getName ( ) ; if ( name . equals ( firstArgAsString ) ) { return result ; } } return null ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . pointcuts ; import groovy . lang . Closure ; import java . util . Collection ; import java . util . Collections ; import java . util . HashSet ; import java . util . Map ; import org . codehaus . groovy . eclipse . GroovyLogManager ; import org . codehaus . groovy . eclipse . TraceCategory ; import org . codehaus . groovy . eclipse . dsl . GroovyDSLCoreActivator ; import org . codehaus . groovy . eclipse . dsl . contributions . DSLContributionGroup ; import org . codehaus . groovy . eclipse . dsl . contributions . IContributionGroup ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . AndPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . NotPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . OrPointcut ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IStorage ; public abstract class AbstractPointcut implements IPointcut { private IStorage containerIdentifier ; private StringObjectVector elements = new StringObjectVector ( <NUM_LIT:1> ) ; private IProject project ; private String pointcutName ; public AbstractPointcut ( IStorage containerIdentifier , String pointcutName ) { this . containerIdentifier = containerIdentifier ; this . pointcutName = pointcutName ; } public String getPointcutName ( ) { return pointcutName ; } public void setPointcutName ( String pointcutName ) { this . pointcutName = pointcutName ; } public String getPointcutDebugName ( ) { return pointcutName + "<STR_LIT:U+0020(>" + getClass ( ) . getSimpleName ( ) + "<STR_LIT:)>" ; } public IStorage getContainerIdentifier ( ) { return containerIdentifier ; } public void setContainerIdentifier ( IStorage containerIdentifier ) { this . containerIdentifier = containerIdentifier ; } public void verify ( ) throws PointcutVerificationException { if ( elements . size > <NUM_LIT:1> ) { throw new PointcutVerificationException ( "<STR_LIT>" , this ) ; } } public final void addArgument ( Object argument ) { elements . add ( null , argument ) ; } public abstract Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) ; public final void addArgument ( String name , Object argument ) { if ( name == null ) { addArgument ( argument ) ; return ; } elements . add ( name , argument ) ; } protected Collection < ? > matchOnPointcutArgument ( IPointcut argument , GroovyDSLDContext pattern , Collection < ? > allElementsToMatch ) { if ( allElementsToMatch == null ) { return null ; } Collection < Object > outerResults = new HashSet < Object > ( ) ; for ( Object toMatch : allElementsToMatch ) { Collection < ? > innerResults = argument . matches ( pattern , toMatch ) ; if ( innerResults != null ) { String bindingName = getArgumentName ( argument ) ; if ( bindingName != null ) { pattern . addToBinding ( bindingName , innerResults ) ; } outerResults . add ( toMatch ) ; } } return outerResults . size ( ) > <NUM_LIT:0> ? outerResults : null ; } protected Collection < ? > matchOnPointcutArgumentReturnInner ( IPointcut argument , GroovyDSLDContext pattern , Collection < ? > allElementsToMatch ) { String bindingName = getArgumentName ( argument ) ; Collection < Object > innerResults = new HashSet < Object > ( ) ; for ( Object toMatch : allElementsToMatch ) { Collection < ? > tempInnerResults = argument . matches ( pattern , toMatch ) ; if ( tempInnerResults != null ) { innerResults . addAll ( tempInnerResults ) ; } } if ( bindingName != null && innerResults . size ( ) > <NUM_LIT:0> ) { pattern . addToBinding ( bindingName , innerResults ) ; } return innerResults != null && innerResults . size ( ) > <NUM_LIT:0> ? innerResults : null ; } protected Collection < ? > flatten ( Map < Object , Collection < ? > > pointcutResult ) { Collection < Object > newCollection = new HashSet < Object > ( pointcutResult . size ( ) ) ; for ( Collection < ? > collection : pointcutResult . values ( ) ) { newCollection . addAll ( collection ) ; } return newCollection ; } public final Object getFirstArgument ( ) { if ( elements . size > <NUM_LIT:0> ) { return elements . elementAt ( <NUM_LIT:0> ) ; } else { return null ; } } public final String [ ] getArgumentNames ( ) { return elements . getNames ( ) ; } public final Object [ ] getArgumentValues ( ) { return elements . getElements ( ) ; } public final String getArgumentName ( Object argument ) { for ( int i = <NUM_LIT:0> ; i < elements . size ; i ++ ) { if ( elements . elementAt ( i ) == argument ) { return elements . nameAt ( i ) ; } } return null ; } public final String getFirstArgumentName ( ) { if ( elements . size > <NUM_LIT:0> ) { return elements . nameAt ( <NUM_LIT:0> ) ; } else { return null ; } } public final String getNameForArgument ( Object arg ) { return elements . nameOf ( arg ) ; } public IPointcut normalize ( ) { for ( int i = <NUM_LIT:0> ; i < elements . size ; i ++ ) { Object elt = elements . elementAt ( i ) ; if ( elt instanceof IPointcut ) { elements . setElement ( ( ( IPointcut ) elt ) . normalize ( ) , i ) ; } } return this ; } public boolean fastMatch ( GroovyDSLDContext pattern ) { for ( Object elt : elements . getElements ( ) ) { if ( elt instanceof IPointcut && ! ( ( IPointcut ) elt ) . fastMatch ( pattern ) ) { return false ; } } return true ; } public void setProject ( IProject project ) { this . project = project ; } public void accept ( @ SuppressWarnings ( "<STR_LIT:rawtypes>" ) Closure contributionGroupClosure ) { IContributionGroup group = new DSLContributionGroup ( contributionGroupClosure ) ; if ( project != null ) { try { this . verify ( ) ; IProject p = project ; IPointcut normalized = this . normalize ( ) ; if ( GroovyLogManager . manager . hasLoggers ( ) ) { GroovyLogManager . manager . log ( TraceCategory . DSL , "<STR_LIT>" + this . toString ( ) ) ; } GroovyDSLCoreActivator . getDefault ( ) . getContextStoreManager ( ) . getDSLDStore ( p ) . addContributionGroup ( normalized , group ) ; } catch ( PointcutVerificationException e ) { if ( GroovyLogManager . manager . hasLoggers ( ) ) { GroovyLogManager . manager . log ( TraceCategory . DSL , "<STR_LIT>" ) ; GroovyLogManager . manager . log ( TraceCategory . DSL , e . getPointcutMessage ( ) ) ; GroovyLogManager . manager . logException ( TraceCategory . DSL , e ) ; } } } } protected final String allArgsArePointcuts ( ) throws PointcutVerificationException { for ( Object arg : elements . getElements ( ) ) { if ( arg == null ) { continue ; } if ( ! ( arg instanceof IPointcut ) ) { return "<STR_LIT>" ; } else { ( ( IPointcut ) arg ) . verify ( ) ; } } return null ; } protected final String matchesArgNumber ( int num ) { Object [ ] elements2 = elements . getElements ( ) ; if ( elements2 . length == num ) { return null ; } else { return "<STR_LIT>" + num + "<STR_LIT>" + elements2 . length ; } } protected final String hasOneArg ( ) { if ( elements . getElements ( ) . length == <NUM_LIT:1> ) { return null ; } else { return "<STR_LIT>" + elements . getElements ( ) . length + "<STR_LIT>" ; } } protected final String hasOneOrNoArgs ( ) { if ( elements . getElements ( ) . length <= <NUM_LIT:1> ) { return null ; } else { return "<STR_LIT>" + elements . getElements ( ) . length + "<STR_LIT>" ; } } protected final String hasNoArgs ( ) { if ( elements . getElements ( ) . length == <NUM_LIT:0> ) { return null ; } else { return "<STR_LIT>" + elements . getElements ( ) . length + "<STR_LIT>" ; } } protected final String allArgsAreStrings ( ) { for ( Object arg : elements . getElements ( ) ) { if ( arg == null ) { continue ; } if ( ! ( arg instanceof String ) ) { return "<STR_LIT>" ; } } return null ; } protected final String oneStringOrOnePointcutArg ( ) throws PointcutVerificationException { String maybeStatus = allArgsAreStrings ( ) ; String maybeStatus2 = allArgsArePointcuts ( ) ; if ( maybeStatus != null && maybeStatus2 != null ) { return "<STR_LIT>" ; } maybeStatus = hasOneArg ( ) ; if ( maybeStatus != null ) { return maybeStatus ; } return null ; } protected final String oneStringOrOnePointcutOrOneClassArg ( ) throws PointcutVerificationException { String maybeStatus = allArgsAreStrings ( ) ; String maybeStatus2 = allArgsArePointcuts ( ) ; String maybeStatus3 = allArgsAreClasses ( ) ; if ( maybeStatus != null && maybeStatus2 != null && maybeStatus3 != null ) { return "<STR_LIT>" ; } maybeStatus = hasOneArg ( ) ; if ( maybeStatus != null ) { return maybeStatus ; } return null ; } protected final String allArgsAreClasses ( ) { for ( Object arg : elements . getElements ( ) ) { if ( arg == null ) { continue ; } if ( ! ( arg instanceof Class < ? > ) ) { return "<STR_LIT>" ; } } return null ; } protected IPointcut and ( IPointcut other ) { AbstractPointcut andPointcut = new AndPointcut ( containerIdentifier , "<STR_LIT>" ) ; andPointcut . setProject ( project ) ; andPointcut . addArgument ( this ) ; andPointcut . addArgument ( other ) ; return andPointcut ; } protected IPointcut or ( IPointcut other ) { AbstractPointcut orPointcut = new OrPointcut ( containerIdentifier , "<STR_LIT>" ) ; orPointcut . setProject ( project ) ; orPointcut . addArgument ( this ) ; orPointcut . addArgument ( other ) ; return orPointcut ; } protected IPointcut bitwiseNegate ( ) { AbstractPointcut notPointcut = new NotPointcut ( containerIdentifier , "<STR_LIT>" ) ; notPointcut . setProject ( project ) ; notPointcut . addArgument ( this ) ; return notPointcut ; } @ Override public String toString ( ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "<STR_LIT:(>" + containerIdentifier + "<STR_LIT>" ) ; formatedString ( sb , <NUM_LIT:2> ) ; return sb . toString ( ) ; } protected void formatedString ( StringBuilder sb , int indent ) { sb . append ( getPointcutDebugName ( ) ) ; elements . formattedString ( sb , indent + <NUM_LIT:2> ) ; sb . append ( "<STR_LIT:n>" ) ; } static String spaces ( int indent ) { StringBuilder sb = new StringBuilder ( indent + <NUM_LIT:2> ) ; for ( int i = <NUM_LIT:0> ; i < indent ; i ++ ) { sb . append ( '<CHAR_LIT:U+0020>' ) ; } return sb . toString ( ) ; } protected Map < String , Object > namedArgumentsAsMap ( ) { return elements . asMap ( ) ; } protected Collection < ? > ensureCollection ( Object toMatch ) { if ( toMatch == null ) { return null ; } return toMatch instanceof Collection ? ( Collection < ? > ) toMatch : Collections . singleton ( toMatch ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; import org . codehaus . groovy . eclipse . GroovyLogManager ; import org . codehaus . groovy . eclipse . TraceCategory ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . SuggestionsLoader ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . writer . SuggestionsFileProperties ; import org . codehaus . groovy . eclipse . dsl . script . DSLDScriptExecutor ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IFolder ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . resources . IResourceRuleFactory ; import org . eclipse . core . resources . IResourceVisitor ; import org . eclipse . core . resources . IStorage ; import org . eclipse . core . resources . IWorkspace ; import org . eclipse . core . resources . IWorkspaceRunnable ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . runtime . IStatus ; import org . eclipse . core . runtime . MultiStatus ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . core . runtime . OperationCanceledException ; import org . eclipse . core . runtime . Status ; import org . eclipse . core . runtime . SubProgressMonitor ; import org . eclipse . core . runtime . jobs . ISchedulingRule ; import org . eclipse . core . runtime . jobs . Job ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . internal . core . ExternalPackageFragmentRoot ; import org . eclipse . jface . preference . IPreferenceStore ; public class RefreshDSLDJob extends Job { public class DSLDResourceVisitor implements IResourceVisitor { private static final String PLUGIN_DSLD_SUPPORT = "<STR_LIT>" ; private static final String GLOBAL_DSLD_SUPPORT = "<STR_LIT>" ; private final IProject project ; private final Set < IStorage > dsldFiles ; private final Set < String > alreadyAdded ; public DSLDResourceVisitor ( IProject project ) { this . project = project ; this . dsldFiles = new HashSet < IStorage > ( ) ; alreadyAdded = new HashSet < String > ( ) ; } public boolean visit ( IResource resource ) throws CoreException { if ( resource . isDerived ( ) ) { return false ; } if ( resource . getType ( ) == IResource . FILE ) { IFile file = ( IFile ) resource ; if ( ! alreadyAdded . contains ( file ) && ( isDSLD ( file ) || isSuggestionFile ( file ) ) ) { alreadyAdded . add ( file . getName ( ) ) ; dsldFiles . add ( file ) ; } else { if ( alreadyAdded . contains ( file . getName ( ) ) ) { GroovyDSLCoreActivator . logWarning ( "<STR_LIT>" + file . getFullPath ( ) + "<STR_LIT>" ) ; } } } return true ; } public Set < IStorage > findFiles ( IProgressMonitor monitor ) { try { project . accept ( this ) ; findDSLDsInLibraries ( monitor ) ; } catch ( CoreException e ) { GroovyDSLCoreActivator . logException ( e ) ; } return dsldFiles ; } protected void findDSLDsInLibraries ( IProgressMonitor monitor ) throws JavaModelException { IJavaProject javaProject = JavaCore . create ( project ) ; IPackageFragmentRoot [ ] roots = getFragmentRoots ( javaProject , monitor ) ; for ( IPackageFragmentRoot root : roots ) { if ( monitor . isCanceled ( ) ) { throw new OperationCanceledException ( ) ; } if ( root . getKind ( ) == IPackageFragmentRoot . K_BINARY || isSourceFolderFromOtherProject ( root ) ) { IPackageFragment frag = root . getPackageFragment ( "<STR_LIT>" ) ; if ( frag . exists ( ) || root . getElementName ( ) . equals ( GLOBAL_DSLD_SUPPORT ) || root . getElementName ( ) . equals ( PLUGIN_DSLD_SUPPORT ) ) { IResource rootResource = root . getResource ( ) ; if ( rootResource == null && root instanceof ExternalPackageFragmentRoot ) { rootResource = ( ( ExternalPackageFragmentRoot ) root ) . resource ( ) ; } if ( rootResource != null ) { try { rootResource . refreshLocal ( IResource . DEPTH_INFINITE , monitor ) ; root . close ( ) ; root . open ( monitor ) ; if ( monitor . isCanceled ( ) ) { throw new OperationCanceledException ( ) ; } if ( ! root . exists ( ) || ! frag . exists ( ) ) { continue ; } } catch ( CoreException e ) { GroovyDSLCoreActivator . logException ( e ) ; } } if ( rootResource instanceof IFolder && ( ( IFolder ) rootResource ) . getFolder ( "<STR_LIT>" ) . exists ( ) ) { IFolder dsldFolder = ( ( IFolder ) rootResource ) . getFolder ( "<STR_LIT>" ) ; try { for ( IResource resource : dsldFolder . members ( ) ) { if ( resource . getType ( ) == IResource . FILE && ! alreadyAdded . contains ( resource . getName ( ) ) && isDSLD ( ( IFile ) resource ) ) { alreadyAdded . add ( resource . getName ( ) ) ; dsldFiles . add ( ( IStorage ) resource ) ; } else { if ( alreadyAdded . contains ( resource . getName ( ) ) ) { GroovyLogManager . manager . log ( TraceCategory . DSL , "<STR_LIT>" + resource . getFullPath ( ) + "<STR_LIT>" ) ; } } } } catch ( CoreException e ) { GroovyDSLCoreActivator . logException ( e ) ; } } else { Object [ ] resources = frag . getNonJavaResources ( ) ; for ( Object resource : resources ) { if ( resource instanceof IStorage ) { IStorage file = ( IStorage ) resource ; if ( ! alreadyAdded . contains ( file . getName ( ) ) && isDSLD ( file ) ) { alreadyAdded . add ( file . getName ( ) ) ; dsldFiles . add ( file ) ; } else { if ( alreadyAdded . contains ( file . getName ( ) ) ) { GroovyLogManager . manager . log ( TraceCategory . DSL , "<STR_LIT>" + file . getFullPath ( ) + "<STR_LIT>" ) ; } } } } } } } } } private boolean isSourceFolderFromOtherProject ( IPackageFragmentRoot root ) { if ( root . isReadOnly ( ) ) { return false ; } IResource resource = root . getResource ( ) ; if ( resource == null ) { return false ; } if ( resource . getProject ( ) . equals ( project ) ) { return false ; } return true ; } private IPackageFragmentRoot [ ] getFragmentRoots ( final IJavaProject javaProject , IProgressMonitor monitor ) throws JavaModelException { final IPackageFragmentRoot [ ] [ ] roots = new IPackageFragmentRoot [ <NUM_LIT:1> ] [ ] ; try { ResourcesPlugin . getWorkspace ( ) . run ( new IWorkspaceRunnable ( ) { public void run ( IProgressMonitor monitor ) throws CoreException { roots [ <NUM_LIT:0> ] = javaProject . getAllPackageFragmentRoots ( ) ; } } , getSchedulingRule ( ) , IWorkspace . AVOID_UPDATE , monitor ) ; } catch ( CoreException e ) { GroovyDSLCoreActivator . logException ( e ) ; } return roots [ <NUM_LIT:0> ] != null ? roots [ <NUM_LIT:0> ] : new IPackageFragmentRoot [ <NUM_LIT:0> ] ; } private ISchedulingRule getSchedulingRule ( ) { IResourceRuleFactory ruleFactory = ResourcesPlugin . getWorkspace ( ) . getRuleFactory ( ) ; return ruleFactory . buildRule ( ) ; } } private final List < IProject > projects ; public RefreshDSLDJob ( IProject project ) { this ( Collections . singletonList ( project ) ) ; } public RefreshDSLDJob ( List < IProject > projects ) { super ( "<STR_LIT>" ) ; this . projects = projects ; } protected boolean isDSLD ( IStorage file ) { return isFile ( file , "<STR_LIT>" ) ; } protected boolean isSuggestionFile ( IStorage file ) { return isFile ( file , SuggestionsFileProperties . FILE_TYPE ) ; } protected boolean isFile ( IStorage file , String extension ) { if ( file instanceof IFile ) { IFile iFile = ( IFile ) file ; return ! iFile . isDerived ( ) && extension . equals ( iFile . getFileExtension ( ) ) ; } else { String name = file . getName ( ) ; return name != null && name . endsWith ( extension ) ; } } @ Override public IStatus run ( IProgressMonitor monitor ) { IPreferenceStore prefStore = GroovyDSLCoreActivator . getDefault ( ) . getPreferenceStore ( ) ; if ( prefStore . getBoolean ( DSLPreferencesInitializer . DSLD_DISABLED ) ) { if ( GroovyLogManager . manager . hasLoggers ( ) ) { GroovyLogManager . manager . log ( TraceCategory . DSL , "<STR_LIT>" ) ; } return Status . OK_STATUS ; } List < IStatus > errorStatuses = new ArrayList < IStatus > ( ) ; if ( monitor == null ) { monitor = new NullProgressMonitor ( ) ; } monitor . beginTask ( "<STR_LIT>" , projects . size ( ) * <NUM_LIT:9> ) ; for ( IProject project : projects ) { IStatus res = refreshProject ( project , new SubProgressMonitor ( monitor , <NUM_LIT:9> ) ) ; if ( ! res . isOK ( ) ) { errorStatuses . add ( res ) ; } else if ( res == Status . CANCEL_STATUS ) { return res ; } } monitor . done ( ) ; if ( errorStatuses . isEmpty ( ) ) { return Status . OK_STATUS ; } else { MultiStatus multi = new MultiStatus ( GroovyDSLCoreActivator . PLUGIN_ID , <NUM_LIT:0> , "<STR_LIT>" , null ) ; for ( IStatus error : errorStatuses ) { multi . add ( error ) ; } return multi ; } } private IStatus refreshProject ( IProject project , IProgressMonitor monitor ) { String event = null ; if ( GroovyLogManager . manager . hasLoggers ( ) ) { GroovyLogManager . manager . log ( TraceCategory . DSL , "<STR_LIT>" + project . getName ( ) ) ; event = "<STR_LIT>" + project . getName ( ) ; GroovyLogManager . manager . logStart ( event ) ; } monitor . beginTask ( "<STR_LIT>" + project . getName ( ) , <NUM_LIT:9> ) ; if ( monitor . isCanceled ( ) ) { return Status . CANCEL_STATUS ; } monitor . worked ( <NUM_LIT:1> ) ; if ( GroovyLogManager . manager . hasLoggers ( ) ) { GroovyLogManager . manager . log ( TraceCategory . DSL , "<STR_LIT>" ) ; } DSLDStore store = GroovyDSLCoreActivator . getDefault ( ) . getContextStoreManager ( ) . getDSLDStore ( project ) ; store . purgeAll ( ) ; if ( monitor . isCanceled ( ) ) { return Status . CANCEL_STATUS ; } monitor . worked ( <NUM_LIT:1> ) ; if ( GroovyLogManager . manager . hasLoggers ( ) ) { GroovyLogManager . manager . log ( TraceCategory . DSL , "<STR_LIT>" ) ; } Set < IStorage > findDSLDFiles = new DSLDResourceVisitor ( project ) . findFiles ( monitor ) ; if ( monitor . isCanceled ( ) ) { return Status . CANCEL_STATUS ; } monitor . worked ( <NUM_LIT:1> ) ; for ( IStorage file : findDSLDFiles ) { if ( GroovyLogManager . manager . hasLoggers ( ) ) { GroovyLogManager . manager . log ( TraceCategory . DSL , "<STR_LIT>" + file . getName ( ) + "<STR_LIT>" + project . getName ( ) ) ; } monitor . subTask ( "<STR_LIT>" + file . getName ( ) + "<STR_LIT>" + project . getName ( ) ) ; if ( isDSLD ( file ) ) { DSLDScriptExecutor executor = new DSLDScriptExecutor ( JavaCore . create ( project ) ) ; executor . executeScript ( file ) ; } else if ( isSuggestionFile ( file ) ) { new SuggestionsLoader ( ( IFile ) file ) . loadExistingSuggestions ( ) ; } if ( monitor . isCanceled ( ) ) { return Status . CANCEL_STATUS ; } } monitor . worked ( <NUM_LIT:6> ) ; monitor . done ( ) ; if ( event != null ) { GroovyLogManager . manager . logEnd ( event , TraceCategory . DSL ) ; } return Status . OK_STATUS ; } @ Override public boolean belongsTo ( Object family ) { return family == RefreshDSLDJob . class ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl ; import org . eclipse . core . runtime . preferences . AbstractPreferenceInitializer ; import org . eclipse . jface . preference . IPreferenceStore ; public class DSLPreferencesInitializer extends AbstractPreferenceInitializer { public static final String AUTO_ADD_DSL_SUPPORT = "<STR_LIT>" ; public static final String PROJECTS_TO_IGNORE = "<STR_LIT>" ; public static final String DSLD_DISABLED = "<STR_LIT>" ; @ Override public void initializeDefaultPreferences ( ) { IPreferenceStore store = GroovyDSLCoreActivator . getDefault ( ) . getPreferenceStore ( ) ; store . setDefault ( AUTO_ADD_DSL_SUPPORT , true ) ; store . setDefault ( DSLD_DISABLED , false ) ; store . setDefault ( PROJECTS_TO_IGNORE , "<STR_LIT>" ) ; } public static void reset ( ) { IPreferenceStore store = GroovyDSLCoreActivator . getDefault ( ) . getPreferenceStore ( ) ; store . setValue ( AUTO_ADD_DSL_SUPPORT , true ) ; store . setValue ( DSLD_DISABLED , false ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . classpath ; import org . codehaus . groovy . eclipse . dsl . DSLPreferencesInitializer ; import org . codehaus . groovy . eclipse . dsl . GroovyDSLCoreActivator ; import org . eclipse . jdt . internal . ui . packageview . ClassPathContainer ; import org . eclipse . jface . viewers . IDecoration ; import org . eclipse . jface . viewers . ILightweightLabelDecorator ; import org . eclipse . jface . viewers . LabelProvider ; public class DSLDClasspathContainerDecorator extends LabelProvider implements ILightweightLabelDecorator { public void decorate ( Object element , IDecoration decoration ) { if ( element instanceof ClassPathContainer ) { ClassPathContainer container = ( ClassPathContainer ) element ; if ( container . getClasspathEntry ( ) . getPath ( ) . equals ( GroovyDSLCoreActivator . CLASSPATH_CONTAINER_ID ) ) { if ( container . getJavaProject ( ) . getProject ( ) . isAccessible ( ) && GroovyDSLCoreActivator . getDefault ( ) . getPreferenceStore ( ) . getBoolean ( DSLPreferencesInitializer . DSLD_DISABLED ) ) { decoration . addSuffix ( "<STR_LIT>" ) ; } } } } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . classpath ; import static org . eclipse . jdt . core . JavaCore . newLibraryEntry ; import java . io . File ; import java . net . URL ; import java . util . ArrayList ; import java . util . List ; import org . codehaus . groovy . eclipse . core . builder . GroovyClasspathContainer ; import org . codehaus . groovy . eclipse . core . compiler . CompilerUtils ; import org . codehaus . groovy . eclipse . dsl . DSLPreferencesInitializer ; import org . codehaus . groovy . eclipse . dsl . GroovyDSLCoreActivator ; import org . eclipse . core . runtime . Assert ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . Path ; import org . eclipse . jdt . core . ClasspathContainerInitializer ; import org . eclipse . jdt . core . IClasspathContainer ; import org . eclipse . jdt . core . IClasspathEntry ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . JavaCore ; public class DSLDContainerInitializer extends ClasspathContainerInitializer { private static final IClasspathEntry [ ] NO_ENTRIES = new IClasspathEntry [ <NUM_LIT:0> ] ; private final class DSLDClasspathContainer implements IClasspathContainer { private IClasspathEntry [ ] entries ; public IPath getPath ( ) { return GroovyDSLCoreActivator . CLASSPATH_CONTAINER_ID ; } public int getKind ( ) { return K_APPLICATION ; } public String getDescription ( ) { return "<STR_LIT>" ; } public IClasspathEntry [ ] getClasspathEntries ( ) { if ( entries == null ) { entries = calculateEntries ( ) ; } return entries ; } void reset ( ) { entries = null ; } protected IClasspathEntry [ ] calculateEntries ( ) { if ( GroovyDSLCoreActivator . getDefault ( ) . getPreferenceStore ( ) . getBoolean ( DSLPreferencesInitializer . DSLD_DISABLED ) ) { return NO_ENTRIES ; } String dotGroovyLocation = CompilerUtils . getDotGroovyLocation ( ) ; List < IClasspathEntry > newEntries = new ArrayList < IClasspathEntry > ( ) ; if ( dotGroovyLocation != null ) { dotGroovyLocation += "<STR_LIT>" ; File globalDsldLocation = new File ( dotGroovyLocation ) ; if ( ! globalDsldLocation . exists ( ) ) { try { globalDsldLocation . mkdirs ( ) ; } catch ( SecurityException e ) { GroovyDSLCoreActivator . logException ( "<STR_LIT>" + dotGroovyLocation + "<STR_LIT>" , e ) ; } } if ( globalDsldLocation . exists ( ) ) { IPath dsldPath = new Path ( globalDsldLocation . getAbsolutePath ( ) ) ; newEntries . add ( newLibraryEntry ( dsldPath , null , null , false ) ) ; } } URL folder = CompilerUtils . findDSLDFolder ( ) ; if ( folder != null ) { String file = folder . getFile ( ) ; Assert . isTrue ( new File ( file ) . exists ( ) , "<STR_LIT>" + file ) ; IPath path = new Path ( folder . getPath ( ) ) ; newEntries . add ( newLibraryEntry ( path , null , null ) ) ; } return newEntries . toArray ( NO_ENTRIES ) ; } } private IJavaProject javaProject ; @ Override public void initialize ( final IPath containerPath , final IJavaProject javaProject ) throws CoreException { this . javaProject = javaProject ; IClasspathContainer container = new DSLDClasspathContainer ( ) ; JavaCore . setClasspathContainer ( containerPath , new IJavaProject [ ] { javaProject } , new IClasspathContainer [ ] { container } , null ) ; } @ Override public boolean canUpdateClasspathContainer ( IPath containerPath , IJavaProject project ) { return true ; } @ Override public void requestClasspathContainerUpdate ( IPath containerPath , IJavaProject project , IClasspathContainer containerSuggestion ) throws CoreException { if ( containerSuggestion instanceof DSLDClasspathContainer ) { ( ( DSLDClasspathContainer ) containerSuggestion ) . reset ( ) ; } if ( javaProject == null ) { IClasspathContainer dsld = JavaCore . getClasspathContainer ( GroovyClasspathContainer . CONTAINER_ID , javaProject ) ; if ( dsld instanceof DSLDClasspathContainer ) { ( ( DSLDClasspathContainer ) dsld ) . reset ( ) ; } } } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . classpath ; import java . io . IOException ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . dsl . DSLPreferences ; import org . codehaus . groovy . eclipse . dsl . DSLPreferencesInitializer ; import org . codehaus . groovy . eclipse . dsl . GroovyDSLCoreActivator ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . resources . IResourceChangeEvent ; import org . eclipse . core . resources . IResourceChangeListener ; import org . eclipse . core . resources . IResourceDelta ; import org . eclipse . core . resources . IResourceRuleFactory ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . runtime . IStatus ; import org . eclipse . core . runtime . Status ; import org . eclipse . core . runtime . jobs . ISchedulingRule ; import org . eclipse . core . runtime . jobs . Job ; import org . eclipse . core . runtime . jobs . MultiRule ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . internal . core . JavaModelManager ; import org . eclipse . jdt . internal . core . SetClasspathOperation ; import org . eclipse . jface . preference . IPersistentPreferenceStore ; import org . eclipse . jface . preference . IPreferenceStore ; public class AutoAddContainerSupport implements IResourceChangeListener { private final class AddDSLSupportJob extends Job { private final String projectName ; private final IJavaProject project ; private AddDSLSupportJob ( String name , String projectName , IJavaProject project ) { super ( name ) ; this . projectName = projectName ; this . project = project ; } @ Override public IStatus run ( IProgressMonitor monitor ) { try { GroovyRuntime . addLibraryToClasspath ( project , GroovyDSLCoreActivator . CLASSPATH_CONTAINER_ID , false ) ; alreadyAddedProjects . add ( projectName ) ; return Status . OK_STATUS ; } catch ( JavaModelException e ) { GroovyDSLCoreActivator . logException ( "<STR_LIT>" + projectName , e ) ; return e . getStatus ( ) ; } } } private final IPreferenceStore store = GroovyDSLCoreActivator . getDefault ( ) . getPreferenceStore ( ) ; private final Set < String > alreadyAddedProjects ; public AutoAddContainerSupport ( ) { alreadyAddedProjects = new HashSet < String > ( ) ; String toIgnore = store . getString ( DSLPreferencesInitializer . PROJECTS_TO_IGNORE ) ; if ( toIgnore != null ) { String [ ] split = toIgnore . split ( "<STR_LIT:U+002C>" ) ; for ( String projName : split ) { projName = projName . trim ( ) ; if ( projName . length ( ) > <NUM_LIT:0> && ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getProject ( projName ) . exists ( ) ) { alreadyAddedProjects . add ( projName ) ; } } } } private boolean shouldAddSupport ( ) { return store . getBoolean ( DSLPreferences . AUTO_ADD_DSL_SUPPORT ) || store . getBoolean ( DSLPreferences . DISABLED_SCRIPTS ) ; } private void addContainer ( final IJavaProject project ) { final String projectName = project . getElementName ( ) ; AddDSLSupportJob runnable = new AddDSLSupportJob ( "<STR_LIT>" , projectName , project ) ; runnable . setPriority ( Job . BUILD ) ; runnable . setSystem ( true ) ; runnable . setRule ( getSetClassPathSchedulingRule ( project ) ) ; runnable . schedule ( ) ; } private ISchedulingRule getSetClassPathSchedulingRule ( IJavaProject project ) { IResourceRuleFactory ruleFactory = ResourcesPlugin . getWorkspace ( ) . getRuleFactory ( ) ; return new MultiRule ( new ISchedulingRule [ ] { ruleFactory . modifyRule ( project . getProject ( ) ) , ruleFactory . modifyRule ( JavaModelManager . getExternalManager ( ) . getExternalFoldersProject ( ) ) , } ) ; } public void addContainerToAll ( ) { if ( ! shouldAddSupport ( ) ) { return ; } IProject [ ] allProjects = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getProjects ( ) ; for ( IProject project : allProjects ) { if ( ! alreadyAddedProjects . contains ( project . getName ( ) ) && GroovyNature . hasGroovyNature ( project ) ) { addContainer ( JavaCore . create ( project ) ) ; } } } public void resourceChanged ( IResourceChangeEvent event ) { if ( ! shouldAddSupport ( ) ) { return ; } IResourceDelta delta = event . getDelta ( ) ; if ( delta != null ) { List < IProject > projects = new ArrayList < IProject > ( ) ; if ( delta . getAffectedChildren ( ) . length > <NUM_LIT:0> ) { IResourceDelta [ ] children = delta . getAffectedChildren ( ) ; for ( IResourceDelta child : children ) { if ( child . getResource ( ) instanceof IProject ) { if ( child . getAffectedChildren ( ) . length == <NUM_LIT:0> ) { projects . add ( ( IProject ) child . getResource ( ) ) ; } else { for ( IResourceDelta childDelta : child . getAffectedChildren ( ) ) { IResource r = childDelta . getResource ( ) ; if ( r instanceof IFile && r . getName ( ) . equals ( "<STR_LIT>" ) ) { projects . add ( ( IProject ) child . getResource ( ) ) ; } } } } } } for ( IProject project : projects ) { if ( ! alreadyAddedProjects . contains ( project . getName ( ) ) && GroovyNature . hasGroovyNature ( project ) ) { addContainer ( JavaCore . create ( project ) ) ; } } } } public void dispose ( ) { StringBuilder sb = new StringBuilder ( ) ; for ( String projName : alreadyAddedProjects ) { sb . append ( projName ) ; sb . append ( "<STR_LIT:U+002C>" ) ; } if ( sb . length ( ) > <NUM_LIT:0> ) { sb . replace ( sb . length ( ) - <NUM_LIT:1> , sb . length ( ) , "<STR_LIT>" ) ; } store . setValue ( DSLPreferencesInitializer . PROJECTS_TO_IGNORE , sb . toString ( ) ) ; if ( store instanceof IPersistentPreferenceStore ) { try { ( ( IPersistentPreferenceStore ) store ) . save ( ) ; } catch ( IOException e ) { GroovyDSLCoreActivator . logException ( e ) ; } } } public void ignoreProject ( IProject project ) { alreadyAddedProjects . add ( project . getName ( ) ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; import java . util . ArrayList ; import java . util . List ; public class GroovySuggestionDeclaringType implements IBaseGroovySuggestion { private List < IGroovySuggestion > suggestions ; private String name ; public GroovySuggestionDeclaringType ( String name ) { this . suggestions = new ArrayList < IGroovySuggestion > ( ) ; this . name = name ; } public String getName ( ) { return name ; } public IGroovySuggestion createSuggestion ( SuggestionDescriptor descriptor ) { IGroovySuggestion suggestion = new SuggestionFactory ( descriptor ) . createSuggestion ( this ) ; if ( containsSuggestion ( suggestion ) ) { return null ; } suggestions . add ( suggestion ) ; return suggestion ; } protected boolean containsSuggestion ( IGroovySuggestion suggestion ) { boolean isContained = false ; if ( suggestion instanceof GroovyPropertySuggestion ) { String name = suggestion . getName ( ) ; for ( IGroovySuggestion existingSugg : suggestions ) { if ( existingSugg instanceof GroovyPropertySuggestion && existingSugg . getName ( ) . equals ( name ) ) { isContained = true ; break ; } } } else if ( suggestion instanceof GroovyMethodSuggestion ) { String name = suggestion . getName ( ) ; GroovyMethodSuggestion methodSuggestion = ( GroovyMethodSuggestion ) suggestion ; for ( IGroovySuggestion existingSugg : suggestions ) { if ( existingSugg instanceof GroovyMethodSuggestion && existingSugg . getName ( ) . equals ( name ) ) { GroovyMethodSuggestion existingMethodSuggestion = ( GroovyMethodSuggestion ) existingSugg ; List < MethodParameter > existingParameters = existingMethodSuggestion . getParameters ( ) ; List < MethodParameter > parameters = methodSuggestion . getParameters ( ) ; if ( existingParameters != null ) { if ( parameters != null && parameters . size ( ) == existingParameters . size ( ) ) { boolean same = true ; for ( int i = <NUM_LIT:0> ; i < parameters . size ( ) ; i ++ ) { String existingType = existingParameters . get ( i ) . getType ( ) ; String type = parameters . get ( i ) . getType ( ) ; if ( type != null ) { if ( ! type . equals ( existingType ) ) { same = false ; break ; } } else if ( existingType != null ) { same = false ; break ; } } if ( same ) { isContained = true ; break ; } } } else if ( parameters == null ) { isContained = true ; break ; } } } } return isContained ; } public IGroovySuggestion replaceSuggestion ( SuggestionDescriptor descriptor , IGroovySuggestion suggestion ) { if ( suggestions . contains ( suggestion ) ) { removeSuggestion ( suggestion ) ; IGroovySuggestion nwSuggestion = createSuggestion ( descriptor ) ; return nwSuggestion ; } return null ; } public boolean removeSuggestion ( IGroovySuggestion suggestion ) { return suggestions . remove ( suggestion ) ; } public List < IGroovySuggestion > getSuggestions ( ) { return suggestions ; } public boolean hasSuggestions ( ) { return ! suggestions . isEmpty ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; import org . eclipse . core . runtime . IStatus ; import org . eclipse . jdt . core . JavaConventions ; import org . eclipse . jdt . core . JavaCore ; public class JavaValidIdentifierRule implements IValueCheckingRule { protected static final String INVALID_JAVA_IDENTIFIER = "<STR_LIT>" ; public ValueStatus checkValidity ( Object value ) { if ( value instanceof String ) { String text = ( String ) value ; IStatus status = checkJavaType ( text ) ; if ( status . getSeverity ( ) == IStatus . ERROR ) { return ValueStatus . getErrorStatus ( value , status . getMessage ( ) ) ; } else { return ValueStatus . getValidStatus ( value ) ; } } return ValueStatus . getErrorStatus ( value ) ; } protected IStatus checkJavaType ( String value ) { return JavaConventions . validateIdentifier ( value , JavaCore . VERSION_1_3 , JavaCore . VERSION_1_3 ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; import groovy . lang . Closure ; import java . util . Collection ; import java . util . Collections ; import java . util . List ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . InferencingSuggestionsManager . ProjectSuggestions ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IStorage ; public class SuggestionsPointCut implements IPointcut { private IFile xdslFile ; private IProject project ; public SuggestionsPointCut ( IFile xdslFile ) { this . xdslFile = xdslFile ; this . project = xdslFile . getProject ( ) ; } public Collection < ? > matches ( GroovyDSLDContext pattern , Object toMatch ) { ProjectSuggestions suggestions = InferencingSuggestionsManager . getInstance ( ) . getSuggestions ( project ) ; if ( suggestions != null && ! suggestions . getDeclaringTypes ( ) . isEmpty ( ) ) { List < GroovySuggestionDeclaringType > superTypes = new DeclaringTypeSuperTypeMatcher ( project ) . getAllSuperTypes ( pattern ) ; if ( superTypes != null && ! superTypes . isEmpty ( ) ) { return Collections . singletonList ( toMatch ) ; } } return null ; } public IStorage getContainerIdentifier ( ) { return xdslFile ; } public IPointcut normalize ( ) { return this ; } public void addArgument ( String name , Object argument ) { } public void addArgument ( Object argument ) { } public void verify ( ) throws PointcutVerificationException { } public Object getFirstArgument ( ) { return null ; } public String getFirstArgumentName ( ) { return null ; } public Object [ ] getArgumentValues ( ) { return null ; } public String [ ] getArgumentNames ( ) { return null ; } public void setProject ( IProject project ) { this . project = project ; } public void accept ( Closure contributionGroupClosure ) { } public boolean fastMatch ( GroovyDSLDContext pattern ) { return true ; } public String getPointcutName ( ) { return null ; } public String getPointcutDebugName ( ) { return null ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; public class GroovyPropertySuggestion extends GroovySuggestion { public GroovyPropertySuggestion ( GroovySuggestionDeclaringType declaringType , String name , String type , boolean isStatic , String javaDoc , boolean isActive ) { super ( declaringType , name , type , isStatic , javaDoc , isActive ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . InferencingSuggestionsManager . ProjectSuggestions ; import org . eclipse . core . resources . IProject ; public class AddSuggestionsOperation extends AbstractCreateOperation { public AddSuggestionsOperation ( IProject project , IBaseGroovySuggestion suggestionContext ) { super ( project , suggestionContext ) ; } protected ValueStatus run ( SuggestionDescriptor descriptor ) { ProjectSuggestions suggestions = InferencingSuggestionsManager . getInstance ( ) . getSuggestions ( getProject ( ) ) ; if ( suggestions != null ) { IGroovySuggestion suggestion = suggestions . addSuggestion ( descriptor ) ; return ValueStatus . getValidStatus ( suggestion ) ; } return ValueStatus . getErrorStatus ( descriptor , "<STR_LIT>" ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; import java . util . List ; public class SuggestionDescriptor { private boolean isStatic ; private boolean isMethod = false ; private String name ; private String javaDoc ; private boolean isActive ; private String suggestionType ; private String declaringTypeName ; private boolean useArgumentNames ; private List < MethodParameter > parameters ; protected SuggestionDescriptor ( String declaringTypeName , boolean isStatic , boolean isMethod , String name , String javaDoc , String suggestionType , boolean useArgumentNames , List < MethodParameter > parameters , boolean isActive ) { this . isStatic = isStatic ; this . isMethod = isMethod ; this . name = name ; this . javaDoc = javaDoc ; this . suggestionType = suggestionType ; this . isActive = isActive ; this . declaringTypeName = declaringTypeName ; this . useArgumentNames = useArgumentNames ; this . parameters = parameters ; } public SuggestionDescriptor ( String declaringTypeName , boolean isStatic , String name , String javaDoc , String suggestionType , boolean useArgumentNames , List < MethodParameter > parameters , boolean isActive ) { this ( declaringTypeName , isStatic , true , name , javaDoc , suggestionType , useArgumentNames , parameters , isActive ) ; } public SuggestionDescriptor ( String declaringTypeName , boolean isStatic , String name , String javaDoc , String suggestionType , boolean isActive ) { this ( declaringTypeName , isStatic , false , name , javaDoc , suggestionType , false , null , isActive ) ; } public SuggestionDescriptor ( IGroovySuggestion suggestion ) { this ( suggestion , suggestion . isActive ( ) ) ; } public SuggestionDescriptor ( IGroovySuggestion suggestion , boolean isActive ) { this . isStatic = suggestion . isStatic ( ) ; this . isActive = isActive ; this . name = suggestion . getName ( ) ; this . javaDoc = suggestion . getJavaDoc ( ) ; this . suggestionType = suggestion . getType ( ) ; this . declaringTypeName = suggestion . getDeclaringType ( ) . getName ( ) ; if ( suggestion instanceof GroovyMethodSuggestion ) { GroovyMethodSuggestion methodSuggestion = ( GroovyMethodSuggestion ) suggestion ; this . useArgumentNames = methodSuggestion . useNamedArguments ( ) ; this . parameters = methodSuggestion . getParameters ( ) ; this . isMethod = true ; } } public boolean isStatic ( ) { return isStatic ; } public boolean isActive ( ) { return isActive ; } public boolean isMethod ( ) { return isMethod ; } public String getName ( ) { return name ; } public String getDeclaringTypeName ( ) { return declaringTypeName ; } public String getJavaDoc ( ) { return javaDoc ; } public String getSuggestionType ( ) { return suggestionType ; } public boolean isUseArgumentNames ( ) { return useArgumentNames ; } public List < MethodParameter > getParameters ( ) { return parameters ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . InferencingSuggestionsManager . ProjectSuggestions ; import org . eclipse . core . resources . IProject ; public class EditSuggestionOperation extends AbstractCreateOperation { public EditSuggestionOperation ( IProject project , IBaseGroovySuggestion suggestionContext ) { super ( project , suggestionContext ) ; } protected ValueStatus run ( SuggestionDescriptor descriptor ) { IBaseGroovySuggestion baseSuggestion = getContext ( ) ; IGroovySuggestion editedSuggestion = null ; if ( baseSuggestion instanceof IGroovySuggestion ) { IGroovySuggestion existingSuggestion = ( IGroovySuggestion ) baseSuggestion ; GroovySuggestionDeclaringType declaringType = existingSuggestion . getDeclaringType ( ) ; if ( ! declaringType . getName ( ) . equals ( descriptor . getDeclaringTypeName ( ) ) ) { declaringType . removeSuggestion ( existingSuggestion ) ; ProjectSuggestions projectSuggestions = InferencingSuggestionsManager . getInstance ( ) . getSuggestions ( getProject ( ) ) ; if ( projectSuggestions != null ) { if ( declaringType . getSuggestions ( ) . isEmpty ( ) ) { projectSuggestions . removeDeclaringType ( declaringType ) ; } editedSuggestion = projectSuggestions . addSuggestion ( descriptor ) ; } } else { editedSuggestion = declaringType . replaceSuggestion ( descriptor , existingSuggestion ) ; } } return ValueStatus . getValidStatus ( editedSuggestion ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; public interface IValueCheckingRule { public ValueStatus checkValidity ( Object value ) ; } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; public class SuggestionFactory { private SuggestionDescriptor descriptor ; public SuggestionFactory ( SuggestionDescriptor descriptor ) { this . descriptor = descriptor ; } public IGroovySuggestion createSuggestion ( GroovySuggestionDeclaringType declaringType ) { IGroovySuggestion suggestion = null ; if ( declaringType != null ) { suggestion = descriptor . isMethod ( ) ? new GroovyMethodSuggestion ( declaringType , descriptor . getParameters ( ) , descriptor . isUseArgumentNames ( ) , descriptor . getName ( ) , descriptor . getSuggestionType ( ) , descriptor . isStatic ( ) , descriptor . getJavaDoc ( ) , descriptor . isActive ( ) ) : new GroovyPropertySuggestion ( declaringType , descriptor . getName ( ) , descriptor . getSuggestionType ( ) , descriptor . isStatic ( ) , descriptor . getJavaDoc ( ) , descriptor . isActive ( ) ) ; } return suggestion ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; import java . util . ArrayList ; import java . util . List ; import org . codehaus . groovy . eclipse . dsl . contributions . ContributionGroup ; import org . codehaus . groovy . eclipse . dsl . contributions . IContributionElement ; import org . codehaus . groovy . eclipse . dsl . contributions . MethodContributionElement ; import org . codehaus . groovy . eclipse . dsl . contributions . ParameterContribution ; import org . codehaus . groovy . eclipse . dsl . contributions . PropertyContributionElement ; import org . codehaus . groovy . eclipse . dsl . pointcuts . BindingSet ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . eclipse . core . resources . IFile ; public class SuggestionsContributionGroup extends ContributionGroup { private IFile file ; public SuggestionsContributionGroup ( IFile file ) { this . file = file ; } public List < IContributionElement > getContributions ( GroovyDSLDContext pattern , BindingSet matches ) { List < IContributionElement > currentContributions = new ArrayList < IContributionElement > ( ) ; List < GroovySuggestionDeclaringType > superTypes = new DeclaringTypeSuperTypeMatcher ( file . getProject ( ) ) . getAllSuperTypes ( pattern ) ; if ( superTypes != null ) { for ( GroovySuggestionDeclaringType declaringType : superTypes ) { List < IGroovySuggestion > suggestions = declaringType . getSuggestions ( ) ; if ( suggestions != null ) { for ( IGroovySuggestion suggestion : suggestions ) { if ( suggestion . isActive ( ) ) { if ( suggestion instanceof GroovyPropertySuggestion ) { GroovyPropertySuggestion prop = ( GroovyPropertySuggestion ) suggestion ; currentContributions . add ( new PropertyContributionElement ( prop . getName ( ) , prop . getType ( ) , prop . getDeclaringType ( ) . getName ( ) , prop . isStatic ( ) , DEFAULT_PROVIDER , prop . getJavaDoc ( ) , false , DEFAULT_RELEVANCE_MULTIPLIER ) ) ; } else if ( suggestion instanceof GroovyMethodSuggestion ) { GroovyMethodSuggestion method = ( GroovyMethodSuggestion ) suggestion ; ParameterContribution [ ] paramContribution = null ; List < MethodParameter > parameters = method . getParameters ( ) ; if ( parameters != null ) { paramContribution = new ParameterContribution [ method . getParameters ( ) . size ( ) ] ; int i = <NUM_LIT:0> ; for ( MethodParameter parameter : parameters ) { if ( i < paramContribution . length ) { paramContribution [ i ++ ] = new ParameterContribution ( parameter . getName ( ) , parameter . getType ( ) ) ; } } } currentContributions . add ( new MethodContributionElement ( method . getName ( ) , paramContribution , method . getType ( ) , method . getDeclaringType ( ) . getName ( ) , method . isStatic ( ) , DEFAULT_PROVIDER , method . getJavaDoc ( ) , method . useNamedArguments ( ) , false , DEFAULT_RELEVANCE_MULTIPLIER ) ) ; } } } } } return currentContributions ; } return null ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; import org . codehaus . groovy . eclipse . dsl . DSLDStore ; import org . codehaus . groovy . eclipse . dsl . GroovyDSLCoreActivator ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . writer . SuggestionsReader ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . IPath ; public class SuggestionsLoader { private IFile file ; public SuggestionsLoader ( IFile file ) { this . file = file ; } public boolean loadExistingSuggestions ( ) { if ( file != null && file . isAccessible ( ) ) { IProject project = file . getProject ( ) ; if ( InferencingSuggestionsManager . getInstance ( ) . isValidProject ( project ) ) { IPath path = file . getLocation ( ) ; String absoluteFileName = path != null ? path . toString ( ) : null ; SuggestionsReader reader = new SuggestionsReader ( file . getProject ( ) , absoluteFileName ) ; reader . read ( ) ; addSuggestionsContributionGroup ( ) ; return true ; } } return false ; } public void addSuggestionsContributionGroup ( ) { DSLDStore store = GroovyDSLCoreActivator . getDefault ( ) . getContextStoreManager ( ) . getDSLDStore ( file . getProject ( ) ) ; store . purgeIdentifier ( file ) ; store . addContributionGroup ( new SuggestionsPointCut ( file ) , new SuggestionsContributionGroup ( file ) ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; import java . util . List ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . internal . core . DefaultWorkingCopyOwner ; import org . eclipse . jdt . internal . core . JavaProject ; import org . eclipse . jdt . internal . core . NameLookup ; public abstract class AbstractJavaTypeVerifiedRule implements IValueCheckingRule { public static final String THE_SPECIFIED_JAVA_TYPES_DO_NOT_EXIST = "<STR_LIT>" ; public static final String INVALID_JAVA = "<STR_LIT>" ; private IJavaProject project ; private NameLookup nameLookup ; public AbstractJavaTypeVerifiedRule ( IJavaProject project ) { this . project = project ; } protected IJavaProject getJavaProject ( ) { return project ; } protected NameLookup getNameLookup ( ) throws JavaModelException { if ( nameLookup == null ) { if ( project instanceof JavaProject ) { nameLookup = ( ( JavaProject ) project ) . newNameLookup ( DefaultWorkingCopyOwner . PRIMARY ) ; } } return nameLookup ; } protected IType getActualType ( String name ) throws JavaModelException { NameLookup nameLkUp = getNameLookup ( ) ; if ( nameLkUp != null ) { return nameLkUp . findType ( name , false , NameLookup . ACCEPT_ALL ) ; } return null ; } protected String composeErrorMessage ( List < String > allNonExistantTypes ) { StringBuffer buffer = new StringBuffer ( ) ; buffer . append ( THE_SPECIFIED_JAVA_TYPES_DO_NOT_EXIST ) ; int size = allNonExistantTypes . size ( ) ; for ( String name : allNonExistantTypes ) { buffer . append ( name ) ; if ( -- size > <NUM_LIT:0> ) { buffer . append ( "<STR_LIT:U+002CU+0020>" ) ; } } return buffer . toString ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; import org . eclipse . core . resources . IProject ; public abstract class AbstractSuggestionOperation implements ISuggestionsOperation { private IProject project ; private IBaseGroovySuggestion suggestionContext ; public AbstractSuggestionOperation ( IProject project , IBaseGroovySuggestion suggestionContext ) { this . project = project ; this . suggestionContext = suggestionContext ; } public IProject getProject ( ) { return project ; } public IBaseGroovySuggestion getContext ( ) { return suggestionContext ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; import java . util . List ; public class DuplicateParameterRule implements IValueCheckingRule { private List < MethodParameter > existingParameters ; static final String ERROR = "<STR_LIT>" ; public DuplicateParameterRule ( List < MethodParameter > existingParameters ) { this . existingParameters = existingParameters ; } public ValueStatus checkValidity ( Object value ) { if ( ! ( value instanceof String ) || existingParameters == null ) { return ValueStatus . getErrorStatus ( value ) ; } String paramName = ( String ) value ; ValueStatus status = ValueStatus . getValidStatus ( value ) ; for ( MethodParameter existingParamter : existingParameters ) { if ( existingParamter . getName ( ) . equals ( paramName ) ) { status = ValueStatus . getErrorStatus ( value , ERROR ) ; break ; } } return status ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; import java . util . List ; import org . eclipse . core . resources . IProject ; import org . eclipse . swt . widgets . Shell ; public class OperationManager { public IGroovySuggestion addGroovySuggestion ( IProject project , IBaseGroovySuggestion context , Shell shell ) { return performGroovyOperation ( new AddSuggestionsOperation ( project , context ) , shell ) ; } public IGroovySuggestion addGroovySuggestion ( IProject project , SuggestionDescriptor descriptor , Shell shell ) { AddSuggestionsOperation operation = new AddSuggestionsOperation ( project , null ) ; operation . setSuggestionDescriptor ( descriptor ) ; return performGroovyOperation ( operation , shell ) ; } public IGroovySuggestion editGroovySuggestion ( IProject project , IBaseGroovySuggestion context , Shell shell ) { return performGroovyOperation ( new EditSuggestionOperation ( project , context ) , shell ) ; } protected IGroovySuggestion performGroovyOperation ( AbstractCreateOperation operation , Shell shell ) { SuggestionsUIOperation uiOperation = new SuggestionsUIOperation ( operation , shell ) ; ValueStatus status = uiOperation . run ( ) ; if ( ! status . isError ( ) ) { Object valObj = status . getValue ( ) ; if ( valObj instanceof IGroovySuggestion ) { return ( IGroovySuggestion ) valObj ; } } return null ; } public void removeGroovySuggestion ( IProject project , List < IBaseGroovySuggestion > selection ) { new RemoveSuggestionOperation ( project , selection ) . run ( ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . ASTNodeFinder ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . Region ; import org . codehaus . groovy . eclipse . dsl . GroovyDSLCoreActivator ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . resources . IProject ; import org . eclipse . jdt . groovy . search . TypeInferencingVisitorFactory ; import org . eclipse . jdt . groovy . search . TypeInferencingVisitorWithRequestor ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; public class SuggestionCompilationUnitHelper { private int length ; private int offset ; private GroovyCompilationUnit unit ; private IProject project ; public SuggestionCompilationUnitHelper ( int length , int offset , GroovyCompilationUnit unit , IProject project ) { this . length = length ; this . offset = offset ; this . unit = unit ; this . project = project ; } public IGroovySuggestion addSuggestion ( ) { IGroovySuggestion suggestion = null ; ASTNode node = findValidASTNode ( ) ; if ( node != null ) { SuggestionsRequestor requestor = new SuggestionsRequestor ( node ) ; TypeInferencingVisitorWithRequestor visitor = new TypeInferencingVisitorFactory ( ) . createVisitor ( unit ) ; visitor . visitCompilationUnit ( requestor ) ; SuggestionDescriptor descriptor = requestor . getSuggestionDescriptor ( ) ; suggestion = createSuggestion ( descriptor ) ; } return suggestion ; } public boolean canAddSuggestion ( ) { return findValidASTNode ( ) != null ; } protected ASTNode findValidASTNode ( ) { if ( unit == null ) { return null ; } Region region = new Region ( offset , length ) ; ASTNodeFinder finder = new ASTNodeFinder ( region ) ; ASTNode node = finder . doVisit ( unit . getModuleNode ( ) ) ; return SuggestionsRequestor . isValidNode ( node ) ? node : null ; } protected IGroovySuggestion createSuggestion ( SuggestionDescriptor descriptor ) { if ( descriptor == null ) { return null ; } Shell shell = getShell ( ) ; IGroovySuggestion suggestion = null ; if ( shell != null ) { suggestion = new OperationManager ( ) . addGroovySuggestion ( project , descriptor , shell ) ; InferencingSuggestionsManager . getInstance ( ) . commitChanges ( project ) ; } else { GroovyDSLCoreActivator . logException ( "<STR_LIT>" , new Exception ( ) ) ; } return suggestion ; } protected Shell getShell ( ) { Display display = Display . getCurrent ( ) ; if ( display == null ) { display = Display . getDefault ( ) ; } if ( display == null ) { return null ; } Shell shell = display . getActiveShell ( ) ; if ( shell == null || shell . isDisposed ( ) ) { for ( Shell shll : display . getShells ( ) ) { if ( shll != null && ! shll . isDisposed ( ) ) { shell = shll ; break ; } } } return shell ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; public class MethodParameter { private String name ; private String type ; public MethodParameter ( String name , String type ) { this . name = name ; this . type = type ; } public String getName ( ) { return name ; } public String getType ( ) { return type ; } public int hashCode ( ) { final int prime = <NUM_LIT:31> ; int result = <NUM_LIT:1> ; result = prime * result + ( ( name == null ) ? <NUM_LIT:0> : name . hashCode ( ) ) ; result = prime * result + ( ( type == null ) ? <NUM_LIT:0> : type . hashCode ( ) ) ; return result ; } public boolean equals ( Object obj ) { if ( this == obj ) return true ; if ( obj == null ) return false ; if ( getClass ( ) != obj . getClass ( ) ) return false ; MethodParameter other = ( MethodParameter ) obj ; if ( name == null ) { if ( other . name != null ) return false ; } else if ( ! name . equals ( other . name ) ) return false ; if ( type == null ) { if ( other . type != null ) return false ; } else if ( ! type . equals ( other . type ) ) return false ; return true ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; import java . util . ArrayList ; import java . util . List ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . InferencingSuggestionsManager . ProjectSuggestions ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . eclipse . core . resources . IProject ; public class DeclaringTypeSuperTypeMatcher { private IProject project ; public DeclaringTypeSuperTypeMatcher ( IProject project ) { this . project = project ; } public List < GroovySuggestionDeclaringType > getAllSuperTypes ( GroovyDSLDContext context ) { ProjectSuggestions suggestions = InferencingSuggestionsManager . getInstance ( ) . getSuggestions ( project ) ; List < GroovySuggestionDeclaringType > superTypes = new ArrayList < GroovySuggestionDeclaringType > ( ) ; if ( suggestions != null ) { for ( GroovySuggestionDeclaringType declaringType : suggestions . getDeclaringTypes ( ) ) { if ( context . matchesType ( declaringType . getName ( ) ) ) { superTypes . add ( declaringType ) ; } } } return superTypes ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; import java . io . ByteArrayInputStream ; import java . util . Collection ; import java . util . HashMap ; import java . util . Map ; import org . codehaus . groovy . eclipse . dsl . GroovyDSLCoreActivator ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . writer . SuggestionsFile ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . writer . SuggestionsTransform ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . NullProgressMonitor ; public class InferencingSuggestionsManager { private Map < IProject , ProjectSuggestions > perProjectSuggestions ; private static InferencingSuggestionsManager manager ; private IProject lastModifiedProject ; private InferencingSuggestionsManager ( ) { } public static InferencingSuggestionsManager getInstance ( ) { if ( manager == null ) { manager = new InferencingSuggestionsManager ( ) ; } return manager ; } public boolean commitChanges ( IProject project ) { if ( ! isValidProject ( project ) ) { return false ; } lastModifiedProject = project ; ProjectSuggestions suggestions = getSuggestions ( project ) ; SuggestionsTransform transform = new SuggestionsTransform ( suggestions ) ; String result = transform . transform ( ) ; if ( result != null ) { SuggestionsFile suggestionsFile = new SuggestionsFile ( project ) ; IFile file = suggestionsFile . createFile ( ) ; writeToFile ( file , result ) ; return true ; } return false ; } public boolean restoreSuggestions ( IProject project ) { if ( isValidProject ( project ) ) { SuggestionsFile suggestionFile = new SuggestionsFile ( project ) ; IFile file = suggestionFile . getFile ( ) ; if ( file != null && file . exists ( ) ) { return new SuggestionsLoader ( file ) . loadExistingSuggestions ( ) ; } } ProjectSuggestions suggestions = getSuggestions ( project ) ; if ( suggestions != null ) { suggestions . removeAll ( ) ; return true ; } return false ; } public boolean isValidProject ( IProject project ) { return project != null && project . isAccessible ( ) && GroovyNature . hasGroovyNature ( project ) ; } public IProject getlastModifiedProject ( ) { if ( isValidProject ( lastModifiedProject ) ) { return lastModifiedProject ; } return lastModifiedProject = null ; } protected void writeToFile ( IFile file , String value ) { if ( file != null ) { try { file . setContents ( new ByteArrayInputStream ( value . getBytes ( ) ) , true , true , new NullProgressMonitor ( ) ) ; } catch ( CoreException e ) { GroovyDSLCoreActivator . logException ( e ) ; } } } public ProjectSuggestions getSuggestions ( IProject project ) { if ( ! isValidProject ( project ) ) { return null ; } if ( perProjectSuggestions == null ) { perProjectSuggestions = new HashMap < IProject , ProjectSuggestions > ( ) ; } ProjectSuggestions projectSuggestions = perProjectSuggestions . get ( project ) ; if ( projectSuggestions == null ) { projectSuggestions = new ProjectSuggestions ( project ) ; perProjectSuggestions . put ( project , projectSuggestions ) ; } return projectSuggestions ; } public class ProjectSuggestions { private Map < String , GroovySuggestionDeclaringType > suggestions ; private IProject project ; protected ProjectSuggestions ( IProject project ) { suggestions = new HashMap < String , GroovySuggestionDeclaringType > ( ) ; this . project = project ; } public ProjectSuggestions registerNewProjectSuggestion ( ) { suggestions . clear ( ) ; ProjectSuggestions cleanProjectSuggestions = new ProjectSuggestions ( project ) ; perProjectSuggestions . put ( project , cleanProjectSuggestions ) ; return cleanProjectSuggestions ; } public GroovySuggestionDeclaringType getExactDeclaringType ( String declaringTypeName ) { return suggestions . get ( declaringTypeName ) ; } public IGroovySuggestion addSuggestion ( SuggestionDescriptor descriptor ) { String declaringTypeName = descriptor . getDeclaringTypeName ( ) ; GroovySuggestionDeclaringType declaringType = suggestions . get ( declaringTypeName ) ; if ( declaringType == null ) { declaringType = new GroovySuggestionDeclaringType ( declaringTypeName ) ; } IGroovySuggestion createdSuggestion = declaringType . createSuggestion ( descriptor ) ; if ( createdSuggestion != null && ! suggestions . containsKey ( declaringType . getName ( ) ) ) { suggestions . put ( declaringTypeName , declaringType ) ; } return createdSuggestion ; } public void removeDeclaringType ( GroovySuggestionDeclaringType declaringType ) { suggestions . remove ( declaringType . getName ( ) ) ; } public void removeAll ( ) { suggestions . clear ( ) ; } public Collection < GroovySuggestionDeclaringType > getDeclaringTypes ( ) { return suggestions . values ( ) ; } } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; public interface IBaseGroovySuggestion { public String getName ( ) ; } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; import java . util . List ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . InferencingSuggestionsManager . ProjectSuggestions ; import org . eclipse . core . resources . IProject ; public class RemoveSuggestionOperation extends AbstractSuggestionOperation { private List < IBaseGroovySuggestion > selections ; public RemoveSuggestionOperation ( IProject project , List < IBaseGroovySuggestion > selections ) { super ( project , null ) ; this . selections = selections ; } public ValueStatus run ( ) { ProjectSuggestions suggestions = InferencingSuggestionsManager . getInstance ( ) . getSuggestions ( getProject ( ) ) ; if ( suggestions != null ) { for ( Object obj : selections ) { if ( obj instanceof GroovySuggestionDeclaringType ) { suggestions . removeDeclaringType ( ( GroovySuggestionDeclaringType ) obj ) ; } else if ( obj instanceof IGroovySuggestion ) { IGroovySuggestion suggestion = ( IGroovySuggestion ) obj ; GroovySuggestionDeclaringType declaringType = suggestion . getDeclaringType ( ) ; declaringType . removeSuggestion ( suggestion ) ; if ( declaringType . getSuggestions ( ) . isEmpty ( ) ) { suggestions . removeDeclaringType ( declaringType ) ; } } } } return ValueStatus . getValidStatus ( null ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions ; public class GroovySuggestion implements IGroovySuggestion { protected String name ; protected String type ; protected boolean isStatic ; protected String javaDoc ; protected boolean isActive ; protected GroovySuggestionDeclaringType declaringType ; public GroovySuggestionDeclaringType getDeclaringType ( ) { return declaringType ; } public GroovySuggestion ( GroovySuggestionDeclaringType declaringType , String name , String type , boolean isStatic , String javaDoc , boolean isActive ) { this . name = name ; this . type = type ; this . isStatic = isStatic ; this . javaDoc = javaDoc ; this . isActive = isActive ; this . declaringType = declaringType ; } public boolean isActive ( ) { return isActive ; } public String getName ( ) { return name ; } public String getType ( ) { return type ; } public boolean isStatic ( ) { return isStatic ; } public String getJavaDoc ( ) { return javaDoc ; } public void changeActiveState ( boolean isActive ) { this . isActive = isActive ; } public int hashCode ( ) { final int prime = <NUM_LIT:31> ; int result = <NUM_LIT:1> ; result = prime * result + ( ( declaringType == null ) ? <NUM_LIT:0> : declaringType . hashCode ( ) ) ; result = prime * result + ( isActive ? <NUM_LIT> : <NUM_LIT> ) ; result = prime * result + ( isStatic ? <NUM_LIT> : <NUM_LIT> ) ; result = prime * result + ( ( javaDoc == null ) ? <NUM_LIT:0> : javaDoc . hashCode ( ) ) ; result = prime * result + ( ( name == null ) ? <NUM_LIT:0> : name . hashCode ( ) ) ; result = prime * result + ( ( type == null ) ? <NUM_LIT:0> : type . hashCode ( ) ) ; return result ; } public boolean equals ( Object obj ) { if ( this == obj ) return true ; if ( obj == null ) return false ; if ( getClass ( ) != obj . getClass ( ) ) return false ; GroovySuggestion other = ( GroovySuggestion ) obj ; if ( declaringType == null ) { if ( other . declaringType != null ) return false ; } else if ( ! declaringType . equals ( other . declaringType ) ) return false ; if ( isActive != other . isActive ) return false ; if ( isStatic != other . isStatic ) return false ; if ( javaDoc == null ) { if ( other . javaDoc != null ) return false ; } else if ( ! javaDoc . equals ( other . javaDoc ) ) return false ; if ( name == null ) { if ( other . name != null ) return false ; } else if ( ! name . equals ( other . name ) ) return false ; if ( type == null ) { if ( other . type != null ) return false ; } else if ( ! type . equals ( other . type ) ) return false ; return true ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . writer ; import java . util . List ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . GroovyMethodSuggestion ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . GroovySuggestionDeclaringType ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . IGroovySuggestion ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . MethodParameter ; public class TransformElementFactory { public TransformElement getSuggestionsElement ( IGroovySuggestion suggestion ) { if ( suggestion == null ) { return null ; } GroovyMethodSuggestion methodSuggestion = suggestion instanceof GroovyMethodSuggestion ? ( GroovyMethodSuggestion ) suggestion : null ; String elementName = methodSuggestion != null ? SuggestionElementStatics . METHOD : SuggestionElementStatics . PROPERTY ; TransformElement suggestionsElement = new TransformElement ( elementName , null ) ; suggestionsElement . addProperty ( SuggestionElementStatics . NAME_ATT , suggestion . getName ( ) ) ; suggestionsElement . addProperty ( SuggestionElementStatics . TYPE_ATT , suggestion . getType ( ) ) ; suggestionsElement . addProperty ( SuggestionElementStatics . IS_STATIC_ATT , suggestion . isStatic ( ) + "<STR_LIT>" ) ; suggestionsElement . addProperty ( SuggestionElementStatics . IS_ACTIVE , suggestion . isActive ( ) + "<STR_LIT>" ) ; if ( methodSuggestion != null ) { TransformElement argumentsElement = new TransformElement ( SuggestionElementStatics . PARAMETERS , null ) ; suggestionsElement . addChild ( argumentsElement ) ; argumentsElement . addProperty ( SuggestionElementStatics . USE_NAMED_ARGUMENTS_ATT , methodSuggestion . useNamedArguments ( ) + "<STR_LIT>" ) ; List < MethodParameter > parameters = methodSuggestion . getParameters ( ) ; if ( parameters != null ) { for ( MethodParameter parameter : parameters ) { TransformElement parameterElement = new TransformElement ( SuggestionElementStatics . PARAMETER , null ) ; parameterElement . addProperty ( SuggestionElementStatics . NAME_ATT , parameter . getName ( ) ) ; parameterElement . addProperty ( SuggestionElementStatics . TYPE_ATT , parameter . getType ( ) ) ; argumentsElement . addChild ( parameterElement ) ; } } } TransformElement javadocElement = new TransformElement ( SuggestionElementStatics . DOC , suggestion . getJavaDoc ( ) ) ; suggestionsElement . addChild ( javadocElement ) ; return suggestionsElement ; } public TransformElement getRootElement ( ) { return new TransformElement ( SuggestionElementStatics . ROOT , null ) ; } public TransformElement getDeclaringTypeWriterElement ( GroovySuggestionDeclaringType declaringType ) { if ( declaringType == null ) { return null ; } TransformElement declaringTypeElement = new TransformElement ( SuggestionElementStatics . DECLARING_TYPE , null ) ; TransformElementProperty property = new TransformElementProperty ( SuggestionElementStatics . TYPE_ATT , declaringType . getName ( ) ) ; declaringTypeElement . addProperty ( property ) ; List < IGroovySuggestion > suggestions = declaringType . getSuggestions ( ) ; for ( IGroovySuggestion suggestion : suggestions ) { TransformElement suggestionElement = getSuggestionsElement ( suggestion ) ; declaringTypeElement . addChild ( suggestionElement ) ; } return declaringTypeElement ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . writer ; public class SuggestionElementStatics { public static final String PROJECT = "<STR_LIT>" ; public static final String DECLARING_TYPE = "<STR_LIT>" ; public static final String ROOT = "<STR_LIT>" ; public static final String METHOD = "<STR_LIT>" ; public static final String PROPERTY = "<STR_LIT>" ; public static final String PARAMETERS = "<STR_LIT>" ; public static final String PARAMETER = "<STR_LIT>" ; public static final String DOC = "<STR_LIT>" ; public static final String NAME_ATT = "<STR_LIT:name>" ; public static final String TYPE_ATT = "<STR_LIT:type>" ; public static final String IS_STATIC_ATT = "<STR_LIT>" ; public static final String USE_NAMED_ARGUMENTS_ATT = "<STR_LIT>" ; public static final String IS_ACTIVE = "<STR_LIT>" ; } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . writer ; import java . lang . reflect . InvocationTargetException ; import org . codehaus . groovy . eclipse . dsl . GroovyDSLCoreActivator ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . InferencingSuggestionsManager ; import org . eclipse . core . commands . ExecutionException ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . jface . operation . IRunnableContext ; import org . eclipse . jface . operation . IRunnableWithProgress ; import org . eclipse . ui . IWorkbench ; import org . eclipse . ui . PlatformUI ; import org . eclipse . ui . ide . undo . CreateFileOperation ; public class SuggestionsFile { private IProject project ; private SuggestionsFileProperties location ; public SuggestionsFile ( IProject project ) { this . project = project ; location = new SuggestionsFileProperties ( ) ; } public IProject getProject ( ) { return project ; } public IFile createFile ( ) { String path = getPath ( ) ; if ( path != null ) { IFile suggestionsFile = project . getFile ( path ) ; if ( ! suggestionsFile . exists ( ) ) { suggestionsFile = createNewFile ( suggestionsFile ) ; } return suggestionsFile != null && suggestionsFile . exists ( ) ? suggestionsFile : null ; } return null ; } protected String getPath ( ) { return InferencingSuggestionsManager . getInstance ( ) . isValidProject ( project ) && location != null ? location . getWritingLocation ( ) + location . getFileName ( ) + '<CHAR_LIT:.>' + location . getFileType ( ) : null ; } public IFile getFile ( ) { String path = getPath ( ) ; if ( path != null ) { IFile suggestionsFile = project . getFile ( path ) ; return suggestionsFile != null && suggestionsFile . exists ( ) ? suggestionsFile : null ; } return null ; } protected IFile createNewFile ( IFile fileHandle ) { IWorkbench workBench = PlatformUI . getWorkbench ( ) ; if ( workBench == null || fileHandle . exists ( ) ) { return null ; } IRunnableContext runnableContext = workBench . getActiveWorkbenchWindow ( ) ; final IFile newFile = fileHandle ; IRunnableWithProgress op = new IRunnableWithProgress ( ) { public void run ( IProgressMonitor monitor ) { CreateFileOperation op = new CreateFileOperation ( newFile , null , null , "<STR_LIT>" ) ; try { op . execute ( monitor , null ) ; } catch ( final ExecutionException e ) { GroovyDSLCoreActivator . logException ( e ) ; } } } ; try { runnableContext . run ( true , true , op ) ; newFile . refreshLocal ( <NUM_LIT:0> , new NullProgressMonitor ( ) ) ; } catch ( InterruptedException e ) { GroovyDSLCoreActivator . logException ( e ) ; return null ; } catch ( InvocationTargetException e ) { GroovyDSLCoreActivator . logException ( e ) ; return null ; } catch ( CoreException e ) { GroovyDSLCoreActivator . logException ( e ) ; return null ; } return newFile ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . writer ; public class TransformElementProperty { private String name ; private String value ; public TransformElementProperty ( String name , String value ) { super ( ) ; this . name = name ; this . value = value ; } public String getName ( ) { return name ; } public String getValue ( ) { return value ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . writer ; import java . util . List ; import javax . xml . parsers . DocumentBuilder ; import javax . xml . parsers . DocumentBuilderFactory ; import javax . xml . parsers . ParserConfigurationException ; import javax . xml . transform . OutputKeys ; import javax . xml . transform . Transformer ; import javax . xml . transform . TransformerConfigurationException ; import javax . xml . transform . TransformerException ; import javax . xml . transform . TransformerFactory ; import javax . xml . transform . TransformerFactoryConfigurationError ; import javax . xml . transform . dom . DOMSource ; import javax . xml . transform . stream . StreamResult ; import org . codehaus . groovy . eclipse . dsl . GroovyDSLCoreActivator ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . GroovySuggestionDeclaringType ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . InferencingSuggestionsManager . ProjectSuggestions ; import org . codehaus . groovy . runtime . StringBufferWriter ; import org . w3c . dom . Attr ; import org . w3c . dom . Document ; import org . w3c . dom . NamedNodeMap ; import org . w3c . dom . Node ; public class SuggestionsTransform { private ProjectSuggestions suggestions ; public SuggestionsTransform ( ProjectSuggestions suggestions ) { this . suggestions = suggestions ; } public String transform ( ) { try { DocumentBuilderFactory factory = DocumentBuilderFactory . newInstance ( ) ; DocumentBuilder builder = factory . newDocumentBuilder ( ) ; Document document = builder . newDocument ( ) ; TransformElementFactory elementFactory = new TransformElementFactory ( ) ; TransformElement rootElement = elementFactory . getRootElement ( ) ; Node root = document . createElement ( rootElement . getElementName ( ) ) ; document . appendChild ( root ) ; for ( GroovySuggestionDeclaringType declaringType : suggestions . getDeclaringTypes ( ) ) { TransformElement element = elementFactory . getDeclaringTypeWriterElement ( declaringType ) ; transform ( element , root , document ) ; } Transformer transformer = TransformerFactory . newInstance ( ) . newTransformer ( ) ; transformer . setOutputProperty ( OutputKeys . METHOD , "<STR_LIT>" ) ; transformer . setOutputProperty ( OutputKeys . ENCODING , "<STR_LIT:UTF-8>" ) ; transformer . setOutputProperty ( OutputKeys . INDENT , "<STR_LIT:yes>" ) ; DOMSource source = new DOMSource ( document ) ; StringBuffer buffer = new StringBuffer ( ) ; StringBufferWriter bufferWriter = new StringBufferWriter ( buffer ) ; StreamResult result = new StreamResult ( bufferWriter ) ; transformer . transform ( source , result ) ; return buffer . toString ( ) ; } catch ( TransformerConfigurationException e ) { GroovyDSLCoreActivator . logException ( e ) ; } catch ( IllegalArgumentException e ) { GroovyDSLCoreActivator . logException ( e ) ; } catch ( ParserConfigurationException e ) { GroovyDSLCoreActivator . logException ( e ) ; } catch ( TransformerFactoryConfigurationError e ) { GroovyDSLCoreActivator . logException ( e ) ; } catch ( TransformerException e ) { GroovyDSLCoreActivator . logException ( e ) ; } return null ; } protected void transform ( TransformElement element , Node parent , Document document ) { String name = element . getElementName ( ) ; Node node = document . createElement ( name ) ; String elementValue = element . getValue ( ) ; if ( elementValue != null ) { node . setTextContent ( element . getValue ( ) ) ; } parent . appendChild ( node ) ; List < TransformElementProperty > properties = element . getProperties ( ) ; if ( properties != null ) { NamedNodeMap attributes = node . getAttributes ( ) ; for ( TransformElementProperty property : properties ) { Attr attr = document . createAttribute ( property . getName ( ) ) ; attr . setValue ( property . getValue ( ) ) ; attributes . setNamedItem ( attr ) ; } } List < TransformElement > children = element . getChildren ( ) ; if ( children != null ) { for ( TransformElement child : children ) { transform ( child , node , document ) ; } } } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . writer ; import java . io . BufferedReader ; import java . io . FileReader ; import java . io . IOException ; import java . io . Reader ; import java . util . ArrayList ; import java . util . List ; import javax . xml . parsers . DocumentBuilder ; import javax . xml . parsers . DocumentBuilderFactory ; import javax . xml . parsers . ParserConfigurationException ; import org . codehaus . groovy . eclipse . dsl . GroovyDSLCoreActivator ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . InferencingSuggestionsManager ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . InferencingSuggestionsManager . ProjectSuggestions ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . MethodParameter ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . SuggestionDescriptor ; import org . eclipse . core . resources . IProject ; import org . w3c . dom . Document ; import org . w3c . dom . Element ; import org . w3c . dom . Node ; import org . w3c . dom . NodeList ; import org . xml . sax . InputSource ; import org . xml . sax . SAXException ; public class SuggestionsReader { private String absoluteFile ; private ProjectSuggestions projectSuggestions ; public SuggestionsReader ( IProject project , String absoluteFile ) { this . projectSuggestions = InferencingSuggestionsManager . getInstance ( ) . getSuggestions ( project ) ; this . absoluteFile = absoluteFile ; } public ProjectSuggestions read ( ) { try { if ( absoluteFile == null || projectSuggestions == null ) { return null ; } DocumentBuilderFactory factory = DocumentBuilderFactory . newInstance ( ) ; DocumentBuilder parser = factory . newDocumentBuilder ( ) ; Reader reader = new BufferedReader ( new FileReader ( absoluteFile ) ) ; Document document = parser . parse ( new InputSource ( reader ) ) ; if ( document != null ) { projectSuggestions = projectSuggestions . registerNewProjectSuggestion ( ) ; NodeList list = document . getChildNodes ( ) ; if ( list . getLength ( ) > <NUM_LIT:0> ) { Node node = list . item ( <NUM_LIT:0> ) ; if ( node instanceof Element ) { Element element = ( Element ) node ; if ( element . getNodeName ( ) . equals ( SuggestionElementStatics . ROOT ) ) { NodeList declaringTypeList = element . getChildNodes ( ) ; if ( declaringTypeList != null ) { handleDeclaringTypeNodes ( declaringTypeList ) ; } } } } } return projectSuggestions ; } catch ( ParserConfigurationException e ) { GroovyDSLCoreActivator . logException ( e ) ; } catch ( IOException e ) { GroovyDSLCoreActivator . logException ( e ) ; } catch ( SAXException e ) { GroovyDSLCoreActivator . logException ( e ) ; } return null ; } protected void handleDeclaringTypeNodes ( NodeList list ) { for ( int i = <NUM_LIT:0> ; i < list . getLength ( ) ; i ++ ) { Node node = list . item ( i ) ; if ( node instanceof Element ) { Element element = ( Element ) node ; if ( element . getNodeName ( ) . equals ( SuggestionElementStatics . DECLARING_TYPE ) ) { String declaringTypeName = element . getAttribute ( SuggestionElementStatics . TYPE_ATT ) ; NodeList suggestions = element . getChildNodes ( ) ; for ( int j = <NUM_LIT:0> ; j < suggestions . getLength ( ) ; j ++ ) { Node suggNode = suggestions . item ( j ) ; if ( suggNode instanceof Element ) { SuggestionDescriptor descriptor = getSuggestionDescriptor ( ( Element ) suggNode , declaringTypeName ) ; if ( descriptor != null ) { projectSuggestions . addSuggestion ( descriptor ) ; } } } } } } } protected SuggestionDescriptor getSuggestionDescriptor ( Element element , String declaringTypeName ) { if ( element . getNodeName ( ) . equals ( SuggestionElementStatics . METHOD ) || element . getNodeName ( ) . equals ( SuggestionElementStatics . PROPERTY ) ) { String suggestionName = element . getAttribute ( SuggestionElementStatics . NAME_ATT ) ; String suggestionType = element . getAttribute ( SuggestionElementStatics . TYPE_ATT ) ; boolean isStatic = new Boolean ( element . getAttribute ( SuggestionElementStatics . IS_STATIC_ATT ) ) . booleanValue ( ) ; boolean isActive = new Boolean ( element . getAttribute ( SuggestionElementStatics . IS_ACTIVE ) ) . booleanValue ( ) ; NodeList docNodes = element . getElementsByTagName ( SuggestionElementStatics . DOC ) ; String doc = null ; if ( docNodes != null && docNodes . getLength ( ) > <NUM_LIT:0> ) { Node docNode = docNodes . item ( <NUM_LIT:0> ) ; if ( docNode instanceof Element ) { Element docElement = ( Element ) docNode ; doc = docElement . getNodeValue ( ) ; } } SuggestionDescriptor descriptor = null ; if ( element . getNodeName ( ) . equals ( SuggestionElementStatics . METHOD ) ) { Element parametersElement = getParametersElement ( element ) ; boolean useNameArguments = false ; if ( parametersElement != null ) { useNameArguments = new Boolean ( parametersElement . getAttribute ( SuggestionElementStatics . USE_NAMED_ARGUMENTS_ATT ) ) . booleanValue ( ) ; } List < MethodParameter > modelParameters = getParameters ( parametersElement ) ; descriptor = new SuggestionDescriptor ( declaringTypeName , isStatic , suggestionName , doc , suggestionType , useNameArguments , modelParameters , isActive ) ; } else { descriptor = new SuggestionDescriptor ( declaringTypeName , isStatic , suggestionName , doc , suggestionType , isActive ) ; } return descriptor ; } return null ; } protected Element getParametersElement ( Element element ) { Node node = element . getFirstChild ( ) ; if ( node . getNodeName ( ) . equals ( SuggestionElementStatics . PARAMETERS ) && node instanceof Element ) { return ( Element ) node ; } return null ; } protected List < MethodParameter > getParameters ( Element parametersElement ) { if ( parametersElement == null ) { return null ; } List < MethodParameter > parameters = new ArrayList < MethodParameter > ( ) ; NodeList parametersNodeList = parametersElement . getChildNodes ( ) ; if ( parametersNodeList != null ) { for ( int i = <NUM_LIT:0> ; i < parametersNodeList . getLength ( ) ; i ++ ) { Node paramNode = parametersNodeList . item ( i ) ; if ( paramNode instanceof Element && paramNode . getNodeName ( ) . equals ( SuggestionElementStatics . PARAMETER ) ) { Element paramElement = ( Element ) paramNode ; String nameParam = paramElement . getAttribute ( SuggestionElementStatics . NAME_ATT ) ; String typeParam = paramElement . getAttribute ( SuggestionElementStatics . TYPE_ATT ) ; parameters . add ( new MethodParameter ( nameParam , typeParam ) ) ; } } } return parameters ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . writer ; public class SuggestionsFileProperties { private static final String LOCATION = "<STR_LIT>" ; public static final String FILE_TYPE = "<STR_LIT>" ; private static final String FILE_NAME = "<STR_LIT>" ; public String getWritingLocation ( ) { return LOCATION ; } public String getFileType ( ) { return FILE_TYPE ; } public String getFileName ( ) { return FILE_NAME ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . writer ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; public class TransformElement { private String elementName ; private String value ; private List < TransformElementProperty > properties = new ArrayList < TransformElementProperty > ( ) ; private List < TransformElement > children = new ArrayList < TransformElement > ( ) ; public TransformElement ( String name , String value ) { this . elementName = name ; this . value = value ; } public String getElementName ( ) { return elementName ; } public String getValue ( ) { return value ; } public boolean addProperty ( TransformElementProperty property ) { return properties . add ( property ) ; } public boolean addProperty ( String propertyName , String propertyValue ) { TransformElementProperty property = new TransformElementProperty ( propertyName , propertyValue ) ; return addProperty ( property ) ; } public boolean addChild ( TransformElement element ) { return children . add ( element ) ; } public List < TransformElementProperty > getProperties ( ) { return Collections . unmodifiableList ( properties ) ; } public List < TransformElement > getChildren ( ) { return Collections . unmodifiableList ( children ) ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . ui ; public abstract class ControlSelectionListener implements IControlSelectionListener { public void handleInvalidSelection ( ControlSelectionEvent event ) { } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . ui ; import org . eclipse . core . resources . IProject ; import org . eclipse . swt . widgets . Control ; public interface IProjectUIControl { public IProject getProject ( ) ; public Control createControls ( ) ; public IProject setProject ( IProject project ) ; } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . ui ; import org . eclipse . core . resources . IProject ; public interface ISelectionHandler { public void selectionChanged ( IProject project ) ; } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . ui ; import java . util . HashMap ; import java . util . Map ; import org . eclipse . jface . layout . GridDataFactory ; import org . eclipse . jface . layout . GridLayoutFactory ; import org . eclipse . swt . SWT ; import org . eclipse . swt . graphics . Point ; import org . eclipse . swt . layout . GridData ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Control ; import org . eclipse . swt . widgets . Label ; public abstract class AbstractLabeledDialogueControl extends AbstractControlManager { private Point offsetLabelLocation ; private Label parameterNameLabel ; private IDialogueControlDescriptor labelDescriptor ; protected AbstractLabeledDialogueControl ( IDialogueControlDescriptor labelDescriptor , Point offsetLabelLocation ) { this . labelDescriptor = labelDescriptor ; this . offsetLabelLocation = offsetLabelLocation ; } protected IDialogueControlDescriptor getLabelDescriptor ( ) { return labelDescriptor ; } protected int numberofColumns ( ) { return <NUM_LIT:2> ; } protected Map < Control , IDialogueControlDescriptor > createManagedControls ( Composite parent ) { Map < Control , IDialogueControlDescriptor > controls = new HashMap < Control , IDialogueControlDescriptor > ( ) ; if ( labelDescriptor != null ) { Composite labelArea = new Composite ( parent , SWT . NONE ) ; GridLayoutFactory . fillDefaults ( ) . numColumns ( numberofColumns ( ) ) . margins ( <NUM_LIT:0> , <NUM_LIT:0> ) . equalWidth ( false ) . applyTo ( labelArea ) ; GridDataFactory . fillDefaults ( ) . grab ( true , false ) . applyTo ( labelArea ) ; parameterNameLabel = new Label ( labelArea , SWT . READ_ONLY ) ; parameterNameLabel . setText ( labelDescriptor . getLabel ( ) + "<STR_LIT::U+0020>" ) ; parameterNameLabel . setToolTipText ( labelDescriptor . getToolTipText ( ) ) ; GridDataFactory . fillDefaults ( ) . grab ( false , false ) . align ( SWT . FILL , SWT . CENTER ) . applyTo ( parameterNameLabel ) ; if ( offsetLabelLocation != null ) { GridData data = ( GridData ) parameterNameLabel . getLayoutData ( ) ; int heightHint = offsetLabelLocation . y ; if ( heightHint > <NUM_LIT:0> ) { data . heightHint = heightHint ; } int widthHint = offsetLabelLocation . x ; if ( widthHint > <NUM_LIT:0> ) { data . widthHint = widthHint ; } } Control labeledControl = getManagedControl ( labelArea ) ; if ( labeledControl != null ) { controls . put ( labeledControl , getLabelDescriptor ( ) ) ; } } return controls ; } abstract protected Control getManagedControl ( Composite parent ) ; public Label getLabel ( ) { return parameterNameLabel != null && ! parameterNameLabel . isDisposed ( ) ? parameterNameLabel : null ; } } </s>
<s> package org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . ui ; public class ControlSelectionEvent { private Object data ; private IDialogueControlDescriptor descriptor ; private String errorMessage ; public ControlSelectionEvent ( IDialogueControlDescriptor descriptor , String errorMessage ) { this . data = null ; this . descriptor = descriptor ; this . errorMessage = errorMessage ; } public ControlSelectionEvent ( Object data , IDialogueControlDescriptor descriptor ) { this . data = data ; this . descriptor = descriptor ; this . errorMessage = null ; } public Object getSelectionData ( ) { return data ; } public IDialogueControlDescriptor getControlDescriptor ( ) { return descriptor ; } public String getErrorMessage ( ) { return errorMessage ; } } </s>