text
stringlengths 30
1.67M
|
|---|
<s> package org . eclim . plugin . jdt ; import java . io . ByteArrayInputStream ; import java . io . File ; import java . io . FilenameFilter ; import java . io . InputStream ; import java . util . HashMap ; import java . util . Properties ; import java . util . regex . Pattern ; import org . apache . commons . lang . SystemUtils ; import org . apache . tools . ant . taskdefs . condition . Os ; import org . eclim . Services ; import org . eclim . logging . Logger ; import org . eclim . plugin . AbstractPluginResources ; import org . eclim . plugin . core . preference . PreferenceFactory ; import org . eclim . plugin . core . preference . Preferences ; import org . eclim . plugin . core . project . ProjectManagement ; import org . eclim . plugin . core . project . ProjectNatureFactory ; import org . eclim . plugin . jdt . preference . OptionHandler ; import org . eclim . plugin . jdt . project . JavaProjectManager ; import org . eclim . util . IOUtils ; import org . eclim . util . StringUtils ; import org . eclim . util . file . FileUtils ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . Path ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . launching . IVMInstall ; import org . eclipse . jdt . launching . JavaRuntime ; import org . eclipse . jdt . launching . LibraryLocation ; public class PluginResources extends AbstractPluginResources { public static final String NAME = "<STR_LIT>" ; public static final String NATURE = JavaCore . NATURE_ID ; private static final Logger logger = Logger . getLogger ( PluginResources . class ) ; private static final String VARIABLES = "<STR_LIT>" ; private static final String [ ] SRC_LOCATIONS = { "<STR_LIT>" , "<STR_LIT>" , SystemUtils . JAVA_HOME . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) + "<STR_LIT>" , SystemUtils . JAVA_HOME . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) + "<STR_LIT>" , SystemUtils . JAVA_HOME . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) + "<STR_LIT>" , SystemUtils . JAVA_HOME . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) + "<STR_LIT>" , SystemUtils . JAVA_HOME . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) + "<STR_LIT>" , } ; @ Override public void initialize ( String name ) { super . initialize ( name ) ; logger . debug ( "<STR_LIT>" ) ; initializeJreSrc ( ) ; initializeVars ( VARIABLES ) ; Preferences . addOptionHandler ( "<STR_LIT>" , new OptionHandler ( ) ) ; ProjectNatureFactory . addNature ( "<STR_LIT>" , NATURE ) ; ProjectManagement . addProjectManager ( NATURE , new JavaProjectManager ( ) ) ; PreferenceFactory . addPreferences ( NATURE , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; PreferenceFactory . addOptions ( NATURE , "<STR_LIT>" + "<STR_LIT>" ) ; } @ Override protected String getBundleBaseName ( ) { return "<STR_LIT>" ; } protected void initializeJreSrc ( ) { String jarName = Os . isFamily ( Os . FAMILY_MAC ) ? "<STR_LIT>" : "<STR_LIT>" ; try { IVMInstall vm = JavaRuntime . getDefaultVMInstall ( ) ; LibraryLocation [ ] locations = JavaRuntime . getLibraryLocations ( vm ) ; LibraryLocation [ ] newLocations = new LibraryLocation [ locations . length ] ; for ( int ii = <NUM_LIT:0> ; ii < locations . length ; ii ++ ) { IPath libraryPath = locations [ ii ] . getSystemLibraryPath ( ) ; if ( libraryPath . lastSegment ( ) . equals ( jarName ) && ( locations [ ii ] . getSystemLibrarySourcePath ( ) . isEmpty ( ) || ! locations [ ii ] . getSystemLibrarySourcePath ( ) . toFile ( ) . exists ( ) ) ) { IPath jreSrc = null ; logger . debug ( "<STR_LIT>" , SystemUtils . JAVA_HOME ) ; for ( int jj = <NUM_LIT:0> ; jj < SRC_LOCATIONS . length ; jj ++ ) { String location = SRC_LOCATIONS [ jj ] ; if ( location . startsWith ( "<STR_LIT:/>" ) || location . indexOf ( '<CHAR_LIT::>' ) != - <NUM_LIT:1> ) { jreSrc = new Path ( location ) ; } else { jreSrc = libraryPath . removeLastSegments ( <NUM_LIT:3> ) . append ( location ) ; } logger . debug ( "<STR_LIT>" , jreSrc ) ; if ( jreSrc . toFile ( ) . exists ( ) ) { break ; } } if ( ! jreSrc . toFile ( ) . exists ( ) && Os . isFamily ( Os . FAMILY_WINDOWS ) ) { String path = libraryPath . toOSString ( ) . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; String altHome = path . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; if ( ! altHome . equals ( path ) ) { jreSrc = new Path ( altHome ) . append ( "<STR_LIT>" ) ; } if ( ! jreSrc . toFile ( ) . exists ( ) ) { String base = FileUtils . getBaseName ( path ) ; final String major = base . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; if ( ! major . equals ( base ) ) { File dir = new File ( FileUtils . getFullPath ( path ) ) ; String [ ] jdks = dir . list ( new FilenameFilter ( ) { private final Pattern JDK = Pattern . compile ( "<STR_LIT>" + major + "<STR_LIT>" ) ; public boolean accept ( File dir , String name ) { return JDK . matcher ( name ) . matches ( ) ; } } ) ; for ( String jdk : jdks ) { jreSrc = new Path ( dir . toString ( ) ) . append ( jdk ) . append ( "<STR_LIT>" ) ; if ( jreSrc . toFile ( ) . exists ( ) ) { break ; } } } } } if ( jreSrc . toFile ( ) . exists ( ) ) { logger . info ( "<STR_LIT>" , JavaRuntime . JRESRC_VARIABLE , jreSrc ) ; newLocations [ ii ] = new LibraryLocation ( locations [ ii ] . getSystemLibraryPath ( ) , jreSrc , locations [ ii ] . getPackageRootPath ( ) , locations [ ii ] . getJavadocLocation ( ) ) ; } else { logger . debug ( "<STR_LIT>" + SystemUtils . JAVA_HOME ) ; newLocations [ ii ] = new LibraryLocation ( locations [ ii ] . getSystemLibraryPath ( ) , Path . EMPTY , locations [ ii ] . getPackageRootPath ( ) , locations [ ii ] . getJavadocLocation ( ) ) ; } } else { newLocations [ ii ] = locations [ ii ] ; } } vm . setLibraryLocations ( newLocations ) ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } } protected void initializeVars ( String variable ) { String file = "<STR_LIT:/>" + variable + "<STR_LIT>" ; logger . debug ( "<STR_LIT>" , file ) ; InputStream in = null ; try { in = getClass ( ) . getResourceAsStream ( file ) ; String propertiesString = IOUtils . toString ( in ) ; HashMap < Object , String > values = new HashMap < Object , String > ( ) ; for ( Object key : System . getProperties ( ) . keySet ( ) ) { values . put ( key , System . getProperty ( ( String ) key ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ) ; } propertiesString = StringUtils . replacePlaceholders ( propertiesString , values ) ; Properties properties = new Properties ( ) ; properties . load ( new ByteArrayInputStream ( propertiesString . getBytes ( ) ) ) ; for ( Object key : properties . keySet ( ) ) { String name = ( String ) key ; IPath path = new Path ( properties . getProperty ( name ) ) ; logger . debug ( "<STR_LIT>" , name , path ) ; JavaCore . setClasspathVariable ( name , path , null ) ; } } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } finally { IOUtils . closeQuietly ( in ) ; } } } </s>
|
<s> package org . eclim . plugin . jdt . util ; import java . util . Arrays ; import org . apache . commons . lang . builder . EqualsBuilder ; import org . apache . commons . lang . builder . HashCodeBuilder ; import org . eclipse . jdt . core . IType ; public class TypeInfo { private IType type ; private String [ ] typeParameters ; private String [ ] typeArguments ; public TypeInfo ( IType type , String [ ] typeParameters , String [ ] typeArguments ) { this . type = type ; this . typeParameters = typeParameters != null ? typeParameters : new String [ <NUM_LIT:0> ] ; this . typeArguments = typeArguments != null ? typeArguments : new String [ <NUM_LIT:0> ] ; } public IType getType ( ) { return this . type ; } public String [ ] getTypeParameters ( ) { return this . typeParameters ; } public String [ ] getTypeArguments ( ) { return this . typeArguments ; } public boolean equals ( Object other ) { if ( ! ( other instanceof TypeInfo ) ) { return false ; } if ( this == other ) { return true ; } TypeInfo result = ( TypeInfo ) other ; boolean equal = new EqualsBuilder ( ) . append ( getType ( ) , result . getType ( ) ) . isEquals ( ) ; return equal ; } public int hashCode ( ) { return new HashCodeBuilder ( <NUM_LIT:24> , <NUM_LIT> ) . append ( type ) . toHashCode ( ) ; } public String toString ( ) { return new StringBuffer ( ) . append ( type != null ? type . getElementName ( ) : "<STR_LIT:null>" ) . append ( "<STR_LIT::>" ) . append ( "<STR_LIT>" ) . append ( Arrays . toString ( typeParameters ) ) . append ( "<STR_LIT>" ) . append ( Arrays . toString ( typeArguments ) ) . toString ( ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . util ; import org . eclipse . jdt . core . Flags ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . Signature ; public class MethodUtils { private static final String VARARGS = "<STR_LIT:...>" ; public static boolean containsMethod ( TypeInfo typeInfo , IMethod method ) throws Exception { IType type = typeInfo . getType ( ) ; String signature = getMinimalMethodSignature ( method , typeInfo ) ; if ( method . isConstructor ( ) ) { signature = signature . replaceFirst ( method . getDeclaringType ( ) . getElementName ( ) , type . getElementName ( ) ) ; } IMethod [ ] methods = type . getMethods ( ) ; for ( int ii = <NUM_LIT:0> ; ii < methods . length ; ii ++ ) { String methodSig = getMinimalMethodSignature ( methods [ ii ] , typeInfo ) ; if ( methodSig . equals ( signature ) ) { return true ; } } return false ; } public static IMethod getMethod ( TypeInfo typeInfo , IMethod method ) throws Exception { IType type = typeInfo . getType ( ) ; String signature = getMinimalMethodSignature ( method , typeInfo ) ; if ( method . isConstructor ( ) ) { signature = signature . replaceFirst ( method . getDeclaringType ( ) . getElementName ( ) , type . getElementName ( ) ) ; } IMethod [ ] methods = type . getMethods ( ) ; for ( int ii = <NUM_LIT:0> ; ii < methods . length ; ii ++ ) { String methodSig = getMinimalMethodSignature ( methods [ ii ] , typeInfo ) ; if ( methodSig . equals ( signature ) ) { return methods [ ii ] ; } } return null ; } public static IMethod getMethodAfter ( IType type , IMethod method ) throws Exception { if ( type == null || method == null ) { return null ; } IMethod [ ] all = type . getMethods ( ) ; for ( int ii = <NUM_LIT:0> ; ii < all . length ; ii ++ ) { if ( all [ ii ] . equals ( method ) && ii < all . length - <NUM_LIT:1> ) { return all [ ii + <NUM_LIT:1> ] ; } } return null ; } public static String getMethodSignature ( IMethod method , TypeInfo typeInfo ) throws Exception { int flags = method . getFlags ( ) ; StringBuffer buffer = new StringBuffer ( ) ; if ( method . getDeclaringType ( ) . isInterface ( ) ) { buffer . append ( "<STR_LIT>" ) ; } else { buffer . append ( Flags . isPublic ( method . getFlags ( ) ) ? "<STR_LIT>" : "<STR_LIT>" ) ; } buffer . append ( Flags . isAbstract ( flags ) ? "<STR_LIT>" : "<STR_LIT>" ) ; if ( ! method . isConstructor ( ) ) { String name = Signature . getSignatureSimpleName ( method . getReturnType ( ) ) ; buffer . append ( TypeUtils . replaceTypeParams ( name , typeInfo ) ) . append ( '<CHAR_LIT:U+0020>' ) ; } buffer . append ( method . getElementName ( ) ) . append ( "<STR_LIT:(>" ) . append ( getMethodParameters ( method , typeInfo , true ) ) . append ( '<CHAR_LIT:)>' ) ; String [ ] exceptions = method . getExceptionTypes ( ) ; if ( exceptions . length > <NUM_LIT:0> ) { buffer . append ( "<STR_LIT>" ) . append ( getMethodThrows ( method ) ) ; } return buffer . toString ( ) ; } public static String getMinimalMethodSignature ( IMethod method , TypeInfo typeInfo ) throws Exception { StringBuffer buffer = new StringBuffer ( ) ; buffer . append ( method . getElementName ( ) ) . append ( '<CHAR_LIT:(>' ) . append ( getMethodParameters ( method , typeInfo , false ) ) . append ( '<CHAR_LIT:)>' ) ; return buffer . toString ( ) ; } public static String getMethodParameters ( IMethod method , TypeInfo typeInfo , boolean includeNames ) throws Exception { StringBuffer buffer = new StringBuffer ( ) ; String [ ] paramTypes = method . getParameterTypes ( ) ; String [ ] paramNames = null ; if ( includeNames ) { paramNames = method . getParameterNames ( ) ; } boolean varargs = false ; for ( int ii = <NUM_LIT:0> ; ii < paramTypes . length ; ii ++ ) { if ( ii != <NUM_LIT:0> ) { buffer . append ( includeNames ? "<STR_LIT:U+002CU+0020>" : "<STR_LIT:U+002C>" ) ; } String type = paramTypes [ ii ] ; if ( ii == paramTypes . length - <NUM_LIT:1> && Signature . getTypeSignatureKind ( type ) == Signature . ARRAY_TYPE_SIGNATURE && Flags . isVarargs ( method . getFlags ( ) ) ) { type = Signature . getElementType ( paramTypes [ ii ] ) ; varargs = true ; } type = Signature . getSignatureSimpleName ( type ) ; type = type . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; type = TypeUtils . replaceTypeParams ( type , typeInfo ) ; buffer . append ( type ) ; if ( varargs ) { buffer . append ( VARARGS ) ; } if ( includeNames ) { buffer . append ( '<CHAR_LIT:U+0020>' ) . append ( paramNames [ ii ] ) ; } } return buffer . toString ( ) ; } public static String getMethodThrows ( IMethod method ) throws Exception { String [ ] exceptions = method . getExceptionTypes ( ) ; if ( exceptions . length > <NUM_LIT:0> ) { StringBuffer buffer = new StringBuffer ( ) ; for ( int ii = <NUM_LIT:0> ; ii < exceptions . length ; ii ++ ) { if ( ii != <NUM_LIT:0> ) { buffer . append ( "<STR_LIT:U+002CU+0020>" ) ; } buffer . append ( Signature . getSignatureSimpleName ( exceptions [ ii ] ) ) ; } return buffer . toString ( ) ; } return null ; } } </s>
|
<s> package org . eclim . plugin . jdt . util ; import java . util . ArrayList ; import java . util . List ; import org . eclim . logging . Logger ; import org . eclim . plugin . jdt . command . search . SearchRequestor ; import org . eclim . util . StringUtils ; import org . eclim . util . file . Position ; import org . eclipse . jdt . core . Flags ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IImportDeclaration ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IPackageDeclaration ; import org . eclipse . jdt . core . ISourceRange ; import org . eclipse . jdt . core . ISourceReference ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . ITypeParameter ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . core . search . IJavaSearchConstants ; import org . eclipse . jdt . core . search . IJavaSearchScope ; import org . eclipse . jdt . core . search . SearchEngine ; import org . eclipse . jdt . core . search . SearchMatch ; import org . eclipse . jdt . core . search . SearchParticipant ; import org . eclipse . jdt . core . search . SearchPattern ; import org . eclipse . jdt . internal . core . CompilationUnit ; public class TypeUtils { private static final Logger logger = Logger . getLogger ( TypeUtils . class ) ; public static IType getType ( ICompilationUnit src , int offset ) throws Exception { IJavaElement element = src . getElementAt ( offset ) ; IType type = null ; if ( element == null ) { type = ( ( CompilationUnit ) src ) . getTypeRoot ( ) . findPrimaryType ( ) ; } else if ( element != null && element . getElementType ( ) == IJavaElement . TYPE ) { type = ( IType ) element ; } else { element = element . getParent ( ) ; if ( element . getElementType ( ) == IJavaElement . IMPORT_CONTAINER ) { element = element . getParent ( ) ; } if ( element . getElementType ( ) == IJavaElement . COMPILATION_UNIT ) { element = ( ( CompilationUnit ) element ) . getTypeRoot ( ) . findPrimaryType ( ) ; } type = ( IType ) element ; } return type ; } public static Position getPosition ( IType type , ISourceReference reference ) throws Exception { ISourceRange range = reference . getSourceRange ( ) ; return Position . fromOffset ( type . getResource ( ) . getLocation ( ) . toOSString ( ) , null , range . getOffset ( ) , range . getLength ( ) ) ; } public static String getTypeSignature ( TypeInfo typeInfo ) throws Exception { StringBuffer buffer = new StringBuffer ( ) ; IType type = typeInfo . getType ( ) ; int flags = type . getFlags ( ) ; if ( Flags . isPublic ( flags ) ) { buffer . append ( "<STR_LIT>" ) ; } buffer . append ( type . isClass ( ) ? "<STR_LIT>" : "<STR_LIT>" ) ; IJavaElement parent = type . getParent ( ) ; if ( parent . getElementType ( ) == IJavaElement . TYPE ) { buffer . append ( type . getParent ( ) . getElementName ( ) ) . append ( '<CHAR_LIT:.>' ) ; } else if ( parent . getElementType ( ) == IJavaElement . CLASS_FILE ) { int index = parent . getElementName ( ) . indexOf ( '<CHAR_LIT>' ) ; if ( index != - <NUM_LIT:1> ) { buffer . append ( parent . getElementName ( ) . substring ( <NUM_LIT:0> , index ) ) . append ( '<CHAR_LIT:.>' ) ; } } buffer . append ( type . getElementName ( ) ) ; String [ ] params = typeInfo . getTypeParameters ( ) ; String [ ] args = typeInfo . getTypeArguments ( ) ; if ( params != null && params . length > <NUM_LIT:0> && args != null && args . length > <NUM_LIT:0> ) { buffer . append ( '<CHAR_LIT>' ) ; for ( int ii = <NUM_LIT:0> ; ii < args . length ; ii ++ ) { if ( ii > <NUM_LIT:0> ) { buffer . append ( '<CHAR_LIT:U+002C>' ) ; } buffer . append ( args [ ii ] ) ; } buffer . append ( '<CHAR_LIT:>>' ) ; } return buffer . toString ( ) ; } public static TypeInfo getSuperTypeContainingMethod ( IType type , IMethod method ) throws Exception { TypeInfo [ ] types = getSuperTypes ( type ) ; for ( TypeInfo info : types ) { IMethod [ ] methods = info . getType ( ) . getMethods ( ) ; for ( IMethod m : methods ) { if ( m . isSimilar ( method ) ) { return info ; } } } return null ; } public static Object [ ] getSuperTypeContainingMethod ( IType type , String signature ) throws Exception { TypeInfo [ ] types = getSuperTypes ( type ) ; for ( TypeInfo info : types ) { IMethod [ ] methods = info . getType ( ) . getMethods ( ) ; for ( IMethod method : methods ) { String sig = MethodUtils . getMinimalMethodSignature ( method , info ) ; if ( sig . equals ( signature ) ) { return new Object [ ] { info , method } ; } } } return null ; } public static String getBaseTypeFromGeneric ( IType type , String typeSignature ) throws Exception { int arrayCount = Signature . getArrayCount ( typeSignature ) ; if ( arrayCount > <NUM_LIT:0> ) { for ( int ii = <NUM_LIT:0> ; ii < arrayCount ; ii ++ ) { typeSignature = Signature . getElementType ( typeSignature ) ; } } String result = null ; ITypeParameter param = type . getTypeParameter ( Signature . getSignatureSimpleName ( typeSignature ) ) ; if ( param . exists ( ) ) { result = param . getBounds ( ) [ <NUM_LIT:0> ] ; } else { result = Signature . getSignatureSimpleName ( Signature . getTypeErasure ( typeSignature ) ) ; } if ( arrayCount > <NUM_LIT:0> ) { for ( int ii = <NUM_LIT:0> ; ii < arrayCount ; ii ++ ) { result = result + "<STR_LIT:[]>" ; } } return result ; } public static IType findUnqualifiedType ( ICompilationUnit src , String typeName ) throws Exception { String name = "<STR_LIT:.>" + typeName ; int index = name . indexOf ( '<CHAR_LIT>' ) ; if ( index != - <NUM_LIT:1> ) { name = name . substring ( <NUM_LIT:0> , index ) ; } IImportDeclaration [ ] imports = src . getImports ( ) ; for ( IImportDeclaration decl : imports ) { if ( decl . getElementName ( ) . endsWith ( name ) ) { return src . getJavaProject ( ) . findType ( decl . getElementName ( ) ) ; } } IPackageDeclaration [ ] packages = src . getPackageDeclarations ( ) ; if ( packages != null && packages . length > <NUM_LIT:0> ) { name = packages [ <NUM_LIT:0> ] . getElementName ( ) + name ; } else { name = typeName ; } IType type = src . getJavaProject ( ) . findType ( name ) ; if ( type == null ) { type = src . getJavaProject ( ) . findType ( "<STR_LIT>" + typeName ) ; } return type ; } public static TypeInfo [ ] getSuperTypes ( IType type ) throws Exception { return getSuperTypes ( type , false ) ; } public static TypeInfo [ ] getSuperTypes ( IType type , boolean returnNotFound ) throws Exception { TypeInfo [ ] interfaces = getInterfaces ( type , returnNotFound ) ; TypeInfo [ ] superClasses = getSuperClasses ( type , returnNotFound ) ; TypeInfo [ ] types = new TypeInfo [ interfaces . length + superClasses . length ] ; System . arraycopy ( interfaces , <NUM_LIT:0> , types , <NUM_LIT:0> , interfaces . length ) ; System . arraycopy ( superClasses , <NUM_LIT:0> , types , interfaces . length , superClasses . length ) ; return types ; } public static TypeInfo [ ] getSuperClasses ( IType type ) throws Exception { return getSuperClasses ( type , false ) ; } public static TypeInfo [ ] getSuperClasses ( IType type , boolean returnNotFound ) throws Exception { ArrayList < TypeInfo > types = new ArrayList < TypeInfo > ( ) ; getSuperClasses ( type , types , returnNotFound , null ) ; IType objectType = type . getJavaProject ( ) . findType ( "<STR_LIT>" ) ; TypeInfo objectTypeInfo = new TypeInfo ( objectType , null , null ) ; if ( ! types . contains ( objectTypeInfo ) ) { types . add ( objectTypeInfo ) ; } return ( TypeInfo [ ] ) types . toArray ( new TypeInfo [ types . size ( ) ] ) ; } public static TypeInfo [ ] getInterfaces ( IType type ) throws Exception { return getInterfaces ( type , false ) ; } public static TypeInfo [ ] getInterfaces ( IType type , boolean returnNotFound ) throws Exception { ArrayList < TypeInfo > types = new ArrayList < TypeInfo > ( ) ; getInterfaces ( type , types , returnNotFound , null ) ; return ( TypeInfo [ ] ) types . toArray ( new TypeInfo [ types . size ( ) ] ) ; } public static void getSuperClasses ( IType type , List < TypeInfo > superclasses , boolean includeNotFound , TypeInfo baseType ) throws Exception { TypeInfo superclassInfo = getSuperClass ( type , baseType ) ; if ( superclassInfo != null ) { if ( baseType == null || baseType . getTypeArguments ( ) . length != superclassInfo . getTypeArguments ( ) . length ) { baseType = superclassInfo ; } } if ( superclassInfo != null && ! superclasses . contains ( superclassInfo ) ) { superclasses . add ( superclassInfo ) ; getSuperClasses ( superclassInfo . getType ( ) , superclasses , includeNotFound , baseType ) ; } else if ( superclassInfo == null && includeNotFound ) { String typeName = type . getSuperclassName ( ) ; if ( typeName != null ) { try { IType superclass = type . getType ( typeName ) ; superclassInfo = new TypeInfo ( superclass , null , null ) ; if ( ! superclasses . contains ( superclassInfo ) ) { superclasses . add ( superclassInfo ) ; } } catch ( Exception e ) { logger . warn ( "<STR_LIT>" + typeName + "<STR_LIT:'>" , e ) ; } } } } public static TypeInfo getSuperClass ( IType type ) throws Exception { return getSuperClass ( type , null ) ; } private static TypeInfo getSuperClass ( IType type , TypeInfo baseType ) throws Exception { String superclassSig = type . getSuperclassTypeSignature ( ) ; if ( superclassSig != null ) { String qualifier = Signature . getSignatureQualifier ( superclassSig ) ; qualifier = ( qualifier != null && ! qualifier . equals ( StringUtils . EMPTY ) ) ? qualifier + '<CHAR_LIT:.>' : StringUtils . EMPTY ; String superclass = qualifier + Signature . getSignatureSimpleName ( superclassSig ) ; String [ ] args = Signature . getTypeArguments ( superclassSig ) ; String [ ] typeArgs = new String [ args . length ] ; for ( int ii = <NUM_LIT:0> ; ii < args . length ; ii ++ ) { typeArgs [ ii ] = Signature . getSignatureSimpleName ( args [ ii ] ) ; } if ( baseType != null && baseType . getTypeArguments ( ) . length == typeArgs . length ) { typeArgs = baseType . getTypeArguments ( ) ; } String [ ] [ ] types = type . resolveType ( superclass ) ; if ( types != null ) { for ( String [ ] typeInfo : types ) { String typeName = typeInfo [ <NUM_LIT:0> ] + "<STR_LIT:.>" + typeInfo [ <NUM_LIT:1> ] ; IType found = type . getJavaProject ( ) . findType ( typeName ) ; if ( found != null ) { ITypeParameter [ ] params = found . getTypeParameters ( ) ; String [ ] typeParams = new String [ params . length ] ; for ( int ii = <NUM_LIT:0> ; ii < params . length ; ii ++ ) { typeParams [ ii ] = params [ ii ] . getElementName ( ) ; } return new TypeInfo ( found , typeParams , typeArgs ) ; } } } else { IType found = type . getJavaProject ( ) . findType ( superclass ) ; if ( found != null ) { return new TypeInfo ( found , null , typeArgs ) ; } } } return null ; } public static IType [ ] getSuperInterfaces ( IType type ) throws Exception { String [ ] parents = type . getSuperInterfaceNames ( ) ; ArrayList < IType > interfaces = new ArrayList < IType > ( parents . length ) ; for ( String parent : parents ) { String [ ] [ ] types = type . resolveType ( parent ) ; if ( types != null ) { for ( String [ ] typeInfo : types ) { String typeName = typeInfo [ <NUM_LIT:0> ] + "<STR_LIT:.>" + typeInfo [ <NUM_LIT:1> ] ; IType found = type . getJavaProject ( ) . findType ( typeName ) ; if ( found != null ) { interfaces . add ( found ) ; } } } else { IType found = type . getJavaProject ( ) . findType ( parent ) ; if ( found != null ) { interfaces . add ( found ) ; } } } return interfaces . toArray ( new IType [ interfaces . size ( ) ] ) ; } public static void getInterfaces ( IType type , List < TypeInfo > interfaces , boolean includeNotFound , TypeInfo baseType ) throws Exception { String [ ] parentSigs = type . getSuperInterfaceTypeSignatures ( ) ; for ( String parentSig : parentSigs ) { String parent = Signature . getSignatureSimpleName ( parentSig ) ; String [ ] args = Signature . getTypeArguments ( parentSig ) ; String [ ] typeArgs = new String [ args . length ] ; for ( int ii = <NUM_LIT:0> ; ii < args . length ; ii ++ ) { typeArgs [ ii ] = Signature . getSignatureSimpleName ( args [ ii ] ) ; } if ( baseType != null && baseType . getTypeArguments ( ) . length == typeArgs . length ) { typeArgs = baseType . getTypeArguments ( ) ; } IType found = null ; String [ ] [ ] types = type . resolveType ( parent ) ; if ( types != null ) { for ( String [ ] typeInfo : types ) { String typeName = typeInfo [ <NUM_LIT:0> ] + "<STR_LIT:.>" + typeInfo [ <NUM_LIT:1> ] ; found = type . getJavaProject ( ) . findType ( typeName ) ; } } else { found = type . getJavaProject ( ) . findType ( parent ) ; } if ( found != null ) { ITypeParameter [ ] params = found . getTypeParameters ( ) ; String [ ] typeParams = new String [ params . length ] ; for ( int ii = <NUM_LIT:0> ; ii < params . length ; ii ++ ) { typeParams [ ii ] = params [ ii ] . getElementName ( ) ; } TypeInfo typeInfo = new TypeInfo ( found , typeParams , typeArgs ) ; if ( ! interfaces . contains ( typeInfo ) ) { interfaces . add ( typeInfo ) ; if ( baseType == null || baseType . getTypeArguments ( ) . length != typeInfo . getTypeArguments ( ) . length ) { baseType = typeInfo ; } getInterfaces ( found , interfaces , includeNotFound , baseType ) ; } } else if ( found == null && includeNotFound ) { String typeName = parent ; if ( typeName != null ) { try { found = type . getType ( typeName ) ; TypeInfo typeInfo = new TypeInfo ( found , null , typeArgs ) ; if ( ! interfaces . contains ( typeInfo ) ) { interfaces . add ( typeInfo ) ; } } catch ( Exception e ) { logger . warn ( "<STR_LIT>" + typeName + "<STR_LIT:'>" , e ) ; } } } else if ( found == null ) { logger . warn ( "<STR_LIT>" , parent , type . getFullyQualifiedName ( ) ) ; } } TypeInfo superclassInfo = getSuperClass ( type ) ; if ( superclassInfo != null ) { getInterfaces ( superclassInfo . getType ( ) , interfaces , includeNotFound , superclassInfo ) ; } } public static String replaceTypeParams ( String type , TypeInfo typeInfo ) { if ( typeInfo != null ) { String [ ] params = typeInfo . getTypeParameters ( ) ; String [ ] args = typeInfo . getTypeArguments ( ) ; if ( params != null && params . length == args . length ) { for ( int ii = <NUM_LIT:0> ; ii < params . length ; ii ++ ) { type = type . replaceAll ( "<STR_LIT>" + params [ ii ] + "<STR_LIT>" , args [ ii ] ) ; } } } return type ; } public static IType [ ] findTypes ( IJavaProject javaProject , String name ) throws Exception { SearchPattern pattern = SearchPattern . createPattern ( name , IJavaSearchConstants . TYPE , IJavaSearchConstants . DECLARATIONS , SearchPattern . R_EXACT_MATCH | SearchPattern . R_CASE_SENSITIVE ) ; IJavaSearchScope scope = SearchEngine . createJavaSearchScope ( new IJavaElement [ ] { javaProject } ) ; SearchRequestor requestor = new SearchRequestor ( ) ; SearchEngine engine = new SearchEngine ( ) ; SearchParticipant [ ] participants = new SearchParticipant [ ] { SearchEngine . getDefaultSearchParticipant ( ) } ; engine . search ( pattern , participants , scope , requestor , null ) ; ArrayList < IType > types = new ArrayList < IType > ( ) ; if ( requestor . getMatches ( ) . size ( ) > <NUM_LIT:0> ) { for ( SearchMatch match : requestor . getMatches ( ) ) { if ( match . getAccuracy ( ) != SearchMatch . A_ACCURATE ) { continue ; } IJavaElement element = ( IJavaElement ) match . getElement ( ) ; if ( element . getElementType ( ) == IJavaElement . TYPE ) { types . add ( ( IType ) element ) ; } } } return types . toArray ( new IType [ types . size ( ) ] ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . util ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Hashtable ; import java . util . List ; import java . util . Map ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import org . apache . commons . lang . StringUtils ; import org . apache . commons . vfs . FileObject ; import org . apache . commons . vfs . FileSystemManager ; import org . apache . commons . vfs . VFS ; import org . eclim . Services ; import org . eclim . plugin . core . preference . Preferences ; import org . eclim . plugin . core . project . ProjectNatureFactory ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . jdt . PluginResources ; import org . eclim . util . IOUtils ; import org . eclim . util . file . FileUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . IConfigurationElement ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . IStatus ; import org . eclipse . core . runtime . Path ; import org . eclipse . core . runtime . Platform ; import org . eclipse . jdt . core . IBuffer ; import org . eclipse . jdt . core . IClassFile ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IField ; import org . eclipse . jdt . core . IImportDeclaration ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IPackageDeclaration ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . core . compiler . IProblem ; import org . eclipse . jdt . core . formatter . IndentManipulation ; import org . eclipse . jdt . internal . core . DocumentAdapter ; import org . eclipse . jdt . internal . corext . codemanipulation . StubUtility ; import org . eclipse . jdt . internal . formatter . DefaultCodeFormatter ; import org . eclipse . jdt . internal . ui . JavaPlugin ; import org . eclipse . jdt . internal . ui . text . correction . ContributedProcessorDescriptor ; import org . eclipse . jdt . ui . JavaUI ; import org . eclipse . jdt . ui . text . java . IQuickAssistProcessor ; import org . eclipse . jdt . ui . text . java . IQuickFixProcessor ; import org . eclipse . jface . text . Document ; import org . eclipse . jface . text . IDocument ; import org . eclipse . text . edits . TextEdit ; public class JavaUtils { public static final String JAVA_LANG = "<STR_LIT>" ; private static final Pattern PACKAGE_LINE = Pattern . compile ( "<STR_LIT>" ) ; private static final Pattern TRAILING_WHITESPACE = Pattern . compile ( "<STR_LIT>" , Pattern . MULTILINE ) ; private static ContributedProcessorDescriptor [ ] correctionProcessors ; private static ContributedProcessorDescriptor [ ] assistProcessors ; public static IJavaProject getJavaProject ( String project ) throws Exception { return getJavaProject ( ProjectUtils . getProject ( project , true ) ) ; } public static IJavaProject getJavaProject ( IProject project ) throws Exception { if ( ProjectUtils . getPath ( project ) == null ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , project . getName ( ) ) ) ; } if ( ! project . hasNature ( PluginResources . NATURE ) ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , project . getName ( ) , ProjectNatureFactory . getAliasForNature ( PluginResources . NATURE ) ) ) ; } IJavaProject javaProject = JavaCore . create ( project ) ; if ( javaProject == null || ! javaProject . exists ( ) ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , project ) ) ; } return javaProject ; } public static ICompilationUnit getCompilationUnit ( String project , String file ) throws Exception { IJavaProject javaProject = getJavaProject ( project ) ; return getCompilationUnit ( javaProject , file ) ; } public static ICompilationUnit getCompilationUnit ( String file ) throws Exception { IProject [ ] projects = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getProjects ( ) ; for ( int ii = <NUM_LIT:0> ; ii < projects . length ; ii ++ ) { IJavaProject javaProject = getJavaProject ( projects [ ii ] ) ; ICompilationUnit src = JavaCore . createCompilationUnitFrom ( ProjectUtils . getFile ( javaProject . getProject ( ) , file ) ) ; if ( src != null && src . exists ( ) ) { return src ; } } throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , file , "<STR_LIT>" ) ) ; } public static ICompilationUnit getCompilationUnit ( IJavaProject project , String file ) throws Exception { ICompilationUnit src = JavaCore . createCompilationUnitFrom ( ProjectUtils . getFile ( project . getProject ( ) , file ) ) ; if ( src == null || ! src . exists ( ) ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , file , "<STR_LIT>" ) ) ; } return src ; } public static ICompilationUnit findCompilationUnit ( String project , String file ) throws Exception { IPath path = Path . fromOSString ( file ) ; IJavaProject javaProject = getJavaProject ( project ) ; javaProject . open ( null ) ; ICompilationUnit src = ( ICompilationUnit ) javaProject . findElement ( path ) ; return src ; } public static ICompilationUnit findCompilationUnit ( String file ) throws Exception { IPath path = Path . fromOSString ( file ) ; IProject [ ] projects = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getProjects ( ) ; for ( IProject project : projects ) { if ( project . hasNature ( JavaCore . NATURE_ID ) ) { IJavaProject javaProject = getJavaProject ( project ) ; javaProject . open ( null ) ; ICompilationUnit src = ( ICompilationUnit ) javaProject . findElement ( path ) ; if ( src != null ) { return src ; } } } return null ; } public static IClassFile findClassFile ( IJavaProject project , String path ) throws Exception { if ( path . startsWith ( "<STR_LIT:/>" ) || path . toLowerCase ( ) . startsWith ( "<STR_LIT>" ) || path . toLowerCase ( ) . startsWith ( "<STR_LIT>" ) ) { FileSystemManager fsManager = VFS . getManager ( ) ; FileObject file = fsManager . resolveFile ( path ) ; if ( file . exists ( ) ) { BufferedReader in = null ; try { in = new BufferedReader ( new InputStreamReader ( file . getContent ( ) . getInputStream ( ) ) ) ; String pack = null ; String line = null ; while ( ( line = in . readLine ( ) ) != null ) { Matcher matcher = PACKAGE_LINE . matcher ( line ) ; if ( matcher . matches ( ) ) { pack = matcher . group ( <NUM_LIT:1> ) ; break ; } } if ( pack != null ) { String name = pack + '<CHAR_LIT:.>' + FileUtils . getFileName ( file . getName ( ) . getPath ( ) ) ; IType type = project . findType ( name ) ; if ( type != null ) { return type . getClassFile ( ) ; } } } finally { IOUtils . closeQuietly ( in ) ; } } } return null ; } public static IJavaElement getPrimaryElement ( IJavaElement element ) { IJavaElement parent = element ; while ( parent . getElementType ( ) != IJavaElement . COMPILATION_UNIT && parent . getElementType ( ) != IJavaElement . CLASS_FILE ) { parent = parent . getParent ( ) ; } return parent ; } public static IDocument getDocument ( ICompilationUnit src ) throws Exception { IBuffer buffer = src . getBuffer ( ) ; if ( buffer instanceof IDocument ) { return ( IDocument ) buffer ; } return new DocumentAdapter ( buffer ) ; } public static String getFullyQualifiedName ( IJavaElement element ) { IJavaElement parent = element ; while ( parent . getElementType ( ) != IJavaElement . COMPILATION_UNIT && parent . getElementType ( ) != IJavaElement . CLASS_FILE ) { parent = parent . getParent ( ) ; } StringBuffer elementName = new StringBuffer ( ) . append ( parent . getParent ( ) . getElementName ( ) ) . append ( '<CHAR_LIT:.>' ) . append ( FileUtils . getFileName ( parent . getElementName ( ) ) ) ; switch ( element . getElementType ( ) ) { case IJavaElement . FIELD : IField field = ( IField ) element ; elementName . append ( '<CHAR_LIT>' ) . append ( field . getElementName ( ) ) ; break ; case IJavaElement . METHOD : IMethod method = ( IMethod ) element ; elementName . append ( '<CHAR_LIT>' ) . append ( method . getElementName ( ) ) . append ( '<CHAR_LIT:(>' ) ; String [ ] parameters = method . getParameterTypes ( ) ; for ( int ii = <NUM_LIT:0> ; ii < parameters . length ; ii ++ ) { if ( ii != <NUM_LIT:0> ) { elementName . append ( "<STR_LIT:U+002CU+0020>" ) ; } elementName . append ( Signature . toString ( parameters [ ii ] ) . replace ( '<CHAR_LIT:/>' , '<CHAR_LIT:.>' ) ) ; } elementName . append ( '<CHAR_LIT:)>' ) ; break ; } return elementName . toString ( ) ; } public static String getCompilationUnitRelativeTypeName ( ICompilationUnit src , IType type ) throws Exception { String typeName = type . getFullyQualifiedName ( ) . replace ( '<CHAR_LIT>' , '<CHAR_LIT:.>' ) ; if ( JavaUtils . containsImport ( src , type ) ) { typeName = type . getElementName ( ) ; int parentType = type . getParent ( ) . getElementType ( ) ; if ( parentType == IJavaElement . TYPE ) { typeName = type . getParent ( ) . getElementName ( ) + '<CHAR_LIT:.>' + typeName ; } else if ( parentType == IJavaElement . CLASS_FILE ) { String parentName = type . getParent ( ) . getElementName ( ) ; int index = parentName . indexOf ( '<CHAR_LIT>' ) ; if ( index != - <NUM_LIT:1> ) { parentName = parentName . substring ( <NUM_LIT:0> , index ) ; typeName = parentName + '<CHAR_LIT:.>' + typeName ; } } } else { typeName = type . getFullyQualifiedName ( ) . replace ( '<CHAR_LIT>' , '<CHAR_LIT:.>' ) ; } return typeName ; } public static boolean containsImport ( ICompilationUnit src , String type ) throws Exception { return containsImport ( src , src . getType ( type ) ) ; } public static boolean containsImport ( ICompilationUnit src , IType type ) throws Exception { String typePkg = type . getPackageFragment ( ) . getElementName ( ) ; IPackageDeclaration [ ] packages = src . getPackageDeclarations ( ) ; String pkg = packages . length > <NUM_LIT:0> ? packages [ <NUM_LIT:0> ] . getElementName ( ) : null ; if ( ( pkg == null && typePkg == null ) || ( pkg != null && pkg . equals ( typePkg ) ) ) { return true ; } if ( JAVA_LANG . equals ( typePkg ) ) { return true ; } typePkg = typePkg + "<STR_LIT>" ; String typeName = type . getFullyQualifiedName ( ) . replace ( '<CHAR_LIT>' , '<CHAR_LIT:.>' ) ; IImportDeclaration [ ] imports = src . getImports ( ) ; for ( int ii = <NUM_LIT:0> ; ii < imports . length ; ii ++ ) { String name = imports [ ii ] . getElementName ( ) ; if ( name . equals ( typeName ) || name . equals ( typePkg ) ) { return true ; } } return false ; } public static void format ( ICompilationUnit src , int kind , int offset , int length ) throws Exception { IBuffer buffer = src . getBuffer ( ) ; String contents = buffer . getContents ( ) ; String delimiter = StubUtility . getLineDelimiterUsed ( src ) ; DefaultCodeFormatter formatter = new DefaultCodeFormatter ( src . getJavaProject ( ) . getOptions ( true ) ) ; while ( offset > <NUM_LIT:0> && ! IndentManipulation . isLineDelimiterChar ( buffer . getChar ( offset - <NUM_LIT:1> ) ) ) { offset -- ; length ++ ; } while ( ( offset + length ) < contents . length ( ) && IndentManipulation . isLineDelimiterChar ( buffer . getChar ( offset + length ) ) ) { length ++ ; } TextEdit edits = formatter . format ( kind , contents , offset , length , <NUM_LIT:0> , delimiter ) ; if ( edits != null ) { int oldLength = contents . length ( ) ; Document document = new Document ( contents ) ; edits . apply ( document ) ; String formatted = document . get ( ) ; length += formatted . length ( ) - oldLength ; if ( offset < ( offset + length ) ) { String pre = formatted . substring ( <NUM_LIT:0> , offset ) ; StringBuffer section = new StringBuffer ( formatted . substring ( offset , offset + length ) ) ; StringBuffer post = new StringBuffer ( formatted . substring ( offset + length ) ) ; while ( ! section . toString ( ) . endsWith ( delimiter ) && post . length ( ) > <NUM_LIT:0> ) { section . append ( post . charAt ( <NUM_LIT:0> ) ) ; post . deleteCharAt ( <NUM_LIT:0> ) ; } Matcher matcher = TRAILING_WHITESPACE . matcher ( section ) ; String stripped = matcher . replaceAll ( StringUtils . EMPTY ) ; src . getBuffer ( ) . setContents ( pre + stripped + post ) ; } else { src . getBuffer ( ) . setContents ( formatted ) ; } if ( src . isWorkingCopy ( ) ) { src . commitWorkingCopy ( false , null ) ; } src . save ( null , false ) ; } } public static String getCompilerSourceCompliance ( IJavaProject project ) { return ( String ) project . getOptions ( true ) . get ( JavaCore . COMPILER_SOURCE ) ; } @ SuppressWarnings ( { "<STR_LIT:unchecked>" , "<STR_LIT:rawtypes>" } ) public static void setCompilerSourceCompliance ( String version ) throws Exception { Map < String , String > options = JavaCore . getOptions ( ) ; options . put ( JavaCore . COMPILER_SOURCE , version ) ; options . put ( JavaCore . COMPILER_COMPLIANCE , version ) ; options . put ( JavaCore . COMPILER_CODEGEN_TARGET_PLATFORM , version ) ; JavaCore . setOptions ( ( Hashtable ) options ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public static void setCompilerSourceCompliance ( IJavaProject project , String version ) throws Exception { Map < String , String > options = project . getOptions ( false ) ; options . put ( JavaCore . COMPILER_SOURCE , version ) ; options . put ( JavaCore . COMPILER_COMPLIANCE , version ) ; options . put ( JavaCore . COMPILER_CODEGEN_TARGET_PLATFORM , version ) ; project . setOptions ( options ) ; } public static void loadPreferencesForTemplate ( IProject project , Preferences preferences , Map < String , Object > values ) throws Exception { Map < String , String > options = preferences . getValues ( project ) ; for ( String key : options . keySet ( ) ) { String value = options . get ( key ) ; values . put ( key . replace ( '<CHAR_LIT:.>' , '<CHAR_LIT:_>' ) , value ) ; } } public static IProblem [ ] getProblems ( ICompilationUnit src ) throws Exception { return getProblems ( src , null ) ; } public static IProblem [ ] getProblems ( ICompilationUnit src , int [ ] ids ) throws Exception { ICompilationUnit workingCopy = src . getWorkingCopy ( null ) ; ProblemRequestor requestor = new ProblemRequestor ( ids ) ; try { workingCopy . discardWorkingCopy ( ) ; workingCopy . becomeWorkingCopy ( requestor , null ) ; } finally { workingCopy . discardWorkingCopy ( ) ; } List < IProblem > problems = requestor . getProblems ( ) ; return ( IProblem [ ] ) problems . toArray ( new IProblem [ problems . size ( ) ] ) ; } public static IQuickFixProcessor [ ] getQuickFixProcessors ( ICompilationUnit src ) throws Exception { if ( correctionProcessors == null ) { correctionProcessors = getProcessorDescriptors ( "<STR_LIT>" , true ) ; } IQuickFixProcessor [ ] processors = new IQuickFixProcessor [ correctionProcessors . length ] ; for ( int ii = <NUM_LIT:0> ; ii < correctionProcessors . length ; ii ++ ) { processors [ ii ] = ( IQuickFixProcessor ) correctionProcessors [ ii ] . getProcessor ( src , IQuickFixProcessor . class ) ; } return processors ; } public static IQuickAssistProcessor [ ] getQuickAssistProcessors ( ICompilationUnit src ) throws Exception { if ( assistProcessors == null ) { assistProcessors = getProcessorDescriptors ( "<STR_LIT>" , false ) ; } IQuickAssistProcessor [ ] processors = new IQuickAssistProcessor [ assistProcessors . length ] ; for ( int ii = <NUM_LIT:0> ; ii < assistProcessors . length ; ii ++ ) { processors [ ii ] = ( IQuickAssistProcessor ) assistProcessors [ ii ] . getProcessor ( src , IQuickAssistProcessor . class ) ; } return processors ; } private static ContributedProcessorDescriptor [ ] getProcessorDescriptors ( String id , boolean testMarkerTypes ) throws Exception { IConfigurationElement [ ] elements = Platform . getExtensionRegistry ( ) . getConfigurationElementsFor ( JavaUI . ID_PLUGIN , id ) ; ArrayList < ContributedProcessorDescriptor > res = new ArrayList < ContributedProcessorDescriptor > ( elements . length ) ; for ( int ii = <NUM_LIT:0> ; ii < elements . length ; ii ++ ) { ContributedProcessorDescriptor desc = new ContributedProcessorDescriptor ( elements [ ii ] , testMarkerTypes ) ; IStatus status = desc . checkSyntax ( ) ; if ( status . isOK ( ) ) { res . add ( desc ) ; } else { JavaPlugin . log ( status ) ; } } return ( ContributedProcessorDescriptor [ ] ) res . toArray ( new ContributedProcessorDescriptor [ res . size ( ) ] ) ; } public static class ProblemRequestor implements org . eclipse . jdt . core . IProblemRequestor { private ArrayList < IProblem > problems = new ArrayList < IProblem > ( ) ; private int [ ] ids ; public ProblemRequestor ( int [ ] ids ) { this . ids = ids ; } public List < IProblem > getProblems ( ) { return problems ; } public void acceptProblem ( IProblem problem ) { if ( ids != null ) { for ( int ii = <NUM_LIT:0> ; ii < ids . length ; ii ++ ) { if ( problem . getID ( ) == ids [ ii ] ) { problems . add ( problem ) ; break ; } } } else { problems . add ( problem ) ; } } public void beginReporting ( ) { } public void endReporting ( ) { } public boolean isActive ( ) { return true ; } } } </s>
|
<s> package org . eclim . plugin . jdt . util ; import org . eclim . logging . Logger ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . dom . AST ; import org . eclipse . jdt . core . dom . ASTNode ; import org . eclipse . jdt . core . dom . ASTParser ; import org . eclipse . jdt . core . dom . AbstractTypeDeclaration ; import org . eclipse . jdt . core . dom . CompilationUnit ; import org . eclipse . jdt . core . dom . FieldDeclaration ; import org . eclipse . jdt . core . dom . ImportDeclaration ; import org . eclipse . jdt . core . dom . Initializer ; import org . eclipse . jdt . core . dom . MethodDeclaration ; import org . eclipse . jdt . core . dom . NodeFinder ; import org . eclipse . jdt . core . dom . PackageDeclaration ; import org . eclipse . jface . text . Document ; import org . eclipse . text . edits . TextEdit ; public class ASTUtils { private static final Logger logger = Logger . getLogger ( ASTUtils . class ) ; private ASTUtils ( ) { } public static CompilationUnit getCompilationUnit ( ICompilationUnit src ) throws Exception { return getCompilationUnit ( src , false ) ; } public static CompilationUnit getCompilationUnit ( ICompilationUnit src , boolean recordModifications ) throws Exception { ASTParser parser = ASTParser . newParser ( AST . JLS4 ) ; parser . setSource ( src ) ; CompilationUnit cu = ( CompilationUnit ) parser . createAST ( null ) ; if ( recordModifications ) { cu . recordModifications ( ) ; } return cu ; } public static void commitCompilationUnit ( ICompilationUnit src , CompilationUnit node ) throws Exception { Document document = new Document ( src . getBuffer ( ) . getContents ( ) ) ; TextEdit edits = node . rewrite ( document , src . getJavaProject ( ) . getOptions ( true ) ) ; edits . apply ( document ) ; src . getBuffer ( ) . setContents ( document . get ( ) ) ; if ( src . isWorkingCopy ( ) ) { src . commitWorkingCopy ( false , null ) ; } src . save ( null , false ) ; } public static ASTNode findNode ( CompilationUnit cu , int offset ) throws Exception { NodeFinder finder = new NodeFinder ( cu , offset , <NUM_LIT:1> ) ; return finder . getCoveringNode ( ) ; } public static ASTNode findNode ( CompilationUnit cu , int offset , IJavaElement element ) throws Exception { ASTNode node = findNode ( cu , offset ) ; if ( node == null ) { return null ; } if ( element . getElementType ( ) == IJavaElement . TYPE_PARAMETER ) { element = element . getParent ( ) ; } switch ( element . getElementType ( ) ) { case IJavaElement . PACKAGE_DECLARATION : node = resolveNode ( node , PackageDeclaration . class ) ; break ; case IJavaElement . IMPORT_DECLARATION : node = resolveNode ( node , ImportDeclaration . class ) ; break ; case IJavaElement . TYPE : node = resolveNode ( node , AbstractTypeDeclaration . class ) ; break ; case IJavaElement . INITIALIZER : node = resolveNode ( node , Initializer . class ) ; break ; case IJavaElement . FIELD : node = resolveNode ( node , FieldDeclaration . class ) ; break ; case IJavaElement . METHOD : node = resolveNode ( node , MethodDeclaration . class ) ; break ; default : logger . info ( "<STR_LIT>" + "<STR_LIT>" + element . getElementType ( ) ) ; } return node ; } @ SuppressWarnings ( { "<STR_LIT:rawtypes>" , "<STR_LIT:unchecked>" } ) private static ASTNode resolveNode ( ASTNode node , Class type ) throws Exception { if ( node == null ) { return null ; } if ( type . isAssignableFrom ( node . getClass ( ) ) ) { return node ; } return resolveNode ( node . getParent ( ) , type ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . util ; import java . util . Comparator ; import org . eclipse . jdt . core . IJavaElement ; public class IJavaElementComparator implements Comparator < IJavaElement > { public int compare ( IJavaElement o1 , IJavaElement o2 ) { if ( o1 == null && o2 == null ) { return <NUM_LIT:0> ; } else if ( o2 == null ) { return - <NUM_LIT:1> ; } else if ( o1 == null ) { return <NUM_LIT:1> ; } IJavaElement p1 = JavaUtils . getPrimaryElement ( o1 ) ; IJavaElement p2 = JavaUtils . getPrimaryElement ( o2 ) ; return p1 . getElementType ( ) - p2 . getElementType ( ) ; } public boolean equals ( Object obj ) { if ( obj instanceof IJavaElementComparator ) { return true ; } return false ; } } </s>
|
<s> package org . eclim . plugin . jdt . util ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; import org . eclim . logging . Logger ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . IClasspathEntry ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . JavaModelException ; public class ClasspathUtils { private static final Logger logger = Logger . getLogger ( ClasspathUtils . class ) ; public static String [ ] getClasspath ( IJavaProject project ) throws Exception { HashSet < IJavaProject > visited = new HashSet < IJavaProject > ( ) ; ArrayList < String > paths = new ArrayList < String > ( ) ; collect ( project , paths , visited , true ) ; return paths . toArray ( new String [ paths . size ( ) ] ) ; } public static String [ ] getSrcPaths ( IJavaProject project ) throws Exception { ArrayList < String > paths = new ArrayList < String > ( ) ; IClasspathEntry [ ] entries = project . getResolvedClasspath ( true ) ; for ( IClasspathEntry entry : entries ) { if ( entry . getEntryKind ( ) == IClasspathEntry . CPE_SOURCE ) { paths . add ( ProjectUtils . getFilePath ( project . getProject ( ) , entry . getPath ( ) . toOSString ( ) ) ) ; } } return paths . toArray ( new String [ paths . size ( ) ] ) ; } private static void collect ( IJavaProject javaProject , List < String > paths , Set < IJavaProject > visited , boolean isFirstProject ) throws Exception { if ( visited . contains ( javaProject ) ) { return ; } visited . add ( javaProject ) ; try { IPath out = javaProject . getOutputLocation ( ) ; paths . add ( ProjectUtils . getFilePath ( javaProject . getProject ( ) , out . addTrailingSeparator ( ) . toOSString ( ) ) ) ; } catch ( JavaModelException ignore ) { } IProject project = javaProject . getProject ( ) ; String name = project . getName ( ) ; IClasspathEntry [ ] entries = null ; try { entries = javaProject . getResolvedClasspath ( true ) ; } catch ( JavaModelException jme ) { logger . warn ( "<STR_LIT>" + name , jme ) ; return ; } for ( IClasspathEntry entry : entries ) { switch ( entry . getEntryKind ( ) ) { case IClasspathEntry . CPE_LIBRARY : case IClasspathEntry . CPE_CONTAINER : case IClasspathEntry . CPE_VARIABLE : String path = entry . getPath ( ) . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; if ( path . startsWith ( "<STR_LIT:/>" + name + "<STR_LIT:/>" ) ) { path = ProjectUtils . getFilePath ( project , path ) ; } paths . add ( path ) ; break ; case IClasspathEntry . CPE_PROJECT : if ( isFirstProject || entry . isExported ( ) ) { javaProject = JavaUtils . getJavaProject ( entry . getPath ( ) . segment ( <NUM_LIT:0> ) ) ; if ( javaProject != null ) { collect ( javaProject , paths , visited , false ) ; } } break ; case IClasspathEntry . CPE_SOURCE : IPath out = entry . getOutputLocation ( ) ; if ( out != null ) { paths . add ( ProjectUtils . getFilePath ( javaProject . getProject ( ) , out . addTrailingSeparator ( ) . toOSString ( ) ) ) ; } break ; } } } } </s>
|
<s> package org . eclim . plugin . jdt . command . hierarchy ; import java . util . ArrayList ; import java . util . List ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . plugin . jdt . util . TypeInfo ; import org . eclim . plugin . jdt . util . TypeUtils ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IType ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class HierarchyCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; ICompilationUnit src = JavaUtils . getCompilationUnit ( project , file ) ; int offset = commandLine . getIntValue ( Options . OFFSET_OPTION ) ; if ( offset != - <NUM_LIT:1> ) { offset = getOffset ( commandLine ) ; } IType type = TypeUtils . getType ( src , offset ) ; HierarchyNode hierarchy = new HierarchyNode ( type , createChildNodes ( type ) ) ; return hierarchy ; } private List < HierarchyNode > createChildNodes ( IType type ) throws Exception { ArrayList < HierarchyNode > nodes = new ArrayList < HierarchyNode > ( ) ; TypeInfo parentClassInfo = TypeUtils . getSuperClass ( type ) ; String jlo = "<STR_LIT>" ; if ( parentClassInfo != null ) { IType parentClass = parentClassInfo . getType ( ) ; if ( ! jlo . equals ( JavaUtils . getFullyQualifiedName ( parentClass ) ) ) { nodes . add ( new HierarchyNode ( parentClass , createChildNodes ( parentClass ) ) ) ; } } IType [ ] parentInterfaces = TypeUtils . getSuperInterfaces ( type ) ; if ( parentInterfaces . length != <NUM_LIT:0> ) { for ( IType parentInterface : parentInterfaces ) { nodes . add ( new HierarchyNode ( parentInterface , createChildNodes ( parentInterface ) ) ) ; } } return nodes ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . hierarchy ; import java . util . List ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . plugin . jdt . util . TypeInfo ; import org . eclim . plugin . jdt . util . TypeUtils ; import org . eclipse . jdt . core . IType ; public class HierarchyNode { private String name ; private String qualified ; private List < HierarchyNode > children ; public HierarchyNode ( IType type , List < HierarchyNode > children ) throws Exception { this . name = TypeUtils . getTypeSignature ( new TypeInfo ( type , null , null ) ) ; this . qualified = JavaUtils . getFullyQualifiedName ( type ) ; this . children = children ; } public String getName ( ) { return this . name ; } public String getQualified ( ) { return this . qualified ; } public List < HierarchyNode > getChildren ( ) { return this . children ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . doc ; import java . io . StringReader ; import java . lang . reflect . Method ; import java . net . URI ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . util . IOUtils ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . ITypeRoot ; import org . eclipse . jdt . internal . ui . text . java . hover . JavadocBrowserInformationControlInput ; import org . eclipse . jdt . internal . ui . text . java . hover . JavadocHover ; import org . eclipse . jdt . internal . ui . viewsupport . JavaElementLinks ; import org . eclipse . jface . internal . text . html . HTML2TextReader ; import org . eclipse . jface . text . IRegion ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class GetElementDocCommand extends AbstractCommand { private static final Pattern LINKS = Pattern . compile ( "<STR_LIT>" ) ; @ Override public Object execute ( CommandLine commandLine ) throws Exception { IJavaElement [ ] elements = null ; Object url = commandLine . getRawValue ( Options . URL_OPTION ) ; if ( url != null ) { IJavaElement target = JavaElementLinks . parseURI ( new URI ( ( String ) url ) ) ; if ( target != null ) { elements = new IJavaElement [ ] { target } ; } } else { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; int offset = getOffset ( commandLine ) ; int length = commandLine . getIntValue ( Options . LENGTH_OPTION ) ; ICompilationUnit src = JavaUtils . getCompilationUnit ( project , file ) ; elements = src . codeSelect ( offset , length ) ; } if ( elements == null || elements . length == <NUM_LIT:0> ) { return null ; } Method getHoverInfo = JavadocHover . class . getDeclaredMethod ( "<STR_LIT>" , IJavaElement [ ] . class , ITypeRoot . class , IRegion . class , JavadocBrowserInformationControlInput . class ) ; getHoverInfo . setAccessible ( true ) ; JavadocBrowserInformationControlInput info = ( JavadocBrowserInformationControlInput ) getHoverInfo . invoke ( null , elements , null , null , null ) ; if ( info == null ) { return null ; } ArrayList < HashMap < String , String > > links = new ArrayList < HashMap < String , String > > ( ) ; Matcher matcher = LINKS . matcher ( info . getHtml ( ) ) ; StringBuffer buffer = new StringBuffer ( ) ; int index = <NUM_LIT:0> ; while ( matcher . find ( ) ) { String href = matcher . group ( <NUM_LIT:2> ) ; String text = matcher . group ( <NUM_LIT:3> ) ; HashMap < String , String > link = new HashMap < String , String > ( ) ; link . put ( "<STR_LIT>" , href ) ; link . put ( "<STR_LIT:text>" , text ) ; links . add ( link ) ; matcher . appendReplacement ( buffer , "<STR_LIT>" + ( index ++ ) + "<STR_LIT>" ) ; } matcher . appendTail ( buffer ) ; String html = buffer . toString ( ) ; String result = IOUtils . toString ( new HTML2TextReader ( new StringReader ( html ) , null ) ) ; result = result . replaceAll ( "<STR_LIT:r>" , "<STR_LIT>" ) ; result = result . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; HashMap < String , Object > response = new HashMap < String , Object > ( ) ; response . put ( "<STR_LIT:text>" , result ) ; response . put ( "<STR_LIT>" , links ) ; return response ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . doc ; import java . net . URL ; import java . util . ArrayList ; import java . util . regex . Pattern ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . jdt . command . include . ImportUtils ; import org . eclim . plugin . jdt . command . search . SearchCommand ; import org . eclipse . core . resources . IProject ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . search . SearchMatch ; import org . eclipse . jdt . ui . JavaUI ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class DocSearchCommand extends SearchCommand { private static final Pattern ANDROID_JDK_URL = Pattern . compile ( "<STR_LIT>" , Pattern . CASE_INSENSITIVE ) ; @ Override public Object execute ( CommandLine commandLine ) throws Exception { IProject project = ProjectUtils . getProject ( commandLine . getValue ( Options . NAME_OPTION ) ) ; String pattern = commandLine . getValue ( Options . PATTERN_OPTION ) ; ArrayList < String > results = new ArrayList < String > ( ) ; for ( SearchMatch match : executeSearch ( commandLine ) ) { IJavaElement element = ( IJavaElement ) match . getElement ( ) ; if ( element == null ) { continue ; } if ( pattern != null ) { String name = null ; switch ( element . getElementType ( ) ) { case IJavaElement . TYPE : name = ( ( IType ) element ) . getFullyQualifiedName ( ) ; break ; case IJavaElement . METHOD : case IJavaElement . FIELD : name = ( ( IType ) element . getParent ( ) ) . getFullyQualifiedName ( ) ; break ; } if ( name != null ) { name = name . replace ( '<CHAR_LIT>' , '<CHAR_LIT:.>' ) ; if ( ImportUtils . isImportExcluded ( project , name ) ) { continue ; } } } URL url = JavaUI . getJavadocLocation ( element , true ) ; if ( url == null ) { continue ; } if ( ANDROID_JDK_URL . matcher ( url . toString ( ) ) . matches ( ) && ! project . hasNature ( ANDROID_NATURE ) ) { continue ; } results . add ( url . toString ( ) ) ; } return results ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . doc ; import java . io . BufferedReader ; import java . io . File ; import java . io . FileReader ; import java . util . HashMap ; import java . util . List ; import java . util . regex . Pattern ; import org . apache . commons . lang . StringUtils ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . preference . Preferences ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . jdt . util . ASTUtils ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . plugin . jdt . util . MethodUtils ; import org . eclim . plugin . jdt . util . TypeInfo ; import org . eclim . plugin . jdt . util . TypeUtils ; import org . eclim . util . IOUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . jdt . core . IAnnotation ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . core . dom . ASTNode ; import org . eclipse . jdt . core . dom . BodyDeclaration ; import org . eclipse . jdt . core . dom . CompilationUnit ; import org . eclipse . jdt . core . dom . Javadoc ; import org . eclipse . jdt . core . dom . Name ; import org . eclipse . jdt . core . dom . PackageDeclaration ; import org . eclipse . jdt . core . dom . TagElement ; import org . eclipse . jdt . core . dom . TextElement ; import org . eclipse . jdt . core . formatter . CodeFormatter ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class CommentCommand extends AbstractCommand { private static final Pattern THROWS_PATTERN = Pattern . compile ( "<STR_LIT>" ) ; private static final String INHERIT_DOC = "<STR_LIT:{>" + TagElement . TAG_INHERITDOC + "<STR_LIT:}>" ; @ Override public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; int offset = getOffset ( commandLine ) ; ICompilationUnit src = JavaUtils . getCompilationUnit ( project , file ) ; IJavaElement element = src . getElementAt ( offset ) ; if ( element . getElementType ( ) == IJavaElement . IMPORT_DECLARATION ) { return null ; } CompilationUnit cu = ASTUtils . getCompilationUnit ( src , true ) ; ASTNode node = ASTUtils . findNode ( cu , offset , element ) ; if ( node != null ) { comment ( src , node , element ) ; ASTUtils . commitCompilationUnit ( src , cu ) ; cu = ASTUtils . getCompilationUnit ( src , true ) ; node = ASTUtils . findNode ( cu , offset , element ) ; Javadoc javadoc = ( node instanceof PackageDeclaration ) ? ( ( PackageDeclaration ) node ) . getJavadoc ( ) : ( ( BodyDeclaration ) node ) . getJavadoc ( ) ; JavaUtils . format ( src , CodeFormatter . K_COMPILATION_UNIT , javadoc . getStartPosition ( ) , javadoc . getLength ( ) ) ; } return null ; } private void comment ( ICompilationUnit src , ASTNode node , IJavaElement element ) throws Exception { Javadoc javadoc = null ; boolean isNew = false ; if ( node instanceof PackageDeclaration ) { javadoc = ( ( PackageDeclaration ) node ) . getJavadoc ( ) ; if ( javadoc == null ) { isNew = true ; javadoc = node . getAST ( ) . newJavadoc ( ) ; ( ( PackageDeclaration ) node ) . setJavadoc ( javadoc ) ; } } else { javadoc = ( ( BodyDeclaration ) node ) . getJavadoc ( ) ; if ( javadoc == null ) { isNew = true ; javadoc = node . getAST ( ) . newJavadoc ( ) ; ( ( BodyDeclaration ) node ) . setJavadoc ( javadoc ) ; } } switch ( node . getNodeType ( ) ) { case ASTNode . PACKAGE_DECLARATION : commentPackage ( src , javadoc , element , isNew ) ; break ; case ASTNode . ENUM_DECLARATION : case ASTNode . TYPE_DECLARATION : commentType ( src , javadoc , element , isNew ) ; break ; case ASTNode . METHOD_DECLARATION : commentMethod ( src , javadoc , element , isNew ) ; break ; default : commentOther ( src , javadoc , element , isNew ) ; } } private void commentPackage ( ICompilationUnit src , Javadoc javadoc , IJavaElement element , boolean isNew ) throws Exception { IProject project = element . getJavaProject ( ) . getProject ( ) ; String copyright = getPreferences ( ) . getValue ( project , Preferences . PROJECT_COPYRIGHT_PREFERENCE ) ; if ( copyright != null && copyright . trim ( ) . length ( ) > <NUM_LIT:0> ) { File file = new File ( ProjectUtils . getFilePath ( project , copyright ) ) ; if ( ! file . exists ( ) ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , file ) ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) List < TagElement > tags = javadoc . tags ( ) ; tags . clear ( ) ; BufferedReader reader = null ; try { reader = new BufferedReader ( new FileReader ( file ) ) ; String line = null ; while ( ( line = reader . readLine ( ) ) != null ) { addTag ( javadoc , tags . size ( ) , null , line ) ; } } finally { IOUtils . closeQuietly ( reader ) ; } } else { commentOther ( src , javadoc , element , isNew ) ; } } private void commentType ( ICompilationUnit src , Javadoc javadoc , IJavaElement element , boolean isNew ) throws Exception { if ( element . getParent ( ) . getElementType ( ) == IJavaElement . COMPILATION_UNIT ) { @ SuppressWarnings ( "<STR_LIT:unchecked>" ) List < TagElement > tags = javadoc . tags ( ) ; IProject project = element . getJavaProject ( ) . getProject ( ) ; if ( isNew ) { addTag ( javadoc , tags . size ( ) , null , null ) ; addTag ( javadoc , tags . size ( ) , null , null ) ; addTag ( javadoc , tags . size ( ) , TagElement . TAG_AUTHOR , getAuthor ( project ) ) ; String version = getPreferences ( ) . getValue ( project , "<STR_LIT>" ) ; if ( version != null && ! StringUtils . EMPTY . equals ( version . trim ( ) ) ) { version = StringUtils . replace ( version , "<STR_LIT>" , "<STR_LIT:$>" ) ; addTag ( javadoc , tags . size ( ) , TagElement . TAG_VERSION , version ) ; } } else { int index = - <NUM_LIT:1> ; String author = getAuthor ( project ) ; for ( int ii = <NUM_LIT:0> ; ii < tags . size ( ) ; ii ++ ) { TagElement tag = ( TagElement ) tags . get ( ii ) ; if ( TagElement . TAG_AUTHOR . equals ( tag . getTagName ( ) ) ) { String authorText = tag . fragments ( ) . size ( ) > <NUM_LIT:0> ? ( ( TextElement ) tag . fragments ( ) . get ( <NUM_LIT:0> ) ) . getText ( ) : null ; if ( authorText != null && author . trim ( ) . equals ( authorText . trim ( ) ) ) { index = - <NUM_LIT:1> ; break ; } index = ii + <NUM_LIT:1> ; } else if ( tag . getTagName ( ) != null ) { if ( index == - <NUM_LIT:1> ) { index = ii ; } } } if ( index > - <NUM_LIT:1> ) { TagElement authorTag = javadoc . getAST ( ) . newTagElement ( ) ; TextElement authorText = javadoc . getAST ( ) . newTextElement ( ) ; authorText . setText ( author ) ; authorTag . setTagName ( TagElement . TAG_AUTHOR ) ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) List < ASTNode > fragments = authorTag . fragments ( ) ; fragments . add ( authorText ) ; tags . add ( index , authorTag ) ; } boolean versionExists = false ; for ( int ii = <NUM_LIT:0> ; ii < tags . size ( ) ; ii ++ ) { TagElement tag = ( TagElement ) tags . get ( ii ) ; if ( TagElement . TAG_VERSION . equals ( tag . getTagName ( ) ) ) { versionExists = true ; break ; } } if ( ! versionExists ) { String version = getPreferences ( ) . getValue ( project , "<STR_LIT>" ) ; version = StringUtils . replace ( version , "<STR_LIT>" , "<STR_LIT:$>" ) ; addTag ( javadoc , tags . size ( ) , TagElement . TAG_VERSION , version ) ; } } } else { commentOther ( src , javadoc , element , isNew ) ; } } private void commentMethod ( ICompilationUnit src , Javadoc javadoc , IJavaElement element , boolean isNew ) throws Exception { @ SuppressWarnings ( "<STR_LIT:unchecked>" ) List < TagElement > tags = javadoc . tags ( ) ; IMethod method = ( IMethod ) element ; IType type = method . getDeclaringType ( ) ; boolean hasOverride = false ; IAnnotation [ ] annotations = method . getAnnotations ( ) ; for ( IAnnotation annotation : annotations ) { for ( String [ ] result : type . resolveType ( annotation . getElementName ( ) ) ) { if ( result [ <NUM_LIT:0> ] . equals ( "<STR_LIT>" ) && result [ <NUM_LIT:1> ] . equals ( "<STR_LIT>" ) ) { hasOverride = true ; break ; } } } if ( isNew ) { IType parentType = null ; TypeInfo [ ] types = TypeUtils . getSuperTypes ( type ) ; for ( TypeInfo info : types ) { if ( MethodUtils . containsMethod ( info , method ) ) { parentType = info . getType ( ) ; break ; } } if ( parentType != null ) { if ( ! hasOverride ) { addTag ( javadoc , tags . size ( ) , null , INHERIT_DOC ) ; String typeName = JavaUtils . getCompilationUnitRelativeTypeName ( src , parentType ) ; StringBuffer signature = new StringBuffer ( ) ; signature . append ( typeName ) . append ( '<CHAR_LIT>' ) . append ( MethodUtils . getMinimalMethodSignature ( method , null ) ) ; addTag ( javadoc , tags . size ( ) , TagElement . TAG_SEE , signature . toString ( ) ) ; } } else { addTag ( javadoc , tags . size ( ) , null , null ) ; addTag ( javadoc , tags . size ( ) , null , null ) ; } } boolean update = true ; for ( TagElement tag : tags ) { if ( tag . getTagName ( ) == null && tag . fragments ( ) . size ( ) > <NUM_LIT:0> ) { if ( INHERIT_DOC . equals ( tag . fragments ( ) . get ( <NUM_LIT:0> ) . toString ( ) ) ) { update = false ; break ; } } } if ( update ) { addUpdateParamTags ( javadoc , method , isNew ) ; addUpdateReturnTag ( javadoc , method , isNew ) ; addUpdateThrowsTags ( javadoc , method , isNew ) ; } } private void commentOther ( ICompilationUnit src , Javadoc javadoc , IJavaElement element , boolean isNew ) throws Exception { if ( isNew ) { addTag ( javadoc , <NUM_LIT:0> , null , null ) ; } } private void addUpdateParamTags ( Javadoc javadoc , IMethod method , boolean isNew ) throws Exception { @ SuppressWarnings ( "<STR_LIT:unchecked>" ) List < TagElement > tags = javadoc . tags ( ) ; String [ ] params = method . getParameterNames ( ) ; if ( isNew ) { for ( int ii = <NUM_LIT:0> ; ii < params . length ; ii ++ ) { addTag ( javadoc , tags . size ( ) , TagElement . TAG_PARAM , params [ ii ] ) ; } } else { int index = <NUM_LIT:0> ; HashMap < String , TagElement > current = new HashMap < String , TagElement > ( ) ; for ( int ii = <NUM_LIT:0> ; ii < tags . size ( ) ; ii ++ ) { TagElement tag = ( TagElement ) tags . get ( ii ) ; if ( TagElement . TAG_PARAM . equals ( tag . getTagName ( ) ) ) { if ( current . size ( ) == <NUM_LIT:0> ) { index = ii ; } Object element = tag . fragments ( ) . size ( ) > <NUM_LIT:0> ? tag . fragments ( ) . get ( <NUM_LIT:0> ) : null ; if ( element != null && element instanceof Name ) { String name = ( ( Name ) element ) . getFullyQualifiedName ( ) ; current . put ( name , tag ) ; } else { current . put ( String . valueOf ( ii ) , tag ) ; } } else { if ( current . size ( ) > <NUM_LIT:0> ) { break ; } if ( tag . getTagName ( ) == null ) { index = ii + <NUM_LIT:1> ; } } } if ( current . size ( ) > <NUM_LIT:0> ) { for ( int ii = <NUM_LIT:0> ; ii < params . length ; ii ++ ) { if ( current . containsKey ( params [ ii ] ) ) { TagElement tag = ( TagElement ) current . get ( params [ ii ] ) ; int currentIndex = tags . indexOf ( tag ) ; if ( currentIndex != ii ) { tags . remove ( tag ) ; tags . add ( index + ii , tag ) ; } current . remove ( params [ ii ] ) ; } else { addTag ( javadoc , index + ii , TagElement . TAG_PARAM , params [ ii ] ) ; } } for ( TagElement tag : current . values ( ) ) { tags . remove ( tag ) ; } } else { for ( int ii = <NUM_LIT:0> ; ii < params . length ; ii ++ ) { addTag ( javadoc , index + ii , TagElement . TAG_PARAM , params [ ii ] ) ; } } } } private void addUpdateReturnTag ( Javadoc javadoc , IMethod method , boolean isNew ) throws Exception { @ SuppressWarnings ( "<STR_LIT:unchecked>" ) List < TagElement > tags = javadoc . tags ( ) ; if ( ! method . isConstructor ( ) ) { String returnType = Signature . getSignatureSimpleName ( method . getReturnType ( ) ) ; if ( ! "<STR_LIT>" . equals ( returnType ) ) { if ( isNew ) { addTag ( javadoc , tags . size ( ) , TagElement . TAG_RETURN , null ) ; } else { int index = tags . size ( ) ; for ( int ii = tags . size ( ) - <NUM_LIT:1> ; ii >= <NUM_LIT:0> ; ii -- ) { TagElement tag = ( TagElement ) tags . get ( ii ) ; if ( TagElement . TAG_RETURN . equals ( tag . getTagName ( ) ) ) { index = - <NUM_LIT:1> ; break ; } if ( TagElement . TAG_PARAM . equals ( tag . getTagName ( ) ) || tag . getTagName ( ) == null ) { index = ii + <NUM_LIT:1> ; break ; } index = ii ; } if ( index > - <NUM_LIT:1> ) { addTag ( javadoc , index , TagElement . TAG_RETURN , null ) ; } } } else { for ( int ii = tags . size ( ) - <NUM_LIT:1> ; ii >= <NUM_LIT:0> ; ii -- ) { TagElement tag = ( TagElement ) tags . get ( ii ) ; if ( TagElement . TAG_RETURN . equals ( tag . getTagName ( ) ) ) { tags . remove ( tag ) ; } if ( TagElement . TAG_PARAM . equals ( tag . getTagName ( ) ) || tag . getTagName ( ) == null ) { break ; } } } } } private void addUpdateThrowsTags ( Javadoc javadoc , IMethod method , boolean isNew ) throws Exception { @ SuppressWarnings ( "<STR_LIT:unchecked>" ) List < TagElement > tags = javadoc . tags ( ) ; String [ ] exceptions = method . getExceptionTypes ( ) ; if ( isNew && exceptions . length > <NUM_LIT:0> ) { addTag ( javadoc , tags . size ( ) , null , null ) ; for ( int ii = <NUM_LIT:0> ; ii < exceptions . length ; ii ++ ) { addTag ( javadoc , tags . size ( ) , TagElement . TAG_THROWS , Signature . getSignatureSimpleName ( exceptions [ ii ] ) ) ; } } else { HashMap < String , TagElement > current = new HashMap < String , TagElement > ( ) ; int index = tags . size ( ) ; for ( int ii = tags . size ( ) - <NUM_LIT:1> ; ii >= <NUM_LIT:0> ; ii -- ) { TagElement tag = ( TagElement ) tags . get ( ii ) ; if ( TagElement . TAG_THROWS . equals ( tag . getTagName ( ) ) ) { index = index == tags . size ( ) ? ii + <NUM_LIT:1> : index ; Name name = tag . fragments ( ) . size ( ) > <NUM_LIT:0> ? ( Name ) tag . fragments ( ) . get ( <NUM_LIT:0> ) : null ; if ( name != null ) { String text = name . getFullyQualifiedName ( ) ; String key = THROWS_PATTERN . matcher ( text ) . replaceFirst ( "<STR_LIT>" ) ; current . put ( key , tag ) ; } else { current . put ( String . valueOf ( ii ) , tag ) ; } } if ( TagElement . TAG_PARAM . equals ( tag . getTagName ( ) ) || TagElement . TAG_RETURN . equals ( tag . getTagName ( ) ) || tag . getTagName ( ) == null ) { break ; } } for ( int ii = <NUM_LIT:0> ; ii < exceptions . length ; ii ++ ) { String name = Signature . getSignatureSimpleName ( exceptions [ ii ] ) ; if ( ! current . containsKey ( name ) ) { addTag ( javadoc , index , TagElement . TAG_THROWS , name ) ; } else { current . remove ( name ) ; } } for ( TagElement tag : current . values ( ) ) { tags . remove ( tag ) ; } } } private String getAuthor ( IProject project ) throws Exception { String username = getPreferences ( ) . getValue ( project . getProject ( ) , Preferences . USERNAME_PREFERENCE ) ; String email = getPreferences ( ) . getValue ( project . getProject ( ) , Preferences . USEREMAIL_PREFERENCE ) ; StringBuffer author = new StringBuffer ( ) ; if ( username != null && username . trim ( ) . length ( ) > <NUM_LIT:0> ) { author . append ( username ) ; if ( email != null && email . trim ( ) . length ( ) > <NUM_LIT:0> ) { author . append ( "<STR_LIT:U+0020(>" ) . append ( email ) . append ( "<STR_LIT:)>" ) ; } } else if ( email != null && email . trim ( ) . length ( ) > <NUM_LIT:0> ) { author . append ( email ) ; } return author . toString ( ) ; } private void addTag ( Javadoc javadoc , int index , String name , String text ) throws Exception { TagElement tag = javadoc . getAST ( ) . newTagElement ( ) ; tag . setTagName ( name ) ; if ( text != null ) { TextElement textElement = javadoc . getAST ( ) . newTextElement ( ) ; textElement . setText ( text ) ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) List < ASTNode > fragments = tag . fragments ( ) ; fragments . add ( textElement ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) List < TagElement > tags = javadoc . tags ( ) ; tags . add ( index , tag ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . doc ; import java . net . URL ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclipse . jdt . internal . ui . actions . OpenBrowserUtil ; import org . eclipse . swt . widgets . Display ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class DocUrlOpenCommand extends AbstractCommand { @ Override public Object execute ( CommandLine commandLine ) throws Exception { String url = commandLine . getValue ( Options . URL_OPTION ) ; OpenBrowserUtil . openExternal ( new URL ( url ) , Display . getDefault ( ) ) ; return null ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . doc ; import java . io . File ; import org . apache . tools . ant . BuildLogger ; import org . apache . tools . ant . DefaultLogger ; import org . apache . tools . ant . Project ; import org . apache . tools . ant . taskdefs . Javadoc ; import org . apache . tools . ant . types . FileSet ; import org . apache . tools . ant . types . Path ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . jdt . util . ClasspathUtils ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . util . StringUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . jdt . core . IJavaProject ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class JavadocCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; String files = commandLine . getValue ( Options . FILE_OPTION ) ; boolean debug = commandLine . hasOption ( Options . DEBUG_OPTION ) ; IProject project = ProjectUtils . getProject ( projectName ) ; IJavaProject javaProject = JavaUtils . getJavaProject ( project ) ; String dest = getPreferences ( ) . getValue ( project , "<STR_LIT>" ) ; String packageNames = getPreferences ( ) . getValue ( project , "<STR_LIT>" ) ; Project antProject = new Project ( ) ; BuildLogger buildLogger = new DefaultLogger ( ) ; buildLogger . setMessageOutputLevel ( debug ? Project . MSG_DEBUG : Project . MSG_INFO ) ; buildLogger . setOutputPrintStream ( getContext ( ) . out ) ; buildLogger . setErrorPrintStream ( getContext ( ) . err ) ; antProject . addBuildListener ( buildLogger ) ; antProject . setBasedir ( ProjectUtils . getPath ( project ) ) ; Javadoc javadoc = new Javadoc ( ) ; javadoc . setTaskName ( "<STR_LIT>" ) ; javadoc . setProject ( antProject ) ; javadoc . setDestdir ( new File ( ProjectUtils . getFilePath ( project , dest ) ) ) ; if ( packageNames != null && ! packageNames . trim ( ) . equals ( StringUtils . EMPTY ) ) { javadoc . setPackagenames ( packageNames ) ; } Path classpath = new Path ( antProject ) ; String [ ] paths = ClasspathUtils . getClasspath ( javaProject ) ; for ( String path : paths ) { Path . PathElement pe = classpath . createPathElement ( ) ; pe . setPath ( path ) ; } javadoc . setClasspath ( classpath ) ; if ( files == null ) { String sourcepath = getPreferences ( ) . getValue ( project , "<STR_LIT>" ) ; if ( sourcepath != null && ! sourcepath . trim ( ) . equals ( StringUtils . EMPTY ) ) { paths = StringUtils . split ( sourcepath , "<STR_LIT:U+0020>" ) ; } else { paths = ClasspathUtils . getSrcPaths ( javaProject ) ; } for ( String path : paths ) { FileSet fileset = new FileSet ( ) ; fileset . setProject ( antProject ) ; fileset . setDir ( new File ( ProjectUtils . getFilePath ( project , path ) ) ) ; fileset . setIncludes ( "<STR_LIT>" ) ; javadoc . addFileset ( fileset ) ; } } else { paths = StringUtils . split ( files ) ; for ( String path : paths ) { javadoc . addSource ( new Javadoc . SourceFile ( new File ( ProjectUtils . getFilePath ( project , path ) ) ) ) ; } } javadoc . execute ( ) ; return null ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . log4j ; import java . util . ArrayList ; import java . util . List ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclim . command . Options ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . IType ; import org . xml . sax . Attributes ; import org . xml . sax . Locator ; import org . xml . sax . SAXException ; import org . xml . sax . helpers . DefaultHandler ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class ValidateCommand extends org . eclim . plugin . core . command . xml . ValidateCommand { public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; Log4jHandler handler = new Log4jHandler ( JavaUtils . getJavaProject ( project ) , file ) ; List < Error > errors = super . validate ( project , file , false , handler ) ; errors . addAll ( handler . getErrors ( ) ) ; return errors ; } private static class Log4jHandler extends DefaultHandler { private static final String CATEGORY = "<STR_LIT>" ; private static final String CLASS = "<STR_LIT:class>" ; private static final String LEVEL = "<STR_LIT>" ; private static final String LOGGER = "<STR_LIT>" ; private static final String NAME = "<STR_LIT:name>" ; private static final String PRIORITY = "<STR_LIT>" ; private static final String VALUE = "<STR_LIT:value>" ; private static final ArrayList < String > LEVELS = new ArrayList < String > ( ) ; static { LEVELS . add ( "<STR_LIT>" ) ; LEVELS . add ( "<STR_LIT>" ) ; LEVELS . add ( "<STR_LIT>" ) ; LEVELS . add ( "<STR_LIT>" ) ; } private Locator locator ; private IJavaProject project ; private String file ; private ArrayList < Error > errors = new ArrayList < Error > ( ) ; public Log4jHandler ( IJavaProject project , String file ) throws Exception { this . project = project ; this . file = ProjectUtils . getFilePath ( project . getProject ( ) , file ) ; } public void setDocumentLocator ( Locator locator ) { super . setDocumentLocator ( locator ) ; this . locator = locator ; } public void startElement ( String uri , String localName , String qName , Attributes atts ) throws SAXException { try { if ( CATEGORY . equals ( localName ) || LOGGER . equals ( localName ) ) { String name = atts . getValue ( NAME ) ; if ( name != null ) { IPackageFragment pkg = getPackage ( name ) ; if ( pkg == null ) { IType type = project . findType ( name ) ; if ( type == null || ! type . exists ( ) ) { String message = Services . getMessage ( "<STR_LIT>" , name ) ; errors . add ( new Error ( message , file , locator . getLineNumber ( ) , <NUM_LIT:1> , false ) ) ; } } } } else if ( PRIORITY . equals ( localName ) || LEVEL . equals ( localName ) ) { String value = atts . getValue ( VALUE ) ; if ( atts . getValue ( CLASS ) == null && value != null ) { if ( ! LEVELS . contains ( value . trim ( ) . toLowerCase ( ) ) ) { String message = Services . getMessage ( "<STR_LIT>" , value ) ; errors . add ( new Error ( message , file , locator . getLineNumber ( ) , <NUM_LIT:1> , false ) ) ; } } } String classname = atts . getValue ( CLASS ) ; if ( classname != null ) { IType type = project . findType ( classname ) ; if ( type == null || ! type . exists ( ) ) { String message = Services . getMessage ( "<STR_LIT>" , project . getElementName ( ) , classname ) ; errors . add ( new Error ( message , file , locator . getLineNumber ( ) , <NUM_LIT:1> , false ) ) ; } } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } public List < Error > getErrors ( ) { return errors ; } private IPackageFragment getPackage ( String name ) throws Exception { IPackageFragmentRoot [ ] roots = project . getAllPackageFragmentRoots ( ) ; for ( int ii = <NUM_LIT:0> ; ii < roots . length ; ii ++ ) { IPackageFragment fragment = roots [ ii ] . getPackageFragment ( name ) ; if ( fragment != null && fragment . exists ( ) ) { return fragment ; } } return null ; } } } </s>
|
<s> package org . eclim . plugin . jdt . command . complete ; import java . util . ArrayList ; import java . util . List ; import org . eclim . command . Error ; import org . eclim . plugin . jdt . command . include . ImportUtils ; import org . eclim . plugin . jdt . command . search . SearchRequestor ; import org . eclim . util . file . FileOffsets ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . runtime . IStatus ; import org . eclipse . core . runtime . Status ; import org . eclipse . jdt . core . CompletionProposal ; import org . eclipse . jdt . core . Flags ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . compiler . IProblem ; import org . eclipse . jdt . core . search . IJavaSearchConstants ; import org . eclipse . jdt . core . search . IJavaSearchScope ; import org . eclipse . jdt . core . search . SearchEngine ; import org . eclipse . jdt . core . search . SearchMatch ; import org . eclipse . jdt . core . search . SearchParticipant ; import org . eclipse . jdt . core . search . SearchPattern ; import org . eclipse . jdt . internal . ui . JavaPlugin ; public class CompletionProposalCollector extends org . eclipse . jdt . ui . text . java . CompletionProposalCollector { private ArrayList < CompletionProposal > proposals = new ArrayList < CompletionProposal > ( ) ; private ArrayList < String > imports ; private Error error ; public CompletionProposalCollector ( ICompilationUnit cu ) { super ( cu ) ; } public void accept ( CompletionProposal proposal ) { try { if ( isFiltered ( proposal ) ) { return ; } if ( proposal . getKind ( ) != CompletionProposal . POTENTIAL_METHOD_DECLARATION ) { switch ( proposal . getKind ( ) ) { case CompletionProposal . KEYWORD : case CompletionProposal . PACKAGE_REF : case CompletionProposal . TYPE_REF : case CompletionProposal . FIELD_REF : case CompletionProposal . METHOD_REF : case CompletionProposal . METHOD_NAME_REFERENCE : case CompletionProposal . METHOD_DECLARATION : case CompletionProposal . ANONYMOUS_CLASS_DECLARATION : case CompletionProposal . LABEL_REF : case CompletionProposal . LOCAL_VARIABLE_REF : case CompletionProposal . VARIABLE_DECLARATION : case CompletionProposal . ANNOTATION_ATTRIBUTE_REF : case CompletionProposal . POTENTIAL_METHOD_DECLARATION : proposals . add ( proposal ) ; super . accept ( proposal ) ; break ; default : } } } catch ( IllegalArgumentException e ) { JavaPlugin . log ( new Status ( IStatus . ERROR , JavaPlugin . getPluginId ( ) , IStatus . OK , "<STR_LIT>" + String . valueOf ( proposal . getCompletion ( ) ) , e ) ) ; } } public CompletionProposal getProposal ( int index ) { return ( CompletionProposal ) proposals . get ( index ) ; } public void completionFailure ( IProblem problem ) { ICompilationUnit src = getCompilationUnit ( ) ; IJavaProject javaProject = src . getJavaProject ( ) ; IProject project = javaProject . getProject ( ) ; if ( problem . getID ( ) == IProblem . UndefinedType || problem . getID ( ) == IProblem . UnresolvedVariable ) { try { SearchPattern pattern = SearchPattern . createPattern ( problem . getArguments ( ) [ <NUM_LIT:0> ] , IJavaSearchConstants . TYPE , IJavaSearchConstants . DECLARATIONS , SearchPattern . R_EXACT_MATCH | SearchPattern . R_CASE_SENSITIVE ) ; IJavaSearchScope scope = SearchEngine . createJavaSearchScope ( new IJavaElement [ ] { javaProject } ) ; SearchRequestor requestor = new SearchRequestor ( ) ; SearchEngine engine = new SearchEngine ( ) ; SearchParticipant [ ] participants = new SearchParticipant [ ] { SearchEngine . getDefaultSearchParticipant ( ) } ; engine . search ( pattern , participants , scope , requestor , null ) ; if ( requestor . getMatches ( ) . size ( ) > <NUM_LIT:0> ) { imports = new ArrayList < String > ( ) ; for ( SearchMatch match : requestor . getMatches ( ) ) { if ( match . getAccuracy ( ) != SearchMatch . A_ACCURATE ) { continue ; } IJavaElement element = ( IJavaElement ) match . getElement ( ) ; String name = null ; switch ( element . getElementType ( ) ) { case IJavaElement . TYPE : IType type = ( IType ) element ; if ( Flags . isPublic ( type . getFlags ( ) ) ) { name = type . getFullyQualifiedName ( ) ; } break ; case IJavaElement . METHOD : case IJavaElement . FIELD : name = ( ( IType ) element . getParent ( ) ) . getFullyQualifiedName ( ) + '<CHAR_LIT:.>' + element . getElementName ( ) ; break ; } if ( name != null ) { name = name . replace ( '<CHAR_LIT>' , '<CHAR_LIT:.>' ) ; if ( ! ImportUtils . isImportExcluded ( project , name ) ) { imports . add ( name ) ; } } } } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } IResource resource = src . getResource ( ) ; String relativeName = resource . getProjectRelativePath ( ) . toString ( ) ; if ( new String ( problem . getOriginatingFileName ( ) ) . endsWith ( relativeName ) ) { String filename = resource . getLocation ( ) . toString ( ) ; if ( problem . getID ( ) == IProblem . PublicClassMustMatchFileName && filename . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) { return ; } FileOffsets offsets = FileOffsets . compile ( filename ) ; int [ ] lineColumn = offsets . offsetToLineColumn ( problem . getSourceStart ( ) ) ; error = new Error ( problem . getMessage ( ) , filename . replace ( "<STR_LIT>" , "<STR_LIT>" ) , lineColumn [ <NUM_LIT:0> ] , lineColumn [ <NUM_LIT:1> ] , problem . isWarning ( ) ) ; } } public List < String > getImports ( ) { return imports ; } public Error getError ( ) { return error ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . complete ; import java . text . Collator ; import java . util . Comparator ; import java . util . Locale ; import org . eclim . plugin . core . command . complete . CodeCompleteResult ; public class CompletionComparator implements Comparator < CodeCompleteResult > { public int compare ( CodeCompleteResult o1 , CodeCompleteResult o2 ) { if ( o1 == null && o2 == null ) { return <NUM_LIT:0> ; } else if ( o2 == null ) { return - <NUM_LIT:1> ; } else if ( o1 == null ) { return <NUM_LIT:1> ; } if ( o1 . getType ( ) == CodeCompleteResult . KEYWORD && o2 . getType ( ) != CodeCompleteResult . KEYWORD ) { return <NUM_LIT:1> ; } else if ( o2 . getType ( ) == CodeCompleteResult . KEYWORD && o1 . getType ( ) != CodeCompleteResult . KEYWORD ) { return - <NUM_LIT:1> ; } return Collator . getInstance ( Locale . US ) . compare ( new String ( o1 . getCompletion ( ) ) , new String ( o2 . getCompletion ( ) ) ) ; } public boolean equals ( Object obj ) { if ( obj instanceof CompletionComparator ) { return true ; } return false ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . complete ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Comparator ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . complete . AbstractCodeCompleteCommand ; import org . eclim . plugin . core . command . complete . CodeCompleteResult ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclipse . jdt . core . CompletionProposal ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . internal . ui . text . java . JavaCompletionProposal ; import org . eclipse . jdt . internal . ui . text . java . LazyJavaCompletionProposal ; import org . eclipse . jdt . ui . text . java . IJavaCompletionProposal ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class CodeCompleteCommand extends AbstractCodeCompleteCommand { private static final Comparator < CodeCompleteResult > COMPLETION_COMPARATOR = new CompletionComparator ( ) ; private static String COMPACT = "<STR_LIT>" ; public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; int offset = getOffset ( commandLine ) ; ICompilationUnit src = JavaUtils . getCompilationUnit ( project , file ) ; CompletionProposalCollector collector = new CompletionProposalCollector ( src ) ; src . codeComplete ( offset , collector ) ; IJavaCompletionProposal [ ] proposals = collector . getJavaCompletionProposals ( ) ; ArrayList < CodeCompleteResult > results = new ArrayList < CodeCompleteResult > ( ) ; for ( int ii = <NUM_LIT:0> ; ii < proposals . length ; ii ++ ) { results . add ( createCompletionResult ( collector , ii , proposals [ ii ] ) ) ; } Collections . sort ( results , COMPLETION_COMPARATOR ) ; String layout = commandLine . getValue ( Options . LAYOUT_OPTION ) ; if ( COMPACT . equals ( layout ) && results . size ( ) > <NUM_LIT:0> ) { results = compact ( results ) ; } return new CodeCompleteResponse ( results , collector . getError ( ) , collector . getImports ( ) ) ; } protected CodeCompleteResult createCompletionResult ( CompletionProposalCollector collector , int index , IJavaCompletionProposal proposal ) { String completion = null ; String menu = proposal . getDisplayString ( ) ; if ( proposal instanceof JavaCompletionProposal ) { JavaCompletionProposal lazy = ( JavaCompletionProposal ) proposal ; completion = lazy . getReplacementString ( ) ; } else if ( proposal instanceof LazyJavaCompletionProposal ) { LazyJavaCompletionProposal lazy = ( LazyJavaCompletionProposal ) proposal ; completion = lazy . getReplacementString ( ) ; } int kind = collector . getProposal ( index ) . getKind ( ) ; switch ( kind ) { case CompletionProposal . METHOD_REF : if ( menu . lastIndexOf ( '<CHAR_LIT:)>' ) > menu . lastIndexOf ( '<CHAR_LIT:(>' ) + <NUM_LIT:1> && ( completion . length ( ) > <NUM_LIT:0> && completion . charAt ( completion . length ( ) - <NUM_LIT:1> ) == '<CHAR_LIT:)>' ) ) { completion = completion . substring ( <NUM_LIT:0> , completion . length ( ) - <NUM_LIT:1> ) ; } break ; case CompletionProposal . TYPE_REF : int idx = completion . lastIndexOf ( '<CHAR_LIT:.>' ) ; if ( idx != - <NUM_LIT:1> ) { completion = completion . substring ( idx + <NUM_LIT:1> ) ; } break ; } if ( "<STR_LIT:class>" . equals ( completion ) ) { kind = CompletionProposal . KEYWORD ; } String type = "<STR_LIT>" ; switch ( kind ) { case CompletionProposal . TYPE_REF : type = CodeCompleteResult . TYPE ; break ; case CompletionProposal . FIELD_REF : case CompletionProposal . LOCAL_VARIABLE_REF : type = CodeCompleteResult . VARIABLE ; type = CodeCompleteResult . VARIABLE ; break ; case CompletionProposal . METHOD_REF : type = CodeCompleteResult . FUNCTION ; break ; case CompletionProposal . KEYWORD : type = CodeCompleteResult . KEYWORD ; break ; } return new CodeCompleteResult ( completion , menu , menu , type ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . complete ; import java . util . List ; import org . eclim . command . Error ; import org . eclim . plugin . core . command . complete . CodeCompleteResult ; @ SuppressWarnings ( "<STR_LIT:unused>" ) public class CodeCompleteResponse { private List < CodeCompleteResult > completions ; private Error error ; private List < String > imports ; public CodeCompleteResponse ( List < CodeCompleteResult > completions , Error error , List < String > imports ) { this . completions = completions ; this . error = error ; this . imports = imports ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . launching ; import java . util . ArrayList ; import java . util . HashMap ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclipse . jdt . launching . AbstractVMInstall ; import org . eclipse . jdt . launching . IVMInstall ; import org . eclipse . jdt . launching . IVMInstallType ; import org . eclipse . jdt . launching . JavaRuntime ; @ Command ( name = "<STR_LIT>" ) public class ListVmInstalls extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { ArrayList < HashMap < String , Object > > results = new ArrayList < HashMap < String , Object > > ( ) ; AbstractVMInstall defaultInstall = ( AbstractVMInstall ) JavaRuntime . getDefaultVMInstall ( ) ; IVMInstallType [ ] types = JavaRuntime . getVMInstallTypes ( ) ; for ( IVMInstallType type : types ) { IVMInstall [ ] installs = type . getVMInstalls ( ) ; if ( installs . length > <NUM_LIT:0> ) { for ( IVMInstall iinstall : installs ) { AbstractVMInstall install = ( AbstractVMInstall ) iinstall ; HashMap < String , Object > result = new HashMap < String , Object > ( ) ; results . add ( result ) ; result . put ( "<STR_LIT:type>" , type . getName ( ) ) ; result . put ( "<STR_LIT:name>" , install . getName ( ) ) ; result . put ( "<STR_LIT>" , install . getInstallLocation ( ) . getPath ( ) ) ; result . put ( "<STR_LIT:version>" , install . getJavaVersion ( ) ) ; result . put ( "<STR_LIT>" , install . getVMArgs ( ) ) ; result . put ( "<STR_LIT:default>" , install . equals ( defaultInstall ) ) ; } } } return results ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . launching ; import java . io . File ; import java . io . InputStream ; import java . io . IOException ; import java . io . OutputStream ; import java . lang . reflect . Method ; import java . util . ArrayList ; import org . apache . tools . ant . BuildException ; import org . apache . tools . ant . BuildLogger ; import org . apache . tools . ant . DefaultLogger ; import org . apache . tools . ant . Project ; import org . apache . tools . ant . Task ; import org . apache . tools . ant . taskdefs . ExecuteStreamHandler ; import org . apache . tools . ant . taskdefs . Java ; import org . apache . tools . ant . taskdefs . PumpStreamHandler ; import org . apache . tools . ant . taskdefs . Redirector ; import org . apache . tools . ant . taskdefs . StreamPumper ; import org . apache . tools . ant . types . Commandline . Argument ; import org . apache . tools . ant . types . Environment . Variable ; import org . apache . tools . ant . types . Path ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . jdt . util . ClasspathUtils ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . util . StringUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IncrementalProjectBuilder ; import org . eclipse . jdt . core . Flags ; import org . eclipse . jdt . core . IClasspathEntry ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IPackageDeclaration ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . core . search . IJavaSearchConstants ; import org . eclipse . jdt . core . search . IJavaSearchScope ; import org . eclipse . jdt . core . search . SearchEngine ; import org . eclipse . jdt . core . search . SearchMatch ; import org . eclipse . jdt . core . search . SearchParticipant ; import org . eclipse . jdt . core . search . SearchPattern ; import org . eclipse . jdt . core . search . SearchRequestor ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class JavaCommand extends AbstractCommand { private static final String WORKINGDIR_OPTION = "<STR_LIT>" ; private static final String VMARGS_OPTION = "<STR_LIT>" ; private static final String SYSPROPS_OPTION = "<STR_LIT:s>" ; private static final String ENVARGS_OPTION = "<STR_LIT:e>" ; public Object execute ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; String mainClass = commandLine . getValue ( Options . CLASSNAME_OPTION ) ; boolean debug = commandLine . hasOption ( Options . DEBUG_OPTION ) ; String workingDir = commandLine . getValue ( WORKINGDIR_OPTION ) ; IProject project = ProjectUtils . getProject ( projectName ) ; project . build ( IncrementalProjectBuilder . INCREMENTAL_BUILD , null ) ; IJavaProject javaProject = JavaUtils . getJavaProject ( project ) ; Project antProject = new Project ( ) ; BuildLogger buildLogger = new DefaultLogger ( ) ; buildLogger . setMessageOutputLevel ( debug ? Project . MSG_DEBUG : Project . MSG_INFO ) ; buildLogger . setOutputPrintStream ( getContext ( ) . out ) ; buildLogger . setErrorPrintStream ( getContext ( ) . err ) ; antProject . addBuildListener ( buildLogger ) ; antProject . setBasedir ( ProjectUtils . getPath ( project ) ) ; antProject . setDefaultInputStream ( System . in ) ; if ( mainClass == null ) { mainClass = getPreferences ( ) . getValue ( project , "<STR_LIT>" ) ; } if ( mainClass == null || mainClass . trim ( ) . equals ( StringUtils . EMPTY ) || mainClass . trim ( ) . equals ( "<STR_LIT:none>" ) ) { mainClass = findMainClass ( javaProject ) ; if ( mainClass == null ) { throw new RuntimeException ( Services . getMessage ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } } if ( mainClass . endsWith ( "<STR_LIT>" ) || mainClass . endsWith ( "<STR_LIT:.class>" ) ) { mainClass = mainClass . substring ( <NUM_LIT:0> , mainClass . lastIndexOf ( '<CHAR_LIT:.>' ) ) ; } Java java = new MyJava ( ) ; java . setTaskName ( "<STR_LIT>" ) ; java . setProject ( antProject ) ; java . setClassname ( mainClass ) ; java . setFork ( true ) ; if ( workingDir != null ) { java . setDir ( new File ( workingDir ) ) ; } Path classpath = new Path ( antProject ) ; String [ ] paths = ClasspathUtils . getClasspath ( javaProject ) ; for ( String path : paths ) { Path . PathElement pe = classpath . createPathElement ( ) ; pe . setPath ( path ) ; } java . setClasspath ( classpath ) ; String [ ] defaultArgs = getPreferences ( ) . getArrayValue ( project , "<STR_LIT>" ) ; for ( String vmarg : defaultArgs ) { if ( ! vmarg . startsWith ( "<STR_LIT:->" ) ) { continue ; } Argument a = java . createJvmarg ( ) ; a . setValue ( vmarg ) ; } String [ ] vmargs = commandLine . getValues ( VMARGS_OPTION ) ; if ( vmargs != null && vmargs . length > <NUM_LIT:0> ) { for ( String vmarg : vmargs ) { if ( ! vmarg . startsWith ( "<STR_LIT:->" ) ) { continue ; } Argument a = java . createJvmarg ( ) ; a . setValue ( vmarg ) ; } } String [ ] props = commandLine . getValues ( SYSPROPS_OPTION ) ; if ( props != null && props . length > <NUM_LIT:0> ) { for ( String prop : props ) { String [ ] sysprop = StringUtils . split ( prop , "<STR_LIT:=>" , <NUM_LIT:2> ) ; if ( sysprop . length != <NUM_LIT:2> ) { continue ; } if ( sysprop [ <NUM_LIT:0> ] . startsWith ( "<STR_LIT>" ) ) { sysprop [ <NUM_LIT:0> ] = sysprop [ <NUM_LIT:0> ] . substring ( <NUM_LIT:2> ) ; } Variable var = new Variable ( ) ; var . setKey ( sysprop [ <NUM_LIT:0> ] ) ; var . setValue ( sysprop [ <NUM_LIT:1> ] ) ; java . addSysproperty ( var ) ; } } String [ ] envs = commandLine . getValues ( ENVARGS_OPTION ) ; if ( envs != null && envs . length > <NUM_LIT:0> ) { for ( String env : envs ) { String [ ] envvar = StringUtils . split ( env , "<STR_LIT:=>" , <NUM_LIT:2> ) ; if ( envvar . length != <NUM_LIT:2> ) { continue ; } Variable var = new Variable ( ) ; var . setKey ( envvar [ <NUM_LIT:0> ] ) ; var . setValue ( envvar [ <NUM_LIT:1> ] ) ; java . addEnv ( var ) ; } } String [ ] args = commandLine . getValues ( Options . ARGS_OPTION ) ; if ( args != null && args . length > <NUM_LIT:0> ) { for ( String arg : args ) { Argument a = java . createArg ( ) ; a . setValue ( arg ) ; } } java . execute ( ) ; return null ; } private String findMainClass ( IJavaProject javaProject ) throws Exception { ArrayList < IJavaElement > srcs = new ArrayList < IJavaElement > ( ) ; for ( IClasspathEntry entry : javaProject . getResolvedClasspath ( true ) ) { if ( entry . getEntryKind ( ) == IClasspathEntry . CPE_SOURCE ) { for ( IPackageFragmentRoot root : javaProject . findPackageFragmentRoots ( entry ) ) { srcs . add ( root ) ; } } } final ArrayList < IMethod > methods = new ArrayList < IMethod > ( ) ; int context = IJavaSearchConstants . DECLARATIONS ; int type = IJavaSearchConstants . METHOD ; int matchType = SearchPattern . R_EXACT_MATCH | SearchPattern . R_CASE_SENSITIVE ; IJavaSearchScope scope = SearchEngine . createJavaSearchScope ( srcs . toArray ( new IJavaElement [ srcs . size ( ) ] ) ) ; SearchPattern pattern = SearchPattern . createPattern ( "<STR_LIT>" , type , context , matchType ) ; SearchRequestor requestor = new SearchRequestor ( ) { public void acceptSearchMatch ( SearchMatch match ) { if ( match . getAccuracy ( ) != SearchMatch . A_ACCURATE ) { return ; } try { IMethod method = ( IMethod ) match . getElement ( ) ; String [ ] params = method . getParameterTypes ( ) ; if ( params . length != <NUM_LIT:1> ) { return ; } if ( ! Signature . SIG_VOID . equals ( method . getReturnType ( ) ) ) { return ; } int flags = method . getFlags ( ) ; if ( ! Flags . isPublic ( flags ) || ! Flags . isStatic ( flags ) ) { return ; } methods . add ( method ) ; } catch ( JavaModelException e ) { } } } ; SearchEngine engine = new SearchEngine ( ) ; SearchParticipant [ ] participants = new SearchParticipant [ ] { SearchEngine . getDefaultSearchParticipant ( ) } ; engine . search ( pattern , participants , scope , requestor , null ) ; if ( methods . size ( ) == <NUM_LIT:1> ) { IMethod method = methods . get ( <NUM_LIT:0> ) ; ICompilationUnit cu = method . getCompilationUnit ( ) ; IPackageDeclaration [ ] packages = cu . getPackageDeclarations ( ) ; if ( packages != null && packages . length > <NUM_LIT:0> ) { return packages [ <NUM_LIT:0> ] . getElementName ( ) + "<STR_LIT:.>" + cu . getElementName ( ) ; } return cu . getElementName ( ) ; } return null ; } private class MyJava extends Java { public MyJava ( ) { super ( ) ; this . redirector = new MyRedirector ( this ) ; } } private class MyRedirector extends Redirector { public MyRedirector ( Task task ) { super ( task ) ; } @ Override public synchronized ExecuteStreamHandler createHandler ( ) throws BuildException { return new MyPumpStreamHandler ( ) ; } @ Override public synchronized void complete ( ) throws IOException { getContext ( ) . out . flush ( ) ; getContext ( ) . err . flush ( ) ; } } private class MyPumpStreamHandler extends PumpStreamHandler { public MyPumpStreamHandler ( ) { super ( new FlushingOutputStream ( getContext ( ) . out ) , getContext ( ) . err , getContext ( ) . in , true ) ; } protected Thread createPump ( InputStream is , OutputStream os , boolean closeWhenExhausted , boolean nonBlockingIO ) { Thread pump = super . createPump ( is , os , closeWhenExhausted , nonBlockingIO ) ; try { Method getPumper = pump . getClass ( ) . getDeclaredMethod ( "<STR_LIT>" ) ; getPumper . setAccessible ( true ) ; StreamPumper pumper = ( StreamPumper ) getPumper . invoke ( pump ) ; Method setAutoflush = pumper . getClass ( ) . getDeclaredMethod ( "<STR_LIT>" , Boolean . TYPE ) ; setAutoflush . setAccessible ( true ) ; setAutoflush . invoke ( pumper , Boolean . TRUE ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } return pump ; } } private class FlushingOutputStream extends OutputStream { private OutputStream out ; public FlushingOutputStream ( OutputStream out ) { this . out = out ; } @ Override public void write ( int b ) throws IOException { out . write ( b ) ; out . flush ( ) ; } @ Override public void write ( byte [ ] b ) throws IOException { out . write ( b ) ; out . flush ( ) ; } @ Override public void write ( byte [ ] b , int off , int len ) throws IOException { out . write ( b , off , len ) ; out . flush ( ) ; } } } </s>
|
<s> package org . eclim . plugin . jdt . command . junit ; import java . util . ArrayList ; import java . util . Collections ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . junit . JUnitCore ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class JUnitTestsCommand extends AbstractCommand { @ Override public Object execute ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; IJavaProject javaProject = JavaUtils . getJavaProject ( projectName ) ; ArrayList < String > names = new ArrayList < String > ( ) ; IType [ ] types = JUnitCore . findTestTypes ( javaProject , null ) ; for ( IType type : types ) { names . add ( type . getFullyQualifiedName ( ) ) ; } Collections . sort ( names ) ; return names ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . junit ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . jdt . command . impl . ImplCommand ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclipse . core . resources . IWorkspaceRunnable ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . dom . AST ; import org . eclipse . jdt . core . dom . ASTNode ; import org . eclipse . jdt . core . dom . AbstractTypeDeclaration ; import org . eclipse . jdt . core . dom . Annotation ; import org . eclipse . jdt . core . dom . Block ; import org . eclipse . jdt . core . dom . ChildListPropertyDescriptor ; import org . eclipse . jdt . core . dom . CompilationUnit ; import org . eclipse . jdt . core . dom . IMethodBinding ; import org . eclipse . jdt . core . dom . ITypeBinding ; import org . eclipse . jdt . core . dom . MethodDeclaration ; import org . eclipse . jdt . core . dom . Modifier ; import org . eclipse . jdt . core . dom . rewrite . ASTRewrite ; import org . eclipse . jdt . core . dom . rewrite . ImportRewrite ; import org . eclipse . jdt . core . dom . rewrite . ListRewrite ; import org . eclipse . jdt . internal . corext . codemanipulation . StubUtility ; import org . eclipse . jdt . internal . corext . dom . ASTNodes ; import org . eclipse . jdt . internal . corext . refactoring . structure . ASTNodeSearchUtil ; import org . eclipse . jdt . internal . corext . refactoring . util . RefactoringASTParser ; import org . eclipse . jdt . internal . corext . util . JavaModelUtil ; import org . eclipse . jdt . internal . junit . JUnitCorePlugin ; import org . eclipse . jdt . internal . junit . Messages ; import org . eclipse . jdt . internal . junit . util . JUnitStubUtility ; import org . eclipse . jdt . internal . junit . wizards . WizardMessages ; import org . eclipse . jdt . internal . ui . javaeditor . ASTProvider ; import org . eclipse . text . edits . MultiTextEdit ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class JUnitImplCommand extends ImplCommand { private ThreadLocal < ITypeBinding > base = new ThreadLocal < ITypeBinding > ( ) ; @ Override public Object execute ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; IJavaProject javaProject = JavaUtils . getJavaProject ( projectName ) ; ICompilationUnit test = JavaUtils . getCompilationUnit ( javaProject , file ) ; ICompilationUnit src = JUnitUtils . findClass ( javaProject , test . getTypes ( ) [ <NUM_LIT:0> ] ) ; if ( base == null ) { return Services . getMessage ( "<STR_LIT>" ) ; } RefactoringASTParser parser = new RefactoringASTParser ( ASTProvider . SHARED_AST_LEVEL ) ; CompilationUnit cu = parser . parse ( src , true ) ; ITypeBinding base = ASTNodeSearchUtil . getTypeDeclarationNode ( src . getTypes ( ) [ <NUM_LIT:0> ] , cu ) . resolveBinding ( ) ; this . base . set ( base ) ; return super . execute ( commandLine ) ; } @ Override protected List < IMethodBinding > getOverridableMethods ( CompilationUnit cu , ITypeBinding typeBinding ) throws Exception { HashSet < String > testMethods = new HashSet < String > ( ) ; for ( IMethodBinding method : typeBinding . getDeclaredMethods ( ) ) { int modifiers = method . getModifiers ( ) ; if ( ! method . isConstructor ( ) && ! Modifier . isPrivate ( modifiers ) ) { testMethods . add ( method . getName ( ) ) ; } } List < IMethodBinding > testable = new ArrayList < IMethodBinding > ( ) ; ITypeBinding objectBinding = cu . getAST ( ) . resolveWellKnownType ( "<STR_LIT>" ) ; ITypeBinding parentBinding = base . get ( ) ; while ( parentBinding != null && ! parentBinding . equals ( objectBinding ) ) { for ( IMethodBinding method : parentBinding . getDeclaredMethods ( ) ) { String name = method . getName ( ) ; int modifiers = method . getModifiers ( ) ; if ( ! method . isConstructor ( ) && ! Modifier . isPrivate ( modifiers ) && ! testMethods . contains ( name ) ) { testable . add ( method ) ; } } parentBinding = parentBinding . getSuperclass ( ) ; } return testable ; } @ Override protected IWorkspaceRunnable getImplOperation ( ICompilationUnit src , IType type , Set < String > chosen , IJavaElement sibling , int pos , CommandLine commandLine ) throws Exception { RefactoringASTParser parser = new RefactoringASTParser ( ASTProvider . SHARED_AST_LEVEL ) ; CompilationUnit cu = parser . parse ( type . getCompilationUnit ( ) , true ) ; ITypeBinding typeBinding = ASTNodes . getTypeBinding ( cu , type ) ; String superType = commandLine . getValue ( Options . SUPERTYPE_OPTION ) ; List < IMethodBinding > testable = getOverridableMethods ( cu , typeBinding ) ; List < IMethodBinding > tests = new ArrayList < IMethodBinding > ( ) ; for ( IMethodBinding binding : testable ) { ITypeBinding declBinding = binding . getDeclaringClass ( ) ; String fqn = declBinding . getQualifiedName ( ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; if ( fqn . equals ( superType ) && isChosen ( chosen , binding ) ) { tests . add ( binding ) ; } } if ( tests . size ( ) > <NUM_LIT:0> ) { return new AddTestMethodsOperation ( cu , typeBinding , tests . toArray ( new IMethodBinding [ tests . size ( ) ] ) ) ; } return null ; } private class AddTestMethodsOperation implements IWorkspaceRunnable { private CompilationUnit cu ; private ITypeBinding typeBinding ; private IMethodBinding [ ] methodBindings ; public AddTestMethodsOperation ( CompilationUnit cu , ITypeBinding typeBinding , IMethodBinding [ ] methodBindings ) { this . cu = cu ; this . typeBinding = typeBinding ; this . methodBindings = methodBindings ; } @ Override @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void run ( IProgressMonitor monitor ) { try { ICompilationUnit src = ( ICompilationUnit ) cu . getJavaElement ( ) ; IJavaProject javaProject = src . getJavaProject ( ) ; MultiTextEdit edit = new MultiTextEdit ( ) ; ImportRewrite imports = StubUtility . createImportRewrite ( cu , true ) ; imports . addStaticImport ( "<STR_LIT>" , "<STR_LIT:*>" , false ) ; imports . addImport ( JUnitCorePlugin . JUNIT4_ANNOTATION_NAME ) ; edit . addChild ( imports . rewriteImports ( null ) ) ; AST ast = cu . getAST ( ) ; ASTRewrite astRewrite = ASTRewrite . create ( ast ) ; ASTNode node = cu . findDeclaringNode ( typeBinding ) ; ChildListPropertyDescriptor property = ( ( AbstractTypeDeclaration ) node ) . getBodyDeclarationsProperty ( ) ; ListRewrite memberRewriter = astRewrite . getListRewrite ( node , property ) ; HashSet < String > added = new HashSet < String > ( ) ; for ( IMethodBinding binding : methodBindings ) { String name = binding . getName ( ) ; if ( added . contains ( name ) ) { continue ; } added . add ( name ) ; MethodDeclaration stub = ast . newMethodDeclaration ( ) ; stub . setConstructor ( false ) ; stub . modifiers ( ) . addAll ( ast . newModifiers ( Modifier . PUBLIC ) ) ; Annotation marker = ast . newMarkerAnnotation ( ) ; marker . setTypeName ( ast . newSimpleName ( "<STR_LIT:Test>" ) ) ; astRewrite . getListRewrite ( stub , MethodDeclaration . MODIFIERS2_PROPERTY ) . insertFirst ( marker , null ) ; stub . setName ( ast . newSimpleName ( name ) ) ; Block body = ast . newBlock ( ) ; stub . setBody ( body ) ; String todoTask = "<STR_LIT>" ; String todoTaskTag = JUnitStubUtility . getTodoTaskTag ( javaProject ) ; if ( todoTaskTag != null ) { todoTask = "<STR_LIT>" + todoTaskTag ; } String message = WizardMessages . NewTestCaseWizardPageOne_not_yet_implemented_string ; body . statements ( ) . add ( astRewrite . createStringPlaceholder ( todoTask , ASTNode . RETURN_STATEMENT ) ) ; body . statements ( ) . add ( astRewrite . createStringPlaceholder ( Messages . format ( "<STR_LIT>" , message ) , ASTNode . RETURN_STATEMENT ) ) ; memberRewriter . insertLast ( stub , null ) ; } edit . addChild ( astRewrite . rewriteAST ( ) ) ; JavaModelUtil . applyEdit ( src , edit , true , null ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } } } </s>
|
<s> package org . eclim . plugin . jdt . command . junit ; import java . util . ArrayList ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import org . apache . commons . lang . StringUtils ; import org . eclim . plugin . jdt . util . TypeUtils ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . Signature ; public class JUnitUtils { private static final Pattern TESTING_CLASS_NAME = Pattern . compile ( "<STR_LIT>" ) ; public static ICompilationUnit findTest ( IJavaProject javaProject , IType type ) throws Exception { String [ ] names = new String [ ] { type . getFullyQualifiedName ( ) + "<STR_LIT:Test>" , type . getPackageFragment ( ) . getElementName ( ) + "<STR_LIT>" + type . getElementName ( ) , } ; for ( String name : names ) { IType [ ] results = TypeUtils . findTypes ( javaProject , name ) ; for ( IType result : results ) { if ( result . getCompilationUnit ( ) != null ) { return result . getCompilationUnit ( ) ; } } } return null ; } public static ICompilationUnit findClass ( IJavaProject javaProject , IType type ) throws Exception { String name = type . getElementName ( ) ; Matcher matcher = TESTING_CLASS_NAME . matcher ( name ) ; IType found = null ; if ( matcher . matches ( ) ) { name = matcher . group ( <NUM_LIT:2> ) ; String fqn = type . getPackageFragment ( ) . getElementName ( ) + '<CHAR_LIT:.>' + name ; found = javaProject . findType ( fqn ) ; } if ( found == null ) { IType [ ] types = findTypes ( javaProject , type , name ) ; if ( types . length == <NUM_LIT:1> ) { found = types [ <NUM_LIT:0> ] ; } } return found . getCompilationUnit ( ) ; } private static IType [ ] findTypes ( IJavaProject javaProject , IType ignore , String name ) throws Exception { ArrayList < IType > types = new ArrayList < IType > ( ) ; for ( IType type : TypeUtils . findTypes ( javaProject , name ) ) { if ( ! type . equals ( ignore ) && type . getCompilationUnit ( ) != null ) { types . add ( type ) ; } } return types . toArray ( new IType [ types . size ( ) ] ) ; } public static IMethod findTestMethod ( ICompilationUnit testSrc , IMethod method ) throws Exception { String testName = "<STR_LIT:test>" + StringUtils . capitalize ( method . getElementName ( ) ) ; StringBuffer testNameWithParams = new StringBuffer ( testName ) ; appendParameterNamesToMethodName ( testNameWithParams , method . getParameterTypes ( ) ) ; replaceIllegalCharacters ( testNameWithParams ) ; StringBuffer nameWithParams = new StringBuffer ( method . getElementName ( ) ) ; appendParameterNamesToMethodName ( nameWithParams , method . getParameterTypes ( ) ) ; replaceIllegalCharacters ( nameWithParams ) ; String [ ] methodNames = new String [ ] { testNameWithParams . toString ( ) , nameWithParams . toString ( ) , testName , method . getElementName ( ) , } ; for ( String name : methodNames ) { IMethod test = testSrc . getTypes ( ) [ <NUM_LIT:0> ] . getMethod ( name , null ) ; if ( test != null && test . exists ( ) ) { return test ; } } return null ; } public static IMethod findClassMethod ( ICompilationUnit src , IMethod testMethod ) throws Exception { ICompilationUnit testSrc = testMethod . getCompilationUnit ( ) ; if ( testSrc == null ) { return null ; } IType testType = testSrc . getTypes ( ) [ <NUM_LIT:0> ] ; IMethod [ ] methods = src . getTypes ( ) [ <NUM_LIT:0> ] . getMethods ( ) ; for ( IMethod method : methods ) { String testName = "<STR_LIT:test>" + StringUtils . capitalize ( method . getElementName ( ) ) ; StringBuffer testNameWithParams = new StringBuffer ( testName ) ; appendParameterNamesToMethodName ( testNameWithParams , method . getParameterTypes ( ) ) ; replaceIllegalCharacters ( testNameWithParams ) ; StringBuffer nameWithParams = new StringBuffer ( method . getElementName ( ) ) ; appendParameterNamesToMethodName ( nameWithParams , method . getParameterTypes ( ) ) ; replaceIllegalCharacters ( nameWithParams ) ; String [ ] methodNames = new String [ ] { testNameWithParams . toString ( ) , nameWithParams . toString ( ) , } ; for ( String name : methodNames ) { if ( testMethod . equals ( testType . getMethod ( name , null ) ) ) { return method ; } } } for ( IMethod method : methods ) { String testName = "<STR_LIT:test>" + StringUtils . capitalize ( method . getElementName ( ) ) ; String [ ] methodNames = new String [ ] { testName , method . getElementName ( ) , } ; for ( String name : methodNames ) { if ( testMethod . equals ( testType . getMethod ( name , null ) ) ) { return method ; } } } return null ; } private final static String QUESTION_MARK_TAG = "<STR_LIT>" ; private final static String OF_TAG = "<STR_LIT>" ; private static void appendParameterNamesToMethodName ( StringBuffer buffer , String [ ] parameters ) { for ( String parameter : parameters ) { final StringBuffer buf = new StringBuffer ( Signature . getSimpleName ( Signature . toString ( Signature . getElementType ( parameter ) ) ) ) ; final char character = buf . charAt ( <NUM_LIT:0> ) ; if ( buf . length ( ) > <NUM_LIT:0> && ! Character . isUpperCase ( character ) ) buf . setCharAt ( <NUM_LIT:0> , Character . toUpperCase ( character ) ) ; buffer . append ( buf . toString ( ) ) ; for ( int j = <NUM_LIT:0> , arrayCount = Signature . getArrayCount ( parameter ) ; j < arrayCount ; j ++ ) { buffer . append ( "<STR_LIT>" ) ; } } } private static void replaceIllegalCharacters ( StringBuffer buffer ) { char character = <NUM_LIT:0> ; for ( int index = buffer . length ( ) - <NUM_LIT:1> ; index >= <NUM_LIT:0> ; index -- ) { character = buffer . charAt ( index ) ; if ( Character . isWhitespace ( character ) ) { buffer . deleteCharAt ( index ) ; } else if ( character == '<CHAR_LIT>' ) { buffer . replace ( index , index + <NUM_LIT:1> , OF_TAG ) ; } else if ( character == '<CHAR_LIT>' ) { buffer . replace ( index , index + <NUM_LIT:1> , QUESTION_MARK_TAG ) ; } } } } </s>
|
<s> package org . eclim . plugin . jdt . command . junit ; import java . io . File ; import java . lang . reflect . Field ; import java . util . ArrayList ; import java . util . Collections ; import org . apache . tools . ant . BuildException ; import org . apache . tools . ant . BuildLogger ; import org . apache . tools . ant . DefaultLogger ; import org . apache . tools . ant . Project ; import org . apache . tools . ant . taskdefs . optional . junit . BatchTest ; import org . apache . tools . ant . taskdefs . optional . junit . FormatterElement ; import org . apache . tools . ant . taskdefs . optional . junit . JUnitTask ; import org . apache . tools . ant . taskdefs . optional . junit . JUnitTest ; import org . apache . tools . ant . types . FileSet ; import org . apache . tools . ant . types . Path ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . jdt . util . ClasspathUtils ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IncrementalProjectBuilder ; import org . eclipse . core . runtime . FileLocator ; import org . eclipse . core . runtime . Platform ; import org . eclipse . jdt . core . IAnnotation ; import org . eclipse . jdt . core . IClasspathEntry ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . internal . junit . launcher . JUnit4TestFinder ; import org . eclipse . jdt . junit . JUnitCore ; import org . osgi . framework . Bundle ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class JUnitCommand extends AbstractCommand { @ Override public Object execute ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; String testName = commandLine . getValue ( Options . TEST_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; int offset = getOffset ( commandLine ) ; boolean debug = commandLine . hasOption ( Options . DEBUG_OPTION ) ; boolean halt = commandLine . hasOption ( Options . HALT_OPTION ) ; IProject project = ProjectUtils . getProject ( projectName ) ; project . build ( IncrementalProjectBuilder . INCREMENTAL_BUILD , null ) ; IJavaProject javaProject = JavaUtils . getJavaProject ( project ) ; JUnitTask junit = createJUnitTask ( javaProject , debug , halt ) ; if ( file != null ) { ICompilationUnit src = JavaUtils . getCompilationUnit ( javaProject , file ) ; IMethod method = null ; if ( offset != - <NUM_LIT:1> ) { IJavaElement element = src . getElementAt ( offset ) ; if ( element != null && element . getElementType ( ) == IJavaElement . METHOD ) { method = ( IMethod ) element ; } } JUnit4TestFinder finder = new JUnit4TestFinder ( ) ; IType type = src . getTypes ( ) [ <NUM_LIT:0> ] ; if ( ! finder . isTest ( type ) ) { src = JUnitUtils . findTest ( javaProject , type ) ; if ( src == null ) { println ( Services . getMessage ( "<STR_LIT>" ) ) ; return null ; } if ( method != null ) { method = JUnitUtils . findTestMethod ( src , method ) ; if ( method == null ) { println ( Services . getMessage ( "<STR_LIT>" ) ) ; return null ; } } } JUnitTest test = new JUnitTest ( ) ; test . setName ( JavaUtils . getFullyQualifiedName ( src ) ) ; if ( method != null ) { IAnnotation testAnnotation = method . getAnnotation ( "<STR_LIT:Test>" ) ; if ( testAnnotation == null || ! testAnnotation . exists ( ) ) { println ( Services . getMessage ( "<STR_LIT>" , method . getElementName ( ) ) ) ; return null ; } test . setMethods ( method . getElementName ( ) ) ; } junit . addTest ( test ) ; } else if ( testName != null ) { if ( testName . indexOf ( '<CHAR_LIT>' ) != - <NUM_LIT:1> ) { createBatchTest ( javaProject , junit , testName ) ; } else { JUnitTest test = new JUnitTest ( ) ; test . setName ( testName ) ; junit . addTest ( test ) ; } } else { ArrayList < String > names = new ArrayList < String > ( ) ; IType [ ] types = JUnitCore . findTestTypes ( javaProject , null ) ; for ( IType type : types ) { names . add ( type . getFullyQualifiedName ( ) ) ; } Collections . sort ( names ) ; for ( String name : names ) { JUnitTest test = new JUnitTest ( ) ; test . setName ( name ) ; junit . addTest ( test ) ; } } try { junit . init ( ) ; junit . execute ( ) ; } catch ( BuildException be ) { if ( debug ) { be . printStackTrace ( getContext ( ) . err ) ; } } return null ; } private JUnitTask createJUnitTask ( IJavaProject javaProject , boolean debug , boolean halt ) throws Exception { Project antProject = new Project ( ) ; BuildLogger buildLogger = new DefaultLogger ( ) ; buildLogger . setEmacsMode ( true ) ; buildLogger . setMessageOutputLevel ( debug ? Project . MSG_DEBUG : Project . MSG_INFO ) ; buildLogger . setOutputPrintStream ( getContext ( ) . out ) ; buildLogger . setErrorPrintStream ( getContext ( ) . err ) ; antProject . addBuildListener ( buildLogger ) ; antProject . setBasedir ( ProjectUtils . getPath ( javaProject . getProject ( ) ) ) ; Path classpath = new Path ( antProject ) ; String [ ] paths = ClasspathUtils . getClasspath ( javaProject ) ; for ( String path : paths ) { Path . PathElement pe = classpath . createPathElement ( ) ; pe . setPath ( path ) ; } Bundle bundle = Platform . getBundle ( "<STR_LIT>" ) ; String pathName = FileLocator . getBundleFile ( bundle ) . getPath ( ) ; classpath . createPathElement ( ) . setPath ( pathName + "<STR_LIT>" ) ; classpath . createPathElement ( ) . setPath ( pathName + "<STR_LIT>" ) ; classpath . createPathElement ( ) . setPath ( pathName + "<STR_LIT>" ) ; bundle = Platform . getBundle ( "<STR_LIT>" ) ; pathName = FileLocator . getBundleFile ( bundle ) . getPath ( ) ; classpath . createPathElement ( ) . setPath ( pathName + "<STR_LIT>" ) ; JUnitTask junit = new JUnitTask ( ) ; junit . setProject ( antProject ) ; junit . setTaskName ( "<STR_LIT>" ) ; junit . setFork ( true ) ; junit . setHaltonerror ( halt ) ; junit . setHaltonfailure ( halt ) ; junit . createClasspath ( ) . append ( classpath ) ; Field forkedPathChecked = JUnitTask . class . getDeclaredField ( "<STR_LIT>" ) ; forkedPathChecked . setAccessible ( true ) ; forkedPathChecked . set ( junit , true ) ; FormatterElement formatter = new FormatterElement ( ) ; junit . addFormatter ( formatter ) ; formatter . setClassname ( "<STR_LIT>" ) ; formatter . setUseFile ( false ) ; return junit ; } private void createBatchTest ( IJavaProject javaProject , JUnitTask junit , String pattern ) throws Exception { if ( ! pattern . endsWith ( "<STR_LIT>" ) ) { pattern += "<STR_LIT>" ; } BatchTest batch = junit . createBatchTest ( ) ; IClasspathEntry [ ] entries = javaProject . getResolvedClasspath ( true ) ; for ( IClasspathEntry entry : entries ) { if ( entry . getEntryKind ( ) == IClasspathEntry . CPE_SOURCE ) { String path = ProjectUtils . getFilePath ( javaProject . getProject ( ) , entry . getPath ( ) . toOSString ( ) ) ; FileSet fileset = new FileSet ( ) ; fileset . setDir ( new File ( path ) ) ; fileset . setIncludes ( pattern ) ; batch . addFileSet ( fileset ) ; } } } } </s>
|
<s> package org . eclim . plugin . jdt . command . junit ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . util . file . Position ; import org . eclipse . core . resources . IProject ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaProject ; 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 . internal . junit . launcher . JUnit4TestFinder ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class JUnitFindTestCommand extends AbstractCommand { @ Override public Object execute ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; int offset = getOffset ( commandLine ) ; IProject project = ProjectUtils . getProject ( projectName ) ; IJavaProject javaProject = JavaUtils . getJavaProject ( project ) ; JUnit4TestFinder finder = new JUnit4TestFinder ( ) ; ICompilationUnit src = JavaUtils . getCompilationUnit ( javaProject , file ) ; ICompilationUnit result = null ; if ( finder . isTest ( src . getTypes ( ) [ <NUM_LIT:0> ] ) ) { result = JUnitUtils . findClass ( javaProject , src . getTypes ( ) [ <NUM_LIT:0> ] ) ; if ( result == null ) { return Services . getMessage ( "<STR_LIT>" ) ; } } else { result = JUnitUtils . findTest ( javaProject , src . getTypes ( ) [ <NUM_LIT:0> ] ) ; if ( result == null ) { return Services . getMessage ( "<STR_LIT>" ) ; } } IType resultType = result . getTypes ( ) [ <NUM_LIT:0> ] ; String name = resultType . getElementName ( ) ; ISourceReference ref = resultType ; ISourceRange docRange = resultType . getJavadocRange ( ) ; IJavaElement element = src . getElementAt ( offset ) ; if ( element != null && element . getElementType ( ) == IJavaElement . METHOD ) { IMethod method = null ; if ( finder . isTest ( src . getTypes ( ) [ <NUM_LIT:0> ] ) ) { method = JUnitUtils . findClassMethod ( result , ( IMethod ) element ) ; } else { method = JUnitUtils . findTestMethod ( result , ( IMethod ) element ) ; } if ( method != null ) { name = method . getElementName ( ) ; ref = method ; docRange = method . getJavadocRange ( ) ; } } String lineDelim = result . findRecommendedLineSeparator ( ) ; int docLength = docRange != null ? docRange . getLength ( ) + lineDelim . length ( ) : <NUM_LIT:0> ; return Position . fromOffset ( result . getResource ( ) . getLocation ( ) . toOSString ( ) , name , ref . getSourceRange ( ) . getOffset ( ) + docLength , <NUM_LIT:0> ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . junit ; import java . io . IOException ; import java . io . OutputStream ; import org . apache . tools . ant . BuildException ; import org . apache . tools . ant . taskdefs . optional . junit . JUnitTest ; import org . apache . tools . ant . taskdefs . optional . junit . PlainJUnitResultFormatter ; import org . apache . tools . ant . util . StringUtils ; public class ResultFormatter extends PlainJUnitResultFormatter { private OutputStream out ; @ Override public void setOutput ( OutputStream out ) { super . setOutput ( out ) ; this . out = out ; } @ Override public void startTestSuite ( JUnitTest suite ) throws BuildException { if ( out == null ) { return ; } String name = suite . getName ( ) ; StringBuffer nameDelim = new StringBuffer ( ) ; for ( int i = <NUM_LIT:0> ; i < name . length ( ) ; i ++ ) { nameDelim . append ( '<CHAR_LIT:->' ) ; } StringBuffer sb = new StringBuffer ( ) ; sb . append ( StringUtils . LINE_SEP ) ; sb . append ( "<STR_LIT>" ) . append ( nameDelim ) . append ( StringUtils . LINE_SEP ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( name ) ; sb . append ( StringUtils . LINE_SEP ) ; sb . append ( "<STR_LIT>" ) . append ( nameDelim ) . append ( StringUtils . LINE_SEP ) ; try { out . write ( sb . toString ( ) . getBytes ( ) ) ; out . flush ( ) ; } catch ( IOException ex ) { throw new BuildException ( "<STR_LIT>" , ex ) ; } } } </s>
|
<s> package org . eclim . plugin . jdt . command . src ; import java . io . File ; import java . io . FileInputStream ; import java . net . URL ; import java . net . URLClassLoader ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . List ; import java . util . Properties ; import java . util . Set ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclim . command . Options ; import org . eclim . logging . Logger ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . preference . Preferences ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . util . IOUtils ; import org . eclim . util . StringUtils ; import org . eclim . util . file . FileUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . IClasspathEntry ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . JavaModelException ; import com . puppycrawl . tools . checkstyle . Checker ; import com . puppycrawl . tools . checkstyle . ConfigurationLoader ; import com . puppycrawl . tools . checkstyle . PropertiesExpander ; import com . puppycrawl . tools . checkstyle . api . AuditEvent ; import com . puppycrawl . tools . checkstyle . api . AuditListener ; import com . puppycrawl . tools . checkstyle . api . Configuration ; import com . puppycrawl . tools . checkstyle . api . SeverityLevel ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class CheckstyleCommand extends AbstractCommand { private static final Logger logger = Logger . getLogger ( CheckstyleCommand . class ) ; @ Override public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; IProject project = ProjectUtils . getProject ( name , true ) ; Preferences prefs = getPreferences ( ) ; String configFile = prefs . getValue ( project , "<STR_LIT>" ) ; String propsFile = prefs . getValue ( project , "<STR_LIT>" ) ; Properties properties = System . getProperties ( ) ; if ( propsFile != null && ! propsFile . equals ( StringUtils . EMPTY ) ) { FileInputStream fis = null ; try { File pfile = new File ( propsFile ) ; if ( ! pfile . exists ( ) ) { pfile = new File ( ProjectUtils . getFilePath ( project , propsFile ) ) ; if ( ! pfile . exists ( ) ) { throw new RuntimeException ( Services . getMessage ( "<STR_LIT>" , configFile ) ) ; } } fis = new FileInputStream ( pfile ) ; properties = new Properties ( ) ; properties . load ( fis ) ; } finally { IOUtils . closeQuietly ( fis ) ; } } if ( ! new File ( configFile ) . exists ( ) ) { String projectConfigFile = ProjectUtils . getFilePath ( project , configFile ) ; if ( ! new File ( projectConfigFile ) . exists ( ) ) { throw new RuntimeException ( Services . getMessage ( "<STR_LIT>" , configFile ) ) ; } configFile = projectConfigFile ; } Configuration config = ConfigurationLoader . loadConfiguration ( configFile , new PropertiesExpander ( properties ) ) ; CheckstyleListener listener = new CheckstyleListener ( ) ; List < File > files = new ArrayList < File > ( ) ; files . add ( new File ( ProjectUtils . getFilePath ( project , file ) ) ) ; Checker checker = new Checker ( ) ; checker . setModuleClassLoader ( new ProjectClassLoader ( JavaUtils . getJavaProject ( project ) , Checker . class . getClassLoader ( ) ) ) ; checker . setClassloader ( new ProjectClassLoader ( JavaUtils . getJavaProject ( project ) ) ) ; checker . configure ( config ) ; checker . addListener ( listener ) ; checker . process ( files ) ; return listener . getErrors ( ) ; } private static class CheckstyleListener implements AuditListener { private static final String CHECKSTYLE_PREFIX = "<STR_LIT>" ; private ArrayList < Error > errors ; public CheckstyleListener ( ) { errors = new ArrayList < Error > ( ) ; } @ Override public void auditStarted ( AuditEvent event ) { } @ Override public void auditFinished ( AuditEvent event ) { } @ Override public void fileStarted ( AuditEvent event ) { } @ Override public void fileFinished ( AuditEvent event ) { } @ Override public void addError ( AuditEvent event ) { errors . add ( new Error ( CHECKSTYLE_PREFIX + event . getMessage ( ) , event . getFileName ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) , event . getLine ( ) , event . getColumn ( ) , event . getSeverityLevel ( ) != SeverityLevel . ERROR ) ) ; } @ Override public void addException ( AuditEvent event , Throwable throwable ) { throw new RuntimeException ( throwable ) ; } public ArrayList < Error > getErrors ( ) { return this . errors ; } } private static class ProjectClassLoader extends URLClassLoader { public ProjectClassLoader ( IJavaProject project ) throws Exception { super ( ProjectClassLoader . classpath ( project ) ) ; } public ProjectClassLoader ( IJavaProject project , ClassLoader parent ) throws Exception { super ( ProjectClassLoader . classpath ( project ) , parent ) ; } private static URL [ ] classpath ( IJavaProject project ) throws Exception { Set < IJavaProject > visited = new HashSet < IJavaProject > ( ) ; List < URL > urls = new ArrayList < URL > ( ) ; collect ( project , urls , visited , true ) ; return urls . toArray ( new URL [ urls . size ( ) ] ) ; } private static void collect ( IJavaProject javaProject , List < URL > urls , Set < IJavaProject > visited , boolean isFirstProject ) throws Exception { if ( visited . contains ( javaProject ) ) { return ; } visited . add ( javaProject ) ; try { IPath out = javaProject . getOutputLocation ( ) ; String path = ProjectUtils . getFilePath ( javaProject . getProject ( ) , out . toOSString ( ) ) ; path = FileUtils . addTrailingSlash ( path . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ) ; urls . add ( new URL ( "<STR_LIT>" + path ) ) ; } catch ( JavaModelException ignore ) { } IProject project = javaProject . getProject ( ) ; String name = project . getName ( ) ; IClasspathEntry [ ] entries = null ; try { entries = javaProject . getResolvedClasspath ( true ) ; } catch ( JavaModelException jme ) { logger . warn ( "<STR_LIT>" + name , jme ) ; return ; } for ( IClasspathEntry entry : entries ) { switch ( entry . getEntryKind ( ) ) { case IClasspathEntry . CPE_LIBRARY : case IClasspathEntry . CPE_CONTAINER : case IClasspathEntry . CPE_VARIABLE : String path = entry . getPath ( ) . toOSString ( ) ; if ( path . startsWith ( "<STR_LIT:/>" + name + "<STR_LIT:/>" ) ) { path = ProjectUtils . getFilePath ( project , path ) ; } urls . add ( new URL ( "<STR_LIT>" + path ) ) ; break ; case IClasspathEntry . CPE_PROJECT : if ( isFirstProject || entry . isExported ( ) ) { collect ( getJavaProject ( entry ) , urls , visited , false ) ; } break ; } } } private static IJavaProject getJavaProject ( IClasspathEntry entry ) throws Exception { IProject project = ProjectUtils . getProject ( entry . getPath ( ) . segment ( <NUM_LIT:0> ) ) ; if ( project != null ) { return JavaUtils . getJavaProject ( project ) ; } return null ; } } } </s>
|
<s> package org . eclim . plugin . jdt . command . src ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclipse . jdt . core . ICompilationUnit ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class SrcFindCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String classname = commandLine . getValue ( Options . CLASSNAME_OPTION ) ; String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; ICompilationUnit src = null ; String file = classname . replace ( '<CHAR_LIT:.>' , '<CHAR_LIT:/>' ) + "<STR_LIT>" ; if ( projectName != null ) { src = JavaUtils . findCompilationUnit ( projectName , file ) ; } else { src = JavaUtils . findCompilationUnit ( file ) ; } if ( src != null && src . exists ( ) ) { return src . getResource ( ) . getLocation ( ) . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; } return "<STR_LIT>" ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . src ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . jdt . util . ClasspathUtils ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . util . StringUtils ; import org . eclipse . jdt . core . IJavaProject ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class SrcDirsCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; IJavaProject javaProject = JavaUtils . getJavaProject ( projectName ) ; String [ ] paths = ClasspathUtils . getSrcPaths ( javaProject ) ; return StringUtils . join ( paths , "<STR_LIT:n>" ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . src ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . logging . Logger ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclipse . jdt . core . ICompilationUnit ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class SrcFileExistsCommand extends AbstractCommand { private static final Logger logger = Logger . getLogger ( SrcFileExistsCommand . class ) ; public Object execute ( CommandLine commandLine ) throws Exception { try { String file = commandLine . getValue ( Options . FILE_OPTION ) ; String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; if ( projectName != null ) { ICompilationUnit src = JavaUtils . findCompilationUnit ( projectName , file ) ; return src != null && src . exists ( ) ? Boolean . TRUE . toString ( ) : Boolean . FALSE . toString ( ) ; } ICompilationUnit src = JavaUtils . findCompilationUnit ( file ) ; return src != null && src . exists ( ) ? Boolean . TRUE . toString ( ) : Boolean . FALSE . toString ( ) ; } catch ( IllegalArgumentException iae ) { logger . error ( "<STR_LIT>" , iae ) ; return Boolean . FALSE . toString ( ) ; } } } </s>
|
<s> package org . eclim . plugin . jdt . command . src ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . formatter . CodeFormatter ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class FormatCommand extends AbstractCommand { @ Override public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; ICompilationUnit src = JavaUtils . getCompilationUnit ( project , file ) ; int headOffset = getOffset ( commandLine , "<STR_LIT>" ) ; int tailOffset = getOffset ( commandLine , "<STR_LIT:t>" ) ; int kind = CodeFormatter . K_COMPILATION_UNIT | CodeFormatter . F_INCLUDE_COMMENTS ; JavaUtils . format ( src , kind , headOffset , tailOffset - headOffset ) ; return null ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . src ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileWriter ; import java . io . PrintWriter ; import java . io . Writer ; import java . util . Set ; import java . util . TreeSet ; import org . apache . commons . lang . SystemUtils ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . logging . Logger ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . util . IOUtils ; import org . eclim . util . StringUtils ; import org . eclim . util . file . FileUtils ; import org . eclipse . jdt . core . Flags ; import org . eclipse . jdt . core . IField ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IMember ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . Signature ; import org . objectweb . asm . AnnotationVisitor ; import org . objectweb . asm . Attribute ; import org . objectweb . asm . ClassReader ; import org . objectweb . asm . ClassVisitor ; import org . objectweb . asm . FieldVisitor ; import org . objectweb . asm . Label ; import org . objectweb . asm . MethodVisitor ; import org . objectweb . asm . Opcodes ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class ClassPrototypeCommand extends AbstractCommand { private static final Logger logger = Logger . getLogger ( ClassPrototypeCommand . class ) ; private static final String INDENT = "<STR_LIT:t>" ; private static final String IMPORT_PATTERN = "<STR_LIT>" ; private static final String OBJECT = "<STR_LIT>" ; private static final String ANNOTATION = "<STR_LIT>" ; public Object execute ( CommandLine commandLine ) throws Exception { String className = commandLine . getValue ( Options . CLASSNAME_OPTION ) ; if ( ! commandLine . hasOption ( Options . PROJECT_OPTION ) && ! commandLine . hasOption ( Options . FILE_OPTION ) ) { throw new RuntimeException ( Services . getMessage ( "<STR_LIT>" ) ) ; } File file = new File ( SystemUtils . JAVA_IO_TMPDIR + '<CHAR_LIT:/>' + className . replace ( '<CHAR_LIT:.>' , '<CHAR_LIT:/>' ) + "<STR_LIT>" ) ; new File ( FileUtils . getFullPath ( file . getAbsolutePath ( ) ) ) . mkdirs ( ) ; file . deleteOnExit ( ) ; FileWriter out = null ; try { out = new FileWriter ( file ) ; if ( commandLine . hasOption ( Options . FILE_OPTION ) ) { prototype ( commandLine . getValue ( Options . FILE_OPTION ) , out ) ; } else { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; IJavaProject javaProject = JavaUtils . getJavaProject ( projectName ) ; IType type = javaProject . findType ( className ) ; if ( type == null ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , projectName , className ) ) ; } String prototype = prototype ( type ) ; out . write ( prototype ) ; } } finally { IOUtils . closeQuietly ( out ) ; } return file . getAbsolutePath ( ) ; } protected void prototype ( String file , Writer writer ) throws Exception { FileInputStream in = null ; try { in = new FileInputStream ( file ) ; ClassReader reader = new ClassReader ( in ) ; reader . accept ( new AsmClassVisitor ( new PrintWriter ( writer ) ) , false ) ; } finally { IOUtils . closeQuietly ( in ) ; } } protected String prototype ( IType type ) throws Exception { Set < String > imports = new TreeSet < String > ( ) ; StringBuffer buffer = new StringBuffer ( ) ; buffer . append ( Services . getMessage ( "<STR_LIT>" ) ) ; buffer . append ( "<STR_LIT>" ) . append ( type . getPackageFragment ( ) . getElementName ( ) ) . append ( "<STR_LIT>" ) ; prototype ( buffer , type , "<STR_LIT>" , imports ) ; StringBuffer importClauses = new StringBuffer ( ) . append ( "<STR_LIT>" ) ; for ( String className : imports ) { importClauses . append ( "<STR_LIT>" ) . append ( className ) . append ( "<STR_LIT>" ) ; } buffer . insert ( buffer . indexOf ( "<STR_LIT:;>" ) + <NUM_LIT:1> , importClauses . toString ( ) ) ; return buffer . toString ( ) ; } protected void prototype ( StringBuffer buffer , IType type , String indent , Set < String > imports ) throws Exception { buffer . append ( indent ) ; prototypeFlags ( buffer , type ) ; int flags = type . getFlags ( ) ; if ( Flags . isEnum ( flags ) ) { buffer . append ( "<STR_LIT>" ) ; } else if ( Flags . isInterface ( flags ) ) { buffer . append ( "<STR_LIT>" ) ; } else if ( Flags . isAnnotation ( flags ) ) { buffer . append ( "<STR_LIT>" ) ; } else { buffer . append ( "<STR_LIT>" ) ; } buffer . append ( type . getElementName ( ) ) ; String superclass = type . getSuperclassName ( ) ; if ( superclass != null ) { buffer . append ( '<STR_LIT:\n>' ) . append ( indent ) . append ( INDENT ) . append ( "<STR_LIT>" ) . append ( superclass ) ; } String [ ] interfaces = type . getSuperInterfaceNames ( ) ; if ( interfaces != null && interfaces . length > <NUM_LIT:0> ) { buffer . append ( '<STR_LIT:\n>' ) . append ( indent ) . append ( INDENT ) . append ( "<STR_LIT>" ) ; for ( int ii = <NUM_LIT:0> ; ii < interfaces . length ; ii ++ ) { if ( ii != <NUM_LIT:0> ) { buffer . append ( "<STR_LIT:U+002CU+0020>" ) ; } buffer . append ( interfaces [ ii ] ) ; } } buffer . append ( '<STR_LIT:\n>' ) . append ( indent ) . append ( "<STR_LIT>" ) ; int length = buffer . length ( ) ; IField [ ] fields = type . getFields ( ) ; for ( int ii = <NUM_LIT:0> ; ii < fields . length ; ii ++ ) { prototypeField ( buffer , fields [ ii ] , indent + INDENT , imports ) ; } IMethod [ ] methods = type . getMethods ( ) ; if ( methods != null && methods . length > <NUM_LIT:0> ) { for ( int ii = <NUM_LIT:0> ; ii < methods . length ; ii ++ ) { if ( length != buffer . length ( ) ) { buffer . append ( '<STR_LIT:\n>' ) ; } length = buffer . length ( ) ; prototypeMethod ( buffer , methods [ ii ] , indent + INDENT , imports ) ; } } IType [ ] types = type . getTypes ( ) ; if ( types != null && types . length > <NUM_LIT:0> ) { if ( length != buffer . length ( ) ) { buffer . append ( '<STR_LIT:\n>' ) ; } for ( int ii = <NUM_LIT:0> ; ii < types . length ; ii ++ ) { if ( ii > <NUM_LIT:0> ) { buffer . append ( '<STR_LIT:\n>' ) ; } prototype ( buffer , types [ ii ] , indent + INDENT , imports ) ; buffer . append ( '<STR_LIT:\n>' ) ; } } buffer . append ( indent ) . append ( "<STR_LIT:}>" ) ; } protected void prototypeField ( StringBuffer buffer , IField field , String indent , Set < String > imports ) throws Exception { String fieldName = field . getElementName ( ) ; if ( fieldName . indexOf ( "<STR_LIT:$>" ) == - <NUM_LIT:1> ) { buffer . append ( indent ) ; prototypeFlags ( buffer , field ) ; String type = field . getTypeSignature ( ) ; String typeName = Signature . getSignatureSimpleName ( type ) ; buffer . append ( typeName ) . append ( '<CHAR_LIT:U+0020>' ) . append ( field . getElementName ( ) ) ; addImport ( imports , type ) ; Object defaultValue = field . getConstant ( ) ; if ( defaultValue != null ) { buffer . append ( "<STR_LIT:U+0020=U+0020>" ) ; if ( typeName . equals ( "<STR_LIT>" ) ) { buffer . append ( '<STR_LIT>' ) . append ( defaultValue ) . append ( '<STR_LIT>' ) ; } else if ( typeName . equals ( "<STR_LIT:int>" ) || typeName . equals ( "<STR_LIT:long>" ) || typeName . equals ( "<STR_LIT>" ) || typeName . equals ( "<STR_LIT:double>" ) || typeName . equals ( "<STR_LIT:float>" ) || typeName . equals ( "<STR_LIT:boolean>" ) || typeName . equals ( "<STR_LIT>" ) ) { buffer . append ( defaultValue ) ; } else if ( defaultValue instanceof String ) { buffer . append ( '<CHAR_LIT:">' ) . append ( defaultValue ) . append ( '<CHAR_LIT:">' ) ; } else { logger . warn ( "<STR_LIT>" , defaultValue . getClass ( ) . getName ( ) , defaultValue ) ; } } buffer . append ( "<STR_LIT>" ) ; } } protected void prototypeMethod ( StringBuffer buffer , IMethod method , String indent , Set < String > imports ) throws Exception { String methodName = method . getElementName ( ) ; if ( methodName . indexOf ( "<STR_LIT:$>" ) == - <NUM_LIT:1> && ! methodName . equals ( "<STR_LIT>" ) ) { buffer . append ( indent ) ; prototypeFlags ( buffer , method ) ; String returnType = method . getReturnType ( ) ; String returnTypeName = Signature . getSignatureSimpleName ( returnType ) ; addImport ( imports , returnType ) ; buffer . append ( returnTypeName ) . append ( '<CHAR_LIT:U+0020>' ) . append ( methodName ) . append ( "<STR_LIT:U+0020(>" ) ; String [ ] paramNames = method . getParameterNames ( ) ; String [ ] paramTypes = method . getParameterTypes ( ) ; if ( paramNames . length > <NUM_LIT:0> ) { for ( int ii = <NUM_LIT:0> ; ii < paramNames . length ; ii ++ ) { if ( ii != <NUM_LIT:0> ) { buffer . append ( "<STR_LIT:U+002CU+0020>" ) ; } addImport ( imports , paramTypes [ ii ] ) ; String typeName = Signature . getSignatureSimpleName ( paramTypes [ ii ] ) ; buffer . append ( typeName ) . append ( '<CHAR_LIT:U+0020>' ) . append ( paramNames [ ii ] ) ; } } buffer . append ( "<STR_LIT:)>" ) ; String [ ] exceptions = method . getExceptionTypes ( ) ; if ( exceptions . length > <NUM_LIT:0> ) { buffer . append ( '<STR_LIT:\n>' ) . append ( indent ) . append ( INDENT ) . append ( "<STR_LIT>" ) ; for ( int ii = <NUM_LIT:0> ; ii < exceptions . length ; ii ++ ) { if ( ii != <NUM_LIT:0> ) { buffer . append ( "<STR_LIT:U+002CU+0020>" ) ; } buffer . append ( Signature . getSignatureSimpleName ( exceptions [ ii ] ) ) ; } } buffer . append ( "<STR_LIT>" ) ; } } protected void prototypeFlags ( StringBuffer buffer , IMember member ) throws Exception { int flags = member . getFlags ( ) ; if ( Flags . isPublic ( flags ) ) { buffer . append ( "<STR_LIT>" ) ; } else if ( Flags . isProtected ( flags ) ) { buffer . append ( "<STR_LIT>" ) ; } else if ( Flags . isPrivate ( flags ) ) { buffer . append ( "<STR_LIT>" ) ; } if ( Flags . isStatic ( flags ) ) { buffer . append ( "<STR_LIT>" ) ; } if ( Flags . isFinal ( flags ) ) { buffer . append ( "<STR_LIT>" ) ; } if ( Flags . isAbstract ( flags ) ) { buffer . append ( "<STR_LIT>" ) ; } if ( Flags . isNative ( flags ) ) { buffer . append ( "<STR_LIT>" ) ; } if ( Flags . isTransient ( flags ) ) { buffer . append ( "<STR_LIT>" ) ; } if ( Flags . isVolatile ( flags ) ) { buffer . append ( "<STR_LIT>" ) ; } if ( Flags . isSynchronized ( flags ) ) { buffer . append ( "<STR_LIT>" ) ; } } protected void addImport ( Set < String > imports , String signature ) { String name = Signature . getSignatureSimpleName ( signature ) ; if ( name . length ( ) > <NUM_LIT:1> && ! name . equals ( "<STR_LIT>" ) ) { String pckg = Signature . getSignatureQualifier ( signature ) ; if ( pckg != null && pckg . length ( ) > <NUM_LIT:0> ) { name = pckg + '<CHAR_LIT:.>' + name ; imports . add ( name . replaceFirst ( IMPORT_PATTERN , "<STR_LIT>" ) ) ; } } } private static class AsmClassVisitor implements ClassVisitor { private PrintWriter writer ; private StringBuffer classBuffer ; private String name ; public AsmClassVisitor ( PrintWriter writer ) { super ( ) ; this . writer = writer ; } public void visit ( int version , int access , String name , String signature , String superName , String [ ] interfaces ) { writer . print ( Services . getMessage ( "<STR_LIT>" ) ) ; int index = name . lastIndexOf ( '<CHAR_LIT:/>' ) ; if ( index != - <NUM_LIT:1> ) { String pack = name . substring ( <NUM_LIT:0> , index ) . replace ( '<CHAR_LIT:/>' , '<CHAR_LIT:.>' ) ; name = name . substring ( index + <NUM_LIT:1> ) ; writer . print ( "<STR_LIT>" ) ; writer . print ( pack ) ; writer . println ( "<STR_LIT>" ) ; } this . name = name ; classBuffer = new StringBuffer ( ) . append ( getAccess ( access ) ) ; if ( ( access & Opcodes . ACC_INTERFACE ) == <NUM_LIT:1> ) { classBuffer . append ( "<STR_LIT>" ) ; } else if ( ( access & Opcodes . ACC_ENUM ) == <NUM_LIT:1> ) { classBuffer . append ( "<STR_LIT>" ) ; } else { if ( interfaces . length > <NUM_LIT:0> && interfaces [ <NUM_LIT:0> ] . equals ( ANNOTATION ) ) { classBuffer . append ( "<STR_LIT>" ) ; } else { classBuffer . append ( "<STR_LIT>" ) ; } } classBuffer . append ( name ) . append ( '<STR_LIT:\n>' ) ; if ( ! OBJECT . equals ( superName ) ) { classBuffer . append ( INDENT ) . append ( "<STR_LIT>" ) . append ( superName . replace ( '<CHAR_LIT:/>' , '<CHAR_LIT:.>' ) ) . append ( '<STR_LIT:\n>' ) ; } StringBuffer ifaces = new StringBuffer ( ) ; for ( String iface : interfaces ) { if ( ! ANNOTATION . equals ( iface ) ) { if ( ifaces . length ( ) > <NUM_LIT:0> ) { ifaces . append ( "<STR_LIT:U+002CU+0020>" ) ; } ifaces . append ( iface . replace ( '<CHAR_LIT:/>' , '<CHAR_LIT:.>' ) ) ; } } if ( ifaces . length ( ) > <NUM_LIT:0> ) { classBuffer . append ( INDENT ) . append ( "<STR_LIT>" ) . append ( ifaces ) . append ( '<STR_LIT:\n>' ) ; } classBuffer . append ( "<STR_LIT>" ) ; } public void visitSource ( String source , String debug ) { } public void visitOuterClass ( String owner , String name , String desc ) { } public AnnotationVisitor visitAnnotation ( String desc , boolean visible ) { writer . print ( '<CHAR_LIT>' ) ; writer . print ( getDescName ( desc ) ) ; return new AsmAnnotationVisitor ( ) ; } public void visitAttribute ( Attribute attr ) { } public void visitInnerClass ( String name , String outerName , String innerName , int access ) { flushClassDeclaration ( ) ; } public FieldVisitor visitField ( int access , String name , String desc , String signature , Object value ) { flushClassDeclaration ( ) ; return new AsmFieldVisitor ( access , name , desc , value ) ; } public MethodVisitor visitMethod ( int access , String name , String desc , String signature , String [ ] exceptions ) { flushClassDeclaration ( ) ; return new AsmMethodVisitor ( access , name , signature != null ? signature : desc , exceptions ) ; } private void flushClassDeclaration ( ) { if ( classBuffer != null ) { writer . write ( classBuffer . toString ( ) ) ; classBuffer = null ; } } public void visitEnd ( ) { flushClassDeclaration ( ) ; writer . print ( '<CHAR_LIT:}>' ) ; } private String getDescName ( String desc ) { if ( desc != null ) { int indexStart = desc . indexOf ( '<CHAR_LIT>' ) ; int indexEnd = desc . lastIndexOf ( '<CHAR_LIT:>>' ) ; if ( indexStart != - <NUM_LIT:1> && indexEnd != - <NUM_LIT:1> ) { String outer = desc . substring ( <NUM_LIT:0> , indexStart ) ; String inner = desc . substring ( indexStart + <NUM_LIT:1> , indexEnd ) ; return getDescName ( outer ) + '<CHAR_LIT>' + getDescName ( inner ) + '<CHAR_LIT:>>' ; } int index = desc . lastIndexOf ( '<CHAR_LIT:/>' ) ; if ( index != - <NUM_LIT:1> ) { String name = desc . substring ( index + <NUM_LIT:1> ) ; if ( name . endsWith ( "<STR_LIT:;>" ) ) { name = name . substring ( <NUM_LIT:0> , name . length ( ) - <NUM_LIT:1> ) ; } while ( desc . startsWith ( "<STR_LIT:[>" ) ) { desc = desc . substring ( <NUM_LIT:1> ) ; name += "<STR_LIT:[]>" ; } return name ; } String primitive = null ; if ( "<STR_LIT>" . equals ( desc ) ) { return "<STR_LIT>" ; } else if ( desc . endsWith ( "<STR_LIT:I>" ) ) { primitive = "<STR_LIT:int>" ; } else if ( desc . endsWith ( "<STR_LIT>" ) ) { primitive = "<STR_LIT:long>" ; } else if ( desc . endsWith ( "<STR_LIT:S>" ) ) { primitive = "<STR_LIT>" ; } else if ( desc . endsWith ( "<STR_LIT:C>" ) ) { primitive = "<STR_LIT>" ; } else if ( desc . endsWith ( "<STR_LIT:B>" ) ) { primitive = "<STR_LIT>" ; } else if ( desc . endsWith ( "<STR_LIT:Z>" ) ) { primitive = "<STR_LIT:boolean>" ; } if ( primitive != null ) { for ( int ii = <NUM_LIT:0> ; ii < desc . length ( ) - <NUM_LIT:1> ; ii ++ ) { primitive += "<STR_LIT:[]>" ; } return primitive ; } } return StringUtils . EMPTY ; } private String getAccess ( int access ) { StringBuffer buffer = new StringBuffer ( ) ; if ( ( access & Opcodes . ACC_PUBLIC ) != <NUM_LIT:0> ) { buffer . append ( "<STR_LIT>" ) ; } if ( ( access & Opcodes . ACC_PRIVATE ) != <NUM_LIT:0> ) { buffer . append ( "<STR_LIT>" ) ; } if ( ( access & Opcodes . ACC_PROTECTED ) != <NUM_LIT:0> ) { buffer . append ( "<STR_LIT>" ) ; } if ( ( access & Opcodes . ACC_STATIC ) != <NUM_LIT:0> ) { buffer . append ( "<STR_LIT>" ) ; } if ( ( access & Opcodes . ACC_FINAL ) != <NUM_LIT:0> ) { buffer . append ( "<STR_LIT>" ) ; } if ( ( access & Opcodes . ACC_TRANSIENT ) != <NUM_LIT:0> ) { buffer . append ( "<STR_LIT>" ) ; } if ( ( access & Opcodes . ACC_NATIVE ) != <NUM_LIT:0> ) { buffer . append ( "<STR_LIT>" ) ; } if ( ( access & Opcodes . ACC_SYNCHRONIZED ) != <NUM_LIT:0> ) { buffer . append ( "<STR_LIT>" ) ; } if ( ( access & Opcodes . ACC_ABSTRACT ) != <NUM_LIT:0> ) { buffer . append ( "<STR_LIT>" ) ; } return buffer . toString ( ) ; } private String getValueString ( Object value ) { if ( value instanceof String ) { return new StringBuffer ( ) . append ( '<CHAR_LIT:">' ) . append ( value ) . append ( '<CHAR_LIT:">' ) . toString ( ) ; } else if ( value instanceof Character ) { return new StringBuffer ( ) . append ( '<STR_LIT>' ) . append ( value ) . append ( '<STR_LIT>' ) . toString ( ) ; } return String . valueOf ( value ) ; } private class AsmAnnotationVisitor implements AnnotationVisitor { private boolean wrote = false ; private boolean wroteOpenParen = false ; public void visit ( String name , Object value ) { if ( name != null ) { writeOpenParen ( ) ; writer . print ( name ) ; writer . print ( "<STR_LIT:U+0020=U+0020>" ) ; writer . print ( getValueString ( value ) ) ; wrote = true ; } } public void visitEnum ( String name , String desc , String value ) { writeOpenParen ( ) ; writer . print ( getDescName ( desc ) ) ; writer . print ( '<CHAR_LIT:.>' ) ; writer . print ( value ) ; wrote = true ; } public AnnotationVisitor visitAnnotation ( String name , String desc ) { return new AsmAnnotationVisitor ( ) ; } public AnnotationVisitor visitArray ( String name ) { return new AsmAnnotationVisitor ( ) ; } public void visitEnd ( ) { if ( wrote ) { if ( wroteOpenParen ) { writer . print ( '<CHAR_LIT:)>' ) ; } writer . println ( ) ; wrote = false ; } } private void writeOpenParen ( ) { if ( ! wroteOpenParen ) { writer . print ( '<CHAR_LIT:(>' ) ; wroteOpenParen = true ; } else { writer . print ( "<STR_LIT:U+002CU+0020>" ) ; } } } private class AsmMethodVisitor implements MethodVisitor { private int access ; private String name ; private String desc ; private String [ ] exceptions ; public AsmMethodVisitor ( int access , String name , String desc , String [ ] exceptions ) { this . access = access ; this . name = name ; this . desc = desc ; this . exceptions = exceptions ; } public AnnotationVisitor visitAnnotationDefault ( ) { return new AsmAnnotationVisitor ( ) ; } public AnnotationVisitor visitAnnotation ( String desc , boolean visible ) { return new AsmAnnotationVisitor ( ) ; } public AnnotationVisitor visitParameterAnnotation ( int parameter , String desc , boolean visible ) { return new AsmAnnotationVisitor ( ) ; } public void visitAttribute ( Attribute attr ) { } public void visitCode ( ) { } public void visitInsn ( int opcode ) { } public void visitIntInsn ( int opcode , int operand ) { } public void visitVarInsn ( int opcode , int var ) { } public void visitTypeInsn ( int opcode , String desc ) { } public void visitFieldInsn ( int opcode , String owner , String name , String desc ) { } public void visitMethodInsn ( int opcode , String owner , String name , String desc ) { } public void visitJumpInsn ( int opcode , Label operand ) { } public void visitLabel ( Label label ) { } public void visitLdcInsn ( Object cst ) { } public void visitIincInsn ( int var , int increment ) { } public void visitTableSwitchInsn ( int min , int max , Label dflt , Label [ ] labels ) { } public void visitLookupSwitchInsn ( Label dflt , int [ ] keys , Label [ ] labels ) { } public void visitMultiANewArrayInsn ( String desc , int dims ) { } public void visitTryCatchBlock ( Label start , Label end , Label handler , String type ) { } public void visitLocalVariable ( String name , String desc , String signature , Label start , Label end , int index ) { } public void visitLineNumber ( int line , Label start ) { } public void visitMaxs ( int maxStack , int maxLocal ) { } public void visitEnd ( ) { if ( "<STR_LIT>" . equals ( name ) ) { return ; } if ( "<STR_LIT>" . equals ( name ) ) { name = AsmClassVisitor . this . name ; } String ret = "<STR_LIT>" ; int index = desc . lastIndexOf ( '<CHAR_LIT:)>' ) ; if ( index != - <NUM_LIT:1> ) { ret = getDescName ( desc . substring ( index + <NUM_LIT:1> , desc . length ( ) ) ) ; } StringBuffer params = new StringBuffer ( ) ; int openParen = desc . indexOf ( '<CHAR_LIT:(>' ) ; int closeParen = desc . indexOf ( '<CHAR_LIT:)>' ) ; if ( closeParen > ( openParen + <NUM_LIT:1> ) ) { String args = desc . substring ( openParen + <NUM_LIT:1> , closeParen ) ; StringBuffer buffer = new StringBuffer ( ) ; int paramIndex = <NUM_LIT:0> ; int typeLevel = <NUM_LIT:0> ; boolean inType = false ; for ( char c : args . toCharArray ( ) ) { if ( c == '<CHAR_LIT:[>' || c == '<CHAR_LIT>' ) { inType = false ; buffer . append ( c ) ; continue ; } if ( c == '<CHAR_LIT:;>' || ( ! inType && Character . isLetter ( c ) && Character . isUpperCase ( c ) && c != '<CHAR_LIT>' ) ) { buffer . append ( c ) ; if ( c == '<CHAR_LIT:;>' ) { typeLevel -= <NUM_LIT:1> ; inType = false ; } if ( typeLevel > <NUM_LIT:0> ) { continue ; } if ( params . length ( ) != <NUM_LIT:0> ) { params . append ( "<STR_LIT:U+002CU+0020>" ) ; } params . append ( getDescName ( buffer . toString ( ) ) ) ; params . append ( "<STR_LIT>" ) . append ( paramIndex ++ ) ; buffer = new StringBuffer ( ) ; continue ; } if ( ( ! inType && c == '<CHAR_LIT>' ) || c == '<CHAR_LIT>' ) { typeLevel += <NUM_LIT:1> ; inType = true ; } buffer . append ( c ) ; } } writer . print ( INDENT ) ; writer . print ( getAccess ( access ) ) ; writer . print ( ret ) ; writer . print ( '<CHAR_LIT:U+0020>' ) ; writer . print ( name ) ; writer . print ( '<CHAR_LIT:(>' ) ; writer . print ( params ) ; writer . print ( '<CHAR_LIT:)>' ) ; if ( exceptions != null && exceptions . length > <NUM_LIT:0> ) { writer . println ( ) ; writer . print ( INDENT ) ; writer . print ( INDENT ) ; writer . print ( "<STR_LIT>" ) ; for ( int ii = <NUM_LIT:0> ; ii < exceptions . length ; ii ++ ) { if ( ii > <NUM_LIT:0> ) { writer . print ( "<STR_LIT:U+002CU+0020>" ) ; } writer . print ( getDescName ( exceptions [ ii ] ) ) ; } } writer . print ( "<STR_LIT>" ) ; } } private class AsmFieldVisitor implements FieldVisitor { private int access ; private String name ; private String desc ; private Object value ; public AsmFieldVisitor ( int access , String name , String desc , Object value ) { this . access = access ; this . name = name ; this . desc = desc ; this . value = value ; } public AnnotationVisitor visitAnnotation ( String desc , boolean visible ) { return new AsmAnnotationVisitor ( ) ; } public void visitAttribute ( Attribute attr ) { } public void visitEnd ( ) { writer . print ( INDENT ) ; writer . print ( getAccess ( access ) ) ; writer . print ( getDescName ( desc ) ) ; writer . print ( '<CHAR_LIT:U+0020>' ) ; writer . print ( name ) ; if ( value != null ) { writer . print ( "<STR_LIT:U+0020=U+0020>" ) ; writer . print ( getValueString ( value ) ) ; } writer . print ( "<STR_LIT>" ) ; } } } } </s>
|
<s> package org . eclim . plugin . jdt . command . src ; import java . util . ArrayList ; import java . util . List ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . util . file . FileOffsets ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IncrementalProjectBuilder ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . compiler . IProblem ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class SrcUpdateCommand extends AbstractCommand { @ Override @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public Object execute ( CommandLine commandLine ) throws Exception { String file = commandLine . getValue ( Options . FILE_OPTION ) ; String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; IProject project = ProjectUtils . getProject ( projectName ) ; if ( ! commandLine . hasOption ( Options . VALIDATE_OPTION ) ) { ProjectUtils . getFile ( project , file ) ; } else { IJavaProject javaProject = JavaUtils . getJavaProject ( project ) ; ICompilationUnit src = JavaUtils . getCompilationUnit ( javaProject , file ) ; IProblem [ ] problems = JavaUtils . getProblems ( src ) ; ArrayList < Error > errors = new ArrayList < Error > ( ) ; String filename = src . getResource ( ) . getLocation ( ) . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; FileOffsets offsets = FileOffsets . compile ( filename ) ; for ( int ii = <NUM_LIT:0> ; ii < problems . length ; ii ++ ) { int [ ] lineColumn = offsets . offsetToLineColumn ( problems [ ii ] . getSourceStart ( ) ) ; errors . add ( new Error ( problems [ ii ] . getMessage ( ) , filename , lineColumn [ <NUM_LIT:0> ] , lineColumn [ <NUM_LIT:1> ] , problems [ ii ] . isWarning ( ) ) ) ; } boolean checkstyle = "<STR_LIT:true>" . equals ( getPreferences ( ) . getValue ( project , "<STR_LIT>" ) ) ; if ( checkstyle ) { errors . addAll ( ( List < Error > ) Services . getCommand ( "<STR_LIT>" ) . execute ( commandLine ) ) ; } if ( commandLine . hasOption ( Options . BUILD_OPTION ) ) { project . build ( IncrementalProjectBuilder . INCREMENTAL_BUILD , new NullProgressMonitor ( ) ) ; } return errors ; } return null ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . src ; import java . text . Collator ; import java . util . ArrayList ; import java . util . Collections ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IPackageFragmentRoot ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class CompletePackageCommand extends AbstractCommand { @ Override public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String name = commandLine . getValue ( Options . NAME_OPTION ) ; IJavaProject javaProject = JavaUtils . getJavaProject ( project ) ; IPackageFragment [ ] packs = javaProject . getPackageFragments ( ) ; ArrayList < String > results = new ArrayList < String > ( ) ; for ( IPackageFragment pack : packs ) { if ( pack . getKind ( ) != IPackageFragmentRoot . K_SOURCE ) { continue ; } String packName = pack . getElementName ( ) ; if ( packName . length ( ) > <NUM_LIT:0> && ! results . contains ( packName ) && ( name == null || packName . startsWith ( name ) ) ) { results . add ( packName ) ; } } Collections . sort ( results , Collator . getInstance ( ) ) ; return results ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . include ; import java . util . ArrayList ; import java . util . Collections ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . util . file . Position ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . IStatus ; import org . eclipse . core . runtime . OperationCanceledException ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . dom . ASTNode ; import org . eclipse . jdt . core . dom . CompilationUnit ; import org . eclipse . jdt . core . dom . ImportDeclaration ; import org . eclipse . jdt . core . dom . NodeFinder ; import org . eclipse . jdt . core . dom . rewrite . ImportRewrite ; import org . eclipse . jdt . core . dom . rewrite . ImportRewrite . ImportRewriteContext ; import org . eclipse . jdt . core . search . TypeNameMatch ; import org . eclipse . jdt . internal . corext . codemanipulation . AddImportsOperation ; import org . eclipse . jdt . internal . corext . codemanipulation . CodeGenerationMessages ; import org . eclipse . jdt . internal . corext . codemanipulation . ContextSensitiveImportRewriteContext ; import org . eclipse . jdt . internal . corext . codemanipulation . StubUtility ; import org . eclipse . jdt . internal . corext . util . JavaModelUtil ; import org . eclipse . jdt . ui . SharedASTProvider ; import org . eclipse . text . edits . InsertEdit ; import org . eclipse . text . edits . MultiTextEdit ; import org . eclipse . text . edits . TextEdit ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class ImportCommand extends AbstractCommand { @ Override public Object execute ( CommandLine commandLine ) throws Exception { String file = commandLine . getValue ( Options . FILE_OPTION ) ; String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; String type = commandLine . getValue ( Options . TYPE_OPTION ) ; int offset = getOffset ( commandLine ) ; ICompilationUnit src = JavaUtils . getCompilationUnit ( projectName , file ) ; IProject project = src . getJavaProject ( ) . getProject ( ) ; TextEdit edits = null ; int oldLength = src . getBuffer ( ) . getLength ( ) ; if ( type != null ) { CompilationUnit astRoot = SharedASTProvider . getAST ( src , SharedASTProvider . WAIT_YES , null ) ; edits = new MultiTextEdit ( ) ; ImportRewrite importRewrite = StubUtility . createImportRewrite ( astRoot , true ) ; ImportRewriteContext context = new ContextSensitiveImportRewriteContext ( astRoot , offset , importRewrite ) ; String res = importRewrite . addImport ( type , context ) ; if ( type . equals ( res ) ) { return CodeGenerationMessages . AddImportsOperation_error_importclash ; } TextEdit rewrite = importRewrite . rewriteImports ( null ) ; edits . addChild ( rewrite ) ; JavaModelUtil . applyEdit ( src , edits , true , null ) ; if ( src . isWorkingCopy ( ) ) { src . commitWorkingCopy ( false , null ) ; } } else { ChooseImport query = new ChooseImport ( project , type ) ; try { AddImportsOperation op = new AddImportsOperation ( src , offset , <NUM_LIT:1> , query , true , true ) ; op . run ( null ) ; edits = op . getResultingEdit ( ) ; if ( edits == null ) { IStatus status = op . getStatus ( ) ; return status . getSeverity ( ) != IStatus . OK ? status . getMessage ( ) : null ; } } catch ( OperationCanceledException oce ) { return query . choices ; } } TextEdit groupingEdit = importGroupingEdit ( src , edits . getOffset ( ) ) ; if ( groupingEdit != null ) { JavaModelUtil . applyEdit ( src , groupingEdit , true , null ) ; if ( src . isWorkingCopy ( ) ) { src . commitWorkingCopy ( false , null ) ; } } if ( edits . getOffset ( ) < offset ) { offset += src . getBuffer ( ) . getLength ( ) - oldLength ; } return Position . fromOffset ( ProjectUtils . getFilePath ( projectName , file ) , null , offset , <NUM_LIT:0> ) ; } private TextEdit importGroupingEdit ( ICompilationUnit src , int offset ) throws Exception { int separationLevel = getPreferences ( ) . getIntValue ( src . getJavaProject ( ) . getProject ( ) , "<STR_LIT>" ) ; String lineDelim = src . findRecommendedLineSeparator ( ) ; CompilationUnit astRoot = SharedASTProvider . getAST ( src , SharedASTProvider . WAIT_YES , null ) ; ASTNode node = NodeFinder . perform ( astRoot , offset , <NUM_LIT:1> ) ; MultiTextEdit edit = new MultiTextEdit ( ) ; if ( node != null && node . getNodeType ( ) == ASTNode . IMPORT_DECLARATION ) { ImportDeclaration imprt = ( ImportDeclaration ) node ; int end = node . getStartPosition ( ) + node . getLength ( ) + lineDelim . length ( ) ; ASTNode next = NodeFinder . perform ( astRoot , end , <NUM_LIT:1> ) ; if ( next != null && next . getNodeType ( ) == ASTNode . IMPORT_DECLARATION ) { ImportDeclaration nextImprt = ( ImportDeclaration ) next ; if ( ! ImportUtils . importsInSameGroup ( separationLevel , imprt , nextImprt ) ) { edit . addChild ( new InsertEdit ( end , lineDelim ) ) ; } } ASTNode prev = NodeFinder . perform ( astRoot , offset - ( lineDelim . length ( ) + <NUM_LIT:1> ) , <NUM_LIT:1> ) ; if ( prev != null && prev . getNodeType ( ) == ASTNode . IMPORT_DECLARATION ) { ImportDeclaration prevImprt = ( ImportDeclaration ) prev ; if ( ! ImportUtils . importsInSameGroup ( separationLevel , imprt , prevImprt ) ) { end = prev . getStartPosition ( ) + prev . getLength ( ) + lineDelim . length ( ) ; edit . addChild ( new InsertEdit ( end , lineDelim ) ) ; } } } return edit . getChildrenSize ( ) > <NUM_LIT:0> ? edit : null ; } private class ChooseImport implements AddImportsOperation . IChooseImportQuery { public ArrayList < String > choices ; private IProject project ; private String type ; public ChooseImport ( IProject project , String type ) { this . project = project ; this . type = type ; } @ Override public TypeNameMatch chooseImport ( TypeNameMatch [ ] choices , String name ) { if ( type != null ) { for ( TypeNameMatch match : choices ) { if ( type . equals ( match . getFullyQualifiedName ( ) ) ) { return match ; } } } if ( this . choices == null ) { try { this . choices = new ArrayList < String > ( choices . length ) ; for ( TypeNameMatch match : choices ) { String fqn = match . getFullyQualifiedName ( ) ; if ( ! ImportUtils . isImportExcluded ( project , fqn ) && ! this . choices . contains ( fqn ) ) { this . choices . add ( fqn ) ; } } if ( this . choices . size ( ) == <NUM_LIT:1> ) { type = this . choices . get ( <NUM_LIT:0> ) ; return chooseImport ( choices , name ) ; } Collections . sort ( this . choices ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } return null ; } } } </s>
|
<s> package org . eclim . plugin . jdt . command . include ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashSet ; import java . util . List ; import org . apache . commons . lang . StringUtils ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . util . file . Position ; import org . eclipse . core . resources . IProject ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . ISourceRange ; import org . eclipse . jdt . core . dom . CompilationUnit ; import org . eclipse . jdt . core . dom . ImportDeclaration ; import org . eclipse . jdt . core . search . TypeNameMatch ; import org . eclipse . jdt . internal . corext . codemanipulation . CodeGenerationSettings ; import org . eclipse . jdt . internal . corext . codemanipulation . OrganizeImportsOperation ; import org . eclipse . jdt . internal . corext . util . JavaModelUtil ; import org . eclipse . jdt . internal . ui . preferences . JavaPreferencesSettings ; import org . eclipse . jdt . ui . SharedASTProvider ; import org . eclipse . text . edits . InsertEdit ; import org . eclipse . text . edits . MultiTextEdit ; import org . eclipse . text . edits . TextEdit ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class ImportOrganizeCommand extends AbstractCommand { @ Override public Object execute ( CommandLine commandLine ) throws Exception { String file = commandLine . getValue ( Options . FILE_OPTION ) ; String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; String types = commandLine . getValue ( Options . TYPE_OPTION ) ; int offset = getOffset ( commandLine ) ; ICompilationUnit src = JavaUtils . getCompilationUnit ( projectName , file ) ; IProject project = src . getJavaProject ( ) . getProject ( ) ; int oldLength = src . getBuffer ( ) . getLength ( ) ; CompilationUnit astRoot = SharedASTProvider . getAST ( src , SharedASTProvider . WAIT_YES , null ) ; String [ ] typeNames = types != null ? StringUtils . split ( types , '<CHAR_LIT:U+002C>' ) : null ; ChooseImports query = new ChooseImports ( project , typeNames ) ; CodeGenerationSettings settings = JavaPreferencesSettings . getCodeGenerationSettings ( src . getJavaProject ( ) ) ; OrganizeImportsOperation op = new OrganizeImportsOperation ( src , astRoot , settings . importIgnoreLowercase , true , true , query ) ; TextEdit edit = op . createTextEdit ( null ) ; if ( query . choices != null && query . choices . size ( ) > <NUM_LIT:0> ) { return query . choices ; } if ( edit != null ) { JavaModelUtil . applyEdit ( src , edit , true , null ) ; if ( src . isWorkingCopy ( ) ) { src . commitWorkingCopy ( false , null ) ; } } TextEdit groupingEdit = importGroupingEdit ( src ) ; if ( groupingEdit != null ) { if ( edit == null ) { edit = groupingEdit ; } JavaModelUtil . applyEdit ( src , groupingEdit , true , null ) ; if ( src . isWorkingCopy ( ) ) { src . commitWorkingCopy ( false , null ) ; } } if ( edit != null ) { if ( edit . getOffset ( ) < offset ) { offset += src . getBuffer ( ) . getLength ( ) - oldLength ; } return Position . fromOffset ( ProjectUtils . getFilePath ( projectName , file ) , null , offset , <NUM_LIT:0> ) ; } return null ; } private TextEdit importGroupingEdit ( ICompilationUnit src ) throws Exception { int separationLevel = getPreferences ( ) . getIntValue ( src . getJavaProject ( ) . getProject ( ) , "<STR_LIT>" ) ; CompilationUnit astRoot = SharedASTProvider . getAST ( src , SharedASTProvider . WAIT_YES , null ) ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) List < ImportDeclaration > imports = astRoot . imports ( ) ; String lineDelim = src . findRecommendedLineSeparator ( ) ; MultiTextEdit edit = new MultiTextEdit ( ) ; ImportDeclaration next = null ; for ( int i = imports . size ( ) - <NUM_LIT:1> ; i >= <NUM_LIT:0> ; i -- ) { ImportDeclaration imprt = imports . get ( i ) ; int end = imprt . getStartPosition ( ) + imprt . getLength ( ) + lineDelim . length ( ) ; if ( next != null && end == next . getStartPosition ( ) && ! ImportUtils . importsInSameGroup ( separationLevel , imprt , next ) ) { edit . addChild ( new InsertEdit ( end , lineDelim ) ) ; } next = imprt ; } return edit . getChildrenSize ( ) > <NUM_LIT:0> ? edit : null ; } private class ChooseImports implements OrganizeImportsOperation . IChooseImportQuery { public ArrayList < ArrayList < String > > choices ; private IProject project ; private HashSet < String > types ; public ChooseImports ( IProject project , String [ ] types ) { this . project = project ; if ( types != null ) { this . types = new HashSet < String > ( types . length ) ; for ( String type : types ) { this . types . add ( type ) ; } } } public TypeNameMatch [ ] chooseImports ( TypeNameMatch [ ] [ ] choices , ISourceRange [ ] ranges ) { ArrayList < TypeNameMatch > chosen = new ArrayList < TypeNameMatch > ( ) ; this . choices = new ArrayList < ArrayList < String > > ( ) ; try { for ( TypeNameMatch [ ] matches : choices ) { boolean foundChoice = false ; if ( types != null && types . size ( ) > <NUM_LIT:0> ) { for ( TypeNameMatch match : matches ) { if ( types . contains ( match . getFullyQualifiedName ( ) ) ) { foundChoice = true ; chosen . add ( match ) ; break ; } } } if ( ! foundChoice ) { ArrayList < String > names = new ArrayList < String > ( matches . length ) ; for ( TypeNameMatch match : matches ) { String name = match . getFullyQualifiedName ( ) ; if ( ! ImportUtils . isImportExcluded ( project , name ) ) { names . add ( name ) ; } } if ( names . size ( ) == <NUM_LIT:1> ) { for ( TypeNameMatch match : matches ) { if ( names . get ( <NUM_LIT:0> ) . equals ( match . getFullyQualifiedName ( ) ) ) { chosen . add ( match ) ; break ; } } } else if ( names . size ( ) > <NUM_LIT:0> ) { Collections . sort ( names ) ; this . choices . add ( names ) ; } } } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } return chosen . toArray ( new TypeNameMatch [ chosen . size ( ) ] ) ; } } } </s>
|
<s> package org . eclim . plugin . jdt . command . include ; import java . util . ArrayList ; import java . util . List ; import org . apache . commons . lang . StringUtils ; import org . eclim . plugin . core . preference . Preferences ; import org . eclipse . core . resources . IProject ; import org . eclipse . jdt . core . dom . ImportDeclaration ; public class ImportUtils { public static boolean importsInSameGroup ( int separationLevel , ImportDeclaration i1 , ImportDeclaration i2 ) { if ( separationLevel == <NUM_LIT:0> ) { return true ; } List < String > pn1 = packageName ( i1 ) ; List < String > pn2 = packageName ( i2 ) ; for ( int i = <NUM_LIT:0> ; ( i < separationLevel || separationLevel == - <NUM_LIT:1> ) ; i ++ ) { int level = i + <NUM_LIT:1> ; if ( pn1 . size ( ) < level ) { return pn2 . size ( ) < level ; } if ( pn2 . size ( ) < level ) { return pn1 . size ( ) < level ; } if ( ! pn1 . get ( i ) . equals ( pn2 . get ( i ) ) ) { return false ; } } return true ; } public static List < String > packageName ( ImportDeclaration imprt ) { String name = imprt . getName ( ) . getFullyQualifiedName ( ) ; List < String > pack = new ArrayList < String > ( ) ; for ( String part : StringUtils . split ( name , '<CHAR_LIT:.>' ) ) { if ( Character . isUpperCase ( part . charAt ( <NUM_LIT:0> ) ) ) { break ; } pack . add ( part ) ; } return pack ; } public static boolean isImportExcluded ( IProject project , String name ) throws Exception { String [ ] patterns = Preferences . getInstance ( ) . getArrayValue ( project , "<STR_LIT>" ) ; for ( String pattern : patterns ) { if ( name . matches ( pattern ) ) { return true ; } } return false ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . refactoring ; import java . lang . reflect . Field ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . refactoring . AbstractRefactorCommand ; import org . eclim . plugin . core . command . refactoring . Refactor ; import org . eclim . plugin . core . command . refactoring . RefactorException ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IField ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . ILocalVariable ; import org . eclipse . jdt . core . IMember ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . ITypeParameter ; import org . eclipse . jdt . internal . corext . refactoring . rename . JavaRenameProcessor ; import org . eclipse . jdt . internal . corext . refactoring . rename . MethodChecks ; import org . eclipse . jdt . internal . corext . refactoring . rename . RenameEnumConstProcessor ; import org . eclipse . jdt . internal . corext . refactoring . rename . RenameFieldProcessor ; import org . eclipse . jdt . internal . corext . refactoring . rename . RenameLocalVariableProcessor ; import org . eclipse . jdt . internal . corext . refactoring . rename . RenameNonVirtualMethodProcessor ; import org . eclipse . jdt . internal . corext . refactoring . rename . RenamePackageProcessor ; import org . eclipse . jdt . internal . corext . refactoring . rename . RenameTypeParameterProcessor ; import org . eclipse . jdt . internal . corext . refactoring . rename . RenameTypeProcessor ; import org . eclipse . jdt . internal . corext . refactoring . rename . RenameVirtualMethodProcessor ; import org . eclipse . jdt . internal . corext . refactoring . tagging . IReferenceUpdating ; import org . eclipse . jdt . internal . corext . refactoring . tagging . ITextUpdating ; import org . eclipse . jdt . internal . corext . util . JdtFlags ; import org . eclipse . jdt . ui . refactoring . RenameSupport ; import org . eclipse . ltk . core . refactoring . Refactoring ; import org . eclipse . ltk . core . refactoring . participants . RenameRefactoring ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class RenameCommand extends AbstractRefactorCommand { @ Override public Refactor createRefactoring ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; String name = commandLine . getValue ( Options . NAME_OPTION ) ; int offset = getOffset ( commandLine ) ; int length = commandLine . getIntValue ( Options . LENGTH_OPTION ) ; int flags = RenameSupport . UPDATE_REFERENCES ; ICompilationUnit src = JavaUtils . getCompilationUnit ( project , file ) ; IJavaElement [ ] elements = src . codeSelect ( offset , length ) ; if ( elements == null || elements . length == <NUM_LIT:0> ) { throw new RefactorException ( ) ; } IJavaElement element = elements [ <NUM_LIT:0> ] ; if ( element instanceof IMember ) { ICompilationUnit cu = ( ( IMember ) element ) . getCompilationUnit ( ) ; if ( cu == null ) { throw new RefactorException ( Services . getMessage ( "<STR_LIT>" , element . getElementName ( ) ) ) ; } } JavaRenameProcessor processor = getProcessor ( element , name , flags ) ; Refactoring refactoring = new RenameRefactoring ( processor ) ; String desc = refactoring . getName ( ) + "<STR_LIT:U+0020(>" + element . getElementName ( ) + "<STR_LIT>" + name + '<CHAR_LIT:)>' ; return new Refactor ( desc , refactoring ) ; } private JavaRenameProcessor getProcessor ( IJavaElement element , String name , int flags ) throws Exception { JavaRenameProcessor processor ; if ( element instanceof IPackageFragment ) { processor = new RenamePackageProcessor ( ( IPackageFragment ) element ) ; Field renameSubpackages = RenamePackageProcessor . class . getDeclaredField ( "<STR_LIT>" ) ; renameSubpackages . setAccessible ( true ) ; renameSubpackages . setBoolean ( processor , true ) ; } else if ( element instanceof IType ) { processor = new RenameTypeProcessor ( ( IType ) element ) ; } else if ( element instanceof IMethod ) { IMethod method = ( IMethod ) element ; if ( MethodChecks . isVirtual ( method ) ) { processor = new RenameVirtualMethodProcessor ( method ) ; } else { processor = new RenameNonVirtualMethodProcessor ( method ) ; } } else if ( element instanceof IField ) { IField field = ( IField ) element ; if ( JdtFlags . isEnum ( field ) ) { processor = new RenameEnumConstProcessor ( field ) ; } else { flags |= RenameSupport . UPDATE_GETTER_METHOD ; flags |= RenameSupport . UPDATE_SETTER_METHOD ; RenameFieldProcessor renameField = new RenameFieldProcessor ( field ) ; renameField . setRenameGetter ( ( flags & RenameSupport . UPDATE_GETTER_METHOD ) != <NUM_LIT:0> ) ; renameField . setRenameSetter ( ( flags & RenameSupport . UPDATE_SETTER_METHOD ) != <NUM_LIT:0> ) ; processor = renameField ; } } else if ( element instanceof ITypeParameter ) { processor = new RenameTypeParameterProcessor ( ( ITypeParameter ) element ) ; } else if ( element instanceof ILocalVariable ) { processor = new RenameLocalVariableProcessor ( ( ILocalVariable ) element ) ; } else { return null ; } processor . setNewElementName ( name ) ; if ( processor instanceof IReferenceUpdating ) { IReferenceUpdating reference = ( IReferenceUpdating ) processor ; reference . setUpdateReferences ( ( flags & RenameSupport . UPDATE_REFERENCES ) != <NUM_LIT:0> ) ; } if ( processor instanceof ITextUpdating ) { ITextUpdating text = ( ITextUpdating ) processor ; @ SuppressWarnings ( "<STR_LIT:deprecation>" ) int TEXT_UPDATES = RenameSupport . UPDATE_TEXTUAL_MATCHES | RenameSupport . UPDATE_REGULAR_COMMENTS | RenameSupport . UPDATE_STRING_LITERALS ; text . setUpdateTextualMatches ( ( flags & TEXT_UPDATES ) != <NUM_LIT:0> ) ; } return processor ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . refactoring ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . eclipse . EclimPlugin ; import org . eclim . plugin . core . command . refactoring . AbstractRefactorCommand ; import org . eclim . plugin . core . command . refactoring . Refactor ; import org . eclim . plugin . core . command . refactoring . RefactorException ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclipse . core . resources . IResource ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . internal . corext . refactoring . reorg . IReorgDestination ; import org . eclipse . jdt . internal . corext . refactoring . reorg . IReorgPolicy . IMovePolicy ; import org . eclipse . jdt . internal . corext . refactoring . reorg . JavaMoveProcessor ; import org . eclipse . jdt . internal . corext . refactoring . reorg . ReorgDestinationFactory ; import org . eclipse . jdt . internal . corext . refactoring . reorg . ReorgPolicyFactory ; import org . eclipse . jdt . internal . corext . util . JavaModelUtil ; import org . eclipse . jdt . internal . ui . refactoring . reorg . CreateTargetQueries ; import org . eclipse . jdt . internal . ui . refactoring . reorg . ReorgQueries ; import org . eclipse . ltk . core . refactoring . Refactoring ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; import org . eclipse . ltk . core . refactoring . participants . MoveRefactoring ; import org . eclipse . swt . widgets . Shell ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class MoveCommand extends AbstractRefactorCommand { @ Override public Refactor createRefactoring ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; String packName = commandLine . getValue ( Options . NAME_OPTION ) ; ICompilationUnit src = JavaUtils . getCompilationUnit ( project , file ) ; IPackageFragmentRoot root = JavaModelUtil . getPackageFragmentRoot ( src ) ; IPackageFragment pack = root . getPackageFragment ( packName ) ; ICompilationUnit dest = pack . getCompilationUnit ( src . getElementName ( ) ) ; if ( dest . exists ( ) ) { throw new RefactorException ( Services . getMessage ( "<STR_LIT>" , pack . getElementName ( ) , src . getElementName ( ) ) ) ; } if ( ! pack . exists ( ) ) { pack = root . createPackageFragment ( packName , true , null ) ; } IMovePolicy policy = ReorgPolicyFactory . createMovePolicy ( new IResource [ <NUM_LIT:0> ] , new IJavaElement [ ] { src } ) ; JavaMoveProcessor processor = new JavaMoveProcessor ( policy ) ; IReorgDestination destination = ReorgDestinationFactory . createDestination ( pack ) ; RefactoringStatus status = processor . setDestination ( destination ) ; if ( status . hasError ( ) ) { throw new RefactorException ( status ) ; } Shell shell = EclimPlugin . getShell ( ) ; processor . setCreateTargetQueries ( new CreateTargetQueries ( shell ) ) ; processor . setReorgQueries ( new ReorgQueries ( shell ) ) ; Refactoring refactoring = new MoveRefactoring ( processor ) ; String desc = refactoring . getName ( ) + "<STR_LIT:U+0020(>" + src . getElementName ( ) + "<STR_LIT>" + pack . getElementName ( ) + '<CHAR_LIT:)>' ; return new Refactor ( desc , refactoring ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . correct ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . HashSet ; import java . util . List ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . command . refactoring . ResourceChangeListener ; import org . eclim . plugin . jdt . command . include . ImportUtils ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IWorkspace ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . compiler . IProblem ; import org . eclipse . jdt . core . dom . rewrite . ImportRewrite ; import org . eclipse . jdt . core . formatter . CodeFormatter ; import org . eclipse . jdt . core . refactoring . CompilationUnitChange ; import org . eclipse . jdt . internal . ui . text . correction . AssistContext ; import org . eclipse . jdt . internal . ui . text . correction . CorrectionMessages ; import org . eclipse . jdt . internal . ui . text . correction . ReorgCorrectionsSubProcessor . ClasspathFixCorrectionProposal ; import org . eclipse . jdt . internal . ui . text . correction . proposals . NewCUUsingWizardProposal ; import org . eclipse . jdt . ui . text . java . CompletionProposalComparator ; import org . eclipse . jdt . ui . text . java . IJavaCompletionProposal ; import org . eclipse . jdt . ui . text . java . IProblemLocation ; import org . eclipse . jdt . ui . text . java . IQuickFixProcessor ; import org . eclipse . jdt . ui . text . java . correction . ASTRewriteCorrectionProposal ; import org . eclipse . jdt . ui . text . java . correction . ChangeCorrectionProposal ; import org . eclipse . ltk . core . refactoring . Change ; import org . eclipse . ltk . core . refactoring . PerformChangeOperation ; import org . eclipse . ltk . core . refactoring . RefactoringCore ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; import org . eclipse . ltk . core . refactoring . RefactoringStatusEntry ; import org . eclipse . ltk . core . refactoring . TextFileChange ; import org . eclipse . text . edits . TextEdit ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class CodeCorrectCommand extends AbstractCommand { private static HashSet < Class < ? extends IJavaCompletionProposal > > IGNORE_BY_TYPE = new HashSet < Class < ? extends IJavaCompletionProposal > > ( ) ; static { IGNORE_BY_TYPE . add ( NewCUUsingWizardProposal . class ) ; IGNORE_BY_TYPE . add ( ClasspathFixCorrectionProposal . class ) ; } private static HashSet < String > IGNORE_BY_INFO = new HashSet < String > ( ) ; static { IGNORE_BY_INFO . add ( CorrectionMessages . LocalCorrectionsSubProcessor_InferGenericTypeArguments_description ) ; } @ Override public Object execute ( CommandLine commandLine ) throws Exception { String file = commandLine . getValue ( Options . FILE_OPTION ) ; String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; int line = commandLine . getIntValue ( Options . LINE_OPTION ) ; int offset = getOffset ( commandLine ) ; ICompilationUnit src = JavaUtils . getCompilationUnit ( projectName , file ) ; IProblem problem = getProblem ( src , line , offset ) ; if ( problem == null ) { String message = Services . getMessage ( "<STR_LIT>" , file , line ) ; if ( commandLine . hasOption ( Options . APPLY_OPTION ) ) { throw new RuntimeException ( message ) ; } return message ; } List < ChangeCorrectionProposal > proposals = getProposals ( src , problem ) ; if ( commandLine . hasOption ( Options . APPLY_OPTION ) ) { ChangeCorrectionProposal proposal = proposals . get ( commandLine . getIntValue ( Options . APPLY_OPTION ) ) ; return apply ( src , proposal ) ; } HashMap < String , Object > result = new HashMap < String , Object > ( ) ; result . put ( "<STR_LIT:message>" , problem . getMessage ( ) ) ; result . put ( "<STR_LIT>" , problem . getSourceStart ( ) ) ; result . put ( "<STR_LIT>" , getCorrections ( proposals ) ) ; return result ; } private IProblem getProblem ( ICompilationUnit src , int line , int offset ) throws Exception { IProblem [ ] problems = JavaUtils . getProblems ( src ) ; ArrayList < IProblem > errors = new ArrayList < IProblem > ( ) ; for ( int ii = <NUM_LIT:0> ; ii < problems . length ; ii ++ ) { if ( problems [ ii ] . getSourceLineNumber ( ) == line ) { errors . add ( problems [ ii ] ) ; } } IProblem problem = null ; if ( errors . size ( ) == <NUM_LIT:0> ) { return null ; } else if ( errors . size ( ) > <NUM_LIT:0> ) { for ( IProblem p : errors ) { if ( offset < p . getSourceStart ( ) && offset <= p . getSourceEnd ( ) ) { problem = p ; } } } if ( problem == null ) { problem = ( IProblem ) errors . get ( <NUM_LIT:0> ) ; } return problem ; } private List < ChangeCorrectionProposal > getProposals ( ICompilationUnit src , IProblem problem ) throws Exception { IProject project = src . getJavaProject ( ) . getProject ( ) ; ArrayList < ChangeCorrectionProposal > results = new ArrayList < ChangeCorrectionProposal > ( ) ; int length = ( problem . getSourceEnd ( ) + <NUM_LIT:1> ) - problem . getSourceStart ( ) ; AssistContext context = new AssistContext ( src , problem . getSourceStart ( ) , length ) ; IProblemLocation [ ] locations = new IProblemLocation [ ] { new ProblemLocation ( problem ) } ; IQuickFixProcessor [ ] processors = JavaUtils . getQuickFixProcessors ( src ) ; for ( int ii = <NUM_LIT:0> ; ii < processors . length ; ii ++ ) { if ( processors [ ii ] != null && processors [ ii ] . hasCorrections ( src , problem . getID ( ) ) ) { if ( processors [ ii ] . getClass ( ) . getName ( ) . equals ( "<STR_LIT>" ) ) { continue ; } IJavaCompletionProposal [ ] proposals = processors [ ii ] . getCorrections ( context , locations ) ; if ( proposals != null ) { for ( IJavaCompletionProposal proposal : proposals ) { if ( ! ( proposal instanceof ChangeCorrectionProposal ) ) { continue ; } if ( IGNORE_BY_TYPE . contains ( proposal . getClass ( ) ) || IGNORE_BY_INFO . contains ( proposal . getAdditionalProposalInfo ( ) ) ) { continue ; } if ( proposal instanceof ASTRewriteCorrectionProposal ) { ImportRewrite rewrite = ( ( ASTRewriteCorrectionProposal ) proposal ) . getImportRewrite ( ) ; if ( rewrite != null ) { boolean exclude = true ; for ( String fqn : rewrite . getAddedImports ( ) ) { if ( ! ImportUtils . isImportExcluded ( project , fqn ) ) { exclude = false ; break ; } } for ( String fqn : rewrite . getAddedStaticImports ( ) ) { if ( ! ImportUtils . isImportExcluded ( project , fqn ) ) { exclude = false ; break ; } } if ( exclude ) { continue ; } } } results . add ( ( ChangeCorrectionProposal ) proposal ) ; } } } } Collections . sort ( results , new CompletionProposalComparator ( ) ) ; return results ; } private List < CodeCorrectResult > getCorrections ( List < ChangeCorrectionProposal > proposals ) throws Exception { ArrayList < CodeCorrectResult > corrections = new ArrayList < CodeCorrectResult > ( ) ; int index = <NUM_LIT:0> ; for ( ChangeCorrectionProposal proposal : proposals ) { String preview = proposal . getAdditionalProposalInfo ( ) ; if ( preview != null ) { preview = preview . replaceAll ( "<STR_LIT>" , "<STR_LIT:n>" ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT>" , "<STR_LIT:<>" ) . replaceAll ( "<STR_LIT>" , "<STR_LIT:>>" ) ; } corrections . add ( new CodeCorrectResult ( index , proposal . getDisplayString ( ) , preview ) ) ; index ++ ; } return corrections ; } private Object apply ( ICompilationUnit src , ChangeCorrectionProposal proposal ) throws Exception { Change change = null ; try { NullProgressMonitor monitor = new NullProgressMonitor ( ) ; change = proposal . getChange ( ) ; change . initializeValidationData ( monitor ) ; RefactoringStatus status = change . isValid ( monitor ) ; if ( status . hasFatalError ( ) ) { List < String > errors = new ArrayList < String > ( ) ; for ( RefactoringStatusEntry entry : status . getEntries ( ) ) { String message = entry . getMessage ( ) ; if ( ! errors . contains ( message ) && ! message . startsWith ( "<STR_LIT>" ) ) { errors . add ( message ) ; } } HashMap < String , List < String > > result = new HashMap < String , List < String > > ( ) ; result . put ( "<STR_LIT>" , errors ) ; return result ; } ResourceChangeListener rcl = new ResourceChangeListener ( ) ; IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; workspace . addResourceChangeListener ( rcl ) ; try { TextEdit edit = null ; if ( change instanceof TextFileChange ) { TextFileChange fileChange = ( TextFileChange ) change ; fileChange . setSaveMode ( TextFileChange . FORCE_SAVE ) ; edit = fileChange . getEdit ( ) ; } PerformChangeOperation changeOperation = new PerformChangeOperation ( change ) ; changeOperation . setUndoManager ( RefactoringCore . getUndoManager ( ) , proposal . getName ( ) ) ; changeOperation . run ( monitor ) ; if ( edit != null && change instanceof CompilationUnitChange && src . equals ( ( ( CompilationUnitChange ) change ) . getCompilationUnit ( ) ) ) { JavaUtils . format ( src , CodeFormatter . K_COMPILATION_UNIT , edit . getOffset ( ) , edit . getLength ( ) ) ; } return rcl . getChangedFiles ( ) ; } finally { workspace . removeResourceChangeListener ( rcl ) ; } } finally { if ( change != null ) { change . dispose ( ) ; } } } } </s>
|
<s> package org . eclim . plugin . jdt . command . correct ; public class CodeCorrectResult { private int index ; private String description ; private String preview ; public CodeCorrectResult ( int index , String description , String preview ) { this . index = index ; this . description = description ; this . preview = preview ; } public int getIndex ( ) { return index ; } public String getDescription ( ) { return description ; } public String getPreview ( ) { return preview ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . correct ; import org . eclipse . jdt . core . IJavaModelMarker ; import org . eclipse . jdt . core . compiler . IProblem ; import org . eclipse . jdt . core . dom . ASTNode ; import org . eclipse . jdt . core . dom . CompilationUnit ; import org . eclipse . jdt . core . dom . NodeFinder ; import org . eclipse . jdt . ui . text . java . IProblemLocation ; public class ProblemLocation implements IProblemLocation { private int id ; private int offset ; private int length ; private String [ ] arguments ; private boolean error ; public ProblemLocation ( IProblem problem ) { id = problem . getID ( ) ; offset = problem . getSourceStart ( ) ; length = ( problem . getSourceEnd ( ) + <NUM_LIT:1> ) - offset ; arguments = problem . getArguments ( ) ; error = problem . isError ( ) ; } public ASTNode getCoveredNode ( CompilationUnit astRoot ) { NodeFinder finder = new NodeFinder ( astRoot , offset , length ) ; return finder . getCoveredNode ( ) ; } public ASTNode getCoveringNode ( CompilationUnit astRoot ) { NodeFinder finder = new NodeFinder ( astRoot , offset , length ) ; return finder . getCoveringNode ( ) ; } public int getLength ( ) { return length ; } public int getOffset ( ) { return offset ; } public String [ ] getProblemArguments ( ) { return arguments ; } public int getProblemId ( ) { return id ; } public boolean isError ( ) { return error ; } public String getMarkerType ( ) { return IJavaModelMarker . JAVA_MODEL_PROBLEM_MARKER ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . search ; import java . io . File ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . List ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import org . apache . commons . vfs . FileObject ; import org . apache . commons . vfs . FileSystemManager ; import org . apache . commons . vfs . VFS ; import org . apache . tools . ant . taskdefs . condition . Os ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . util . file . FileUtils ; import org . eclim . util . file . Position ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . ICodeAssist ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . search . IJavaSearchConstants ; import org . eclipse . jdt . core . search . IJavaSearchScope ; import org . eclipse . jdt . core . search . SearchEngine ; import org . eclipse . jdt . core . search . SearchMatch ; import org . eclipse . jdt . core . search . SearchParticipant ; import org . eclipse . jdt . core . search . SearchPattern ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class SearchCommand extends AbstractCommand { public static final String CONTEXT_ALL = "<STR_LIT:all>" ; public static final String CONTEXT_DECLARATIONS = "<STR_LIT>" ; public static final String CONTEXT_IMPLEMENTORS = "<STR_LIT>" ; public static final String CONTEXT_REFERENCES = "<STR_LIT>" ; public static final String SCOPE_ALL = "<STR_LIT:all>" ; public static final String SCOPE_PROJECT = "<STR_LIT>" ; public static final String SCOPE_TYPE = "<STR_LIT:type>" ; public static final String TYPE_ALL = "<STR_LIT:all>" ; public static final String TYPE_ANNOTATION = "<STR_LIT>" ; public static final String TYPE_CLASS = "<STR_LIT:class>" ; public static final String TYPE_CLASS_OR_ENUM = "<STR_LIT>" ; public static final String TYPE_CLASS_OR_INTERFACE = "<STR_LIT>" ; public static final String TYPE_CONSTRUCTOR = "<STR_LIT>" ; public static final String TYPE_ENUM = "<STR_LIT>" ; public static final String TYPE_FIELD = "<STR_LIT:field>" ; public static final String TYPE_INTERFACE = "<STR_LIT>" ; public static final String TYPE_METHOD = "<STR_LIT>" ; public static final String TYPE_PACKAGE = "<STR_LIT>" ; public static final String TYPE_TYPE = "<STR_LIT:type>" ; private static final Pattern INNER_CLASS = Pattern . compile ( "<STR_LIT>" ) ; protected static final String ANDROID_NATURE = "<STR_LIT>" ; private static final Pattern ANDROID_JDK_URL = Pattern . compile ( "<STR_LIT>" ) ; @ Override public Object execute ( CommandLine commandLine ) throws Exception { List < SearchMatch > matches = executeSearch ( commandLine ) ; String projectName = commandLine . getValue ( Options . NAME_OPTION ) ; IProject project = projectName != null ? ProjectUtils . getProject ( projectName ) : null ; ArrayList < Position > results = new ArrayList < Position > ( ) ; for ( SearchMatch match : matches ) { IJavaElement element = ( IJavaElement ) match . getElement ( ) ; if ( element != null ) { int elementType = element . getElementType ( ) ; if ( elementType != IJavaElement . PACKAGE_FRAGMENT && elementType != IJavaElement . PACKAGE_FRAGMENT_ROOT ) { Position result = createPosition ( project , match ) ; if ( result != null ) { results . add ( result ) ; } } } } return results ; } public List < SearchMatch > executeSearch ( CommandLine commandLine ) throws Exception { int context = - <NUM_LIT:1> ; if ( commandLine . hasOption ( Options . CONTEXT_OPTION ) ) { context = getContext ( commandLine . getValue ( Options . CONTEXT_OPTION ) ) ; } String project = commandLine . getValue ( Options . NAME_OPTION ) ; String scope = commandLine . getValue ( Options . SCOPE_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; String offset = commandLine . getValue ( Options . OFFSET_OPTION ) ; String length = commandLine . getValue ( Options . LENGTH_OPTION ) ; String pat = commandLine . getValue ( Options . PATTERN_OPTION ) ; SearchPattern pattern = null ; IJavaProject javaProject = project != null ? JavaUtils . getJavaProject ( project ) : null ; if ( file != null && offset != null && length != null ) { int charOffset = getOffset ( commandLine ) ; IJavaElement element = getElement ( javaProject , file , charOffset , Integer . parseInt ( length ) ) ; if ( element != null ) { if ( context == - <NUM_LIT:1> ) { context = getElementContextualContext ( element ) ; } pattern = SearchPattern . createPattern ( element , context ) ; } } else if ( pat != null ) { if ( context == - <NUM_LIT:1> ) { context = IJavaSearchConstants . DECLARATIONS ; } int matchType = SearchPattern . R_EXACT_MATCH ; if ( pat . indexOf ( '<CHAR_LIT>' ) != - <NUM_LIT:1> || pat . indexOf ( '<CHAR_LIT>' ) != - <NUM_LIT:1> ) { matchType = SearchPattern . R_PATTERN_MATCH ; } else if ( pat . equals ( pat . toUpperCase ( ) ) ) { matchType |= SearchPattern . R_CAMELCASE_MATCH ; } boolean caseSensitive = ! commandLine . hasOption ( Options . CASE_INSENSITIVE_OPTION ) ; if ( caseSensitive ) { matchType |= SearchPattern . R_CASE_SENSITIVE ; } int type = getType ( commandLine . getValue ( Options . TYPE_OPTION ) ) ; Matcher matcher = INNER_CLASS . matcher ( pat ) ; if ( matcher . matches ( ) ) { pattern = SearchPattern . createPattern ( matcher . replaceFirst ( "<STR_LIT>" ) , type , context , matchType ) ; Pattern toMatch = Pattern . compile ( pat . replace ( "<STR_LIT:.>" , "<STR_LIT:\\.>" ) . replace ( "<STR_LIT:$>" , "<STR_LIT>" ) . replace ( "<STR_LIT:(>" , "<STR_LIT>" ) . replace ( "<STR_LIT:)>" , "<STR_LIT>" ) . replace ( "<STR_LIT:*>" , "<STR_LIT>" ) . replace ( "<STR_LIT:?>" , "<STR_LIT:.>" ) ) ; List < SearchMatch > matches = search ( pattern , getScope ( scope , javaProject ) ) ; Iterator < SearchMatch > iterator = matches . iterator ( ) ; while ( iterator . hasNext ( ) ) { SearchMatch match = iterator . next ( ) ; String name = JavaUtils . getFullyQualifiedName ( ( IJavaElement ) match . getElement ( ) ) . replace ( "<STR_LIT:#>" , "<STR_LIT:.>" ) ; if ( ! toMatch . matcher ( name ) . matches ( ) ) { iterator . remove ( ) ; } } return matches ; } pattern = SearchPattern . createPattern ( pat , type , context , matchType ) ; } else { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" ) ) ; } List < SearchMatch > matches = search ( pattern , getScope ( scope , javaProject ) ) ; return matches ; } protected List < SearchMatch > search ( SearchPattern pattern , IJavaSearchScope scope ) throws CoreException { SearchRequestor requestor = new SearchRequestor ( ) ; if ( pattern != null ) { SearchEngine engine = new SearchEngine ( ) ; SearchParticipant [ ] participants = new SearchParticipant [ ] { SearchEngine . getDefaultSearchParticipant ( ) } ; engine . search ( pattern , participants , scope , requestor , null ) ; } return requestor . getMatches ( ) ; } protected IJavaElement getElement ( IJavaProject javaProject , String filename , int offset , int length ) throws Exception { ICodeAssist code = null ; try { code = JavaUtils . getCompilationUnit ( javaProject , filename ) ; } catch ( IllegalArgumentException iae ) { code = JavaUtils . findClassFile ( javaProject , filename ) ; } if ( code != null ) { IJavaElement [ ] elements = code . codeSelect ( offset , length ) ; if ( elements != null && elements . length > <NUM_LIT:0> ) { return elements [ <NUM_LIT:0> ] ; } } return null ; } protected boolean isJarArchive ( IPath path ) { String ext = path . getFileExtension ( ) ; return ext != null && ext . toLowerCase ( ) . matches ( "<STR_LIT>" ) ; } protected Position createPosition ( IProject project , SearchMatch match ) throws Exception { IJavaElement element = ( IJavaElement ) match . getElement ( ) ; IJavaElement parent = JavaUtils . getPrimaryElement ( element ) ; String file = null ; String elementName = JavaUtils . getFullyQualifiedName ( parent ) ; if ( parent . getElementType ( ) == IJavaElement . CLASS_FILE ) { IResource resource = parent . getResource ( ) ; if ( resource != null && resource . getType ( ) == IResource . FILE && ! isJarArchive ( resource . getLocation ( ) ) ) { file = resource . getLocation ( ) . toOSString ( ) ; } else { IPath path = null ; IPackageFragmentRoot root = ( IPackageFragmentRoot ) parent . getParent ( ) . getParent ( ) ; resource = root . getResource ( ) ; if ( resource != null ) { if ( resource . getType ( ) == IResource . PROJECT ) { path = ProjectUtils . getIPath ( ( IProject ) resource ) ; } else { path = resource . getLocation ( ) ; } } else { path = root . getPath ( ) ; } String classFile = elementName . replace ( '<CHAR_LIT:.>' , File . separatorChar ) ; if ( isJarArchive ( path ) ) { file = "<STR_LIT>" + path . toOSString ( ) + '<CHAR_LIT>' + classFile + "<STR_LIT:.class>" ; } else { file = path . toOSString ( ) + '<CHAR_LIT:/>' + classFile + "<STR_LIT:.class>" ; } if ( ANDROID_JDK_URL . matcher ( file ) . matches ( ) && project != null && ! project . hasNature ( ANDROID_NATURE ) ) { return null ; } IPath srcPath = root . getSourceAttachmentPath ( ) ; if ( srcPath != null ) { String rootPath ; IProject elementProject = root . getJavaProject ( ) . getProject ( ) ; if ( srcPath . isAbsolute ( ) && elementProject . getName ( ) . equals ( srcPath . segment ( <NUM_LIT:0> ) ) ) { rootPath = ProjectUtils . getFilePath ( elementProject , srcPath . toString ( ) ) ; } else { rootPath = srcPath . toOSString ( ) ; } String srcFile = FileUtils . toUrl ( rootPath + File . separator + classFile + "<STR_LIT>" ) ; FileSystemManager fsManager = VFS . getManager ( ) ; FileObject fileObject = fsManager . resolveFile ( srcFile ) ; if ( fileObject . exists ( ) ) { file = srcFile ; } else if ( Os . isFamily ( Os . FAMILY_MAC ) ) { srcFile = FileUtils . toUrl ( rootPath + File . separator + "<STR_LIT:src>" + File . separator + classFile + "<STR_LIT>" ) ; fileObject = fsManager . resolveFile ( srcFile ) ; if ( fileObject . exists ( ) ) { file = srcFile ; } } } } } else { IPath location = match . getResource ( ) . getLocation ( ) ; file = location != null ? location . toOSString ( ) : null ; } elementName = JavaUtils . getFullyQualifiedName ( element ) ; return Position . fromOffset ( file . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) , elementName , match . getOffset ( ) , match . getLength ( ) ) ; } protected IJavaSearchScope getScope ( String scope , IJavaProject project ) throws Exception { if ( project == null ) { return SearchEngine . createWorkspaceScope ( ) ; } else if ( SCOPE_PROJECT . equals ( scope ) ) { return SearchEngine . createJavaSearchScope ( new IJavaElement [ ] { project } ) ; } return SearchEngine . createWorkspaceScope ( ) ; } protected int getElementContextualContext ( IJavaElement element ) { Class < ? > theClass = element . getClass ( ) ; if ( theClass . equals ( org . eclipse . jdt . internal . core . SourceType . class ) || theClass . equals ( org . eclipse . jdt . internal . core . SourceField . class ) || theClass . equals ( org . eclipse . jdt . internal . core . SourceMethod . class ) ) { return IJavaSearchConstants . ALL_OCCURRENCES ; } return IJavaSearchConstants . DECLARATIONS ; } protected int getContext ( String context ) { if ( CONTEXT_ALL . equals ( context ) ) { return IJavaSearchConstants . ALL_OCCURRENCES ; } else if ( CONTEXT_IMPLEMENTORS . equals ( context ) ) { return IJavaSearchConstants . IMPLEMENTORS ; } else if ( CONTEXT_REFERENCES . equals ( context ) ) { return IJavaSearchConstants . REFERENCES ; } return IJavaSearchConstants . DECLARATIONS ; } protected int getType ( String type ) { if ( TYPE_ANNOTATION . equals ( type ) ) { return IJavaSearchConstants . ANNOTATION_TYPE ; } else if ( TYPE_CLASS . equals ( type ) ) { return IJavaSearchConstants . CLASS ; } else if ( TYPE_CLASS_OR_ENUM . equals ( type ) ) { return IJavaSearchConstants . CLASS_AND_ENUM ; } else if ( TYPE_CLASS_OR_INTERFACE . equals ( type ) ) { return IJavaSearchConstants . CLASS_AND_INTERFACE ; } else if ( TYPE_CONSTRUCTOR . equals ( type ) ) { return IJavaSearchConstants . CONSTRUCTOR ; } else if ( TYPE_ENUM . equals ( type ) ) { return IJavaSearchConstants . ENUM ; } else if ( TYPE_FIELD . equals ( type ) ) { return IJavaSearchConstants . FIELD ; } else if ( TYPE_INTERFACE . equals ( type ) ) { return IJavaSearchConstants . INTERFACE ; } else if ( TYPE_METHOD . equals ( type ) ) { return IJavaSearchConstants . METHOD ; } else if ( TYPE_PACKAGE . equals ( type ) ) { return IJavaSearchConstants . PACKAGE ; } return IJavaSearchConstants . TYPE ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . search ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Comparator ; import java . util . List ; import org . eclim . plugin . jdt . util . IJavaElementComparator ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . search . SearchMatch ; public class SearchRequestor extends org . eclipse . jdt . core . search . SearchRequestor { private static final SearchMatchComparator MATCH_COMPARATOR = new SearchMatchComparator ( ) ; private ArrayList < SearchMatch > matches = new ArrayList < SearchMatch > ( ) ; public void acceptSearchMatch ( SearchMatch match ) throws CoreException { if ( match . getAccuracy ( ) == SearchMatch . A_ACCURATE ) { matches . add ( match ) ; } } public List < SearchMatch > getMatches ( ) { Collections . sort ( matches , MATCH_COMPARATOR ) ; return matches ; } public static class SearchMatchComparator implements Comparator < SearchMatch > { private static final IJavaElementComparator ELEMENT_COMPATATOR = new IJavaElementComparator ( ) ; public int compare ( SearchMatch o1 , SearchMatch o2 ) { return ELEMENT_COMPATATOR . compare ( ( IJavaElement ) o1 . getElement ( ) , ( IJavaElement ) o2 . getElement ( ) ) ; } public boolean equals ( Object obj ) { if ( obj instanceof SearchMatchComparator ) { return true ; } return false ; } } } </s>
|
<s> package org . eclim . plugin . jdt . command . classpath ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclipse . core . runtime . Path ; import org . eclipse . jdt . core . JavaCore ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class ClasspathVariableCreateCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . NAME_OPTION ) ; String path = commandLine . getValue ( Options . PATH_OPTION ) ; JavaCore . setClasspathVariable ( name , new Path ( path ) , null ) ; return Services . getMessage ( "<STR_LIT>" , name ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . classpath ; public class ClasspathVariable implements Comparable < ClasspathVariable > { private String name ; private String path ; public String getName ( ) { return this . name ; } public void setName ( String name ) { this . name = name ; } public String getPath ( ) { return this . path ; } public void setPath ( String path ) { this . path = path ; } public int compareTo ( ClasspathVariable obj ) { if ( obj == this ) { return <NUM_LIT:0> ; } return this . getName ( ) . compareTo ( obj . getName ( ) ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . classpath ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclipse . jdt . core . JavaCore ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class ClasspathVariableDeleteCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . NAME_OPTION ) ; JavaCore . removeClasspathVariable ( name , null ) ; return Services . getMessage ( "<STR_LIT>" , name ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . classpath ; import java . util . ArrayList ; import java . util . Collections ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . JavaCore ; @ Command ( name = "<STR_LIT>" ) public class ClasspathVariablesCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { ArrayList < ClasspathVariable > results = new ArrayList < ClasspathVariable > ( ) ; String [ ] names = JavaCore . getClasspathVariableNames ( ) ; for ( int ii = <NUM_LIT:0> ; ii < names . length ; ii ++ ) { IPath path = JavaCore . getClasspathVariable ( names [ ii ] ) ; if ( path != null ) { ClasspathVariable variable = new ClasspathVariable ( ) ; variable . setName ( names [ ii ] ) ; variable . setPath ( path . toOSString ( ) ) ; results . add ( variable ) ; } } Collections . sort ( results ) ; return results ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . classpath ; import org . apache . commons . lang . SystemUtils ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . jdt . util . ClasspathUtils ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . util . StringUtils ; import org . eclipse . jdt . core . IJavaProject ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class ClasspathCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . PROJECT_OPTION ) ; String delim = commandLine . getValue ( Options . DELIMETER_OPTION , SystemUtils . PATH_SEPARATOR ) ; IJavaProject javaProject = JavaUtils . getJavaProject ( name ) ; String [ ] paths = ClasspathUtils . getClasspath ( javaProject ) ; return StringUtils . join ( paths , delim ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . webxml ; import java . util . ArrayList ; import java . util . List ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclim . command . Options ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IType ; import org . xml . sax . Attributes ; import org . xml . sax . Locator ; import org . xml . sax . SAXException ; import org . xml . sax . helpers . DefaultHandler ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class ValidateCommand extends org . eclim . plugin . core . command . xml . ValidateCommand { public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; WebXmlHandler handler = new WebXmlHandler ( JavaUtils . getJavaProject ( project ) , file ) ; List < Error > errors = super . validate ( project , file , false , handler ) ; errors . addAll ( handler . getErrors ( ) ) ; return errors ; } private static class WebXmlHandler extends DefaultHandler { private static final String CLASS = "<STR_LIT>" ; private static final String FILTER = "<STR_LIT>" ; private static final String FILTER_MAPPING = "<STR_LIT>" ; private static final String FILTER_NAME = "<STR_LIT>" ; private static final String SERVLET = "<STR_LIT>" ; private static final String SERVLET_MAPPING = "<STR_LIT>" ; private static final String SERVLET_NAME = "<STR_LIT>" ; private Locator locator ; private IJavaProject project ; private String file ; private StringBuffer text = new StringBuffer ( ) ; private boolean mapping = false ; private ArrayList < String > filters = new ArrayList < String > ( ) ; private ArrayList < String > servlets = new ArrayList < String > ( ) ; private ArrayList < Error > errors = new ArrayList < Error > ( ) ; public WebXmlHandler ( IJavaProject project , String file ) throws Exception { this . project = project ; this . file = ProjectUtils . getFilePath ( project . getProject ( ) , file ) ; } public void setDocumentLocator ( Locator locator ) { super . setDocumentLocator ( locator ) ; this . locator = locator ; } public void startElement ( String uri , String localName , String qName , Attributes attributes ) throws SAXException { if ( SERVLET . equals ( localName ) || FILTER . equals ( localName ) ) { mapping = false ; } else if ( SERVLET_MAPPING . equals ( localName ) || FILTER_MAPPING . equals ( localName ) ) { mapping = true ; } } public void endElement ( String uri , String localName , String qName ) throws SAXException { try { if ( localName . endsWith ( CLASS ) ) { String name = text . toString ( ) . trim ( ) ; IType type = project . findType ( name ) ; if ( type == null || ! type . exists ( ) ) { String message = Services . getMessage ( "<STR_LIT>" , project . getElementName ( ) , name ) ; errors . add ( new Error ( message , file , locator . getLineNumber ( ) , <NUM_LIT:1> , false ) ) ; } } else if ( SERVLET_NAME . equals ( localName ) ) { String name = text . toString ( ) . trim ( ) ; if ( mapping && ! servlets . contains ( name ) ) { String message = Services . getMessage ( "<STR_LIT>" , name ) ; errors . add ( new Error ( message , file , locator . getLineNumber ( ) , <NUM_LIT:1> , false ) ) ; } else if ( ! mapping ) { servlets . add ( name ) ; } } else if ( FILTER_NAME . equals ( localName ) ) { String name = text . toString ( ) . trim ( ) ; if ( mapping && ! filters . contains ( name ) ) { String message = Services . getMessage ( "<STR_LIT>" , name ) ; errors . add ( new Error ( message , file , locator . getLineNumber ( ) , <NUM_LIT:1> , false ) ) ; } else if ( ! mapping ) { filters . add ( name ) ; } } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } finally { text = new StringBuffer ( ) ; } } public void characters ( char [ ] ch , int start , int length ) throws SAXException { for ( int ii = start ; ii < start + length ; ii ++ ) { text . append ( ch [ ii ] ) ; } } public List < Error > getErrors ( ) { return errors ; } } } </s>
|
<s> package org . eclim . plugin . jdt . command . impl ; import java . util . Arrays ; import java . util . Comparator ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . plugin . jdt . util . TypeUtils ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IField ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . core . dom . CompilationUnit ; import org . eclipse . jdt . core . dom . IMethodBinding ; import org . eclipse . jdt . core . dom . ITypeBinding ; import org . eclipse . jdt . core . dom . IVariableBinding ; import org . eclipse . jdt . core . dom . Modifier ; import org . eclipse . jdt . core . formatter . CodeFormatter ; import org . eclipse . jdt . internal . corext . codemanipulation . AddCustomConstructorOperation ; import org . eclipse . jdt . internal . corext . codemanipulation . CodeGenerationSettings ; import org . eclipse . jdt . internal . corext . codemanipulation . StubUtility2 ; import org . eclipse . jdt . internal . corext . dom . ASTNodes ; import org . eclipse . jdt . internal . corext . dom . Bindings ; import org . eclipse . jdt . internal . corext . refactoring . structure . ASTNodeSearchUtil ; import org . eclipse . jdt . internal . ui . actions . ActionMessages ; import org . eclipse . jdt . internal . ui . preferences . JavaPreferencesSettings ; import org . eclipse . jdt . ui . SharedASTProvider ; import org . eclipse . text . edits . TextEdit ; import com . google . gson . Gson ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class ConstructorCommand extends AbstractCommand { @ Override public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; String propertiesOption = commandLine . getValue ( Options . PROPERTIES_OPTION ) ; int offset = getOffset ( commandLine ) ; String [ ] properties = { } ; if ( propertiesOption != null ) { properties = new Gson ( ) . fromJson ( propertiesOption , String [ ] . class ) ; } ICompilationUnit src = JavaUtils . getCompilationUnit ( project , file ) ; IType type = TypeUtils . getType ( src , offset ) ; CompilationUnit cu = SharedASTProvider . getAST ( src , SharedASTProvider . WAIT_YES , null ) ; ITypeBinding typeBinding = ASTNodes . getTypeBinding ( cu , type ) ; if ( typeBinding . isAnonymous ( ) ) { return ActionMessages . GenerateConstructorUsingFieldsAction_error_anonymous_class ; } IVariableBinding [ ] variables = new IVariableBinding [ properties . length ] ; for ( int ii = <NUM_LIT:0> ; ii < properties . length ; ii ++ ) { IField field = type . getField ( properties [ ii ] ) ; if ( ! field . exists ( ) ) { return Services . getMessage ( "<STR_LIT>" , properties [ ii ] , type . getElementName ( ) ) ; } variables [ ii ] = ASTNodeSearchUtil . getFieldDeclarationFragmentNode ( field , cu ) . resolveBinding ( ) ; } if ( findExistingConstructor ( type , properties ) . exists ( ) ) { return Services . getMessage ( "<STR_LIT>" , type . getElementName ( ) + '<CHAR_LIT:(>' + buildParams ( type , properties ) + '<CHAR_LIT:)>' ) ; } IMethodBinding constructor = findParentConstructor ( cu , typeBinding , variables ) ; if ( constructor == null ) { return ActionMessages . GenerateConstructorUsingFieldsAction_error_nothing_found ; } insertConstructor ( src , cu , typeBinding , variables , constructor , commandLine ) ; return null ; } private void insertConstructor ( ICompilationUnit src , CompilationUnit cu , ITypeBinding typeBinding , IVariableBinding [ ] variables , IMethodBinding constructor , CommandLine commandLine ) throws Exception { CodeGenerationSettings settings = JavaPreferencesSettings . getCodeGenerationSettings ( src . getJavaProject ( ) ) ; settings . createComments = true ; boolean isDefault = constructor . getDeclaringClass ( ) . getQualifiedName ( ) . equals ( "<STR_LIT>" ) || constructor . isDefaultConstructor ( ) ; AddCustomConstructorOperation op = new AddCustomConstructorOperation ( cu , typeBinding , variables , constructor , getSibling ( ( IType ) typeBinding . getJavaElement ( ) ) , settings , true , true ) ; op . setOmitSuper ( ! commandLine . hasOption ( Options . SUPERTYPE_OPTION ) || isDefault ) ; if ( ! typeBinding . isEnum ( ) ) { op . setVisibility ( Modifier . PUBLIC ) ; } op . run ( null ) ; TextEdit edit = op . getResultingEdit ( ) ; if ( edit != null ) { edit = edit . getChildren ( ) [ <NUM_LIT:0> ] ; JavaUtils . format ( src , CodeFormatter . K_COMPILATION_UNIT , edit . getOffset ( ) , edit . getLength ( ) ) ; } } private IMethod findExistingConstructor ( IType type , String [ ] properties ) throws Exception { if ( properties . length == <NUM_LIT:0> ) { return type . getMethod ( type . getElementName ( ) , null ) ; } String [ ] fieldSigs = new String [ properties . length ] ; for ( int ii = <NUM_LIT:0> ; ii < properties . length ; ii ++ ) { fieldSigs [ ii ] = type . getField ( properties [ ii ] ) . getTypeSignature ( ) ; } return type . getMethod ( type . getElementName ( ) , fieldSigs ) ; } private IMethodBinding findParentConstructor ( CompilationUnit cu , ITypeBinding typeBinding , IVariableBinding [ ] variables ) { IMethodBinding constructor = null ; if ( typeBinding . isEnum ( ) || variables . length != <NUM_LIT:0> ) { ITypeBinding binding = cu . getAST ( ) . resolveWellKnownType ( "<STR_LIT>" ) ; constructor = Bindings . findMethodInType ( binding , "<STR_LIT>" , new ITypeBinding [ <NUM_LIT:0> ] ) ; } else { IMethodBinding [ ] bindings = StubUtility2 . getVisibleConstructors ( typeBinding , false , true ) ; Arrays . sort ( bindings , new Comparator < IMethodBinding > ( ) { public int compare ( IMethodBinding b1 , IMethodBinding b2 ) { return b1 . getParameterTypes ( ) . length - b2 . getParameterTypes ( ) . length ; } } ) ; constructor = bindings . length > <NUM_LIT:0> ? bindings [ <NUM_LIT:0> ] : null ; } return constructor ; } private IJavaElement getSibling ( IType type ) throws Exception { IJavaElement sibling = null ; IMethod [ ] methods = type . getMethods ( ) ; for ( int ii = <NUM_LIT:0> ; ii < methods . length ; ii ++ ) { if ( methods [ ii ] . isConstructor ( ) ) { sibling = ii < methods . length - <NUM_LIT:1> ? methods [ ii + <NUM_LIT:1> ] : null ; } } if ( sibling == null ) { if ( methods . length > <NUM_LIT:0> ) { sibling = methods [ <NUM_LIT:0> ] ; } else { IType [ ] types = type . getTypes ( ) ; sibling = types != null && types . length > <NUM_LIT:0> ? types [ <NUM_LIT:0> ] : null ; } } return sibling ; } private String buildParams ( IType type , String [ ] fields ) throws Exception { StringBuffer params = new StringBuffer ( ) ; for ( int ii = <NUM_LIT:0> ; ii < fields . length ; ii ++ ) { if ( ii != <NUM_LIT:0> ) { params . append ( "<STR_LIT:U+002CU+0020>" ) ; } IField field = type . getField ( fields [ ii ] ) ; params . append ( Signature . getSignatureSimpleName ( field . getTypeSignature ( ) ) ) . append ( '<CHAR_LIT:U+0020>' ) . append ( field . getElementName ( ) ) ; } return params . toString ( ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . impl ; import java . util . Arrays ; import java . util . List ; import org . apache . commons . lang . StringUtils ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . jdt . util . ASTUtils ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . plugin . jdt . util . MethodUtils ; import org . eclim . plugin . jdt . util . TypeUtils ; import org . eclim . util . file . Position ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IField ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . core . dom . Modifier ; import org . eclipse . jdt . core . formatter . CodeFormatter ; import org . eclipse . jdt . internal . corext . codemanipulation . AddGetterSetterOperation ; import org . eclipse . jdt . internal . corext . codemanipulation . CodeGenerationSettings ; import org . eclipse . jdt . internal . corext . codemanipulation . GetterSetterUtil ; import org . eclipse . jdt . internal . ui . preferences . JavaPreferencesSettings ; import org . eclipse . text . edits . TextEdit ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class BeanPropertiesCommand extends AbstractCommand { private static final String GETTER = "<STR_LIT>" ; private static final String SETTER = "<STR_LIT>" ; private static final int TYPE_GET = <NUM_LIT:0> ; private static final int TYPE_GET_INDEX = <NUM_LIT:1> ; private static final int TYPE_SET = <NUM_LIT:2> ; private static final int TYPE_SET_INDEX = <NUM_LIT:3> ; private static final String INT_SIG = Signature . createTypeSignature ( "<STR_LIT:int>" , true ) ; private static final String [ ] INT_ARG = new String [ ] { INT_SIG } ; private static final IField [ ] NO_FIELDS = new IField [ <NUM_LIT:0> ] ; @ Override public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; String methods = commandLine . getValue ( Options . TYPE_OPTION ) ; String [ ] properties = StringUtils . split ( commandLine . getValue ( Options . PROPERTIES_OPTION ) , '<CHAR_LIT:U+002C>' ) ; int offset = getOffset ( commandLine ) ; boolean indexed = commandLine . hasOption ( Options . INDEXED_OPTION ) ; ICompilationUnit src = JavaUtils . getCompilationUnit ( project , file ) ; IType type = TypeUtils . getType ( src , offset ) ; List < IField > fields = Arrays . asList ( type . getFields ( ) ) ; CodeGenerationSettings settings = JavaPreferencesSettings . getCodeGenerationSettings ( src . getJavaProject ( ) ) ; settings . createComments = true ; for ( String property : properties ) { IField field = type . getField ( property ) ; if ( field != null ) { boolean isArray = Signature . getArrayCount ( field . getTypeSignature ( ) ) > <NUM_LIT:0> ; IField getter = methods . indexOf ( GETTER ) != - <NUM_LIT:1> ? field : null ; IField setter = methods . indexOf ( SETTER ) != - <NUM_LIT:1> ? field : null ; int methodType = getter != null ? TYPE_GET : TYPE_SET ; if ( getter != null && setter != null && GetterSetterUtil . getGetter ( field ) != null ) { methodType = TYPE_SET ; } IJavaElement sibling = getSibling ( type , fields , field , methodType ) ; insertMethods ( src , type , sibling , settings , getter , setter ) ; if ( isArray && indexed ) { insertIndexMethods ( src , type , fields , settings , getter , setter ) ; } } } return null ; } private void insertMethods ( ICompilationUnit src , IType type , IJavaElement sibling , CodeGenerationSettings settings , IField getter , IField setter ) throws Exception { AddGetterSetterOperation op = new AddGetterSetterOperation ( type , getter != null ? new IField [ ] { getter } : NO_FIELDS , setter != null ? new IField [ ] { setter } : NO_FIELDS , NO_FIELDS , ASTUtils . getCompilationUnit ( src ) , null , sibling , settings , true , true ) ; op . run ( null ) ; TextEdit edit = op . getResultingEdit ( ) ; if ( edit != null ) { JavaUtils . format ( src , CodeFormatter . K_COMPILATION_UNIT , edit . getOffset ( ) , edit . getLength ( ) ) ; } } private void insertIndexMethods ( ICompilationUnit src , IType type , List < IField > fields , CodeGenerationSettings settings , IField getter , IField setter ) throws Exception { if ( getter != null ) { IMethod existing = getBeanMethod ( type , getter , TYPE_GET_INDEX ) ; if ( existing == null ) { IJavaElement sibling = getSibling ( type , fields , getter , TYPE_GET_INDEX ) ; String name = GetterSetterUtil . getGetterName ( getter , null ) ; String stub = GetterSetterUtil . getGetterStub ( getter , name , settings . createComments , Modifier . PUBLIC ) ; stub = stub . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; stub = stub . replaceFirst ( "<STR_LIT>" + name + "<STR_LIT>" , "<STR_LIT>" ) ; stub = stub . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; IMethod inserted = type . createMethod ( stub , sibling , false , null ) ; Position position = TypeUtils . getPosition ( type , inserted ) ; JavaUtils . format ( src , CodeFormatter . K_COMPILATION_UNIT , position . getOffset ( ) , position . getLength ( ) ) ; } } if ( setter != null ) { IMethod existing = getBeanMethod ( type , setter , TYPE_SET_INDEX ) ; if ( existing == null ) { IJavaElement sibling = getSibling ( type , fields , setter , TYPE_SET_INDEX ) ; String name = GetterSetterUtil . getSetterName ( setter , null ) ; String stub = GetterSetterUtil . getSetterStub ( setter , name , settings . createComments , Modifier . PUBLIC ) ; stub = stub . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; stub = stub . replaceFirst ( "<STR_LIT:(>" + name + "<STR_LIT>" , "<STR_LIT>" ) ; stub = stub . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; IMethod inserted = type . createMethod ( stub , sibling , false , null ) ; Position position = TypeUtils . getPosition ( type , inserted ) ; JavaUtils . format ( src , CodeFormatter . K_COMPILATION_UNIT , position . getOffset ( ) , position . getLength ( ) ) ; } } } private IJavaElement getSibling ( IType type , List < IField > fields , IField field , int methodType ) throws Exception { IMethod siblingMethod = null ; int siblingType = TYPE_GET ; for ( int ii = TYPE_GET ; ii <= TYPE_SET_INDEX ; ii ++ ) { IMethod method = getBeanMethod ( type , field , ii ) ; if ( method != null ) { siblingMethod = method ; siblingType = ii ; } } if ( siblingMethod != null ) { if ( siblingType < methodType ) { siblingMethod = MethodUtils . getMethodAfter ( type , siblingMethod ) ; } if ( siblingMethod != null ) { return siblingMethod ; } return getFirstInnerType ( type ) ; } int index = fields . indexOf ( field ) ; if ( fields . size ( ) > <NUM_LIT:1> && ( index + <NUM_LIT:1> ) < fields . size ( ) ) { IMethod method = null ; for ( int ii = index + <NUM_LIT:1> ; method == null && ii < fields . size ( ) ; ii ++ ) { IField property = ( IField ) fields . get ( ii ) ; method = getBeanMethod ( type , property , false ) ; } if ( method != null ) { return method ; } } if ( fields . size ( ) > <NUM_LIT:1> && index > <NUM_LIT:0> ) { IMethod method = null ; for ( int ii = index - <NUM_LIT:1> ; method == null && ii >= <NUM_LIT:0> ; ii -- ) { IField property = ( IField ) fields . get ( ii ) ; method = getBeanMethod ( type , property , true ) ; } if ( method != null ) { method = MethodUtils . getMethodAfter ( type , method ) ; if ( method != null ) { return method ; } } } return getFirstInnerType ( type ) ; } private IType getFirstInnerType ( IType type ) throws Exception { IType [ ] types = type . getTypes ( ) ; for ( int ii = <NUM_LIT:0> ; ii < types . length ; ii ++ ) { if ( ! types [ ii ] . isEnum ( ) ) { return types [ ii ] ; } } return null ; } private IMethod getBeanMethod ( IType type , IField field , int methodType ) throws Exception { String name = Signature . getSignatureSimpleName ( field . getTypeSignature ( ) ) ; boolean isArray = Signature . getArrayCount ( field . getTypeSignature ( ) ) > <NUM_LIT:0> ; String signature = null ; switch ( methodType ) { case TYPE_GET : return GetterSetterUtil . getGetter ( field ) ; case TYPE_GET_INDEX : if ( isArray ) { signature = GetterSetterUtil . getGetterName ( field , null ) + "<STR_LIT>" ; } break ; case TYPE_SET : return GetterSetterUtil . getSetter ( field ) ; case TYPE_SET_INDEX : if ( isArray ) { signature = GetterSetterUtil . getSetterName ( field , null ) + "<STR_LIT>" + name + '<CHAR_LIT:)>' ; } } if ( signature != null ) { IMethod [ ] methods = type . getMethods ( ) ; for ( int ii = <NUM_LIT:0> ; ii < methods . length ; ii ++ ) { String sig = MethodUtils . getMinimalMethodSignature ( methods [ ii ] , null ) ; if ( sig . equals ( signature ) ) { return methods [ ii ] ; } } } return null ; } private IMethod getBeanMethod ( IType type , IField field , boolean last ) throws Exception { IMethod result = null ; boolean isArray = Signature . getArrayCount ( field . getTypeSignature ( ) ) > <NUM_LIT:0> ; IMethod method = GetterSetterUtil . getGetter ( field ) ; if ( method != null && method . exists ( ) && ! last ) { return method ; } else if ( method != null && method . exists ( ) ) { result = method ; } if ( isArray ) { method = type . getMethod ( GetterSetterUtil . getGetterName ( field , null ) , INT_ARG ) ; if ( method . exists ( ) && ! last ) { return method ; } else if ( method . exists ( ) ) { result = method ; } } method = GetterSetterUtil . getSetter ( field ) ; if ( method != null && method . exists ( ) && ! last ) { return method ; } else if ( method != null && method . exists ( ) ) { result = method ; } if ( ! isArray ) { String elementType = Signature . getElementType ( field . getTypeSignature ( ) ) ; method = type . getMethod ( GetterSetterUtil . getSetterName ( field , null ) , new String [ ] { INT_SIG , elementType } ) ; if ( method . exists ( ) ) { result = method ; } } return result ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . impl ; import java . util . List ; @ SuppressWarnings ( "<STR_LIT:unused>" ) public class ImplResult { private String type ; private List < ImplType > superTypes ; public ImplResult ( String type , List < ImplType > superTypes ) { this . type = type ; this . superTypes = superTypes ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . impl ; @ SuppressWarnings ( "<STR_LIT:unused>" ) public class ImplType { private String packageName ; private String signature ; private String [ ] methods ; public ImplType ( String packageName , String signature , String [ ] methods ) { this . packageName = packageName ; this . signature = signature ; this . methods = methods ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . impl ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; import org . apache . commons . lang . StringUtils ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . plugin . jdt . util . MethodUtils ; import org . eclim . plugin . jdt . util . TypeUtils ; import org . eclipse . core . resources . IWorkspaceRunnable ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IImportDeclaration ; 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 . dom . CompilationUnit ; import org . eclipse . jdt . core . dom . IMethodBinding ; import org . eclipse . jdt . core . dom . IPackageBinding ; import org . eclipse . jdt . core . dom . ITypeBinding ; import org . eclipse . jdt . core . formatter . CodeFormatter ; import org . eclipse . jdt . internal . corext . codemanipulation . AddUnimplementedMethodsOperation ; import org . eclipse . jdt . internal . corext . codemanipulation . StubUtility2 ; import org . eclipse . jdt . internal . corext . dom . ASTNodes ; import org . eclipse . jdt . internal . corext . dom . Bindings ; import org . eclipse . jdt . internal . corext . refactoring . util . RefactoringASTParser ; import org . eclipse . jdt . internal . ui . javaeditor . ASTProvider ; import com . google . gson . Gson ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class ImplCommand extends AbstractCommand { @ Override public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; ICompilationUnit src = JavaUtils . getCompilationUnit ( project , file ) ; IType type = getType ( src , commandLine ) ; if ( commandLine . hasOption ( Options . SUPERTYPE_OPTION ) ) { insertMethods ( src , type , commandLine ) ; } return getImplResult ( src , type ) ; } protected IType getType ( ICompilationUnit src , CommandLine commandLine ) throws Exception { return commandLine . hasOption ( Options . TYPE_OPTION ) ? src . getJavaProject ( ) . findType ( commandLine . getValue ( Options . TYPE_OPTION ) . replace ( '<CHAR_LIT>' , '<CHAR_LIT:.>' ) ) : TypeUtils . getType ( src , getOffset ( commandLine ) ) ; } protected IWorkspaceRunnable getImplOperation ( ICompilationUnit src , IType type , Set < String > chosen , IJavaElement sibling , int pos , CommandLine commandLine ) throws Exception { RefactoringASTParser parser = new RefactoringASTParser ( ASTProvider . SHARED_AST_LEVEL ) ; CompilationUnit cu = parser . parse ( type . getCompilationUnit ( ) , true ) ; ITypeBinding typeBinding = ASTNodes . getTypeBinding ( cu , type ) ; String superType = commandLine . getValue ( Options . SUPERTYPE_OPTION ) ; List < IMethodBinding > overridable = getOverridableMethods ( cu , typeBinding ) ; List < IMethodBinding > override = new ArrayList < IMethodBinding > ( ) ; for ( IMethodBinding binding : overridable ) { ITypeBinding declBinding = binding . getDeclaringClass ( ) ; String fqn = declBinding . getQualifiedName ( ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; if ( fqn . equals ( superType ) && isChosen ( chosen , binding ) ) { override . add ( binding ) ; } } if ( override . size ( ) > <NUM_LIT:0> ) { return new AddUnimplementedMethodsOperation ( cu , typeBinding , override . toArray ( new IMethodBinding [ override . size ( ) ] ) , pos , true , true , true ) ; } return null ; } protected boolean isChosen ( Set < String > chosen , IMethodBinding methodBinding ) { return chosen == null || chosen . contains ( getMethodBindingShortCallSignature ( methodBinding ) ) ; } protected ImplResult getImplResult ( ICompilationUnit src , IType type ) throws Exception { List < IMethodBinding > overridable = getOverridableMethods ( src , type ) ; return getImplResult ( type . getFullyQualifiedName ( ) , overridable ) ; } protected ImplResult getImplResult ( String name , List < IMethodBinding > methods ) { ArrayList < ImplType > results = new ArrayList < ImplType > ( ) ; ArrayList < String > overrideMethods = null ; ITypeBinding curTypeBinding = null ; for ( IMethodBinding methodBinding : methods ) { ITypeBinding typeBinding = methodBinding . getDeclaringClass ( ) ; if ( typeBinding != curTypeBinding ) { if ( overrideMethods != null && overrideMethods . size ( ) > <NUM_LIT:0> ) { results . add ( createImplType ( curTypeBinding , overrideMethods ) ) ; } overrideMethods = new ArrayList < String > ( ) ; } curTypeBinding = typeBinding ; overrideMethods . add ( getMethodBindingSignature ( methodBinding ) ) ; } if ( overrideMethods != null && overrideMethods . size ( ) > <NUM_LIT:0> ) { results . add ( createImplType ( curTypeBinding , overrideMethods ) ) ; } return new ImplResult ( name , results ) ; } protected List < IMethodBinding > getOverridableMethods ( ICompilationUnit src , IType type ) throws Exception { RefactoringASTParser parser = new RefactoringASTParser ( ASTProvider . SHARED_AST_LEVEL ) ; CompilationUnit cu = parser . parse ( type . getCompilationUnit ( ) , true ) ; ITypeBinding typeBinding = ASTNodes . getTypeBinding ( cu , type ) ; return getOverridableMethods ( cu , typeBinding ) ; } protected List < IMethodBinding > getOverridableMethods ( CompilationUnit cu , ITypeBinding typeBinding ) throws Exception { if ( ! typeBinding . isClass ( ) ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , typeBinding . getQualifiedName ( ) ) ) ; } IPackageBinding packageBinding = typeBinding . getPackage ( ) ; IMethodBinding [ ] methods = StubUtility2 . getOverridableMethods ( cu . getAST ( ) , typeBinding , false ) ; ArrayList < IMethodBinding > overridable = new ArrayList < IMethodBinding > ( ) ; for ( IMethodBinding methodBinding : methods ) { if ( Bindings . isVisibleInHierarchy ( methodBinding , packageBinding ) ) { overridable . add ( methodBinding ) ; } } return overridable ; } private ImplType createImplType ( ITypeBinding typeBinding , List < String > overridable ) { String signature = ( typeBinding . isInterface ( ) ? "<STR_LIT>" : "<STR_LIT>" ) + typeBinding . getName ( ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; return new ImplType ( typeBinding . getPackage ( ) . getName ( ) , signature , overridable . toArray ( new String [ overridable . size ( ) ] ) ) ; } private void insertMethods ( ICompilationUnit src , IType type , CommandLine commandLine ) throws Exception { String methodsOption = commandLine . getValue ( Options . METHOD_OPTION ) ; HashSet < String > chosen = null ; if ( methodsOption != null ) { chosen = new HashSet < String > ( ) ; String [ ] sigs = new Gson ( ) . fromJson ( methodsOption , String [ ] . class ) ; for ( String sig : sigs ) { chosen . add ( sig . replace ( "<STR_LIT:U+0020>" , "<STR_LIT>" ) ) ; } } int pos = - <NUM_LIT:1> ; int len = src . getBuffer ( ) . getLength ( ) ; IJavaElement sibling = getSibling ( type ) ; if ( sibling != null ) { pos = ( ( ISourceReference ) sibling ) . getSourceRange ( ) . getOffset ( ) ; } IWorkspaceRunnable op = getImplOperation ( src , type , chosen , sibling , pos , commandLine ) ; if ( op != null ) { String lineDelim = src . findRecommendedLineSeparator ( ) ; IImportDeclaration [ ] imports = src . getImports ( ) ; int importsEnd = - <NUM_LIT:1> ; if ( imports . length > <NUM_LIT:0> ) { ISourceRange last = imports [ imports . length - <NUM_LIT:1> ] . getSourceRange ( ) ; importsEnd = last . getOffset ( ) + last . getLength ( ) + lineDelim . length ( ) ; } op . run ( null ) ; int offset = pos != - <NUM_LIT:1> ? pos : ( len - <NUM_LIT:1> - lineDelim . length ( ) ) ; int newLen = src . getBuffer ( ) . getLength ( ) ; int length = newLen - len - <NUM_LIT:1> ; int importLenChange = <NUM_LIT:0> ; imports = src . getImports ( ) ; if ( importsEnd != - <NUM_LIT:1> ) { ISourceRange last = imports [ imports . length - <NUM_LIT:1> ] . getSourceRange ( ) ; importLenChange = last . getOffset ( ) + last . getLength ( ) + lineDelim . length ( ) - importsEnd ; } else if ( imports . length > <NUM_LIT:0> ) { ISourceRange first = imports [ <NUM_LIT:0> ] . getSourceRange ( ) ; ISourceRange last = imports [ imports . length - <NUM_LIT:1> ] . getSourceRange ( ) ; importLenChange = last . getOffset ( ) + last . getLength ( ) + ( lineDelim . length ( ) * <NUM_LIT:2> ) - first . getOffset ( ) ; } offset += importLenChange ; length -= importLenChange ; JavaUtils . format ( src , CodeFormatter . K_COMPILATION_UNIT , offset , length ) ; } } private String getMethodBindingSignature ( IMethodBinding binding ) { return binding . toString ( ) . trim ( ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) . replaceFirst ( "<STR_LIT>" , getMethodBindingCallSignature ( binding ) ) ; } private String getMethodBindingCallSignature ( IMethodBinding binding ) { ITypeBinding [ ] paramTypes = binding . getParameterTypes ( ) ; String [ ] params = new String [ paramTypes . length ] ; for ( int i = <NUM_LIT:0> ; i < paramTypes . length ; i ++ ) { params [ i ] = paramTypes [ i ] . getQualifiedName ( ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; } return binding . getName ( ) + '<CHAR_LIT:(>' + StringUtils . join ( params , '<CHAR_LIT:U+002C>' ) + '<CHAR_LIT:)>' ; } private String getMethodBindingShortCallSignature ( IMethodBinding binding ) { return getMethodBindingCallSignature ( binding ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; } private IJavaElement getSibling ( IType type ) throws Exception { IJavaElement sibling = null ; IMethod [ ] methods = type . getMethods ( ) ; if ( methods . length > <NUM_LIT:0> ) { sibling = MethodUtils . getMethodAfter ( type , methods [ methods . length - <NUM_LIT:1> ] ) ; } if ( sibling == null ) { IType [ ] types = type . getTypes ( ) ; for ( int ii = <NUM_LIT:0> ; ii < types . length ; ii ++ ) { if ( ! types [ ii ] . isEnum ( ) ) { sibling = types [ ii ] ; break ; } } } return sibling ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . impl ; import java . util . ArrayList ; import java . util . List ; import java . util . Set ; import org . apache . commons . lang . StringUtils ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . jdt . command . impl . ImplCommand ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . plugin . jdt . util . TypeUtils ; import org . eclipse . core . resources . IWorkspaceRunnable ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IField ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . core . dom . CompilationUnit ; import org . eclipse . jdt . core . dom . IMethodBinding ; import org . eclipse . jdt . core . dom . ITypeBinding ; import org . eclipse . jdt . core . dom . IVariableBinding ; import org . eclipse . jdt . internal . corext . codemanipulation . AddDelegateMethodsOperation ; import org . eclipse . jdt . internal . corext . codemanipulation . AddDelegateMethodsOperation . DelegateEntry ; import org . eclipse . jdt . internal . corext . codemanipulation . CodeGenerationSettings ; import org . eclipse . jdt . internal . corext . codemanipulation . StubUtility2 ; import org . eclipse . jdt . internal . corext . dom . ASTNodes ; import org . eclipse . jdt . internal . corext . refactoring . structure . ASTNodeSearchUtil ; import org . eclipse . jdt . internal . corext . refactoring . util . RefactoringASTParser ; import org . eclipse . jdt . internal . ui . javaeditor . ASTProvider ; import org . eclipse . jdt . internal . ui . preferences . JavaPreferencesSettings ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class DelegateCommand extends ImplCommand { private ThreadLocal < IField > field = new ThreadLocal < IField > ( ) ; @ Override public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; ICompilationUnit src = JavaUtils . getCompilationUnit ( project , file ) ; IJavaElement element = null ; if ( commandLine . hasOption ( Options . VARIABLE_OPTION ) ) { String var = commandLine . getValue ( Options . VARIABLE_OPTION ) ; String [ ] parts = StringUtils . split ( var , "<STR_LIT:.>" ) ; String varName = parts [ parts . length - <NUM_LIT:1> ] ; IType type = getType ( src , commandLine ) ; element = type . getField ( varName ) ; } else { element = src . getElementAt ( getOffset ( commandLine ) ) ; } if ( element == null || element . getElementType ( ) != IJavaElement . FIELD ) { return Services . getMessage ( "<STR_LIT>" ) ; } IField field = ( IField ) element ; String signature = field . getTypeSignature ( ) ; IType delegateType = TypeUtils . findUnqualifiedType ( src , Signature . getSignatureSimpleName ( signature ) ) ; if ( delegateType == null ) { return Services . getMessage ( "<STR_LIT>" , src . getJavaProject ( ) . getElementName ( ) , Signature . getSignatureSimpleName ( signature ) ) + "<STR_LIT:U+0020U+0020>" + Services . getMessage ( "<STR_LIT>" ) ; } this . field . set ( field ) ; return super . execute ( commandLine ) ; } @ Override protected IType getType ( ICompilationUnit src , CommandLine commandLine ) throws Exception { if ( commandLine . hasOption ( Options . VARIABLE_OPTION ) ) { String var = commandLine . getValue ( Options . VARIABLE_OPTION ) ; String [ ] parts = StringUtils . split ( var , "<STR_LIT:.>" ) ; String typeName = StringUtils . join ( parts , '<CHAR_LIT:.>' , <NUM_LIT:0> , parts . length - <NUM_LIT:1> ) ; return src . getJavaProject ( ) . findType ( typeName . replace ( '<CHAR_LIT>' , '<CHAR_LIT:.>' ) ) ; } return super . getType ( src , commandLine ) ; } @ Override protected IWorkspaceRunnable getImplOperation ( ICompilationUnit src , IType type , Set < String > chosen , IJavaElement sibling , int pos , CommandLine commandLine ) throws Exception { RefactoringASTParser parser = new RefactoringASTParser ( ASTProvider . SHARED_AST_LEVEL ) ; CompilationUnit cu = parser . parse ( type . getCompilationUnit ( ) , true ) ; ITypeBinding typeBinding = ASTNodes . getTypeBinding ( cu , type ) ; String superType = commandLine . getValue ( Options . SUPERTYPE_OPTION ) ; List < DelegateEntry > delegatable = getDelegatableMethods ( cu , typeBinding ) ; List < DelegateEntry > delegate = new ArrayList < DelegateEntry > ( ) ; for ( DelegateEntry entry : delegatable ) { ITypeBinding declBinding = entry . delegateMethod . getDeclaringClass ( ) ; String fqn = declBinding . getQualifiedName ( ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; if ( fqn . equals ( superType ) && isChosen ( chosen , entry . delegateMethod ) ) { delegate . add ( entry ) ; } } if ( delegate . size ( ) > <NUM_LIT:0> ) { CodeGenerationSettings settings = JavaPreferencesSettings . getCodeGenerationSettings ( src . getJavaProject ( ) ) ; settings . createComments = true ; return new AddDelegateMethodsOperation ( cu , delegate . toArray ( new DelegateEntry [ delegate . size ( ) ] ) , sibling , settings , true , true ) ; } return null ; } @ Override protected ImplResult getImplResult ( ICompilationUnit src , IType type ) throws Exception { List < DelegateEntry > delegatable = getDelegatableMethods ( src , type ) ; List < IMethodBinding > methods = new ArrayList < IMethodBinding > ( delegatable . size ( ) ) ; for ( DelegateEntry entry : delegatable ) { methods . add ( entry . delegateMethod ) ; } String name = type . getFullyQualifiedName ( ) + '<CHAR_LIT:.>' + field . get ( ) . getElementName ( ) ; return getImplResult ( name , methods ) ; } private List < DelegateEntry > getDelegatableMethods ( ICompilationUnit src , IType type ) throws Exception { RefactoringASTParser parser = new RefactoringASTParser ( ASTProvider . SHARED_AST_LEVEL ) ; CompilationUnit cu = parser . parse ( type . getCompilationUnit ( ) , true ) ; ITypeBinding typeBinding = ASTNodes . getTypeBinding ( cu , type ) ; return getDelegatableMethods ( cu , typeBinding ) ; } private List < DelegateEntry > getDelegatableMethods ( CompilationUnit cu , ITypeBinding typeBinding ) throws Exception { IVariableBinding variable = ASTNodeSearchUtil . getFieldDeclarationFragmentNode ( field . get ( ) , cu ) . resolveBinding ( ) ; DelegateEntry [ ] entries = StubUtility2 . getDelegatableMethods ( typeBinding ) ; ArrayList < DelegateEntry > delegatable = new ArrayList < DelegateEntry > ( ) ; for ( DelegateEntry entry : entries ) { if ( entry . field . equals ( variable ) ) { delegatable . add ( entry ) ; } } return delegatable ; } } </s>
|
<s> package org . eclim . plugin . jdt . preference ; import java . util . Hashtable ; import java . util . Map ; import org . eclim . Services ; import org . eclim . plugin . core . preference . Preferences ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . ProjectScope ; import org . eclipse . core . runtime . preferences . DefaultScope ; import org . eclipse . core . runtime . preferences . IEclipsePreferences ; import org . eclipse . core . runtime . preferences . IScopeContext ; import org . eclipse . core . runtime . preferences . InstanceScope ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . ui . JavaUI ; public class OptionHandler implements org . eclim . plugin . core . preference . OptionHandler { private static final String NATURE = "<STR_LIT>" ; public String getNature ( ) { return NATURE ; } public Map < String , String > getValues ( ) throws Exception { @ SuppressWarnings ( "<STR_LIT:unchecked>" ) Map < String , String > coreOptions = JavaCore . getOptions ( ) ; Map < String , String > options = new Hashtable < String , String > ( ) ; options . putAll ( coreOptions ) ; options . putAll ( getUIValues ( null ) ) ; return options ; } public Map < String , String > getValues ( IProject project ) throws Exception { IJavaProject javaProject = JavaCore . create ( project ) ; if ( ! javaProject . exists ( ) ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , project . getName ( ) ) ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) Map < String , String > coreOptions = javaProject . getOptions ( true ) ; Map < String , String > options = new Hashtable < String , String > ( ) ; options . putAll ( coreOptions ) ; options . putAll ( getUIValues ( project ) ) ; return options ; } private Map < String , String > getUIValues ( IProject project ) throws Exception { Hashtable < String , String > options = new Hashtable < String , String > ( ) ; IScopeContext [ ] contexts = null ; if ( project != null ) { contexts = new IScopeContext [ ] { new ProjectScope ( project ) , InstanceScope . INSTANCE , DefaultScope . INSTANCE , } ; } else { contexts = new IScopeContext [ ] { InstanceScope . INSTANCE , DefaultScope . INSTANCE , } ; } String [ ] names = Preferences . getInstance ( ) . getOptionNames ( ) ; for ( String name : names ) { if ( name . startsWith ( JavaUI . ID_PLUGIN ) ) { for ( IScopeContext context : contexts ) { IEclipsePreferences node = context . getNode ( JavaUI . ID_PLUGIN ) ; String value = node . get ( name , null ) ; if ( value != null ) { options . put ( name , value ) ; break ; } } } } return options ; } public void setOption ( String name , String value ) throws Exception { @ SuppressWarnings ( "<STR_LIT:unchecked>" ) Map < String , String > options = JavaCore . getOptions ( ) ; if ( name . equals ( JavaCore . COMPILER_SOURCE ) ) { JavaUtils . setCompilerSourceCompliance ( value ) ; } else if ( name . startsWith ( JavaUI . ID_PLUGIN ) ) { Preferences . getInstance ( ) . setPreference ( JavaUI . ID_PLUGIN , null , name , value ) ; } else { options . put ( name , value ) ; JavaCore . setOptions ( ( Hashtable < String , String > ) options ) ; } } public void setOption ( IProject project , String name , String value ) throws Exception { IJavaProject javaProject = JavaCore . create ( project ) ; if ( ! javaProject . exists ( ) ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , project . getName ( ) ) ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) Map < String , String > global = javaProject . getOptions ( true ) ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) Map < String , String > options = javaProject . getOptions ( false ) ; Object current = global . get ( name ) ; if ( current == null || ! current . equals ( value ) ) { if ( name . equals ( JavaCore . COMPILER_SOURCE ) ) { JavaUtils . setCompilerSourceCompliance ( javaProject , value ) ; } else if ( name . startsWith ( JavaUI . ID_PLUGIN ) ) { Preferences . getInstance ( ) . setPreference ( JavaUI . ID_PLUGIN , project , name , value ) ; } else { options . put ( name , value ) ; javaProject . setOptions ( options ) ; } } } } </s>
|
<s> package org . eclim . plugin . jdt . project ; import java . io . File ; import java . io . FileInputStream ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import org . apache . commons . lang . StringUtils ; import org . eclim . Services ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclim . command . Options ; import org . eclim . plugin . core . project . ProjectManager ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . core . util . XmlUtils ; import org . eclim . plugin . jdt . PluginResources ; import org . eclim . plugin . jdt . project . classpath . Dependency ; import org . eclim . plugin . jdt . project . classpath . IvyParser ; import org . eclim . plugin . jdt . project . classpath . MvnParser ; import org . eclim . plugin . jdt . project . classpath . Parser ; import org . eclim . plugin . jdt . util . JavaUtils ; import org . eclim . util . IOUtils ; import org . eclim . util . file . FileOffsets ; import org . eclim . util . file . FileUtils ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . resources . IWorkspaceRoot ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . IClasspathAttribute ; import org . eclipse . jdt . core . IClasspathEntry ; import org . eclipse . jdt . core . IJavaModelStatus ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . JavaConventions ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . internal . core . JavaProject ; import org . eclipse . jdt . internal . ui . wizards . ClassPathDetector ; import org . eclipse . jdt . internal . ui . wizards . buildpaths . BuildPathsBlock ; import org . eclipse . jdt . internal . ui . wizards . buildpaths . CPListElement ; import org . eclipse . jdt . ui . PreferenceConstants ; import org . eclipse . jface . preference . IPreferenceStore ; public class JavaProjectManager implements ProjectManager { private static final String PRESERVE = "<STR_LIT>" ; private static final String CLASSPATH = "<STR_LIT>" ; private static final String CLASSPATH_XSD = "<STR_LIT>" ; private static final HashMap < String , Parser > PARSERS = new HashMap < String , Parser > ( ) ; static { PARSERS . put ( "<STR_LIT>" , new IvyParser ( ) ) ; PARSERS . put ( "<STR_LIT>" , new MvnParser ( ) ) ; } public void create ( IProject project , CommandLine commandLine ) throws Exception { String depends = commandLine . getValue ( Options . DEPENDS_OPTION ) ; create ( project , depends ) ; } public List < Error > update ( IProject project , CommandLine commandLine ) throws Exception { String buildfile = commandLine . getValue ( Options . BUILD_FILE_OPTION ) ; IJavaProject javaProject = JavaUtils . getJavaProject ( project ) ; javaProject . getResource ( ) . refreshLocal ( IResource . DEPTH_INFINITE , null ) ; PluginResources resources = ( PluginResources ) Services . getPluginResources ( PluginResources . NAME ) ; List < Error > errors = XmlUtils . validateXml ( javaProject . getProject ( ) . getName ( ) , CLASSPATH , resources . getResource ( CLASSPATH_XSD ) . toString ( ) ) ; if ( errors . size ( ) > <NUM_LIT:0> ) { return errors ; } String dotclasspath = javaProject . getProject ( ) . getFile ( CLASSPATH ) . getRawLocation ( ) . toOSString ( ) ; if ( buildfile != null ) { String filename = FileUtils . getBaseName ( buildfile ) ; Parser parser = PARSERS . get ( filename ) ; IClasspathEntry [ ] entries = merge ( javaProject , parser . parse ( buildfile ) ) ; errors = setClasspath ( javaProject , entries , dotclasspath ) ; } else { IClasspathEntry [ ] entries = javaProject . readRawClasspath ( ) ; errors = setClasspath ( javaProject , entries , dotclasspath ) ; } if ( errors . size ( ) > <NUM_LIT:0> ) { return errors ; } return null ; } public void refresh ( IProject project , CommandLine commandLine ) throws Exception { } public void refresh ( IProject project , IFile file ) throws Exception { } public void delete ( IProject project , CommandLine commandLine ) throws Exception { } protected void create ( IProject project , String depends ) throws Exception { IJavaProject javaProject = JavaCore . create ( project ) ; ( ( JavaProject ) javaProject ) . configure ( ) ; if ( ! project . getFile ( CLASSPATH ) . exists ( ) ) { ArrayList < IClasspathEntry > classpath = new ArrayList < IClasspathEntry > ( ) ; boolean source = false ; boolean container = false ; ClassPathDetector detector = new ClassPathDetector ( project , null ) ; for ( IClasspathEntry entry : detector . getClasspath ( ) ) { if ( entry . getEntryKind ( ) == IClasspathEntry . CPE_SOURCE ) { source = true ; } else if ( entry . getEntryKind ( ) == IClasspathEntry . CPE_CONTAINER ) { container = true ; } classpath . add ( entry ) ; } if ( ! source ) { IResource src ; IPreferenceStore store = PreferenceConstants . getPreferenceStore ( ) ; String name = store . getString ( PreferenceConstants . SRCBIN_SRCNAME ) ; boolean srcBinFolders = store . getBoolean ( PreferenceConstants . SRCBIN_FOLDERS_IN_NEWPROJ ) ; if ( srcBinFolders && name . length ( ) > <NUM_LIT:0> ) { src = javaProject . getProject ( ) . getFolder ( name ) ; } else { src = javaProject . getProject ( ) ; } classpath . add ( new CPListElement ( javaProject , IClasspathEntry . CPE_SOURCE , src . getFullPath ( ) , src ) . getClasspathEntry ( ) ) ; File srcPath = new File ( ProjectUtils . getFilePath ( project , src . getFullPath ( ) . toString ( ) ) ) ; if ( ! srcPath . exists ( ) ) { srcPath . mkdirs ( ) ; } } if ( ! container ) { for ( IClasspathEntry entry : PreferenceConstants . getDefaultJRELibrary ( ) ) { classpath . add ( entry ) ; } } for ( IClasspathEntry entry : createOrUpdateDependencies ( javaProject , depends ) ) { classpath . add ( entry ) ; } javaProject . setRawClasspath ( classpath . toArray ( new IClasspathEntry [ classpath . size ( ) ] ) , null ) ; IPath output = detector . getOutputLocation ( ) ; if ( output == null ) { output = BuildPathsBlock . getDefaultOutputLocation ( javaProject ) ; } javaProject . setOutputLocation ( output , null ) ; } javaProject . makeConsistent ( null ) ; javaProject . save ( null , false ) ; } protected IClasspathEntry [ ] createOrUpdateDependencies ( IJavaProject project , String depends ) throws Exception { if ( depends != null ) { String [ ] dependPaths = StringUtils . split ( depends , '<CHAR_LIT:U+002C>' ) ; IClasspathEntry [ ] entries = new IClasspathEntry [ dependPaths . length ] ; for ( int ii = <NUM_LIT:0> ; ii < dependPaths . length ; ii ++ ) { IProject theProject = ProjectUtils . getProject ( dependPaths [ ii ] ) ; if ( ! theProject . exists ( ) ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , dependPaths [ ii ] ) ) ; } IJavaProject otherProject = JavaCore . create ( theProject ) ; entries [ ii ] = JavaCore . newProjectEntry ( otherProject . getPath ( ) , true ) ; } return entries ; } return new IClasspathEntry [ <NUM_LIT:0> ] ; } protected IClasspathEntry [ ] merge ( IClasspathEntry [ ] [ ] entries ) { ArrayList < IClasspathEntry > union = new ArrayList < IClasspathEntry > ( ) ; if ( entries != null ) { for ( IClasspathEntry [ ] values : entries ) { if ( values != null ) { for ( IClasspathEntry entry : values ) { if ( ! union . contains ( entry ) ) { union . add ( entry ) ; } } } } } return ( IClasspathEntry [ ] ) union . toArray ( new IClasspathEntry [ union . size ( ) ] ) ; } protected List < Error > setClasspath ( IJavaProject javaProject , IClasspathEntry [ ] entries , String classpath ) throws Exception { FileOffsets offsets = FileOffsets . compile ( classpath ) ; String classpathValue = IOUtils . toString ( new FileInputStream ( classpath ) ) ; ArrayList < Error > errors = new ArrayList < Error > ( ) ; for ( IClasspathEntry entry : entries ) { IJavaModelStatus status = JavaConventions . validateClasspathEntry ( javaProject , entry , true ) ; if ( ! status . isOK ( ) ) { errors . add ( createErrorForEntry ( javaProject , entry , status , offsets , classpath , classpathValue ) ) ; } } IJavaModelStatus status = JavaConventions . validateClasspath ( javaProject , entries , javaProject . getOutputLocation ( ) ) ; javaProject . setRawClasspath ( entries , null ) ; javaProject . makeConsistent ( null ) ; if ( ! status . isOK ( ) ) { errors . add ( new Error ( status . getMessage ( ) , classpath , <NUM_LIT:1> , <NUM_LIT:1> , false ) ) ; } return errors ; } protected Error createErrorForEntry ( IJavaProject project , IClasspathEntry entry , IJavaModelStatus status , FileOffsets offsets , String filename , String contents ) throws Exception { int line = <NUM_LIT:0> ; int col = <NUM_LIT:0> ; String path = entry . getPath ( ) . toOSString ( ) ; path = path . replaceFirst ( "<STR_LIT>" + project . getProject ( ) . getName ( ) + "<STR_LIT:/>" , "<STR_LIT>" ) ; Matcher matcher = Pattern . compile ( "<STR_LIT>" + path + "<STR_LIT>" ) . matcher ( contents ) ; if ( matcher . find ( ) ) { int [ ] position = offsets . offsetToLineColumn ( matcher . start ( ) ) ; line = position [ <NUM_LIT:0> ] ; col = position [ <NUM_LIT:1> ] ; } return new Error ( status . getMessage ( ) , filename , line , col , false ) ; } protected IClasspathEntry [ ] merge ( IJavaProject project , Dependency [ ] dependencies ) throws Exception { IWorkspaceRoot root = project . getProject ( ) . getWorkspace ( ) . getRoot ( ) ; ArrayList < IClasspathEntry > results = new ArrayList < IClasspathEntry > ( ) ; IClasspathEntry [ ] entries = project . getRawClasspath ( ) ; for ( int ii = <NUM_LIT:0> ; ii < entries . length ; ii ++ ) { if ( entries [ ii ] . getEntryKind ( ) != IClasspathEntry . CPE_LIBRARY && entries [ ii ] . getEntryKind ( ) != IClasspathEntry . CPE_VARIABLE ) { results . add ( entries [ ii ] ) ; } else if ( preserve ( entries [ ii ] ) ) { results . add ( entries [ ii ] ) ; } } for ( int ii = <NUM_LIT:0> ; ii < dependencies . length ; ii ++ ) { IClasspathEntry match = null ; for ( int jj = <NUM_LIT:0> ; jj < entries . length ; jj ++ ) { if ( entries [ jj ] . getEntryKind ( ) == IClasspathEntry . CPE_LIBRARY || entries [ jj ] . getEntryKind ( ) == IClasspathEntry . CPE_VARIABLE ) { String path = entries [ jj ] . getPath ( ) . toOSString ( ) ; String pattern = dependencies [ ii ] . getName ( ) + Dependency . VERSION_SEPARATOR ; if ( path . endsWith ( dependencies [ ii ] . toString ( ) ) ) { match = entries [ jj ] ; results . add ( entries [ jj ] ) ; break ; } else if ( path . indexOf ( pattern ) != - <NUM_LIT:1> ) { break ; } } else if ( entries [ jj ] . getEntryKind ( ) == IClasspathEntry . CPE_PROJECT ) { String path = entries [ jj ] . getPath ( ) . toOSString ( ) ; if ( path . endsWith ( dependencies [ ii ] . getName ( ) ) ) { match = entries [ jj ] ; break ; } } } if ( match == null ) { IClasspathEntry entry = createEntry ( root , project , dependencies [ ii ] ) ; results . add ( entry ) ; } else { match = null ; } } return ( IClasspathEntry [ ] ) results . toArray ( new IClasspathEntry [ results . size ( ) ] ) ; } protected boolean preserve ( IClasspathEntry entry ) { IClasspathAttribute [ ] attributes = entry . getExtraAttributes ( ) ; for ( int ii = <NUM_LIT:0> ; ii < attributes . length ; ii ++ ) { String name = attributes [ ii ] . getName ( ) ; if ( PRESERVE . equals ( name ) ) { return Boolean . parseBoolean ( attributes [ ii ] . getValue ( ) ) ; } } return false ; } protected IClasspathEntry createEntry ( IWorkspaceRoot root , IJavaProject project , Dependency dependency ) throws Exception { if ( dependency . isVariable ( ) ) { return JavaCore . newVariableEntry ( dependency . getPath ( ) , null , null , true ) ; } return JavaCore . newLibraryEntry ( dependency . getPath ( ) , null , null , true ) ; } protected boolean startsWithVariable ( String path ) { String [ ] variables = JavaCore . getClasspathVariableNames ( ) ; for ( int ii = <NUM_LIT:0> ; ii < variables . length ; ii ++ ) { if ( path . startsWith ( variables [ ii ] ) ) { return true ; } } return false ; } } </s>
|
<s> package org . eclim . plugin . jdt . project . classpath ; import org . eclipse . core . runtime . IPath ; public class Dependency { public static final String JAR = "<STR_LIT>" ; public static final String SEPARATOR = "<STR_LIT:/>" ; public static final String VERSION_SEPARATOR = "<STR_LIT:->" ; private String organization ; private String name ; private String version ; private IPath path ; private boolean variable ; public Dependency ( String org , String name , String version , IPath path ) { this . organization = org ; this . name = name ; this . version = version ; this . path = path . append ( resolveArtifact ( ) ) ; } public String getOrganization ( ) { return this . organization ; } public void setOrganization ( String organization ) { this . organization = organization ; } public String getName ( ) { return this . name ; } public void setName ( String name ) { this . name = name ; } public String getVersion ( ) { return this . version ; } public void setVersion ( String version ) { this . version = version ; } public IPath getPath ( ) { return this . path ; } public void setPath ( IPath path ) { this . path = path ; } public boolean isVariable ( ) { return this . variable ; } public void setVariable ( boolean variable ) { this . variable = variable ; } public String resolveArtifact ( ) { return toString ( ) ; } public String toString ( ) { StringBuffer buffer = new StringBuffer ( getName ( ) ) ; if ( getVersion ( ) != null && getVersion ( ) . trim ( ) . length ( ) > <NUM_LIT:0> ) { buffer . append ( VERSION_SEPARATOR ) . append ( getVersion ( ) ) ; } buffer . append ( JAR ) ; return buffer . toString ( ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . project . classpath ; import org . eclipse . core . runtime . IPath ; public class IvyDependency extends Dependency { private static final String JARS = "<STR_LIT>" ; public IvyDependency ( String org , String name , String version , IPath path ) { super ( org , name , version , path ) ; } public String resolveArtifact ( ) { StringBuffer buffer = new StringBuffer ( ) ; buffer . append ( getOrganization ( ) ) . append ( SEPARATOR ) . append ( getName ( ) ) . append ( SEPARATOR ) . append ( JARS ) . append ( SEPARATOR ) . append ( toString ( ) ) ; return buffer . toString ( ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . project . classpath ; import org . eclipse . core . runtime . IPath ; public class MvnDependency extends Dependency { public MvnDependency ( String org , String name , String version , IPath path ) { super ( org , name , version , path ) ; } public String resolveArtifact ( ) { StringBuffer buffer = new StringBuffer ( ) ; buffer . append ( getOrganization ( ) . replace ( "<STR_LIT:.>" , SEPARATOR ) ) . append ( SEPARATOR ) . append ( getName ( ) . replace ( "<STR_LIT:.>" , SEPARATOR ) ) . append ( SEPARATOR ) . append ( getVersion ( ) ) . append ( SEPARATOR ) . append ( toString ( ) ) ; return buffer . toString ( ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . project . classpath ; import javax . xml . xpath . XPathConstants ; import javax . xml . xpath . XPathExpression ; import org . eclim . Services ; import org . eclim . plugin . core . util . XmlUtils ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . Path ; import org . eclipse . jdt . core . JavaCore ; import org . w3c . dom . Document ; import org . w3c . dom . Element ; import org . w3c . dom . NodeList ; public class IvyParser extends AbstractXmlParser { private static final String IVY_REPO = "<STR_LIT>" ; private static final String ORG = "<STR_LIT>" ; private static final String NAME = "<STR_LIT:name>" ; private static final String REVISION = "<STR_LIT>" ; private static XPathExpression xpath ; public Dependency [ ] parse ( Document document ) throws Exception { try { if ( xpath == null ) { xpath = XmlUtils . createXPathExpression ( "<STR_LIT>" ) ; } if ( JavaCore . getClasspathVariable ( IVY_REPO ) == null ) { throw new IllegalStateException ( Services . getMessage ( "<STR_LIT>" , IVY_REPO ) ) ; } IPath path = new Path ( IVY_REPO ) ; NodeList results = ( NodeList ) xpath . evaluate ( document , XPathConstants . NODESET ) ; Dependency [ ] dependencies = new Dependency [ results . getLength ( ) ] ; for ( int ii = <NUM_LIT:0> ; ii < results . getLength ( ) ; ii ++ ) { Element element = ( Element ) results . item ( ii ) ; dependencies [ ii ] = new IvyDependency ( element . getAttribute ( ORG ) , element . getAttribute ( NAME ) , element . getAttribute ( REVISION ) , path ) ; dependencies [ ii ] . setVariable ( true ) ; } return dependencies ; } catch ( IllegalStateException iae ) { throw iae ; } } } </s>
|
<s> package org . eclim . plugin . jdt . project . classpath ; public interface Parser { public Dependency [ ] parse ( String filename ) throws Exception ; } </s>
|
<s> package org . eclim . plugin . jdt . project . classpath ; import java . io . File ; import javax . xml . parsers . DocumentBuilderFactory ; import org . w3c . dom . Document ; public abstract class AbstractXmlParser implements Parser { private static DocumentBuilderFactory factory ; public Dependency [ ] parse ( String filename ) throws Exception { if ( factory == null ) { factory = DocumentBuilderFactory . newInstance ( ) ; } Document document = factory . newDocumentBuilder ( ) . parse ( new File ( filename ) ) ; return parse ( document ) ; } public abstract Dependency [ ] parse ( Document document ) throws Exception ; } </s>
|
<s> package org . eclim . plugin . jdt . project . classpath ; import java . util . ArrayList ; import javax . xml . xpath . XPathConstants ; import javax . xml . xpath . XPathExpression ; import org . eclim . Services ; import org . eclim . plugin . core . util . XmlUtils ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . Path ; import org . eclipse . jdt . core . JavaCore ; import org . w3c . dom . Document ; import org . w3c . dom . Element ; import org . w3c . dom . Node ; import org . w3c . dom . NodeList ; public class MvnParser extends AbstractXmlParser { private static final String MVN_REPO = "<STR_LIT>" ; private static final String GROUP_ID = "<STR_LIT>" ; private static final String ARTIFACT_ID = "<STR_LIT>" ; private static final String VERSION = "<STR_LIT:version>" ; private static XPathExpression xpath ; public Dependency [ ] parse ( Document document ) throws Exception { try { if ( xpath == null ) { xpath = XmlUtils . createXPathExpression ( "<STR_LIT>" ) ; } if ( JavaCore . getClasspathVariable ( MVN_REPO ) == null ) { throw new IllegalStateException ( Services . getMessage ( "<STR_LIT>" , MVN_REPO ) ) ; } IPath path = new Path ( MVN_REPO ) ; NodeList results = ( NodeList ) xpath . evaluate ( document , XPathConstants . NODESET ) ; ArrayList < Dependency > dependencies = new ArrayList < Dependency > ( ) ; for ( int ii = <NUM_LIT:0> ; ii < results . getLength ( ) ; ii ++ ) { Element element = ( Element ) results . item ( ii ) ; NodeList group = element . getElementsByTagName ( GROUP_ID ) ; NodeList artifact = element . getElementsByTagName ( ARTIFACT_ID ) ; NodeList ver = element . getElementsByTagName ( VERSION ) ; if ( group == null || group . getLength ( ) < <NUM_LIT:1> || artifact == null || artifact . getLength ( ) < <NUM_LIT:1> || ver == null || ver . getLength ( ) < <NUM_LIT:1> ) { continue ; } Node groupId = group . item ( <NUM_LIT:0> ) . getFirstChild ( ) ; Node artifactId = artifact . item ( <NUM_LIT:0> ) . getFirstChild ( ) ; Node version = ver . item ( <NUM_LIT:0> ) . getFirstChild ( ) ; if ( groupId == null || artifactId == null || version == null ) { continue ; } String groupIdValue = groupId . getNodeValue ( ) . trim ( ) ; String artifactIdValue = artifactId . getNodeValue ( ) . trim ( ) ; String versionValue = version . getNodeValue ( ) . trim ( ) ; if ( groupIdValue . length ( ) == <NUM_LIT:0> || artifactIdValue . length ( ) == <NUM_LIT:0> || versionValue . length ( ) == <NUM_LIT:0> ) { continue ; } Dependency dependency = new MvnDependency ( groupIdValue , artifactIdValue , versionValue , path ) ; dependency . setVariable ( true ) ; dependencies . add ( dependency ) ; } return ( Dependency [ ] ) dependencies . toArray ( new Dependency [ dependencies . size ( ) ] ) ; } catch ( IllegalStateException iae ) { throw iae ; } } } </s>
|
<s> package org . eclim . plugin . ant ; import org . eclim . Services ; import org . eclim . plugin . AbstractPluginResources ; public class PluginResources extends AbstractPluginResources { public static final String NAME = "<STR_LIT>" ; protected String getBundleBaseName ( ) { return "<STR_LIT>" ; } } </s>
|
<s> package org . eclim . plugin . ant . util ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . ant . internal . ui . AntUtil ; import org . eclipse . ant . internal . ui . model . AntModel ; import org . eclipse . ant . internal . ui . model . IAntModel ; import org . eclipse . ant . internal . ui . model . IProblemRequestor ; import org . eclipse . ant . internal . ui . model . LocationProvider ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jface . text . IDocument ; public class AntUtils { public static IAntModel getAntModel ( String project , String antFile ) throws Exception { return getAntModel ( project , antFile , null ) ; } public static IAntModel getAntModel ( String project , String antFile , IProblemRequestor requestor ) throws Exception { final IFile file = AntUtil . getFileForLocation ( ProjectUtils . getFilePath ( project , antFile ) , null ) ; if ( file == null ) { throw new RuntimeException ( "<STR_LIT>" ) ; } file . refreshLocal ( IResource . DEPTH_INFINITE , null ) ; IDocument doc = ProjectUtils . getDocument ( project , antFile ) ; LocationProvider provider = new LocationProvider ( null ) { public IFile getFile ( ) { return file ; } public IPath getLocation ( ) { return file . getLocation ( ) ; } } ; return new AntModel ( doc , requestor , provider , true , true , true ) ; } } </s>
|
<s> package org . eclim . plugin . ant . command . complete ; import org . eclim . eclipse . jface . text . contentassist . DummyContentAssistantExtension2 ; import org . eclipse . ant . internal . ui . model . AntModel ; public class AntEditorCompletionProcessor extends org . eclipse . ant . internal . ui . editor . AntEditorCompletionProcessor { public AntEditorCompletionProcessor ( AntModel model ) { super ( model ) ; super . fContentAssistant = new DummyContentAssistantExtension2 ( ) ; } } </s>
|
<s> package org . eclim . plugin . ant . command . complete ; import org . apache . commons . lang . builder . EqualsBuilder ; import org . apache . commons . lang . builder . HashCodeBuilder ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . plugin . ant . util . AntUtils ; import org . eclim . plugin . core . command . complete . AbstractCodeCompleteCommand ; import org . eclim . plugin . core . command . complete . CodeCompleteResult ; import org . eclipse . ant . internal . ui . model . AntModel ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; import org . eclipse . jface . text . contentassist . IContentAssistProcessor ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class CodeCompleteCommand extends AbstractCodeCompleteCommand { @ Override protected CodeCompleteResult createCodeCompletionResult ( ICompletionProposal proposal ) { return new AntCodeCompleteResult ( getCompletion ( proposal ) , getMenu ( proposal ) , getInfo ( proposal ) ) ; } protected IContentAssistProcessor getContentAssistProcessor ( CommandLine commandLine , String project , String file ) throws Exception { AntModel model = ( AntModel ) AntUtils . getAntModel ( project , file ) ; AntEditorCompletionProcessor processor = new AntEditorCompletionProcessor ( model ) ; return processor ; } protected String getCompletion ( ICompletionProposal proposal ) { String completion = super . getCompletion ( proposal ) ; int index = completion . indexOf ( "<STR_LIT:U+0020-U+0020>" ) ; if ( index != - <NUM_LIT:1> ) { completion = completion . substring ( <NUM_LIT:0> , index ) ; } return completion ; } private class AntCodeCompleteResult extends CodeCompleteResult { public AntCodeCompleteResult ( String completion , String menu , String info ) { super ( completion , menu , info ) ; } @ Override public boolean equals ( Object other ) { if ( ! ( other instanceof AntCodeCompleteResult ) ) { return false ; } if ( this == other ) { return true ; } AntCodeCompleteResult result = ( AntCodeCompleteResult ) other ; boolean equal = new EqualsBuilder ( ) . append ( getCompletion ( ) , result . getCompletion ( ) ) . isEquals ( ) ; return equal ; } @ Override public int hashCode ( ) { return new HashCodeBuilder ( <NUM_LIT> , <NUM_LIT> ) . append ( getCompletion ( ) ) . toHashCode ( ) ; } } } </s>
|
<s> package org . eclim . plugin . ant . command . run ; import java . text . Collator ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Map ; import org . apache . tools . ant . Project ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . ant . util . AntUtils ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclipse . ant . internal . ui . model . AntModel ; import org . eclipse . ant . internal . ui . model . AntProjectNode ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class TargetsCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { ArrayList < String > results = new ArrayList < String > ( ) ; String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; AntModel model = ( AntModel ) AntUtils . getAntModel ( project , file ) ; AntProjectNode projectNode = model . getProjectNode ( true ) ; Project antProject = projectNode . getProject ( ) ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) Map < String , Object > targets = antProject . getTargets ( ) ; for ( String target : targets . keySet ( ) ) { if ( target . trim ( ) . length ( ) > <NUM_LIT:0> ) { results . add ( target ) ; } } Collections . sort ( results , Collator . getInstance ( ) ) ; return results ; } } </s>
|
<s> package org . eclim . plugin . ant . command . validate ; import java . util . ArrayList ; import java . util . List ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclim . command . Options ; import org . eclim . plugin . ant . util . AntUtils ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . util . file . FileOffsets ; import org . eclipse . ant . internal . ui . model . IAntModel ; import org . eclipse . ant . internal . ui . model . IProblem ; import org . eclipse . ant . internal . ui . model . IProblemRequestor ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class ValidateCommand extends org . eclim . plugin . core . command . xml . ValidateCommand { public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; List < Error > errors = super . validate ( project , file , false , null ) ; ProblemRequestor requestor = new ProblemRequestor ( ) ; IAntModel model = AntUtils . getAntModel ( project , file , requestor ) ; model . reconcile ( ) ; String filepath = ProjectUtils . getFilePath ( project , file ) ; List < IProblem > problems = requestor . getProblems ( ) ; FileOffsets offsets = FileOffsets . compile ( filepath ) ; for ( IProblem problem : problems ) { int [ ] lineColumn = offsets . offsetToLineColumn ( problem . getOffset ( ) ) ; Error error = new Error ( problem . getUnmodifiedMessage ( ) , filepath , lineColumn [ <NUM_LIT:0> ] , lineColumn [ <NUM_LIT:1> ] , problem . isWarning ( ) ) ; if ( ! errors . contains ( error ) ) { errors . add ( error ) ; } } return errors ; } private class ProblemRequestor implements IProblemRequestor { private ArrayList < IProblem > problems = new ArrayList < IProblem > ( ) ; public List < IProblem > getProblems ( ) { return problems ; } public void acceptProblem ( IProblem problem ) { problems . add ( problem ) ; } public void beginReporting ( ) { } public void endReporting ( ) { } } } </s>
|
<s> package org . eclim . eclipse ; import java . io . File ; import java . io . FileFilter ; import java . io . FileInputStream ; import java . io . FilenameFilter ; import java . io . IOException ; import java . net . URL ; import java . security . CodeSource ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . HashSet ; import java . util . LinkedHashSet ; import java . util . Map ; import java . util . Set ; import org . apache . commons . lang . StringUtils ; import org . eclim . logging . Logger ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . util . IOUtils ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . FileLocator ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . core . runtime . Path ; import org . eclipse . core . runtime . Platform ; import org . eclipse . jdt . core . ClasspathContainerInitializer ; import org . eclipse . jdt . core . IClasspathAttribute ; import org . eclipse . jdt . core . IClasspathContainer ; import org . eclipse . jdt . core . IClasspathEntry ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . osgi . util . ManifestElement ; import org . eclipse . swt . SWT ; import org . osgi . framework . Bundle ; public class EclimClasspathInitializer extends ClasspathContainerInitializer { private static final Logger logger = Logger . getLogger ( EclimClasspathInitializer . class ) ; private Map < IPath , Map < String , String > > docJars = new HashMap < IPath , Map < String , String > > ( ) ; private Set < String > platformNames = new HashSet < String > ( ) ; { platformNames . add ( "<STR_LIT>" ) ; platformNames . add ( "<STR_LIT>" ) ; platformNames . add ( "<STR_LIT>" ) ; platformNames . add ( "<STR_LIT>" ) ; platformNames . add ( "<STR_LIT>" ) ; platformNames . add ( "<STR_LIT>" ) ; platformNames . add ( "<STR_LIT>" ) ; platformNames . add ( "<STR_LIT>" ) ; platformNames . add ( "<STR_LIT>" ) ; platformNames . add ( "<STR_LIT>" ) ; platformNames . add ( "<STR_LIT>" ) ; platformNames . add ( "<STR_LIT>" ) ; platformNames . add ( "<STR_LIT>" ) ; platformNames . add ( "<STR_LIT>" ) ; platformNames . add ( "<STR_LIT>" ) ; platformNames . add ( "<STR_LIT>" ) ; } @ Override public void initialize ( IPath path , IJavaProject javaProject ) throws CoreException { if ( javaProject . getProject ( ) . getName ( ) . equals ( "<STR_LIT>" ) ) { EclimClasspathContainer container = new EclimClasspathContainer ( path , computeClasspathEntries ( javaProject ) ) ; JavaCore . setClasspathContainer ( path , new IJavaProject [ ] { javaProject } , new IClasspathContainer [ ] { container } , new NullProgressMonitor ( ) ) ; } } private IClasspathEntry [ ] computeClasspathEntries ( IJavaProject javaProject ) { final ArrayList < IClasspathEntry > list = new ArrayList < IClasspathEntry > ( ) ; try { final LinkedHashSet < String > bundleNames = new LinkedHashSet < String > ( ) ; final ArrayList < String > jarPaths = new ArrayList < String > ( ) ; final String projectPath = ProjectUtils . getPath ( javaProject . getProject ( ) ) ; new File ( projectPath ) . list ( new FilenameFilter ( ) { public boolean accept ( File dir , String name ) { if ( name . startsWith ( "<STR_LIT>" ) ) { File manifest = new File ( dir . getPath ( ) + '<CHAR_LIT:/>' + name + "<STR_LIT>" ) ; if ( manifest . exists ( ) ) { FileInputStream fin = null ; try { fin = new FileInputStream ( manifest ) ; HashMap < String , String > headers = new HashMap < String , String > ( ) ; ManifestElement . parseBundleManifest ( fin , headers ) ; String requiredBundles = headers . get ( "<STR_LIT>" ) ; for ( String bname : requiredBundles . split ( "<STR_LIT>" ) ) { if ( bname . startsWith ( "<STR_LIT>" ) ) { continue ; } bundleNames . add ( bname ) ; } } catch ( Exception e ) { logger . error ( "<STR_LIT>" + manifest , e ) ; } finally { IOUtils . closeQuietly ( fin ) ; } } File lib = new File ( dir . getPath ( ) + '<CHAR_LIT:/>' + name + "<STR_LIT>" ) ; if ( lib . exists ( ) ) { for ( String jar : lib . list ( ) ) { if ( jar . endsWith ( "<STR_LIT>" ) ) { jarPaths . add ( name + "<STR_LIT>" + jar ) ; } } } } return false ; } } ) ; CodeSource source = SWT . class . getProtectionDomain ( ) . getCodeSource ( ) ; if ( source != null ) { URL swt = source . getLocation ( ) ; if ( swt != null ) { logger . debug ( "<STR_LIT>" , swt . getPath ( ) ) ; Path path = new Path ( swt . getPath ( ) ) ; list . add ( JavaCore . newLibraryEntry ( path , sourcePath ( path ) , null , null , attributes ( path ) , false ) ) ; } } for ( String name : bundleNames ) { logger . debug ( "<STR_LIT>" , name ) ; try { Bundle bundle = Platform . getBundle ( name ) ; if ( bundle != null ) { String pathName = FileLocator . getBundleFile ( bundle ) . getPath ( ) ; Path path = new Path ( pathName ) ; list . add ( JavaCore . newLibraryEntry ( path , sourcePath ( path ) , null , null , attributes ( path ) , false ) ) ; if ( path . toFile ( ) . isDirectory ( ) ) { listFiles ( path . toFile ( ) , new FileFilter ( ) { public boolean accept ( File file ) { if ( file . getName ( ) . endsWith ( "<STR_LIT>" ) ) { list . add ( JavaCore . newLibraryEntry ( new Path ( file . getPath ( ) ) , null , null , null , null , false ) ) ; } else if ( file . isDirectory ( ) ) { listFiles ( file , this ) ; } return false ; } } ) ; } } } catch ( IOException ioe ) { logger . error ( "<STR_LIT>" + name , ioe ) ; } } listFiles ( new File ( projectPath + "<STR_LIT>" ) , new FileFilter ( ) { public boolean accept ( File file ) { if ( file . getName ( ) . endsWith ( "<STR_LIT>" ) ) { String jar = file . getPath ( ) . replace ( projectPath , "<STR_LIT>" ) ; if ( jar . startsWith ( "<STR_LIT:/>" ) ) { jar = jar . substring ( <NUM_LIT:1> ) ; } jarPaths . add ( jar ) ; } if ( file . isDirectory ( ) ) { listFiles ( file , this ) ; } return false ; } } ) ; for ( String jarPath : jarPaths ) { logger . debug ( "<STR_LIT>" , jarPath ) ; list . add ( JavaCore . newLibraryEntry ( new Path ( projectPath + '<CHAR_LIT:/>' + jarPath ) , null , null , null , null , false ) ) ; } } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } return ( IClasspathEntry [ ] ) list . toArray ( new IClasspathEntry [ list . size ( ) ] ) ; } private void listFiles ( File dir , FileFilter filter ) { dir . listFiles ( filter ) ; } private Path sourcePath ( Path path ) { Path sourcePath = null ; if ( path . lastSegment ( ) . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) { sourcePath = new Path ( path . uptoSegment ( path . segmentCount ( ) - <NUM_LIT:1> ) . toString ( ) + File . separator + path . lastSegment ( ) . replace ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } else { String [ ] parts = StringUtils . split ( path . lastSegment ( ) , "<STR_LIT:_>" , <NUM_LIT:2> ) ; sourcePath = parts . length == <NUM_LIT:2> ? new Path ( path . uptoSegment ( path . segmentCount ( ) - <NUM_LIT:1> ) . toString ( ) + File . separator + parts [ <NUM_LIT:0> ] + "<STR_LIT>" + parts [ <NUM_LIT:1> ] ) : null ; } return sourcePath != null && sourcePath . toFile ( ) . exists ( ) ? sourcePath : null ; } private IClasspathAttribute [ ] attributes ( Path path ) { String name = null ; if ( path . lastSegment ( ) . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) { name = path . lastSegment ( ) . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; } else { String [ ] parts = StringUtils . split ( path . lastSegment ( ) , "<STR_LIT:_>" , <NUM_LIT:2> ) ; name = parts [ <NUM_LIT:0> ] ; } if ( ! name . startsWith ( "<STR_LIT>" ) ) { return null ; } final IPath dir = path . uptoSegment ( path . segmentCount ( ) - <NUM_LIT:1> ) ; if ( ! docJars . containsKey ( dir ) ) { docJars . put ( dir , new HashMap < String , String > ( ) ) ; dir . toFile ( ) . list ( new FilenameFilter ( ) { public boolean accept ( File path , String name ) { if ( name . endsWith ( "<STR_LIT>" ) && name . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) { String url = "<STR_LIT>" + path + '<CHAR_LIT:/>' + name + "<STR_LIT>" ; String bundleName = name . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; docJars . get ( dir ) . put ( bundleName , url ) ; } return false ; } } ) ; } String url = null ; Map < String , String > jars = docJars . get ( dir ) ; String shortName = StringUtils . join ( StringUtils . split ( name , "<STR_LIT:.>" , <NUM_LIT:4> ) , "<STR_LIT:.>" , <NUM_LIT:0> , <NUM_LIT:3> ) ; if ( jars . containsKey ( shortName ) ) { url = jars . get ( shortName ) ; } else if ( platformNames . contains ( shortName ) && docJars . containsKey ( "<STR_LIT>" ) ) { url = jars . get ( "<STR_LIT>" ) ; } if ( url != null ) { return new IClasspathAttribute [ ] { JavaCore . newClasspathAttribute ( IClasspathAttribute . JAVADOC_LOCATION_ATTRIBUTE_NAME , url ) } ; } return null ; } } </s>
|
<s> package org . eclim . eclipse ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . IClasspathContainer ; import org . eclipse . jdt . core . IClasspathEntry ; public class EclimClasspathContainer implements IClasspathContainer { private IPath path ; private IClasspathEntry [ ] entries ; public EclimClasspathContainer ( IPath path , IClasspathEntry [ ] entries ) { this . path = path ; this . entries = entries ; } public IClasspathEntry [ ] getClasspathEntries ( ) { return entries ; } public String getDescription ( ) { return "<STR_LIT>" ; } public int getKind ( ) { return IClasspathContainer . K_DEFAULT_SYSTEM ; } public IPath getPath ( ) { return path ; } } </s>
|
<s> package org . eclim . plugin . maven . command . dependency ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . maven . Maven ; import org . junit . Test ; import static org . junit . Assert . * ; public class SearchCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void execute ( ) { List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Maven . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; assertEquals ( "<STR_LIT>" , results . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; Map < String , Object > junit381 = null ; for ( Map < String , Object > result : results ) { if ( result . get ( "<STR_LIT>" ) . equals ( "<STR_LIT>" ) && result . get ( "<STR_LIT:version>" ) . equals ( "<STR_LIT>" ) ) { junit381 = result ; break ; } } assertNotNull ( junit381 ) ; assertEquals ( true , junit381 . get ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package org . eclim . plugin . maven ; public class Maven { public static final String TEST_PROJECT = "<STR_LIT>" ; } </s>
|
<s> package org . eclim . plugin . jdt . command . log4j ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class ValidateCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void validateXmlErrors ( ) { List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:6> , results . size ( ) ) ; String file = Eclim . resolveFile ( Jdt . TEST_PROJECT , TEST_FILE ) ; Map < String , Object > error = results . get ( <NUM_LIT:0> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertEquals ( error . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; error = results . get ( <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertEquals ( error . get ( "<STR_LIT:message>" ) , "<STR_LIT>" + "<STR_LIT>" ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; error = results . get ( <NUM_LIT:2> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertEquals ( error . get ( "<STR_LIT:message>" ) , "<STR_LIT>" + "<STR_LIT>" ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:9> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; error = results . get ( <NUM_LIT:3> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertEquals ( error . get ( "<STR_LIT:message>" ) , "<STR_LIT>" + "<STR_LIT>" ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; error = results . get ( <NUM_LIT:4> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertEquals ( error . get ( "<STR_LIT:message>" ) , "<STR_LIT>" + "<STR_LIT>" ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; error = results . get ( <NUM_LIT:5> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertEquals ( error . get ( "<STR_LIT:message>" ) , "<STR_LIT>" + "<STR_LIT>" ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:24> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . complete ; import java . util . ArrayList ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class CodeCompleteCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void completionAllMembers ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Map < String , Object > results = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" } ) ; List < Map < String , Object > > completions = ( List < Map < String , Object > > ) results . get ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , completions . size ( ) > <NUM_LIT:30> ) ; Map < String , Object > result = completions . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT:type>" ) , "<STR_LIT:f>" ) ; result = completions . get ( completions . size ( ) - <NUM_LIT:1> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT:type>" ) , "<STR_LIT:f>" ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void completionByPrefix ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Map < String , Object > results = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" } ) ; List < Map < String , Object > > completions = ( List < Map < String , Object > > ) results . get ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:4> , completions . size ( ) ) ; Map < String , Object > result = completions . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT:type>" ) , "<STR_LIT:f>" ) ; result = completions . get ( completions . size ( ) - <NUM_LIT:1> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT:type>" ) , "<STR_LIT:f>" ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void completionMissingImport ( ) { Map < String , Object > results = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" } ) ; List < Map < String , Object > > completions = ( List < Map < String , Object > > ) results . get ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:0> , completions . size ( ) ) ; assertTrue ( "<STR_LIT>" , results . containsKey ( "<STR_LIT>" ) ) ; ArrayList < String > imports = new ArrayList < String > ( ) ; imports . add ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , imports , results . get ( "<STR_LIT>" ) ) ; assertTrue ( "<STR_LIT>" , results . containsKey ( "<STR_LIT:error>" ) ) ; Map < String , Object > error = ( Map < String , Object > ) results . get ( "<STR_LIT:error>" ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , error . get ( "<STR_LIT:message>" ) ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void completionMissingImportStatic ( ) { Map < String , Object > results = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" } ) ; List < Map < String , Object > > completions = ( List < Map < String , Object > > ) results . get ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:0> , completions . size ( ) ) ; assertTrue ( "<STR_LIT>" , results . containsKey ( "<STR_LIT>" ) ) ; ArrayList < String > imports = new ArrayList < String > ( ) ; imports . add ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , imports , results . get ( "<STR_LIT>" ) ) ; assertTrue ( "<STR_LIT>" , results . containsKey ( "<STR_LIT:error>" ) ) ; Map < String , Object > error = ( Map < String , Object > ) results . get ( "<STR_LIT:error>" ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , error . get ( "<STR_LIT:message>" ) ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . junit ; import java . util . List ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class JUnitTestsCommandTest { @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void execute ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; List < String > results = ( List < String > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT } ) ; results . remove ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:3> , results . size ( ) ) ; assertEquals ( "<STR_LIT>" , results . get ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , results . get ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , results . get ( <NUM_LIT:2> ) ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . junit ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class JUnitFindTestCommandTest { private static final String CLASS = "<STR_LIT>" ; private static final String TEST = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void executeClassToTest ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Map < String , Object > result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , CLASS , "<STR_LIT>" , "<STR_LIT:0>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , } ) ; assertEquals ( Eclim . resolveFile ( Jdt . TEST_PROJECT , TEST ) , result . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , result . get ( "<STR_LIT:message>" ) ) ; assertEquals ( <NUM_LIT:7> , result . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:1> , result . get ( "<STR_LIT>" ) ) ; result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , CLASS , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , } ) ; assertEquals ( Eclim . resolveFile ( Jdt . TEST_PROJECT , TEST ) , result . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT:foo>" , result . get ( "<STR_LIT:message>" ) ) ; assertEquals ( <NUM_LIT:9> , result . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:3> , result . get ( "<STR_LIT>" ) ) ; result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , CLASS , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , } ) ; assertEquals ( Eclim . resolveFile ( Jdt . TEST_PROJECT , TEST ) , result . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , result . get ( "<STR_LIT:message>" ) ) ; assertEquals ( <NUM_LIT:16> , result . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:3> , result . get ( "<STR_LIT>" ) ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void executeTestToClass ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Map < String , Object > result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST , "<STR_LIT>" , "<STR_LIT:0>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , } ) ; assertEquals ( Eclim . resolveFile ( Jdt . TEST_PROJECT , CLASS ) , result . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , result . get ( "<STR_LIT:message>" ) ) ; assertEquals ( <NUM_LIT:3> , result . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:1> , result . get ( "<STR_LIT>" ) ) ; result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , } ) ; assertEquals ( Eclim . resolveFile ( Jdt . TEST_PROJECT , CLASS ) , result . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT:foo>" , result . get ( "<STR_LIT:message>" ) ) ; assertEquals ( <NUM_LIT:5> , result . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:3> , result . get ( "<STR_LIT>" ) ) ; result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , } ) ; assertEquals ( Eclim . resolveFile ( Jdt . TEST_PROJECT , CLASS ) , result . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT:foo>" , result . get ( "<STR_LIT:message>" ) ) ; assertEquals ( <NUM_LIT:10> , result . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:3> , result . get ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . junit ; import org . apache . commons . lang . StringUtils ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class JUnitCommandTest { private static final String CLASS = "<STR_LIT>" ; private static final String TEST = "<STR_LIT>" ; @ Test public void executeTest ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; String result = ( String ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , } , false ) ; String [ ] lines = StringUtils . split ( result , '<STR_LIT:\n>' ) ; assertEquals ( "<STR_LIT>" , lines [ <NUM_LIT:1> ] ) ; assertTrue ( lines [ <NUM_LIT:3> ] . startsWith ( "<STR_LIT>" ) ) ; assertTrue ( lines [ <NUM_LIT:4> ] . startsWith ( "<STR_LIT>" ) ) ; assertTrue ( lines [ <NUM_LIT:5> ] . startsWith ( "<STR_LIT>" ) ) ; assertTrue ( lines [ <NUM_LIT:6> ] . startsWith ( "<STR_LIT>" ) ) ; } @ Test public void executeMethod ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; String result = ( String ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , } , false ) ; String [ ] lines = StringUtils . split ( result , '<STR_LIT:\n>' ) ; assertEquals ( "<STR_LIT>" , lines [ <NUM_LIT:1> ] ) ; assertTrue ( lines [ <NUM_LIT:3> ] . startsWith ( "<STR_LIT>" ) ) ; assertTrue ( lines [ <NUM_LIT:4> ] . startsWith ( "<STR_LIT>" ) ) ; result = ( String ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , CLASS , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , } , false ) ; lines = StringUtils . split ( result , '<STR_LIT:\n>' ) ; assertEquals ( "<STR_LIT>" , lines [ <NUM_LIT:1> ] ) ; assertTrue ( lines [ <NUM_LIT:3> ] . startsWith ( "<STR_LIT>" ) ) ; assertTrue ( lines [ <NUM_LIT:4> ] . startsWith ( "<STR_LIT>" ) ) ; } @ Test public void executePattern ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; String result = ( String ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , } , false ) ; String [ ] lines = StringUtils . split ( result , '<STR_LIT:\n>' ) ; assertEquals ( "<STR_LIT>" , lines [ <NUM_LIT:1> ] ) ; assertTrue ( lines [ <NUM_LIT:3> ] . startsWith ( "<STR_LIT>" ) ) ; assertTrue ( lines [ <NUM_LIT:4> ] . startsWith ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , lines [ <NUM_LIT:6> ] ) ; assertTrue ( lines [ <NUM_LIT:8> ] . startsWith ( "<STR_LIT>" ) ) ; assertTrue ( lines [ <NUM_LIT:9> ] . startsWith ( "<STR_LIT>" ) ) ; assertTrue ( lines [ <NUM_LIT:10> ] . startsWith ( "<STR_LIT>" ) ) ; assertTrue ( lines [ <NUM_LIT:11> ] . startsWith ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . junit ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . regex . Pattern ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class JUnitImplCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; private static final String TEST_FILE_DIFF_PACK = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void execute ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Map < String , Object > result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , } ) ; assertEquals ( "<STR_LIT>" , result . get ( "<STR_LIT:type>" ) ) ; List < Map < String , Object > > types = ( List < Map < String , Object > > ) result . get ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:3> , types . size ( ) ) ; assertEquals ( "<STR_LIT>" , types . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , types . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; HashSet < String > methods = new HashSet < String > ( ( List < String > ) types . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertTrue ( methods . contains ( "<STR_LIT>" ) ) ; assertTrue ( methods . contains ( "<STR_LIT>" ) ) ; assertTrue ( methods . contains ( "<STR_LIT>" ) ) ; result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; String contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; types = ( List < Map < String , Object > > ) result . get ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , types . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , types . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; methods = new HashSet < String > ( ( List < String > ) types . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertFalse ( methods . contains ( "<STR_LIT>" ) ) ; assertFalse ( methods . contains ( "<STR_LIT>" ) ) ; assertTrue ( methods . contains ( "<STR_LIT>" ) ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void executeDifferentPackage ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Map < String , Object > result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE_DIFF_PACK , } ) ; assertEquals ( "<STR_LIT>" , result . get ( "<STR_LIT:type>" ) ) ; List < Map < String , Object > > types = ( List < Map < String , Object > > ) result . get ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:2> , types . size ( ) ) ; assertEquals ( "<STR_LIT>" , types . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , types . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; HashSet < String > methods = new HashSet < String > ( ( List < String > ) types . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertTrue ( methods . contains ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . classpath ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class ClasspathVariableCommandsTest { private static final String TEST_VARIABLE = "<STR_LIT>" ; private static final String TEST_PATH = "<STR_LIT>" ; @ Test public void createVariable ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , TEST_VARIABLE } ) ; assertFalse ( "<STR_LIT>" , variableExists ( ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , TEST_VARIABLE , "<STR_LIT>" , TEST_PATH } ) ; assertTrue ( "<STR_LIT>" , variableExists ( ) ) ; } @ Test public void deleteVariable ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; assertTrue ( "<STR_LIT>" , variableExists ( ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , TEST_VARIABLE } ) ; assertFalse ( "<STR_LIT>" , variableExists ( ) ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) private boolean variableExists ( ) { List < Map < String , String > > list = ( List < Map < String , String > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" } ) ; Map < String , String > var = new HashMap < String , String > ( ) ; var . put ( "<STR_LIT:name>" , TEST_VARIABLE ) ; var . put ( "<STR_LIT:path>" , TEST_PATH ) ; return list . contains ( var ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . impl ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . regex . Pattern ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class DelegateCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void execute ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Map < String , Object > result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; assertEquals ( "<STR_LIT>" , result . get ( "<STR_LIT:type>" ) ) ; List < Map < String , Object > > types = ( List < Map < String , Object > > ) result . get ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:1> , types . size ( ) ) ; assertEquals ( "<STR_LIT>" , types . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , types . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; HashSet < String > methods = new HashSet < String > ( ( List < String > ) types . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertTrue ( methods . contains ( "<STR_LIT>" ) ) ; assertTrue ( methods . contains ( "<STR_LIT>" ) ) ; result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; String contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" + "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" + "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; types = ( List < Map < String , Object > > ) result . get ( "<STR_LIT>" ) ; methods = new HashSet < String > ( ( List < String > ) types . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertFalse ( methods . contains ( "<STR_LIT>" ) ) ; assertFalse ( methods . contains ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . impl ; import java . util . regex . Pattern ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class BeanPropertiesCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test public void executeGet ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:name>" } ) ; String contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; } @ Test public void executeSet ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:name>" } ) ; String contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; } @ Test public void executeGetSet ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; String contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; } @ Test public void executeGetSetIndex ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; String contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . impl ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . regex . Pattern ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class ImplCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; private static final String TEST_SUB_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void execute ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Map < String , Object > result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; assertEquals ( "<STR_LIT>" , result . get ( "<STR_LIT:type>" ) ) ; List < Map < String , Object > > superTypes = ( List < Map < String , Object > > ) result . get ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:4> , superTypes . size ( ) ) ; assertEquals ( "<STR_LIT>" , superTypes . get ( <NUM_LIT:1> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , superTypes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; HashSet < String > methods = new HashSet < String > ( ( List < String > ) superTypes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertTrue ( methods . contains ( "<STR_LIT>" ) ) ; assertTrue ( methods . contains ( "<STR_LIT>" ) ) ; assertTrue ( methods . contains ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , superTypes . get ( <NUM_LIT:3> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , superTypes . get ( <NUM_LIT:3> ) . get ( "<STR_LIT>" ) ) ; methods = new HashSet < String > ( ( List < String > ) superTypes . get ( <NUM_LIT:3> ) . get ( "<STR_LIT>" ) ) ; assertTrue ( methods . contains ( "<STR_LIT>" ) ) ; result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; String contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; superTypes = ( List < Map < String , Object > > ) result . get ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , superTypes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , superTypes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; methods = new HashSet < String > ( ( List < String > ) superTypes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertFalse ( methods . contains ( "<STR_LIT>" ) ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void executeSub ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Map < String , Object > result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_SUB_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; assertEquals ( "<STR_LIT>" , result . get ( "<STR_LIT:type>" ) ) ; List < Map < String , Object > > superTypes = ( List < Map < String , Object > > ) result . get ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , superTypes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , superTypes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; HashSet < String > methods = new HashSet < String > ( ( List < String > ) superTypes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertTrue ( methods . contains ( "<STR_LIT>" ) ) ; result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_SUB_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; String contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_SUB_FILE ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; superTypes = ( List < Map < String , Object > > ) result . get ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , superTypes . get ( <NUM_LIT:1> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , superTypes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; methods = new HashSet < String > ( ( List < String > ) superTypes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertFalse ( methods . contains ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , superTypes . get ( <NUM_LIT:3> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , superTypes . get ( <NUM_LIT:3> ) . get ( "<STR_LIT>" ) ) ; methods = new HashSet < String > ( ( List < String > ) superTypes . get ( <NUM_LIT:3> ) . get ( "<STR_LIT>" ) ) ; assertTrue ( methods . contains ( "<STR_LIT>" ) ) ; result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_SUB_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , } ) ; contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_SUB_FILE ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; superTypes = ( List < Map < String , Object > > ) result . get ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:3> , superTypes . size ( ) ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . impl ; import java . util . regex . Pattern ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class ConstructorCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; private static final String TEST_ENUM_FILE = "<STR_LIT>" ; private static final String TEST_SUPER_FILE = "<STR_LIT>" ; @ Test public void emptyConstructor ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_ENUM_FILE , "<STR_LIT>" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; String contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_ENUM_FILE ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" , Pattern . MULTILINE ) . matcher ( contents ) . find ( ) ) ; } @ Test public void argConstructor ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_SUPER_FILE , "<STR_LIT>" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" } ) ; String contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_SUPER_FILE ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; } @ Test public void nestedConstructor ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; String contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; } @ Test public void nestedArgConstructor ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" } ) ; String contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; } @ Test public void enumConstructor ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_ENUM_FILE , "<STR_LIT>" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" } ) ; String contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_ENUM_FILE ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" , Pattern . MULTILINE ) . matcher ( contents ) . find ( ) ) ; } @ Test public void anonymousConstructor ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; String result = ( String ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" } ) ; System . out . println ( result ) ; assertEquals ( "<STR_LIT>" , result ) ; } @ Test public void superConstructor ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" } ) ; String contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( contents ) . find ( ) ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . src ; import java . io . FileWriter ; import org . apache . commons . lang . StringUtils ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Before ; import org . junit . BeforeClass ; import org . junit . Test ; import static org . junit . Assert . * ; public class FormatCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; private static String contents ; @ BeforeClass public static void setupClass ( ) { contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; } @ Before public void setupTest ( ) throws Exception { String path = Eclim . resolveFile ( Jdt . TEST_PROJECT , TEST_FILE ) ; FileWriter writer = new FileWriter ( path ) ; writer . write ( contents ) ; writer . close ( ) ; } @ Test public void execute ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; String contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; String [ ] lines = StringUtils . split ( contents , '<STR_LIT:\n>' ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , lines [ <NUM_LIT:6> ] ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; lines = StringUtils . split ( contents . replace ( "<STR_LIT:t>" , "<STR_LIT:U+0020U+0020>" ) , '<STR_LIT:\n>' ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , lines [ <NUM_LIT:6> ] ) ; contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; lines = StringUtils . split ( contents , '<STR_LIT:\n>' ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , lines [ <NUM_LIT:7> ] ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , lines [ <NUM_LIT:8> ] ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:}>" , lines [ <NUM_LIT:9> ] ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; lines = StringUtils . split ( contents . replace ( "<STR_LIT:t>" , "<STR_LIT:U+0020U+0020>" ) , '<STR_LIT:\n>' ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , lines [ <NUM_LIT:7> ] ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , lines [ <NUM_LIT:8> ] ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , lines [ <NUM_LIT:9> ] ) ; assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; lines = StringUtils . split ( contents , '<STR_LIT:\n>' ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , lines [ <NUM_LIT:2> ] ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , lines [ <NUM_LIT:3> ] ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , lines [ <NUM_LIT:4> ] ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT:0>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; contents = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; lines = StringUtils . split ( contents . replace ( "<STR_LIT:t>" , "<STR_LIT:U+0020U+0020>" ) , '<STR_LIT:\n>' ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , lines [ <NUM_LIT:2> ] ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , lines [ <NUM_LIT:3> ] ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . src ; import java . io . File ; import java . io . FileInputStream ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . eclim . util . IOUtils ; import org . junit . Test ; import static org . junit . Assert . * ; public class ClassPrototypeCommandTest { @ Test public void execute ( ) throws Exception { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; String result = ( String ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" } ) ; File file = new File ( result ) ; assertTrue ( "<STR_LIT>" , file . exists ( ) ) ; FileInputStream fin = null ; try { fin = new FileInputStream ( file ) ; String contents = IOUtils . toString ( fin ) ; System . out . println ( "<STR_LIT>" + contents ) ; assertTrue ( "<STR_LIT>" , contents . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; assertTrue ( "<STR_LIT>" , contents . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; assertTrue ( "<STR_LIT>" , contents . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; assertTrue ( "<STR_LIT>" , contents . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; } finally { IOUtils . closeQuietly ( fin ) ; } } } </s>
|
<s> package org . eclim . plugin . jdt . command . src ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class SrcFileExistsCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test public void execute ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; String result = ( String ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE } ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:true>" , result ) ; result = ( String ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE . replace ( '<CHAR_LIT>' , '<CHAR_LIT>' ) } ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:false>" , result ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . src ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class SrcUpdateCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void update ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:3> , results . size ( ) ) ; String file = Eclim . resolveFile ( Jdt . TEST_PROJECT , TEST_FILE ) ; Map < String , Object > error = results . get ( <NUM_LIT:0> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertTrue ( ( ( String ) error . get ( "<STR_LIT:message>" ) ) . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:10> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:5> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , true ) ; error = results . get ( <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertTrue ( ( ( String ) error . get ( "<STR_LIT:message>" ) ) . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:10> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , true ) ; error = results . get ( <NUM_LIT:2> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertTrue ( ( ( String ) error . get ( "<STR_LIT:message>" ) ) . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:11> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:10> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . src ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class CheckstyleCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void execute ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:4> , results . size ( ) ) ; String file = Eclim . resolveFile ( Jdt . TEST_PROJECT , TEST_FILE ) ; Map < String , Object > error = results . get ( <NUM_LIT:0> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertEquals ( error . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:5> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , true ) ; error = results . get ( <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertEquals ( error . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:6> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:12> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , true ) ; error = results . get ( <NUM_LIT:2> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertEquals ( error . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:6> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , true ) ; error = results . get ( <NUM_LIT:3> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertEquals ( error . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:9> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , true ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . src ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class SrcFindCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test public void execute ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; String result = ( String ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" } ) ; assertEquals ( "<STR_LIT>" , Eclim . resolveFile ( Jdt . TEST_PROJECT , TEST_FILE ) , result ) ; result = ( String ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" } ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , result ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . include ; import java . util . List ; import java . util . Map ; import java . util . regex . Pattern ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . BeforeClass ; import org . junit . Test ; import static org . junit . Assert . * ; public class ImportCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ BeforeClass public static void setUp ( ) { Eclim . setProjectSetting ( Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT:-1>" ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void execute ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Pattern listImport = Pattern . compile ( "<STR_LIT>" ) ; String file = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertFalse ( listImport . matcher ( file ) . find ( ) ) ; List < String > results = ( List < String > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , } ) ; assertEquals ( <NUM_LIT:2> , results . size ( ) ) ; assertEquals ( "<STR_LIT>" , results . get ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , results . get ( <NUM_LIT:1> ) ) ; file = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertFalse ( listImport . matcher ( file ) . find ( ) ) ; Map < String , Object > position = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" , } ) ; file = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertTrue ( listImport . matcher ( file ) . find ( ) ) ; assertEquals ( <NUM_LIT> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:7> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , position . get ( "<STR_LIT>" ) ) ; position = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , } ) ; Pattern arrayListImport = Pattern . compile ( "<STR_LIT>" ) ; file = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertTrue ( arrayListImport . matcher ( file ) . find ( ) ) ; assertEquals ( <NUM_LIT> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:8> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , position . get ( "<STR_LIT>" ) ) ; position = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , } ) ; Pattern patternImport = Pattern . compile ( "<STR_LIT>" ) ; file = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertTrue ( patternImport . matcher ( file ) . find ( ) ) ; assertEquals ( <NUM_LIT> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:11> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , position . get ( "<STR_LIT>" ) ) ; position = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , } ) ; Pattern fileImport = Pattern . compile ( "<STR_LIT>" ) ; file = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertTrue ( fileImport . matcher ( file ) . find ( ) ) ; assertEquals ( <NUM_LIT> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:11> , position . get ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . include ; import java . util . List ; import java . util . Map ; import java . util . regex . Pattern ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . BeforeClass ; import org . junit . Test ; import static org . junit . Assert . * ; public class ImportOrganizeCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ BeforeClass public static void setUp ( ) { Eclim . setProjectSetting ( Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT:-1>" ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void execute ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Pattern listImport = Pattern . compile ( "<STR_LIT>" ) ; String file = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertFalse ( listImport . matcher ( file ) . find ( ) ) ; List < List < String > > results = ( List < List < String > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , } ) ; assertEquals ( <NUM_LIT:2> , results . size ( ) ) ; List < String > entries = results . get ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , entries . get ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , entries . get ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , entries . get ( <NUM_LIT:2> ) ) ; List < String > lists = results . get ( <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , lists . get ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , lists . get ( <NUM_LIT:1> ) ) ; file = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertFalse ( listImport . matcher ( file ) . find ( ) ) ; Map < String , Object > position = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" , } ) ; file = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertTrue ( listImport . matcher ( file ) . find ( ) ) ; assertEquals ( <NUM_LIT> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:16> , position . get ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . refactoring ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class MoveCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void execute ( ) throws Exception { String p = Eclim . resolveFile ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; Map < String , Object > result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" } ) ; assertTrue ( result . containsKey ( "<STR_LIT>" ) ) ; List < String > errors = ( List < String > ) result . get ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:1> , errors . size ( ) ) ; assertEquals ( "<STR_LIT>" , errors . get ( <NUM_LIT:0> ) ) ; List < Map < String , String > > results = ( List < Map < String , String > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" } ) ; assertEquals ( p + "<STR_LIT>" , results . get ( <NUM_LIT:0> ) . get ( "<STR_LIT:file>" ) ) ; assertEquals ( p + "<STR_LIT>" , results . get ( <NUM_LIT:1> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( p + "<STR_LIT>" , results . get ( <NUM_LIT:1> ) . get ( "<STR_LIT>" ) ) ; results = ( List < Map < String , String > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" } ) ; assertEquals ( p + "<STR_LIT>" , results . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( p + "<STR_LIT>" , results . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( p + "<STR_LIT>" , results . get ( <NUM_LIT:1> ) . get ( "<STR_LIT:file>" ) ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . refactoring ; import java . io . File ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class RenameCommandTest { @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void executeRenameField ( ) throws Exception { String p = Eclim . resolveFile ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; String tn1Contents = Eclim . fileToString ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , tn1Contents . indexOf ( "<STR_LIT>" ) > <NUM_LIT:0> ) ; String tn2Contents = Eclim . fileToString ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , tn2Contents . indexOf ( "<STR_LIT>" ) > <NUM_LIT:0> ) ; assertTrue ( "<STR_LIT>" , tn2Contents . indexOf ( "<STR_LIT>" ) > <NUM_LIT:0> ) ; Map < String , Object > preview = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:3>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , } ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , preview . get ( "<STR_LIT>" ) ) ; List < Map < String , String > > changes = ( List < Map < String , String > > ) preview . get ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:2> , changes . size ( ) ) ; assertEquals ( "<STR_LIT>" , changes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT:type>" ) ) ; assertEquals ( p + "<STR_LIT>" , changes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT:file>" ) ) ; assertEquals ( "<STR_LIT>" , changes . get ( <NUM_LIT:1> ) . get ( "<STR_LIT:type>" ) ) ; assertEquals ( p + "<STR_LIT>" , changes . get ( <NUM_LIT:1> ) . get ( "<STR_LIT:file>" ) ) ; String diff = ( String ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:3>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" , Eclim . resolveFile ( Jdt . TEST_PROJECT , "<STR_LIT>" ) , } ) ; assertEquals ( "<STR_LIT>" , tn2Contents . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) , diff ) ; List < Map < String , String > > result = ( List < Map < String , String > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:3>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , } ) ; assertEquals ( p + "<STR_LIT>" , result . get ( <NUM_LIT:0> ) . get ( "<STR_LIT:file>" ) ) ; assertEquals ( p + "<STR_LIT>" , result . get ( <NUM_LIT:1> ) . get ( "<STR_LIT:file>" ) ) ; String tn1NewContents = Eclim . fileToString ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , tn1Contents . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) , tn1NewContents ) ; String tn2NewContents = Eclim . fileToString ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , tn2Contents . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) , tn2NewContents ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void executeRenameMethod ( ) throws Exception { String p = Eclim . resolveFile ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; String tn1Contents = Eclim . fileToString ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , tn1Contents . indexOf ( "<STR_LIT>" ) > <NUM_LIT:0> ) ; String tn2Contents = Eclim . fileToString ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , tn2Contents . indexOf ( "<STR_LIT>" ) > <NUM_LIT:0> ) ; Map < String , Object > preview = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:10>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , } ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , preview . get ( "<STR_LIT>" ) ) ; List < Map < String , String > > changes = ( List < Map < String , String > > ) preview . get ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:2> , changes . size ( ) ) ; assertEquals ( "<STR_LIT>" , changes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT:type>" ) ) ; assertEquals ( p + "<STR_LIT>" , changes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT:file>" ) ) ; assertEquals ( "<STR_LIT>" , changes . get ( <NUM_LIT:1> ) . get ( "<STR_LIT:type>" ) ) ; assertEquals ( p + "<STR_LIT>" , changes . get ( <NUM_LIT:1> ) . get ( "<STR_LIT:file>" ) ) ; String diff = ( String ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:10>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" , Eclim . resolveFile ( Jdt . TEST_PROJECT , "<STR_LIT>" ) , } ) ; assertEquals ( "<STR_LIT>" , tn1Contents . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) , diff ) ; List < Map < String , String > > result = ( List < Map < String , String > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:10>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , } ) ; assertEquals ( p + "<STR_LIT>" , result . get ( <NUM_LIT:0> ) . get ( "<STR_LIT:file>" ) ) ; assertEquals ( p + "<STR_LIT>" , result . get ( <NUM_LIT:1> ) . get ( "<STR_LIT:file>" ) ) ; String tn1NewContents = Eclim . fileToString ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , tn1Contents . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) , tn1NewContents ) ; String tn2NewContents = Eclim . fileToString ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , tn2Contents . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) , tn2NewContents ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void executeRenameType ( ) throws Exception { String p = Eclim . resolveFile ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; String tn1Contents = Eclim . fileToString ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , tn1Contents . indexOf ( "<STR_LIT>" ) > <NUM_LIT:0> ) ; String tn2Contents = Eclim . fileToString ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , tn2Contents . indexOf ( "<STR_LIT>" ) > <NUM_LIT:0> ) ; Map < String , Object > preview = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:6>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , } ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , preview . get ( "<STR_LIT>" ) ) ; List < Map < String , String > > changes = ( List < Map < String , String > > ) preview . get ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:2> , changes . size ( ) ) ; assertEquals ( "<STR_LIT>" , changes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT:type>" ) ) ; assertEquals ( p + "<STR_LIT>" , changes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT:file>" ) ) ; assertEquals ( "<STR_LIT>" , changes . get ( <NUM_LIT:1> ) . get ( "<STR_LIT:type>" ) ) ; assertEquals ( "<STR_LIT>" , changes . get ( <NUM_LIT:1> ) . get ( "<STR_LIT:message>" ) ) ; String diff = ( String ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:6>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" , Eclim . resolveFile ( Jdt . TEST_PROJECT , "<STR_LIT>" ) , } ) ; assertEquals ( "<STR_LIT>" , tn2Contents . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) , diff ) ; List < Map < String , String > > result = ( List < Map < String , String > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:6>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , } ) ; assertEquals ( p + "<STR_LIT>" , result . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( p + "<STR_LIT>" , result . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( p + "<STR_LIT>" , result . get ( <NUM_LIT:1> ) . get ( "<STR_LIT:file>" ) ) ; assertFalse ( new File ( Eclim . resolveFile ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ) . exists ( ) ) ; String tn1NewContents = Eclim . fileToString ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , tn1Contents . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) , tn1NewContents ) ; String tn2NewContents = Eclim . fileToString ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , tn2Contents . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) , tn2NewContents ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void executeRenamePackage ( ) throws Exception { String p = Eclim . resolveFile ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; String tr1Contents = Eclim . fileToString ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , tr1Contents . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; String tn2Contents = Eclim . fileToString ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , tn2Contents . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; Map < String , Object > preview = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:2>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , } ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , preview . get ( "<STR_LIT>" ) ) ; List < Map < String , String > > changes = ( List < Map < String , String > > ) preview . get ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:2> , changes . size ( ) ) ; assertEquals ( "<STR_LIT>" , changes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT:type>" ) ) ; assertEquals ( p + "<STR_LIT>" , changes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT:file>" ) ) ; assertEquals ( "<STR_LIT>" , changes . get ( <NUM_LIT:1> ) . get ( "<STR_LIT:type>" ) ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" , changes . get ( <NUM_LIT:1> ) . get ( "<STR_LIT:message>" ) ) ; String diff = ( String ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:2>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" , Eclim . resolveFile ( Jdt . TEST_PROJECT , "<STR_LIT>" ) , } ) ; assertEquals ( "<STR_LIT>" , tn2Contents . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) , diff ) ; List < Map < String , String > > result = ( List < Map < String , String > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:2>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , } ) ; assertEquals ( p + "<STR_LIT>" , result . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( p + "<STR_LIT>" , result . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( p + "<STR_LIT>" , result . get ( <NUM_LIT:1> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( p + "<STR_LIT>" , result . get ( <NUM_LIT:1> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( p + "<STR_LIT>" , result . get ( <NUM_LIT:2> ) . get ( "<STR_LIT>" ) ) ; assertEquals ( p + "<STR_LIT>" , result . get ( <NUM_LIT:2> ) . get ( "<STR_LIT>" ) ) ; assertFalse ( new File ( Eclim . resolveFile ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ) . exists ( ) ) ; String tn1NewContents = Eclim . fileToString ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , tr1Contents . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) , tn1NewContents ) ; assertFalse ( new File ( Eclim . resolveFile ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ) . exists ( ) ) ; String tn2NewContents = Eclim . fileToString ( Jdt . TEST_PROJECT , "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , tn2Contents . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) , tn2NewContents ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . correct ; import java . util . List ; import java . util . Map ; import java . util . regex . Pattern ; import org . apache . commons . lang . StringUtils ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class CorrectCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; private static final String TEST_FILE_PACKAGE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void suggest ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Map < String , Object > result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT:5>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; assertEquals ( "<STR_LIT>" , result . get ( "<STR_LIT:message>" ) ) ; assertEquals ( <NUM_LIT> , result . get ( "<STR_LIT>" ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) result . get ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:0> , results . get ( <NUM_LIT:0> ) . get ( "<STR_LIT:index>" ) ) ; assertEquals ( "<STR_LIT>" , results . get ( <NUM_LIT:0> ) . get ( "<STR_LIT:description>" ) ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void apply ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Map < String , Object > result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT:5>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) result . get ( "<STR_LIT>" ) ; int apply = - <NUM_LIT:1> ; for ( Map < String , Object > r : results ) { if ( r . get ( "<STR_LIT:description>" ) . equals ( "<STR_LIT>" ) ) { apply = ( ( Integer ) r . get ( "<STR_LIT:index>" ) ) . intValue ( ) ; break ; } } assertTrue ( "<STR_LIT>" , apply > - <NUM_LIT:1> ) ; List < Map < String , String > > changes = ( List < Map < String , String > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT:5>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , String . valueOf ( apply ) } ) ; assertEquals ( <NUM_LIT:1> , changes . size ( ) ) ; assertEquals ( Eclim . resolveFile ( Jdt . TEST_PROJECT , TEST_FILE ) , changes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT:file>" ) ) ; String file = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE ) ; assertTrue ( "<STR_LIT>" , Pattern . compile ( "<STR_LIT>" ) . matcher ( file ) . find ( ) ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void suggestPackage ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; Map < String , Object > result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE_PACKAGE , "<STR_LIT>" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT:0>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" , result . get ( "<STR_LIT:message>" ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) result . get ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , results . get ( <NUM_LIT:1> ) . get ( "<STR_LIT:description>" ) ) ; assertEquals ( "<STR_LIT>" , results . get ( <NUM_LIT:1> ) . get ( "<STR_LIT>" ) ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void applyPackage ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; List < Map < String , String > > changes = ( List < Map < String , String > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE_PACKAGE , "<STR_LIT>" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT:0>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT:1>" } ) ; assertEquals ( <NUM_LIT:1> , changes . size ( ) ) ; assertEquals ( Eclim . resolveFile ( Jdt . TEST_PROJECT , TEST_FILE_PACKAGE ) , changes . get ( <NUM_LIT:0> ) . get ( "<STR_LIT:file>" ) ) ; String file = Eclim . fileToString ( Jdt . TEST_PROJECT , TEST_FILE_PACKAGE ) ; String [ ] lines = StringUtils . split ( file , '<STR_LIT:\n>' ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , lines [ <NUM_LIT:0> ] ) ; } } </s>
|
<s> package org . eclim . plugin . jdt . command . search ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . jdt . Jdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class SearchCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void searchCamelCase ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , results . size ( ) ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertTrue ( ( ( String ) result . get ( "<STR_LIT>" ) ) . endsWith ( "<STR_LIT>" ) ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:7> ) ; result = results . get ( <NUM_LIT:1> ) ; assertTrue ( ( ( String ) result . get ( "<STR_LIT>" ) ) . endsWith ( "<STR_LIT>" ) ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void searchElement ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT:4>" } ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertTrue ( ( ( String ) result . get ( "<STR_LIT>" ) ) . endsWith ( "<STR_LIT>" ) ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:8> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:16> ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void searchPattern ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , results . size ( ) ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertTrue ( ( ( String ) result . get ( "<STR_LIT>" ) ) . endsWith ( "<STR_LIT>" ) ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:6> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; result = results . get ( <NUM_LIT:1> ) ; assertTrue ( ( ( String ) result . get ( "<STR_LIT>" ) ) . endsWith ( "<STR_LIT>" ) ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:6> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void searchField ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Jdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Jdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:field>" } ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertTrue ( ( ( String ) result . get ( "<STR_LIT>" ) ) . endsWith ( "<STR_LIT>" ) ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:8> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:16> ) ; } } </s>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.