mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Support of AspectJ language
This commit is contained in:
		| @@ -129,6 +129,12 @@ AsciiDoc: | |||||||
|   - .adoc |   - .adoc | ||||||
|   - .asc |   - .asc | ||||||
|  |  | ||||||
|  | AspectJ: | ||||||
|  |   type: programming | ||||||
|  |   lexer: AspectJ | ||||||
|  |   color: "#1957b0" | ||||||
|  |   primary_extension: .aj | ||||||
|  |  | ||||||
| Assembly: | Assembly: | ||||||
|   type: programming |   type: programming | ||||||
|   lexer: NASM |   lexer: NASM | ||||||
|   | |||||||
							
								
								
									
										41
									
								
								samples/AspectJ/CacheAspect.aj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								samples/AspectJ/CacheAspect.aj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | |||||||
|  | package com.blogspot.miguelinlas3.aspectj.cache; | ||||||
|  |  | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.WeakHashMap; | ||||||
|  |  | ||||||
|  | import org.aspectj.lang.JoinPoint; | ||||||
|  |  | ||||||
|  | import com.blogspot.miguelinlas3.aspectj.cache.marker.Cachable; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * This simple aspect simulates the behaviour of a very simple cache | ||||||
|  |  *   | ||||||
|  |  * @author migue | ||||||
|  |  * | ||||||
|  |  */ | ||||||
|  | public aspect CacheAspect { | ||||||
|  |  | ||||||
|  | 	public pointcut cache(Cachable cachable): execution(@Cachable * * (..)) && @annotation(cachable); | ||||||
|  | 	 | ||||||
|  | 	Object around(Cachable cachable): cache(cachable){ | ||||||
|  | 	 | ||||||
|  | 		String evaluatedKey = this.evaluateKey(cachable.scriptKey(), thisJoinPoint); | ||||||
|  | 		 | ||||||
|  | 		if(cache.containsKey(evaluatedKey)){ | ||||||
|  | 			System.out.println("Cache hit for key " + evaluatedKey); | ||||||
|  | 			return this.cache.get(evaluatedKey); | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  | 		System.out.println("Cache miss for key " + evaluatedKey); | ||||||
|  | 		Object value = proceed(cachable); | ||||||
|  | 		cache.put(evaluatedKey, value); | ||||||
|  | 		return value; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	protected String evaluateKey(String key, JoinPoint joinPoint) { | ||||||
|  | 		// TODO add some smart staff to allow simple scripting in @Cachable annotation | ||||||
|  | 		return key; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	protected Map<String, Object> cache = new WeakHashMap<String, Object>(); | ||||||
|  | } | ||||||
							
								
								
									
										50
									
								
								samples/AspectJ/OptimizeRecursionCache.aj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								samples/AspectJ/OptimizeRecursionCache.aj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,50 @@ | |||||||
|  | package aspects.caching; | ||||||
|  |  | ||||||
|  | import java.util.Map; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Cache aspect for optimize recursive functions. | ||||||
|  |  *  | ||||||
|  |  * @author Migueli | ||||||
|  |  * @date 05/11/2013 | ||||||
|  |  * @version 1.0 | ||||||
|  |  * | ||||||
|  |  */ | ||||||
|  | public abstract aspect OptimizeRecursionCache { | ||||||
|  | 		 | ||||||
|  | 	@SuppressWarnings("rawtypes") | ||||||
|  | 	private Map _cache; | ||||||
|  | 	 | ||||||
|  | 	public OptimizeRecursionCache() { | ||||||
|  | 		_cache = getCache(); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	@SuppressWarnings("rawtypes") | ||||||
|  | 	abstract public Map getCache(); | ||||||
|  | 	 | ||||||
|  | 	abstract public pointcut operation(Object o); | ||||||
|  |  | ||||||
|  | 	pointcut topLevelOperation(Object o): operation(o) && !cflowbelow(operation(Object)); | ||||||
|  |  | ||||||
|  | 	before(Object o) : topLevelOperation(o) { | ||||||
|  | 		System.out.println("Seeking value for " + o); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	Object around(Object o) : operation(o) { | ||||||
|  | 		Object cachedValue = _cache.get(o); | ||||||
|  | 		if (cachedValue != null) { | ||||||
|  | 			System.out.println("Found cached value for " + o + ": " + cachedValue); | ||||||
|  | 			return cachedValue; | ||||||
|  | 		} | ||||||
|  | 		return proceed(o); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	@SuppressWarnings("unchecked") | ||||||
|  | 	after(Object o) returning(Object result) : topLevelOperation(o) { | ||||||
|  | 		_cache.put(o, result); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	after(Object o) returning(Object result) : topLevelOperation(o) { | ||||||
|  | 		System.out.println("cache size: " + _cache.size()); | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @@ -10,6 +10,7 @@ class TestLanguage < Test::Unit::TestCase | |||||||
|  |  | ||||||
|   def test_lexer |   def test_lexer | ||||||
|     assert_equal Lexer['ActionScript 3'], Language['ActionScript'].lexer |     assert_equal Lexer['ActionScript 3'], Language['ActionScript'].lexer | ||||||
|  |     assert_equal Lexer['AspectJ'], Language['AspectJ'].lexer | ||||||
|     assert_equal Lexer['Bash'], Language['Gentoo Ebuild'].lexer |     assert_equal Lexer['Bash'], Language['Gentoo Ebuild'].lexer | ||||||
|     assert_equal Lexer['Bash'], Language['Gentoo Eclass'].lexer |     assert_equal Lexer['Bash'], Language['Gentoo Eclass'].lexer | ||||||
|     assert_equal Lexer['Bash'], Language['Shell'].lexer |     assert_equal Lexer['Bash'], Language['Shell'].lexer | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user