All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.aspectj.ajdt.internal.compiler.lookup.OwningClassSupportForFieldBindings.aj Maven / Gradle / Ivy

Go to download

AspectJ tools most notably contains the AspectJ compiler (AJC). AJC applies aspects to Java classes during compilation, fully replacing Javac for plain Java classes and also compiling native AspectJ or annotation-based @AspectJ syntax. Furthermore, AJC can weave aspects into existing class files in a post-compile binary weaving step. This library is a superset of AspectJ weaver and hence also of AspectJ runtime.

There is a newer version: 1.9.22.1
Show newest version
/* *******************************************************************
 * Copyright (c) 2005 Contributors.
 * All rights reserved.
 * This program and the accompanying materials are made available
 * under the terms of the Eclipse Public License v 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
 *  
 * Contributors: 
 *   Adrian Colyer			Initial implementation
 * ******************************************************************/
package org.aspectj.ajdt.internal.compiler.lookup;

import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
//import org.eclipse.jdt.internal.compiler.lookup.ParameterizedFieldBinding;

/**
 * Many routines in the JDT compiler use fieldBinding.declaringClass to get
 * the class that owns a field in order to perform checks etc.
 * For inter-type declared fields, the declaringClass will be the aspect,
 * and the owningClass will be the onType of the ITD. We need to ensure that
 * JDT always sees the appropriate type.
 */
public aspect OwningClassSupportForFieldBindings {

	/**
	 * This method is overriden by InterTypeFieldBinding to return the onType instead
	 */
	public ReferenceBinding FieldBinding.getOwningClass() {
		return declaringClass; 
	}
	
	/**
	 * ParameterizedFieldBindings are backed by the "original" method
	 * they parameterize. The real owning class is the one owned by that. 
	 */
//	public ReferenceBinding ParameterizedFieldBinding.getOwningClass() {
//		return original().getOwningClass();
//   }
	
   /**
    * This aspect handles the switch from declaringClass to owningClass()
    */
   declare warning : call(* FieldBinding.getOwningClass())  
                       && !within(OwningClassSupportForFieldBindings)
                     : "owningClass() support is handled by OwningClassSupportForFieldBindings aspect"; //$NON-NLS-1$
                       
   pointcut accessingDeclaringTypeOfAFieldBinding(FieldBinding aBinding) :
	   get(* FieldBinding.declaringClass) && target(aBinding);
   
   pointcut redirectedDeclaringClassAccesses(FieldBinding aBinding) :
	   accessingDeclaringTypeOfAFieldBinding(aBinding) && 
	   !within(OwningClassSupportForFieldBindings) &&
	   !withincode(* FieldBinding.canBeSeenBy(..)) && // must be based on aspect type here
	   !withincode(FieldBinding.new(..));             // allow binding to initialise properly
   
   Object around(FieldBinding aBinding) : redirectedDeclaringClassAccesses(aBinding) { 
	   return aBinding.getOwningClass();
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy